[svn-commits] rmudgett: branch 11 r430564 - /branches/11/apps/app_macro.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jan 13 12:06:32 CST 2015


Author: rmudgett
Date: Tue Jan 13 12:06:21 2015
New Revision: 430564

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=430564
Log:
app_macro: Don't restore the calling location on a channel redirect.

v11: If a channel redirect to a macro exten of a macro that is active
happens, the redirect location doesn't get executed.  Instead the original
macro location is restored and gets reexecuted.

v13: An additional effect happens if a parked call times out to an
extension in the macro that parked the call then the macro is reexecuted
instead of the expected park return location.

* Made not restore the macro calling location on an
AST_SOFTHANGUP_ASYNCGOTO.

* Increased the locked channel range when setting up the macro execution
environment to cover things that should be done while the channel is
locked.

* Removed unnecessary NULL tests before calling ast_free() in
_macro_exec().

ASTERISK-23850 #close
Reported by: Andrew Nagy

Review: https://reviewboard.asterisk.org/r/4292/

Modified:
    branches/11/apps/app_macro.c

Modified: branches/11/apps/app_macro.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/apps/app_macro.c?view=diff&rev=430564&r1=430563&r2=430564
==============================================================================
--- branches/11/apps/app_macro.c (original)
+++ branches/11/apps/app_macro.c Tue Jan 13 12:06:21 2015
@@ -329,6 +329,7 @@
 	}
 
 	/* Save old info */
+	ast_channel_lock(chan);
 	oldpriority = ast_channel_priority(chan);
 	ast_copy_string(oldexten, ast_channel_exten(chan), sizeof(oldexten));
 	ast_copy_string(oldcontext, ast_channel_context(chan), sizeof(oldcontext));
@@ -360,7 +361,6 @@
 	ast_channel_context_set(chan, fullmacro);
 	ast_channel_priority_set(chan, 1);
 
-	ast_channel_lock(chan);
 	while((cur = strsep(&rest, ",")) && (argc < MAX_ARGS)) {
 		const char *argp;
   		/* Save copy of old arguments if we're overwriting some, otherwise
@@ -372,9 +372,10 @@
 		pbx_builtin_setvar_helper(chan, varname, cur);
 		argc++;
 	}
-	ast_channel_unlock(chan);
 	autoloopflag = ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP);
 	ast_set_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP);
+	ast_channel_unlock(chan);
+
 	while (ast_exists_extension(chan, ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan),
 		S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
 		struct ast_context *c;
@@ -499,7 +500,10 @@
 
 		/* don't stop executing extensions when we're in "h" */
 		if (ast_check_hangup(chan) && !inhangup) {
-			ast_debug(1, "Extension %s, macroexten %s, priority %d returned normally even though call was hung up\n", ast_channel_exten(chan), ast_channel_macroexten(chan), ast_channel_priority(chan));
+			ast_debug(1, "Extension %s, macroexten %s, priority %d returned normally even though call was hung up\n",
+				ast_channel_exten(chan),
+				ast_channel_macroexten(chan),
+				ast_channel_priority(chan));
 			goto out;
 		}
 		ast_channel_priority_set(chan, ast_channel_priority(chan) + 1);
@@ -517,24 +521,17 @@
   	for (x = 1; x < argc; x++) {
   		/* Restore old arguments and delete ours */
 		snprintf(varname, sizeof(varname), "ARG%d", x);
-  		if (oldargs[x]) {
-			pbx_builtin_setvar_helper(chan, varname, oldargs[x]);
-			ast_free(oldargs[x]);
-		} else {
-			pbx_builtin_setvar_helper(chan, varname, NULL);
-		}
+		pbx_builtin_setvar_helper(chan, varname, oldargs[x]);
+		ast_free(oldargs[x]);
   	}
 
 	/* Restore macro variables */
 	pbx_builtin_setvar_helper(chan, "MACRO_EXTEN", save_macro_exten);
 	pbx_builtin_setvar_helper(chan, "MACRO_CONTEXT", save_macro_context);
 	pbx_builtin_setvar_helper(chan, "MACRO_PRIORITY", save_macro_priority);
-	if (save_macro_exten)
-		ast_free(save_macro_exten);
-	if (save_macro_context)
-		ast_free(save_macro_context);
-	if (save_macro_priority)
-		ast_free(save_macro_priority);
+	ast_free(save_macro_exten);
+	ast_free(save_macro_context);
+	ast_free(save_macro_priority);
 
 	if (setmacrocontext) {
 		ast_channel_macrocontext_set(chan, "");
@@ -542,7 +539,8 @@
 		ast_channel_macropriority_set(chan, 0);
 	}
 
-	if (!strcasecmp(ast_channel_context(chan), fullmacro)) {
+	if (!strcasecmp(ast_channel_context(chan), fullmacro)
+		&& !(ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_ASYNCGOTO)) {
 		const char *offsets;
 
   		/* If we're leaving the macro normally, restore original information */
@@ -563,8 +561,7 @@
 	}
 
 	pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", save_macro_offset);
-	if (save_macro_offset)
-		ast_free(save_macro_offset);
+	ast_free(save_macro_offset);
 
 	/* Unlock the macro */
 	if (exclusive) {




More information about the svn-commits mailing list