[svn-commits] eliel: branch group/data_api_gsoc2009 r207351 - in /team/group/data_api_gsoc2...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sun Jul 19 00:00:23 CDT 2009


Author: eliel
Date: Sun Jul 19 00:00:18 2009
New Revision: 207351

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=207351
Log:
- Do not output queues that has no members and we are trying to match
one.
- unref after getting a search node.

Modified:
    team/group/data_api_gsoc2009/apps/app_queue.c
    team/group/data_api_gsoc2009/include/asterisk/data.h
    team/group/data_api_gsoc2009/main/data.c

Modified: team/group/data_api_gsoc2009/apps/app_queue.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/apps/app_queue.c?view=diff&rev=207351&r1=207350&r2=207351
==============================================================================
--- team/group/data_api_gsoc2009/apps/app_queue.c (original)
+++ team/group/data_api_gsoc2009/apps/app_queue.c Sun Jul 19 00:00:18 2009
@@ -7537,7 +7537,7 @@
 static void queues_data_provider_get_helper(const struct ast_data_search *search,
 	struct ast_data *data_root, struct call_queue *queue)
 {
-	int member_added = 1, member_notmatch = 0, caller_notmatch = 0;
+	int member_added = 0, caller_added = 0, member_notmatch = 0, caller_notmatch = 0;
 	struct ao2_iterator im;
 	struct member *member;
 	struct queue_ent *qe;
@@ -7551,46 +7551,49 @@
 	}
 
 	/* add queue members */
-	if (queue->members) {
-		member_added = 0;
-		im = ao2_iterator_init(queue->members, 0);
-		while ((member = ao2_iterator_next(&im))) {
-			/* compare the member structure. */
-			if (ast_data_search_cmp_structure(search, member, member,
-						"queue/members/member")) {
-				ao2_ref(member, -1);
-				member_notmatch = 1;
-				continue;
-			}
-
+	im = ao2_iterator_init(queue->members, 0);
+	while ((member = ao2_iterator_next(&im))) {
+		/* compare the member structure. */
+		if (ast_data_search_cmp_structure(search, member, member,
+					"queue/members/member")) {
+			ao2_ref(member, -1);
+			member_notmatch = 1;
+			continue;
+		}
+
+		if (!data_queue) {
+			data_queue = ast_data_add_node(data_root, "queue");
 			if (!data_queue) {
-				data_queue = ast_data_add_node(data_root,
-						"queue");
-				if (!data_queue) {
-					ao2_ref(member, -1);
-					continue;
-				}
-			}
-
-			if (!data_members) {
-				data_members = ast_data_add_node(data_queue,
-						"members");
-				if (!data_members) {
-					ao2_ref(member, -1);
-					continue;
-				}
-			}
-
-			data_member = ast_data_add_node(data_members, "member");
-			if (!data_member) {
 				ao2_ref(member, -1);
 				continue;
 			}
-
-			ast_data_add_structure(member, data_member, member);
-			member_added = 1;
+		}
+
+		if (!data_members) {
+			data_members = ast_data_add_node(data_queue, "members");
+			if (!data_members) {
+				ao2_ref(member, -1);
+				continue;
+			}
+		}
+
+		data_member = ast_data_add_node(data_members, "member");
+		if (!data_member) {
 			ao2_ref(member, -1);
-		}
+			continue;
+		}
+
+		ast_data_add_structure(member, data_member, member);
+
+		member_added++;
+		ao2_ref(member, -1);
+	}
+
+	if (!member_added) {
+		/* if there is a condition to match, but this queue has nothing to compare,
+		 * do not return it. */
+		member_notmatch = ast_data_search_has_condition(search,
+			"queue/members/member");
 	}
 
 	/* include the callers inside the result. */
@@ -7624,6 +7627,9 @@
 
 			ast_data_add_structure(queue_ent, data_caller, qe);
 
+			caller_added++;
+
+			/* add the caller channel. */
 			data_caller_channel = ast_data_add_node(data_caller, "channel");
 			if (!data_caller_channel) {
 				continue;
@@ -7631,6 +7637,12 @@
 
 			ast_channel_data_add_structure(data_caller_channel, qe->chan);
 		}
+	}
+
+	if (!caller_added) {
+		/* if there is a condition to match, but this queue has nothing to compare,
+		 * do not return it. */
+		caller_notmatch = ast_data_search_has_condition(search, "queue/callers/caller");
 	}
 
 	/* if there was a member added to the tree, then added the following

Modified: team/group/data_api_gsoc2009/include/asterisk/data.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/include/asterisk/data.h?view=diff&rev=207351&r1=207350&r2=207351
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/data.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/data.h Sun Jul 19 00:00:18 2009
@@ -378,6 +378,17 @@
 	ARRAY_LEN(__data_mapping_structure_##structure_name), structure, structure_name_cmp)
 
 /*!
+ * \brief Check if there is a compare condition inside the search tree with the
+ *	  passed 'compare_condition' node names.
+ * \param[in] search The search tree.
+ * \param[in] compare_condition The path of the compare condition.
+ * \retval 0 There is no compare condition.
+ * \retval 1 There is a compare condition.
+ */
+int ast_data_search_has_condition(const struct ast_data_search *search,
+	const char *compare_condition);
+
+/*!
  * \brief Retrieve a subtree from the asterisk data API.
  * \param[in] query The query structure specifying what nodes to retrieve.
  * \retval NULL on error.

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=207351&r1=207350&r2=207351
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Sun Jul 19 00:00:18 2009
@@ -1171,6 +1171,20 @@
 	return -1;
 }
 
+int ast_data_search_has_condition(const struct ast_data_search *search, const char *compare_condition)
+{
+	struct ast_data_search *child;
+
+	child = data_search_get_node(search, compare_condition);
+	if (!child) {
+		return 0;
+	}
+
+	ao2_ref(child, -1);
+
+	return 1;
+}
+
 int __ast_data_search_cmp_structure(const struct ast_data_search *search,
 	const struct ast_data_mapping_structure *mapping, size_t mapping_len,
 	void *structure, const char *structure_name)
@@ -1194,13 +1208,8 @@
 		if (member < 0) {
 			/* the structure member name doesn't match! */
 			ao2_ref(node, -1);
+			ao2_ref(struct_children, -1);
 			return 1;
-		}
-
-		if (mapping[member].type == AST_DATA_CONTAINER) {
-			/* XXX: Compare the internal structure. */
-			ao2_ref(node, -1);
-			continue;
 		}
 
 		notmatch = 0;
@@ -1240,6 +1249,8 @@
 		ao2_ref(node, -1);
 	}
 
+	ao2_ref(struct_children, -1);
+
 	return notmatch;
 }
 




More information about the svn-commits mailing list