Skip to content

Commit

Permalink
core: relocated $def(...) and $defn(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Dec 27, 2020
1 parent b1286bd commit d1b982c
Showing 1 changed file with 69 additions and 17 deletions.
86 changes: 69 additions & 17 deletions src/core/pv_core.c
Expand Up @@ -28,27 +28,12 @@

#include "pv_core.h"
#include "pvar.h"
#include "ppcfg.h"
#include "str.h"
#include "mem/pkg.h"

static int pv_get_retcode(struct sip_msg*, pv_param_t*, pv_value_t*);
static int pv_parse_env_name(pv_spec_p sp, str *in);
static int pv_get_env(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);


static pv_export_t core_pvs[] = {
/* return code, various synonims */
{ STR_STATIC_INIT("?"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
{ STR_STATIC_INIT("rc"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
{ STR_STATIC_INIT("retcode"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
{ STR_STATIC_INIT("env"), PVT_OTHER, pv_get_env, 0,
pv_parse_env_name, 0, 0, 0},

{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
};


/** ugly hack to get the return code, needed because the PVs do not know (yet)
/** needed to get the return code, because the PVs do not know (yet)
* about the script context */
extern int _last_returned_code;

Expand Down Expand Up @@ -97,6 +82,73 @@ static int pv_get_env(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
return pv_get_null(msg, param, res);
}

static 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;

}

static 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);
}

static int pv_parse_defn_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_defn(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
{
int n = 0;
str *val = pp_define_get(param->pvn.u.isname.name.s.len,
param->pvn.u.isname.name.s.s);

if (val) {
str2sint(val, &n);
return pv_get_intstrval(msg, param, res, n, val);
} else {
return pv_get_sintval(msg, param, res, n);
}
}

/**
*
*/
static pv_export_t core_pvs[] = {
/* return code, various synonims */
{ STR_STATIC_INIT("?"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
{ STR_STATIC_INIT("rc"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
{ STR_STATIC_INIT("retcode"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
{ STR_STATIC_INIT("env"), PVT_OTHER, pv_get_env, 0,
pv_parse_env_name, 0, 0, 0},
{{"def", (sizeof("def")-1)}, PVT_OTHER, pv_get_def, 0,
pv_parse_def_name, 0, 0, 0},
{{"defn", (sizeof("defn")-1)}, PVT_OTHER, pv_get_defn, 0,
pv_parse_defn_name, 0, 0, 0},

{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
};

/**
* register built-in core pvars.
Expand Down

0 comments on commit d1b982c

Please sign in to comment.