[svn-commits] wedhorn: trunk r381717 - /trunk/channels/chan_skinny.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Feb 19 00:51:00 CST 2013


Author: wedhorn
Date: Tue Feb 19 00:50:57 2013
New Revision: 381717

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381717
Log:
Fixup skinny CLI completion.

Auto complete for skinny debug allows multiple options and negation, also add 
debug all option. Usage example: 'skinny debug all -packets' (each can be 
autocompleted including -packet).

Change show device to use device name. Remove the duplicate ast_strdup's from 
place calling device complete return immediately from complete devicename and 
complete linename so that multiple options are displayed on the CLI if more 
than one option available.

Review: https://reviewboard.asterisk.org/r/2333/

Modified:
    trunk/channels/chan_skinny.c

Modified: trunk/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_skinny.c?view=diff&rev=381717&r1=381716&r2=381717
==============================================================================
--- trunk/channels/chan_skinny.c (original)
+++ trunk/channels/chan_skinny.c Tue Feb 19 00:50:57 2013
@@ -3531,6 +3531,36 @@
 	return dbgcli_buf;
 }
 
+static char *complete_skinny_debug(const char *line, const char *word, int pos, int state)
+{
+	const char *debugOpts[]={ "all","audio","hint","lock","off","packet","show","sub","template","thread",NULL };
+	char *wordptr = (char *)word;
+	char buf[32];
+	char *bufptr = buf;
+	int buflen = sizeof(buf);
+	int wordlen;
+	int which = 0;
+	int i = 0;
+
+	if (*word == '+' || *word == '-' || *word == '!') {
+		*bufptr = *word;
+		wordptr++;
+		bufptr++;
+		buflen--;
+	}
+	wordlen = strlen(wordptr);
+
+	while (debugOpts[i]) {
+		if (!strncasecmp(wordptr, debugOpts[i], wordlen) && ++which > state) {
+			ast_copy_string(bufptr, debugOpts[i], buflen);
+			return ast_strdup(buf);
+		}
+		i++;
+	}
+
+	return NULL;
+}
+
 static char *handle_skinny_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	int i;
@@ -3541,13 +3571,14 @@
 
 	switch (cmd) {
 	case CLI_INIT:
-		e->command = "skinny debug {audio|hint|lock|off|packet|show|sub|template|thread}";
+		e->command = "skinny debug";
 		e->usage =
 			"Usage: skinny debug {audio|hint|lock|off|packet|show|sub|template|thread}\n"
 			"       Enables/Disables various Skinny debugging messages\n";
 		return NULL;
 	case CLI_GENERATE:
-		return NULL;
+		return complete_skinny_debug(a->line, a->word, a->pos, a->n);
+
 	}
 
 	if (a->argc < 3)
@@ -3558,12 +3589,17 @@
 		return CLI_SUCCESS;
 	}
 
-	for(i = e->args-1; i < a->argc; i++) {
+	for(i = e->args; i < a->argc; i++) {
 		result++;
 		arg = a->argv[i];
 
 		if (!strncasecmp(arg, "off", 3)) {
 			skinnydebug = 0;
+			continue;
+		}
+
+		if (!strncasecmp(arg, "all", 3)) {
+			skinnydebug = DEBUG_GENERAL|DEBUG_SUB|DEBUG_PACKET|DEBUG_AUDIO|DEBUG_LOCK|DEBUG_TEMPLATE|DEBUG_THREAD|DEBUG_HINT;
 			continue;
 		}
 
@@ -3638,32 +3674,31 @@
 static char *complete_skinny_devices(const char *word, int state)
 {
 	struct skinny_device *d;
-	char *result = NULL;
 	int wordlen = strlen(word), which = 0;
 
 	AST_LIST_TRAVERSE(&devices, d, list) {
-		if (!strncasecmp(word, d->id, wordlen) && ++which > state)
-			result = ast_strdup(d->id);
-	}
-
-	return result;
+		if (!strncasecmp(word, d->name, wordlen) && ++which > state) {
+                       return ast_strdup(d->name);
+               }
+	}
+
+	return NULL;
 }
 
 static char *complete_skinny_show_device(const char *line, const char *word, int pos, int state)
 {
-	return (pos == 3 ? ast_strdup(complete_skinny_devices(word, state)) : NULL);
+	return (pos == 3 ? complete_skinny_devices(word, state) : NULL);
 }
 
 static char *complete_skinny_reset(const char *line, const char *word, int pos, int state)
 {
-	return (pos == 2 ? ast_strdup(complete_skinny_devices(word, state)) : NULL);
+	return (pos == 2 ? complete_skinny_devices(word, state) : NULL);
 }
 
 static char *complete_skinny_show_line(const char *line, const char *word, int pos, int state)
 {
 	struct skinny_device *d;
 	struct skinny_line *l;
-	char *result = NULL;
 	int wordlen = strlen(word), which = 0;
 
 	if (pos != 3)
@@ -3671,12 +3706,13 @@
 
 	AST_LIST_TRAVERSE(&devices, d, list) {
 		AST_LIST_TRAVERSE(&d->lines, l, list) {
-			if (!strncasecmp(word, l->name, wordlen) && ++which > state)
-				result = ast_strdup(l->name);
-		}
-	}
-
-	return result;
+			if (!strncasecmp(word, l->name, wordlen) && ++which > state) {
+				return ast_strdup(l->name);
+			}
+		}
+	}
+
+	return NULL;
 }
 
 static char *handle_skinny_reset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)




More information about the svn-commits mailing list