[sr-dev] git:master:3a7f6c18: pv: added {s.rafter, x} and {s.rbefore, x}

Daniel-Constantin Mierla miconda at gmail.com
Fri Jun 25 09:54:24 CEST 2021


Module: kamailio
Branch: master
Commit: 3a7f6c18810cb307332fbf061a248252996b0464
URL: https://github.com/kamailio/kamailio/commit/3a7f6c18810cb307332fbf061a248252996b0464

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-06-25T09:51:10+02:00

pv: added {s.rafter,x} and {s.rbefore,x}

- similar to {s.after,x} and {s.before,x}, but searches from end of the
value

---

Modified: src/modules/pv/pv_trans.c
Modified: src/modules/pv/pv_trans.h

---

Diff:  https://github.com/kamailio/kamailio/commit/3a7f6c18810cb307332fbf061a248252996b0464.diff
Patch: https://github.com/kamailio/kamailio/commit/3a7f6c18810cb307332fbf061a248252996b0464.patch

---

diff --git a/src/modules/pv/pv_trans.c b/src/modules/pv/pv_trans.c
index 98cce7caa8..6a026cc9ae 100644
--- a/src/modules/pv/pv_trans.c
+++ b/src/modules/pv/pv_trans.c
@@ -1340,6 +1340,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
 			break;
 
 		case TR_S_BEFORE:
+		case TR_S_RBEFORE:
 			if(tp==NULL)
 			{
 				LM_ERR("invalid parameters (cfg line: %d)\n",
@@ -1366,11 +1367,20 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
 				}
 				st = v.rs;
 			}
-			for(i=0; i<val->rs.len; i++) {
-				if(val->rs.s[i]==st.s[0]) {
-					break;
+			if(subtype==TR_S_BEFORE) {
+				for(i=0; i<val->rs.len; i++) {
+					if(val->rs.s[i]==st.s[0]) {
+						break;
+					}
+				}
+			} else {
+				for(i=val->rs.len-1; i>=0; i++) {
+					if(val->rs.s[i]==st.s[0]) {
+						break;
+					}
 				}
 			}
+
 			if(i==0) {
 				_tr_buffer[0] = '\0';
 				val->rs.len = 0;
@@ -1384,6 +1394,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
 			break;
 
 		case TR_S_AFTER:
+		case TR_S_RAFTER:
 			if(tp==NULL)
 			{
 				LM_ERR("invalid parameters (cfg line: %d)\n",
@@ -1410,9 +1421,17 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
 				}
 				st = v.rs;
 			}
-			for(i=0; i<val->rs.len; i++) {
-				if(val->rs.s[i]==st.s[0]) {
-					break;
+			if(subtype==TR_S_AFTER) {
+				for(i=0; i<val->rs.len; i++) {
+					if(val->rs.s[i]==st.s[0]) {
+						break;
+					}
+				}
+			} else {
+				for(i=val->rs.len-1; i>=0; i++) {
+					if(val->rs.s[i]==st.s[0]) {
+						break;
+					}
 				}
 			}
 			if(i>=val->rs.len-1) {
@@ -3012,6 +3031,46 @@ char* tr_parse_string(str* in, trans_t *t)
 			goto error;
 		}
 		goto done;
+	} else if(name.len==7 && strncasecmp(name.s, "rbefore", 7)==0) {
+		t->subtype = TR_S_RBEFORE;
+		if(*p!=TR_PARAM_MARKER)
+		{
+			LM_ERR("invalid rbefore transformation: %.*s!\n",
+					in->len, in->s);
+			goto error;
+		}
+		p++;
+		_tr_parse_sparamx(p, p0, tp, spec, ps, in, s, 1);
+		t->params = tp;
+		tp = 0;
+		while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
+		if(*p!=TR_RBRACKET)
+		{
+			LM_ERR("invalid rbefore transformation: %.*s!!\n",
+					in->len, in->s);
+			goto error;
+		}
+		goto done;
+	} else if(name.len==6 && strncasecmp(name.s, "rafter", 6)==0) {
+		t->subtype = TR_S_RAFTER;
+		if(*p!=TR_PARAM_MARKER)
+		{
+			LM_ERR("invalid rafter transformation: %.*s!\n",
+					in->len, in->s);
+			goto error;
+		}
+		p++;
+		_tr_parse_sparamx(p, p0, tp, spec, ps, in, s, 1);
+		t->params = tp;
+		tp = 0;
+		while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
+		if(*p!=TR_RBRACKET)
+		{
+			LM_ERR("invalid rafter 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/src/modules/pv/pv_trans.h b/src/modules/pv/pv_trans.h
index 4b8e1ff12f..9d474cf08b 100644
--- a/src/modules/pv/pv_trans.h
+++ b/src/modules/pv/pv_trans.h
@@ -45,7 +45,7 @@ enum _tr_s_subtype {
 	TR_S_UNBRACKET, TR_S_COUNT, TR_S_ENCODEBASE64T, TR_S_DECODEBASE64T,
 	TR_S_ENCODEBASE64URL, TR_S_DECODEBASE64URL,
 	TR_S_ENCODEBASE64URLT, TR_S_DECODEBASE64URLT, TR_S_RMWS, TR_S_BEFORE,
-	TR_S_AFTER
+	TR_S_AFTER, TR_S_RBEFORE, TR_S_RAFTER
 };
 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