Module: kamailio Branch: master Commit: 3467291d80dba021e8684d203c50fb5a6b546bd8 URL: https://github.com/kamailio/kamailio/commit/3467291d80dba021e8684d203c50fb5a...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2020-06-18T08:33:27+02:00
siputils: new function uri_param_any(param)
- check if r-uri has the param, with or without value
---
Modified: src/modules/siputils/checks.c Modified: src/modules/siputils/checks.h Modified: src/modules/siputils/siputils.c
---
Diff: https://github.com/kamailio/kamailio/commit/3467291d80dba021e8684d203c50fb5a... Patch: https://github.com/kamailio/kamailio/commit/3467291d80dba021e8684d203c50fb5a...
---
diff --git a/src/modules/siputils/checks.c b/src/modules/siputils/checks.c index 0c6b545abb..3e01eb9782 100644 --- a/src/modules/siputils/checks.c +++ b/src/modules/siputils/checks.c @@ -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, ¶ms) < 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 */ diff --git a/src/modules/siputils/checks.h b/src/modules/siputils/checks.h index 202ca47ed2..2a05bdd53d 100644 --- a/src/modules/siputils/checks.h +++ b/src/modules/siputils/checks.h @@ -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 */ diff --git a/src/modules/siputils/siputils.c b/src/modules/siputils/siputils.c index abeeb98eaf..33a3c40a61 100644 --- a/src/modules/siputils/siputils.c +++ b/src/modules/siputils/siputils.c @@ -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, @@ -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,