indent pass 2

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8689 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2008-05-27 04:54:52 +00:00
parent 9bbcabbbdd
commit f930eaeec7
101 changed files with 31644 additions and 31458 deletions
+41 -38
View File
@@ -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;
}
+43 -44
View File
@@ -45,23 +45,23 @@ static struct {
char *xml_handler;
} globals;
int luaopen_freeswitch(lua_State* L);
int luaopen_freeswitch(lua_State * L);
static int panic (lua_State *L)
static int panic(lua_State * L)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "unprotected error in call to Lua API (%s)\n",
lua_tostring(L, -1));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "unprotected error in call to Lua API (%s)\n", lua_tostring(L, -1));
return 0;
}
static void lua_uninit(lua_State *L)
static void lua_uninit(lua_State * L)
{
lua_gc(L, LUA_GCCOLLECT, 0);
lua_close(L);
}
static int traceback (lua_State *L) {
static int traceback(lua_State * L)
{
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
if (!lua_istable(L, -1)) {
lua_pop(L, 1);
@@ -72,30 +72,32 @@ static int traceback (lua_State *L) {
lua_pop(L, 2);
return 1;
}
lua_pushvalue(L, 1); /* pass error message */
lua_pushinteger(L, 2); /* skip this function and traceback */
lua_call(L, 2, 1); /* call debug.traceback */
lua_pushvalue(L, 1); /* pass error message */
lua_pushinteger(L, 2); /* skip this function and traceback */
lua_call(L, 2, 1); /* call debug.traceback */
return 1;
}
static int docall (lua_State *L, int narg, int clear) {
static int docall(lua_State * L, int narg, int clear)
{
int status;
int base = lua_gettop(L) - narg; /* function index */
lua_pushcfunction(L, traceback); /* push traceback function */
lua_insert(L, base); /* put it under chunk and args */
int base = lua_gettop(L) - narg; /* function index */
lua_pushcfunction(L, traceback); /* push traceback function */
lua_insert(L, base); /* put it under chunk and args */
status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
lua_remove(L, base); /* remove traceback function */
lua_remove(L, base); /* remove traceback function */
/* force a complete garbage collection in case of errors */
if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
if (status != 0)
lua_gc(L, LUA_GCCOLLECT, 0);
return status;
}
static lua_State *lua_init(void)
static lua_State *lua_init(void)
{
lua_State *L = lua_open();
int error = 0;
@@ -108,12 +110,12 @@ static lua_State *lua_init(void)
lua_gc(L, LUA_GCRESTART, 0);
lua_atpanic(L, panic);
error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 1);
}
}
return L;
}
static int lua_parse_and_execute(lua_State *L, char *input_code)
static int lua_parse_and_execute(lua_State * L, char *input_code)
{
int error = 0;
@@ -124,7 +126,7 @@ static int lua_parse_and_execute(lua_State *L, char *input_code)
if (*input_code == '~') {
char *buff = input_code + 1;
error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 1); //lua_pcall(L, 0, 0, 0);
error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 1); //lua_pcall(L, 0, 0, 0);
} else {
char *args = strchr(input_code, ' ');
if (args) {
@@ -136,13 +138,13 @@ static int lua_parse_and_execute(lua_State *L, char *input_code)
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 = (char *)stream.data;
code = (char *) stream.data;
} else {
code = switch_mprintf("argv = {};");
}
@@ -154,7 +156,7 @@ static int lua_parse_and_execute(lua_State *L, char *input_code)
}
if (!error) {
char *file = input_code, *fdup = NULL;
if (!switch_is_file_path(file)) {
fdup = switch_mprintf("%s/%s", SWITCH_GLOBAL_dirs.script_dir, file);
switch_assert(fdup);
@@ -170,7 +172,7 @@ static int lua_parse_and_execute(lua_State *L, char *input_code)
if (!switch_strlen_zero(err)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err);
}
lua_pop(L, 1); /* pop error message from the stack */
lua_pop(L, 1); /* pop error message from the stack */
}
return error;
@@ -179,10 +181,10 @@ static int lua_parse_and_execute(lua_State *L, char *input_code)
static void *SWITCH_THREAD_FUNC lua_thread_run(switch_thread_t *thread, void *obj)
{
char *input_code = (char *) obj;
lua_State *L = lua_init(); /* opens Lua */
lua_State *L = lua_init(); /* opens Lua */
lua_parse_and_execute(L, input_code);
if (input_code) {
free(input_code);
}
@@ -193,12 +195,8 @@ static void *SWITCH_THREAD_FUNC lua_thread_run(switch_thread_t *thread, void *ob
}
static switch_xml_t lua_fetch(const char *section,
const char *tag_name,
const char *key_name,
const char *key_value,
switch_event_t *params,
void *user_data)
static switch_xml_t lua_fetch(const char *section,
const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
{
switch_xml_t xml = NULL;
@@ -238,11 +236,11 @@ static switch_xml_t lua_fetch(const char *section,
if (str) {
if (switch_strlen_zero(str)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Result\n");
} else if (!(xml = switch_xml_parse_str((char *)str, strlen(str)))) {
} else if (!(xml = switch_xml_parse_str((char *) str, strlen(str)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing XML Result!\n");
}
}
lua_uninit(L);
free(mycmd);
}
@@ -304,13 +302,13 @@ SWITCH_STANDARD_APP(lua_function)
if (switch_strlen_zero(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "no args specified!\n");
return;
}
return;
}
snprintf(code, sizeof(code), "~session = freeswitch.Session(\"%s\");", switch_core_session_get_uuid(session));
error = lua_parse_and_execute(L, code);
mycmd = strdup((char *)data);
mycmd = strdup((char *) data);
switch_assert(mycmd);
lua_parse_and_execute(L, mycmd);
@@ -319,8 +317,9 @@ SWITCH_STANDARD_APP(lua_function)
}
SWITCH_STANDARD_API(luarun_api_function) {
SWITCH_STANDARD_API(luarun_api_function)
{
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "-ERR no args specified!\n");
} else {
@@ -332,7 +331,8 @@ SWITCH_STANDARD_API(luarun_api_function) {
}
SWITCH_STANDARD_API(lua_api_function) {
SWITCH_STANDARD_API(lua_api_function)
{
lua_State *L = lua_init();
char *mycmd;
@@ -370,13 +370,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load)
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_API(api_interface, "luarun", "run a script", luarun_api_function, "<script>");
SWITCH_ADD_API(api_interface, "lua", "run a script as an api function", lua_api_function, "<script>");
SWITCH_ADD_APP(app_interface, "lua", "Launch LUA ivr", "Run a lua ivr on a channel", lua_function, "<script>", SAF_SUPPORT_NOMEDIA);
globals.pool = pool;
do_config();
@@ -385,7 +385,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load)
}
SWITCH_END_EXTERN_C
/* For Emacs:
* Local Variables:
* mode:c
+4 -7
View File
@@ -1,18 +1,15 @@
SWITCH_BEGIN_EXTERN_C
void mod_lua_conjure_event(lua_State *L, switch_event_t *event, 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)
{
Event *result = new Event(event);
SWIG_NewPointerObj(L,result,SWIGTYPE_p_Event, destroy_me);
SWIG_NewPointerObj(L, result, SWIGTYPE_p_Event, destroy_me);
lua_setglobal(L, name);
}
void mod_lua_conjure_stream(lua_State *L, switch_stream_handle_t *stream, 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)
{
Stream *result = new Stream(stream);
SWIG_NewPointerObj(L,result,SWIGTYPE_p_Stream, destroy_me);
SWIG_NewPointerObj(L, result, SWIGTYPE_p_Stream, destroy_me);
lua_setglobal(L, name);
}
File diff suppressed because it is too large Load Diff