<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7255">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">CLI: Remove calls to ast_cli_generator.<br><br>The ability to add to localized storage cannot be supported by<br>ast_cli_generator. The only calls to ast_cli_generator should be by<br>functions that need to proxy the CLI generator, for example 'cli check<br>permissions' or 'core show help'.<br><br>* ast_cli_generatornummatches now retrieves the vector of matches and<br> reports the number of elements (not including 'best' match).<br>* test_substitution retrieves and iterates the vector.<br><br>Change-Id: I8cd6b93905363cf7a33a2d2b0e2a8f8446d9f248<br>---<br>M include/asterisk/cli.h<br>M main/cli.c<br>M tests/test_substitution.c<br>3 files changed, 25 insertions(+), 16 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk/cli.h b/include/asterisk/cli.h<br>index 3ed88eb..51f077f 100644<br>--- a/include/asterisk/cli.h<br>+++ b/include/asterisk/cli.h<br>@@ -287,6 +287,9 @@<br> * Useful for readline, that's about it<br> * \retval 0 on success<br> * \retval -1 on failure<br>+ *<br>+ * Only call this function to proxy the CLI generator to<br>+ * another.<br> */<br> char *ast_cli_generator(const char *, const char *, int);<br> <br>diff --git a/main/cli.c b/main/cli.c<br>index eae14ad..1653838 100644<br>--- a/main/cli.c<br>+++ b/main/cli.c<br>@@ -2475,18 +2475,17 @@<br> /*! \brief Return the number of unique matches for the generator */<br> int ast_cli_generatornummatches(const char *text, const char *word)<br> {<br>- int matches = 0, i = 0;<br>- char *buf = NULL, *oldbuf = NULL;<br>+ int matches;<br>+ struct ast_vector_string *vec = ast_cli_completion_vector(text, word);<br> <br>- while ((buf = ast_cli_generator(text, word, i++))) {<br>- if (!oldbuf || strcmp(buf,oldbuf))<br>- matches++;<br>- if (oldbuf)<br>- ast_free(oldbuf);<br>- oldbuf = buf;<br>+ if (!vec) {<br>+ return 0;<br> }<br>- if (oldbuf)<br>- ast_free(oldbuf);<br>+<br>+ matches = AST_VECTOR_SIZE(vec) - 1;<br>+ AST_VECTOR_CALLBACK_VOID(vec, ast_free);<br>+ AST_VECTOR_PTR_FREE(vec);<br>+<br> return matches;<br> }<br> <br>diff --git a/tests/test_substitution.c b/tests/test_substitution.c<br>index 3a1dc1f..8b9a164 100644<br>--- a/tests/test_substitution.c<br>+++ b/tests/test_substitution.c<br>@@ -43,6 +43,7 @@<br> #include "asterisk/stringfields.h"<br> #include "asterisk/threadstorage.h"<br> #include "asterisk/test.h"<br>+#include "asterisk/vector.h"<br> <br> static enum ast_test_result_state test_chan_integer(struct ast_test *test,<br> struct ast_channel *c, int *ifield, const char *expression)<br>@@ -225,6 +226,7 @@<br> struct ast_channel *c;<br> int i;<br> enum ast_test_result_state res = AST_TEST_PASS;<br>+ struct ast_vector_string *funcs;<br> <br> switch (cmd) {<br> case TEST_INIT:<br>@@ -302,11 +304,12 @@<br> #undef TEST<br> <br> /* For testing dialplan functions */<br>- for (i = 0; ; i++) {<br>- char *cmd = ast_cli_generator("core show function", "", i);<br>- if (cmd == NULL) {<br>- break;<br>- }<br>+ funcs = ast_cli_completion_vector("core show function", "");<br>+<br>+ /* Skip "best match" element 0 */<br>+ for (i = 1; funcs && i < AST_VECTOR_SIZE(funcs); i++) {<br>+ char *cmd = AST_VECTOR_GET(funcs, i);<br>+<br> if (strcmp(cmd, "CHANNEL") && strcmp(cmd, "CALLERID") && strncmp(cmd, "CURL", 4) &&<br> strncmp(cmd, "AES", 3) && strncmp(cmd, "BASE64", 6) &&<br> strcmp(cmd, "CDR") && strcmp(cmd, "ENV") && strcmp(cmd, "GLOBAL") &&<br>@@ -321,10 +324,14 @@<br> }<br> }<br> }<br>- ast_free(cmd);<br> }<br> <br>+ if (funcs) {<br>+ AST_VECTOR_CALLBACK_VOID(funcs, ast_free);<br>+ AST_VECTOR_PTR_FREE(funcs);<br>+ }<br> ast_hangup(c);<br>+<br> return res;<br> }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7255">change 7255</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.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.asterisk.org/7255"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I8cd6b93905363cf7a33a2d2b0e2a8f8446d9f248 </div>
<div style="display:none"> Gerrit-Change-Number: 7255 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>