[asterisk-commits] file: trunk r89612 - in /trunk: ./ main/dial.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Nov 26 15:14:08 CST 2007


Author: file
Date: Mon Nov 26 15:14:07 2007
New Revision: 89612

URL: http://svn.digium.com/view/asterisk?view=rev&rev=89612
Log:
Merged revisions 89610 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r89610 | file | 2007-11-26 17:10:29 -0400 (Mon, 26 Nov 2007) | 2 lines

Fix issues with async dialing with an application executing. The application has to be terminated and control returned to the thread before hanging things up. (issue #BE-252)

........

Modified:
    trunk/   (props changed)
    trunk/main/dial.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/main/dial.c
URL: http://svn.digium.com/view/asterisk/trunk/main/dial.c?view=diff&rev=89612&r1=89611&r2=89612
==============================================================================
--- trunk/main/dial.c (original)
+++ trunk/main/dial.c Mon Nov 26 15:14:07 2007
@@ -58,6 +58,7 @@
 	char *device;                          /*!< Device being dialed */
 	void *options[AST_DIAL_OPTION_MAX];    /*!< Channel specific options */
 	int cause;                             /*!< Cause code in case of failure */
+	int is_running_app:1;                  /*!< Is this running an application? */
 	struct ast_channel *owner;             /*!< Asterisk channel */
 	AST_LIST_ENTRY(ast_dial_channel) list; /*!< Linked list information */
 };
@@ -135,8 +136,9 @@
 }
 
 /*! \brief Application execution function for 'ANSWER_EXEC' option */
-static void answer_exec_run(struct ast_channel *chan, char *app, char *args)
-{
+static void answer_exec_run(struct ast_dial *dial, struct ast_dial_channel *dial_channel, char *app, char *args)
+{
+	struct ast_channel *chan = dial_channel->owner;
 	struct ast_app *ast_app = pbx_findapp(app);
 
 	/* If the application was not found, return immediately */
@@ -145,6 +147,12 @@
 
 	/* All is well... execute the application */
 	pbx_exec(chan, ast_app, args);
+
+	/* If another thread is not taking over hang up the channel */
+	if (dial->thread != AST_PTHREADT_STOP) {
+		ast_hangup(chan);
+		dial_channel->owner = NULL;
+	}
 
 	return;
 }
@@ -619,8 +627,11 @@
 			channel->owner = NULL;
 		}
 		/* If ANSWER_EXEC is enabled as an option, execute application on answered channel */
-		if ((channel = find_relative_dial_channel(dial, who)) && (answer_exec = FIND_RELATIVE_OPTION(dial, channel, AST_DIAL_OPTION_ANSWER_EXEC)))
-			answer_exec_run(who, answer_exec->app, answer_exec->args);
+		if ((channel = find_relative_dial_channel(dial, who)) && (answer_exec = FIND_RELATIVE_OPTION(dial, channel, AST_DIAL_OPTION_ANSWER_EXEC))) {
+			channel->is_running_app = 1;
+			answer_exec_run(dial, channel, answer_exec->app, answer_exec->args);
+			channel->is_running_app = 0;
+		}
 
 		if (chan && dial->options[AST_DIAL_OPTION_MUSIC] && 
 			!ast_strlen_zero(dial->options[AST_DIAL_OPTION_MUSIC])) {
@@ -731,8 +742,16 @@
 	/* Stop the thread */
 	dial->thread = AST_PTHREADT_STOP;
 
-	/* Now we signal it with SIGURG so it will break out of it's waitfor */
-	pthread_kill(thread, SIGURG);
+	/* If the answered channel is running an application we have to soft hangup it, can't just poke the thread */
+	if (AST_LIST_FIRST(&dial->channels)->is_running_app) {
+		struct ast_channel *chan = AST_LIST_FIRST(&dial->channels)->owner;
+		ast_channel_lock(chan);
+		ast_softhangup(chan, AST_SOFTHANGUP_EXPLICIT);
+		ast_channel_unlock(chan);
+	} else {
+		/* Now we signal it with SIGURG so it will break out of it's waitfor */
+		pthread_kill(thread, SIGURG);
+	}
 
 	/* Finally wait for the thread to exit */
 	pthread_join(thread, NULL);




More information about the asterisk-commits mailing list