Skip to content

Commit

Permalink
uri_db: added function to check any sip uri
Browse files Browse the repository at this point in the history
- until now only from and to uri can be checked
- so added a function check_uri to check any uri
  • Loading branch information
Rick Barenthin committed Aug 4, 2016
1 parent b99dad6 commit fa2f74c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
25 changes: 25 additions & 0 deletions modules/uri_db/checks.c
Expand Up @@ -29,6 +29,7 @@
#include "../../parser/parse_uri.h"
#include "../../ut.h" /* Handy utilities */
#include "../../lib/srdb1/db.h" /* Database API */
#include "../../mod_fix.h"
#include "uri_db.h"
#include "checks.h"

Expand Down Expand Up @@ -172,6 +173,30 @@ int check_from(struct sip_msg* _m, char* _s1, char* _s2)
}


/*
*
*/
int check_uri(struct sip_msg* msg, char* uri, char* _s2)
{
str suri;
struct sip_uri parsed_uri;

if (fixup_get_svalue(msg, (gparam_t*)uri, &suri) != 0)
{
ERR("cannot get uri value\n");
return -1;
}

if (parse_uri(suri.s, suri.len, &parsed_uri) != 0)
{
ERR("Error while parsing URI\n");
return -1;
}

return check_username(msg, &parsed_uri);
}


/*
* Check if uri belongs to a local user
*/
Expand Down
6 changes: 6 additions & 0 deletions modules/uri_db/checks.h
Expand Up @@ -42,6 +42,12 @@ int check_to(struct sip_msg* _msg, char* _str1, char* _str2);
int check_from(struct sip_msg* _msg, char* _str1, char* _str2);


/*
*
*/
int check_uri(struct sip_msg* msg, char* uri, char* _s2);


/*
* Check if uri belongs to a local user, contributed by Juha Heinanen
*/
Expand Down
32 changes: 32 additions & 0 deletions modules/uri_db/doc/uri_db_admin.xml
Expand Up @@ -253,6 +253,38 @@ if (check_from()) {
</example>
</section>

<section id="uri_db.f.check_uri">
<title>
<function moreinfo="none">check_uri(uri)</function>
</title>
<para>
Check the username from the given uri against &uri; table (if use_uri_table is set) or
digest credentials (no DB backend required).
</para>
<para>Description of parameters:</para>
<itemizedlist>
<listitem>
<para><emphasis>uri</emphasis> Has to be a valid SIP URI,
used to extract the username from. The parameter can be
a static or dynamic (with variables) string.
</para>
</listitem>
</itemizedlist>
<para>
This function can be used from REQUEST_ROUTE.
</para>
<example>
<title><function>check_uri</function> usage</title>
<programlisting format="linespecific">
...
if (check_uri("$var(uri)")) {
...
};
...
</programlisting>
</example>
</section>

<section id="uri_db.f.does_uri_exist">
<title>
<function moreinfo="none">does_uri_exist()</function>
Expand Down
3 changes: 3 additions & 0 deletions modules/uri_db/uri_db.c
Expand Up @@ -30,6 +30,7 @@
#include "../../ut.h"
#include "../../error.h"
#include "../../mem/mem.h"
#include "../../mod_fix.h"
#include "uri_db.h"
#include "checks.h"

Expand Down Expand Up @@ -78,6 +79,8 @@ static cmd_export_t cmds[] = {
REQUEST_ROUTE},
{"check_from", (cmd_function)check_from, 0, 0, 0,
REQUEST_ROUTE},
{"check_uri", (cmd_function)check_uri, 1, fixup_spve_null, 0,
REQUEST_ROUTE},
{"does_uri_exist", (cmd_function)does_uri_exist, 0, 0, fixup_exist,
REQUEST_ROUTE|LOCAL_ROUTE},
{0, 0, 0, 0, 0, 0}
Expand Down

0 comments on commit fa2f74c

Please sign in to comment.