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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jul 20 13:19:45 CDT 2009


Author: eliel
Date: Mon Jul 20 13:19:43 2009
New Revision: 207420

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=207420
Log:
- Support regular expressions inside the iterator.
- Make the test module use the structure mapping mechanism.


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

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=207420&r1=207419&r2=207420
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Mon Jul 20 13:19:43 2009
@@ -34,6 +34,7 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/xml.h"
 #include "asterisk/linkedlists.h"
+#include <regex.h>
 
 #define NUM_DATA_NODE_BUCKETS	60
 #define NUM_DATA_RESULT_BUCKETS 60
@@ -133,6 +134,10 @@
 	struct ast_data *last;
 	/*! \brief The iterator pattern. */
 	const char *pattern;
+	/*! \brief The compiled patter. */
+	regex_t regex_pattern;
+	/*! \brief is a regular expression. */
+	unsigned int is_pattern:1;
 };
 
 /*! \brief The asterisk data main content structure. */
@@ -1981,23 +1986,23 @@
 {
 	struct ast_data_iterator *iterator;
 	struct ao2_iterator i;
-	struct ast_data *internal;
-	char *path, *ptr;
-
-	path = ast_strdupa(elements);
-
-	ptr = strrchr(path, '/');
-	if (ptr) {
-		*ptr = '\0';
-		internal = data_result_get_node(tree, path);
-		if (!internal) {
-			return NULL;
-		}
-	} else {
-		internal = tree;
-	}
-
-	iterator = ast_malloc(sizeof(*iterator));
+	struct ast_data *internal = tree;
+	char *path, *ptr = NULL;
+
+	if (elements) {
+		path = ast_strdupa(elements);
+
+		ptr = strrchr(path, '/');
+		if (ptr) {
+			*ptr = '\0';
+			internal = data_result_get_node(tree, path);
+			if (!internal) {
+				return NULL;
+			}
+		}
+	}
+
+	iterator = ast_calloc(1, sizeof(*iterator));
 	if (!iterator) {
 		return NULL;
 	}
@@ -2005,7 +2010,12 @@
 	i = ao2_iterator_init(internal->children, 0);
 
 	iterator->pattern = (ptr ? strrchr(elements, '/') + 1 : elements);
-	iterator->last = NULL;
+
+	if (!regcomp(&(iterator->regex_pattern), iterator->pattern,
+			REG_EXTENDED | REG_NOSUB | REG_ICASE)) {
+		iterator->is_pattern = 1;
+	}
+
 	iterator->internal_iterator = i;
 
 	return iterator;
@@ -2015,6 +2025,10 @@
 {
 	if (iterator->last) {
 		ao2_ref(iterator->last, -1);
+	}
+
+	if (iterator->is_pattern) {
+		regfree(&(iterator->regex_pattern));
 	}
 
 	ast_free(iterator);
@@ -2035,7 +2049,14 @@
 			 * the next node. */
 			break;
 		}
-		if ((iterator->pattern && !strcasecmp(res->name, iterator->pattern))) {
+
+		if (iterator->is_pattern && !regexec(&(iterator->regex_pattern),
+			res->name, 0, NULL, 0)) {
+			break;
+		}
+
+		if (!iterator->is_pattern &&
+			(iterator->pattern && !strcasecmp(res->name, iterator->pattern))) {
 			/* if there is a pattern specified, check if this node matches
 			 * the wanted node names. */
 			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=207420&r1=207419&r2=207420
==============================================================================
--- team/group/data_api_gsoc2009/tests/test_data.c (original)
+++ team/group/data_api_gsoc2009/tests/test_data.c Mon Jul 20 13:19:43 2009
@@ -40,39 +40,38 @@
 #include "asterisk/cli.h"
 #include "asterisk/data.h"
 
+struct test_structure {
+	int a_int;
+	unsigned int b_bool:1;
+	char *c_str;
+	unsigned int a_uint;
+};
+
+#define DATA_EXPORT_TEST_STRUCTURE(MEMBER)				\
+	MEMBER(test_structure, a_int, AST_DATA_INTEGER)			\
+	MEMBER(test_structure, b_bool, AST_DATA_BOOLEAN)		\
+	MEMBER(test_structure, c_str, AST_DATA_STRING)			\
+	MEMBER(test_structure, a_uint, AST_DATA_UNSIGNED_INTEGER)
+
+AST_DATA_STRUCTURE(test_structure, DATA_EXPORT_TEST_STRUCTURE);
+
 static int test_data_full_provider(const struct ast_data_search *search, struct ast_data *root)
 {
-	struct ast_data *internal;
-
-	if (ast_data_search_cmp_int(search, "root_test/data1", 10)) {
-		ast_log(LOG_ERROR, "root_test/data1 doesn't match\n");
-	} else {
-		ast_log(LOG_ERROR, "root_test/data1 match!\n");
-	}
-
-	if (ast_data_search_cmp_int(search, "root_test/data2", 20)) {
-		ast_log(LOG_ERROR, "root_test/data2 doesn't match\n");
-	} else {
-		ast_log(LOG_ERROR, "root_test/data2 match!\n");
-	}
-
-	if (ast_data_search_cmp_string(search, "root_test/name", "eliel")) {
-		ast_log(LOG_ERROR, "root_test/data2 doesn't match\n");
-	} else {
-		ast_log(LOG_ERROR, "root_test/data2 match!\n");
-	}
-
-	ast_data_add_int(root, "data1", 10);
-	ast_data_add_dbl(root, "data2", 20);
-	ast_data_add_bool(root, "data3", 1);
-	ast_data_add_str(root, "name", "eliel");
-
-	internal = ast_data_add_node(root, "internal");
-	if (!internal) {
-		return -1;
-	}
-
-	ast_data_add_str(internal, "name", "eliel");
+	struct ast_data *test_structure;
+	struct test_structure local_test_structure = {
+		.a_int = 10,
+		.b_bool = 1,
+		.c_str = "test string",
+		.a_uint = 20
+	};
+
+	test_structure = ast_data_add_node(root, "test_structure");
+	if (!test_structure) {
+		ast_debug(1, "Internal data api error\n");
+		return 0;
+	}
+
+	ast_data_add_structure(test_structure, test_structure, &local_test_structure);
 
 	return 0;
 }
@@ -153,7 +152,7 @@
 	struct ast_data_query query = {
 		.version = AST_DATA_QUERY_VERSION,
 		.path = "test/node1/node11/node111",
-		.search = "node111/root_test/data1>=10,node111/root_test/data2<20"
+		.search = "node111/test_structure/a_int=10"
 	};
 
 	switch (cmd) {
@@ -179,7 +178,7 @@
 	}
 
 	/* initiate the iterator and check for errors. */
-	i = ast_data_iterator_init(res, NULL);
+	i = ast_data_iterator_init(res, "test_structure/");
 	ast_cli(a->fd, "Starting iterator... ");
 	if (i) {
 		ast_cli(a->fd, " OK\n");
@@ -209,8 +208,7 @@
 	FILE *outfile;
 	struct ast_data_query query = {
 		.version = AST_DATA_QUERY_VERSION,
-		.path = "asterisk/application/app_queue/queues",
-		.search = "queues/queue/callers/caller/channel/data=cola1"
+		.path = "test"
 	};
 
 	switch (cmd) {




More information about the svn-commits mailing list