Skip to content

Commit

Permalink
topology_hiding: port script functions to new param interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu authored and liviuchircu committed Apr 4, 2019
1 parent ab57519 commit b1833c2
Showing 1 changed file with 36 additions and 81 deletions.
117 changes: 36 additions & 81 deletions modules/topology_hiding/topology_hiding.c
Expand Up @@ -43,24 +43,19 @@ str th_contact_encode_param = str_init("thinfo");

static int mod_init(void);
static void mod_destroy(void);
static int fixup_mmode(void **param, int param_no);
static int fixup_topo_hiding(void **param, int param_no);
int w_topology_hiding1(struct sip_msg *req,char *param);
int w_topology_hiding(struct sip_msg *req);
int w_topology_hiding_match(struct sip_msg *req, char *seq_match_mode);
static int fixup_mmode(void **param);
int w_topology_hiding(struct sip_msg *req, str *flags_s);
int w_topology_hiding_match(struct sip_msg *req, void *seq_match_mode_val);
static int pv_topo_callee_callid(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);

/* Exported functions */
static cmd_export_t cmds[]={
{"topology_hiding",(cmd_function)w_topology_hiding,0,NULL,
0, REQUEST_ROUTE},
{"topology_hiding",(cmd_function)w_topology_hiding1,1,fixup_topo_hiding,
0, REQUEST_ROUTE},
{"topology_hiding_match",(cmd_function)w_topology_hiding_match,0,NULL,
0, REQUEST_ROUTE},
{"topology_hiding_match",(cmd_function)w_topology_hiding_match,1,fixup_mmode,
0, REQUEST_ROUTE},
{0,0,0,0,0,0}
{"topology_hiding",(cmd_function)w_topology_hiding, {
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, {0,0,0}},
REQUEST_ROUTE},
{"topology_hiding_match",(cmd_function)w_topology_hiding_match, {
{CMD_PARAM_STR|CMD_PARAM_OPT, fixup_mmode, 0}, {0,0,0}},
REQUEST_ROUTE},
{0,0,{{0,0,0}},0}
};

/* Exported parameters */
Expand Down Expand Up @@ -184,92 +179,52 @@ static void mod_destroy(void)
return;
}

static int fixup_mmode(void **param, int param_no)
static int fixup_mmode(void **param)
{
int rc;
gparam_p gp;

rc = fixup_sgp(param);
if (rc != 0)
return rc;

gp = (gparam_p)*param;
if (gp->type != GPARAM_TYPE_STR)
return 0;

gp->v.sval.len = dlg_match_mode_str_to_int(&gp->v.sval);
*param = (void*)(unsigned long)dlg_match_mode_str_to_int((str*)*param);

return 0;
}

static int fixup_topo_hiding(void **param, int param_no)
{
return fixup_sgp(param);
}

int w_topology_hiding(struct sip_msg *req)
{
return topology_hiding(req,0);
}

int w_topology_hiding1(struct sip_msg *req,char *param)
int w_topology_hiding(struct sip_msg *req, str *flags_s)
{
str res = {0,0};
int flags=0;
char *p;

if (fixup_get_svalue(req, (gparam_p)param, &res) !=0)
{
LM_ERR("no create dialog flags\n");
return -1;
}

for (p=res.s;p<res.s+res.len;p++)
{
switch (*p)
if (flags_s)
for (p=flags_s->s;p<flags_s->s+flags_s->len;p++)
{
case 'U':
flags |= TOPOH_KEEP_USER;
LM_DBG("Will preserve usernames while doing topo hiding\n");
break;
case 'C':
flags |= TOPOH_HIDE_CALLID;
LM_DBG("Will change callid while doing topo hiding\n");
break;
case 'D':
flags |= TOPOH_DID_IN_USER;
LM_DBG("Will push DID into contact username\n");
break;
default:
LM_DBG("unknown topology_hiding flag : [%c] . Skipping\n",*p);
switch (*p)
{
case 'U':
flags |= TOPOH_KEEP_USER;
LM_DBG("Will preserve usernames while doing topo hiding\n");
break;
case 'C':
flags |= TOPOH_HIDE_CALLID;
LM_DBG("Will change callid while doing topo hiding\n");
break;
case 'D':
flags |= TOPOH_DID_IN_USER;
LM_DBG("Will push DID into contact username\n");
break;
default:
LM_DBG("unknown topology_hiding flag : [%c] . Skipping\n",*p);
}
}
}

return topology_hiding(req,flags);
}

int w_topology_hiding_match(struct sip_msg *req, char *seq_match_mode_gp)
int w_topology_hiding_match(struct sip_msg *req, void *seq_match_mode_val)
{
str res = STR_NULL;
gparam_p mm_gp = (gparam_p)seq_match_mode_gp;
int mm;

/* copy-paste from w_match_dialog() */
if (!seq_match_mode_gp) {
if (!seq_match_mode_val)
mm = SEQ_MATCH_DEFAULT;
} else {
if (mm_gp->type == GPARAM_TYPE_STR) {
mm = mm_gp->v.sval.len;
} else {
if (fixup_get_svalue(req, mm_gp, &res) != 0) {
LM_ERR("failed to extract matching mode pv! "
"using 'DID_FALLBACK'\n");
mm = SEQ_MATCH_FALLBACK;
} else {
mm = dlg_match_mode_str_to_int(&res);
}
}
}
else
mm = (int)seq_match_mode_val;

if (!dlg_api.match_dialog || dlg_api.match_dialog(req, mm) < 0)
return topology_hiding_match(req);
Expand Down

0 comments on commit b1833c2

Please sign in to comment.