data.c File Reference

Data retrieval API. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include <regex.h>
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/data.h"
#include "asterisk/astobj2.h"
#include "asterisk/xml.h"
#include "asterisk/cli.h"
#include "asterisk/term.h"
#include "asterisk/manager.h"
#include "asterisk/test.h"
#include "asterisk/frame.h"
#include "asterisk/codec.h"

Include dependency graph for data.c:

Go to the source code of this file.

Data Structures

struct  ast_data
 The data tree to be returned by the callbacks and managed by functions local to this file. More...
struct  ast_data_iterator
 This structure is used by the iterator. More...
struct  ast_data_search
 The list of nodes with their search requirement. More...
struct  data_filter
 The filter node. More...
struct  data_filter::glob_list_t
 glob list More...
struct  data_provider
 A data container node pointing to the registered handler. More...

Defines

#define data_read_lock()   ast_rwlock_rdlock(&root_data.lock)
#define data_unlock()   ast_rwlock_unlock(&root_data.lock)
#define data_write_lock()   ast_rwlock_wrlock(&root_data.lock)
#define NUM_DATA_FILTER_BUCKETS   59
#define NUM_DATA_NODE_BUCKETS   59
#define NUM_DATA_RESULT_BUCKETS   59
#define NUM_DATA_SEARCH_BUCKETS   59

Enumerations

enum  data_search_comparison {
  DATA_CMP_UNKNOWN, DATA_CMP_EQ, DATA_CMP_NEQ, DATA_CMP_GT,
  DATA_CMP_GE, DATA_CMP_LT, DATA_CMP_LE
}
 Type of comparisons allow in the search string. More...

Functions

static struct ast_data__ast_data_add (struct ast_data *root, const char *name, enum ast_data_type type, void *ptr)
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.
static void __data_result_print_cli (int fd, const struct ast_data *root, uint32_t depth)
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 *name, 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 *cap)
 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 *name, 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 *name)
 Add a container child.
struct ast_dataast_data_add_password (struct ast_data *root, const char *childname, const char *value)
 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 *value)
 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 *name, 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.
int ast_data_init (void)
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.
char * ast_data_retrieve_name (struct ast_data *node)
 Get the node name.
enum ast_data_type ast_data_retrieve_type (struct ast_data *node, const char *path)
 Get a node type.
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.
static int data_add_codec (struct ast_data *codecs, struct ast_format *format)
static struct data_filterdata_filter_add_child (struct ao2_container *root, char *name)
static int data_filter_add_nodes (struct ao2_container *root, char *path)
static struct data_filterdata_filter_alloc (const char *name)
static int data_filter_cmp (void *obj, void *arg, int flags)
static void data_filter_destructor (void *obj)
static struct data_filterdata_filter_find (struct ao2_container *parent, const char *name)
static struct data_filterdata_filter_generate (const char *constfilter)
static int data_filter_hash (const void *obj, const int flags)
static void data_filter_release (struct data_filter *filter)
static struct data_providerdata_provider_add_child (struct ao2_container *parent, const char *name, const struct ast_data_handler *handler, const char *registrar)
static int data_provider_cmp (void *obj1, void *obj2, int flags)
static struct data_providerdata_provider_create (struct ao2_container *parent, const char *path, const char *registrar)
static void data_provider_destructor (void *obj)
static struct data_providerdata_provider_find (struct ao2_container *parent, const char *name, const char *registrar)
static int data_provider_hash (const void *obj, const int flags)
static struct data_providerdata_provider_new (const char *name, const struct ast_data_handler *handler, const char *registrar)
static void data_provider_print_cli (int fd, const char *name, struct ao2_container *container, struct ast_str *path)
static int data_provider_release (struct ao2_container *parent, const char *path, const char *registrar)
static void data_provider_release_all (struct ao2_container *parent, const char *registrar)
static void data_result_add_child (struct ast_data *root, struct ast_data *child)
static int data_result_cmp (void *obj, void *arg, int flags)
static struct ast_datadata_result_create (const char *name)
static void data_result_destructor (void *obj)
static struct ast_datadata_result_find_child (struct ast_data *root, const char *name)
static struct ast_datadata_result_generate (const struct ast_data_query *query, const char *search_path)
static struct ast_datadata_result_generate_node (const struct ast_data_query *query, const struct data_provider *root_provider, const char *parent_node_name, const struct ast_data_search *search, const struct data_filter *filter)
static int data_result_get_color (enum ast_data_type type)
static struct ast_datadata_result_get_node (struct ast_data *node, const char *path)
static int data_result_hash (const void *obj, const int flags)
static void data_result_manager_output (struct mansession *s, const char *name, struct ao2_container *container, struct ast_str *path, int id)
static void data_result_print_cli (int fd, const struct ast_data *root)
static void data_result_print_cli_node (int fd, const struct ast_data *node, uint32_t depth)
static struct ast_data_searchdata_search_add_child (struct ao2_container *parent, const char *name)
static struct ast_data_searchdata_search_alloc (const char *name)
static int data_search_cmp (void *obj, void *arg, int flags)
static int data_search_cmp_bool (const struct ast_data_search *root, const char *name, unsigned int value)
static int data_search_cmp_char (const struct ast_data_search *root, const char *name, char value)
static int data_search_cmp_dbl (const struct ast_data_search *root, const char *name, double value)
static int data_search_cmp_int (const struct ast_data_search *root, const char *name, int value)
static int data_search_cmp_ipaddr (const struct ast_data_search *root, const char *name, struct in_addr addr)
static int data_search_cmp_ptr (const struct ast_data_search *root, const char *name, void *ptr)
static int data_search_cmp_string (const struct ast_data_search *root, const char *name, char *value)
static int data_search_cmp_uint (const struct ast_data_search *root, const char *name, unsigned int value)
static int data_search_comparison_char (char a)
static int data_search_comparison_result (int cmpval, enum data_search_comparison comparison_type)
static enum data_search_comparison data_search_comparison_type (const char *comparison)
static struct ast_data_searchdata_search_create (struct ao2_container *parent, const char *path)
static void data_search_destructor (void *obj)
static struct ast_data_searchdata_search_find (struct ao2_container *parent, const char *name)
static struct ast_data_searchdata_search_generate (const char *search_string)
static struct ast_data_searchdata_search_get_node (const struct ast_data_search *node, const char *path)
static int data_search_hash (const void *obj, const int flags)
static int data_search_mapping_find (const struct ast_data_mapping_structure *map, size_t mapping_len, const char *member_name)
static void data_search_release (struct ast_data_search *search)
static void data_shutdown (void)
static int data_structure_compatible (int structure_version, uint32_t latest_compatible, uint32_t current)
static char * handle_cli_data_get (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_cli_data_show_providers (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int manager_data_get (struct mansession *s, const struct message *m)
static char * next_node_name (char **path)

Variables

static struct ast_cli_entry cli_data []
static const uint32_t current_handler_version = AST_DATA_HANDLER_VERSION
 Current handler structure version.
static const uint32_t current_query_version = AST_DATA_QUERY_VERSION
 Current query structure version.
struct {
   int   color
   enum ast_data_type   type
data_result_color []
static const uint32_t latest_handler_compatible_version = 0
 The last compatible version.
static const uint32_t latest_query_compatible_version = 0
 The last compatible version.
struct {
   struct ao2_container *   container
 The asterisk data main content structure.
   ast_rwlock_t   lock
 asterisk data locking mechanism.
root_data


Detailed Description

Data retrieval API.

Author:
Brett Bryant <brettbryant@gmail.com>

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

Definition in file data.c.


Define Documentation

 
#define data_read_lock (  )     ast_rwlock_rdlock(&root_data.lock)

Definition at line 239 of file data.c.

Referenced by ast_data_get(), and handle_cli_data_show_providers().

 
#define data_unlock (  )     ast_rwlock_unlock(&root_data.lock)

 
#define data_write_lock (  )     ast_rwlock_wrlock(&root_data.lock)

Definition at line 232 of file data.c.

Referenced by __ast_data_register(), and __ast_data_unregister().

#define NUM_DATA_FILTER_BUCKETS   59

Definition at line 70 of file data.c.

Referenced by data_filter_alloc().

#define NUM_DATA_NODE_BUCKETS   59

Definition at line 67 of file data.c.

Referenced by ast_data_init(), and data_provider_new().

#define NUM_DATA_RESULT_BUCKETS   59

Definition at line 68 of file data.c.

Referenced by data_result_create().

#define NUM_DATA_SEARCH_BUCKETS   59

Definition at line 69 of file data.c.

Referenced by data_search_alloc().


Enumeration Type Documentation

Type of comparisons allow in the search string.

Enumerator:
DATA_CMP_UNKNOWN 
DATA_CMP_EQ 
DATA_CMP_NEQ 
DATA_CMP_GT 
DATA_CMP_GE 
DATA_CMP_LT 
DATA_CMP_LE 

Definition at line 112 of file data.c.

00112                             {
00113    DATA_CMP_UNKNOWN,
00114    DATA_CMP_EQ,   /* =  */
00115    DATA_CMP_NEQ,  /* != */
00116    DATA_CMP_GT,   /* >  */
00117    DATA_CMP_GE,   /* >= */
00118    DATA_CMP_LT,   /* <  */
00119    DATA_CMP_LE /* <= */
00120 };


Function Documentation

static struct ast_data* __ast_data_add ( struct ast_data root,
const char *  name,
enum ast_data_type  type,
void *  ptr 
) [static, read]

Definition at line 2241 of file data.c.

References 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_SECONDS, AST_DATA_STRING, AST_DATA_TIMESTAMP, AST_DATA_UNSIGNED_INTEGER, ast_data::boolean, ast_data::character, data_filter::children, ast_data::children, data_filter_find(), data_result_add_child(), data_result_create(), ast_data::dbl, ast_data::filter, filter(), ast_data::ipaddr, NULL, ast_data::payload, ast_data::ptr, ast_data::sint, ast_data::str, ast_data::type, and ast_data::uint.

Referenced by 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_node(), ast_data_add_password(), ast_data_add_ptr(), ast_data_add_seconds(), ast_data_add_str(), ast_data_add_timestamp(), and ast_data_add_uint().

02243 {
02244    struct ast_data *node;
02245    struct data_filter *filter, *filter_child = NULL;
02246 
02247    if (!root || !root->children) {
02248       /* invalid data result node. */
02249       return NULL;
02250    }
02251 
02252    /* check if we need to add this node, based on the filter. */
02253    if (root->filter) {
02254       filter = data_filter_find(root->filter->children, name);
02255       if (!filter) {
02256          return NULL;
02257       }
02258       ao2_ref(filter, -1);
02259    }
02260 
02261    node = data_result_create(name);
02262    if (!node) {
02263       return NULL;
02264    }
02265 
02266    node->type = type;
02267 
02268    switch (type) {
02269    case AST_DATA_BOOLEAN:
02270       node->payload.boolean = *(unsigned int *) ptr;
02271       break;
02272    case AST_DATA_INTEGER:
02273       node->payload.sint = *(int *) ptr;
02274       break;
02275    case AST_DATA_TIMESTAMP:
02276    case AST_DATA_SECONDS:
02277    case AST_DATA_MILLISECONDS:
02278    case AST_DATA_UNSIGNED_INTEGER:
02279       node->payload.uint = *(unsigned int *) ptr;
02280       break;
02281    case AST_DATA_DOUBLE:
02282       node->payload.dbl = *(double *) ptr;
02283       break;
02284    case AST_DATA_PASSWORD:
02285    case AST_DATA_STRING:
02286       node->payload.str = (char *) ptr;
02287       break;
02288    case AST_DATA_CHARACTER:
02289       node->payload.character = *(char *) ptr;
02290       break;
02291    case AST_DATA_POINTER:
02292       node->payload.ptr = ptr;
02293       break;
02294    case AST_DATA_IPADDR:
02295       node->payload.ipaddr = *(struct in_addr *) ptr;
02296       break;
02297    case AST_DATA_CONTAINER:
02298       if (root->filter) {
02299          filter_child = data_filter_find(root->filter->children, name);
02300          if (filter_child) {
02301             /* do not increment the refcount because it is not neccesary. */
02302             ao2_ref(filter_child, -1);
02303          }
02304       }
02305       node->filter = filter_child;
02306       break;
02307    default:
02308       break;
02309    }
02310 
02311    data_result_add_child(root, node);
02312 
02313    ao2_ref(node, -1);
02314 
02315    return node;
02316 }

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 }

static void __data_result_print_cli ( int  fd,
const struct ast_data root,
uint32_t  depth 
) [static]

Definition at line 2820 of file data.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, AST_DATA_CONTAINER, ast_data::children, data_result_print_cli_node(), and ast_data::type.

Referenced by data_result_print_cli(), and data_result_print_cli_node().

02821 {
02822    struct ao2_iterator iter;
02823    struct ast_data *node;
02824 
02825    if (root->type == AST_DATA_CONTAINER) {
02826       iter = ao2_iterator_init(root->children, 0);
02827       while ((node = ao2_iterator_next(&iter))) {
02828          data_result_print_cli_node(fd, node, depth + 1);
02829          ao2_ref(node, -1);
02830       }
02831       ao2_iterator_destroy(&iter);
02832    } else {
02833       data_result_print_cli_node(fd, root, depth);
02834    }
02835 }

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 }

int ast_data_init ( void   ) 

Provided by data.c

Definition at line 3328 of file data.c.

References ao2_container_alloc, ARRAY_LEN, ast_cli_register_multiple(), ast_manager_register_xml_core, ast_register_cleanup(), ast_rwlock_init, AST_TEST_REGISTER, cli_data, data_provider_cmp(), data_provider_hash(), data_shutdown(), manager_data_get(), NUM_DATA_NODE_BUCKETS, and root_data.

Referenced by main().

03329 {
03330    int res = 0;
03331 
03332    ast_rwlock_init(&root_data.lock);
03333 
03334    if (!(root_data.container = ao2_container_alloc(NUM_DATA_NODE_BUCKETS,
03335       data_provider_hash, data_provider_cmp))) {
03336       return -1;
03337    }
03338 
03339    res |= ast_cli_register_multiple(cli_data, ARRAY_LEN(cli_data));
03340 
03341    res |= ast_manager_register_xml_core("DataGet", 0, manager_data_get);
03342 
03343    AST_TEST_REGISTER(test_data_get);
03344 
03345    ast_register_cleanup(data_shutdown);
03346 
03347    return res;
03348 }

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 }

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 }

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 }

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 }

static int data_add_codec ( struct ast_data codecs,
struct ast_format format 
) [static]

Definition at line 3101 of file data.c.

References ao2_ref, ast_codec_get_by_id(), ast_data_add_int(), ast_data_add_node(), ast_data_add_str(), ast_format_get_codec_id(), ast_codec::description, ast_codec::minimum_bytes, ast_codec::name, ast_codec::sample_rate, and tmp().

Referenced by ast_data_add_codec(), and ast_data_add_codecs().

03101                                                                               {
03102    struct ast_data *codec;
03103    struct ast_codec *tmp;
03104 
03105    tmp = ast_codec_get_by_id(ast_format_get_codec_id(format));
03106    if (!tmp) {
03107       return -1;
03108    }
03109 
03110    codec = ast_data_add_node(codecs, "codec");
03111    if (!codec) {
03112       ao2_ref(tmp, -1);
03113       return -1;
03114    }
03115 
03116    ast_data_add_str(codec, "name", tmp->name);
03117    ast_data_add_int(codec, "samplespersecond", tmp->sample_rate);
03118    ast_data_add_str(codec, "description", tmp->description);
03119    ast_data_add_int(codec, "frame_length", tmp->minimum_bytes);
03120    ao2_ref(tmp, -1);
03121 
03122    return 0;
03123 }

static struct data_filter* data_filter_add_child ( struct ao2_container root,
char *  name 
) [static, read]

Definition at line 1781 of file data.c.

References ao2_link, data_filter_alloc(), data_filter_find(), and NULL.

Referenced by data_filter_add_nodes().

01783 {
01784    struct data_filter *node;
01785 
01786    node = data_filter_find(root, name);
01787    if (node) {
01788       return node;
01789    }
01790 
01791    node = data_filter_alloc(name);
01792    if (!node) {
01793       return NULL;
01794    }
01795 
01796    ao2_link(root, node);
01797 
01798    return node;
01799 }

static int data_filter_add_nodes ( struct ao2_container root,
char *  path 
) [static]

Definition at line 1809 of file data.c.

References ao2_ref, ast_strdupa, data_filter::children, data_filter_add_child(), next_node_name(), and NULL.

Referenced by data_filter_generate().

01810 {
01811    struct data_filter *node;
01812    char *savepath, *saveptr, *token, *node_name;
01813    int ret = 0;
01814 
01815    if (!path) {
01816       return 0;
01817    }
01818 
01819    savepath = ast_strdupa(path);
01820 
01821    node_name = next_node_name(&savepath);
01822 
01823    if (!node_name) {
01824       return 0;
01825    }
01826 
01827    for (token = strtok_r(node_name, "|", &saveptr);
01828          token; token = strtok_r(NULL, "|", &saveptr)) {
01829       node = data_filter_add_child(root, token);
01830       if (!node) {
01831          continue;
01832       }
01833       data_filter_add_nodes(node->children, savepath);
01834       ret = 1;
01835       ao2_ref(node, -1);
01836    }
01837 
01838    return ret;
01839 }

static struct data_filter* data_filter_alloc ( const char *  name  )  [static, read]

Definition at line 1648 of file data.c.

References ao2_alloc, ao2_container_alloc, ao2_ref, AST_LIST_INSERT_TAIL, ast_strdupa, data_filter::children, data_filter_cmp(), data_filter_destructor(), data_filter_hash(), data_filter::glob_list, data_filter::list, data_filter::name, NULL, NUM_DATA_FILTER_BUCKETS, and strsep().

Referenced by data_filter_add_child(), data_filter_find(), and data_filter_generate().

01649 {
01650    char *globname, *token;
01651    struct data_filter *res, *globfilter;
01652    size_t name_len = strlen(name) + 1;
01653 
01654    res = ao2_alloc(sizeof(*res) + name_len, data_filter_destructor);
01655    if (!res) {
01656       return NULL;
01657    }
01658 
01659    res->children = ao2_container_alloc(NUM_DATA_FILTER_BUCKETS, data_filter_hash,
01660       data_filter_cmp);
01661 
01662    if (!res->children) {
01663       ao2_ref(res, -1);
01664       return NULL;
01665    }
01666 
01667    strcpy(res->name, name);
01668 
01669    if (strchr(res->name, '*')) {
01670       globname = ast_strdupa(res->name);
01671 
01672       while ((token = strsep(&globname, "*"))) {
01673          globfilter = data_filter_alloc(token);
01674          AST_LIST_INSERT_TAIL(&(res->glob_list), globfilter, list);
01675       }
01676    }
01677 
01678    return res;
01679 }

static int data_filter_cmp ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 1620 of file data.c.

References CMP_MATCH, and data_filter::name.

Referenced by data_filter_alloc().

01621 {
01622    struct data_filter *node1 = obj, *node2 = arg;
01623    return strcasecmp(node1->name, node2->name) ? 0 : CMP_MATCH;
01624 }

static void data_filter_destructor ( void *  obj  )  [static]

Definition at line 1631 of file data.c.

References ao2_ref, AST_LIST_REMOVE_HEAD, data_filter::children, filter(), data_filter::glob_list, and data_filter::list.

Referenced by data_filter_alloc().

01632 {
01633    struct data_filter *filter = obj, *globres;
01634 
01635    while ((globres = AST_LIST_REMOVE_HEAD(&(filter->glob_list), list))) {
01636       ao2_ref(globres, -1);
01637    }
01638 
01639    ao2_ref(filter->children, -1);
01640 }

static struct data_filter* data_filter_find ( struct ao2_container parent,
const char *  name 
) [static, read]

Definition at line 1700 of file data.c.

References ao2_find, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_LAST, AST_LIST_TRAVERSE, ast_strlen_zero, data_filter_alloc(), data_filter::glob_list, data_filter::list, data_filter::name, NULL, and OBJ_POINTER.

Referenced by __ast_data_add(), data_filter_add_child(), data_result_generate(), and data_result_generate_node().

01702 {
01703    int i, olend, orend, globfound;
01704    size_t name_len = strlen(name), glob_len;
01705    struct ao2_iterator iter;
01706    struct data_filter *find_node, *found, *globres;
01707 
01708    find_node = data_filter_alloc(name);
01709    if (!find_node) {
01710       return NULL;
01711    }
01712 
01713    found = ao2_find(parent, find_node, OBJ_POINTER);
01714 
01715    /* free the created node used for searching. */
01716    ao2_ref(find_node, -1);
01717 
01718    if (found) {
01719       return found;
01720    }
01721 
01722    iter = ao2_iterator_init(parent, 0);
01723    while ((found = ao2_iterator_next(&iter))) {
01724       if (!AST_LIST_EMPTY(&(found->glob_list))) {
01725          i = 0;
01726          globfound = 1;
01727 
01728          olend = ast_strlen_zero(AST_LIST_FIRST(&(found->glob_list))->name);
01729          orend = ast_strlen_zero(AST_LIST_LAST(&(found->glob_list))->name);
01730 
01731          AST_LIST_TRAVERSE(&(found->glob_list), globres, list) {
01732             if (!*globres->name) {
01733                continue;
01734             }
01735 
01736             glob_len = strlen(globres->name);
01737 
01738             if (!i && !olend) {
01739                if (strncasecmp(name, globres->name, glob_len)) {
01740                   globfound = 0;
01741                   break;
01742                }
01743 
01744                i += glob_len;
01745                continue;
01746             }
01747 
01748             for (globfound = 0; name_len - i >= glob_len; ++i) {
01749                if (!strncasecmp(name + i, globres->name, glob_len)) {
01750                   globfound = 1;
01751                   i += glob_len;
01752                   break;
01753                }
01754             }
01755 
01756             if (!globfound) {
01757                break;
01758             }
01759          }
01760 
01761          if (globfound && (i == name_len || orend)) {
01762             ao2_iterator_destroy(&iter);
01763             return found;
01764          }
01765       }
01766 
01767       ao2_ref(found, -1);
01768    }
01769    ao2_iterator_destroy(&iter);
01770 
01771    return NULL;
01772 }

static struct data_filter* data_filter_generate ( const char *  constfilter  )  [static, read]

Definition at line 1846 of file data.c.

References ao2_ref, ast_strdupa, data_filter::children, data_filter_add_nodes(), data_filter_alloc(), filter(), and NULL.

Referenced by data_result_generate().

01847 {
01848    struct data_filter *filter = NULL;
01849    char *strfilter, *token, *saveptr;
01850    int node_added = 0;
01851 
01852    if (!constfilter) {
01853       return NULL;
01854    }
01855 
01856    strfilter = ast_strdupa(constfilter);
01857 
01858    filter = data_filter_alloc("/");
01859    if (!filter) {
01860       return NULL;
01861    }
01862 
01863    for (token = strtok_r(strfilter, ",", &saveptr); token;
01864          token = strtok_r(NULL, ",", &saveptr)) {
01865       node_added = data_filter_add_nodes(filter->children, token);
01866    }
01867 
01868    if (!node_added) {
01869       ao2_ref(filter, -1);
01870       return NULL;
01871    }
01872 
01873    return filter;
01874 }

static int data_filter_hash ( const void *  obj,
const int  flags 
) [static]

Definition at line 1610 of file data.c.

References ast_str_hash(), and data_filter::name.

Referenced by data_filter_alloc().

01611 {
01612    const struct data_filter *node = obj;
01613    return ast_str_hash(node->name);
01614 }

static void data_filter_release ( struct data_filter filter  )  [static]

Definition at line 1686 of file data.c.

References ao2_ref.

Referenced by data_result_generate().

01687 {
01688    ao2_ref(filter, -1);
01689 }

static struct data_provider* data_provider_add_child ( struct ao2_container parent,
const char *  name,
const struct ast_data_handler handler,
const char *  registrar 
) [static, read]

Definition at line 345 of file data.c.

References ao2_link, data_provider_new(), and NULL.

Referenced by data_provider_create().

00347 {
00348    struct data_provider *child;
00349 
00350    child = data_provider_new(name, handler, registrar);
00351    if (!child) {
00352       return NULL;
00353    }
00354 
00355    ao2_link(parent, child);
00356 
00357    return child;
00358 }

static int data_provider_cmp ( void *  obj1,
void *  obj2,
int  flags 
) [static]

Definition at line 201 of file data.c.

References CMP_MATCH, and data_provider::name.

Referenced by ast_data_init(), and data_provider_new().

00202 {
00203    struct data_provider *node1 = obj1, *node2 = obj2;
00204    return strcasecmp(node1->name, node2->name) ? 0 : CMP_MATCH;
00205 }

static struct data_provider* data_provider_create ( struct ao2_container parent,
const char *  path,
const char *  registrar 
) [static, read]

Definition at line 488 of file data.c.

References ao2_ref, ast_strdupa, data_provider::children, data_provider_add_child(), data_provider_find(), next_node_name(), and NULL.

Referenced by __ast_data_register().

00490 {
00491    char *rpath, *node_name;
00492    struct data_provider *child, *ret = NULL;
00493 
00494    rpath = ast_strdupa(path);
00495 
00496    node_name = next_node_name(&rpath);
00497    if (!node_name) {
00498       /* no more nodes to create. */
00499       return NULL;
00500    }
00501 
00502    child = data_provider_find(parent, node_name, NULL);
00503 
00504    if (!child) {
00505       /* nodes without handler are non-terminal nodes. */
00506       child = data_provider_add_child(parent, node_name, NULL, registrar);
00507    }
00508 
00509    if (rpath) {
00510       ret = data_provider_create(child->children, rpath, registrar);
00511       if (ret) {
00512          ao2_ref(child, -1);
00513       }
00514    }
00515 
00516    return ret ? ret : child;
00517 }

static void data_provider_destructor ( void *  obj  )  [static]

Definition at line 292 of file data.c.

References ao2_ref, and data_provider::children.

Referenced by data_provider_new().

00293 {
00294    struct data_provider *provider = obj;
00295 
00296    ao2_ref(provider->children, -1);
00297 }

static struct data_provider* data_provider_find ( struct ao2_container parent,
const char *  name,
const char *  registrar 
) [static, read]

Definition at line 370 of file data.c.

References ao2_find, ao2_ref, ast_debug, data_provider_new(), NULL, OBJ_POINTER, and data_provider::registrar.

Referenced by data_provider_create(), data_provider_release(), and data_result_generate().

00372 {
00373    struct data_provider *find_node, *found;
00374 
00375    /* XXX avoid allocating a new data node for searching... */
00376    find_node = data_provider_new(name, NULL, NULL);
00377    if (!find_node) {
00378       return NULL;
00379    }
00380 
00381    found = ao2_find(parent, find_node, OBJ_POINTER);
00382 
00383    /* free the created node used for searching. */
00384    ao2_ref(find_node, -1);
00385 
00386    if (found && found->registrar && registrar) {
00387       if (strcmp(found->registrar, registrar)) {
00388          /* if the name doesn't match, do not return this node. */
00389          ast_debug(1, "Registrar doesn't match, node was registered"
00390             " by '%s' and we are searching for '%s'\n",
00391             found->registrar, registrar);
00392          ao2_ref(found, -1);
00393          return NULL;
00394       }
00395    }
00396 
00397    return found;
00398 }

static int data_provider_hash ( const void *  obj,
const int  flags 
) [static]

Definition at line 190 of file data.c.

References ast_str_case_hash(), and data_provider::name.

Referenced by ast_data_init(), and data_provider_new().

00191 {
00192    const struct data_provider *node = obj;
00193    return ast_str_case_hash(node->name);
00194 }

static struct data_provider* data_provider_new ( const char *  name,
const struct ast_data_handler handler,
const char *  registrar 
) [static, read]

Definition at line 308 of file data.c.

References ao2_alloc, ao2_container_alloc, ao2_ref, data_provider::children, data_provider_cmp(), data_provider_destructor(), data_provider_hash(), data_provider::handler, data_provider::name, NULL, NUM_DATA_NODE_BUCKETS, and data_provider::registrar.

Referenced by data_provider_add_child(), and data_provider_find().

00310 {
00311    struct data_provider *node;
00312    size_t namelen;
00313 
00314    namelen = strlen(name) + 1;
00315 
00316    node = ao2_alloc(sizeof(*node) + namelen, data_provider_destructor);
00317    if (!node) {
00318       return NULL;
00319    }
00320 
00321    node->handler = handler;
00322    node->registrar = registrar;
00323    strcpy(node->name, name);
00324 
00325    /* initialize the childrens container. */
00326    if (!(node->children = ao2_container_alloc(NUM_DATA_NODE_BUCKETS,
00327          data_provider_hash, data_provider_cmp))) {
00328       ao2_ref(node, -1);
00329       return NULL;
00330    }
00331 
00332    return node;
00333 }

static void data_provider_print_cli ( int  fd,
const char *  name,
struct ao2_container container,
struct ast_str path 
) [static]

Definition at line 2909 of file data.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli(), ast_free, ast_str_buffer(), ast_str_create(), ast_str_reset(), ast_str_set(), data_provider::children, ast_data_handler::get, data_provider::handler, data_provider::name, and data_provider::registrar.

Referenced by handle_cli_data_show_providers().

02911 {
02912    struct ao2_iterator i;
02913    struct ast_str *current_path;
02914    struct data_provider *provider;
02915 
02916    current_path = ast_str_create(60);
02917    if (!current_path) {
02918       return;
02919    }
02920 
02921    ast_str_reset(current_path);
02922    if (path) {
02923       ast_str_set(&current_path, 0, "%s/%s", ast_str_buffer(path), name);
02924    } else {
02925       ast_str_set(&current_path, 0, "%s", name);
02926    }
02927 
02928    i = ao2_iterator_init(container, 0);
02929    while ((provider = ao2_iterator_next(&i))) {
02930       if (provider->handler) {
02931          /* terminal node, print it. */
02932          ast_cli(fd, "%s/%s (", ast_str_buffer(current_path),
02933             provider->name);
02934          if (provider->handler->get) {
02935             ast_cli(fd, "get");
02936          }
02937          ast_cli(fd, ") [%s]\n", provider->registrar);
02938       }
02939       data_provider_print_cli(fd, provider->name, provider->children,
02940          current_path);
02941       ao2_ref(provider, -1);
02942    }
02943    ao2_iterator_destroy(&i);
02944 
02945    ast_free(current_path);
02946 }

static int data_provider_release ( struct ao2_container parent,
const char *  path,
const char *  registrar 
) [static]

Definition at line 410 of file data.c.

References ao2_container_count(), ao2_ref, ao2_unlink, ast_strdupa, data_provider::children, data_provider_find(), data_provider::handler, and next_node_name().

Referenced by __ast_data_unregister().

00412 {
00413    char *node_name, *rpath;
00414    struct data_provider *child;
00415    int ret = 0;
00416 
00417    rpath = ast_strdupa(path);
00418 
00419    node_name = next_node_name(&rpath);
00420    if (!node_name) {
00421       return -1;
00422    }
00423 
00424    child = data_provider_find(parent, node_name, registrar);
00425    if (!child) {
00426       return -1;
00427    }
00428 
00429    /* if this is not a terminal node. */
00430    if (!child->handler && rpath) {
00431       ret = data_provider_release(child->children, rpath, registrar);
00432    }
00433 
00434    /* if this node is empty, unlink it. */
00435    if (!ret && !ao2_container_count(child->children)) {
00436       ao2_unlink(parent, child);
00437    }
00438 
00439    ao2_ref(child, -1);
00440 
00441    return ret;
00442 }

static void data_provider_release_all ( struct ao2_container parent,
const char *  registrar 
) [static]

Definition at line 451 of file data.c.

References ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ao2_unlink, data_provider::children, data_provider::handler, and data_provider::registrar.

Referenced by __ast_data_unregister().

00453 {
00454    struct ao2_iterator i;
00455    struct data_provider *node;
00456 
00457    i = ao2_iterator_init(parent, 0);
00458    while ((node = ao2_iterator_next(&i))) {
00459       if (!node->handler) {
00460          /* this is a non-terminal node, go inside it. */
00461          data_provider_release_all(node->children, registrar);
00462          if (!ao2_container_count(node->children)) {
00463             /* if this node was left empty, unlink it. */
00464             ao2_unlink(parent, node);
00465          }
00466       } else {
00467          if (!strcmp(node->registrar, registrar)) {
00468             /* if the registrars match, release it! */
00469             ao2_unlink(parent, node);
00470          }
00471       }
00472       ao2_ref(node, -1);
00473    }
00474    ao2_iterator_destroy(&i);
00475 
00476 }

static void data_result_add_child ( struct ast_data root,
struct ast_data child 
) [static]

Definition at line 1601 of file data.c.

References ao2_link, and ast_data::children.

Referenced by __ast_data_add(), and data_result_generate_node().

01602 {
01603    ao2_link(root->children, child);
01604 }

static int data_result_cmp ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 221 of file data.c.

References CMP_MATCH, and ast_data::name.

Referenced by data_result_create().

00222 {
00223    struct ast_data *node1 = obj, *node2 = arg;
00224    return strcasecmp(node1->name, node2->name) ? 0 : CMP_MATCH;
00225 }

static struct ast_data* data_result_create ( const char *  name  )  [static, read]

Definition at line 1406 of file data.c.

References ao2_alloc, ao2_container_alloc, ao2_ref, AST_DATA_CONTAINER, ast_strlen_zero, ast_data::children, data_result_cmp(), data_result_destructor(), data_result_hash(), ast_data::name, NULL, NUM_DATA_RESULT_BUCKETS, and ast_data::type.

Referenced by __ast_data_add(), data_result_find_child(), and data_result_generate_node().

01407 {
01408    struct ast_data *res;
01409    size_t namelen;
01410 
01411    namelen = ast_strlen_zero(name) ? 1 : strlen(name) + 1;
01412 
01413    res = ao2_alloc(sizeof(*res) + namelen, data_result_destructor);
01414    if (!res) {
01415       return NULL;
01416    }
01417 
01418    strcpy(res->name, namelen ? name : "");
01419 
01420    /* initialize the children container */
01421    res->children = ao2_container_alloc(NUM_DATA_RESULT_BUCKETS, data_result_hash,
01422       data_result_cmp);
01423    if (!res->children) {
01424       ao2_ref(res, -1);
01425       return NULL;
01426    }
01427 
01428    /* set this node as a container. */
01429    res->type = AST_DATA_CONTAINER;
01430 
01431    return res;
01432 }

static void data_result_destructor ( void *  obj  )  [static]

Definition at line 1380 of file data.c.

References 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_SECONDS, AST_DATA_STRING, AST_DATA_TIMESTAMP, AST_DATA_UNSIGNED_INTEGER, ast_free, ast_data::children, ast_data::payload, ast_data::str, and ast_data::type.

Referenced by data_result_create().

01381 {
01382    struct ast_data *root = obj;
01383 
01384    switch (root->type) {
01385    case AST_DATA_PASSWORD:
01386    case AST_DATA_STRING:
01387       ast_free(root->payload.str);
01388       ao2_ref(root->children, -1);
01389       break;
01390    case AST_DATA_POINTER:
01391    case AST_DATA_CHARACTER:
01392    case AST_DATA_CONTAINER:
01393    case AST_DATA_INTEGER:
01394    case AST_DATA_TIMESTAMP:
01395    case AST_DATA_SECONDS:
01396    case AST_DATA_MILLISECONDS:
01397    case AST_DATA_UNSIGNED_INTEGER:
01398    case AST_DATA_DOUBLE:
01399    case AST_DATA_BOOLEAN:
01400    case AST_DATA_IPADDR:
01401       ao2_ref(root->children, -1);
01402       break;
01403    }
01404 }

static struct ast_data* data_result_find_child ( struct ast_data root,
const char *  name 
) [static, read]

Definition at line 1442 of file data.c.

References ao2_find, ao2_ref, ast_data::children, data_result_create(), NULL, and OBJ_POINTER.

Referenced by ast_data_search_match(), and data_result_get_node().

01443 {
01444    struct ast_data *found, *find_node;
01445 
01446    find_node = data_result_create(name);
01447    if (!find_node) {
01448       return NULL;
01449    }
01450 
01451    found = ao2_find(root->children, find_node, OBJ_POINTER);
01452 
01453    /* release the temporary created node used for searching. */
01454    ao2_ref(find_node, -1);
01455 
01456    return found;
01457 }

static struct ast_data* data_result_generate ( const struct ast_data_query query,
const char *  search_path 
) [static, read]

Definition at line 1974 of file data.c.

References ao2_ref, ast_log, ast_strdupa, data_filter::children, ast_data_search::children, data_provider::children, data_filter_find(), data_filter_generate(), data_filter_release(), data_provider_find(), data_result_generate_node(), data_search_find(), data_search_generate(), data_search_release(), ast_data_query::filter, filter(), LOG_ERROR, data_provider::name, next_node_name(), NULL, result, root_data, and ast_data_query::search.

Referenced by ast_data_get().

01976 {
01977    char *node_name, *tmp_path;
01978    struct data_provider *provider_child, *tmp_provider_child;
01979    struct ast_data *result, *result_filtered;
01980    struct ast_data_search *search = NULL, *search_child = NULL;
01981    struct data_filter *filter = NULL, *filter_child = NULL;
01982 
01983    if (!search_path) {
01984       /* generate all the trees?. */
01985       return NULL;
01986    }
01987 
01988    tmp_path = ast_strdupa(search_path);
01989 
01990    /* start searching the root node name */
01991    node_name = next_node_name(&tmp_path);
01992    if (!node_name) {
01993       return NULL;
01994    }
01995    provider_child = data_provider_find(root_data.container, node_name, NULL);
01996 
01997    /* continue with the rest of the path. */
01998    while (provider_child) {
01999       node_name = next_node_name(&tmp_path);
02000       if (!node_name) {
02001          break;
02002       }
02003 
02004       tmp_provider_child = data_provider_find(provider_child->children,
02005             node_name, NULL);
02006 
02007       /* release the reference from this child */
02008       ao2_ref(provider_child, -1);
02009 
02010       provider_child = tmp_provider_child;
02011    }
02012 
02013    if (!provider_child) {
02014       ast_log(LOG_ERROR, "Invalid path '%s', '%s' not found.\n",
02015             tmp_path, node_name);
02016       return NULL;
02017    }
02018 
02019    /* generate the search tree. */
02020    if (query->search) {
02021       search = data_search_generate(query->search);
02022       if (search) {
02023          search_child = data_search_find(search->children,
02024             provider_child->name);
02025       }
02026    }
02027 
02028    /* generate the filter tree. */
02029    if (query->filter) {
02030       filter = data_filter_generate(query->filter);
02031       if (filter) {
02032          filter_child = data_filter_find(filter->children,
02033             provider_child->name);
02034       }
02035    }
02036 
02037    result = data_result_generate_node(query, provider_child, provider_child->name,
02038          search_child, filter_child);
02039 
02040    /* release the requested provider. */
02041    ao2_ref(provider_child, -1);
02042 
02043    /* release the generated search tree. */
02044    if (search_child) {
02045       ao2_ref(search_child, -1);
02046    }
02047 
02048    if (filter_child) {
02049       ao2_ref(filter_child, -1);
02050    }
02051 
02052    if (search) {
02053       data_search_release(search);
02054    }
02055 
02056    result_filtered = result;
02057 
02058    /* release the generated filter tree. */
02059    if (filter) {
02060       data_filter_release(filter);
02061    }
02062 
02063    return result_filtered;
02064 }

static struct ast_data* data_result_generate_node ( const struct ast_data_query query,
const struct data_provider root_provider,
const char *  parent_node_name,
const struct ast_data_search search,
const struct data_filter filter 
) [static, read]

Definition at line 1885 of file data.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_log, ast_module_ref, ast_module_unref, data_filter::children, ast_data_search::children, data_provider::children, data_filter_find(), data_result_add_child(), data_result_create(), data_search_find(), ast_data::filter, ast_data_handler::get, data_provider::handler, LOG_ERROR, data_provider::module, data_provider::name, and NULL.

Referenced by data_result_generate().

01890 {
01891    struct ast_data *generated, *node;
01892    struct ao2_iterator i;
01893    struct data_provider *provider;
01894    struct ast_data_search *search_child = NULL;
01895    struct data_filter *filter_child;
01896 
01897    node = data_result_create(parent_node_name);
01898    if (!node) {
01899       ast_log(LOG_ERROR, "Unable to allocate '%s' node\n", parent_node_name);
01900       return NULL;
01901    }
01902 
01903    if (root_provider->module) {
01904       ast_module_ref(root_provider->module);
01905    }
01906 
01907    /* if this is a terminal node, just run the callback function. */
01908    if (root_provider->handler && root_provider->handler->get) {
01909       node->filter = filter;
01910       root_provider->handler->get(search, node);
01911       if (root_provider->module) {
01912          ast_module_unref(root_provider->module);
01913       }
01914       return node;
01915    }
01916 
01917    if (root_provider->module) {
01918       ast_module_unref(root_provider->module);
01919    }
01920 
01921    /* if this is not a terminal node, generate every child node. */
01922    i = ao2_iterator_init(root_provider->children, 0);
01923    while ((provider = ao2_iterator_next(&i))) {
01924       filter_child = NULL;
01925       generated = NULL;
01926 
01927       /* get the internal search node. */
01928       if (search) {
01929          search_child = data_search_find(search->children, provider->name);
01930       }
01931       /* get the internal filter node. */
01932       if (filter) {
01933          filter_child = data_filter_find(filter->children, provider->name);
01934       }
01935 
01936       if (!filter || filter_child) {
01937          /* only generate the internal node, if we have something to
01938           * generate based on the filtering string. */
01939          generated = data_result_generate_node(query, provider,
01940             provider->name,
01941             search_child, filter_child);
01942       }
01943 
01944       /* decrement the refcount of the internal search node. */
01945       if (search_child) {
01946          ao2_ref(search_child, -1);
01947       }
01948 
01949       /* decrement the refcount of the internal filter node. */
01950       if (filter_child) {
01951          ao2_ref(filter_child, -1);
01952       }
01953 
01954       if (generated) {
01955          data_result_add_child(node, generated);
01956          ao2_ref(generated, -1);
01957       }
01958 
01959       ao2_ref(provider, -1);
01960    }
01961    ao2_iterator_destroy(&i);
01962 
01963    return node;
01964 }

static int data_result_get_color ( enum ast_data_type  type  )  [static]

Definition at line 2688 of file data.c.

References ARRAY_LEN, COLOR_BLUE, and data_result_color.

Referenced by data_result_print_cli(), and data_result_print_cli_node().

02689 {
02690    int i;
02691    for (i = 0; i < ARRAY_LEN(data_result_color); i++) {
02692       if (data_result_color[i].type == type) {
02693          return data_result_color[i].color;
02694       }
02695    }
02696 
02697    return COLOR_BLUE;
02698 }

static struct ast_data* data_result_get_node ( struct ast_data node,
const char *  path 
) [static, read]

Definition at line 1566 of file data.c.

References ao2_ref, ast_strdupa, data_result_find_child(), next_node_name(), and NULL.

Referenced by ast_data_iterator_init(), ast_data_retrieve(), and ast_data_retrieve_type().

01568 {
01569    char *savepath, *node_name;
01570    struct ast_data *child, *current = node;
01571 
01572    savepath = ast_strdupa(path);
01573    node_name = next_node_name(&savepath);
01574 
01575    while (node_name) {
01576       child = data_result_find_child(current, node_name);
01577       if (current != node) {
01578          ao2_ref(current, -1);
01579       }
01580       if (!child) {
01581          return NULL;
01582       }
01583       current = child;
01584       node_name = next_node_name(&savepath);
01585    }
01586 
01587    /* do not increment the refcount of the returned object. */
01588    if (current != node) {
01589       ao2_ref(current, -1);
01590    }
01591 
01592    return current;
01593 }

static int data_result_hash ( const void *  obj,
const int  flags 
) [static]

Definition at line 211 of file data.c.

References ast_str_hash(), and ast_data::name.

Referenced by data_result_create().

00212 {
00213    const struct ast_data *node = obj;
00214    return ast_str_hash(node->name);
00215 }

static void data_result_manager_output ( struct mansession s,
const char *  name,
struct ao2_container container,
struct ast_str path,
int  id 
) [static]

Definition at line 2990 of file data.c.

References 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_SECONDS, AST_DATA_STRING, AST_DATA_TIMESTAMP, AST_DATA_UNSIGNED_INTEGER, ast_free, ast_inet_ntoa(), ast_str_buffer(), ast_str_create(), ast_str_reset(), ast_str_set(), astman_append(), ast_data::boolean, ast_data::character, ast_data::children, ast_data::dbl, ast_data::ipaddr, ast_data::name, ast_data::payload, ast_data::sint, ast_data::str, ast_data::type, and ast_data::uint.

Referenced by manager_data_get().

02992 {
02993    struct ao2_iterator i;
02994    struct ast_str *current_path;
02995    struct ast_data *node;
02996    int current_id = id;
02997 
02998    current_path = ast_str_create(60);
02999    if (!current_path) {
03000       return;
03001    }
03002 
03003    ast_str_reset(current_path);
03004    if (path) {
03005       ast_str_set(&current_path, 0, "%s.%s", ast_str_buffer(path), name);
03006    } else {
03007       ast_str_set(&current_path, 0, "%s", name);
03008    }
03009 
03010    i = ao2_iterator_init(container, 0);
03011    while ((node = ao2_iterator_next(&i))) {
03012       /* terminal node, print it. */
03013       if (node->type != AST_DATA_CONTAINER) {
03014          astman_append(s, "%d-%s.%s", id, ast_str_buffer(current_path),
03015                node->name);
03016       }
03017       switch (node->type) {
03018       case AST_DATA_CONTAINER:
03019          data_result_manager_output(s, node->name, node->children, current_path, ++current_id);
03020          break;
03021       case AST_DATA_INTEGER:
03022          astman_append(s, ": %d\r\n", node->payload.sint);
03023          break;
03024       case AST_DATA_TIMESTAMP:
03025       case AST_DATA_SECONDS:
03026       case AST_DATA_MILLISECONDS:
03027       case AST_DATA_UNSIGNED_INTEGER:
03028          astman_append(s, ": %u\r\n", node->payload.uint);
03029          break;
03030       case AST_DATA_PASSWORD:
03031          astman_append(s, ": %s\r\n", node->payload.str);
03032          break;
03033       case AST_DATA_STRING:
03034          astman_append(s, ": %s\r\n", node->payload.str);
03035          break;
03036       case AST_DATA_CHARACTER:
03037          astman_append(s, ": %c\r\n", node->payload.character);
03038          break;
03039       case AST_DATA_IPADDR:
03040          astman_append(s, ": %s\r\n", ast_inet_ntoa(node->payload.ipaddr));
03041          break;
03042       case AST_DATA_POINTER:
03043          break;
03044       case AST_DATA_DOUBLE:
03045          astman_append(s, ": %f\r\n", node->payload.dbl);
03046          break;
03047       case AST_DATA_BOOLEAN:
03048          astman_append(s, ": %s\r\n",
03049             (node->payload.boolean ? "True" : "False"));
03050          break;
03051       }
03052 
03053       ao2_ref(node, -1);
03054    }
03055    ao2_iterator_destroy(&i);
03056 
03057    ast_free(current_path);
03058 }

static void data_result_print_cli ( int  fd,
const struct ast_data root 
) [static]

Definition at line 2843 of file data.c.

References __data_result_print_cli(), ast_cli(), COLORIZE, COLORIZE_FMT, data_result_get_color(), ast_data::name, and ast_data::type.

Referenced by handle_cli_data_get().

02844 {
02845    ast_cli(fd, COLORIZE_FMT "\n", COLORIZE(data_result_get_color(root->type), 0, root->name));
02846 
02847    __data_result_print_cli(fd, root, 0);
02848 
02849    ast_cli(fd, "\n");
02850 }

static void data_result_print_cli_node ( int  fd,
const struct ast_data node,
uint32_t  depth 
) [static]

Definition at line 2707 of file data.c.

References __data_result_print_cli(), ast_cli(), 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, ast_free, ast_inet_ntoa(), ast_str_append(), ast_str_buffer(), ast_str_create(), ast_str_reset(), ast_term_color_code(), ast_data::boolean, ast_data::character, data_result_get_color(), ast_data::dbl, ast_data::ipaddr, ast_data::name, ast_data::payload, ast_data::ptr, ast_data::sint, ast_data::str, ast_data::type, and ast_data::uint.

Referenced by __data_result_print_cli().

02708 {
02709    int i;
02710    struct ast_str *tabs, *output;
02711 
02712    tabs = ast_str_create(depth * 10 + 1);
02713    if (!tabs) {
02714       return;
02715    }
02716    ast_str_reset(tabs);
02717    for (i = 0; i < depth; i++) {
02718       ast_str_append(&tabs, 0, "  ");
02719    }
02720 
02721    output = ast_str_create(20);
02722    if (!output) {
02723       ast_free(tabs);
02724       return;
02725    }
02726 
02727    ast_str_reset(output);
02728    ast_term_color_code(&output, data_result_get_color(node->type), 0);
02729 
02730    switch (node->type) {
02731    case AST_DATA_POINTER:
02732       ast_str_append(&output, 0, "%s%s: %p\n", ast_str_buffer(tabs),
02733             node->name, node->payload.ptr);
02734       break;
02735    case AST_DATA_PASSWORD:
02736       ast_str_append(&output, 0, "%s%s: \"%s\"\n",
02737             ast_str_buffer(tabs),
02738             node->name,
02739             node->payload.str);
02740       break;
02741    case AST_DATA_STRING:
02742       ast_str_append(&output, 0, "%s%s: \"%s\"\n",
02743             ast_str_buffer(tabs),
02744             node->name,
02745             node->payload.str);
02746       break;
02747    case AST_DATA_CHARACTER:
02748       ast_str_append(&output, 0, "%s%s: \'%c\'\n",
02749             ast_str_buffer(tabs),
02750             node->name,
02751             node->payload.character);
02752       break;
02753    case AST_DATA_CONTAINER:
02754       ast_str_append(&output, 0, "%s%s\n", ast_str_buffer(tabs),
02755             node->name);
02756       break;
02757    case AST_DATA_TIMESTAMP:
02758       ast_str_append(&output, 0, "%s%s: %u\n", ast_str_buffer(tabs),
02759             node->name,
02760             node->payload.uint);
02761       break;
02762    case AST_DATA_SECONDS:
02763       ast_str_append(&output, 0, "%s%s: %u\n", ast_str_buffer(tabs),
02764             node->name,
02765             node->payload.uint);
02766       break;
02767    case AST_DATA_MILLISECONDS:
02768       ast_str_append(&output, 0, "%s%s: %u\n", ast_str_buffer(tabs),
02769             node->name,
02770             node->payload.uint);
02771       break;
02772    case AST_DATA_INTEGER:
02773       ast_str_append(&output, 0, "%s%s: %d\n", ast_str_buffer(tabs),
02774             node->name,
02775             node->payload.sint);
02776       break;
02777    case AST_DATA_UNSIGNED_INTEGER:
02778       ast_str_append(&output, 0, "%s%s: %u\n", ast_str_buffer(tabs),
02779             node->name,
02780             node->payload.uint);
02781       break;
02782    case AST_DATA_DOUBLE:
02783       ast_str_append(&output, 0, "%s%s: %lf\n", ast_str_buffer(tabs),
02784             node->name,
02785             node->payload.dbl);
02786       break;
02787    case AST_DATA_BOOLEAN:
02788       ast_str_append(&output, 0, "%s%s: %s\n", ast_str_buffer(tabs),
02789             node->name,
02790             ((node->payload.boolean) ? "True" : "False"));
02791       break;
02792    case AST_DATA_IPADDR:
02793       ast_str_append(&output, 0, "%s%s: %s\n", ast_str_buffer(tabs),
02794             node->name,
02795             ast_inet_ntoa(node->payload.ipaddr));
02796       break;
02797    }
02798 
02799    ast_free(tabs);
02800 
02801    ast_term_color_code(&output, 0, 0);
02802 
02803    ast_cli(fd, "%s", ast_str_buffer(output));
02804 
02805    ast_free(output);
02806 
02807    if (node->type == AST_DATA_CONTAINER) {
02808       __data_result_print_cli(fd, node, depth + 1);
02809    }
02810 }

static struct ast_data_search* data_search_add_child ( struct ao2_container parent,
const char *  name 
) [static, read]

Definition at line 749 of file data.c.

References ao2_link, data_search_alloc(), and NULL.

Referenced by data_search_create().

00751 {
00752    struct ast_data_search *child;
00753 
00754    child = data_search_alloc(name);
00755    if (!child) {
00756       return NULL;
00757    }
00758 
00759    ao2_link(parent, child);
00760 
00761    return child;
00762 }

static struct ast_data_search* data_search_alloc ( const char *  name  )  [static, read]

Definition at line 691 of file data.c.

References ao2_alloc, ao2_container_alloc, ao2_ref, ast_data_search::children, data_search_cmp(), data_search_destructor(), data_search_hash(), ast_data_search::name, NULL, and NUM_DATA_SEARCH_BUCKETS.

Referenced by data_search_add_child(), data_search_find(), and data_search_generate().

00692 {
00693    struct ast_data_search *res;
00694    size_t name_len = strlen(name) + 1;
00695 
00696    res = ao2_alloc(sizeof(*res) + name_len, data_search_destructor);
00697    if (!res) {
00698       return NULL;
00699    }
00700 
00701    res->children = ao2_container_alloc(NUM_DATA_SEARCH_BUCKETS, data_search_hash,
00702       data_search_cmp);
00703 
00704    if (!res->children) {
00705       ao2_ref(res, -1);
00706       return NULL;
00707    }
00708 
00709    strcpy(res->name, name);
00710 
00711    return res;
00712 }

static int data_search_cmp ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 664 of file data.c.

References CMP_MATCH, and ast_data_search::name.

Referenced by data_search_alloc().

00665 {
00666    struct ast_data_search *node1 = obj, *node2 = arg;
00667    return strcasecmp(node1->name, node2->name) ? 0 : CMP_MATCH;
00668 }

static int data_search_cmp_bool ( const struct ast_data_search root,
const char *  name,
unsigned int  value 
) [static]

Definition at line 1103 of file data.c.

References abs, ao2_ref, ast_true(), ast_data_search::cmp_type, data_search_comparison_result(), data_search_get_node(), and ast_data_search::value.

Referenced by __ast_data_search_cmp_structure(), and ast_data_search_match().

01105 {
01106    struct ast_data_search *child;
01107    unsigned int node_value;
01108    enum data_search_comparison cmp_type;
01109 
01110    child = data_search_get_node(root, name);
01111    if (!child) {
01112       return 0;
01113    }
01114 
01115    node_value = abs(ast_true(child->value));
01116    cmp_type = child->cmp_type;
01117 
01118    ao2_ref(child, -1);
01119 
01120    return data_search_comparison_result(value - node_value, cmp_type);
01121 }

static int data_search_cmp_char ( const struct ast_data_search root,
const char *  name,
char  value 
) [static]

Definition at line 1231 of file data.c.

References ao2_ref, ast_data_search::cmp_type, data_search_comparison_result(), data_search_get_node(), and ast_data_search::value.

Referenced by __ast_data_search_cmp_structure(), and ast_data_search_match().

01233 {
01234    struct ast_data_search *child;
01235    char node_value;
01236    enum data_search_comparison cmp_type;
01237 
01238    child = data_search_get_node(root, name);
01239    if (!child) {
01240       return 0;
01241    }
01242 
01243    node_value = *(child->value);
01244    cmp_type = child->cmp_type;
01245 
01246    ao2_ref(child, -1);
01247 
01248    return data_search_comparison_result(value - node_value, cmp_type);
01249 }

static int data_search_cmp_dbl ( const struct ast_data_search root,
const char *  name,
double  value 
) [static]

Definition at line 1135 of file data.c.

References ao2_ref, ast_data_search::cmp_type, data_search_comparison_result(), data_search_get_node(), NULL, and ast_data_search::value.

Referenced by __ast_data_search_cmp_structure().

01137 {
01138    struct ast_data_search *child;
01139    double node_value;
01140    enum data_search_comparison cmp_type;
01141 
01142    child = data_search_get_node(root, name);
01143    if (!child) {
01144       return 0;
01145    }
01146 
01147    node_value = strtod(child->value, NULL);
01148    cmp_type = child->cmp_type;
01149 
01150    ao2_ref(child, -1);
01151 
01152    return data_search_comparison_result(value - node_value, cmp_type);
01153 }

static int data_search_cmp_int ( const struct ast_data_search root,
const char *  name,
int  value 
) [static]

Definition at line 1199 of file data.c.

References ao2_ref, ast_data_search::cmp_type, data_search_comparison_result(), data_search_get_node(), and ast_data_search::value.

Referenced by __ast_data_search_cmp_structure(), and ast_data_search_match().

01201 {
01202    struct ast_data_search *child;
01203    int node_value;
01204    enum data_search_comparison cmp_type;
01205 
01206    child = data_search_get_node(root, name);
01207    if (!child) {
01208       return 0;
01209    }
01210 
01211    node_value = atoi(child->value);
01212    cmp_type = child->cmp_type;
01213 
01214    ao2_ref(child, -1);
01215 
01216    return data_search_comparison_result(value - node_value, cmp_type);
01217 }

static int data_search_cmp_ipaddr ( const struct ast_data_search root,
const char *  name,
struct in_addr  addr 
) [static]

Definition at line 1071 of file data.c.

References ao2_ref, ast_data_search::cmp_type, data_search_comparison_result(), data_search_get_node(), and inet_aton().

Referenced by __ast_data_search_cmp_structure(), and ast_data_search_match().

01073 {
01074    struct ast_data_search *child;
01075    enum data_search_comparison cmp_type;
01076    struct in_addr node_addr;
01077 
01078    child = data_search_get_node(root, name);
01079    if (!child) {
01080       return 0;
01081    }
01082    cmp_type = child->cmp_type;
01083 
01084    inet_aton(child->value, &node_addr);
01085 
01086    ao2_ref(child, -1);
01087 
01088    return data_search_comparison_result((node_addr.s_addr - addr.s_addr), cmp_type);
01089 }

static int data_search_cmp_ptr ( const struct ast_data_search root,
const char *  name,
void *  ptr 
) [static]

Definition at line 1035 of file data.c.

References ao2_ref, ast_data_search::cmp_type, data_search_comparison_result(), data_search_get_node(), and ast_data_search::value.

Referenced by __ast_data_search_cmp_structure(), and ast_data_search_match().

01037 {
01038    struct ast_data_search *child;
01039    enum data_search_comparison cmp_type;
01040    void *node_ptr;
01041 
01042    child = data_search_get_node(root, name);
01043    if (!child) {
01044       return 0;
01045    }
01046 
01047    cmp_type = child->cmp_type;
01048 
01049    if (sscanf(child->value, "%p", &node_ptr) <= 0) {
01050       ao2_ref(child, -1);
01051       return 1;
01052    }
01053 
01054    ao2_ref(child, -1);
01055 
01056    return data_search_comparison_result((node_ptr - ptr), cmp_type);
01057 }

static int data_search_cmp_string ( const struct ast_data_search root,
const char *  name,
char *  value 
) [static]

Definition at line 1003 of file data.c.

References ao2_ref, ast_data_search::cmp_type, data_search_comparison_result(), data_search_get_node(), and ast_data_search::value.

Referenced by __ast_data_search_cmp_structure(), and ast_data_search_match().

01005 {
01006    struct ast_data_search *child;
01007    enum data_search_comparison cmp_type;
01008    int ret;
01009 
01010    child = data_search_get_node(root, name);
01011    if (!child) {
01012       return 0;
01013    }
01014 
01015    ret = strcmp(value, child->value);
01016    cmp_type = child->cmp_type;
01017 
01018    ao2_ref(child, -1);
01019 
01020    return data_search_comparison_result(ret, cmp_type);
01021 }

static int data_search_cmp_uint ( const struct ast_data_search root,
const char *  name,
unsigned int  value 
) [static]

Definition at line 1167 of file data.c.

References ao2_ref, ast_data_search::cmp_type, data_search_comparison_result(), data_search_get_node(), and ast_data_search::value.

Referenced by __ast_data_search_cmp_structure(), and ast_data_search_match().

01169 {
01170    struct ast_data_search *child;
01171    unsigned int node_value;
01172    enum data_search_comparison cmp_type;
01173 
01174    child = data_search_get_node(root, name);
01175    if (!child) {
01176       return 0;
01177    }
01178 
01179    node_value = atoi(child->value);
01180    cmp_type = child->cmp_type;
01181 
01182    ao2_ref(child, -1);
01183 
01184    return data_search_comparison_result(value - node_value, cmp_type);
01185 }

static int data_search_comparison_char ( char  a  )  [static]

Definition at line 614 of file data.c.

Referenced by data_search_generate().

00615 {
00616    switch (a) {
00617    case '!':
00618    case '=':
00619    case '<':
00620    case '>':
00621       return 1;
00622    }
00623 
00624    return 0;
00625 }

static int data_search_comparison_result ( int  cmpval,
enum data_search_comparison  comparison_type 
) [inline, static]

Definition at line 915 of file data.c.

References DATA_CMP_EQ, DATA_CMP_GE, DATA_CMP_GT, DATA_CMP_LE, DATA_CMP_LT, DATA_CMP_NEQ, and DATA_CMP_UNKNOWN.

Referenced by 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(), and data_search_cmp_uint().

00917 {
00918    switch (comparison_type) {
00919    case DATA_CMP_GE:
00920       if (cmpval >= 0) {
00921          return 0;
00922       }
00923       break;
00924    case DATA_CMP_LE:
00925       if (cmpval <= 0) {
00926          return 0;
00927       }
00928       break;
00929    case DATA_CMP_EQ:
00930       if (cmpval == 0) {
00931          return 0;
00932       }
00933       break;
00934    case DATA_CMP_NEQ:
00935       if (cmpval != 0) {
00936          return 0;
00937       }
00938       break;
00939    case DATA_CMP_LT:
00940       if (cmpval < 0) {
00941          return 0;
00942       }
00943       break;
00944    case DATA_CMP_GT:
00945       if (cmpval > 0) {
00946          return 0;
00947       }
00948       break;
00949    case DATA_CMP_UNKNOWN:
00950       break;
00951    }
00952    return 1;
00953 }

static enum data_search_comparison data_search_comparison_type ( const char *  comparison  )  [static]

Definition at line 631 of file data.c.

References DATA_CMP_EQ, DATA_CMP_GE, DATA_CMP_GT, DATA_CMP_LE, DATA_CMP_LT, DATA_CMP_NEQ, and DATA_CMP_UNKNOWN.

Referenced by data_search_generate().

00632 {
00633    if (!strcmp(comparison, "=")) {
00634       return DATA_CMP_EQ;
00635    } else if (!strcmp(comparison, "!=")) {
00636       return DATA_CMP_NEQ;
00637    } else if (!strcmp(comparison, "<")) {
00638       return DATA_CMP_LT;
00639    } else if (!strcmp(comparison, ">")) {
00640       return DATA_CMP_GT;
00641    } else if (!strcmp(comparison, "<=")) {
00642       return DATA_CMP_LE;
00643    } else if (!strcmp(comparison, ">=")) {
00644       return DATA_CMP_GE;
00645    }
00646 
00647    return DATA_CMP_UNKNOWN;
00648 }

static struct ast_data_search* data_search_create ( struct ao2_container parent,
const char *  path 
) [static, read]

Definition at line 772 of file data.c.

References ao2_ref, ast_strdupa, ast_data_search::children, data_search_add_child(), data_search_find(), next_node_name(), and NULL.

Referenced by data_search_generate().

00774 {
00775    char *rpath, *node_name;
00776    struct ast_data_search *child = NULL;
00777    struct ao2_container *current = parent;
00778 
00779    rpath = ast_strdupa(path);
00780 
00781    node_name = next_node_name(&rpath);
00782    while (node_name) {
00783       child = data_search_find(current, node_name);
00784       if (!child) {
00785          child = data_search_add_child(current, node_name);
00786       }
00787       ao2_ref(child, -1);
00788       current = child->children;
00789       node_name = next_node_name(&rpath);
00790    }
00791 
00792    return child;
00793 }

static void data_search_destructor ( void *  obj  )  [static]

Definition at line 674 of file data.c.

References ao2_ref, ast_free, ast_data_search::children, and ast_data_search::value.

Referenced by data_search_alloc().

00675 {
00676    struct ast_data_search *node = obj;
00677 
00678    if (node->value) {
00679       ast_free(node->value);
00680    }
00681 
00682    ao2_ref(node->children, -1);
00683 }

static struct ast_data_search* data_search_find ( struct ao2_container parent,
const char *  name 
) [static, read]

Definition at line 723 of file data.c.

References ao2_find, ao2_ref, data_search_alloc(), NULL, and OBJ_POINTER.

Referenced by ast_data_search_match(), data_result_generate(), data_result_generate_node(), data_search_create(), and data_search_get_node().

00725 {
00726    struct ast_data_search *find_node, *found;
00727 
00728    find_node = data_search_alloc(name);
00729    if (!find_node) {
00730       return NULL;
00731    }
00732 
00733    found = ao2_find(parent, find_node, OBJ_POINTER);
00734 
00735    /* free the created node used for searching. */
00736    ao2_ref(find_node, -1);
00737 
00738    return found;
00739 }

static struct ast_data_search* data_search_generate ( const char *  search_string  )  [static, read]

Definition at line 802 of file data.c.

References ast_free, ast_log, ast_str_append(), ast_str_buffer(), ast_str_create(), ast_str_reset(), ast_strdup, ast_strdupa, ast_data_search::children, ast_data_search::cmp_type, DATA_CMP_UNKNOWN, data_search_alloc(), data_search_comparison_char(), data_search_comparison_type(), data_search_create(), LOG_ERROR, data_filter::name, NULL, ast_data_search::value, and value.

Referenced by data_result_generate().

00803 {
00804    struct ast_str *name, *value, *comparison;
00805    char *elements, *search_string_dup, *saveptr;
00806    int i;
00807    struct ast_data_search *root, *child;
00808    enum data_search_comparison cmp_type;
00809    size_t search_string_len;
00810 
00811    if (!search_string) {
00812       ast_log(LOG_ERROR, "You must pass a valid search string.\n");
00813       return NULL;
00814    }
00815 
00816    search_string_len = strlen(search_string);
00817 
00818    name = ast_str_create(search_string_len);
00819    if (!name) {
00820       return NULL;
00821    }
00822    value = ast_str_create(search_string_len);
00823    if (!value) {
00824       ast_free(name);
00825       return NULL;
00826    }
00827    comparison = ast_str_create(search_string_len);
00828    if (!comparison) {
00829       ast_free(name);
00830       ast_free(value);
00831       return NULL;
00832    }
00833 
00834    search_string_dup = ast_strdupa(search_string);
00835 
00836    /* Create the root node (just used as a container) */
00837    root = data_search_alloc("/");
00838    if (!root) {
00839       ast_free(name);
00840       ast_free(value);
00841       ast_free(comparison);
00842       return NULL;
00843    }
00844 
00845    for (elements = strtok_r(search_string_dup, ",", &saveptr); elements;
00846       elements = strtok_r(NULL, ",", &saveptr)) {
00847       /* Parse the name */
00848       ast_str_reset(name);
00849       for (i = 0; !data_search_comparison_char(elements[i]) &&
00850          elements[i]; i++) {
00851          ast_str_append(&name, 0, "%c", elements[i]);
00852       }
00853 
00854       /* check if the syntax is ok. */
00855       if (!data_search_comparison_char(elements[i])) {
00856          /* if this is the end of the string, then this is
00857           * an error! */
00858          ast_log(LOG_ERROR, "Invalid search string!\n");
00859          continue;
00860       }
00861 
00862       /* parse the comparison string. */
00863       ast_str_reset(comparison);
00864       for (; data_search_comparison_char(elements[i]) && elements[i]; i++) {
00865          ast_str_append(&comparison, 0, "%c", elements[i]);
00866       }
00867 
00868       /* parse the value string. */
00869       ast_str_reset(value);
00870       for (; elements[i]; i++) {
00871          ast_str_append(&value, 0, "%c", elements[i]);
00872       }
00873 
00874       cmp_type = data_search_comparison_type(ast_str_buffer(comparison));
00875       if (cmp_type == DATA_CMP_UNKNOWN) {
00876          ast_log(LOG_ERROR, "Invalid comparison '%s'\n",
00877             ast_str_buffer(comparison));
00878          continue;
00879       }
00880 
00881       /* add this node to the tree. */
00882       child = data_search_create(root->children, ast_str_buffer(name));
00883       if (child) {
00884          child->cmp_type = cmp_type;
00885          child->value = ast_strdup(ast_str_buffer(value));
00886       }
00887    }
00888 
00889    ast_free(name);
00890    ast_free(value);
00891    ast_free(comparison);
00892 
00893    return root;
00894 }

static struct ast_data_search* data_search_get_node ( const struct ast_data_search node,
const char *  path 
) [static, read]

Definition at line 963 of file data.c.

References ao2_ref, ast_strdupa, ast_data_search::children, data_search_find(), next_node_name(), and NULL.

Referenced by __ast_data_search_cmp_structure(), 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(), and data_search_cmp_uint().

00965 {
00966    char *savepath, *node_name;
00967    struct ast_data_search *child, *current = (struct ast_data_search *) node;
00968 
00969    if (!node) {
00970       return NULL;
00971    }
00972 
00973    savepath = ast_strdupa(path);
00974    node_name = next_node_name(&savepath);
00975 
00976    while (node_name) {
00977       child = data_search_find(current->children, node_name);
00978       if (current != node) {
00979          ao2_ref(current, -1);
00980       }
00981       if (!child) {
00982          return NULL;
00983       };
00984       current = child;
00985       node_name = next_node_name(&savepath);
00986    }
00987 
00988    return current;
00989 }

static int data_search_hash ( const void *  obj,
const int  flags 
) [static]

Definition at line 654 of file data.c.

References ast_str_hash(), and ast_data_search::name.

Referenced by data_search_alloc().

00655 {
00656    const struct ast_data_search *node = obj;
00657    return ast_str_hash(node->name);
00658 }

static int data_search_mapping_find ( const struct ast_data_mapping_structure map,
size_t  mapping_len,
const char *  member_name 
) [inline, static]

Definition at line 1258 of file data.c.

References data_filter::name.

Referenced by __ast_data_search_cmp_structure().

01261 {
01262    int i;
01263 
01264    for (i = 0; i < mapping_len; i++) {
01265       if (!strcmp(map[i].name, member_name)) {
01266          return i;
01267       }
01268    }
01269 
01270    return -1;
01271 }

static void data_search_release ( struct ast_data_search search  )  [static]

Definition at line 901 of file data.c.

References ao2_ref.

Referenced by data_result_generate().

00902 {
00903    ao2_ref(search, -1);
00904 }

static void data_shutdown ( void   )  [static]

Definition at line 3318 of file data.c.

References ao2_t_ref, ARRAY_LEN, ast_cli_unregister_multiple(), ast_manager_unregister(), ast_rwlock_destroy, AST_TEST_UNREGISTER, cli_data, NULL, and root_data.

Referenced by ast_data_init().

03319 {
03320    ast_manager_unregister("DataGet");
03321    ast_cli_unregister_multiple(cli_data, ARRAY_LEN(cli_data));
03322    ao2_t_ref(root_data.container, -1, "Unref root_data.container in data_shutdown");
03323    root_data.container = NULL;
03324    ast_rwlock_destroy(&root_data.lock);
03325    AST_TEST_UNREGISTER(test_data_get);
03326 }

static int data_structure_compatible ( int  structure_version,
uint32_t  latest_compatible,
uint32_t  current 
) [static]

Definition at line 256 of file data.c.

References ast_log, and LOG_ERROR.

Referenced by __ast_data_register(), and ast_data_get().

00258 {
00259    if (structure_version >= latest_compatible && structure_version <= current) {
00260       return 1;
00261    }
00262 
00263    ast_log(LOG_ERROR, "A module is not compatible with the"
00264       "current data api version\n");
00265 
00266    return 0;
00267 }

static char* handle_cli_data_get ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 2856 of file data.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_data_free(), ast_data_get(), AST_DATA_QUERY_VERSION, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, data_result_print_cli(), ast_cli_args::fd, ast_data_query::filter, NULL, ast_data_query::path, ast_data_query::search, ast_cli_entry::usage, and ast_data_query::version.

02858 {
02859    struct ast_data_query query = {
02860       .version = AST_DATA_QUERY_VERSION
02861    };
02862    struct ast_data *tree;
02863 
02864    switch (cmd) {
02865    case CLI_INIT:
02866       e->command = "data get";
02867       e->usage = ""
02868          "Usage: data get <path> [<search> [<filter>]]\n"
02869          "       Get the tree based on a path.\n";
02870       return NULL;
02871    case CLI_GENERATE:
02872       return NULL;
02873    }
02874 
02875    if (a->argc < e->args + 1) {
02876       return CLI_SHOWUSAGE;
02877    }
02878 
02879    query.path = (char *) a->argv[e->args];
02880 
02881    if (a->argc > e->args + 1) {
02882       query.search = (char *) a->argv[e->args + 1];
02883    }
02884 
02885    if (a->argc > e->args + 2) {
02886       query.filter = (char *) a->argv[e->args + 2];
02887    }
02888 
02889    tree = ast_data_get(&query);
02890    if (!tree) {
02891       return CLI_FAILURE;
02892    }
02893 
02894    data_result_print_cli(a->fd, tree);
02895 
02896    ast_data_free(tree);
02897 
02898    return CLI_SUCCESS;
02899 }

static char* handle_cli_data_show_providers ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 2952 of file data.c.

References CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, data_provider_print_cli(), data_read_lock, data_unlock, ast_cli_args::fd, NULL, root_data, and ast_cli_entry::usage.

02954 {
02955    switch (cmd) {
02956    case CLI_INIT:
02957       e->command = "data show providers";
02958       e->usage = ""
02959          "Usage: data show providers\n"
02960          "       Show the list of registered providers\n";
02961       return NULL;
02962    case CLI_GENERATE:
02963       return NULL;
02964    }
02965 
02966    data_read_lock();
02967    data_provider_print_cli(a->fd, "", root_data.container, NULL);
02968    data_unlock();
02969 
02970    return CLI_SUCCESS;
02971 }

static int manager_data_get ( struct mansession s,
const struct message m 
) [static]

Definition at line 3064 of file data.c.

References ast_data_free(), ast_data_get(), AST_DATA_QUERY_VERSION, ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), ast_data::children, data_result_manager_output(), filter(), ast_data::name, NULL, RESULT_SUCCESS, and ast_data_query::version.

Referenced by ast_data_init().

03065 {
03066    const char *path = astman_get_header(m, "Path");
03067    const char *search = astman_get_header(m, "Search");
03068    const char *filter = astman_get_header(m, "Filter");
03069    const char *id = astman_get_header(m, "ActionID");
03070    struct ast_data *res;
03071    struct ast_data_query query = {
03072       .version = AST_DATA_QUERY_VERSION,
03073       .path = (char *) path,
03074       .search = (char *) search,
03075       .filter = (char *) filter,
03076    };
03077 
03078    if (ast_strlen_zero(path)) {
03079       astman_send_error(s, m, "'Path' parameter not specified");
03080       return 0;
03081    }
03082 
03083    res = ast_data_get(&query);
03084    if (!res) {
03085       astman_send_error(s, m, "No data returned");
03086       return 0;
03087    }
03088 
03089    astman_append(s, "Event: DataGet Tree\r\n");
03090    if (!ast_strlen_zero(id)) {
03091       astman_append(s, "ActionID: %s\r\n", id);
03092    }
03093    data_result_manager_output(s, res->name, res->children, NULL, 0);
03094    astman_append(s, "\r\n");
03095 
03096    ast_data_free(res);
03097 
03098    return RESULT_SUCCESS;
03099 }

static char* next_node_name ( char **  path  )  [static]

Definition at line 277 of file data.c.

References ast_strlen_zero, and strsep().

Referenced by data_filter_add_nodes(), data_provider_create(), data_provider_release(), data_result_generate(), data_result_get_node(), data_search_create(), and data_search_get_node().

00278 {
00279    char *res;
00280 
00281    do {
00282       res = strsep(path, "/");
00283    } while (res && ast_strlen_zero(res));
00284 
00285    return res;
00286 }


Variable Documentation

struct ast_cli_entry cli_data[] [static]

Initial value:

Definition at line 2977 of file data.c.

Referenced by ast_data_init(), and data_shutdown().

int color

Definition at line 2665 of file data.c.

const uint32_t current_handler_version = AST_DATA_HANDLER_VERSION [static]

Current handler structure version.

Definition at line 79 of file data.c.

const uint32_t current_query_version = AST_DATA_QUERY_VERSION [static]

Current query structure version.

Definition at line 82 of file data.c.

struct { ... } data_result_color[] [static]

Referenced by data_result_get_color().

const uint32_t latest_handler_compatible_version = 0 [static]

The last compatible version.

Definition at line 73 of file data.c.

const uint32_t latest_query_compatible_version = 0 [static]

The last compatible version.

Definition at line 76 of file data.c.

asterisk data locking mechanism.

Definition at line 180 of file data.c.

struct { ... } root_data

Definition at line 2664 of file data.c.


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