Changes to list peers and users in alpha. order, as per a reasonable request in 12494. Due to changes in trunk to use the astobj2 i/f in the sip channel driver, the order of the entries in the config file was lost, thus the output was in a random order, but no longer.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@123448 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.1
Steve Murphy 17 years ago
parent c23e5fea96
commit bb20ef7017

@ -121,6 +121,9 @@ SIP Changes
lost packets. lost packets.
* Added t38pt_usertpsource option. See sip.conf.sample for details. * Added t38pt_usertpsource option. See sip.conf.sample for details.
* Added SIPnotify AMI command, for sending arbitrary SIP notify commands. * Added SIPnotify AMI command, for sending arbitrary SIP notify commands.
* 'sip show peers' and 'sip show users' display their entries sorted in
alphabetical order, as opposed to the order they were in, in the config
file or database.
IAX Changes IAX Changes
----------- -----------

@ -12408,14 +12408,30 @@ static char *sip_show_tcp(struct ast_cli_entry *e, int cmd, struct ast_cli_args
#undef FORMAT2 #undef FORMAT2
} }
int usercomparefunc(const void *a, const void *b);
int usercomparefunc(const void *a, const void *b)
{
struct sip_user **ap = (struct sip_user **)a;
struct sip_user **bp = (struct sip_user **)b;
return strcmp((*ap)->name, (*bp)->name);
}
/*! \brief CLI Command 'SIP Show Users' */ /*! \brief CLI Command 'SIP Show Users' */
static char *sip_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) static char *sip_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{ {
regex_t regexbuf; regex_t regexbuf;
int havepattern = FALSE; int havepattern = FALSE;
int count = 0; int count = 0;
int totcount = 0;
struct sip_user *user; struct sip_user *user;
struct ao2_iterator i; struct ao2_iterator i;
int objcount = ao2_container_count(users);
struct sip_user **userarray;
int k;
userarray = ast_calloc(sizeof(struct sip_user *), objcount);
#define FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n" #define FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n"
@ -12451,13 +12467,22 @@ static char *sip_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
while ((user = ao2_t_iterator_next(&i, "iterate thru user table"))) { while ((user = ao2_t_iterator_next(&i, "iterate thru user table"))) {
ao2_lock(user); ao2_lock(user);
count++; totcount++;
if (havepattern && regexec(&regexbuf, user->name, 0, NULL, 0)) { if (havepattern && regexec(&regexbuf, user->name, 0, NULL, 0)) {
ao2_unlock(user); ao2_unlock(user);
unref_user(user, "toss iterator pointer via a continue in iterator loop"); unref_user(user, "toss iterator pointer via a continue in iterator loop");
continue; continue;
} }
userarray[count++] = user;
ao2_unlock(user);
}
qsort(userarray, count, sizeof(struct sip_user *), usercomparefunc);
for(k=0; k < count; k++) {
user = userarray[k];
ao2_lock(user);
ast_cli(a->fd, FORMAT, user->name, ast_cli(a->fd, FORMAT, user->name,
user->secret, user->secret,
user->accountcode, user->accountcode,
@ -12470,8 +12495,12 @@ static char *sip_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
if (havepattern) if (havepattern)
regfree(&regexbuf); regfree(&regexbuf);
ast_cli(a->fd, "Total of %d user entries\n", count); if (havepattern)
ast_cli(a->fd, "Total %d of %d user entries\n", count, totcount);
else
ast_cli(a->fd, "Total of %d user entries\n", totcount);
ast_free(userarray);
return CLI_SUCCESS; return CLI_SUCCESS;
#undef FORMAT #undef FORMAT
} }
@ -12864,6 +12893,16 @@ static char *_sip_dbdump(int fd, int *total, struct mansession *s, const struct
return CLI_SUCCESS; return CLI_SUCCESS;
} }
int peercomparefunc(const void *a, const void *b);
int peercomparefunc(const void *a, const void *b)
{
struct sip_peer **ap = (struct sip_peer **)a;
struct sip_peer **bp = (struct sip_peer **)b;
return strcmp((*ap)->name, (*bp)->name);
}
/*! \brief Execute sip show peers command */ /*! \brief Execute sip show peers command */
static char *_sip_show_peers(int fd, int *total, struct mansession *s, const struct message *m, int argc, const char *argv[]) static char *_sip_show_peers(int fd, int *total, struct mansession *s, const struct message *m, int argc, const char *argv[])
{ {
@ -12885,8 +12924,13 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
const char *id; const char *id;
char idtext[256] = ""; char idtext[256] = "";
int realtimepeers; int realtimepeers;
int objcount = ao2_container_count(peers);
struct sip_peer **peerarray;
int k;
realtimepeers = ast_check_realtime("sippeers"); realtimepeers = ast_check_realtime("sippeers");
peerarray = ast_calloc(sizeof(struct sip_peer *), objcount);
if (s) { /* Manager - get ActionID */ if (s) { /* Manager - get ActionID */
id = astman_get_header(m, "ActionID"); id = astman_get_header(m, "ActionID");
@ -12911,11 +12955,28 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
if (!s) /* Normal list */ if (!s) /* Normal list */
ast_cli(fd, FORMAT2, "Name/username", "Host", "Dyn", "Nat", "ACL", "Port", "Status", (realtimepeers ? "Realtime" : "")); ast_cli(fd, FORMAT2, "Name/username", "Host", "Dyn", "Nat", "ACL", "Port", "Status", (realtimepeers ? "Realtime" : ""));
i = ao2_iterator_init(peers, 0); i = ao2_iterator_init(peers, 0);
while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) { while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) {
ao2_lock(peer);
if (havepattern && regexec(&regexbuf, peer->name, 0, NULL, 0)) {
objcount--;
ao2_unlock(peer);
unref_peer(peer, "toss iterator peer ptr before continue");
continue;
}
peerarray[total_peers++] = peer;
ao2_unlock(peer);
}
qsort(peerarray, total_peers, sizeof(struct sip_peer *), peercomparefunc);
for(k=0; k < total_peers; k++) {
char status[20] = ""; char status[20] = "";
char srch[2000]; char srch[2000];
char pstatus; char pstatus;
peer = peerarray[k];
ao2_lock(peer); ao2_lock(peer);
if (havepattern && regexec(&regexbuf, peer->name, 0, NULL, 0)) { if (havepattern && regexec(&regexbuf, peer->name, 0, NULL, 0)) {
@ -12986,8 +13047,6 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
status, status,
realtimepeers ? (peer->is_realtime ? "yes":"no") : "no"); realtimepeers ? (peer->is_realtime ? "yes":"no") : "no");
} }
total_peers++;
ao2_unlock(peer); ao2_unlock(peer);
unref_peer(peer, "toss iterator peer ptr"); unref_peer(peer, "toss iterator peer ptr");
} }
@ -13002,6 +13061,7 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
if (total) if (total)
*total = total_peers; *total = total_peers;
ast_free(peerarray);
return CLI_SUCCESS; return CLI_SUCCESS;
#undef FORMAT #undef FORMAT

Loading…
Cancel
Save