Module: kamailio
Branch: master
Commit: 1cbdb6f6ee77ee319f39d1cadd629b8ff5525c72
URL:
https://github.com/kamailio/kamailio/commit/1cbdb6f6ee77ee319f39d1cadd629b8…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: GitHub <noreply(a)github.com>
Date: 2016-08-08T08:49:03+02:00
Merge pull request #737 from dunst0/master
uri_db: added function to check any sip uri
---
Modified: modules/uri_db/checks.c
Modified: modules/uri_db/checks.h
Modified: modules/uri_db/doc/uri_db_admin.xml
Modified: modules/uri_db/uri_db.c
---
Diff:
https://github.com/kamailio/kamailio/commit/1cbdb6f6ee77ee319f39d1cadd629b8…
Patch:
https://github.com/kamailio/kamailio/commit/1cbdb6f6ee77ee319f39d1cadd629b8…
---
diff --git a/modules/uri_db/checks.c b/modules/uri_db/checks.c
index 07ea8d8..794bb33 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"
@@ -173,6 +174,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
*/
int does_uri_exist(struct sip_msg* _msg, char* _s1, char* _s2)
diff --git a/modules/uri_db/checks.h b/modules/uri_db/checks.h
index 36b9ec3..b671013 100644
--- a/modules/uri_db/checks.h
+++ b/modules/uri_db/checks.h
@@ -43,6 +43,12 @@ 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
*/
int does_uri_exist(struct sip_msg* _msg, char* _table, char* _s2);
diff --git a/modules/uri_db/doc/uri_db_admin.xml b/modules/uri_db/doc/uri_db_admin.xml
index 2dc0e43..ab513b5 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()) {
</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>
diff --git a/modules/uri_db/uri_db.c b/modules/uri_db/uri_db.c
index c2b9bb4..3f120e4 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}