--- apps/app_chanisavail.c 2006-08-20 23:11:39.000000000 -0300 +++ apps/app_chanisavail.c 2008-03-24 10:42:59.000000000 -0300 @@ -60,16 +60,18 @@ " ${AVAILORIGCHAN} - the canonical channel name that was used to create the channel\n" " ${AVAILSTATUS} - the status code for the available channel\n" " Options:\n" +" a - Check for all available channels, not only the first one.\n" " s - Consider the channel unavailable if the channel is in use at all\n" " j - Support jumping to priority n+101 if no channel is available\n"; static int chanavail_exec(struct ast_channel *chan, void *data) { - int res=-1, inuse=-1, option_state=0, priority_jump=0; + int inuse=-1, option_state=0, priority_jump=0, option_all_avail=0; int status; struct ast_module_user *u; char *info, tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur; + char tmp_availchan[1024] = "", tmp_availorig[1024] = "", tmp_availstat[1024] = ""; struct ast_channel *tempchan; AST_DECLARE_APP_ARGS(args, AST_APP_ARG(reqchans); @@ -88,6 +90,8 @@ AST_STANDARD_APP_ARGS(args, info); if (args.options) { + if (strchr(args.options, 'a')) + option_all_avail = 1; if (strchr(args.options, 's')) option_state = 1; if (strchr(args.options, 'j')) @@ -122,31 +126,47 @@ status = inuse = ast_device_state(trychan); } if ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) { - pbx_builtin_setvar_helper(chan, "AVAILCHAN", tempchan->name); - /* Store the originally used channel too */ + + if (strlen(tmp_availchan) > 0) + strcat(tmp_availchan, "&"); + strcat(tmp_availchan, tempchan->name); + + if (strlen(tmp_availorig) > 0) + strcat(tmp_availorig, "&"); + snprintf(tmp, sizeof(tmp), "%s/%s", tech, number); - pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", tmp); + strcat(tmp_availorig, tmp); + + if (strlen(tmp_availstat) > 0) + strcat(tmp_availstat, "&"); snprintf(tmp, sizeof(tmp), "%d", status); - pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp); + strcat(tmp_availstat, tmp); + ast_hangup(tempchan); tempchan = NULL; - res = 1; - break; + + if (!option_all_avail) + break; + } else { + if (strlen(tmp_availstat) > 0) + strcat(tmp_availstat, "&"); snprintf(tmp, sizeof(tmp), "%d", status); - pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp); + strcat(tmp_availstat, tmp); } cur = rest; } while (cur); } - if (res < 1) { - pbx_builtin_setvar_helper(chan, "AVAILCHAN", ""); - pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", ""); - if (priority_jump || ast_opt_priority_jumping) { - if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) { - ast_module_user_remove(u); - return -1; - } + + pbx_builtin_setvar_helper(chan, "AVAILCHAN", tmp_availchan); + /* Store the originally used channel too */ + pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", tmp_availorig); + pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp_availstat); + + if (priority_jump || ast_opt_priority_jumping) { + if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) { + ast_module_user_remove(u); + return -1; } }