Module: kamailio Branch: master Commit: 4badb27c07be39fcfaf58686394810ac15e80111 URL: https://github.com/kamailio/kamailio/commit/4badb27c07be39fcfaf58686394810ac...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: GitHub noreply@github.com Date: 2019-01-24T14:47:19+01:00
Merge pull request #1814 from kamailio/lazedo/pv-def
pv: add $def pseudo variable
---
Modified: src/core/cfg.lex Modified: src/core/ppcfg.c Modified: src/modules/pv/pv.c Modified: src/modules/pv/pv_core.c Modified: src/modules/pv/pv_core.h
---
Diff: https://github.com/kamailio/kamailio/commit/4badb27c07be39fcfaf58686394810ac... Patch: https://github.com/kamailio/kamailio/commit/4badb27c07be39fcfaf58686394810ac...
---
diff --git a/src/core/cfg.lex b/src/core/cfg.lex index 6e4d6971e5..9912d111bc 100644 --- a/src/core/cfg.lex +++ b/src/core/cfg.lex @@ -113,7 +113,7 @@ struct sr_yy_fname *next; } *sr_yy_fname_list = 0;
- static str *pp_define_get(int len, const char * text); + str *pp_define_get(int len, const char * text); static int pp_ifdef_type(int pos); static void pp_ifdef_var(int len, const char * text); static void pp_ifdef(); @@ -1856,7 +1856,7 @@ int pp_define_set(int len, char *text) return 0; }
-static str *pp_define_get(int len, const char * text) +str *pp_define_get(int len, const char * text) { str var = {(char *)text, len}; int i; diff --git a/src/core/ppcfg.c b/src/core/ppcfg.c index 1ff3103f52..a06795f760 100644 --- a/src/core/ppcfg.c +++ b/src/core/ppcfg.c @@ -32,6 +32,7 @@ #include "dprint.h"
#include "ppcfg.h" +#include "fmsg.h"
typedef struct _pp_subst_rule { char *indata; @@ -184,7 +185,8 @@ int pp_subst_run(char **data) i = 0; while(pr) { - result=subst_str(*data, 0, + sip_msg_t *fmsg = faked_msg_get_next(); + result=subst_str(*data, fmsg, (struct subst_expr*)pr->ppdata, 0); /* pkg malloc'ed result */ if(result!=NULL) { diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c index 06f831bd97..0df9353606 100644 --- a/src/modules/pv/pv.c +++ b/src/modules/pv/pv.c @@ -189,6 +189,8 @@ static pv_export_t mod_pvs[] = { {{"dd", (sizeof("dd")-1)}, /* */ PVT_OTHER, pv_get_dsturi_attr, 0, 0, 0, pv_init_iname, 1}, + {{"def", (sizeof("env")-1)}, PVT_OTHER, pv_get_def, 0, + pv_parse_def_name, 0, 0, 0}, {{"di", (sizeof("di")-1)}, /* */ PVT_OTHER, pv_get_diversion, 0, 0, 0, pv_init_iname, 1}, diff --git a/src/modules/pv/pv_core.c b/src/modules/pv/pv_core.c index 01cebc8534..2e54253eb4 100644 --- a/src/modules/pv/pv_core.c +++ b/src/modules/pv/pv_core.c @@ -3658,3 +3658,28 @@ int pv_get_env(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) return pv_get_null(msg, param, res); }
+int pv_parse_def_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; + +} + +extern str *pp_define_get(int len, const char * text); + +int pv_get_def(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) +{ + str *val = pp_define_get(param->pvn.u.isname.name.s.len, param->pvn.u.isname.name.s.s); + + if (val) { + return pv_get_strval(msg, param, res, val); + } + return pv_get_null(msg, param, res); +} + diff --git a/src/modules/pv/pv_core.h b/src/modules/pv/pv_core.h index 411f2f8aac..86629e66e0 100644 --- a/src/modules/pv/pv_core.h +++ b/src/modules/pv/pv_core.h @@ -379,5 +379,8 @@ int pv_parse_ksr_attrs_name(pv_spec_p sp, str *in); int pv_get_ksr_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
+int pv_parse_def_name(pv_spec_p sp, str *in); +int pv_get_def(sip_msg_t *msg, pv_param_t *param, pv_value_t *res); + #endif