From c35e4a2d96ba94229ab89e2df16608d8c0848c59 Mon Sep 17 00:00:00 2001 From: automerge Date: Sun, 8 Apr 2007 14:54:53 +0000 Subject: automerge commit git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.2-netsec@60761 f38db490-d61c-443f-a65b-d21fe96a405b --- apps/app_macro.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 2 deletions(-) (limited to 'apps') diff --git a/apps/app_macro.c b/apps/app_macro.c index 45e7d70ab..c38af0a63 100644 --- a/apps/app_macro.c +++ b/apps/app_macro.c @@ -98,6 +98,41 @@ STANDARD_LOCAL_USER; LOCAL_USER_DECL; +static struct ast_exten *find_matching_priority(struct ast_context *c, const char *exten, int priority, const char *callerid) +{ + struct ast_exten *e; + struct ast_include *i; + struct ast_context *c2; + + for (e=ast_walk_context_extensions(c, NULL); e; e=ast_walk_context_extensions(c, e)) { + if (ast_extension_match(ast_get_extension_name(e), exten)) { + int needmatch = ast_get_extension_matchcid(e); + if ((needmatch && ast_extension_match(ast_get_extension_cidmatch(e), callerid)) || + (!needmatch)) { + /* This is the matching extension we want */ + struct ast_exten *p; + for (p=ast_walk_extension_priorities(e, NULL); p; p=ast_walk_extension_priorities(e, p)) { + if (priority != ast_get_extension_priority(p)) + continue; + return p; + } + } + } + } + + /* No match; run through includes */ + for (i=ast_walk_context_includes(c, NULL); i; i=ast_walk_context_includes(c, i)) { + for (c2=ast_walk_contexts(NULL); c2; c2=ast_walk_contexts(c2)) { + if (!strcmp(ast_get_context_name(c2), ast_get_include_name(i))) { + e = find_matching_priority(c2, exten, priority, callerid); + if (e) + return e; + } + } + } + return NULL; +} + static int macro_exec(struct ast_channel *chan, void *data) { char *tmp; @@ -109,7 +144,7 @@ static int macro_exec(struct ast_channel *chan, void *data) int argc, x; int res=0; char oldexten[256]=""; - int oldpriority; + int oldpriority, gosub_level = 0; char pc[80], depthc[12]; char oldcontext[AST_MAX_CONTEXT] = ""; char *offsets, *s, *inhangupc; @@ -123,6 +158,9 @@ static int macro_exec(struct ast_channel *chan, void *data) char *save_macro_offset; struct localuser *u; + struct ast_context *c; + struct ast_exten *e; + if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Macro() requires arguments. See \"show application macro\" for help.\n"); return -1; @@ -228,8 +266,17 @@ static int macro_exec(struct ast_channel *chan, void *data) autoloopflag = ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP); ast_set_flag(chan, AST_FLAG_IN_AUTOLOOP); while(ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) { + /* What application will execute? */ + for (c = ast_walk_contexts(NULL), e = NULL; c; c = ast_walk_contexts(c)) { + if (!strcmp(ast_get_context_name(c), chan->context)) { + e = find_matching_priority(c, chan->exten, chan->priority, chan->cid.cid_num); + break; + } + } + /* Reset the macro depth, if it was changed in the last iteration */ pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc); + if ((res = ast_spawn_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num))) { /* Something bad happened, or a hangup has been requested. */ if (((res >= '0') && (res <= '9')) || ((res >= 'A') && (res <= 'F')) || @@ -258,11 +305,70 @@ static int macro_exec(struct ast_channel *chan, void *data) goto out; } } - if (strcasecmp(chan->context, fullmacro)) { + + ast_log(LOG_DEBUG, "Executed application: %s\n", ast_get_extension_app(e)); + + if (e && !strcasecmp(ast_get_extension_app(e), "GOSUB")) { + gosub_level++; + ast_log(LOG_DEBUG, "Incrementing gosub_level\n"); + } else if (e && !strcasecmp(ast_get_extension_app(e), "GOSUBIF")) { + const char *tmp = ast_get_extension_app_data(e); + char tmp2[1024] = "", *cond, *app, *app2 = tmp2; + pbx_substitute_variables_helper(chan, tmp, tmp2, sizeof(tmp2) - 1); + cond = strsep(&app2, "?"); + app = strsep(&app2, ":"); + if (pbx_checkcondition(cond)) { + if (!ast_strlen_zero(app)) { + gosub_level++; + ast_log(LOG_DEBUG, "Incrementing gosub_level\n"); + } + } else { + if (!ast_strlen_zero(app2)) { + gosub_level++; + ast_log(LOG_DEBUG, "Incrementing gosub_level\n"); + } + } + } else if (e && !strcasecmp(ast_get_extension_app(e), "RETURN")) { + gosub_level--; + ast_log(LOG_DEBUG, "Decrementing gosub_level\n"); + } else if (e && !strcasecmp(ast_get_extension_app(e), "STACKPOP")) { + gosub_level--; + ast_log(LOG_DEBUG, "Decrementing gosub_level\n"); + } else if (e && !strncasecmp(ast_get_extension_app(e), "EXEC", 4)) { + /* Must evaluate args to find actual app */ + const char *tmp = ast_get_extension_app_data(e); + char tmp2[1024] = "", *tmp3 = NULL; + pbx_substitute_variables_helper(chan, tmp, tmp2, sizeof(tmp2) - 1); + if (!strcasecmp(ast_get_extension_app(e), "EXECIF")) { + tmp3 = strchr(tmp2, '|'); + if (tmp3) + *tmp3++ = '\0'; + if (!pbx_checkcondition(tmp2)) + tmp3 = NULL; + } else + tmp3 = tmp2; + + if (tmp3) + ast_log(LOG_DEBUG, "Last app: %s\n", tmp3); + + if (tmp3 && !strncasecmp(tmp3, "GOSUB", 5)) { + gosub_level++; + ast_log(LOG_DEBUG, "Incrementing gosub_level\n"); + } else if (tmp3 && !strncasecmp(tmp3, "RETURN", 6)) { + gosub_level--; + ast_log(LOG_DEBUG, "Decrementing gosub_level\n"); + } else if (tmp3 && !strncasecmp(tmp3, "STACKPOP", 8)) { + gosub_level--; + ast_log(LOG_DEBUG, "Decrementing gosub_level\n"); + } + } + + if (gosub_level == 0 && strcasecmp(chan->context, fullmacro)) { if (option_verbose > 1) ast_verbose(VERBOSE_PREFIX_2 "Channel '%s' jumping out of macro '%s'\n", chan->name, macro); break; } + /* don't stop executing extensions when we're in "h" */ if (chan->_softhangup && !inhangup) { ast_log(LOG_DEBUG, "Extension %s, macroexten %s, priority %d returned normally even though call was hung up\n", -- cgit v1.2.3