[asterisk-commits] pabelanger: branch pabelanger/issue17173 r258773 - /team/pabelanger/issue1717...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Apr 24 12:44:06 CDT 2010


Author: pabelanger
Date: Sat Apr 24 12:44:01 2010
New Revision: 258773

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=258773
Log:
New CLI functions for manager interface events.

Modified:
    team/pabelanger/issue17173/main/manager.c

Modified: team/pabelanger/issue17173/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/pabelanger/issue17173/main/manager.c?view=diff&rev=258773&r1=258772&r2=258773
==============================================================================
--- team/pabelanger/issue17173/main/manager.c (original)
+++ team/pabelanger/issue17173/main/manager.c Sat Apr 24 12:44:01 2010
@@ -1195,26 +1195,38 @@
 	struct manager_action *cur;
 	struct ast_str *authority;
 	int num, l, which;
-	char *ret = NULL;
+	char *ret = NULL, *command, *usage;
 #ifdef AST_XML_DOCS
 	char syntax_title[64], description_title[64], synopsis_title[64], seealso_title[64], arguments_title[64];
 #endif
 
+	if (type == MANAGER_COMMAND) {
+		command = "manager show command";
+		usage =
+			"Usage: manager show command <actionname> [<actionname> [<actionname> [...]]]\n"
+			"	Shows the detailed description for a specific Asterisk manager interface command.\n";
+	} else {
+		command = "manager show event";
+		usage =
+			"Usage: manager show event <actionname> [<actionname> [<actionname> [...]]]\n"
+			"	Shows the detailed description for a specific Asterisk manager interface event.\n";
+	}
+
 	switch (cmd) {
 	case CLI_INIT:
-		e->command = "manager show command";
-		e->usage =
-			"Usage: manager show command <actionname> [<actionname> [<actionname> [...]]]\n"
-			"	Shows the detailed description for a specific Asterisk manager interface command.\n";
+		e->command = command;
+		e->usage = usage;
 		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 (cur->type == type) {
+				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 */
+				}
 			}
 		}
 		AST_RWLIST_UNLOCK(&actions);
@@ -1236,30 +1248,32 @@
 
 	AST_RWLIST_RDLOCK(&actions);
 	AST_RWLIST_TRAVERSE(&actions, cur, list) {
-		for (num = 3; num < a->argc; num++) {
-			if (!strcasecmp(cur->action, a->argv[num])) {
+		if (cur->type == type) {
+			for (num = 3; num < a->argc; num++) {
+				if (!strcasecmp(cur->action, a->argv[num])) {
 #ifdef AST_XML_DOCS
-				if (cur->docsrc == AST_XML_DOC) {
-					ast_cli(a->fd, "%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n",
-						syntax_title,
-						ast_xmldoc_printable(S_OR(cur->syntax, "Not available"), 1),
-						synopsis_title,
-						ast_xmldoc_printable(S_OR(cur->synopsis, "Not available"), 1),
-						description_title,
-						ast_xmldoc_printable(S_OR(cur->description, "Not available"), 1),
-						arguments_title,
-						ast_xmldoc_printable(S_OR(cur->arguments, "Not available"), 1),
-						seealso_title,
-						ast_xmldoc_printable(S_OR(cur->seealso, "Not available"), 1));
-				} else {
+					if (cur->docsrc == AST_XML_DOC) {
+						ast_cli(a->fd, "%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n",
+							syntax_title,
+							ast_xmldoc_printable(S_OR(cur->syntax, "Not available"), 1),
+							synopsis_title,
+							ast_xmldoc_printable(S_OR(cur->synopsis, "Not available"), 1),
+							description_title,
+							ast_xmldoc_printable(S_OR(cur->description, "Not available"), 1),
+							arguments_title,
+							ast_xmldoc_printable(S_OR(cur->arguments, "Not available"), 1),
+							seealso_title,
+							ast_xmldoc_printable(S_OR(cur->seealso, "Not available"), 1));
+					} else {
 #endif
-					ast_cli(a->fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n",
-							cur->action, cur->synopsis,
-							authority_to_str(cur->authority, &authority),
-							S_OR(cur->description, ""));
+						ast_cli(a->fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n",
+								cur->action, cur->synopsis,
+								authority_to_str(cur->authority, &authority),
+								S_OR(cur->description, ""));
 #ifdef AST_XML_DOCS
+					}
+#endif
 				}
-#endif
 			}
 		}
 	}
@@ -1271,6 +1285,11 @@
 static char *handle_showmancmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	return handle_show_manager_action(MANAGER_COMMAND, e, cmd, a);
+}
+
+static char *handle_show_manager_event(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	return handle_show_manager_action(MANAGER_EVENT, e, cmd, a);
 }
 
 static char *handle_mandebug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
@@ -1409,13 +1428,25 @@
 {
 	struct manager_action *cur;
 	struct ast_str *authority;
+	char *command, *usage;
 #define HSMC_FORMAT "  %-15.15s  %-15.15s  %-55.55s\n"
+
+	if (type == MANAGER_COMMAND) {
+		command = "manager show commands";
+		usage =
+			"Usage: manager show commands\n"
+			"	Prints a listing of all the available Asterisk manager interface commands.\n";
+	} else {
+		command = "manager show events";
+		usage =
+			"Usage: manager show events\n"
+			"	Prints a listing of all the available Asterisk manager interface events.\n";
+	}
+
 	switch (cmd) {
 	case CLI_INIT:
-		e->command = "manager show commands";
-		e->usage =
-			"Usage: manager show commands\n"
-			"	Prints a listing of all the available Asterisk manager interface commands.\n";
+		e->command = command;
+		e->usage = usage;
 		return NULL;
 	case CLI_GENERATE:
 		return NULL;
@@ -1426,16 +1457,24 @@
 
 	AST_RWLIST_RDLOCK(&actions);
 	AST_RWLIST_TRAVERSE(&actions, cur, list)
-		ast_cli(a->fd, HSMC_FORMAT, cur->action, authority_to_str(cur->authority, &authority), cur->synopsis);
+		if (cur->type == type) {
+			ast_cli(a->fd, HSMC_FORMAT, cur->action, authority_to_str(cur->authority, &authority), cur->synopsis);
+		}
 	AST_RWLIST_UNLOCK(&actions);
 
 	return CLI_SUCCESS;
 }
 
-/*! \brief  CLI command  manager list commands */
+/*! \brief  CLI command manager list commands */
 static char *handle_showmancmds(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	return handle_show_manager_actions(MANAGER_COMMAND, e, cmd, a);
+}
+
+/*! \brief  CLI command manager list events */
+static char *handle_show_manager_events(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	return handle_show_manager_actions(MANAGER_EVENT, e, cmd, a);
 }
 
 /*! \brief CLI command manager list connected */
@@ -1532,6 +1571,8 @@
 	AST_CLI_DEFINE(handle_showmanagers, "List configured manager users"),
 	AST_CLI_DEFINE(handle_showmanager, "Display information on a specific manager user"),
 	AST_CLI_DEFINE(handle_mandebug, "Show, enable, disable debugging of the manager code"),
+	AST_CLI_DEFINE(handle_show_manager_event, "Show a manager interface event"),
+	AST_CLI_DEFINE(handle_show_manager_events, "List manager interface events"),
 	AST_CLI_DEFINE(handle_manager_reload, "Reload manager configurations"),
 };
 
@@ -4475,6 +4516,7 @@
 		return -1;
 	}
 
+	cur->type = type;
 	cur->action = action;
 	cur->authority = auth;
 	cur->func = func;




More information about the asterisk-commits mailing list