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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 4 09:06:01 CDT 2009


Author: eliel
Date: Tue Aug  4 09:05:58 2009
New Revision: 210235

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=210235
Log:
Fix a bug while trying to print to the console the complete tree.

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=210235&r1=210234&r2=210235
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Tue Aug  4 09:05:58 2009
@@ -148,6 +148,8 @@
 	ast_rwlock_t lock;
 } root_data;
 
+static void __ast_data_print_debug(const struct ast_data *root, uint32_t depth);
+
 /*!
  * \internal
  * \brief Common string hash function.
@@ -568,16 +570,15 @@
 	return ret;
 }
 
-/*!
- * \internal
- * \brief Print out an ast_data tree to the console for debugging purposes.
- * \see ast_data_print_debug
- */
-static void __ast_data_print_debug(const struct ast_data *root, uint32_t depth)
+
+/*!
+ * \internal
+ * \brief Print a node to the console.
+ * \see __ast_data_print_debug, ast_data_print_debug
+ */
+static void __ast_data_print_debug_node(const struct ast_data *node, uint32_t depth)
 {
 	int i;
-	struct ao2_iterator iter;
-	struct ast_data *node;
 	struct ast_str *tabs;
 
 	tabs = ast_str_create(depth * 10 + 1);
@@ -589,55 +590,71 @@
 		ast_str_append(&tabs, 0, "\t");
 	}
 
-	ast_debug(1, "%s%s (container)\n", ast_str_buffer(tabs), root->name);
-
-	iter = ao2_iterator_init(root->children, 0);
-	while ((node = ao2_iterator_next(&iter))) {
-		switch (root->type) {
-		case AST_DATA_POINTER:
-			ast_debug(1, "%s%s (pointer): %p\n", ast_str_buffer(tabs),
+	switch (node->type) {
+	case AST_DATA_POINTER:
+		ast_debug(1, "%s%s (pointer): %p\n", ast_str_buffer(tabs),
 				node->name, node->payload.ptr);
-			break;
-		case AST_DATA_STRING:
-			ast_debug(1, "%s%s (string)[%u]: \"%s\"", ast_str_buffer(tabs),
+		break;
+	case AST_DATA_STRING:
+		ast_debug(1, "%s%s (string)[%u]: \"%s\"\n", ast_str_buffer(tabs),
 				node->name,
 				(unsigned int) strlen(node->payload.str),
 				node->payload.str);
-			break;
-		case AST_DATA_CONTAINER:
-			__ast_data_print_debug(node, depth + 1);
-			break;
-		case AST_DATA_INTEGER:
-			ast_debug(1, "%s%s (integer): %d\n", ast_str_buffer(tabs),
+		break;
+	case AST_DATA_CONTAINER:
+		ast_debug(1, "%s%s (container)\n", ast_str_buffer(tabs),
+				node->name);
+		__ast_data_print_debug(node, depth + 1);
+		break;
+	case AST_DATA_INTEGER:
+		ast_debug(1, "%s%s (integer): %d\n", ast_str_buffer(tabs),
 				node->name,
 				node->payload.sint);
-			break;
-		case AST_DATA_UNSIGNED_INTEGER:
-			ast_debug(1, "%s%s (unsigned integer): %u\n", ast_str_buffer(tabs),
+		break;
+	case AST_DATA_UNSIGNED_INTEGER:
+		ast_debug(1, "%s%s (unsigned integer): %u\n", ast_str_buffer(tabs),
 				node->name,
 				node->payload.uint);
-			break;
-		case AST_DATA_DOUBLE:
-			ast_debug(1, "%s%s (double): %lf\n", ast_str_buffer(tabs),
+		break;
+	case AST_DATA_DOUBLE:
+		ast_debug(1, "%s%s (double): %lf\n", ast_str_buffer(tabs),
 				node->name,
 				node->payload.dbl);
-			break;
-		case AST_DATA_BOOLEAN:
-			ast_debug(1, "%s%s (boolean): %s\n", ast_str_buffer(tabs),
+		break;
+	case AST_DATA_BOOLEAN:
+		ast_debug(1, "%s%s (boolean): %s\n", ast_str_buffer(tabs),
 				node->name,
 				((node->payload.boolean) ? "True" : "False"));
-			break;
-		case AST_DATA_IPADDR:
-			ast_debug(1, "%s%s (ipaddr): %s\n", ast_str_buffer(tabs),
+		break;
+	case AST_DATA_IPADDR:
+		ast_debug(1, "%s%s (ipaddr): %s\n", ast_str_buffer(tabs),
 				node->name,
 				ast_inet_ntoa(node->payload.ipaddr));
-			break;
-		}
-
-		ao2_ref(node, -1);
+		break;
 	}
 
 	ast_free(tabs);
+}
+
+/*!
+ * \internal
+ * \brief Print out an ast_data tree to the console for debugging purposes.
+ * \see ast_data_print_debug
+ */
+static void __ast_data_print_debug(const struct ast_data *root, uint32_t depth)
+{
+	struct ao2_iterator iter;
+	struct ast_data *node;
+
+	if (root->type == AST_DATA_CONTAINER) {
+		iter = ao2_iterator_init(root->children, 0);
+		while ((node = ao2_iterator_next(&iter))) {
+			__ast_data_print_debug_node(node, depth + 1);
+			ao2_ref(node, -1);
+		}
+	} else {
+		__ast_data_print_debug_node(root, depth);
+	}
 }
 
 /*!

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=210235&r1=210234&r2=210235
==============================================================================
--- team/group/data_api_gsoc2009/tests/test_data.c (original)
+++ team/group/data_api_gsoc2009/tests/test_data.c Tue Aug  4 09:05:58 2009
@@ -252,18 +252,26 @@
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "data test get";
-		e->usage = "Usage: data test get <path>\n"
+		e->usage = "Usage: data test get <path> [<search>] [<filter>]\n"
 			   "   Dump data to the console\n";
 		return NULL;
 	case CLI_GENERATE:
 		return NULL;
 	}
 
-	if (a->argc != e->args + 1) {
+	if (a->argc < e->args + 1) {
 		return CLI_SHOWUSAGE;
 	}
 
 	query.path = (char *) a->argv[e->args];
+
+	if (a->argc > e->args + 1) {
+		query.search = (char *) a->argv[e->args + 1];
+	}
+
+	if (a->argc > e->args + 2) {
+		query.filter = (char *) a->argv[e->args + 2];
+	}
 
 	tree = ast_data_get(&query);
 	if (!tree) {




More information about the asterisk-commits mailing list