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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">vty/command: add CMD_ATTR_LIB_COMMAND and install() API wrappers<br><br>This new attribute would allow to distinguish commands provided<br>by libraries from commands registered by the application itself,<br>so vty_dump_element() would print proper description for the<br>library specific attributes.<br><br>All VTY commands defined by the libraries need to use the new API:<br><br>  - install_lib_element(), and<br>  - install_lib_element_ve,<br><br>instead of the old functions (respectively):<br><br>  - install_element(), and<br>  - install_element_ve().<br><br>See https://lists.osmocom.org/pipermail/openbsc/2020-October/013278.html.<br><br>Change-Id: I8baf31ace93c536421893c2aa4e3d9d298dcbcc6<br>Related: SYS#4937<br>---<br>M include/osmocom/vty/command.h<br>M src/vty/command.c<br>2 files changed, 21 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/vty/command.h b/include/osmocom/vty/command.h</span><br><span>index f558bb1..49f0bfe 100644</span><br><span>--- a/include/osmocom/vty/command.h</span><br><span>+++ b/include/osmocom/vty/command.h</span><br><span>@@ -139,6 +139,7 @@</span><br><span>        CMD_ATTR_HIDDEN         = (1 << 1),</span><br><span>    CMD_ATTR_IMMEDIATE      = (1 << 2),</span><br><span>    CMD_ATTR_NODE_EXIT      = (1 << 3),</span><br><span style="color: hsl(120, 100%, 40%);">+     CMD_ATTR_LIB_COMMAND    = (1 << 4),</span><br><span> };</span><br><span> </span><br><span> /*! Structure of a command element */</span><br><span>@@ -397,7 +398,9 @@</span><br><span> void install_node(struct cmd_node *, int (*)(struct vty *));</span><br><span> void install_default(int node_type) OSMO_DEPRECATED("Now happens implicitly with install_node()");</span><br><span> void install_element(int node_type, struct cmd_element *);</span><br><span style="color: hsl(120, 100%, 40%);">+void install_lib_element(int node_type, struct cmd_element *);</span><br><span> void install_element_ve(struct cmd_element *cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+void install_lib_element_ve(struct cmd_element *cmd);</span><br><span> void sort_node(void);</span><br><span> </span><br><span> void vty_install_default(int node_type) OSMO_DEPRECATED("Now happens implicitly with install_node()");</span><br><span>diff --git a/src/vty/command.c b/src/vty/command.c</span><br><span>index b472f6d..398c716 100644</span><br><span>--- a/src/vty/command.c</span><br><span>+++ b/src/vty/command.c</span><br><span>@@ -627,6 +627,7 @@</span><br><span>         { CMD_ATTR_HIDDEN,              "This command is hidden" },</span><br><span>        { CMD_ATTR_IMMEDIATE,           "This command applies immediately" },</span><br><span>      { CMD_ATTR_NODE_EXIT,           "This command applies on VTY node exit" },</span><br><span style="color: hsl(120, 100%, 40%);">+  /* CMD_ATTR_LIB_COMMAND is intentionally skipped */</span><br><span>  { 0, NULL }</span><br><span> };</span><br><span> </span><br><span>@@ -860,6 +861,16 @@</span><br><span>         cmd->cmdsize = cmd_cmdsize(cmd->strvec);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Install a library command into a node</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] ntype Node Type</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] cmd element to be installed</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void install_lib_element(int ntype, struct cmd_element *cmd)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  cmd->attr |= CMD_ATTR_LIB_COMMAND;</span><br><span style="color: hsl(120, 100%, 40%);">+ install_element(ntype, cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Install a command into VIEW and ENABLE node */</span><br><span> void install_element_ve(struct cmd_element *cmd)</span><br><span> {</span><br><span>@@ -867,6 +878,13 @@</span><br><span>       install_element(ENABLE_NODE, cmd);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Install a library command into VIEW and ENABLE node */</span><br><span style="color: hsl(120, 100%, 40%);">+void install_lib_element_ve(struct cmd_element *cmd)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       cmd->attr |= CMD_ATTR_LIB_COMMAND;</span><br><span style="color: hsl(120, 100%, 40%);">+ install_element_ve(cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #ifdef VTY_CRYPT_PW</span><br><span> static unsigned char itoa64[] =</span><br><span>     "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/20440">change 20440</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/+/20440"/><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: I8baf31ace93c536421893c2aa4e3d9d298dcbcc6 </div>
<div style="display:none"> Gerrit-Change-Number: 20440 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </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: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>