regex_t regexbuf;
int havepattern = FALSE;
struct sip_peer *peer;
- struct ao2_iterator i;
+ struct ao2_iterator* it_peers;
/* the last argument is left-aligned, so we don't need a size anyways */
#define FORMAT2 "%-25.25s %-39.39s %-3.3s %-10.10s %-3.3s %-8s %-11s %-32.32s %s\n"
const char *id;
char idtext[256] = "";
int realtimepeers;
- int objcount = ao2_container_count(peers);
struct sip_peer **peerarray;
int k;
realtimepeers = ast_check_realtime("sippeers");
- peerarray = ast_calloc(sizeof(struct sip_peer *), objcount);
if (s) { /* Manager - get ActionID */
id = astman_get_header(m, "ActionID");
return CLI_SHOWUSAGE;
}
- if (!s) /* Normal list */
+ if (!s) {
+ /* Normal list */
ast_cli(fd, FORMAT2, "Name/username", "Host", "Dyn", "Forcerport", "ACL", "Port", "Status", "Description", (realtimepeers ? "Realtime" : ""));
+ }
- i = ao2_iterator_init(peers, 0);
- while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) {
+ ao2_lock(peers);
+ if (!(it_peers = ao2_callback(peers, OBJ_MULTIPLE, NULL, NULL))) {
+ ast_log(AST_LOG_ERROR, "Unable to create iterator for peers container for sip show peers\n");
+ ao2_unlock(peers);
+ return CLI_FAILURE;
+ }
+ if (!(peerarray = ast_calloc(sizeof(struct sip_peer *), ao2_container_count(peers)))) {
+ ast_log(AST_LOG_ERROR, "Unable to allocate peer array for sip show peers\n");
+ ao2_iterator_destroy(it_peers);
+ ao2_unlock(peers);
+ return CLI_FAILURE;
+ }
+ ao2_unlock(peers);
+
+ while ((peer = ao2_t_iterator_next(it_peers, "iterate thru peers table"))) {
ao2_lock(peer);
if (!(peer->type & SIP_TYPE_PEER)) {
}
if (havepattern && regexec(®exbuf, peer->name, 0, NULL, 0)) {
- objcount--;
ao2_unlock(peer);
sip_unref_peer(peer, "toss iterator peer ptr before continue");
continue;
peerarray[total_peers++] = peer;
ao2_unlock(peer);
}
- ao2_iterator_destroy(&i);
+ ao2_iterator_destroy(it_peers);
qsort(peerarray, total_peers, sizeof(struct sip_peer *), peercomparefunc);