various code formatting changes and cleanups related to bug #4706

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6137 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.2-netsec
Kevin P. Fleming 21 years ago
parent 7dfba67f7d
commit 17fee8dc68

@ -3289,8 +3289,10 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
pthread_t threadid; pthread_t threadid;
pthread_attr_t attr; pthread_attr_t attr;
struct ast_channel *chan; struct ast_channel *chan;
pthread_attr_init(&attr); pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
index = zt_get_index(ast, p, 0); index = zt_get_index(ast, p, 0);
p->subs[index].f.frametype = AST_FRAME_NULL; p->subs[index].f.frametype = AST_FRAME_NULL;
p->subs[index].f.datalen = 0; p->subs[index].f.datalen = 0;
@ -3306,7 +3308,9 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
p->fake_event = 0; p->fake_event = 0;
} else } else
res = zt_get_event(p->subs[index].zfd); res = zt_get_event(p->subs[index].zfd);
ast_log(LOG_DEBUG, "Got event %s(%d) on channel %d (index %d)\n", event2str(res), res, p->channel, index); ast_log(LOG_DEBUG, "Got event %s(%d) on channel %d (index %d)\n", event2str(res), res, p->channel, index);
if (res & (ZT_EVENT_PULSEDIGIT | ZT_EVENT_DTMFUP)) { if (res & (ZT_EVENT_PULSEDIGIT | ZT_EVENT_DTMFUP)) {
if (res & ZT_EVENT_PULSEDIGIT) if (res & ZT_EVENT_PULSEDIGIT)
p->pulsedial = 1; p->pulsedial = 1;
@ -3319,6 +3323,7 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
zt_confmute(p, 0); zt_confmute(p, 0);
return &p->subs[index].f; return &p->subs[index].f;
} }
if (res & ZT_EVENT_DTMFDOWN) { if (res & ZT_EVENT_DTMFDOWN) {
ast_log(LOG_DEBUG, "DTMF Down '%c'\n", res & 0xff); ast_log(LOG_DEBUG, "DTMF Down '%c'\n", res & 0xff);
p->subs[index].f.frametype = AST_FRAME_NULL; p->subs[index].f.frametype = AST_FRAME_NULL;
@ -3327,6 +3332,7 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
/* Mute conference, return null frame */ /* Mute conference, return null frame */
return &p->subs[index].f; return &p->subs[index].f;
} }
switch(res) { switch(res) {
case ZT_EVENT_BITSCHANGED: case ZT_EVENT_BITSCHANGED:
if (p->sig == SIG_R2) { if (p->sig == SIG_R2) {
@ -3486,13 +3492,13 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV; p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
ast_log(LOG_DEBUG, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel); ast_log(LOG_DEBUG, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock); ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
} else if ((ast->pbx) || } else if ((ast->pbx) || (ast->_state == AST_STATE_UP)) {
(ast->_state == AST_STATE_UP)) {
if (p->transfer) { if (p->transfer) {
/* In any case this isn't a threeway call anymore */ /* In any case this isn't a threeway call anymore */
p->subs[SUB_REAL].inthreeway = 0; p->subs[SUB_REAL].inthreeway = 0;
p->subs[SUB_THREEWAY].inthreeway = 0; p->subs[SUB_THREEWAY].inthreeway = 0;
if (!p->transfertobusy && p->owner->_state == AST_STATE_BUSY) { /* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
if (!p->transfertobusy && ast->_state == AST_STATE_BUSY) {
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock); ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
/* Swap subs and dis-own channel */ /* Swap subs and dis-own channel */
swap_subs(p, SUB_THREEWAY, SUB_REAL); swap_subs(p, SUB_THREEWAY, SUB_REAL);
@ -3500,20 +3506,22 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
/* Ring the phone */ /* Ring the phone */
zt_ring_phone(p); zt_ring_phone(p);
} else { } else {
/* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */ if ((res = attempt_transfer(p)) < 0) {
if ((res = attempt_transfer(p)) < 0)
p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV; p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
else if (res) { if (p->subs[SUB_THREEWAY].owner)
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
} else if (res) {
/* Don't actually hang up at this point */ /* Don't actually hang up at this point */
if (p->subs[SUB_THREEWAY].owner) if (p->subs[SUB_THREEWAY].owner)
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock); ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
break; break;
} }
} }
} else } else {
p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV; p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
if (p->subs[SUB_THREEWAY].owner) if (p->subs[SUB_THREEWAY].owner)
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock); ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
}
} else { } else {
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock); ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
/* Swap subs and dis-own channel */ /* Swap subs and dis-own channel */
@ -3725,7 +3733,12 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
ast_log(LOG_DEBUG, "Winkflash, index: %d, normal: %d, callwait: %d, thirdcall: %d\n", ast_log(LOG_DEBUG, "Winkflash, index: %d, normal: %d, callwait: %d, thirdcall: %d\n",
index, p->subs[SUB_REAL].zfd, p->subs[SUB_CALLWAIT].zfd, p->subs[SUB_THREEWAY].zfd); index, p->subs[SUB_REAL].zfd, p->subs[SUB_CALLWAIT].zfd, p->subs[SUB_THREEWAY].zfd);
p->callwaitcas = 0; p->callwaitcas = 0;
if (index == SUB_REAL) {
if (index != SUB_REAL) {
ast_log(LOG_WARNING, "Got flash hook with index %d on channel %d?!?\n", index, p->channel);
goto winkflashdone;
}
if (p->subs[SUB_CALLWAIT].owner) { if (p->subs[SUB_CALLWAIT].owner) {
/* Swap to call-wait */ /* Swap to call-wait */
swap_subs(p, SUB_REAL, SUB_CALLWAIT); swap_subs(p, SUB_REAL, SUB_CALLWAIT);
@ -3744,9 +3757,14 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
if (ast_bridged_channel(p->subs[SUB_REAL].owner)) if (ast_bridged_channel(p->subs[SUB_REAL].owner))
ast_moh_stop(ast_bridged_channel(p->subs[SUB_REAL].owner)); ast_moh_stop(ast_bridged_channel(p->subs[SUB_REAL].owner));
} else if (!p->subs[SUB_THREEWAY].owner) { } else if (!p->subs[SUB_THREEWAY].owner) {
char cid_num[256]=""; char cid_num[256];
char cid_name[256]=""; char cid_name[256];
if (p->threewaycalling && !check_for_conference(p)) {
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)) {
if (p->zaptrcallerid && p->owner) { if (p->zaptrcallerid && p->owner) {
if (p->owner->cid.cid_num) if (p->owner->cid.cid_num)
ast_copy_string(cid_num, p->owner->cid.cid_num, sizeof(cid_num)); ast_copy_string(cid_num, p->owner->cid.cid_num, sizeof(cid_num));
@ -3755,10 +3773,16 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
} }
/* XXX This section needs much more error checking!!! XXX */ /* XXX This section needs much more error checking!!! XXX */
/* Start a 3-way call if feasible */ /* Start a 3-way call if feasible */
if ((ast->pbx) || if (!((ast->pbx) ||
(ast->_state == AST_STATE_UP) || (ast->_state == AST_STATE_UP) ||
(ast->_state == AST_STATE_RING)) { (ast->_state == AST_STATE_RING))) {
if (!alloc_sub(p, SUB_THREEWAY)) { ast_log(LOG_DEBUG, "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 */ /* Make new channel */
chan = zt_new(p, AST_STATE_RESERVED, 0, SUB_THREEWAY, 0, 0); chan = zt_new(p, AST_STATE_RESERVED, 0, SUB_THREEWAY, 0, 0);
if (p->zaptrcallerid) { if (p->zaptrcallerid) {
@ -3777,13 +3801,13 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
if (res) if (res)
ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel); ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
p->owner = chan; p->owner = chan;
if (chan && ast_pthread_create(&threadid, &attr, ss_thread, chan)) { if (!chan) {
ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", p->channel);
} else if (ast_pthread_create(&threadid, &attr, ss_thread, chan)) {
ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel); ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel);
res = tone_zone_play_tone(p->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION); res = tone_zone_play_tone(p->subs[SUB_REAL].zfd, ZT_TONE_CONGESTION);
zt_enable_ec(p); zt_enable_ec(p);
ast_hangup(chan); ast_hangup(chan);
} else if (!chan) {
ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", p->channel);
} else { } else {
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Started three way call on channel %d\n", p->channel); ast_verbose(VERBOSE_PREFIX_3 "Started three way call on channel %d\n", p->channel);
@ -3791,13 +3815,6 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
if (ast_bridged_channel(p->subs[SUB_THREEWAY].owner)) if (ast_bridged_channel(p->subs[SUB_THREEWAY].owner))
ast_moh_start(ast_bridged_channel(p->subs[SUB_THREEWAY].owner), NULL); ast_moh_start(ast_bridged_channel(p->subs[SUB_THREEWAY].owner), NULL);
} }
} else
ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n");
} else
ast_log(LOG_DEBUG, "Flash when call not up or ringing\n");
} else if (!p->threewaycalling) {
/* Just send a flash if no 3-way calling or callwait */
p->subs[SUB_REAL].needflash = 1;
} }
} else { } else {
/* Already have a 3 way call */ /* Already have a 3 way call */
@ -3807,7 +3824,7 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
ast_log(LOG_DEBUG, "Got flash with three way call up, dropping last call on %d\n", p->channel); ast_log(LOG_DEBUG, "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 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)) { if ((p->subs[SUB_REAL].owner->_state != AST_STATE_UP) && (p->subs[SUB_THREEWAY].owner->_state == AST_STATE_UP)) {
/* Swap back -- we're droppign the real 3-way that isn't finished yet*/ /* Swap back -- we're dropping the real 3-way that isn't finished yet*/
swap_subs(p, SUB_THREEWAY, SUB_REAL); swap_subs(p, SUB_THREEWAY, SUB_REAL);
p->owner = p->subs[SUB_REAL].owner; p->owner = p->subs[SUB_REAL].owner;
} }
@ -3820,7 +3837,7 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
} else { } else {
/* Lets see what we're up to */ /* Lets see what we're up to */
if (((ast->pbx) || (ast->_state == AST_STATE_UP)) && if (((ast->pbx) || (ast->_state == AST_STATE_UP)) &&
(p->transfertobusy || (p->owner->_state != AST_STATE_BUSY))) { (p->transfertobusy || (ast->_state != AST_STATE_BUSY))) {
int otherindex = SUB_THREEWAY; int otherindex = SUB_THREEWAY;
if (option_verbose > 2) if (option_verbose > 2)
@ -3853,9 +3870,7 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
} }
} }
} else { winkflashdone:
ast_log(LOG_WARNING, "Got flash hook with index %d on channel %d?!?\n", index, p->channel);
}
update_conf(p); update_conf(p);
break; break;
case SIG_EM: case SIG_EM:

Loading…
Cancel
Save