[asterisk-commits] qwell: trunk r83213 - in /trunk: apps/ channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 19 18:16:52 CDT 2007


Author: qwell
Date: Wed Sep 19 18:16:51 2007
New Revision: 83213

URL: http://svn.digium.com/view/asterisk?view=rev&rev=83213
Log:
More conversions to NEW_CLI

(issue #10724)
Patches:
      chan_zap.c.patch uploaded by moy (license 222)
      app_queue.c.patch uploaded by eliel (license 64)
      app_voicemail.c.patch uploaded by eliel (license 64)
      app_meetme.c.patch uploaded by eliel (license 64)

Modified:
    trunk/apps/app_meetme.c
    trunk/apps/app_queue.c
    trunk/apps/app_voicemail.c
    trunk/channels/chan_zap.c

Modified: trunk/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_meetme.c?view=diff&rev=83213&r1=83212&r2=83213
==============================================================================
--- trunk/apps/app_meetme.c (original)
+++ trunk/apps/app_meetme.c Wed Sep 19 18:16:51 2007
@@ -845,155 +845,6 @@
 	return cnf;
 }
 
-static int meetme_cmd(int fd, int argc, char **argv) 
-{
-	/* Process the command */
-	struct ast_conference *cnf;
-	struct ast_conf_user *user;
-	int hr, min, sec;
-	int i = 0, total = 0;
-	time_t now;
-	char *header_format = "%-14s %-14s %-10s %-8s  %-8s  %-6s\n";
-	char *data_format = "%-12.12s   %4.4d	      %4.4s       %02d:%02d:%02d  %-8s  %-6s\n";
-	char cmdline[1024] = "";
-
-	if (argc > 8)
-		ast_cli(fd, "Invalid Arguments.\n");
-	/* Check for length so no buffer will overflow... */
-	for (i = 0; i < argc; i++) {
-		if (strlen(argv[i]) > 100)
-			ast_cli(fd, "Invalid Arguments.\n");
-	}
-	if (argc == 1) {
-		/* 'MeetMe': List all the conferences */	
-		now = time(NULL);
-		AST_LIST_LOCK(&confs);
-		if (AST_LIST_EMPTY(&confs)) {
-			ast_cli(fd, "No active MeetMe conferences.\n");
-			AST_LIST_UNLOCK(&confs);
-			return RESULT_SUCCESS;
-		}
-		ast_cli(fd, header_format, "Conf Num", "Parties", "Marked", "Activity", "Creation", "Locked");
-		AST_LIST_TRAVERSE(&confs, cnf, list) {
-			if (cnf->markedusers == 0)
-				strcpy(cmdline, "N/A ");
-			else 
-				snprintf(cmdline, sizeof(cmdline), "%4.4d", cnf->markedusers);
-			hr = (now - cnf->start) / 3600;
-			min = ((now - cnf->start) % 3600) / 60;
-			sec = (now - cnf->start) % 60;
-
-			ast_cli(fd, data_format, cnf->confno, cnf->users, cmdline, hr, min, sec, cnf->isdynamic ? "Dynamic" : "Static", cnf->locked ? "Yes" : "No");
-
-			total += cnf->users; 	
-		}
-		AST_LIST_UNLOCK(&confs);
-		ast_cli(fd, "* Total number of MeetMe users: %d\n", total);
-		return RESULT_SUCCESS;
-	}
-	if (argc < 3)
-		return RESULT_SHOWUSAGE;
-	ast_copy_string(cmdline, argv[2], sizeof(cmdline));	/* Argv 2: conference number */
-	if (strstr(argv[1], "lock")) {	
-		if (strcmp(argv[1], "lock") == 0) {
-			/* Lock */
-			strncat(cmdline, ",L", sizeof(cmdline) - strlen(cmdline) - 1);
-		} else {
-			/* Unlock */
-			strncat(cmdline, ",l", sizeof(cmdline) - strlen(cmdline) - 1);
-		}
-	} else if (strstr(argv[1], "mute")) { 
-		if (argc < 4)
-			return RESULT_SHOWUSAGE;
-		if (strcmp(argv[1], "mute") == 0) {
-			/* Mute */
-			if (strcmp(argv[3], "all") == 0) {
-				strncat(cmdline, ",N", sizeof(cmdline) - strlen(cmdline) - 1);
-			} else {
-				strncat(cmdline, ",M,", sizeof(cmdline) - strlen(cmdline) - 1);	
-				strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
-			}
-		} else {
-			/* Unmute */
-			if (strcmp(argv[3], "all") == 0) {
-				strncat(cmdline, ",n", sizeof(cmdline) - strlen(cmdline) - 1);
-			} else {
-				strncat(cmdline, ",m,", sizeof(cmdline) - strlen(cmdline) - 1);
-				strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
-			}
-		}
-	} else if (strcmp(argv[1], "kick") == 0) {
-		if (argc < 4)
-			return RESULT_SHOWUSAGE;
-		if (strcmp(argv[3], "all") == 0) {
-			/* Kick all */
-			strncat(cmdline, ",K", sizeof(cmdline) - strlen(cmdline) - 1);
-		} else {
-			/* Kick a single user */
-			strncat(cmdline, ",k,", sizeof(cmdline) - strlen(cmdline) - 1);
-			strncat(cmdline, argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
-		}
-	} else if(strcmp(argv[1], "list") == 0) {
-		int concise = ( 4 == argc && ( !strcasecmp(argv[3], "concise") ) );
-		/* List all the users in a conference */
-		if (AST_LIST_EMPTY(&confs)) {
-			if ( !concise )
-				ast_cli(fd, "No active conferences.\n");
-			return RESULT_SUCCESS;	
-		}
-		/* Find the right conference */
-		AST_LIST_LOCK(&confs);
-		AST_LIST_TRAVERSE(&confs, cnf, list) {
-			if (strcmp(cnf->confno, argv[2]) == 0)
-				break;
-		}
-		if (!cnf) {
-			if ( !concise )
-				ast_cli(fd, "No such conference: %s.\n",argv[2]);
-			AST_LIST_UNLOCK(&confs);
-			return RESULT_SUCCESS;
-		}
-		/* Show all the users */
-		time(&now);
-		AST_LIST_TRAVERSE(&cnf->userlist, user, list) {
-			hr = (now - user->jointime) / 3600;
-			min = ((now - user->jointime) % 3600) / 60;
-			sec = (now - user->jointime) % 60;
-			if ( !concise )
-				ast_cli(fd, "User #: %-2.2d %12.12s %-20.20s Channel: %s %s %s %s %s %02d:%02d:%02d\n",
-					user->user_no,
-					S_OR(user->chan->cid.cid_num, "<unknown>"),
-					S_OR(user->chan->cid.cid_name, "<no name>"),
-					user->chan->name,
-					user->userflags & CONFFLAG_ADMIN ? "(Admin)" : "",
-					user->userflags & CONFFLAG_MONITOR ? "(Listen only)" : "",
-					user->adminflags & ADMINFLAG_MUTED ? "(Admin Muted)" : user->adminflags & ADMINFLAG_SELFMUTED ? "(Muted)" : "",
-					istalking(user->talking), hr, min, sec); 
-			else 
-				ast_cli(fd, "%d!%s!%s!%s!%s!%s!%s!%d!%02d:%02d:%02d\n",
-					user->user_no,
-					S_OR(user->chan->cid.cid_num, ""),
-					S_OR(user->chan->cid.cid_name, ""),
-					user->chan->name,
-					user->userflags  & CONFFLAG_ADMIN   ? "1" : "",
-					user->userflags  & CONFFLAG_MONITOR ? "1" : "",
-					user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)  ? "1" : "",
-					user->talking, hr, min, sec);
-			
-		}
-		if ( !concise )
-			ast_cli(fd,"%d users in that conference.\n",cnf->users);
-		AST_LIST_UNLOCK(&confs);
-		return RESULT_SUCCESS;
-	} else 
-		return RESULT_SHOWUSAGE;
-
-	ast_debug(1, "Cmdline: %s\n", cmdline);
-
-	admin_exec(NULL, cmdline);
-
-	return 0;
-}
 
 static char *complete_meetmecmd(const char *line, const char *word, int pos, int state)
 {
@@ -1056,10 +907,167 @@
 
 	return NULL;
 }
-	
-static const char meetme_usage[] =
-"Usage: meetme (un)lock|(un)mute|kick|list [concise] <confno> <usernumber>\n"
-"       Executes a command for the conference or on a conferee\n";
+
+static char *meetme_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	/* Process the command */
+	struct ast_conference *cnf;
+	struct ast_conf_user *user;
+	int hr, min, sec;
+	int i = 0, total = 0;
+	time_t now;
+	char *header_format = "%-14s %-14s %-10s %-8s  %-8s  %-6s\n";
+	char *data_format = "%-12.12s   %4.4d	      %4.4s       %02d:%02d:%02d  %-8s  %-6s\n";
+	char cmdline[1024] = "";
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "meetme";
+		e->usage =
+			"Usage: meetme (un)lock|(un)mute|kick|list [concise] <confno> <usernumber>\n"
+			"       Executes a command for the conference or on a conferee\n";
+		return NULL;
+	case CLI_GENERATE:
+		return complete_meetmecmd(a->line, a->word, a->pos, a->n);
+	}
+
+	if (a->argc > 8)
+		ast_cli(a->fd, "Invalid Arguments.\n");
+	/* Check for length so no buffer will overflow... */
+	for (i = 0; i < a->argc; i++) {
+		if (strlen(a->argv[i]) > 100)
+			ast_cli(a->fd, "Invalid Arguments.\n");
+	}
+	if (a->argc == 1) {
+		/* 'MeetMe': List all the conferences */	
+		now = time(NULL);
+		AST_LIST_LOCK(&confs);
+		if (AST_LIST_EMPTY(&confs)) {
+			ast_cli(a->fd, "No active MeetMe conferences.\n");
+			AST_LIST_UNLOCK(&confs);
+			return CLI_SUCCESS;
+		}
+		ast_cli(a->fd, header_format, "Conf Num", "Parties", "Marked", "Activity", "Creation", "Locked");
+		AST_LIST_TRAVERSE(&confs, cnf, list) {
+			if (cnf->markedusers == 0)
+				strcpy(cmdline, "N/A ");
+			else 
+				snprintf(cmdline, sizeof(cmdline), "%4.4d", cnf->markedusers);
+			hr = (now - cnf->start) / 3600;
+			min = ((now - cnf->start) % 3600) / 60;
+			sec = (now - cnf->start) % 60;
+
+			ast_cli(a->fd, data_format, cnf->confno, cnf->users, cmdline, hr, min, sec, cnf->isdynamic ? "Dynamic" : "Static", cnf->locked ? "Yes" : "No");
+
+			total += cnf->users; 	
+		}
+		AST_LIST_UNLOCK(&confs);
+		ast_cli(a->fd, "* Total number of MeetMe users: %d\n", total);
+		return CLI_SUCCESS;
+	}
+	if (a->argc < 3)
+		return CLI_SHOWUSAGE;
+	ast_copy_string(cmdline, a->argv[2], sizeof(cmdline));	/* Argv 2: conference number */
+	if (strstr(a->argv[1], "lock")) {	
+		if (strcmp(a->argv[1], "lock") == 0) {
+			/* Lock */
+			strncat(cmdline, ",L", sizeof(cmdline) - strlen(cmdline) - 1);
+		} else {
+			/* Unlock */
+			strncat(cmdline, ",l", sizeof(cmdline) - strlen(cmdline) - 1);
+		}
+	} else if (strstr(a->argv[1], "mute")) { 
+		if (a->argc < 4)
+			return CLI_SHOWUSAGE;
+		if (strcmp(a->argv[1], "mute") == 0) {
+			/* Mute */
+			if (strcmp(a->argv[3], "all") == 0) {
+				strncat(cmdline, ",N", sizeof(cmdline) - strlen(cmdline) - 1);
+			} else {
+				strncat(cmdline, ",M,", sizeof(cmdline) - strlen(cmdline) - 1);	
+				strncat(cmdline, a->argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
+			}
+		} else {
+			/* Unmute */
+			if (strcmp(a->argv[3], "all") == 0) {
+				strncat(cmdline, ",n", sizeof(cmdline) - strlen(cmdline) - 1);
+			} else {
+				strncat(cmdline, ",m,", sizeof(cmdline) - strlen(cmdline) - 1);
+				strncat(cmdline, a->argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
+			}
+		}
+	} else if (strcmp(a->argv[1], "kick") == 0) {
+		if (a->argc < 4)
+			return CLI_SHOWUSAGE;
+		if (strcmp(a->argv[3], "all") == 0) {
+			/* Kick all */
+			strncat(cmdline, ",K", sizeof(cmdline) - strlen(cmdline) - 1);
+		} else {
+			/* Kick a single user */
+			strncat(cmdline, ",k,", sizeof(cmdline) - strlen(cmdline) - 1);
+			strncat(cmdline, a->argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
+		}
+	} else if(strcmp(a->argv[1], "list") == 0) {
+		int concise = ( 4 == a->argc && ( !strcasecmp(a->argv[3], "concise") ) );
+		/* List all the users in a conference */
+		if (AST_LIST_EMPTY(&confs)) {
+			if ( !concise )
+				ast_cli(a->fd, "No active conferences.\n");
+			return CLI_SUCCESS;	
+		}
+		/* Find the right conference */
+		AST_LIST_LOCK(&confs);
+		AST_LIST_TRAVERSE(&confs, cnf, list) {
+			if (strcmp(cnf->confno, a->argv[2]) == 0)
+				break;
+		}
+		if (!cnf) {
+			if ( !concise )
+				ast_cli(a->fd, "No such conference: %s.\n",a->argv[2]);
+			AST_LIST_UNLOCK(&confs);
+			return CLI_SUCCESS;
+		}
+		/* Show all the users */
+		time(&now);
+		AST_LIST_TRAVERSE(&cnf->userlist, user, list) {
+			hr = (now - user->jointime) / 3600;
+			min = ((now - user->jointime) % 3600) / 60;
+			sec = (now - user->jointime) % 60;
+			if ( !concise )
+				ast_cli(a->fd, "User #: %-2.2d %12.12s %-20.20s Channel: %s %s %s %s %s %02d:%02d:%02d\n",
+					user->user_no,
+					S_OR(user->chan->cid.cid_num, "<unknown>"),
+					S_OR(user->chan->cid.cid_name, "<no name>"),
+					user->chan->name,
+					user->userflags & CONFFLAG_ADMIN ? "(Admin)" : "",
+					user->userflags & CONFFLAG_MONITOR ? "(Listen only)" : "",
+					user->adminflags & ADMINFLAG_MUTED ? "(Admin Muted)" : user->adminflags & ADMINFLAG_SELFMUTED ? "(Muted)" : "",
+					istalking(user->talking), hr, min, sec); 
+			else 
+				ast_cli(a->fd, "%d!%s!%s!%s!%s!%s!%s!%d!%02d:%02d:%02d\n",
+					user->user_no,
+					S_OR(user->chan->cid.cid_num, ""),
+					S_OR(user->chan->cid.cid_name, ""),
+					user->chan->name,
+					user->userflags  & CONFFLAG_ADMIN   ? "1" : "",
+					user->userflags  & CONFFLAG_MONITOR ? "1" : "",
+					user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)  ? "1" : "",
+					user->talking, hr, min, sec);
+			
+		}
+		if ( !concise )
+			ast_cli(a->fd,"%d users in that conference.\n",cnf->users);
+		AST_LIST_UNLOCK(&confs);
+		return CLI_SUCCESS;
+	} else 
+		return CLI_SHOWUSAGE;
+
+	ast_debug(1, "Cmdline: %s\n", cmdline);
+
+	admin_exec(NULL, cmdline);
+
+	return CLI_SUCCESS;
+}
 
 static const char *sla_hold_str(unsigned int hold_access)
 {
@@ -1078,11 +1086,22 @@
 	return hold;
 }
 
-static int sla_show_trunks(int fd, int argc, char **argv)
+static char *sla_show_trunks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	const struct sla_trunk *trunk;
 
-	ast_cli(fd, "\n"
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "sla show trunks";
+		e->usage =
+			"Usage: sla show trunks\n"
+			"       This will list all trunks defined in sla.conf\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	ast_cli(a->fd, "\n"
 	            "=============================================================\n"
 	            "=== Configured SLA Trunks ===================================\n"
 	            "=============================================================\n"
@@ -1093,7 +1112,7 @@
 		char ring_timeout[16] = "(none)";
 		if (trunk->ring_timeout)
 			snprintf(ring_timeout, sizeof(ring_timeout), "%u Seconds", trunk->ring_timeout);
-		ast_cli(fd, "=== ---------------------------------------------------------\n"
+		ast_cli(a->fd, "=== ---------------------------------------------------------\n"
 		            "=== Trunk Name:       %s\n"
 		            "=== ==> Device:       %s\n"
 		            "=== ==> AutoContext:  %s\n"
@@ -1108,16 +1127,14 @@
 		            sla_hold_str(trunk->hold_access));
 		AST_RWLIST_RDLOCK(&sla_stations);
 		AST_LIST_TRAVERSE(&trunk->stations, station_ref, entry)
-			ast_cli(fd, "===    ==> Station name: %s\n", station_ref->station->name);
+			ast_cli(a->fd, "===    ==> Station name: %s\n", station_ref->station->name);
 		AST_RWLIST_UNLOCK(&sla_stations);
-		ast_cli(fd, "=== ---------------------------------------------------------\n"
-		            "===\n");
+		ast_cli(a->fd, "=== ---------------------------------------------------------\n===\n");
 	}
 	AST_RWLIST_UNLOCK(&sla_trunks);
-	ast_cli(fd, "=============================================================\n"
-	            "\n");
-
-	return RESULT_SUCCESS;
+	ast_cli(a->fd, "=============================================================\n\n");
+
+	return CLI_SUCCESS;
 }
 
 static const char *trunkstate2str(enum sla_trunk_state state)
@@ -1134,15 +1151,22 @@
 #undef S
 }
 
-static const char sla_show_trunks_usage[] =
-"Usage: sla show trunks\n"
-"       This will list all trunks defined in sla.conf\n";
-
-static int sla_show_stations(int fd, int argc, char **argv)
+static char *sla_show_stations(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	const struct sla_station *station;
 
-	ast_cli(fd, "\n" 
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "sla show stations";
+		e->usage =
+			"Usage: sla show stations\n"
+			"       This will list all stations defined in sla.conf\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	ast_cli(a->fd, "\n" 
 	            "=============================================================\n"
 	            "=== Configured SLA Stations =================================\n"
 	            "=============================================================\n"
@@ -1160,7 +1184,7 @@
 			snprintf(ring_delay, sizeof(ring_delay), 
 				"%u", station->ring_delay);
 		}
-		ast_cli(fd, "=== ---------------------------------------------------------\n"
+		ast_cli(a->fd, "=== ---------------------------------------------------------\n"
 		            "=== Station Name:    %s\n"
 		            "=== ==> Device:      %s\n"
 		            "=== ==> AutoContext: %s\n"
@@ -1184,7 +1208,7 @@
 					"%u", trunk_ref->ring_delay);
 			} else
 				strcpy(ring_delay, "(none)");
-			ast_cli(fd, "===    ==> Trunk Name: %s\n"
+				ast_cli(a->fd, "===    ==> Trunk Name: %s\n"
 			            "===       ==> State:       %s\n"
 			            "===       ==> RingTimeout: %s\n"
 			            "===       ==> RingDelay:   %s\n",
@@ -1193,32 +1217,20 @@
 			            ring_timeout, ring_delay);
 		}
 		AST_RWLIST_UNLOCK(&sla_trunks);
-		ast_cli(fd, "=== ---------------------------------------------------------\n"
+		ast_cli(a->fd, "=== ---------------------------------------------------------\n"
 		            "===\n");
 	}
 	AST_RWLIST_UNLOCK(&sla_stations);
-	ast_cli(fd, "============================================================\n"
+	ast_cli(a->fd, "============================================================\n"
 	            "\n");
 
-	return RESULT_SUCCESS;
-}
-
-static const char sla_show_stations_usage[] =
-"Usage: sla show stations\n"
-"       This will list all stations defined in sla.conf\n";
+	return CLI_SUCCESS;
+}
 
 static struct ast_cli_entry cli_meetme[] = {
-	{ { "meetme", NULL, NULL },
-	meetme_cmd, "Execute a command on a conference or conferee",
-	meetme_usage, complete_meetmecmd },
-
-	{ { "sla", "show", "trunks", NULL },
-	sla_show_trunks, "Show SLA Trunks",
-	sla_show_trunks_usage, NULL },
-
-	{ { "sla", "show", "stations", NULL },
-	sla_show_stations, "Show SLA Stations",
-	sla_show_stations_usage, NULL },
+	NEW_CLI(meetme_cmd, "Execute a command on a conference or conferee"),
+	NEW_CLI(sla_show_trunks, "Show SLA Trunks"),
+	NEW_CLI(sla_show_stations, "Show SLA Stations"),
 };
 
 static void conf_flush(int fd, struct ast_channel *chan)

Modified: trunk/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_queue.c?view=diff&rev=83213&r1=83212&r2=83213
==============================================================================
--- trunk/apps/app_queue.c (original)
+++ trunk/apps/app_queue.c Wed Sep 19 18:16:51 2007
@@ -4248,7 +4248,7 @@
 		ast_cli(fd, "%s\n", str);
 }
 
-static int __queues_show(struct mansession *s, int fd, int argc, char **argv)
+static char *__queues_show(struct mansession *s, int fd, int argc, char **argv)
 {
 	struct call_queue *q;
 	struct ast_str *out = ast_str_alloca(240);
@@ -4257,7 +4257,7 @@
 	struct ao2_iterator mem_iter;
 
 	if (argc != 2 && argc != 3)
-		return RESULT_SHOWUSAGE;
+		return CLI_SHOWUSAGE;
 
 	/* We only want to load realtime queues when a specific queue is asked for. */
 	if (argc == 3)	/* specific queue */
@@ -4338,12 +4338,7 @@
 			ast_str_set(&out, 0, "No queues.");
 		do_print(s, fd, out->str);
 	}
-	return RESULT_SUCCESS;
-}
-
-static int queue_show(int fd, int argc, char **argv)
-{
-	return __queues_show(NULL, fd, argc, argv);
+	return CLI_SUCCESS;
 }
 
 static char *complete_queue(const char *line, const char *word, int pos, int state)
@@ -4352,11 +4347,11 @@
 	char *ret = NULL;
 	int which = 0;
 	int wordlen = strlen(word);
-	
+
 	AST_LIST_LOCK(&queues);
 	AST_LIST_TRAVERSE(&queues, q, list) {
 		if (!strncasecmp(word, q->name, wordlen) && ++which > state) {
-			ret = ast_strdup(q->name);	
+			ret = ast_strdup(q->name);
 			break;
 		}
 	}
@@ -4370,6 +4365,22 @@
 	if (pos == 2)
 		return complete_queue(line, word, pos, state);
 	return NULL;
+}
+
+static char *queue_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	switch ( cmd ) {
+	case CLI_INIT:
+		e->command = "queue show";
+		e->usage =
+			"Usage: queue show\n"
+			"       Provides summary information on a specified queue.\n";
+		return NULL;
+	case CLI_GENERATE:
+		return complete_queue_show(a->line, a->word, a->pos, a->n);	
+	}
+
+	return __queues_show(NULL, a->fd, a->argc, a->argv);
 }
 
 /*!\brief callback to display queues status in manager
@@ -4667,74 +4678,20 @@
 	return 0;
 }
 
-static int handle_queue_add_member(int fd, int argc, char *argv[])
-{
-	char *queuename, *interface, *membername = NULL;
-	int penalty;
-
-	if ((argc != 6) && (argc != 8) && (argc != 10)) {
-		return RESULT_SHOWUSAGE;
-	} else if (strcmp(argv[4], "to")) {
-		return RESULT_SHOWUSAGE;
-	} else if ((argc == 8) && strcmp(argv[6], "penalty")) {
-		return RESULT_SHOWUSAGE;
-	} else if ((argc == 10) && strcmp(argv[8], "as")) {
-		return RESULT_SHOWUSAGE;
-	}
-
-	queuename = argv[5];
-	interface = argv[3];
-	if (argc >= 8) {
-		if (sscanf(argv[7], "%d", &penalty) == 1) {
-			if (penalty < 0) {
-				ast_cli(fd, "Penalty must be >= 0\n");
-				penalty = 0;
-			}
-		} else {
-			ast_cli(fd, "Penalty must be an integer >= 0\n");
-			penalty = 0;
-		}
-	} else {
-		penalty = 0;
-	}
-
-	if (argc >= 10) {
-		membername = argv[9];
-	}
-
-	switch (add_to_queue(queuename, interface, membername, penalty, 0, queue_persistent_members)) {
-	case RES_OKAY:
-		ast_queue_log(queuename, "CLI", interface, "ADDMEMBER", "%s", "");
-		ast_cli(fd, "Added interface '%s' to queue '%s'\n", interface, queuename);
-		return RESULT_SUCCESS;
-	case RES_EXISTS:
-		ast_cli(fd, "Unable to add interface '%s' to queue '%s': Already there\n", interface, queuename);
-		return RESULT_FAILURE;
-	case RES_NOSUCHQUEUE:
-		ast_cli(fd, "Unable to add interface to queue '%s': No such queue\n", queuename);
-		return RESULT_FAILURE;
-	case RES_OUTOFMEMORY:
-		ast_cli(fd, "Out of memory\n");
-		return RESULT_FAILURE;
-	default:
-		return RESULT_FAILURE;
-	}
-}
-
 static char *complete_queue_add_member(const char *line, const char *word, int pos, int state)
 {
 	/* 0 - queue; 1 - add; 2 - member; 3 - <interface>; 4 - to; 5 - <queue>; 6 - penalty; 7 - <penalty>; 8 - as; 9 - <membername> */
 	switch (pos) {
-	case 3:	/* Don't attempt to complete name of interface (infinite possibilities) */
+	case 3: /* Don't attempt to complete name of interface (infinite possibilities) */
 		return NULL;
-	case 4:	/* only one possible match, "to" */
+	case 4: /* only one possible match, "to" */
 		return state == 0 ? ast_strdup("to") : NULL;
-	case 5:	/* <queue> */
+	case 5: /* <queue> */
 		return complete_queue(line, word, pos, state);
 	case 6: /* only one possible match, "penalty" */
 		return state == 0 ? ast_strdup("penalty") : NULL;
 	case 7:
-		if (state < 100) {	/* 0-99 */
+		if (state < 100) {      /* 0-99 */
 			char *num;
 			if ((num = ast_malloc(3))) {
 				sprintf(num, "%d", state);
@@ -4745,42 +4702,74 @@
 		}
 	case 8: /* only one possible match, "as" */
 		return state == 0 ? ast_strdup("as") : NULL;
-	case 9:	/* Don't attempt to complete name of member (infinite possibilities) */
+	case 9: /* Don't attempt to complete name of member (infinite possibilities) */
 		return NULL;
 	default:
 		return NULL;
 	}
 }
 
-static int handle_queue_remove_member(int fd, int argc, char *argv[])
-{
-	char *queuename, *interface;
-
-	if (argc != 6) {
-		return RESULT_SHOWUSAGE;
-	} else if (strcmp(argv[4], "from")) {
-		return RESULT_SHOWUSAGE;
-	}
-
-	queuename = argv[5];
-	interface = argv[3];
-
-	switch (remove_from_queue(queuename, interface)) {
+static char *handle_queue_add_member(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	char *queuename, *interface, *membername = NULL;
+	int penalty;
+
+	switch ( cmd ) {
+	case CLI_INIT:
+		e->command = "queue add member";
+		e->usage =
+			"Usage: queue add member <channel> to <queue> [penalty <penalty>]\n"; 
+		return NULL;
+	case CLI_GENERATE:
+		return complete_queue_add_member(a->line, a->word, a->pos, a->n);
+	}
+
+	if ((a->argc != 6) && (a->argc != 8) && (a->argc != 10)) {
+		return CLI_SHOWUSAGE;
+	} else if (strcmp(a->argv[4], "to")) {
+		return CLI_SHOWUSAGE;
+	} else if ((a->argc == 8) && strcmp(a->argv[6], "penalty")) {
+		return CLI_SHOWUSAGE;
+	} else if ((a->argc == 10) && strcmp(a->argv[8], "as")) {
+		return CLI_SHOWUSAGE;
+	}
+
+	queuename = a->argv[5];
+	interface = a->argv[3];
+	if (a->argc >= 8) {
+		if (sscanf(a->argv[7], "%d", &penalty) == 1) {
+			if (penalty < 0) {
+				ast_cli(a->fd, "Penalty must be >= 0\n");
+				penalty = 0;
+			}
+		} else {
+			ast_cli(a->fd, "Penalty must be an integer >= 0\n");
+			penalty = 0;
+		}
+	} else {
+		penalty = 0;
+	}
+
+	if (a->argc >= 10) {
+		membername = a->argv[9];
+	}
+
+	switch (add_to_queue(queuename, interface, membername, penalty, 0, queue_persistent_members)) {
 	case RES_OKAY:
-		ast_queue_log(queuename, "CLI", interface, "REMOVEMEMBER", "%s", "");
-		ast_cli(fd, "Removed interface '%s' from queue '%s'\n", interface, queuename);
-		return RESULT_SUCCESS;
+		ast_queue_log(queuename, "CLI", interface, "ADDMEMBER", "%s", "");
+		ast_cli(a->fd, "Added interface '%s' to queue '%s'\n", interface, queuename);
+		return CLI_SUCCESS;
 	case RES_EXISTS:
-		ast_cli(fd, "Unable to remove interface '%s' from queue '%s': Not there\n", interface, queuename);
-		return RESULT_FAILURE;
+		ast_cli(a->fd, "Unable to add interface '%s' to queue '%s': Already there\n", interface, queuename);
+		return CLI_FAILURE;
 	case RES_NOSUCHQUEUE:
-		ast_cli(fd, "Unable to remove interface from queue '%s': No such queue\n", queuename);
-		return RESULT_FAILURE;
+		ast_cli(a->fd, "Unable to add interface to queue '%s': No such queue\n", queuename);
+		return CLI_FAILURE;
 	case RES_OUTOFMEMORY:
-		ast_cli(fd, "Out of memory\n");
-		return RESULT_FAILURE;
+		ast_cli(a->fd, "Out of memory\n");
+		return CLI_FAILURE;
 	default:
-		return RESULT_FAILURE;
+		return CLI_FAILURE;
 	}
 }
 
@@ -4790,14 +4779,15 @@
 	struct call_queue *q;
 	struct member *m;
 	struct ao2_iterator mem_iter;
+	int wordlen = strlen(word);
 
 	/* 0 - queue; 1 - remove; 2 - member; 3 - <member>; 4 - from; 5 - <queue> */
 	if (pos > 5 || pos < 3)
 		return NULL;
-	if (pos == 4)	/* only one possible match, 'from' */
-		return state == 0 ? ast_strdup("from") : NULL;
-
-	if (pos == 5)	/* No need to duplicate code */
+	if (pos == 4)   /* only one possible match, 'from' */
+		return (state == 0 ? ast_strdup("from") : NULL);
+
+	if (pos == 5)   /* No need to duplicate code */
 		return complete_queue(line, word, pos, state);
 
 	/* here is the case for 3, <member> */
@@ -4806,7 +4796,7 @@
 			ast_mutex_lock(&q->lock);
 			mem_iter = ao2_iterator_init(q->members, 0);
 			while ((m = ao2_iterator_next(&mem_iter))) {
-				if (++which > state) {
+				if (!strncasecmp(word, m->membername, wordlen) && ++which > state) {
 					char *tmp;
 					ast_mutex_unlock(&q->lock);
 					tmp = m->membername;
@@ -4820,6 +4810,47 @@
 	}
 
 	return NULL;
+}
+
+static char *handle_queue_remove_member(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	char *queuename, *interface;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "queue remove member";
+		e->usage = "Usage: queue remove member <channel> from <queue>\n"; 
+		return NULL;
+	case CLI_GENERATE:
+		return complete_queue_remove_member(a->line, a->word, a->pos, a->n);
+	}
+
+	if (a->argc != 6) {
+		return CLI_SHOWUSAGE;
+	} else if (strcmp(a->argv[4], "from")) {
+		return CLI_SHOWUSAGE;
+	}
+
+	queuename = a->argv[5];
+	interface = a->argv[3];
+
+	switch (remove_from_queue(queuename, interface)) {
+	case RES_OKAY:
+		ast_queue_log(queuename, "CLI", interface, "REMOVEMEMBER", "%s", "");
+		ast_cli(a->fd, "Removed interface '%s' from queue '%s'\n", interface, queuename);
+		return CLI_SUCCESS;
+	case RES_EXISTS:
+		ast_cli(a->fd, "Unable to remove interface '%s' from queue '%s': Not there\n", interface, queuename);
+		return CLI_FAILURE;
+	case RES_NOSUCHQUEUE:
+		ast_cli(a->fd, "Unable to remove interface from queue '%s': No such queue\n", queuename);
+		return CLI_FAILURE;
+	case RES_OUTOFMEMORY:
+		ast_cli(a->fd, "Out of memory\n");
+		return CLI_FAILURE;
+	default:
+		return CLI_FAILURE;
+	}
 }
 
 static char *complete_queue_pause_member(const char *line, const char *word, int pos, int state)
@@ -4892,16 +4923,6 @@
 	}
 }
 
-static const char queue_show_usage[] =
-"Usage: queue show\n"
-"       Provides summary information on a specified queue.\n";
-
-static const char qam_cmd_usage[] =
-"Usage: queue add member <channel> to <queue> [penalty <penalty>]\n";
-
-static const char qrm_cmd_usage[] =
-"Usage: queue remove member <channel> from <queue>\n";
-
 static const char qpm_cmd_usage[] = 
 "Usage: queue pause member <channel> in <queue> reason <reason>\n";
 
@@ -4909,18 +4930,9 @@
 "Usage: queue unpause member <channel> in <queue> reason <reason>\n";
 
 static struct ast_cli_entry cli_queue[] = {
-	{ { "queue", "show", NULL },
-	queue_show, "Show status of a specified queue",
-	queue_show_usage, complete_queue_show, NULL },
-
-	{ { "queue", "add", "member", NULL },
-	handle_queue_add_member, "Add a channel to a specified queue",
-	qam_cmd_usage, complete_queue_add_member, NULL },
-
-	{ { "queue", "remove", "member", NULL },
-	handle_queue_remove_member, "Removes a channel from a specified queue",
-	qrm_cmd_usage, complete_queue_remove_member, NULL },
-
+	NEW_CLI(queue_show, "Show status of a specified queue"),
+	NEW_CLI(handle_queue_add_member, "Add a channel to a specified queue"),
+	NEW_CLI(handle_queue_remove_member, "Removes a channel from a specified queue"),
 	NEW_CLI(handle_queue_pause_member, "Pause or unpause a queue member"),
 };
 

Modified: trunk/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_voicemail.c?view=diff&rev=83213&r1=83212&r2=83213
==============================================================================
--- trunk/apps/app_voicemail.c (original)
+++ trunk/apps/app_voicemail.c Wed Sep 19 18:16:51 2007
@@ -7570,22 +7570,14 @@
 	return res;
 }
 
-static const char voicemail_show_users_help[] =
-"Usage: voicemail show users [for <context>]\n"
-"       Lists all mailboxes currently set up\n";
-
-static const char voicemail_show_zones_help[] =
-"Usage: voicemail show zones\n"
-"       Lists zone message formats\n";
-
-static int show_users_realtime(int fd, const char *context)
+static char *show_users_realtime(int fd, const char *context)
 {
 	struct ast_config *cfg;
 	const char *cat = NULL;
 
 	if (!(cfg = ast_load_realtime_multientry("voicemail", 
 		"context", context, NULL))) {
-		return RESULT_FAILURE;
+		return CLI_FAILURE;
 	}
 
 	ast_cli(fd, "\n"
@@ -7608,95 +7600,7 @@
 	ast_cli(fd, "=============================================================\n"
 	            "\n");
 
-	return RESULT_SUCCESS;
-}
-
-/*! \brief Show a list of voicemail users in the CLI */
-static int handle_voicemail_show_users(int fd, int argc, char *argv[])
-{
-	struct ast_vm_user *vmu;
-	char *output_format = "%-10s %-5s %-25s %-10s %6s\n";
-	const char *context = NULL;
-	int users_counter = 0;
-
-	if ((argc < 3) || (argc > 5) || (argc == 4))
-		return RESULT_SHOWUSAGE;
-	if (argc == 5) {
-		if (strcmp(argv[3],"for"))
-			return RESULT_SHOWUSAGE;
-		context = argv[4];
-	}
-
-	if (ast_check_realtime("voicemail")) {
-		if (!context) {
-			ast_cli(fd, "You must specify a specific context to show users from realtime!\n");
-			return RESULT_SHOWUSAGE;
-		}
-		return show_users_realtime(fd, context);
-	}
-
-	AST_LIST_LOCK(&users);
-	if (AST_LIST_EMPTY(&users)) {
-		ast_cli(fd, "There are no voicemail users currently defined\n");
-		AST_LIST_UNLOCK(&users);
-		return RESULT_FAILURE;
-	}
-	if (argc == 3)
-		ast_cli(fd, output_format, "Context", "Mbox", "User", "Zone", "NewMsg");
-	else {
-		int count = 0;
-		AST_LIST_TRAVERSE(&users, vmu, list) {
-			if (!strcmp(context, vmu->context))
-				count++;
-		}
-		if (count) {
-			ast_cli(fd, output_format, "Context", "Mbox", "User", "Zone", "NewMsg");
-		} else {
-			ast_cli(fd, "No such voicemail context \"%s\"\n", context);
-			AST_LIST_UNLOCK(&users);
-			return RESULT_FAILURE;
-		}
-	}
-	AST_LIST_TRAVERSE(&users, vmu, list) {
-		int newmsgs = 0, oldmsgs = 0;
-		char count[12], tmp[256] = "";
-
-		if ((argc == 3) || ((argc == 5) && !strcmp(context, vmu->context))) {
-			snprintf(tmp, sizeof(tmp), "%s@%s", vmu->mailbox, ast_strlen_zero(vmu->context) ? "default" : vmu->context);
-			inboxcount(tmp, &newmsgs, &oldmsgs);
-			snprintf(count,sizeof(count),"%d",newmsgs);
-			ast_cli(fd, output_format, vmu->context, vmu->mailbox, vmu->fullname, vmu->zonetag, count);
-			users_counter++;
-		}
-	}
-	AST_LIST_UNLOCK(&users);
-	ast_cli(fd, "%d voicemail users configured.\n", users_counter);
-	return RESULT_SUCCESS;
-}
-
-/*! \brief Show a list of voicemail zones in the CLI */
-static int handle_voicemail_show_zones(int fd, int argc, char *argv[])
-{
-	struct vm_zone *zone;
-	char *output_format = "%-15s %-20s %-45s\n";
-	int res = RESULT_SUCCESS;
-
-	if (argc != 3)
-		return RESULT_SHOWUSAGE;
-
-	AST_LIST_LOCK(&zones);
-	if (!AST_LIST_EMPTY(&zones)) {
-		ast_cli(fd, output_format, "Zone", "Timezone", "Message Format");
-		AST_LIST_TRAVERSE(&zones, zone, list) {
-			ast_cli(fd, output_format, zone->name, zone->timezone, zone->msg_format);
-		}
-	} else {
-		ast_cli(fd, "There are no voicemail zones currently defined\n");
-		res = RESULT_FAILURE;
-	}
-	AST_LIST_UNLOCK(&zones);
-
-	return res;
+	return CLI_SUCCESS;
 }
 
 static char *complete_voicemail_show_users(const char *line, const char *word, int pos, int state)
@@ -7723,14 +7627,119 @@
 	return NULL;
 }
 
+/*! \brief Show a list of voicemail users in the CLI */
+static char *handle_voicemail_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct ast_vm_user *vmu;
+	char *output_format = "%-10s %-5s %-25s %-10s %6s\n";
+	const char *context = NULL;
+	int users_counter = 0;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "voicemail show users";
+		e->usage =
+			"Usage: voicemail show users [for <context>]\n"
+			"       Lists all mailboxes currently set up\n";
+		return NULL;
+	case CLI_GENERATE:
+		return complete_voicemail_show_users(a->line, a->word, a->pos, a->n);
+	}	
+
+	if ((a->argc < 3) || (a->argc > 5) || (a->argc == 4))
+		return CLI_SHOWUSAGE;
+	if (a->argc == 5) {
+		if (strcmp(a->argv[3],"for"))
+			return CLI_SHOWUSAGE;
+		context = a->argv[4];
+	}
+
+	if (ast_check_realtime("voicemail")) {
+		if (!context) {
+			ast_cli(a->fd, "You must specify a specific context to show users from realtime!\n");
+			return CLI_SHOWUSAGE;
+		}
+		return show_users_realtime(a->fd, context);
+	}
+
+	AST_LIST_LOCK(&users);
+	if (AST_LIST_EMPTY(&users)) {
+		ast_cli(a->fd, "There are no voicemail users currently defined\n");
+		AST_LIST_UNLOCK(&users);
+		return CLI_FAILURE;
+	}
+	if (a->argc == 3)
+		ast_cli(a->fd, output_format, "Context", "Mbox", "User", "Zone", "NewMsg");
+	else {
+		int count = 0;
+		AST_LIST_TRAVERSE(&users, vmu, list) {
+			if (!strcmp(context, vmu->context))
+				count++;
+		}
+		if (count) {
+			ast_cli(a->fd, output_format, "Context", "Mbox", "User", "Zone", "NewMsg");
+		} else {
+			ast_cli(a->fd, "No such voicemail context \"%s\"\n", context);
+			AST_LIST_UNLOCK(&users);
+			return CLI_FAILURE;
+		}
+	}
+	AST_LIST_TRAVERSE(&users, vmu, list) {
+		int newmsgs = 0, oldmsgs = 0;
+		char count[12], tmp[256] = "";
+
+		if ((a->argc == 3) || ((a->argc == 5) && !strcmp(context, vmu->context))) {
+			snprintf(tmp, sizeof(tmp), "%s@%s", vmu->mailbox, ast_strlen_zero(vmu->context) ? "default" : vmu->context);
+			inboxcount(tmp, &newmsgs, &oldmsgs);
+			snprintf(count,sizeof(count),"%d",newmsgs);
+			ast_cli(a->fd, output_format, vmu->context, vmu->mailbox, vmu->fullname, vmu->zonetag, count);
+			users_counter++;
+		}
+	}
+	AST_LIST_UNLOCK(&users);
+	ast_cli(a->fd, "%d voicemail users configured.\n", users_counter);
+	return CLI_SUCCESS;
+}
+
+/*! \brief Show a list of voicemail zones in the CLI */
+static char *handle_voicemail_show_zones(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct vm_zone *zone;
+	char *output_format = "%-15s %-20s %-45s\n";
+	char *res = CLI_SUCCESS;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "voicemail show zones";
+		e->usage =
+			"Usage: voicemail show zones\n"
+			"       Lists zone message formats\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc != 3)
+		return CLI_SHOWUSAGE;
+
+	AST_LIST_LOCK(&zones);
+	if (!AST_LIST_EMPTY(&zones)) {
+		ast_cli(a->fd, output_format, "Zone", "Timezone", "Message Format");
+		AST_LIST_TRAVERSE(&zones, zone, list) {
+			ast_cli(a->fd, output_format, zone->name, zone->timezone, zone->msg_format);
+		}
+	} else {
+		ast_cli(a->fd, "There are no voicemail zones currently defined\n");
+		res = CLI_FAILURE;
+	}
+	AST_LIST_UNLOCK(&zones);
+
+	return res;
+}
+
 static struct ast_cli_entry cli_voicemail[] = {
-	{ { "voicemail", "show", "users", NULL },
-	handle_voicemail_show_users, "List defined voicemail boxes",
-	voicemail_show_users_help, complete_voicemail_show_users, NULL },
-
-	{ { "voicemail", "show", "zones", NULL },
-	handle_voicemail_show_zones, "List zone message formats",
-	voicemail_show_zones_help, NULL, NULL },
+	NEW_CLI(handle_voicemail_show_users, "List defined voicemail boxes"),
+	NEW_CLI(handle_voicemail_show_zones, "List zone message formats"),
 };
 
 static void poll_subscribed_mailboxes(void)

Modified: trunk/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_zap.c?view=diff&rev=83213&r1=83212&r2=83213
==============================================================================
--- trunk/channels/chan_zap.c (original)
+++ trunk/channels/chan_zap.c Wed Sep 19 18:16:51 2007
@@ -10463,61 +10463,88 @@
 	return complete_span_helper(line,word,pos,state,4);
 }
 
-static int handle_pri_set_debug_file(int fd, int argc, char **argv)
+static char *handle_pri_unset_debug_file(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "pri unset debug file";
+		e->usage = "Usage: pri unset debug file\n"
+			   "       Stop sending debug output to the previously \n"
+		           "       specified file\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;	
+	}
+	/* Assume it is unset */
+	ast_mutex_lock(&pridebugfdlock);
+	close(pridebugfd);
+	pridebugfd = -1;
+	ast_cli(a->fd, "PRI debug output to file disabled\n");
+	ast_mutex_unlock(&pridebugfdlock);
+	return CLI_SUCCESS;
+}
+
+static char *handle_pri_set_debug_file(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	int myfd;
-
-	if (!strncasecmp(argv[1], "set", 3)) {
-		if (argc < 5) 
-			return RESULT_SHOWUSAGE;
-
-		if (ast_strlen_zero(argv[4]))
-			return RESULT_SHOWUSAGE;
-
-		myfd = open(argv[4], O_CREAT|O_WRONLY, AST_FILE_MODE);
-		if (myfd < 0) {
-			ast_cli(fd, "Unable to open '%s' for writing\n", argv[4]);
-			return RESULT_SUCCESS;
-		}
-
-		ast_mutex_lock(&pridebugfdlock);
-
-		if (pridebugfd >= 0)
-			close(pridebugfd);
-
-		pridebugfd = myfd;
-		ast_copy_string(pridebugfilename,argv[4],sizeof(pridebugfilename));
-		
-		ast_mutex_unlock(&pridebugfdlock);
-
-		ast_cli(fd, "PRI debug output will be sent to '%s'\n", argv[4]);
-	} else {
-		/* Assume it is unset */
-		ast_mutex_lock(&pridebugfdlock);
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "pri set debug file";
+		e->usage = "Usage: pri set debug file [output-file]\n"
+			   "       Sends PRI debug output to the specified output file\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;	
+	}
+	if (a->argc < 5)
+		return CLI_SHOWUSAGE;
+
+	if (ast_strlen_zero(a->argv[4]))
+		return CLI_SHOWUSAGE;
+
+	myfd = open(a->argv[4], O_CREAT|O_WRONLY, AST_FILE_MODE);
+	if (myfd < 0) {
+		ast_cli(a->fd, "Unable to open '%s' for writing\n", a->argv[4]);
+		return CLI_SUCCESS;
+	}
+
+	ast_mutex_lock(&pridebugfdlock);
+
+	if (pridebugfd >= 0)
 		close(pridebugfd);
-		pridebugfd = -1;
-		ast_cli(fd, "PRI debug output to file disabled\n");
-		ast_mutex_unlock(&pridebugfdlock);
-	}
-
-	return RESULT_SUCCESS;
-}
-
-static int handle_pri_debug(int fd, int argc, char *argv[])
+
+	pridebugfd = myfd;
+	ast_copy_string(pridebugfilename,a->argv[4],sizeof(pridebugfilename));
+	ast_mutex_unlock(&pridebugfdlock);
+	ast_cli(a->fd, "PRI debug output will be sent to '%s'\n", a->argv[4]);
+	return CLI_SUCCESS;
+}
+
+static char *handle_pri_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	int span;
 	int x;
-	if (argc < 4) {
-		return RESULT_SHOWUSAGE;
-	}
-	span = atoi(argv[3]);
+	switch (cmd) {
+	case CLI_INIT:	
+		e->command = "pri debug span";
+		e->usage = 
+			"Usage: pri debug span <span>\n"
+			"       Enables debugging on a given PRI span\n";
+		return NULL;
+	case CLI_GENERATE:	
+		return complete_span_4(a->line, a->word, a->pos, a->n);
+	}
+	if (a->argc < 4) {
+		return CLI_SHOWUSAGE;
+	}
+	span = atoi(a->argv[3]);
 	if ((span < 1) || (span > NUM_SPANS)) {
-		ast_cli(fd, "Invalid span %s.  Should be a number %d to %d\n", argv[3], 1, NUM_SPANS);
-		return RESULT_SUCCESS;

[... 1232 lines stripped ...]



More information about the asterisk-commits mailing list