start cleaning up this code so we can split the 900 lines function

into manageable chunks.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@21468 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Luigi Rizzo 20 years ago
parent 2745be5b26
commit 3aaaa41609

@ -371,18 +371,14 @@ static void senddialevent(struct ast_channel *src, struct ast_channel *dst)
static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_localuser *outgoing, int *to, struct ast_flags *peerflags, int *sentringing, char *status, size_t statussize, int busystart, int nochanstart, int congestionstart, int priority_jump, int *result) static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_localuser *outgoing, int *to, struct ast_flags *peerflags, int *sentringing, char *status, size_t statussize, int busystart, int nochanstart, int congestionstart, int priority_jump, int *result)
{ {
struct dial_localuser *o; struct dial_localuser *o;
int found;
int numlines;
int numbusy = busystart; int numbusy = busystart;
int numcongestion = congestionstart; int numcongestion = congestionstart;
int numnochan = nochanstart; int numnochan = nochanstart;
int prestart = busystart + congestionstart + nochanstart; int prestart = busystart + congestionstart + nochanstart;
int cause; int cause;
int orig = *to; int orig = *to;
struct ast_frame *f;
struct ast_channel *peer = NULL; struct ast_channel *peer = NULL;
struct ast_channel *watchers[AST_MAX_WATCHERS]; struct ast_channel *watchers[AST_MAX_WATCHERS];
int pos;
int single; int single;
struct ast_channel *winner; struct ast_channel *winner;
const char *context = NULL; const char *context = NULL;
@ -399,21 +395,16 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
while (*to && !peer) { while (*to && !peer) {
o = outgoing; int pos = 0; /* how many channels do we handle */
found = -1; int numlines = prestart;
pos = 1; watchers[pos++] = in;
numlines = prestart; for (o = outgoing; o; o = o->next) {
watchers[0] = in;
while (o) {
/* Keep track of important channels */ /* Keep track of important channels */
if (ast_test_flag(o, DIAL_STILLGOING) && o->chan) { if (ast_test_flag(o, DIAL_STILLGOING) && o->chan)
watchers[pos++] = o->chan; watchers[pos++] = o->chan;
found = 1;
}
o = o->next;
numlines++; numlines++;
} }
if (found < 0) { if (pos == 1) { /* only the input channel is available */
if (numlines == (numbusy + numcongestion + numnochan)) { if (numlines == (numbusy + numcongestion + numnochan)) {
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_2 "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, numbusy, numcongestion, numnochan); ast_verbose( VERBOSE_PREFIX_2 "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, numbusy, numcongestion, numnochan);
@ -434,20 +425,28 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
} }
winner = ast_waitfor_n(watchers, pos, to); winner = ast_waitfor_n(watchers, pos, to);
o = outgoing; o = outgoing;
while (o) { for (o = outgoing; o; o = o->next) {
if (ast_test_flag(o, DIAL_STILLGOING) && o->chan && (o->chan->_state == AST_STATE_UP)) { struct ast_frame *f;
struct ast_channel *c = o->chan;
if (c == NULL)
continue;
if (ast_test_flag(o, DIAL_STILLGOING) && c->_state == AST_STATE_UP) {
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 |
OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
DIAL_NOFORWARDHTML); DIAL_NOFORWARDHTML);
} }
} else if (o->chan && (o->chan == winner)) { continue;
if (!ast_strlen_zero(o->chan->call_forward)) { }
if (c != winner)
continue;
if (!ast_strlen_zero(c->call_forward)) {
char tmpchan[256]; char tmpchan[256];
char *stuff; char *stuff;
char *tech; char *tech;
@ -547,10 +546,17 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
/* Hangup the original channel now, in case we needed it */ /* Hangup the original channel now, in case we needed it */
ast_hangup(winner); ast_hangup(winner);
continue; continue;
} }
f = ast_read(winner); f = ast_read(winner);
if (f) { if (!f) {
if (f->frametype == AST_FRAME_CONTROL) { in->hangupcause = o->chan->hangupcause;
ast_hangup(o->chan);
o->chan = NULL;
ast_clear_flag(o, DIAL_STILLGOING);
HANDLE_CAUSE(in->hangupcause, in);
continue;
}
if (f->frametype == AST_FRAME_CONTROL) {
switch(f->subclass) { switch(f->subclass) {
case AST_CONTROL_ANSWER: case AST_CONTROL_ANSWER:
/* This is our guy if someone answered. */ /* This is our guy if someone answered. */
@ -637,35 +643,26 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "Dunno what to do with control type %d\n", f->subclass); ast_log(LOG_DEBUG, "Dunno what to do with control type %d\n", f->subclass);
} }
} else if (single && (f->frametype == AST_FRAME_VOICE) && } else if (single && (f->frametype == AST_FRAME_VOICE) &&
!(ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK))) { !(ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK))) {
if (ast_write(in, f)) if (ast_write(in, f))
ast_log(LOG_WARNING, "Unable to forward voice frame\n"); ast_log(LOG_WARNING, "Unable to forward voice frame\n");
} else if (single && (f->frametype == AST_FRAME_IMAGE) && } else if (single && (f->frametype == AST_FRAME_IMAGE) &&
!(ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK))) { !(ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK))) {
if (ast_write(in, f)) if (ast_write(in, f))
ast_log(LOG_WARNING, "Unable to forward image\n"); ast_log(LOG_WARNING, "Unable to forward image\n");
} else if (single && (f->frametype == AST_FRAME_TEXT) && } else if (single && (f->frametype == AST_FRAME_TEXT) &&
!(ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK))) { !(ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK))) {
if (ast_write(in, f)) if (ast_write(in, f))
ast_log(LOG_WARNING, "Unable to send text\n"); ast_log(LOG_WARNING, "Unable to send text\n");
} else if (single && (f->frametype == AST_FRAME_HTML) && !ast_test_flag(outgoing, DIAL_NOFORWARDHTML)) } else if (single && (f->frametype == AST_FRAME_HTML) && !ast_test_flag(outgoing, DIAL_NOFORWARDHTML)) {
if(ast_channel_sendhtml(in, f->subclass, f->data, f->datalen) == -1) if(ast_channel_sendhtml(in, f->subclass, f->data, f->datalen) == -1)
ast_log(LOG_WARNING, "Unable to send URL\n"); ast_log(LOG_WARNING, "Unable to send URL\n");
ast_frfree(f);
} else {
in->hangupcause = o->chan->hangupcause;
ast_hangup(o->chan);
o->chan = NULL;
ast_clear_flag(o, DIAL_STILLGOING);
HANDLE_CAUSE(in->hangupcause, in);
}
} }
o = o->next; ast_frfree(f);
} } /* end for */
if (winner == in) { if (winner == in) {
f = ast_read(in); struct ast_frame *f = ast_read(in);
#if 0 #if 0
if (f && (f->frametype != AST_FRAME_VOICE)) if (f && (f->frametype != AST_FRAME_VOICE))
printf("Frame type: %d, %d\n", f->frametype, f->subclass); printf("Frame type: %d, %d\n", f->frametype, f->subclass);
@ -728,7 +725,13 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_l
} }
return peer; return peer;
}
static void replace_macro_delimiter(char *s)
{
for (; *s; s++)
if (*s == '^')
*s = '|';
} }
static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags *peerflags) static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags *peerflags)
@ -787,32 +790,25 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
if (!(parse = ast_strdupa(data))) { if (!(parse = ast_strdupa(data)))
LOCAL_USER_REMOVE(u); goto done;
return -1;
}
AST_STANDARD_APP_ARGS(args, parse); AST_STANDARD_APP_ARGS(args, parse);
if (!ast_strlen_zero(args.options)) { if (!ast_strlen_zero(args.options) &&
if (ast_app_parse_options(dial_exec_options, &opts, opt_args, args.options)) { ast_app_parse_options(dial_exec_options, &opts, opt_args, args.options))
LOCAL_USER_REMOVE(u); goto done;
return -1;
}
}
if (ast_strlen_zero(args.peers)) { if (ast_strlen_zero(args.peers)) {
ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n"); ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
LOCAL_USER_REMOVE(u); goto done;
return -1;
} }
if (ast_test_flag(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) { if (ast_test_flag(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {
calldurationlimit = atoi(opt_args[OPT_ARG_DURATION_STOP]); calldurationlimit = atoi(opt_args[OPT_ARG_DURATION_STOP]);
if (!calldurationlimit) { if (!calldurationlimit) {
ast_log(LOG_WARNING, "Dial does not accept S(%s), hanging up.\n", opt_args[OPT_ARG_DURATION_STOP]); ast_log(LOG_WARNING, "Dial does not accept S(%s), hanging up.\n", opt_args[OPT_ARG_DURATION_STOP]);
LOCAL_USER_REMOVE(u); goto done;
return -1;
} }
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Setting call duration limit to %d seconds.\n", calldurationlimit); ast_verbose(VERBOSE_PREFIX_3 "Setting call duration limit to %d seconds.\n", calldurationlimit);
@ -840,8 +836,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
if (!timelimit) { if (!timelimit) {
ast_log(LOG_WARNING, "Dial does not accept L(%s), hanging up.\n", limit_str); ast_log(LOG_WARNING, "Dial does not accept L(%s), hanging up.\n", limit_str);
LOCAL_USER_REMOVE(u); goto done;
return -1;
} else if (play_warning > timelimit) { } else if (play_warning > timelimit) {
/* If the first warning is requested _after_ the entire call would end, /* If the first warning is requested _after_ the entire call would end,
and no warning frequency is requested, then turn off the warning. If and no warning frequency is requested, then turn off the warning. If
@ -852,6 +847,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
if (!warning_freq) { if (!warning_freq) {
play_warning = 0; play_warning = 0;
} else { } else {
/* XXX fix this!! */
while (play_warning > timelimit) while (play_warning > timelimit)
play_warning -= warning_freq; play_warning -= warning_freq;
if (play_warning < 1) if (play_warning < 1)
@ -998,26 +994,18 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"); outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP");
ast_copy_flags(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID | OPT_CALLER_HANGUP); ast_copy_flags(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID | OPT_CALLER_HANGUP);
cur = args.peers; /* loop through the list of dial destinations */
do { rest = args.peers;
/* Remember where to start next time */ while ((cur = strsep(&rest, "&")) ) {
rest = strchr(cur, '&');
if (rest) {
*rest = 0;
rest++;
}
/* Get a technology/[device:]number pair */ /* Get a technology/[device:]number pair */
tech = cur; number = cur;
number = strchr(tech, '/'); tech = strsep(&number, "/");
if (!number) { if (!number) {
ast_log(LOG_WARNING, "Dial argument takes format (technology/[device:]number1)\n"); ast_log(LOG_WARNING, "Dial argument takes format (technology/[device:]number1)\n");
goto out; goto out;
} }
*number = '\0'; if (!(tmp = ast_calloc(1, sizeof(*tmp))))
number++;
if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
goto out; goto out;
}
if (opts.flags) { if (opts.flags) {
ast_copy_flags(tmp, &opts, ast_copy_flags(tmp, &opts,
OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
@ -1033,8 +1021,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
/* If we can't, just go on to the next call */ /* If we can't, just go on to the next call */
ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n", tech, cause, ast_cause2str(cause)); ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n", tech, cause, ast_cause2str(cause));
HANDLE_CAUSE(cause, chan); HANDLE_CAUSE(cause, chan);
cur = rest; if (!rest) /* we are on the last destination */
if (!cur)
chan->hangupcause = cause; chan->hangupcause = cause;
continue; continue;
} }
@ -1045,8 +1032,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
char *tech; char *tech;
ast_copy_string(tmpchan, tmp->chan->call_forward, sizeof(tmpchan)); ast_copy_string(tmpchan, tmp->chan->call_forward, sizeof(tmpchan));
if ((stuff = strchr(tmpchan, '/'))) { if ((stuff = strchr(tmpchan, '/'))) {
*stuff = '\0'; *stuff++ = '\0';
stuff++;
tech = tmpchan; tech = tmpchan;
} else { } else {
snprintf(tmpchan, sizeof(tmpchan), "%s@%s", tmp->chan->call_forward, tmp->chan->context); snprintf(tmpchan, sizeof(tmpchan), "%s@%s", tmp->chan->call_forward, tmp->chan->context);
@ -1071,7 +1057,6 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
} }
if (!tmp->chan) { if (!tmp->chan) {
HANDLE_CAUSE(cause, chan); HANDLE_CAUSE(cause, chan);
cur = rest;
continue; continue;
} }
} }
@ -1141,7 +1126,6 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
ast_verbose(VERBOSE_PREFIX_3 "Couldn't call %s\n", numsubst); ast_verbose(VERBOSE_PREFIX_3 "Couldn't call %s\n", numsubst);
ast_hangup(tmp->chan); ast_hangup(tmp->chan);
tmp->chan = NULL; tmp->chan = NULL;
cur = rest;
continue; continue;
} else { } else {
senddialevent(chan, tmp->chan); senddialevent(chan, tmp->chan);
@ -1159,19 +1143,21 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
/* If this line is up, don't try anybody else */ /* If this line is up, don't try anybody else */
if (outgoing->chan->_state == AST_STATE_UP) if (outgoing->chan->_state == AST_STATE_UP)
break; break;
cur = rest; }
} while (cur);
if (!ast_strlen_zero(args.timeout)) { if (ast_strlen_zero(args.timeout)) {
to = -1;
} else {
to = atoi(args.timeout); to = atoi(args.timeout);
if (to > 0) if (to > 0)
to *= 1000; to *= 1000;
else else
ast_log(LOG_WARNING, "Invalid timeout specified: '%s'\n", args.timeout); ast_log(LOG_WARNING, "Invalid timeout specified: '%s'\n", args.timeout);
} else }
to = -1;
if (outgoing) { if (!outgoing) {
strcpy(status, "CHANUNAVAIL");
} else {
/* Our status will at least be NOANSWER */ /* Our status will at least be NOANSWER */
strcpy(status, "NOANSWER"); strcpy(status, "NOANSWER");
if (ast_test_flag(outgoing, OPT_MUSICBACK)) { if (ast_test_flag(outgoing, OPT_MUSICBACK)) {
@ -1181,8 +1167,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
ast_indicate(chan, AST_CONTROL_RINGING); ast_indicate(chan, AST_CONTROL_RINGING);
sentringing++; sentringing++;
} }
} else }
strcpy(status, "CHANUNAVAIL");
time(&start_time); time(&start_time);
peer = wait_for_answer(chan, outgoing, &to, peerflags, &sentringing, status, sizeof(status), numbusy, numnochan, numcongestion, ast_test_flag(&opts, OPT_PRIORITY_JUMP), &result); peer = wait_for_answer(chan, outgoing, &to, peerflags, &sentringing, status, sizeof(status), numbusy, numnochan, numcongestion, ast_test_flag(&opts, OPT_PRIORITY_JUMP), &result);
@ -1190,16 +1175,12 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
if (!peer) { if (!peer) {
if (result) { if (result) {
res = result; res = result;
} else if (to) } else if (to) { /* Musta gotten hung up */
/* Musta gotten hung up */
res = -1; res = -1;
else } else { /* Nobody answered, next please? */
/* Nobody answered, next please? */
res = 0; res = 0;
}
goto out; } else {
}
if (peer) {
time(&answer_time); time(&answer_time);
strcpy(status, "ANSWER"); strcpy(status, "ANSWER");
/* Ah ha! Someone answered within the desired timeframe. Of course after this /* Ah ha! Someone answered within the desired timeframe. Of course after this
@ -1407,7 +1388,9 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
} }
} }
} }
if (ast_test_flag(&opts, OPT_ANNOUNCE) && !ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) { if (!ast_test_flag(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
res = 0;
} else {
/* Start autoservice on the other chan */ /* Start autoservice on the other chan */
res = ast_autoservice_start(chan); res = ast_autoservice_start(chan);
/* Now Stream the File */ /* Now Stream the File */
@ -1423,28 +1406,20 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
else else
res = digit; res = digit;
} else }
res = 0;
if (chan && peer && ast_test_flag(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) { if (chan && peer && ast_test_flag(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
char *ch; replace_macro_delimiter(opt_args[OPT_ARG_GOTO]);
for (ch = opt_args[OPT_ARG_GOTO]; *ch; ch++) {
if (*ch == '^')
*ch = '|';
}
ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]); ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
ast_parseable_goto(peer, opt_args[OPT_ARG_GOTO]); ast_parseable_goto(peer, opt_args[OPT_ARG_GOTO]);
peer->priority++; peer->priority++;
ast_pbx_start(peer); ast_pbx_start(peer);
hanguptree(outgoing, NULL); hanguptree(outgoing, NULL);
LOCAL_USER_REMOVE(u); res = 0;
return 0; goto done;
} }
if (ast_test_flag(&opts, OPT_CALLEE_MACRO) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_MACRO])) { if (ast_test_flag(&opts, OPT_CALLEE_MACRO) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_MACRO])) {
char *ch;
res = ast_autoservice_start(chan); res = ast_autoservice_start(chan);
if (res) { if (res) {
ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n"); ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n");
@ -1454,10 +1429,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
app = pbx_findapp("Macro"); app = pbx_findapp("Macro");
if (app && !res) { if (app && !res) {
for (ch = opt_args[OPT_ARG_CALLEE_MACRO]; *ch; ch++) { replace_macro_delimiter(opt_args[OPT_ARG_CALLEE_MACRO]);
if (*ch == '^')
*ch = '|';
}
res = pbx_exec(peer, app, opt_args[OPT_ARG_CALLEE_MACRO]); res = pbx_exec(peer, app, opt_args[OPT_ARG_CALLEE_MACRO]);
ast_log(LOG_DEBUG, "Macro exited with status %d\n", res); ast_log(LOG_DEBUG, "Macro exited with status %d\n", res);
res = 0; res = 0;
@ -1502,11 +1474,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
res = -1; res = -1;
/* perform a transfer to a new extension */ /* perform a transfer to a new extension */
if (strchr(macro_transfer_dest, '^')) { /* context^exten^priority*/ if (strchr(macro_transfer_dest, '^')) { /* context^exten^priority*/
/* no brainer mode... substitute ^ with | and feed it to builtin goto */ replace_macro_delimiter(macro_transfer_dest);
for (res = 0; res < strlen(macro_transfer_dest); res++)
if (macro_transfer_dest[res] == '^')
macro_transfer_dest[res] = '|';
if (!ast_parseable_goto(chan, macro_transfer_dest)) if (!ast_parseable_goto(chan, macro_transfer_dest))
ast_set_flag(peerflags, OPT_GO_ON); ast_set_flag(peerflags, OPT_GO_ON);
@ -1610,9 +1578,9 @@ out:
if ((ast_test_flag(peerflags, OPT_GO_ON)) && (!chan->_softhangup) && (res != AST_PBX_KEEPALIVE)) if ((ast_test_flag(peerflags, OPT_GO_ON)) && (!chan->_softhangup) && (res != AST_PBX_KEEPALIVE))
res = 0; res = 0;
done:
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);
return res; return res;
} }
@ -1627,7 +1595,7 @@ static int retrydial_exec(struct ast_channel *chan, void *data)
{ {
char *announce = NULL, *dialdata = NULL; char *announce = NULL, *dialdata = NULL;
const char *context = NULL; const char *context = NULL;
int sleep = 0, loops = 0, res = 0; int sleep = 0, loops = 0, res = -1;
struct localuser *u; struct localuser *u;
struct ast_flags peerflags; struct ast_flags peerflags;
@ -1638,51 +1606,44 @@ static int retrydial_exec(struct ast_channel *chan, void *data)
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
if (!(announce = ast_strdupa(data))) { if (!(announce = ast_strdupa(data)))
LOCAL_USER_REMOVE(u); goto done;
return -1;
}
memset(&peerflags, 0, sizeof(peerflags)); memset(&peerflags, 0, sizeof(peerflags));
if ((dialdata = strchr(announce, '|'))) { if ((dialdata = strchr(announce, '|'))) {
*dialdata = '\0'; *dialdata++ = '\0';
dialdata++;
if ((sleep = atoi(dialdata))) { if ((sleep = atoi(dialdata))) {
sleep *= 1000; sleep *= 1000;
} else { } else {
ast_log(LOG_ERROR, "%s requires the numerical argument <sleep>\n",rapp); ast_log(LOG_ERROR, "%s requires the numerical argument <sleep>\n",rapp);
LOCAL_USER_REMOVE(u); goto done;
return -1;
} }
if ((dialdata = strchr(dialdata, '|'))) { if ((dialdata = strchr(dialdata, '|'))) {
*dialdata = '\0'; *dialdata++ = '\0';
dialdata++;
if (!(loops = atoi(dialdata))) { if (!(loops = atoi(dialdata))) {
ast_log(LOG_ERROR, "%s requires the numerical argument <loops>\n",rapp); ast_log(LOG_ERROR, "%s requires the numerical argument <loops>\n",rapp);
LOCAL_USER_REMOVE(u); goto done;
return -1;
} }
} }
} }
if ((dialdata = strchr(dialdata, '|'))) { if ((dialdata = strchr(dialdata, '|'))) {
*dialdata = '\0'; *dialdata++ = '\0';
dialdata++;
} else { } else {
ast_log(LOG_ERROR, "%s requires more arguments\n",rapp); ast_log(LOG_ERROR, "%s requires more arguments\n",rapp);
LOCAL_USER_REMOVE(u); goto done;
return -1;
} }
if (sleep < 1000) if (sleep < 1000)
sleep = 10000; sleep = 10000;
if (!loops) if (!loops)
loops = -1; loops = -1; /* run forever */
context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT"); context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
res = 0;
while (loops) { while (loops) {
chan->data = "Retrying"; chan->data = "Retrying";
if (ast_test_flag(chan, AST_FLAG_MOH)) if (ast_test_flag(chan, AST_FLAG_MOH))
@ -1719,13 +1680,14 @@ static int retrydial_exec(struct ast_channel *chan, void *data)
} }
loops--; loops--;
} }
if (loops == 0)
res = 0;
if (ast_test_flag(chan, AST_FLAG_MOH)) if (ast_test_flag(chan, AST_FLAG_MOH))
ast_moh_stop(chan); ast_moh_stop(chan);
done:
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);
return loops ? res : 0; return res;
} }
static int unload_module(void *mod) static int unload_module(void *mod)
@ -1744,7 +1706,6 @@ static int load_module(void *mod)
{ {
int res; int res;
__mod_desc = mod;
res = ast_register_application(app, dial_exec, synopsis, descrip); res = ast_register_application(app, dial_exec, synopsis, descrip);
res |= ast_register_application(rapp, retrydial_exec, rsynopsis, rdescrip); res |= ast_register_application(rapp, retrydial_exec, rsynopsis, rdescrip);
@ -1754,7 +1715,6 @@ static int load_module(void *mod)
static const char *description(void) static const char *description(void)
{ {
return "Dialing Application"; return "Dialing Application";
} }
static const char *key(void) static const char *key(void)

Loading…
Cancel
Save