Module: kamailio
Branch: master
Commit: 4a3ad2bf58d6c18f522bb73330030403a50cafbf
URL:
https://github.com/kamailio/kamailio/commit/4a3ad2bf58d6c18f522bb7333003040…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-08-28T20:42:15+02:00
pv: new transformation {uri.suri}
- get the simple routing uri - keep only transport parameter, if exists
---
Modified: src/modules/pv/pv_trans.c
Modified: src/modules/pv/pv_trans.h
---
Diff:
https://github.com/kamailio/kamailio/commit/4a3ad2bf58d6c18f522bb7333003040…
Patch:
https://github.com/kamailio/kamailio/commit/4a3ad2bf58d6c18f522bb7333003040…
---
diff --git a/src/modules/pv/pv_trans.c b/src/modules/pv/pv_trans.c
index d07e55e719..b9eb291b99 100644
--- a/src/modules/pv/pv_trans.c
+++ b/src/modules/pv/pv_trans.c
@@ -1408,6 +1408,62 @@ int tr_eval_uri(struct sip_msg *msg, tr_param_t *tp, int subtype,
case TR_URI_PASSWD:
val->rs = (_tr_parsed_uri.passwd.s)?_tr_parsed_uri.passwd:_tr_empty;
break;
+ case TR_URI_SURI:
+ if(_tr_uri.len >= TR_BUFFER_SIZE) {
+ LM_WARN("uri too long [%.*s] (%d)\n",
+ _tr_uri.len, _tr_uri.s, _tr_uri.len);
+ val->rs = _tr_empty;
+ break;
+ }
+
+ tr_set_crt_buffer();
+ sv.s = _tr_uri.s;
+ sv.len = 0;
+ while(sv.len<_tr_uri.len) {
+ if(_tr_uri.s[sv.len]==':') {
+ break;
+ }
+ sv.len++;
+ }
+ if(_tr_uri.s[sv.len]!=':') {
+ LM_WARN("uri schema not found [%.*s] (%d)\n",
+ _tr_uri.len, _tr_uri.s, _tr_uri.len);
+ val->rs = _tr_empty;
+ break;
+ }
+ sv.len++;
+ memcpy(_tr_buffer, sv.s, sv.len);
+ sv.s = _tr_buffer;
+ sv.len++;
+ if(_tr_parsed_uri.user.len > 0) {
+ memcpy(sv.s + sv.len, _tr_parsed_uri.user.s,
+ _tr_parsed_uri.user.len);
+ sv.len += _tr_parsed_uri.user.len;
+ sv.s[sv.len] = '@';
+ sv.len++;
+ }
+ if(_tr_parsed_uri.host.len > 0) {
+ memcpy(sv.s + sv.len, _tr_parsed_uri.host.s,
+ _tr_parsed_uri.host.len);
+ sv.len += _tr_parsed_uri.host.len;
+ }
+ if(_tr_parsed_uri.port.len > 0) {
+ sv.s[sv.len] = ':';
+ sv.len++;
+ memcpy(sv.s + sv.len, _tr_parsed_uri.port.s,
+ _tr_parsed_uri.port.len);
+ sv.len += _tr_parsed_uri.port.len;
+ }
+ if(_tr_parsed_uri.transport_val.len > 0) {
+ memcpy(sv.s + sv.len, ";transport=", 11);
+ sv.len += 11;
+ memcpy(sv.s + sv.len, _tr_parsed_uri.transport_val.s,
+ _tr_parsed_uri.transport_val.len);
+ sv.len += _tr_parsed_uri.transport_val.len;
+ }
+ sv.s[sv.len] = '\0';
+ val->rs = sv;
+ break;
case TR_URI_PORT:
val->flags |= PV_TYPE_INT|PV_VAL_INT;
val->rs = (_tr_parsed_uri.port.s)?_tr_parsed_uri.port:_tr_empty;
@@ -2788,6 +2844,9 @@ char* tr_parse_uri(str* in, trans_t *t)
} else if(name.len==4 && strncasecmp(name.s, "port", 4)==0) {
t->subtype = TR_URI_PORT;
goto done;
+ } else if(name.len==4 && strncasecmp(name.s, "suri", 4)==0) {
+ t->subtype = TR_URI_SURI;
+ goto done;
} else if(name.len==6 && strncasecmp(name.s, "params", 6)==0) {
t->subtype = TR_URI_PARAMS;
goto done;
diff --git a/src/modules/pv/pv_trans.h b/src/modules/pv/pv_trans.h
index 6494852246..bf4c922243 100644
--- a/src/modules/pv/pv_trans.h
+++ b/src/modules/pv/pv_trans.h
@@ -50,7 +50,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_TOSOCKET
+ TR_URI_R2, TR_URI_SCHEME, TR_URI_TOSOCKET, TR_URI_SURI
};
enum _tr_param_subtype {
TR_PL_NONE=0, TR_PL_VALUE, TR_PL_VALUEAT, TR_PL_NAME, TR_PL_COUNT