[Asterisk-code-review] manager: Use ast cli completion add for completion generators. (asterisk[15])

Joshua Colp asteriskteam at digium.com
Tue Mar 20 09:22:41 CDT 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/8591 )

Change subject: manager: Use ast_cli_completion_add for completion generators.
......................................................................

manager: Use ast_cli_completion_add for completion generators.

Change-Id: I658141c6ec490a3e866b02d2afea757928ceaabf
---
M main/manager.c
1 file changed, 24 insertions(+), 22 deletions(-)

Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Joshua Colp: Approved for Submit



diff --git a/main/manager.c b/main/manager.c
index 31465f6..ace44c2 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -2325,9 +2325,9 @@
 {
 	struct manager_action *cur;
 	struct ast_str *authority;
-	int num, l, which;
+	int num;
+	int l;
 	const char *auth_str;
-	char *ret = NULL;
 #ifdef AST_XML_DOCS
 	char syntax_title[64], description_title[64], synopsis_title[64], seealso_title[64];
 	char arguments_title[64], privilege_title[64], final_response_title[64], list_responses_title[64];
@@ -2342,16 +2342,16 @@
 		return NULL;
 	case CLI_GENERATE:
 		l = strlen(a->word);
-		which = 0;
 		AST_RWLIST_RDLOCK(&actions);
 		AST_RWLIST_TRAVERSE(&actions, cur, list) {
-			if (!strncasecmp(a->word, cur->action, l) && ++which > a->n) {
-				ret = ast_strdup(cur->action);
-				break;	/* make sure we exit even if ast_strdup() returns NULL */
+			if (!strncasecmp(a->word, cur->action, l)) {
+				if (ast_cli_completion_add(ast_strdup(cur->action))) {
+					break;
+				}
 			}
 		}
 		AST_RWLIST_UNLOCK(&actions);
-		return ret;
+		return NULL;
 	}
 	if (a->argc < 4) {
 		return CLI_SHOWUSAGE;
@@ -2481,8 +2481,7 @@
 static char *handle_showmanager(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_manager_user *user = NULL;
-	int l, which;
-	char *ret = NULL;
+	int l;
 	struct ast_str *rauthority = ast_str_alloca(MAX_AUTH_PERM_STRING);
 	struct ast_str *wauthority = ast_str_alloca(MAX_AUTH_PERM_STRING);
 	struct ast_variable *v;
@@ -2496,19 +2495,19 @@
 		return NULL;
 	case CLI_GENERATE:
 		l = strlen(a->word);
-		which = 0;
 		if (a->pos != 3) {
 			return NULL;
 		}
 		AST_RWLIST_RDLOCK(&users);
 		AST_RWLIST_TRAVERSE(&users, user, list) {
-			if ( !strncasecmp(a->word, user->username, l) && ++which > a->n ) {
-				ret = ast_strdup(user->username);
-				break;
+			if (!strncasecmp(a->word, user->username, l)) {
+				if (ast_cli_completion_add(ast_strdup(user->username))) {
+					break;
+				}
 			}
 		}
 		AST_RWLIST_UNLOCK(&users);
-		return ret;
+		return NULL;
 	}
 
 	if (a->argc != 4) {
@@ -8636,8 +8635,6 @@
 	struct ao2_iterator it_events;
 	struct ast_xml_doc_item *item, *temp;
 	int length;
-	int which;
-	char *match = NULL;
 
 	if (cmd == CLI_INIT) {
 		e->command = "manager show event";
@@ -8654,19 +8651,24 @@
 	}
 
 	if (cmd == CLI_GENERATE) {
+		if (a->pos != 3) {
+			return NULL;
+		}
+
 		length = strlen(a->word);
-		which = 0;
 		it_events = ao2_iterator_init(events, 0);
 		while ((item = ao2_iterator_next(&it_events))) {
-			if (!strncasecmp(a->word, item->name, length) && ++which > a->n) {
-				match = ast_strdup(item->name);
-				ao2_ref(item, -1);
-				break;
+			if (!strncasecmp(a->word, item->name, length)) {
+				if (ast_cli_completion_add(ast_strdup(item->name))) {
+					ao2_ref(item, -1);
+					break;
+				}
 			}
 			ao2_ref(item, -1);
 		}
 		ao2_iterator_destroy(&it_events);
-		return match;
+
+		return NULL;
 	}
 
 	if (a->argc != 4) {

-- 
To view, visit https://gerrit.asterisk.org/8591
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: I658141c6ec490a3e866b02d2afea757928ceaabf
Gerrit-Change-Number: 8591
Gerrit-PatchSet: 2
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180320/fc82addd/attachment.html>


More information about the asterisk-code-review mailing list