[asterisk-commits] qwell: trunk r83381 - in /trunk: apps/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 20 18:14:31 CDT 2007


Author: qwell
Date: Thu Sep 20 18:14:30 2007
New Revision: 83381

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

(issue #10724)
Patches:
      app_playback.c.patch uploaded by moy (license 222)
      app_minivm.c.patch uploaded by eliel (license 64)
      astmm.c.patch uploaded by eliel (license 64)

Modified:
    trunk/apps/app_minivm.c
    trunk/apps/app_playback.c
    trunk/main/astmm.c

Modified: trunk/apps/app_minivm.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_minivm.c?view=diff&rev=83381&r1=83380&r2=83381
==============================================================================
--- trunk/apps/app_minivm.c (original)
+++ trunk/apps/app_minivm.c Thu Sep 20 18:14:30 2007
@@ -463,7 +463,7 @@
 static char *message_template_parse_emailbody(const char *body);
 static int create_vmaccount(char *name, struct ast_variable *var, int realtime);
 static struct minivm_account *find_user_realtime(const char *domain, const char *username);
-static int handle_minivm_reload(int fd, int argc, char *argv[]);
+static char *handle_minivm_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 
 /*! \brief Create message template */
 static struct minivm_template *message_template_create(const char *name)
@@ -2484,50 +2484,37 @@
 	return 0;
 }
 
-static const char minivm_show_users_help[] =
-"Usage: minivm list accounts\n"
-"       Lists all mailboxes currently set up\n";
-
-static const char minivm_show_zones_help[] =
-"Usage: minivm list zones\n"
-"       Lists zone message formats\n";
-
-static const char minivm_list_templates_help[] =
-"Usage: minivm list templates\n"
-"       Lists message templates for e-mail, paging and IM\n";
-
-static const char minivm_show_stats_help[] =
-"Usage: minivm show stats\n"
-"       Display Mini-Voicemail counters\n";
-
-static const char minivm_show_settings_help[] =
-"Usage: minivm show settings\n"
-"       Display Mini-Voicemail general settings\n";
-
-static const char minivm_reload_help[] =
-"Usage: minivm reload\n"
-"       Reload mini-voicemail configuration and reset statistics\n";
-
 /*! \brief CLI routine for listing templates */
-static int handle_minivm_list_templates(int fd, int argc, char *argv[])
+static char *handle_minivm_list_templates(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct minivm_template *this;
 	char *output_format = "%-15s %-10s %-10s %-15.15s %-50s\n";
 	int count = 0;
 
-	if (argc > 3)
-		return RESULT_SHOWUSAGE;
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "minivm list templates";
+		e->usage =
+			"Usage: minivm list templates\n"
+			"       Lists message templates for e-mail, paging and IM\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc > 3)
+		return CLI_SHOWUSAGE;
 
 	AST_LIST_LOCK(&message_templates);
 	if (AST_LIST_EMPTY(&message_templates)) {
-		ast_cli(fd, "There are no message templates defined\n");
+		ast_cli(a->fd, "There are no message templates defined\n");
 		AST_LIST_UNLOCK(&message_templates);
-		return RESULT_FAILURE;
-	}
-	ast_cli(fd, output_format, "Template name", "Charset", "Locale", "Attach media", "Subject");
-	ast_cli(fd, output_format, "-------------", "-------", "------", "------------", "-------");
+		return CLI_FAILURE;
+	}
+	ast_cli(a->fd, output_format, "Template name", "Charset", "Locale", "Attach media", "Subject");
+	ast_cli(a->fd, output_format, "-------------", "-------", "------", "------------", "-------");
 	AST_LIST_TRAVERSE(&message_templates, this, list) {
-		ast_cli(fd, output_format, this->name, 
+		ast_cli(a->fd, output_format, this->name, 
 			this->charset ? this->charset : "-", 
 			this->locale ? this->locale : "-",
 			this->attachment ? "Yes" : "No",
@@ -2535,75 +2522,9 @@
 		count++;
 	}
 	AST_LIST_UNLOCK(&message_templates);
-	ast_cli(fd, "\n * Total: %d minivoicemail message templates\n", count);
-	return RESULT_SUCCESS;
-}
-
-/*! \brief CLI command to list voicemail accounts */
-static int handle_minivm_show_users(int fd, int argc, char *argv[])
-{
-	struct minivm_account *vmu;
-	char *output_format = "%-23s %-15s %-15s %-10s %-10s %-50s\n";
-	int count = 0;
-
-	if ((argc < 3) || (argc > 5) || (argc == 4))
-		return RESULT_SHOWUSAGE;
-	if ((argc == 5) && strcmp(argv[3],"for"))
-		return RESULT_SHOWUSAGE;
-
-	AST_LIST_LOCK(&minivm_accounts);
-	if (AST_LIST_EMPTY(&minivm_accounts)) {
-		ast_cli(fd, "There are no voicemail users currently defined\n");
-		AST_LIST_UNLOCK(&minivm_accounts);
-		return RESULT_FAILURE;
-	}
-	ast_cli(fd, output_format, "User", "E-Template", "P-template", "Zone", "Format", "Full name");
-	ast_cli(fd, output_format, "----", "----------", "----------", "----", "------", "---------");
-	AST_LIST_TRAVERSE(&minivm_accounts, vmu, list) {
-		char tmp[256] = "";
-
-
-		if ((argc == 3) || ((argc == 5) && !strcmp(argv[4], vmu->domain))) {
-			count++;
-			snprintf(tmp, sizeof(tmp), "%s@%s", vmu->username, vmu->domain);
-			ast_cli(fd, output_format, tmp, vmu->etemplate ? vmu->etemplate : "-", 
-				vmu->ptemplate ? vmu->ptemplate : "-",
-				vmu->zonetag ? vmu->zonetag : "-", 
-				vmu->attachfmt ? vmu->attachfmt : "-",
-				vmu->fullname);
-		}
-	}
-	AST_LIST_UNLOCK(&minivm_accounts);
-	ast_cli(fd, "\n * Total: %d minivoicemail accounts\n", count);
-	return RESULT_SUCCESS;
-}
-
-/*! \brief Show a list of voicemail zones in the CLI */
-static int handle_minivm_show_zones(int fd, int argc, char *argv[])
-{
-	struct minivm_zone *zone;
-	char *output_format = "%-15s %-20s %-45s\n";
-	int res = RESULT_SUCCESS;
-
-	if (argc != 3)
-		return RESULT_SHOWUSAGE;
-
-	AST_LIST_LOCK(&minivm_zones);
-	if (!AST_LIST_EMPTY(&minivm_zones)) {
-		ast_cli(fd, output_format, "Zone", "Timezone", "Message Format");
-		ast_cli(fd, output_format, "----", "--------", "--------------");
-		AST_LIST_TRAVERSE(&minivm_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(&minivm_zones);
-
-	return res;
-}
-
+	ast_cli(a->fd, "\n * Total: %d minivoicemail message templates\n", count);
+	return CLI_SUCCESS;
+}
 
 static char *complete_minivm_show_users(const char *line, const char *word, int pos, int state)
 {
@@ -2612,7 +2533,7 @@
 	struct minivm_account *vmu;
 	const char *domain = "";
 
-	/* 0 - show; 1 - voicemail; 2 - users; 3 - for; 4 - <domain> */
+	/* 0 - voicemail; 1 - list; 2 - accounts; 3 - for; 4 - <domain> */
 	if (pos > 4)
 		return NULL;
 	if (pos == 3)
@@ -2629,53 +2550,161 @@
 	return NULL;
 }
 
+/*! \brief CLI command to list voicemail accounts */
+static char *handle_minivm_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct minivm_account *vmu;
+	char *output_format = "%-23s %-15s %-15s %-10s %-10s %-50s\n";
+	int count = 0;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "minivm list accounts";
+		e->usage =
+			"Usage: minivm list accounts\n"
+			"       Lists all mailboxes currently set up\n";
+		return NULL;
+	case CLI_GENERATE:
+		return complete_minivm_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) && strcmp(a->argv[3],"for"))
+		return CLI_SHOWUSAGE;
+
+	AST_LIST_LOCK(&minivm_accounts);
+	if (AST_LIST_EMPTY(&minivm_accounts)) {
+		ast_cli(a->fd, "There are no voicemail users currently defined\n");
+		AST_LIST_UNLOCK(&minivm_accounts);
+		return CLI_FAILURE;
+	}
+	ast_cli(a->fd, output_format, "User", "E-Template", "P-template", "Zone", "Format", "Full name");
+	ast_cli(a->fd, output_format, "----", "----------", "----------", "----", "------", "---------");
+	AST_LIST_TRAVERSE(&minivm_accounts, vmu, list) {
+		char tmp[256] = "";
+		if ((a->argc == 3) || ((a->argc == 5) && !strcmp(a->argv[4], vmu->domain))) {
+			count++;
+			snprintf(tmp, sizeof(tmp), "%s@%s", vmu->username, vmu->domain);
+			ast_cli(a->fd, output_format, tmp, vmu->etemplate ? vmu->etemplate : "-", 
+				vmu->ptemplate ? vmu->ptemplate : "-",
+				vmu->zonetag ? vmu->zonetag : "-", 
+				vmu->attachfmt ? vmu->attachfmt : "-",
+				vmu->fullname);
+		}
+	}
+	AST_LIST_UNLOCK(&minivm_accounts);
+	ast_cli(a->fd, "\n * Total: %d minivoicemail accounts\n", count);
+	return CLI_SUCCESS;
+}
+
+/*! \brief Show a list of voicemail zones in the CLI */
+static char *handle_minivm_show_zones(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct minivm_zone *zone;
+	char *output_format = "%-15s %-20s %-45s\n";
+	char *res = CLI_SUCCESS;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "minivm list zones";
+		e->usage =
+			"Usage: minivm list zones\n"
+			"       Lists zone message formats\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc != 3)
+		return CLI_SHOWUSAGE;
+
+	AST_LIST_LOCK(&minivm_zones);
+	if (!AST_LIST_EMPTY(&minivm_zones)) {
+		ast_cli(a->fd, output_format, "Zone", "Timezone", "Message Format");
+		ast_cli(a->fd, output_format, "----", "--------", "--------------");
+		AST_LIST_TRAVERSE(&minivm_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(&minivm_zones);
+
+	return res;
+}
+
 /*! \brief CLI Show settings */
-static int handle_minivm_show_settings(int fd, int argc, char *argv[])
-{
-	ast_cli(fd, "* Mini-Voicemail general settings\n");
-	ast_cli(fd, "  -------------------------------\n");
-	ast_cli(fd, "\n");
-	ast_cli(fd, "  Mail command (shell):               %s\n", global_mailcmd);
-	ast_cli(fd, "  Max silence:                        %d\n", global_maxsilence);
-	ast_cli(fd, "  Silence treshold:                   %d\n", global_silencethreshold);
-	ast_cli(fd, "  Max message length (secs):          %d\n", global_vmmaxmessage);
-	ast_cli(fd, "  Min message length (secs):          %d\n", global_vmminmessage);
-	ast_cli(fd, "  Default format:                     %s\n", default_vmformat);
-	ast_cli(fd, "  Extern notify (shell):              %s\n", global_externnotify);
-	ast_cli(fd, "  Logfile:                            %s\n", global_logfile[0] ? global_logfile : "<disabled>");
-	ast_cli(fd, "  Operator exit:                      %s\n", ast_test_flag(&globalflags, MVM_OPERATOR) ? "Yes" : "No");
-	ast_cli(fd, "  Message review:                     %s\n", ast_test_flag(&globalflags, MVM_REVIEW) ? "Yes" : "No");
-
-	ast_cli(fd, "\n");
-	return RESULT_SUCCESS;
+static char *handle_minivm_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "minivm show settings";
+		e->usage =
+			"Usage: minivm show settings\n"
+			"       Display Mini-Voicemail general settings\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	ast_cli(a->fd, "* Mini-Voicemail general settings\n");
+	ast_cli(a->fd, "  -------------------------------\n");
+	ast_cli(a->fd, "\n");
+	ast_cli(a->fd, "  Mail command (shell):               %s\n", global_mailcmd);
+	ast_cli(a->fd, "  Max silence:                        %d\n", global_maxsilence);
+	ast_cli(a->fd, "  Silence treshold:                   %d\n", global_silencethreshold);
+	ast_cli(a->fd, "  Max message length (secs):          %d\n", global_vmmaxmessage);
+	ast_cli(a->fd, "  Min message length (secs):          %d\n", global_vmminmessage);
+	ast_cli(a->fd, "  Default format:                     %s\n", default_vmformat);
+	ast_cli(a->fd, "  Extern notify (shell):              %s\n", global_externnotify);
+	ast_cli(a->fd, "  Logfile:                            %s\n", global_logfile[0] ? global_logfile : "<disabled>");
+	ast_cli(a->fd, "  Operator exit:                      %s\n", ast_test_flag(&globalflags, MVM_OPERATOR) ? "Yes" : "No");
+	ast_cli(a->fd, "  Message review:                     %s\n", ast_test_flag(&globalflags, MVM_REVIEW) ? "Yes" : "No");
+
+	ast_cli(a->fd, "\n");
+	return CLI_SUCCESS;
 }
 
 /*! \brief Show stats */
-static int handle_minivm_show_stats(int fd, int argc, char *argv[])
+static char *handle_minivm_show_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_tm time;
 	char buf[BUFSIZ];
 
-	ast_cli(fd, "* Mini-Voicemail statistics\n");
-	ast_cli(fd, "  -------------------------\n");
-	ast_cli(fd, "\n");
-	ast_cli(fd, "  Voicemail accounts:                  %5d\n", global_stats.voicemailaccounts);
-	ast_cli(fd, "  Templates:                           %5d\n", global_stats.templates);
-	ast_cli(fd, "  Timezones:                           %5d\n", global_stats.timezones);
+	switch (cmd) {
+	
+	case CLI_INIT:
+		e->command = "minivm show stats";
+		e->usage =
+			"Usage: minivm show stats\n"
+			"       Display Mini-Voicemail counters\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	ast_cli(a->fd, "* Mini-Voicemail statistics\n");
+	ast_cli(a->fd, "  -------------------------\n");
+	ast_cli(a->fd, "\n");
+	ast_cli(a->fd, "  Voicemail accounts:                  %5d\n", global_stats.voicemailaccounts);
+	ast_cli(a->fd, "  Templates:                           %5d\n", global_stats.templates);
+	ast_cli(a->fd, "  Timezones:                           %5d\n", global_stats.timezones);
 	if (global_stats.receivedmessages == 0) {
-		ast_cli(fd, "  Received messages since last reset:  <none>\n");
+		ast_cli(a->fd, "  Received messages since last reset:  <none>\n");
 	} else {
-		ast_cli(fd, "  Received messages since last reset:  %d\n", global_stats.receivedmessages);
+		ast_cli(a->fd, "  Received messages since last reset:  %d\n", global_stats.receivedmessages);
 		ast_localtime(&global_stats.lastreceived, &time, NULL);
 		ast_strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time);
-		ast_cli(fd, "  Last received voicemail:             %s\n", buf);
+		ast_cli(a->fd, "  Last received voicemail:             %s\n", buf);
 	}
 	ast_localtime(&global_stats.reset, &time, NULL);
 	ast_strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time);
-	ast_cli(fd, "  Last reset:                          %s\n", buf);
-
-	ast_cli(fd, "\n");
-	return RESULT_SUCCESS;
+	ast_cli(a->fd, "  Last reset:                          %s\n", buf);
+
+	ast_cli(a->fd, "\n");
+	return CLI_SUCCESS;
 }
 
 /*! \brief  ${MINIVMACCOUNT()} Dialplan function - reads account data */
@@ -2963,29 +2992,12 @@
 
 /*! \brief CLI commands for Mini-voicemail */
 static struct ast_cli_entry cli_minivm[] = {
-	{ { "minivm", "list", "accounts", NULL },
-	handle_minivm_show_users, "List defined mini-voicemail boxes",
-	minivm_show_users_help, complete_minivm_show_users, NULL },
-
-	{ { "minivm", "list", "zones", NULL },
-	handle_minivm_show_zones, "List zone message formats",
-	minivm_show_zones_help, NULL, NULL },
-
-	{ { "minivm", "list", "templates", NULL },
-	handle_minivm_list_templates, "List message templates",
-	minivm_list_templates_help, NULL, NULL },
-
-	{ { "minivm", "reload", NULL, NULL },
-	handle_minivm_reload, "Reload Mini-voicemail configuration",
-	minivm_reload_help, NULL, NULL },
-
-	{ { "minivm", "show", "stats", NULL },
-	handle_minivm_show_stats, "Show some mini-voicemail statistics",
-	minivm_show_stats_help, NULL, NULL },
-
-	{ { "minivm", "show", "settings", NULL },
-	handle_minivm_show_settings, "Show mini-voicemail general settings",
-	minivm_show_settings_help, NULL, NULL },
+	NEW_CLI(handle_minivm_show_users, "List defined mini-voicemail boxes"),
+	NEW_CLI(handle_minivm_show_zones, "List zone message formats"),
+	NEW_CLI(handle_minivm_list_templates, "List message templates"),	
+	NEW_CLI(handle_minivm_reload, "Reload Mini-voicemail configuration"),
+	NEW_CLI(handle_minivm_show_stats, "Show some mini-voicemail statistics"),
+	NEW_CLI(handle_minivm_show_settings, "Show mini-voicemail general settings"),
 };
 
 static struct ast_custom_function minivm_counter_function = {
@@ -3061,11 +3073,23 @@
 }
 
 /*! \brief Reload cofiguration */
-static int handle_minivm_reload(int fd, int argc, char *argv[])
-{
+static char *handle_minivm_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "minivm reload";
+		e->usage =
+			"Usage: minivm reload\n"
+			"       Reload mini-voicemail configuration and reset statistics\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+	
 	reload();
-	ast_cli(fd, "\n-- Mini voicemail re-configured \n");
-	return RESULT_SUCCESS;
+	ast_cli(a->fd, "\n-- Mini voicemail re-configured \n");
+	return CLI_SUCCESS;
 }
 
 /*! \brief Unload mini voicemail module */

Modified: trunk/apps/app_playback.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_playback.c?view=diff&rev=83381&r1=83380&r2=83381
==============================================================================
--- trunk/apps/app_playback.c (original)
+++ trunk/apps/app_playback.c Thu Sep 20 18:14:30 2007
@@ -75,14 +75,6 @@
 static const void *say_api_buf[40];
 static const char *say_old = "old";
 static const char *say_new = "new";
-static const char say_load_usage[] = 
-"Usage: say load [new|old]\n"
-"       say load\n"
-"	   Report status of current say mode\n"
-"       say load new\n"
-"          Set say method, configured in say.conf\n"
-"       say load old\n"
-"          Set old say metod, coded in asterisk core\n";
 
 static void save_say_mode(const void *arg)
 {
@@ -366,17 +358,31 @@
 }
 
 
-static int __say_cli_init(int fd, int argc, char *argv[])
+static char *__say_cli_init(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	const char *old_mode = say_api_buf[0] ? say_new : say_old;
 	char *mode;
-
-	if (argc == 2) {
-		ast_cli(fd, "say mode is [%s]\n", old_mode);
-		return RESULT_SUCCESS;
-        } else if (argc != 3)
-                return RESULT_SHOWUSAGE;
-        mode = argv[2];
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "say load [new|old]";
+		e->usage = 
+			"Usage: say load [new|old]\n"
+			"       say load\n"
+			"	   Report status of current say mode\n"
+			"       say load new\n"
+			"          Set say method, configured in say.conf\n"
+			"       say load old\n"
+			"          Set old say metod, coded in asterisk core\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+	if (a->argc == 2) {
+		ast_cli(a->fd, "say mode is [%s]\n", old_mode);
+		return CLI_SUCCESS;
+        } else if (a->argc != 3)
+                return CLI_SHOWUSAGE;
+        mode = a->argv[2];
 	
 	if (!strcmp(mode, old_mode)) {
 		ast_log(LOG_NOTICE, "say mode is %s already\n", mode);
@@ -385,23 +391,13 @@
 			ast_log(LOG_NOTICE, "init say.c from %s to %s\n", old_mode, mode);
 		}
 	}
-
-	return RESULT_SUCCESS;
-}
-
+	return CLI_SUCCESS;
+}
 
 static struct ast_cli_entry cli_playback[] = {
-        { { "say", "load", NULL },
-	__say_cli_init, "Set or show the say mode",
-	say_load_usage },
-
-        { { "say", "load", "new", NULL },
-	__say_cli_init, "Set the say mode",
-	say_load_usage },
-
-        { { "say", "load", "old", NULL },
-	__say_cli_init, "Set the say mode",
-	say_load_usage },
+	NEW_CLI(__say_cli_init, "Set or show the say mode"),
+	NEW_CLI(__say_cli_init, "Set the say mode"),
+	NEW_CLI(__say_cli_init, "Set the say mode"),
 };
 
 static int playback_exec(struct ast_channel *chan, void *data)

Modified: trunk/main/astmm.c
URL: http://svn.digium.com/view/asterisk/trunk/main/astmm.c?view=diff&rev=83381&r1=83380&r2=83381
==============================================================================
--- trunk/main/astmm.c (original)
+++ trunk/main/astmm.c Thu Sep 20 18:14:30 2007
@@ -307,7 +307,7 @@
 	return size;
 }
 
-static int handle_show_memory(int fd, int argc, char *argv[])
+static char *handle_memory_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	char *fn = NULL;
 	struct ast_region *reg;
@@ -317,8 +317,21 @@
 	unsigned int count = 0;
 	unsigned int *fence;
 
-	if (argc > 3)
-		fn = argv[3];
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "memory show allocations";
+		e->usage =
+			"Usage: memory show allocations [<file>]\n"
+			"       Dumps a list of all segments of allocated memory, optionally\n"
+			"       limited to those from a specific file\n";
+		break;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+
+	if (a->argc > 3)
+		fn = a->argv[3];
 
 	ast_mutex_lock(&showmemorylock);
 	for (x = 0; x < SOME_PRIME; x++) {
@@ -336,7 +349,7 @@
 				}
 			}
 			if (!fn || !strcasecmp(fn, reg->file)) {
-				ast_cli(fd, "%10d bytes allocated%s in %20s at line %5d of %s\n", 
+				ast_cli(a->fd, "%10d bytes allocated%s in %20s at line %5d of %s\n", 
 					(int) reg->len, reg->cache ? " (cache)" : "", 
 					reg->func, reg->lineno, reg->file);
 				len += reg->len;
@@ -349,14 +362,14 @@
 	ast_mutex_unlock(&showmemorylock);
 	
 	if (cache_len)
-		ast_cli(fd, "%d bytes allocated (%d in caches) in %d allocations\n", len, cache_len, count);
+		ast_cli(a->fd, "%d bytes allocated (%d in caches) in %d allocations\n", len, cache_len, count);
 	else
-		ast_cli(fd, "%d bytes allocated in %d allocations\n", len, count);
-	
-	return RESULT_SUCCESS;
-}
-
-static int handle_show_memory_summary(int fd, int argc, char *argv[])
+		ast_cli(a->fd, "%d bytes allocated in %d allocations\n", len, count);
+	
+	return CLI_SUCCESS;
+}
+
+static char *handle_memory_show_summary(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	char *fn = NULL;
 	int x;
@@ -372,8 +385,20 @@
 		struct file_summary *next;
 	} *list = NULL, *cur;
 	
-	if (argc > 3) 
-		fn = argv[3];
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "memory show summary";
+		e->usage =
+			"Usage: memory show summary [<file>]\n"
+			"       Summarizes heap memory allocations by file, or optionally\n"
+			"by function, if a file is specified\n";
+		break;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc > 3) 
+		fn = a->argv[3];
 
 	ast_mutex_lock(&reglock);
 	for (x = 0; x < SOME_PRIME; x++) {
@@ -408,49 +433,34 @@
 		count += cur->count;
 		if (cur->cache_len) {
 			if (fn) {
-				ast_cli(fd, "%10d bytes (%10d cache) in %d allocations in function '%s' of '%s'\n", 
+				ast_cli(a->fd, "%10d bytes (%10d cache) in %d allocations in function '%s' of '%s'\n", 
 					cur->len, cur->cache_len, cur->count, cur->fn, fn);
 			} else {
-				ast_cli(fd, "%10d bytes (%10d cache) in %d allocations in file '%s'\n", 
+				ast_cli(a->fd, "%10d bytes (%10d cache) in %d allocations in file '%s'\n", 
 					cur->len, cur->cache_len, cur->count, cur->fn);
 			}
 		} else {
 			if (fn) {
-				ast_cli(fd, "%10d bytes in %d allocations in function '%s' of '%s'\n", 
+				ast_cli(a->fd, "%10d bytes in %d allocations in function '%s' of '%s'\n", 
 					cur->len, cur->count, cur->fn, fn);
 			} else {
-				ast_cli(fd, "%10d bytes in %d allocations in file '%s'\n", 
+				ast_cli(a->fd, "%10d bytes in %d allocations in file '%s'\n", 
 					cur->len, cur->count, cur->fn);
 			}
 		}
 	}
 
 	if (cache_len)
-		ast_cli(fd, "%d bytes allocated (%d in caches) in %d allocations\n", len, cache_len, count);
+		ast_cli(a->fd, "%d bytes allocated (%d in caches) in %d allocations\n", len, cache_len, count);
 	else
-		ast_cli(fd, "%d bytes allocated in %d allocations\n", len, count);
-
-	return RESULT_SUCCESS;
-}
-
-static char show_memory_help[] = 
-"Usage: memory show allocations [<file>]\n"
-"       Dumps a list of all segments of allocated memory, optionally\n"
-"limited to those from a specific file\n";
-
-static char show_memory_summary_help[] = 
-"Usage: memory show summary [<file>]\n"
-"       Summarizes heap memory allocations by file, or optionally\n"
-"by function, if a file is specified\n";
+		ast_cli(a->fd, "%d bytes allocated in %d allocations\n", len, count);
+
+	return CLI_SUCCESS;
+}
 
 static struct ast_cli_entry cli_memory[] = {
-	{ { "memory", "show", "allocations", NULL },
-	handle_show_memory, "Display outstanding memory allocations",
-	show_memory_help },
-
-	{ { "memory", "show", "summary", NULL },
-	handle_show_memory_summary, "Summarize outstanding memory allocations",
-	show_memory_summary_help },
+	NEW_CLI(handle_memory_show, "Display outstanding memory allocations"),
+	NEW_CLI(handle_memory_show_summary, "Summarize outstanding memory allocations"),
 };
 
 void __ast_mm_init(void)




More information about the asterisk-commits mailing list