mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-01 11:32:25 +00:00
replace ast_build_string() with ast_str_*();
simplify __queues_show() git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48550 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
166
apps/app_queue.c
166
apps/app_queue.c
@@ -4035,141 +4035,107 @@ static int reload_queues(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __queues_show(struct mansession *s, int manager, int fd, int argc, char **argv)
|
/*! \brief direct ouput to manager or cli with proper terminator */
|
||||||
|
static void do_print(struct mansession *s, int fd, const char *str)
|
||||||
|
{
|
||||||
|
if (s)
|
||||||
|
astman_append(s, "%s\r\n", str);
|
||||||
|
else
|
||||||
|
ast_cli(fd, "%s\n", str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __queues_show(struct mansession *s, int fd, int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct call_queue *q;
|
struct call_queue *q;
|
||||||
struct queue_ent *qe;
|
struct ast_str *out = ast_str_alloca(80);
|
||||||
struct member *mem;
|
int found = 0;
|
||||||
int pos, queue_show;
|
time_t now = time(NULL);
|
||||||
time_t now;
|
|
||||||
char max_buf[80];
|
|
||||||
char *max;
|
|
||||||
size_t max_left;
|
|
||||||
float sl = 0;
|
|
||||||
char *term = manager ? "\r\n" : "\n";
|
|
||||||
|
|
||||||
time(&now);
|
if (argc != 2 && argc != 3)
|
||||||
if (argc == 2)
|
|
||||||
queue_show = 0;
|
|
||||||
else if (argc == 3)
|
|
||||||
queue_show = 1;
|
|
||||||
else
|
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
|
|
||||||
/* We only want to load realtime queues when a specific queue is asked for. */
|
/* We only want to load realtime queues when a specific queue is asked for. */
|
||||||
if (queue_show)
|
if (argc == 3) /* specific queue */
|
||||||
load_realtime_queue(argv[2]);
|
load_realtime_queue(argv[2]);
|
||||||
|
|
||||||
AST_LIST_LOCK(&queues);
|
AST_LIST_LOCK(&queues);
|
||||||
if (AST_LIST_EMPTY(&queues)) {
|
|
||||||
AST_LIST_UNLOCK(&queues);
|
|
||||||
if (queue_show) {
|
|
||||||
if (s)
|
|
||||||
astman_append(s, "No such queue: %s.%s",argv[2], term);
|
|
||||||
else
|
|
||||||
ast_cli(fd, "No such queue: %s.%s",argv[2], term);
|
|
||||||
} else {
|
|
||||||
if (s)
|
|
||||||
astman_append(s, "No queues.%s", term);
|
|
||||||
else
|
|
||||||
ast_cli(fd, "No queues.%s", term);
|
|
||||||
}
|
|
||||||
return RESULT_SUCCESS;
|
|
||||||
}
|
|
||||||
AST_LIST_TRAVERSE(&queues, q, list) {
|
AST_LIST_TRAVERSE(&queues, q, list) {
|
||||||
|
float sl;
|
||||||
|
|
||||||
ast_mutex_lock(&q->lock);
|
ast_mutex_lock(&q->lock);
|
||||||
if (queue_show) {
|
if (argc == 3 && !strcasecmp(q->name, argv[2])) {
|
||||||
if (strcasecmp(q->name, argv[2]) != 0) {
|
|
||||||
ast_mutex_unlock(&q->lock);
|
ast_mutex_unlock(&q->lock);
|
||||||
if (!AST_LIST_NEXT(q, list)) {
|
|
||||||
ast_cli(fd, "No such queue: %s.%s",argv[2], term);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
found = 1;
|
||||||
max_buf[0] = '\0';
|
|
||||||
max = max_buf;
|
ast_str_set(&out, 0, "%-12.12s has %d calls (max ", q->name, q->count);
|
||||||
max_left = sizeof(max_buf);
|
|
||||||
if (q->maxlen)
|
if (q->maxlen)
|
||||||
ast_build_string(&max, &max_left, "%d", q->maxlen);
|
ast_str_append(&out, 0, "%d", q->maxlen);
|
||||||
else
|
else
|
||||||
ast_build_string(&max, &max_left, "unlimited");
|
ast_str_append(&out, 0, "unlimited");
|
||||||
sl = 0;
|
sl = 0;
|
||||||
if (q->callscompleted > 0)
|
if (q->callscompleted > 0)
|
||||||
sl = 100 * ((float) q->callscompletedinsl / (float) q->callscompleted);
|
sl = 100 * ((float) q->callscompletedinsl / (float) q->callscompleted);
|
||||||
if (s)
|
ast_str_append(&out, 0, ") in '%s' strategy (%ds holdtime), W:%d, C:%d, A:%d, SL:%2.1f%% within %ds",
|
||||||
astman_append(s, "%-12.12s has %d calls (max %s) in '%s' strategy (%ds holdtime), W:%d, C:%d, A:%d, SL:%2.1f%% within %ds%s",
|
int2strat(q->strategy), q->holdtime, q->weight,
|
||||||
q->name, q->count, max_buf, int2strat(q->strategy), q->holdtime, q->weight,
|
q->callscompleted, q->callsabandoned,sl,q->servicelevel);
|
||||||
q->callscompleted, q->callsabandoned,sl,q->servicelevel, term);
|
do_print(s, fd, out->str);
|
||||||
else
|
if (!q->members)
|
||||||
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%s",
|
do_print(s, fd, " No Members");
|
||||||
q->name, q->count, max_buf, int2strat(q->strategy), q->holdtime, q->weight, q->callscompleted, q->callsabandoned,sl,q->servicelevel, term);
|
else {
|
||||||
if (q->members) {
|
struct member *mem;
|
||||||
if (s)
|
|
||||||
astman_append(s, " Members: %s", term);
|
do_print(s, fd, " Members: ");
|
||||||
else
|
|
||||||
ast_cli(fd, " Members: %s", term);
|
|
||||||
for (mem = q->members; mem; mem = mem->next) {
|
for (mem = q->members; mem; mem = mem->next) {
|
||||||
max_buf[0] = '\0';
|
ast_str_set(&out, 0, " %s", mem->interface);
|
||||||
max = max_buf;
|
|
||||||
max_left = sizeof(max_buf);
|
|
||||||
if (mem->penalty)
|
if (mem->penalty)
|
||||||
ast_build_string(&max, &max_left, " with penalty %d", mem->penalty);
|
ast_str_append(&out, 0, " with penalty %d", mem->penalty);
|
||||||
if (mem->dynamic)
|
ast_str_append(&out, 0, "%s%s (%s)",
|
||||||
ast_build_string(&max, &max_left, " (dynamic)");
|
mem->dynamic ? " (dynamic)" : "",
|
||||||
if (mem->paused)
|
mem->paused ? " (paused)" : "",
|
||||||
ast_build_string(&max, &max_left, " (paused)");
|
devstate2str(mem->status));
|
||||||
ast_build_string(&max, &max_left, " (%s)", devstate2str(mem->status));
|
if (mem->calls)
|
||||||
if (mem->calls) {
|
ast_str_append(&out, 0, " has taken %d calls (last was %ld secs ago)",
|
||||||
ast_build_string(&max, &max_left, " has taken %d calls (last was %ld secs ago)",
|
|
||||||
mem->calls, (long) (time(NULL) - mem->lastcall));
|
mem->calls, (long) (time(NULL) - mem->lastcall));
|
||||||
} else
|
|
||||||
ast_build_string(&max, &max_left, " has taken no calls yet");
|
|
||||||
if (s)
|
|
||||||
astman_append(s, " %s%s%s", mem->interface, max_buf, term);
|
|
||||||
else
|
else
|
||||||
ast_cli(fd, " %s%s%s", mem->interface, max_buf, term);
|
ast_str_append(&out, 0, " has taken no calls yet");
|
||||||
|
do_print(s, fd, out->str);
|
||||||
}
|
}
|
||||||
} else if (s)
|
}
|
||||||
astman_append(s, " No Members%s", term);
|
if (!q->head)
|
||||||
else
|
do_print(s, fd, " No Callers");
|
||||||
ast_cli(fd, " No Members%s", term);
|
else {
|
||||||
if (q->head) {
|
struct queue_ent *qe;
|
||||||
pos = 1;
|
int pos = 1;
|
||||||
if (s)
|
|
||||||
astman_append(s, " Callers: %s", term);
|
do_print(s, fd, " Callers: ");
|
||||||
else
|
|
||||||
ast_cli(fd, " Callers: %s", term);
|
|
||||||
for (qe = q->head; qe; qe = qe->next) {
|
for (qe = q->head; qe; qe = qe->next) {
|
||||||
if (s)
|
ast_str_set(&out, 0, " %d. %s (wait: %ld:%2.2ld, prio: %d)",
|
||||||
astman_append(s, " %d. %s (wait: %ld:%2.2ld, prio: %d)%s",
|
|
||||||
pos++, qe->chan->name, (long) (now - qe->start) / 60,
|
pos++, qe->chan->name, (long) (now - qe->start) / 60,
|
||||||
(long) (now - qe->start) % 60, qe->prio, term);
|
(long) (now - qe->start) % 60, qe->prio);
|
||||||
else
|
do_print(s, fd, out->str);
|
||||||
ast_cli(fd, " %d. %s (wait: %ld:%2.2ld, prio: %d)%s", pos++,
|
|
||||||
qe->chan->name, (long) (now - qe->start) / 60,
|
|
||||||
(long) (now - qe->start) % 60, qe->prio, term);
|
|
||||||
}
|
}
|
||||||
} else if (s)
|
}
|
||||||
astman_append(s, " No Callers%s", term);
|
do_print(s, fd, ""); /* blank line between entries */
|
||||||
else
|
|
||||||
ast_cli(fd, " No Callers%s", term);
|
|
||||||
if (s)
|
|
||||||
astman_append(s, "%s", term);
|
|
||||||
else
|
|
||||||
ast_cli(fd, "%s", term);
|
|
||||||
ast_mutex_unlock(&q->lock);
|
ast_mutex_unlock(&q->lock);
|
||||||
if (queue_show)
|
if (argc == 3) /* print a specific entry */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
AST_LIST_UNLOCK(&queues);
|
AST_LIST_UNLOCK(&queues);
|
||||||
|
if (!found) {
|
||||||
|
if (argc == 3)
|
||||||
|
ast_str_set(&out, 0, "No such queue: %s.", argv[2]);
|
||||||
|
else
|
||||||
|
ast_str_set(&out, 0, "No queues.");
|
||||||
|
do_print(s, fd, out->str);
|
||||||
|
}
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int queue_show(int fd, int argc, char **argv)
|
static int queue_show(int fd, int argc, char **argv)
|
||||||
{
|
{
|
||||||
return __queues_show(NULL, 0, fd, argc, argv);
|
return __queues_show(NULL, fd, argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *complete_queue(const char *line, const char *word, int pos, int state)
|
static char *complete_queue(const char *line, const char *word, int pos, int state)
|
||||||
@@ -4198,7 +4164,7 @@ static int manager_queues_show( struct mansession *s, struct message *m )
|
|||||||
{
|
{
|
||||||
char *a[] = { "queue", "show" };
|
char *a[] = { "queue", "show" };
|
||||||
|
|
||||||
__queues_show(s, 1, -1, 2, a);
|
__queues_show(s, -1, 2, a);
|
||||||
astman_append(s, "\r\n\r\n"); /* Properly terminate Manager output */
|
astman_append(s, "\r\n\r\n"); /* Properly terminate Manager output */
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
|
|||||||
Reference in New Issue
Block a user