diff options
author | eliel <eliel@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-07-08 14:48:42 +0000 |
---|---|---|
committer | eliel <eliel@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-07-08 14:48:42 +0000 |
commit | 7a61a43adbc1ef91229e7757f6ac88619adff202 (patch) | |
tree | 80476efaba3fcc99c7526182d9ad935264c099eb /include | |
parent | f28601a4b00a7b39fd8d3826b02c98e4b868e476 (diff) |
Implement AstData API data providers as part of the GSOC 2010 project,
midterm evaluation.
Review: https://reviewboard.asterisk.org/r/757/
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@274727 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/cdr.h | 12 | ||||
-rw-r--r-- | include/asterisk/channel.h | 3 | ||||
-rw-r--r-- | include/asterisk/data.h | 243 | ||||
-rw-r--r-- | include/asterisk/indications.h | 10 |
4 files changed, 159 insertions, 109 deletions
diff --git a/include/asterisk/cdr.h b/include/asterisk/cdr.h index 4ca479728..5442fdb0c 100644 --- a/include/asterisk/cdr.h +++ b/include/asterisk/cdr.h @@ -28,6 +28,8 @@ #include <sys/time.h> +#include "asterisk/data.h" + /*! * \brief CDR Flags */ @@ -435,4 +437,14 @@ int ast_cdr_engine_init(void); /*! Submit any remaining CDRs and prepare for shutdown */ void ast_cdr_engine_term(void); +/*! + * \brief + * \param[in] tree Where to insert the cdr. + * \param[in] cdr The cdr structure to insert in 'tree'. + * \param[in] recur Go throw all the cdr levels. + * \retval <0 on error. + * \retval 0 on success. + */ +int ast_cdr_data_add_structure(struct ast_data *tree, struct ast_cdr *cdr, int recur); + #endif /* _ASTERISK_CDR_H */ diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index 1e96aa66c..0ea2cb11a 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -2821,10 +2821,11 @@ int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struc * \brief Insert into an astdata tree, the channel structure. * \param[in] tree The ast data tree. * \param[in] chan The channel structure to add to tree. + * \param[in] add_bridged Add the bridged channel to the structure. * \retval <0 on error. * \retval 0 on success. */ -int ast_channel_data_add_structure(struct ast_data *tree, struct ast_channel *chan); +int ast_channel_data_add_structure(struct ast_data *tree, struct ast_channel *chan, int add_bridged); /*! * \brief Compare to channel structures using the data api. diff --git a/include/asterisk/data.h b/include/asterisk/data.h index c52cee96a..6851bd511 100644 --- a/include/asterisk/data.h +++ b/include/asterisk/data.h @@ -25,6 +25,8 @@ #ifndef ASTERISK_DATA_H #define ASTERISK_DATA_H +#include "asterisk/frame.h" + /*! * \page AstDataRetrieval The Asterisk DATA retrieval API. * @@ -106,10 +108,6 @@ * .b = 20 * }; * - * if (ast_data_search_cmp_structure(search, test_structure, "test_node")) { - * return 0; - * } - * * internal_node = ast_data_add_node(root_node, "test_node"); * if (!internal_node) { * return -1; @@ -117,6 +115,10 @@ * * ast_data_add_structure(test_structure, internal_node, ts); * + * if (!ast_data_search_match(search, internal_node)) { + * ast_data_remove_node(root_node, internal_node); + * } + * * return 0; * } * @@ -189,7 +191,12 @@ enum ast_data_type { AST_DATA_DOUBLE, AST_DATA_BOOLEAN, AST_DATA_STRING, + AST_DATA_CHARACTER, + AST_DATA_PASSWORD, AST_DATA_IPADDR, + AST_DATA_TIMESTAMP, + AST_DATA_SECONDS, + AST_DATA_MILLISECONDS, AST_DATA_POINTER }; @@ -212,8 +219,13 @@ struct ast_data_retrieve { enum ast_data_type type; union { + char AST_DATA_CHARACTER; char *AST_DATA_STRING; + char *AST_DATA_PASSWORD; int AST_DATA_INTEGER; + unsigned int AST_DATA_TIMESTAMP; + unsigned int AST_DATA_SECONDS; + unsigned int AST_DATA_MILLISECONDS; double AST_DATA_DOUBLE; unsigned int AST_DATA_UNSIGNED_INTEGER; unsigned int AST_DATA_BOOLEAN; @@ -268,8 +280,13 @@ struct ast_data_mapping_structure { enum ast_data_type type; /*! \brief member getter. */ union { + char (*AST_DATA_CHARACTER)(void *ptr); char *(*AST_DATA_STRING)(void *ptr); + char *(*AST_DATA_PASSWORD)(void *ptr); int (*AST_DATA_INTEGER)(void *ptr); + int (*AST_DATA_TIMESTAMP)(void *ptr); + int (*AST_DATA_SECONDS)(void *ptr); + int (*AST_DATA_MILLISECONDS)(void *ptr); double (*AST_DATA_DOUBLE)(void *ptr); unsigned int (*AST_DATA_UNSIGNED_INTEGER)(void *ptr); unsigned int (*AST_DATA_BOOLEAN)(void *ptr); @@ -292,10 +309,20 @@ struct ast_data_mapping_structure { .type = __type }, /* based on the data type, specifify the type of return value for the getter function. */ +#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_PASSWORD(__structure, __member) \ + __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_PASSWORD, char *) #define __AST_DATA_MAPPING_FUNCTION_AST_DATA_STRING(__structure, __member) \ __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_STRING, char *) +#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_CHARACTER(__structure, __member) \ + __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_CHARACTER, char) #define __AST_DATA_MAPPING_FUNCTION_AST_DATA_INTEGER(__structure, __member) \ __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_INTEGER, int) +#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_TIMESTAMP(__structure, __member) \ + __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_INTEGER, int) +#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_SECONDS(__structure, __member) \ + __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_INTEGER, int) +#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_MILLISECONDS(__structure, __member) \ + __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_INTEGER, int) #define __AST_DATA_MAPPING_FUNCTION_AST_DATA_UNSIGNED_INTEGER(__structure, __member) \ __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_UNSIGNED_INTEGER, unsigned int) #define __AST_DATA_MAPPING_FUNCTION_AST_DATA_BOOLEAN(__structure, __member) \ @@ -367,100 +394,15 @@ int __ast_data_unregister(const char *path, const char *registrar); #define ast_data_unregister(path) __ast_data_unregister(path, __FILE__) /*! - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current string value. - * .search = "somename=somestring" - * name = "somename" - * value is the current value of something and will be evaluated against "somestring". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] value The value to compare. - * \returns The strcmp return value. - */ -int ast_data_search_cmp_string(const struct ast_data_search *root, const char *name, char *value); - -/*! - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current pointer address value. - * .search = "something=0x32323232" - * name = "something" - * value is the current value of something and will be evaluated against "0x32323232". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] ptr The pointer address to compare. - * \returns The (value - current_value) result. - */ -int ast_data_search_cmp_ptr(const struct ast_data_search *root, const char *name, - void *ptr); - -/*! - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current ipv4 address value. - * .search = "something=192.168.2.2" - * name = "something" - * value is the current value of something and will be evaluated against "192.168.2.2". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] addr The ipv4 address value to compare. - * \returns The (value - current_value) result. - */ -int ast_data_search_cmp_ipaddr(const struct ast_data_search *root, const char *name, - struct in_addr addr); - -/*! - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current double value. - * .search = "something=222" - * name = "something" - * value is the current value of something and will be evaluated against "222". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] value The double value to compare. - * \returns The (value - current_value) result. - */ -int ast_data_search_cmp_dbl(const struct ast_data_search *root, const char *name, - double value); - -/*! - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current boolean value. - * .search = "something=true" - * name = "something" - * value is the current value of something and will be evaluated against "true". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] value The boolean value to compare. - * \returns The (value - current_value) result. - */ -int ast_data_search_cmp_bool(const struct ast_data_search *root, const char *name, - unsigned int value); - -/*! - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current unsigned integer value. - * .search = "something=10" - * name = "something" - * value is the current value of something and will be evaluated against "10". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] value The unsigned value to compare. - * \returns The strcmp return value. + * \brief Check the current generated node to know if it matches the search + * condition. + * \param[in] search The search condition. + * \param[in] data The AstData node generated. + * \return 1 If the "data" node matches the search condition. + * \return 0 If the "data" node does not matches the search condition. + * \see ast_data_remove_node */ -int ast_data_search_cmp_uint(const struct ast_data_search *root, const char *name, - unsigned int value); - -/*! - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current signed integer value. - * .search = "something=10" - * name = "something" - * value is the current value of something and will be evaluated against "10". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] value The value to compare. - * \returns The strcmp return value. - */ -int ast_data_search_cmp_int(const struct ast_data_search *root, const char *name, int value); +int ast_data_search_match(const struct ast_data_search *search, struct ast_data *data); /*! * \brief Based on a search tree, evaluate every member of a structure against it. @@ -480,17 +422,6 @@ int __ast_data_search_cmp_structure(const struct ast_data_search *search, ARRAY_LEN(__data_mapping_structure_##structure_name), structure, structure_name_cmp) /*! - * \brief Check if there is a compare condition inside the search tree with the - * passed 'compare_condition' node names. - * \param[in] search The search tree. - * \param[in] compare_condition The path of the compare condition. - * \retval 0 There is no compare condition. - * \retval 1 There is a compare condition. - */ -int ast_data_search_has_condition(const struct ast_data_search *search, - const char *compare_condition); - -/*! * \brief Retrieve a subtree from the asterisk data API. * \param[in] query The query structure specifying what nodes to retrieve. * \retval NULL on error. @@ -555,6 +486,17 @@ struct ast_data *ast_data_add_int(struct ast_data *root, const char *childname, int value); /*! + * \brief Add a char node type. + * \param[in] root The root of the ast_data to insert into. + * \param[in] childname The name of the child element to be added. + * \param[in] value The value for the new node. + * \retval NULL on error (memory exhaustion only). + * \retval non-NULL a newly allocated node. + */ +struct ast_data *ast_data_add_char(struct ast_data *root, const char *childname, + char value); + +/*! * \brief Add an unsigned integer node type. * \param[in] root The root of the ast_data to insert into. * \param[in] childname The name of the child element to be added. @@ -598,6 +540,50 @@ struct ast_data *ast_data_add_ptr(struct ast_data *root, const char *childname, void *ptr); /*! + * \brief Add a password node type. + * \param[in] root The root of the ast_data to insert into. + * \param[in] childname The name of the child element to be added. + * \param[in] string The value for the new node. + * \retval NULL on error (memory exhaustion only). + * \retval non-NULL a newly allocated node. + */ +struct ast_data *ast_data_add_password(struct ast_data *root, const char *childname, + const char *string); + +/*! + * \brief Add a timestamp node type. + * \param[in] root The root of the ast_data to insert into. + * \param[in] childname The name of the child element to be added. + * \param[in] timestamp The value for the new node. + * \retval NULL on error (memory exhaustion only). + * \retval non-NULL a newly allocated node. + */ +struct ast_data *ast_data_add_timestamp(struct ast_data *root, const char *childname, + unsigned int timestamp); + +/*! + * \brief Add a seconds node type. + * \param[in] root The root of the ast_data to insert into. + * \param[in] childname The name of the child element to be added. + * \param[in] seconds The value for the new node. + * \retval NULL on error (memory exhaustion only). + * \retval non-NULL a newly allocated node. + */ +struct ast_data *ast_data_add_seconds(struct ast_data *root, const char *childname, + unsigned int seconds); + +/*! + * \brief Add a milliseconds node type. + * \param[in] root The root of the ast_data to insert into. + * \param[in] childname The name of the child element to be added. + * \param[in] milliseconds The value for the new node. + * \retval NULL on error (memory exhaustion only). + * \retval non-NULL a newly allocated node. + */ +struct ast_data *ast_data_add_milliseconds(struct ast_data *root, const char *childname, + unsigned int milliseconds); + +/*! * \brief Add a string node type. * \param[in] root The root of the ast_data to insert into. * \param[in] childname The name of the child element to be added. @@ -694,6 +680,21 @@ static inline int ast_data_retrieve_int(struct ast_data *tree, const char *path) } /*! + * \brief Retrieve the character value of a node. + * \param[in] tree The tree from where to get the value. + * \param[in] path The node name or path. + * \returns The value of the node. + */ +static inline char ast_data_retrieve_char(struct ast_data *tree, const char *path) +{ + struct ast_data_retrieve ret; + + ast_data_retrieve(tree, path, &ret); + + return ret.value.AST_DATA_CHARACTER; +} + +/*! * \brief Retrieve the boolean value of a node. * \param[in] tree The tree from where to get the value. * \param[in] path The node name or path. @@ -724,6 +725,21 @@ static inline unsigned int ast_data_retrieve_uint(struct ast_data *tree, const c } /*! + * \brief Retrieve the password value of a node. + * \param[in] tree The tree from where to get the value. + * \param[in] path The node name or path. + * \returns The value of the node. + */ +static inline const char *ast_data_retrieve_password(struct ast_data *tree, const char *path) +{ + struct ast_data_retrieve ret; + + ast_data_retrieve(tree, path, &ret); + + return ret.value.AST_DATA_PASSWORD; +} + +/*! * \brief Retrieve the string value of a node. * \param[in] tree The tree from where to get the value. * \param[in] path The node name or path. @@ -783,6 +799,17 @@ static inline struct in_addr ast_data_retrieve_ipaddr(struct ast_data *tree, con return ret.value.AST_DATA_IPADDR; } +/*! + * \brief Add the list of codecs in the root node based on the capability parameter. + * \param[in] root The astdata root node where to add the codecs node. + * \param[in] node_name The name of the node where we are going to add the list of + * codecs. + * \param[in] capability The codecs allowed. + * \return < 0 on error. + * \return 0 on success. + */ +int ast_data_add_codecs(struct ast_data *root, const char *node_name, format_t capability); + #if defined(__cplusplus) || defined(c_plusplus) } #endif diff --git a/include/asterisk/indications.h b/include/asterisk/indications.h index 41a77210c..f69eb86c6 100644 --- a/include/asterisk/indications.h +++ b/include/asterisk/indications.h @@ -27,6 +27,8 @@ #define _ASTERISK_INDICATIONS_H #include "asterisk/astobj2.h" +#include "asterisk/utils.h" +#include "asterisk/data.h" /*! * \brief Description of a tone @@ -237,4 +239,12 @@ static inline struct ast_tone_zone_sound *ast_tone_zone_sound_ref(struct ast_ton return ts; } +/*! + * \brief Add a tone_zone structure to the data tree specified. + * + * \retval <0 on error. + * \retval 0 on success. + */ +int ast_tone_zone_data_add_structure(struct ast_data *tree, struct ast_tone_zone *zone); + #endif /* _ASTERISK_INDICATIONS_H */ |