[sr-dev] git:master: pv: added s.rm transformation

Daniel-Constantin Mierla miconda at gmail.com
Thu Dec 15 19:00:27 CET 2011


Module: sip-router
Branch: master
Commit: c37efcf217148e9c1623a96c3cd2b54d52364078
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c37efcf217148e9c1623a96c3cd2b54d52364078

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Thu Dec 15 17:54:21 2011 +0100

pv: added s.rm transformation

- {s.rm,match} - remove occurrences of 'match' from PV
- 'match' can be static string or variable

---

 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 139275b..932e9c2 100644
--- a/modules_k/pv/pv_trans.c
+++ b/modules_k/pv/pv_trans.c
@@ -628,6 +628,47 @@ 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_RM:
+			if(tp==NULL)
+			{
+				LM_ERR("invalid parameters\n");
+				return -1;
+			}
+			if(!(val->flags&PV_VAL_STR))
+				val->rs.s = int2str(val->ri, &val->rs.len);
+			if(val->rs.len>TR_BUFFER_SIZE-2)
+				return -1;
+			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("cannot get parameter value\n");
+					return -1;
+				}
+				st = v.rs;
+			}
+			val->flags = PV_VAL_STR;
+			val->ri = 0;
+
+			i = 0;
+			j = 0;
+			max = val->rs.len - st.len;
+			while (i < val->rs.len && j < TR_BUFFER_SIZE) {
+				if (i <= max && val->rs.s[i] == st.s[0]
+						&& strncmp(val->rs.s+i, st.s, st.len) == 0) {
+					i += st.len;
+				} else {
+					_tr_buffer[j++] = val->rs.s[i++];
+				}
+			}
+			val->rs.s = _tr_buffer;
+			val->rs.s[j] = '\0';
+			val->rs.len = j;
+			break;
+
 		default:
 			LM_ERR("unknown subtype %d\n",
 					subtype);
@@ -1625,6 +1666,26 @@ char* tr_parse_string(str* in, trans_t *t)
 	} else if(name.len==5 && strncasecmp(name.s, "ltrim", 5)==0) {
 		t->subtype = TR_S_LTRIM;
 		goto done;
+	} else if(name.len==2 && strncasecmp(name.s, "rm", 2)==0) {
+		t->subtype = TR_S_RM;
+		if(*p!=TR_PARAM_MARKER)
+		{
+			LM_ERR("invalid ftime 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 ftime transformation: %.*s!!\n",
+				in->len, in->s);
+			goto error;
+		}
+		goto done;
 	}
 
 	LM_ERR("unknown transformation: %.*s/%.*s/%d!\n", in->len, in->s,
diff --git a/modules_k/pv/pv_trans.h b/modules_k/pv/pv_trans.h
index 24f4bc2..391084c 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_TIMEFORMAT, TR_S_TRIM, TR_S_RTRIM, TR_S_LTRIM, TR_S_RM
 };
 enum _tr_uri_subtype {
 	TR_URI_NONE=0, TR_URI_USER, TR_URI_HOST, TR_URI_PASSWD, TR_URI_PORT,




More information about the sr-dev mailing list