[sr-dev] git:master:533e8f5c: pv: new transformation {s.unquote}

Daniel-Constantin Mierla miconda at gmail.com
Tue Sep 4 09:48:59 CEST 2018


Module: kamailio
Branch: master
Commit: 533e8f5cca940652f8507a272b076d51161432bd
URL: https://github.com/kamailio/kamailio/commit/533e8f5cca940652f8507a272b076d51161432bd

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2018-09-04T09:46:01+02:00

pv: new transformation {s.unquote}

- return the value without surrounding double/single quotes (" or ')

---

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

---

Diff:  https://github.com/kamailio/kamailio/commit/533e8f5cca940652f8507a272b076d51161432bd.diff
Patch: https://github.com/kamailio/kamailio/commit/533e8f5cca940652f8507a272b076d51161432bd.patch

---

diff --git a/src/modules/pv/pv_trans.c b/src/modules/pv/pv_trans.c
index f93a5e3d6f..30c6379a7f 100644
--- a/src/modules/pv/pv_trans.c
+++ b/src/modules/pv/pv_trans.c
@@ -1156,6 +1156,30 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
 			val->ri = 0;
 			break;
 
+		case TR_S_UNQUOTE:
+			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[0] == '\'')) {
+				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());
@@ -2508,6 +2532,9 @@ char* tr_parse_string(str* in, trans_t *t)
 	} else if(name.len==15 && strncasecmp(name.s, "urldecode.param", 15)==0) {
 		t->subtype = TR_S_URLDECODEPARAM;
 		goto done;
+	} else if(name.len==7 && strncasecmp(name.s, "unquote", 7)==0) {
+		t->subtype = TR_S_UNQUOTE;
+		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 a4bc0759e8..ca24a3c108 100644
--- a/src/modules/pv/pv_trans.h
+++ b/src/modules/pv/pv_trans.h
@@ -41,7 +41,7 @@ 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_ENCODEBASE58, TR_S_DECODEBASE58, TR_S_COREHASH, TR_S_UNQUOTE
 };
 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