Fix queue, iax and sip formatting issues (bug #5449)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6811 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.2-netsec
Mark Spencer 20 years ago
parent a863d2b280
commit 4e919f337c

@ -3181,7 +3181,7 @@ static void reload_queues(void)
ast_mutex_unlock(&qlock); ast_mutex_unlock(&qlock);
} }
static int __queues_show(int fd, int argc, char **argv, int queue_show) static int __queues_show(int manager, int fd, int argc, char **argv, int queue_show)
{ {
struct ast_call_queue *q; struct ast_call_queue *q;
struct queue_ent *qe; struct queue_ent *qe;
@ -3192,6 +3192,7 @@ static int __queues_show(int fd, int argc, char **argv, int queue_show)
char *max; char *max;
size_t max_left; size_t max_left;
float sl = 0; float sl = 0;
char *term = manager ? "\r\n" : "\n";
time(&now); time(&now);
if ((!queue_show && argc != 2) || (queue_show && argc != 3)) if ((!queue_show && argc != 2) || (queue_show && argc != 3))
@ -3201,9 +3202,9 @@ static int __queues_show(int fd, int argc, char **argv, int queue_show)
if (!q) { if (!q) {
ast_mutex_unlock(&qlock); ast_mutex_unlock(&qlock);
if (queue_show) if (queue_show)
ast_cli(fd, "No such queue: %s.\n",argv[2]); ast_cli(fd, "No such queue: %s.%s",argv[2], term);
else else
ast_cli(fd, "No queues.\n"); ast_cli(fd, "No queues.%s", term);
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
while (q) { while (q) {
@ -3213,7 +3214,7 @@ static int __queues_show(int fd, int argc, char **argv, int queue_show)
ast_mutex_unlock(&q->lock); ast_mutex_unlock(&q->lock);
q = q->next; q = q->next;
if (!q) { if (!q) {
ast_cli(fd, "No such queue: %s.\n",argv[2]); ast_cli(fd, "No such queue: %s.%s",argv[2], term);
break; break;
} }
continue; continue;
@ -3229,10 +3230,10 @@ static int __queues_show(int fd, int argc, char **argv, int queue_show)
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);
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", 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",
q->name, q->count, max_buf, int2strat(q->strategy), q->holdtime, q->weight, q->callscompleted, q->callsabandoned,sl,q->servicelevel); q->name, q->count, max_buf, int2strat(q->strategy), q->holdtime, q->weight, q->callscompleted, q->callsabandoned,sl,q->servicelevel, term);
if (q->members) { if (q->members) {
ast_cli(fd, " Members: \n"); 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'; max_buf[0] = '\0';
max = max_buf; max = max_buf;
@ -3249,19 +3250,19 @@ static int __queues_show(int fd, int argc, char **argv, int queue_show)
mem->calls, (long)(time(NULL) - mem->lastcall)); mem->calls, (long)(time(NULL) - mem->lastcall));
} else } else
ast_build_string(&max, &max_left, " has taken no calls yet"); ast_build_string(&max, &max_left, " has taken no calls yet");
ast_cli(fd, " %s%s\n", mem->interface, max_buf); ast_cli(fd, " %s%s%s", mem->interface, max_buf, term);
} }
} else } else
ast_cli(fd, " No Members\n"); ast_cli(fd, " No Members%s", term);
if (q->head) { if (q->head) {
pos = 1; pos = 1;
ast_cli(fd, " Callers: \n"); ast_cli(fd, " Callers: %s", term);
for (qe = q->head; qe; qe = qe->next) for (qe = q->head; qe; qe = qe->next)
ast_cli(fd, " %d. %s (wait: %ld:%2.2ld, prio: %d)\n", pos++, qe->chan->name, 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); (long)(now - qe->start) / 60, (long)(now - qe->start) % 60, qe->prio, term);
} else } else
ast_cli(fd, " No Callers\n"); ast_cli(fd, " No Callers%s", term);
ast_cli(fd, "\n"); ast_cli(fd, "%s", term);
ast_mutex_unlock(&q->lock); ast_mutex_unlock(&q->lock);
q = q->next; q = q->next;
if (queue_show) if (queue_show)
@ -3273,12 +3274,12 @@ static int __queues_show(int fd, int argc, char **argv, int queue_show)
static int queues_show(int fd, int argc, char **argv) static int queues_show(int fd, int argc, char **argv)
{ {
return __queues_show(fd, argc, argv, 0); return __queues_show(0, fd, argc, argv, 0);
} }
static int queue_show(int fd, int argc, char **argv) static int queue_show(int fd, int argc, char **argv)
{ {
return __queues_show(fd, argc, argv, 1); return __queues_show(0, fd, argc, argv, 1);
} }
static char *complete_queue(char *line, char *word, int pos, int state) static char *complete_queue(char *line, char *word, int pos, int state)
@ -3301,7 +3302,7 @@ static char *complete_queue(char *line, char *word, int pos, int state)
static int manager_queues_show( struct mansession *s, struct message *m ) static int manager_queues_show( struct mansession *s, struct message *m )
{ {
char *a[] = { "show", "queues" }; char *a[] = { "show", "queues" };
queues_show(s->fd, 2, a); __queues_show(1, s->fd, 2, a, 0);
ast_cli(s->fd, "\r\n\r\n"); /* Properly terminate Manager output */ ast_cli(s->fd, "\r\n\r\n"); /* Properly terminate Manager output */
return RESULT_SUCCESS; return RESULT_SUCCESS;

@ -4114,7 +4114,7 @@ static int iax2_show_users(int fd, int argc, char *argv[])
#undef FORMAT2 #undef FORMAT2
} }
static int iax2_show_peers(int fd, int argc, char *argv[]) static int __iax2_show_peers(int manager, int fd, int argc, char *argv[])
{ {
regex_t regexbuf; regex_t regexbuf;
int havepattern = 0; int havepattern = 0;
@ -4123,13 +4123,14 @@ static int iax2_show_peers(int fd, int argc, char *argv[])
int offline_peers = 0; int offline_peers = 0;
int unmonitored_peers = 0; int unmonitored_peers = 0;
#define FORMAT2 "%-15.15s %-15.15s %s %-15.15s %-8s %s %-10s\n" #define FORMAT2 "%-15.15s %-15.15s %s %-15.15s %-8s %s %-10s%s"
#define FORMAT "%-15.15s %-15.15s %s %-15.15s %-5d%s %s %-10s\n" #define FORMAT "%-15.15s %-15.15s %s %-15.15s %-5d%s %s %-10s%s"
struct iax2_peer *peer; struct iax2_peer *peer;
char name[256]; char name[256];
char iabuf[INET_ADDRSTRLEN]; char iabuf[INET_ADDRSTRLEN];
int registeredonly=0; int registeredonly=0;
char *term = manager ? "\r\n" : "\n";
switch (argc) { switch (argc) {
case 6: case 6:
@ -4165,7 +4166,7 @@ static int iax2_show_peers(int fd, int argc, char *argv[])
} }
ast_mutex_lock(&peerl.lock); ast_mutex_lock(&peerl.lock);
ast_cli(fd, FORMAT2, "Name/Username", "Host", " ", "Mask", "Port", " ", "Status"); ast_cli(fd, FORMAT2, "Name/Username", "Host", " ", "Mask", "Port", " ", "Status", term);
for (peer = peerl.peers;peer;peer = peer->next) { for (peer = peerl.peers;peer;peer = peer->next) {
char nm[20]; char nm[20];
char status[20]; char status[20];
@ -4208,19 +4209,19 @@ static int iax2_show_peers(int fd, int argc, char *argv[])
ast_test_flag(peer, IAX_DYNAMIC) ? "(D)" : "(S)", ast_test_flag(peer, IAX_DYNAMIC) ? "(D)" : "(S)",
nm, nm,
ntohs(peer->addr.sin_port), ast_test_flag(peer, IAX_TRUNK) ? "(T)" : " ", ntohs(peer->addr.sin_port), ast_test_flag(peer, IAX_TRUNK) ? "(T)" : " ",
peer->encmethods ? "(E)" : " ", status); peer->encmethods ? "(E)" : " ", status, term);
ast_cli(fd, FORMAT, name, ast_cli(fd, FORMAT, name,
peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)",
ast_test_flag(peer, IAX_DYNAMIC) ? "(D)" : "(S)", ast_test_flag(peer, IAX_DYNAMIC) ? "(D)" : "(S)",
nm, nm,
ntohs(peer->addr.sin_port), ast_test_flag(peer, IAX_TRUNK) ? "(T)" : " ", ntohs(peer->addr.sin_port), ast_test_flag(peer, IAX_TRUNK) ? "(T)" : " ",
peer->encmethods ? "(E)" : " ", status); peer->encmethods ? "(E)" : " ", status, term);
total_peers++; total_peers++;
} }
ast_mutex_unlock(&peerl.lock); ast_mutex_unlock(&peerl.lock);
ast_cli(fd,"%d iax2 peers [%d online, %d offline, %d unmonitored]\n", total_peers, online_peers, offline_peers, unmonitored_peers); ast_cli(fd,"%d iax2 peers [%d online, %d offline, %d unmonitored]%s", total_peers, online_peers, offline_peers, unmonitored_peers, term);
if (havepattern) if (havepattern)
regfree(&regexbuf); regfree(&regexbuf);
@ -4230,6 +4231,10 @@ static int iax2_show_peers(int fd, int argc, char *argv[])
#undef FORMAT2 #undef FORMAT2
} }
static int iax2_show_peers(int fd, int argc, char *argv[])
{
return __iax2_show_peers(0, fd, argc, argv);
}
static int manager_iax2_show_netstats( struct mansession *s, struct message *m ) static int manager_iax2_show_netstats( struct mansession *s, struct message *m )
{ {
ast_cli_netstats(s->fd, 0); ast_cli_netstats(s->fd, 0);
@ -4267,8 +4272,12 @@ static int manager_iax2_show_peers( struct mansession *s, struct message *m )
{ {
char *a[] = { "iax2", "show", "users" }; char *a[] = { "iax2", "show", "users" };
int ret; int ret;
ret = iax2_show_peers( s->fd, 3, a ); char *id;
ast_cli( s->fd, "\r\n\r\n" ); id = astman_get_header(m,"ActionID");
if (id && !ast_strlen_zero(id))
ast_cli(s->fd, "ActionID: %s\r\n",id);
ret = __iax2_show_peers(1, s->fd, 3, a );
ast_cli(s->fd, "\r\n\r\n" );
return ret; return ret;
} /* /JDG */ } /* /JDG */

@ -7541,10 +7541,10 @@ static int sip_show_objects(int fd, int argc, char *argv[])
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
/*--- print_group: Print call group and pickup group ---*/ /*--- print_group: Print call group and pickup group ---*/
static void print_group(int fd, unsigned int group) static void print_group(int fd, unsigned int group, int crlf)
{ {
char buf[256]; char buf[256];
ast_cli(fd, "%s\n", ast_print_group(buf, sizeof(buf), group) ); ast_cli(fd, crlf ? "%s\r\n" : "%s\n", ast_print_group(buf, sizeof(buf), group) );
} }
/*--- dtmfmode2str: Convert DTMF mode to printable string ---*/ /*--- dtmfmode2str: Convert DTMF mode to printable string ---*/
@ -7865,9 +7865,9 @@ static int _sip_show_peer(int type, int fd, struct mansession *s, struct message
if (!ast_strlen_zero(peer->fromdomain)) if (!ast_strlen_zero(peer->fromdomain))
ast_cli(fd, " FromDomain : %s\n", peer->fromdomain); ast_cli(fd, " FromDomain : %s\n", peer->fromdomain);
ast_cli(fd, " Callgroup : "); ast_cli(fd, " Callgroup : ");
print_group(fd, peer->callgroup); print_group(fd, peer->callgroup, 0);
ast_cli(fd, " Pickupgroup : "); ast_cli(fd, " Pickupgroup : ");
print_group(fd, peer->pickupgroup); print_group(fd, peer->pickupgroup, 0);
ast_cli(fd, " Mailbox : %s\n", peer->mailbox); ast_cli(fd, " Mailbox : %s\n", peer->mailbox);
ast_cli(fd, " VM Extension : %s\n", peer->vmexten); ast_cli(fd, " VM Extension : %s\n", peer->vmexten);
ast_cli(fd, " LastMsgsSent : %d\n", peer->lastmsgssent); ast_cli(fd, " LastMsgsSent : %d\n", peer->lastmsgssent);
@ -7942,9 +7942,9 @@ static int _sip_show_peer(int type, int fd, struct mansession *s, struct message
if (!ast_strlen_zero(peer->fromdomain)) if (!ast_strlen_zero(peer->fromdomain))
ast_cli(fd, "SIP-FromDomain: %s\r\n", peer->fromdomain); ast_cli(fd, "SIP-FromDomain: %s\r\n", peer->fromdomain);
ast_cli(fd, "Callgroup: "); ast_cli(fd, "Callgroup: ");
print_group(fd, peer->callgroup); print_group(fd, peer->callgroup, 1);
ast_cli(fd, "Pickupgroup: "); ast_cli(fd, "Pickupgroup: ");
print_group(fd, peer->pickupgroup); print_group(fd, peer->pickupgroup, 1);
ast_cli(fd, "VoiceMailbox: %s\r\n", peer->mailbox); ast_cli(fd, "VoiceMailbox: %s\r\n", peer->mailbox);
ast_cli(fd, "LastMsgsSent: %d\r\n", peer->lastmsgssent); ast_cli(fd, "LastMsgsSent: %d\r\n", peer->lastmsgssent);
ast_cli(fd, "Call limit: %d\r\n", peer->call_limit); ast_cli(fd, "Call limit: %d\r\n", peer->call_limit);
@ -8031,9 +8031,9 @@ static int sip_show_user(int fd, int argc, char *argv[])
ast_cli(fd, " CallingPres : %s\n", ast_describe_caller_presentation(user->callingpres)); ast_cli(fd, " CallingPres : %s\n", ast_describe_caller_presentation(user->callingpres));
ast_cli(fd, " Call limit : %d\n", user->call_limit); ast_cli(fd, " Call limit : %d\n", user->call_limit);
ast_cli(fd, " Callgroup : "); ast_cli(fd, " Callgroup : ");
print_group(fd, user->callgroup); print_group(fd, user->callgroup, 0);
ast_cli(fd, " Pickupgroup : "); ast_cli(fd, " Pickupgroup : ");
print_group(fd, user->pickupgroup); print_group(fd, user->pickupgroup, 0);
ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), user->cid_name, user->cid_num, "<unspecified>")); ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), user->cid_name, user->cid_num, "<unspecified>"));
ast_cli(fd, " ACL : %s\n", (user->ha?"Yes":"No")); ast_cli(fd, " ACL : %s\n", (user->ha?"Yes":"No"));
ast_cli(fd, " Codec Order : ("); ast_cli(fd, " Codec Order : (");

Loading…
Cancel
Save