~davewalker/ubuntu/maverick/asterisk/lp_705014

« back to all changes in this revision

Viewing changes to apps/app_macro.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Porcheron
  • Date: 2007-06-19 18:08:27 UTC
  • mto: (1.2.1 upstream) (8.2.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: james.westby@ubuntu.com-20070619180827-4d9gqoqys7kel3yk
Tags: upstream-1.4.5~dfsg
ImportĀ upstreamĀ versionĀ 1.4.5~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#include "asterisk.h"
29
29
 
30
 
ASTERISK_FILE_VERSION(__FILE__, "$Revision: 60713 $")
 
30
ASTERISK_FILE_VERSION(__FILE__, "$Revision: 66770 $")
31
31
 
32
32
#include <stdlib.h>
33
33
#include <stdio.h>
147
147
        char *macro;
148
148
        char fullmacro[80];
149
149
        char varname[80];
 
150
        char runningapp[80], runningdata[1024];
150
151
        char *oldargs[MAX_ARGS + 1] = { NULL, };
151
152
        int argc, x;
152
153
        int res=0;
165
166
        char *save_macro_offset;
166
167
        struct ast_module_user *u;
167
168
 
168
 
        struct ast_context *c;
169
 
        struct ast_exten *e;
170
 
 
171
169
        if (ast_strlen_zero(data)) {
172
170
                ast_log(LOG_WARNING, "Macro() requires arguments. See \"show application macro\" for help.\n");
173
171
                return -1;
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;
 
279
                struct ast_exten *e;
 
280
                runningapp[0] = '\0';
 
281
                runningdata[0] = '\0';
 
282
 
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
 
                                break;
 
284
                if (ast_lock_contexts()) {
 
285
                        ast_log(LOG_WARNING, "Failed to lock contexts list\n");
 
286
                } else {
 
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");
 
291
                                        } else {
 
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));
 
296
                                                }
 
297
                                                ast_unlock_context(c);
 
298
                                        }
 
299
                                        break;
 
300
                                }
285
301
                        }
286
302
                }
 
303
                ast_unlock_contexts();
287
304
 
288
305
                /* Reset the macro depth, if it was changed in the last iteration */
289
306
                pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
317
334
                        }
318
335
                }
319
336
 
320
 
                ast_log(LOG_DEBUG, "Executed application: %s\n", ast_get_extension_app(e));
 
337
                ast_log(LOG_DEBUG, "Executed application: %s\n", runningapp);
321
338
 
322
 
                if (e && !strcasecmp(ast_get_extension_app(e), "GOSUB")) {
 
339
                if (!strcasecmp(runningapp, "GOSUB")) {
323
340
                        gosub_level++;
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");
340
356
                                }
341
357
                        }
342
 
                } else if (e && !strcasecmp(ast_get_extension_app(e), "RETURN")) {
343
 
                        gosub_level--;
344
 
                        ast_log(LOG_DEBUG, "Decrementing gosub_level\n");
345
 
                } else if (e && !strcasecmp(ast_get_extension_app(e), "STACKPOP")) {
346
 
                        gosub_level--;
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")) {
 
359
                        gosub_level--;
 
360
                        ast_log(LOG_DEBUG, "Decrementing gosub_level\n");
 
361
                } else if (!strcasecmp(runningapp, "STACKPOP")) {
 
362
                        gosub_level--;
 
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, '|');
355
370
                                if (tmp3)
356
371
                                        *tmp3++ = '\0';