From: Matthew Nicholson Date: Fri, 6 May 2011 19:34:00 +0000 (+0000) Subject: pbx_lua autoservice fixes X-Git-Tag: 1.6.2.19-rc1~3^2~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7eca34890a6bdff1fa411e7969fc7ef9359ae93e;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.6.2@317859 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/pbx/pbx_lua.c b/pbx/pbx_lua.c index c22dab5567..d56fa22f4e 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;