run indent on the whole tree and update copyright dates in prep for 1.0.5

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16579 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2010-02-06 03:38:24 +00:00
1 parent 7b347417e5
commit 886e1ddb4d
229 files changed
+20252 -20192

No files matched your search

+12 -14
View File
@@ -6,21 +6,19 @@
extern JavaVM *javaVM;
class JavaSession : public CoreSession
{
public:
JavaSession();
JavaSession(char *uuid);
JavaSession(switch_core_session_t *session);
virtual ~JavaSession();
class JavaSession:public CoreSession {
public:
JavaSession();
JavaSession(char *uuid);
JavaSession(switch_core_session_t *session);
virtual ~ JavaSession();
virtual bool begin_allow_threads();
virtual bool end_allow_threads();
void setDTMFCallback(jobject dtmfCallback, char *funcargs);
void setHangupHook(jobject hangupHook);
virtual void check_hangup_hook();
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
virtual bool begin_allow_threads();
virtual bool end_allow_threads();
void setDTMFCallback(jobject dtmfCallback, char *funcargs);
void setHangupHook(jobject hangupHook);
virtual void check_hangup_hook();
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
};
#endif
+158 -189
View File
@@ -45,236 +45,205 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_java_shutdown);
SWITCH_MODULE_DEFINITION(mod_java, mod_java_load, mod_java_shutdown, NULL);
static void launch_java(switch_core_session_t *session, const char *data, JNIEnv *env)
static void launch_java(switch_core_session_t *session, const char *data, JNIEnv * env)
{
jclass Launcher = NULL;
jmethodID launch = NULL;
jstring uuid = NULL;
jstring args = NULL;
jclass Launcher = NULL;
jmethodID launch = NULL;
jstring uuid = NULL;
jstring args = NULL;
Launcher = (*env)->FindClass(env, "org/freeswitch/Launcher");
if (Launcher == NULL)
{
(*env)->ExceptionDescribe(env);
goto done;
}
Launcher = (*env)->FindClass(env, "org/freeswitch/Launcher");
if (Launcher == NULL) {
(*env)->ExceptionDescribe(env);
goto done;
}
launch = (*env)->GetStaticMethodID(env, Launcher, "launch", "(Ljava/lang/String;Ljava/lang/String;)V");
if (launch == NULL)
{
(*env)->ExceptionDescribe(env);
goto done;
}
launch = (*env)->GetStaticMethodID(env, Launcher, "launch", "(Ljava/lang/String;Ljava/lang/String;)V");
if (launch == NULL) {
(*env)->ExceptionDescribe(env);
goto done;
}
uuid = (*env)->NewStringUTF(env, switch_core_session_get_uuid(session));
if (uuid == NULL)
{
(*env)->ExceptionDescribe(env);
goto done;
}
uuid = (*env)->NewStringUTF(env, switch_core_session_get_uuid(session));
if (uuid == NULL) {
(*env)->ExceptionDescribe(env);
goto done;
}
args = (*env)->NewStringUTF(env, data);
if (args == NULL)
{
(*env)->ExceptionDescribe(env);
goto done;
}
args = (*env)->NewStringUTF(env, data);
if (args == NULL) {
(*env)->ExceptionDescribe(env);
goto done;
}
(*env)->CallStaticVoidMethod(env, Launcher, launch, uuid, args);
if ((*env)->ExceptionOccurred(env))
(*env)->ExceptionDescribe(env);
(*env)->CallStaticVoidMethod(env, Launcher, launch, uuid, args);
if ((*env)->ExceptionOccurred(env))
(*env)->ExceptionDescribe(env);
done:
if (args != NULL)
(*env)->DeleteLocalRef(env, args);
if (uuid != NULL)
(*env)->DeleteLocalRef(env, uuid);
if (Launcher != NULL)
(*env)->DeleteLocalRef(env, Launcher);
done:
if (args != NULL)
(*env)->DeleteLocalRef(env, args);
if (uuid != NULL)
(*env)->DeleteLocalRef(env, uuid);
if (Launcher != NULL)
(*env)->DeleteLocalRef(env, Launcher);
}
SWITCH_STANDARD_APP(java_function)
{
JNIEnv *env;
jint res;
JNIEnv *env;
jint res;
if (javaVM == NULL)
return;
if (javaVM == NULL)
return;
res = (*javaVM)->AttachCurrentThread(javaVM, (void*) &env, NULL);
if (res == JNI_OK)
{
launch_java(session, data, env);
(*javaVM)->DetachCurrentThread(javaVM);
}
else
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error attaching thread to Java VM!\n");
res = (*javaVM)->AttachCurrentThread(javaVM, (void *) &env, NULL);
if (res == JNI_OK) {
launch_java(session, data, env);
(*javaVM)->DetachCurrentThread(javaVM);
} else
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error attaching thread to Java VM!\n");
}
static switch_status_t load_config(JavaVMOption **javaOptions, int *optionCount)
static switch_status_t load_config(JavaVMOption ** javaOptions, int *optionCount)
{
switch_xml_t cfg, xml;
switch_status_t status;
switch_xml_t cfg, xml;
switch_status_t status;
xml = switch_xml_open_cfg("java.conf", &cfg, NULL);
if (xml)
{
switch_xml_t javavm;
switch_xml_t options;
xml = switch_xml_open_cfg("java.conf", &cfg, NULL);
if (xml) {
switch_xml_t javavm;
switch_xml_t options;
javavm = switch_xml_child(cfg, "javavm");
if (javavm != NULL)
{
const char *path = switch_xml_attr_soft(javavm, "path");
if (path != NULL)
{
status = switch_dso_load(&javaVMHandle, path, memoryPool);
if (status != SWITCH_STATUS_SUCCESS)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error loading %s\n", path);
}
else
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n");
status = SWITCH_STATUS_FALSE;
}
}
else
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n");
status = SWITCH_STATUS_FALSE;
goto close;
}
javavm = switch_xml_child(cfg, "javavm");
if (javavm != NULL) {
const char *path = switch_xml_attr_soft(javavm, "path");
if (path != NULL) {
status = switch_dso_load(&javaVMHandle, path, memoryPool);
if (status != SWITCH_STATUS_SUCCESS)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error loading %s\n", path);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n");
status = SWITCH_STATUS_FALSE;
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n");
status = SWITCH_STATUS_FALSE;
goto close;
}
options = switch_xml_child(cfg, "options");
if (options != NULL)
{
switch_xml_t option;
int i = 0;
*optionCount = 0;
for (option = switch_xml_child(options, "option"); option; option = option->next)
{
const char *value = switch_xml_attr_soft(option, "value");
if (value != NULL)
++*optionCount;
}
*optionCount += 1;
*javaOptions = switch_core_alloc(memoryPool, (switch_size_t)(*optionCount * sizeof(JavaVMOption)));
if (*javaOptions == NULL)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
status = SWITCH_STATUS_FALSE;
goto close;
}
for (option = switch_xml_child(options, "option"); option; option = option->next)
{
const char *value = switch_xml_attr_soft(option, "value");
if (value == NULL)
continue;
(*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value);
if ((*javaOptions)[i].optionString == NULL)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
status = SWITCH_STATUS_FALSE;
goto close;
}
++i;
}
(*javaOptions)[i].optionString = "-Djava.library.path=" SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "mod";
}
options = switch_xml_child(cfg, "options");
if (options != NULL) {
switch_xml_t option;
int i = 0;
*optionCount = 0;
for (option = switch_xml_child(options, "option"); option; option = option->next) {
const char *value = switch_xml_attr_soft(option, "value");
if (value != NULL)
++ * optionCount;
}
*optionCount += 1;
*javaOptions = switch_core_alloc(memoryPool, (switch_size_t) (*optionCount * sizeof(JavaVMOption)));
if (*javaOptions == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
status = SWITCH_STATUS_FALSE;
goto close;
}
for (option = switch_xml_child(options, "option"); option; option = option->next) {
const char *value = switch_xml_attr_soft(option, "value");
if (value == NULL)
continue;
(*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value);
if ((*javaOptions)[i].optionString == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
status = SWITCH_STATUS_FALSE;
goto close;
}
++i;
}
(*javaOptions)[i].optionString = "-Djava.library.path=" SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "mod";
}
close:
switch_xml_free(xml);
}
else
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n");
status = SWITCH_STATUS_FALSE;
}
return status;
close:
switch_xml_free(xml);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n");
status = SWITCH_STATUS_FALSE;
}
return status;
}
static switch_status_t create_java_vm(JavaVMOption *options, int optionCount)
static switch_status_t create_java_vm(JavaVMOption * options, int optionCount)
{
jint (JNICALL *pJNI_CreateJavaVM)(JavaVM**,void**,void*);
switch_status_t status;
jint(JNICALL * pJNI_CreateJavaVM) (JavaVM **, void **, void *);
switch_status_t status;
status = switch_dso_sym((void*) &pJNI_CreateJavaVM, javaVMHandle, "JNI_CreateJavaVM");
if (status == SWITCH_STATUS_SUCCESS)
{
JNIEnv *env;
JavaVMInitArgs initArgs;
jint res;
status = switch_dso_sym((void *) &pJNI_CreateJavaVM, javaVMHandle, "JNI_CreateJavaVM");
if (status == SWITCH_STATUS_SUCCESS) {
JNIEnv *env;
JavaVMInitArgs initArgs;
jint res;
memset(&initArgs, 0, sizeof(initArgs));
initArgs.version = JNI_VERSION_1_4;
initArgs.nOptions = optionCount;
initArgs.options = options;
initArgs.ignoreUnrecognized = JNI_TRUE;
memset(&initArgs, 0, sizeof(initArgs));
initArgs.version = JNI_VERSION_1_4;
initArgs.nOptions = optionCount;
initArgs.options = options;
initArgs.ignoreUnrecognized = JNI_TRUE;
res = pJNI_CreateJavaVM(&javaVM, (void*) &env, &initArgs);
if (res == JNI_OK)
{
(*javaVM)->DetachCurrentThread(javaVM);
status = SWITCH_STATUS_SUCCESS;
}
else
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating Java VM!\n");
status = SWITCH_STATUS_FALSE;
}
}
else
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Specified Java VM doesn't have JNI_CreateJavaVM\n");
status = SWITCH_STATUS_FALSE;
}
return status;
res = pJNI_CreateJavaVM(&javaVM, (void *) &env, &initArgs);
if (res == JNI_OK) {
(*javaVM)->DetachCurrentThread(javaVM);
status = SWITCH_STATUS_SUCCESS;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating Java VM!\n");
status = SWITCH_STATUS_FALSE;
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Specified Java VM doesn't have JNI_CreateJavaVM\n");
status = SWITCH_STATUS_FALSE;
}
return status;
}
SWITCH_MODULE_LOAD_FUNCTION(mod_java_load)
{
switch_status_t status;
JavaVMOption *options = NULL;
int optionCount = 0;
switch_status_t status;
JavaVMOption *options = NULL;
int optionCount = 0;
switch_application_interface_t *app_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_APP(app_interface, "java", NULL, NULL, java_function, NULL, SAF_SUPPORT_NOMEDIA);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Java Framework Loading...\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Java Framework Loading...\n");
if (javaVM != NULL)
return SWITCH_STATUS_SUCCESS;
if (javaVM != NULL)
return SWITCH_STATUS_SUCCESS;
status = switch_core_new_memory_pool(&memoryPool);
if (status == SWITCH_STATUS_SUCCESS)
{
status = load_config(&options, &optionCount);
if (status == SWITCH_STATUS_SUCCESS)
{
status = create_java_vm(options, optionCount);
if (status == SWITCH_STATUS_SUCCESS)
return SWITCH_STATUS_SUCCESS;
switch_dso_unload(javaVMHandle);
}
switch_core_destroy_memory_pool(&memoryPool);
}
else
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating memory pool\n");
status = switch_core_new_memory_pool(&memoryPool);
if (status == SWITCH_STATUS_SUCCESS) {
status = load_config(&options, &optionCount);
if (status == SWITCH_STATUS_SUCCESS) {
status = create_java_vm(options, optionCount);
if (status == SWITCH_STATUS_SUCCESS)
return SWITCH_STATUS_SUCCESS;
switch_dso_unload(javaVMHandle);
}
switch_core_destroy_memory_pool(&memoryPool);
} else
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating memory pool\n");
return status == SWITCH_STATUS_SUCCESS ? SWITCH_STATUS_NOUNLOAD : status;
return status == SWITCH_STATUS_SUCCESS ? SWITCH_STATUS_NOUNLOAD : status;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_java_shutdown)
{
if (javaVM == NULL)
return SWITCH_STATUS_FALSE;
if (javaVM == NULL)
return SWITCH_STATUS_FALSE;
(*javaVM)->DestroyJavaVM(javaVM);
javaVM = NULL;
switch_dso_unload(javaVMHandle);
switch_core_destroy_memory_pool(&memoryPool);
return SWITCH_STATUS_SUCCESS;
(*javaVM)->DestroyJavaVM(javaVM);
javaVM = NULL;
switch_dso_unload(javaVMHandle);
switch_core_destroy_memory_pool(&memoryPool);
return SWITCH_STATUS_SUCCESS;
}
+30 -32
View File
@@ -7,41 +7,39 @@ extern "C" {
#include <lualib.h>
#include "mod_lua_extra.h"
}
#include <switch_cpp.h>
namespace LUA {
class Session : public CoreSession {
private:
virtual void do_hangup_hook();
lua_State *getLUA();
lua_State *L;
int hh;
int mark;
public:
Session();
Session(char *uuid, CoreSession *a_leg = NULL);
Session(switch_core_session_t *session);
~Session();
SWITCH_MOD_DECLARE(virtual void) destroy(void);
virtual bool begin_allow_threads();
virtual bool end_allow_threads();
virtual void check_hangup_hook();
class Session:public CoreSession {
private:
virtual void do_hangup_hook();
lua_State *getLUA();
lua_State *L;
int hh;
int mark;
public:
Session();
Session(char *uuid, CoreSession * a_leg = NULL);
Session(switch_core_session_t *session);
~Session();
SWITCH_MOD_DECLARE(virtual void) destroy(void);
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
void unsetInputCallback(void);
void setInputCallback(char *cbfunc, char *funcargs = NULL);
void setHangupHook(char *func, char *arg = NULL);
bool ready();
int originate(CoreSession *a_leg_session, char *dest, int timeout);
char *cb_function;
char *cb_arg;
char *hangup_func_str;
char *hangup_func_arg;
void setLUA(lua_State *state);
virtual bool begin_allow_threads();
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 unsetInputCallback(void);
void setInputCallback(char *cbfunc, char *funcargs = NULL);
void setHangupHook(char *func, char *arg = NULL);
bool ready();
int originate(CoreSession * a_leg_session, char *dest, int timeout);
char *cb_function;
char *cb_arg;
char *hangup_func_str;
char *hangup_func_arg;
void setLUA(lua_State * state);
};
}
#endif
+1 -1
View File
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
+2 -4
View File
@@ -1,9 +1,7 @@
#ifndef MOD_LUA_EXTRA
#define MOD_LUA_EXTRA
SWITCH_BEGIN_EXTERN_C
void mod_lua_conjure_event(lua_State *L, switch_event_t *event, const char *name, int destroy_me);
void mod_lua_conjure_stream(lua_State *L, switch_stream_handle_t *stream, const char *name, int destroy_me);
SWITCH_BEGIN_EXTERN_C void mod_lua_conjure_event(lua_State * L, switch_event_t *event, const char *name, int destroy_me);
void mod_lua_conjure_stream(lua_State * L, switch_stream_handle_t *stream, const char *name, int destroy_me);
void mod_lua_conjure_session(lua_State * L, switch_core_session_t *session, const char *name, int destroy_me);
SWITCH_END_EXTERN_C
+97 -110
View File
@@ -1,169 +1,160 @@
typedef struct input_callback_state {
void *function;
void *function;
void *threadState;
void *threadState;
void *extra;
char *funcargs;
void *extra;
char *funcargs;
} input_callback_state_t;
typedef enum {
S_HUP = (1 << 0),
S_FREE = (1 << 1),
S_RDLOCK = (1 << 2)
S_HUP = (1 << 0),
S_FREE = (1 << 1),
S_RDLOCK = (1 << 2)
} session_flag_t;
class Stream {
protected:
switch_stream_handle_t mystream;
switch_stream_handle_t *stream_p;
int mine;
public:
Stream(void);
Stream(switch_stream_handle_t *);
virtual ~Stream();
void write(const char *data);
const char *get_data(void);
protected:
switch_stream_handle_t mystream;
switch_stream_handle_t *stream_p;
int mine;
public:
Stream(void);
Stream(switch_stream_handle_t *);
virtual ~ Stream();
void write(const char *data);
const char *get_data(void);
};
class Event {
protected:
public:
switch_event_t *event;
char *serialized_string;
int mine;
protected:
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 setPriority(switch_priority_t priority = SWITCH_PRIORITY_NORMAL);
char *getHeader(char *header_name);
char *getBody(void);
char *getType(void);
bool addBody(const char *value);
bool addHeader(const char *header_name, const char *value);
bool delHeader(const char *header_name);
bool fire(void);
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 setPriority(switch_priority_t priority = SWITCH_PRIORITY_NORMAL);
char *getHeader(char *header_name);
char *getBody(void);
char *getType(void);
bool addBody(const char *value);
bool addHeader(const char *header_name, const char *value);
bool delHeader(const char *header_name);
bool fire(void);
};
class CoreSession {
protected:
switch_input_args_t args;
protected:
switch_input_args_t args;
switch_input_args_t *ap;
switch_caller_profile_t caller_profile;
switch_input_args_t *ap;
switch_caller_profile_t caller_profile;
char *uuid;
char *tts_name;
char *voice_name;
void store_file_handle(switch_file_handle_t *fh);
void *on_hangup;
switch_file_handle_t local_fh;
switch_file_handle_t *fhp;
switch_status_t process_callback_result(char *ret);
public:
CoreSession();
CoreSession(char *uuid);
CoreSession(switch_core_session_t *new_session);
virtual ~CoreSession();
switch_core_session_t *session;
switch_channel_t *channel;
unsigned int flags;
int allocated;
input_callback_state cb_state;
char *uuid;
char *tts_name;
char *voice_name;
void store_file_handle(switch_file_handle_t *fh);
void *on_hangup;
switch_file_handle_t local_fh;
switch_file_handle_t *fhp;
switch_status_t process_callback_result(char *ret);
public:
CoreSession();
CoreSession(char *uuid);
CoreSession(switch_core_session_t *new_session);
virtual ~ CoreSession();
switch_core_session_t *session;
switch_channel_t *channel;
unsigned int flags;
int allocated;
input_callback_state cb_state;
switch_channel_state_t hook_state;
switch_channel_state_t hook_state;
int answer();
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);
int recordFile(char *file_name, int max_len=0, int silence_threshold=0, int silence_secs=0);
int answer();
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);
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);
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 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 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 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 flushEvents();
int flushDigits();
int flushDigits();
int setAutoHangup(bool val);
int setAutoHangup(bool val);
void setHangupHook(void *hangup_func);
void setHangupHook(void *hangup_func);
bool ready();
bool ready();
void execute(char *app, char *data);
void execute(char *app, char *data);
void sendEvent(Event *sendME);
void sendEvent(Event * sendME);
virtual bool begin_allow_threads() = 0;
virtual bool end_allow_threads() = 0;
virtual bool begin_allow_threads() = 0;
virtual bool end_allow_threads() = 0;
char* get_uuid() const { return uuid; };
char *get_uuid() const {
return uuid;
};
const switch_input_args_t& get_cb_args() const { return args; };
const switch_input_args_t &get_cb_args() const {
return args;
};
virtual void check_hangup_hook() = 0;
virtual void check_hangup_hook() = 0;
virtual switch_status_t run_dtmf_callback(void *input,
switch_input_type_t itype) = 0;
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype) = 0;
};
@@ -180,7 +171,7 @@ void api_reply_delete(char *reply);
void bridge(CoreSession &session_a, CoreSession &session_b);
void bridge(CoreSession & session_a, CoreSession & session_b);
@@ -189,8 +180,4 @@ void bridge(CoreSession &session_a, CoreSession &session_b);
switch_status_t hanguphook(switch_core_session_t *session);
switch_status_t dtmf_callback(switch_core_session_t *session,
void *input,
switch_input_type_t itype,
void *buf,
unsigned int buflen);
switch_status_t dtmf_callback(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen);
@@ -34,12 +34,10 @@
#define FREESWITCH_MANAGED_H
SWITCH_BEGIN_EXTERN_C
#include <switch.h>
#include <switch_cpp.h>
typedef void (*hangupFunction)(void);
typedef char* (*inputFunction)(void*, switch_input_type_t);
typedef void (*hangupFunction) (void);
typedef char *(*inputFunction) (void *, switch_input_type_t);
#ifndef _MANAGED
#include <glib.h>
@@ -79,58 +77,109 @@ extern mod_managed_globals globals;
#endif
SWITCH_END_EXTERN_C
#ifdef _MANAGED
// this section remove linker error LNK4248 for these opaque structures
struct switch_core_session {char foo[];};
struct apr_pool_t {char foo[];};
struct switch_channel {char foo[];};
struct apr_thread_t {char foo[];};
struct switch_hash {char foo[];};
struct apr_thread_mutex_t {char foo[];};
struct switch_network_list {char foo[];};
struct switch_xml_binding {char foo[];};
struct apr_sockaddr_t {char foo[];};
struct switch_core_port_allocator {char foo[];};
struct switch_media_bug {char foo[];};
struct switch_rtp {char foo[];};
struct sqlite3_stmt {char foo[];};
struct switch_buffer {char foo[];};
struct switch_ivr_menu {char foo[];};
struct switch_event_node {char foo[];};
struct switch_ivr_digit_stream_parser {char foo[];};
struct sqlite3 {char foo[];};
struct switch_ivr_digit_stream {char foo[];};
struct real_pcre {char foo[];};
struct HashElem {char foo[];};
struct switch_ivr_menu_xml_ctx {char foo[];};
struct apr_file_t {char foo[];};
struct apr_thread_rwlock_t {char foo[];};
struct apr_pollfd_t {char foo[];};
struct apr_queue_t {char foo[];};
struct apr_socket_t {char foo[];};
struct switch_core_session {
char foo[];
};
struct apr_pool_t {
char foo[];
};
struct switch_channel {
char foo[];
};
struct apr_thread_t {
char foo[];
};
struct switch_hash {
char foo[];
};
struct apr_thread_mutex_t {
char foo[];
};
struct switch_network_list {
char foo[];
};
struct switch_xml_binding {
char foo[];
};
struct apr_sockaddr_t {
char foo[];
};
struct switch_core_port_allocator {
char foo[];
};
struct switch_media_bug {
char foo[];
};
struct switch_rtp {
char foo[];
};
struct sqlite3_stmt {
char foo[];
};
struct switch_buffer {
char foo[];
};
struct switch_ivr_menu {
char foo[];
};
struct switch_event_node {
char foo[];
};
struct switch_ivr_digit_stream_parser {
char foo[];
};
struct sqlite3 {
char foo[];
};
struct switch_ivr_digit_stream {
char foo[];
};
struct real_pcre {
char foo[];
};
struct HashElem {
char foo[];
};
struct switch_ivr_menu_xml_ctx {
char foo[];
};
struct apr_file_t {
char foo[];
};
struct apr_thread_rwlock_t {
char foo[];
};
struct apr_pollfd_t {
char foo[];
};
struct apr_queue_t {
char foo[];
};
struct apr_socket_t {
char foo[];
};
// LNK Error
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
public ref class FreeSwitchManaged
{
public:
static Assembly^ mod_dotnet_managed;
static MethodInfo^ loadMethod;
public ref class FreeSwitchManaged {
public:
static Assembly ^ mod_dotnet_managed;
static MethodInfo ^ loadMethod;
};
#endif
class ManagedSession : public CoreSession
{
public:
class ManagedSession:public CoreSession {
public:
ManagedSession(void);
ManagedSession(char *uuid);
ManagedSession(switch_core_session_t *session);
virtual ~ManagedSession();
virtual ~ ManagedSession();
virtual bool begin_allow_threads();
virtual bool end_allow_threads();
@@ -138,8 +187,8 @@ public:
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
// P/Invoke function pointer to delegates
inputFunction dtmfDelegate;
hangupFunction hangupDelegate;
inputFunction dtmfDelegate;
hangupFunction hangupDelegate;
};
#endif
+30 -32
View File
@@ -14,41 +14,39 @@ extern "C" {
#include <perl.h>
#include <switch.h>
}
#include <switch_cpp.h>
namespace PERL {
class Session : public CoreSession {
private:
virtual void do_hangup_hook();
PerlInterpreter *getPERL();
PerlInterpreter *my_perl;
int hh;
int mark;
SV *me;
public:
Session();
Session(char *uuid, CoreSession *a_leg = NULL);
Session(switch_core_session_t *session);
~Session();
class Session:public CoreSession {
private:
virtual void do_hangup_hook();
PerlInterpreter *getPERL();
PerlInterpreter *my_perl;
int hh;
int mark;
SV *me;
public:
Session();
Session(char *uuid, CoreSession * a_leg = NULL);
Session(switch_core_session_t *session);
~Session();
virtual void destroy(void);
virtual bool begin_allow_threads();
virtual bool end_allow_threads();
virtual void check_hangup_hook();
virtual void destroy(void);
virtual bool begin_allow_threads();
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 setME(SV *p);
void setInputCallback(char *cbfunc = "on_input", char *funcargs = NULL);
void unsetInputCallback(void);
void setHangupHook(char *func, char *arg=NULL);
bool ready();
char *suuid;
char *cb_function;
char *cb_arg;
char *hangup_func_str;
char *hangup_func_arg;
void setPERL(PerlInterpreter *pi);
};
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
void setME(SV * p);
void setInputCallback(char *cbfunc = "on_input", char *funcargs = NULL);
void unsetInputCallback(void);
void setHangupHook(char *func, char *arg = NULL);
bool ready();
char *suuid;
char *cb_function;
char *cb_arg;
char *hangup_func_str;
char *hangup_func_arg;
void setPERL(PerlInterpreter * pi);
};
}
#endif
+2 -2
View File
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -282,7 +282,7 @@ static void *SWITCH_THREAD_FUNC perl_thread_run(switch_thread_t *thread, void *o
if (po->d) {
free(po);
}
return NULL;
}
+2 -4
View File
@@ -1,9 +1,7 @@
#ifndef MOD_PERL_EXTRA
#define MOD_PERL_EXTRA
SWITCH_BEGIN_EXTERN_C
void mod_perl_conjure_event(PerlInterpreter *my_perl, switch_event_t *event, const char *name);
void mod_perl_conjure_stream(PerlInterpreter *my_perl, switch_stream_handle_t *stream, const char *name);
SWITCH_BEGIN_EXTERN_C void mod_perl_conjure_event(PerlInterpreter * my_perl, switch_event_t *event, const char *name);
void mod_perl_conjure_stream(PerlInterpreter * my_perl, switch_stream_handle_t *stream, const char *name);
SWITCH_END_EXTERN_C
#endif
@@ -5,47 +5,45 @@ extern "C" {
#include <Python.h>
#include "mod_python_extra.h"
}
#include <switch_cpp.h>
namespace PYTHON {
class Session : public CoreSession {
private:
virtual void do_hangup_hook();
PyObject *getPython();
PyObject *Py;
PyObject *Self;
int hh;
int mark;
PyThreadState *TS;
public:
Session();
Session(char *nuuid, CoreSession *a_leg = NULL);
Session(switch_core_session_t *session);
virtual ~Session();
virtual bool begin_allow_threads();
virtual bool end_allow_threads();
virtual void check_hangup_hook();
virtual void destroy(void);
class Session:public CoreSession {
private:
virtual void do_hangup_hook();
PyObject *getPython();
PyObject *Py;
PyObject *Self;
int hh;
int mark;
PyThreadState *TS;
public:
Session();
Session(char *nuuid, CoreSession * a_leg = NULL);
Session(switch_core_session_t *session);
virtual ~ Session();
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
void setInputCallback(PyObject *cbfunc, PyObject *funcargs = NULL);
void unsetInputCallback(void);
void setHangupHook(PyObject *pyfunc, PyObject *arg = NULL);
bool ready();
PyObject *cb_function;
PyObject *cb_arg;
PyObject *hangup_func;
PyObject *hangup_func_arg;
virtual bool begin_allow_threads();
virtual bool end_allow_threads();
virtual void check_hangup_hook();
virtual void destroy(void);
/* keep a pointer to parent module, internal use only*/
void setPython(PyObject *state);
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
void setInputCallback(PyObject * cbfunc, PyObject * funcargs = NULL);
void unsetInputCallback(void);
void setHangupHook(PyObject * pyfunc, PyObject * arg = NULL);
bool ready();
/* keeps the PyObject * version of the Session so it can be used as args to the callback */
void setSelf(PyObject *state);
PyObject *cb_function;
PyObject *cb_arg;
PyObject *hangup_func;
PyObject *hangup_func_arg;
};
/* keep a pointer to parent module, internal use only */
void setPython(PyObject * state);
/* keeps the PyObject * version of the Session so it can be used as args to the callback */
void setSelf(PyObject * state);
};
}
#endif
+30 -34
View File
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -61,7 +61,7 @@ static struct {
} globals;
struct switch_py_thread {
struct switch_py_thread *prev, *next;
struct switch_py_thread *prev, *next;
char *cmd;
char *args;
switch_memory_pool_t *pool;
@@ -70,7 +70,8 @@ struct switch_py_thread {
struct switch_py_thread *thread_pool_head = NULL;
static switch_mutex_t *THREAD_POOL_LOCK = NULL;
static void eval_some_python(const char *funcname, char *args, switch_core_session_t *session, switch_stream_handle_t *stream, switch_event_t *params, char **str, struct switch_py_thread *pt)
static void eval_some_python(const char *funcname, char *args, switch_core_session_t *session, switch_stream_handle_t *stream, switch_event_t *params,
char **str, struct switch_py_thread *pt)
{
PyThreadState *tstate = NULL;
char *dupargs = NULL;
@@ -103,7 +104,7 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
}
script = strdup(switch_str_nil(argv[0]));
lead = 1;
if ((p = strstr(script, "::"))) {
@@ -115,13 +116,13 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Invoking py module: %s\n", script);
tstate = PyThreadState_New(mainThreadState->interp);
if (!tstate) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error acquiring tstate\n");
goto done;
}
/* Save state in thread struct so we can terminate it later if needed */
if (pt)
pt->tstate = tstate;
@@ -146,9 +147,8 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
PyErr_Clear();
goto done_swap_out;
}
// get the handler function to be called
function = PyObject_GetAttrString(module, (char *)funcname);
function = PyObject_GetAttrString(module, (char *) funcname);
if (!function) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Module does not define %s\n", funcname);
PyErr_Print();
@@ -183,13 +183,13 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
} else {
arg = Py_BuildValue("(s)", switch_str_nil(argv[1]));
}
// invoke the handler
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call python script \n");
result = PyEval_CallObjectWithKeywords(function, arg, (PyObject *) NULL);
Py_DECREF(function);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Finished calling python script \n");
// check the result and print out any errors
if (result) {
if (str) {
@@ -204,24 +204,24 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
PyGC_Collect();
}
done_swap_out:
done_swap_out:
if (arg) {
Py_DECREF(arg);
}
if (sp) {
Py_DECREF(sp);
}
if (tstate) {
// thread state must be cleared explicitly or we'll get memory leaks
PyThreadState_Clear(tstate);
PyEval_ReleaseThread(tstate);
PyThreadState_Delete(tstate);
}
done:
done:
switch_safe_free(dupargs);
switch_safe_free(script);
@@ -231,7 +231,7 @@ static void eval_some_python(const char *funcname, char *args, switch_core_sessi
static switch_xml_t python_fetch(const char *section,
const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
{
switch_xml_t xml = NULL;
@@ -300,20 +300,20 @@ static switch_status_t do_config(void)
* we must decrease the default python recursion limit accordingly. Otherwise, python can easily blow
* up the stack and the whole switch crashes. See modlang-134
*/
static void set_max_recursion_depth(void) {
static void set_max_recursion_depth(void)
{
// assume that a stack frame is approximately 1K, so divide thread stack size (eg, 240K) by
// 1K to get the approx number of stack frames we can hold before blowing up.
int newMaxRecursionDepth = SWITCH_THREAD_STACKSIZE / 1024;
PyObject *sysModule = PyImport_ImportModule("sys");
PyObject *setRecursionLimit = PyObject_GetAttrString(sysModule, "setrecursionlimit");
PyObject *recLimit = Py_BuildValue("(i)",newMaxRecursionDepth);
PyObject *recLimit = Py_BuildValue("(i)", newMaxRecursionDepth);
PyObject *setrecursion_result = PyEval_CallObjectWithKeywords(setRecursionLimit, recLimit, (PyObject *) NULL);
if (setrecursion_result) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set python recursion limit to %d\n", newMaxRecursionDepth);
}
else {
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set recursion limit to %d\n", newMaxRecursionDepth);
PyErr_Print();
PyErr_Clear();
@@ -365,7 +365,7 @@ static void *SWITCH_THREAD_FUNC py_thread_run(switch_thread_t *thread, void *obj
SWITCH_STANDARD_API(api_python)
{
eval_some_python("fsapi", (char *) cmd, session, stream, NULL, NULL, NULL);
return SWITCH_STATUS_SUCCESS;
@@ -430,7 +430,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_python_load)
// initialize python system
Py_Initialize();
// create GIL and a threadstate
PyEval_InitThreads();
@@ -479,11 +479,10 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_python_shutdown)
pt = thread_pool_head;
PyEval_AcquireLock();
while (pt) {
thread_cnt ++;
thread_cnt++;
nextpt = pt->next;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Forcibly terminating script [%s]\n", pt->args);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Forcibly terminating script [%s]\n", pt->args);
/* Kill python script */
PyThreadState_Swap(pt->tstate);
@@ -495,13 +494,12 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_python_shutdown)
PyEval_ReleaseLock();
switch_yield(1000000);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Had to kill %d threads\n", thread_cnt);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Had to kill %d threads\n", thread_cnt);
/* Give threads a few seconds to terminate.
Not using switch_thread_join() since if threads refuse to die
then freeswitch will hang */
for (i=0; i < 10 && thread_pool_head; i++) {
for (i = 0; i < 10 && thread_pool_head; i++) {
switch_yield(1000000);
}
if (thread_pool_head) {
@@ -509,12 +507,10 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_python_shutdown)
pt = thread_pool_head;
while (pt) {
nextpt = pt->next;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Script [%s] didn't exit in time\n", pt->args);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Script [%s] didn't exit in time\n", pt->args);
pt = nextpt;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Forcing python shutdown. This might cause freeswitch to crash!\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Forcing python shutdown. This might cause freeswitch to crash!\n");
}
+11 -13
View File
@@ -1,11 +1,9 @@
SWITCH_BEGIN_EXTERN_C
PyObject *mod_python_conjure_event(switch_event_t *event)
SWITCH_BEGIN_EXTERN_C PyObject * mod_python_conjure_event(switch_event_t *event)
{
PyObject *obj;
Event *result = new Event(event, 0);
obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Event, SWIG_POINTER_OWN );
obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Event, SWIG_POINTER_OWN);
return obj;
}
@@ -16,18 +14,18 @@ PyObject *mod_python_conjure_stream(switch_stream_handle_t *stream)
PyObject *obj;
Stream *result = new Stream(stream);
obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Stream, SWIG_POINTER_OWN );
obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Stream, SWIG_POINTER_OWN);
return obj;
}
PyObject *mod_python_conjure_session(PyObject *module, switch_core_session_t *session)
PyObject *mod_python_conjure_session(PyObject * module, switch_core_session_t *session)
{
PyObject *obj;
PYTHON::Session *result = new PYTHON::Session(session);
PYTHON::Session * result = new PYTHON::Session(session);
obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_PYTHON__Session, SWIG_POINTER_OWN);
result->setPython(module);
result->setSelf(obj);
@@ -39,18 +37,18 @@ PyObject *mod_python_conjure_session(PyObject *module, switch_core_session_t *se
#endif
return obj;
}
PyObject *mod_python_conjure_DTMF(char digit, int32_t duration)
{
PyObject *obj;
DTMF *result = new DTMF(digit, duration);
obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_DTMF, SWIG_POINTER_OWN);
return obj;
}
@@ -1,10 +1,8 @@
#ifndef MOD_PYTHON_EXTRA
#define MOD_PYTHON_EXTRA
SWITCH_BEGIN_EXTERN_C
PyObject *mod_python_conjure_event(switch_event_t *event);
SWITCH_BEGIN_EXTERN_C PyObject * mod_python_conjure_event(switch_event_t *event);
PyObject *mod_python_conjure_stream(switch_stream_handle_t *stream);
PyObject *mod_python_conjure_session(PyObject *module, switch_core_session_t *session);
PyObject *mod_python_conjure_session(PyObject * module, switch_core_session_t *session);
PyObject *mod_python_conjure_DTMF(char digit, int32_t duration);
SWITCH_END_EXTERN_C
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -38,7 +38,7 @@
#include <curl/curl.h>
#endif
static int foo = 0;
static jsval check_hangup_hook(struct js_session *jss, jsval *rp);
static jsval check_hangup_hook(struct js_session *jss, jsval * rp);
SWITCH_MODULE_LOAD_FUNCTION(mod_spidermonkey_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_spidermonkey_shutdown);
@@ -924,7 +924,7 @@ static switch_status_t sm_load_file(char *filename)
err = "Could not allocate memory\n";
}
err:
err:
if (err || !module) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Loading module %s\n**%s**\n", filename, switch_str_nil(err));
@@ -1104,7 +1104,7 @@ static switch_status_t js_common_callback(switch_core_session_t *session, void *
char var_name[SWITCH_UUID_FORMATTED_LENGTH + 25];
char *p;
switch_status_t status = SWITCH_STATUS_FALSE;
if (!jss || !jss->session) {
return SWITCH_STATUS_FALSE;
}
@@ -1117,13 +1117,13 @@ static switch_status_t js_common_callback(switch_core_session_t *session, void *
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
switch_snprintf(var_name, sizeof(var_name), "__event_%s", uuid_str);
for(p = var_name; p && *p; p++) {
for (p = var_name; p && *p; p++) {
if (*p == '-') {
*p = '_';
}
}
}
JS_ResumeRequest(cb_state->cx, cb_state->saveDepth);
METHOD_SANITY_CHECK();
@@ -1151,7 +1151,7 @@ static switch_status_t js_common_callback(switch_core_session_t *session, void *
case SWITCH_INPUT_TYPE_DTMF:
{
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
if (dtmf) {
if ((Event = new_js_dtmf(dtmf, var_name, cb_state->cx, cb_state->obj))) {
argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cb_state->cx, "dtmf"));
@@ -1175,7 +1175,7 @@ static switch_status_t js_common_callback(switch_core_session_t *session, void *
}
status = SWITCH_STATUS_SUCCESS;
done:
done:
cb_state->saveDepth = JS_SuspendRequest(cb_state->cx);
jss->stack_depth--;
return status;
@@ -1450,7 +1450,7 @@ static JSBool session_recordfile(JSContext * cx, JSObject * obj, uintN argc, jsv
args.input_callback = dtmf_func;
args.buf = bp;
args.buflen = len;
switch_ivr_record_file(jss->session, &fh, file_name, &args, limit);
JS_ResumeRequest(cx, cb_state.saveDepth);
check_hangup_hook(jss, &ret);
@@ -1594,7 +1594,7 @@ static JSBool session_sayphrase(JSContext * cx, JSObject * obj, uintN argc, jsva
return ret;
}
static jsval check_hangup_hook(struct js_session *jss, jsval *rp)
static jsval check_hangup_hook(struct js_session *jss, jsval * rp)
{
jsval argv[3] = { 0 };
int argc = 0;
@@ -1753,7 +1753,7 @@ static JSBool session_sleep(JSContext * cx, JSObject * obj, uintN argc, jsval *
int32 ms = 0;
jsval ret = JS_TRUE;
int32 sync = 0;
METHOD_SANITY_CHECK();
channel = switch_core_session_get_channel(jss->session);
CHANNEL_SANITY_CHECK();
@@ -2123,7 +2123,9 @@ static JSBool session_answered(JSContext * cx, JSObject * obj, uintN argc, jsval
{
struct js_session *jss = JS_GetPrivate(cx, obj);
*rval = BOOLEAN_TO_JSVAL((jss && jss->session && switch_channel_test_flag(switch_core_session_get_channel(jss->session), CF_ANSWERED)) ? JS_TRUE : JS_FALSE);
*rval =
BOOLEAN_TO_JSVAL((jss && jss->session
&& switch_channel_test_flag(switch_core_session_get_channel(jss->session), CF_ANSWERED)) ? JS_TRUE : JS_FALSE);
return JS_TRUE;
}
@@ -2186,7 +2188,7 @@ static JSBool session_wait_for_answer(JSContext * cx, JSObject * obj, uintN argc
int32 timeout = 60000;
jsrefcount saveDepth;
jsval ret = JS_TRUE;
METHOD_SANITY_CHECK();
channel = switch_core_session_get_channel(jss->session);
@@ -2200,8 +2202,8 @@ static JSBool session_wait_for_answer(JSContext * cx, JSObject * obj, uintN argc
}
if (check_hangup_hook(jss, NULL) != JS_TRUE) {
return JS_FALSE;
}
return JS_FALSE;
}
saveDepth = JS_SuspendRequest(cx);
for (;;) {
@@ -2245,7 +2247,7 @@ static JSBool session_detach(JSContext * cx, JSObject * obj, uintN argc, jsval *
cause = switch_channel_str2cause(cause_name);
}
}
if (cause) {
channel = switch_core_session_get_channel(session);
switch_channel_hangup(channel, cause);
@@ -2289,7 +2291,7 @@ static JSBool session_execute(JSContext * cx, JSObject * obj, uintN argc, jsval
if (check_hangup_hook(jss, NULL) != JS_TRUE) {
return JS_FALSE;
}
saveDepth = JS_SuspendRequest(cx);
switch_core_session_exec(jss->session, application_interface, app_arg);
JS_ResumeRequest(cx, saveDepth);
@@ -2826,7 +2828,7 @@ static JSBool session_construct(JSContext * cx, JSObject * obj, uintN argc, jsva
{
struct js_session *jss = NULL;
JSObject *session_obj = NULL;
jss = malloc(sizeof(*jss));
switch_assert(jss);
memset(jss, 0, sizeof(*jss));
@@ -2835,7 +2837,7 @@ static JSBool session_construct(JSContext * cx, JSObject * obj, uintN argc, jsva
JS_SetPrivate(cx, obj, jss);
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
if (argc > 0) {
char *uuid = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
@@ -2851,7 +2853,7 @@ static JSBool session_construct(JSContext * cx, JSObject * obj, uintN argc, jsva
old_jss = JS_GetPrivate(cx, session_obj);
}
}
if (switch_ivr_originate(old_jss ? old_jss->session : NULL,
if (switch_ivr_originate(old_jss ? old_jss->session : NULL,
&jss->session, &jss->cause, uuid, 60, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL) == SWITCH_STATUS_SUCCESS) {
switch_set_flag(jss, S_HUP);
switch_channel_set_state(switch_core_session_get_channel(jss->session), CS_SOFT_EXECUTE);
@@ -2948,18 +2950,18 @@ static JSBool session_originate(JSContext * cx, JSObject * obj, uintN argc, jsva
if (JS_ValueToObject(cx, argv[0], &session_obj)) {
struct js_session *old_jss = NULL;
if (session_obj && (old_jss = JS_GetPrivate(cx, session_obj))) {
if (old_jss == jss) {
eval_some_js("~throw new Error(\"Supplied a_leg session is the same as our session\");", cx, obj, rval);
return JS_FALSE;
};
if (!old_jss->session) {
eval_some_js("~throw new Error(\"Supplied a_leg session is not initilaized!\");", cx, obj, rval);
return JS_FALSE;
}
session = old_jss->session;
orig_caller_profile = switch_channel_get_caller_profile(switch_core_session_get_channel(session));
dialplan = orig_caller_profile->dialplan;
@@ -3013,7 +3015,8 @@ static JSBool session_originate(JSContext * cx, JSObject * obj, uintN argc, jsva
caller_profile = switch_caller_profile_new(pool, username, dialplan, cid_name, cid_num, network_addr, ani, aniii, rdnis, modname, context, dest);
saveDepth = JS_SuspendRequest(cx);
status = switch_ivr_originate(session, &peer_session, &jss->cause, dest, to ? atoi(to) : 60, NULL, NULL, NULL, caller_profile, NULL, SOF_NONE, NULL);
status =
switch_ivr_originate(session, &peer_session, &jss->cause, dest, to ? atoi(to) : 60, NULL, NULL, NULL, caller_profile, NULL, SOF_NONE, NULL);
JS_ResumeRequest(cx, saveDepth);
if (status != SWITCH_STATUS_SUCCESS) {
@@ -3374,7 +3377,7 @@ static JSBool js_api_sleep(JSContext * cx, JSObject * obj, uintN argc, jsval * a
if (argc > 0) {
JS_ValueToInt32(cx, argv[0], &msec);
}
}
if (msec) {
switch_yield(msec * 1000);
@@ -3437,7 +3440,7 @@ static JSBool js_api_execute(JSContext * cx, JSObject * obj, uintN argc, jsval *
SWITCH_STANDARD_STREAM(stream);
switch_api_execute(cmd, arg, session, &stream);
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_str_nil((char *)stream.data)));
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_str_nil((char *) stream.data)));
switch_safe_free(stream.data);
} else {
@@ -3597,7 +3600,7 @@ static void js_parse_and_execute(switch_core_session_t *session, const char *inp
struct js_session *jss;
JSContext *cx = NULL;
jsval rval;
if (zstr(input_code)) {
return;
}
@@ -3624,7 +3627,7 @@ static void js_parse_and_execute(switch_core_session_t *session, const char *inp
script = input_code;
if (*script != '~') {
if (*script != '~') {
if ((arg = strchr(script, ' '))) {
*arg++ = '\0';
argc = switch_separate_string(arg, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
@@ -3771,7 +3774,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_spidermonkey_shutdown)
{
// this causes a crash
//JS_DestroyRuntime(globals.rt);
curl_global_cleanup();
switch_core_hash_destroy(&module_manager.mod_hash);
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -150,7 +150,7 @@ struct js_session {
struct js_session_speech *speech;
};
JSBool DEFAULT_SET_PROPERTY(JSContext * cx, JSObject *obj, jsval id, jsval *vp)
JSBool DEFAULT_SET_PROPERTY(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
eval_some_js("~throw new Error(\"this property cannot be changed!\");", cx, obj, vp);
return JS_FALSE;
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -190,10 +190,10 @@ static JSBool db_step_ex(JSContext * cx, JSObject * obj, uintN argc, jsval * arg
break;
} else if (result == SWITCH_CORE_DB_BUSY) {
running++;
switch_cond_next(); /* wait a bit before retrying */
switch_cond_next(); /* wait a bit before retrying */
continue;
}
if (switch_core_db_finalize(dbo->stmt) != SWITCH_CORE_DB_OK) {
}
if (switch_core_db_finalize(dbo->stmt) != SWITCH_CORE_DB_OK) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", switch_core_db_errmsg(dbo->db));
}
dbo->stmt = NULL;
@@ -209,7 +209,7 @@ static JSBool db_step_ex(JSContext * cx, JSObject * obj, uintN argc, jsval * arg
*/
static JSBool db_next(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
/* return true until no more rows available */
/* return true until no more rows available */
return db_step_ex(cx, obj, argc, argv, rval, SWITCH_CORE_DB_ROW);
}
@@ -218,7 +218,7 @@ static JSBool db_next(JSContext * cx, JSObject * obj, uintN argc, jsval * argv,
*/
static JSBool db_step(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
/* return true when the statement has finished executing successfully */
/* return true when the statement has finished executing successfully */
return db_step_ex(cx, obj, argc, argv, rval, SWITCH_CORE_DB_DONE);
}
@@ -242,7 +242,7 @@ static JSBool db_fetch(JSContext * cx, JSObject * obj, uintN argc, jsval * argv,
for (x = 0; x < colcount; x++) {
const char *var = (char *) switch_core_db_column_name(dbo->stmt, x);
const char *val = (char *) switch_core_db_column_text(dbo->stmt, x);
if (var && val) {
switch_snprintf(code, sizeof(code), "~_dB_RoW_DaTa_[\"%s\"] = \"%s\"", var, val);
eval_some_js(code, dbo->cx, dbo->obj, rval);
@@ -289,7 +289,7 @@ static JSBool db_bind_text(JSContext * cx, JSObject * obj, uintN argc, jsval * a
struct db_obj *dbo = JS_GetPrivate(cx, obj);
JSBool status;
int32 param_index = -1;
char *param_value = NULL;
char *param_value = NULL;
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
@@ -297,26 +297,26 @@ static JSBool db_bind_text(JSContext * cx, JSObject * obj, uintN argc, jsval * a
return JS_FALSE;
}
/* db_prepare() must be called first */
/* db_prepare() must be called first */
if (!dbo->stmt) {
return JS_FALSE;
}
/* argv[0] = parameter index
argv[1] = parameter value
*/
argv[1] = parameter value
*/
if (argc < 2) {
return JS_FALSE;
}
/* convert args */
status = JS_ValueToECMAUint32(cx, argv[0], (uint32*)&param_index);
status = JS_ValueToECMAUint32(cx, argv[0], (uint32 *) & param_index);
switch_assert(status == JS_TRUE);
param_value = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
param_value = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
if ((param_index < 1) || (NULL == param_value)) {
return JS_FALSE;
return JS_FALSE;
}
/* bind param */
@@ -343,26 +343,26 @@ static JSBool db_bind_int(JSContext * cx, JSObject * obj, uintN argc, jsval * ar
return JS_FALSE;
}
/* db_prepare() must be called first */
/* db_prepare() must be called first */
if (!dbo->stmt) {
return JS_FALSE;
}
/* argv[0] = parameter index
argv[1] = parameter value
*/
argv[1] = parameter value
*/
if (argc < 2) {
return JS_FALSE;
}
/* convert args */
status = JS_ValueToECMAUint32(cx, argv[0], (uint32*)&param_index);
status = JS_ValueToECMAUint32(cx, argv[0], (uint32 *) & param_index);
switch_assert(status == JS_TRUE);
status = JS_ValueToECMAUint32(cx, argv[1], (uint32*)&param_value);
status = JS_ValueToECMAUint32(cx, argv[1], (uint32 *) & param_value);
switch_assert(status == JS_TRUE);
if (param_index < 1) {
return JS_FALSE;
if (param_index < 1) {
return JS_FALSE;
}
/* bind param */
@@ -456,7 +456,7 @@ const sm_module_interface_t DB_module_interface = {
/*.next */ NULL
};
SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &DB_module_interface;
return SWITCH_STATUS_SUCCESS;
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -128,7 +128,7 @@ static JSBool curl_run(JSContext * cx, JSObject * obj, uintN argc, jsval * argv,
curl_easy_setopt(co->curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(co->curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
}
if (argc > 2) {
data = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
@@ -240,7 +240,7 @@ const sm_module_interface_t curl_module_interface = {
/*.next */ NULL
};
SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
curl_global_init(CURL_GLOBAL_ALL);
*module_interface = &curl_module_interface;
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -86,7 +86,7 @@ switch_odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
return switch_odbc_handle_connect(obj->handle);
}
static void destroy_odbc_obj(odbc_obj_t **objp)
static void destroy_odbc_obj(odbc_obj_t ** objp)
{
odbc_obj_t *obj = *objp;
if (obj == NULL)
@@ -271,7 +271,7 @@ static JSBool odbc_num_rows(JSContext * cx, JSObject * obj, uintN argc, jsval *
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
SQLLEN row_count = 0;
if (!odbc_obj || switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
goto done;
@@ -401,7 +401,7 @@ static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval *
return JS_TRUE;
}
if ( SQLNumResultCols( odbc_obj->stmt, &nColumns ) != SQL_SUCCESS )
if (SQLNumResultCols(odbc_obj->stmt, &nColumns) != SQL_SUCCESS)
return JS_FALSE;
for (x = 1; x <= nColumns; x++) {
@@ -431,7 +431,7 @@ static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval *
JS_GetProperty(cx, obj, "_oDbC_dB_RoW_DaTa_", rval);
return JS_TRUE;
}
@@ -466,7 +466,7 @@ static JSBool odbc_disconnect(JSContext * cx, JSObject * obj, uintN argc, jsval
switch_odbc_handle_disconnect(odbc_obj->handle);
done:
done:
return JS_TRUE;
}
@@ -543,7 +543,7 @@ const sm_module_interface_t odbc_module_interface = {
/*.next */ NULL
};
SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &odbc_module_interface;
return SWITCH_STATUS_SUCCESS;
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -93,7 +93,7 @@ const sm_module_interface_t skel_module_interface = {
/*.next */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &skel_module_interface;
return SWITCH_STATUS_SUCCESS;
@@ -324,7 +324,7 @@ const sm_module_interface_t socket_module_interface = {
/*.next */ NULL
};
SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &socket_module_interface;
return SWITCH_STATUS_SUCCESS;
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -80,7 +80,7 @@ static JSBool teletone_construct(JSContext * cx, JSObject * obj, uintN argc, jsv
struct js_session *jss = NULL;
switch_memory_pool_t *pool;
char *timer_name = NULL;
switch_codec_implementation_t read_impl = {0};
switch_codec_implementation_t read_impl = { 0 };
@@ -109,15 +109,14 @@ static JSBool teletone_construct(JSContext * cx, JSObject * obj, uintN argc, jsv
return JS_FALSE;
}
switch_core_session_get_read_impl(jss->session, &read_impl);
switch_core_session_get_read_impl(jss->session, &read_impl);
if (switch_core_codec_init(&tto->codec,
"L16",
NULL,
read_impl.actual_samples_per_second,
read_impl.microseconds_per_packet / 1000,
read_impl.number_of_channels,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) {
read_impl.number_of_channels, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed\n");
@@ -127,10 +126,7 @@ static JSBool teletone_construct(JSContext * cx, JSObject * obj, uintN argc, jsv
if (timer_name) {
unsigned int ms = read_impl.microseconds_per_packet / 1000;
if (switch_core_timer_init(&tto->timer_base,
timer_name,
ms,
(read_impl.samples_per_second / 50) *
read_impl.number_of_channels, pool) == SWITCH_STATUS_SUCCESS) {
timer_name, ms, (read_impl.samples_per_second / 50) * read_impl.number_of_channels, pool) == SWITCH_STATUS_SUCCESS) {
tto->timer = &tto->timer_base;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timer INIT Success %u\n", ms);
} else {
@@ -347,7 +343,7 @@ const sm_module_interface_t teletone_module_interface = {
/*.next */ NULL
};
SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &teletone_module_interface;
return SWITCH_STATUS_SUCCESS;
+80 -91
View File
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -37,65 +37,56 @@ SWITCH_MODULE_DEFINITION(mod_yaml, mod_yaml_load, NULL, NULL);
static void print_error(yaml_parser_t *parser)
{
switch (parser->error)
{
case YAML_MEMORY_ERROR:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory error: Not enough memory for parsing\n");
break;
switch (parser->error) {
case YAML_MEMORY_ERROR:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory error: Not enough memory for parsing\n");
break;
case YAML_READER_ERROR:
if (parser->problem_value != -1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Reader error: %s: #%X at %d\n", parser->problem,
parser->problem_value, (int) parser->problem_offset);
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Reader error: %s at %d\n", parser->problem,
(int) parser->problem_offset);
}
break;
case YAML_SCANNER_ERROR:
if (parser->context) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Scanner error: %s at line %d, column %d\n"
"%s at line %d, column %d\n", parser->context,
(int)parser->context_mark.line+1, (int)parser->context_mark.column+1,
parser->problem, (int)parser->problem_mark.line+1,
(int)parser->problem_mark.column+1);
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Scanner error: %s at line %d, column %d\n",
parser->problem, (int)parser->problem_mark.line+1,
(int)parser->problem_mark.column+1);
}
break;
case YAML_PARSER_ERROR:
if (parser->context) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parser error: %s at line %d, column %d\n"
"%s at line %d, column %d\n", parser->context,
(int)parser->context_mark.line+1, (int)parser->context_mark.column+1,
parser->problem, (int)parser->problem_mark.line+1,
(int)parser->problem_mark.column+1);
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parser error: %s at line %d, column %d\n",
parser->problem, (int)parser->problem_mark.line+1,
(int)parser->problem_mark.column+1);
}
break;
default:
/* Couldn't happen. */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Internal error\n");
break;
case YAML_READER_ERROR:
if (parser->problem_value != -1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Reader error: %s: #%X at %d\n", parser->problem,
parser->problem_value, (int) parser->problem_offset);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Reader error: %s at %d\n", parser->problem, (int) parser->problem_offset);
}
break;
case YAML_SCANNER_ERROR:
if (parser->context) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Scanner error: %s at line %d, column %d\n"
"%s at line %d, column %d\n", parser->context,
(int) parser->context_mark.line + 1, (int) parser->context_mark.column + 1,
parser->problem, (int) parser->problem_mark.line + 1, (int) parser->problem_mark.column + 1);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Scanner error: %s at line %d, column %d\n",
parser->problem, (int) parser->problem_mark.line + 1, (int) parser->problem_mark.column + 1);
}
break;
case YAML_PARSER_ERROR:
if (parser->context) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parser error: %s at line %d, column %d\n"
"%s at line %d, column %d\n", parser->context,
(int) parser->context_mark.line + 1, (int) parser->context_mark.column + 1,
parser->problem, (int) parser->problem_mark.line + 1, (int) parser->problem_mark.column + 1);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parser error: %s at line %d, column %d\n",
parser->problem, (int) parser->problem_mark.line + 1, (int) parser->problem_mark.column + 1);
}
break;
default:
/* Couldn't happen. */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Internal error\n");
break;
}
}
static switch_xml_t parse_file(FILE *input, const char *file_name)
static switch_xml_t parse_file(FILE * input, const char *file_name)
{
yaml_parser_t parser;
yaml_event_t event = {0};
yaml_event_t event = { 0 };
char *scalar_data;
int done = 0;
int depth = 0;
@@ -108,7 +99,7 @@ static switch_xml_t parse_file(FILE *input, const char *file_name)
yaml_parser_initialize(&parser);
yaml_parser_set_input_file(&parser, input);
if (!(xml = switch_xml_new("document"))) {
return NULL;
}
@@ -119,7 +110,7 @@ static switch_xml_t parse_file(FILE *input, const char *file_name)
top = switch_xml_add_child_d(current, "configuration", 0);
switch_xml_set_attr_d(top, "name", file_name);
while (!done) {
if (!yaml_parser_parse(&parser, &event)) {
print_error(&parser);
@@ -139,7 +130,7 @@ static switch_xml_t parse_file(FILE *input, const char *file_name)
scalar_data = (char *) event.data.scalar.value;
switch (depth) {
case 1:
if (!(current = switch_xml_add_child_d(top, scalar_data, depth-1))) {
if (!(current = switch_xml_add_child_d(top, scalar_data, depth - 1))) {
done = 1;
}
switch_set_string(category, scalar_data);
@@ -161,7 +152,7 @@ static switch_xml_t parse_file(FILE *input, const char *file_name)
}
break;
}
break;
default:
break;
@@ -169,14 +160,13 @@ static switch_xml_t parse_file(FILE *input, const char *file_name)
}
yaml_event_delete(&event);
}
}
yaml_parser_delete(&parser);
if (input) {
fclose(input);
}
#ifdef DEBUG_XML
if (xml) {
char *foo = switch_xml_toxml(xml, SWITCH_FALSE);
@@ -186,11 +176,11 @@ static switch_xml_t parse_file(FILE *input, const char *file_name)
#endif
return xml;
}
static switch_xml_t yaml_fetch(const char *section,
const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
{
char *path;
FILE *input;
@@ -201,17 +191,17 @@ static switch_xml_t yaml_fetch(const char *section,
xml = parse_file(input, key_value);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "cannot open %s\n", path);
}
}
switch_safe_free(path);
return xml;
}
static switch_caller_extension_t *parse_dp(FILE *input, switch_core_session_t *session, switch_caller_profile_t *caller_profile)
static switch_caller_extension_t *parse_dp(FILE * input, switch_core_session_t *session, switch_caller_profile_t *caller_profile)
{
yaml_parser_t parser;
yaml_event_t event = {0};
yaml_event_t event = { 0 };
char *scalar_data;
int done = 0;
int depth = 0;
@@ -221,7 +211,7 @@ static switch_caller_extension_t *parse_dp(FILE *input, switch_core_session_t *s
char *last_field = NULL;
int nv = 0;
switch_caller_extension_t *extension = NULL;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_t *channel = switch_core_session_get_channel(session);
int context_hit = 0;
int proceed = 0;
switch_regex_t *re = NULL;
@@ -244,7 +234,7 @@ static switch_caller_extension_t *parse_dp(FILE *input, switch_core_session_t *s
yaml_parser_initialize(&parser);
yaml_parser_set_input_file(&parser, input);
while (!done) {
if (!yaml_parser_parse(&parser, &event)) {
print_error(&parser);
@@ -273,19 +263,19 @@ static switch_caller_extension_t *parse_dp(FILE *input, switch_core_session_t *s
char *field = switch_core_session_strdup(session, scalar_data);
char *p, *e, *expression = NULL, *field_expanded = NULL, *expression_expanded = NULL;
const char *field_data = NULL;
parens = 0;
proceed = 0;
switch_regex_safe_free(re);
if ((p = strstr(field, "=~"))) {
*p = '\0';
e = p-1;
while(*e == ' ') {
e = p - 1;
while (*e == ' ') {
*e-- = '\0';
}
e = p+2;
while(*e == ' ') {
e = p + 2;
while (*e == ' ') {
*e++ = '\0';
}
expression = e;
@@ -313,7 +303,7 @@ static switch_caller_extension_t *parse_dp(FILE *input, switch_core_session_t *s
}
switch_safe_free(last_field);
last_field = strdup(field_data);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "test conditions %s(%s) =~ /%s/\n", field, field_data, expression);
if (!(proceed = switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Regex mismatch\n");
@@ -344,12 +334,12 @@ static switch_caller_extension_t *parse_dp(FILE *input, switch_core_session_t *s
char *substituted = NULL;
char *app_data;
if (!extension) {
extension = switch_caller_extension_new(session, "YAML", caller_profile->destination_number);
switch_assert(extension);
}
if (parens) {
len = (uint32_t) (strlen(value) + strlen(last_field) + 10) * proceed;
switch_zmalloc(substituted, len);
@@ -358,14 +348,14 @@ static switch_caller_extension_t *parse_dp(FILE *input, switch_core_session_t *s
} else {
app_data = value;
}
switch_caller_extension_add_application(session, extension, name, app_data);
switch_safe_free(substituted);
}
}
break;
}
}
break;
default:
break;
@@ -375,7 +365,7 @@ static switch_caller_extension_t *parse_dp(FILE *input, switch_core_session_t *s
yaml_event_delete(&event);
}
end:
end:
switch_safe_free(last_field);
switch_regex_safe_free(re);
@@ -384,7 +374,6 @@ static switch_caller_extension_t *parse_dp(FILE *input, switch_core_session_t *s
if (input) {
fclose(input);
}
#ifdef DEBUG_XML
if (xml) {
char *foo = switch_xml_toxml(xml, SWITCH_FALSE);
@@ -394,7 +383,7 @@ static switch_caller_extension_t *parse_dp(FILE *input, switch_core_session_t *s
#endif
return extension;
}
SWITCH_STANDARD_DIALPLAN(yaml_dialplan_hunt)
@@ -414,9 +403,9 @@ SWITCH_STANDARD_DIALPLAN(yaml_dialplan_hunt)
extension = parse_dp(input, session, caller_profile);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
}
switch_safe_free(path);
}
switch_safe_free(path);
return extension;
}
@@ -424,7 +413,7 @@ SWITCH_STANDARD_DIALPLAN(yaml_dialplan_hunt)
static switch_status_t do_config(void)
{
yaml_parser_t parser;
yaml_event_t event = {0};
yaml_event_t event = { 0 };
char *path;
const char *cfg = "mod_yaml.yaml";
FILE *input;
@@ -438,7 +427,7 @@ static switch_status_t do_config(void)
int nv = 0;
path = switch_mprintf("%s/yaml/%s", SWITCH_GLOBAL_dirs.conf_dir, cfg);
if (!(input = fopen(path, "r"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
goto end;
@@ -485,7 +474,7 @@ static switch_status_t do_config(void)
}
break;
}
break;
default:
break;
@@ -493,21 +482,21 @@ static switch_status_t do_config(void)
}
yaml_event_delete(&event);
}
}
yaml_parser_delete(&parser);
status = SWITCH_STATUS_SUCCESS;
end:
end:
if (input) {
fclose(input);
}
switch_safe_free(path);
return status;
}
SWITCH_MODULE_LOAD_FUNCTION(mod_yaml_load)