1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
--- a/pbx/pbx_lua.c.orig 2011-12-08 08:28:31.000000000 +0200
+++ b/pbx/pbx_lua.c 2011-12-08 08:54:22.000000000 +0200
@@ -94,7 +94,6 @@
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_concat_args(lua_State *L, int start, int nargs);
static void lua_state_destroy(void *data);
@@ -213,19 +212,10 @@
chan = lua_touserdata(L, -1);
lua_pop(L, 1);
+ context = ast_strdupa(chan->context);
+ exten = ast_strdupa(chan->exten);
+ priority = chan->priority;
- lua_getfield(L, LUA_REGISTRYINDEX, "context");
- context = ast_strdupa(lua_tostring(L, -1));
- lua_pop(L, 1);
-
- lua_getfield(L, LUA_REGISTRYINDEX, "exten");
- exten = ast_strdupa(lua_tostring(L, -1));
- lua_pop(L, 1);
-
- lua_getfield(L, LUA_REGISTRYINDEX, "priority");
- priority = lua_tointeger(L, -1);
- lua_pop(L, 1);
-
lua_concat_args(L, 2, nargs);
data = lua_tostring(L, -1);
@@ -256,75 +246,51 @@
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)) {
+ if (strcmp(context, chan->context)) {
+ lua_pushstring(L, context);
+ lua_pushstring(L, chan->context);
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)) {
+ } else if (strcmp(exten, chan->exten)) {
+ lua_pushstring(L, exten);
+ lua_pushstring(L, chan->exten);
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)) {
+ } else if (priority != chan->priority) {
+ lua_pushinteger(L, priority);
+ lua_pushinteger(L, chan->priority);
lua_pushliteral(L, "priority");
- goto e_goto_detected;
+ } else {
+ /* no goto - restore the original position back
+ * to lua state, in case this was a recursive dialplan
+ * call (a dialplan application re-entering dialplan) */
+ lua_update_registry(L, context, exten, priority);
+ return 0;
}
- lua_pop(L, 2);
- return;
-
-e_goto_detected:
- /* format our debug message */
- lua_insert(L, -3);
- lua_pushliteral(L, " changed from ");
+ /* goto detected - construct error message */
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_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);
+
+ return 0;
}
/*!
* \brief [lua_CFunction] Used to get the value of a variable or dialplan
* function (for access from lua, don't call directly)
- *
+ *
* The value of the variable or function is returned. This function is the
* 'get()' function in the following example as would be seen in
* extensions.lua.
|