Index: app_chanisavail.c =================================================================== --- app_chanisavail.c (revisão 109355) +++ app_chanisavail.c (cópia de trabalho) @@ -50,6 +50,7 @@ "This application will check to see if any of the specified channels are\n" "available.\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" " t - Simply checks if specified channels exist in the channel list\n" " (implies option s).\n" @@ -61,9 +62,10 @@ static int chanavail_exec(struct ast_channel *chan, void *data) { - int res=-1, inuse=-1, option_state=0, string_compare=0; + int inuse=-1, option_state=0, string_compare=0, option_all_avail=0; int status; char *info, tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur; + char tmp_availchan[2048] = "", tmp_availorig[2048] = "", tmp_availstat[2048] = ""; struct ast_channel *tempchan; AST_DECLARE_APP_ARGS(args, AST_APP_ARG(reqchans); @@ -80,6 +82,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, 't')) @@ -118,29 +122,44 @@ snprintf(trychan, sizeof(trychan), "%s/%s",cur,number); 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 ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) + { + if (strlen(tmp_availchan) > 0) + strcat(tmp_availchan, "&"); + strcat(tmp_availchan, tempchan->name); + snprintf(tmp, sizeof(tmp), "%s/%s", tech, number); - pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", tmp); + if (strlen(tmp_availorig) > 0) + strcat(tmp_availorig, "&"); + strcat(tmp_availorig, tmp); + snprintf(tmp, sizeof(tmp), "%d", status); - pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp); + if (strlen(tmp_availstat) > 0) + strcat(tmp_availstat, "&"); + strcat(tmp_availstat, tmp); + ast_hangup(tempchan); tempchan = NULL; - res = 1; - break; + + if (!option_all_avail) + break; + } else { snprintf(tmp, sizeof(tmp), "%d", status); - pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp); + if (strlen(tmp_availstat) > 0) + strcat(tmp_availstat, "&"); + strcat(tmp_availstat, tmp); + } cur = rest; } while (cur); } - if (res < 1) { - pbx_builtin_setvar_helper(chan, "AVAILCHAN", ""); - pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", ""); - } + 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); + return 0; }