Browse Source

- parameters of prefix2domain() can be a PV
- use of core fixup functions


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3917 689a6050-402a-0410-94f2-e92a70836424

Elena-Ramona Modroiu 17 years ago
parent
commit
522ece1d08
3 changed files with 85 additions and 45 deletions
  1. 10 6
      modules_k/pdt/README
  2. 35 14
      modules_k/pdt/doc/pdt_admin.xml
  3. 40 25
      modules_k/pdt/pdt.c

+ 10 - 6
modules_k/pdt/README

@@ -268,20 +268,21 @@ modparam("pdt", "check_domain", 0)
    the database entries where sdomain has the value "*".
 
    The "rewrite_mode" parameter specifies whether to strip or not
-   the prefix from user part. If the parameter is missing or it
-   has the value "0", then the prefix is removed along with the
-   leading prefix. If the value is "1", only the leading prefix is
-   removed. If the values is "2" the user part of the URI is not
-   changed.
+   the prefix from user part. The possible values are:
+     * 0: the prefix is removed along with the leading prefix.
+     * 1: only the leading prefix is removed.
+     * 2: the user part of the URI is not changed.
+     * $PV : any PV holding one of the above values.
 
    The "multidomain_mode" parameter specifies the kind of
-   multidomain support to use. There are three possible values:
+   multidomain support to use. The possible values are:
      * 0 : Translation of URI regardless of source domain.
      * 1 : Translation of URI using as source domain the domain in
        From-URI.
      * 2 : Translation of URI using as source domain the domain in
        From-URI. In case there is no entry for the required
        sdomain, it tries the translation using "*" as sdomain.
+     * $PV : any PV holding one of the above values.
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
 
@@ -289,6 +290,9 @@ modparam("pdt", "check_domain", 0)
 ...
 prefix2domain("2", "2");
 ...
+$var(a) = 1;
+prefix2domain("$var(a)", "2");
+...
 
 1.4.2.  prefix2domain(rewrite_mode)
 

+ 35 - 14
modules_k/pdt/doc/pdt_admin.xml

@@ -330,25 +330,43 @@ modparam("pdt", "check_domain", 0)
 		</para>
 		<para>
 		The <quote>rewrite_mode</quote> parameter specifies whether to strip or not
-		the prefix from user part. If the parameter is missing or it has the
-		value <quote>0</quote>, then the prefix is removed along with the 
-		leading prefix. If the value is <quote>1</quote>, only the leading
-		prefix is removed. If the values is <quote>2</quote> the user part
-		of the URI is not changed.
+		the prefix from user part. The possible values are:
 		</para>
+		<itemizedlist>
+			<listitem>	  
+				<para>0: the prefix is removed along with the leading prefix.</para>
+			</listitem>	  
+			<listitem>	  
+				<para>1: only the leading prefix is removed.</para> 
+			</listitem>	  
+			<listitem>
+				<para>2: the user part of the URI is not changed.</para>
+			</listitem>	  
+			<listitem>
+				<para>$PV : any PV holding one of the above values.</para>
+			</listitem>	  
+		</itemizedlist>
 		<para>
-		The  <quote>multidomain_mode</quote> parameter specifies the kind of multidomain
-		support to use. There are three possible values:
+		The <quote>multidomain_mode</quote> parameter specifies the kind of multidomain
+		support to use. The possible values are:
+		</para>
 		<itemizedlist>
-			<listitem><para>0 : Translation of &uri; regardless of source domain.</para>
+			<listitem>
+				<para>0 : Translation of &uri; regardless of source domain.</para>
+			</listitem>	  
+			<listitem>
+				<para>1 :  Translation of &uri; using as source domain the domain
+					in From-URI.</para>
+			</listitem>			
+			<listitem>
+				<para>2 :  Translation of &uri; using as source domain the domain
+				in From-URI. In case there is no entry for the required sdomain,
+				it tries the translation using "*" as sdomain.</para>
+			</listitem>
+			<listitem>
+				<para>$PV : any PV holding one of the above values.</para>
 			</listitem>	  
-			<listitem><para>1 :  Translation of &uri; using as source domain the domain
-			in From-URI.</para></listitem>			
-			<listitem><para>2 :  Translation of &uri; using as source domain the domain
-			in From-URI. In case there is no entry for the required sdomain, it tries 
-			the translation using "*" as sdomain.</para></listitem>
 		</itemizedlist>		
-		</para>
 	    <para>
 		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
 		</para>
@@ -358,6 +376,9 @@ modparam("pdt", "check_domain", 0)
 ...
 prefix2domain("2", "2");
 ...
+$var(a) = 1;
+prefix2domain("$var(a)", "2");
+...
 </programlisting>
 	    </example>
 	</section>

+ 40 - 25
modules_k/pdt/pdt.c

@@ -51,6 +51,7 @@
 #include "../../ut.h"
 #include "../../locking.h"
 #include "../../action.h"
+#include "../../mod_fix.h"
 #include "../../parser/parse_from.h"
 
 #include "domains.h"
@@ -109,9 +110,12 @@ static int update_new_uri(struct sip_msg *msg, int plen, str *d, int mode);
 static int pdt_load_db();
 
 static cmd_export_t cmds[]={
-	{"prefix2domain", (cmd_function)w_prefix2domain,   0, 0, 0, REQUEST_ROUTE|FAILURE_ROUTE},
-	{"prefix2domain", (cmd_function)w_prefix2domain_1, 1, 0, 0, REQUEST_ROUTE|FAILURE_ROUTE},
-	{"prefix2domain", (cmd_function)w_prefix2domain_2, 2, 0, 0, REQUEST_ROUTE|FAILURE_ROUTE},
+	{"prefix2domain", (cmd_function)w_prefix2domain,   0, 0,
+		0, REQUEST_ROUTE|FAILURE_ROUTE},
+	{"prefix2domain", (cmd_function)w_prefix2domain_1, 1, fixup_igp_null,
+		0, REQUEST_ROUTE|FAILURE_ROUTE},
+	{"prefix2domain", (cmd_function)w_prefix2domain_2, 2, fixup_igp_igp,
+		0, REQUEST_ROUTE|FAILURE_ROUTE},
 	{0, 0, 0, 0, 0, 0}
 };
 
@@ -343,32 +347,43 @@ static int w_prefix2domain(struct sip_msg* msg, char* str1, char* str2)
 
 static int w_prefix2domain_1(struct sip_msg* msg, char* mode, char* str2)
 {
-	if(mode!=NULL && *mode=='1')
-		return prefix2domain(msg, 1, 0);
-	else if(mode!=NULL && *mode=='2')
-			return prefix2domain(msg, 2, 0);
-	else return prefix2domain(msg, 0, 0);
+	int m;
+
+	if(fixup_get_ivalue(msg, (gparam_p)mode, &m)!=0)
+	{
+		LM_ERR("no mode value\n");
+		return -1;
+	}
+
+	if(m!=1 && m!=2)
+		m = 0;
+
+	return prefix2domain(msg, m, 0);
 }
 
-static int w_prefix2domain_2(struct sip_msg* msg, char* mode, char* sd_en)
+static int w_prefix2domain_2(struct sip_msg* msg, char* mode, char* sdm)
 {
-	int tmp=0;
-	
-	if((sd_en==NULL) || ((sd_en!=NULL) && (*sd_en!='0') && (*sd_en!='1')
-				&& (*sd_en!='2')))
+	int m, s;
+
+	if(fixup_get_ivalue(msg, (gparam_p)mode, &m)!=0)
+	{
+		LM_ERR("no mode value\n");
 		return -1;
-	
-    if (*sd_en=='1')
-		tmp = 1;
-    if (*sd_en=='2')
-		tmp = 2;
-	
-		
-	if(mode!=NULL && *mode=='1')
-		return prefix2domain(msg, 1, tmp);
-	else if(mode!=NULL && *mode=='2')
-			return prefix2domain(msg, 2, tmp);
-	else return prefix2domain(msg, 0, tmp);
+	}
+
+	if(m!=1 && m!=2)
+		m = 0;
+
+	if(fixup_get_ivalue(msg, (gparam_p)sdm, &s)!=0)
+	{
+		LM_ERR("no multi-domain mode value\n");
+		return -1;
+	}
+
+	if(s!=1 && s!=2)
+		s = 0;
+
+	return prefix2domain(msg, m, s);
 }
 
 /* change the r-uri if it is a PSTN format */