Skip to content

Commit

Permalink
siputils: added is_alphanum(v) function
Browse files Browse the repository at this point in the history
- helper function to check if a string value contains only digits or
  alphabetic characters
  • Loading branch information
miconda committed Mar 3, 2017
1 parent 980c861 commit 41c4319
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 16 deletions.
27 changes: 27 additions & 0 deletions src/modules/siputils/checks.c
Expand Up @@ -806,3 +806,30 @@ int is_numeric(sip_msg_t *msg, char *_sp, char* _s2)

return 1;
}

/*
* Check if the parameter contains alphanumeric characters
*/
int is_alphanum(sip_msg_t *msg, char *_sp, char* _s2)
{
str tval = {0, 0};
int i;

if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0)
{
LM_ERR("cannot get parameter value\n");
return -1;
}
if(tval.len<=0)
return -2;

i = 0;
for(; i<tval.len; i++) {
if( !((tval.s[i]>='0' && tval.s[i]<='9')
|| (tval.s[i]>='A' && tval.s[i]<='Z')
|| (tval.s[i]>='z' && tval.s[i]<='z')) )
return -3;
}

return 1;
}
5 changes: 5 additions & 0 deletions src/modules/siputils/checks.h
Expand Up @@ -124,4 +124,9 @@ int is_tel_number(sip_msg_t *msg, char *_sp, char* _s2);
*/
int is_numeric(sip_msg_t *msg, char *_sp, char* _s2);

/*
* Check if the parameter contains alphanumeric characters
*/
int is_alphanum(sip_msg_t *msg, char *_sp, char* _s2);

#endif /* CHECKS_H */
52 changes: 38 additions & 14 deletions src/modules/siputils/doc/siputils_admin.xml
Expand Up @@ -10,9 +10,9 @@
<!-- Module User's Guide -->

<chapter>

<title>&adminguide;</title>

<section>
<title>Overview</title>
<para>
Expand All @@ -26,16 +26,16 @@
So its necessary to drop the 183 in this cases and send a 180 instead.
</para>
<para>
This module also provides a function to answer OPTIONS requests which
are directed to the server itself. This means an OPTIONS request
which has the address of the server in the request URI, and no
username in the URI. The request will be answered with a 200 OK
This module also provides a function to answer OPTIONS requests which
are directed to the server itself. This means an OPTIONS request
which has the address of the server in the request URI, and no
username in the URI. The request will be answered with a 200 OK
with the capabilities of the server.
</para>
<para>
To answer OPTIONS request directed to your server is the easiest
way for is-alive-tests on the SIP (application) layer from remote
(similar to ICMP echo requests, also known as <quote>ping</quote>,
way for is-alive-tests on the SIP (application) layer from remote
(similar to ICMP echo requests, also known as <quote>ping</quote>,
on the network layer).
</para>
</section>
Expand All @@ -57,7 +57,7 @@
<section>
<title>External Libraries or Applications</title>
<para>
The following libraries or applications must be installed before
The following libraries or applications must be installed before
running &kamailio; with this module loaded:
<itemizedlist>
<listitem>
Expand All @@ -69,7 +69,7 @@
</para>
</section>
</section>

<section>
<title>Parameters</title>
<section>
Expand Down Expand Up @@ -640,7 +640,8 @@ if (is_tel_number("+24242424") {
<function moreinfo="none">is_numeric(tval)</function>
</title>
<para>
Checks if the parameter value consists solely of decimal digits. The parameter can include variables.
Checks if the parameter value consists solely of decimal digits.
The parameter can include variables.
</para>
<para>
This function can be used from ANY_ROUTE.
Expand All @@ -649,7 +650,30 @@ if (is_tel_number("+24242424") {
<title><function>is_numeric</function> usage</title>
<programlisting format="linespecific">
...
if (is_numeric($rU)) { # Test if R-URI user consists of decimal digits
if (is_numeric("$rU")) { # Test if R-URI user consists of decimal digits
...
}
...
</programlisting>
</example>
</section>

<section id="siputils.f.is_alphanum">
<title>
<function moreinfo="none">is_alphanum(tval)</function>
</title>
<para>
Checks if the parameter value consists solely of decimal digits
or alphabetic ASCII characters. The parameter can include variables.
</para>
<para>
This function can be used from ANY_ROUTE.
</para>
<example>
<title><function>is_alphanum</function> usage</title>
<programlisting format="linespecific">
...
if (is_alphanum("$rU")) {
...
}
...
Expand All @@ -662,13 +686,13 @@ if (is_numeric($rU)) { # Test if R-URI user consists of decimal digits
<function moreinfo="none">encode_contact(encoding_prefix,hostpart)</function>
</title>
<para>
This function will encode uri-s inside Contact header in the following
This function will encode uri-s inside Contact header in the following
manner
sip:username:password@ip:port;transport=protocol goes
sip:encoding_prefix*username*ip*port*protocol@hostpart.
</para>
<para>
* is the default separator and can be changed by setting the contact_flds_separator
* is the default separator and can be changed by setting the contact_flds_separator
module parameter.
</para>
<para>
Expand Down
6 changes: 4 additions & 2 deletions src/modules/siputils/siputils.c
Expand Up @@ -171,14 +171,16 @@ static cmd_export_t cmds[]={
0, ANY_ROUTE},
{"is_gruu", (cmd_function)w_is_gruu, 1, fixup_spve_null,
0, ANY_ROUTE},
{"is_supported", (cmd_function)w_is_supported, 1, fixup_option,
{"is_supported", (cmd_function)w_is_supported, 1, fixup_option,
0, ANY_ROUTE},
{"is_first_hop", (cmd_function)w_is_first_hop, 0, 0,
{"is_first_hop", (cmd_function)w_is_first_hop, 0, 0,
0, ANY_ROUTE},
{"is_tel_number", (cmd_function)is_tel_number, 1, fixup_spve_null,
0, ANY_ROUTE},
{"is_numeric", (cmd_function)is_numeric, 1, fixup_spve_null,
0, ANY_ROUTE},
{"is_alphanum", (cmd_function)is_alphanum, 1, fixup_spve_null,
0, ANY_ROUTE},
{"sip_p_charging_vector", (cmd_function)sip_handle_pcv, 1, fixup_spve_null,
fixup_free_spve_null, ANY_ROUTE},
{0,0,0,0,0,0}
Expand Down

0 comments on commit 41c4319

Please sign in to comment.