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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 7 12:36:33 CDT 2009


Author: eliel
Date: Tue Jul  7 12:36:29 2009
New Revision: 205046

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=205046
Log:
Implement the first two comparison 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=205046&r1=205045&r2=205046
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/data.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/data.h Tue Jul  7 12:36:29 2009
@@ -187,6 +187,26 @@
 #define ast_data_unregister(path) __ast_data_unregister(path, __FILE__)
 
 /*!
+ * \internal
+ * \brief
+ * \param[in] root
+ * \param[in] name
+ * \param[in] value
+ * \returns The strcmp return value.
+ */
+int ast_data_search_cmp_string(const struct ast_data_search *root, const char *name, const char *value);
+
+/*!
+ * \internal
+ * \brief
+ * \param[in] root
+ * \param[in] name
+ * \param[in] value
+ * \returns The strcmp return value.
+ */
+int ast_data_search_cmp_sint(const struct ast_data_search *root, const char *name, int value);
+
+/*!
  * \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=205046&r1=205045&r2=205046
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Tue Jul  7 12:36:29 2009
@@ -834,6 +834,124 @@
 static void data_search_release(struct ast_data_search *search)
 {
 	ao2_ref(search, -1);
+}
+
+/*!
+ * \internal
+ * \brief XXX
+ */
+static inline int data_search_comparison_result(int cmpval, enum data_search_comparison comparison_type)
+{
+	ast_log(LOG_ERROR, "CMPVAL = %d\n", cmpval);
+	switch (comparison_type) {
+	case DATA_CMP_GE:
+		ast_log(LOG_ERROR, "CMP = GE\n");
+		if (cmpval >= 0) {
+			return 0;
+		}
+		break;
+	case DATA_CMP_LE:
+		ast_log(LOG_ERROR, "CMP = LE\n");
+		if (cmpval <= 0) {
+			return 0;
+		}
+		break;
+	case DATA_CMP_EQ:
+		ast_log(LOG_ERROR, "CMP = EQ\n");
+		if (cmpval == 0) {
+			return 0;
+		}
+		break;
+	case DATA_CMP_NEQ:
+		ast_log(LOG_ERROR, "CMP = NEQ\n");
+		if (cmpval != 0) {
+			return 0;
+		}
+		break;
+	case DATA_CMP_LT:
+		ast_log(LOG_ERROR, "CMP = LT\n");
+		if (cmpval < 0) {
+			return 0;
+		}
+		break;
+	case DATA_CMP_GT:
+		ast_log(LOG_ERROR, "CMP = GT\n");
+		if (cmpval > 0) {
+			return 0;
+		}
+		break;
+	case DATA_CMP_UNKNOWN:
+		ast_log(LOG_ERROR, "CMP = UNK\n");
+		break;
+	}
+	return 1;
+}
+
+/*!
+ * \internal
+ * \brief Get an internal node, from the search tree.
+ * \param[in] node A node container.
+ * \param[in] path The path to the needed internal node.
+ * \retval NULL if the internal node is not found.
+ * \retval non-NULL the internal node with path 'path'.
+ */
+static struct ast_data_search *data_search_get_node(const struct ast_data_search *node,
+	const char *path)
+{
+	char *savepath;
+	struct ast_data_search *child;
+
+	if (!path) {
+		return (struct ast_data_search *) node;
+	}
+
+	savepath = ast_strdupa(path);
+
+	child = data_search_find(node->children, next_node_name(&savepath));
+	if (!child) {
+		return NULL;
+	}
+
+	return data_search_get_node(child, savepath);
+}
+
+int ast_data_search_cmp_string(const struct ast_data_search *root, const char *name, const char *value)
+{
+	struct ast_data_search *child;
+	enum data_search_comparison cmp_type;
+	int ret;
+
+	child = data_search_get_node(root, name);
+	if (!child) {
+		return 0;
+	}
+
+	ret = strcmp(value, child->value);
+	cmp_type = child->cmp_type;
+
+	ao2_ref(child, -1);
+
+	return data_search_comparison_result(ret, cmp_type);
+}
+
+int ast_data_search_cmp_sint(const struct ast_data_search *root, const char *name, int value)
+{
+	struct ast_data_search *child;
+	int node_value;
+	enum data_search_comparison cmp_type;
+
+	child = data_search_get_node(root, name);
+	if (!child) {
+		ast_log(LOG_ERROR, "Not found!!! %s->%s\n", root->name, name);
+		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);
 }
 
 /*!

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=205046&r1=205045&r2=205046
==============================================================================
--- team/group/data_api_gsoc2009/tests/test_data.c (original)
+++ team/group/data_api_gsoc2009/tests/test_data.c Tue Jul  7 12:36:29 2009
@@ -42,6 +42,14 @@
 static struct ast_data *test_data_full_provider(const struct ast_data_search *search)
 {
 	struct ast_data *res, *internal;
+
+	if (!ast_data_search_cmp_sint(search, "root_test/data1", 10)) {
+		ast_log(LOG_ERROR, "Se cumplio!!!\n");
+		return NULL;
+	} else {
+		ast_log(LOG_ERROR, "NO SE CUMPLIO!\n");
+		return NULL;
+	}
 
 	res = ast_data_create("root_test");
 	if (!res) {
@@ -138,7 +146,7 @@
 	struct ast_data_query query = {
 		.version = AST_DATA_QUERY_VERSION,
 		.path = "test/node1/node11/node111",
-		.search = "node111/root_test/data1=10"
+		.search = "node111/root_test/data1>=20"
 	};
 
 	switch (cmd) {
@@ -192,7 +200,8 @@
 	FILE *outfile;
 	struct ast_data_query query = {
 		.version = AST_DATA_QUERY_VERSION,
-		.path = "test",
+		.path = "test/node1/node11/node111",
+		.search = "node111/root_test/data1<20"
 	};
 
 	switch (cmd) {




More information about the asterisk-commits mailing list