mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-08 05:11:51 +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:
@@ -3,19 +3,19 @@
|
||||
#include "freeswitch_lua.h"
|
||||
using namespace LUA;
|
||||
|
||||
Session::Session() : CoreSession()
|
||||
Session::Session():CoreSession()
|
||||
{
|
||||
cb_function = cb_arg = hangup_func_str = hangup_func_arg = NULL;
|
||||
hh = mark = 0;
|
||||
}
|
||||
|
||||
Session::Session(char *uuid) : CoreSession(uuid)
|
||||
Session::Session(char *uuid):CoreSession(uuid)
|
||||
{
|
||||
cb_function = cb_arg = hangup_func_str = hangup_func_arg = NULL;
|
||||
hh = mark = 0;
|
||||
}
|
||||
|
||||
Session::Session(switch_core_session_t *new_session) : CoreSession(new_session)
|
||||
Session::Session(switch_core_session_t *new_session):CoreSession(new_session)
|
||||
{
|
||||
cb_function = cb_arg = hangup_func_str = hangup_func_arg = NULL;
|
||||
hh = mark = 0;
|
||||
@@ -30,25 +30,25 @@ Session::~Session()
|
||||
}
|
||||
free(hangup_func_str);
|
||||
}
|
||||
|
||||
|
||||
switch_safe_free(hangup_func_arg);
|
||||
switch_safe_free(cb_function);
|
||||
switch_safe_free(cb_arg);
|
||||
}
|
||||
|
||||
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::setLUA(lua_State *state)
|
||||
void Session::setLUA(lua_State * state)
|
||||
{
|
||||
L = state;
|
||||
}
|
||||
@@ -56,30 +56,31 @@ void Session::setLUA(lua_State *state)
|
||||
lua_State *Session::getLUA()
|
||||
{
|
||||
if (!L) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
|
||||
}
|
||||
return L;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
@@ -90,25 +91,25 @@ void Session::do_hangup_hook()
|
||||
return;
|
||||
}
|
||||
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, (char *)hangup_func_str);
|
||||
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, (char *) hangup_func_str);
|
||||
|
||||
lua_pushstring(L, hook_state == CS_HANGUP ? "hangup" : "transfer");
|
||||
|
||||
if (hangup_func_arg) {
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, (char *)hangup_func_arg);
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, (char *) hangup_func_arg);
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
|
||||
lua_call(L, arg_count, 1);
|
||||
err = lua_tostring(L, -1);
|
||||
|
||||
if (!switch_strlen_zero(err)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static switch_status_t lua_hanguphook(switch_core_session_t *session_hungup)
|
||||
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;
|
||||
@@ -125,13 +126,14 @@ static switch_status_t lua_hanguphook(switch_core_session_t *session_hungup)
|
||||
}
|
||||
|
||||
|
||||
void Session::setHangupHook(char *func, char *arg) {
|
||||
void Session::setHangupHook(char *func, char *arg)
|
||||
{
|
||||
|
||||
sanity_check_noreturn;
|
||||
|
||||
switch_safe_free(hangup_func_str);
|
||||
switch_safe_free(hangup_func_arg);
|
||||
|
||||
|
||||
if (func) {
|
||||
hangup_func_str = strdup(func);
|
||||
if (!switch_strlen_zero(arg)) {
|
||||
@@ -143,7 +145,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;
|
||||
|
||||
@@ -156,15 +159,15 @@ 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)
|
||||
{
|
||||
const char *ret;
|
||||
|
||||
@@ -173,27 +176,27 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
|
||||
}
|
||||
|
||||
switch (itype) {
|
||||
case SWITCH_INPUT_TYPE_DTMF:
|
||||
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_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);
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, (char *) cb_arg);
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
@@ -201,30 +204,30 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
|
||||
ret = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
return process_callback_result((char *)ret);
|
||||
return process_callback_result((char *) ret);
|
||||
}
|
||||
break;
|
||||
case SWITCH_INPUT_TYPE_EVENT:
|
||||
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_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);
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, (char *) cb_arg);
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
lua_call(L, 2, 1);
|
||||
|
||||
ret = lua_tostring(L, -1);
|
||||
ret = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
return process_callback_result((char *)ret);
|
||||
|
||||
return process_callback_result((char *) ret);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user