Skip to content

Commit

Permalink
siputils: new function uri_param_any(param)
Browse files Browse the repository at this point in the history
- check if r-uri has the param, with or without value
  • Loading branch information
miconda committed Jun 18, 2020
1 parent b31c885 commit 3467291
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/modules/siputils/checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,73 @@ int ki_uri_param(sip_msg_t *_msg, str *sparam)
return ki_uri_param_value(_msg, sparam, NULL);
}

/*
* Check if param with or without value exists in Request URI
*/
int ki_uri_param_any(sip_msg_t *msg, str *sparam)
{
str t;
str ouri;
sip_uri_t puri;
param_hooks_t hooks;
param_t* params, *pit;

if((msg->new_uri.s == NULL) || (msg->new_uri.len == 0)) {
ouri = msg->first_line.u.request.uri;
if(ouri.s == NULL) {
LM_ERR("r-uri not found\n");
return -1;
}
} else {
ouri = msg->new_uri;
}

if (parse_uri(ouri.s, ouri.len, &puri) < 0) {
LM_ERR("failed to parse r-uri [%.*s]\n", ouri.len, ouri.s);
return -1;
}
if(puri.sip_params.len>0) {
t = puri.sip_params;
} else if(puri.params.len>0) {
t = puri.params;
} else {
LM_DBG("no uri params [%.*s]\n", ouri.len, ouri.s);
return -1;
}

if (parse_params(&t, CLASS_ANY, &hooks, &params) < 0) {
LM_ERR("ruri parameter parsing failed\n");
return -1;
}

for (pit = params; pit; pit = pit->next) {
if ((pit->name.len == sparam->len)
&& (strncasecmp(pit->name.s, sparam->s, sparam->len) == 0)) {
break;
}
}
if(pit==NULL) {
free_params(params);
return -1;
}

free_params(params);
return 1;
}

/*
* Find if Request URI has a given parameter with or without value
*/
int w_uri_param_any(struct sip_msg* _msg, char* _param, char* _str2)
{
str sparam;
if(fixup_get_svalue(_msg, (gparam_t*)_param, &sparam)<0) {
LM_ERR("failed to get parameter\n");
return -1;
}
return ki_uri_param_any(_msg, &sparam);
}

/*
* Adds a new parameter to Request URI
*/
Expand Down
4 changes: 4 additions & 0 deletions src/modules/siputils/checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,8 @@ int ki_uri_param_rm(sip_msg_t *msg, str *sparam);

int w_uri_param_rm(struct sip_msg* _msg, char* _param, char* _str2);

int ki_uri_param_any(sip_msg_t *msg, str *sparam);

int w_uri_param_any(struct sip_msg* _msg, char* _param, char* _str2);

#endif /* CHECKS_H */
7 changes: 7 additions & 0 deletions src/modules/siputils/siputils.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ static cmd_export_t cmds[]={
0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE},
{"uri_param", (cmd_function)uri_param_2, 2, fixup_spve_spve,
0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE},
{"uri_param_any", (cmd_function)w_uri_param_any, 1, fixup_spve_null,
0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE},
{"add_uri_param", (cmd_function)add_uri_param, 1, fixup_str_null,
0, REQUEST_ROUTE},
{"get_uri_param", (cmd_function)get_uri_param, 2, fixup_get_uri_param,
Expand Down Expand Up @@ -589,6 +591,11 @@ static sr_kemi_t sr_kemi_siputils_exports[] = {
{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("siputils"), str_init("uri_param_any"),
SR_KEMIP_INT, ki_uri_param_any,
{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("siputils"), str_init("uri_param_rm"),
SR_KEMIP_INT, ki_uri_param_rm,
{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
Expand Down

0 comments on commit 3467291

Please sign in to comment.