From anthm@freeswitch.org Wed Apr 30 21:09:54 2008 From: Freeswitch SVN To: freeswitch-svn@lists.freeswitch.org Subject: [Freeswitch-svn] [commit] r8228 - freeswitch/trunk/src/mod/languages/mod_lua Date: Wed, 30 Apr 2008 21:09:54 -0400 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2481732341388547688==" --===============2481732341388547688== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Author: anthm Date: Wed Apr 30 21:09:54 2008 New Revision: 8228 Modified: freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.c Log: fix Modified: freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.c (original) +++ freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.c Wed Apr 30 21:09:54 = 2008 @@ -109,6 +109,11 @@ { int error =3D 0; =20 + if (switch_strlen_zero(input_code)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No code to execut= e!\n"); + return; + } + if (*input_code =3D=3D '~') { char *buff =3D input_code + 1; error =3D luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 1= ); //lua_pcall(L, 0, 0, 0); @@ -287,15 +292,32 @@ { lua_State *L =3D lua_init(); char code[1024] =3D ""; + char *mycmd; + if (switch_strlen_zero(data)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "no args specified= !\n"); + return; + } + snprintf(code, sizeof(code), "~session =3D freeswitch.Session(\"%s\");", sw= itch_core_session_get_uuid(session)); lua_parse_and_execute(L, code); - lua_parse_and_execute(L, (char *) data); + + mycmd =3D strdup((char *)data); + switch_assert(mycmd); + + lua_parse_and_execute(L, mycmd); lua_uninit(L); + free(mycmd); } =20 SWITCH_STANDARD_API(luarun_api_function) { - lua_thread(cmd); - stream->write_function(stream, "+OK\n"); + + if (switch_strlen_zero(cmd)) { + stream->write_function(stream, "-ERR no args specified!\n"); + } else { + lua_thread(cmd); + stream->write_function(stream, "+OK\n"); + } + return SWITCH_STATUS_SUCCESS; } =20 @@ -303,17 +325,24 @@ SWITCH_STANDARD_API(lua_api_function) { =20 lua_State *L =3D lua_init(); - char *mycmd =3D strdup(cmd); + char *mycmd; +=09 + if (switch_strlen_zero(cmd)) { + stream->write_function(stream, ""); + } else { =20 - switch_assert(mycmd); - mod_lua_conjure_stream(L, stream, "stream", 1); - if (stream->event) { - mod_lua_conjure_event(L, stream->event, "env", 1); - } + mycmd =3D strdup(cmd); + switch_assert(mycmd); + mod_lua_conjure_stream(L, stream, "stream", 1); =20 - lua_parse_and_execute(L, mycmd); - lua_uninit(L); - free(mycmd); + if (stream->event) { + mod_lua_conjure_event(L, stream->event, "env", 1); + } + + lua_parse_and_execute(L, mycmd); + lua_uninit(L); + free(mycmd); + } return SWITCH_STATUS_SUCCESS; } =20 @@ -324,12 +353,12 @@ =20 /* connect my internal structure to the blank pointer passed to me */ *module_interface =3D switch_loadable_module_create_module_interface(pool, = modname); - +=09 SWITCH_ADD_API(api_interface, "luarun", "run a script", luarun_api_function= , "