[Freeswitch-svn] [commit] r8247 - in freeswitch/trunk/src: . mod/languages/mod_lua mod/languages/mod_perl

Freeswitch SVN anthm at freeswitch.org
Fri May 2 09:58:45 EDT 2008


Author: anthm
Date: Fri May  2 09:58:44 2008
New Revision: 8247

Modified:
   freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.cpp
   freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.c
   freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.cpp
   freeswitch/trunk/src/mod/languages/mod_perl/mod_perl.c
   freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp
   freeswitch/trunk/src/switch_cpp.cpp
   freeswitch/trunk/src/switch_event.c

Log:
make callback stuff work on mod_perl

Modified: freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.cpp	(original)
+++ freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.cpp	Fri May  2 09:58:44 2008
@@ -211,47 +211,3 @@
 
 	return SWITCH_STATUS_SUCCESS;
 }
-
-
-#if 0
-int Session::answer() {}
-int Session::preAnswer() {}
-void Session::hangup(char *cause) {}
-void Session::setVariable(char *var, char *val) {}
-const char *Session::getVariable(char *var) {}
-int Session::recordFile(char *file_name, int max_len, int silence_threshold, int silence_secs) {}
-void Session::setCallerData(char *var, char *val) {}
-int Session::originate(CoreSession *a_leg_session, char *dest, int timeout) {}
-void Session::setDTMFCallback(void *cbfunc, char *funcargs) {}
-int Session::speak(char *text) {}
-void Session::set_tts_parms(char *tts_name, char *voice_name) {}
-int Session::collectDigits(int timeout) {}
-int Session::getDigits(char *dtmf_buf, 
-			  switch_size_t buflen, 
-			  switch_size_t maxdigits, 
-			  char *terminators, 
-			  char *terminator, 
-			  int timeout) {}
-
-int Session::transfer(char *extensions, char *dialplan, char *context) {}
-int Session::playAndGetDigits(int min_digits, 
-					 int max_digits, 
-					 int max_tries, 
-					 int timeout, 
-					 char *terminators,
-					 char *audio_files, 
-					 char *bad_input_audio_files, 
-					 char *dtmf_buf, 
-					 char *digits_regex) {}
-
-int Session::streamFile(char *file, int starting_sample_count) {}
-int Session::flushEvents() {}
-int Session::flushDigits() {}
-int Session::setAutoHangup(bool val) {}
-void Session::setHangupHook(void *hangup_func) {}
-bool Session::ready() {}
-void Session::execute(char *app, char *data) {}
-char* Session::get_uuid() {}
-const switch_input_args_t& Session::get_cb_args() {}
-
-#endif

Modified: freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.c	Fri May  2 09:58:44 2008
@@ -175,11 +175,6 @@
 	char *input_code = (char *) obj;
 	lua_State *L = lua_init();	 /* opens Lua */
 
-	//switch_event_t *event;
-	//switch_event_create(&event, SWITCH_EVENT_MESSAGE);
-	//switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "testing", "1234");
-	//mod_lua_conjure_event(L, event, "blah");
-
 	lua_parse_and_execute(L, input_code);
 	
 	if (input_code) {

Modified: freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.cpp	(original)
+++ freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.cpp	Fri May  2 09:58:44 2008
@@ -4,22 +4,21 @@
 
 static STRLEN n_a;
 
+#define init_me() cb_function = hangup_func_str = NULL; hh = mark = 0; my_perl = NULL; cb_arg = NULL
+
 Session::Session() : CoreSession()
 {
-	cb_function = cb_arg = hangup_func_str = NULL;
-	hh = mark = 0;
+	init_me();
 }
 
 Session::Session(char *uuid) : CoreSession(uuid)
 {
-	cb_function = cb_arg = hangup_func_str = NULL;
-	hh = mark = 0;
+	init_me();
 }
 
 Session::Session(switch_core_session_t *new_session) : CoreSession(new_session)
 {
-	cb_function = cb_arg = hangup_func_str = NULL;
-	hh = mark = 0;
+	init_me();
 }
 static switch_status_t perl_hanguphook(switch_core_session_t *session_hungup);
 Session::~Session()
@@ -143,8 +142,6 @@
 
 switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t itype) 
 {
-	const char *ret;
-
 	if (!getPERL()) {
 		return SWITCH_STATUS_FALSE;;
 	}
@@ -173,15 +170,11 @@
 			sv_setpv(this_sv, str);
 			hv_store(hash, "duration", 8, this_sv, 0);			
 
-			if (cb_arg) {
-				//this_sv = get_sv(cb_arg, TRUE); DOH!
-			}
-			
-			code = switch_mprintf("%s('dtmf', \\%__dtmf, %s);", cb_function, switch_str_nil(cb_arg));
-			Perl_eval_pv(my_perl, code, TRUE);
+			code = switch_mprintf("$__RV = %s('dtmf', \\%%__dtmf, %s);", cb_function, switch_str_nil(cb_arg));
+			Perl_eval_pv(my_perl, code, FALSE);
 			free(code);
 
-			return process_callback_result(SvPV(get_sv(cb_function, FALSE), n_a));
+			return process_callback_result(SvPV(get_sv("__RV", TRUE), n_a));
 		}
 		break;
     case SWITCH_INPUT_TYPE_EVENT:
@@ -192,12 +185,11 @@
 
 			mod_perl_conjure_event(my_perl, event, "__Input_Event__");
 			
-			code = switch_mprintf("%s('event', $__Input_Event__, %s);", cb_function, switch_str_nil(cb_arg));
+			code = switch_mprintf("$__RV = %s('event', $__Input_Event__, %s);", cb_function, switch_str_nil(cb_arg));
 			Perl_eval_pv(my_perl, code, TRUE);
 			free(code);
 			
-			
-            return process_callback_result((char *)ret);			
+			return process_callback_result(SvPV(get_sv("__RV", TRUE), n_a));
 		}
 		break;
 	}

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	Fri May  2 09:58:44 2008
@@ -123,10 +123,10 @@
 			char *file = input_code;
 			
 			if (!switch_is_file_path(file)) {
-				file = switch_mprintf("require '%s/%s';\n", SWITCH_GLOBAL_dirs.script_dir, file);
+				file = switch_mprintf("do '%s/%s';\n", SWITCH_GLOBAL_dirs.script_dir, file);
 				switch_assert(file);
 			} else {
-				file = switch_mprintf("require '%s';\n", file);
+				file = switch_mprintf("do '%s';\n", file);
 				switch_assert(file);
 			}
 			error = Perl_safe_eval(my_perl, file);

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	Fri May  2 09:58:44 2008
@@ -1462,12 +1462,11 @@
 #define SWIGTYPE_p_switch_input_args_t swig_types[13]
 #define SWIGTYPE_p_switch_input_type_t swig_types[14]
 #define SWIGTYPE_p_switch_priority_t swig_types[15]
-#define SWIGTYPE_p_switch_size_t swig_types[16]
-#define SWIGTYPE_p_switch_status_t swig_types[17]
-#define SWIGTYPE_p_switch_stream_handle_t swig_types[18]
-#define SWIGTYPE_p_void swig_types[19]
-static swig_type_info *swig_types[21];
-static swig_module_info swig_module = {swig_types, 20, 0, 0, 0, 0};
+#define SWIGTYPE_p_switch_status_t swig_types[16]
+#define SWIGTYPE_p_switch_stream_handle_t swig_types[17]
+#define SWIGTYPE_p_void swig_types[18]
+static swig_type_info *swig_types[20];
+static swig_module_info swig_module = {swig_types, 19, 0, 0, 0, 0};
 #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
 #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
 
@@ -5224,15 +5223,15 @@
 XS(_wrap_CoreSession_getDigits) {
   {
     CoreSession *arg1 = (CoreSession *) 0 ;
-    switch_size_t arg2 ;
+    int arg2 ;
     char *arg3 = (char *) 0 ;
     char *arg4 = (char *) 0 ;
     int arg5 ;
     char *result = 0 ;
     void *argp1 = 0 ;
     int res1 = 0 ;
-    void *argp2 ;
-    int res2 = 0 ;
+    int val2 ;
+    int ecode2 = 0 ;
     int res3 ;
     char *buf3 = 0 ;
     int alloc3 = 0 ;
@@ -5252,17 +5251,11 @@
       SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_getDigits" "', argument " "1"" of type '" "CoreSession *""'"); 
     }
     arg1 = reinterpret_cast< CoreSession * >(argp1);
-    {
-      res2 = SWIG_ConvertPtr(ST(1), &argp2, SWIGTYPE_p_switch_size_t,  0 );
-      if (!SWIG_IsOK(res2)) {
-        SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_getDigits" "', argument " "2"" of type '" "switch_size_t""'"); 
-      }  
-      if (!argp2) {
-        SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "CoreSession_getDigits" "', argument " "2"" of type '" "switch_size_t""'");
-      } else {
-        arg2 = *(reinterpret_cast< switch_size_t * >(argp2));
-      }
-    }
+    ecode2 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(1), &val2);
+    if (!SWIG_IsOK(ecode2)) {
+      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "CoreSession_getDigits" "', argument " "2"" of type '" "int""'");
+    } 
+    arg2 = static_cast< int >(val2);
     res3 = SWIG_AsCharPtrAndSize(ST(2), &buf3, NULL, &alloc3);
     if (!SWIG_IsOK(res3)) {
       SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CoreSession_getDigits" "', argument " "3"" of type '" "char *""'");
@@ -5281,12 +5274,14 @@
     result = (char *)(arg1)->getDigits(arg2,arg3,arg4,arg5);
     ST(argvi) = SWIG_FromCharPtr((const char *)result); argvi++ ;
     
+    
     if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
     if (alloc4 == SWIG_NEWOBJ) delete[] buf4;
     
     XSRETURN(argvi);
   fail:
     
+    
     if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
     if (alloc4 == SWIG_NEWOBJ) delete[] buf4;
     
@@ -6982,7 +6977,6 @@
 static swig_type_info _swigt__p_switch_input_args_t = {"_p_switch_input_args_t", "switch_input_args_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_input_type_t = {"_p_switch_input_type_t", "switch_input_type_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_priority_t = {"_p_switch_priority_t", "switch_priority_t *", 0, 0, (void*)0, 0};
-static swig_type_info _swigt__p_switch_size_t = {"_p_switch_size_t", "switch_size_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_status_t = {"_p_switch_status_t", "switch_status_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_stream_handle_t = {"_p_switch_stream_handle_t", "switch_stream_handle_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_void = {"_p_void", "void *", 0, 0, (void*)0, 0};
@@ -7004,7 +6998,6 @@
   &_swigt__p_switch_input_args_t,
   &_swigt__p_switch_input_type_t,
   &_swigt__p_switch_priority_t,
-  &_swigt__p_switch_size_t,
   &_swigt__p_switch_status_t,
   &_swigt__p_switch_stream_handle_t,
   &_swigt__p_void,
@@ -7026,7 +7019,6 @@
 static swig_cast_info _swigc__p_switch_input_args_t[] = {  {&_swigt__p_switch_input_args_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_input_type_t[] = {  {&_swigt__p_switch_input_type_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_priority_t[] = {  {&_swigt__p_switch_priority_t, 0, 0, 0},{0, 0, 0, 0}};
-static swig_cast_info _swigc__p_switch_size_t[] = {  {&_swigt__p_switch_size_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_status_t[] = {  {&_swigt__p_switch_status_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_stream_handle_t[] = {  {&_swigt__p_switch_stream_handle_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_void[] = {  {&_swigt__p_void, 0, 0, 0},{0, 0, 0, 0}};
@@ -7048,7 +7040,6 @@
   _swigc__p_switch_input_args_t,
   _swigc__p_switch_input_type_t,
   _swigc__p_switch_priority_t,
-  _swigc__p_switch_size_t,
   _swigc__p_switch_status_t,
   _swigc__p_switch_stream_handle_t,
   _swigc__p_void,

Modified: freeswitch/trunk/src/switch_cpp.cpp
==============================================================================
--- freeswitch/trunk/src/switch_cpp.cpp	(original)
+++ freeswitch/trunk/src/switch_cpp.cpp	Fri May  2 09:58:44 2008
@@ -154,8 +154,11 @@
 	}
 
 	if (event) {
-		switch_event_fire(&event);
-		return true;
+		switch_event_t *new_event;
+		if (switch_event_dup(&new_event, event) == SWITCH_STATUS_SUCCESS) {
+			switch_event_fire(&new_event);
+			return true;
+		}
 	}
 	return false;
 }
@@ -416,10 +419,11 @@
 
 SWITCH_DECLARE(void) CoreSession::sendEvent(Event *sendME)
 {
-	if (sendME->mine) {
-		switch_core_session_receive_event(session, &sendME->event);
-	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Not My event!\n");
+	if (sendME->event) {
+		switch_event_t *new_event;
+		if (switch_event_dup(&new_event, sendME->event) == SWITCH_STATUS_SUCCESS) {
+			switch_core_session_receive_event(session, &new_event);
+		}
 	}
 }
 

Modified: freeswitch/trunk/src/switch_event.c
==============================================================================
--- freeswitch/trunk/src/switch_event.c	(original)
+++ freeswitch/trunk/src/switch_event.c	Fri May  2 09:58:44 2008
@@ -632,6 +632,7 @@
 		if (ret == -1) {
 			return SWITCH_STATUS_GENERR;
 		} else {
+			switch_safe_free(event->body);
 			event->body = data;
 			return SWITCH_STATUS_SUCCESS;
 		}



More information about the Freeswitch-svn mailing list