[asterisk-commits] eliel: branch eliel/data_retrieval r188021 - in /team/eliel/data_retrieval: i...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Apr 11 13:25:03 CDT 2009
Author: eliel
Date: Sat Apr 11 13:25:00 2009
New Revision: 188021
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=188021
Log:
Use long integer instead of unsigned integer to store values.
Implement the ast_data_get_#type# API functions.
Modified:
team/eliel/data_retrieval/include/asterisk/data.h
team/eliel/data_retrieval/main/data.c
Modified: team/eliel/data_retrieval/include/asterisk/data.h
URL: http://svn.digium.com/svn-view/asterisk/team/eliel/data_retrieval/include/asterisk/data.h?view=diff&rev=188021&r1=188020&r2=188021
==============================================================================
--- team/eliel/data_retrieval/include/asterisk/data.h (original)
+++ team/eliel/data_retrieval/include/asterisk/data.h Sat Apr 11 13:25:00 2009
@@ -30,7 +30,7 @@
/*! \brief Possible node content types. */
enum ast_data_type {
AST_DATA_TYPE_CONTAINER,
- AST_DATA_TYPE_UINTEGER,
+ AST_DATA_TYPE_LONG,
AST_DATA_TYPE_STRING,
AST_DATA_TYPE_BOOLEAN,
AST_DATA_TYPE_UNKNOWN
@@ -89,13 +89,13 @@
void ast_data_free(struct ast_data *data);
/*!
- * \brief Get an unsigned integer from a node.
+ * \brief Get a long from a node.
* \param handler The ast_data handler.
* \param path Which node's content to get.
* \see ast_data_get
- * \returns The requested unsigned integer value.
+ * \returns The requested long integer value.
*/
-unsigned int ast_data_get_uint(struct ast_data *handler, const char *path);
+long ast_data_get_long(struct ast_data *handler, const char *path);
/*!
* \brief Get a string from a node.
@@ -136,7 +136,7 @@
const char *value);
/*!
- * \brief Insert a node named 'path' with the unsigned integer value 'value'.
+ * \brief Insert a node named 'path' with the long integer value 'value'.
* \param handler The result handler.
* \param path The path of the node to insert.
* \param value The content of the node to create.
@@ -144,8 +144,8 @@
* \retval 0 on success.
* \retval -1 on error.
*/
-int ast_data_insert_uint(struct ast_data_node *handler, const char *path,
- unsigned int value);
+int ast_data_insert_long(struct ast_data_node *handler, const char *path,
+ long value);
/*!
* \brief Insert a node named 'path' with the boolean value 'value'.
Modified: team/eliel/data_retrieval/main/data.c
URL: http://svn.digium.com/svn-view/asterisk/team/eliel/data_retrieval/main/data.c?view=diff&rev=188021&r1=188020&r2=188021
==============================================================================
--- team/eliel/data_retrieval/main/data.c (original)
+++ team/eliel/data_retrieval/main/data.c Sat Apr 11 13:25:00 2009
@@ -34,7 +34,7 @@
#define NUM_DATA_NODE_BUCKETS 60
-#define DATA_TYPE_UINT "uint"
+#define DATA_TYPE_LONG "long"
#define DATA_TYPE_STRING "str"
#define DATA_TYPE_BOOL "bool"
@@ -463,6 +463,46 @@
return node;
}
+/*!
+ * \internal
+ * \brief XXX: Complete.
+ * \param handler
+ * \param path
+ * \retval NULL if the node wasn't found.
+ * \retval The xml node referenced by path.
+ */
+static struct ast_xml_node *data_xml_node_get(struct ast_data *handler, const char *path)
+{
+ struct ast_xml_node *node;
+ char *rpath, *node_name;
+
+ node = ast_xml_get_root((struct ast_xml_doc *) handler);
+
+ rpath = ast_strdupa(path);
+ if (!rpath || !node) {
+ return NULL;
+ }
+
+ /* check the root node. */
+ node_name = next_node_name(&rpath);
+ if (!node_name) {
+ return node;
+ }
+
+ if (strcasecmp(ast_xml_node_get_name(node), node_name)) {
+ ast_log(LOG_WARNING, "Invalid path '%s', unknown root node '%s'\n", path, node_name);
+ return NULL;
+ }
+
+ node_name = next_node_name(&rpath);
+ while (node_name && node) {
+ node = ast_xml_find_element(ast_xml_node_get_children(node), node_name, NULL, NULL);
+ node_name = next_node_name(&rpath);
+ }
+
+ return node;
+}
+
int ast_data_register(const char *path, ast_data_cb read_handler)
{
struct data_node *node;
@@ -516,37 +556,11 @@
enum ast_data_type ast_data_get_type(struct ast_data *handler, const char *path)
{
- char *node_name, *rpath;
struct ast_xml_node *node;
const char *attr;
enum ast_data_type ret;
- if (!path) {
- return AST_DATA_TYPE_UNKNOWN;
- }
-
- rpath = ast_strdupa(path);
- if (!rpath) {
- return AST_DATA_TYPE_UNKNOWN;
- }
-
- node = ast_xml_get_root((struct ast_xml_doc *) handler);
- if (!node) {
- return AST_DATA_TYPE_UNKNOWN;
- }
-
- /* check the root node. */
- node_name = next_node_name(&rpath);
- if (strcasecmp(ast_xml_node_get_name(node), node_name)) {
- ast_log(LOG_WARNING, "Invalid path '%s', unknown root node '%s'\n", path, node_name);
- return AST_DATA_TYPE_UNKNOWN;
- }
-
- node_name = next_node_name(&rpath);
- while (node_name && node) {
- node = ast_xml_find_element(ast_xml_node_get_children(node), node_name, NULL, NULL);
- node_name = next_node_name(&rpath);
- }
+ node = data_xml_node_get(handler, path);
if (!node) {
return AST_DATA_TYPE_UNKNOWN;
@@ -560,8 +574,8 @@
}
if (!strcmp(attr, DATA_TYPE_STRING)) {
ret = AST_DATA_TYPE_STRING;
- } else if (!strcmp(attr, DATA_TYPE_UINT)) {
- ret = AST_DATA_TYPE_UINTEGER;
+ } else if (!strcmp(attr, DATA_TYPE_LONG)) {
+ ret = AST_DATA_TYPE_LONG;
} else if (!strcmp(attr, DATA_TYPE_BOOL)) {
ret = AST_DATA_TYPE_BOOLEAN;
} else {
@@ -572,22 +586,79 @@
return ret;
}
-unsigned int ast_data_get_uint(struct ast_data *handler, const char *path)
-{
- /* TODO */
- return 0;
+long ast_data_get_long(struct ast_data *handler, const char *path)
+{
+ struct ast_xml_node *node;
+ const char *content;
+ long ret;
+
+ node = data_xml_node_get(handler, path);
+ if (!node) {
+ ast_log(LOG_WARNING, "Invalid node path '%s'\n", path);
+ return 0;
+ }
+
+ content = ast_xml_get_text(node);
+ if (!content) {
+ ast_log(LOG_ERROR, "Unable to get node '%s' content.\n", path);
+ return 0;
+ }
+
+ ret = atol(content);
+
+ ast_xml_free_text(content);
+
+ return ret;
}
char *ast_data_get_str(struct ast_data *handler, const char *path)
{
- /* TODO */
- return NULL;
+ struct ast_xml_node *node;
+ char *ret;
+ const char *content;
+
+ node = data_xml_node_get(handler, path);
+ if (!node) {
+ ast_log(LOG_WARNING, "Invalid node path '%s'\n", path);
+ return NULL;
+ }
+
+ content = ast_xml_get_text(node);
+ if (!content) {
+ ast_log(LOG_ERROR, "Unable to get node '%s' content.\n", path);
+ return NULL;
+ }
+
+ ret = ast_strdup(content);
+
+ ast_xml_free_text(content);
+
+ return ret;
}
unsigned char ast_data_get_bool(struct ast_data *handler, const char *path)
{
- /* TODO */
- return 0;
+ unsigned char ret;
+ struct ast_xml_node *node;
+ const char *content;
+
+ node = data_xml_node_get(handler, path);
+ if (!node) {
+ ast_log(LOG_WARNING, "Invalid node path '%s'\n", path);
+ return 0;
+ }
+
+ content = ast_xml_get_text(node);
+ if (!content) {
+ ast_log(LOG_ERROR, "Unable to get node '%s' content.\n", path);
+ return 0;
+ }
+
+ ret = ast_true(content);
+
+ ast_xml_free_text(content);
+
+ return ret;
}
struct ast_data *ast_data_get(const char *path)
@@ -655,7 +726,7 @@
return 0;
}
-int ast_data_insert_uint(struct ast_data_node *handler, const char *path, unsigned int value)
+int ast_data_insert_long(struct ast_data_node *handler, const char *path, long value)
{
struct ast_xml_node *node;
char tmpbuf[32];
@@ -667,13 +738,13 @@
}
/* set the node type. */
- if (ast_xml_set_attribute(node, "type", DATA_TYPE_UINT)) {
+ if (ast_xml_set_attribute(node, "type", DATA_TYPE_LONG)) {
ast_log(LOG_ERROR, "Unable to set the node type\n");
ast_xml_free_node(node);
return -1;
}
- snprintf(tmpbuf, sizeof(tmpbuf), "%u", value);
+ snprintf(tmpbuf, sizeof(tmpbuf), "%ld", value);
ast_xml_set_text(node, tmpbuf);
@@ -711,7 +782,7 @@
res = ast_data_result("eliel");
- ast_data_insert_uint(res, "eliel/canaan/sardanons", 26);
+ ast_data_insert_long(res, "eliel/canaan/sardanons", 26);
ast_data_insert_str(res, "eliel/pruebastr", "test string");
return res;
More information about the asterisk-commits
mailing list