<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/20459">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">vty/command: introduce a command to list attributes<br><br>Here is an example of listing all attributes:<br><br>  OsmoBSC# show vty-attributes<br>    Global attributes:<br>      .  This command is deprecated<br>      .  This command is hidden<br>      .  This command applies immediately<br>      .  This command applies on VTY node exit<br>    Library specific attributes:<br>      (no attributes)<br>    Application specific attributes:<br>      o  This command applies on A-bis OML link (re)establishment<br>      r  This command applies on A-bis RSL link (re)establishment<br><br>or only a specific kind of attributes:<br><br>  OsmoBSC# show vty-attributes application<br>    Application specific attributes:<br>      o  This command applies on A-bis OML link (re)establishment<br>      r  This command applies on A-bis RSL link (re)establishment<br><br>Change-Id: I561114d7416e30cc06b7d49c0bc1217a76039c99<br>Related: SYS#4937<br>---<br>M src/vty/command.c<br>1 file changed, 97 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/vty/command.c b/src/vty/command.c</span><br><span>index faad9fe..46fe854 100644</span><br><span>--- a/src/vty/command.c</span><br><span>+++ b/src/vty/command.c</span><br><span>@@ -2948,6 +2948,96 @@</span><br><span>   return CMD_SUCCESS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+enum {</span><br><span style="color: hsl(120, 100%, 40%);">+  ATTR_TYPE_GLOBAL        = (1 << 0),</span><br><span style="color: hsl(120, 100%, 40%);">+     ATTR_TYPE_LIB           = (1 << 1),</span><br><span style="color: hsl(120, 100%, 40%);">+     ATTR_TYPE_APP           = (1 << 2),</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void print_attr_list(struct vty *vty, unsigned int attr_mask)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      const char *desc;</span><br><span style="color: hsl(120, 100%, 40%);">+     unsigned int i;</span><br><span style="color: hsl(120, 100%, 40%);">+       bool found;</span><br><span style="color: hsl(120, 100%, 40%);">+   char flag;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  if (attr_mask & ATTR_TYPE_GLOBAL) {</span><br><span style="color: hsl(120, 100%, 40%);">+               vty_out(vty, "  Global attributes:%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+              for (i = 0; i < ARRAY_SIZE(cmd_attr_desc) - 1; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+                      desc = cmd_attr_desc[i].str;</span><br><span style="color: hsl(120, 100%, 40%);">+                  flag = '.'; /* FIXME: no flags defined */</span><br><span style="color: hsl(120, 100%, 40%);">+                     vty_out(vty, "    %c  %s%s", flag, desc, VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+              }</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (attr_mask & ATTR_TYPE_LIB) {</span><br><span style="color: hsl(120, 100%, 40%);">+          vty_out(vty, "  Library specific attributes:%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+            for (i = 0, found = false; i < _OSMO_CORE_LIB_ATTR_COUNT; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+                   if ((desc = cmd_lib_attr_desc[i]) == NULL)</span><br><span style="color: hsl(120, 100%, 40%);">+                            continue;</span><br><span style="color: hsl(120, 100%, 40%);">+                     found = true;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                       flag = cmd_lib_attr_letters[i];</span><br><span style="color: hsl(120, 100%, 40%);">+                       if (flag == '\0')</span><br><span style="color: hsl(120, 100%, 40%);">+                             flag = '.';</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                 vty_out(vty, "    %c  %s%s", flag, desc, VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+              }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           if (!found)</span><br><span style="color: hsl(120, 100%, 40%);">+                   vty_out(vty, "    (no attributes)%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (attr_mask & ATTR_TYPE_APP) {</span><br><span style="color: hsl(120, 100%, 40%);">+          vty_out(vty, "  Application specific attributes:%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                for (i = 0, found = false; i < VTY_CMD_USR_ATTR_NUM; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+                        if ((desc = host.app_info->usr_attr_desc[i]) == NULL)</span><br><span style="color: hsl(120, 100%, 40%);">+                              continue;</span><br><span style="color: hsl(120, 100%, 40%);">+                     found = true;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                       flag = host.app_info->usr_attr_letters[i];</span><br><span style="color: hsl(120, 100%, 40%);">+                 if (flag == '\0')</span><br><span style="color: hsl(120, 100%, 40%);">+                             flag = '.';</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                 vty_out(vty, "    %c  %s%s", flag, desc, VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+              }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           if (!found)</span><br><span style="color: hsl(120, 100%, 40%);">+                   vty_out(vty, "    (no attributes)%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+gDEFUN(show_vty_attr_all, show_vty_attr_all_cmd,</span><br><span style="color: hsl(120, 100%, 40%);">+       "show vty-attributes",</span><br><span style="color: hsl(120, 100%, 40%);">+       SHOW_STR "List of VTY attributes\n")</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   print_attr_list(vty, 0xff);</span><br><span style="color: hsl(120, 100%, 40%);">+   return CMD_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+gDEFUN(show_vty_attr, show_vty_attr_cmd,</span><br><span style="color: hsl(120, 100%, 40%);">+       "show vty-attributes (application|library|global)",</span><br><span style="color: hsl(120, 100%, 40%);">+       SHOW_STR "List of VTY attributes\n"</span><br><span style="color: hsl(120, 100%, 40%);">+       "Application specific attributes only\n"</span><br><span style="color: hsl(120, 100%, 40%);">+       "Library specific attributes only\n"</span><br><span style="color: hsl(120, 100%, 40%);">+       "Global attributes only\n")</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     unsigned int attr_mask = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (argv[0][0] == 'g') /* global */</span><br><span style="color: hsl(120, 100%, 40%);">+           attr_mask |= ATTR_TYPE_GLOBAL;</span><br><span style="color: hsl(120, 100%, 40%);">+        else if (argv[0][0] == 'l') /* library */</span><br><span style="color: hsl(120, 100%, 40%);">+             attr_mask |= ATTR_TYPE_LIB;</span><br><span style="color: hsl(120, 100%, 40%);">+   else if (argv[0][0] == 'a') /* application */</span><br><span style="color: hsl(120, 100%, 40%);">+         attr_mask |= ATTR_TYPE_APP;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ print_attr_list(vty, attr_mask);</span><br><span style="color: hsl(120, 100%, 40%);">+      return CMD_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Help display function for all node. */</span><br><span> gDEFUN(config_list, config_list_cmd, "list", "Print command list\n")</span><br><span> {</span><br><span>@@ -3932,6 +4022,9 @@</span><br><span>       install_lib_element(node, &config_help_cmd);</span><br><span>     install_lib_element(node, &config_list_cmd);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+  install_lib_element(node, &show_vty_attr_all_cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+        install_lib_element(node, &show_vty_attr_cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>         install_lib_element(node, &config_write_terminal_cmd);</span><br><span>   install_lib_element(node, &config_write_file_cmd);</span><br><span>       install_lib_element(node, &config_write_memory_cmd);</span><br><span>@@ -3952,6 +4045,8 @@</span><br><span> static bool vty_command_is_common(struct cmd_element *cmd)</span><br><span> {</span><br><span>  if (cmd == &config_help_cmd</span><br><span style="color: hsl(120, 100%, 40%);">+           || cmd == &show_vty_attr_all_cmd</span><br><span style="color: hsl(120, 100%, 40%);">+          || cmd == &show_vty_attr_cmd</span><br><span>             || cmd == &config_list_cmd</span><br><span>       || cmd == &config_write_terminal_cmd</span><br><span>             || cmd == &config_write_file_cmd</span><br><span>@@ -4035,6 +4130,8 @@</span><br><span>             install_lib_element(VIEW_NODE, &config_list_cmd);</span><br><span>                install_lib_element(VIEW_NODE, &config_exit_cmd);</span><br><span>                install_lib_element(VIEW_NODE, &config_help_cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+         install_lib_element(VIEW_NODE, &show_vty_attr_all_cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+           install_lib_element(VIEW_NODE, &show_vty_attr_cmd);</span><br><span>              install_lib_element(VIEW_NODE, &config_enable_cmd);</span><br><span>              install_lib_element(VIEW_NODE, &config_terminal_length_cmd);</span><br><span>             install_lib_element(VIEW_NODE, &config_terminal_no_length_cmd);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/20459">change 20459</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmocore/+/20459"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I561114d7416e30cc06b7d49c0bc1217a76039c99 </div>
<div style="display:none"> Gerrit-Change-Number: 20459 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Vadim Yanitskiy <vyanitskiy@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>