[asterisk-commits] moy: branch moy/mfcr2-1.4 r201568 - /team/moy/mfcr2-1.4/channels/chan_dahdi.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jun 17 23:47:23 CDT 2009


Author: moy
Date: Wed Jun 17 23:47:10 2009
New Revision: 201568

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=201568
Log:
improved handling of call disconnection to release the channel properly even when the stack fails to disconnect the call

Modified:
    team/moy/mfcr2-1.4/channels/chan_dahdi.c

Modified: team/moy/mfcr2-1.4/channels/chan_dahdi.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/moy/mfcr2-1.4/channels/chan_dahdi.c?view=diff&rev=201568&r1=201567&r2=201568
==============================================================================
--- team/moy/mfcr2-1.4/channels/chan_dahdi.c (original)
+++ team/moy/mfcr2-1.4/channels/chan_dahdi.c Wed Jun 17 23:47:10 2009
@@ -1083,6 +1083,19 @@
 	ast_mutex_unlock(&mfcr2->monitored_count_lock);
 }
 
+static void dahdi_r2_disconnect_call(struct dahdi_pvt *p, openr2_call_disconnect_cause_t cause)
+{
+	if (openr2_chan_disconnect_call(p->r2chan, cause)) {
+		ast_log(LOG_NOTICE, "Bad! failed to disconnect call on channel %d with reason %s, hope for the best!\n", 
+				p->channel, openr2_proto_get_disconnect_string(cause));
+		/* force the chan to idle and release the call flag now since we will not see a clean on_call_end */
+		openr2_chan_set_idle(p->r2chan);
+		ast_mutex_lock(&p->lock);
+		p->mfcr2call = 0;
+		ast_mutex_unlock(&p->lock);
+	}
+}
+
 static void dahdi_r2_on_call_offered(openr2_chan_t *r2chan, const char *ani, const char *dnis, openr2_calling_party_category_t category)
 {
 	struct dahdi_pvt *p;
@@ -1091,8 +1104,8 @@
 			openr2_chan_get_number(r2chan), ani ? ani : "(restricted)", dnis, openr2_proto_get_category_string(category));
 	p = openr2_chan_get_client_data(r2chan);
 	if (!p->mfcr2_allow_collect_calls && category == OR2_CALLING_PARTY_CATEGORY_COLLECT_CALL) {
-		ast_log(LOG_NOTICE, "Rejecting MFC/R2 collect call\n");
-		openr2_chan_disconnect_call(r2chan, OR2_CAUSE_COLLECT_CALL_REJECTED);
+		ast_log(LOG_NOTICE, "Rejecting MFC/R2 collect call on chan %d\n", p->channel);
+		dahdi_r2_disconnect_call(p, OR2_CAUSE_COLLECT_CALL_REJECTED);
 		return;
 	}
 	ast_mutex_lock(&p->lock);
@@ -1113,7 +1126,7 @@
 	if (!ast_exists_extension(NULL, p->context, p->exten, 1, p->cid_num)) {
 		ast_log(LOG_NOTICE, "MFC/R2 call on channel %d requested non-existent extension '%s' in context '%s'. Rejecting call.\n",
 				p->channel, p->exten, p->context);
-		openr2_chan_disconnect_call(r2chan, OR2_CAUSE_UNALLOCATED_NUMBER);
+		dahdi_r2_disconnect_call(p, OR2_CAUSE_UNALLOCATED_NUMBER);
 	} else {
 		/* if the user does not want to accept on offer, then we should launch the PBX thread now */
 		if (!p->mfcr2_accept_on_offer) {
@@ -1124,7 +1137,7 @@
 				   the call or reject it and detect the tone off condition of the other end */
 			} else {
 				ast_log(LOG_ERROR, "Unable to create PBX channel on chan %d\n", p->channel);
-				openr2_chan_disconnect_call(r2chan, OR2_CAUSE_OUT_OF_ORDER);
+				dahdi_r2_disconnect_call(p, OR2_CAUSE_OUT_OF_ORDER);
 			}
 		} else if (p->mfcr2_charge_calls) {
 			ast_log(LOG_DEBUG, "Accepting MFC/R2 call on offer with charge on chan %d\n", p->channel);
@@ -1172,7 +1185,7 @@
 			openr2_chan_disable_read(r2chan);
 		} else {
 			ast_log(LOG_ERROR, "Unable to create PBX channel on chan %d\n", p->channel);
-			openr2_chan_disconnect_call(r2chan, OR2_CAUSE_OUT_OF_ORDER);
+			dahdi_r2_disconnect_call(p, OR2_CAUSE_OUT_OF_ORDER);
 			return;
 		}
 	} else {
@@ -1277,7 +1290,7 @@
 	} else {
 		ast_mutex_unlock(&p->lock);
 		/* no owner, therefore we can't use zt_hangup to disconnect, do it right now */
-		openr2_chan_disconnect_call(r2chan, OR2_CAUSE_NORMAL_CLEARING);
+		dahdi_r2_disconnect_call(p, OR2_CAUSE_NORMAL_CLEARING);
 	}
 }
 
@@ -3419,14 +3432,14 @@
 			ast_log(LOG_DEBUG, "disconnecting MFC/R2 call on chan %d\n", p->channel);
 			ast_log(LOG_DEBUG, "ast->hangupcause is %d\n", ast->hangupcause);
 			if (openr2_chan_get_direction(p->r2chan) == OR2_DIR_BACKWARD && p->mfcr2_forced_release) {
-				openr2_chan_disconnect_call(p->r2chan, OR2_CAUSE_FORCED_RELEASE);
+				dahdi_r2_disconnect_call(p, OR2_CAUSE_FORCED_RELEASE);
 			} else {
 				const char *r2causestr = pbx_builtin_getvar_helper(ast,"MFCR2_CAUSE");
 				int r2cause_user = r2causestr ? atoi(r2causestr) : 0;
 				openr2_call_disconnect_cause_t r2cause = r2cause_user
 								       ? dahdi_ast_cause_to_r2_cause(r2cause_user)
 								       : dahdi_ast_cause_to_r2_cause(ast->hangupcause);
-				openr2_chan_disconnect_call(p->r2chan, r2cause);
+				dahdi_r2_disconnect_call(p, r2cause);
 			}
 			dahdi_r2_update_monitor_count(p->mfcr2, 1);
 		}	
@@ -11273,6 +11286,9 @@
 			continue;
 		}
 		openr2_chan_set_idle(p->r2chan);
+		ast_mutex_lock(&p->lock);
+		p->mfcr2call = 0;
+		ast_mutex_unlock(&p->lock);
 		if (channo != -1) {
 			break;
 		} else {




More information about the asterisk-commits mailing list