mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-06 04:11:52 +00:00
anti-venom for a nasty python byte
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5098 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "freeswitch_python.h"
|
||||
|
||||
void *globalDTMFCallbackFunction;
|
||||
#define sanity_check(x) do { if (!session) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0)
|
||||
|
||||
SessionContainer::SessionContainer(char *nuuid)
|
||||
{
|
||||
@@ -8,35 +8,25 @@ SessionContainer::SessionContainer(char *nuuid)
|
||||
dtmfCallbackFunction = NULL;
|
||||
tts_name = NULL;
|
||||
voice_name = NULL;
|
||||
if ((session = switch_core_session_locate(uuid))) {
|
||||
switch_core_session_rwunlock(session);
|
||||
channel = switch_core_session_get_channel(session);
|
||||
|
||||
if (session = switch_core_session_locate(uuid)) {
|
||||
channel = switch_core_session_get_channel(session);
|
||||
}
|
||||
}
|
||||
|
||||
SessionContainer::~SessionContainer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SessionContainer::console_log(char *level_str, char *msg)
|
||||
{
|
||||
switch_log_level_t level = SWITCH_LOG_DEBUG;
|
||||
if (level_str) {
|
||||
level = switch_log_str2level(level_str);
|
||||
}
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, level, msg);
|
||||
}
|
||||
|
||||
void SessionContainer::console_clean_log(char *msg)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN,SWITCH_LOG_DEBUG, msg);
|
||||
if (session) {
|
||||
switch_core_session_rwunlock(session);
|
||||
}
|
||||
}
|
||||
|
||||
int SessionContainer::answer()
|
||||
{
|
||||
switch_status_t status;
|
||||
|
||||
|
||||
sanity_check(-1);
|
||||
status = switch_channel_answer(channel);
|
||||
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
||||
}
|
||||
@@ -44,30 +34,34 @@ int SessionContainer::answer()
|
||||
int SessionContainer::pre_answer()
|
||||
{
|
||||
switch_status_t status;
|
||||
|
||||
sanity_check(-1);
|
||||
switch_channel_pre_answer(channel);
|
||||
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
||||
}
|
||||
|
||||
void SessionContainer::hangup(char *cause)
|
||||
{
|
||||
sanity_check();
|
||||
switch_channel_hangup(channel, switch_channel_str2cause(cause));
|
||||
}
|
||||
|
||||
void SessionContainer::set_variable(char *var, char *val)
|
||||
{
|
||||
sanity_check();
|
||||
switch_channel_set_variable(channel, var, val);
|
||||
}
|
||||
|
||||
void SessionContainer::get_variable(char *var, char *val)
|
||||
{
|
||||
sanity_check();
|
||||
switch_channel_get_variable(channel, var);
|
||||
}
|
||||
|
||||
void SessionContainer::set_state(char *state)
|
||||
{
|
||||
switch_channel_state_t current_state = switch_channel_get_state(channel);
|
||||
|
||||
switch_channel_state_t current_state;
|
||||
sanity_check();
|
||||
current_state = switch_channel_get_state(channel);
|
||||
if ((current_state = switch_channel_name_state(state)) < CS_HANGUP) {
|
||||
switch_channel_set_state(channel, current_state);
|
||||
}
|
||||
@@ -76,26 +70,26 @@ void SessionContainer::set_state(char *state)
|
||||
int SessionContainer::play_file(char *file, char *timer_name)
|
||||
{
|
||||
switch_status_t status;
|
||||
switch_input_args_t args = { 0 };
|
||||
switch_input_args_t args = { 0 }, *ap = NULL;
|
||||
sanity_check(-1);
|
||||
|
||||
if (switch_strlen_zero(timer_name)) {
|
||||
timer_name = NULL;
|
||||
}
|
||||
|
||||
if (!dtmfCallbackFunction) {
|
||||
status = switch_ivr_play_file(session, NULL, file, &args);
|
||||
}
|
||||
else {
|
||||
globalDTMFCallbackFunction = dtmfCallbackFunction;
|
||||
if (dtmfCallbackFunction) {
|
||||
args.buf = dtmfCallbackFunction;
|
||||
args.input_callback = PythonDTMFCallback;
|
||||
status = switch_ivr_play_file(session, NULL, file, &args);
|
||||
ap = &args;
|
||||
}
|
||||
|
||||
status = switch_ivr_play_file(session, NULL, file, ap);
|
||||
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
||||
}
|
||||
|
||||
void SessionContainer::set_dtmf_callback(PyObject *pyfunc)
|
||||
{
|
||||
sanity_check();
|
||||
if (!PyCallable_Check(pyfunc)) {
|
||||
dtmfCallbackFunction = NULL;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF function is not a python function.");
|
||||
@@ -109,25 +103,24 @@ int SessionContainer::speak_text(char *text)
|
||||
{
|
||||
switch_status_t status;
|
||||
switch_codec_t *codec;
|
||||
switch_input_args_t args = { 0 };
|
||||
switch_input_args_t args = { 0 }, *ap = NULL;
|
||||
|
||||
sanity_check(-1);
|
||||
|
||||
codec = switch_core_session_get_read_codec(session);
|
||||
if (!dtmfCallbackFunction) {
|
||||
status = switch_ivr_speak_text(session, tts_name, voice_name,
|
||||
codec->implementation->samples_per_second, text, &args);
|
||||
}
|
||||
else {
|
||||
globalDTMFCallbackFunction = dtmfCallbackFunction;
|
||||
if (dtmfCallbackFunction) {
|
||||
args.buf = dtmfCallbackFunction;
|
||||
args.input_callback = PythonDTMFCallback;
|
||||
status = switch_ivr_speak_text(session, tts_name, voice_name,
|
||||
codec->implementation->samples_per_second, text, &args);
|
||||
ap = &args;
|
||||
}
|
||||
|
||||
status = switch_ivr_speak_text(session, tts_name, voice_name, codec->implementation->samples_per_second, text, ap);
|
||||
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
||||
}
|
||||
|
||||
void SessionContainer::set_tts_parms(char *tts_name_p, char *voice_name_p)
|
||||
{
|
||||
sanity_check();
|
||||
tts_name = tts_name_p;
|
||||
voice_name = voice_name_p;
|
||||
}
|
||||
@@ -135,7 +128,7 @@ void SessionContainer::set_tts_parms(char *tts_name_p, char *voice_name_p)
|
||||
int SessionContainer::get_digits(char *dtmf_buf, int len, char *terminators, char *terminator, int timeout)
|
||||
{
|
||||
switch_status_t status;
|
||||
|
||||
sanity_check(-1);
|
||||
status = switch_ivr_collect_digits_count(session, dtmf_buf,(uint32_t) len,(uint32_t) len, terminators, terminator, (uint32_t) timeout);
|
||||
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
||||
}
|
||||
@@ -143,7 +136,7 @@ int SessionContainer::get_digits(char *dtmf_buf, int len, char *terminators, cha
|
||||
int SessionContainer::transfer(char *extension, char *dialplan, char *context)
|
||||
{
|
||||
switch_status_t status;
|
||||
|
||||
sanity_check(-1);
|
||||
status = switch_ivr_session_transfer(session, extension, dialplan, context);
|
||||
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
||||
}
|
||||
@@ -152,7 +145,7 @@ int SessionContainer::play_and_get_digits(int min_digits, int max_digits, int ma
|
||||
char *audio_files, char *bad_input_audio_files, char *dtmf_buf, char *digits_regex)
|
||||
{
|
||||
switch_status_t status;
|
||||
|
||||
sanity_check(-1);
|
||||
status = switch_play_and_get_digits( session, (uint32_t) min_digits,(uint32_t) max_digits,
|
||||
(uint32_t) max_tries, (uint32_t) timeout,
|
||||
terminators, audio_files, bad_input_audio_files, dtmf_buf, 128, digits_regex);
|
||||
|
||||
Reference in New Issue
Block a user