[asterisk-commits] eliel: branch eliel/data_retrieval r186235 - in /team/eliel/data_retrieval: i...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 2 21:15:48 CDT 2009


Author: eliel
Date: Thu Apr  2 21:15:45 2009
New Revision: 186235

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=186235
Log:
- Implement ast_data_get_type().
- Fix an issue when trying to register two callbacks in the same path.

Modified:
    team/eliel/data_retrieval/include/asterisk/data.h
    team/eliel/data_retrieval/main/data.c

Modified: team/eliel/data_retrieval/include/asterisk/data.h
URL: http://svn.digium.com/svn-view/asterisk/team/eliel/data_retrieval/include/asterisk/data.h?view=diff&rev=186235&r1=186234&r2=186235
==============================================================================
--- team/eliel/data_retrieval/include/asterisk/data.h (original)
+++ team/eliel/data_retrieval/include/asterisk/data.h Thu Apr  2 21:15:45 2009
@@ -32,7 +32,8 @@
 	AST_DATA_TYPE_CONTAINER,
 	AST_DATA_TYPE_UINTEGER,
 	AST_DATA_TYPE_STRING,
-	AST_DATA_TYPE_BOOLEAN
+	AST_DATA_TYPE_BOOLEAN,
+	AST_DATA_TYPE_UNKNOWN
 };
 
 /*! \brief opaque definition of an ast_data handler. */

Modified: team/eliel/data_retrieval/main/data.c
URL: http://svn.digium.com/svn-view/asterisk/team/eliel/data_retrieval/main/data.c?view=diff&rev=186235&r1=186234&r2=186235
==============================================================================
--- team/eliel/data_retrieval/main/data.c (original)
+++ team/eliel/data_retrieval/main/data.c Thu Apr  2 21:15:45 2009
@@ -34,6 +34,10 @@
 
 #define NUM_DATA_NODE_BUCKETS 60
 
+#define DATA_TYPE_UINT		"uint"
+#define DATA_TYPE_STRING	"str"
+#define DATA_TYPE_BOOL		"bool"
+
 /*! \brief A data container node pointing to the registered handler. */
 struct data_node {
 	/*! \brief node content handler. */
@@ -377,7 +381,7 @@
 	}
 
 	if (!child) {
-		ast_log(LOG_ERROR, "Invalid path '%s'\n", path);
+		ast_log(LOG_ERROR, "Invalid path '%s', '%s' not found.\n", path, node_name);
 		return NULL;
 	}
 
@@ -436,7 +440,6 @@
 
 	node_name = next_node_name(&rpath);
 	while (node_name) {
-		/* TODO: Check node types and do not go inside of a node that is not a CONTAINER */
 		child = ast_xml_find_element(ast_xml_node_get_children(node), node_name, NULL, NULL);
 		if (!child) {
 			/* create the missing node. */
@@ -472,7 +475,7 @@
 		return -1;
 	}
 
-	if (ao2_container_count(node->children)) {
+	if (ao2_container_count(node->children) || node->read) {
 		ast_log(LOG_ERROR, "The node '%s' was already registered. We were unable to register %s.\n", node->name, path);
 		ao2_ref(node, -1);
 		data_unlock();
@@ -506,8 +509,58 @@
 
 enum ast_data_type ast_data_get_type(struct ast_data *handler, const char *path)
 {
-	/* TODO */
-	return 0;
+	char *node_name, *rpath;
+	struct ast_xml_node *node;
+	const char *attr;
+	enum ast_data_type ret;
+
+	if (!path) {
+		return AST_DATA_TYPE_UNKNOWN;
+	}
+
+	rpath = ast_strdupa(path);
+	if (!rpath) {
+		return AST_DATA_TYPE_UNKNOWN;
+	}
+
+	node = ast_xml_get_root((struct ast_xml_doc *) handler);
+	if (!node) {
+		return AST_DATA_TYPE_UNKNOWN;
+	}
+
+	/* check the root node. */
+	node_name = next_node_name(&rpath);
+	if (strcasecmp(ast_xml_node_get_name(node), node_name)) {
+		ast_log(LOG_WARNING, "Invalid path '%s', unknown root node '%s'\n", path, node_name);
+		return AST_DATA_TYPE_UNKNOWN;
+	}
+
+	node_name = next_node_name(&rpath);
+	while (node_name && node) {
+		node = ast_xml_find_element(ast_xml_node_get_children(node), node_name, NULL, NULL);
+		node_name = next_node_name(&rpath);
+	}
+
+	if (!node) {
+		return AST_DATA_TYPE_UNKNOWN;
+	}
+
+	attr = ast_xml_get_attribute(node, "type");
+	if (!attr) {
+		return AST_DATA_TYPE_CONTAINER;
+	}
+	if (!strcmp(attr, DATA_TYPE_STRING)) {
+		ret = AST_DATA_TYPE_STRING;
+	} else if (!strcmp(attr, DATA_TYPE_UINT)) {
+		ret = AST_DATA_TYPE_UINTEGER;
+	} else if (!strcmp(attr, DATA_TYPE_BOOL)) {
+		ret = AST_DATA_TYPE_BOOLEAN;
+	} else {
+		ret = AST_DATA_TYPE_UNKNOWN;
+	}
+
+	ast_xml_free_attr(attr);
+	return ret;
 }
 
 unsigned int ast_data_get_uint(struct ast_data *handler, const char *path)
@@ -582,7 +635,7 @@
 	}
 
 	/* set the node type. */
-	if (ast_xml_set_attribute(node, "type", "str")) {
+	if (ast_xml_set_attribute(node, "type", DATA_TYPE_STRING)) {
 		ast_log(LOG_ERROR, "Unable to set the node type\n");
 		ast_xml_free_node(node);
 		return -1;
@@ -605,7 +658,7 @@
 	}
 
 	/* set the node type. */
-	if (ast_xml_set_attribute(node, "type", "uint")) {
+	if (ast_xml_set_attribute(node, "type", DATA_TYPE_UINT)) {
 		ast_log(LOG_ERROR, "Unable to set the node type\n");
 		ast_xml_free_node(node);
 		return -1;
@@ -630,7 +683,7 @@
 	}
 
 	/* set the node type. */
-	if (ast_xml_set_attribute(node, "type", "bool")) {
+	if (ast_xml_set_attribute(node, "type", DATA_TYPE_BOOL)) {
 		ast_log(LOG_ERROR, "Unable to set the node type\n");
 		ast_xml_free_node(node);
 		return -1;
@@ -667,10 +720,10 @@
 	}
 
 	/* some tests */
-	ast_data_register("asterisk/pepe/jose/prueba", test_data_provider);
-	ast_data_register("asterisk/pepe/jojojo/pepepe/prueba222", test_data_provider);
-
-	res = ast_data_get("asterisk");
+	ast_data_register("asterisk/node1/node11/node111", test_data_provider);
+	ast_data_register("asterisk/node2/node21/node211", test_data_provider);
+
+	res = ast_data_get("asterisk/node1");
 
 	out = fopen("/tmp/xmltest", "w+");
 	ast_xml_doc_dump_file(out, (struct ast_xml_doc *)res);




More information about the asterisk-commits mailing list