Explorar o código

Merge pull request #737 from dunst0/master

uri_db: added function to check any sip uri
Daniel-Constantin Mierla %!s(int64=9) %!d(string=hai) anos
pai
achega
1cbdb6f6ee

+ 25 - 0
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
  */

+ 6 - 0
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
  */

+ 32 - 0
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>

+ 3 - 0
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}