Skip to content

Commit

Permalink
dispatcher: new variable $dsg(key) to get attributes of a dispatcher …
Browse files Browse the repository at this point in the history
…group
  • Loading branch information
miconda committed Sep 4, 2023
1 parent 4bbeaad commit ff323e8
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions src/modules/dispatcher/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ static int w_ds_reload(struct sip_msg* msg, char*, char*);

static int w_ds_is_active(sip_msg_t *msg, char *pset, char *p2);
static int w_ds_is_active_uri(sip_msg_t *msg, char *pset, char *puri);
static int w_ds_dsg_fetch(sip_msg_t *msg, char *pset, char *p2);

static int fixup_ds_is_from_list(void** param, int param_no);
static int fixup_ds_list_exist(void** param,int param_no);
Expand All @@ -194,10 +195,15 @@ static int ds_warn_fixup(void** param, int param_no);

static int pv_get_dsv(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
static int pv_parse_dsv(pv_spec_p sp, str *in);
static int pv_get_dsg(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
static int pv_parse_dsg(pv_spec_p sp, str *in);
static void ds_dsg_fetch(int dg);

static pv_export_t mod_pvs[] = {
{ {"dsv", (sizeof("dsv")-1)}, PVT_OTHER, pv_get_dsv, 0,
pv_parse_dsv, 0, 0, 0 },
{ {"dsg", (sizeof("dsg")-1)}, PVT_OTHER, pv_get_dsg, 0,
pv_parse_dsg, 0, 0, 0 },

{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
};
Expand Down Expand Up @@ -255,6 +261,8 @@ static cmd_export_t cmds[]={
0, 0, 0},
{"ds_reload", (cmd_function)w_ds_reload, 0,
0, 0, ANY_ROUTE},
{"ds_dsg_fetch", (cmd_function)w_ds_dsg_fetch, 1,
fixup_igp_null, fixup_free_igp_null, ANY_ROUTE},
{0,0,0,0,0,0}
};

Expand Down Expand Up @@ -1349,6 +1357,106 @@ static int pv_parse_dsv(pv_spec_p sp, str *in)
return -1;
}

/**
*
*/
static int _pv_dsg_fetch = 1;

/**
*
*/
static void ds_dsg_fetch(int dg)
{
_pv_dsg_fetch = dg;
}

/**
*
*/
static int w_ds_dsg_fetch(sip_msg_t *msg, char *pset, char *p2)
{
int set;

if(fixup_get_ivalue(msg, (gparam_p)pset, &set) != 0) {
LM_ERR("cannot get set id param value\n");
return -1;
}
ds_dsg_fetch(set);

return 1;
}

/**
*
*/
static int pv_get_dsg(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
{
ds_set_t *dsg;
int count = 0;
int active = 0;
int inactive = 0;

if(param == NULL) {
return -1;
}
dsg = ds_list_lookup(_pv_dsg_fetch);

if(dsg == NULL) {
return pv_get_null(msg, param, res);
}

switch(param->pvn.u.isname.name.n) {
case 0: /* count */
return pv_get_sintval(msg, param, res, count);
case 1: /* active */
return pv_get_sintval(msg, param, res, active);
case 2: /* inactive */
return pv_get_sintval(msg, param, res, inactive);
default:
return pv_get_null(msg, param, res);
}
}

/**
*
*/
static int pv_parse_dsg(pv_spec_p sp, str *in)
{
if(sp == NULL || in == NULL || in->len <= 0)
return -1;

switch(in->len) {
case 5:
if(strncmp(in->s, "count", 5) == 0)
sp->pvp.pvn.u.isname.name.n = 0;
else
goto error;
break;
case 6:
if(strncmp(in->s, "active", 6) == 0)
sp->pvp.pvn.u.isname.name.n = 1;
else
goto error;
break;
case 8:
if(strncmp(in->s, "inactive", 8) == 0)
sp->pvp.pvn.u.isname.name.n = 2;
else
goto error;
break;
default:
goto error;
}
sp->pvp.pvn.type = PV_NAME_INTSTR;
sp->pvp.pvn.u.isname.type = 0;

return 0;

error:
LM_ERR("unknown PV key: %.*s\n", in->len, in->s);
return -1;
}

/* KEMI wrappers */
/**
*
Expand Down

0 comments on commit ff323e8

Please sign in to comment.