[Freeswitch-svn] [commit] r8206 - freeswitch/trunk/src/mod/languages/mod_perl

Freeswitch SVN anthm at freeswitch.org
Sat Apr 26 11:57:06 EDT 2008


Author: anthm
Date: Sat Apr 26 11:57:05 2008
New Revision: 8206

Modified:
   freeswitch/trunk/src/mod/languages/mod_perl/mod_perl.c
   freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp

Log:
tweak

Modified: freeswitch/trunk/src/mod/languages/mod_perl/mod_perl.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_perl/mod_perl.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_perl/mod_perl.c	Sat Apr 26 11:57:05 2008
@@ -56,17 +56,17 @@
 	char *xml_handler;
 } globals;
 
-static void Perl_safe_eval(PerlInterpreter *my_perl, const char *string, int tf)
+static int Perl_safe_eval(PerlInterpreter *my_perl, const char *string, int tf)
 {
-	char *st = switch_mprintf("eval { %s }; $__ERR = $@", string);
 	char *err = NULL;
-	Perl_eval_pv(my_perl, st, tf);
-	
-	if ((err = SvPV(get_sv("__ERR", FALSE), n_a)) && !switch_strlen_zero(err)) {
+
+	Perl_eval_pv(my_perl, string, FALSE);
+
+	if ((err = SvPV(get_sv("@", TRUE), n_a)) && !switch_strlen_zero(err)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err);
+		return -1;
 	}
-	
-	switch_safe_free(st);
+	return 0;
 }
 
 static void destroy_perl(PerlInterpreter ** to_destroy)
@@ -90,18 +90,29 @@
 	if (*input_code == '~') {
 		char *buff = input_code + 1;
 		perl_parse(my_perl, xs_init, 3, embedding, NULL);
-		if (setup_code) Perl_safe_eval(my_perl, setup_code, TRUE);
+		if (setup_code) Perl_safe_eval(my_perl, setup_code, FALSE);
 		Perl_safe_eval(my_perl, buff, TRUE);
 	} else {
 		int argc = 0;
 		char *argv[128] = { 0 };
+		char *err;
 		argv[0] = "FreeSWITCH";
 		argc++;
 		
 		argc += switch_separate_string(input_code, ' ', &argv[1], (sizeof(argv) / sizeof(argv[0])) - 1);
-		perl_parse(my_perl, xs_init, argc, argv, (char **)NULL);
-		if (setup_code) Perl_safe_eval(my_perl, setup_code, TRUE);
-		perl_run(my_perl);
+		if (!perl_parse(my_perl, xs_init, argc, argv, (char **)NULL)) {
+			if (setup_code) {
+				if (!Perl_safe_eval(my_perl, setup_code, FALSE)) {
+					perl_run(my_perl);
+				}
+			}
+		}
+		
+		if ((err = SvPV(get_sv("@", TRUE), n_a)) && !switch_strlen_zero(err)) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err);
+		}
+		
+
 	}
 }
 
@@ -122,8 +133,8 @@
 			uuid);
 
 	perl_parse_and_execute(my_perl, data, code);
-	Perl_safe_eval(my_perl, "undef $session;", TRUE);
-	Perl_safe_eval(my_perl, "undef (*);", TRUE);
+	Perl_safe_eval(my_perl, "undef $session;", FALSE);
+	Perl_safe_eval(my_perl, "undef (*);", FALSE);
 	destroy_perl(&my_perl);
 }
 
@@ -157,7 +168,7 @@
 		free(input_code);
 	}
 
-	Perl_safe_eval(my_perl, "undef(*);", TRUE);
+	Perl_safe_eval(my_perl, "undef(*);", FALSE);
 	destroy_perl(&my_perl);
 
 	return NULL;
@@ -207,25 +218,25 @@
 			);
 
 	perl_parse(my_perl, xs_init, 3, embedding, NULL);
-	Perl_safe_eval(my_perl, code, TRUE);
+	Perl_safe_eval(my_perl, code, FALSE);
 
 	if (uuid) {
 		switch_snprintf(code, sizeof(code), "$session = new freeswitch::Session(\"%s\")", uuid);
-		Perl_safe_eval(my_perl, code, TRUE);
+		Perl_safe_eval(my_perl, code, FALSE);
 	}
 
 	if (cmd) {
-		Perl_safe_eval(my_perl, cmd, TRUE);
+		Perl_safe_eval(my_perl, cmd, FALSE);
 	}
 
 	stream->write_function(stream, "%s", switch_str_nil(SvPV(get_sv("__OUT", FALSE), n_a)));
 
 	if (uuid) {
 		switch_snprintf(code, sizeof(code), "undef $session;", uuid);
-		Perl_safe_eval(my_perl, code, TRUE);
+		Perl_safe_eval(my_perl, code, FALSE);
 	}
 
-	Perl_safe_eval(my_perl, "undef(*);", TRUE);
+	Perl_safe_eval(my_perl, "undef(*);", FALSE);
 	destroy_perl(&my_perl);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -315,7 +326,7 @@
 						,
 						SWITCH_GLOBAL_dirs.base_dir
 						);
-		Perl_safe_eval(my_perl, code, TRUE);
+		Perl_safe_eval(my_perl, code, FALSE);
 
 		perl_run(my_perl);
 		str = SvPV(get_sv("XML_STRING", FALSE), n_a);

Modified: freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp	(original)
+++ freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp	Sat Apr 26 11:57:05 2008
@@ -3361,7 +3361,7 @@
 XS(_wrap_CoreSession_hangup) {
   {
     CoreSession *arg1 = (CoreSession *) 0 ;
-    char *arg2 = (char *) 0 ;
+    char *arg2 = (char *) "normal_clearing" ;
     void *argp1 = 0 ;
     int res1 = 0 ;
     int res2 ;
@@ -3370,7 +3370,7 @@
     int argvi = 0;
     dXSARGS;
     
-    if ((items < 2) || (items > 2)) {
+    if ((items < 1) || (items > 2)) {
       SWIG_croak("Usage: CoreSession_hangup(self,cause);");
     }
     res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 |  0 );
@@ -3378,11 +3378,13 @@
       SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_hangup" "', argument " "1"" of type '" "CoreSession *""'"); 
     }
     arg1 = reinterpret_cast< CoreSession * >(argp1);
-    res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
-    if (!SWIG_IsOK(res2)) {
-      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_hangup" "', argument " "2"" of type '" "char *""'");
+    if (items > 1) {
+      res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
+      if (!SWIG_IsOK(res2)) {
+        SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_hangup" "', argument " "2"" of type '" "char *""'");
+      }
+      arg2 = reinterpret_cast< char * >(buf2);
     }
-    arg2 = reinterpret_cast< char * >(buf2);
     (arg1)->hangup(arg2);
     
     



More information about the Freeswitch-svn mailing list