2
0
Эх сурвалжийг харах

app_python: proper usage of pv in cfg function parameters

Daniel-Constantin Mierla 8 жил өмнө
parent
commit
a7bedbddc9

+ 5 - 2
src/modules/app_python/app_python_mod.c

@@ -24,6 +24,7 @@
 
 #include "../../core/str.h"
 #include "../../core/sr_module.h"
+#include "../../core/mod_fix.h"
 #include "../../core/kemi.h"
 
 #include "python_exec.h"
@@ -68,8 +69,10 @@ static param_export_t params[]={
  * Exported functions
  */
 static cmd_export_t cmds[] = {
-	{ "python_exec", (cmd_function)python_exec1, 1,  NULL, 0,	ANY_ROUTE },
-	{ "python_exec", (cmd_function)python_exec2, 2,  NULL, 0,	ANY_ROUTE },
+	{ "python_exec", (cmd_function)python_exec1, 1,  fixup_spve_null,
+		0,	ANY_ROUTE },
+	{ "python_exec", (cmd_function)python_exec2, 2,  fixup_spve_spve,
+		0,	ANY_ROUTE },
 	{ 0, 0, 0, 0, 0, 0 }
 };
 

+ 18 - 2
src/modules/app_python/python_exec.c

@@ -28,6 +28,7 @@
 #include "../../core/dprint.h"
 #include "../../core/action.h"
 #include "../../core/config.h"
+#include "../../core/mod_fix.h"
 #include "../../core/parser/parse_uri.h"
 
 #include "python_exec.h"
@@ -183,7 +184,12 @@ int apy_exec(sip_msg_t *_msg, char *fname, char *fparam, int emode)
  */
 int python_exec1(sip_msg_t *_msg, char *method_name, char *foobar)
 {
-	return apy_exec(_msg, method_name, NULL, 1);
+	str method = STR_NULL;
+	if(fixup_get_svalue(_msg, (gparam_t*)method_name, &method)<0) {
+		LM_ERR("cannot get the python method to be executed\n");
+		return -1;
+	}
+	return apy_exec(_msg, method.s, NULL, 1);
 }
 
 /**
@@ -191,5 +197,15 @@ int python_exec1(sip_msg_t *_msg, char *method_name, char *foobar)
  */
 int python_exec2(sip_msg_t *_msg, char *method_name, char *mystr)
 {
-	return apy_exec(_msg, method_name, mystr, 1);
+	str method = STR_NULL;
+	str param = STR_NULL;
+	if(fixup_get_svalue(_msg, (gparam_t*)method_name, &method)<0) {
+		LM_ERR("cannot get the python method to be executed\n");
+		return -1;
+	}
+	if(fixup_get_svalue(_msg, (gparam_t*)mystr, &param)<0) {
+		LM_ERR("cannot get the parameter of the python method\n");
+		return -1;
+	}
+	return apy_exec(_msg, method.s, param.s, 1);
 }