Newer
Older
cur_ptr = queue_data;
while ((member = strsep(&cur_ptr, "|"))) {
if (ast_strlen_zero(member))
continue;
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
interface = strsep(&member, ";");
penalty_tok = strsep(&member, ";");
paused_tok = strsep(&member, ";");
if (!penalty_tok) {
ast_log(LOG_WARNING, "Error parsing persisent member string for '%s' (penalty)\n", queue_name);
break;
}
penalty = strtol(penalty_tok, NULL, 10);
if (errno == ERANGE) {
ast_log(LOG_WARNING, "Error converting penalty: %s: Out of range.\n", penalty_tok);
break;
}
if (!paused_tok) {
ast_log(LOG_WARNING, "Error parsing persistent member string for '%s' (paused)\n", queue_name);
break;
}
paused = strtol(paused_tok, NULL, 10);
if ((errno == ERANGE) || paused < 0 || paused > 1) {
ast_log(LOG_WARNING, "Error converting paused: %s: Expected 0 or 1.\n", paused_tok);
break;
}
if (option_debug)
ast_log(LOG_DEBUG, "Reload Members: Queue: %s Member: %s Penalty: %d Paused: %d\n", queue_name, interface, penalty, paused);
if (add_to_queue(queue_name, interface, penalty, paused, 0) == RES_OUTOFMEMORY) {
ast_log(LOG_ERROR, "Out of Memory when reloading persistent queue member\n");
break;
}
}
}
ast_mutex_unlock(&qlock);
if (db_tree) {
ast_log(LOG_NOTICE, "Queue members sucessfully reloaded from database.\n");
ast_db_freetree(db_tree);
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
static int pqm_exec(struct ast_channel *chan, void *data)
{
struct localuser *u;
char *queuename, *interface;
if (!data) {
ast_log(LOG_WARNING, "PauseQueueMember requires an argument ([queuename]|interface])\n");
return -1;
}
queuename = ast_strdupa((char *)data);
if (!queuename) {
ast_log(LOG_ERROR, "Out of memory\n");
return -1;
}
interface = strchr(queuename, '|');
if (!interface) {
ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename]|interface])\n");
return -1;
}
LOCAL_USER_ADD(u);
*interface = '\0';
interface++;
if (set_member_paused(queuename, interface, 1)) {
ast_log(LOG_WARNING, "Attempt to pause interface %s, not found\n", interface);
if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num)) {
chan->priority += 100;
LOCAL_USER_REMOVE(u);
return 0;
}
return -1;
}
LOCAL_USER_REMOVE(u);
return 0;
}
static int upqm_exec(struct ast_channel *chan, void *data)
{
struct localuser *u;
char *queuename, *interface;
if (!data) {
ast_log(LOG_WARNING, "UnpauseQueueMember requires an argument ([queuename]|interface])\n");
return -1;
}
queuename = ast_strdupa((char *)data);
if (!queuename) {
ast_log(LOG_ERROR, "Out of memory\n");
return -1;
}
interface = strchr(queuename, '|');
if (!interface) {
ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename]|interface])\n");
return -1;
}
LOCAL_USER_ADD(u);
*interface = '\0';
interface++;
if (set_member_paused(queuename, interface, 0)) {
ast_log(LOG_WARNING, "Attempt to unpause interface %s, not found\n", interface);
if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num)) {
chan->priority += 100;
LOCAL_USER_REMOVE(u);
return 0;
}
return -1;
}
LOCAL_USER_REMOVE(u);
return 0;
}
static int rqm_exec(struct ast_channel *chan, void *data)
{
int res=-1;
struct localuser *u;
char *info, *queuename;
char *interface = NULL;
ast_log(LOG_WARNING, "RemoveQueueMember requires an argument (queuename[|interface])\n");
info = ast_strdupa((char *)data);
if (!info) {
ast_log(LOG_ERROR, "Out of memory\n");
return -1;
}
LOCAL_USER_ADD(u);
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;
}
switch (remove_from_queue(queuename, interface)) {
case RES_OKAY:
ast_log(LOG_NOTICE, "Removed interface '%s' from queue '%s'\n", interface, queuename);
res = 0;
break;
case RES_EXISTS:
ast_log(LOG_WARNING, "Unable to remove interface '%s' from queue '%s': Not there\n", interface, queuename);
if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num)) {
chan->priority += 100;
res = 0;
break;
case RES_NOSUCHQUEUE:
ast_log(LOG_WARNING, "Unable to remove interface from queue '%s': No such queue\n", queuename);
res = 0;
break;
case RES_OUTOFMEMORY:
ast_log(LOG_ERROR, "Out of memory\n");
break;
}
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;
char *penaltys=NULL;
int penalty = 0;
ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename[|[interface][|penalty]])\n");
info = ast_strdupa((char *)data);
if (!info) {
ast_log(LOG_ERROR, "Out of memory\n");
return -1;
}
LOCAL_USER_ADD(u);
queuename = info;
if (queuename) {
interface = strchr(queuename, '|');
if (interface) {
*interface = '\0';
interface++;
}
if (interface) {
penaltys = strchr(interface, '|');
if (penaltys) {
*penaltys = '\0';
if (!interface || ast_strlen_zero(interface)) {
strncpy(tmpchan, chan->name, sizeof(tmpchan) - 1);
interface = strrchr(tmpchan, '-');
if (interface)
*interface = '\0';
interface = tmpchan;
}
if (penaltys && !ast_strlen_zero(penaltys)) {
if ((sscanf(penaltys, "%d", &penalty) != 1) || penalty < 0) {
ast_log(LOG_WARNING, "Penalty '%s' is invalid, must be an integer >= 0\n", penaltys);
penalty = 0;
}
}
switch (add_to_queue(queuename, interface, penalty, 0, queue_persistent_members)) {
case RES_OKAY:
ast_log(LOG_NOTICE, "Added interface '%s' to queue '%s'\n", interface, queuename);
res = 0;
break;
case RES_EXISTS:
ast_log(LOG_WARNING, "Unable to add interface '%s' to queue '%s': Already there\n", interface, queuename);
if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num)) {
chan->priority += 100;
res = 0;
break;
case RES_NOSUCHQUEUE:
ast_log(LOG_WARNING, "Unable to add interface to queue '%s': No such queue\n", queuename);
res = 0;
break;
case RES_OUTOFMEMORY:
ast_log(LOG_ERROR, "Out of memory adding member %s to queue %s\n", interface, queuename);
break;
}
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 *info_ptr = info;
char *url = NULL;
char *announceoverride = NULL;
char *user_priority;
int prio;
Mark Spencer
committed
enum queue_result reason = QUEUE_UNKNOWN;
/* whether to exit Queue application after the timeout hits */
int go_on = 0;
/* Our queue entry */
struct queue_ent qe;
if (!data || ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Queue requires an argument: queuename[|options[|URL][|announceoverride][|timeout]]\n");
/* Setup our queue entry */
memset(&qe, 0, sizeof(qe));
qe.start = time(NULL);
/* Parse our arguments XXX Check for failure XXX */
strncpy(info, (char *) data, sizeof(info) - 1);
queuename = strsep(&info_ptr, "|");
options = strsep(&info_ptr, "|");
url = strsep(&info_ptr, "|");
announceoverride = strsep(&info_ptr, "|");
queuetimeoutstr = info_ptr;
/* set the expire time based on the supplied timeout; */
if (queuetimeoutstr)
qe.expire = qe.start + atoi(queuetimeoutstr);
else
qe.expire = 0;
/* Get the priority from the variable ${QUEUE_PRIO} */
user_priority = pbx_builtin_getvar_helper(chan, "QUEUE_PRIO");
if (user_priority) {
if (sscanf(user_priority, "%d", &prio) == 1) {
if (option_debug)
ast_log(LOG_DEBUG, "%s: Got priority %d from ${QUEUE_PRIO}.\n",
Mark Spencer
committed
chan->name, prio);
} else {
ast_log(LOG_WARNING, "${QUEUE_PRIO}: Invalid value (%s), channel %s.\n",
Mark Spencer
committed
user_priority, chan->name);
prio = 0;
}
} else {
ast_log(LOG_DEBUG, "NO QUEUE_PRIO variable found. Using default.\n");
prio = 0;
Mark Spencer
committed
if (options && (strchr(options, 'r')))
ringing = 1;
ast_log(LOG_DEBUG, "queue: %s, options: %s, url: %s, announce: %s, expires: %ld, priority: %d\n",
Mark Spencer
committed
queuename, options, url, announceoverride, (long)qe.expire, (int)prio);
qe.prio = (int)prio;
qe.last_pos_said = 0;
qe.last_pos = 0;
Mark Spencer
committed
if (!join_queue(queuename, &qe, &reason)) {
ast_queue_log(queuename, chan->uniqueid, "NONE", "ENTERQUEUE", "%s|%s", url ? url : "",
chan->cid.cid_num ? chan->cid.cid_num : "");
if (ringing) {
ast_indicate(chan, AST_CONTROL_RINGING);
} else {
ast_moh_start(chan, qe.moh);
}
/* This is the wait loop for callers 2 through maxlen */
Mark Spencer
committed
res = wait_our_turn(&qe, ringing, &reason);
/* If they hungup, return immediately */
if (res < 0) {
/* Record this abandoned call */
record_abandoned(&qe);
ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
ast_verbose(VERBOSE_PREFIX_3 "User disconnected from queue %s while waiting their turn\n", queuename);
if (valid_exit(&qe, res)) {
ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos);
Mark Spencer
committed
int makeannouncement = 0;
/* This is the wait loop for the head caller*/
/* To exit, they may get their call answered; */
/* they may dial a digit from the queue context; */
/* or, they may timeout. */
Mark Spencer
committed
enum queue_member_status stat;
/* Leave if we have exceeded our queuetimeout */
if (qe.expire && (time(NULL) > qe.expire)) {
Mark Spencer
committed
reason = QUEUE_TIMEOUT;
Mark Spencer
committed
if (makeannouncement) {
/* Make a position announcement, if enabled */
if (qe.parent->announcefrequency && !ringing)
say_position(&qe);
Mark Spencer
committed
makeannouncement = 1;
/* Try calling all queue members for 'timeout' seconds */
res = try_calling(&qe, options, announceoverride, url, &go_on);
if (res) {
if (res < 0) {
if (!qe.handled)
ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
} else if (res > 0)
ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos);
Mark Spencer
committed
stat = get_member_status(qe.parent);
Mark Spencer
committed
/* leave the queue if no agents, if enabled */
Mark Spencer
committed
if (qe.parent->leavewhenempty && (stat == QUEUE_NO_MEMBERS)) {
reason = QUEUE_LEAVEEMPTY;
res = 0;
break;
}
/* leave the queue if no reachable agents, if enabled */
if ((qe.parent->leavewhenempty == QUEUE_EMPTY_STRICT) && (stat == QUEUE_NO_REACHABLE_MEMBERS)) {
Mark Spencer
committed
reason = QUEUE_LEAVEUNAVAIL;
Mark Spencer
committed
res = 0;
break;
}
/* Leave if we have exceeded our queuetimeout */
if (qe.expire && (time(NULL) > qe.expire)) {
Mark Spencer
committed
reason = QUEUE_TIMEOUT;
res = 0;
break;
}
/* OK, we didn't get anybody; wait for 'retry' seconds; may get a digit to exit with */
ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
ast_verbose(VERBOSE_PREFIX_3 "User disconnected from queue %s when they almost made it\n", queuename);
if (res && valid_exit(&qe, res)) {
ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos);
/* exit after 'timeout' cycle if 'n' option enabled */
if (option_verbose > 2) {
ast_verbose(VERBOSE_PREFIX_3 "Exiting on time-out cycle\n");
res = -1;
}
ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
Mark Spencer
committed
reason = QUEUE_TIMEOUT;
/* Since this is a priority queue and
* it is not sure that we are still at the head
* of the queue, go and check for our turn again.
*/
if (!is_our_turn(&qe)) {
if (option_debug)
ast_log(LOG_DEBUG, "Darn priorities, going back in queue (%s)!\n",
qe.chan->name);
goto check_turns;
}
if (res >= 0 && res != AST_PBX_KEEPALIVE) {
if (ringing) {
ast_indicate(chan, -1);
} else {
ast_moh_stop(chan);
}
Mark Spencer
committed
if (reason != QUEUE_UNKNOWN)
set_queue_result(chan, reason);
} else {
ast_log(LOG_WARNING, "Unable to join queue '%s'\n", queuename);
Mark Spencer
committed
set_queue_result(chan, reason);
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;
char *general_val = NULL;
ast_log(LOG_NOTICE, "No call queueing config file (queues.conf), so no call queues\n");
ast_mutex_lock(&qlock);
/* Mark all queues as dead for the moment */
q = queues;
while(q) {
Mark Spencer
committed
q->dead = 1;
q = q->next;
}
/* Chug through config file */
cat = ast_category_browse(cfg, NULL);
while(cat) {
if (strcasecmp(cat, "general")) { /* Define queue */
/* 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) - 1);
new = 1;
} else new = 0;
} else
new = 0;
if (q) {
if (!new)
ast_mutex_lock(&q->lock);
Mark Spencer
committed
q->dead = 0;
q->announcefrequency = 0;
q->announceholdtime = 0;
q->roundingseconds = 0; /* Default - don't announce seconds */
q->holdtime = 0;
q->callscompleted = 0;
q->callsabandoned = 0;
q->callscompletedinsl = 0;
q->servicelevel = 0;
q->moh[0] = '\0';
q->announce[0] = '\0';
q->context[0] = '\0';
q->monfmt[0] = '\0';
strncpy(q->sound_next, "queue-youarenext", sizeof(q->sound_next) - 1);
strncpy(q->sound_thereare, "queue-thereare", sizeof(q->sound_thereare) - 1);
strncpy(q->sound_calls, "queue-callswaiting", sizeof(q->sound_calls) - 1);
strncpy(q->sound_holdtime, "queue-holdtime", sizeof(q->sound_holdtime) - 1);
strncpy(q->sound_minutes, "queue-minutes", sizeof(q->sound_minutes) - 1);
strncpy(q->sound_seconds, "queue-seconds", sizeof(q->sound_seconds) - 1);
strncpy(q->sound_thanks, "queue-thankyou", sizeof(q->sound_thanks) - 1);
strncpy(q->sound_lessthan, "queue-less-than", sizeof(q->sound_lessthan) - 1);
strncpy(q->sound_reporthold, "queue-reporthold", sizeof(q->sound_reporthold) - 1);
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->interface, var->value, sizeof(cur->interface) - 1);
if ((tmp = strchr(cur->interface, ','))) {
*tmp = '\0';
tmp++;
cur->penalty = atoi(tmp);
if (cur->penalty < 0)
cur->penalty = 0;
}
if (!strchr(cur->interface, '/'))
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") || !strcasecmp(var->name, "musiconhold")) {
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, "monitor-join")) {
Mark Spencer
committed
q->monjoin = ast_true(var->value);
} else if (!strcasecmp(var->name, "monitor-format")) {
strncpy(q->monfmt, var->value, sizeof(q->monfmt) - 1);
} else if (!strcasecmp(var->name, "queue-youarenext")) {
strncpy(q->sound_next, var->value, sizeof(q->sound_next) - 1);
} else if (!strcasecmp(var->name, "queue-thereare")) {
strncpy(q->sound_thereare, var->value, sizeof(q->sound_thereare) - 1);
} else if (!strcasecmp(var->name, "queue-callswaiting")) {
strncpy(q->sound_calls, var->value, sizeof(q->sound_calls) - 1);
} else if (!strcasecmp(var->name, "queue-holdtime")) {
strncpy(q->sound_holdtime, var->value, sizeof(q->sound_holdtime) - 1);
} else if (!strcasecmp(var->name, "queue-minutes")) {
strncpy(q->sound_minutes, var->value, sizeof(q->sound_minutes) - 1);
} else if (!strcasecmp(var->name, "queue-seconds")) {
strncpy(q->sound_seconds, var->value, sizeof(q->sound_seconds) - 1);
Mark Spencer
committed
} else if (!strcasecmp(var->name, "queue-lessthan")) {
strncpy(q->sound_lessthan, var->value, sizeof(q->sound_lessthan) - 1);
} else if (!strcasecmp(var->name, "queue-thankyou")) {
strncpy(q->sound_thanks, var->value, sizeof(q->sound_thanks) - 1);
} else if (!strcasecmp(var->name, "queue-reporthold")) {
strncpy(q->sound_reporthold, var->value, sizeof(q->sound_reporthold) - 1);
} else if (!strcasecmp(var->name, "announce-frequency")) {
q->announcefrequency = atoi(var->value);
} else if (!strcasecmp(var->name, "announce-round-seconds")) {
q->roundingseconds = atoi(var->value);
if(q->roundingseconds>60 || q->roundingseconds<0) {
ast_log(LOG_WARNING, "'%s' isn't a valid value for queue-rounding-seconds using 0 instead at line %d of queue.conf\n", var->value, var->lineno);
q->roundingseconds=0;
}
} else if (!strcasecmp(var->name, "announce-holdtime")) {
Mark Spencer
committed
if (!strcasecmp(var->value, "once"))
q->announceholdtime = ANNOUNCEHOLDTIME_ONCE;
else if (ast_true(var->value))
q->announceholdtime = ANNOUNCEHOLDTIME_ALWAYS;
else
q->announceholdtime = 0;
} else if (!strcasecmp(var->name, "retry")) {
q->retry = atoi(var->value);
} else if (!strcasecmp(var->name, "wrapuptime")) {
q->wrapuptime = atoi(var->value);
} else if (!strcasecmp(var->name, "maxlen")) {
q->maxlen = atoi(var->value);
} else if (!strcasecmp(var->name, "servicelevel")) {
q->servicelevel= 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 if (!strcasecmp(var->name, "joinempty")) {
Mark Spencer
committed
if (!strcasecmp(var->value, "strict"))
q->joinempty = QUEUE_EMPTY_STRICT;
else if (ast_true(var->value))
q->joinempty = QUEUE_EMPTY_NORMAL;
else
q->joinempty = 0;
} else if (!strcasecmp(var->name, "leavewhenempty")) {
Mark Spencer
committed
if (!strcasecmp(var->value, "strict"))
q->leavewhenempty = QUEUE_EMPTY_STRICT;
else if (ast_true(var->value))
q->leavewhenempty = QUEUE_EMPTY_NORMAL;
else
q->leavewhenempty = 0;
} else if (!strcasecmp(var->name, "eventmemberstatus")) {
q->maskmemberstatus = !ast_true(var->value);
} else if (!strcasecmp(var->name, "eventwhencalled")) {
Mark Spencer
committed
q->eventwhencalled = ast_true(var->value);
} else if (!strcasecmp(var->name, "reportholdtime")) {
Mark Spencer
committed
q->reportholdtime = ast_true(var->value);
} else if (!strcasecmp(var->name, "memberdelay")) {
q->memberdelay = atoi(var->value);
} else if (!strcasecmp(var->name, "weight")) {
q->weight = atoi(var->value);
if (q->weight)
use_weight++;
} else if (!strcasecmp(var->name, "timeoutrestart")) {
Mark Spencer
committed
q->timeoutrestart = ast_true(var->value);
} 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;
}
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;
}
}
/* Initialize global settings */
queue_persistent_members = 0;
if ((general_val = ast_variable_retrieve(cfg, "general", "persistentmembers")))
queue_persistent_members = ast_true(general_val);
}
cat = ast_category_browse(cfg, cat);
}
q = queues;
ql = NULL;
while(q) {
qn = q->next;
Mark Spencer
committed
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 little memory :( XXX\n");
for (cur = q->members; cur; cur = cur->next)
cur->status = ast_device_state(cur->interface);
ast_mutex_unlock(&qlock);
Mark Spencer
committed
static char *status2str(int status, char *buf, int buflen)
{
switch(status) {
case AST_DEVICE_UNKNOWN:
strncpy(buf, "unknown", buflen - 1);
Mark Spencer
committed
break;
case AST_DEVICE_NOT_INUSE:
strncpy(buf, "notinuse", buflen - 1);
Mark Spencer
committed
break;
case AST_DEVICE_INUSE:
strncpy(buf, "inuse", buflen - 1);
break;
case AST_DEVICE_BUSY:
strncpy(buf, "busy", buflen - 1);
Mark Spencer
committed
break;
case AST_DEVICE_INVALID:
strncpy(buf, "invalid", buflen - 1);
Mark Spencer
committed
break;
case AST_DEVICE_UNAVAILABLE:
strncpy(buf, "unavailable", buflen - 1);
Mark Spencer
committed
break;
default:
snprintf(buf, buflen, "unknown status %d", status);
}
return buf;
}
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] = "";
Mark Spencer
committed
char tmpbuf[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
strncpy(max, "unlimited", sizeof(max) - 1);
sl = 0;
if(q->callscompleted > 0)
sl = 100*((float)q->callscompletedinsl/(float)q->callscompleted);
ast_cli(fd, "%-12.12s has %d calls (max %s) in '%s' strategy (%ds holdtime), W:%d, C:%d, A:%d, SL:%2.1f%% within %ds\n",
q->name, q->count, max, int2strat(q->strategy), q->holdtime, q->weight, q->callscompleted, q->callsabandoned,sl,q->servicelevel);
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
max[0] = '\0';
strncat(max, " (dynamic)", sizeof(max) - strlen(max) - 1);
if (mem->paused)
strncat(max, " (paused)", sizeof(max) - strlen(max) - 1);
Mark Spencer
committed
if (mem->status)
snprintf(max + strlen(max), sizeof(max) - strlen(max), " (%s)", status2str(mem->status, tmpbuf, sizeof(tmpbuf)));
if (mem->calls) {
snprintf(calls, sizeof(calls), " has taken %d calls (last was %ld secs ago)",
mem->calls, (long)(time(NULL) - mem->lastcall));
} else
strncpy(calls, " has taken no calls yet", sizeof(calls) - 1);
ast_cli(fd, " %s%s%s\n", mem->interface, 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, prio: %d)\n", pos++, qe->chan->name,
(long)(now - qe->start) / 60, (long)(now - qe->start) % 60, qe->prio);
} else
ast_cli(fd, " No Callers\n");
ast_cli(fd, "\n");
ast_mutex_unlock(&q->lock);
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);
for (q = queues; q; q = q->next) {
if (!strncasecmp(word, q->name, strlen(word))) {
if (++which > state)
break;
}
}
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);
}
/* 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 *queuefilter = astman_get_header(m,"Queue");
char *memberfilter = astman_get_header(m,"Member");
struct ast_call_queue *q;
struct queue_ent *qe;
float sl = 0;
struct member *mem;
astman_send_ack(s, m, "Queue status will follow");
if (!ast_strlen_zero(id)) {
snprintf(idText,256,"ActionID: %s\r\n",id);
}
for (q = queues; q; q = q->next) {
ast_mutex_lock(&q->lock);
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
if (ast_strlen_zero(queuefilter) || !strcmp(q->name, queuefilter)) {
if(q->callscompleted > 0)
sl = 100*((float)q->callscompletedinsl/(float)q->callscompleted);
ast_mutex_lock(&s->lock);
ast_cli(s->fd, "Event: QueueParams\r\n"
"Queue: %s\r\n"
"Max: %d\r\n"
"Calls: %d\r\n"
"Holdtime: %d\r\n"
"Completed: %d\r\n"
"Abandoned: %d\r\n"
"ServiceLevel: %d\r\n"
"ServicelevelPerf: %2.1f\r\n"
"Weight: %d\r\n"
"%s"
"\r\n",
q->name, q->maxlen, q->count, q->holdtime, q->callscompleted,
q->callsabandoned, q->servicelevel, sl, q->weight, idText);
/* List Queue Members */
for (mem = q->members; mem; mem = mem->next) {
if (ast_strlen_zero(memberfilter) || !strcmp(mem->interface, memberfilter)) {
ast_cli(s->fd, "Event: QueueMember\r\n"
"Queue: %s\r\n"
"Location: %s\r\n"
"Membership: %s\r\n"
"Penalty: %d\r\n"
"CallsTaken: %d\r\n"
"LastCall: %ld\r\n"
"Status: %d\r\n"
"Paused: %d\r\n"
"%s"
"\r\n",
q->name, mem->interface, mem->dynamic ? "dynamic" : "static",
mem->penalty, mem->calls, mem->lastcall, mem->status, mem->paused, idText);
}
}
/* List Queue Entries */
pos = 1;
for (qe = q->head; qe; qe = qe->next) {
ast_cli(s->fd, "Event: QueueEntry\r\n"
"Position: %d\r\n"
"Channel: %s\r\n"
"CallerID: %s\r\n"
"CallerIDName: %s\r\n"
"Wait: %ld\r\n"
"\r\n",
q->name, pos++, qe->chan->name,
qe->chan->cid.cid_num ? qe->chan->cid.cid_num : "unknown",
qe->chan->cid.cid_name ? qe->chan->cid.cid_name : "unknown",
(long)(now - qe->start), idText);
}
}
ast_mutex_unlock(&q->lock);
static int manager_add_queue_member(struct mansession *s, struct message *m)
{
char *queuename, *interface, *penalty_s, *paused_s;
int paused, penalty = 0;
queuename = astman_get_header(m, "Queue");
interface = astman_get_header(m, "Interface");
penalty_s = astman_get_header(m, "Penalty");
paused_s = astman_get_header(m, "Paused");
if (ast_strlen_zero(queuename)) {
astman_send_error(s, m, "'Queue' not specified.");
return 0;
}
if (ast_strlen_zero(interface)) {
astman_send_error(s, m, "'Interface' not specified.");
return 0;
}
if (ast_strlen_zero(penalty_s))
penalty = 0;
else if (sscanf(penalty_s, "%d", &penalty) != 1) {
penalty = 0;
}
if (ast_strlen_zero(paused_s))
paused = 0;
else