Przeglądaj źródła

modules/diaplan: dest pv is now optional in dp_translate()

- If dest pv is not given, only matching and storing of matching rule's
  attributes is done.
- If replacement empty, dest pv is not set no matter what kind of pv it is.
Juha Heinanen 15 lat temu
rodzic
commit
a3080718b9

+ 24 - 23
modules/dialplan/README

@@ -12,9 +12,9 @@ Edited by
 
 
 Juha Heinanen
 Juha Heinanen
 
 
-   Copyright © 2007-2008 voice-system.ro
+   Copyright © 2007-2008 voice-system.ro
 
 
-   Copyright © 2008 Juha Heinanen
+   Copyright © 2008-2010 Juha Heinanen
    Revision History
    Revision History
    Revision $Revision: 1.1 $ $Date: 2007/08/30 13:16:22 $
    Revision $Revision: 1.1 $ $Date: 2007/08/30 13:16:22 $
    Revision $Revision: 1.2 $ $Date: 2008/10/9 15:57 $
    Revision $Revision: 1.2 $ $Date: 2008/10/9 15:57 $
@@ -49,7 +49,7 @@ Juha Heinanen
 
 
         6. Exported Functions
         6. Exported Functions
 
 
-              6.1. dp_translate(id, src/dest)
+              6.1. dp_translate(id, src[/dest])
 
 
         7. Exported MI Functions
         7. Exported MI Functions
 
 
@@ -106,7 +106,7 @@ Chapter 1. Admin Guide
 
 
    6. Exported Functions
    6. Exported Functions
 
 
-        6.1. dp_translate(id, src/dest)
+        6.1. dp_translate(id, src[/dest])
 
 
    7. Exported MI Functions
    7. Exported MI Functions
 
 
@@ -191,7 +191,7 @@ Chapter 1. Admin Guide
 
 
    The translation rules will be loaded using this database URL.
    The translation rules will be loaded using this database URL.
 
 
-   Default value is "mysql://openser:openserrw@localhost/openser".
+   Default value is “mysql://openser:openserrw@localhost/openser�.
 
 
    Example 1.1. Set db_url parameter
    Example 1.1. Set db_url parameter
 ...
 ...
@@ -202,7 +202,7 @@ modparam("dialplan", "db_url", "mysql://user:passwb@localhost/db")
 
 
    The table's name from which to load the translation rules.
    The table's name from which to load the translation rules.
 
 
-   Default value is "dialplan".
+   Default value is “dialplan�.
 
 
    Example 1.2. Set table_name parameter
    Example 1.2. Set table_name parameter
 ...
 ...
@@ -213,7 +213,7 @@ modparam("dialplan", "table_name", "my_table")
 
 
    The column name used to store the dialplan ID group.
    The column name used to store the dialplan ID group.
 
 
-   Default value is "dpid".
+   Default value is “dpid�.
 
 
    Example 1.3. Set dpid_col parameter
    Example 1.3. Set dpid_col parameter
 ...
 ...
@@ -225,7 +225,7 @@ modparam("dialplan", "dpid_col", "column_name")
    The column name used to store the priority of the corresponding rule
    The column name used to store the priority of the corresponding rule
    from the database row.
    from the database row.
 
 
-   Default value is "pr".
+   Default value is “pr�.
 
 
    Example 1.4. Set pr_col parameter
    Example 1.4. Set pr_col parameter
 ...
 ...
@@ -236,7 +236,7 @@ modparam("dialplan", "pr_col", "column_name")
 
 
    The column name used to store the type of matching of the rule.
    The column name used to store the type of matching of the rule.
 
 
-   Default value is "match_op".
+   Default value is “match_op�.
 
 
    Example 1.5. Set match_op_col parameter
    Example 1.5. Set match_op_col parameter
 ...
 ...
@@ -247,7 +247,7 @@ modparam("dialplan", "match_op_col", "column_name")
 
 
    The column name to store the rule match expression.
    The column name to store the rule match expression.
 
 
-   Default value is "match_exp".
+   Default value is “match_exp�.
 
 
    Example 1.6. Set match_exp_col parameter
    Example 1.6. Set match_exp_col parameter
 ...
 ...
@@ -259,7 +259,7 @@ modparam("dialplan", "match_exp_col", "column_name")
    The column name to store the length of a string matching the match
    The column name to store the length of a string matching the match
    expression.
    expression.
 
 
-   Default value is "match_len".
+   Default value is “match_len�.
 
 
    Example 1.7. Set pr_col parameter
    Example 1.7. Set pr_col parameter
 ...
 ...
@@ -270,7 +270,7 @@ modparam("dialplan", "match_len_col", "column_name")
 
 
    The column name to store the rule's substitution expression.
    The column name to store the rule's substitution expression.
 
 
-   Default value is "subst_exp".
+   Default value is “subst_exp�.
 
 
    Example 1.8. Set pr_col parameter
    Example 1.8. Set pr_col parameter
 ...
 ...
@@ -281,7 +281,7 @@ modparam("dialplan", "subst_exp_col", "column_name")
 
 
    The column name to store the rule's replacement expression.
    The column name to store the rule's replacement expression.
 
 
-   Default value is "repl_exp".
+   Default value is “repl_exp�.
 
 
    Example 1.9. Set repl_exp_col parameter
    Example 1.9. Set repl_exp_col parameter
 ...
 ...
@@ -293,7 +293,7 @@ modparam("dialplan", "repl_exp_col", "column_name")
    The column name to store the rule's attributes to be set to the
    The column name to store the rule's attributes to be set to the
    message.
    message.
 
 
-   Default value is "attrs".
+   Default value is “attrs�.
 
 
    Example 1.10. Set attrs_col parameter
    Example 1.10. Set attrs_col parameter
 ...
 ...
@@ -306,7 +306,7 @@ modparam("dialplan", "attrs_col", "column_name")
    (dp_translate() succeeds). This parameter can be an AVP or a SCRIPT
    (dp_translate() succeeds). This parameter can be an AVP or a SCRIPT
    VAR.
    VAR.
 
 
-   Default value is "NULL".
+   Default value is “NULL�.
 
 
    Example 1.11. Set attrs_pvar parameter
    Example 1.11. Set attrs_pvar parameter
 ...
 ...
@@ -317,7 +317,7 @@ modparam("dialplan", "attrs_pvar", "$avp(s:dest)")
 
 
    The number of rows to be fetched at once from database
    The number of rows to be fetched at once from database
 
 
-   Default value is "1000".
+   Default value is “1000�.
 
 
    Example 1.12. Set fetch_rows parameter
    Example 1.12. Set fetch_rows parameter
 ...
 ...
@@ -326,12 +326,13 @@ modparam("dialplan", "fetch_rows", 4000)
 
 
 6. Exported Functions
 6. Exported Functions
 
 
-   6.1. dp_translate(id, src/dest)
+   6.1. dp_translate(id, src[/dest])
 
 
-6.1. dp_translate(id, src/dest)
+6.1.  dp_translate(id, src[/dest])
 
 
-   Will try to translate the src string into dest string according to the
-   translation rules with dialplan ID equal to id.
+   Will try to translate src into dest according to the translation rules
+   with dialplan ID equal to id. If dest is missing, only matching and
+   storing of matching rule's attributes is done.
 
 
    Meaning of the parameters is as follows:
    Meaning of the parameters is as follows:
      * id -the dialplan id of the possible matching rules. This parameter
      * id -the dialplan id of the possible matching rules. This parameter
@@ -342,12 +343,12 @@ modparam("dialplan", "fetch_rows", 4000)
           + script var - the dialplan id is the value of an existing
           + script var - the dialplan id is the value of an existing
             script variable.
             script variable.
      * src/dest - input and output of the function. If this parameter is
      * src/dest - input and output of the function. If this parameter is
-       missing the default parameter "ruri.user/ruri.user" will be used,
-       thus translating the request uri.
+       missing the default parameter “ruri.user/ruri.user� will be used,
+       thus translating the request uri user part.
        Input parameter src can be any pseudo variable. Output parameter
        Input parameter src can be any pseudo variable. Output parameter
        dest can be:
        dest can be:
           + R-URI
           + R-URI
-            - the string is the r-uri or r-uri username
+            - the string is the r-uri or r-uri user part
           + avp var
           + avp var
             - At input the function will get the input string from an
             - At input the function will get the input string from an
             existing avp variable. At output the function will add an avp
             existing avp variable. At output the function will add an avp

+ 19 - 12
modules/dialplan/dialplan.c

@@ -267,13 +267,12 @@ static int dp_get_svalue(struct sip_msg * msg, pv_spec_t spec, str* val)
 
 
 
 
 static int dp_update(struct sip_msg * msg, pv_spec_t * src, pv_spec_t * dest,
 static int dp_update(struct sip_msg * msg, pv_spec_t * src, pv_spec_t * dest,
-											str * repl, str * attrs)
+		     str * repl, str * attrs)
 {
 {
 	int no_change;
 	int no_change;
 	pv_value_t val;
 	pv_value_t val;
 
 
-	no_change = ((!repl->s) || (!repl->len)) && (src->type == dest->type) 
-		&& ((src->type == PVT_RURI) || (src->type == PVT_RURI_USERNAME));
+	no_change = (dest->type == PVT_NONE) || (!repl->s) || (!repl->len);
 
 
 	if (no_change)
 	if (no_change)
 		goto set_attr_pvar;
 		goto set_attr_pvar;
@@ -380,7 +379,7 @@ static int dp_translate_f(struct sip_msg* msg, char* str1, char* str2)
 
 
 /* first param: DPID: type: INT, AVP, SVAR
 /* first param: DPID: type: INT, AVP, SVAR
  * second param: SRC type: any psedo variable type
  * second param: SRC type: any psedo variable type
- * second param: DST type: RURI, RURI_USERNAME, AVP, SVAR
+ * second param: DST type: RURI, RURI_USERNAME, AVP, SVAR, N/A
  * default value for the second param: $ru.user/$ru.user
  * default value for the second param: $ru.user/$ru.user
  */
  */
 static int dp_trans_fixup(void ** param, int param_no){
 static int dp_trans_fixup(void ** param, int param_no){
@@ -429,21 +428,29 @@ static int dp_trans_fixup(void ** param, int param_no){
 			dp_par->type = DP_VAL_SPEC;
 			dp_par->type = DP_VAL_SPEC;
 		}
 		}
 	} else {
 	} else {
-		if( ((s = strchr(p, '/')) == 0) ||( *(s+1)=='\0'))
-				goto error;
+
+	    if (((s = strchr(p, '/')) != 0) && (*(s+1)=='\0'))
+		goto error;
+
+	    if (s != 0) {
 		*s = '\0'; s++;
 		*s = '\0'; s++;
+	    }
 
 
-		lstr.s = p; lstr.len = strlen(p);
-		if(pv_parse_spec( &lstr, &dp_par->v.sp[0])==NULL)
-			goto error;
+	    lstr.s = p; lstr.len = strlen(p);
+	    if(pv_parse_spec( &lstr, &dp_par->v.sp[0])==NULL)
+		goto error;
 
 
+	    if (s != 0) {
 		lstr.s = s; lstr.len = strlen(s);
 		lstr.s = s; lstr.len = strlen(s);
 		if (pv_parse_spec( &lstr, &dp_par->v.sp[1] )==NULL)
 		if (pv_parse_spec( &lstr, &dp_par->v.sp[1] )==NULL)
-			goto error;
-
+		    goto error;
 		verify_par_type(param_no, dp_par->v.sp[1]);
 		verify_par_type(param_no, dp_par->v.sp[1]);
+	    } else {
+		dp_par->v.sp[1].type = PVT_NONE;
+	    }
+
+	    dp_par->type = DP_VAL_SPEC;
 
 
-		dp_par->type = DP_VAL_SPEC;
 	}
 	}
 	
 	
 	*param = (void *)dp_par;
 	*param = (void *)dp_par;

+ 1 - 1
modules/dialplan/doc/dialplan.xml

@@ -38,7 +38,7 @@
 		<holder>&voicesystem;</holder>
 		<holder>&voicesystem;</holder>
 	</copyright>
 	</copyright>
 	<copyright>
 	<copyright>
-		<year>2008</year>
+		<year>2008-2010</year>
 		<holder>Juha Heinanen</holder>
 		<holder>Juha Heinanen</holder>
 	</copyright>
 	</copyright>
 	<revhistory>
 	<revhistory>

+ 8 - 6
modules/dialplan/doc/dialplan_admin.xml

@@ -357,11 +357,13 @@ modparam("dialplan", "fetch_rows", 4000)
 	
 	
 	<section>
 	<section>
 	<title>
 	<title>
-		<function moreinfo="none">dp_translate(id, src/dest)</function>
+		<function moreinfo="none">dp_translate(id, src[/dest])</function>
 	</title>
 	</title>
 	<para>
 	<para>
-	Will try to translate the src string into dest string according to 
-	the translation rules with dialplan ID equal to id.
+	Will try to translate src into dest according to 
+	the translation rules with dialplan ID equal to id.  If dest is
+	missing, only matching and storing of matching rule's
+	attributes is done.
 	</para>
 	</para>
 	<para>Meaning of the parameters is as follows:</para>
 	<para>Meaning of the parameters is as follows:</para>
 	<itemizedlist>
 	<itemizedlist>
@@ -393,8 +395,8 @@ modparam("dialplan", "fetch_rows", 4000)
 		<para>
 		<para>
  		<emphasis>src/dest</emphasis> - input and output of the function.
  		<emphasis>src/dest</emphasis> - input and output of the function.
 		If this parameter is missing the default parameter 
 		If this parameter is missing the default parameter 
-		<quote>ruri.user/ruri.user</quote> will be used, thus translating 
-		the request uri. 
+		<quote>ruri.user/ruri.user</quote> will be used, thus
+		translating the request uri user part. 
  		</para>
  		</para>
 		<para>Input parameter src can be any pseudo variable.
 		<para>Input parameter src can be any pseudo variable.
 		Output parameter dest can be:
 		Output parameter dest can be:
@@ -403,7 +405,7 @@ modparam("dialplan", "fetch_rows", 4000)
 			<listitem>
 			<listitem>
 			<para><emphasis>R-URI</emphasis></para>
 			<para><emphasis>R-URI</emphasis></para>
 			<para>
 			<para>
-			- the string is the r-uri or r-uri username
+			- the string is the r-uri or r-uri user part
 			</para>
 			</para>
 			</listitem>
 			</listitem>