Module: kamailio Branch: master Commit: ef0bb31d689f7cf8e7ac750dc4d3257daa176b4f URL: https://github.com/kamailio/kamailio/commit/ef0bb31d689f7cf8e7ac750dc4d3257daa176b4f
Author: Daniel-Constantin Mierla <[email protected]> Committer: Daniel-Constantin Mierla <[email protected]> Date: 2025-12-10T10:28:23+01:00 json: new trasformation {json.parsex,path} - the separator for the fields in the path is the first character --- Modified: src/modules/json/json_trans.c Modified: src/modules/json/json_trans.h --- Diff: https://github.com/kamailio/kamailio/commit/ef0bb31d689f7cf8e7ac750dc4d3257daa176b4f.diff Patch: https://github.com/kamailio/kamailio/commit/ef0bb31d689f7cf8e7ac750dc4d3257daa176b4f.patch --- diff --git a/src/modules/json/json_trans.c b/src/modules/json/json_trans.c index fbae4b307ef..a5c60529b11 100644 --- a/src/modules/json/json_trans.c +++ b/src/modules/json/json_trans.c @@ -226,6 +226,7 @@ int json_tr_eval( pv_value_t *pv; pv_value_t v; str v2 = {0, 0}; + char sep = '.'; if(val == NULL || (val->flags & PV_VAL_NULL)) return -1; @@ -262,6 +263,7 @@ int json_tr_eval( break; case TR_JSON_PARSE: + case TR_JSON_PARSEX: if(!(val->flags & PV_VAL_STR)) return -1; @@ -290,6 +292,10 @@ int json_tr_eval( } sv = v.rs; } + if(sv.s == NULL || sv.len < 1) { + LM_ERR("invalid value for: %.*s\n", tp->v.s.len, tp->v.s.s); + return -1; + } pv = json_alloc_pv_value(); if(pv == NULL) { @@ -297,7 +303,12 @@ int json_tr_eval( return -1; } - if(tr_json_get_field_ex(&val->rs, &sv, '.', pv) != 1) { + if(subtype == TR_JSON_PARSEX) { + sep = sv.s[0]; + sv.s++; + sv.len--; + } + if(tr_json_get_field_ex(&val->rs, &sv, sep, pv) != 1) { LM_ERR("error getting json\n"); json_destroy_pv_value(pv); return -1; @@ -429,6 +440,23 @@ char *json_tr_parse(str *in, trans_t *t) goto error; } goto done; + } else if(name.len == 6 && strncasecmp(name.s, "parsex", 6) == 0) { + t->subtype = TR_JSON_PARSEX; + if(*p != TR_PARAM_MARKER) { + LM_ERR("invalid json transformation: %.*s!\n", in->len, in->s); + goto error; + } + p++; + _json_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 json transformation: %.*s!!\n", in->len, in->s); + goto error; + } + goto done; } LM_ERR("unknown JSON transformation: %.*s/%.*s/%d!\n", in->len, in->s, diff --git a/src/modules/json/json_trans.h b/src/modules/json/json_trans.h index 65a443752ab..1a6ca4a45d9 100644 --- a/src/modules/json/json_trans.h +++ b/src/modules/json/json_trans.h @@ -40,7 +40,8 @@ enum _json_tr_subtype { TR_JSON_NONE = 0, TR_JSON_ENCODE, - TR_JSON_PARSE + TR_JSON_PARSE, + TR_JSON_PARSEX }; char *json_tr_parse(str *in, trans_t *tr); _______________________________________________ Kamailio - Development Mailing List -- [email protected] To unsubscribe send an email to [email protected] Important: keep the mailing list in the recipients, do not reply only to the sender!
