[asterisk-commits] eliel: branch group/data_api_gsoc2009 r211715 - in /team/group/data_api_gsoc2...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 11 14:27:08 CDT 2009


Author: eliel
Date: Tue Aug 11 14:27:04 2009
New Revision: 211715

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=211715
Log:
New AMI action "DataGet" to retrieve the Data API tree.


Modified:
    team/group/data_api_gsoc2009/doc/manager_1_1.txt
    team/group/data_api_gsoc2009/main/data.c

Modified: team/group/data_api_gsoc2009/doc/manager_1_1.txt
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/doc/manager_1_1.txt?view=diff&rev=211715&r1=211714&r2=211715
==============================================================================
--- team/group/data_api_gsoc2009/doc/manager_1_1.txt (original)
+++ team/group/data_api_gsoc2009/doc/manager_1_1.txt Tue Aug 11 14:27:04 2009
@@ -138,6 +138,16 @@
 
 * NEW ACTIONS
 -------------
+- Action: DataGet
+	Modules: data.c
+	Purpose:
+		To be able to retrieve the asterisk data tree.
+	Variables:
+	  ActionID: <id>          Action ID for this transaction. Will be returned.
+	  Path: <data path>       The path to the callback node to retrieve.
+	  Filter: <filter>        Which nodes to retrieve.
+	  Search: <search>        Search condition.
+
 - Action: ModuleLoad
 	Modules: loader.c
 	Purpose:

Modified: team/group/data_api_gsoc2009/main/data.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/main/data.c?view=diff&rev=211715&r1=211714&r2=211715
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Tue Aug 11 14:27:04 2009
@@ -37,6 +37,24 @@
 #include "asterisk/xml.h"
 #include "asterisk/cli.h"
 #include "asterisk/term.h"
+#include "asterisk/manager.h"
+
+/*** DOCUMENTATION
+	<manager name="DataGet" language="en_US">
+		<synopsis>
+			Retrieve the data api tree.
+		</synopsis>
+		<syntax>
+			<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
+			<parameter name="Path" required="true" />
+			<parameter name="Search" />
+			<parameter name="Filter" />
+		</syntax>
+		<description>
+			<para>Retrieve the data api tree.</para>
+		</description>
+	</manager>
+ ***/
 
 #define NUM_DATA_NODE_BUCKETS	59
 #define NUM_DATA_RESULT_BUCKETS 59
@@ -2492,8 +2510,119 @@
 	AST_CLI_DEFINE(handle_cli_data_show_providers, "Show data providers")
 };
 
+/*!
+ * \internal
+ * \brief Output a tree to the AMI.
+ * \param[in] s
+ * \param[in] name
+ * \param[in] container
+ * \param[in] path
+ */
+static void data_result_manager_output(struct mansession *s, const char *name,
+	struct ao2_container *container, struct ast_str *path, int id)
+{
+	struct ao2_iterator i;
+	struct ast_str *current_path;
+	struct ast_data *node;
+	int current_id = id;
+
+	current_path = ast_str_create(60);
+	if (!current_path) {
+		return;
+	}
+
+	ast_str_reset(current_path);
+	if (path) {
+		ast_str_set(&current_path, 0, "%s.%s", ast_str_buffer(path), name);
+	} else {
+		ast_str_set(&current_path, 0, "%s", name);
+	}
+
+	i = ao2_iterator_init(container, 0);
+	while ((node = ao2_iterator_next(&i))) {
+		/* terminal node, print it. */
+		if (node->type != AST_DATA_CONTAINER) {
+			astman_append(s, "%d-%s.%s", id, ast_str_buffer(current_path),
+					node->name);
+		}
+		switch (node->type) {
+		case AST_DATA_CONTAINER:
+			data_result_manager_output(s, node->name, node->children, current_path, ++current_id);
+			break;
+		case AST_DATA_INTEGER:
+			astman_append(s, ": %d\r\n", node->payload.sint);
+			break;
+		case AST_DATA_UNSIGNED_INTEGER:
+			astman_append(s, ": %u\r\n", node->payload.uint);
+			break;
+		case AST_DATA_STRING:
+			astman_append(s, ": %s\r\n", node->payload.str);
+			break;
+		case AST_DATA_IPADDR:
+			astman_append(s, ": %s\r\n", ast_inet_ntoa(node->payload.ipaddr));
+			break;
+		case AST_DATA_POINTER:
+			break;
+		case AST_DATA_DOUBLE:
+			astman_append(s, ": %f\r\n", node->payload.dbl);
+			break;
+		case AST_DATA_BOOLEAN:
+			astman_append(s, ": %s\r\n",
+				(node->payload.boolean ? "True" : "False"));
+			break;
+		}
+
+		ao2_ref(node, -1);
+	}
+
+	ast_free(current_path);
+}
+
+/*!
+ * \internal
+ * \brief Implements the manager action: "DataGet".
+ */
+static int manager_data_get(struct mansession *s, const struct message *m)
+{
+	const char *path = astman_get_header(m, "Path");
+	const char *search = astman_get_header(m, "Search");
+	const char *filter = astman_get_header(m, "Filter");
+	const char *id = astman_get_header(m, "ActionID");
+	struct ast_data *res;
+	struct ast_data_query query = {
+		.version = AST_DATA_QUERY_VERSION,
+		.path = (char *) path,
+		.search = (char *) search,
+		.filter = (char *) filter,
+	};
+
+	if (ast_strlen_zero(path)) {
+		astman_send_error(s, m, "'Path' parameter not specified");
+		return 0;
+	}
+
+	res = ast_data_get(&query);
+	if (!res) {
+		astman_send_error(s, m, "No data returned");
+		return 0;
+	}
+
+	astman_append(s, "Event: DataGet Tree\r\n");
+	if (!ast_strlen_zero(id)) {
+		astman_append(s, "ActionID: %s\r\n", id);
+	}
+	data_result_manager_output(s, res->name, res->children, NULL, 0);
+	astman_append(s, "\r\n");
+
+	ast_data_free(res);
+
+	return RESULT_SUCCESS;
+}
+
 int ast_data_init(void)
 {
+	int res = 0;
+
 	ast_rwlock_init(&root_data.lock);
 
 	if (!(root_data.container = ao2_container_alloc(NUM_DATA_NODE_BUCKETS,
@@ -2501,7 +2630,9 @@
 		return -1;
 	}
 
-	ast_cli_register_multiple(cli_data, ARRAY_LEN(cli_data));
-
-	return 0;
-}
+	res |= ast_cli_register_multiple(cli_data, ARRAY_LEN(cli_data));
+
+	res |= ast_manager_register_xml("DataGet", 0, manager_data_get);
+
+	return res;
+}




More information about the asterisk-commits mailing list