Module: kamailio Branch: master Commit: 72699b5d85bc1ca8b487749798ed8e93622d1686 URL: https://github.com/kamailio/kamailio/commit/72699b5d85bc1ca8b487749798ed8e93...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2025-06-17T19:42:24+02:00
core: added $defv(name) variable
- return the unquoted value of the define 'name' - unquotes in both cases of single and double quotes - if no quotes enclose the defined value, then the value is returned as it is
---
Modified: src/core/pv_core.c
---
Diff: https://github.com/kamailio/kamailio/commit/72699b5d85bc1ca8b487749798ed8e93... Patch: https://github.com/kamailio/kamailio/commit/72699b5d85bc1ca8b487749798ed8e93...
---
diff --git a/src/core/pv_core.c b/src/core/pv_core.c index 87bf4cc91d3..f577c4ba3a9 100644 --- a/src/core/pv_core.c +++ b/src/core/pv_core.c @@ -28,6 +28,7 @@
#include "pv_core.h" #include "pvar.h" +#include "pvapi.h" #include "ppcfg.h" #include "str.h" #include "mem/pkg.h" @@ -168,6 +169,49 @@ static int pv_get_defn(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) } }
+static int pv_parse_defv_name(pv_spec_p sp, str *in) +{ + if(in == NULL || in->s == NULL || sp == NULL) { + LM_ERR("INVALID DEF NAME\n"); + return -1; + } + sp->pvp.pvn.type = PV_NAME_INTSTR; + sp->pvp.pvn.u.isname.type = AVP_NAME_STR; + sp->pvp.pvn.u.isname.name.s = *in; + return 0; +} + +static int pv_get_defv(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) +{ + str *val = NULL; + str ret = STR_NULL; + + val = pp_define_get( + param->pvn.u.isname.name.s.len, param->pvn.u.isname.name.s.s); + + if(!val) { + return pv_get_null(msg, param, res); + } + + if(val->len < 2) { + return pv_get_strval(msg, param, res, val); + } + if((val->s[0] == '"' && val->s[val->len - 1] == '"') + || (val->s[0] == ''' && val->s[val->len - 1] == ''')) { + ret.s = pv_get_buffer(); + ret.len = pv_get_buffer_size(); + if(ret.len < val->len) { + return pv_get_null(msg, param, res); + } + memcpy(ret.s, val->s + 1, val->len - 2); + ret.len = val->len - 2; + ret.s[ret.len] = '\0'; + return pv_get_strval(msg, param, res, &ret); + } else { + return pv_get_strval(msg, param, res, val); + } +} + /* clang-format off */ /** * @@ -185,6 +229,8 @@ static pv_export_t core_pvs[] = { 0, 0}, {STR_STATIC_INIT("defn"), PVT_OTHER, pv_get_defn, 0, pv_parse_defn_name, 0, 0, 0}, + {STR_STATIC_INIT("defv"), PVT_OTHER, pv_get_defv, 0, pv_parse_defv_name, + 0, 0, 0},
{{0, 0}, 0, 0, 0, 0, 0, 0, 0} };