[asterisk-commits] jpeeler: branch jpeeler/asterisk-sigwork-trunk r197999 - /team/jpeeler/asteri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 29 13:15:13 CDT 2009


Author: jpeeler
Date: Fri May 29 13:15:09 2009
New Revision: 197999

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=197999
Log:
lots of whitespace fixes

Modified:
    team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c
    team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.c
    team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.h

Modified: team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c?view=diff&rev=197999&r1=197998&r2=197999
==============================================================================
--- team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c (original)
+++ team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c Fri May 29 13:15:09 2009
@@ -1643,7 +1643,6 @@
 	dahdi_setlinear(p->subs[index].dfd, 0);
 
 	return 0;
-		
 }
 
 static int my_stop_cid_detect(void *pvt)
@@ -1750,7 +1749,7 @@
 	}
 	p->cidpos = 0;
 	send_callerid(p);
-	
+
 	return 0;
 }
 
@@ -2133,48 +2132,48 @@
 	enum analog_event res = ANALOG_EVENT_ERROR;
 
 	switch (event) {
-		case DAHDI_EVENT_DIALCOMPLETE:
-			res = ANALOG_EVENT_DIALCOMPLETE;
-			break;
-		case DAHDI_EVENT_WINKFLASH:
-			res = ANALOG_EVENT_WINKFLASH;
-			break;
-		case DAHDI_EVENT_ONHOOK:
-			res = ANALOG_EVENT_ONHOOK;
-			break;
-		case DAHDI_EVENT_RINGOFFHOOK:
-			res = ANALOG_EVENT_RINGOFFHOOK;
-			break;
-		case DAHDI_EVENT_ALARM:
-			res = ANALOG_EVENT_ALARM;
-			break;
-		case DAHDI_EVENT_NOALARM:
-			res = ANALOG_EVENT_NOALARM;
-			break;
-		case DAHDI_EVENT_HOOKCOMPLETE:
-			res = ANALOG_EVENT_HOOKCOMPLETE;
-			break;
-		case DAHDI_EVENT_POLARITY:
-			res = ANALOG_EVENT_POLARITY;
-			break;
-		case DAHDI_EVENT_RINGERON:
-			res = ANALOG_EVENT_RINGERON;
-			break;
-		case DAHDI_EVENT_RINGEROFF:
-			res = ANALOG_EVENT_RINGEROFF;
-			break;
-		case DAHDI_EVENT_RINGBEGIN:
-			res = ANALOG_EVENT_RINGBEGIN;
-			break;
-		case DAHDI_EVENT_PULSE_START:
-			res = ANALOG_EVENT_PULSE_START;
-			break;
-		case DAHDI_EVENT_NEONMWI_ACTIVE:
-			res = ANALOG_EVENT_NEONMWI_ACTIVE;
-			break;
-		case DAHDI_EVENT_NEONMWI_INACTIVE:
-			res = ANALOG_EVENT_NEONMWI_INACTIVE;
-			break;
+	case DAHDI_EVENT_DIALCOMPLETE:
+		res = ANALOG_EVENT_DIALCOMPLETE;
+		break;
+	case DAHDI_EVENT_WINKFLASH:
+		res = ANALOG_EVENT_WINKFLASH;
+		break;
+	case DAHDI_EVENT_ONHOOK:
+		res = ANALOG_EVENT_ONHOOK;
+		break;
+	case DAHDI_EVENT_RINGOFFHOOK:
+		res = ANALOG_EVENT_RINGOFFHOOK;
+		break;
+	case DAHDI_EVENT_ALARM:
+		res = ANALOG_EVENT_ALARM;
+		break;
+	case DAHDI_EVENT_NOALARM:
+		res = ANALOG_EVENT_NOALARM;
+		break;
+	case DAHDI_EVENT_HOOKCOMPLETE:
+		res = ANALOG_EVENT_HOOKCOMPLETE;
+		break;
+	case DAHDI_EVENT_POLARITY:
+		res = ANALOG_EVENT_POLARITY;
+		break;
+	case DAHDI_EVENT_RINGERON:
+		res = ANALOG_EVENT_RINGERON;
+		break;
+	case DAHDI_EVENT_RINGEROFF:
+		res = ANALOG_EVENT_RINGEROFF;
+		break;
+	case DAHDI_EVENT_RINGBEGIN:
+		res = ANALOG_EVENT_RINGBEGIN;
+		break;
+	case DAHDI_EVENT_PULSE_START:
+		res = ANALOG_EVENT_PULSE_START;
+	break;
+	case DAHDI_EVENT_NEONMWI_ACTIVE:
+		res = ANALOG_EVENT_NEONMWI_ACTIVE;
+		break;
+	case DAHDI_EVENT_NEONMWI_INACTIVE:
+		res = ANALOG_EVENT_NEONMWI_INACTIVE;
+		break;
 	}
 
 	return res;
@@ -2298,7 +2297,7 @@
 	struct dahdi_pvt *p = pvt;
 
 	dahdi_train_ec(p);
-	
+
 	return 0;
 }
 
@@ -5356,7 +5355,7 @@
 		dahdi_confmute(p, 0);
 		restore_gains(p);
 		p->ignoredtmf = 0;
-	
+
 		if (p->bufferoverrideinuse) {
 			/* faxbuffers are in use, revert them */
 			struct dahdi_bufferinfo bi = {
@@ -5370,7 +5369,7 @@
 			if ((bpres = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
 				ast_log(LOG_WARNING, "Channel '%s' unable to revert buffer policy: %s\n", ast->name, strerror(errno));
 			}
-			p->bufferoverrideinuse = 0;	
+			p->bufferoverrideinuse = 0;
 		}
 
 		res = analog_hangup(p->sig_pvt, ast);
@@ -5546,7 +5545,7 @@
 			if ((bpres = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
 				ast_log(LOG_WARNING, "Channel '%s' unable to revert buffer policy: %s\n", ast->name, strerror(errno));
 			}
-			p->bufferoverrideinuse = 0;	
+			p->bufferoverrideinuse = 0;
 		}
 
 		law = DAHDI_LAW_DEFAULT;
@@ -6916,818 +6915,818 @@
 	}
 
 	switch (res) {
-		case DAHDI_EVENT_EC_DISABLED:
-			ast_verb(3, "Channel %d echo canceler disabled.\n", p->channel);
-			p->echocanon = 0;
+	case DAHDI_EVENT_EC_DISABLED:
+		ast_verb(3, "Channel %d echo canceler disabled.\n", p->channel);
+		p->echocanon = 0;
+		break;
+#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
+	case DAHDI_EVENT_TX_CED_DETECTED:
+		ast_verb(3, "Channel %d detected a CED tone towards the network.\n", p->channel);
+		break;
+	case DAHDI_EVENT_RX_CED_DETECTED:
+		ast_verb(3, "Channel %d detected a CED tone from the network.\n", p->channel);
+		break;
+	case DAHDI_EVENT_EC_NLP_DISABLED:
+		ast_verb(3, "Channel %d echo canceler disabled its NLP.\n", p->channel);
+		break;
+	case DAHDI_EVENT_EC_NLP_ENABLED:
+		ast_verb(3, "Channel %d echo canceler enabled its NLP.\n", p->channel);
+		break;
+#endif
+	case DAHDI_EVENT_BITSCHANGED:
+#ifdef HAVE_OPENR2
+		if (p->sig != SIG_MFCR2) {
+			ast_log(LOG_WARNING, "Recieved bits changed on %s signalling?\n", sig2str(p->sig));
+		} else {
+			ast_log(LOG_DEBUG, "bits changed in chan %d\n", p->channel);
+			openr2_chan_handle_cas(p->r2chan);
+		}
+#else
+		ast_log(LOG_WARNING, "Recieved bits changed on %s signalling?\n", sig2str(p->sig));
+#endif
+	case DAHDI_EVENT_PULSE_START:
+		/* Stop tone if there's a pulse start and the PBX isn't started */
+		if (!ast->pbx)
+			tone_zone_play_tone(p->subs[idx].dfd, -1);
+		break;
+	case DAHDI_EVENT_DIALCOMPLETE:
+#ifdef HAVE_OPENR2
+		if ((p->sig & SIG_MFCR2) && p->r2chan && ast->_state != AST_STATE_UP) {
+			/* we don't need to do anything for this event for R2 signaling
+			   if the call is being setup */
 			break;
-#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
-		case DAHDI_EVENT_TX_CED_DETECTED:
-			ast_verb(3, "Channel %d detected a CED tone towards the network.\n", p->channel);
+		}
+#endif
+		if (p->inalarm) break;
+		if ((p->radio || (p->oprmode < 0))) break;
+		if (ioctl(p->subs[idx].dfd,DAHDI_DIALING,&x) == -1) {
+			ast_log(LOG_DEBUG, "DAHDI_DIALING ioctl failed on %s: %s\n",ast->name, strerror(errno));
+			return NULL;
+		}
+		if (!x) { /* if not still dialing in driver */
+			dahdi_enable_ec(p);
+			if (p->echobreak) {
+				dahdi_train_ec(p);
+				ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
+				p->dop.op = DAHDI_DIAL_OP_REPLACE;
+				res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop);
+				p->echobreak = 0;
+			} else {
+				p->dialing = 0;
+				if ((mysig == SIG_E911) || (mysig == SIG_FGC_CAMA) || (mysig == SIG_FGC_CAMAMF)) {
+					/* if thru with dialing after offhook */
+					if (ast->_state == AST_STATE_DIALING_OFFHOOK) {
+						ast_setstate(ast, AST_STATE_UP);
+						p->subs[idx].f.frametype = AST_FRAME_CONTROL;
+						p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
+						break;
+					} else { /* if to state wait for offhook to dial rest */
+						/* we now wait for off hook */
+						ast_setstate(ast,AST_STATE_DIALING_OFFHOOK);
+					}
+				}
+				if (ast->_state == AST_STATE_DIALING) {
+					if ((p->callprogress & CALLPROGRESS_PROGRESS) && CANPROGRESSDETECT(p) && p->dsp && p->outgoing) {
+						ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n");
+					} else if (p->confirmanswer || (!p->dialednone
+						&& ((mysig == SIG_EM) || (mysig == SIG_EM_E1)
+							|| (mysig == SIG_EMWINK) || (mysig == SIG_FEATD)
+							|| (mysig == SIG_FEATDMF_TA) || (mysig == SIG_FEATDMF)
+							|| (mysig == SIG_E911) || (mysig == SIG_FGC_CAMA)
+							|| (mysig == SIG_FGC_CAMAMF) || (mysig == SIG_FEATB)
+							|| (mysig == SIG_SF) || (mysig == SIG_SFWINK)
+							|| (mysig == SIG_SF_FEATD) || (mysig == SIG_SF_FEATDMF)
+							|| (mysig == SIG_SF_FEATB)))) {
+						ast_setstate(ast, AST_STATE_RINGING);
+					} else if (!p->answeronpolarityswitch) {
+						ast_setstate(ast, AST_STATE_UP);
+						p->subs[idx].f.frametype = AST_FRAME_CONTROL;
+						p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
+						/* If aops=0 and hops=1, this is necessary */
+						p->polarity = POLARITY_REV;
+					} else {
+						/* Start clean, so we can catch the change to REV polarity when party answers */
+						p->polarity = POLARITY_IDLE;
+					}
+				}
+			}
+		}
+		break;
+	case DAHDI_EVENT_ALARM:
+#ifdef HAVE_PRI
+		if ((p->sig == SIG_PRI) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP)) {
+			if (!p->pri || !p->pri->pri || (pri_get_timer(p->pri->pri, PRI_TIMER_T309) < 0)) {
+				/* T309 is not enabled : hangup calls when alarm occurs */
+				if (p->call) {
+					if (p->pri && p->pri->pri) {
+						if (!pri_grab(p, p->pri)) {
+							pri_hangup(p->pri->pri, p->call, -1);
+							pri_destroycall(p->pri->pri, p->call);
+							p->call = NULL;
+							pri_rel(p->pri);
+						} else
+							ast_log(LOG_WARNING, "Failed to grab PRI!\n");
+					} else
+						ast_log(LOG_WARNING, "The PRI Call has not been destroyed\n");
+				}
+				if (p->owner)
+					p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
+			}
+		}
+		if (p->bearer)
+			p->bearer->inalarm = 1;
+		else
+#endif
+		p->inalarm = 1;
+		res = get_alarms(p);
+		handle_alarms(p, res);
+#ifdef HAVE_PRI
+		if (!p->pri || !p->pri->pri || pri_get_timer(p->pri->pri, PRI_TIMER_T309) < 0) {
+			/* fall through intentionally */
+		} else {
 			break;
-		case DAHDI_EVENT_RX_CED_DETECTED:
-			ast_verb(3, "Channel %d detected a CED tone from the network.\n", p->channel);
+		}
+#endif
+#ifdef HAVE_SS7
+		if (p->sig == SIG_SS7)
 			break;
-		case DAHDI_EVENT_EC_NLP_DISABLED:
-			ast_verb(3, "Channel %d echo canceler disabled its NLP.\n", p->channel);
+#endif
+#ifdef HAVE_OPENR2
+		if (p->sig == SIG_MFCR2)
 			break;
-		case DAHDI_EVENT_EC_NLP_ENABLED:
-			ast_verb(3, "Channel %d echo canceler enabled its NLP.\n", p->channel);
+#endif
+	case DAHDI_EVENT_ONHOOK:
+		if (p->radio) {
+			p->subs[idx].f.frametype = AST_FRAME_CONTROL;
+			p->subs[idx].f.subclass = AST_CONTROL_RADIO_UNKEY;
 			break;
-#endif
-		case DAHDI_EVENT_BITSCHANGED:
-#ifdef HAVE_OPENR2
-			if (p->sig != SIG_MFCR2) {
-				ast_log(LOG_WARNING, "Recieved bits changed on %s signalling?\n", sig2str(p->sig));
-			} else {
-				ast_log(LOG_DEBUG, "bits changed in chan %d\n", p->channel);
-				openr2_chan_handle_cas(p->r2chan);
-			}
-#else
-			ast_log(LOG_WARNING, "Recieved bits changed on %s signalling?\n", sig2str(p->sig));
-#endif
-		case DAHDI_EVENT_PULSE_START:
-			/* Stop tone if there's a pulse start and the PBX isn't started */
-			if (!ast->pbx)
-				tone_zone_play_tone(p->subs[idx].dfd, -1);
+		}
+		if (p->oprmode < 0)
+		{
+			if (p->oprmode != -1) break;
+			if ((p->sig == SIG_FXOLS) || (p->sig == SIG_FXOKS) || (p->sig == SIG_FXOGS))
+			{
+				/* Make sure it starts ringing */
+				dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_RINGOFF);
+				dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_RING);
+				save_conference(p->oprpeer);
+				tone_zone_play_tone(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_TONE_RINGTONE);
+			}
 			break;
-		case DAHDI_EVENT_DIALCOMPLETE:
-#ifdef HAVE_OPENR2
-			if ((p->sig & SIG_MFCR2) && p->r2chan && ast->_state != AST_STATE_UP) {
-				/* we don't need to do anything for this event for R2 signaling
-				   if the call is being setup */
-				break;
-			}
-#endif
-			if (p->inalarm) break;
-			if ((p->radio || (p->oprmode < 0))) break;
-			if (ioctl(p->subs[idx].dfd,DAHDI_DIALING,&x) == -1) {
-				ast_log(LOG_DEBUG, "DAHDI_DIALING ioctl failed on %s: %s\n",ast->name, strerror(errno));
-				return NULL;
-			}
-			if (!x) { /* if not still dialing in driver */
-				dahdi_enable_ec(p);
-				if (p->echobreak) {
-					dahdi_train_ec(p);
-					ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
-					p->dop.op = DAHDI_DIAL_OP_REPLACE;
-					res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop);
-					p->echobreak = 0;
-				} else {
-					p->dialing = 0;
-					if ((mysig == SIG_E911) || (mysig == SIG_FGC_CAMA) || (mysig == SIG_FGC_CAMAMF)) {
-						/* if thru with dialing after offhook */
-						if (ast->_state == AST_STATE_DIALING_OFFHOOK) {
-							ast_setstate(ast, AST_STATE_UP);
-							p->subs[idx].f.frametype = AST_FRAME_CONTROL;
-							p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
-							break;
-						} else { /* if to state wait for offhook to dial rest */
-							/* we now wait for off hook */
-							ast_setstate(ast,AST_STATE_DIALING_OFFHOOK);
+		}
+		switch (p->sig) {
+		case SIG_FXOLS:
+		case SIG_FXOGS:
+		case SIG_FXOKS:
+			p->onhooktime = time(NULL);
+			p->fxsoffhookstate = 0;
+			p->msgstate = -1;
+			/* Check for some special conditions regarding call waiting */
+			if (idx == SUB_REAL) {
+				/* The normal line was hung up */
+				if (p->subs[SUB_CALLWAIT].owner) {
+					/* There's a call waiting call, so ring the phone, but make it unowned in the mean time */
+					swap_subs(p, SUB_CALLWAIT, SUB_REAL);
+					ast_verb(3, "Channel %d still has (callwait) call, ringing phone\n", p->channel);
+					unalloc_sub(p, SUB_CALLWAIT);
+#if 0
+					p->subs[idx].needanswer = 0;
+					p->subs[idx].needringing = 0;
+#endif
+					p->callwaitingrepeat = 0;
+					p->cidcwexpire = 0;
+					p->owner = NULL;
+					/* Don't start streaming audio yet if the incoming call isn't up yet */
+					if (p->subs[SUB_REAL].owner->_state != AST_STATE_UP)
+						p->dialing = 1;
+					dahdi_ring_phone(p);
+				} else if (p->subs[SUB_THREEWAY].owner) {
+					unsigned int mssinceflash;
+					/* Here we have to retain the lock on both the main channel, the 3-way channel, and
+					   the private structure -- not especially easy or clean */
+					while (p->subs[SUB_THREEWAY].owner && ast_channel_trylock(p->subs[SUB_THREEWAY].owner)) {
+						/* Yuck, didn't get the lock on the 3-way, gotta release everything and re-grab! */
+						DLA_UNLOCK(&p->lock);
+						CHANNEL_DEADLOCK_AVOIDANCE(ast);
+						/* We can grab ast and p in that order, without worry.  We should make sure
+						   nothing seriously bad has happened though like some sort of bizarre double
+						   masquerade! */
+						DLA_LOCK(&p->lock);
+						if (p->owner != ast) {
+							ast_log(LOG_WARNING, "This isn't good...\n");
+							return NULL;
 						}
 					}
-					if (ast->_state == AST_STATE_DIALING) {
-						if ((p->callprogress & CALLPROGRESS_PROGRESS) && CANPROGRESSDETECT(p) && p->dsp && p->outgoing) {
-							ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n");
-						} else if (p->confirmanswer || (!p->dialednone
-							&& ((mysig == SIG_EM) || (mysig == SIG_EM_E1)
-								|| (mysig == SIG_EMWINK) || (mysig == SIG_FEATD)
-								|| (mysig == SIG_FEATDMF_TA) || (mysig == SIG_FEATDMF)
-								|| (mysig == SIG_E911) || (mysig == SIG_FGC_CAMA)
-								|| (mysig == SIG_FGC_CAMAMF) || (mysig == SIG_FEATB)
-								|| (mysig == SIG_SF) || (mysig == SIG_SFWINK)
-								|| (mysig == SIG_SF_FEATD) || (mysig == SIG_SF_FEATDMF)
-								|| (mysig == SIG_SF_FEATB)))) {
-							ast_setstate(ast, AST_STATE_RINGING);
-						} else if (!p->answeronpolarityswitch) {
-							ast_setstate(ast, AST_STATE_UP);
-							p->subs[idx].f.frametype = AST_FRAME_CONTROL;
-							p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
-							/* If aops=0 and hops=1, this is necessary */
-							p->polarity = POLARITY_REV;
-						} else {
-							/* Start clean, so we can catch the change to REV polarity when party answers */
-							p->polarity = POLARITY_IDLE;
-						}
+					if (!p->subs[SUB_THREEWAY].owner) {
+						ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n");
+						return NULL;
 					}
-				}
-			}
-			break;
-		case DAHDI_EVENT_ALARM:
-#ifdef HAVE_PRI
-			if ((p->sig == SIG_PRI) || (p->sig == SIG_BRI) || (p->sig == SIG_BRI_PTMP)) {
-				if (!p->pri || !p->pri->pri || (pri_get_timer(p->pri->pri, PRI_TIMER_T309) < 0)) {
-					/* T309 is not enabled : hangup calls when alarm occurs */
-					if (p->call) {
-						if (p->pri && p->pri->pri) {
-							if (!pri_grab(p, p->pri)) {
-								pri_hangup(p->pri->pri, p->call, -1);
-								pri_destroycall(p->pri->pri, p->call);
-								p->call = NULL;
-								pri_rel(p->pri);
-							} else
-								ast_log(LOG_WARNING, "Failed to grab PRI!\n");
-						} else
-							ast_log(LOG_WARNING, "The PRI Call has not been destroyed\n");
-					}
-					if (p->owner)
-						p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
-				}
-			}
-			if (p->bearer)
-				p->bearer->inalarm = 1;
-			else
-#endif
-			p->inalarm = 1;
-			res = get_alarms(p);
-			handle_alarms(p, res);
-#ifdef HAVE_PRI
-			if (!p->pri || !p->pri->pri || pri_get_timer(p->pri->pri, PRI_TIMER_T309) < 0) {
-				/* fall through intentionally */
-			} else {
-				break;
-			}
-#endif
-#ifdef HAVE_SS7
-			if (p->sig == SIG_SS7)
-				break;
-#endif
-#ifdef HAVE_OPENR2
-			if (p->sig == SIG_MFCR2)
-				break;
-#endif
-		case DAHDI_EVENT_ONHOOK:
-			if (p->radio) {
-				p->subs[idx].f.frametype = AST_FRAME_CONTROL;
-				p->subs[idx].f.subclass = AST_CONTROL_RADIO_UNKEY;
-				break;
-			}
-			if (p->oprmode < 0)
-			{
-				if (p->oprmode != -1) break;
-				if ((p->sig == SIG_FXOLS) || (p->sig == SIG_FXOKS) || (p->sig == SIG_FXOGS))
-				{
-					/* Make sure it starts ringing */
-					dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_RINGOFF);
-					dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_RING);
-					save_conference(p->oprpeer);
-					tone_zone_play_tone(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_TONE_RINGTONE);
-				}
-				break;
-			}
-			switch (p->sig) {
-			case SIG_FXOLS:
-			case SIG_FXOGS:
-			case SIG_FXOKS:
-				p->onhooktime = time(NULL);
-				p->fxsoffhookstate = 0;
-				p->msgstate = -1;
-				/* Check for some special conditions regarding call waiting */
-				if (idx == SUB_REAL) {
-					/* The normal line was hung up */
-					if (p->subs[SUB_CALLWAIT].owner) {
-						/* There's a call waiting call, so ring the phone, but make it unowned in the mean time */
-						swap_subs(p, SUB_CALLWAIT, SUB_REAL);
-						ast_verb(3, "Channel %d still has (callwait) call, ringing phone\n", p->channel);
-						unalloc_sub(p, SUB_CALLWAIT);
-#if 0
-						p->subs[idx].needanswer = 0;
-						p->subs[idx].needringing = 0;
-#endif
-						p->callwaitingrepeat = 0;
-						p->cidcwexpire = 0;
-						p->owner = NULL;
-						/* Don't start streaming audio yet if the incoming call isn't up yet */
-						if (p->subs[SUB_REAL].owner->_state != AST_STATE_UP)
-							p->dialing = 1;
-						dahdi_ring_phone(p);
-					} else if (p->subs[SUB_THREEWAY].owner) {
-						unsigned int mssinceflash;
-						/* Here we have to retain the lock on both the main channel, the 3-way channel, and
-						   the private structure -- not especially easy or clean */
-						while (p->subs[SUB_THREEWAY].owner && ast_channel_trylock(p->subs[SUB_THREEWAY].owner)) {
-							/* Yuck, didn't get the lock on the 3-way, gotta release everything and re-grab! */
-							DLA_UNLOCK(&p->lock);
-							CHANNEL_DEADLOCK_AVOIDANCE(ast);
-							/* We can grab ast and p in that order, without worry.  We should make sure
-							   nothing seriously bad has happened though like some sort of bizarre double
-							   masquerade! */
-							DLA_LOCK(&p->lock);
-							if (p->owner != ast) {
-								ast_log(LOG_WARNING, "This isn't good...\n");
-								return NULL;
-							}
-						}
-						if (!p->subs[SUB_THREEWAY].owner) {
-							ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n");
-							return NULL;
-						}
-						mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
-						ast_debug(1, "Last flash was %d ms ago\n", mssinceflash);
-						if (mssinceflash < MIN_MS_SINCE_FLASH) {
-							/* It hasn't been long enough since the last flashook.  This is probably a bounce on
-							   hanging up.  Hangup both channels now */
-							if (p->subs[SUB_THREEWAY].owner)
-								ast_queue_hangup_with_cause(p->subs[SUB_THREEWAY].owner, AST_CAUSE_NO_ANSWER);
-							p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
-							ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
-							ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
-						} else if ((ast->pbx) || (ast->_state == AST_STATE_UP)) {
-							if (p->transfer) {
-								/* In any case this isn't a threeway call anymore */
-								p->subs[SUB_REAL].inthreeway = 0;
-								p->subs[SUB_THREEWAY].inthreeway = 0;
-								/* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
-								if (!p->transfertobusy && ast->_state == AST_STATE_BUSY) {
-									ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
-									/* Swap subs and dis-own channel */
-									swap_subs(p, SUB_THREEWAY, SUB_REAL);
-									p->owner = NULL;
-									/* Ring the phone */
-									dahdi_ring_phone(p);
-								} else {
-									if ((res = attempt_transfer(p)) < 0) {
-										p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
-										if (p->subs[SUB_THREEWAY].owner)
-											ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
-									} else if (res) {
-										/* Don't actually hang up at this point */
-										if (p->subs[SUB_THREEWAY].owner)
-											ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
-										break;
-									}
+					mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
+					ast_debug(1, "Last flash was %d ms ago\n", mssinceflash);
+					if (mssinceflash < MIN_MS_SINCE_FLASH) {
+						/* It hasn't been long enough since the last flashook.  This is probably a bounce on
+						   hanging up.  Hangup both channels now */
+						if (p->subs[SUB_THREEWAY].owner)
+							ast_queue_hangup_with_cause(p->subs[SUB_THREEWAY].owner, AST_CAUSE_NO_ANSWER);
+						p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
+						ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
+						ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
+					} else if ((ast->pbx) || (ast->_state == AST_STATE_UP)) {
+						if (p->transfer) {
+							/* In any case this isn't a threeway call anymore */
+							p->subs[SUB_REAL].inthreeway = 0;
+							p->subs[SUB_THREEWAY].inthreeway = 0;
+							/* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
+							if (!p->transfertobusy && ast->_state == AST_STATE_BUSY) {
+								ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
+								/* Swap subs and dis-own channel */
+								swap_subs(p, SUB_THREEWAY, SUB_REAL);
+								p->owner = NULL;
+								/* Ring the phone */
+								dahdi_ring_phone(p);
+							} else {
+								if ((res = attempt_transfer(p)) < 0) {
+									p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
+									if (p->subs[SUB_THREEWAY].owner)
+										ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
+								} else if (res) {
+									/* Don't actually hang up at this point */
+									if (p->subs[SUB_THREEWAY].owner)
+										ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
+									break;
 								}
-							} else {
-								p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
-								if (p->subs[SUB_THREEWAY].owner)
-									ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
 							}
 						} else {
-							ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
-							/* Swap subs and dis-own channel */
-							swap_subs(p, SUB_THREEWAY, SUB_REAL);
-							p->owner = NULL;
-							/* Ring the phone */
-							dahdi_ring_phone(p);
+							p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
+							if (p->subs[SUB_THREEWAY].owner)
+								ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
 						}
+					} else {
+						ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
+						/* Swap subs and dis-own channel */
+						swap_subs(p, SUB_THREEWAY, SUB_REAL);
+						p->owner = NULL;
+						/* Ring the phone */
+						dahdi_ring_phone(p);
 					}
-				} else {
-					ast_log(LOG_WARNING, "Got a hangup and my index is %d?\n", idx);
-				}
-				/* Fall through */
-			default:
-				dahdi_disable_ec(p);
+				}
+			} else {
+				ast_log(LOG_WARNING, "Got a hangup and my index is %d?\n", idx);
+			}
+			/* Fall through */
+		default:
+			dahdi_disable_ec(p);
+			return NULL;
+		}
+		break;
+	case DAHDI_EVENT_RINGOFFHOOK:
+		if (p->inalarm) break;
+		if (p->oprmode < 0)
+		{
+			if ((p->sig == SIG_FXOLS) || (p->sig == SIG_FXOKS) || (p->sig == SIG_FXOGS))
+			{
+				/* Make sure it stops ringing */
+				dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_RINGOFF);
+				tone_zone_play_tone(p->oprpeer->subs[SUB_REAL].dfd, -1);
+				restore_conference(p->oprpeer);
+			}
+			break;
+		}
+		if (p->radio)
+		{
+			p->subs[idx].f.frametype = AST_FRAME_CONTROL;
+			p->subs[idx].f.subclass = AST_CONTROL_RADIO_KEY;
+			break;
+ 		}
+		/* for E911, its supposed to wait for offhook then dial
+		   the second half of the dial string */
+		if (((mysig == SIG_E911) || (mysig == SIG_FGC_CAMA) || (mysig == SIG_FGC_CAMAMF)) && (ast->_state == AST_STATE_DIALING_OFFHOOK)) {
+			c = strchr(p->dialdest, '/');
+			if (c)
+				c++;
+			else
+				c = p->dialdest;
+			if (*c) snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
+			else ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
+			if (strlen(p->dop.dialstr) > 4) {
+				memset(p->echorest, 'w', sizeof(p->echorest) - 1);
+				strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
+				p->echorest[sizeof(p->echorest) - 1] = '\0';
+				p->echobreak = 1;
+				p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
+			} else
+				p->echobreak = 0;
+			if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop)) {
+				int saveerr = errno;
+
+				x = DAHDI_ONHOOK;
+				ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
+				ast_log(LOG_WARNING, "Dialing failed on channel %d: %s\n", p->channel, strerror(saveerr));
 				return NULL;
-			}
-			break;
-		case DAHDI_EVENT_RINGOFFHOOK:
-			if (p->inalarm) break;
-			if (p->oprmode < 0)
-			{
-				if ((p->sig == SIG_FXOLS) || (p->sig == SIG_FXOKS) || (p->sig == SIG_FXOGS))
-				{
-					/* Make sure it stops ringing */
-					dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_RINGOFF);
-					tone_zone_play_tone(p->oprpeer->subs[SUB_REAL].dfd, -1);
-					restore_conference(p->oprpeer);
-				}
-				break;
-			}
-			if (p->radio)
-			{
+				}
+			p->dialing = 1;
+			return &p->subs[idx].f;
+		}
+		switch (p->sig) {
+		case SIG_FXOLS:
+		case SIG_FXOGS:
+		case SIG_FXOKS:
+			p->fxsoffhookstate = 1;
+			switch (ast->_state) {
+			case AST_STATE_RINGING:
+				dahdi_enable_ec(p);
+				dahdi_train_ec(p);
 				p->subs[idx].f.frametype = AST_FRAME_CONTROL;
-				p->subs[idx].f.subclass = AST_CONTROL_RADIO_KEY;
-				break;
- 			}
-			/* for E911, its supposed to wait for offhook then dial
-			   the second half of the dial string */
-			if (((mysig == SIG_E911) || (mysig == SIG_FGC_CAMA) || (mysig == SIG_FGC_CAMAMF)) && (ast->_state == AST_STATE_DIALING_OFFHOOK)) {
-				c = strchr(p->dialdest, '/');
-				if (c)
-					c++;
-				else
-					c = p->dialdest;
-				if (*c) snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
-				else ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
-				if (strlen(p->dop.dialstr) > 4) {
-					memset(p->echorest, 'w', sizeof(p->echorest) - 1);
-					strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
-					p->echorest[sizeof(p->echorest) - 1] = '\0';
-					p->echobreak = 1;
-					p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
-				} else
-					p->echobreak = 0;
-				if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop)) {
-					int saveerr = errno;
-
-					x = DAHDI_ONHOOK;
-					ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
-					ast_log(LOG_WARNING, "Dialing failed on channel %d: %s\n", p->channel, strerror(saveerr));
-					return NULL;
-					}
-				p->dialing = 1;
-				return &p->subs[idx].f;
-			}
-			switch (p->sig) {
-			case SIG_FXOLS:
-			case SIG_FXOGS:
-			case SIG_FXOKS:
-				p->fxsoffhookstate = 1;
-				switch (ast->_state) {
-				case AST_STATE_RINGING:
-					dahdi_enable_ec(p);
-					dahdi_train_ec(p);
-					p->subs[idx].f.frametype = AST_FRAME_CONTROL;
-					p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
-					/* Make sure it stops ringing */
-					dahdi_set_hook(p->subs[idx].dfd, DAHDI_OFFHOOK);
-					ast_debug(1, "channel %d answered\n", p->channel);
-					if (p->cidspill) {
-						/* Cancel any running CallerID spill */
-						ast_free(p->cidspill);
-						p->cidspill = NULL;
-					}
-					p->dialing = 0;
-					p->callwaitcas = 0;
-					if (p->confirmanswer) {
-						/* Ignore answer if "confirm answer" is enabled */
-						p->subs[idx].f.frametype = AST_FRAME_NULL;
-						p->subs[idx].f.subclass = 0;
-					} else if (!ast_strlen_zero(p->dop.dialstr)) {
-						/* nick at dccinc.com 4/3/03 - fxo should be able to do deferred dialing */
-						res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_DIAL, &p->dop);
-						if (res < 0) {
-							ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d: %s\n", p->channel, strerror(errno));
-							p->dop.dialstr[0] = '\0';
-							return NULL;
-						} else {
-							ast_debug(1, "Sent FXO deferred digit string: %s\n", p->dop.dialstr);
-							p->subs[idx].f.frametype = AST_FRAME_NULL;
-							p->subs[idx].f.subclass = 0;
-							p->dialing = 1;
-						}
-						p->dop.dialstr[0] = '\0';
-						ast_setstate(ast, AST_STATE_DIALING);
-					} else
-						ast_setstate(ast, AST_STATE_UP);
-					return &p->subs[idx].f;
-				case AST_STATE_DOWN:
-					ast_setstate(ast, AST_STATE_RING);
-					ast->rings = 1;
-					p->subs[idx].f.frametype = AST_FRAME_CONTROL;
-					p->subs[idx].f.subclass = AST_CONTROL_OFFHOOK;
-					ast_debug(1, "channel %d picked up\n", p->channel);
-					return &p->subs[idx].f;
-				case AST_STATE_UP:
-					/* Make sure it stops ringing */
-					dahdi_set_hook(p->subs[idx].dfd, DAHDI_OFFHOOK);
-					/* Okay -- probably call waiting*/
-					if (ast_bridged_channel(p->owner))
-						ast_queue_control(p->owner, AST_CONTROL_UNHOLD);
-					p->subs[idx].needunhold = 1;
-					break;
-				case AST_STATE_RESERVED:
-					/* Start up dialtone */
-					if (has_voicemail(p))
-						res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_STUTTER);
-					else
-						res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_DIALTONE);
-					break;
-				default:
-					ast_log(LOG_WARNING, "FXO phone off hook in weird state %d??\n", ast->_state);
-				}
-				break;
-			case SIG_FXSLS:
-			case SIG_FXSGS:
-			case SIG_FXSKS:
-				if (ast->_state == AST_STATE_RING) {
-					p->ringt = p->ringt_base;
-				}
-
-				/* If we get a ring then we cannot be in
-				 * reversed polarity. So we reset to idle */
-				ast_debug(1, "Setting IDLE polarity due "
-					"to ring. Old polarity was %d\n",
-					p->polarity);
-				p->polarity = POLARITY_IDLE;
-
-				/* Fall through */
-			case SIG_EM:
-			case SIG_EM_E1:
-			case SIG_EMWINK:
-			case SIG_FEATD:
-			case SIG_FEATDMF:
-			case SIG_FEATDMF_TA:
-			case SIG_E911:
-			case SIG_FGC_CAMA:
-			case SIG_FGC_CAMAMF:
-			case SIG_FEATB:
-			case SIG_SF:
-			case SIG_SFWINK:
-			case SIG_SF_FEATD:
-			case SIG_SF_FEATDMF:
-			case SIG_SF_FEATB:
-				if (ast->_state == AST_STATE_PRERING)
-					ast_setstate(ast, AST_STATE_RING);
-				if ((ast->_state == AST_STATE_DOWN) || (ast->_state == AST_STATE_RING)) {
-					ast_debug(1, "Ring detected\n");
-					p->subs[idx].f.frametype = AST_FRAME_CONTROL;
-					p->subs[idx].f.subclass = AST_CONTROL_RING;
-				} else if (p->outgoing && ((ast->_state == AST_STATE_RINGING) || (ast->_state == AST_STATE_DIALING))) {
-					ast_debug(1, "Line answered\n");
-					if (p->confirmanswer) {
-						p->subs[idx].f.frametype = AST_FRAME_NULL;
-						p->subs[idx].f.subclass = 0;
-					} else {
-						p->subs[idx].f.frametype = AST_FRAME_CONTROL;
-						p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
-						ast_setstate(ast, AST_STATE_UP);
-					}
-				} else if (ast->_state != AST_STATE_RING)
-					ast_log(LOG_WARNING, "Ring/Off-hook in strange state %d on channel %d\n", ast->_state, p->channel);
-				break;
-			default:
-				ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
-			}
-			break;
-		case DAHDI_EVENT_RINGBEGIN:
-			switch (p->sig) {
-			case SIG_FXSLS:
-			case SIG_FXSGS:
-			case SIG_FXSKS:
-				if (ast->_state == AST_STATE_RING) {
-					p->ringt = p->ringt_base;
-				}
-				break;
-			}
-			break;
-		case DAHDI_EVENT_RINGEROFF:
-			if (p->inalarm) break;
-			if ((p->radio || (p->oprmode < 0))) break;
-			ast->rings++;
-			if ((ast->rings > p->cidrings) && (p->cidspill)) {
-				ast_log(LOG_WARNING, "Didn't finish Caller-ID spill.  Cancelling.\n");
-				ast_free(p->cidspill);
-				p->cidspill = NULL;
+				p->subs[idx].f.subclass = AST_CONTROL_ANSWER;
+				/* Make sure it stops ringing */
+				dahdi_set_hook(p->subs[idx].dfd, DAHDI_OFFHOOK);
+				ast_debug(1, "channel %d answered\n", p->channel);
+				if (p->cidspill) {
+					/* Cancel any running CallerID spill */
+					ast_free(p->cidspill);
+					p->cidspill = NULL;
+				}
+				p->dialing = 0;
 				p->callwaitcas = 0;
-			}
-			p->subs[idx].f.frametype = AST_FRAME_CONTROL;
-			p->subs[idx].f.subclass = AST_CONTROL_RINGING;
-			break;
-		case DAHDI_EVENT_RINGERON:
-			break;
-		case DAHDI_EVENT_NOALARM:
-			p->inalarm = 0;
-#ifdef HAVE_PRI
-			/* Extremely unlikely but just in case */
-			if (p->bearer)
-				p->bearer->inalarm = 0;
-#endif
-			ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", p->channel);
-			manager_event(EVENT_FLAG_SYSTEM, "AlarmClear",
-								"Channel: %d\r\n", p->channel);
-			break;
-		case DAHDI_EVENT_WINKFLASH:
-			if (p->inalarm) break;
-			if (p->radio) break;
-			if (p->oprmode < 0) break;
-			if (p->oprmode > 1)
-			{
-				struct dahdi_params par;
-
-				memset(&par, 0, sizeof(par));
-				if (ioctl(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par) != -1)
-				{
-					if (!par.rxisoffhook)
-					{
-						/* Make sure it stops ringing */
-						dahdi_set_hook(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_RINGOFF);
-						dahdi_set_hook(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_RING);
-						save_conference(p);
-						tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_RINGTONE);
-					}
-				}
-				break;
-			}
-			/* Remember last time we got a flash-hook */
-			p->flashtime = ast_tvnow();
-			switch (mysig) {
-			case SIG_FXOLS:
-			case SIG_FXOGS:
-			case SIG_FXOKS:
-				ast_debug(1, "Winkflash, index: %d, normal: %d, callwait: %d, thirdcall: %d\n",
-					idx, p->subs[SUB_REAL].dfd, p->subs[SUB_CALLWAIT].dfd, p->subs[SUB_THREEWAY].dfd);
-				p->callwaitcas = 0;
-
-				if (idx != SUB_REAL) {
-					ast_log(LOG_WARNING, "Got flash hook with index %d on channel %d?!?\n", idx, p->channel);
-					goto winkflashdone;
-				}
-
-				if (p->subs[SUB_CALLWAIT].owner) {
-					/* Swap to call-wait */
-					swap_subs(p, SUB_REAL, SUB_CALLWAIT);
-					tone_zone_play_tone(p->subs[SUB_REAL].dfd, -1);
-					p->owner = p->subs[SUB_REAL].owner;
-					ast_debug(1, "Making %s the new owner\n", p->owner->name);
-					if (p->owner->_state == AST_STATE_RINGING) {
-						ast_setstate(p->owner, AST_STATE_UP);
-						p->subs[SUB_REAL].needanswer = 1;
-					}
-					p->callwaitingrepeat = 0;
-					p->cidcwexpire = 0;
-					/* Start music on hold if appropriate */
-					if (!p->subs[SUB_CALLWAIT].inthreeway && ast_bridged_channel(p->subs[SUB_CALLWAIT].owner)) {
-						ast_queue_control_data(p->subs[SUB_CALLWAIT].owner, AST_CONTROL_HOLD,
-							S_OR(p->mohsuggest, NULL),
-							!ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
-					}
-					p->subs[SUB_CALLWAIT].needhold = 1;
-					if (ast_bridged_channel(p->subs[SUB_REAL].owner)) {
-						ast_queue_control_data(p->subs[SUB_REAL].owner, AST_CONTROL_HOLD,
-							S_OR(p->mohsuggest, NULL),
-							!ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
-					}
-					p->subs[SUB_REAL].needunhold = 1;
-				} else if (!p->subs[SUB_THREEWAY].owner) {
-					if (!p->threewaycalling) {
-						/* Just send a flash if no 3-way calling */
-						p->subs[SUB_REAL].needflash = 1;
-						goto winkflashdone;
-					} else if (!check_for_conference(p)) {
-						char cid_num[256];
-						char cid_name[256];
-
-						cid_num[0] = 0;
-						cid_name[0] = 0;
-						if (p->dahditrcallerid && p->owner) {
-							if (p->owner->cid.cid_num)
-								ast_copy_string(cid_num, p->owner->cid.cid_num, sizeof(cid_num));
-							if (p->owner->cid.cid_name)
-								ast_copy_string(cid_name, p->owner->cid.cid_name, sizeof(cid_name));
-						}
-						/* XXX This section needs much more error checking!!! XXX */
-						/* Start a 3-way call if feasible */
-						if (!((ast->pbx) ||
-							(ast->_state == AST_STATE_UP) ||
-							(ast->_state == AST_STATE_RING))) {
-							ast_debug(1, "Flash when call not up or ringing\n");
-							goto winkflashdone;
-						}
-						if (alloc_sub(p, SUB_THREEWAY)) {
-							ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n");
-							goto winkflashdone;
-						}
-						/* Make new channel */
-						chan = dahdi_new(p, AST_STATE_RESERVED, 0, SUB_THREEWAY, 0, 0);
-						if (p->dahditrcallerid) {
-							if (!p->origcid_num)
-								p->origcid_num = ast_strdup(p->cid_num);
-							if (!p->origcid_name)
-								p->origcid_name = ast_strdup(p->cid_name);
-							ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num));
-							ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name));
-						}
-						/* Swap things around between the three-way and real call */
-						swap_subs(p, SUB_THREEWAY, SUB_REAL);
-						/* Disable echo canceller for better dialing */
-						dahdi_disable_ec(p);
-						res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_DIALRECALL);
-						if (res)
-							ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
-						p->owner = chan;
-						if (!chan) {
-							ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", p->channel);
-						} else if (ast_pthread_create_detached(&threadid, NULL, analog_ss_thread, chan)) {
-							ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel);
-							res = tone_zone_play_tone(p->subs[SUB_REAL].dfd, DAHDI_TONE_CONGESTION);
-							dahdi_enable_ec(p);
-							ast_hangup(chan);
-						} else {
- 							struct ast_channel *other = ast_bridged_channel(p->subs[SUB_THREEWAY].owner);
- 							int way3bridge = 0, cdr3way = 0;
-
- 							if (!other) {
- 								other = ast_bridged_channel(p->subs[SUB_REAL].owner);
- 							} else
- 								way3bridge = 1;
-
- 							if (p->subs[SUB_THREEWAY].owner->cdr)
- 								cdr3way = 1;
-
-							ast_verb(3, "Started three way call on channel %d\n", p->channel);
-
-							/* Start music on hold if appropriate */
-							if (ast_bridged_channel(p->subs[SUB_THREEWAY].owner)) {
-								ast_queue_control_data(p->subs[SUB_THREEWAY].owner, AST_CONTROL_HOLD,
-									S_OR(p->mohsuggest, NULL),
-									!ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
-							}
-							p->subs[SUB_THREEWAY].needhold = 1;
-						}
-					}
-				} else {
-					/* Already have a 3 way call */
-					if (p->subs[SUB_THREEWAY].inthreeway) {
-						/* Call is already up, drop the last person */
-						ast_debug(1, "Got flash with three way call up, dropping last call on %d\n", p->channel);
-						/* If the primary call isn't answered yet, use it */
-						if ((p->subs[SUB_REAL].owner->_state != AST_STATE_UP) && (p->subs[SUB_THREEWAY].owner->_state == AST_STATE_UP)) {
-							/* Swap back -- we're dropping the real 3-way that isn't finished yet*/
-							swap_subs(p, SUB_THREEWAY, SUB_REAL);
-							p->owner = p->subs[SUB_REAL].owner;
-						}
-						/* Drop the last call and stop the conference */
-						ast_verb(3, "Dropping three-way call on %s\n", p->subs[SUB_THREEWAY].owner->name);

[... 2446 lines stripped ...]



More information about the asterisk-commits mailing list