--- app_zapbarge.c.orig 2003-09-13 15:04:49.000000000 -0400 +++ app_zapbarge.c 2003-09-13 15:58:20.000000000 -0400 @@ -7,6 +7,9 @@ * * Mark Spencer * + * Updated to add scanning functionality 9/2003 by + * David Troy + * * This program is free software, distributed under the terms of * the GNU General Public License * @@ -41,10 +44,13 @@ static char *synopsis = "Barge in (monitor) Zap channel"; static char *descrip = -" ZapBarge([channel]): Barges in on a specified zap\n" +" ZapBarge([channel]|[s]): Barges in on a specified zap\n" "channel or prompts if one is not specified. Returns\n" "-1 when caller user hangs up and is independent of the\n" -"state of the channel being monitored."; +"state of the channel being monitored. If the 's' argument\n" +"is provided, then scan through the off-hook Zap\n" +"channels starting with the specified channel, using the\n" +"'#' key to scan through active channels.\n"; STANDARD_LOCAL_USER; @@ -244,15 +250,16 @@ int retrycnt = 0; int confflags = 0; int confno = 0; - char confstr[80]; + char confstr[80], *scan = NULL, *tmp = NULL; + struct ast_channel *tempchan = NULL, *lastchan = NULL; - if (data && strlen(data)) { - if ((sscanf(data, "Zap/%d", &confno) != 1) && - (sscanf(data, "%d", &confno) != 1)) { - ast_log(LOG_WARNING, "ZapBarge Argument (if specified) must be a channel number, not '%s'\n", (char *)data); - return 0; - } + if (data && strlen((char *)data)) { + if (sscanf((char *)data, "Zap/%d", &confno) != 1) + sscanf((char *)data, "%d", &confno); + if (scan = strchr((char *)data,'|')) + scan++; } + LOCAL_USER_ADD(u); if (chan->_state != AST_STATE_UP) ast_answer(chan); @@ -257,6 +264,37 @@ if (chan->_state != AST_STATE_UP) ast_answer(chan); + /* If we got handed a channel number, let's monitor it */ + if (confno) { + ast_stopstream(chan); + ast_say_number(chan, confno, AST_DIGIT_ANY, chan->language); + res = conf_run(chan, confno, confflags); + if (res<0) goto out; + } + + /* If we are scanning, let's scan */ + if (scan && *scan == 's') { + for (;;) { + tempchan = ast_channel_walk(tempchan); + /* Quit if there are no channels in use */ + if ( !tempchan && !lastchan ) + break; + if ( tempchan && (!strcmp(tempchan->type, "Zap")) && (tempchan != chan) ) { + ast_verbose(VERBOSE_PREFIX_3 "Zap channel %s is in-use, monitoring...\n", tempchan->name); + strcpy(confstr, tempchan->name); + if (tmp = strchr(confstr,'-')) + *tmp = '\0'; + confno = atoi(strchr(confstr,'/') + 1); + ast_stopstream(chan); + ast_say_number(chan, confno, AST_DIGIT_ANY, chan->language); + res = conf_run(chan, confno, confflags); + if (res<0) goto out; + } + lastchan = tempchan; + } + } + + /* Otherwise prompt for a channel to monitor */ while(!confno && (++retrycnt < 4)) { /* Prompt user for conference number */ strcpy(confstr, ""); @@ -265,13 +303,10 @@ if (sscanf(confstr, "%d", &confno) != 1) confno = 0; } - if (confno) { - /* XXX Should prompt user for pin if pin is required XXX */ - /* Run the conference */ + if (confno) res = conf_run(chan, confno, confflags); - } + out: - /* Do the conference */ LOCAL_USER_REMOVE(u); return res; }