[asterisk-commits] mnicholson: trunk r317721 - in /trunk: CHANGES pbx/pbx_lua.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 6 13:04:32 CDT 2011


Author: mnicholson
Date: Fri May  6 13:04:23 2011
New Revision: 317721

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=317721
Log:
Detect Goto in pbx_lua.

This code will actually detect any dialplan jump from any application that
calls ast_explicit_goto().  This change is only being done in trunk as it may
change the way some dialplans execute.

Modified:
    trunk/CHANGES
    trunk/pbx/pbx_lua.c

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=317721&r1=317720&r2=317721
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Fri May  6 13:04:23 2011
@@ -114,6 +114,14 @@
 --------------------------
  * cel_pgsql now supports the 'extra' column for data added using the
    CELGenUserEvent() application.
+
+pbx_lua
+--------------------------
+ * Applications that perform jumps in the dialplan such as Goto will now
+   execute properly. When pbx_lua detects that the context, extension, or
+   priority we are executing on has changed it will immediatly return control
+   to the asterisk PBX engine. Currently the engine cannot detect a Goto to the
+   priority after the currently executing priority.
 
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 1.6.2 to Asterisk 1.8 ----------------

Modified: trunk/pbx/pbx_lua.c
URL: http://svnview.digium.com/svn/asterisk/trunk/pbx/pbx_lua.c?view=diff&rev=317721&r1=317720&r2=317721
==============================================================================
--- trunk/pbx/pbx_lua.c (original)
+++ trunk/pbx/pbx_lua.c Fri May  6 13:04:23 2011
@@ -51,6 +51,11 @@
 
 #define LUA_EXT_DATA_SIZE 256
 #define LUA_BUF_SIZE 4096
+
+/* This value is used by the lua engine to signal that a Goto or dialplan jump
+ * was detected. Ensure this value does not conflict with any values dialplan
+ * applications might return */
+#define LUA_GOTO_DETECTED 5
 
 static char *lua_read_extensions_file(lua_State *L, long *size);
 static int lua_load_extensions(lua_State *L, struct ast_channel *chan);
@@ -84,6 +89,7 @@
 static void lua_create_application_metatable(lua_State *L);
 static void lua_create_autoservice_functions(lua_State *L);
 static void lua_create_hangup_function(lua_State *L);
+static void lua_detect_goto(lua_State *L);
 
 static void lua_state_destroy(void *data);
 static void lua_datastore_fixup(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan);
@@ -254,7 +260,70 @@
 		lua_pushinteger(L, res);
 		return lua_error(L);
 	}
+
+	lua_detect_goto(L);
+
 	return 0;
+}
+
+/*!
+ * \brief Detect if a Goto or other dialplan jump has been executed and return
+ * control to the pbx engine.
+ */
+static void lua_detect_goto(lua_State *L)
+{
+	struct ast_channel *chan;
+
+	lua_getfield(L, LUA_REGISTRYINDEX, "channel");
+	chan = lua_touserdata(L, -1);
+	lua_pop(L, 1);
+
+	/* check context */
+	lua_getfield(L, LUA_REGISTRYINDEX, "context");
+	lua_pushstring(L, chan->context);
+	if (!lua_equal(L, -1, -2)) {
+		lua_pushliteral(L, "context");
+		goto e_goto_detected;
+	}
+	lua_pop(L, 2);
+
+	/* check exten */
+	lua_getfield(L, LUA_REGISTRYINDEX, "exten");
+	lua_pushstring(L, chan->exten);
+	if (!lua_equal(L, -1, -2)) {
+		lua_pushliteral(L, "exten");
+		goto e_goto_detected;
+	}
+	lua_pop(L, 2);
+
+	/* check priority */
+	lua_getfield(L, LUA_REGISTRYINDEX, "priority");
+	lua_pushinteger(L, chan->priority);
+	if (!lua_equal(L, -1, -2)) {
+		lua_pushliteral(L, "priority");
+		goto e_goto_detected;
+	}
+	lua_pop(L, 2);
+	return;
+
+e_goto_detected:
+	/* format our debug message */
+	lua_insert(L, -3);
+
+	lua_pushliteral(L, " changed from ");
+	lua_insert(L, -3);
+
+	lua_pushliteral(L, " to ");
+	lua_insert(L, -2);
+
+	lua_concat(L, 5);
+
+	ast_debug(2, "Goto detected: %s\n", lua_tostring(L, -1));
+	lua_pop(L, 1);
+
+	/* let the lua engine know it needs to return control to the pbx */
+	lua_pushinteger(L, LUA_GOTO_DETECTED);
+	lua_error(L);
 }
 
 /*!
@@ -1372,6 +1441,10 @@
 			res = -1;
 			if (lua_isnumber(L, -1)) {
 				res = lua_tointeger(L, -1);
+
+				if (res == LUA_GOTO_DETECTED) {
+					res = 0;
+				}
 			} else if (lua_isstring(L, -1)) {
 				const char *error = lua_tostring(L, -1);
 				ast_log(LOG_ERROR, "Error executing lua extension: %s\n", error);




More information about the asterisk-commits mailing list