more simplifications - use a local variable c instead of o->chan,

use S_OR as appropriate.

Still need to fix the indentation of some blocks.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@21480 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Luigi Rizzo 20 years ago
parent acf0f038dc
commit 25c6ab22f9

@ -439,14 +439,13 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
char *tech; char *tech;
const char *forward_context; const char *forward_context;
ast_copy_string(tmpchan, o->chan->call_forward, sizeof(tmpchan)); ast_copy_string(tmpchan, c->call_forward, sizeof(tmpchan));
if ((stuff = strchr(tmpchan, '/'))) { if ((stuff = strchr(tmpchan, '/'))) {
*stuff = '\0'; *stuff++ = '\0';
stuff++;
tech = tmpchan; tech = tmpchan;
} else { } else {
forward_context = pbx_builtin_getvar_helper(o->chan, "FORWARD_CONTEXT"); forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
snprintf(tmpchan, sizeof(tmpchan), "%s@%s", o->chan->call_forward, forward_context ? forward_context : o->chan->context); snprintf(tmpchan, sizeof(tmpchan), "%s@%s", c->call_forward, forward_context ? forward_context : c->context);
stuff = tmpchan; stuff = tmpchan;
tech = "Local"; tech = "Local";
} }
@ -454,80 +453,59 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
o->forwards++; o->forwards++;
if (o->forwards < AST_MAX_FORWARDS) { if (o->forwards < AST_MAX_FORWARDS) {
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, o->chan->name); ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, c->name);
/* Setup parameters */ /* Setup parameters */
o->chan = ast_request(tech, in->nativeformats, stuff, &cause); c = o->chan = ast_request(tech, in->nativeformats, stuff, &cause);
if (!o->chan) if (!c)
ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause); ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause);
} else { } else {
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Too many forwards from %s\n", o->chan->name); ast_verbose(VERBOSE_PREFIX_3 "Too many forwards from %s\n", c->name);
cause = AST_CAUSE_CONGESTION; cause = AST_CAUSE_CONGESTION;
o->chan = NULL; c = o->chan = NULL;
} }
if (!o->chan) { if (!c) {
ast_clear_flag(o, DIAL_STILLGOING); ast_clear_flag(o, DIAL_STILLGOING);
HANDLE_CAUSE(cause, in); HANDLE_CAUSE(cause, in);
} else { } else {
ast_rtp_make_compatible(o->chan, in); ast_rtp_make_compatible(c, in);
if (o->chan->cid.cid_num) if (c->cid.cid_num)
free(o->chan->cid.cid_num); free(c->cid.cid_num);
o->chan->cid.cid_num = NULL; c->cid.cid_num = NULL;
if (o->chan->cid.cid_name) if (c->cid.cid_name)
free(o->chan->cid.cid_name); free(c->cid.cid_name);
o->chan->cid.cid_name = NULL; c->cid.cid_name = NULL;
if (ast_test_flag(o, OPT_FORCECLID)) { if (ast_test_flag(o, OPT_FORCECLID)) {
char *newcid = NULL; c->cid.cid_num = ast_strdup(S_OR(in->macroexten, in->exten));
ast_string_field_set(c, accountcode, winner->accountcode);
if (!ast_strlen_zero(in->macroexten)) c->cdrflags = winner->cdrflags;
newcid = in->macroexten;
else
newcid = in->exten;
o->chan->cid.cid_num = strdup(newcid);
ast_string_field_set(o->chan, accountcode, winner->accountcode);
o->chan->cdrflags = winner->cdrflags;
if (!o->chan->cid.cid_num)
ast_log(LOG_WARNING, "Out of memory\n");
} else { } else {
if (in->cid.cid_num) { c->cid.cid_num = ast_strdup(in->cid.cid_num);
o->chan->cid.cid_num = strdup(in->cid.cid_num); c->cid.cid_name = ast_strdup(in->cid.cid_name);
if (!o->chan->cid.cid_num) ast_string_field_set(c, accountcode, in->accountcode);
ast_log(LOG_WARNING, "Out of memory\n"); c->cdrflags = in->cdrflags;
}
if (in->cid.cid_name) {
o->chan->cid.cid_name = strdup(in->cid.cid_name);
if (!o->chan->cid.cid_name)
ast_log(LOG_WARNING, "Out of memory\n");
}
ast_string_field_set(o->chan, accountcode, in->accountcode);
o->chan->cdrflags = in->cdrflags;
} }
if (in->cid.cid_ani) { if (in->cid.cid_ani) {
if (o->chan->cid.cid_ani) if (c->cid.cid_ani)
free(o->chan->cid.cid_ani); free(c->cid.cid_ani);
o->chan->cid.cid_ani = strdup(in->cid.cid_ani); c->cid.cid_ani = ast_strdup(in->cid.cid_ani);
if (!o->chan->cid.cid_ani)
ast_log(LOG_WARNING, "Out of memory\n");
} }
if (o->chan->cid.cid_rdnis) if (c->cid.cid_rdnis)
free(o->chan->cid.cid_rdnis); free(c->cid.cid_rdnis);
if (!ast_strlen_zero(in->macroexten)) c->cid.cid_rdnis = ast_strdup(S_OR(in->macroexten, in->exten));
o->chan->cid.cid_rdnis = strdup(in->macroexten); if (ast_call(c, tmpchan, 0)) {
else
o->chan->cid.cid_rdnis = strdup(in->exten);
if (ast_call(o->chan, tmpchan, 0)) {
ast_log(LOG_NOTICE, "Failed to dial on local channel for call forward to '%s'\n", tmpchan); ast_log(LOG_NOTICE, "Failed to dial on local channel for call forward to '%s'\n", tmpchan);
ast_clear_flag(o, DIAL_STILLGOING); ast_clear_flag(o, DIAL_STILLGOING);
ast_hangup(o->chan); ast_hangup(c);
o->chan = NULL; c = o->chan = NULL;
numnochan++; numnochan++;
} else { } else {
senddialevent(in, o->chan); senddialevent(in, c);
/* After calling, set callerid to extension */ /* After calling, set callerid to extension */
if (!ast_test_flag(peerflags, OPT_ORIGINAL_CLID)) if (!ast_test_flag(peerflags, OPT_ORIGINAL_CLID))
ast_set_callerid(o->chan, S_OR(in->macroexten, in->exten), get_cid_name(cidname, sizeof(cidname), in), NULL); ast_set_callerid(c, S_OR(in->macroexten, in->exten), get_cid_name(cidname, sizeof(cidname), in), NULL);
} }
} }
/* Hangup the original channel now, in case we needed it */ /* Hangup the original channel now, in case we needed it */
@ -536,9 +514,9 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
} }
f = ast_read(winner); f = ast_read(winner);
if (!f) { if (!f) {
in->hangupcause = o->chan->hangupcause; in->hangupcause = c->hangupcause;
ast_hangup(o->chan); ast_hangup(c);
o->chan = NULL; c = o->chan = NULL;
ast_clear_flag(o, DIAL_STILLGOING); ast_clear_flag(o, DIAL_STILLGOING);
HANDLE_CAUSE(in->hangupcause, in); HANDLE_CAUSE(in->hangupcause, in);
continue; continue;
@ -549,8 +527,8 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
/* This is our guy if someone answered. */ /* This is our guy if someone answered. */
if (!peer) { if (!peer) {
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", o->chan->name, in->name); ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", c->name, in->name);
peer = o->chan; peer = c;
ast_copy_flags(peerflags, o, ast_copy_flags(peerflags, o,
OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP | OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
@ -559,29 +537,29 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
} }
/* If call has been answered, then the eventual hangup is likely to be normal hangup */ /* If call has been answered, then the eventual hangup is likely to be normal hangup */
in->hangupcause = AST_CAUSE_NORMAL_CLEARING; in->hangupcause = AST_CAUSE_NORMAL_CLEARING;
o->chan->hangupcause = AST_CAUSE_NORMAL_CLEARING; c->hangupcause = AST_CAUSE_NORMAL_CLEARING;
break; break;
case AST_CONTROL_BUSY: case AST_CONTROL_BUSY:
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "%s is busy\n", o->chan->name); ast_verbose(VERBOSE_PREFIX_3 "%s is busy\n", c->name);
in->hangupcause = o->chan->hangupcause; in->hangupcause = c->hangupcause;
ast_hangup(o->chan); ast_hangup(c);
o->chan = NULL; c = o->chan = NULL;
ast_clear_flag(o, DIAL_STILLGOING); ast_clear_flag(o, DIAL_STILLGOING);
HANDLE_CAUSE(AST_CAUSE_BUSY, in); HANDLE_CAUSE(AST_CAUSE_BUSY, in);
break; break;
case AST_CONTROL_CONGESTION: case AST_CONTROL_CONGESTION:
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "%s is circuit-busy\n", o->chan->name); ast_verbose(VERBOSE_PREFIX_3 "%s is circuit-busy\n", c->name);
in->hangupcause = o->chan->hangupcause; in->hangupcause = c->hangupcause;
ast_hangup(o->chan); ast_hangup(c);
o->chan = NULL; c = o->chan = NULL;
ast_clear_flag(o, DIAL_STILLGOING); ast_clear_flag(o, DIAL_STILLGOING);
HANDLE_CAUSE(AST_CAUSE_CONGESTION, in); HANDLE_CAUSE(AST_CAUSE_CONGESTION, in);
break; break;
case AST_CONTROL_RINGING: case AST_CONTROL_RINGING:
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "%s is ringing\n", o->chan->name); ast_verbose(VERBOSE_PREFIX_3 "%s is ringing\n", c->name);
if (!(*sentringing) && !ast_test_flag(outgoing, OPT_MUSICBACK)) { if (!(*sentringing) && !ast_test_flag(outgoing, OPT_MUSICBACK)) {
ast_indicate(in, AST_CONTROL_RINGING); ast_indicate(in, AST_CONTROL_RINGING);
(*sentringing)++; (*sentringing)++;
@ -589,29 +567,29 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
break; break;
case AST_CONTROL_PROGRESS: case AST_CONTROL_PROGRESS:
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose (VERBOSE_PREFIX_3 "%s is making progress passing it to %s\n", o->chan->name,in->name); ast_verbose (VERBOSE_PREFIX_3 "%s is making progress passing it to %s\n", c->name, in->name);
if (!ast_test_flag(outgoing, OPT_RINGBACK)) if (!ast_test_flag(outgoing, OPT_RINGBACK))
ast_indicate(in, AST_CONTROL_PROGRESS); ast_indicate(in, AST_CONTROL_PROGRESS);
break; break;
case AST_CONTROL_VIDUPDATE: case AST_CONTROL_VIDUPDATE:
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose (VERBOSE_PREFIX_3 "%s requested a video update, passing it to %s\n", o->chan->name,in->name); ast_verbose (VERBOSE_PREFIX_3 "%s requested a video update, passing it to %s\n", c->name, in->name);
ast_indicate(in, AST_CONTROL_VIDUPDATE); ast_indicate(in, AST_CONTROL_VIDUPDATE);
break; break;
case AST_CONTROL_PROCEEDING: case AST_CONTROL_PROCEEDING:
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose (VERBOSE_PREFIX_3 "%s is proceeding passing it to %s\n", o->chan->name,in->name); ast_verbose (VERBOSE_PREFIX_3 "%s is proceeding passing it to %s\n", c->name, in->name);
if (!ast_test_flag(outgoing, OPT_RINGBACK)) if (!ast_test_flag(outgoing, OPT_RINGBACK))
ast_indicate(in, AST_CONTROL_PROCEEDING); ast_indicate(in, AST_CONTROL_PROCEEDING);
break; break;
case AST_CONTROL_HOLD: case AST_CONTROL_HOLD:
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Call on %s placed on hold\n", o->chan->name); ast_verbose(VERBOSE_PREFIX_3 "Call on %s placed on hold\n", c->name);
ast_indicate(in, AST_CONTROL_HOLD); ast_indicate(in, AST_CONTROL_HOLD);
break; break;
case AST_CONTROL_UNHOLD: case AST_CONTROL_UNHOLD:
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Call on %s left from hold\n", o->chan->name); ast_verbose(VERBOSE_PREFIX_3 "Call on %s left from hold\n", c->name);
ast_indicate(in, AST_CONTROL_UNHOLD); ast_indicate(in, AST_CONTROL_UNHOLD);
break; break;
case AST_CONTROL_OFFHOOK: case AST_CONTROL_OFFHOOK:
@ -621,7 +599,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
case -1: case -1:
if (!ast_test_flag(outgoing, OPT_RINGBACK | OPT_MUSICBACK)) { if (!ast_test_flag(outgoing, OPT_RINGBACK | OPT_MUSICBACK)) {
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "%s stopped sounds\n", o->chan->name); ast_verbose(VERBOSE_PREFIX_3 "%s stopped sounds\n", c->name);
ast_indicate(in, -1); ast_indicate(in, -1);
(*sentringing) = 0; (*sentringing) = 0;
} }

Loading…
Cancel
Save