[asterisk-commits] russell: branch russell/data_retrieval r111944 - in /team/russell/data_retrie...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Mar 29 00:07:39 CDT 2008


Author: russell
Date: Sat Mar 29 00:07:37 2008
New Revision: 111944

URL: http://svn.digium.com/view/asterisk?view=rev&rev=111944
Log:
tweak API a bit more, add back error checking in the existing providers,
fix up the ast_data_node_destroy() function to completely destroy the tree,
as it previously missed a case

Modified:
    team/russell/data_retrieval/channels/chan_sip.c
    team/russell/data_retrieval/include/asterisk/data.h
    team/russell/data_retrieval/main/data.c

Modified: team/russell/data_retrieval/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/russell/data_retrieval/channels/chan_sip.c?view=diff&rev=111944&r1=111943&r2=111944
==============================================================================
--- team/russell/data_retrieval/channels/chan_sip.c (original)
+++ team/russell/data_retrieval/channels/chan_sip.c Sat Mar 29 00:07:37 2008
@@ -21444,19 +21444,24 @@
 	const struct ast_data_node *query)
 {
 	struct ast_data_node *settings_node;
+	int res = 0;
 
 	if (!(settings_node = ast_data_node_new("sip_settings"))) {
 		return NULL;
 	}
 
-	ast_data_node_add_child_str(settings_node, "bindaddr", ast_inet_ntoa(bindaddr.sin_addr));
-	ast_data_node_add_child_uint(settings_node, "bindport", (uint32_t) ntohs(bindaddr.sin_port));
-	ast_data_node_add_child_bool(settings_node, "videosupport",
+	res |= ast_data_node_add_child_str(settings_node, "bindaddr", ast_inet_ntoa(bindaddr.sin_addr));
+	res |= ast_data_node_add_child_uint(settings_node, "bindport", (uint32_t) ntohs(bindaddr.sin_port));
+	res |= ast_data_node_add_child_bool(settings_node, "videosupport",
 		ast_test_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT));
-	ast_data_node_add_child_bool(settings_node, "textsupport",
+	res |= ast_data_node_add_child_bool(settings_node, "textsupport",
 		ast_test_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT));
-	ast_data_node_add_child_bool(settings_node, "autocreatepeer", autocreatepeer);
-	ast_data_node_add_child_bool(settings_node, "match_auth_username", global_match_auth_username);
+	res |= ast_data_node_add_child_bool(settings_node, "autocreatepeer", autocreatepeer);
+	res |= ast_data_node_add_child_bool(settings_node, "match_auth_username", global_match_auth_username);
+
+	if (res) {
+		settings_node = ast_data_node_destroy(settings_node);
+	}
 
 	return settings_node;
 }

Modified: team/russell/data_retrieval/include/asterisk/data.h
URL: http://svn.digium.com/view/asterisk/team/russell/data_retrieval/include/asterisk/data.h?view=diff&rev=111944&r1=111943&r2=111944
==============================================================================
--- team/russell/data_retrieval/include/asterisk/data.h (original)
+++ team/russell/data_retrieval/include/asterisk/data.h Sat Mar 29 00:07:37 2008
@@ -99,13 +99,13 @@
 struct ast_data_node *ast_data_node_add_child_grouping(struct ast_data_node *parent, 
 	const char *name);
 
-struct ast_data_node *ast_data_node_add_child_bool(struct ast_data_node *parent, 
+int ast_data_node_add_child_bool(struct ast_data_node *parent, 
 	const char *name, unsigned int val);
 
-struct ast_data_node *ast_data_node_add_child_uint(struct ast_data_node *parent, 
+int ast_data_node_add_child_uint(struct ast_data_node *parent, 
 	const char *name, uint32_t uint);
 
-struct ast_data_node *ast_data_node_add_child_str(struct ast_data_node *parent, 
+int ast_data_node_add_child_str(struct ast_data_node *parent, 
 	const char *name, const char *str);
 
 /*! @} */

Modified: team/russell/data_retrieval/main/data.c
URL: http://svn.digium.com/view/asterisk/team/russell/data_retrieval/main/data.c?view=diff&rev=111944&r1=111943&r2=111944
==============================================================================
--- team/russell/data_retrieval/main/data.c (original)
+++ team/russell/data_retrieval/main/data.c Sat Mar 29 00:07:37 2008
@@ -114,9 +114,14 @@
 {
 	struct ast_data_node *child_node;
 
+	if (!node)
+		return NULL;
+	
 	while ((child_node = AST_LIST_REMOVE_HEAD(&node->children, entry))) {
 		ast_data_node_destroy(child_node);
 	}
+	
+	ast_data_node_destroy(AST_LIST_NEXT(node, entry));
 
 	if (node->node_type == AST_DATA_NODE_STR) {
 		ast_free((char *) node->payload.str);
@@ -180,61 +185,70 @@
 	return node;
 }
 
-struct ast_data_node *ast_data_node_add_child_bool(struct ast_data_node *parent, 
+int ast_data_node_add_child_bool(struct ast_data_node *parent, 
 	const char *name, unsigned int val)
 {
 	struct ast_data_node *node;
 
 	if (!(node = ast_data_node_new(name))) {
-		return NULL;
-	}
-
-	ast_data_node_set_payload_bool(node, val);
+		return -1;
+	}
+
+	if (ast_data_node_set_payload_bool(node, val)) {
+		node = ast_data_node_destroy(node);
+		return -1;
+	}
 
 	if (ast_data_node_add_child(parent, node)) {
 		node = ast_data_node_destroy(node);
-	}
-
-	return node;
-}
-
-struct ast_data_node *ast_data_node_add_child_uint(struct ast_data_node *parent, 
+		return -1;
+	}
+
+	return 0;
+}
+
+int ast_data_node_add_child_uint(struct ast_data_node *parent, 
 	const char *name, uint32_t uint)
 {
 	struct ast_data_node *node;
 
 	if (!(node = ast_data_node_new(name))) {
-		return NULL;
-	}
-
-	ast_data_node_set_payload_uint(node, uint);
+		return -1;
+	}
+
+	if ((ast_data_node_set_payload_uint(node, uint))) {
+		node = ast_data_node_destroy(node);
+		return -1;
+	}
 
 	if (ast_data_node_add_child(parent, node)) {
 		node = ast_data_node_destroy(node);
-	}
-
-	return node;
-}
-
-struct ast_data_node *ast_data_node_add_child_str(struct ast_data_node *parent, 
+		return -1;
+	}
+
+	return 0;
+}
+
+int ast_data_node_add_child_str(struct ast_data_node *parent, 
 	const char *name, const char *str)
 {
 	struct ast_data_node *node;
 
 	if (!(node = ast_data_node_new(name))) {
-		return NULL;
+		return -1;
 	}
 
 	if (ast_data_node_set_payload_str(node, str)) {
 		node = ast_data_node_destroy(node);
-		return NULL;
+		return -1;
 	}
 
 	if (ast_data_node_add_child(parent, node)) {
 		node = ast_data_node_destroy(node);
-	}
-
-	return node;
+		return -1;
+	}
+
+	return 0;
 }
 
 struct ast_data_node *ast_data_query(const struct ast_data_node *query)
@@ -348,6 +362,7 @@
 	const struct ast_data_node *query)
 {
 	struct ast_data_node *results, *fruit, *orange, *veggies;
+	int res = 0;
 
 	if (!(results = ast_data_node_new("test_provider"))) {
 		return NULL;
@@ -355,16 +370,29 @@
 
 	fruit = ast_data_node_add_child_grouping(results, "fruits");
 
-	ast_data_node_add_child_str(fruit, "fruit", "apple");
-	orange = ast_data_node_add_child_grouping(fruit, "oranges");
-	ast_data_node_add_child_str(orange, "orange", "mandarin");
-	ast_data_node_add_child_str(orange, "orange", "navel");
-	ast_data_node_add_child_str(fruit, "fruit", "banana");
-
-	veggies = ast_data_node_add_child_grouping(results, "veggies");
-	ast_data_node_add_child_str(veggies, "veggie", "broccoli");
-	ast_data_node_add_child_str(veggies, "veggie", "squash");
-	ast_data_node_add_child_str(veggies, "veggie", "spinach");
+	res |= ast_data_node_add_child_str(fruit, "fruit", "apple");
+
+	if (!(orange = ast_data_node_add_child_grouping(fruit, "oranges"))) {
+		results = ast_data_node_destroy(results);
+		return NULL;
+	}
+
+	res |= ast_data_node_add_child_str(orange, "orange", "mandarin");
+	res |= ast_data_node_add_child_str(orange, "orange", "navel");
+	res |= ast_data_node_add_child_str(fruit, "fruit", "banana");
+
+	if (!(veggies = ast_data_node_add_child_grouping(results, "veggies"))) {
+		results = ast_data_node_destroy(results);
+		return NULL;
+	}
+
+	res |= ast_data_node_add_child_str(veggies, "veggie", "broccoli");
+	res |= ast_data_node_add_child_str(veggies, "veggie", "squash");
+	res |= ast_data_node_add_child_str(veggies, "veggie", "spinach");
+
+	if (res) {
+		results = ast_data_node_destroy(results);
+	}
 
 	return results;
 }




More information about the asterisk-commits mailing list