Module: sip-router
Branch: master
Commit: 5b1f81c72b40a0f7609aac32a8ce6e7325a70396
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5b1f81c…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Wed Sep 26 09:17:00 2012 +0200
pv: new transformation {s.stripto,c}
- remove the prefix until meeting 'c'
- "abcdef"{s.stripto,d} => "def"
- the char can be given in a pv
---
modules_k/pv/pv_trans.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++
modules_k/pv/pv_trans.h | 2 +-
2 files changed, 62 insertions(+), 1 deletions(-)
diff --git a/modules_k/pv/pv_trans.c b/modules_k/pv/pv_trans.c
index d127e76..995d25a 100644
--- a/modules_k/pv/pv_trans.c
+++ b/modules_k/pv/pv_trans.c
@@ -487,6 +487,47 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
val->rs.len -= i;
break;
+
+ case TR_S_STRIPTO:
+ if(tp==NULL)
+ {
+ LM_ERR("stripto invalid parameters\n");
+ return -1;
+ }
+ if(!(val->flags&PV_VAL_STR))
+ val->rs.s = int2str(val->ri, &val->rs.len);
+
+ if(tp->type==TR_PARAM_STRING)
+ {
+ st = tp->v.s;
+ } else {
+ if(pv_get_spec_value(msg, (pv_spec_p)tp->v.data, &v)!=0
+ || (!(v.flags&PV_VAL_STR)) || v.rs.len<=0)
+ {
+ LM_ERR("stripto cannot get p1\n");
+ return -1;
+ }
+ st = v.rs;
+ }
+
+ val->flags = PV_VAL_STR;
+ val->ri = 0;
+ for(i=0; i<val->rs.len; i++)
+ {
+ if(val->rs.s[i] == st.s[0])
+ break;
+ }
+ if(i>=val->rs.len)
+ {
+ _tr_buffer[0] = '\0';
+ val->rs.s = _tr_buffer;
+ val->rs.len = 0;
+ break;
+ }
+ val->rs.s += i;
+ val->rs.len -= i;
+ break;
+
case TR_S_PREFIXES:
case TR_S_PREFIXES_QUOT:
if(!(val->flags&PV_VAL_STR))
@@ -1874,6 +1915,26 @@ char* tr_parse_string(str* in, trans_t *t)
goto error;
}
goto done;
+ } else if(name.len==7 && strncasecmp(name.s, "stripto", 7)==0) {
+ t->subtype = TR_S_STRIPTO;
+ if(*p!=TR_PARAM_MARKER)
+ {
+ LM_ERR("invalid stripto transformation: %.*s!\n",
+ in->len, in->s);
+ goto error;
+ }
+ p++;
+ _tr_parse_sparam(p, p0, tp, spec, ps, in, s);
+ t->params = tp;
+ tp = 0;
+ while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
+ if(*p!=TR_RBRACKET)
+ {
+ LM_ERR("invalid strip transformation: %.*s!!\n",
+ in->len, in->s);
+ goto error;
+ }
+ goto done;
} else if(name.len==5 && strncasecmp(name.s, "ftime", 5)==0) {
t->subtype = TR_S_TIMEFORMAT;
if(*p!=TR_PARAM_MARKER)
diff --git a/modules_k/pv/pv_trans.h b/modules_k/pv/pv_trans.h
index c660102..a34eca2 100644
--- a/modules_k/pv/pv_trans.h
+++ b/modules_k/pv/pv_trans.h
@@ -40,7 +40,7 @@ enum _tr_s_subtype {
TR_S_ESCAPECOMMON, TR_S_UNESCAPECOMMON, TR_S_ESCAPEUSER, TR_S_UNESCAPEUSER,
TR_S_ESCAPEPARAM, TR_S_UNESCAPEPARAM, TR_S_TOLOWER, TR_S_TOUPPER,
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_TIMEFORMAT, TR_S_TRIM, TR_S_RTRIM, TR_S_LTRIM, TR_S_RM, TR_S_STRIPTO
};
enum _tr_uri_subtype {
TR_URI_NONE=0, TR_URI_USER, TR_URI_HOST, TR_URI_PASSWD, TR_URI_PORT,