git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8214 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-04-29 23:34:26 +00:00
parent f2994a09f8
commit 5952667987
14 changed files with 2999 additions and 586 deletions

View File

@ -11,6 +11,11 @@ extern "C" {
#include <switch.h>
#define sanity_check(x) do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0)
#define sanity_check_noreturn do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return;}} while(0)
#define init_vars() do { session = NULL; channel = NULL; uuid = NULL; tts_name = NULL; voice_name = NULL; memset(&args, 0, sizeof(args)); ap = NULL; caller_profile.source = "mod_unknown"; caller_profile.dialplan = ""; caller_profile.context = ""; caller_profile.caller_id_name = ""; caller_profile.caller_id_number = ""; caller_profile.network_addr = ""; caller_profile.ani = ""; caller_profile.aniii = ""; caller_profile.rdnis = ""; caller_profile.username = ""; on_hangup = NULL; memset(&cb_state, 0, sizeof(cb_state)); hook_state = CS_NEW; } while(0)
//
// C++ Interface: switch_to_cpp_mempool
//
@ -62,19 +67,6 @@ char *api_execute(char *cmd, char *arg);
void api_reply_delete(char *reply);
/**
* \brief - process language specific callback results
*
* First the actual callback is called, (in the case of python,
* PythonDTMFCallback), it then calls the language specific callback defined
* by the user (eg, some python method), and then _this_ function is called
* with the results of the language specific callback.
*/
switch_status_t process_callback_result(char *raw_result,
struct input_callback_state *cb_state,
switch_core_session_t *session);
typedef struct input_callback_state {
void *function; // pointer to the language specific callback function
// eg, PyObject *pyfunc
@ -105,10 +97,15 @@ class Stream {
class Event {
protected:
switch_event_t *event;
public:
switch_event_t *event;
char *serialized_string;
int mine;
Event(const char *type, const char *subclass_name = NULL);
Event(switch_event_t *wrap_me, int free_me=0);
virtual ~Event();
const char *serialize(const char *format=NULL);
bool set_priority(switch_priority_t priority = SWITCH_PRIORITY_NORMAL);
char *get_header(char *header_name);
char *get_body(void);
@ -131,8 +128,9 @@ class CoreSession {
char *voice_name;
void store_file_handle(switch_file_handle_t *fh);
void *on_hangup; // language specific callback function, cast as void *
switch_file_handle_t local_fh;
switch_file_handle_t *fhp;
switch_status_t process_callback_result(char *ret);
public:
CoreSession();
CoreSession(char *uuid);
@ -150,6 +148,8 @@ class CoreSession {
int preAnswer();
virtual void hangup(char *cause = "normal_clearing");
void setVariable(char *var, char *val);
void setPrivate(char *var, void *val);
void *getPrivate(char *var);
const char *getVariable(char *var);
@ -193,7 +193,6 @@ class CoreSession {
*/
void setDTMFCallback(void *cbfunc, char *funcargs);
int speak(char *text);
void set_tts_parms(char *tts_name, char *voice_name);
@ -265,6 +264,9 @@ class CoreSession {
bool ready();
void execute(char *app, char *data);
void sendEvent(Event *sendME);
virtual bool begin_allow_threads() = 0;
virtual bool end_allow_threads() = 0;

View File

@ -3,12 +3,12 @@ LOCAL_CFLAGS=-Ilua
LIBLUA_A=lua/liblua.a
LOCAL_LIBADD=$(LIBLUA_A)
LOCAL_LDFLAGS=-lm
LOCAL_OBJS=freeswitch_lua.o mod_lua_wrap.o #glua.o
LOCAL_OBJS=freeswitch_lua.o mod_lua_wrap.o
VERBOSE=1
include $(BASE)/build/modmake.rules
glua.o: mod_lua_wrap.cpp
local_depend: $(LOCAL_OBJS)
$(LIBLUA_A):
cd lua && $(MAKE) CFLAGS="$(ALL_CFLAGS) -DLUA_USE_LINUX -w" liblua.a
@ -16,14 +16,18 @@ $(LIBLUA_A):
luaclean:
cd lua && $(MAKE) clean
freeswitch_lua.o: freeswitch_lua.h
allclean: clean luaclean
rm -f mod_lua_wrap.* freeswitch_lua.$(DYNAMIC_LIB_EXTEN)
swigclean:
rm mod_lua_wrap.*
mod_lua_wrap.cpp:
mod_lua_wrap.cpp: mod_lua_extra.c
swig -lua -c++ -I../../../../src/include -oh mod_lua_wrap.h -o mod_lua_wrap.cpp freeswitch.i
echo "#include \"mod_lua_extra.c\"" >> mod_lua_wrap.cpp
patch -s -p0 -i hack.diff
freeswitch_lua.$(DYNAMIC_LIB_EXTEN): $(LOCAL_OBJS) $(LOCAL_LIBADD)
$(LINK) $(SOLINK) -o freeswitch_lua.$(DYNAMIC_LIB_EXTEN) $(LOCAL_OBJS) $(LOCAL_LIBADD) $(LDFLAGS)

View File

@ -1,23 +1,34 @@
#include "freeswitch_lua.h"
SWITCH_BEGIN_EXTERN_C
#include "lua.h"
#include <lauxlib.h>
#include <lualib.h>
#include "mod_lua_extra.h"
SWITCH_END_EXTERN_C
Session::Session() : CoreSession()
{
cb_function = cb_arg = hangup_func_str = NULL;
}
Session::Session(char *uuid) : CoreSession(uuid)
{
cb_function = cb_arg = hangup_func_str = NULL;
}
Session::Session(switch_core_session_t *new_session) : CoreSession(new_session)
{
cb_function = cb_arg = hangup_func_str = NULL;
}
static switch_status_t lua_hanguphook(switch_core_session_t *session_hungup);
Session::~Session()
{
switch_safe_free(cb_function);
switch_safe_free(cb_arg);
switch_safe_free(hangup_func_str);
switch_core_event_hook_remove_state_change(session, lua_hanguphook);
}
@ -33,13 +44,147 @@ bool Session::end_allow_threads()
void Session::check_hangup_hook()
{
if (hangup_func_str && (hook_state == CS_HANGUP || hook_state == CS_RING)) {
lua_State *L;
L = (lua_State *) getPrivate("__L");
if (!L) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
return;
}
lua_getfield(L, LUA_GLOBALSINDEX, (char *)hangup_func_str);
lua_pushstring(L, hook_state == CS_HANGUP ? "hangup" : "transfer");
lua_call(L, 1, 0);
}
}
static switch_status_t lua_hanguphook(switch_core_session_t *session_hungup)
{
switch_channel_t *channel = switch_core_session_get_channel(session_hungup);
CoreSession *coresession = NULL;
switch_channel_state_t state = switch_channel_get_state(channel);
if ((coresession = (CoreSession *) switch_channel_get_private(channel, "CoreSession"))) {
if (coresession->hook_state != state) {
coresession->hook_state = state;
coresession->check_hangup_hook();
}
}
return SWITCH_STATUS_SUCCESS;
}
void Session::setHangupHook(char *func) {
sanity_check_noreturn;
switch_safe_free(hangup_func_str);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Not Currently Available\n");
func = NULL;
if (func) {
hangup_func_str = strdup(func);
switch_channel_set_private(channel, "CoreSession", this);
hook_state = switch_channel_get_state(channel);
switch_core_event_hook_add_state_change(session, lua_hanguphook);
}
}
void Session::setInputCallback(char *cbfunc, char *funcargs) {
sanity_check_noreturn;
switch_safe_free(cb_function);
if (cbfunc) {
cb_function = strdup(cbfunc);
}
switch_safe_free(cb_arg);
if (funcargs) {
cb_arg = strdup(funcargs);
}
args.buf = this;
switch_channel_set_private(channel, "CoreSession", this);
args.input_callback = dtmf_callback;
ap = &args;
}
switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t itype)
{
lua_State *L;
const char *ret;
L = (lua_State *) getPrivate("__L");
if (!L) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
return SWITCH_STATUS_FALSE;
}
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF:
{
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
char str[2] = "";
int arg_count = 2;
lua_getfield(L, LUA_GLOBALSINDEX, (char *)cb_function);
lua_pushstring(L, "dtmf");
lua_newtable(L);
lua_pushstring(L, "digit");
str[0] = dtmf->digit;
lua_pushstring(L, str);
lua_rawset(L, -3);
lua_pushstring(L, "duration");
lua_pushnumber(L, dtmf->duration);
lua_rawset(L, -3);
if (cb_arg) {
lua_getfield(L, LUA_GLOBALSINDEX, (char *)cb_arg);
arg_count++;
}
lua_call(L, arg_count, 1);
ret = lua_tostring(L, -1);
lua_pop(L, 1);
return process_callback_result((char *)ret);
}
break;
case SWITCH_INPUT_TYPE_EVENT:
{
switch_event_t *event = (switch_event_t *) input;
int arg_count = 2;
lua_getfield(L, LUA_GLOBALSINDEX, (char *)cb_function);
lua_pushstring(L, "event");
mod_lua_conjure_event(L, event, "__Input_Event__", 1);
lua_getfield(L, LUA_GLOBALSINDEX, "__Input_Event__");
if (cb_arg) {
lua_getfield(L, LUA_GLOBALSINDEX, (char *)cb_arg);
arg_count++;
}
lua_call(L, 2, 1);
ret = lua_tostring(L, -1);
lua_pop(L, 1);
return process_callback_result((char *)ret);
}
break;
}
return SWITCH_STATUS_SUCCESS;
}
#if 0
int Session::answer() {}

View File

@ -1,5 +1,5 @@
#ifndef FREESWITCH_PYTHON_H
#define FREESWITCH_PYTHON_H
#ifndef FREESWITCH_LUA_H
#define FREESWITCH_LUA_H
#include <switch_cpp.h>
@ -10,7 +10,6 @@ void api_reply_delete(char *reply);
class Session : public CoreSession {
private:
public:
Session();
Session(char *uuid);
@ -21,58 +20,12 @@ class Session : public CoreSession {
virtual bool end_allow_threads();
virtual void check_hangup_hook();
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
void setInputCallback(char *cbfunc, char *funcargs);
void setHangupHook(char *func);
switch_core_session_t *session;
switch_channel_t *channel;
unsigned int flags;
int allocated;
input_callback_state cb_state; // callback state, always pointed to by the buf
// field in this->args
switch_channel_state_t hook_state; // store hookstate for on_hangup callback
#if 0
int answer();
int preAnswer();
virtual void hangup(char *cause);
void setVariable(char *var, char *val);
const char *getVariable(char *var);
int recordFile(char *file_name, int max_len=0, int silence_threshold=0, int silence_secs=0);
void setCallerData(char *var, char *val);
int originate(CoreSession *a_leg_session, char *dest, int timeout=60);
void setDTMFCallback(void *cbfunc, char *funcargs);
int speak(char *text);
void set_tts_parms(char *tts_name, char *voice_name);
int collectDigits(int timeout);
int getDigits(char *dtmf_buf,
switch_size_t buflen,
switch_size_t maxdigits,
char *terminators,
char *terminator,
int timeout);
int transfer(char *extensions, char *dialplan, char *context);
int 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 streamFile(char *file, int starting_sample_count=0);
int flushEvents();
int flushDigits();
int setAutoHangup(bool val);
void setHangupHook(void *hangup_func);
bool ready();
void execute(char *app, char *data);
char* get_uuid();
const switch_input_args_t& get_cb_args();
#endif
char *cb_function;
char *cb_arg;
char *hangup_func_str;
};
#endif

View File

@ -0,0 +1,29 @@
--- hack.cpp 2008-04-29 13:49:22.000000000 -0400
+++ mod_lua_wrap.cpp 2008-04-29 13:49:10.000000000 -0400
@@ -4028,7 +4028,7 @@
SWIG_check_num_args("Session",0,0)
result = (Session *)new Session();
SWIG_arg=0;
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++;
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setPrivate("__L", L);
return SWIG_arg;
if(0) SWIG_fail;
@@ -4049,7 +4049,7 @@
arg1 = (char *)lua_tostring(L, 1);
result = (Session *)new Session(arg1);
SWIG_arg=0;
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++;
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setPrivate("__L", L);
return SWIG_arg;
if(0) SWIG_fail;
@@ -4074,7 +4074,7 @@
result = (Session *)new Session(arg1);
SWIG_arg=0;
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++;
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setPrivate("__L", L);
return SWIG_arg;
if(0) SWIG_fail;

File diff suppressed because it is too large Load Diff

View File

@ -33,16 +33,27 @@
#include "lua.h"
#include <lauxlib.h>
#include <lualib.h>
#include "mod_lua_extra.h"
SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load);
SWITCH_MODULE_DEFINITION(mod_lua, mod_lua_load, NULL, NULL);
static struct {
switch_memory_pool_t *pool;
char *xml_handler;
} globals;
int luaopen_freeswitch(lua_State* L);
static int panic (lua_State *L)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "unprotected error in call to Lua API (%s)\n",
lua_tostring(L, -1));
return 0;
}
static lua_State *lua_init(void)
{
lua_State *L = lua_open();
@ -51,6 +62,7 @@ static lua_State *lua_init(void)
luaL_openlibs(L);
luaopen_freeswitch(L);
lua_gc(L, LUA_GCRESTART, 0);
lua_atpanic(L, panic);
}
return L;
}
@ -144,6 +156,11 @@ 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) {
@ -155,6 +172,96 @@ static void *SWITCH_THREAD_FUNC lua_thread_run(switch_thread_t *thread, void *ob
return NULL;
}
static switch_xml_t lua_fetch(const char *section,
const char *tag_name,
const char *key_name,
const char *key_value,
switch_event_t *params,
void *user_data)
{
switch_xml_t xml = NULL;
if (!switch_strlen_zero(globals.xml_handler)) {
lua_State *L = lua_init();
char *mycmd = strdup(globals.xml_handler);
const char *str;
switch_assert(mycmd);
lua_newtable(L);
lua_pushstring(L, "section");
lua_pushstring(L, switch_str_nil(section));
lua_rawset(L, -3);
lua_pushstring(L, "tag_name");
lua_pushstring(L, switch_str_nil(tag_name));
lua_rawset(L, -3);
lua_pushstring(L, "key_name");
lua_pushstring(L, switch_str_nil(key_name));
lua_rawset(L, -3);
lua_pushstring(L, "key_value");
lua_pushstring(L, switch_str_nil(key_value));
lua_rawset(L, -3);
lua_setglobal(L, "XML_REQUEST");
if (params) {
mod_lua_conjure_event(L, params, "params", 1);
}
lua_parse_and_execute(L, mycmd);
lua_getfield(L, LUA_GLOBALSINDEX, "XML_STRING");
str = lua_tostring(L, 1);
if (str) {
if (switch_strlen_zero(str)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Result\n");
} else if (!(xml = switch_xml_parse_str((char *)str, strlen(str)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing XML Result!\n");
}
}
lua_uninit(L);
free(mycmd);
}
return xml;
}
static switch_status_t do_config(void)
{
char *cf = "lua.conf";
switch_xml_t cfg, xml, settings, param;
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
}
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcmp(var, "xml-handler-script")) {
globals.xml_handler = switch_core_strdup(globals.pool, val);
} else if (!strcmp(var, "xml-handler-bindings")) {
if (!switch_strlen_zero(globals.xml_handler)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "binding '%s' to '%s'\n", globals.xml_handler, val);
switch_xml_bind_search_function(lua_fetch, switch_xml_parse_section_string(val), NULL);
}
}
}
}
switch_xml_free(xml);
return SWITCH_STATUS_SUCCESS;
}
int lua_thread(const char *text)
{
switch_thread_t *thread;
@ -172,20 +279,36 @@ SWITCH_STANDARD_APP(lua_function)
{
lua_State *L = lua_init();
char code[1024] = "";
snprintf(code, sizeof(code), "~session = LUASession:new(\"%s\");", switch_core_session_get_uuid(session));
snprintf(code, sizeof(code), "~session = freeswitch.Session(\"%s\");", switch_core_session_get_uuid(session));
lua_parse_and_execute(L, code);
lua_parse_and_execute(L, (char *) data);
snprintf(code, sizeof(code), "~session:delete()");
lua_parse_and_execute(L, code);
lua_uninit(L);
}
SWITCH_STANDARD_API(lua_api_function) {
SWITCH_STANDARD_API(luarun_api_function) {
lua_thread(cmd);
stream->write_function(stream, "+OK\n");
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(lua_api_function) {
lua_State *L = lua_init();
char *mycmd = strdup(cmd);
switch_assert(mycmd);
mod_lua_conjure_stream(L, stream, "stream", 1);
if (stream->event) {
mod_lua_conjure_event(L, stream->event, "env", 1);
}
lua_parse_and_execute(L, mycmd);
lua_uninit(L);
free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load)
{
switch_api_interface_t *api_interface;
@ -194,12 +317,14 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load)
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_API(api_interface, "luarun", "run a script", lua_api_function, "<script>");
SWITCH_ADD_API(api_interface, "luarun", "run a script", luarun_api_function, "<script>");
SWITCH_ADD_API(api_interface, "lua", "run a script as an api function", lua_api_function, "<script>");
SWITCH_ADD_APP(app_interface, "lua", "Launch LUA ivr", "Run a lua ivr on a channel", lua_function, "<script>", SAF_SUPPORT_NOMEDIA);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
globals.pool = pool;
do_config();
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;

View File

@ -0,0 +1,21 @@
SWITCH_BEGIN_EXTERN_C
int mod_lua_conjure_event(lua_State *L, switch_event_t *event, const char *name, int destroy_me)
{
Event *result = new Event(event);
SWIG_NewPointerObj(L,result,SWIGTYPE_p_Event, destroy_me);
lua_setglobal(L, name);
}
int mod_lua_conjure_stream(lua_State *L, switch_stream_handle_t *stream, const char *name, int destroy_me)
{
Stream *result = new Stream(stream);
SWIG_NewPointerObj(L,result,SWIGTYPE_p_Stream, destroy_me);
lua_setglobal(L, name);
}
SWITCH_END_EXTERN_C

View File

@ -0,0 +1,9 @@
#ifndef MOD_LUA_EXTRA
#define MOD_LUA_EXTRA
SWITCH_BEGIN_EXTERN_C
int mod_lua_conjure_event(lua_State *L, switch_event_t *event, const char *name, int destroy_me);
int mod_lua_conjure_stream(lua_State *L, switch_stream_handle_t *stream, const char *name, int destroy_me);
SWITCH_END_EXTERN_C
#endif

File diff suppressed because it is too large Load Diff

View File

@ -52,7 +52,6 @@ package freeswitch;
*console_clean_log = *freeswitchc::console_clean_log;
*api_execute = *freeswitchc::api_execute;
*api_reply_delete = *freeswitchc::api_reply_delete;
*process_callback_result = *freeswitchc::process_callback_result;
*bridge = *freeswitchc::bridge;
*hanguphook = *freeswitchc::hanguphook;
*dtmf_callback = *freeswitchc::dtmf_callback;
@ -148,6 +147,12 @@ use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
@ISA = qw( freeswitch );
%OWNER = ();
%ITERATORS = ();
*swig_event_get = *freeswitchc::Event_event_get;
*swig_event_set = *freeswitchc::Event_event_set;
*swig_serialized_string_get = *freeswitchc::Event_serialized_string_get;
*swig_serialized_string_set = *freeswitchc::Event_serialized_string_set;
*swig_mine_get = *freeswitchc::Event_mine_get;
*swig_mine_set = *freeswitchc::Event_mine_set;
sub new {
my $pkg = shift;
my $self = freeswitchc::new_Event(@_);
@ -165,6 +170,7 @@ sub DESTROY {
}
}
*serialize = *freeswitchc::Event_serialize;
*set_priority = *freeswitchc::Event_set_priority;
*get_header = *freeswitchc::Event_get_header;
*get_body = *freeswitchc::Event_get_body;
@ -219,6 +225,8 @@ sub DESTROY {
*preAnswer = *freeswitchc::CoreSession_preAnswer;
*hangup = *freeswitchc::CoreSession_hangup;
*setVariable = *freeswitchc::CoreSession_setVariable;
*setPrivate = *freeswitchc::CoreSession_setPrivate;
*getPrivate = *freeswitchc::CoreSession_getPrivate;
*getVariable = *freeswitchc::CoreSession_getVariable;
*recordFile = *freeswitchc::CoreSession_recordFile;
*setCallerData = *freeswitchc::CoreSession_setCallerData;
@ -237,6 +245,7 @@ sub DESTROY {
*setHangupHook = *freeswitchc::CoreSession_setHangupHook;
*ready = *freeswitchc::CoreSession_ready;
*execute = *freeswitchc::CoreSession_execute;
*sendEvent = *freeswitchc::CoreSession_sendEvent;
*begin_allow_threads = *freeswitchc::CoreSession_begin_allow_threads;
*end_allow_threads = *freeswitchc::CoreSession_end_allow_threads;
*get_uuid = *freeswitchc::CoreSession_get_uuid;

View File

@ -1456,15 +1456,16 @@ SWIG_Perl_SetModule(swig_module_info *module) {
#define SWIGTYPE_p_switch_channel_state_t swig_types[7]
#define SWIGTYPE_p_switch_channel_t swig_types[8]
#define SWIGTYPE_p_switch_core_session_t swig_types[9]
#define SWIGTYPE_p_switch_input_args_t swig_types[10]
#define SWIGTYPE_p_switch_input_type_t swig_types[11]
#define SWIGTYPE_p_switch_priority_t swig_types[12]
#define SWIGTYPE_p_switch_size_t swig_types[13]
#define SWIGTYPE_p_switch_status_t swig_types[14]
#define SWIGTYPE_p_switch_stream_handle_t swig_types[15]
#define SWIGTYPE_p_void swig_types[16]
static swig_type_info *swig_types[18];
static swig_module_info swig_module = {swig_types, 17, 0, 0, 0, 0};
#define SWIGTYPE_p_switch_event_t swig_types[10]
#define SWIGTYPE_p_switch_input_args_t swig_types[11]
#define SWIGTYPE_p_switch_input_type_t swig_types[12]
#define SWIGTYPE_p_switch_priority_t swig_types[13]
#define SWIGTYPE_p_switch_size_t swig_types[14]
#define SWIGTYPE_p_switch_status_t swig_types[15]
#define SWIGTYPE_p_switch_stream_handle_t swig_types[16]
#define SWIGTYPE_p_void swig_types[17]
static swig_type_info *swig_types[19];
static swig_module_info swig_module = {swig_types, 18, 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)
@ -1591,19 +1592,6 @@ SWIG_From_int SWIG_PERL_DECL_ARGS_1(int value)
}
SWIGINTERNINLINE SV *
SWIG_From_bool SWIG_PERL_DECL_ARGS_1(bool value)
{
SV *obj = sv_newmortal();
if (value) {
sv_setsv(obj, &PL_sv_yes);
} else {
sv_setsv(obj, &PL_sv_no);
}
return obj;
}
#include <limits.h>
#if !defined(SWIG_NO_LLONG_MAX)
# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__)
@ -1679,6 +1667,72 @@ SWIG_CanCastAsInteger(double *d, double min, double max) {
}
SWIGINTERN int
SWIG_AsVal_long SWIG_PERL_DECL_ARGS_2(SV *obj, long* val)
{
if (SvIOK(obj)) {
if (val) *val = SvIV(obj);
return SWIG_OK;
} else {
int dispatch = 0;
const char *nptr = SvPV_nolen(obj);
if (nptr) {
char *endptr;
long v;
errno = 0;
v = strtol(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_Str2NumCast(SWIG_OK);
}
}
}
if (!dispatch) {
double d;
int res = SWIG_AddCast(SWIG_AsVal_double SWIG_PERL_CALL_ARGS_2(obj,&d));
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) {
if (val) *val = (long)(d);
return res;
}
}
}
return SWIG_TypeError;
}
SWIGINTERN int
SWIG_AsVal_int SWIG_PERL_DECL_ARGS_2(SV * obj, int *val)
{
long v;
int res = SWIG_AsVal_long SWIG_PERL_CALL_ARGS_2(obj, &v);
if (SWIG_IsOK(res)) {
if ((v < INT_MIN || v > INT_MAX)) {
return SWIG_OverflowError;
} else {
if (val) *val = static_cast< int >(v);
}
}
return res;
}
SWIGINTERNINLINE SV *
SWIG_From_bool SWIG_PERL_DECL_ARGS_1(bool value)
{
SV *obj = sv_newmortal();
if (value) {
sv_setsv(obj, &PL_sv_yes);
} else {
sv_setsv(obj, &PL_sv_no);
}
return obj;
}
SWIGINTERN int
SWIG_AsVal_unsigned_SS_long SWIG_PERL_DECL_ARGS_2(SV *obj, unsigned long *val)
{
@ -1756,59 +1810,6 @@ SWIG_From_unsigned_SS_int SWIG_PERL_DECL_ARGS_1(unsigned int value)
}
SWIGINTERN int
SWIG_AsVal_long SWIG_PERL_DECL_ARGS_2(SV *obj, long* val)
{
if (SvIOK(obj)) {
if (val) *val = SvIV(obj);
return SWIG_OK;
} else {
int dispatch = 0;
const char *nptr = SvPV_nolen(obj);
if (nptr) {
char *endptr;
long v;
errno = 0;
v = strtol(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_Str2NumCast(SWIG_OK);
}
}
}
if (!dispatch) {
double d;
int res = SWIG_AddCast(SWIG_AsVal_double SWIG_PERL_CALL_ARGS_2(obj,&d));
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) {
if (val) *val = (long)(d);
return res;
}
}
}
return SWIG_TypeError;
}
SWIGINTERN int
SWIG_AsVal_int SWIG_PERL_DECL_ARGS_2(SV * obj, int *val)
{
long v;
int res = SWIG_AsVal_long SWIG_PERL_CALL_ARGS_2(obj, &v);
if (SWIG_IsOK(res)) {
if ((v < INT_MIN || v > INT_MAX)) {
return SWIG_OverflowError;
} else {
if (val) *val = static_cast< int >(v);
}
}
return res;
}
SWIGINTERN int
SWIG_AsVal_bool SWIG_PERL_DECL_ARGS_2(SV *obj, bool* val)
{
@ -1989,55 +1990,6 @@ XS(_wrap_api_reply_delete) {
}
XS(_wrap_process_callback_result) {
{
char *arg1 = (char *) 0 ;
input_callback_state *arg2 = (input_callback_state *) 0 ;
switch_core_session_t *arg3 = (switch_core_session_t *) 0 ;
switch_status_t result;
int res1 ;
char *buf1 = 0 ;
int alloc1 = 0 ;
void *argp2 = 0 ;
int res2 = 0 ;
void *argp3 = 0 ;
int res3 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 3) || (items > 3)) {
SWIG_croak("Usage: process_callback_result(raw_result,cb_state,session);");
}
res1 = SWIG_AsCharPtrAndSize(ST(0), &buf1, NULL, &alloc1);
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "process_callback_result" "', argument " "1"" of type '" "char *""'");
}
arg1 = reinterpret_cast< char * >(buf1);
res2 = SWIG_ConvertPtr(ST(1), &argp2,SWIGTYPE_p_input_callback_state, 0 | 0 );
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "process_callback_result" "', argument " "2"" of type '" "input_callback_state *""'");
}
arg2 = reinterpret_cast< input_callback_state * >(argp2);
res3 = SWIG_ConvertPtr(ST(2), &argp3,SWIGTYPE_p_switch_core_session_t, 0 | 0 );
if (!SWIG_IsOK(res3)) {
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "process_callback_result" "', argument " "3"" of type '" "switch_core_session_t *""'");
}
arg3 = reinterpret_cast< switch_core_session_t * >(argp3);
result = process_callback_result(arg1,arg2,arg3);
ST(argvi) = SWIG_NewPointerObj((new switch_status_t(static_cast< const switch_status_t& >(result))), SWIGTYPE_p_switch_status_t, SWIG_POINTER_OWN | 0); argvi++ ;
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
XSRETURN(argvi);
fail:
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
SWIG_croak_null();
}
}
XS(_wrap_input_callback_state_t_function_set) {
{
input_callback_state_t *arg1 = (input_callback_state_t *) 0 ;
@ -2537,7 +2489,211 @@ XS(_wrap_Stream_get_data) {
}
XS(_wrap_new_Event) {
XS(_wrap_Event_event_set) {
{
Event *arg1 = (Event *) 0 ;
switch_event_t *arg2 = (switch_event_t *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
void *argp2 = 0 ;
int res2 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 2) || (items > 2)) {
SWIG_croak("Usage: Event_event_set(self,event);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_event_set" "', argument " "1"" of type '" "Event *""'");
}
arg1 = reinterpret_cast< Event * >(argp1);
res2 = SWIG_ConvertPtr(ST(1), &argp2,SWIGTYPE_p_switch_event_t, SWIG_POINTER_DISOWN | 0 );
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Event_event_set" "', argument " "2"" of type '" "switch_event_t *""'");
}
arg2 = reinterpret_cast< switch_event_t * >(argp2);
if (arg1) (arg1)->event = arg2;
XSRETURN(argvi);
fail:
SWIG_croak_null();
}
}
XS(_wrap_Event_event_get) {
{
Event *arg1 = (Event *) 0 ;
switch_event_t *result = 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 1) || (items > 1)) {
SWIG_croak("Usage: Event_event_get(self);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_event_get" "', argument " "1"" of type '" "Event *""'");
}
arg1 = reinterpret_cast< Event * >(argp1);
result = (switch_event_t *) ((arg1)->event);
ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_switch_event_t, 0 | 0); argvi++ ;
XSRETURN(argvi);
fail:
SWIG_croak_null();
}
}
XS(_wrap_Event_serialized_string_set) {
{
Event *arg1 = (Event *) 0 ;
char *arg2 = (char *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 2) || (items > 2)) {
SWIG_croak("Usage: Event_serialized_string_set(self,serialized_string);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_serialized_string_set" "', argument " "1"" of type '" "Event *""'");
}
arg1 = reinterpret_cast< Event * >(argp1);
res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Event_serialized_string_set" "', argument " "2"" of type '" "char *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
if (arg1->serialized_string) delete[] arg1->serialized_string;
if (arg2) {
size_t size = strlen(reinterpret_cast< const char * >(arg2)) + 1;
arg1->serialized_string = (char *)reinterpret_cast< char* >(memcpy((new char[size]), reinterpret_cast< const char * >(arg2), sizeof(char)*(size)));
} else {
arg1->serialized_string = 0;
}
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
XSRETURN(argvi);
fail:
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
SWIG_croak_null();
}
}
XS(_wrap_Event_serialized_string_get) {
{
Event *arg1 = (Event *) 0 ;
char *result = 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 1) || (items > 1)) {
SWIG_croak("Usage: Event_serialized_string_get(self);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_serialized_string_get" "', argument " "1"" of type '" "Event *""'");
}
arg1 = reinterpret_cast< Event * >(argp1);
result = (char *) ((arg1)->serialized_string);
ST(argvi) = SWIG_FromCharPtr((const char *)result); argvi++ ;
XSRETURN(argvi);
fail:
SWIG_croak_null();
}
}
XS(_wrap_Event_mine_set) {
{
Event *arg1 = (Event *) 0 ;
int arg2 ;
void *argp1 = 0 ;
int res1 = 0 ;
int val2 ;
int ecode2 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 2) || (items > 2)) {
SWIG_croak("Usage: Event_mine_set(self,mine);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_mine_set" "', argument " "1"" of type '" "Event *""'");
}
arg1 = reinterpret_cast< Event * >(argp1);
ecode2 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(1), &val2);
if (!SWIG_IsOK(ecode2)) {
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Event_mine_set" "', argument " "2"" of type '" "int""'");
}
arg2 = static_cast< int >(val2);
if (arg1) (arg1)->mine = arg2;
XSRETURN(argvi);
fail:
SWIG_croak_null();
}
}
XS(_wrap_Event_mine_get) {
{
Event *arg1 = (Event *) 0 ;
int result;
void *argp1 = 0 ;
int res1 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 1) || (items > 1)) {
SWIG_croak("Usage: Event_mine_get(self);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_mine_get" "', argument " "1"" of type '" "Event *""'");
}
arg1 = reinterpret_cast< Event * >(argp1);
result = (int) ((arg1)->mine);
ST(argvi) = SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(result)); argvi++ ;
XSRETURN(argvi);
fail:
SWIG_croak_null();
}
}
XS(_wrap_new_Event__SWIG_0) {
{
char *arg1 = (char *) 0 ;
char *arg2 = (char *) NULL ;
@ -2579,6 +2735,129 @@ XS(_wrap_new_Event) {
}
XS(_wrap_new_Event__SWIG_1) {
{
switch_event_t *arg1 = (switch_event_t *) 0 ;
int arg2 = (int) 0 ;
Event *result = 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
int val2 ;
int ecode2 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 1) || (items > 2)) {
SWIG_croak("Usage: new_Event(wrap_me,free_me);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_switch_event_t, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_Event" "', argument " "1"" of type '" "switch_event_t *""'");
}
arg1 = reinterpret_cast< switch_event_t * >(argp1);
if (items > 1) {
ecode2 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(1), &val2);
if (!SWIG_IsOK(ecode2)) {
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "new_Event" "', argument " "2"" of type '" "int""'");
}
arg2 = static_cast< int >(val2);
}
result = (Event *)new Event(arg1,arg2);
ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Event, SWIG_OWNER | SWIG_SHADOW); argvi++ ;
XSRETURN(argvi);
fail:
SWIG_croak_null();
}
}
XS(_wrap_new_Event) {
dXSARGS;
{
unsigned long _index = 0;
SWIG_TypeRank _rank = 0;
if ((items >= 1) && (items <= 2)) {
SWIG_TypeRank _ranki = 0;
SWIG_TypeRank _rankm = 0;
SWIG_TypeRank _pi = 1;
int _v = 0;
{
void *vptr = 0;
int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_switch_event_t, 0);
_v = SWIG_CheckState(res);
}
if (!_v) goto check_1;
_ranki += _v*_pi;
_rankm += _pi;
_pi *= SWIG_MAXCASTRANK;
if (items > 1) {
{
{
int res = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(1), NULL);
_v = SWIG_CheckState(res);
}
}
if (!_v) goto check_1;
_ranki += _v*_pi;
_rankm += _pi;
_pi *= SWIG_MAXCASTRANK;
}
if (!_index || (_ranki < _rank)) {
_rank = _ranki; _index = 1;
if (_rank == _rankm) goto dispatch;
}
}
check_1:
if ((items >= 1) && (items <= 2)) {
SWIG_TypeRank _ranki = 0;
SWIG_TypeRank _rankm = 0;
SWIG_TypeRank _pi = 1;
int _v = 0;
{
int res = SWIG_AsCharPtrAndSize(ST(0), 0, NULL, 0);
_v = SWIG_CheckState(res);
}
if (!_v) goto check_2;
_ranki += _v*_pi;
_rankm += _pi;
_pi *= SWIG_MAXCASTRANK;
if (items > 1) {
{
int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0);
_v = SWIG_CheckState(res);
}
if (!_v) goto check_2;
_ranki += _v*_pi;
_rankm += _pi;
_pi *= SWIG_MAXCASTRANK;
}
if (!_index || (_ranki < _rank)) {
_rank = _ranki; _index = 2;
if (_rank == _rankm) goto dispatch;
}
}
check_2:
dispatch:
switch(_index) {
case 1:
++PL_markstack_ptr; SWIG_CALLXS(_wrap_new_Event__SWIG_1); return;
case 2:
++PL_markstack_ptr; SWIG_CALLXS(_wrap_new_Event__SWIG_0); return;
}
}
croak("No matching function for overloaded 'new_Event'");
XSRETURN(0);
}
XS(_wrap_delete_Event) {
{
Event *arg1 = (Event *) 0 ;
@ -2607,6 +2886,47 @@ XS(_wrap_delete_Event) {
}
XS(_wrap_Event_serialize) {
{
Event *arg1 = (Event *) 0 ;
char *arg2 = (char *) NULL ;
char *result = 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 1) || (items > 2)) {
SWIG_croak("Usage: Event_serialize(self,format);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_serialize" "', argument " "1"" of type '" "Event *""'");
}
arg1 = reinterpret_cast< Event * >(argp1);
if (items > 1) {
res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Event_serialize" "', argument " "2"" of type '" "char const *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
}
result = (char *)(arg1)->serialize((char const *)arg2);
ST(argvi) = SWIG_FromCharPtr((const char *)result); argvi++ ;
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
XSRETURN(argvi);
fail:
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
SWIG_croak_null();
}
}
XS(_wrap_Event_set_priority) {
{
Event *arg1 = (Event *) 0 ;
@ -3447,6 +3767,91 @@ XS(_wrap_CoreSession_setVariable) {
}
XS(_wrap_CoreSession_setPrivate) {
{
CoreSession *arg1 = (CoreSession *) 0 ;
char *arg2 = (char *) 0 ;
void *arg3 = (void *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
int res3 ;
int argvi = 0;
dXSARGS;
if ((items < 3) || (items > 3)) {
SWIG_croak("Usage: CoreSession_setPrivate(self,var,val);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_setPrivate" "', 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_setPrivate" "', argument " "2"" of type '" "char *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
res3 = SWIG_ConvertPtr(ST(2),SWIG_as_voidptrptr(&arg3), 0, 0);
if (!SWIG_IsOK(res3)) {
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CoreSession_setPrivate" "', argument " "3"" of type '" "void *""'");
}
(arg1)->setPrivate(arg2,arg3);
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
XSRETURN(argvi);
fail:
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
SWIG_croak_null();
}
}
XS(_wrap_CoreSession_getPrivate) {
{
CoreSession *arg1 = (CoreSession *) 0 ;
char *arg2 = (char *) 0 ;
void *result = 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 2) || (items > 2)) {
SWIG_croak("Usage: CoreSession_getPrivate(self,var);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_getPrivate" "', 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_getPrivate" "', argument " "2"" of type '" "char *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
result = (void *)(arg1)->getPrivate(arg2);
ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_void, 0 | 0); argvi++ ;
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
XSRETURN(argvi);
fail:
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
SWIG_croak_null();
}
}
XS(_wrap_CoreSession_getVariable) {
{
CoreSession *arg1 = (CoreSession *) 0 ;
@ -4383,6 +4788,43 @@ XS(_wrap_CoreSession_execute) {
}
XS(_wrap_CoreSession_sendEvent) {
{
CoreSession *arg1 = (CoreSession *) 0 ;
Event *arg2 = (Event *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
void *argp2 = 0 ;
int res2 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 2) || (items > 2)) {
SWIG_croak("Usage: CoreSession_sendEvent(self,sendME);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_sendEvent" "', argument " "1"" of type '" "CoreSession *""'");
}
arg1 = reinterpret_cast< CoreSession * >(argp1);
res2 = SWIG_ConvertPtr(ST(1), &argp2,SWIGTYPE_p_Event, 0 | 0 );
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_sendEvent" "', argument " "2"" of type '" "Event *""'");
}
arg2 = reinterpret_cast< Event * >(argp2);
(arg1)->sendEvent(arg2);
XSRETURN(argvi);
fail:
SWIG_croak_null();
}
}
XS(_wrap_CoreSession_begin_allow_threads) {
{
CoreSession *arg1 = (CoreSession *) 0 ;
@ -5437,6 +5879,7 @@ static swig_type_info _swigt__p_session_flag_t = {"_p_session_flag_t", "enum ses
static swig_type_info _swigt__p_switch_channel_state_t = {"_p_switch_channel_state_t", "switch_channel_state_t *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_switch_channel_t = {"_p_switch_channel_t", "switch_channel_t *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_switch_core_session_t = {"_p_switch_core_session_t", "switch_core_session_t *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_switch_event_t = {"_p_switch_event_t", "switch_event_t *", 0, 0, (void*)0, 0};
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};
@ -5456,6 +5899,7 @@ static swig_type_info *swig_type_initial[] = {
&_swigt__p_switch_channel_state_t,
&_swigt__p_switch_channel_t,
&_swigt__p_switch_core_session_t,
&_swigt__p_switch_event_t,
&_swigt__p_switch_input_args_t,
&_swigt__p_switch_input_type_t,
&_swigt__p_switch_priority_t,
@ -5475,6 +5919,7 @@ static swig_cast_info _swigc__p_session_flag_t[] = { {&_swigt__p_session_flag_t
static swig_cast_info _swigc__p_switch_channel_state_t[] = { {&_swigt__p_switch_channel_state_t, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_switch_channel_t[] = { {&_swigt__p_switch_channel_t, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_switch_core_session_t[] = { {&_swigt__p_switch_core_session_t, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_switch_event_t[] = { {&_swigt__p_switch_event_t, 0, 0, 0},{0, 0, 0, 0}};
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}};
@ -5494,6 +5939,7 @@ static swig_cast_info *swig_cast_initial[] = {
_swigc__p_switch_channel_state_t,
_swigc__p_switch_channel_t,
_swigc__p_switch_core_session_t,
_swigc__p_switch_event_t,
_swigc__p_switch_input_args_t,
_swigc__p_switch_input_type_t,
_swigc__p_switch_priority_t,
@ -5520,7 +5966,6 @@ static swig_command_info swig_commands[] = {
{"freeswitchc::console_clean_log", _wrap_console_clean_log},
{"freeswitchc::api_execute", _wrap_api_execute},
{"freeswitchc::api_reply_delete", _wrap_api_reply_delete},
{"freeswitchc::process_callback_result", _wrap_process_callback_result},
{"freeswitchc::input_callback_state_t_function_set", _wrap_input_callback_state_t_function_set},
{"freeswitchc::input_callback_state_t_function_get", _wrap_input_callback_state_t_function_get},
{"freeswitchc::input_callback_state_t_threadState_set", _wrap_input_callback_state_t_threadState_set},
@ -5535,8 +5980,15 @@ static swig_command_info swig_commands[] = {
{"freeswitchc::delete_Stream", _wrap_delete_Stream},
{"freeswitchc::Stream_write", _wrap_Stream_write},
{"freeswitchc::Stream_get_data", _wrap_Stream_get_data},
{"freeswitchc::Event_event_set", _wrap_Event_event_set},
{"freeswitchc::Event_event_get", _wrap_Event_event_get},
{"freeswitchc::Event_serialized_string_set", _wrap_Event_serialized_string_set},
{"freeswitchc::Event_serialized_string_get", _wrap_Event_serialized_string_get},
{"freeswitchc::Event_mine_set", _wrap_Event_mine_set},
{"freeswitchc::Event_mine_get", _wrap_Event_mine_get},
{"freeswitchc::new_Event", _wrap_new_Event},
{"freeswitchc::delete_Event", _wrap_delete_Event},
{"freeswitchc::Event_serialize", _wrap_Event_serialize},
{"freeswitchc::Event_set_priority", _wrap_Event_set_priority},
{"freeswitchc::Event_get_header", _wrap_Event_get_header},
{"freeswitchc::Event_get_body", _wrap_Event_get_body},
@ -5561,6 +6013,8 @@ static swig_command_info swig_commands[] = {
{"freeswitchc::CoreSession_preAnswer", _wrap_CoreSession_preAnswer},
{"freeswitchc::CoreSession_hangup", _wrap_CoreSession_hangup},
{"freeswitchc::CoreSession_setVariable", _wrap_CoreSession_setVariable},
{"freeswitchc::CoreSession_setPrivate", _wrap_CoreSession_setPrivate},
{"freeswitchc::CoreSession_getPrivate", _wrap_CoreSession_getPrivate},
{"freeswitchc::CoreSession_getVariable", _wrap_CoreSession_getVariable},
{"freeswitchc::CoreSession_recordFile", _wrap_CoreSession_recordFile},
{"freeswitchc::CoreSession_setCallerData", _wrap_CoreSession_setCallerData},
@ -5579,6 +6033,7 @@ static swig_command_info swig_commands[] = {
{"freeswitchc::CoreSession_setHangupHook", _wrap_CoreSession_setHangupHook},
{"freeswitchc::CoreSession_ready", _wrap_CoreSession_ready},
{"freeswitchc::CoreSession_execute", _wrap_CoreSession_execute},
{"freeswitchc::CoreSession_sendEvent", _wrap_CoreSession_sendEvent},
{"freeswitchc::CoreSession_begin_allow_threads", _wrap_CoreSession_begin_allow_threads},
{"freeswitchc::CoreSession_end_allow_threads", _wrap_CoreSession_end_allow_threads},
{"freeswitchc::CoreSession_get_uuid", _wrap_CoreSession_get_uuid},

View File

@ -37,9 +37,6 @@
#pragma warning(disable:4127 4003)
#endif
#define sanity_check(x) do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0)
#define sanity_check_noreturn do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return;}} while(0)
#define init_vars() do { session = NULL; channel = NULL; uuid = NULL; tts_name = NULL; voice_name = NULL; memset(&args, 0, sizeof(args)); ap = NULL; caller_profile.source = "mod_unknown"; caller_profile.dialplan = ""; caller_profile.context = ""; caller_profile.caller_id_name = ""; caller_profile.caller_id_number = ""; caller_profile.network_addr = ""; caller_profile.ani = ""; caller_profile.aniii = ""; caller_profile.rdnis = ""; caller_profile.username = ""; on_hangup = NULL; cb_state.function = NULL; } while(0)
Event::Event(const char *type, const char *subclass_name)
{
@ -50,17 +47,73 @@ Event::Event(const char *type, const char *subclass_name)
}
switch_event_create_subclass(&event, event_id, subclass_name);
serialized_string = NULL;
mine = 1;
}
Event::Event(switch_event_t *wrap_me, int free_me)
{
event = wrap_me;
mine = free_me;
serialized_string = NULL;
}
Event::~Event()
{
if (event) {
if (serialized_string) {
free(serialized_string);
}
if (event && mine) {
switch_event_destroy(&event);
}
}
const char *Event::serialize(const char *format)
{
int isxml = 0;
if (serialized_string) {
free(serialized_string);
}
if (!event) {
return "";
}
if (format && !strcasecmp(format, "xml")) {
isxml++;
}
if (isxml) {
switch_xml_t xml;
char *xmlstr;
if ((xml = switch_event_xmlize(event, SWITCH_VA_NONE))) {
serialized_string = switch_xml_toxml(xml, SWITCH_FALSE);
switch_xml_free(xml);
return serialized_string;
} else {
return "";
}
} else {
if (switch_event_serialize(event, &serialized_string, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
return serialized_string;
}
}
return "";
}
bool Event::fire(void)
{
if (!mine) {
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Not My event!\n");
return false;
}
if (event) {
switch_event_fire(&event);
return true;
@ -184,7 +237,7 @@ CoreSession::CoreSession(char *nuuid)
{
memset(&caller_profile, 0, sizeof(caller_profile));
init_vars();
if (session = switch_core_session_locate(nuuid)) {
if (!strchr(nuuid, '/') && (session = switch_core_session_locate(nuuid))) {
uuid = strdup(nuuid);
channel = switch_core_session_get_channel(session);
allocated = 1;
@ -254,6 +307,18 @@ void CoreSession::hangup(char *cause)
switch_channel_hangup(channel, switch_channel_str2cause(cause));
}
void CoreSession::setPrivate(char *var, void *val)
{
sanity_check_noreturn;
switch_channel_set_private(channel, var, val);
}
void *CoreSession::getPrivate(char *var)
{
sanity_check(NULL);
return switch_channel_get_private(channel, var);
}
void CoreSession::setVariable(char *var, char *val)
{
sanity_check_noreturn;
@ -301,6 +366,15 @@ void CoreSession::setDTMFCallback(void *cbfunc, char *funcargs) {
}
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");
}
}
int CoreSession::speak(char *text)
{
switch_status_t status;
@ -417,24 +491,30 @@ int CoreSession::playAndGetDigits(int min_digits,
int CoreSession::streamFile(char *file, int starting_sample_count) {
switch_status_t status;
switch_file_handle_t fh = { 0 };
//switch_file_handle_t fh = { 0 };
const char *prebuf;
sanity_check(-1);
fh.samples = starting_sample_count;
store_file_handle(&fh);
begin_allow_threads();
status = switch_ivr_play_file(session, &fh, file, ap);
end_allow_threads();
memset(&local_fh, 0, sizeof(local_fh));
fhp = &local_fh;
local_fh.samples = starting_sample_count;
if ((prebuf = switch_channel_get_variable(this->channel, "stream_prebuffer"))) {
int maybe = atoi(prebuf);
if (maybe > 0) {
fh.prebuf = maybe;
local_fh.prebuf = maybe;
}
}
store_file_handle(&local_fh);
begin_allow_threads();
status = switch_ivr_play_file(session, fhp, file, ap);
end_allow_threads();
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
@ -676,7 +756,7 @@ switch_status_t hanguphook(switch_core_session_t *session_hungup)
switch_channel_state_t state = switch_channel_get_state(channel);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangup_hook called\n");
fflush(stdout);
if ((coresession = (CoreSession *) switch_channel_get_private(channel, "CoreSession"))) {
if (coresession->hook_state != state) {
@ -700,9 +780,11 @@ switch_status_t dtmf_callback(switch_core_session_t *session_cb,
switch_status_t result;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "dtmf_callback called\n");
fflush(stdout);
//coresession = (CoreSession *) buf;
coresession = (CoreSession *) switch_channel_get_private(channel, "CoreSession");
if (!coresession) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid CoreSession\n");
return SWITCH_STATUS_FALSE;
@ -717,24 +799,24 @@ switch_status_t dtmf_callback(switch_core_session_t *session_cb,
}
switch_status_t process_callback_result(char *ret,
struct input_callback_state *cb_state,
switch_core_session_t *session)
switch_status_t CoreSession::process_callback_result(char *ret)
{
switch_file_handle_t *fh = NULL;
if (!cb_state) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Process callback result aborted because cb_state is null\n");
if (fhp) {
fh = fhp;
} else {
if (!cb_state.extra) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Process callback result aborted because cb_state.extra is null\n");
return SWITCH_STATUS_FALSE;
}
if (!cb_state->extra) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Process callback result aborted because cb_state->extra is null\n");
return SWITCH_STATUS_FALSE;
fh = (switch_file_handle_t *) cb_state.extra;
}
fh = (switch_file_handle_t *) cb_state->extra;
if (!fh) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Process callback result aborted because fh is null\n");
@ -747,8 +829,7 @@ switch_status_t process_callback_result(char *ret,
}
if (!ret) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Process callback result aborted because ret is null\n");
return SWITCH_STATUS_FALSE;
return SWITCH_STATUS_SUCCESS;
}
if (!session) {

View File

@ -871,7 +871,7 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch
add_xml_header(xml, hp->name, hp->value, off++);
}
if (data) {
if (!switch_strlen_zero(data)) {
body = data;
} else if (event->body) {
body = event->body;