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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 20 12:02:03 CDT 2009


Author: eliel
Date: Fri Mar 20 12:02:00 2009
New Revision: 183561

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=183561
Log:
Make ast_data be the root node instead of a complex structure.

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

Modified: team/eliel/data_retrieval/include/asterisk/xml.h
URL: http://svn.digium.com/svn-view/asterisk/team/eliel/data_retrieval/include/asterisk/xml.h?view=diff&rev=183561&r1=183560&r2=183561
==============================================================================
--- team/eliel/data_retrieval/include/asterisk/xml.h (original)
+++ team/eliel/data_retrieval/include/asterisk/xml.h Fri Mar 20 12:02:00 2009
@@ -104,6 +104,13 @@
  */
 void ast_xml_free_attr(const char *attribute);
 
+/*! \brief Get the document based on a node.
+ *  \param node A node that is part of the dom.
+ *  \retval NULL on error.
+ *  \retval The dom pointer where this node resides.
+ */
+struct ast_xml_doc *ast_xml_get_doc(struct ast_xml_node *node);
+
 /*! \brief Free a content element that was returned by ast_xml_get_text()
  *  \param text text to be freed.
  */

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=183561&r1=183560&r2=183561
==============================================================================
--- team/eliel/data_retrieval/main/data.c (original)
+++ team/eliel/data_retrieval/main/data.c Fri Mar 20 12:02:00 2009
@@ -32,13 +32,6 @@
 #include "asterisk/xml.h"
 #include "asterisk/data.h"
 
-struct ast_data {
-	/*! \brief The returned xml dom. */
-	struct ast_xml_doc *doc;
-	/*! \brief Current node. */
-	struct ast_xml_node *current;
-};
-
 /*! \brief A data container node pointing to the registered handler. */
 struct data_node {
 	/*! \brief node content handler. */
@@ -265,7 +258,7 @@
  * \retval NULL on error.
  * \retval
  */
-static struct data_node *data_retrieve_node(struct data_node *parent, const char *path)
+static struct data_node *data_node_retrieve(struct data_node *parent, const char *path)
 {
 	struct data_node *child = parent;
 	char *rpath, *node_name;
@@ -284,6 +277,7 @@
 		} while (!strlen(node_name));
 
 		child = data_find_child(child, node_name);
+		/* is this a terminal node? */
 		if (child && child->read) {
 			return child;
 		}
@@ -292,21 +286,21 @@
 	return NULL;
 }
 
-static struct ast_xml_node *data_generate_node(struct ast_xml_node *parent, struct data_node *node)
+static struct ast_data *data_generate_node(struct ast_xml_node *parent, struct data_node *node)
 {
 	struct data_node *child;
-	struct ast_xml_node *parent_child, *res;
+	struct ast_xml_node *parent_child;
 	struct ast_data *resdata;
 
 	AST_LIST_TRAVERSE(&node->children, child, entry) {
 		if (child->read) {
 			resdata = child->read();
-			return ast_xml_get_root(resdata->doc);
+			return resdata;
 		} else {
 			parent_child = ast_xml_new_child(parent, child->name);
-			res = data_generate_node(parent_child, child);
-			if (res) {
-				ast_xml_add_child(parent, res);
+			resdata = data_generate_node(parent_child, child);
+			if (resdata) {
+				ast_xml_add_child(parent, (struct ast_xml_node *) resdata);
 			}
 		}
 	}
@@ -320,7 +314,7 @@
  * \retval NULL on error.
  * \retval
  */
-static struct ast_xml_doc *data_generate_result(struct data_node *node)
+static struct ast_xml_node *data_generate_result(struct data_node *node)
 {
 	struct ast_xml_doc *doc;
 	struct ast_xml_node *res_node;
@@ -342,7 +336,7 @@
 
 	data_generate_node(res_node, node);
 
-	return doc;
+	return res_node;
 }
 
 int ast_data_register(const char *path, ast_data_cb handler)
@@ -382,44 +376,33 @@
 struct ast_data *ast_data_get(const char *path)
 {
 	struct data_node *last_node;
-	struct ast_xml_doc *retxmldoc;
-	struct ast_data *retdata;
+	struct ast_xml_node *retxml;
 
 	if (!path) {
 		return NULL;
 	}
 
 	data_read_lock();
-	last_node = data_retrieve_node(root_data, path);
+	last_node = data_node_retrieve(root_data, path);
 	if (!last_node) {
 		ast_log(LOG_ERROR, "Unable to find %s\n", path);
 		data_unlock();
 		return NULL;
 	}
 
-	retxmldoc = data_generate_result(last_node);
+	retxml = data_generate_result(last_node);
 	data_unlock();
 
-	if (!retxmldoc) {
-		return NULL;
-	}
-
-	retdata = ast_calloc(1, sizeof(*retdata));
-	if (!retdata) {
-		ast_xml_close(retxmldoc);
-		return NULL;
-	}
-
-	retdata->doc = retxmldoc;
-	retdata->current = ast_xml_get_root(retxmldoc);
-
-	return retdata;
+	if (!retxml) {
+		return NULL;
+	}
+
+	return (struct ast_data *) retxml;
 }
 
 void ast_data_free(struct ast_data *data)
 {
-	ast_xml_close(data->doc);
-	ast_free(data);
+	ast_xml_close(ast_xml_get_doc((struct ast_xml_node *) data));
 }
 
 unsigned int ast_data_get_uint(struct ast_data *handler, const char *path)

Modified: team/eliel/data_retrieval/main/xml.c
URL: http://svn.digium.com/svn-view/asterisk/team/eliel/data_retrieval/main/xml.c?view=diff&rev=183561&r1=183560&r2=183561
==============================================================================
--- team/eliel/data_retrieval/main/xml.c (original)
+++ team/eliel/data_retrieval/main/xml.c Fri Mar 20 12:02:00 2009
@@ -211,6 +211,15 @@
 	return NULL;
 }
 
+struct ast_xml_doc *ast_xml_get_doc(struct ast_xml_node *node)
+{
+	if (!node) {
+		return NULL;
+	}
+
+	return (struct ast_xml_doc *) ((xmlNode *)node)->doc;
+}
+
 const char *ast_xml_get_text(struct ast_xml_node *node)
 {
 	if (!node) {




More information about the asterisk-commits mailing list