[asterisk-commits] eliel: branch group/data_api_gsoc2009 r203566 - /team/group/data_api_gsoc2009...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jun 25 21:28:24 CDT 2009
Author: eliel
Date: Thu Jun 25 21:28:21 2009
New Revision: 203566
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=203566
Log:
Start using the ast_data_add_<type>() functions to test some code.
Modified:
team/group/data_api_gsoc2009/main/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=203566&r1=203565&r2=203566
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Thu Jun 25 21:28:21 2009
@@ -832,37 +832,36 @@
enum ast_data_type type, void *ptr)
{
struct ast_data *node;
- size_t namelen = 1 + (ast_strlen_zero(name) ? 0 : strlen(name));
if (!root || !root->children) {
/* invalid data result node. */
return NULL;
}
- if (!(node = ao2_alloc(sizeof(*node) + namelen, data_result_destructor))) {
- return NULL;
- }
-
- strcpy(node->name, (ast_strlen_zero(name) ? "" : name));
+ node = data_result_create(name);
+ if (!node) {
+ return NULL;
+ }
+
+ node->type = type;
switch (type) {
case AST_DATA_BOOLEAN:
node->payload.boolean = *(unsigned int *)ptr;
break;
case AST_DATA_INTEGER:
+ node->payload.sint = *(unsigned int *)ptr;
+ break;
case AST_DATA_UNSIGNED_INTEGER:
- node->payload.sint = *(int *)ptr;
+ node->payload.sint = *(unsigned int *)ptr;
break;
-
case AST_DATA_DOUBLE:
node->payload.dbl = *(double *)ptr;
break;
-
case AST_DATA_STRING:
case AST_DATA_POINTER:
node->payload.ptr = ptr;
break;
-
case AST_DATA_IPADDR:
node->payload.ipaddr = *(struct in_addr *)ptr;
break;
@@ -936,7 +935,23 @@
/* XXX: test callback */
static struct ast_data *test_data_provider(void)
{
- struct ast_data *res = NULL;
+ struct ast_data *res, *internal;
+
+ res = ast_data_create("root_test");
+ if (!res) {
+ return NULL;
+ }
+
+ ast_data_add_int(res, "data1", 10);
+ ast_data_add_dbl(res, "data2", 20);
+ ast_data_add_bool(res, "data3", 1);
+
+ internal = ast_data_add_node(res, "internal");
+ if (!internal) {
+ return res;
+ }
+
+ ast_data_add_str(internal, "name", "eliel");
return res;
}
More information about the asterisk-commits
mailing list