Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.336 diff -u -r1.336 chan_sip.c --- channels/chan_sip.c 19 Apr 2004 22:55:35 -0000 1.336 +++ channels/chan_sip.c 23 Apr 2004 21:07:48 -0000 @@ -4465,13 +4465,15 @@ #define FORMAT "%-15.15s %-15.15s %s %-15.15s %-8d %-10s\n" struct sip_peer *peer; char name[256] = ""; - if (argc != 3) + if (argc != 3 && argc != 5) return RESULT_SHOWUSAGE; ast_mutex_lock(&peerl.lock); ast_cli(fd, FORMAT2, "Name/username", "Host", " ", "Mask", "Port", "Status"); for (peer = peerl.peers;peer;peer = peer->next) { char nm[20] = ""; char status[20]; + int print_line = -1; + char srch[2000]; strncpy(nm, inet_ntoa(peer->mask), sizeof(nm)-1); if (strlen(peer->username)) snprintf(name, sizeof(name), "%s/%s", peer->name, peer->username); @@ -4488,11 +4490,31 @@ strcpy(status, "UNKNOWN"); } else strcpy(status, "Unmonitored"); + sprintf(srch, FORMAT, name, + peer->addr.sin_addr.s_addr ? inet_ntoa(peer->addr.sin_addr) : "(Unspecified)", + peer->dynamic ? "(D)" : " ", + nm, + ntohs(peer->addr.sin_port), status); + + if (argc == 5) { + if (!strcasecmp(argv[3],"include") && strstr(srch,argv[4])) { + print_line = -1; + } else if (!strcasecmp(argv[3],"exclude") && !strstr(srch,argv[4])) { + print_line = 1; + } else if (!strcasecmp(argv[3],"begin") && !strncasecmp(srch,argv[4],strlen(argv[4]))) { + print_line = -1; + } else { + print_line = 0; + } + } + + if (print_line) { ast_cli(fd, FORMAT, name, peer->addr.sin_addr.s_addr ? inet_ntoa(peer->addr.sin_addr) : "(Unspecified)", peer->dynamic ? "(D)" : " ", nm, ntohs(peer->addr.sin_port), status); + } } ast_mutex_unlock(&peerl.lock); return RESULT_SUCCESS; @@ -4905,6 +4927,12 @@ { { "sip", "show", "channel", NULL }, sip_show_channel, "Show detailed SIP channel info", show_channel_usage, complete_sipch }; static struct ast_cli_entry cli_show_peers = { { "sip", "show", "peers", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage }; +static struct ast_cli_entry cli_show_peers_include = + { { "sip", "show", "peers", "include", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage }; +static struct ast_cli_entry cli_show_peers_exclude = + { { "sip", "show", "peers", "exclude", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage }; +static struct ast_cli_entry cli_show_peers_begin = + { { "sip", "show", "peers", "begin", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage }; static struct ast_cli_entry cli_inuse_show = { { "sip", "show", "inuse", NULL }, sip_show_inuse, "List all inuse/limit", show_inuse_usage }; static struct ast_cli_entry cli_show_registry = @@ -6936,6 +6964,9 @@ ast_cli_register(&cli_show_channels); ast_cli_register(&cli_show_channel); ast_cli_register(&cli_show_peers); + ast_cli_register(&cli_show_peers_begin); + ast_cli_register(&cli_show_peers_include); + ast_cli_register(&cli_show_peers_exclude); ast_cli_register(&cli_show_registry); ast_cli_register(&cli_debug); ast_cli_register(&cli_no_debug); @@ -6970,6 +7001,9 @@ ast_cli_unregister(&cli_show_channels); ast_cli_unregister(&cli_show_channel); ast_cli_unregister(&cli_show_peers); + ast_cli_unregister(&cli_show_peers_include); + ast_cli_unregister(&cli_show_peers_exclude); + ast_cli_unregister(&cli_show_peers_begin); ast_cli_unregister(&cli_show_registry); ast_cli_unregister(&cli_debug); ast_cli_unregister(&cli_no_debug);