[Freeswitch-branches] [commit] r5452 - in freeswitch/branches/greenlizard/src: . include mod/languages/mod_python
Freeswitch SVN
greenlizard at freeswitch.org
Sun Jun 24 13:19:33 EDT 2007
Author: greenlizard
Date: Sun Jun 24 13:19:32 2007
New Revision: 5452
Modified:
freeswitch/branches/greenlizard/src/include/switch_cpp.h
freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py
freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp
freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.c
freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp
freeswitch/branches/greenlizard/src/switch_cpp.cpp
Log:
fix segfault that was happening with originate/bridge due to no valid session in b leg. rename streamfile to streamFile. remove playFile since streamFile does the same thing
Modified: freeswitch/branches/greenlizard/src/include/switch_cpp.h
==============================================================================
--- freeswitch/branches/greenlizard/src/include/switch_cpp.h (original)
+++ freeswitch/branches/greenlizard/src/include/switch_cpp.h Sun Jun 24 13:19:32 2007
@@ -142,29 +142,17 @@
/** \brief Originate a call to a destination
*
- * \param old_session - the session where the call is originating from
- * and also the session in which _this_ session was
- * created
+ * \param a_leg_sessoin - the session where the call is originating from
+ * and also the session in which _this_ session was
+ * created
* \param dest - a string representing destination, eg, sofia/mydomain.com/foo at bar.com
* \return an int status code indicating success or failure
*
*/
- int originate(CoreSession *aleg_session,
+ int originate(CoreSession *a_leg_session,
char *dest,
int timeout=60);
- /** \brief Play a file that resides on disk into the channel
- *
- * \param file - the path to the .wav/.mp3 to be played
- * \param timer_name - ?? does not seem to be used, what is this?
- * \return an int status code indicating success or failure
- *
- * NOTE: if a dtmf callback is installed before calling this
- * function, that callback will be called upon receiving any
- * dtmfs
- */
- int playFile(char *file, char *timer_name);
-
/** \brief set a DTMF callback function
*
@@ -215,7 +203,7 @@
* \return an int status code indicating success or failure
*
*/
- int streamfile(char *file, int starting_sample_count);
+ int streamFile(char *file, int starting_sample_count);
/** \brief flush any pending events
*/
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py Sun Jun 24 13:19:32 2007
@@ -115,14 +115,13 @@
def recordFile(*args): return _freeswitch.CoreSession_recordFile(*args)
def setCallerData(*args): return _freeswitch.CoreSession_setCallerData(*args)
def originate(*args): return _freeswitch.CoreSession_originate(*args)
- def playFile(*args): return _freeswitch.CoreSession_playFile(*args)
def setDTMFCallback(*args): return _freeswitch.CoreSession_setDTMFCallback(*args)
def speak(*args): return _freeswitch.CoreSession_speak(*args)
def set_tts_parms(*args): return _freeswitch.CoreSession_set_tts_parms(*args)
def getDigits(*args): return _freeswitch.CoreSession_getDigits(*args)
def transfer(*args): return _freeswitch.CoreSession_transfer(*args)
def playAndGetDigits(*args): return _freeswitch.CoreSession_playAndGetDigits(*args)
- def streamfile(*args): return _freeswitch.CoreSession_streamfile(*args)
+ def streamFile(*args): return _freeswitch.CoreSession_streamFile(*args)
def flushEvents(*args): return _freeswitch.CoreSession_flushEvents(*args)
def flushDigits(*args): return _freeswitch.CoreSession_flushDigits(*args)
def setAutoHangup(*args): return _freeswitch.CoreSession_setAutoHangup(*args)
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp Sun Jun 24 13:19:32 2007
@@ -175,6 +175,11 @@
bool PySession::begin_allow_threads(void) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "PySession::begin_allow_threads() called\n");
+ if (!session) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No valid session\n");
+ return false;
+ }
+
// swap out threadstate and store in instance variable
switch_channel_t *channel = switch_core_session_get_channel(session);
PyThreadState *swapin_tstate = (PyThreadState *) switch_channel_get_private(channel, "SwapInThreadState");
@@ -196,7 +201,6 @@
}
else {
// currently swapped out
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Threadstate already swapd-out! Skipping\n");
return false;
}
@@ -205,11 +209,15 @@
bool PySession::end_allow_threads(void) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "PySession::end_allow_threads() called\n");
// swap in threadstate from instance variable saved earlier
+ if (!session) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No valid session\n");
+ return false;
+ }
+
switch_channel_t *channel = switch_core_session_get_channel(session);
PyThreadState *swapin_tstate = (PyThreadState *) switch_channel_get_private(channel, "SwapInThreadState");
if (swapin_tstate == NULL) {
// currently swapped in
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Threadstate double swap-in! Skipping\n");
return false;
}
else {
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.c (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.c Sun Jun 24 13:19:32 2007
@@ -177,18 +177,19 @@
// will be null
if (swapin_tstate == NULL) {
// swap it out
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Threadstate mod_python.c swap-out! \n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Threadstate mod_python.c swap-out! \n");
// PyEval_ReleaseThread(cur_tstate);
swapin_tstate = (void *) PyEval_SaveThread();
switch_channel_set_private(channel, "SwapInThreadState", (void *) swapin_tstate);
}
else {
// thread state is already swapped out, so, nothing for us to do
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "according to chan priv data, already swapped out \n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "according to chan priv data, already swapped out \n");
}
}
else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Threadstate mod_python.c swap-out! \n");
+ // they ran python script from cmd line, behave a bit differently (untested)
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Threadstate mod_python.c swap-out! \n");
PyEval_ReleaseThread(tstate);
}
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp Sun Jun 24 13:19:32 2007
@@ -3961,52 +3961,6 @@
}
-SWIGINTERN PyObject *_wrap_CoreSession_playFile(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
- PyObject *resultobj = 0;
- CoreSession *arg1 = (CoreSession *) 0 ;
- char *arg2 = (char *) 0 ;
- char *arg3 = (char *) 0 ;
- int result;
- void *argp1 = 0 ;
- int res1 = 0 ;
- int res2 ;
- char *buf2 = 0 ;
- int alloc2 = 0 ;
- int res3 ;
- char *buf3 = 0 ;
- int alloc3 = 0 ;
- PyObject * obj0 = 0 ;
- PyObject * obj1 = 0 ;
- PyObject * obj2 = 0 ;
-
- if (!PyArg_ParseTuple(args,(char *)"OOO:CoreSession_playFile",&obj0,&obj1,&obj2)) SWIG_fail;
- res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CoreSession, 0 | 0 );
- if (!SWIG_IsOK(res1)) {
- SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_playFile" "', argument " "1"" of type '" "CoreSession *""'");
- }
- arg1 = reinterpret_cast< CoreSession * >(argp1);
- res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
- if (!SWIG_IsOK(res2)) {
- SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_playFile" "', argument " "2"" of type '" "char *""'");
- }
- arg2 = reinterpret_cast< char * >(buf2);
- res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3);
- if (!SWIG_IsOK(res3)) {
- SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CoreSession_playFile" "', argument " "3"" of type '" "char *""'");
- }
- arg3 = reinterpret_cast< char * >(buf3);
- result = (int)(arg1)->playFile(arg2,arg3);
- resultobj = SWIG_From_int(static_cast< int >(result));
- if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
- if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
- return resultobj;
-fail:
- if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
- if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
- return NULL;
-}
-
-
SWIGINTERN PyObject *_wrap_CoreSession_setDTMFCallback(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
CoreSession *arg1 = (CoreSession *) 0 ;
@@ -4405,7 +4359,7 @@
}
-SWIGINTERN PyObject *_wrap_CoreSession_streamfile(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+SWIGINTERN PyObject *_wrap_CoreSession_streamFile(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
CoreSession *arg1 = (CoreSession *) 0 ;
char *arg2 = (char *) 0 ;
@@ -4422,23 +4376,23 @@
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
- if (!PyArg_ParseTuple(args,(char *)"OOO:CoreSession_streamfile",&obj0,&obj1,&obj2)) SWIG_fail;
+ if (!PyArg_ParseTuple(args,(char *)"OOO:CoreSession_streamFile",&obj0,&obj1,&obj2)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CoreSession, 0 | 0 );
if (!SWIG_IsOK(res1)) {
- SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_streamfile" "', argument " "1"" of type '" "CoreSession *""'");
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_streamFile" "', argument " "1"" of type '" "CoreSession *""'");
}
arg1 = reinterpret_cast< CoreSession * >(argp1);
res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
- SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_streamfile" "', argument " "2"" of type '" "char *""'");
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_streamFile" "', argument " "2"" of type '" "char *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
ecode3 = SWIG_AsVal_int(obj2, &val3);
if (!SWIG_IsOK(ecode3)) {
- SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "CoreSession_streamfile" "', argument " "3"" of type '" "int""'");
+ SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "CoreSession_streamFile" "', argument " "3"" of type '" "int""'");
}
arg3 = static_cast< int >(val3);
- result = (int)(arg1)->streamfile(arg2,arg3);
+ result = (int)(arg1)->streamFile(arg2,arg3);
resultobj = SWIG_From_int(static_cast< int >(result));
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
return resultobj;
@@ -5269,14 +5223,13 @@
{ (char *)"CoreSession_recordFile", _wrap_CoreSession_recordFile, METH_VARARGS, NULL},
{ (char *)"CoreSession_setCallerData", _wrap_CoreSession_setCallerData, METH_VARARGS, NULL},
{ (char *)"CoreSession_originate", _wrap_CoreSession_originate, METH_VARARGS, NULL},
- { (char *)"CoreSession_playFile", _wrap_CoreSession_playFile, METH_VARARGS, NULL},
{ (char *)"CoreSession_setDTMFCallback", _wrap_CoreSession_setDTMFCallback, METH_VARARGS, NULL},
{ (char *)"CoreSession_speak", _wrap_CoreSession_speak, METH_VARARGS, NULL},
{ (char *)"CoreSession_set_tts_parms", _wrap_CoreSession_set_tts_parms, METH_VARARGS, NULL},
{ (char *)"CoreSession_getDigits", _wrap_CoreSession_getDigits, METH_VARARGS, NULL},
{ (char *)"CoreSession_transfer", _wrap_CoreSession_transfer, METH_VARARGS, NULL},
{ (char *)"CoreSession_playAndGetDigits", _wrap_CoreSession_playAndGetDigits, METH_VARARGS, NULL},
- { (char *)"CoreSession_streamfile", _wrap_CoreSession_streamfile, METH_VARARGS, NULL},
+ { (char *)"CoreSession_streamFile", _wrap_CoreSession_streamFile, METH_VARARGS, NULL},
{ (char *)"CoreSession_flushEvents", _wrap_CoreSession_flushEvents, METH_VARARGS, NULL},
{ (char *)"CoreSession_flushDigits", _wrap_CoreSession_flushDigits, METH_VARARGS, NULL},
{ (char *)"CoreSession_setAutoHangup", _wrap_CoreSession_setAutoHangup, METH_VARARGS, NULL},
Modified: freeswitch/branches/greenlizard/src/switch_cpp.cpp
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_cpp.cpp (original)
+++ freeswitch/branches/greenlizard/src/switch_cpp.cpp Sun Jun 24 13:19:32 2007
@@ -92,6 +92,7 @@
const switch_application_interface_t *application_interface;
sanity_check_noreturn;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CoreSession::execute. data:%s\n", data);
if ((application_interface = switch_loadable_module_get_application_interface(app))) {
begin_allow_threads();
switch_core_session_exec(session, application_interface, data);
@@ -99,25 +100,6 @@
}
}
-int CoreSession::playFile(char *file, char *timer_name)
-{
- switch_status_t status;
- switch_file_handle_t fh = { 0 };
- sanity_check(-1);
- if (switch_strlen_zero(timer_name)) {
- timer_name = NULL;
- }
- store_file_handle(&fh);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "playFile begin_allow_threads\n");
- begin_allow_threads();
- status = switch_ivr_play_file(session, &fh, file, ap);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "playFile end_allow_threads\n");
- end_allow_threads();
- return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
-
-}
-
-
void CoreSession::setDTMFCallback(void *cbfunc, char *funcargs) {
cb_state.funcargs = funcargs;
@@ -206,6 +188,7 @@
sanity_check(-1);
begin_allow_threads();
status = switch_ivr_session_transfer(session, extension, dialplan, context);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "transfer result: %d\n", status);
end_allow_threads();
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
@@ -241,7 +224,7 @@
}
-int CoreSession::streamfile(char *file, int starting_sample_count) {
+int CoreSession::streamFile(char *file, int starting_sample_count) {
switch_status_t status;
switch_file_handle_t fh = { 0 };
@@ -283,7 +266,7 @@
}
-int CoreSession::originate(CoreSession *aleg_session,
+int CoreSession::originate(CoreSession *a_leg_session,
char *dest,
int timeout)
{
@@ -294,11 +277,15 @@
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
- if (aleg_session != NULL) {
- aleg_core_session = aleg_session->session;
+ if (a_leg_session != NULL) {
+ aleg_core_session = a_leg_session->session;
}
- begin_allow_threads();
+ // this session has no valid switch_core_session_t at this point, and therefore
+ // no valid channel. since the threadstate is stored in the channel, and there
+ // is none, if we try to call begin_alllow_threads it will fail miserably.
+ // use the 'a leg session' to do the thread swapping stuff.
+ a_leg_session->begin_allow_threads();
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
@@ -319,11 +306,11 @@
}
- end_allow_threads();
+ a_leg_session->end_allow_threads();
return SWITCH_STATUS_SUCCESS;
failed:
- end_allow_threads();
+ a_leg_session->end_allow_threads();
return SWITCH_STATUS_FALSE;
}
More information about the Freeswitch-branches
mailing list