From fa2f74c26bac5ec3b951e342924cf6b41c2bdfd7 Mon Sep 17 00:00:00 2001 From: Rick Barenthin Date: Thu, 4 Aug 2016 09:50:08 +0200 Subject: [PATCH] uri_db: added function to check any sip uri - until now only from and to uri can be checked - so added a function check_uri to check any uri --- modules/uri_db/checks.c | 25 ++++++++++++++++++++++ modules/uri_db/checks.h | 6 ++++++ modules/uri_db/doc/uri_db_admin.xml | 32 +++++++++++++++++++++++++++++ modules/uri_db/uri_db.c | 3 +++ 4 files changed, 66 insertions(+) diff --git a/modules/uri_db/checks.c b/modules/uri_db/checks.c index 07ea8d80771..794bb338b60 100644 --- a/modules/uri_db/checks.c +++ b/modules/uri_db/checks.c @@ -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" @@ -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 */ diff --git a/modules/uri_db/checks.h b/modules/uri_db/checks.h index 36b9ec38cef..b671013a0e4 100644 --- a/modules/uri_db/checks.h +++ b/modules/uri_db/checks.h @@ -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 */ diff --git a/modules/uri_db/doc/uri_db_admin.xml b/modules/uri_db/doc/uri_db_admin.xml index 2dc0e43f5ca..ab513b5f4ec 100644 --- a/modules/uri_db/doc/uri_db_admin.xml +++ b/modules/uri_db/doc/uri_db_admin.xml @@ -253,6 +253,38 @@ if (check_from()) { +
+ + <function moreinfo="none">check_uri(uri)</function> + + + Check the username from the given uri against &uri; table (if use_uri_table is set) or + digest credentials (no DB backend required). + + Description of parameters: + + + uri Has to be a valid SIP URI, + used to extract the username from. The parameter can be + a static or dynamic (with variables) string. + + + + + This function can be used from REQUEST_ROUTE. + + + <function>check_uri</function> usage + +... +if (check_uri("$var(uri)")) { + ... +}; +... + + +
+
<function moreinfo="none">does_uri_exist()</function> diff --git a/modules/uri_db/uri_db.c b/modules/uri_db/uri_db.c index c2b9bb4f48b..3f120e45ad3 100644 --- a/modules/uri_db/uri_db.c +++ b/modules/uri_db/uri_db.c @@ -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" @@ -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}