<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8569">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">main/bridge: Use ast_cli_completion_add.<br><br>Change-Id: I3775a696d6a57139fdf09651ecb786bcf1774509<br>---<br>M main/bridge.c<br>1 file changed, 39 insertions(+), 63 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/69/8569/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/bridge.c b/main/bridge.c<br>index 4f79852..1109c4b 100644<br>--- a/main/bridge.c<br>+++ b/main/bridge.c<br>@@ -5027,46 +5027,29 @@<br>      return ao2_find(bridges, bridge_id, OBJ_SEARCH_KEY);<br> }<br> <br>-struct bridge_complete {<br>-       /*! Nth match to return. */<br>-  int state;<br>-   /*! Which match currently on. */<br>-     int which;<br>-};<br>-<br>-static int complete_bridge_live_search(void *obj, void *arg, void *data, int flags)<br>+static int complete_bridge_live_search(void *obj, void *arg, int flags)<br> {<br>-       struct bridge_complete *search = data;<br>+       struct ast_bridge *bridge = obj;<br> <br>-  if (++search->which > search->state) {<br>-              return CMP_MATCH;<br>+    if (ast_cli_completion_add(ast_strdup(bridge->uniqueid))) {<br>+               return CMP_STOP;<br>      }<br>+<br>  return 0;<br> }<br> <br>-static char *complete_bridge_live(const char *word, int state)<br>+static char *complete_bridge_live(const char *word)<br> {<br>-  char *ret;<br>-   struct ast_bridge *bridge;<br>-   struct bridge_complete search = {<br>-            .state = state,<br>-              };<br>+   ao2_callback(bridges, ast_strlen_zero(word) ? 0 : OBJ_PARTIAL_KEY,<br>+           complete_bridge_live_search, (char *) word);<br> <br>-      bridge = ao2_callback_data(bridges, ast_strlen_zero(word) ? 0 : OBJ_PARTIAL_KEY,<br>-             complete_bridge_live_search, (char *) word, &search);<br>-    if (!bridge) {<br>-               return NULL;<br>- }<br>-    ret = ast_strdup(bridge->uniqueid);<br>-       ao2_ref(bridge, -1);<br>- return ret;<br>+  return NULL;<br> }<br> <br>-static char *complete_bridge_stasis(const char *word, int state)<br>+static char *complete_bridge_stasis(const char *word)<br> {<br>-   char *ret = NULL;<br>-    int wordlen = strlen(word), which = 0;<br>-       RAII_VAR(struct ao2_container *, cached_bridges, NULL, ao2_cleanup);<br>+ int wordlen = strlen(word);<br>+  struct ao2_container *cached_bridges;<br>         struct ao2_iterator iter;<br>     struct stasis_message *msg;<br> <br>@@ -5079,15 +5062,17 @@<br>       for (; (msg = ao2_iterator_next(&iter)); ao2_ref(msg, -1)) {<br>              struct ast_bridge_snapshot *snapshot = stasis_message_data(msg);<br> <br>-          if (!strncasecmp(word, snapshot->uniqueid, wordlen) && (++which > state)) {<br>-                    ret = ast_strdup(snapshot->uniqueid);<br>-                     ao2_ref(msg, -1);<br>-                    break;<br>+               if (!strncasecmp(word, snapshot->uniqueid, wordlen)) {<br>+                    if (ast_cli_completion_add(ast_strdup(snapshot->uniqueid))) {<br>+                             ao2_ref(msg, -1);<br>+                            break;<br>+                       }<br>             }<br>     }<br>     ao2_iterator_destroy(&iter);<br>+     ao2_ref(cached_bridges, -1);<br> <br>-      return ret;<br>+  return NULL;<br> }<br> <br> static char *handle_bridge_show_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)<br>@@ -5168,7 +5153,7 @@<br>            return NULL;<br>  case CLI_GENERATE:<br>            if (a->pos == 2) {<br>-                        return complete_bridge_stasis(a->word, a->n);<br>+                  return complete_bridge_stasis(a->word);<br>            }<br>             return NULL;<br>  }<br>@@ -5207,7 +5192,7 @@<br>              return NULL;<br>  case CLI_GENERATE:<br>            if (a->pos == 2) {<br>-                        return complete_bridge_live(a->word, a->n);<br>+                    return complete_bridge_live(a->word);<br>              }<br>             return NULL;<br>  }<br>@@ -5229,11 +5214,10 @@<br> }<br> #endif<br> <br>-static char *complete_bridge_participant(const char *bridge_name, const char *line, const char *word, int pos, int state)<br>+static char *complete_bridge_participant(const char *bridge_name, const char *word)<br> {<br>      struct ast_bridge *bridge;<br>    struct ast_bridge_channel *bridge_channel;<br>-   int which;<br>    int wordlen;<br> <br>       bridge = ast_bridge_find_by_id(bridge_name);<br>@@ -5241,19 +5225,17 @@<br>                 return NULL;<br>  }<br> <br>- {<br>-            SCOPED_LOCK(bridge_lock, bridge, ast_bridge_lock, ast_bridge_unlock);<br>+        wordlen = strlen(word);<br> <br>-           which = 0;<br>-           wordlen = strlen(word);<br>-              AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {<br>-                 if (!strncasecmp(ast_channel_name(bridge_channel->chan), word, wordlen)<br>-                           && ++which > state) {<br>-                             ao2_ref(bridge, -1);<br>-                         return ast_strdup(ast_channel_name(bridge_channel->chan));<br>+        ast_bridge_lock(bridge);<br>+     AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {<br>+         if (!strncasecmp(ast_channel_name(bridge_channel->chan), word, wordlen)) {<br>+                        if (ast_cli_completion_add(ast_strdup(ast_channel_name(bridge_channel->chan)))) {<br>+                         break;<br>                        }<br>             }<br>     }<br>+    ast_bridge_unlock(bridge);<br> <br>         ao2_ref(bridge, -1);<br> <br>@@ -5263,7 +5245,6 @@<br> static char *handle_bridge_kick_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)<br> {<br>        static const char * const completions[] = { "all", NULL };<br>- char *complete;<br>       struct ast_bridge *bridge;<br> <br>         switch (cmd) {<br>@@ -5277,14 +5258,11 @@<br>               return NULL;<br>  case CLI_GENERATE:<br>            if (a->pos == 2) {<br>-                        return complete_bridge_live(a->word, a->n);<br>+                    return complete_bridge_live(a->word);<br>              }<br>             if (a->pos == 3) {<br>-                        complete = ast_cli_complete(a->word, completions, a->n);<br>-                       if (!complete) {<br>-                             complete = complete_bridge_participant(a->argv[2], a->line, a->word, a->pos, a->n - 1);<br>-                       }<br>-                    return complete;<br>+                     ast_cli_complete(a->word, completions, -1);<br>+                       return complete_bridge_participant(a->argv[2], a->word);<br>                }<br>             return NULL;<br>  }<br>@@ -5385,24 +5363,22 @@<br> #undef FORMAT<br> }<br> <br>-static char *complete_bridge_technology(const char *word, int state)<br>+static char *complete_bridge_technology(const char *word)<br> {<br>      struct ast_bridge_technology *cur;<br>-   char *res;<br>-   int which;<br>    int wordlen;<br> <br>-      which = 0;<br>    wordlen = strlen(word);<br>       AST_RWLIST_RDLOCK(&bridge_technologies);<br>  AST_RWLIST_TRAVERSE(&bridge_technologies, cur, entry) {<br>-          if (!strncasecmp(cur->name, word, wordlen) && ++which > state) {<br>-                       res = ast_strdup(cur->name);<br>-                      AST_RWLIST_UNLOCK(&bridge_technologies);<br>-                 return res;<br>+          if (!strncasecmp(cur->name, word, wordlen)) {<br>+                     if (ast_cli_completion_add(ast_strdup(cur->name))) {<br>+                              break;<br>+                       }<br>             }<br>     }<br>     AST_RWLIST_UNLOCK(&bridge_technologies);<br>+<br>       return NULL;<br> }<br> <br>@@ -5421,7 +5397,7 @@<br>            return NULL;<br>  case CLI_GENERATE:<br>            if (a->pos == 3) {<br>-                        return complete_bridge_technology(a->word, a->n);<br>+                      return complete_bridge_technology(a->word);<br>                }<br>             return NULL;<br>  }<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8569">change 8569</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/8569"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I3775a696d6a57139fdf09651ecb786bcf1774509 </div>
<div style="display:none"> Gerrit-Change-Number: 8569 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>