From: Matthew Nicholson Date: Fri, 6 May 2011 19:31:50 +0000 (+0000) Subject: pbx_lua autoservice fixes X-Git-Tag: 1.8.5-rc1~11^2~144 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ed15a49a1ba20dc4e1cbcc55cce42cb39f0ae51;p=thirdparty%2Fasterisk.git pbx_lua autoservice fixes Don't start an autoservice in pbx_lua if pbx_lua already started one and don't stop one if we didn't start one. Also start and stop the autoservice when transferring control from and to the pbx. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@317858 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/pbx/pbx_lua.c b/pbx/pbx_lua.c index 6f667bc3aa..c90d10453a 100644 --- a/pbx/pbx_lua.c +++ b/pbx/pbx_lua.c @@ -656,6 +656,13 @@ static int lua_autoservice_start(lua_State *L) struct ast_channel *chan; int res; + lua_getfield(L, LUA_REGISTRYINDEX, "autoservice"); + if (lua_toboolean(L, -1)) { + /* autoservice already running */ + return 1; + } + lua_pop(L, 1); + lua_getfield(L, LUA_REGISTRYINDEX, "channel"); chan = lua_touserdata(L, -1); lua_pop(L, 1); @@ -687,6 +694,13 @@ static int lua_autoservice_stop(lua_State *L) struct ast_channel *chan; int res; + lua_getfield(L, LUA_REGISTRYINDEX, "autoservice"); + if (!lua_toboolean(L, -1)) { + /* no autoservice running */ + return 1; + } + lua_pop(L, 1); + lua_getfield(L, LUA_REGISTRYINDEX, "channel"); chan = lua_touserdata(L, -1); lua_pop(L, 1); @@ -1278,7 +1292,13 @@ static int exec(struct ast_channel *chan, const char *context, const char *exten ast_module_user_remove(u); return -1; } - + + lua_getfield(L, LUA_REGISTRYINDEX, "autoservice"); + if (lua_toboolean(L, -1)) { + ast_autoservice_start(chan); + } + lua_pop(L, 1); + lua_update_registry(L, context, exten, priority); lua_pushstring(L, context); @@ -1304,6 +1324,13 @@ static int exec(struct ast_channel *chan, const char *context, const char *exten lua_pop(L, 1); } lua_remove(L, error_func); + + lua_getfield(L, LUA_REGISTRYINDEX, "autoservice"); + if (lua_toboolean(L, -1)) { + ast_autoservice_stop(chan); + } + lua_pop(L, 1); + if (!chan) lua_close(L); ast_module_user_remove(u); return res;