mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-23 19:54:17 +00:00
indent pass 2
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8689 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
9bbcabbbdd
commit
f930eaeec7
101 files changed
+31644
-31458
No files matched your search
@@ -8,17 +8,17 @@ static STRLEN n_a;
|
||||
|
||||
using namespace PERL;
|
||||
|
||||
Session::Session() : CoreSession()
|
||||
Session::Session():CoreSession()
|
||||
{
|
||||
init_me();
|
||||
}
|
||||
|
||||
Session::Session(char *uuid) : CoreSession(uuid)
|
||||
Session::Session(char *uuid):CoreSession(uuid)
|
||||
{
|
||||
init_me();
|
||||
}
|
||||
|
||||
Session::Session(switch_core_session_t *new_session) : CoreSession(new_session)
|
||||
Session::Session(switch_core_session_t *new_session):CoreSession(new_session)
|
||||
{
|
||||
init_me();
|
||||
}
|
||||
@@ -37,19 +37,19 @@ Session::~Session()
|
||||
|
||||
}
|
||||
|
||||
bool Session::begin_allow_threads()
|
||||
bool Session::begin_allow_threads()
|
||||
{
|
||||
do_hangup_hook();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Session::end_allow_threads()
|
||||
bool Session::end_allow_threads()
|
||||
{
|
||||
do_hangup_hook();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Session::setPERL(PerlInterpreter *pi)
|
||||
void Session::setPERL(PerlInterpreter * pi)
|
||||
{
|
||||
my_perl = pi;
|
||||
}
|
||||
@@ -57,30 +57,31 @@ void Session::setPERL(PerlInterpreter *pi)
|
||||
PerlInterpreter *Session::getPERL()
|
||||
{
|
||||
if (!my_perl) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
|
||||
}
|
||||
return my_perl;
|
||||
}
|
||||
|
||||
|
||||
bool Session::ready() {
|
||||
bool Session::ready()
|
||||
{
|
||||
bool r;
|
||||
|
||||
sanity_check(false);
|
||||
sanity_check(false);
|
||||
r = switch_channel_ready(channel) != 0;
|
||||
do_hangup_hook();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void Session::check_hangup_hook()
|
||||
void Session::check_hangup_hook()
|
||||
{
|
||||
if (hangup_func_str && (hook_state == CS_HANGUP || hook_state == CS_ROUTING)) {
|
||||
hh++;
|
||||
}
|
||||
}
|
||||
|
||||
void Session::do_hangup_hook()
|
||||
void Session::do_hangup_hook()
|
||||
{
|
||||
if (hh && !mark) {
|
||||
const char *err = NULL;
|
||||
@@ -101,7 +102,7 @@ void Session::do_hangup_hook()
|
||||
}
|
||||
}
|
||||
|
||||
static switch_status_t perl_hanguphook(switch_core_session_t *session_hungup)
|
||||
static switch_status_t perl_hanguphook(switch_core_session_t *session_hungup)
|
||||
{
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session_hungup);
|
||||
CoreSession *coresession = NULL;
|
||||
@@ -118,7 +119,8 @@ static switch_status_t perl_hanguphook(switch_core_session_t *session_hungup)
|
||||
}
|
||||
|
||||
|
||||
void Session::setHangupHook(char *func, char *arg) {
|
||||
void Session::setHangupHook(char *func, char *arg)
|
||||
{
|
||||
|
||||
sanity_check_noreturn;
|
||||
|
||||
@@ -135,7 +137,8 @@ void Session::setHangupHook(char *func, char *arg) {
|
||||
}
|
||||
}
|
||||
|
||||
void Session::setInputCallback(char *cbfunc, char *funcargs) {
|
||||
void Session::setInputCallback(char *cbfunc, char *funcargs)
|
||||
{
|
||||
|
||||
sanity_check_noreturn;
|
||||
|
||||
@@ -148,22 +151,22 @@ void Session::setInputCallback(char *cbfunc, char *funcargs) {
|
||||
if (funcargs) {
|
||||
cb_arg = strdup(funcargs);
|
||||
}
|
||||
|
||||
|
||||
args.buf = this;
|
||||
switch_channel_set_private(channel, "CoreSession", this);
|
||||
|
||||
args.input_callback = dtmf_callback;
|
||||
args.input_callback = dtmf_callback;
|
||||
ap = &args;
|
||||
}
|
||||
|
||||
switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t itype)
|
||||
switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t itype)
|
||||
{
|
||||
if (!getPERL()) {
|
||||
return SWITCH_STATUS_FALSE;;
|
||||
}
|
||||
|
||||
switch (itype) {
|
||||
case SWITCH_INPUT_TYPE_DTMF:
|
||||
case SWITCH_INPUT_TYPE_DTMF:
|
||||
{
|
||||
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
|
||||
char str[32] = "";
|
||||
@@ -177,14 +180,14 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
|
||||
}
|
||||
|
||||
str[0] = dtmf->digit;
|
||||
this_sv = newSV(strlen(str)+1);
|
||||
this_sv = newSV(strlen(str) + 1);
|
||||
sv_setpv(this_sv, str);
|
||||
hv_store(hash, "digit", 5, this_sv, 0);
|
||||
|
||||
switch_snprintf(str, sizeof(str), "%d", dtmf->duration);
|
||||
this_sv = newSV(strlen(str)+1);
|
||||
this_sv = newSV(strlen(str) + 1);
|
||||
sv_setpv(this_sv, str);
|
||||
hv_store(hash, "duration", 8, this_sv, 0);
|
||||
hv_store(hash, "duration", 8, this_sv, 0);
|
||||
|
||||
code = switch_mprintf("$__RV = %s('dtmf', \\%%__dtmf, %s);", cb_function, switch_str_nil(cb_arg));
|
||||
Perl_eval_pv(my_perl, code, FALSE);
|
||||
@@ -193,18 +196,18 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
|
||||
return process_callback_result(SvPV(get_sv("__RV", TRUE), n_a));
|
||||
}
|
||||
break;
|
||||
case SWITCH_INPUT_TYPE_EVENT:
|
||||
case SWITCH_INPUT_TYPE_EVENT:
|
||||
{
|
||||
switch_event_t *event = (switch_event_t *) input;
|
||||
int arg_count = 2;
|
||||
char *code;
|
||||
|
||||
mod_perl_conjure_event(my_perl, event, "__Input_Event__");
|
||||
|
||||
|
||||
code = switch_mprintf("$__RV = %s('event', $__Input_Event__, %s);", cb_function, switch_str_nil(cb_arg));
|
||||
Perl_eval_pv(my_perl, code, TRUE);
|
||||
free(code);
|
||||
|
||||
|
||||
return process_callback_result(SvPV(get_sv("__RV", TRUE), n_a));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -58,7 +58,7 @@ static struct {
|
||||
|
||||
|
||||
|
||||
static int Perl_safe_eval(PerlInterpreter *my_perl, const char *string)
|
||||
static int Perl_safe_eval(PerlInterpreter * my_perl, const char *string)
|
||||
{
|
||||
char *err = NULL;
|
||||
|
||||
@@ -73,7 +73,7 @@ static int Perl_safe_eval(PerlInterpreter *my_perl, const char *string)
|
||||
|
||||
|
||||
|
||||
static int perl_parse_and_execute(PerlInterpreter *my_perl, char *input_code, char *setup_code)
|
||||
static int perl_parse_and_execute(PerlInterpreter * my_perl, char *input_code, char *setup_code)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
@@ -103,10 +103,10 @@ static int perl_parse_and_execute(PerlInterpreter *my_perl, char *input_code, ch
|
||||
if ((argc = switch_separate_string(args, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
|
||||
switch_stream_handle_t stream = { 0 };
|
||||
SWITCH_STANDARD_STREAM(stream);
|
||||
|
||||
|
||||
stream.write_function(&stream, " @ARGV = ( ");
|
||||
for (x = 0; x < argc; x++) {
|
||||
stream.write_function(&stream, "'%s'%s", argv[x], x == argc-1 ? "" : ", ");
|
||||
stream.write_function(&stream, "'%s'%s", argv[x], x == argc - 1 ? "" : ", ");
|
||||
}
|
||||
stream.write_function(&stream, " );");
|
||||
code = stream.data;
|
||||
@@ -130,7 +130,7 @@ static int perl_parse_and_execute(PerlInterpreter *my_perl, char *input_code, ch
|
||||
file = switch_mprintf("require '%s';", file);
|
||||
switch_assert(file);
|
||||
}
|
||||
|
||||
|
||||
error = Perl_safe_eval(my_perl, file);
|
||||
switch_safe_free(file);
|
||||
}
|
||||
@@ -154,14 +154,15 @@ static PerlInterpreter *clone_perl(void)
|
||||
}
|
||||
|
||||
#if 0
|
||||
static perl_parse_and_execute (PerlInterpreter *my_perl, char *input_code, char *setup_code)
|
||||
static perl_parse_and_execute(PerlInterpreter * my_perl, char *input_code, char *setup_code)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
if (*input_code == '~') {
|
||||
char *buff = input_code + 1;
|
||||
perl_parse(my_perl, xs_init, 3, embedding, NULL);
|
||||
if (setup_code) Perl_safe_eval(my_perl, setup_code);
|
||||
if (setup_code)
|
||||
Perl_safe_eval(my_perl, setup_code);
|
||||
Perl_safe_eval(my_perl, buff);
|
||||
} else {
|
||||
int argc = 0;
|
||||
@@ -169,43 +170,38 @@ static perl_parse_and_execute (PerlInterpreter *my_perl, char *input_code, char
|
||||
char *err;
|
||||
argv[0] = "FreeSWITCH";
|
||||
argc++;
|
||||
|
||||
|
||||
argc += switch_separate_string(input_code, ' ', &argv[1], (sizeof(argv) / sizeof(argv[0])) - 1);
|
||||
if (!perl_parse(my_perl, xs_init, argc, argv, (char **)NULL)) {
|
||||
if (!perl_parse(my_perl, xs_init, argc, argv, (char **) NULL)) {
|
||||
if (setup_code) {
|
||||
if (!Perl_safe_eval(my_perl, setup_code)) {
|
||||
perl_run(my_perl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((err = SvPV(get_sv("@", TRUE), n_a)) && !switch_strlen_zero(err)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static void perl_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
char *uuid = switch_core_session_get_uuid(session);
|
||||
PerlInterpreter *my_perl = clone_perl();
|
||||
char code[1024];
|
||||
|
||||
|
||||
perl_parse(my_perl, xs_init, 3, embedding, NULL);
|
||||
Perl_safe_eval(my_perl, code);
|
||||
|
||||
switch_snprintf(code, sizeof(code),
|
||||
"use lib '%s/perl';\n"
|
||||
"use freeswitch;\n"
|
||||
"$SWITCH_ENV{UUID} = \"%s\";\n"
|
||||
"$session = new freeswitch::Session(\"%s\")"
|
||||
,
|
||||
SWITCH_GLOBAL_dirs.base_dir,
|
||||
uuid,
|
||||
uuid);
|
||||
switch_snprintf(code, sizeof(code),
|
||||
"use lib '%s/perl';\n"
|
||||
"use freeswitch;\n"
|
||||
"$SWITCH_ENV{UUID} = \"%s\";\n" "$session = new freeswitch::Session(\"%s\")", SWITCH_GLOBAL_dirs.base_dir, uuid, uuid);
|
||||
|
||||
perl_parse_and_execute(my_perl, data, code);
|
||||
Perl_safe_eval(my_perl, "undef $session;");
|
||||
@@ -244,16 +240,10 @@ static void *SWITCH_THREAD_FUNC perl_thread_run(switch_thread_t *thread, void *o
|
||||
if (session) {
|
||||
uuid = switch_core_session_get_uuid(session);
|
||||
}
|
||||
|
||||
switch_snprintf(code, sizeof(code),
|
||||
"use lib '%s/perl';\n"
|
||||
"use freeswitch;\n"
|
||||
"$SWITCH_ENV{UUID} = \"%s\";\n"
|
||||
,
|
||||
|
||||
SWITCH_GLOBAL_dirs.base_dir,
|
||||
switch_str_nil(uuid)
|
||||
);
|
||||
switch_snprintf(code, sizeof(code),
|
||||
"use lib '%s/perl';\n" "use freeswitch;\n" "$SWITCH_ENV{UUID} = \"%s\";\n", SWITCH_GLOBAL_dirs.base_dir, switch_str_nil(uuid)
|
||||
);
|
||||
|
||||
perl_parse(my_perl, xs_init, 3, embedding, NULL);
|
||||
Perl_safe_eval(my_perl, code);
|
||||
@@ -273,7 +263,7 @@ static void *SWITCH_THREAD_FUNC perl_thread_run(switch_thread_t *thread, void *o
|
||||
//Perl_safe_eval(my_perl, cmd);
|
||||
perl_parse_and_execute(my_perl, cmd, NULL);
|
||||
}
|
||||
|
||||
|
||||
if (uuid) {
|
||||
switch_snprintf(code, sizeof(code), "undef $session;", uuid);
|
||||
Perl_safe_eval(my_perl, code);
|
||||
@@ -301,7 +291,7 @@ int perl_thread(const char *text)
|
||||
memset(po, 0, sizeof(*po));
|
||||
po->cmd = strdup(text);
|
||||
po->d = 1;
|
||||
|
||||
|
||||
switch_threadattr_create(&thd_attr, globals.pool);
|
||||
switch_threadattr_detach_set(thd_attr, 1);
|
||||
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
|
||||
@@ -310,7 +300,8 @@ int perl_thread(const char *text)
|
||||
return 0;
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_API(perlrun_api_function) {
|
||||
SWITCH_STANDARD_API(perlrun_api_function)
|
||||
{
|
||||
|
||||
if (switch_strlen_zero(cmd)) {
|
||||
stream->write_function(stream, "-ERR Missing args.\n");
|
||||
@@ -322,7 +313,8 @@ SWITCH_STANDARD_API(perlrun_api_function) {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_API(perl_api_function) {
|
||||
SWITCH_STANDARD_API(perl_api_function)
|
||||
{
|
||||
|
||||
struct perl_o po = { 0 };
|
||||
|
||||
@@ -337,12 +329,8 @@ SWITCH_STANDARD_API(perl_api_function) {
|
||||
perl_thread_run(NULL, &po);
|
||||
}
|
||||
|
||||
static switch_xml_t perl_fetch(const char *section,
|
||||
const char *tag_name,
|
||||
const char *key_name,
|
||||
const char *key_value,
|
||||
switch_event_t *params,
|
||||
void *user_data)
|
||||
static switch_xml_t perl_fetch(const char *section,
|
||||
const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
|
||||
{
|
||||
|
||||
char *argv[128] = { 0 };
|
||||
@@ -359,10 +347,10 @@ static switch_xml_t perl_fetch(const char *section,
|
||||
|
||||
argv[argc++] = "FreeSWITCH";
|
||||
argv[argc++] = globals.xml_handler;
|
||||
|
||||
|
||||
PERL_SET_CONTEXT(my_perl);
|
||||
|
||||
if (perl_parse(my_perl, xs_init, argc, argv, (char **)NULL)) {
|
||||
|
||||
if (perl_parse(my_perl, xs_init, argc, argv, (char **) NULL)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
|
||||
return NULL;
|
||||
}
|
||||
@@ -375,15 +363,15 @@ static switch_xml_t perl_fetch(const char *section,
|
||||
section = "";
|
||||
}
|
||||
|
||||
this = newSV(strlen(section)+1);
|
||||
this = newSV(strlen(section) + 1);
|
||||
sv_setpv(this, section);
|
||||
hv_store(hash, "section", 7, this, 0);
|
||||
|
||||
|
||||
if (switch_strlen_zero(tag_name)) {
|
||||
tag_name = "";
|
||||
}
|
||||
|
||||
this = newSV(strlen(tag_name)+1);
|
||||
this = newSV(strlen(tag_name) + 1);
|
||||
sv_setpv(this, tag_name);
|
||||
hv_store(hash, "tag_name", 8, this, 0);
|
||||
|
||||
@@ -391,7 +379,7 @@ static switch_xml_t perl_fetch(const char *section,
|
||||
key_name = "";
|
||||
}
|
||||
|
||||
this = newSV(strlen(key_name)+1);
|
||||
this = newSV(strlen(key_name) + 1);
|
||||
sv_setpv(this, key_name);
|
||||
hv_store(hash, "key_name", 8, this, 0);
|
||||
|
||||
@@ -399,28 +387,23 @@ static switch_xml_t perl_fetch(const char *section,
|
||||
key_value = "";
|
||||
}
|
||||
|
||||
this = newSV(strlen(key_value)+1);
|
||||
this = newSV(strlen(key_value) + 1);
|
||||
sv_setpv(this, key_value);
|
||||
hv_store(hash, "key_value", 9, this, 0);
|
||||
|
||||
|
||||
if (!(hash = get_hv("XML_DATA", TRUE))) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (params) {
|
||||
for (hp = params->headers; hp; hp = hp->next) {
|
||||
this = newSV(strlen(hp->value)+1);
|
||||
this = newSV(strlen(hp->value) + 1);
|
||||
sv_setpv(this, hp->value);
|
||||
hv_store(hash, hp->name, strlen(hp->name), this, 0);
|
||||
}
|
||||
}
|
||||
|
||||
switch_snprintf(code, sizeof(code),
|
||||
"use lib '%s/perl';\n"
|
||||
"use freeswitch;\n"
|
||||
,
|
||||
SWITCH_GLOBAL_dirs.base_dir
|
||||
);
|
||||
switch_snprintf(code, sizeof(code), "use lib '%s/perl';\n" "use freeswitch;\n", SWITCH_GLOBAL_dirs.base_dir);
|
||||
Perl_safe_eval(my_perl, code);
|
||||
|
||||
if (params) {
|
||||
@@ -437,7 +420,7 @@ static switch_xml_t perl_fetch(const char *section,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing XML Result!\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
destroy_perl(&my_perl);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
SWITCH_BEGIN_EXTERN_C
|
||||
|
||||
|
||||
void mod_perl_conjure_event(PerlInterpreter *my_perl, switch_event_t *event, const char *name)
|
||||
SWITCH_BEGIN_EXTERN_C void mod_perl_conjure_event(PerlInterpreter * my_perl, switch_event_t *event, const char *name)
|
||||
{
|
||||
Event *result = 0 ;
|
||||
Event *result = 0;
|
||||
SV *sv;
|
||||
PERL_SET_CONTEXT(my_perl);
|
||||
sv = sv_2mortal(get_sv(name, TRUE));
|
||||
result = (Event *)new Event(event);
|
||||
sv = sv_2mortal(get_sv(name, TRUE));
|
||||
result = (Event *) new Event(event);
|
||||
SWIG_Perl_MakePtr(sv, result, SWIGTYPE_p_Event, SWIG_OWNER | SWIG_SHADOW);
|
||||
}
|
||||
|
||||
|
||||
void mod_perl_conjure_stream(PerlInterpreter *my_perl, switch_stream_handle_t *stream, const char *name)
|
||||
void mod_perl_conjure_stream(PerlInterpreter * my_perl, switch_stream_handle_t *stream, const char *name)
|
||||
{
|
||||
Stream *result = 0 ;
|
||||
Stream *result = 0;
|
||||
SV *sv;
|
||||
PERL_SET_CONTEXT(my_perl);
|
||||
sv = sv_2mortal(get_sv(name, TRUE));
|
||||
result = (Stream *)new Stream(stream);
|
||||
sv = sv_2mortal(get_sv(name, TRUE));
|
||||
result = (Stream *) new Stream(stream);
|
||||
SWIG_Perl_MakePtr(sv, result, SWIGTYPE_p_Stream, SWIG_OWNER | SWIG_SHADOW);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,13 +1,12 @@
|
||||
#include <EXTERN.h>
|
||||
#include <perl.h>
|
||||
|
||||
EXTERN_C void xs_init (pTHX);
|
||||
EXTERN_C void xs_init(pTHX);
|
||||
|
||||
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
|
||||
EXTERN_C void boot_freeswitch (pTHX_ CV* cv);
|
||||
EXTERN_C void boot_DynaLoader(pTHX_ CV * cv);
|
||||
EXTERN_C void boot_freeswitch(pTHX_ CV * cv);
|
||||
|
||||
EXTERN_C void
|
||||
xs_init(pTHX)
|
||||
EXTERN_C void xs_init(pTHX)
|
||||
{
|
||||
char *file = __FILE__;
|
||||
dXSUB_SYS;
|
||||
|
||||
Reference in new issue
Block a user