diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-10-19 18:19:02 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-10-19 18:19:02 +0000 |
commit | 58818426d60d583c4becc6a99b398cbac1b7b12f (patch) | |
tree | 5fee3540f8d72d45cd1b2e5bf15e5860581dd4f8 /apps/app_macro.c | |
parent | a4d6ea67a7536e2cb2337527357ce6d3db8639f3 (diff) |
Massive cleanups to applications for LOCAL_USER handling and some other things.
In general, LOCAL_USER_ADD/REMOVE should be the first/last thing called in an
application. An exception is if there is some *fast* setup code that might
halt the execution of the application, such as checking to see if an argument
exists.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6832 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_macro.c')
-rwxr-xr-x | apps/app_macro.c | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/apps/app_macro.c b/apps/app_macro.c index c63886e9f..f74d34766 100755 --- a/apps/app_macro.c +++ b/apps/app_macro.c @@ -110,12 +110,14 @@ static int macro_exec(struct ast_channel *chan, void *data) char *save_macro_priority; char *save_macro_offset; struct localuser *u; - + if (!data || ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Macro() requires arguments. See \"show application macro\" for help.\n"); - return 0; + return -1; } + LOCAL_USER_ADD(u); + /* Count how many levels deep the rabbit hole goes */ tmp = pbx_builtin_getvar_helper(chan, "MACRO_DEPTH"); if (tmp) { @@ -126,16 +128,18 @@ static int macro_exec(struct ast_channel *chan, void *data) if (depth >= 7) { ast_log(LOG_ERROR, "Macro(): possible infinite loop detected. Returning early.\n"); + LOCAL_USER_REMOVE(u); return 0; } snprintf(depthc, sizeof(depthc), "%d", depth + 1); pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc); - tmp = ast_strdupa((char *) data); + tmp = ast_strdupa(data); rest = tmp; macro = strsep(&rest, "|"); if (!macro || ast_strlen_zero(macro)) { ast_log(LOG_WARNING, "Invalid macro name specified\n"); + LOCAL_USER_REMOVE(u); return 0; } snprintf(fullmacro, sizeof(fullmacro), "macro-%s", macro); @@ -144,10 +148,10 @@ static int macro_exec(struct ast_channel *chan, void *data) ast_log(LOG_WARNING, "No such context '%s' for macro '%s'\n", fullmacro, macro); else ast_log(LOG_WARNING, "Context '%s' for macro '%s' lacks 's' extension, priority 1\n", fullmacro, macro); + LOCAL_USER_REMOVE(u); return 0; } - - LOCAL_USER_ADD(u); + /* Save old info */ oldpriority = chan->priority; ast_copy_string(oldexten, chan->exten, sizeof(oldexten)); @@ -305,24 +309,33 @@ static int macroif_exec(struct ast_channel *chan, void *data) { char *expr = NULL, *label_a = NULL, *label_b = NULL; int res = 0; + struct localuser *u; - if((expr = ast_strdupa((char *) data))) { - if ((label_a = strchr(expr, '?'))) { - *label_a = '\0'; - label_a++; - if ((label_b = strchr(label_a, ':'))) { - *label_b = '\0'; - label_b++; - } - if (ast_true(expr)) - macro_exec(chan, label_a); - else if (label_b) - macro_exec(chan, label_b); - - } else - ast_log(LOG_WARNING, "Invalid Syntax.\n"); - } else + LOCAL_USER_ADD(u); + + expr = ast_strdupa(data); + if (!expr) { ast_log(LOG_ERROR, "Out of Memory!\n"); + LOCAL_USER_REMOVE(u); + return -1; + } + + if ((label_a = strchr(expr, '?'))) { + *label_a = '\0'; + label_a++; + if ((label_b = strchr(label_a, ':'))) { + *label_b = '\0'; + label_b++; + } + if (ast_true(expr)) + macro_exec(chan, label_a); + else if (label_b) + macro_exec(chan, label_b); + } else + ast_log(LOG_WARNING, "Invalid Syntax.\n"); + + LOCAL_USER_REMOVE(u); + return res; } |