Prechádzať zdrojové kódy

cpl-c: added an optional parameter to cpl_run_scritp() to provide the URI

- the parameter will be used instead of taking the URI from headers or
  R-URI
Daniel-Constantin Mierla 12 rokov pred
rodič
commit
69a7abb870

+ 21 - 19
modules_k/cpl-c/README

@@ -8,7 +8,7 @@ Edited by
 
 
 Bogdan-Andrei Iancu
 Bogdan-Andrei Iancu
 
 
-   Copyright © 2003 FhG FOKUS
+   Copyright © 2003 FhG FOKUS
      __________________________________________________________________
      __________________________________________________________________
 
 
    Table of Contents
    Table of Contents
@@ -42,7 +42,7 @@ Bogdan-Andrei Iancu
 
 
         4. Functions
         4. Functions
 
 
-              4.1. cpl_run_script(type,mode)
+              4.1. cpl_run_script(type,mode, [uri])
               4.2. cpl_process_register()
               4.2. cpl_process_register()
               4.3. cpl_process_register_norpl()
               4.3. cpl_process_register_norpl()
 
 
@@ -109,7 +109,7 @@ Chapter 1. Admin Guide
 
 
    4. Functions
    4. Functions
 
 
-        4.1. cpl_run_script(type,mode)
+        4.1. cpl_run_script(type,mode, [uri])
         4.2. cpl_process_register()
         4.2. cpl_process_register()
         4.3. cpl_process_register_norpl()
         4.3. cpl_process_register_norpl()
 
 
@@ -180,7 +180,7 @@ Chapter 1. Admin Guide
    name and password can be specified for allowing the module to connect
    name and password can be specified for allowing the module to connect
    to the database server.
    to the database server.
 
 
-   Default value is “mysql://openser:openserrw@localhost/openser�.
+   Default value is "mysql://kamailio:kamailiorw@localhost/kamailio".
 
 
    Example 1.1. Set db_url parameter
    Example 1.1. Set db_url parameter
 ...
 ...
@@ -190,11 +190,11 @@ modparam("cpl-c","db_url","dbdriver://username:password@dbhost/dbname")
 3.2. db_table (string)
 3.2. db_table (string)
 
 
    Indicates the name of the table that store the CPL scripts. This table
    Indicates the name of the table that store the CPL scripts. This table
-   must be locate into the database specified by “db_url� parameter. For
+   must be locate into the database specified by "db_url" parameter. For
    more about the format of the CPL table please see the
    more about the format of the CPL table please see the
    modules/cpl-c/init.mysql file.
    modules/cpl-c/init.mysql file.
 
 
-   Default value is “cpl�.
+   Default value is "cpl".
 
 
    Example 1.2. Set db_table parameter
    Example 1.2. Set db_table parameter
 ...
 ...
@@ -205,7 +205,7 @@ modparam("cpl-c","cpl_table","cpl")
 
 
    Indicates the name of the column used for storing the username.
    Indicates the name of the column used for storing the username.
 
 
-   Default value is “username�.
+   Default value is "username".
 
 
    Example 1.3. Set username_column parameter
    Example 1.3. Set username_column parameter
 ...
 ...
@@ -216,7 +216,7 @@ modparam("cpl-c","username_column","username")
 
 
    Indicates the name of the column used for storing the domain.
    Indicates the name of the column used for storing the domain.
 
 
-   Default value is “domain�.
+   Default value is "domain".
 
 
    Example 1.4. Set domain_column parameter
    Example 1.4. Set domain_column parameter
 ...
 ...
@@ -228,7 +228,7 @@ modparam("cpl-c","domain_column","domain")
    Indicates the name of the column used for storing the the XML version
    Indicates the name of the column used for storing the the XML version
    of the cpl script.
    of the cpl script.
 
 
-   Default value is “cpl_xml�.
+   Default value is "cpl_xml".
 
 
    Example 1.5. Set cpl_xml_column parameter
    Example 1.5. Set cpl_xml_column parameter
 ...
 ...
@@ -240,7 +240,7 @@ modparam("cpl-c","cpl_xml_column","cpl_xml")
    Indicates the name of the column used for storing the the binary
    Indicates the name of the column used for storing the the binary
    version of the cpl script (compiled version).
    version of the cpl script (compiled version).
 
 
-   Default value is “cpl_bin�.
+   Default value is "cpl_bin".
 
 
    Example 1.6. Set cpl_bin_column parameter
    Example 1.6. Set cpl_bin_column parameter
 ...
 ...
@@ -378,7 +378,7 @@ modparam("cpl-c","lookup_append_branches",1)
    Indicates if the domain part of the URI should be used in user
    Indicates if the domain part of the URI should be used in user
    identification (otherwise only username part will be used).
    identification (otherwise only username part will be used).
 
 
-   Default value is “0 (disabled)�.
+   Default value is "0 (disabled)".
 
 
    Example 1.16. Set use_domain parameter
    Example 1.16. Set use_domain parameter
 ...
 ...
@@ -387,11 +387,11 @@ modparam("cpl-c","use_domain",1)
 
 
 4. Functions
 4. Functions
 
 
-   4.1. cpl_run_script(type,mode)
+   4.1. cpl_run_script(type,mode, [uri])
    4.2. cpl_process_register()
    4.2. cpl_process_register()
    4.3. cpl_process_register_norpl()
    4.3. cpl_process_register_norpl()
 
 
-4.1.  cpl_run_script(type,mode)
+4.1. cpl_run_script(type,mode, [uri])
 
 
    Starts the execution of the CPL script. The user name is fetched from
    Starts the execution of the CPL script. The user name is fetched from
    new_uri or requested uri or from To header -in this order- (for
    new_uri or requested uri or from To header -in this order- (for
@@ -438,6 +438,8 @@ modparam("cpl-c","use_domain",1)
        done stateful (retransmission protection) and in the same time, if
        done stateful (retransmission protection) and in the same time, if
        returning to script, it will be in stateless mode (easy to continue
        returning to script, it will be in stateless mode (easy to continue
        the routing script execution)
        the routing script execution)
+     * uri - optional - provide the SIP URI to be used for loading the CPL
+       script, instead of taking it from R-URI or headers.
 
 
    This function can be used from REQUEST_ROUTE.
    This function can be used from REQUEST_ROUTE.
 
 
@@ -446,7 +448,7 @@ modparam("cpl-c","use_domain",1)
 cpl_run_script("incoming","force_stateful");
 cpl_run_script("incoming","force_stateful");
 ...
 ...
 
 
-4.2.  cpl_process_register()
+4.2. cpl_process_register()
 
 
    This function MUST be called only for REGISTER requests. It checks if
    This function MUST be called only for REGISTER requests. It checks if
    the current REGISTER request is related or not with CPL script
    the current REGISTER request is related or not with CPL script
@@ -474,9 +476,9 @@ if (method=="REGISTER") {
 }
 }
 ...
 ...
 
 
-4.3.  cpl_process_register_norpl()
+4.3. cpl_process_register_norpl()
 
 
-   Same as “cpl_process_register� without internally generating the reply.
+   Same as "cpl_process_register" without internally generating the reply.
    All information (script) is appended to the reply but without sending
    All information (script) is appended to the reply but without sending
    it out.
    it out.
 
 
@@ -500,7 +502,7 @@ if (method=="REGISTER") {
    5.2. REMOVE_CPL
    5.2. REMOVE_CPL
    5.3. GET_CPL
    5.3. GET_CPL
 
 
-5.1.  LOAD_CPL
+5.1. LOAD_CPL
 
 
    For the given user, loads the XML cpl file, compiles it into binary
    For the given user, loads the XML cpl file, compiles it into binary
    format and stores both format into database.
    format and stores both format into database.
@@ -517,7 +519,7 @@ if (method=="REGISTER") {
                  cpl_filename
                  cpl_filename
                  _empty_line_
                  _empty_line_
 
 
-5.2.  REMOVE_CPL
+5.2. REMOVE_CPL
 
 
    For the given user, removes the entire database record (XML cpl and
    For the given user, removes the entire database record (XML cpl and
    binary cpl); user with empty cpl scripts are not accepted.
    binary cpl); user with empty cpl scripts are not accepted.
@@ -532,7 +534,7 @@ if (method=="REGISTER") {
                  username
                  username
                  _empty_line_
                  _empty_line_
 
 
-5.3.  GET_CPL
+5.3. GET_CPL
 
 
    For the given user, returns the CPL script in XML format.
    For the given user, returns the CPL script in XML format.
 
 

+ 50 - 10
modules_k/cpl-c/cpl.c

@@ -50,6 +50,7 @@
 #include "../../dprint.h"
 #include "../../dprint.h"
 #include "../../data_lump_rpl.h"
 #include "../../data_lump_rpl.h"
 #include "../../pvar.h"
 #include "../../pvar.h"
+#include "../../mod_fix.h"
 #include "../../parser/parse_uri.h"
 #include "../../parser/parse_uri.h"
 #include "../../parser/parse_from.h"
 #include "../../parser/parse_from.h"
 #include "../../parser/parse_content.h"
 #include "../../parser/parse_content.h"
@@ -100,11 +101,13 @@ static str cpl_ok_rpl = str_init("OK");
 MODULE_VERSION
 MODULE_VERSION
 
 
 
 
-static int cpl_invoke_script (struct sip_msg* msg, char* str, char* str2);
-static int w_process_register(struct sip_msg* msg, char* str, char* str2);
-static int w_process_register_norpl(struct sip_msg* msg, char* str,char* str2);
+static int cpl_invoke_script (struct sip_msg* msg, char* str1, char* str2);
+static int cpl_invoke_script3 (struct sip_msg* msg, char* str1, char* str2, char* str3);
+static int w_process_register(struct sip_msg* msg, char* str1, char* str2);
+static int w_process_register_norpl(struct sip_msg* msg, char* str1,char* str2);
 static int cpl_process_register(struct sip_msg* msg, int no_rpl);
 static int cpl_process_register(struct sip_msg* msg, int no_rpl);
 static int fixup_cpl_run_script(void** param, int param_no);
 static int fixup_cpl_run_script(void** param, int param_no);
+static int fixup_cpl_run_script3(void** param, int param_no);
 static int cpl_init(void);
 static int cpl_init(void);
 static int mi_child_init(void);
 static int mi_child_init(void);
 static int cpl_child_init(int rank);
 static int cpl_child_init(int rank);
@@ -127,6 +130,8 @@ static proc_export_t cpl_procs[] = {
 static cmd_export_t cmds[] = {
 static cmd_export_t cmds[] = {
 	{"cpl_run_script",            (cmd_function)cpl_invoke_script,        2,
 	{"cpl_run_script",            (cmd_function)cpl_invoke_script,        2,
 			fixup_cpl_run_script, 0, REQUEST_ROUTE},
 			fixup_cpl_run_script, 0, REQUEST_ROUTE},
+	{"cpl_run_script",            (cmd_function)cpl_invoke_script3,        3,
+			fixup_cpl_run_script3, 0, REQUEST_ROUTE},
 	{"cpl_process_register",      (cmd_function)w_process_register,       0,
 	{"cpl_process_register",      (cmd_function)w_process_register,       0,
 			0, 0,                    REQUEST_ROUTE},
 			0, 0,                    REQUEST_ROUTE},
 	{"cpl_process_register_norpl",(cmd_function)w_process_register_norpl, 0,
 	{"cpl_process_register_norpl",(cmd_function)w_process_register_norpl, 0,
@@ -222,6 +227,16 @@ static int fixup_cpl_run_script(void** param, int param_no)
 	return 0;
 	return 0;
 }
 }
 
 
+static int fixup_cpl_run_script3(void** param, int param_no)
+{
+	if (param_no==1 || param_no==2) {
+		return fixup_cpl_run_script(param, param_no);
+	} else if (param_no==2) {
+		return fixup_spve_null(param, 1);
+	}
+	return 0;
+}
+
 
 
 
 
 static int cpl_init(void)
 static int cpl_init(void)
@@ -547,24 +562,41 @@ static inline int get_orig_user(struct sip_msg *msg, str *username, str *domain)
 /* Params: 
 /* Params: 
  *   str1 - as unsigned int - can be CPL_RUN_INCOMING or CPL_RUN_OUTGOING 
  *   str1 - as unsigned int - can be CPL_RUN_INCOMING or CPL_RUN_OUTGOING 
  *   str2 - as unsigned int - flags regarding state(less)|(ful) 
  *   str2 - as unsigned int - flags regarding state(less)|(ful) 
+ *   str3 - URI in SPVE structure
  */
  */
-static int cpl_invoke_script(struct sip_msg* msg, char* str1, char* str2)
+static int cpl_invoke_script3(struct sip_msg* msg, char* str1, char* str2, char *str3)
 {
 {
 	struct cpl_interpreter  *cpl_intr;
 	struct cpl_interpreter  *cpl_intr;
 	str  username = {0,0};
 	str  username = {0,0};
 	str  domain = {0,0};
 	str  domain = {0,0};
+	str  uri = {0,0};
+	sip_uri_t puri;
 	str  loc;
 	str  loc;
 	str  script;
 	str  script;
 
 
 	/* get the user_name */
 	/* get the user_name */
-	if ( ((unsigned long)str1)&CPL_RUN_INCOMING ) {
-		/* if it's incoming -> get the destination user name */
-		if (get_dest_user( msg, &username, &domain)==-1)
-			goto error0;
+	if(str3==NULL) {
+		if ( ((unsigned long)str1)&CPL_RUN_INCOMING ) {
+			/* if it's incoming -> get the destination user name */
+			if (get_dest_user( msg, &username, &domain)==-1)
+				goto error0;
+		} else {
+			/* if it's outgoing -> get the origin user name */
+			if (get_orig_user( msg, &username, &domain)==-1)
+				goto error0;
+		}
 	} else {
 	} else {
-		/* if it's outgoing -> get the origin user name */
-		if (get_orig_user( msg, &username, &domain)==-1)
+		if(fixup_get_svalue(msg, (gparam_p)str3, &uri)!=0)
+		{
+			LM_ERR("invalid uri parameter");
 			goto error0;
 			goto error0;
+		}
+		if (parse_uri(uri.s, uri.len, &puri) || !puri.user.len) {
+			LM_ERR("unable to extract user name from URI param\n");
+			return -1;
+		}
+		username = puri.user;
+		domain = puri.host;
 	}
 	}
 
 
 	/* get the script for this user */
 	/* get the script for this user */
@@ -621,6 +653,14 @@ error0:
 	return -1;
 	return -1;
 }
 }
 
 
+/* Params: 
+ *   str1 - as unsigned int - can be CPL_RUN_INCOMING or CPL_RUN_OUTGOING 
+ *   str2 - as unsigned int - flags regarding state(less)|(ful) 
+ */
+static int cpl_invoke_script(struct sip_msg* msg, char* str1, char* str2)
+{
+	return  cpl_invoke_script3(msg, str1, str2, NULL);
+}
 
 
 
 
 #define CPL_SCRIPT          "script"
 #define CPL_SCRIPT          "script"

+ 8 - 1
modules_k/cpl-c/doc/cpl-c_admin.xml

@@ -439,7 +439,7 @@ modparam("cpl-c","use_domain",1)
 		<title>Functions</title>
 		<title>Functions</title>
 		<section>
 		<section>
 			<title>
 			<title>
-				<function moreinfo="none">cpl_run_script(type,mode)</function>
+				<function moreinfo="none">cpl_run_script(type,mode, [uri])</function>
 			</title>
 			</title>
 			<para>
 			<para>
 				Starts the execution of the CPL script. The user name is 
 				Starts the execution of the CPL script. The user name is 
@@ -515,6 +515,13 @@ modparam("cpl-c","use_domain",1)
 				continue the routing script execution)
 				continue the routing script execution)
 				</para>
 				</para>
 			</listitem>
 			</listitem>
+			<listitem>
+				<para><emphasis>uri</emphasis> - optional - provide the SIP URI
+				to be used for loading the CPL script, instead of taking it from
+				R-URI or headers.
+				</para>
+			</listitem>
+
 			</itemizedlist>
 			</itemizedlist>
 			<para>
 			<para>
 			This function can be used from REQUEST_ROUTE.
 			This function can be used from REQUEST_ROUTE.