Module: kamailio
Branch: master
Commit: 5b1177df2193968a3efc26bcf07eba80a59304e7
URL:
https://github.com/kamailio/kamailio/commit/5b1177df2193968a3efc26bcf07eba8…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-12-07T09:27:43+01:00
pv: added {val.jsonqe} - quoted json value
---
Modified: src/modules/pv/pv_trans.c
Modified: src/modules/pv/pv_trans.h
---
Diff:
https://github.com/kamailio/kamailio/commit/5b1177df2193968a3efc26bcf07eba8…
Patch:
https://github.com/kamailio/kamailio/commit/5b1177df2193968a3efc26bcf07eba8…
---
diff --git a/src/modules/pv/pv_trans.c b/src/modules/pv/pv_trans.c
index e221cb300e..5d7e0d32b3 100644
--- a/src/modules/pv/pv_trans.c
+++ b/src/modules/pv/pv_trans.c
@@ -2590,6 +2590,41 @@ int tr_eval_val(struct sip_msg *msg, tr_param_t *tp, int subtype,
val->rs.len = sv.len;
}
break;
+ case TR_VAL_JSONQE:
+ if(val->flags&PV_VAL_NULL) {
+ val->ri = 0;
+ tr_set_crt_buffer();
+ val->rs.s = _tr_buffer;
+ val->rs.s[0] = '"';
+ val->rs.s[1] = '"';
+ val->rs.s[2] = '\0';
+ val->rs.len = 2;
+ val->flags = PV_VAL_STR;
+ } else if(val->flags&PV_TYPE_INT) {
+ break;
+ } else if(val->flags&PV_VAL_STR) {
+ ksr_str_json_escape(&val->rs, &sv, &emode);
+ if(sv.s==NULL) {
+ LM_ERR("failed to escape the value\n");
+ return -1;
+ }
+ if(emode==0) {
+ /* no escape was needed */
+ return 0;
+ }
+ if(sv.len >= TR_BUFFER_SIZE - 3) {
+ LM_ERR("escaped value is too long\n");
+ return -1;
+ }
+ tr_set_crt_buffer();
+ _tr_buffer[0] = '"';
+ memcpy(_tr_buffer + 1, sv.s, sv.len);
+ _tr_buffer[sv.len + 1] = '"';
+ _tr_buffer[sv.len + 2] = '\0';
+ val->rs.s = _tr_buffer;
+ val->rs.len = sv.len + 2;
+ }
+ break;
default:
LM_ERR("unknown subtype %d\n",
@@ -3847,6 +3882,9 @@ char* tr_parse_val(str* in, trans_t *t)
} else if(name.len==4 && strncasecmp(name.s, "json", 4)==0) {
t->subtype = TR_VAL_JSON;
goto done;
+ } else if(name.len==6 && strncasecmp(name.s, "jsonqe", 6)==0) {
+ t->subtype = TR_VAL_JSONQE;
+ goto done;
}
diff --git a/src/modules/pv/pv_trans.h b/src/modules/pv/pv_trans.h
index 329f09a8a2..ff5cbebff8 100644
--- a/src/modules/pv/pv_trans.h
+++ b/src/modules/pv/pv_trans.h
@@ -73,7 +73,7 @@ enum _tr_urialias_subtype {
};
enum _tr_val_subtype {
- TR_VAL_NONE=0, TR_VAL_N0, TR_VAL_NE, TR_VAL_JSON
+ TR_VAL_NONE=0, TR_VAL_N0, TR_VAL_NE, TR_VAL_JSON, TR_VAL_JSONQE
};