Module: kamailio
Branch: master
Commit: f54ce325ced4ac8c0361a2c736cc199b5b641a6d
URL:
https://github.com/kamailio/kamailio/commit/f54ce325ced4ac8c0361a2c736cc199…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-04-10T13:52:14+02:00
pv: added new transformation {uri.tosocket}
- converts a sip uri to socket address format
- from sip:address:port;transport=proto to proto:address:port
---
Modified: src/modules/pv/pv_trans.c
Modified: src/modules/pv/pv_trans.h
---
Diff:
https://github.com/kamailio/kamailio/commit/f54ce325ced4ac8c0361a2c736cc199…
Patch:
https://github.com/kamailio/kamailio/commit/f54ce325ced4ac8c0361a2c736cc199…
---
diff --git a/src/modules/pv/pv_trans.c b/src/modules/pv/pv_trans.c
index dd7d9a7f62..f93a5e3d6f 100644
--- a/src/modules/pv/pv_trans.c
+++ b/src/modules/pv/pv_trans.c
@@ -1180,6 +1180,7 @@ int tr_eval_uri(struct sip_msg *msg, tr_param_t *tp, int subtype,
str sv;
param_hooks_t phooks;
param_t *pit=NULL;
+ str sproto;
if(val==NULL || (!(val->flags&PV_VAL_STR)) || val->rs.len<=0)
return -1;
@@ -1337,6 +1338,31 @@ int tr_eval_uri(struct sip_msg *msg, tr_param_t *tp, int subtype,
val->rs.len++;
}
break;
+ case TR_URI_TOSOCKET:
+ if(msg==NULL) {
+ val->rs = _tr_empty;
+ break;
+ } else {
+ if(get_valid_proto_string(msg->rcv.proto, 1, 0, &sproto)<0) {
+ LM_WARN("unknown transport protocol\n");
+ val->rs = _tr_empty;
+ break;
+ }
+ tr_set_crt_buffer();
+ val->rs.len = snprintf(_tr_buffer, TR_BUFFER_SIZE,
+ "%.*s:%.*s:%d", sproto.len, sproto.s,
+ _tr_parsed_uri.host.len, _tr_parsed_uri.host.s,
+ (_tr_parsed_uri.port_no!=0)
+ ?(int)_tr_parsed_uri.port_no:5060);
+ if(val->rs.len<=0 || val->rs.len>=TR_BUFFER_SIZE) {
+ LM_WARN("error converting uri to socket address [%.*s]\n",
+ _tr_uri.len, _tr_uri.s);
+ val->rs = _tr_empty;
+ break;
+ }
+ val->rs.s = _tr_buffer;
+ }
+ break;
default:
LM_ERR("unknown subtype %d\n",
subtype);
@@ -2594,6 +2620,9 @@ char* tr_parse_uri(str* in, trans_t *t)
} else if(name.len==6 && strncasecmp(name.s, "scheme", 6)==0) {
t->subtype = TR_URI_SCHEME;
goto done;
+ } else if(name.len==6 && strncasecmp(name.s, "tosocket", 8)==0) {
+ t->subtype = TR_URI_TOSOCKET;
+ goto done;
}
LM_ERR("unknown transformation: %.*s/%.*s!\n", in->len,
diff --git a/src/modules/pv/pv_trans.h b/src/modules/pv/pv_trans.h
index aacb722b95..a4bc0759e8 100644
--- a/src/modules/pv/pv_trans.h
+++ b/src/modules/pv/pv_trans.h
@@ -47,7 +47,7 @@ enum _tr_uri_subtype {
TR_URI_NONE=0, TR_URI_USER, TR_URI_HOST, TR_URI_PASSWD, TR_URI_PORT,
TR_URI_PARAMS, TR_URI_PARAM, TR_URI_HEADERS, TR_URI_TRANSPORT, TR_URI_TTL,
TR_URI_UPARAM, TR_URI_MADDR, TR_URI_METHOD, TR_URI_LR,
- TR_URI_R2, TR_URI_SCHEME
+ TR_URI_R2, TR_URI_SCHEME, TR_URI_TOSOCKET
};
enum _tr_param_subtype {
TR_PL_NONE=0, TR_PL_VALUE, TR_PL_VALUEAT, TR_PL_NAME, TR_PL_COUNT