[sr-dev] git:master: prefix_route: new parameter to control the exit from config

Daniel-Constantin Mierla miconda at gmail.com
Sun Sep 2 13:39:53 CEST 2012


Module: sip-router
Branch: master
Commit: dfc98801110554f92aeaa80594e01cad16c9dcd1
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=dfc98801110554f92aeaa80594e01cad16c9dcd1

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Sun Sep  2 13:29:18 2012 +0200

prefix_route: new parameter to control the exit from config

- 'exit' controls if prefix_route() triggers cfg exit or returns true
  upon matching a prefix. Default is 1 (on) for backward compatibility
- prefix_route() takes an optional parameter that can be used to match
  the prefix instead of r-uri username

---

 modules/prefix_route/README            |   37 +++++++++++++++++++++++++-------
 modules/prefix_route/doc/functions.xml |   13 +++++++++-
 modules/prefix_route/doc/params.xml    |   20 +++++++++++++++++
 modules/prefix_route/prefix_route.c    |   29 ++++++++++++++++++-------
 4 files changed, 81 insertions(+), 18 deletions(-)

diff --git a/modules/prefix_route/README b/modules/prefix_route/README
index 92a9024..0aa4780 100644
--- a/modules/prefix_route/README
+++ b/modules/prefix_route/README
@@ -4,9 +4,9 @@ Alfred E. Heggestad
 
    Telio Telecom
 
-   Copyright © 2007 Alfred E. Heggestad
+   Copyright © 2007 Alfred E. Heggestad
 
-   Copyright © 2008 Telio Telecom AS
+   Copyright © 2008 Telio Telecom AS
      __________________________________________________________________
 
    1.1. Overview
@@ -14,10 +14,11 @@ Alfred E. Heggestad
 
         1.2.1. db_url (string)
         1.2.2. db_table (string)
+        1.2.3. exit (int)
 
    1.3. Functions
 
-        1.3.1. prefix_route()
+        1.3.1. prefix_route([user])
 
    1.4. RPC Commands
 
@@ -63,20 +64,40 @@ modparam("prefix_route", "db_url", "mysql://ser:pass@db_host/ser")
 modparam("prefix_route", "db_table", "new_prefix_route")
 ...
 
+1.2.3. exit (int)
+
+   If set, exit the execution of the configuration file when a route block
+   is executed upon matching a prefix. Otherwise return 1 (true).
+
+   Default value is 1 (on).
+
+   Example 3. Setting exit parameter
+...
+modparam("prefix_route", "exit", 0)
+...
+
 1.3. Functions
 
-1.3.1. prefix_route()
+1.3.1. prefix_route([user])
 
    This function tries to find a route from the user part of the request
-   URI. If a route is found, it will be used for further processing.
-   Otherwise the function will return false.
+   URI (if no parameter is provided), or from the value of the parameter.
+   The parameter can contain config variables.
 
-   Example 3. prefix_route() usage
+   If a route is found, it will be used for further processing. Otherwise
+   the function will return false.
+
+   Example 4. prefix_route() usage
 ...
   if (!prefix_route()) {
       xlog("L_ERR", "prefix_route(): no matching routes\n");
   }
 ...
+  if (!prefix_route("$fU")) {
+      xlog("L_ERR", "prefix_route(): no matching routes\n");
+  }
+
+...
 
 1.4. RPC Commands
 
@@ -96,7 +117,7 @@ modparam("prefix_route", "db_table", "new_prefix_route")
      * route - varchar(64) - Route name
      * comment - varchar(64) - Free-form comment
 
-   Example 4. Sample data
+   Example 5. Sample data
 ...
    +--------+-------+---------------+
    | prefix | route | comment       |
diff --git a/modules/prefix_route/doc/functions.xml b/modules/prefix_route/doc/functions.xml
index fd71954..34f86a7 100644
--- a/modules/prefix_route/doc/functions.xml
+++ b/modules/prefix_route/doc/functions.xml
@@ -6,9 +6,13 @@
     <title>Functions</title>
 
 	<section id="prefixroute.prefix_route">
-		<title><function>prefix_route()</function></title>
+		<title><function>prefix_route([user])</function></title>
+		<para>
+		This function tries to find a route from the user part of the request URI
+		(if no parameter is provided), or from the value of the parameter. The
+		parameter can contain config variables.
+		</para>
 		<para>
-		This function tries to find a route from the user part of the request URI.
 		If a route is found, it will be used for further processing. Otherwise the
 		function will return false.
 		</para>
@@ -20,6 +24,11 @@
       xlog("L_ERR", "prefix_route(): no matching routes\n");
   }
 ...
+  if (!prefix_route("$fU")) {
+      xlog("L_ERR", "prefix_route(): no matching routes\n");
+  }
+
+...
 			</programlisting>
 		</example>
 	</section>
diff --git a/modules/prefix_route/doc/params.xml b/modules/prefix_route/doc/params.xml
index 80bb4e0..b584ac3 100644
--- a/modules/prefix_route/doc/params.xml
+++ b/modules/prefix_route/doc/params.xml
@@ -41,4 +41,24 @@ modparam("prefix_route", "db_table", "new_prefix_route")
 		</example>
 	</section>
 
+	<section id="prefixroute.exit">
+		<title><varname>exit</varname> (int)</title>
+		<para>
+			If set, exit the execution of the configuration file
+			when a route block is executed upon matching a prefix.
+			Otherwise return 1 (true).
+		</para>
+		<para>
+			Default value is 1 (on).
+		</para>
+		<example>
+			<title>Setting exit parameter</title>
+			<programlisting>
+...
+modparam("prefix_route", "exit", 0)
+...
+			</programlisting>
+		</example>
+	</section>
+
 </section>
diff --git a/modules/prefix_route/prefix_route.c b/modules/prefix_route/prefix_route.c
index be52f9b..7ae8383 100644
--- a/modules/prefix_route/prefix_route.c
+++ b/modules/prefix_route/prefix_route.c
@@ -32,6 +32,7 @@
 #include "../../lib/srdb2/db.h"
 #include "../../rpc.h"
 #include "../../sr_module.h"
+#include "../../mod_fix.h"
 #include "../../mem/mem.h"
 #include "../../data_lump_rpl.h"
 #include "../../parser/parse_uri.h"
@@ -49,7 +50,7 @@ MODULE_VERSION
 /* Modules parameters */
 static char *db_url   = DEFAULT_DB_URL;
 static char *db_table = "prefix_route";
-
+static int prefix_route_exit = 1;
 
 static int add_route(struct tree_item *root, const char *prefix,
 		     const char *route)
@@ -265,11 +266,19 @@ static int prefix_route(struct sip_msg *msg, char *p1, char *p2)
 	(void)p2;
 
 	/* Get request URI */
-	err = get_username(msg, &user);
-	if (0 != err) {
-		LOG(L_ERR, "prefix_route: could not get username in"
-		    " Request URI (%d)\n", err);
-		return err;
+	if(p1==NULL) {
+		err = get_username(msg, &user);
+		if (0 != err) {
+			LOG(L_ERR, "prefix_route: could not get username in"
+			    " Request URI (%d)\n", err);
+			return err;
+		}
+	} else {
+		if(fixup_get_svalue(msg, (gparam_t*)p1, &user)<0)
+		{
+			LOG(L_ERR, "could not get username in parameter\n");
+			return -1;
+		}
 	}
 
 	route = tree_route_get(&user);
@@ -286,7 +295,7 @@ static int prefix_route(struct sip_msg *msg, char *p1, char *p2)
 	}
 
 	/* Success */
-	return 0;
+	return (prefix_route_exit)?0:1;
 }
 
 
@@ -294,7 +303,10 @@ static int prefix_route(struct sip_msg *msg, char *p1, char *p2)
  * Exported functions
  */
 static cmd_export_t cmds[] = {
-	{"prefix_route", prefix_route, 0, 0, REQUEST_ROUTE},
+	{"prefix_route", prefix_route, 0, 0,
+		REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE},
+	{"prefix_route", prefix_route, 1, fixup_spve_null,
+		ANY_ROUTE},
 	{0,              0,            0, 0, 0            }
 };
 
@@ -304,6 +316,7 @@ static cmd_export_t cmds[] = {
 static param_export_t params[] = {
 	{"db_url",       STR_PARAM, &db_url  },
 	{"db_table",     STR_PARAM, &db_table},
+	{"exit",         INT_PARAM, &prefix_route_exit},
 	{0,              0,         0        }
 };
 




More information about the sr-dev mailing list