Skip to content

Commit

Permalink
uri module: remove parameter with given key script function
Browse files Browse the repository at this point in the history
  • Loading branch information
ionutrazvanionita committed Sep 22, 2015
1 parent fa854c4 commit 8a745d9
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 19 deletions.
33 changes: 25 additions & 8 deletions modules/uri/README
Expand Up @@ -59,8 +59,9 @@ Irina-Maria Stanescu
1.4.9. uri_param(param)
1.4.10. uri_param(param,value)
1.4.11. add_uri_param(param)
1.4.12. tel2sip()
1.4.13. is_uri_user_e164(pseudo-variable)
1.4.12. del_uri_param(param)
1.4.13. tel2sip()
1.4.14. is_uri_user_e164(pseudo-variable)

List of Examples

Expand All @@ -85,8 +86,9 @@ Irina-Maria Stanescu
1.19. uri_param usage
1.20. uri_param usage
1.21. add_uri_param usage
1.22. tel2sip usage
1.23. is_uri_user_e164 usage
1.22. add_uri_param usage
1.23. tel2sip usage
1.24. is_uri_user_e164 usage

Chapter 1. Admin Guide

Expand Down Expand Up @@ -423,27 +425,42 @@ if (uri_param("param1","value1")) {
add_uri_param("nat=yes");
...

1.4.12. tel2sip()
1.4.12. del_uri_param(param)

Delete a parameter from the RURI being given the
key(key=value);

Meaning of the parameters is as follows:
* param - key of the parameter to be removed/

This function can be used from REQUEST_ROUTE.

Example 1.22. add_uri_param usage
...
del_uri_param("name");
...

1.4.13. tel2sip()

Converts RURI, if it is tel URI, to SIP URI. Returns true, only
if conversion succeeded or if no conversion was needed (like
RURI was not tel URI.

This function can be used from REQUEST_ROUTE.

Example 1.22. tel2sip usage
Example 1.23. tel2sip usage
...
tel2sip();
...

1.4.13. is_uri_user_e164(pseudo-variable)
1.4.14. is_uri_user_e164(pseudo-variable)

Checks if userpart of URI stored in pseudo variable is E164
number.

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.

Example 1.23. is_uri_user_e164 usage
Example 1.24. is_uri_user_e164 usage
...
if (is_uri_user_e164("$fu")) { # Check From header URI user part
...
Expand Down
89 changes: 89 additions & 0 deletions modules/uri/checks.c
Expand Up @@ -176,6 +176,95 @@ int uri_param_2(struct sip_msg* _msg, char* _param, char* _value)



/*
* Removes a given parameter from Request URI
*/
int del_uri_param(struct sip_msg* _msg, char* _param, char* _s)
{
str *param;
str params;

char *tok_end;
struct sip_uri *parsed_uri;

str param_tok, key;
str new_uri, old_uri;

int begin_len, end_len;

param = (str*)_param;

if (param->len == 0) {
return 1;
}

if (parse_sip_msg_uri(_msg) < 0) {
LM_ERR("ruri parsing failed\n");
return -1;
}

parsed_uri = &(_msg->parsed_uri);

params = parsed_uri->params;
if (0 == params.s || 0 == params.len) {
LM_WARN("RURI contains no params to delete! Returning...\n");
return 0;
}

while (params.len) {
tok_end = q_memchr(params.s, ';', params.len);

param_tok.s = params.s;
if (tok_end == NULL) {
param_tok.len = params.len;
params.len = 0;
} else {
param_tok.len = tok_end - params.s;
params.len -= (param_tok.len + 1/*';' char*/);
params.s += (param_tok.len + 1);
}

tok_end = q_memchr(param_tok.s, '=', param_tok.len);
if (tok_end == NULL) {
key = param_tok;
} else {
key.s = param_tok.s;
key.len = tok_end - param_tok.s;
}

if (!str_strcmp(param, &key)) {
/* found the param to remove */
old_uri = *GET_RURI(_msg);
new_uri.len = old_uri.len - param_tok.len;
new_uri.s = pkg_malloc(new_uri.len);
if (!new_uri.s) {
LM_ERR("no more pkg mem\n");
return -1;
}

begin_len = param_tok.s - old_uri.s - 1/*remove also the ';'
before the param */;
memcpy(new_uri.s, old_uri.s, begin_len);

end_len = old_uri.len - ((param_tok.s + param_tok.len) - old_uri.s);
if (end_len)
memcpy(new_uri.s + begin_len, param_tok.s + param_tok.len, end_len+1);

if (set_ruri(_msg, &new_uri) == 1) {
pkg_free(new_uri.s);
return 0;
} else {
pkg_free(new_uri.s);
return -1;
}
}
}

LM_DBG("requested key not found in RURI\n");

return 0;
}

/*
* Adds a new parameter to Request URI
*/
Expand Down
4 changes: 4 additions & 0 deletions modules/uri/checks.h
Expand Up @@ -55,6 +55,10 @@ int uri_param_1(struct sip_msg* _msg, char* _param, char* _str2);
*/
int uri_param_2(struct sip_msg* _msg, char* _param, char* _value);

/*
* Removes a given parameter from Request URI
*/
int del_uri_param(struct sip_msg* _msg, char* _param, char* _s);

/*
* Adds a new parameter to Request URI
Expand Down
49 changes: 38 additions & 11 deletions modules/uri/doc/uri_admin.xml
@@ -1,9 +1,9 @@
<!-- Module User's Guide -->

<chapter>

<title>&adminguide;</title>

<section>
<title>Overview</title>
<para>Various checks related to &sip; &uri;.</para>
Expand Down Expand Up @@ -44,7 +44,7 @@
</para>
</section>
</section>

<section>
<title>Exported Parameters</title>
<section>
Expand Down Expand Up @@ -81,8 +81,8 @@ modparam("uri", "service_type", 11)
</programlisting>
</example>
</section>


<section>
<title><varname>use_sip_uri_host</varname> (integer)</title>
<para>
Expand Down Expand Up @@ -238,11 +238,11 @@ modparam("uri", "use_uri_table", 1)
<title><varname>use_domain</varname> (integer)</title>
<para>
Specify if the domain part of the URI should be used to identify the
users (along with username). This is useful in multi domain setups, a
users (along with username). This is useful in multi domain setups, a
non-zero value means true.
</para>
<para>This parameter is only evaluated for calls to <quote>does_uri_exist</quote>,
all other functions checks the digest username and realm against the
all other functions checks the digest username and realm against the
given username, if the <quote>uri</quote> table is used.
</para>
<para>
Expand Down Expand Up @@ -318,7 +318,7 @@ if (db_check_from()) {
</para>
<para>
Matching is done against the &uri; table (if
<emphasis role='bold'>use_uri_table</emphasis> is set)
<emphasis role='bold'>use_uri_table</emphasis> is set)
or the <emphasis>subscriber</emphasis> table.
</para>
<para>
Expand All @@ -335,7 +335,7 @@ if (db_does_uri_exist()) {
</programlisting>
</example>
</section>

<section>
<title>
<function moreinfo="none">db_get_auth_id(string, var, var)</function>
Expand Down Expand Up @@ -564,6 +564,33 @@ add_uri_param("nat=yes");
</programlisting>
</example>
</section>
<section>
<title>
<function moreinfo="none">del_uri_param(param)</function>
</title>
<para>
Delete a parameter from the RURI being given the key(key=value);
</para>
<para>Meaning of the parameters is as follows:</para>
<itemizedlist>
<listitem>
<para><emphasis>param</emphasis> - key of the parameter to be removed/
</para>
</listitem>
</itemizedlist>
<para>
This function can be used from REQUEST_ROUTE.
</para>
<example>
<title><function>add_uri_param</function> usage</title>
<programlisting format="linespecific">
...
del_uri_param("name");
...
</programlisting>
</example>
</section>

<section>
<title>
<function moreinfo="none">tel2sip()</function>
Expand Down Expand Up @@ -611,8 +638,8 @@ if (is_uri_user_e164("$avp(uri)") {
</programlisting>
</example>
</section>


</section>
</chapter>

3 changes: 3 additions & 0 deletions modules/uri/uri_mod.c
Expand Up @@ -155,6 +155,9 @@ static cmd_export_t cmds[] = {
{"add_uri_param", (cmd_function)add_uri_param, 1,
fixup_str_null, 0,
REQUEST_ROUTE},
{"del_uri_param", (cmd_function)del_uri_param, 1,
fixup_str_null, 0,
REQUEST_ROUTE},
{"tel2sip", (cmd_function)tel2sip, 0, 0, 0,
REQUEST_ROUTE},
{"is_uri_user_e164", (cmd_function)is_uri_user_e164, 1,
Expand Down

0 comments on commit 8a745d9

Please sign in to comment.