Module: kamailio
Branch: master
Commit: 1262884a47719fd0349a9ce8553d70e167d5b05a
URL:
https://github.com/kamailio/kamailio/commit/1262884a47719fd0349a9ce8553d70e…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-09-04T18:55:20+02:00
pv: added transformation {s.unbracket}
- return value without surrounding (), [], {} or <>
---
Modified: src/modules/pv/pv_trans.c
Modified: src/modules/pv/pv_trans.h
---
Diff:
https://github.com/kamailio/kamailio/commit/1262884a47719fd0349a9ce8553d70e…
Patch:
https://github.com/kamailio/kamailio/commit/1262884a47719fd0349a9ce8553d70e…
---
diff --git a/src/modules/pv/pv_trans.c b/src/modules/pv/pv_trans.c
index 79e31a9ded..a515393869 100644
--- a/src/modules/pv/pv_trans.c
+++ b/src/modules/pv/pv_trans.c
@@ -1180,6 +1180,32 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int
subtype,
val->rs.s[val->rs.len] = '\0';
break;
+ case TR_S_UNBRACKET:
+ if(!(val->flags&PV_VAL_STR)) {
+ val->rs.s = int2str(val->ri, &val->rs.len);
+ break;
+ }
+ if(val->rs.len<2) {
+ break;
+ }
+ if(val->rs.len>TR_BUFFER_SIZE-2) {
+ LM_ERR("value too large: %d\n", val->rs.len);
+ return -1;
+ }
+ if((val->rs.s[0] == '(' && val->rs.s[val->rs.len-1] ==
')')
+ || (val->rs.s[0] == '[' && val->rs.s[val->rs.len-1] ==
']')
+ || (val->rs.s[0] == '{' && val->rs.s[val->rs.len-1] ==
'}')
+ || (val->rs.s[0] == '<' && val->rs.s[val->rs.len-1] ==
'>')) {
+ memcpy(_tr_buffer, val->rs.s+1, val->rs.len-2);
+ val->rs.len -= 2;
+ } else {
+ memcpy(_tr_buffer, val->rs.s, val->rs.len);
+ }
+ val->flags = PV_VAL_STR;
+ val->rs.s = _tr_buffer;
+ val->rs.s[val->rs.len] = '\0';
+ break;
+
default:
LM_ERR("unknown subtype %d (cfg line: %d)\n",
subtype, get_cfg_crt_line());
@@ -2535,6 +2561,9 @@ char* tr_parse_string(str* in, trans_t *t)
} else if(name.len==7 && strncasecmp(name.s, "unquote", 7)==0) {
t->subtype = TR_S_UNQUOTE;
goto done;
+ } else if(name.len==9 && strncasecmp(name.s, "unbracket", 9)==0) {
+ t->subtype = TR_S_UNBRACKET;
+ goto done;
}
LM_ERR("unknown transformation: %.*s/%.*s/%d!\n", in->len, in->s,
diff --git a/src/modules/pv/pv_trans.h b/src/modules/pv/pv_trans.h
index ca24a3c108..da2cb87624 100644
--- a/src/modules/pv/pv_trans.h
+++ b/src/modules/pv/pv_trans.h
@@ -41,7 +41,8 @@ enum _tr_s_subtype {
TR_S_STRIP, TR_S_STRIPTAIL, TR_S_PREFIXES, TR_S_PREFIXES_QUOT, TR_S_REPLACE,
TR_S_TIMEFORMAT, TR_S_TRIM, TR_S_RTRIM, TR_S_LTRIM, TR_S_RM, TR_S_STRIPTO,
TR_S_URLENCODEPARAM, TR_S_URLDECODEPARAM, TR_S_NUMERIC, TR_S_ESCAPECSV,
- TR_S_ENCODEBASE58, TR_S_DECODEBASE58, TR_S_COREHASH, TR_S_UNQUOTE
+ TR_S_ENCODEBASE58, TR_S_DECODEBASE58, TR_S_COREHASH, TR_S_UNQUOTE,
+ TR_S_UNBRACKET
};
enum _tr_uri_subtype {
TR_URI_NONE=0, TR_URI_USER, TR_URI_HOST, TR_URI_PASSWD, TR_URI_PORT,