]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
pbx_lua autoservice fixes
authorMatthew Nicholson <mnicholson@digium.com>
Fri, 6 May 2011 19:34:00 +0000 (19:34 +0000)
committerMatthew Nicholson <mnicholson@digium.com>
Fri, 6 May 2011 19:34:00 +0000 (19:34 +0000)
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

pbx/pbx_lua.c

index c22dab5567e642417d79db78ecc1e583bcd0cf35..d56fa22f4e03a2ebb40ac453708c2ed9b5110516 100644 (file)
@@ -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;