<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Dec 2, 2014 at 8:29 AM, Matthew Jordan <span dir="ltr"><<a href="mailto:mjordan@digium.com" target="_blank" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=mjordan@digium.com&cc=&bcc=&su=&body=','_blank','location=yes,menubar=yes,resizable=yes,width=800,height=600');return false;">mjordan@digium.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey George -<br>
<br>
This should have been caught in the review, but do you mind updating<br>
the CHANGES notes to reflect the addition of the CLI command?<br>
<br>
Thanks!<br>
<br></blockquote><div><br></div><div>Will do.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Mon, Dec 1, 2014 at 5:55 PM, SVN commits to the Asterisk project<br>
<<a href="mailto:asterisk-commits@lists.digium.com" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=asterisk-commits@lists.digium.com&cc=&bcc=&su=&body=','_blank','location=yes,menubar=yes,resizable=yes,width=800,height=600');return false;">asterisk-commits@lists.digium.com</a>> wrote:<br>
> Author: gtjoseph<br>
> Date: Mon Dec 1 17:55:05 2014<br>
> New Revision: 428725<br>
><br>
> URL: <a href="http://svnview.digium.com/svn/asterisk?view=rev&rev=428725" target="_blank">http://svnview.digium.com/svn/asterisk?view=rev&rev=428725</a><br>
> Log:<br>
> res_pjsip_endpoint_identifier_ip: Add 'show identify(ies)' cli commands<br>
><br>
> While troubleshooting other things I realized there were no pjsip cli<br>
> commands for identify. This patch adds them. It also also fixes a<br>
> reference leak when a 'show endpoint' displayed identifies and properly<br>
> sets the return code if load_module can't allocate a cli formatter structure.<br>
><br>
> Tested-by: George Joseph<br>
><br>
> Review: <a href="https://reviewboard.asterisk.org/r/4212/" target="_blank">https://reviewboard.asterisk.org/r/4212/</a><br>
><br>
><br>
> Modified:<br>
> branches/12/res/res_pjsip/pjsip_cli.c<br>
> branches/12/res/res_pjsip_endpoint_identifier_ip.c<br>
><br>
> Modified: branches/12/res/res_pjsip/pjsip_cli.c<br>
> URL: <a href="http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip/pjsip_cli.c?view=diff&rev=428725&r1=428724&r2=428725" target="_blank">http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip/pjsip_cli.c?view=diff&rev=428725&r1=428724&r2=428725</a><br>
> ==============================================================================<br>
> --- branches/12/res/res_pjsip/pjsip_cli.c (original)<br>
> +++ branches/12/res/res_pjsip/pjsip_cli.c Mon Dec 1 17:55:05 2014<br>
> @@ -144,6 +144,11 @@<br>
> if (!ast_ends_with(cmd2, "s")) {<br>
> ast_copy_string(formatter_type, cmd2, sizeof(formatter_type));<br>
> is_container = 0;<br>
> + } else if (ast_ends_with(cmd2, "ies")) {<br>
> + /* Take the plural "ies" off of the object name and re[place with "y". */<br>
> + int l = strlen(cmd2);<br>
> + snprintf(formatter_type, 64, "%*.*sy", l - 3, l - 3, cmd2);<br>
> + is_container = 1;<br>
> } else {<br>
> /* Take the plural "s" off of the object name. */<br>
> ast_copy_string(formatter_type, cmd2, strlen(cmd2));<br>
><br>
> Modified: branches/12/res/res_pjsip_endpoint_identifier_ip.c<br>
> URL: <a href="http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip_endpoint_identifier_ip.c?view=diff&rev=428725&r1=428724&r2=428725" target="_blank">http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip_endpoint_identifier_ip.c?view=diff&rev=428725&r1=428724&r2=428725</a><br>
> ==============================================================================<br>
> --- branches/12/res/res_pjsip_endpoint_identifier_ip.c (original)<br>
> +++ branches/12/res/res_pjsip_endpoint_identifier_ip.c Mon Dec 1 17:55:05 2014<br>
> @@ -323,6 +323,7 @@<br>
> }<br>
><br>
> ao2_callback(identifies, OBJ_NODATA, callback, args);<br>
> + ao2_cleanup(identifies);<br>
><br>
> return 0;<br>
> }<br>
> @@ -379,13 +380,25 @@<br>
> {<br>
> struct ast_sip_cli_context *context = arg;<br>
> int indent = CLI_INDENT_TO_SPACES(context->indent_level);<br>
> - int filler = CLI_MAX_WIDTH - indent - 14;<br>
> + int filler = CLI_MAX_WIDTH - indent - 22;<br>
><br>
> ast_assert(context->output_buffer != NULL);<br>
><br>
> ast_str_append(&context->output_buffer, 0,<br>
> - "%*s: <MatchList%*.*s>\n",<br>
> + "%*s: <Identify/Endpoint%*.*s>\n",<br>
> indent, "Identify", filler, filler, CLI_HEADER_FILLER);<br>
> +<br>
> + if (context->recurse) {<br>
> + context->indent_level++;<br>
> + indent = CLI_INDENT_TO_SPACES(context->indent_level);<br>
> + filler = CLI_LAST_TABSTOP - indent - 24;<br>
> +<br>
> + ast_str_append(&context->output_buffer, 0,<br>
> + "%*s: <ip/cidr%*.*s>\n",<br>
> + indent, "Match", filler, filler, CLI_HEADER_FILLER);<br>
> +<br>
> + context->indent_level--;<br>
> + }<br>
><br>
> return 0;<br>
> }<br>
> @@ -395,16 +408,70 @@<br>
> RAII_VAR(struct ast_str *, str, ast_str_create(MAX_OBJECT_FIELD), ast_free);<br>
> struct ip_identify_match *ident = obj;<br>
> struct ast_sip_cli_context *context = arg;<br>
> + struct ast_ha *match;<br>
> + int indent;<br>
><br>
> ast_assert(context->output_buffer != NULL);<br>
><br>
> - ast_str_append(&context->output_buffer, 0, "%*s: ",<br>
> - CLI_INDENT_TO_SPACES(context->indent_level), "Identify");<br>
> - ast_ha_join_cidr(ident->matches, &str);<br>
> - ast_str_append(&context->output_buffer, 0, "%s\n", ast_str_buffer(str));<br>
> -<br>
> - return 0;<br>
> -}<br>
> + ast_str_append(&context->output_buffer, 0, "%*s: %s/%s\n",<br>
> + CLI_INDENT_TO_SPACES(context->indent_level), "Identify",<br>
> + ast_sorcery_object_get_id(ident), ident->endpoint_name);<br>
> +<br>
> + if (context->recurse) {<br>
> + context->indent_level++;<br>
> + indent = CLI_INDENT_TO_SPACES(context->indent_level);<br>
> +<br>
> + for (match = ident->matches; match; match = match->next) {<br>
> + const char *addr = ast_sockaddr_stringify_addr(&match->addr);<br>
> +<br>
> + ast_str_append(&context->output_buffer, 0, "%*s: %s%s/%d\n",<br>
> + indent,<br>
> + "Match",<br>
> + match->sense == AST_SENSE_ALLOW ? "!" : "",<br>
> + addr, ast_sockaddr_cidr_bits(&match->netmask));<br>
> + }<br>
> +<br>
> + context->indent_level--;<br>
> +<br>
> + if (context->indent_level == 0) {<br>
> + ast_str_append(&context->output_buffer, 0, "\n");<br>
> + }<br>
> + }<br>
> +<br>
> + if (context->show_details<br>
> + || (context->show_details_only_level_0 && context->indent_level == 0)) {<br>
> + ast_str_append(&context->output_buffer, 0, "\n");<br>
> + ast_sip_cli_print_sorcery_objectset(ident, context, 0);<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +/*<br>
> + * A function pointer to callback needs to be within the<br>
> + * module in order to avoid problems with an undefined<br>
> + * symbol when the module is loaded.<br>
> + */<br>
> +static char *my_cli_traverse_objects(struct ast_cli_entry *e, int cmd,<br>
> + struct ast_cli_args *a)<br>
> +{<br>
> + return ast_sip_cli_traverse_objects(e, cmd, a);<br>
> +}<br>
> +<br>
> +static struct ast_cli_entry cli_identify[] = {<br>
> +AST_CLI_DEFINE(my_cli_traverse_objects, "List PJSIP Identifies",<br>
> + .command = "pjsip list identifies",<br>
> + .usage = "Usage: pjsip list identifies\n"<br>
> + " List the configured PJSIP Identifies\n"),<br>
> +AST_CLI_DEFINE(my_cli_traverse_objects, "Show PJSIP Identifies",<br>
> + .command = "pjsip show identifies",<br>
> + .usage = "Usage: pjsip show identifies\n"<br>
> + " Show the configured PJSIP Identifies\n"),<br>
> +AST_CLI_DEFINE(my_cli_traverse_objects, "Show PJSIP Identify",<br>
> + .command = "pjsip show identify",<br>
> + .usage = "Usage: pjsip show identify <id>\n"<br>
> + " Show the configured PJSIP Identify\n"),<br>
> +};<br>
><br>
> static struct ast_sip_cli_formatter_entry *cli_formatter;<br>
><br>
> @@ -430,7 +497,7 @@<br>
> cli_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL);<br>
> if (!cli_formatter) {<br>
> ast_log(LOG_ERROR, "Unable to allocate memory for cli formatter\n");<br>
> - return -1;<br>
> + return AST_MODULE_LOAD_DECLINE;<br>
> }<br>
> cli_formatter->name = "identify";<br>
> cli_formatter->print_header = cli_print_header;<br>
> @@ -441,6 +508,7 @@<br>
> cli_formatter->retrieve_by_id = cli_retrieve_by_id;<br>
><br>
> ast_sip_register_cli_formatter(cli_formatter);<br>
> + ast_cli_register_multiple(cli_identify, ARRAY_LEN(cli_identify));<br>
><br>
> return AST_MODULE_LOAD_SUCCESS;<br>
> }<br>
> @@ -454,6 +522,7 @@<br>
><br>
> static int unload_module(void)<br>
> {<br>
> + ast_cli_unregister_multiple(cli_identify, ARRAY_LEN(cli_identify));<br>
> ast_sip_unregister_cli_formatter(cli_formatter);<br>
> ast_sip_unregister_endpoint_formatter(&endpoint_identify_formatter);<br>
> ast_sip_unregister_endpoint_identifier(&ip_identifier);<br>
><br>
><br>
> --<br>
> _____________________________________________________________________<br>
> -- Bandwidth and Colocation Provided by <a href="http://www.api-digital.com" target="_blank">http://www.api-digital.com</a> --<br>
><br>
> asterisk-commits mailing list<br>
> To UNSUBSCRIBE or update options visit:<br>
> <a href="http://lists.digium.com/mailman/listinfo/asterisk-commits" target="_blank">http://lists.digium.com/mailman/listinfo/asterisk-commits</a><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Matthew Jordan<br>
Digium, Inc. | Engineering Manager<br>
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA<br>
Check us out at: <a href="http://digium.com" target="_blank">http://digium.com</a> & <a href="http://asterisk.org" target="_blank">http://asterisk.org</a><br>
<br>
--<br>
_____________________________________________________________________<br>
-- Bandwidth and Colocation Provided by <a href="http://www.api-digital.com" target="_blank">http://www.api-digital.com</a> --<br>
<br>
asterisk-dev mailing list<br>
To UNSUBSCRIBE or update options visit:<br>
<a href="http://lists.digium.com/mailman/listinfo/asterisk-dev" target="_blank">http://lists.digium.com/mailman/listinfo/asterisk-dev</a><br>
</font></span></blockquote></div><br></div></div>