Module: kamailio
Branch: master
Commit: 3e5633a1d2a243a4ac9773efc361513720e04f68
URL:
https://github.com/kamailio/kamailio/commit/3e5633a1d2a243a4ac9773efc361513…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-01-28T10:48:34+01:00
pv: new transformation {s.rmsw} - remove whitespaces from value
- removes all occurences of ' ', '\t', '\r', '\n'
---
Modified: src/modules/pv/pv_trans.c
Modified: src/modules/pv/pv_trans.h
---
Diff:
https://github.com/kamailio/kamailio/commit/3e5633a1d2a243a4ac9773efc361513…
Patch:
https://github.com/kamailio/kamailio/commit/3e5633a1d2a243a4ac9773efc361513…
---
diff --git a/src/modules/pv/pv_trans.c b/src/modules/pv/pv_trans.c
index 354a51795c..5f20a22ba0 100644
--- a/src/modules/pv/pv_trans.c
+++ b/src/modules/pv/pv_trans.c
@@ -295,6 +295,25 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
val->flags = PV_TYPE_INT|PV_VAL_INT|PV_VAL_STR;
break;
+ case TR_S_RMWS:
+ if(!(val->flags&PV_VAL_STR))
+ val->rs.s = int2str(val->ri, &val->rs.len);
+ if(val->rs.len >= TR_BUFFER_SIZE - 1)
+ return -1;
+ j = 0;
+ for(i=0; i < val->rs.len; i++) {
+ if(val->rs.s[i] != ' ' && val->rs.s[i] != '\t'
+ && val->rs.s[i] != '\r' && val->rs.s[i] !=
'\n') {
+ _tr_buffer[j] = val->rs.s[i];
+ j++;
+ }
+ }
+ _tr_buffer[j] = '\0';
+ val->flags = PV_VAL_STR;
+ val->ri = 0;
+ val->rs.s = _tr_buffer;
+ val->rs.len = j;
+ break;
case TR_S_MD5:
if(!(val->flags&PV_VAL_STR))
val->rs.s = int2str(val->ri, &val->rs.len);
@@ -2322,6 +2341,9 @@ char* tr_parse_string(str* in, trans_t *t)
} else if(name.len==3 && strncasecmp(name.s, "md5", 3)==0) {
t->subtype = TR_S_MD5;
goto done;
+ } else if(name.len==4 && strncasecmp(name.s, "rmws", 4)==0) {
+ t->subtype = TR_S_RMWS;
+ goto done;
} else if(name.len==6 && strncasecmp(name.s, "sha256", 6)==0) {
t->subtype = TR_S_SHA256;
goto done;
diff --git a/src/modules/pv/pv_trans.h b/src/modules/pv/pv_trans.h
index 88cb9eb321..d663db76ed 100644
--- a/src/modules/pv/pv_trans.h
+++ b/src/modules/pv/pv_trans.h
@@ -42,7 +42,8 @@ enum _tr_s_subtype {
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_UNBRACKET, TR_S_COUNT, TR_S_ENCODEBASE64T, TR_S_DECODEBASE64T
+ TR_S_UNBRACKET, TR_S_COUNT, TR_S_ENCODEBASE64T, TR_S_DECODEBASE64T,
+ TR_S_RMWS
};
enum _tr_uri_subtype {
TR_URI_NONE=0, TR_URI_USER, TR_URI_HOST, TR_URI_PASSWD, TR_URI_PORT,