Răsfoiți Sursa

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

- both parameters can be now PVs
Daniel-Constantin Mierla 13 ani în urmă
părinte
comite
ef6b531dfa

+ 15 - 9
modules_k/diversion/README

@@ -8,7 +8,7 @@ Edited by
 
 
 Jan Janak
 Jan Janak
 
 
-   Copyright © 2004 FhG FOKUS
+   Copyright © 2004 FhG FOKUS
      __________________________________________________________________
      __________________________________________________________________
 
 
    Table of Contents
    Table of Contents
@@ -27,7 +27,7 @@ Jan Janak
 
 
         4. Functions
         4. Functions
 
 
-              4.1. add_diversion(reason)
+              4.1. add_diversion(reason [, uri])
 
 
         5. Diversion Example
         5. Diversion Example
 
 
@@ -54,7 +54,7 @@ Chapter 1. Admin Guide
 
 
    4. Functions
    4. Functions
 
 
-        4.1. add_diversion(reason)
+        4.1. add_diversion(reason [, uri])
 
 
    5. Diversion Example
    5. Diversion Example
 
 
@@ -95,31 +95,37 @@ Warning
    the parameter to specify additional parameters to be added to the
    the parameter to specify additional parameters to be added to the
    header field, see the example.
    header field, see the example.
 
 
-   Default value is “� (empty string).
+   Default value is "" (empty string).
 
 
    Example 1.1. suffix usage
    Example 1.1. suffix usage
 modparam("diversion", "suffix", ";privacy=full")
 modparam("diversion", "suffix", ";privacy=full")
 
 
 4. Functions
 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
    The function adds a new diversion header field before any other
    existing Diversion header field in the message (the newly added
    existing Diversion header field in the message (the newly added
    Diversion header field will become the topmost Diversion header field).
    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:
    Meaning of the parameters is as follows:
      * reason - The reason string to be added as the reason parameter
      * 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
    Example 1.2. add_diversion usage
 ...
 ...
 add_diversion("user-busy");
 add_diversion("user-busy");
+add_diversion("user-busy", "$ru");
 ...
 ...
 
 
 5. Diversion Example
 5. Diversion Example

+ 28 - 13
modules_k/diversion/diversion.c

@@ -48,7 +48,7 @@ MODULE_VERSION
 
 
 str suffix = {"", 0};
 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
  * Module initialization function prototype
@@ -60,8 +60,10 @@ static int mod_init(void);
  * Exported functions
  * Exported functions
  */
  */
 static cmd_export_t cmds[] = {
 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}
 	{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;
 	str div_hf;
 	char *at;
 	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);
 	div_hf.s = pkg_malloc(div_hf.len);
 	if (!div_hf.s) {
 	if (!div_hf.s) {
 		LM_ERR("no pkg memory left\n");
 		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);
 	memcpy(at, DIVERSION_PREFIX, DIVERSION_PREFIX_LEN);
 	at += 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);
 	memcpy(at, DIVERSION_SUFFIX, DIVERSION_SUFFIX_LEN);
 	at += 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);
 	memcpy(at, CRLF, CRLF_LEN);
 
 

+ 12 - 4
modules_k/diversion/doc/diversion_admin.xml

@@ -73,13 +73,13 @@ modparam("diversion", "suffix", ";privacy=full")
 	<section>
 	<section>
 	<title>Functions</title>
 	<title>Functions</title>
 	<section>
 	<section>
-		<title><function moreinfo="none">add_diversion(reason)</function></title>
+		<title><function moreinfo="none">add_diversion(reason [, uri])</function></title>
 		<para>
 		<para>
 		The function adds a new diversion header field before any other 
 		The function adds a new diversion header field before any other 
 		existing Diversion header field in the message (the newly added 
 		existing Diversion header field in the message (the newly added 
 		Diversion header field will become the topmost Diversion header field).
 		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>
 		<para>Meaning of the parameters is as follows:</para>
 		<para>Meaning of the parameters is as follows:</para>
 		<itemizedlist>
 		<itemizedlist>
@@ -88,15 +88,23 @@ modparam("diversion", "suffix", ";privacy=full")
 			as the reason parameter
 			as the reason parameter
 			</para>
 			</para>
 		</listitem>
 		</listitem>
+		<listitem>
+			<para><emphasis>uri</emphasis> - The URI to be set in Diversion header
+			</para>
+		</listitem>
 	</itemizedlist>
 	</itemizedlist>
 	<para>
 	<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>
 	</para>
 	<example>
 	<example>
 		<title><function moreinfo="none">add_diversion</function> usage</title>
 		<title><function moreinfo="none">add_diversion</function> usage</title>
 		<programlisting format="linespecific">
 		<programlisting format="linespecific">
 ...
 ...
 add_diversion("user-busy");
 add_diversion("user-busy");
+add_diversion("user-busy", "$ru");
 ...
 ...
 </programlisting>
 </programlisting>
 	</example>
 	</example>