Skip to content

Commit

Permalink
pv: add $def pseudo variable
Browse files Browse the repository at this point in the history
  • Loading branch information
lazedo committed Jan 18, 2019
1 parent 83a4371 commit 43aeb98
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/modules/pv/pv.c
Expand Up @@ -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},
Expand Down
25 changes: 25 additions & 0 deletions src/modules/pv/pv_core.c
Expand Up @@ -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);
}

3 changes: 3 additions & 0 deletions src/modules/pv/pv_core.h
Expand Up @@ -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

0 comments on commit 43aeb98

Please sign in to comment.