make callback stuff work on mod_perl

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8247 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-05-02 13:58:44 +00:00
parent be276e0cfe
commit 2b5f3563a2
7 changed files with 38 additions and 99 deletions

View File

@ -211,47 +211,3 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
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

View File

@ -175,11 +175,6 @@ static void *SWITCH_THREAD_FUNC lua_thread_run(switch_thread_t *thread, void *ob
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) {

View File

@ -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 @@ void Session::setInputCallback(char *cbfunc, char *funcargs) {
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 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
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 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
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;
}

View File

@ -123,10 +123,10 @@ static int perl_parse_and_execute(PerlInterpreter *my_perl, char *input_code, ch
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);

View File

@ -1462,12 +1462,11 @@ SWIG_Perl_SetModule(swig_module_info *module) {
#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_collectDigits) {
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 @@ XS(_wrap_CoreSession_getDigits) {
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 @@ XS(_wrap_CoreSession_getDigits) {
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_event_t = {"_p_switch_event_t", "switch_e
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 @@ static swig_type_info *swig_type_initial[] = {
&_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_event_t[] = { {&_swigt__p_switch_event_t
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 @@ static swig_cast_info *swig_cast_initial[] = {
_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,

View File

@ -154,8 +154,11 @@ SWITCH_DECLARE(bool) Event::fire(void)
}
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::setDTMFCallback(void *cbfunc, char *funcargs)
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);
}
}
}

View File

@ -632,6 +632,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_add_body(switch_event_t *event, con
if (ret == -1) {
return SWITCH_STATUS_GENERR;
} else {
switch_safe_free(event->body);
event->body = data;
return SWITCH_STATUS_SUCCESS;
}