[sr-dev] git:master: diversion(k): added optional uri parameter to add_diversion()

Daniel-Constantin Mierla miconda at gmail.com
Fri Mar 16 18:38:20 CET 2012


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Fri Mar 16 18:36:37 2012 +0100

diversion(k): added optional uri parameter to add_diversion()

- both parameters can be now PVs

---

 modules_k/diversion/README                  |   24 ++++++++++------
 modules_k/diversion/diversion.c             |   41 ++++++++++++++++++--------
 modules_k/diversion/doc/diversion_admin.xml |   16 ++++++++--
 3 files changed, 55 insertions(+), 26 deletions(-)

diff --git a/modules_k/diversion/README b/modules_k/diversion/README
index 81111fa..ff9d75d 100644
--- a/modules_k/diversion/README
+++ b/modules_k/diversion/README
@@ -8,7 +8,7 @@ Edited by
 
 Jan Janak
 
-   Copyright © 2004 FhG FOKUS
+   Copyright © 2004 FhG FOKUS
      __________________________________________________________________
 
    Table of Contents
@@ -27,7 +27,7 @@ Jan Janak
 
         4. Functions
 
-              4.1. add_diversion(reason)
+              4.1. add_diversion(reason [, uri])
 
         5. Diversion Example
 
@@ -54,7 +54,7 @@ Chapter 1. Admin Guide
 
    4. Functions
 
-        4.1. add_diversion(reason)
+        4.1. add_diversion(reason [, uri])
 
    5. Diversion Example
 
@@ -95,31 +95,37 @@ Warning
    the parameter to specify additional parameters to be added to the
    header field, see the example.
 
-   Default value is “” (empty string).
+   Default value is "" (empty string).
 
    Example 1.1. suffix usage
 modparam("diversion", "suffix", ";privacy=full")
 
 4. Functions
 
-   4.1. add_diversion(reason)
+   4.1. add_diversion(reason [, uri])
 
-4.1. add_diversion(reason)
+4.1. add_diversion(reason [, uri])
 
    The function adds a new diversion header field before any other
    existing Diversion header field in the message (the newly added
    Diversion header field will become the topmost Diversion header field).
-   The inbound (without any modifications done by the proxy server)
-   Request-URI will be used as the Diversion URI.
+   If 'uri' parameter is missing, the inbound (without any modifications
+   done by the proxy server) Request-URI will be used as the Diversion
+   URI.
 
    Meaning of the parameters is as follows:
      * reason - The reason string to be added as the reason parameter
+     * uri - The URI to be set in Diversion header
 
-   This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
+   The parameters can contain pseudo-variables.
+
+   This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
+   BRANCH_ROUTE.
 
    Example 1.2. add_diversion usage
 ...
 add_diversion("user-busy");
+add_diversion("user-busy", "$ru");
 ...
 
 5. Diversion Example
diff --git a/modules_k/diversion/diversion.c b/modules_k/diversion/diversion.c
index 06f3c43..46a51ae 100644
--- a/modules_k/diversion/diversion.c
+++ b/modules_k/diversion/diversion.c
@@ -48,7 +48,7 @@ MODULE_VERSION
 
 str suffix = {"", 0};
 
-int add_diversion(struct sip_msg* msg, char* r, char* s);
+int add_diversion(struct sip_msg* msg, char* r, char* u);
 
 /*
  * Module initialization function prototype
@@ -60,8 +60,10 @@ static int mod_init(void);
  * Exported functions
  */
 static cmd_export_t cmds[] = {
-	{"add_diversion",    (cmd_function)add_diversion,    1, fixup_str_null,
-		0, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
+	{"add_diversion",    (cmd_function)add_diversion,    1, fixup_spve_null,
+		0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
+	{"add_diversion",    (cmd_function)add_diversion,    2, fixup_spve_spve,
+		0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
 	{0, 0, 0, 0, 0, 0}
 };
 
@@ -136,18 +138,31 @@ static inline int add_diversion_helper(struct sip_msg* msg, str* s)
 }
 
 
-int add_diversion(struct sip_msg* msg, char* r, char* s)
+int add_diversion(struct sip_msg* msg, char* r, char* u)
 {
 	str div_hf;
 	char *at;
-	str* uri;
-	str* reason;
+	str uri;
+	str reason;
+
+	if(fixup_get_svalue(msg, (gparam_t*)r, &reason)<0)
+	{
+		LM_ERR("cannot get the script\n");
+		return -1;
+	}
 
-	reason = (str*)r;
 
-	uri = &msg->first_line.u.request.uri;
+	if(u==NULL) {
+		uri = msg->first_line.u.request.uri;
+	} else {
+		if(fixup_get_svalue(msg, (gparam_t*)u, &uri)<0)
+		{
+			LM_ERR("cannot get the uri parameter\n");
+			return -1;
+		}
+	}
 
-	div_hf.len = DIVERSION_PREFIX_LEN + uri->len + DIVERSION_SUFFIX_LEN + reason->len + CRLF_LEN;
+	div_hf.len = DIVERSION_PREFIX_LEN + uri.len + DIVERSION_SUFFIX_LEN + reason.len + CRLF_LEN;
 	div_hf.s = pkg_malloc(div_hf.len);
 	if (!div_hf.s) {
 		LM_ERR("no pkg memory left\n");
@@ -158,14 +173,14 @@ int add_diversion(struct sip_msg* msg, char* r, char* s)
 	memcpy(at, DIVERSION_PREFIX, DIVERSION_PREFIX_LEN);
 	at += DIVERSION_PREFIX_LEN;
 
-	memcpy(at, uri->s, uri->len);
-	at += uri->len;
+	memcpy(at, uri.s, uri.len);
+	at += uri.len;
 
 	memcpy(at, DIVERSION_SUFFIX, DIVERSION_SUFFIX_LEN);
 	at += DIVERSION_SUFFIX_LEN;
 
-	memcpy(at, reason->s, reason->len);
-	at += reason->len;
+	memcpy(at, reason.s, reason.len);
+	at += reason.len;
 
 	memcpy(at, CRLF, CRLF_LEN);
 
diff --git a/modules_k/diversion/doc/diversion_admin.xml b/modules_k/diversion/doc/diversion_admin.xml
index 3ddd1bf..81cb428 100644
--- a/modules_k/diversion/doc/diversion_admin.xml
+++ b/modules_k/diversion/doc/diversion_admin.xml
@@ -73,13 +73,13 @@ modparam("diversion", "suffix", ";privacy=full")
 	<section>
 	<title>Functions</title>
 	<section>
-		<title><function moreinfo="none">add_diversion(reason)</function></title>
+		<title><function moreinfo="none">add_diversion(reason [, uri])</function></title>
 		<para>
 		The function adds a new diversion header field before any other 
 		existing Diversion header field in the message (the newly added 
 		Diversion header field will become the topmost Diversion header field).
-		The inbound (without any modifications done by the
-		proxy server) Request-URI will be used as the Diversion URI.
+		If 'uri' parameter is missing, the inbound (without any modifications done
+		by the proxy server) Request-URI will be used as the Diversion URI.
 		</para>
 		<para>Meaning of the parameters is as follows:</para>
 		<itemizedlist>
@@ -88,15 +88,23 @@ modparam("diversion", "suffix", ";privacy=full")
 			as the reason parameter
 			</para>
 		</listitem>
+		<listitem>
+			<para><emphasis>uri</emphasis> - The URI to be set in Diversion header
+			</para>
+		</listitem>
 	</itemizedlist>
 	<para>
-	This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
+		The parameters can contain pseudo-variables.
+	</para>
+	<para>
+	This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.
 	</para>
 	<example>
 		<title><function moreinfo="none">add_diversion</function> usage</title>
 		<programlisting format="linespecific">
 ...
 add_diversion("user-busy");
+add_diversion("user-busy", "$ru");
 ...
 </programlisting>
 	</example>




More information about the sr-dev mailing list