2 * Asterisk -- A telephony toolkit for Linux.
4 * True call queues with optional send URL on answer
6 * Copyright (C) 1999, Mark Spencer
8 * Mark Spencer <markster@linux-support.net>
10 * These features added by David C. Troy <dave@toad.net>:
11 * - Per-queue holdtime calculation
12 * - Estimated holdtime announcement
13 * - Position announcement
14 * - Abandoned/completed call counters
15 * - Failout timer passed as optional app parameter
16 * - Optional monitoring of calls, started when call is answered
18 * Patch Version 1.07 2003-12-24 01
20 * Added servicelevel statistic by Michiel Betel <michiel@betel.nl>
22 * Fixed ot work with CVS as of 2004-02-25 and released as 1.07a
23 * by Matthew Enger <m.enger@xi.com.au>
25 * This program is free software, distributed under the terms of
26 * the GNU General Public License
29 #include <asterisk/lock.h>
30 #include <asterisk/file.h>
31 #include <asterisk/logger.h>
32 #include <asterisk/channel.h>
33 #include <asterisk/pbx.h>
34 #include <asterisk/options.h>
35 #include <asterisk/module.h>
36 #include <asterisk/translate.h>
37 #include <asterisk/say.h>
38 #include <asterisk/parking.h>
39 #include <asterisk/musiconhold.h>
40 #include <asterisk/cli.h>
41 #include <asterisk/manager.h> /* JDG */
42 #include <asterisk/config.h>
43 #include <asterisk/monitor.h>
51 #include <sys/signal.h>
52 #include <netinet/in.h>
54 #include "../astconf.h"
58 #define QUEUE_STRATEGY_RINGALL 0
59 #define QUEUE_STRATEGY_ROUNDROBIN 1
60 #define QUEUE_STRATEGY_LEASTRECENT 2
61 #define QUEUE_STRATEGY_FEWESTCALLS 3
62 #define QUEUE_STRATEGY_RANDOM 4
64 static struct strategy {
68 { QUEUE_STRATEGY_RINGALL, "ringall" },
69 { QUEUE_STRATEGY_ROUNDROBIN, "roundrobin" },
70 { QUEUE_STRATEGY_LEASTRECENT, "leastrecent" },
71 { QUEUE_STRATEGY_FEWESTCALLS, "fewestcalls" },
72 { QUEUE_STRATEGY_RANDOM, "random" },
75 #define DEFAULT_RETRY 5
76 #define DEFAULT_TIMEOUT 15
77 #define RECHECK 1 /* Recheck every second to see we we're at the top yet */
79 static char *tdesc = "True Call Queueing";
81 static char *app = "Queue";
83 static char *synopsis = "Queue a call for a call queue";
85 static char *descrip =
86 " Queue(queuename[|options[|URL][|announceoverride][|timeout]]):\n"
87 "Queues an incoming call in a particular call queue as defined in queues.conf.\n"
88 " This application returns -1 if the originating channel hangs up, or if the\n"
89 "call is bridged and either of the parties in the bridge terminate the call.\n"
90 "Returns 0 if the queue is full, nonexistant, or has no members.\n"
91 "The option string may contain zero or more of the following characters:\n"
92 " 't' -- allow the called user transfer the calling user\n"
93 " 'T' -- to allow the calling user to transfer the call.\n"
94 " 'd' -- data-quality (modem) call (minimum delay).\n"
95 " 'H' -- allow caller to hang up by hitting *.\n"
96 " 'n' -- no retries on the timeout; will exit this application and go to the next step.\n"
97 " In addition to transferring the call, a call may be parked and then picked\n"
98 "up by another user.\n"
99 " The optional URL will be sent to the called party if the channel supports\n"
101 " The timeout will cause the queue to fail out after a specified number of\n"
102 "seconds, checked between each queues.conf 'timeout' and 'retry' cycle.\n";
105 static char *app_aqm = "AddQueueMember" ;
106 static char *app_aqm_synopsis = "Dynamically adds queue members" ;
107 static char *app_aqm_descrip =
108 " AddQueueMember(queuename[|interface]):\n"
109 "Dynamically adds interface to an existing queue\n"
110 "Returns -1 if there is an error.\n"
111 "Example: AddQueueMember(techsupport|SIP/3000)\n"
114 static char *app_rqm = "RemoveQueueMember" ;
115 static char *app_rqm_synopsis = "Dynamically removes queue members" ;
116 static char *app_rqm_descrip =
117 " RemoveQueueMember(queuename[|interface]):\n"
118 "Dynamically removes interface to an existing queue\n"
119 "Returns -1 if there is an error.\n"
120 "Example: RemoveQueueMember(techsupport|SIP/3000)\n"
123 /* We define a customer "local user" structure because we
124 use it not only for keeping track of what is in use but
125 also for keeping track of who we're dialing. */
128 struct ast_channel *chan;
133 int allowredirect_in;
134 int allowredirect_out;
139 struct member *member;
140 struct localuser *next;
146 struct ast_call_queue *parent; /* What queue is our parent */
147 char moh[80]; /* Name of musiconhold to be used */
148 char announce[80]; /* Announcement to play for member when call is answered */
149 char context[80]; /* Context when user exits queue */
150 int pos; /* Where we are in the queue */
151 int last_pos_said; /* Last position we told the user */
152 time_t last_pos; /* Last time we told the user their position */
153 int opos; /* Where we started in the queue */
154 int handled; /* Whether our call was handled */
155 time_t start; /* When we started holding */
156 int queuetimeout; /* How many seconds before timing out of queue */
157 struct ast_channel *chan; /* Our channel */
158 struct queue_ent *next; /* The next queue entry */
162 char tech[80]; /* Technology */
163 char loc[256]; /* Location */
164 int penalty; /* Are we a last resort? */
166 int dynamic; /* Are we dynamically added? */
167 time_t lastcall; /* When last successful call was hungup */
168 struct member *next; /* Next member */
171 struct ast_call_queue {
173 char name[80]; /* Name of the queue */
174 char moh[80]; /* Name of musiconhold to be used */
175 char announce[80]; /* Announcement to play when call is answered */
176 char context[80]; /* Context for this queue */
177 int strategy; /* Queueing strategy */
178 int announcefrequency; /* How often to announce their position */
179 int announceholdtime; /* When to announce holdtime: 0 = never, -1 = every announcement, 1 = only once */
180 int holdtime; /* Current avg holdtime for this queue, based on recursive boxcar filter */
181 int callscompleted; /* Number of queue calls completed */
182 int callsabandoned; /* Number of queue calls abandoned */
183 int servicelevel; /* seconds setting for servicelevel*/
184 int callscompletedinsl; /* Number of queue calls answererd with servicelevel*/
185 char monfmt[8]; /* Format to use when recording calls */
186 char sound_next[80]; /* Sound file: "Your call is now first in line" (def. queue-youarenext) */
187 char sound_thereare[80]; /* Sound file: "There are currently" (def. queue-thereare) */
188 char sound_calls[80]; /* Sound file: "calls waiting to speak to a representative." (def. queue-callswaiting)*/
189 char sound_holdtime[80]; /* Sound file: "The current estimated total holdtime is" (def. queue-holdtime) */
190 char sound_minutes[80]; /* Sound file: "minutes." (def. queue-minutes) */
191 char sound_thanks[80]; /* Sound file: "Thank you for your patience." (def. queue-thankyou) */
193 int count; /* How many entries are in the queue */
194 int maxlen; /* Max number of entries in queue */
196 int dead; /* Whether this queue is dead or not */
197 int retry; /* Retry calling everyone after this amount of time */
198 int timeout; /* How long to wait for an answer */
200 /* Queue strategy things */
202 int rrpos; /* Round Robin - position */
203 int wrapped; /* Round Robin - wrapped around? */
205 struct member *members; /* Member channels to be tried */
206 struct queue_ent *head; /* Start of the actual queue */
207 struct ast_call_queue *next; /* Next call queue */
210 static struct ast_call_queue *queues = NULL;
211 static ast_mutex_t qlock = AST_MUTEX_INITIALIZER;
213 static char *int2strat(int strategy)
216 for (x=0;x<sizeof(strategies) / sizeof(strategies[0]);x++) {
217 if (strategy == strategies[x].strategy)
218 return strategies[x].name;
223 static int strat2int(char *strategy)
226 for (x=0;x<sizeof(strategies) / sizeof(strategies[0]);x++) {
227 if (!strcasecmp(strategy, strategies[x].name))
228 return strategies[x].strategy;
233 static int join_queue(char *queuename, struct queue_ent *qe)
235 struct ast_call_queue *q;
236 struct queue_ent *cur, *prev = NULL;
239 ast_mutex_lock(&qlock);
242 if (!strcasecmp(q->name, queuename)) {
243 /* This is our one */
244 ast_mutex_lock(&q->lock);
245 if (q->members && (!q->maxlen || (q->count < q->maxlen))) {
246 /* There's space for us, put us at the end */
258 /* Fix additional pointers and
264 strncpy(qe->moh, q->moh, sizeof(qe->moh));
265 strncpy(qe->announce, q->announce, sizeof(qe->announce));
266 strncpy(qe->context, q->context, sizeof(qe->context));
269 manager_event(EVENT_FLAG_CALL, "Join",
270 "Channel: %s\r\nCallerID: %s\r\nQueue: %s\r\nPosition: %d\r\nCount: %d\r\n",
271 qe->chan->name, (qe->chan->callerid ? qe->chan->callerid : "unknown"), q->name, qe->pos, q->count );
273 ast_log(LOG_NOTICE, "Queue '%s' Join, Channel '%s', Position '%d'\n", q->name, qe->chan->name, qe->pos );
276 ast_mutex_unlock(&q->lock);
281 ast_mutex_unlock(&qlock);
285 static void free_members(struct ast_call_queue *q, int all)
287 /* Free non-dynamic members */
288 struct member *curm, *next, *prev;
293 if (all || !curm->dynamic) {
305 static void destroy_queue(struct ast_call_queue *q)
307 struct ast_call_queue *cur, *prev = NULL;
308 ast_mutex_lock(&qlock);
313 prev->next = cur->next;
321 ast_mutex_unlock(&qlock);
326 static int play_file(struct ast_channel *chan, char *filename)
330 ast_stopstream(chan);
331 res = ast_streamfile(chan, filename, chan->language);
334 res = ast_waitstream(chan, "");
339 ast_log(LOG_WARNING, "ast_streamfile failed on %s \n", chan->name);
342 ast_stopstream(chan);
347 static int say_position(struct queue_ent *qe)
349 int res = 0, avgholdmins;
352 /* Check to see if this is ludicrous -- if we just announced position, don't do it again*/
354 if ( (now - qe->last_pos) < 15 )
357 /* If either our position has changed, or we are over the freq timer, say position */
358 if ( (qe->last_pos_said == qe->pos) && ((now - qe->last_pos) < qe->parent->announcefrequency) )
361 ast_moh_stop(qe->chan);
362 /* Say we're next, if we are */
364 res += play_file(qe->chan, qe->parent->sound_next);
367 res += play_file(qe->chan, qe->parent->sound_thereare);
368 res += ast_say_number(qe->chan, qe->pos, AST_DIGIT_ANY, qe->chan->language);
369 res += play_file(qe->chan, qe->parent->sound_calls);
372 /* Round hold time to nearest minute */
373 avgholdmins = ( (qe->parent->holdtime + 30) - (now - qe->start) ) / 60;
374 ast_verbose(VERBOSE_PREFIX_3 "Hold time for %s is %d minutes\n", qe->parent->name, avgholdmins);
376 /* If the hold time is >1 min, if it's enabled, and if it's not
377 supposed to be only once and we have already said it, say it */
378 if (avgholdmins > 1 && (qe->parent->announceholdtime) && (!(qe->parent->announceholdtime==1 && qe->last_pos)) ) {
379 res += play_file(qe->chan, qe->parent->sound_holdtime);
380 res += ast_say_number(qe->chan, avgholdmins, AST_DIGIT_ANY, qe->chan->language);
381 res += play_file(qe->chan, qe->parent->sound_minutes);
385 /* Set our last_pos indicators */
387 qe->last_pos_said = qe->pos;
389 ast_verbose(VERBOSE_PREFIX_3 "Told %s in %s their queue position (which was %d)\n", qe->chan->name, qe->parent->name, qe->pos);
390 res += play_file(qe->chan, qe->parent->sound_thanks);
391 ast_moh_start(qe->chan, qe->moh);
396 static void record_abandoned(struct queue_ent *qe)
398 ast_mutex_lock(&qe->parent->lock);
399 qe->parent->callsabandoned++;
400 ast_mutex_unlock(&qe->parent->lock);
403 static void recalc_holdtime(struct queue_ent *qe)
405 int oldvalue, newvalue;
407 /* Calculate holdtime using a recursive boxcar filter */
408 /* Thanks to SRT for this contribution */
409 /* 2^2 (4) is the filter coefficient; a higher exponent would give old entries more weight */
411 newvalue = time(NULL) - qe->start;
413 ast_mutex_lock(&qe->parent->lock);
414 if (newvalue <= qe->parent->servicelevel)
415 qe->parent->callscompletedinsl++;
416 oldvalue = qe->parent->holdtime;
417 qe->parent->holdtime = (((oldvalue << 2) - oldvalue) + newvalue) >> 2;
418 ast_mutex_unlock(&qe->parent->lock);
422 static void leave_queue(struct queue_ent *qe)
424 struct ast_call_queue *q;
425 struct queue_ent *cur, *prev = NULL;
430 ast_mutex_lock(&q->lock);
438 /* Take us out of the queue */
439 manager_event(EVENT_FLAG_CALL, "Leave",
440 "Channel: %s\r\nQueue: %s\r\nCount: %d\r\n",
441 qe->chan->name, q->name, q->count);
443 ast_log(LOG_NOTICE, "Queue '%s' Leave, Channel '%s'\n", q->name, qe->chan->name );
445 /* Take us out of the queue */
447 prev->next = cur->next;
451 /* Renumber the people after us in the queue based on a new count */
457 ast_mutex_unlock(&q->lock);
458 if (q->dead && !q->count) {
459 /* It's dead and nobody is in it, so kill it */
464 static void hanguptree(struct localuser *outgoing, struct ast_channel *exception)
466 /* Hang up a tree of stuff */
467 struct localuser *oo;
469 /* Hangup any existing lines we have open */
470 if (outgoing->chan && (outgoing->chan != exception))
471 ast_hangup(outgoing->chan);
473 outgoing=outgoing->next;
478 static int ring_entry(struct queue_ent *qe, struct localuser *tmp)
481 /* Request the peer */
482 tmp->chan = ast_request(tmp->tech, qe->chan->nativeformats, tmp->numsubst);
483 if (!tmp->chan) { /* If we can't, just go on to the next call */
485 ast_log(LOG_NOTICE, "Unable to create channel of type '%s'\n", cur->tech);
488 ast_cdr_busy(qe->chan->cdr);
492 tmp->chan->appl = "AppQueue";
493 tmp->chan->data = "(Outgoing Line)";
494 tmp->chan->whentohangup = 0;
495 if (tmp->chan->callerid)
496 free(tmp->chan->callerid);
498 free(tmp->chan->ani);
499 if (qe->chan->callerid)
500 tmp->chan->callerid = strdup(qe->chan->callerid);
502 tmp->chan->callerid = NULL;
504 tmp->chan->ani = strdup(qe->chan->ani);
506 tmp->chan->ani = NULL;
507 /* Presense of ADSI CPE on outgoing channel follows ours */
508 tmp->chan->adsicpe = qe->chan->adsicpe;
509 /* Place the call, but don't wait on the answer */
510 res = ast_call(tmp->chan, tmp->numsubst, 0);
512 /* Again, keep going even if there's an error */
514 ast_log(LOG_DEBUG, "ast call on peer returned %d\n", res);
515 else if (option_verbose > 2)
516 ast_verbose(VERBOSE_PREFIX_3 "Couldn't call %s\n", tmp->numsubst);
517 ast_hangup(tmp->chan);
522 if (option_verbose > 2)
523 ast_verbose(VERBOSE_PREFIX_3 "Called %s\n", tmp->numsubst);
527 static int ring_one(struct queue_ent *qe, struct localuser *outgoing)
529 struct localuser *cur;
530 struct localuser *best;
536 if (cur->stillgoing && /* Not already done */
537 !cur->chan && /* Isn't already going */
538 (!best || (cur->metric < bestmetric))) { /* We haven't found one yet, or it's better */
539 bestmetric = cur->metric;
545 if (!qe->parent->strategy) {
546 /* Ring everyone who shares this best metric (for ringall) */
549 if (cur->stillgoing && !cur->chan && (cur->metric == bestmetric)) {
550 ast_log(LOG_DEBUG, "(Parallel) Trying '%s/%s' with metric %d\n", cur->tech, cur->numsubst, cur->metric);
556 /* Ring just the best channel */
557 ast_log(LOG_DEBUG, "Trying '%s/%s' with metric %d\n", best->tech, best->numsubst, best->metric);
558 ring_entry(qe, best);
561 } while (best && !best->chan);
563 ast_log(LOG_DEBUG, "Nobody left to try ringing in queue\n");
569 static int valid_exit(struct queue_ent *qe, char digit)
572 if (!strlen(qe->context))
576 if (ast_exists_extension(qe->chan, qe->context, tmp, 1, qe->chan->callerid)) {
577 strncpy(qe->chan->context, qe->context, sizeof(qe->chan->context) - 1);
578 strncpy(qe->chan->exten, tmp, sizeof(qe->chan->exten) - 1);
579 qe->chan->priority = 0;
587 static struct localuser *wait_for_answer(struct queue_ent *qe, struct localuser *outgoing, int *to, int *allowredir_in, int *allowredir_out, int *allowdisconnect, char *digit)
589 char *queue = qe->parent->name;
597 struct localuser *peer = NULL;
598 struct ast_channel *watchers[MAX];
600 struct ast_channel *winner;
601 struct ast_channel *in = qe->chan;
603 while(*to && !peer) {
610 /* Keep track of important channels */
611 if (o->stillgoing && o->chan) {
612 watchers[pos++] = o->chan;
619 if (numlines == numbusies) {
620 ast_log(LOG_DEBUG, "Everyone is busy at this time\n");
622 ast_log(LOG_NOTICE, "No one is answering queue '%s'\n", queue);
627 winner = ast_waitfor_n(watchers, pos, to);
630 if (o->stillgoing && (o->chan) && (o->chan->_state == AST_STATE_UP)) {
632 if (option_verbose > 2)
633 ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", o->chan->name, in->name);
635 *allowredir_in = o->allowredirect_in;
636 *allowredir_out = o->allowredirect_out;
637 *allowdisconnect = o->allowdisconnect;
639 } else if (o->chan && (o->chan == winner)) {
640 f = ast_read(winner);
642 if (f->frametype == AST_FRAME_CONTROL) {
643 switch(f->subclass) {
644 case AST_CONTROL_ANSWER:
645 /* This is our guy if someone answered. */
647 if (option_verbose > 2)
648 ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", o->chan->name, in->name);
650 *allowredir_in = o->allowredirect_in;
651 *allowredir_out = o->allowredirect_out;
652 *allowdisconnect = o->allowdisconnect;
655 case AST_CONTROL_BUSY:
656 if (option_verbose > 2)
657 ast_verbose( VERBOSE_PREFIX_3 "%s is busy\n", o->chan->name);
660 ast_cdr_busy(in->cdr);
663 if (qe->parent->strategy)
664 ring_one(qe, outgoing);
667 case AST_CONTROL_CONGESTION:
668 if (option_verbose > 2)
669 ast_verbose( VERBOSE_PREFIX_3 "%s is circuit-busy\n", o->chan->name);
672 ast_cdr_busy(in->cdr);
675 if (qe->parent->strategy)
676 ring_one(qe, outgoing);
679 case AST_CONTROL_RINGING:
680 if (option_verbose > 2)
681 ast_verbose( VERBOSE_PREFIX_3 "%s is ringing\n", o->chan->name);
684 ast_indicate(in, AST_CONTROL_RINGING);
689 case AST_CONTROL_OFFHOOK:
690 /* Ignore going off hook */
693 ast_log(LOG_DEBUG, "Dunno what to do with control type %d\n", f->subclass);
701 if (qe->parent->strategy)
702 ring_one(qe, outgoing);
710 if (f && (f->frametype != AST_FRAME_VOICE))
711 printf("Frame type: %d, %d\n", f->frametype, f->subclass);
712 else if (!f || (f->frametype != AST_FRAME_VOICE))
713 printf("Hangup received on %s\n", in->name);
715 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP))) {
720 if (f && (f->frametype == AST_FRAME_DTMF) && allowdisconnect && (f->subclass == '*')) {
721 if (option_verbose > 3)
722 ast_verbose(VERBOSE_PREFIX_3 "User hit %c to disconnect call.\n", f->subclass);
726 if (f && (f->frametype == AST_FRAME_DTMF) && (f->subclass != '*') && valid_exit(qe, f->subclass)) {
727 if (option_verbose > 3)
728 ast_verbose(VERBOSE_PREFIX_3 "User pressed digit: %c", f->subclass);
734 if (!*to && (option_verbose > 2))
735 ast_verbose( VERBOSE_PREFIX_3 "Nobody picked up in %d ms\n", orig);
742 static int wait_our_turn(struct queue_ent *qe)
744 struct queue_ent *ch;
748 /* This is the holding pen for callers 2 through maxlen */
750 /* Atomically read the parent head -- does not need a lock */
751 ch = qe->parent->head;
753 /* If we are now at the top of the head, break out */
757 /* If we have timed out, break out */
758 if ( qe->queuetimeout ) {
760 if ( (now - qe->start) >= qe->queuetimeout )
764 /* Make a position announcement, if enabled */
765 if (qe->parent->announcefrequency)
769 /* Wait a second before checking again */
770 res = ast_waitfordigit(qe->chan, RECHECK * 1000);
777 static int update_queue(struct ast_call_queue *q, struct localuser *user)
780 /* Since a reload could have taken place, we have to traverse the list to
781 be sure it's still valid */
782 ast_mutex_lock(&q->lock);
785 if (user->member == cur) {
786 time(&cur->lastcall);
793 ast_mutex_unlock(&q->lock);
797 static int calc_metric(struct ast_call_queue *q, struct member *mem, int pos, struct queue_ent *qe, struct localuser *tmp)
799 switch (q->strategy) {
800 case QUEUE_STRATEGY_RINGALL:
801 /* Everyone equal, except for penalty */
802 tmp->metric = mem->penalty * 1000000;
804 case QUEUE_STRATEGY_ROUNDROBIN:
807 /* No more channels, start over */
810 /* Prioritize next entry */
815 if (pos < q->rrpos) {
816 tmp->metric = 1000 + pos;
818 if (pos > q->rrpos) {
819 /* Indicate there is another priority */
824 tmp->metric += mem->penalty * 1000000;
826 case QUEUE_STRATEGY_RANDOM:
827 tmp->metric = rand() % 1000;
828 tmp->metric += mem->penalty * 1000000;
830 case QUEUE_STRATEGY_FEWESTCALLS:
831 tmp->metric = mem->calls;
832 tmp->metric += mem->penalty * 1000000;
834 case QUEUE_STRATEGY_LEASTRECENT:
838 tmp->metric = 1000000 - (time(NULL) - mem->lastcall);
839 tmp->metric += mem->penalty * 1000000;
842 ast_log(LOG_WARNING, "Can't calculate metric for unknown strategy %d\n", q->strategy);
848 static int try_calling(struct queue_ent *qe, char *options, char *announceoverride, char *url, int *go_on)
851 struct localuser *outgoing=NULL, *tmp = NULL;
854 int allowredir_out=0;
855 int allowdisconnect=0;
856 char restofit[AST_MAX_EXTENSION];
857 char oldexten[AST_MAX_EXTENSION]="";
858 char oldcontext[AST_MAX_EXTENSION]="";
859 char queuename[256]="";
861 struct ast_channel *peer;
862 struct localuser *lpeer;
863 int res = 0, bridge = 0;
866 char *announce = NULL;
869 /* Hold the lock while we setup the outgoing calls */
870 ast_mutex_lock(&qe->parent->lock);
871 strncpy(queuename, qe->parent->name, sizeof(queuename) - 1);
872 cur = qe->parent->members;
873 if (strlen(qe->announce))
874 announce = qe->announce;
875 if (announceoverride && strlen(announceoverride))
876 announce = announceoverride;
878 /* Get a technology/[device:]number pair */
879 tmp = malloc(sizeof(struct localuser));
881 ast_mutex_unlock(&qe->parent->lock);
882 ast_log(LOG_WARNING, "Out of memory\n");
885 memset(tmp, 0, sizeof(struct localuser));
886 tmp->stillgoing = -1;
888 if (strchr(options, 't'))
889 tmp->allowredirect_in = 1;
890 if (strchr(options, 'T'))
891 tmp->allowredirect_out = 1;
892 if (strchr(options, 'r'))
893 tmp->ringbackonly = 1;
894 if (strchr(options, 'm'))
895 tmp->musiconhold = 1;
896 if (strchr(options, 'd'))
897 tmp->dataquality = 1;
898 if (strchr(options, 'H'))
899 tmp->allowdisconnect = 1;
900 if (strchr(options, 'n'))
904 ast_log(LOG_DEBUG, "Queue with URL=%s_\n", url);
906 ast_log(LOG_DEBUG, "Simple queue (no URL)\n");
908 tmp->member = cur; /* Never directly dereference! Could change on reload */
909 strncpy(tmp->tech, cur->tech, sizeof(tmp->tech)-1);
910 strncpy(tmp->numsubst, cur->loc, sizeof(tmp->numsubst)-1);
911 /* If we're dialing by extension, look at the extension to know what to dial */
912 if ((newnum = strstr(tmp->numsubst, "BYEXTENSION"))) {
913 strncpy(restofit, newnum + strlen("BYEXTENSION"), sizeof(restofit)-1);
914 snprintf(newnum, sizeof(tmp->numsubst) - (newnum - tmp->numsubst), "%s%s", qe->chan->exten,restofit);
916 ast_log(LOG_DEBUG, "Dialing by extension %s\n", tmp->numsubst);
918 /* Special case: If we ring everyone, go ahead and ring them, otherwise
919 just calculate their metric for the appropriate strategy */
920 calc_metric(qe->parent, cur, x++, qe, tmp);
921 /* Put them in the list of outgoing thingies... We're ready now.
922 XXX If we're forcibly removed, these outgoing calls won't get
924 tmp->next = outgoing;
926 /* If this line is up, don't try anybody else */
927 if (outgoing->chan && (outgoing->chan->_state == AST_STATE_UP))
932 if (qe->parent->timeout)
933 to = qe->parent->timeout * 1000;
936 ring_one(qe, outgoing);
937 ast_mutex_unlock(&qe->parent->lock);
938 lpeer = wait_for_answer(qe, outgoing, &to, &allowredir_in, &allowredir_out, &allowdisconnect, &digit);
945 /* Musta gotten hung up */
946 record_abandoned(qe);
949 if (digit && valid_exit(qe, digit))
952 /* Nobody answered, next please? */
958 /* Ah ha! Someone answered within the desired timeframe. Of course after this
959 we will always return with -1 so that it is hung up properly after the
962 if (!strcmp(qe->chan->type,"Zap")) {
963 if (tmp->dataquality) zapx = 0;
964 ast_channel_setoption(qe->chan,AST_OPTION_TONE_VERIFY,&zapx,sizeof(char),0);
966 if (!strcmp(peer->type,"Zap")) {
967 if (tmp->dataquality) zapx = 0;
968 ast_channel_setoption(peer,AST_OPTION_TONE_VERIFY,&zapx,sizeof(char),0);
970 /* Update parameters for the queue */
972 update_queue(qe->parent, lpeer);
973 hanguptree(outgoing, peer);
974 /* Stop music on hold */
975 ast_moh_stop(qe->chan);
979 res2 = ast_autoservice_start(qe->chan);
981 res2 = ast_streamfile(peer, announce, peer->language);
983 res2 = ast_waitstream(peer, "");
984 res2 |= ast_autoservice_stop(qe->chan);
986 /* Agent must have hung up */
987 ast_log(LOG_WARNING, "Agent on %s hungup on the customer. They're going to be pissed.\n", peer->name);
988 ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "AGENTDUMP", "%s", "");
993 /* If appropriate, log that we have a destination channel */
995 ast_cdr_setdestchan(qe->chan->cdr, peer->name);
996 /* Make sure channels are compatible */
997 res = ast_channel_make_compatible(qe->chan, peer);
999 ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "SYSCOMPAT", "%s", "");
1000 ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", qe->chan->name, peer->name);
1004 /* Begin Monitoring */
1005 if (qe->parent->monfmt && *qe->parent->monfmt) {
1006 ast_monitor_start( peer, qe->parent->monfmt, qe->chan->cdr->uniqueid, 1 );
1008 /* Drop out of the queue at this point, to prepare for next caller */
1011 if( url && strlen(url) && ast_channel_supports_html(peer) ) {
1012 ast_log(LOG_DEBUG, "app_queue: sendurl=%s.\n", url);
1013 ast_channel_sendurl( peer, url );
1015 ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "CONNECT", "%ld", (long)time(NULL) - qe->start);
1016 strncpy(oldcontext, qe->chan->context, sizeof(oldcontext) - 1);
1017 strncpy(oldexten, qe->chan->exten, sizeof(oldexten) - 1);
1019 bridge = ast_bridge_call(qe->chan, peer, allowredir_in, allowredir_out, allowdisconnect);
1020 if (strcasecmp(oldcontext, qe->chan->context) || strcasecmp(oldexten, qe->chan->exten)) {
1021 ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "TRANSFER", "%s|%s", qe->chan->exten, qe->chan->context);
1022 } else if (qe->chan->_softhangup) {
1023 ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "COMPLETECALLER", "%ld|%ld", (long)(callstart - qe->start), (long)(time(NULL) - callstart));
1025 ast_queue_log(queuename, qe->chan->uniqueid, peer->name, "COMPLETEAGENT", "%ld|%ld", (long)(callstart - qe->start), (long)(time(NULL) - callstart));
1028 if(bridge != AST_PBX_NO_HANGUP_PEER)
1031 if( bridge == 0 ) res=1; /* JDG: bridge successfull, leave app_queue */
1032 else res = bridge; /* bridge error, stay in the queue */
1035 hanguptree(outgoing, NULL);
1039 static int wait_a_bit(struct queue_ent *qe)
1041 /* Don't need to hold the lock while we setup the outgoing calls */
1042 int retrywait = qe->parent->retry * 1000;
1043 return ast_waitfordigit(qe->chan, retrywait);
1048 static struct member * interface_exists( struct ast_call_queue * q, char * interface )
1050 struct member * ret = NULL ;
1058 while( mem != NULL ) {
1059 sprintf( buf, "%s/%s", mem->tech, mem->loc);
1061 if( strcmp( buf, interface ) == 0 ) {
1074 static struct member * create_queue_node( char * interface )
1076 struct member * cur ;
1079 /* Add a new member */
1081 cur = malloc(sizeof(struct member));
1084 memset(cur, 0, sizeof(struct member));
1085 strncpy(cur->tech, interface, sizeof(cur->tech) - 1);
1086 if ((tmp = strchr(cur->tech, '/')))
1088 if ((tmp = strchr(interface, '/'))) {
1090 strncpy(cur->loc, tmp, sizeof(cur->loc) - 1);
1092 ast_log(LOG_WARNING, "No location at interface '%s'\n", interface);
1099 static int rqm_exec(struct ast_channel *chan, void *data)
1102 struct localuser *u;
1104 struct member * node ;
1105 struct member * look ;
1107 char tmpchan[256]="";
1108 char *interface=NULL;
1109 struct ast_call_queue *q;
1113 ast_log(LOG_WARNING, "RemoveQueueMember requires an argument (queuename|optional interface)\n");
1117 LOCAL_USER_ADD(u); // not sure if we need this, but better be safe than sorry ;-)
1119 /* Parse our arguments XXX Check for failure XXX */
1120 strncpy(info, (char *)data, strlen((char *)data) + AST_MAX_EXTENSION-1);
1123 interface = strchr(queuename, '|');
1129 strncpy(tmpchan, chan->name, sizeof(tmpchan) - 1);
1130 interface = strrchr(tmpchan, '-');
1133 interface = tmpchan;
1137 if( ( q = queues) != NULL )
1139 while( q && ( res != 0 ) && (!found) )
1141 ast_mutex_lock(&q->lock);
1142 if( strcmp( q->name, queuename) == 0 )
1144 // found queue, try to remove interface
1147 if( ( node = interface_exists( q, interface ) ) != NULL )
1149 if( ( look = q->members ) == node )
1152 q->members = node->next;
1156 while( look != NULL )
1157 if( look->next == node )
1159 look->next = node->next ;
1168 ast_log(LOG_NOTICE, "Removed interface '%s' to queue '%s'\n",
1169 interface, queuename);
1173 ast_log(LOG_WARNING, "Unable to remove interface '%s' from queue '%s': "
1174 "Not there\n", interface, queuename);
1177 ast_mutex_unlock(&q->lock);
1183 ast_log(LOG_WARNING, "Unable to remove interface from queue '%s': No such queue\n", queuename);
1185 LOCAL_USER_REMOVE(u);
1191 static int aqm_exec(struct ast_channel *chan, void *data)
1194 struct localuser *u;
1197 char tmpchan[512]="";
1198 char *interface=NULL;
1199 struct ast_call_queue *q;
1200 struct member *save;
1204 ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename|optional interface)\n");
1208 LOCAL_USER_ADD(u); // not sure if we need this, but better be safe than sorry ;-)
1210 /* Parse our arguments XXX Check for failure XXX */
1211 strncpy(info, (char *)data, strlen((char *)data) + AST_MAX_EXTENSION-1);
1214 interface = strchr(queuename, '|');
1220 strncpy(tmpchan, chan->name, sizeof(tmpchan) - 1);
1221 interface = strrchr(tmpchan, '-');
1224 interface = tmpchan;
1228 if( ( q = queues) != NULL )
1230 while( q && ( res != 0 ) && (!found) )
1232 ast_mutex_lock(&q->lock);
1233 if( strcmp( q->name, queuename) == 0 )
1235 // found queue, try to enable interface
1238 if( interface_exists( q, interface ) == NULL )
1241 q->members = create_queue_node( interface ) ;
1243 if( q->members != NULL ) {
1244 q->members->dynamic = 1;
1245 q->members->next = save ;
1249 ast_log(LOG_NOTICE, "Added interface '%s' to queue '%s'\n", interface, queuename);
1253 ast_log(LOG_WARNING, "Unable to add interface '%s' to queue '%s': "
1254 "Already there\n", interface, queuename);
1257 ast_mutex_unlock(&q->lock);
1263 ast_log(LOG_WARNING, "Unable to add interface to queue '%s': No such queue\n", queuename);
1265 LOCAL_USER_REMOVE(u);
1270 static int queue_exec(struct ast_channel *chan, void *data)
1273 struct localuser *u;
1276 char *options = NULL;
1278 char *announceoverride = NULL;
1279 char *queuetimeoutstr = NULL;
1280 /* whether to exit Queue application after the timeout hits */
1285 /* Our queue entry */
1286 struct queue_ent qe;
1289 ast_log(LOG_WARNING, "Queue requires an argument (queuename|optional timeout|optional URL)\n");
1295 /* Setup our queue entry */
1296 memset(&qe, 0, sizeof(qe));
1298 /* Parse our arguments XXX Check for failure XXX */
1299 strncpy(info, (char *)data, strlen((char *)data) + AST_MAX_EXTENSION-1);
1302 options = strchr(queuename, '|');
1306 url = strchr(options, '|');
1310 announceoverride = strchr(url, '|');
1311 if (announceoverride) {
1312 *announceoverride = '\0';
1314 queuetimeoutstr = strchr(announceoverride, '|');
1315 if (queuetimeoutstr) {
1316 *queuetimeoutstr = '\0';
1318 qe.queuetimeout = atoi(queuetimeoutstr);
1320 qe.queuetimeout = 0;
1327 printf("queue: %s, options: %s, url: %s, announce: %s, timeout: %d\n",
1328 queuename, options, url, announceoverride, qe.queuetimeout);
1332 qe.start = time(NULL);
1333 qe.last_pos_said = 0;
1335 if (!join_queue(queuename, &qe)) {
1336 ast_queue_log(queuename, chan->uniqueid, "NONE", "ENTERQUEUE", "%s|%s", url ? url : "", chan->callerid ? chan->callerid : "");
1337 /* Start music on hold */
1338 ast_moh_start(chan, qe.moh);
1340 /* This is the wait loop for callers 2 through maxlen */
1342 res = wait_our_turn(&qe);
1343 /* If they hungup, return immediately */
1345 /* Record this abandoned call */
1346 record_abandoned(&qe);
1347 ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
1348 if (option_verbose > 2) {
1349 ast_verbose(VERBOSE_PREFIX_3 "User disconnected while waiting their turn\n");
1356 if (valid_exit(&qe, res)) {
1357 ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos);
1363 /* This is the wait loop for the head caller*/
1364 /* To exit, they may get their call answered; */
1365 /* they may dial a digit from the queue context; */
1366 /* or, they may may timeout. */
1368 /* Leave if we have exceeded our queuetimeout */
1369 if (qe.queuetimeout && ( (time(NULL) - qe.start) >= qe.queuetimeout) ) {
1374 /* Make a position announcement, if enabled */
1375 if (qe.parent->announcefrequency)
1378 /* Try calling all queue members for 'timeout' seconds */
1379 res = try_calling(&qe, options, announceoverride, url, &go_on);
1383 ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
1385 ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos);
1389 /* Leave if we have exceeded our queuetimeout */
1390 if (qe.queuetimeout && ( (time(NULL) - qe.start) >= qe.queuetimeout) ) {
1395 /* OK, we didn't get anybody; wait for 'retry' seconds; may get a digit to exit with */
1396 res = wait_a_bit(&qe);
1398 ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
1399 if (option_verbose > 2) {
1400 ast_verbose(VERBOSE_PREFIX_3 "User disconnected when they almost made it\n");
1405 if (res && valid_exit(&qe, res)) {
1406 ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos);
1409 /* exit after 'timeout' cycle if 'n' option enabled */
1411 ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
1418 /* Don't allow return code > 0 */
1419 if (res > 0 && res != AST_PBX_KEEPALIVE) {
1422 ast_stopstream(chan);
1426 ast_log(LOG_WARNING, "Unable to join queue '%s'\n", queuename);
1429 LOCAL_USER_REMOVE(u);
1433 static void reload_queues(void)
1435 struct ast_call_queue *q, *ql, *qn;
1436 struct ast_config *cfg;
1438 struct ast_variable *var;
1439 struct member *prev, *cur;
1441 cfg = ast_load("queues.conf");
1443 ast_log(LOG_NOTICE, "No call queueing config file, so no call queues\n");
1446 ast_mutex_lock(&qlock);
1447 /* Mark all queues as dead for the moment */
1453 /* Chug through config file */
1454 cat = ast_category_browse(cfg, NULL);
1456 if (strcasecmp(cat, "general")) {
1457 /* Look for an existing one */
1460 if (!strcmp(q->name, cat))
1466 q = malloc(sizeof(struct ast_call_queue));
1469 memset(q, 0, sizeof(struct ast_call_queue));
1470 ast_mutex_init(&q->lock);
1471 strncpy(q->name, cat, sizeof(q->name));
1478 ast_mutex_lock(&q->lock);
1479 /* Re-initialize the queue */
1484 q->announcefrequency = 0;
1485 q->announceholdtime = 0;
1487 q->callscompleted = 0;
1488 q->callsabandoned = 0;
1489 q->callscompletedinsl = 0;
1490 q->servicelevel = 0;
1493 strcpy(q->announce, "");
1494 strcpy(q->context, "");
1495 strcpy(q->monfmt, "");
1496 strcpy(q->sound_next, "queue-youarenext");
1497 strcpy(q->sound_thereare, "queue-thereare");
1498 strcpy(q->sound_calls, "queue-callswaiting");
1499 strcpy(q->sound_holdtime, "queue-holdtime");
1500 strcpy(q->sound_minutes, "queue-minutes");
1501 strcpy(q->sound_thanks, "queue-thankyou");
1504 /* find the end of any dynamic members */
1508 var = ast_variable_browse(cfg, cat);
1510 if (!strcasecmp(var->name, "member")) {
1511 /* Add a new member */
1512 cur = malloc(sizeof(struct member));
1514 memset(cur, 0, sizeof(struct member));
1515 strncpy(cur->tech, var->value, sizeof(cur->tech) - 1);
1516 if ((tmp = strchr(cur->tech, ','))) {
1519 cur->penalty = atoi(tmp);
1520 if (cur->penalty < 0)
1523 if ((tmp = strchr(cur->tech, '/')))
1525 if ((tmp = strchr(var->value, '/'))) {
1527 strncpy(cur->loc, tmp, sizeof(cur->loc) - 1);
1528 if ((tmp = strchr(cur->loc, ',')))
1531 ast_log(LOG_WARNING, "No location at line %d of queue.conf\n", var->lineno);
1538 } else if (!strcasecmp(var->name, "music")) {
1539 strncpy(q->moh, var->value, sizeof(q->moh) - 1);
1540 } else if (!strcasecmp(var->name, "announce")) {
1541 strncpy(q->announce, var->value, sizeof(q->announce) - 1);
1542 } else if (!strcasecmp(var->name, "context")) {
1543 strncpy(q->context, var->value, sizeof(q->context) - 1);
1544 } else if (!strcasecmp(var->name, "timeout")) {
1545 q->timeout = atoi(var->value);
1546 } else if (!strcasecmp(var->name, "monitor-format")) {
1547 strncpy(q->monfmt, var->value, sizeof(q->monfmt) - 1);
1548 } else if (!strcasecmp(var->name, "queue-youarenext")) {
1549 strncpy(q->sound_next, var->value, sizeof(q->sound_next) - 1);
1550 } else if (!strcasecmp(var->name, "queue-thereare")) {
1551 strncpy(q->sound_thereare, var->value, sizeof(q->sound_thereare) - 1);
1552 } else if (!strcasecmp(var->name, "queue-callswaiting")) {
1553 strncpy(q->sound_calls, var->value, sizeof(q->sound_calls) - 1);
1554 } else if (!strcasecmp(var->name, "queue-holdtime")) {
1555 strncpy(q->sound_holdtime, var->value, sizeof(q->sound_holdtime) - 1);
1556 } else if (!strcasecmp(var->name, "queue-minutes")) {
1557 strncpy(q->sound_minutes, var->value, sizeof(q->sound_minutes) - 1);
1558 } else if (!strcasecmp(var->name, "queue-thankyou")) {
1559 strncpy(q->sound_thanks, var->value, sizeof(q->sound_thanks) - 1);
1560 } else if (!strcasecmp(var->name, "announce-frequency")) {
1561 q->announcefrequency = atoi(var->value);
1562 } else if (!strcasecmp(var->name, "announce-holdtime")) {
1563 q->announceholdtime = (!strcasecmp(var->value,"once")) ? 1 : ast_true(var->value);
1564 } else if (!strcasecmp(var->name, "retry")) {
1565 q->retry = atoi(var->value);
1566 } else if (!strcasecmp(var->name, "maxlen")) {
1567 q->maxlen = atoi(var->value);
1568 } else if (!strcasecmp(var->name, "servicelevel")) {
1569 q->servicelevel= atoi(var->value);
1570 } else if (!strcasecmp(var->name, "strategy")) {
1571 q->strategy = strat2int(var->value);
1572 if (q->strategy < 0) {
1573 ast_log(LOG_WARNING, "'%s' isn't a valid strategy, using ringall instead\n", var->value);
1577 ast_log(LOG_WARNING, "Unknown keyword in queue '%s': %s at line %d of queue.conf\n", cat, var->name, var->lineno);
1582 q->retry = DEFAULT_RETRY;
1584 q->timeout = DEFAULT_TIMEOUT;
1588 ast_mutex_unlock(&q->lock);
1595 cat = ast_category_browse(cfg, cat);
1610 ast_log(LOG_WARNING, "XXX Leaking a litttle memory :( XXX\n");
1615 ast_mutex_unlock(&qlock);
1618 static int __queues_show(int fd, int argc, char **argv, int queue_show)
1620 struct ast_call_queue *q;
1621 struct queue_ent *qe;
1630 if ((!queue_show && argc != 2) || (queue_show && argc != 3))
1631 return RESULT_SHOWUSAGE;
1632 ast_mutex_lock(&qlock);
1635 ast_mutex_unlock(&qlock);
1637 ast_cli(fd, "No such queue: %s.\n",argv[2]);
1639 ast_cli(fd, "No queues.\n");
1640 return RESULT_SUCCESS;
1643 ast_mutex_lock(&q->lock);
1645 if (strcasecmp(q->name, argv[2]) != 0) {
1646 ast_mutex_unlock(&q->lock);
1649 ast_cli(fd, "No such queue: %s.\n",argv[2]);
1656 snprintf(max, sizeof(max), "%d", q->maxlen);
1658 strcpy(max, "unlimited");
1660 if(q->callscompleted > 0)
1661 sl = 100*((float)q->callscompletedinsl/(float)q->callscompleted);
1662 ast_cli(fd, "%-12.12s has %d calls (max %s) in '%s' strategy (%ds holdtime), C:%d, A:%d, SL:%2.1f%% within %ds\n",
1663 q->name, q->count, max, int2strat(q->strategy), q->holdtime, q->callscompleted, q->callsabandoned,sl,q->servicelevel);
1665 ast_cli(fd, " Members: \n");
1666 for (mem = q->members; mem; mem = mem->next) {
1668 snprintf(max, sizeof(max) - 20, " with penalty %d", mem->penalty);
1672 strcat(max, " (dynamic)");
1674 snprintf(calls, sizeof(calls), " has taken %d calls (last was %ld secs ago)",
1675 mem->calls, (long)(time(NULL) - mem->lastcall));
1677 strcpy(calls, " has taken no calls yet");
1678 ast_cli(fd, " %s/%s%s%s\n", mem->tech, mem->loc, max, calls);
1681 ast_cli(fd, " No Members\n");
1684 ast_cli(fd, " Callers: \n");
1685 for (qe = q->head; qe; qe = qe->next)
1686 ast_cli(fd, " %d. %s (wait: %ld:%2.2ld)\n", pos++, qe->chan->name,
1687 (long)(now - qe->start) / 60, (long)(now - qe->start) % 60);
1689 ast_cli(fd, " No Callers\n");
1691 ast_mutex_unlock(&q->lock);
1696 ast_mutex_unlock(&qlock);
1697 return RESULT_SUCCESS;
1700 static int queues_show(int fd, int argc, char **argv)
1702 return __queues_show(fd, argc, argv, 0);
1705 static int queue_show(int fd, int argc, char **argv)
1707 return __queues_show(fd, argc, argv, 1);
1710 static char *complete_queue(char *line, char *word, int pos, int state)
1712 struct ast_call_queue *q;
1715 ast_mutex_lock(&qlock);
1718 if (!strncasecmp(word, q->name, strlen(word))) {
1719 if (++which > state)
1724 ast_mutex_unlock(&qlock);
1725 return q ? strdup(q->name) : NULL;
1728 /* JDG: callback to display queues status in manager */
1729 static int manager_queues_show( struct mansession *s, struct message *m )
1731 char *a[] = { "show", "queues" };
1732 return queues_show( s->fd, 2, a );
1736 /* Dump queue status */
1737 static int manager_queues_status( struct mansession *s, struct message *m )
1741 char *id = astman_get_header(m,"ActionID");
1742 char idText[256] = "";
1743 struct ast_call_queue *q;
1744 struct queue_ent *qe;
1747 astman_send_ack(s, m, "Queue status will follow");
1749 ast_mutex_lock(&qlock);
1752 snprintf(idText,256,"ActionID: %s\r\n",id);
1755 ast_mutex_lock(&q->lock);
1757 /* List queue properties */
1758 if(q->callscompleted > 0)
1759 sl = 100*((float)q->callscompletedinsl/(float)q->callscompleted);
1760 ast_cli(s->fd, "Event: QueueParams\r\n"
1767 "ServiceLevel: %d\r\n"
1768 "ServicelevelPerf: %2.1f\r\n"
1771 q->name, q->maxlen, q->count, q->holdtime, q->callscompleted,
1772 q->callsabandoned, q->servicelevel, sl, idText);
1774 /* List Queue Members */
1775 for (mem = q->members; mem; mem = mem->next)
1776 ast_cli(s->fd, "Event: QueueMember\r\n"
1778 "Location: %s/%s\r\n"
1779 "Membership: %s\r\n"
1781 "CallsTaken: %d\r\n"
1785 q->name, mem->tech, mem->loc, mem->dynamic ? "dynamic" : "static",
1786 mem->penalty, mem->calls, mem->lastcall, idText);
1788 /* List Queue Entries */
1791 for (qe = q->head; qe; qe = qe->next)
1792 ast_cli(s->fd, "Event: QueueEntry\r\n"
1800 q->name, pos++, qe->chan->name, (qe->chan->callerid ? qe->chan->callerid : ""), (long)(now - qe->start), idText);
1801 ast_mutex_unlock(&q->lock);
1804 ast_mutex_unlock(&qlock);
1805 return RESULT_SUCCESS;
1808 static char show_queues_usage[] =
1809 "Usage: show queues\n"
1810 " Provides summary information on call queues.\n";
1812 static struct ast_cli_entry cli_show_queues = {
1813 { "show", "queues", NULL }, queues_show,
1814 "Show status of queues", show_queues_usage, NULL };
1816 static char show_queue_usage[] =
1817 "Usage: show queue\n"
1818 " Provides summary information on a specified queue.\n";
1820 static struct ast_cli_entry cli_show_queue = {
1821 { "show", "queue", NULL }, queue_show,
1822 "Show status of a specified queue", show_queue_usage, complete_queue };
1824 int unload_module(void)
1826 STANDARD_HANGUP_LOCALUSERS;
1827 ast_cli_unregister(&cli_show_queue);
1828 ast_cli_unregister(&cli_show_queues);
1829 ast_manager_unregister( "Queues" );
1830 ast_manager_unregister( "QueueStatus" );
1831 ast_unregister_application(app_aqm);
1832 ast_unregister_application(app_rqm);
1833 return ast_unregister_application(app);
1836 int load_module(void)
1839 res = ast_register_application(app, queue_exec, synopsis, descrip);
1841 ast_cli_register(&cli_show_queue);
1842 ast_cli_register(&cli_show_queues);
1843 ast_manager_register( "Queues", 0, manager_queues_show, "Queues" );
1844 ast_manager_register( "QueueStatus", 0, manager_queues_status, "Queue Status" );
1847 ast_register_application(app_aqm, aqm_exec, app_aqm_synopsis, app_aqm_descrip) ;
1848 ast_register_application(app_rqm, rqm_exec, app_rqm_synopsis, app_rqm_descrip) ;
1861 char *description(void)
1869 STANDARD_USECOUNT(res);
1875 return ASTERISK_GPL_KEY;