From a8aee0bbdb09f5cfb49802f0c3c09e741814045c Mon Sep 17 00:00:00 2001 From: George Joseph Date: Tue, 20 Oct 2015 15:02:30 -0600 Subject: res_pjsip: Add "like" processing to pjsip list and show commands Add the ability to filter output from pjsip list and show commands using the "like" predicate like chan_sip. For endpoints, aors, auths, registrations, identifyies and transports, the modification was a simple change of an ast_sorcery_retrieve_by_fields call to ast_sorcery_retrieve_by_regex. For channels and contacts a little more work had to be done because neither of those objects are true sorcery objects. That was just removing the non-matching object from the final container. Of course, a little extra plumbing in the common pjsip_cli code was needed to parse the "like" and pass the regex to the get_container callbacks. Some of the get_container code in res_pjsip_endpoint_identifier was also refactored for simplicity. ASTERISK-25477 #close Reported by: Bryant Zimmerman Tested by: George Joseph Change-Id: I646d9326b778aac26bb3e2bcd7fa1346d24434f1 --- res/res_pjsip/pjsip_cli.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'res/res_pjsip/pjsip_cli.c') diff --git a/res/res_pjsip/pjsip_cli.c b/res/res_pjsip/pjsip_cli.c index 16df3f59c..bbd0ac4b8 100644 --- a/res/res_pjsip/pjsip_cli.c +++ b/res/res_pjsip/pjsip_cli.c @@ -125,6 +125,7 @@ char *ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_ const char *cmd2; const char *object_id; char formatter_type[64]; + const char *regex; struct ast_sip_cli_context context = { .indent_level = 0, @@ -162,6 +163,18 @@ char *ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_ is_container = 1; } + if (cmd != CLI_GENERATE + && is_container + && a->argc >= 4 + && strcmp(object_id, "like") == 0) { + if (ast_strlen_zero(a->argv[4])) { + return CLI_SHOWUSAGE; + } + regex = a->argv[4]; + } else { + regex = ""; + } + if (cmd == CLI_GENERATE && (is_container || a->argc > 4 @@ -187,7 +200,7 @@ char *ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_ " =========================================================================================\n\n"); if (is_container || cmd == CLI_GENERATE) { - container = formatter_entry->get_container(); + container = formatter_entry->get_container(regex); if (!container) { ast_cli(a->fd, "No container returned for object type %s.\n", formatter_type); -- cgit v1.2.3