[svn-commits] pabelanger: branch pabelanger/xmldoc r309641 - in /team/pabelanger/xmldoc: in...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Mar 4 17:34:08 CST 2011


Author: pabelanger
Date: Fri Mar  4 17:34:04 2011
New Revision: 309641

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=309641
Log:
First working copy! However, duplicated alot of code.

Modified:
    team/pabelanger/xmldoc/include/asterisk/manager.h
    team/pabelanger/xmldoc/main/manager.c
    team/pabelanger/xmldoc/main/xmldoc.c

Modified: team/pabelanger/xmldoc/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/team/pabelanger/xmldoc/include/asterisk/manager.h?view=diff&rev=309641&r1=309640&r2=309641
==============================================================================
--- team/pabelanger/xmldoc/include/asterisk/manager.h (original)
+++ team/pabelanger/xmldoc/include/asterisk/manager.h Fri Mar  4 17:34:04 2011
@@ -135,7 +135,7 @@
 
 struct manager_action {
 	/*! Name of the action */
-	const char *action;
+	const char *name;
 	AST_DECLARE_STRING_FIELDS(
 		AST_STRING_FIELD(synopsis);	/*!< Synopsis text (short description). */
 		AST_STRING_FIELD(description);	/*!< Description (help text) */
@@ -153,6 +153,24 @@
 	AST_RWLIST_ENTRY(manager_action) list;
 };
 
+struct manager_event {
+	/*! Name of the action */
+	const char *name;
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(synopsis);	/*!< Synopsis text (short description). */
+		AST_STRING_FIELD(description);	/*!< Description (help text) */
+		AST_STRING_FIELD(syntax);	/*!< Syntax text */
+		AST_STRING_FIELD(arguments);	/*!< Description of each argument. */
+		AST_STRING_FIELD(seealso);	/*!< See also */
+	);
+	/*! Permission required for action.  EVENT_FLAG_* */
+	int authority;
+	/*! Where the documentation come from. */
+	enum ast_doc_src docsrc;
+	/*! For easy linking */
+	AST_RWLIST_ENTRY(manager_event) list;
+};
+
 /*! \brief External routines may register/unregister manager callbacks this way 
  * \note  Use ast_manager_register2() to register with help text for new manager commands */
 #define ast_manager_register(a, b, c, d) ast_manager_register2(a, b, c, d, NULL)

Modified: team/pabelanger/xmldoc/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/pabelanger/xmldoc/main/manager.c?view=diff&rev=309641&r1=309640&r2=309641
==============================================================================
--- team/pabelanger/xmldoc/main/manager.c (original)
+++ team/pabelanger/xmldoc/main/manager.c Fri Mar  4 17:34:04 2011
@@ -1016,8 +1016,11 @@
 /*! \brief list of users found in the config file */
 static AST_RWLIST_HEAD_STATIC(users, ast_manager_user);
 
-/*! \brief list of actions registered */
+/*! \brief list of manager actions registered */
 static AST_RWLIST_HEAD_STATIC(actions, manager_action);
+
+/*! \brief list of manager events registered */
+static AST_RWLIST_HEAD_STATIC(events, manager_event);
 
 /*! \brief list of hooks registered */
 static AST_RWLIST_HEAD_STATIC(manager_hooks, manager_custom_hook);
@@ -1365,6 +1368,14 @@
 
 static char *handle_show_manager_event(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
+	struct manager_event *cur;
+	struct ast_str *authority;
+	int num, l, which;
+	char *ret = NULL;
+#ifdef AST_XML_DOCS
+	char syntax_title[64], description_title[64], synopsis_title[64], seealso_title[64], arguments_title[64];
+#endif
+
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "manager show event";
@@ -1373,45 +1384,18 @@
 			"	Show the detailed descriptions for a specific Asterisk manager interface event.\n";
 		return NULL;
 	case CLI_GENERATE:
-		return NULL;
-	}
-	if (a->argc < 4) {
-		return CLI_SHOWUSAGE;
-	}
-	return CLI_SUCCESS;
-}
-
-static char *handle_showmancmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-	struct manager_action *cur;
-	struct ast_str *authority;
-	int num, l, which;
-	char *ret = NULL;
-#ifdef AST_XML_DOCS
-	char syntax_title[64], description_title[64], synopsis_title[64], seealso_title[64], arguments_title[64];
-#endif
-
-	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";
-		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);
+		AST_RWLIST_RDLOCK(&events);
+		AST_RWLIST_TRAVERSE(&events, cur, list) {
+			if (!strncasecmp(a->word, cur->name, l) && ++which > a->n) {
+				ret = ast_strdup(cur->name);
 				break;	/* make sure we exit even if ast_strdup() returns NULL */
 			}
 		}
-		AST_RWLIST_UNLOCK(&actions);
+		AST_RWLIST_UNLOCK(&events);
 		return ret;
 	}
-	authority = ast_str_alloca(80);
 	if (a->argc < 4) {
 		return CLI_SHOWUSAGE;
 	}
@@ -1425,10 +1409,10 @@
 	term_color(arguments_title, "[Arguments]\n", COLOR_MAGENTA, 0, 40);
 #endif
 
-	AST_RWLIST_RDLOCK(&actions);
-	AST_RWLIST_TRAVERSE(&actions, cur, list) {
+	AST_RWLIST_RDLOCK(&events);
+	AST_RWLIST_TRAVERSE(&events, cur, list) {
 		for (num = 3; num < a->argc; num++) {
-			if (!strcasecmp(cur->action, a->argv[num])) {
+			if (!strcasecmp(cur->name, 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",
@@ -1445,7 +1429,85 @@
 				} else {
 #endif
 					ast_cli(a->fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n",
-							cur->action, cur->synopsis,
+							cur->name, cur->synopsis,
+							authority_to_str(cur->authority, &authority),
+							S_OR(cur->description, ""));
+#ifdef AST_XML_DOCS
+				}
+#endif
+			}
+		}
+	}
+	AST_RWLIST_UNLOCK(&events);
+
+	return CLI_SUCCESS;
+}
+
+static char *handle_showmancmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct manager_action *cur;
+	struct ast_str *authority;
+	int num, l, which;
+	char *ret = NULL;
+#ifdef AST_XML_DOCS
+	char syntax_title[64], description_title[64], synopsis_title[64], seealso_title[64], arguments_title[64];
+#endif
+
+	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";
+		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->name, l) && ++which > a->n) {
+				ret = ast_strdup(cur->name);
+				break;	/* make sure we exit even if ast_strdup() returns NULL */
+			}
+		}
+		AST_RWLIST_UNLOCK(&actions);
+		return ret;
+	}
+	authority = ast_str_alloca(80);
+	if (a->argc < 4) {
+		return CLI_SHOWUSAGE;
+	}
+
+#ifdef AST_XML_DOCS
+	/* setup the titles */
+	term_color(synopsis_title, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
+	term_color(description_title, "[Description]\n", COLOR_MAGENTA, 0, 40);
+	term_color(syntax_title, "[Syntax]\n", COLOR_MAGENTA, 0, 40);
+	term_color(seealso_title, "[See Also]\n", COLOR_MAGENTA, 0, 40);
+	term_color(arguments_title, "[Arguments]\n", COLOR_MAGENTA, 0, 40);
+#endif
+
+	AST_RWLIST_RDLOCK(&actions);
+	AST_RWLIST_TRAVERSE(&actions, cur, list) {
+		for (num = 3; num < a->argc; num++) {
+			if (!strcasecmp(cur->name, 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 {
+#endif
+					ast_cli(a->fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n",
+							cur->name, cur->synopsis,
 							authority_to_str(cur->authority, &authority),
 							S_OR(cur->description, ""));
 #ifdef AST_XML_DOCS
@@ -1592,6 +1654,9 @@
 
 static char *handle_show_manager_events(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
+	struct manager_event *cur;
+	struct ast_str *authority;
+#define HSMC_FORMAT "  %-15.15s  %-15.15s  %-55.55s\n"
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "manager show events";
@@ -1602,6 +1667,15 @@
 	case CLI_GENERATE:
 		return NULL;
 	}
+	authority = ast_str_alloca(80);
+	ast_cli(a->fd, HSMC_FORMAT, "Action", "Privilege", "Synopsis");
+	ast_cli(a->fd, HSMC_FORMAT, "------", "---------", "--------");
+
+	AST_RWLIST_RDLOCK(&events);
+	AST_RWLIST_TRAVERSE(&events, cur, list)
+		ast_cli(a->fd, HSMC_FORMAT, cur->name, authority_to_str(cur->authority, &authority), cur->synopsis);
+	AST_RWLIST_UNLOCK(&events);
+
 	return CLI_SUCCESS;
 }
 
@@ -1627,7 +1701,7 @@
 
 	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);
+		ast_cli(a->fd, HSMC_FORMAT, cur->name, authority_to_str(cur->authority, &authority), cur->synopsis);
 	AST_RWLIST_UNLOCK(&actions);
 
 	return CLI_SUCCESS;
@@ -1837,12 +1911,13 @@
 	curlen = strlen(msg);
 	for (x = 0; x < curlen; x++) {
 		int cr;	/* set if we have \r */
-		if (src[x] == '\r' && x+1 < curlen && src[x+1] == '\n')
+		if (src[x] == '\r' && x+1 < curlen && src[x+1] == '\n') {
 			cr = 2;	/* Found. Update length to include \r\n */
-		else if (src[x] == '\n')
+		} else if (src[x] == '\n') {
 			cr = 1;	/* also accept \n only */
-		else
+		} else {
 			continue;
+		}
 		/* don't copy empty lines */
 		if (x) {
 			memmove(header_buf, src, x);	/*... but trim \r\n */
@@ -1855,13 +1930,14 @@
 		x = -1;			/* reset loop */
 	}
 
-	action = astman_get_header(&m,"Action");
-	if (action && strcasecmp(action,"login")) {
+	action = astman_get_header(&m, "Action");
+	if (action && strcasecmp(action, "login")) {
 
 		AST_RWLIST_RDLOCK(&actions);
 		AST_RWLIST_TRAVERSE(&actions, tmp, list) {
-			if (strcasecmp(action, tmp->action))
+			if (strcasecmp(action, tmp->name)) {
 				continue;
+			}
 			/*
 			* we have to simulate a session for this action request
 			* to be able to pass it down for processing
@@ -1876,7 +1952,6 @@
 	}
 	return ret;
 }
-
 
 /*!
  * helper function to send a string to the socket.
@@ -2906,7 +2981,7 @@
 	AST_RWLIST_TRAVERSE(&actions, cur, list) {
 		if (s->session->writeperm & cur->authority || cur->authority == 0) {
 			astman_append(s, "%s: %s (Priv: %s)\r\n",
-				cur->action, cur->synopsis, authority_to_str(cur->authority, &temp));
+				cur->name, cur->synopsis, authority_to_str(cur->authority, &temp));
 		}
 	}
 	astman_append(s, "\r\n");
@@ -3053,7 +3128,7 @@
 	const char *varname = astman_get_header(m, "Variable");
 	const char *varval = astman_get_header(m, "Value");
 	int res = 0;
-	
+
 	if (ast_strlen_zero(varname)) {
 		astman_send_error(s, m, "No variable specified");
 		return 0;
@@ -3072,7 +3147,7 @@
 		c = ast_channel_unref(c);
 	}
 	if (res == 0) {
-		astman_send_ack(s, m, "Variable Set");	
+		astman_send_ack(s, m, "Variable Set");
 	} else {
 		astman_send_error(s, m, "Variable not set");
 	}
@@ -4199,7 +4274,7 @@
 		}
 	}
 
-	astman_send_ack(s, m, "Event Sent");	
+	astman_send_ack(s, m, "Event Sent");
 	manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", event, ast_str_buffer(body));
 	return 0;
 }
@@ -4523,7 +4598,7 @@
 
 	AST_RWLIST_RDLOCK(&actions);
 	AST_RWLIST_TRAVERSE(&actions, tmp, list) {
-		if (strcasecmp(action, tmp->action)) {
+		if (strcasecmp(action, tmp->name)) {
 			continue;
 		}
 		if (s->session->writeperm & tmp->authority || tmp->authority == 0) {
@@ -4538,7 +4613,7 @@
 
 	if (tmp && call_func) {
 		/* call AMI function after actions list are unlocked */
-		ast_debug(1, "Running action '%s'\n", tmp->action);
+		ast_debug(1, "Running action '%s'\n", tmp->name);
 		ret = call_func(s, m);
 	} else {
 		char buf[512];
@@ -4936,7 +5011,7 @@
 		return -1;
 	}
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&actions, cur, list) {
-		if (!strcasecmp(action, cur->action)) {
+		if (!strcasecmp(action, cur->name)) {
 			AST_RWLIST_REMOVE_CURRENT(list);
 			ast_string_field_free_memory(cur);
 			ast_free(cur);
@@ -4966,13 +5041,13 @@
 	struct timespec tv = { 5, };
 
 	if (AST_RWLIST_TIMEDWRLOCK(&actions, &tv)) {
-		ast_log(LOG_ERROR, "Could not obtain lock on manager list\n");
+		ast_log(LOG_ERROR, "Could not obtain lock on manager actions list\n");
 		return -1;
 	}
 	AST_RWLIST_TRAVERSE(&actions, cur, list) {
-		int ret = strcasecmp(cur->action, act->action);
+		int ret = strcasecmp(cur->name, act->name);
 		if (ret == 0) {
-			ast_log(LOG_WARNING, "Manager: Action '%s' already registered\n", act->action);
+			ast_log(LOG_WARNING, "Manager: Action '%s' already registered\n", act->name);
 			AST_RWLIST_UNLOCK(&actions);
 			return -1;
 		}
@@ -4988,16 +5063,100 @@
 		AST_RWLIST_INSERT_HEAD(&actions, act, list);
 	}
 
-	ast_verb(2, "Manager registered action %s\n", act->action);
+	ast_verb(2, "Manager registered action %s\n", act->name);
 
 	AST_RWLIST_UNLOCK(&actions);
+
+	return 0;
+}
+
+static int ast_manager_event_register_struct(struct manager_event *event)
+{
+	struct manager_event *cur, *prev = NULL;
+	struct timespec tv = { 5, };
+
+	if (AST_RWLIST_TIMEDWRLOCK(&events, &tv)) {
+		ast_log(LOG_ERROR, "Could not obtain lock on manager events list\n");
+		return -1;
+	}
+	AST_RWLIST_TRAVERSE(&events, cur, list) {
+		int ret = strcasecmp(cur->name, event->name);
+		if (ret == 0) {
+			ast_log(LOG_WARNING, "Manager: Event '%s' already registered\n", event->name);
+			AST_RWLIST_UNLOCK(&events);
+			return -1;
+		}
+		if (ret > 0) {
+			prev = cur; /* Insert theses alphabetically */
+			break;
+		}
+	}
+
+	if (prev) {
+		AST_RWLIST_INSERT_AFTER(&events, prev, event, list);
+	} else {
+		AST_RWLIST_INSERT_HEAD(&events, event, list);
+	}
+
+	ast_verb(2, "Manager registered event %s\n", event->name);
+
+	AST_RWLIST_UNLOCK(&events);
+
+	return 0;
+}
+
+static int ast_manager_event_register(const char *name, const char *synopsis, const char *description) {
+	struct manager_event *cur = NULL;
+#ifdef AST_XML_DOCS
+	char *tmpxml;
+#endif
+
+	if (!(cur = ast_calloc_with_stringfields(1, struct manager_event, 128))) {
+		return -1;
+	}
+	cur->name = name;
+#ifdef AST_XML_DOCS
+	if (ast_strlen_zero(synopsis) && ast_strlen_zero(description)) {
+		tmpxml = ast_xmldoc_build_synopsis("manager_event", name);
+		ast_string_field_set(cur, synopsis, tmpxml);
+		ast_free(tmpxml);
+
+		tmpxml = ast_xmldoc_build_syntax("manager_event", name);
+		ast_string_field_set(cur, syntax, tmpxml);
+		ast_free(tmpxml);
+
+		tmpxml = ast_xmldoc_build_description("manager_event", name);
+		ast_string_field_set(cur, description, tmpxml);
+		ast_free(tmpxml);
+
+		tmpxml = ast_xmldoc_build_seealso("manager_event", name);
+		ast_string_field_set(cur, seealso, tmpxml);
+		ast_free(tmpxml);
+
+		tmpxml = ast_xmldoc_build_arguments("manager_event", name);
+		ast_string_field_set(cur, arguments, tmpxml);
+		ast_free(tmpxml);
+
+		cur->docsrc = AST_XML_DOC;
+	} else {
+#endif
+		ast_string_field_set(cur, synopsis, synopsis);
+		ast_string_field_set(cur, description, description);
+#ifdef AST_XML_DOCS
+		cur->docsrc = AST_STATIC_DOC;
+	}
+#endif
+	if (ast_manager_event_register_struct(cur)) {
+		ast_free(cur);
+		return -1;
+	}
 
 	return 0;
 }
 
 /*! \brief register a new command with manager, including online help. This is
 	the preferred way to register a manager command */
-int ast_manager_register2(const char *action, int auth, int (*func)(struct mansession *s, const struct message *m), const char *synopsis, const char *description)
+int ast_manager_register2(const char *name, int auth, int (*func)(struct mansession *s, const struct message *m), const char *synopsis, const char *description)
 {
 	struct manager_action *cur = NULL;
 #ifdef AST_XML_DOCS
@@ -5008,28 +5167,28 @@
 		return -1;
 	}
 
-	cur->action = action;
+	cur->name = name;
 	cur->authority = auth;
 	cur->func = func;
 #ifdef AST_XML_DOCS
 	if (ast_strlen_zero(synopsis) && ast_strlen_zero(description)) {
-		tmpxml = ast_xmldoc_build_synopsis("manager_action", action);
+		tmpxml = ast_xmldoc_build_synopsis("manager_action", name);
 		ast_string_field_set(cur, synopsis, tmpxml);
 		ast_free(tmpxml);
 
-		tmpxml = ast_xmldoc_build_syntax("manager_action", action);
+		tmpxml = ast_xmldoc_build_syntax("manager_action", name);
 		ast_string_field_set(cur, syntax, tmpxml);
 		ast_free(tmpxml);
 
-		tmpxml = ast_xmldoc_build_description("manager_action", action);
+		tmpxml = ast_xmldoc_build_description("manager_action", name);
 		ast_string_field_set(cur, description, tmpxml);
 		ast_free(tmpxml);
 
-		tmpxml = ast_xmldoc_build_seealso("manager_action", action);
+		tmpxml = ast_xmldoc_build_seealso("manager_action", name);
 		ast_string_field_set(cur, seealso, tmpxml);
 		ast_free(tmpxml);
 
-		tmpxml = ast_xmldoc_build_arguments("manager_action", action);
+		tmpxml = ast_xmldoc_build_arguments("manager_action", name);
 		ast_string_field_set(cur, arguments, tmpxml);
 		ast_free(tmpxml);
 
@@ -6207,6 +6366,8 @@
 	struct sockaddr_in amis_desc_local_address_tmp = { 0, };
 
 	manager_enabled = 0;
+
+	ast_manager_event_register("ExtensionStatus", NULL, NULL);
 
 	if (!registered) {
 		/* Register default actions */

Modified: team/pabelanger/xmldoc/main/xmldoc.c
URL: http://svnview.digium.com/svn/asterisk/team/pabelanger/xmldoc/main/xmldoc.c?view=diff&rev=309641&r1=309640&r2=309641
==============================================================================
--- team/pabelanger/xmldoc/main/xmldoc.c (original)
+++ team/pabelanger/xmldoc/main/xmldoc.c Fri Mar  4 17:34:04 2011
@@ -993,7 +993,7 @@
  *  \retval The generated syntax.
  *  \retval NULL on error.
  */
-static char *xmldoc_get_syntax_manager_action(struct ast_xml_node *fixnode, const char *name)
+static char *xmldoc_get_syntax_manager(struct ast_xml_node *fixnode, const char *name)
 {
 	struct ast_str *syntax;
 	struct ast_xml_node *node = fixnode;
@@ -1104,10 +1104,8 @@
 			syntax = xmldoc_get_syntax_cmd(node, name, 1);
 			break;
 		case MANAGER_ACTION_SYNTAX:
-			syntax = xmldoc_get_syntax_manager_action(node, name);
-			break;
 		case MANAGER_EVENT_SYNTAX:
-
+			syntax = xmldoc_get_syntax_manager(node, name);
 			break;
 		default:
 			syntax = xmldoc_get_syntax_fun(node, name, "parameter", 1, 1);




More information about the svn-commits mailing list