277
275
autoloopflag = ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP);
278
276
ast_set_flag(chan, AST_FLAG_IN_AUTOLOOP);
279
277
while(ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
278
struct ast_context *c;
280
runningapp[0] = '\0';
281
runningdata[0] = '\0';
280
283
/* What application will execute? */
281
for (c = ast_walk_contexts(NULL), e = NULL; c; c = ast_walk_contexts(c)) {
282
if (!strcmp(ast_get_context_name(c), chan->context)) {
283
e = find_matching_priority(c, chan->exten, chan->priority, chan->cid.cid_num);
284
if (ast_lock_contexts()) {
285
ast_log(LOG_WARNING, "Failed to lock contexts list\n");
287
for (c = ast_walk_contexts(NULL), e = NULL; c; c = ast_walk_contexts(c)) {
288
if (!strcmp(ast_get_context_name(c), chan->context)) {
289
if (ast_lock_context(c)) {
290
ast_log(LOG_WARNING, "Unable to lock context?\n");
292
e = find_matching_priority(c, chan->exten, chan->priority, chan->cid.cid_num);
293
if (e) { /* This will only be undefined for pbx_realtime, which is majorly broken. */
294
ast_copy_string(runningapp, ast_get_extension_app(e), sizeof(runningapp));
295
ast_copy_string(runningdata, ast_get_extension_app_data(e), sizeof(runningdata));
297
ast_unlock_context(c);
303
ast_unlock_contexts();
288
305
/* Reset the macro depth, if it was changed in the last iteration */
289
306
pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
320
ast_log(LOG_DEBUG, "Executed application: %s\n", ast_get_extension_app(e));
337
ast_log(LOG_DEBUG, "Executed application: %s\n", runningapp);
322
if (e && !strcasecmp(ast_get_extension_app(e), "GOSUB")) {
339
if (!strcasecmp(runningapp, "GOSUB")) {
324
341
ast_log(LOG_DEBUG, "Incrementing gosub_level\n");
325
} else if (e && !strcasecmp(ast_get_extension_app(e), "GOSUBIF")) {
326
const char *tmp = ast_get_extension_app_data(e);
342
} else if (!strcasecmp(runningapp, "GOSUBIF")) {
327
343
char tmp2[1024] = "", *cond, *app, *app2 = tmp2;
328
pbx_substitute_variables_helper(chan, tmp, tmp2, sizeof(tmp2) - 1);
344
pbx_substitute_variables_helper(chan, runningdata, tmp2, sizeof(tmp2) - 1);
329
345
cond = strsep(&app2, "?");
330
346
app = strsep(&app2, ":");
331
347
if (pbx_checkcondition(cond)) {
339
355
ast_log(LOG_DEBUG, "Incrementing gosub_level\n");
342
} else if (e && !strcasecmp(ast_get_extension_app(e), "RETURN")) {
344
ast_log(LOG_DEBUG, "Decrementing gosub_level\n");
345
} else if (e && !strcasecmp(ast_get_extension_app(e), "STACKPOP")) {
347
ast_log(LOG_DEBUG, "Decrementing gosub_level\n");
348
} else if (e && !strncasecmp(ast_get_extension_app(e), "EXEC", 4)) {
358
} else if (!strcasecmp(runningapp, "RETURN")) {
360
ast_log(LOG_DEBUG, "Decrementing gosub_level\n");
361
} else if (!strcasecmp(runningapp, "STACKPOP")) {
363
ast_log(LOG_DEBUG, "Decrementing gosub_level\n");
364
} else if (!strncasecmp(runningapp, "EXEC", 4)) {
349
365
/* Must evaluate args to find actual app */
350
const char *tmp = ast_get_extension_app_data(e);
351
366
char tmp2[1024] = "", *tmp3 = NULL;
352
pbx_substitute_variables_helper(chan, tmp, tmp2, sizeof(tmp2) - 1);
353
if (!strcasecmp(ast_get_extension_app(e), "EXECIF")) {
367
pbx_substitute_variables_helper(chan, runningdata, tmp2, sizeof(tmp2) - 1);
368
if (!strcasecmp(runningapp, "EXECIF")) {
354
369
tmp3 = strchr(tmp2, '|');