Newer
Older
if( ! found )
ast_log(LOG_WARNING, "Unable to remove interface from queue '%s': No such queue\n", queuename);
LOCAL_USER_REMOVE(u);
return res;
}
static int aqm_exec(struct ast_channel *chan, void *data)
{
int res=-1;
struct localuser *u;
char *queuename;
char info[512];
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
char *interface=NULL;
struct ast_call_queue *q;
struct member *save;
int found=0 ;
if (!data) {
ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename|optional interface)\n");
return -1;
}
LOCAL_USER_ADD(u); // not sure if we need this, but better be safe than sorry ;-)
/* Parse our arguments XXX Check for failure XXX */
strncpy(info, (char *)data, strlen((char *)data) + AST_MAX_EXTENSION-1);
queuename = info;
if (queuename) {
interface = strchr(queuename, '|');
if (interface) {
*interface = '\0';
interface++;
}
else {
strncpy(tmpchan, chan->name, sizeof(tmpchan) - 1);
interface = strrchr(tmpchan, '-');
if (interface)
*interface = '\0';
interface = tmpchan;
}
}
if( ( q = queues) != NULL )
{
while( q && ( res != 0 ) && (!found) )
{
ast_mutex_lock(&q->lock);
if( strcmp( q->name, queuename) == 0 )
{
// found queue, try to enable interface
found=1 ;
if( interface_exists( q, interface ) == NULL )
{
save = q->members ;
q->members = create_queue_node( interface ) ;
q->members = save ;
ast_log(LOG_NOTICE, "Added interface '%s' to queue '%s'\n", interface, queuename);
res = 0 ;
}
else
ast_log(LOG_WARNING, "Unable to add interface '%s' to queue '%s': "
"Already there\n", interface, queuename);
}
ast_mutex_unlock(&q->lock);
q = q->next;
}
}
if( ! found )
ast_log(LOG_WARNING, "Unable to add interface to queue '%s': No such queue\n", queuename);
LOCAL_USER_REMOVE(u);
return res;
}
static int queue_exec(struct ast_channel *chan, void *data)
{
int res=-1;
struct localuser *u;
char *queuename;
char info[512];
char *options = NULL;
char *url = NULL;
char *announceoverride = NULL;
/* whether to exit Queue application after the timeout hits */
int go_on = 0;
/* Our queue entry */
struct queue_ent qe;
if (!data) {
ast_log(LOG_WARNING, "Queue requires an argument (queuename|optional timeout|optional URL)\n");
return -1;
}
LOCAL_USER_ADD(u);
/* Parse our arguments XXX Check for failure XXX */
strncpy(info, (char *)data, strlen((char *)data) + AST_MAX_EXTENSION-1);
queuename = info;
if (queuename) {
options = strchr(queuename, '|');
if (options) {
*options = '\0';
options++;
url = strchr(options, '|');
if (url) {
*url = '\0';
url++;
announceoverride = strchr(url, '|');
if (announceoverride) {
*announceoverride = '\0';
announceoverride++;
}
}
if (option_debug)
ast_log(LOG_DEBUG, "queue: %s, options: %s, url: %s, announce: %s\n",
queuename, options, url, announceoverride);
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
/* Setup our queue entry */
memset(&qe, 0, sizeof(qe));
qe.chan = chan;
qe.start = time(NULL);
if (!join_queue(queuename, &qe)) {
/* Start music on hold */
ast_moh_start(chan, qe.moh);
for (;;) {
res = wait_our_turn(&qe);
/* If they hungup, return immediately */
if (res < 0) {
if (option_verbose > 2) {
ast_verbose(VERBOSE_PREFIX_3 "User disconnected while waiting their turn\n");
res = -1;
}
break;
}
if (!res)
break;
if (valid_exit(&qe, res))
break;
}
if (!res) {
for (;;) {
res = try_calling(&qe, options, announceoverride, url, &go_on);
if (res)
break;
res = wait_a_bit(&qe);
if (res < 0) {
if (option_verbose > 2) {
ast_verbose(VERBOSE_PREFIX_3 "User disconnected when they almost made it\n");
res = -1;
}
break;
}
if (res && valid_exit(&qe, res))
break;
/* exit after a timeout if 'n' option enabled */
if (go_on) {
res = 0;
break;
}
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
leave_queue(&qe);
} else {
ast_log(LOG_WARNING, "Unable to join queue '%s'\n", queuename);
res = 0;
}
LOCAL_USER_REMOVE(u);
return res;
}
static void reload_queues(void)
{
struct ast_call_queue *q, *ql, *qn;
struct ast_config *cfg;
char *cat, *tmp;
struct ast_variable *var;
struct member *prev, *cur;
int new;
cfg = ast_load("queues.conf");
if (!cfg) {
ast_log(LOG_NOTICE, "No call queueing config file, so no call queues\n");
return;
}
ast_mutex_lock(&qlock);
/* Mark all queues as dead for the moment */
q = queues;
while(q) {
q = q->next;
}
/* Chug through config file */
cat = ast_category_browse(cfg, NULL);
while(cat) {
if (strcasecmp(cat, "general")) {
/* Look for an existing one */
q = queues;
while(q) {
if (!strcmp(q->name, cat))
break;
q = q->next;
}
if (!q) {
/* Make one then */
q = malloc(sizeof(struct ast_call_queue));
if (q) {
/* Initialize it */
memset(q, 0, sizeof(struct ast_call_queue));
ast_mutex_init(&q->lock);
strncpy(q->name, cat, sizeof(q->name));
new = 1;
} else new = 0;
} else
new = 0;
if (q) {
if (!new)
ast_mutex_lock(&q->lock);
/* Re-initialize the queue */
q->dead = 0;
q->retry = 0;
q->timeout = -1;
q->maxlen = 0;
strcpy(q->moh, "");
strcpy(q->announce, "");
strcpy(q->context, "");
prev = q->members;
if (prev) {
/* find the end of any dynamic members */
while(prev->next)
prev = prev->next;
}
var = ast_variable_browse(cfg, cat);
while(var) {
if (!strcasecmp(var->name, "member")) {
/* Add a new member */
cur = malloc(sizeof(struct member));
if (cur) {
memset(cur, 0, sizeof(struct member));
strncpy(cur->tech, var->value, sizeof(cur->tech) - 1);
if ((tmp = strchr(cur->tech, ','))) {
*tmp = '\0';
tmp++;
cur->penalty = atoi(tmp);
if (cur->penalty < 0)
cur->penalty = 0;
}
if ((tmp = strchr(cur->tech, '/')))
*tmp = '\0';
if ((tmp = strchr(var->value, '/'))) {
tmp++;
strncpy(cur->loc, tmp, sizeof(cur->loc) - 1);
if ((tmp = strchr(cur->loc, ',')))
*tmp = '\0';
} else
ast_log(LOG_WARNING, "No location at line %d of queue.conf\n", var->lineno);
if (prev)
prev->next = cur;
else
q->members = cur;
prev = cur;
}
} else if (!strcasecmp(var->name, "music")) {
strncpy(q->moh, var->value, sizeof(q->moh) - 1);
} else if (!strcasecmp(var->name, "announce")) {
strncpy(q->announce, var->value, sizeof(q->announce) - 1);
} else if (!strcasecmp(var->name, "context")) {
strncpy(q->context, var->value, sizeof(q->context) - 1);
} else if (!strcasecmp(var->name, "timeout")) {
q->timeout = atoi(var->value);
} else if (!strcasecmp(var->name, "retry")) {
q->retry = atoi(var->value);
} else if (!strcasecmp(var->name, "maxlen")) {
q->maxlen = atoi(var->value);
} else if (!strcasecmp(var->name, "strategy")) {
q->strategy = strat2int(var->value);
if (q->strategy < 0) {
ast_log(LOG_WARNING, "'%s' isn't a valid strategy, using ringall instead\n", var->value);
q->strategy = 0;
}
} else {
ast_log(LOG_WARNING, "Unknown keyword in queue '%s': %s at line %d of queue.conf\n", cat, var->name, var->lineno);
}
var = var->next;
}
if (q->retry < 1)
q->retry = DEFAULT_RETRY;
if (q->timeout < 0)
q->timeout = DEFAULT_TIMEOUT;
if (q->maxlen < 0)
q->maxlen = 0;
if (!new)
ast_mutex_unlock(&q->lock);
if (new) {
q->next = queues;
queues = q;
}
}
}
cat = ast_category_browse(cfg, cat);
}
q = queues;
ql = NULL;
while(q) {
qn = q->next;
if (q->dead) {
if (ql)
ql->next = q->next;
else
queues = q->next;
if (!q->count) {
free(q);
} else
ast_log(LOG_WARNING, "XXX Leaking a litttle memory :( XXX\n");
} else
ql = q;
q = qn;
}
ast_mutex_unlock(&qlock);
static int __queues_show(int fd, int argc, char **argv, int queue_show)
struct queue_ent *qe;
struct member *mem;
int pos;
time_t now;
char max[80];
char calls[80];
if ((!queue_show && argc != 2) || (queue_show && argc != 3))
if (queue_show)
ast_cli(fd, "No such queue: %s.\n",argv[2]);
else
ast_cli(fd, "No queues.\n");
ast_mutex_lock(&q->lock);
if (queue_show) {
if (strcasecmp(q->name, argv[2]) != 0) {
ast_mutex_unlock(&q->lock);
if (!q) {
ast_cli(fd, "No such queue: %s.\n",argv[2]);
break;
}
continue;
}
}
if (q->maxlen)
snprintf(max, sizeof(max), "%d", q->maxlen);
else
strcpy(max, "unlimited");
ast_cli(fd, "%-12.12s has %d calls (max %s) in '%s' strategy\n", q->name, q->count, max, int2strat(q->strategy));
if (q->members) {
ast_cli(fd, " Members: \n");
for (mem = q->members; mem; mem = mem->next) {
if (mem->penalty)
snprintf(max, sizeof(max) - 20, " with penalty %d", mem->penalty);
else
strcpy(max, "");
if (mem->calls) {
snprintf(calls, sizeof(calls), " has taken %d calls (last was %ld secs ago)",
mem->calls, (long)(time(NULL) - mem->lastcall));
} else
strcpy(calls, " has taken no calls yet");
ast_cli(fd, " %s/%s%s%s\n", mem->tech, mem->loc, max, calls);
}
} else
ast_cli(fd, " No Members\n");
if (q->head) {
pos = 1;
ast_cli(fd, " Callers: \n");
for (qe = q->head; qe; qe = qe->next)
ast_cli(fd, " %d. %s (wait: %ld:%2.2ld)\n", pos++, qe->chan->name,
(long)(now - qe->start) / 60, (long)(now - qe->start) % 60);
} else
ast_cli(fd, " No Callers\n");
ast_cli(fd, "\n");
ast_mutex_unlock(&q->lock);
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
static int queues_show(int fd, int argc, char **argv)
{
return __queues_show(fd, argc, argv, 0);
}
static int queue_show(int fd, int argc, char **argv)
{
return __queues_show(fd, argc, argv, 1);
}
static char *complete_queue(char *line, char *word, int pos, int state)
{
struct ast_call_queue *q;
int which=0;
ast_mutex_lock(&qlock);
q = queues;
while(q) {
if (!strncasecmp(word, q->name, strlen(word))) {
if (++which > state)
break;
}
q = q->next;
}
ast_mutex_unlock(&qlock);
return q ? strdup(q->name) : NULL;
}
/* JDG: callback to display queues status in manager */
static int manager_queues_show( struct mansession *s, struct message *m )
{
char *a[] = { "show", "queues" };
return queues_show( s->fd, 2, a );
} /* /JDG */
/* Dump queue status */
static int manager_queues_status( struct mansession *s, struct message *m )
{
time_t now;
int pos;
char *id = astman_get_header(m,"ActionID");
char idText[256] = "";
struct ast_call_queue *q;
struct queue_ent *qe;
astman_send_ack(s, m, "Queue status will follow");
if (id && &id) {
snprintf(idText,256,"ActionID: %s\r\n",id);
}
ast_mutex_lock(&q->lock);
ast_cli(s->fd, "Event: QueueParams\r\n"
"Queue: %s\r\n"
"Max: %d\r\n"
"Calls: %d\r\n"
#if 0
/* Do we care about queue members? */
for (mem = q->members; mem; mem = mem->next)
ast_cli(fd, " %s/%s\n", mem->tech, mem->loc);
#endif
pos = 1;
for (qe = q->head; qe; qe = qe->next)
ast_cli(s->fd, "Event: QueueMember\r\n"
"Queue: %s\r\n"
"Position: %d\r\n"
"Channel: %s\r\n"
"CallerID: %s\r\n"
"Wait: %ld\r\n"
q->name, pos++, qe->chan->name, (qe->chan->callerid ? qe->chan->callerid : ""), (long)(now - qe->start), idText);
ast_mutex_unlock(&q->lock);
static char show_queues_usage[] =
"Usage: show queues\n"
" Provides summary information on call queues.\n";
static struct ast_cli_entry cli_show_queues = {
{ "show", "queues", NULL }, queues_show,
"Show status of queues", show_queues_usage, NULL };
static char show_queue_usage[] =
"Usage: show queue\n"
" Provides summary information on a specified queue.\n";
static struct ast_cli_entry cli_show_queue = {
{ "show", "queue", NULL }, queue_show,
"Show status of a specified queue", show_queue_usage, complete_queue };
int unload_module(void)
{
STANDARD_HANGUP_LOCALUSERS;
ast_cli_unregister(&cli_show_queue);
ast_manager_unregister( "QueueStatus" );
return ast_unregister_application(app);
}
int load_module(void)
{
int res;
res = ast_register_application(app, queue_exec, synopsis, descrip);
ast_cli_register(&cli_show_queue);
ast_manager_register( "Queues", 0, manager_queues_show, "Queues" );
ast_manager_register( "QueueStatus", 0, manager_queues_status, "Queue Status" );
// [PHM 06/26/03]
ast_register_application(app_aqm, aqm_exec, app_aqm_synopsis, app_aqm_descrip) ;
ast_register_application(app_rqm, rqm_exec, app_rqm_synopsis, app_rqm_descrip) ;
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
int reload(void)
{
reload_queues();
return 0;
}
char *description(void)
{
return tdesc;
}
int usecount(void)
{
int res;
STANDARD_USECOUNT(res);
return res;
}
char *key()
{
return ASTERISK_GPL_KEY;
}