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

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


Author: eliel
Date: Tue Jul 14 11:22:23 2009
New Revision: 206475

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=206475
Log:
Add missing search_cmp_##type and add_##type functions.


Modified:
    team/group/data_api_gsoc2009/include/asterisk/data.h
    team/group/data_api_gsoc2009/main/data.c
    team/group/data_api_gsoc2009/tests/test_data.c

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=206475&r1=206474&r2=206475
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/data.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/data.h Tue Jul 14 11:22:23 2009
@@ -253,13 +253,83 @@
  *        current string value.
  *        .search = "somename=somestring"
  *        name = "somename"
- *        value is the current value of something and will be evaluated against "10".
+ *        value is the current value of something and will be evaluated against "somestring".
  * \param[in] root The root node pointer of the search tree.
  * \param[in] name The name of the specific.
  * \param[in] value The value to compare.
  * \returns The strcmp return value.
  */
 int ast_data_search_cmp_string(const struct ast_data_search *root, const char *name, char *value);
+
+/*!
+ * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the
+ *        current pointer address value.
+ *        .search = "something=0x32323232"
+ *        name = "something"
+ *        value is the current value of something and will be evaluated against "0x32323232".
+ * \param[in] root The root node pointer of the search tree.
+ * \param[in] name The name of the specific.
+ * \param[in] ptr The pointer address to compare.
+ * \returns The (value - current_value) result.
+ */
+int ast_data_search_cmp_ptr(const struct ast_data_search *root, const char *name,
+	void *ptr);
+
+/*!
+ * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the
+ *        current ipv4 address value.
+ *        .search = "something=192.168.2.2"
+ *        name = "something"
+ *        value is the current value of something and will be evaluated against "192.168.2.2".
+ * \param[in] root The root node pointer of the search tree.
+ * \param[in] name The name of the specific.
+ * \param[in] addr The ipv4 address value to compare.
+ * \returns The (value - current_value) result.
+ */
+int ast_data_search_cmp_ipaddr(const struct ast_data_search *root, const char *name,
+	struct in_addr addr);
+
+/*!
+ * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the
+ *        current double value.
+ *        .search = "something=222"
+ *        name = "something"
+ *        value is the current value of something and will be evaluated against "222".
+ * \param[in] root The root node pointer of the search tree.
+ * \param[in] name The name of the specific.
+ * \param[in] value The double value to compare.
+ * \returns The (value - current_value) result.
+ */
+int ast_data_search_cmp_dbl(const struct ast_data_search *root, const char *name,
+	double value);
+
+/*!
+ * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the
+ *        current boolean value.
+ *        .search = "something=true"
+ *        name = "something"
+ *        value is the current value of something and will be evaluated against "true".
+ * \param[in] root The root node pointer of the search tree.
+ * \param[in] name The name of the specific.
+ * \param[in] value The boolean value to compare.
+ * \returns The (value - current_value) result.
+ */
+int ast_data_search_cmp_bool(const struct ast_data_search *root, const char *name,
+	unsigned int value);
+
+/*!
+ * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the
+ *        current unsigned integer value.
+ *        .search = "something=10"
+ *        name = "something"
+ *        value is the current value of something and will be evaluated against "10".
+ * \param[in] root The root node pointer of the search tree.
+ * \param[in] name The name of the specific.
+ * \param[in] value The unsigned value to compare.
+ * \returns The strcmp return value.
+ */
+int ast_data_search_cmp_uint(const struct ast_data_search *root, const char *name,
+	unsigned int value);
 
 /*!
  * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the
@@ -382,7 +452,27 @@
  */
 struct ast_data *ast_data_add_dbl(struct ast_data *root, const char *childname,
 	double dbl);
-
+/*!
+ * \brief Add a ipv4 address type.
+ * \param[in] root The root of the ast_data to insert into.
+ * \param[in] childname The name of the child element to be added.
+ * \param[in] addr The ipv4 address value.
+ * \retval NULL on error (memory exhaustion only).
+ * \retval non-NULL a newly allocated node.
+ */
+struct ast_data *ast_data_add_ipaddr(struct ast_data *root, const char *childname,
+	struct in_addr addr);
+
+/*!
+ * \brief Add a ptr node type.
+ * \param[in] root The root of the ast_data to insert into.
+ * \param[in] childname The name of the child element to be added.
+ * \param[in] ptr The pointer value to add.
+ * \retval NULL on error (memory exhaustion only).
+ * \retval non-NULL a newly allocated node.
+ */
+struct ast_data *ast_data_add_ptr(struct ast_data *root, const char *childname,
+	void *ptr);
 
 /*!
  * \brief Add a string node type.

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=206475&r1=206474&r2=206475
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Tue Jul 14 11:22:23 2009
@@ -1027,6 +1027,109 @@
 	return data_search_comparison_result(ret, cmp_type);
 }
 
+int ast_data_search_cmp_ptr(const struct ast_data_search *root, const char *name,
+	void *ptr)
+{
+	struct ast_data_search *child;
+	enum data_search_comparison cmp_type;
+	void *node_ptr;
+
+	child = data_search_get_node(root, name);
+	if (!child) {
+		return 0;
+	}
+
+	cmp_type = child->cmp_type;
+
+	if (sscanf(child->value, "%p", &node_ptr) <= 0) {
+		return 1;
+	}
+
+	ao2_ref(child, -1);
+
+	return data_search_comparison_result((node_ptr - ptr), cmp_type);
+}
+
+int ast_data_search_cmp_ipaddr(const struct ast_data_search *root, const char *name,
+	struct in_addr addr)
+{
+	struct ast_data_search *child;
+	enum data_search_comparison cmp_type;
+	struct in_addr node_addr;
+
+	child = data_search_get_node(root, name);
+	if (!child) {
+		return 0;
+	}
+	cmp_type = child->cmp_type;
+
+	inet_aton(child->value, &node_addr);
+
+	ao2_ref(child, -1);
+
+	return data_search_comparison_result((node_addr.s_addr - addr.s_addr), cmp_type);
+}
+
+int ast_data_search_cmp_bool(const struct ast_data_search *root, const char *name,
+	unsigned int value)
+{
+	struct ast_data_search *child;
+	unsigned int node_value;
+	enum data_search_comparison cmp_type;
+
+	child = data_search_get_node(root, name);
+	if (!child) {
+		return 0;
+	}
+
+	node_value = ast_true(child->value);
+	cmp_type = child->cmp_type;
+
+	ao2_ref(child, -1);
+
+	return data_search_comparison_result(node_value - value, cmp_type);
+}
+
+int ast_data_search_cmp_dbl(const struct ast_data_search *root, const char *name,
+	double value)
+{
+	struct ast_data_search *child;
+	double node_value;
+	enum data_search_comparison cmp_type;
+
+	child = data_search_get_node(root, name);
+	if (!child) {
+		return 0;
+	}
+
+	node_value = strtod(child->value, NULL);
+	cmp_type = child->cmp_type;
+
+	ao2_ref(child, -1);
+
+	return data_search_comparison_result(node_value - value, cmp_type);
+}
+
+int ast_data_search_cmp_uint(const struct ast_data_search *root, const char *name,
+	unsigned int value)
+{
+	struct ast_data_search *child;
+	unsigned int node_value;
+	enum data_search_comparison cmp_type;
+
+	child = data_search_get_node(root, name);
+	if (!child) {
+		return 0;
+	}
+
+	node_value = atoi(child->value);
+	cmp_type = child->cmp_type;
+
+	ao2_ref(child, -1);
+
+	return data_search_comparison_result(node_value - value, cmp_type);
+}
+
 int ast_data_search_cmp_int(const struct ast_data_search *root, const char *name, int value)
 {
 	struct ast_data_search *child;
@@ -1111,10 +1214,25 @@
 					mapping[member].get.AST_DATA_INTEGER(structure));
 				break;
 			case AST_DATA_BOOLEAN:
+				notmatch = ast_data_search_cmp_bool(struct_children, node->name,
+					mapping[member].get.AST_DATA_BOOLEAN(structure));
+				break;
 			case AST_DATA_UNSIGNED_INTEGER:
+				notmatch = ast_data_search_cmp_uint(struct_children, node->name,
+					mapping[member].get.AST_DATA_UNSIGNED_INTEGER(structure));
+				break;
 			case AST_DATA_DOUBLE:
+				notmatch = ast_data_search_cmp_dbl(struct_children, node->name,
+					mapping[member].get.AST_DATA_DOUBLE(structure));
+				break;
 			case AST_DATA_IPADDR:
+				notmatch = ast_data_search_cmp_ipaddr(struct_children, node->name,
+					mapping[member].get.AST_DATA_IPADDR(structure));
+				break;
 			case AST_DATA_POINTER:
+				notmatch = ast_data_search_cmp_ptr(struct_children, node->name,
+					mapping[member].get.AST_DATA_POINTER(structure));
+				break;
 			case AST_DATA_CONTAINER:
 				break;
 		}
@@ -1267,6 +1385,8 @@
  * \brief Add a node to a filter list from a path
  * \param[in] Filter list to add the path onto.
  * \param[in] The path to add into the filter list.
+ * \retval NULL on error.
+ * \retval non-NULL XXX-document this.
  */
 static struct data_filter_list *data_filter_add_node(struct data_filter_list *flist, char *path)
 {
@@ -1622,6 +1742,9 @@
 			}
 			break;
 		case AST_DATA_POINTER:
+			snprintf(node_content, sizeof(node_content), "%p",
+				node->payload.ptr);
+			ast_xml_set_text(child_xml, node_content);
 			break;
 		case AST_DATA_IPADDR:
 			snprintf(node_content, sizeof(node_content), "%s", ast_inet_ntoa(node->payload.ipaddr));
@@ -1766,6 +1889,18 @@
 	return __ast_data_add(root, childname, AST_DATA_BOOLEAN, &boolean);
 }
 
+struct ast_data *ast_data_add_ipaddr(struct ast_data *root, const char *childname,
+	struct in_addr addr)
+{
+	return __ast_data_add(root, childname, AST_DATA_IPADDR, &addr);
+}
+
+struct ast_data *ast_data_add_ptr(struct ast_data *root, const char *childname,
+	void *ptr)
+{
+	return __ast_data_add(root, childname, AST_DATA_POINTER, ptr);
+}
+
 struct ast_data *ast_data_add_str(struct ast_data *root, const char *childname,
 	const char *value)
 {
@@ -1812,10 +1947,12 @@
 		case AST_DATA_CONTAINER:
 			break;
 		case AST_DATA_IPADDR:
-			ast_data_add_str(root, mapping[i].name,
-				ast_inet_ntoa(mapping[i].get.AST_DATA_IPADDR(structure)));
+			ast_data_add_ipaddr(root, mapping[i].name,
+				mapping[i].get.AST_DATA_IPADDR(structure));
 			break;
 		case AST_DATA_POINTER:
+			ast_data_add_ptr(root, mapping[i].name,
+				mapping[i].get.AST_DATA_POINTER(structure));
 			break;
 		}
 	}

Modified: team/group/data_api_gsoc2009/tests/test_data.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/tests/test_data.c?view=diff&rev=206475&r1=206474&r2=206475
==============================================================================
--- team/group/data_api_gsoc2009/tests/test_data.c (original)
+++ team/group/data_api_gsoc2009/tests/test_data.c Tue Jul 14 11:22:23 2009
@@ -216,7 +216,7 @@
 		.version = AST_DATA_QUERY_VERSION,
 		.path = "asterisk/application/app_queue",
 		.search = "app_queue/queues/queue/members/member/interface=Agent/3000,app_queue/queues/queue/members/member/interface=Agent/1000",
-		.filter = "app_queue/queues/queue/members"
+		.filter = "queues/queue/members/member"
 	};
 
 	switch (cmd) {




More information about the asterisk-commits mailing list