[asterisk-commits] rmudgett: trunk r368979 - /trunk/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 14 17:57:24 CDT 2012


Author: rmudgett
Date: Thu Jun 14 17:57:21 2012
New Revision: 368979

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=368979
Log:
Make the Hangup application set a softhangup flag.

The Hangup application used to just return -1 to cause normal dialplan
execution to hangup a channel.  For the non-normal execution routines like
predial and connected-line interception routines, the hangup request would
exit the routine early but otherwise be ignored.

* Made the Hangup application not allow setting a cause code of zero.  A
zero cause code is not defined.

Modified:
    trunk/main/pbx.c

Modified: trunk/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/pbx.c?view=diff&rev=368979&r1=368978&r2=368979
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Thu Jun 14 17:57:21 2012
@@ -10020,29 +10020,32 @@
  */
 static int pbx_builtin_hangup(struct ast_channel *chan, const char *data)
 {
+	int cause;
+
 	ast_set_hangupsource(chan, "dialplan/builtin", 0);
 
 	if (!ast_strlen_zero(data)) {
-		int cause;
-		char *endptr;
-
-		if ((cause = ast_str2cause(data)) > -1) {
-			ast_channel_hangupcause_set(chan, cause);
-			return -1;
-		}
-
-		cause = strtol((const char *) data, &endptr, 10);
-		if (cause != 0 || (data != endptr)) {
-			ast_channel_hangupcause_set(chan, cause);
-			return -1;
-		}
-
-		ast_log(LOG_WARNING, "Invalid cause given to Hangup(): \"%s\"\n", (char *) data);
-	}
-
-	if (!ast_channel_hangupcause(chan)) {
-		ast_channel_hangupcause_set(chan, AST_CAUSE_NORMAL_CLEARING);
-	}
+		cause = ast_str2cause(data);
+		if (cause <= 0) {
+			if (sscanf(data, "%30d", &cause) != 1 || cause <= 0) {
+				ast_log(LOG_WARNING, "Invalid cause given to Hangup(): \"%s\"\n", data);
+				cause = 0;
+			}
+		}
+	} else {
+		cause = 0;
+	}
+
+	ast_channel_lock(chan);
+	if (cause <= 0) {
+		cause = ast_channel_hangupcause(chan);
+		if (cause <= 0) {
+			cause = AST_CAUSE_NORMAL_CLEARING;
+		}
+	}
+	ast_channel_hangupcause_set(chan, cause);
+	ast_softhangup_nolock(chan, AST_SOFTHANGUP_EXPLICIT);
+	ast_channel_unlock(chan);
 
 	return -1;
 }




More information about the asterisk-commits mailing list