data.h File Reference

Data retrieval API. More...

#include "asterisk/frame.h"
#include "asterisk/format_cap.h"

Include dependency graph for data.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_data_entry
 This entries are for multiple registers. More...
struct  ast_data_handler
 The structure of the node handler. More...
struct  ast_data_mapping_structure
 Map the members of a structure. More...
struct  ast_data_query
 A query to the data API is specified in this structure. More...
struct  ast_data_retrieve
 structure retrieved from a node, with the nodes content. More...

Defines

#define __AST_DATA_MAPPING_FUNCTION(__structure, __member, __type)   __AST_DATA_MAPPING_FUNCTION_##__type(__structure, __member)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_BOOLEAN(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_BOOLEAN, unsigned int)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_CHARACTER(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_CHARACTER, char)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_CONTAINER(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_CONTAINER, void *)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_DOUBLE(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_DBL, double)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_INTEGER(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_INTEGER, int)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_IPADDR(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_IPADDR, struct in_addr)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_MILLISECONDS(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_INTEGER, int)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_PASSWORD(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_PASSWORD, char *)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_POINTER(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_POINTER, void *)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_SECONDS(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_INTEGER, int)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_STRING(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_STRING, char *)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_TIMESTAMP(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_INTEGER, int)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_UNSIGNED_INTEGER(__structure, __member)   __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_UNSIGNED_INTEGER, unsigned int)
#define __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, __type, __real_type)
#define __AST_DATA_MAPPING_STRUCTURE(__structure, __member, __type)
#define ast_data_add_structure(structure_name, root, structure)
#define AST_DATA_ENTRY(__path, __handler)   { .path = __path, .handler = __handler }
#define AST_DATA_HANDLER_VERSION   1
 The Data API structures version.
#define AST_DATA_QUERY_VERSION   1
#define ast_data_register(path, handler)   __ast_data_register(path, handler, __FILE__, ast_module_info->self)
#define ast_data_register_core(path, handler)   __ast_data_register(path, handler, __FILE__, NULL)
#define ast_data_register_multiple(data_entries, entries)   __ast_data_register_multiple(data_entries, entries, __FILE__, ast_module_info->self)
#define ast_data_register_multiple_core(data_entries, entries)   __ast_data_register_multiple(data_entries, entries, __FILE__, NULL)
#define ast_data_search_cmp_structure(search, structure_name, structure, structure_name_cmp)
#define AST_DATA_STRUCTURE(__struct, __name)
#define ast_data_unregister(path)   __ast_data_unregister(path, __FILE__)

Typedefs

typedef int(* ast_data_get_cb )(const struct ast_data_search *search, struct ast_data *root)
 The get callback definition.

Enumerations

enum  ast_data_type {
  AST_DATA_CONTAINER, AST_DATA_INTEGER, AST_DATA_UNSIGNED_INTEGER, AST_DATA_DOUBLE,
  AST_DATA_BOOLEAN, AST_DATA_STRING, AST_DATA_CHARACTER, AST_DATA_PASSWORD,
  AST_DATA_IPADDR, AST_DATA_TIMESTAMP, AST_DATA_SECONDS, AST_DATA_MILLISECONDS,
  AST_DATA_POINTER
}
 The data type of the data node. More...

Functions

int __ast_data_add_structure (struct ast_data *root, const struct ast_data_mapping_structure *mapping, size_t mapping_len, void *structure)
 Add a complete structure to a node.
int __ast_data_register (const char *path, const struct ast_data_handler *handler, const char *registrar, struct ast_module *mod)
 Register a data provider.
int __ast_data_register_multiple (const struct ast_data_entry *data_entries, size_t entries, const char *registrar, struct ast_module *mod)
 Register multiple data providers at once.
int __ast_data_search_cmp_structure (const struct ast_data_search *search, const struct ast_data_mapping_structure *mapping, size_t mapping_len, void *structure, const char *structure_name)
 Based on a search tree, evaluate every member of a structure against it.
int __ast_data_unregister (const char *path, const char *registrar)
 Unregister a data provider.
struct ast_dataast_data_add_bool (struct ast_data *root, const char *childname, unsigned int boolean)
 Add a boolean node type.
struct ast_dataast_data_add_char (struct ast_data *root, const char *childname, char value)
 Add a char node type.
int ast_data_add_codec (struct ast_data *root, const char *node_name, struct ast_format *format)
 Add the codec in the root node based on the format parameter.
int ast_data_add_codecs (struct ast_data *root, const char *node_name, struct ast_format_cap *capability)
 Add the list of codecs in the root node based on the capability parameter.
struct ast_dataast_data_add_dbl (struct ast_data *root, const char *childname, double dbl)
 Add a floating point node type.
struct ast_dataast_data_add_int (struct ast_data *root, const char *childname, int value)
 Add an integer node type.
struct ast_dataast_data_add_ipaddr (struct ast_data *root, const char *childname, struct in_addr addr)
 Add a ipv4 address type.
struct ast_dataast_data_add_milliseconds (struct ast_data *root, const char *childname, unsigned int milliseconds)
 Add a milliseconds node type.
struct ast_dataast_data_add_node (struct ast_data *root, const char *childname)
 Add a container child.
struct ast_dataast_data_add_password (struct ast_data *root, const char *childname, const char *string)
 Add a password node type.
struct ast_dataast_data_add_ptr (struct ast_data *root, const char *childname, void *ptr)
 Add a ptr node type.
struct ast_dataast_data_add_seconds (struct ast_data *root, const char *childname, unsigned int seconds)
 Add a seconds node type.
struct ast_dataast_data_add_str (struct ast_data *root, const char *childname, const char *string)
 Add a string node type.
struct ast_dataast_data_add_timestamp (struct ast_data *root, const char *childname, unsigned int timestamp)
 Add a timestamp node type.
struct ast_dataast_data_add_uint (struct ast_data *root, const char *childname, unsigned int value)
 Add an unsigned integer node type.
void ast_data_free (struct ast_data *root)
 Release the allocated memory of a tree.
struct ast_dataast_data_get (const struct ast_data_query *query)
 Retrieve a subtree from the asterisk data API.
void ast_data_iterator_end (struct ast_data_iterator *iterator)
 Release (stop using) an iterator.
struct ast_data_iteratorast_data_iterator_init (struct ast_data *tree, const char *elements)
 Initialize an iterator.
struct ast_dataast_data_iterator_next (struct ast_data_iterator *iterator)
 Get the next node of the tree.
void ast_data_remove_node (struct ast_data *root, struct ast_data *child)
 Remove a node that was added using ast_data_add_.
int ast_data_retrieve (struct ast_data *tree, const char *path, struct ast_data_retrieve *content)
 Retrieve a value from a node in the tree.
static unsigned int ast_data_retrieve_bool (struct ast_data *tree, const char *path)
 Retrieve the boolean value of a node.
static char ast_data_retrieve_char (struct ast_data *tree, const char *path)
 Retrieve the character value of a node.
static double ast_data_retrieve_dbl (struct ast_data *tree, const char *path)
 Retrieve the double value of a node.
static int ast_data_retrieve_int (struct ast_data *tree, const char *path)
 Retrieve the integer value of a node.
static struct in_addr ast_data_retrieve_ipaddr (struct ast_data *tree, const char *path)
 Retrieve the ipv4 address value of a node.
char * ast_data_retrieve_name (struct ast_data *node)
 Get the node name.
static const char * ast_data_retrieve_password (struct ast_data *tree, const char *path)
 Retrieve the password value of a node.
static void * ast_data_retrieve_ptr (struct ast_data *tree, const char *path)
 Retrieve the ptr value of a node.
static const char * ast_data_retrieve_string (struct ast_data *tree, const char *path)
 Retrieve the string value of a node.
enum ast_data_type ast_data_retrieve_type (struct ast_data *res, const char *path)
 Get a node type.
static unsigned int ast_data_retrieve_uint (struct ast_data *tree, const char *path)
 Retrieve the unsigned integer value of a node.
int ast_data_search_match (const struct ast_data_search *search, struct ast_data *data)
 Check the current generated node to know if it matches the search condition.


Detailed Description

Data retrieval API.

Author:
Brett Bryant <brettbryant@gmail.com>

Eliel C. Sardanons (LU1ALY) <eliels@gmail.com>

Definition in file data.h.


Define Documentation

#define __AST_DATA_MAPPING_FUNCTION ( __structure,
__member,
__type   )     __AST_DATA_MAPPING_FUNCTION_##__type(__structure, __member)

Definition at line 340 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_BOOLEAN ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_BOOLEAN, unsigned int)

Definition at line 329 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_CHARACTER ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_CHARACTER, char)

Definition at line 317 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_CONTAINER ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_CONTAINER, void *)

Definition at line 337 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_DOUBLE ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_DBL, double)

Definition at line 335 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_INTEGER ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_INTEGER, int)

Definition at line 319 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_IPADDR ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_IPADDR, struct in_addr)

Definition at line 333 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_MILLISECONDS ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_INTEGER, int)

Definition at line 325 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_PASSWORD ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_PASSWORD, char *)

Definition at line 313 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_POINTER ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_POINTER, void *)

Definition at line 331 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_SECONDS ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_INTEGER, int)

Definition at line 323 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_STRING ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_STRING, char *)

Definition at line 315 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_TIMESTAMP ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_INTEGER, int)

Definition at line 321 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_UNSIGNED_INTEGER ( __structure,
__member   )     __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_UNSIGNED_INTEGER, unsigned int)

Definition at line 327 of file data.h.

#define __AST_DATA_MAPPING_FUNCTION_TYPE ( __structure,
__member,
__type,
__real_type   ) 

Value:

static __real_type data_mapping_structure_get_##__structure##__member(void *ptr) {  \
      struct __structure *struct_##__member = (struct __structure *) ptr;     \
      return (__real_type) struct_##__member->__member;           \
   }

Definition at line 344 of file data.h.

#define __AST_DATA_MAPPING_STRUCTURE ( __structure,
__member,
__type   ) 

Value:

{ .name = #__member, .get.__type = data_mapping_structure_get_##__structure##__member, \
   .type = __type },

Definition at line 308 of file data.h.

#define ast_data_add_structure ( structure_name,
root,
structure   ) 

#define AST_DATA_ENTRY ( __path,
__handler   )     { .path = __path, .handler = __handler }

Definition at line 261 of file data.h.

#define AST_DATA_HANDLER_VERSION   1

The Data API structures version.

Definition at line 205 of file data.h.

#define AST_DATA_QUERY_VERSION   1

Definition at line 206 of file data.h.

Referenced by handle_cli_data_get(), and manager_data_get().

#define ast_data_register ( path,
handler   )     __ast_data_register(path, handler, __FILE__, ast_module_info->self)

Definition at line 363 of file data.h.

#define ast_data_register_core ( path,
handler   )     __ast_data_register(path, handler, __FILE__, NULL)

Definition at line 364 of file data.h.

#define ast_data_register_multiple ( data_entries,
entries   )     __ast_data_register_multiple(data_entries, entries, __FILE__, ast_module_info->self)

Definition at line 378 of file data.h.

Referenced by load_module().

#define ast_data_register_multiple_core ( data_entries,
entries   )     __ast_data_register_multiple(data_entries, entries, __FILE__, NULL)

Definition at line 380 of file data.h.

Referenced by ast_channels_init(), and load_pbx().

#define ast_data_search_cmp_structure ( search,
structure_name,
structure,
structure_name_cmp   ) 

Value:

__ast_data_search_cmp_structure(search, __data_mapping_structure_##structure_name,     \
   ARRAY_LEN(__data_mapping_structure_##structure_name), structure, structure_name_cmp)

Definition at line 421 of file data.h.

Referenced by ast_channel_data_cmp_structure().

#define AST_DATA_STRUCTURE ( __struct,
__name   ) 

Value:

__name(__AST_DATA_MAPPING_FUNCTION);                        \
   static const struct ast_data_mapping_structure __data_mapping_structure_##__struct[] = {  \
      __name(__AST_DATA_MAPPING_STRUCTURE)                     \
   }

Definition at line 301 of file data.h.

#define ast_data_unregister ( path   )     __ast_data_unregister(path, __FILE__)

Definition at line 395 of file data.h.

Referenced by __unload_module(), channels_shutdown(), unload_module(), and unload_pbx().


Typedef Documentation

typedef int(* ast_data_get_cb)(const struct ast_data_search *search, struct ast_data *root)

The get callback definition.

Definition at line 242 of file data.h.


Enumeration Type Documentation

The data type of the data node.

Enumerator:
AST_DATA_CONTAINER 
AST_DATA_INTEGER 
AST_DATA_UNSIGNED_INTEGER 
AST_DATA_DOUBLE 
AST_DATA_BOOLEAN 
AST_DATA_STRING 
AST_DATA_CHARACTER 
AST_DATA_PASSWORD 
AST_DATA_IPADDR 
AST_DATA_TIMESTAMP 
AST_DATA_SECONDS 
AST_DATA_MILLISECONDS 
AST_DATA_POINTER 

Definition at line 188 of file data.h.


Function Documentation

int __ast_data_add_structure ( struct ast_data root,
const struct ast_data_mapping_structure mapping,
size_t  mapping_len,
void *  structure 
)

Add a complete structure to a node.

Parameters:
[in] root Where to add the structure.
[in] mapping The structure mapping array.
[in] mapping_len The lenght of the mapping array.
[in] structure The structure pointer.
Return values:
0 on success.
1 on error.

Definition at line 2423 of file data.c.

References ast_data_add_bool(), ast_data_add_char(), ast_data_add_dbl(), ast_data_add_int(), ast_data_add_ipaddr(), ast_data_add_milliseconds(), ast_data_add_password(), ast_data_add_ptr(), ast_data_add_seconds(), ast_data_add_str(), ast_data_add_timestamp(), ast_data_add_uint(), AST_DATA_BOOLEAN, AST_DATA_CHARACTER, AST_DATA_CONTAINER, AST_DATA_DOUBLE, AST_DATA_INTEGER, AST_DATA_IPADDR, AST_DATA_MILLISECONDS, AST_DATA_PASSWORD, AST_DATA_POINTER, AST_DATA_SECONDS, AST_DATA_STRING, AST_DATA_TIMESTAMP, AST_DATA_UNSIGNED_INTEGER, data_filter::name, and type.

02426 {
02427    int i;
02428 
02429    for (i = 0; i < mapping_len; i++) {
02430       switch (mapping[i].type) {
02431       case AST_DATA_INTEGER:
02432          ast_data_add_int(root, mapping[i].name,
02433             mapping[i].get.AST_DATA_INTEGER(structure));
02434          break;
02435       case AST_DATA_UNSIGNED_INTEGER:
02436          ast_data_add_uint(root, mapping[i].name,
02437             mapping[i].get.AST_DATA_UNSIGNED_INTEGER(structure));
02438          break;
02439       case AST_DATA_DOUBLE:
02440          ast_data_add_dbl(root, mapping[i].name,
02441             mapping[i].get.AST_DATA_DOUBLE(structure));
02442          break;
02443       case AST_DATA_BOOLEAN:
02444          ast_data_add_bool(root, mapping[i].name,
02445             mapping[i].get.AST_DATA_BOOLEAN(structure));
02446          break;
02447       case AST_DATA_PASSWORD:
02448          ast_data_add_password(root, mapping[i].name,
02449             mapping[i].get.AST_DATA_PASSWORD(structure));
02450          break;
02451       case AST_DATA_TIMESTAMP:
02452          ast_data_add_timestamp(root, mapping[i].name,
02453             mapping[i].get.AST_DATA_TIMESTAMP(structure));
02454          break;
02455       case AST_DATA_SECONDS:
02456          ast_data_add_seconds(root, mapping[i].name,
02457             mapping[i].get.AST_DATA_SECONDS(structure));
02458          break;
02459       case AST_DATA_MILLISECONDS:
02460          ast_data_add_milliseconds(root, mapping[i].name,
02461             mapping[i].get.AST_DATA_MILLISECONDS(structure));
02462          break;
02463       case AST_DATA_STRING:
02464          ast_data_add_str(root, mapping[i].name,
02465             mapping[i].get.AST_DATA_STRING(structure));
02466          break;
02467       case AST_DATA_CHARACTER:
02468          ast_data_add_char(root, mapping[i].name,
02469             mapping[i].get.AST_DATA_CHARACTER(structure));
02470          break;
02471       case AST_DATA_CONTAINER:
02472          break;
02473       case AST_DATA_IPADDR:
02474          ast_data_add_ipaddr(root, mapping[i].name,
02475             mapping[i].get.AST_DATA_IPADDR(structure));
02476          break;
02477       case AST_DATA_POINTER:
02478          ast_data_add_ptr(root, mapping[i].name,
02479             mapping[i].get.AST_DATA_POINTER(structure));
02480          break;
02481       }
02482    }
02483 
02484    return 0;
02485 }

int __ast_data_register ( const char *  path,
const struct ast_data_handler handler,
const char *  registrar,
struct ast_module mod 
)

Register a data provider.

Parameters:
[in] path The path of the node to register.
[in] handler The structure defining this node handler.
[in] registrar Who is registering this node.
[in] mod The module registering this handler.
See also:
ast_data_unregister
Return values:
<0 on error.
0 on success.
See also:
__ast_data_unregister, __ast_data_register_multiple

Definition at line 519 of file data.c.

References ao2_container_count(), ao2_ref, ast_log, data_provider::children, data_provider_create(), data_structure_compatible(), data_unlock, data_write_lock, data_provider::handler, LOG_ERROR, data_provider::module, data_provider::name, root_data, and ast_data_handler::version.

Referenced by __ast_data_register_multiple().

00521 {
00522    struct data_provider *node;
00523 
00524    if (!path) {
00525       return -1;
00526    }
00527 
00528    /* check if the handler structure is compatible. */
00529    if (!data_structure_compatible(handler->version,
00530       latest_handler_compatible_version,
00531       current_handler_version)) {
00532       return -1;
00533    }
00534 
00535    /* create the node structure for the registered handler. */
00536    data_write_lock();
00537 
00538    node = data_provider_create(root_data.container, path, registrar);
00539    if (!node) {
00540       ast_log(LOG_ERROR, "Unable to create the specified path (%s) "
00541          "for '%s'.\n", path, registrar);
00542       data_unlock();
00543       return -1;
00544    }
00545 
00546    if (ao2_container_count(node->children) || node->handler) {
00547       ast_log(LOG_ERROR, "The node '%s' was already registered. "
00548          "We were unable to register '%s' for registrar '%s'.\n",
00549          node->name, path, registrar);
00550       ao2_ref(node, -1);
00551       data_unlock();
00552       return -1;
00553    }
00554 
00555    /* add handler to that node. */
00556    node->handler = handler;
00557    node->module = mod;
00558 
00559    ao2_ref(node, -1);
00560 
00561    data_unlock();
00562 
00563    return 0;
00564 }

int __ast_data_register_multiple ( const struct ast_data_entry data_entries,
size_t  entries,
const char *  registrar,
struct ast_module mod 
)

Register multiple data providers at once.

Parameters:
[in] data_entries An array of data_entries structures.
[in] entries The number of entries in the data_entries array.
[in] registrar Who is registering this nodes.
[in] mod The module registering this handlers.
Return values:
<0 on error (none of the nodes are being registered on error).
0 on success.
See also:
__ast_data_register, __ast_data_unregister

Definition at line 566 of file data.c.

References __ast_data_register(), __ast_data_unregister(), and handler().

00568 {
00569    int i, res;
00570 
00571    for (i = 0; i < entries; i++) {
00572       res = __ast_data_register(data_entries[i].path, data_entries[i].handler,
00573             registrar, mod);
00574       if (res) {
00575          /* unregister all the already registered nodes, and make
00576           * this an atomic action. */
00577          while ((--i) >= 0) {
00578             __ast_data_unregister(data_entries[i].path, registrar);
00579          }
00580          return -1;
00581       }
00582    }
00583 
00584    return 0;
00585 }

int __ast_data_search_cmp_structure ( const struct ast_data_search search,
const struct ast_data_mapping_structure mapping,
size_t  mapping_len,
void *  structure,
const char *  structure_name 
)

Based on a search tree, evaluate every member of a structure against it.

Parameters:
[in] search The search tree.
[in] mapping The structure mapping.
[in] mapping_len The lenght of the structure mapping.
[in] structure The structure pointer.
[in] structure_name The name of the structure to compare.
Return values:
0 If the structure matches.
1 If the structure doesn't match.

Definition at line 1273 of file data.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_data_mapping_structure::AST_DATA_BOOLEAN, AST_DATA_BOOLEAN, ast_data_mapping_structure::AST_DATA_CHARACTER, AST_DATA_CHARACTER, AST_DATA_CONTAINER, ast_data_mapping_structure::AST_DATA_DOUBLE, AST_DATA_DOUBLE, ast_data_mapping_structure::AST_DATA_INTEGER, AST_DATA_INTEGER, ast_data_mapping_structure::AST_DATA_IPADDR, AST_DATA_IPADDR, ast_data_mapping_structure::AST_DATA_MILLISECONDS, AST_DATA_MILLISECONDS, ast_data_mapping_structure::AST_DATA_PASSWORD, AST_DATA_PASSWORD, ast_data_mapping_structure::AST_DATA_POINTER, AST_DATA_POINTER, ast_data_mapping_structure::AST_DATA_SECONDS, AST_DATA_SECONDS, ast_data_mapping_structure::AST_DATA_STRING, AST_DATA_STRING, ast_data_mapping_structure::AST_DATA_TIMESTAMP, AST_DATA_TIMESTAMP, ast_data_mapping_structure::AST_DATA_UNSIGNED_INTEGER, AST_DATA_UNSIGNED_INTEGER, ast_data_search::children, data_search_cmp_bool(), data_search_cmp_char(), data_search_cmp_dbl(), data_search_cmp_int(), data_search_cmp_ipaddr(), data_search_cmp_ptr(), data_search_cmp_string(), data_search_cmp_uint(), data_search_get_node(), data_search_mapping_find(), ast_data_mapping_structure::get, ast_data_search::name, and type.

01276 {
01277    struct ao2_iterator i;
01278    struct ast_data_search *node, *struct_children;
01279    int member, notmatch = 0;
01280 
01281    if (!search) {
01282       return 0;
01283    }
01284 
01285    struct_children = data_search_get_node(search, structure_name);
01286    if (!struct_children) {
01287       return 0;
01288    }
01289 
01290    i = ao2_iterator_init(struct_children->children, 0);
01291    while ((node = ao2_iterator_next(&i))) {
01292       member = data_search_mapping_find(mapping, mapping_len, node->name);
01293       if (member < 0) {
01294          /* the structure member name doesn't match! */
01295          ao2_ref(node, -1);
01296          ao2_ref(struct_children, -1);
01297          ao2_iterator_destroy(&i);
01298          return 0;
01299       }
01300 
01301       notmatch = 0;
01302       switch (mapping[member].type) {
01303       case AST_DATA_PASSWORD:
01304          notmatch = data_search_cmp_string(struct_children,
01305             node->name,
01306             mapping[member].get.AST_DATA_PASSWORD(structure));
01307          break;
01308       case AST_DATA_TIMESTAMP:
01309          notmatch = data_search_cmp_uint(struct_children,
01310             node->name,
01311             mapping[member].get.AST_DATA_TIMESTAMP(structure));
01312          break;
01313       case AST_DATA_SECONDS:
01314          notmatch = data_search_cmp_uint(struct_children,
01315             node->name,
01316             mapping[member].get.AST_DATA_SECONDS(structure));
01317          break;
01318       case AST_DATA_MILLISECONDS:
01319          notmatch = data_search_cmp_uint(struct_children,
01320             node->name,
01321             mapping[member].get.AST_DATA_MILLISECONDS(structure));
01322          break;
01323       case AST_DATA_STRING:
01324          notmatch = data_search_cmp_string(struct_children,
01325             node->name,
01326             mapping[member].get.AST_DATA_STRING(structure));
01327          break;
01328       case AST_DATA_CHARACTER:
01329          notmatch = data_search_cmp_char(struct_children,
01330             node->name,
01331             mapping[member].get.AST_DATA_CHARACTER(structure));
01332          break;
01333       case AST_DATA_INTEGER:
01334          notmatch = data_search_cmp_int(struct_children,
01335             node->name,
01336             mapping[member].get.AST_DATA_INTEGER(structure));
01337          break;
01338       case AST_DATA_BOOLEAN:
01339          notmatch = data_search_cmp_bool(struct_children,
01340             node->name,
01341             mapping[member].get.AST_DATA_BOOLEAN(structure));
01342          break;
01343       case AST_DATA_UNSIGNED_INTEGER:
01344          notmatch = data_search_cmp_uint(struct_children,
01345             node->name,
01346             mapping[member].get.AST_DATA_UNSIGNED_INTEGER(structure));
01347          break;
01348       case AST_DATA_DOUBLE:
01349          notmatch = data_search_cmp_dbl(struct_children,
01350             node->name,
01351             mapping[member].get.AST_DATA_DOUBLE(structure));
01352          break;
01353       case AST_DATA_IPADDR:
01354          notmatch = data_search_cmp_ipaddr(struct_children,
01355             node->name,
01356             mapping[member].get.AST_DATA_IPADDR(structure));
01357          break;
01358       case AST_DATA_POINTER:
01359          notmatch = data_search_cmp_ptr(struct_children,
01360             node->name,
01361             mapping[member].get.AST_DATA_POINTER(structure));
01362          break;
01363       case AST_DATA_CONTAINER:
01364          break;
01365       }
01366 
01367       ao2_ref(node, -1);
01368    }
01369    ao2_iterator_destroy(&i);
01370 
01371    ao2_ref(struct_children, -1);
01372 
01373    return notmatch;
01374 }

int __ast_data_unregister ( const char *  path,
const char *  registrar 
)

Unregister a data provider.

Parameters:
[in] path Which node to unregister, if path is NULL unregister every node registered by the passed 'registrar'.
[in] registrar Who is trying to unregister this node, only the owner (the one who registered the node) will be able to unregister it.
See also:
ast_data_register
Return values:
<0 on error.
0 on success.
See also:
__ast_data_register, __ast_data_register_multiple

Definition at line 587 of file data.c.

References ast_log, data_provider_release(), data_provider_release_all(), data_unlock, data_write_lock, LOG_ERROR, and root_data.

Referenced by __ast_data_register_multiple().

00588 {
00589    int ret = 0;
00590 
00591    data_write_lock();
00592    if (path) {
00593       ret = data_provider_release(root_data.container, path, registrar);
00594    } else {
00595       data_provider_release_all(root_data.container, registrar);
00596    }
00597    data_unlock();
00598 
00599    if (path && ret) {
00600       ast_log(LOG_ERROR, "Unable to unregister '%s' for '%s'\n",
00601          path, registrar);
00602    }
00603 
00604    return ret;
00605 }

struct ast_data* ast_data_add_bool ( struct ast_data root,
const char *  childname,
unsigned int  boolean 
) [read]

Add a boolean node type.

Parameters:
[in] root The root of the ast_data to insert into.
[in] childname The name of the child element to be added.
[in] boolean The value for the new node.
Return values:
NULL on error (memory exhaustion only).
non-NULL a newly allocated node.

Definition at line 2345 of file data.c.

References __ast_data_add(), and AST_DATA_BOOLEAN.

Referenced by __ast_data_add_structure(), ast_channel_data_add_structure(), channel_data_add_flags(), dahdi_status_data_provider_get(), data_channeltypes_provider_handler(), data_odbc_provider_handler(), peers_data_provider_get(), and users_data_provider_get().

02347 {
02348    return __ast_data_add(root, childname, AST_DATA_BOOLEAN, &boolean);
02349 }

struct ast_data* ast_data_add_char ( struct ast_data root,
const char *  childname,
char  value 
) [read]

Add a char node type.

Parameters:
[in] root The root of the ast_data to insert into.
[in] childname The name of the child element to be added.
[in] value The value for the new node.
Return values:
NULL on error (memory exhaustion only).
non-NULL a newly allocated node.

Definition at line 2328 of file data.c.

References __ast_data_add(), and AST_DATA_CHARACTER.

Referenced by __ast_data_add_structure().

02329 {
02330    return __ast_data_add(root, name, AST_DATA_CHARACTER, &value);
02331 }

int ast_data_add_codec ( struct ast_data root,
const char *  node_name,
struct ast_format format 
)

Add the codec in the root node based on the format parameter.

Parameters:
[in] root The astdata root node where to add the codec node.
[in] node_name The name of the node where we are going to add the codec.
[in] format The codec allowed.
Returns:
< 0 on error.

0 on success.

Definition at line 3125 of file data.c.

References ast_data_add_node(), codecs, and data_add_codec().

Referenced by ast_channel_data_add_structure().

03126 {
03127    struct ast_data *codecs;
03128 
03129    codecs = ast_data_add_node(root, node_name);
03130    if (!codecs) {
03131       return -1;
03132    }
03133 
03134    return data_add_codec(codecs, format);
03135 }

int ast_data_add_codecs ( struct ast_data root,
const char *  node_name,
struct ast_format_cap capability 
)

Add the list of codecs in the root node based on the capability parameter.

Parameters:
[in] root The astdata root node where to add the codecs node.
[in] node_name The name of the node where we are going to add the list of codecs.
[in] capability The codecs allowed.
Returns:
< 0 on error.

0 on success.

Definition at line 3137 of file data.c.

References ao2_ref, ast_data_add_node(), ast_format_cap_count(), ast_format_cap_get_format(), codecs, and data_add_codec().

Referenced by ast_channel_data_add_structure(), data_channeltypes_provider_handler(), iax2_data_add_codecs(), and peers_data_provider_get().

03138 {
03139    struct ast_data *codecs;
03140    size_t i;
03141    size_t count;
03142 
03143    codecs = ast_data_add_node(root, node_name);
03144    if (!codecs) {
03145       return -1;
03146    }
03147 
03148    count = ast_format_cap_count(cap);
03149    for (i = 0; i < count; ++i) {
03150       struct ast_format *fmt;
03151 
03152       fmt = ast_format_cap_get_format(cap, i);
03153       if (!fmt) {
03154          return -1;
03155       }
03156 
03157       if (data_add_codec(codecs, fmt)) {
03158          ao2_ref(fmt, -1);
03159          return -1;
03160       }
03161 
03162       ao2_ref(fmt, -1);
03163    }
03164 
03165    return 0;
03166 }

struct ast_data* ast_data_add_dbl ( struct ast_data root,
const char *  childname,
double  dbl 
) [read]

Add a floating point node type.

Parameters:
[in] root The root of the ast_data to insert into.
[in] childname The name of the child element to be added.
[in] dbl The value for the new node.
Return values:
NULL on error (memory exhaustion only).
non-NULL a newly allocated node.

Definition at line 2339 of file data.c.

References __ast_data_add(), and AST_DATA_DOUBLE.

Referenced by __ast_data_add_structure().

02341 {
02342    return __ast_data_add(root, childname, AST_DATA_DOUBLE, &dbl);
02343 }

struct ast_data* ast_data_add_int ( struct ast_data root,
const char *  childname,
int  value 
) [read]

Add an integer node type.

Parameters:
[in] root The root of the ast_data to insert into.
[in] childname The name of the child element to be added.
[in] value The value for the new node.
Return values:
NULL on error (memory exhaustion only).
non-NULL a newly allocated node.

Definition at line 2323 of file data.c.

References __ast_data_add(), and AST_DATA_INTEGER.

Referenced by __ast_data_add_structure(), ast_channel_data_add_structure(), dahdi_status_data_provider_get(), data_add_codec(), data_odbc_provider_handler(), hints_data_provider_get(), peers_data_provider_get(), queues_data_provider_get_helper(), user_add_provider_cb(), users_data_provider_get(), and vm_users_data_provider_get_helper().

02324 {
02325    return __ast_data_add(root, name, AST_DATA_INTEGER, &value);
02326 }

struct ast_data* ast_data_add_ipaddr ( struct ast_data root,
const char *  childname,
struct in_addr  addr 
) [read]

Add a ipv4 address type.

Parameters:
[in] root The root of the ast_data to insert into.
[in] childname The name of the child element to be added.
[in] addr The ipv4 address value.
Return values:
NULL on error (memory exhaustion only).
non-NULL a newly allocated node.

Definition at line 2351 of file data.c.

References __ast_data_add(), and AST_DATA_IPADDR.

Referenced by __ast_data_add_structure().

02353 {
02354    return __ast_data_add(root, childname, AST_DATA_IPADDR, &addr);
02355 }

struct ast_data* ast_data_add_milliseconds ( struct ast_data root,
const char *  childname,
unsigned int  milliseconds 
) [read]

Add a milliseconds node type.

Parameters:
[in] root The root of the ast_data to insert into.
[in] childname The name of the child element to be added.
[in] milliseconds The value for the new node.
Return values:
NULL on error (memory exhaustion only).
non-NULL a newly allocated node.

Definition at line 2375 of file data.c.

References __ast_data_add(), and AST_DATA_MILLISECONDS.

Referenced by __ast_data_add_structure().

02377 {
02378    return __ast_data_add(root, childname, AST_DATA_MILLISECONDS, &milliseconds);
02379 }

struct ast_data* ast_data_add_node ( struct ast_data root,
const char *  childname 
) [read]

struct ast_data* ast_data_add_password ( struct ast_data root,
const char *  childname,
const char *  string 
) [read]

Add a password node type.

Parameters:
[in] root The root of the ast_data to insert into.
[in] childname The name of the child element to be added.
[in] string The value for the new node.
Return values:
NULL on error (memory exhaustion only).
non-NULL a newly allocated node.

Definition at line 2381 of file data.c.

References __ast_data_add(), AST_DATA_PASSWORD, ast_free, ast_malloc, ast_strlen_zero, data_filter::name, and NULL.

Referenced by __ast_data_add_structure(), and users_data_provider_get().

02383 {
02384    char *name;
02385    size_t namelen = 1 + (ast_strlen_zero(value) ? 0 : strlen(value));
02386    struct ast_data *res;
02387 
02388    if (!(name = ast_malloc(namelen))) {
02389       return NULL;
02390    }
02391 
02392    strcpy(name, (ast_strlen_zero(value) ? "" : value));
02393 
02394    res = __ast_data_add(root, childname, AST_DATA_PASSWORD, name);
02395    if (!res) {
02396       ast_free(name);
02397    }
02398 
02399    return res;
02400 }

struct ast_data* ast_data_add_ptr ( struct ast_data root,
const char *  childname,
void *  ptr 
) [read]

Add a ptr node type.

Parameters:
[in] root The root of the ast_data to insert into.
[in] childname The name of the child element to be added.
[in] ptr The pointer value to add.
Return values:
NULL on error (memory exhaustion only).
non-NULL a newly allocated node.

Definition at line 2357 of file data.c.

References __ast_data_add(), and AST_DATA_POINTER.

Referenced by __ast_data_add_structure().

02359 {
02360    return __ast_data_add(root, childname, AST_DATA_POINTER, ptr);
02361 }

struct ast_data* ast_data_add_seconds ( struct ast_data root,
const char *  childname,
unsigned int  seconds 
) [read]

Add a seconds node type.

Parameters:
[in] root The root of the ast_data to insert into.
[in] childname The name of the child element to be added.
[in] seconds The value for the new node.
Return values:
NULL on error (memory exhaustion only).
non-NULL a newly allocated node.

Definition at line 2369 of file data.c.

References __ast_data_add(), and AST_DATA_SECONDS.

Referenced by __ast_data_add_structure().

02371 {
02372    return __ast_data_add(root, childname, AST_DATA_SECONDS, &seconds);
02373 }

struct ast_data* ast_data_add_str ( struct ast_data root,
const char *  childname,
const char *  string 
) [read]

Add a string node type.

Parameters:
[in] root The root of the ast_data to insert into.
[in] childname The name of the child element to be added.
[in] string The value for the new node.
Return values:
NULL on error (memory exhaustion only).
non-NULL a newly allocated node.

Definition at line 2402 of file data.c.

References __ast_data_add(), AST_DATA_STRING, ast_free, ast_malloc, ast_strlen_zero, data_filter::name, and NULL.

Referenced by __ast_data_add_structure(), ast_channel_data_add_structure(), dahdi_status_data_provider_get(), dahdi_version_data_provider_get(), data_add_codec(), data_channeltypes_provider_handler(), data_odbc_provider_handler(), hints_data_provider_get(), peers_data_provider_get(), queues_data_provider_get_helper(), and users_data_provider_get().

02404 {
02405    char *name;
02406    size_t namelen = 1 + (ast_strlen_zero(value) ? 0 : strlen(value));
02407    struct ast_data *res;
02408 
02409    if (!(name = ast_malloc(namelen))) {
02410       return NULL;
02411    }
02412 
02413    strcpy(name, (ast_strlen_zero(value) ? "" : value));
02414 
02415    res = __ast_data_add(root, childname, AST_DATA_STRING, name);
02416    if (!res) {
02417       ast_free(name);
02418    }
02419 
02420    return res;
02421 }

struct ast_data* ast_data_add_timestamp ( struct ast_data root,
const char *  childname,
unsigned int  timestamp 
) [read]

Add a timestamp node type.

Parameters:
[in] root The root of the ast_data to insert into.
[in] childname The name of the child element to be added.
[in] timestamp The value for the new node.
Return values:
NULL on error (memory exhaustion only).
non-NULL a newly allocated node.

Definition at line 2363 of file data.c.

References __ast_data_add(), and AST_DATA_TIMESTAMP.

Referenced by __ast_data_add_structure().

02365 {
02366    return __ast_data_add(root, childname, AST_DATA_TIMESTAMP, &timestamp);
02367 }

struct ast_data* ast_data_add_uint ( struct ast_data root,
const char *  childname,
unsigned int  value 
) [read]

Add an unsigned integer node type.

Parameters:
[in] root The root of the ast_data to insert into.
[in] childname The name of the child element to be added.
[in] value The value for the new node.
Return values:
NULL on error (memory exhaustion only).
non-NULL a newly allocated node.

Definition at line 2333 of file data.c.

References __ast_data_add(), and AST_DATA_UNSIGNED_INTEGER.

Referenced by __ast_data_add_structure(), and ast_channel_data_add_structure().

02335 {
02336    return __ast_data_add(root, name, AST_DATA_UNSIGNED_INTEGER, &value);
02337 }

void ast_data_free ( struct ast_data root  ) 

Release the allocated memory of a tree.

Parameters:
[in] root The sub-tree pointer returned by a call to ast_data_get.
See also:
ast_data_get

Definition at line 2492 of file data.c.

References ao2_ref.

Referenced by handle_cli_data_get(), and manager_data_get().

02493 {
02494    /* destroy it, this will destroy all the internal nodes. */
02495    ao2_ref(root, -1);
02496 }

struct ast_data* ast_data_get ( const struct ast_data_query query  )  [read]

Retrieve a subtree from the asterisk data API.

Parameters:
[in] query The query structure specifying what nodes to retrieve.
Return values:
NULL on error.
non-NULL The dynamically allocated requested sub-tree (it needs to be released using ast_data_free.
See also:
ast_data_free, ast_data_get_xml

Definition at line 2066 of file data.c.

References ast_log, data_read_lock, data_result_generate(), data_structure_compatible(), data_unlock, LOG_ERROR, NULL, ast_data_query::path, and ast_data_query::version.

Referenced by handle_cli_data_get(), and manager_data_get().

02067 {
02068    struct ast_data *res;
02069 
02070    /* check compatibility */
02071    if (!data_structure_compatible(query->version, latest_query_compatible_version,
02072       current_query_version)) {
02073       return NULL;
02074    }
02075 
02076    data_read_lock();
02077    res = data_result_generate(query, query->path);
02078    data_unlock();
02079 
02080    if (!res) {
02081       ast_log(LOG_ERROR, "Unable to get data from %s\n", query->path);
02082       return NULL;
02083    }
02084 
02085    return res;
02086 }

void ast_data_iterator_end ( struct ast_data_iterator iterator  ) 

Release (stop using) an iterator.

Parameters:
[in] iterator The iterator created by ast_data_iterator_start.
See also:
ast_data_iterator_start

Definition at line 2543 of file data.c.

References ao2_iterator_destroy(), ao2_ref, ast_free, ast_data_iterator::internal_iterator, ast_data_iterator::is_pattern, ast_data_iterator::last, NULL, and ast_data_iterator::regex_pattern.

02544 {
02545    /* decrement the reference counter. */
02546    if (iterator->last) {
02547       ao2_ref(iterator->last, -1);
02548    }
02549 
02550    /* release the generated pattern. */
02551    if (iterator->is_pattern) {
02552       regfree(&(iterator->regex_pattern));
02553    }
02554 
02555    ao2_iterator_destroy(&(iterator->internal_iterator));
02556 
02557    ast_free(iterator);
02558    iterator = NULL;
02559 }

struct ast_data_iterator* ast_data_iterator_init ( struct ast_data tree,
const char *  elements 
) [read]

Initialize an iterator.

Parameters:
[in] tree The returned tree by a call to ast_data_get.
[in] elements Which elements to iterate through.
Return values:
NULL on error.
non-NULL A dinamically allocated iterator structure.

Definition at line 2498 of file data.c.

References ao2_iterator_init(), ast_calloc, ast_strdupa, data_result_get_node(), ast_data_iterator::internal_iterator, ast_data_iterator::is_pattern, NULL, ast_data_iterator::pattern, ast_data::ptr, and ast_data_iterator::regex_pattern.

02500 {
02501    struct ast_data_iterator *iterator;
02502    struct ao2_iterator i;
02503    struct ast_data *internal = tree;
02504    char *path, *ptr = NULL;
02505 
02506    if (!elements) {
02507       return NULL;
02508    }
02509 
02510    /* tree is the node we want to use to iterate? or we are going
02511     * to iterate thow an internal node? */
02512    path = ast_strdupa(elements);
02513 
02514    ptr = strrchr(path, '/');
02515    if (ptr) {
02516       *ptr = '\0';
02517       internal = data_result_get_node(tree, path);
02518       if (!internal) {
02519          return NULL;
02520       }
02521    }
02522 
02523    iterator = ast_calloc(1, sizeof(*iterator));
02524    if (!iterator) {
02525       return NULL;
02526    }
02527 
02528    i = ao2_iterator_init(internal->children, 0);
02529 
02530    iterator->pattern = (ptr ? strrchr(elements, '/') + 1 : elements);
02531 
02532    /* is the last node a regular expression?, compile it! */
02533    if (!regcomp(&(iterator->regex_pattern), iterator->pattern,
02534          REG_EXTENDED | REG_NOSUB | REG_ICASE)) {
02535       iterator->is_pattern = 1;
02536    }
02537 
02538    iterator->internal_iterator = i;
02539 
02540    return iterator;
02541 }

struct ast_data* ast_data_iterator_next ( struct ast_data_iterator iterator  )  [read]

Get the next node of the tree.

Parameters:
[in] iterator The iterator structure returned by ast_data_iterator_start.
Return values:
NULL when no more nodes to return.
non-NULL A node of the ast_data tree.
See also:
ast_data_iterator_start, ast_data_iterator_stop

Definition at line 2561 of file data.c.

References ao2_iterator_next, ao2_ref, ast_data_iterator::internal_iterator, ast_data_iterator::is_pattern, ast_data_iterator::last, ast_data::name, NULL, ast_data_iterator::pattern, and ast_data_iterator::regex_pattern.

02562 {
02563    struct ast_data *res;
02564 
02565    if (iterator->last) {
02566       /* release the last retrieved node reference. */
02567       ao2_ref(iterator->last, -1);
02568    }
02569 
02570    while ((res = ao2_iterator_next(&iterator->internal_iterator))) {
02571       /* if there is no node name pattern specified, return
02572        * the next node. */
02573       if (!iterator->pattern) {
02574          break;
02575       }
02576 
02577       /* if the pattern is a regular expression, check if this node
02578        * matches. */
02579       if (iterator->is_pattern && !regexec(&(iterator->regex_pattern),
02580          res->name, 0, NULL, 0)) {
02581          break;
02582       }
02583 
02584       /* if there is a pattern specified, check if this node matches
02585        * the wanted node names. */
02586       if (!iterator->is_pattern && (iterator->pattern &&
02587             !strcasecmp(res->name, iterator->pattern))) {
02588          break;
02589       }
02590 
02591       ao2_ref(res, -1);
02592    }
02593 
02594    iterator->last = res;
02595 
02596    return res;
02597 }

void ast_data_remove_node ( struct ast_data root,
struct ast_data child 
)

Remove a node that was added using ast_data_add_.

Parameters:
[in] root The root node of the node to be removed.
[in] child The node pointer to remove.

Definition at line 2487 of file data.c.

References ao2_unlink, and ast_data::children.

Referenced by dahdi_channels_data_provider_get(), dahdi_status_data_provider_get(), data_channels_provider_handler(), data_channeltypes_provider_handler(), data_odbc_provider_handler(), hints_data_provider_get(), meetme_data_provider_get(), peers_data_provider_get(), queues_data_provider_get_helper(), users_data_provider_get(), and vm_users_data_provider_get_helper().

02488 {
02489    ao2_unlink(root->children, child);
02490 }

int ast_data_retrieve ( struct ast_data tree,
const char *  path,
struct ast_data_retrieve content 
)

Retrieve a value from a node in the tree.

Parameters:
[in] tree The structure returned by a call to ast_data_get.
[in] path The path to the node.
[out] content The node content.
Return values:
0 on success.
<0 on error.

Definition at line 2599 of file data.c.

References ast_data_retrieve::AST_DATA_BOOLEAN, AST_DATA_BOOLEAN, ast_data_retrieve::AST_DATA_CHARACTER, AST_DATA_CHARACTER, AST_DATA_CONTAINER, ast_data_retrieve::AST_DATA_DOUBLE, AST_DATA_DOUBLE, ast_data_retrieve::AST_DATA_INTEGER, AST_DATA_INTEGER, ast_data_retrieve::AST_DATA_IPADDR, AST_DATA_IPADDR, ast_data_retrieve::AST_DATA_MILLISECONDS, AST_DATA_MILLISECONDS, ast_data_retrieve::AST_DATA_PASSWORD, AST_DATA_PASSWORD, ast_data_retrieve::AST_DATA_POINTER, AST_DATA_POINTER, ast_data_retrieve::AST_DATA_SECONDS, AST_DATA_SECONDS, ast_data_retrieve::AST_DATA_STRING, AST_DATA_STRING, ast_data_retrieve::AST_DATA_TIMESTAMP, AST_DATA_TIMESTAMP, ast_data_retrieve::AST_DATA_UNSIGNED_INTEGER, AST_DATA_UNSIGNED_INTEGER, ast_log, ast_data::boolean, ast_data::character, data_result_get_node(), ast_data::dbl, ast_data::ipaddr, LOG_ERROR, ast_data::payload, ast_data::ptr, ast_data::sint, ast_data::str, ast_data::type, ast_data_retrieve::type, ast_data::uint, and ast_data_retrieve::value.

Referenced by ast_data_retrieve_bool(), ast_data_retrieve_char(), ast_data_retrieve_dbl(), ast_data_retrieve_int(), ast_data_retrieve_ipaddr(), ast_data_retrieve_password(), ast_data_retrieve_ptr(), ast_data_retrieve_string(), and ast_data_retrieve_uint().

02601 {
02602    struct ast_data *node;
02603 
02604    if (!content) {
02605       return -1;
02606    }
02607 
02608    node = data_result_get_node(tree, path);
02609    if (!node) {
02610       ast_log(LOG_ERROR, "Invalid internal node %s\n", path);
02611       return -1;
02612    }
02613 
02614    content->type = node->type;
02615    switch (node->type) {
02616    case AST_DATA_STRING:
02617       content->value.AST_DATA_STRING = node->payload.str;
02618       break;
02619    case AST_DATA_PASSWORD:
02620       content->value.AST_DATA_PASSWORD = node->payload.str;
02621       break;
02622    case AST_DATA_TIMESTAMP:
02623       content->value.AST_DATA_TIMESTAMP = node->payload.uint;
02624       break;
02625    case AST_DATA_SECONDS:
02626       content->value.AST_DATA_SECONDS = node->payload.uint;
02627       break;
02628    case AST_DATA_MILLISECONDS:
02629       content->value.AST_DATA_MILLISECONDS = node->payload.uint;
02630       break;
02631    case AST_DATA_CHARACTER:
02632       content->value.AST_DATA_CHARACTER = node->payload.character;
02633       break;
02634    case AST_DATA_INTEGER:
02635       content->value.AST_DATA_INTEGER = node->payload.sint;
02636       break;
02637    case AST_DATA_UNSIGNED_INTEGER:
02638       content->value.AST_DATA_UNSIGNED_INTEGER = node->payload.uint;
02639       break;
02640    case AST_DATA_BOOLEAN:
02641       content->value.AST_DATA_BOOLEAN = node->payload.boolean;
02642       break;
02643    case AST_DATA_IPADDR:
02644       content->value.AST_DATA_IPADDR = node->payload.ipaddr;
02645       break;
02646    case AST_DATA_DOUBLE:
02647       content->value.AST_DATA_DOUBLE = node->payload.dbl;
02648       break;
02649    case AST_DATA_CONTAINER:
02650       break;
02651    case AST_DATA_POINTER:
02652       content->value.AST_DATA_POINTER = node->payload.ptr;
02653       break;
02654    }
02655 
02656    return 0;
02657 }

static unsigned int ast_data_retrieve_bool ( struct ast_data tree,
const char *  path 
) [inline, static]

Retrieve the boolean value of a node.

Parameters:
[in] tree The tree from where to get the value.
[in] path The node name or path.
Returns:
The value of the node.

Definition at line 704 of file data.h.

References ast_data_retrieve::AST_DATA_BOOLEAN, ast_data_retrieve(), and ast_data_retrieve::value.

00705 {
00706    struct ast_data_retrieve ret;
00707 
00708    ast_data_retrieve(tree, path, &ret);
00709 
00710    return ret.value.AST_DATA_BOOLEAN;
00711 }

static char ast_data_retrieve_char ( struct ast_data tree,
const char *  path 
) [inline, static]

Retrieve the character value of a node.

Parameters:
[in] tree The tree from where to get the value.
[in] path The node name or path.
Returns:
The value of the node.

Definition at line 689 of file data.h.

References ast_data_retrieve::AST_DATA_CHARACTER, ast_data_retrieve(), and ast_data_retrieve::value.

00690 {
00691    struct ast_data_retrieve ret;
00692 
00693    ast_data_retrieve(tree, path, &ret);
00694 
00695    return ret.value.AST_DATA_CHARACTER;
00696 }

static double ast_data_retrieve_dbl ( struct ast_data tree,
const char *  path 
) [inline, static]

Retrieve the double value of a node.

Parameters:
[in] tree The tree from where to get the value.
[in] path The node name or path.
Returns:
The value of the node.

Definition at line 779 of file data.h.

References ast_data_retrieve::AST_DATA_DOUBLE, ast_data_retrieve(), and ast_data_retrieve::value.

00780 {
00781    struct ast_data_retrieve ret;
00782 
00783    ast_data_retrieve(tree, path, &ret);
00784 
00785    return ret.value.AST_DATA_DOUBLE;
00786 }

static int ast_data_retrieve_int ( struct ast_data tree,
const char *  path 
) [inline, static]

Retrieve the integer value of a node.

Parameters:
[in] tree The tree from where to get the value.
[in] path The node name or path.
Returns:
The value of the node.

Definition at line 674 of file data.h.

References ast_data_retrieve::AST_DATA_INTEGER, ast_data_retrieve(), and ast_data_retrieve::value.

00675 {
00676    struct ast_data_retrieve ret;
00677 
00678    ast_data_retrieve(tree, path, &ret);
00679 
00680    return ret.value.AST_DATA_INTEGER;
00681 }

static struct in_addr ast_data_retrieve_ipaddr ( struct ast_data tree,
const char *  path 
) [static, read]

Retrieve the ipv4 address value of a node.

Parameters:
[in] tree The tree from where to get the value.
[in] path The node name or path.
Returns:
The value of the node.

Definition at line 794 of file data.h.

References ast_data_retrieve::AST_DATA_IPADDR, ast_data_retrieve(), and ast_data_retrieve::value.

00795 {
00796    struct ast_data_retrieve ret;
00797 
00798    ast_data_retrieve(tree, path, &ret);
00799 
00800    return ret.value.AST_DATA_IPADDR;
00801 }

char* ast_data_retrieve_name ( struct ast_data node  ) 

Get the node name.

Parameters:
[in] node The node pointer.
Returns:
The node name.

Definition at line 2226 of file data.c.

References ast_data::name.

02227 {
02228    return node->name;
02229 }

static const char* ast_data_retrieve_password ( struct ast_data tree,
const char *  path 
) [inline, static]

Retrieve the password value of a node.

Parameters:
[in] tree The tree from where to get the value.
[in] path The node name or path.
Returns:
The value of the node.

Definition at line 734 of file data.h.

References ast_data_retrieve::AST_DATA_PASSWORD, ast_data_retrieve(), and ast_data_retrieve::value.

00735 {
00736    struct ast_data_retrieve ret;
00737 
00738    ast_data_retrieve(tree, path, &ret);
00739 
00740    return ret.value.AST_DATA_PASSWORD;
00741 }

static void* ast_data_retrieve_ptr ( struct ast_data tree,
const char *  path 
) [inline, static]

Retrieve the ptr value of a node.

Parameters:
[in] tree The tree from where to get the value.
[in] path The node name or path.
Returns:
The value of the node.

Definition at line 764 of file data.h.

References ast_data_retrieve::AST_DATA_POINTER, ast_data_retrieve(), and ast_data_retrieve::value.

00765 {
00766    struct ast_data_retrieve ret;
00767 
00768    ast_data_retrieve(tree, path, &ret);
00769 
00770    return ret.value.AST_DATA_POINTER;
00771 }

static const char* ast_data_retrieve_string ( struct ast_data tree,
const char *  path 
) [inline, static]

Retrieve the string value of a node.

Parameters:
[in] tree The tree from where to get the value.
[in] path The node name or path.
Returns:
The value of the node.

Definition at line 749 of file data.h.

References ast_data_retrieve(), ast_data_retrieve::AST_DATA_STRING, and ast_data_retrieve::value.

00750 {
00751    struct ast_data_retrieve ret;
00752 
00753    ast_data_retrieve(tree, path, &ret);
00754 
00755    return ret.value.AST_DATA_STRING;
00756 }

enum ast_data_type ast_data_retrieve_type ( struct ast_data res,
const char *  path 
)

Get a node type.

Parameters:
[in] res A pointer to the ast_data result set.
[in] path A path to the node to get the type.
Returns:
The type of the requested node type.

Definition at line 2214 of file data.c.

References data_result_get_node().

02215 {
02216    struct ast_data *internal;
02217 
02218    internal = data_result_get_node(node, path);
02219    if (!internal) {
02220       return -1;
02221    }
02222 
02223    return internal->type;
02224 }

static unsigned int ast_data_retrieve_uint ( struct ast_data tree,
const char *  path 
) [inline, static]

Retrieve the unsigned integer value of a node.

Parameters:
[in] tree The tree from where to get the value.
[in] path The node name or path.
Returns:
The value of the node.

Definition at line 719 of file data.h.

References ast_data_retrieve(), ast_data_retrieve::AST_DATA_UNSIGNED_INTEGER, and ast_data_retrieve::value.

00720 {
00721    struct ast_data_retrieve ret;
00722 
00723    ast_data_retrieve(tree, path, &ret);
00724 
00725    return ret.value.AST_DATA_UNSIGNED_INTEGER;
00726 }

int ast_data_search_match ( const struct ast_data_search search,
struct ast_data data 
)

Check the current generated node to know if it matches the search condition.

Parameters:
[in] search The search condition.
[in] data The AstData node generated.
Returns:
1 If the "data" node matches the search condition.

0 If the "data" node does not matches the search condition.

See also:
ast_data_remove_node

Definition at line 1459 of file data.c.

References ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, AST_DATA_BOOLEAN, AST_DATA_CHARACTER, AST_DATA_CONTAINER, AST_DATA_DOUBLE, AST_DATA_INTEGER, AST_DATA_IPADDR, AST_DATA_MILLISECONDS, AST_DATA_PASSWORD, AST_DATA_POINTER, ast_data_search_match(), AST_DATA_SECONDS, AST_DATA_STRING, AST_DATA_TIMESTAMP, AST_DATA_UNSIGNED_INTEGER, ast_data::boolean, ast_data::character, ast_data::children, ast_data_search::children, data_result_find_child(), data_search_cmp_bool(), data_search_cmp_char(), data_search_cmp_int(), data_search_cmp_ipaddr(), data_search_cmp_ptr(), data_search_cmp_string(), data_search_cmp_uint(), data_search_find(), ast_data::dbl, ast_data::ipaddr, ast_data_search::name, ast_data::name, ast_data::payload, ast_data::ptr, ast_data::sint, ast_data::str, ast_data::type, and ast_data::uint.

Referenced by ast_data_search_match(), dahdi_channels_data_provider_get(), dahdi_status_data_provider_get(), data_channels_provider_handler(), data_channeltypes_provider_handler(), data_odbc_provider_handler(), hints_data_provider_get(), meetme_data_provider_get(), peers_data_provider_get(), queues_data_provider_get_helper(), users_data_provider_get(), and vm_users_data_provider_get_helper().

01460 {
01461    struct ao2_iterator i, ii;
01462    struct ast_data_search *s, *s_child;
01463    struct ast_data *d_child;
01464    int notmatch = 1;
01465 
01466    if (!search) {
01467       return 1;
01468    }
01469 
01470    s_child = data_search_find(search->children, data->name);
01471    if (!s_child) {
01472       /* nothing to compare */
01473       ao2_ref(s_child, -1);
01474       return 1;
01475    }
01476 
01477    i = ao2_iterator_init(s_child->children, 0);
01478    while ((s = ao2_iterator_next(&i))) {
01479       if (!ao2_container_count(s->children)) {
01480          /* compare this search node with every data node */
01481          d_child = data_result_find_child(data, s->name);
01482          if (!d_child) {
01483             ao2_ref(s, -1);
01484             notmatch = 1;
01485             continue;
01486          }
01487 
01488          switch (d_child->type) {
01489          case AST_DATA_PASSWORD:
01490          case AST_DATA_STRING:
01491             notmatch = data_search_cmp_string(s_child, d_child->name,
01492                d_child->payload.str);
01493             break;
01494          case AST_DATA_CHARACTER:
01495             notmatch = data_search_cmp_char(s_child, d_child->name,
01496                d_child->payload.character);
01497             break;
01498          case AST_DATA_INTEGER:
01499             notmatch = data_search_cmp_int(s_child, d_child->name,
01500                d_child->payload.sint);
01501             break;
01502          case AST_DATA_BOOLEAN:
01503             notmatch = data_search_cmp_bool(s_child, d_child->name,
01504                d_child->payload.boolean);
01505             break;
01506          case AST_DATA_UNSIGNED_INTEGER:
01507             notmatch = data_search_cmp_uint(s_child, d_child->name,
01508                d_child->payload.uint);
01509             break;
01510          case AST_DATA_TIMESTAMP:
01511          case AST_DATA_SECONDS:
01512          case AST_DATA_MILLISECONDS:
01513          case AST_DATA_DOUBLE:
01514             notmatch = data_search_cmp_uint(s_child, d_child->name,
01515                d_child->payload.dbl);
01516             break;
01517          case AST_DATA_IPADDR:
01518             notmatch = data_search_cmp_ipaddr(s_child, d_child->name,
01519                d_child->payload.ipaddr);
01520             break;
01521          case AST_DATA_POINTER:
01522             notmatch = data_search_cmp_ptr(s_child, d_child->name,
01523                d_child->payload.ptr);
01524             break;
01525          case AST_DATA_CONTAINER:
01526             break;
01527          }
01528          ao2_ref(d_child, -1);
01529       } else {
01530          ii = ao2_iterator_init(data->children, 0);
01531          while ((d_child = ao2_iterator_next(&ii))) {
01532             if (strcmp(d_child->name, s->name)) {
01533                ao2_ref(d_child, -1);
01534                continue;
01535             }
01536             if (!(notmatch = !ast_data_search_match(s_child, d_child))) {
01537                /* do not continue if we have a match. */
01538                ao2_ref(d_child, -1);
01539                break;
01540             }
01541             ao2_ref(d_child, -1);
01542          }
01543          ao2_iterator_destroy(&ii);
01544       }
01545       ao2_ref(s, -1);
01546       if (notmatch) {
01547          /* do not continue if we don't have a match. */
01548          break;
01549       }
01550    }
01551    ao2_iterator_destroy(&i);
01552 
01553    ao2_ref(s_child, -1);
01554 
01555    return !notmatch;
01556 }


Generated on Thu Apr 16 06:30:35 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6