Asterisk data retrieval API.

This module implements an abstraction for retrieving and exporting
asterisk data.
Developed by:
	Brett Bryant <brettbryant@gmail.com>
	Eliel C. Sardanons (LU1ALY) <eliels@gmail.com>
For the Google Summer of code 2009 Project.
Documentation can be found in doxygen format and inside the
header include/asterisk/data.h

Review: https://reviewboard.asterisk.org/r/275/



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@258517 65c4cc65-6c06-0410-ace0-fbb531ad65f3
certified/1.8.6
Eliel C. Sardanons 16 years ago
parent 8096f0fecc
commit a753e8878b

@ -783,6 +783,10 @@ IAX Changes
CLI Changes CLI Changes
----------- -----------
* New CLI command, "data get <path> [<search> [<filter>]]" which retrieves the
data tree based on the given <path>.
* New CLI command "data show providers" that will display all the registered
callbacks.
* New CLI command, "config reload <file.conf>" which reloads any module that * New CLI command, "config reload <file.conf>" which reloads any module that
references that particular configuration file. Also added "config list" references that particular configuration file. Also added "config list"
which shows which configuration files are in use. which shows which configuration files are in use.

@ -96,6 +96,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/taskprocessor.h" #include "asterisk/taskprocessor.h"
#include "asterisk/callerid.h" #include "asterisk/callerid.h"
#include "asterisk/cel.h" #include "asterisk/cel.h"
#include "asterisk/data.h"
/* Define, to debug reference counts on queues, without debugging reference counts on queue members */ /* Define, to debug reference counts on queues, without debugging reference counts on queue members */
/* #define REF_DEBUG_ONLY_QUEUES */ /* #define REF_DEBUG_ONLY_QUEUES */
@ -7616,6 +7617,281 @@ static struct ast_cli_entry cli_queue[] = {
AST_CLI_DEFINE(handle_queue_reset, "Reset statistics for a queue"), AST_CLI_DEFINE(handle_queue_reset, "Reset statistics for a queue"),
}; };
/* struct call_queue astdata mapping. */
#define DATA_EXPORT_CALL_QUEUE(MEMBER) \
MEMBER(call_queue, name, AST_DATA_STRING) \
MEMBER(call_queue, moh, AST_DATA_STRING) \
MEMBER(call_queue, announce, AST_DATA_STRING) \
MEMBER(call_queue, context, AST_DATA_STRING) \
MEMBER(call_queue, membermacro, AST_DATA_STRING) \
MEMBER(call_queue, membergosub, AST_DATA_STRING) \
MEMBER(call_queue, defaultrule, AST_DATA_STRING) \
MEMBER(call_queue, sound_next, AST_DATA_STRING) \
MEMBER(call_queue, sound_thereare, AST_DATA_STRING) \
MEMBER(call_queue, sound_calls, AST_DATA_STRING) \
MEMBER(call_queue, queue_quantity1, AST_DATA_STRING) \
MEMBER(call_queue, queue_quantity2, AST_DATA_STRING) \
MEMBER(call_queue, sound_holdtime, AST_DATA_STRING) \
MEMBER(call_queue, sound_minutes, AST_DATA_STRING) \
MEMBER(call_queue, sound_minute, AST_DATA_STRING) \
MEMBER(call_queue, sound_seconds, AST_DATA_STRING) \
MEMBER(call_queue, sound_thanks, AST_DATA_STRING) \
MEMBER(call_queue, sound_callerannounce, AST_DATA_STRING) \
MEMBER(call_queue, sound_reporthold, AST_DATA_STRING) \
MEMBER(call_queue, dead, AST_DATA_BOOLEAN) \
MEMBER(call_queue, eventwhencalled, AST_DATA_BOOLEAN) \
MEMBER(call_queue, ringinuse, AST_DATA_INTEGER) \
MEMBER(call_queue, setinterfacevar, AST_DATA_BOOLEAN) \
MEMBER(call_queue, setqueuevar, AST_DATA_BOOLEAN) \
MEMBER(call_queue, setqueueentryvar, AST_DATA_BOOLEAN) \
MEMBER(call_queue, reportholdtime, AST_DATA_BOOLEAN) \
MEMBER(call_queue, wrapped, AST_DATA_BOOLEAN) \
MEMBER(call_queue, timeoutrestart, AST_DATA_BOOLEAN) \
MEMBER(call_queue, announceholdtime, AST_DATA_INTEGER) \
MEMBER(call_queue, announceposition, AST_DATA_INTEGER) \
MEMBER(call_queue, strategy, AST_DATA_INTEGER) \
MEMBER(call_queue, maskmemberstatus, AST_DATA_BOOLEAN) \
MEMBER(call_queue, realtime, AST_DATA_BOOLEAN) \
MEMBER(call_queue, found, AST_DATA_BOOLEAN) \
MEMBER(call_queue, announcepositionlimit, AST_DATA_INTEGER) \
MEMBER(call_queue, announcefrequency, AST_DATA_INTEGER) \
MEMBER(call_queue, minannouncefrequency, AST_DATA_INTEGER) \
MEMBER(call_queue, periodicannouncefrequency, AST_DATA_INTEGER) \
MEMBER(call_queue, numperiodicannounce, AST_DATA_INTEGER) \
MEMBER(call_queue, randomperiodicannounce, AST_DATA_INTEGER) \
MEMBER(call_queue, roundingseconds, AST_DATA_INTEGER) \
MEMBER(call_queue, holdtime, AST_DATA_INTEGER) \
MEMBER(call_queue, talktime, AST_DATA_INTEGER) \
MEMBER(call_queue, callscompleted, AST_DATA_INTEGER) \
MEMBER(call_queue, callsabandoned, AST_DATA_INTEGER) \
MEMBER(call_queue, servicelevel, AST_DATA_INTEGER) \
MEMBER(call_queue, callscompletedinsl, AST_DATA_INTEGER) \
MEMBER(call_queue, monfmt, AST_DATA_STRING) \
MEMBER(call_queue, montype, AST_DATA_INTEGER) \
MEMBER(call_queue, count, AST_DATA_INTEGER) \
MEMBER(call_queue, maxlen, AST_DATA_INTEGER) \
MEMBER(call_queue, wrapuptime, AST_DATA_INTEGER) \
MEMBER(call_queue, retry, AST_DATA_INTEGER) \
MEMBER(call_queue, timeout, AST_DATA_INTEGER) \
MEMBER(call_queue, weight, AST_DATA_INTEGER) \
MEMBER(call_queue, autopause, AST_DATA_INTEGER) \
MEMBER(call_queue, timeoutpriority, AST_DATA_INTEGER) \
MEMBER(call_queue, rrpos, AST_DATA_INTEGER) \
MEMBER(call_queue, memberdelay, AST_DATA_INTEGER) \
MEMBER(call_queue, autofill, AST_DATA_INTEGER) \
MEMBER(call_queue, members, AST_DATA_CONTAINER) \
MEMBER(call_queue, membercount, AST_DATA_INTEGER)
AST_DATA_STRUCTURE(call_queue, DATA_EXPORT_CALL_QUEUE);
/* struct member astdata mapping. */
#define DATA_EXPORT_MEMBER(MEMBER) \
MEMBER(member, interface, AST_DATA_STRING) \
MEMBER(member, state_interface, AST_DATA_STRING) \
MEMBER(member, membername, AST_DATA_STRING) \
MEMBER(member, penalty, AST_DATA_INTEGER) \
MEMBER(member, calls, AST_DATA_INTEGER) \
MEMBER(member, dynamic, AST_DATA_INTEGER) \
MEMBER(member, realtime, AST_DATA_INTEGER) \
MEMBER(member, status, AST_DATA_INTEGER) \
MEMBER(member, paused, AST_DATA_BOOLEAN) \
MEMBER(member, rt_uniqueid, AST_DATA_STRING)
AST_DATA_STRUCTURE(member, DATA_EXPORT_MEMBER);
#define DATA_EXPORT_QUEUE_ENT(MEMBER) \
MEMBER(queue_ent, moh, AST_DATA_STRING) \
MEMBER(queue_ent, announce, AST_DATA_STRING) \
MEMBER(queue_ent, context, AST_DATA_STRING) \
MEMBER(queue_ent, digits, AST_DATA_STRING) \
MEMBER(queue_ent, valid_digits, AST_DATA_INTEGER) \
MEMBER(queue_ent, pos, AST_DATA_INTEGER) \
MEMBER(queue_ent, prio, AST_DATA_INTEGER) \
MEMBER(queue_ent, last_pos_said, AST_DATA_INTEGER) \
MEMBER(queue_ent, last_periodic_announce_time, AST_DATA_INTEGER) \
MEMBER(queue_ent, last_periodic_announce_sound, AST_DATA_INTEGER) \
MEMBER(queue_ent, last_pos, AST_DATA_INTEGER) \
MEMBER(queue_ent, opos, AST_DATA_INTEGER) \
MEMBER(queue_ent, handled, AST_DATA_INTEGER) \
MEMBER(queue_ent, pending, AST_DATA_INTEGER) \
MEMBER(queue_ent, max_penalty, AST_DATA_INTEGER) \
MEMBER(queue_ent, min_penalty, AST_DATA_INTEGER) \
MEMBER(queue_ent, linpos, AST_DATA_INTEGER) \
MEMBER(queue_ent, linwrapped, AST_DATA_INTEGER) \
MEMBER(queue_ent, start, AST_DATA_INTEGER) \
MEMBER(queue_ent, expire, AST_DATA_INTEGER) \
MEMBER(queue_ent, cancel_answered_elsewhere, AST_DATA_INTEGER)
AST_DATA_STRUCTURE(queue_ent, DATA_EXPORT_QUEUE_ENT);
/*!
* \internal
* \brief Add a queue to the data_root node.
* \param[in] search The search tree.
* \param[in] data_root The main result node.
* \param[in] queue The queue to add.
*/
static void queues_data_provider_get_helper(const struct ast_data_search *search,
struct ast_data *data_root, struct call_queue *queue)
{
int member_notmatch, caller_notmatch, caller_channel_notmatch;
struct ao2_iterator im;
struct member *member;
struct queue_ent *qe;
struct ast_data *data_queue, *data_members = NULL;
struct ast_data *data_member, *data_callers = NULL, *data_caller, *data_caller_channel;
/* compare the search pattern. */
if (ast_data_search_cmp_structure(search, call_queue, queue, "queue")) {
/* this doesn't match! continue! */
return;
}
data_queue = ast_data_add_node(data_root, "queue");
if (!data_queue) {
return;
}
ast_data_add_structure(call_queue, data_queue, queue);
member_notmatch = ast_data_search_has_condition(search, "queue/members/member");
/* add queue members */
im = ao2_iterator_init(queue->members, 0);
while ((member = ao2_iterator_next(&im))) {
/* compare the member structure. */
if (!ast_data_search_cmp_structure(search, member, member,
"queue/members/member")) {
member_notmatch = 0;
}
if (!data_members) {
data_members = ast_data_add_node(data_queue, "members");
if (!data_members) {
ao2_ref(member, -1);
continue;
}
}
data_member = ast_data_add_node(data_members, "member");
if (!data_member) {
ao2_ref(member, -1);
continue;
}
ast_data_add_structure(member, data_member, member);
ao2_ref(member, -1);
}
if (member_notmatch) {
ast_data_remove_node(data_root, data_queue);
return;
}
caller_notmatch = ast_data_search_has_condition(search, "queue/callers/caller");
caller_channel_notmatch = ast_data_search_has_condition(search,
"queue/callers/caller/channel");
/* include the callers inside the result. */
if (queue->head) {
for (qe = queue->head; qe; qe = qe->next) {
/* compare the member structure. */
if (!ast_data_search_cmp_structure(search, queue_ent, qe,
"queue/callers/caller")) {
caller_notmatch = 0;
}
if (!ast_channel_data_cmp_structure(search, qe->chan,
"queue/callers/caller/channel")) {
caller_channel_notmatch = 0;
}
if (!data_callers) {
data_callers = ast_data_add_node(data_queue, "callers");
if (!data_callers) {
continue;
}
}
data_caller = ast_data_add_node(data_callers, "caller");
if (!data_caller) {
continue;
}
ast_data_add_structure(queue_ent, data_caller, qe);
/* add the caller channel. */
data_caller_channel = ast_data_add_node(data_caller, "channel");
if (!data_caller_channel) {
continue;
}
ast_channel_data_add_structure(data_caller_channel, qe->chan);
}
}
/* if this queue doesn't match remove the added queue. */
if (caller_notmatch || caller_channel_notmatch) {
ast_data_remove_node(data_root, data_queue);
}
}
/*!
* \internal
* \brief Callback used to generate the queues tree.
* \param[in] search The search pattern tree.
* \retval NULL on error.
* \retval non-NULL The generated tree.
*/
static int queues_data_provider_get(const struct ast_data_search *search,
struct ast_data *data_root)
{
struct ao2_iterator i;
struct call_queue *queue, *queue_realtime = NULL;
struct ast_config *cfg;
char *queuename;
/* load realtime queues. */
cfg = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL);
if (cfg) {
for (queuename = ast_category_browse(cfg, NULL);
!ast_strlen_zero(queuename);
queuename = ast_category_browse(cfg, queuename)) {
if ((queue = load_realtime_queue(queuename))) {
queue_unref(queue);
}
}
ast_config_destroy(cfg);
}
/* static queues. */
i = ao2_iterator_init(queues, 0);
while ((queue = ao2_iterator_next(&i))) {
ao2_lock(queue);
if (queue->realtime && !(queue_realtime = load_realtime_queue(queue->name))) {
ao2_unlock(queue);
queue_unref(queue);
continue;
} else if (queue->realtime) {
queue_unref(queue_realtime);
}
queues_data_provider_get_helper(search, data_root, queue);
ao2_unlock(queue);
queue_unref(queue);
}
return 0;
}
static const struct ast_data_handler queues_data_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = queues_data_provider_get
};
static const struct ast_data_entry queue_data_providers[] = {
AST_DATA_ENTRY("asterisk/application/app_queue/queues", &queues_data_provider),
};
static int unload_module(void) static int unload_module(void)
{ {
int res; int res;
@ -7646,6 +7922,8 @@ static int unload_module(void)
res |= ast_custom_function_unregister(&queuewaitingcount_function); res |= ast_custom_function_unregister(&queuewaitingcount_function);
res |= ast_custom_function_unregister(&queuememberpenalty_function); res |= ast_custom_function_unregister(&queuememberpenalty_function);
res |= ast_data_unregister(NULL);
if (device_state_sub) if (device_state_sub)
ast_event_unsubscribe(device_state_sub); ast_event_unsubscribe(device_state_sub);
@ -7690,6 +7968,8 @@ static int load_module(void)
if (queue_persistent_members) if (queue_persistent_members)
reload_queue_members(); reload_queue_members();
ast_data_register_multiple(queue_data_providers, ARRAY_LEN(queue_data_providers));
ast_cli_register_multiple(cli_queue, ARRAY_LEN(cli_queue)); ast_cli_register_multiple(cli_queue, ARRAY_LEN(cli_queue));
res = ast_register_application_xml(app, queue_exec); res = ast_register_application_xml(app, queue_exec);
res |= ast_register_application_xml(app_aqm, aqm_exec); res |= ast_register_application_xml(app_aqm, aqm_exec);

@ -10739,6 +10739,206 @@ static struct ast_cli_entry cli_voicemail[] = {
AST_CLI_DEFINE(handle_voicemail_reload, "Reload voicemail configuration"), AST_CLI_DEFINE(handle_voicemail_reload, "Reload voicemail configuration"),
}; };
#ifdef IMAP_STORAGE
#define DATA_EXPORT_VM_USERS(USER) \
USER(ast_vm_user, context, AST_DATA_STRING) \
USER(ast_vm_user, mailbox, AST_DATA_STRING) \
USER(ast_vm_user, password, AST_DATA_STRING) \
USER(ast_vm_user, fullname, AST_DATA_STRING) \
USER(ast_vm_user, email, AST_DATA_STRING) \
USER(ast_vm_user, emailsubject, AST_DATA_STRING) \
USER(ast_vm_user, emailbody, AST_DATA_STRING) \
USER(ast_vm_user, pager, AST_DATA_STRING) \
USER(ast_vm_user, serveremail, AST_DATA_STRING) \
USER(ast_vm_user, mailcmd, AST_DATA_STRING) \
USER(ast_vm_user, language, AST_DATA_STRING) \
USER(ast_vm_user, zonetag, AST_DATA_STRING) \
USER(ast_vm_user, callback, AST_DATA_STRING) \
USER(ast_vm_user, dialout, AST_DATA_STRING) \
USER(ast_vm_user, uniqueid, AST_DATA_STRING) \
USER(ast_vm_user, exit, AST_DATA_STRING) \
USER(ast_vm_user, attachfmt, AST_DATA_STRING) \
USER(ast_vm_user, flags, AST_DATA_UNSIGNED_INTEGER) \
USER(ast_vm_user, saydurationm, AST_DATA_INTEGER) \
USER(ast_vm_user, maxmsg, AST_DATA_INTEGER) \
USER(ast_vm_user, maxdeletedmsg, AST_DATA_INTEGER) \
USER(ast_vm_user, maxsecs, AST_DATA_INTEGER) \
USER(ast_vm_user, imapuser, AST_DATA_STRING) \
USER(ast_vm_user, imappassword, AST_DATA_STRING) \
USER(ast_vm_user, imapvmshareid, AST_DATA_STRING) \
USER(ast_vm_user, volgain, AST_DATA_DOUBLE)
#else
#define DATA_EXPORT_VM_USERS(USER) \
USER(ast_vm_user, context, AST_DATA_STRING) \
USER(ast_vm_user, mailbox, AST_DATA_STRING) \
USER(ast_vm_user, password, AST_DATA_STRING) \
USER(ast_vm_user, fullname, AST_DATA_STRING) \
USER(ast_vm_user, email, AST_DATA_STRING) \
USER(ast_vm_user, emailsubject, AST_DATA_STRING) \
USER(ast_vm_user, emailbody, AST_DATA_STRING) \
USER(ast_vm_user, pager, AST_DATA_STRING) \
USER(ast_vm_user, serveremail, AST_DATA_STRING) \
USER(ast_vm_user, mailcmd, AST_DATA_STRING) \
USER(ast_vm_user, language, AST_DATA_STRING) \
USER(ast_vm_user, zonetag, AST_DATA_STRING) \
USER(ast_vm_user, callback, AST_DATA_STRING) \
USER(ast_vm_user, dialout, AST_DATA_STRING) \
USER(ast_vm_user, uniqueid, AST_DATA_STRING) \
USER(ast_vm_user, exit, AST_DATA_STRING) \
USER(ast_vm_user, attachfmt, AST_DATA_STRING) \
USER(ast_vm_user, flags, AST_DATA_UNSIGNED_INTEGER) \
USER(ast_vm_user, saydurationm, AST_DATA_INTEGER) \
USER(ast_vm_user, maxmsg, AST_DATA_INTEGER) \
USER(ast_vm_user, maxdeletedmsg, AST_DATA_INTEGER) \
USER(ast_vm_user, maxsecs, AST_DATA_INTEGER) \
USER(ast_vm_user, volgain, AST_DATA_DOUBLE)
#endif
AST_DATA_STRUCTURE(ast_vm_user, DATA_EXPORT_VM_USERS);
#define DATA_EXPORT_VM_ZONES(ZONE) \
ZONE(vm_zone, name, AST_DATA_STRING) \
ZONE(vm_zone, timezone, AST_DATA_STRING) \
ZONE(vm_zone, msg_format, AST_DATA_STRING)
AST_DATA_STRUCTURE(vm_zone, DATA_EXPORT_VM_ZONES);
#ifdef IMAP_STORAGE
#define DATA_EXPORT_VM_STATES(STATE) \
STATE(vm_state, curbox, AST_DATA_STRING) \
STATE(vm_state, username, AST_DATA_STRING) \
STATE(vm_state, context, AST_DATA_STRING) \
STATE(vm_state, curdir, AST_DATA_STRING) \
STATE(vm_state, vmbox, AST_DATA_STRING) \
STATE(vm_state, fn, AST_DATA_STRING) \
STATE(vm_state, intro, AST_DATA_STRING) \
STATE(vm_state, curmsg, AST_DATA_INTEGER) \
STATE(vm_state, lastmsg, AST_DATA_INTEGER) \
STATE(vm_state, newmessages, AST_DATA_INTEGER) \
STATE(vm_state, oldmessages, AST_DATA_INTEGER) \
STATE(vm_state, urgentmessages, AST_DATA_INTEGER) \
STATE(vm_state, starting, AST_DATA_INTEGER) \
STATE(vm_state, repeats, AST_DATA_INTEGER) \
STATE(vm_state, updated, AST_DATA_INTEGER) \
STATE(vm_state, msgArray, AST_DATA_CONTAINER) \
STATE(vm_state, vmArrayIndex, AST_DATA_INTEGER) \
STATE(vm_state, imapuser, AST_DATA_STRING) \
STATE(vm_state, interactive, AST_DATA_INTEGER) \
STATE(vm_state, introfn, AST_DATA_STRING) \
STATE(vm_state, quota_limit, AST_DATA_UNSIGNED_INTEGER) \
STATE(vm_state, quota_usage, AST_DATA_UNSIGNED_INTEGER)
#else
#define DATA_EXPORT_VM_STATES(STATE) \
STATE(vm_state, curbox, AST_DATA_STRING) \
STATE(vm_state, username, AST_DATA_STRING) \
STATE(vm_state, context, AST_DATA_STRING) \
STATE(vm_state, curdir, AST_DATA_STRING) \
STATE(vm_state, vmbox, AST_DATA_STRING) \
STATE(vm_state, fn, AST_DATA_STRING) \
STATE(vm_state, intro, AST_DATA_STRING) \
STATE(vm_state, curmsg, AST_DATA_INTEGER) \
STATE(vm_state, lastmsg, AST_DATA_INTEGER) \
STATE(vm_state, newmessages, AST_DATA_INTEGER) \
STATE(vm_state, oldmessages, AST_DATA_INTEGER) \
STATE(vm_state, urgentmessages, AST_DATA_INTEGER) \
STATE(vm_state, starting, AST_DATA_INTEGER) \
STATE(vm_state, repeats, AST_DATA_INTEGER)
#endif
AST_DATA_STRUCTURE(vm_state, DATA_EXPORT_VM_STATES);
/*!
* \internal
* \brief Add voicemail user to the data_root.
* \param[in] search The search tree.
* \param[in] data_root The main result node.
* \param[in] user The voicemail user.
*/
static void vm_users_data_provider_get_helper(const struct ast_data_search *search,
struct ast_data *data_root, struct ast_vm_user *user)
{
struct ast_data *data_user, *data_zone;
#ifdef IMAP_STORAGE
struct ast_data *data_state;
struct vm_state *state;
#endif
struct vm_zone *zone = NULL;
/* check the search pattern to make sure it's valid to add it */
if (ast_data_search_cmp_structure(search, ast_vm_user, user, "user")) {
return;
}
data_user = ast_data_add_node(data_root, "user");
if (!data_user) {
return;
}
ast_data_add_structure(ast_vm_user, data_user, user);
#ifdef IMAP_STORAGE
state = get_vm_state_by_mailbox(user->mailbox, user->context, user->interactive);
#endif
AST_LIST_LOCK(&zones);
AST_LIST_TRAVERSE(&zones, zone, list) {
if (!strcmp(zone->name, user->zonetag)) {
break;
}
}
AST_LIST_UNLOCK(&zones);
/* TODO: Should a user's vm state be accessible without compiling in
* IMAP support? */
if (
#ifdef IMAP_STORAGE
!ast_data_search_cmp_structure(search, vm_state, state, "user/state") ||
#endif
(zone && !ast_data_search_cmp_structure(search, vm_zone,
zone, "user/zone"))) {
ast_data_remove_node(data_root, data_user);
return;
}
#ifdef IMAP_STORAGE
data_state = ast_data_add_node(data_user, "state");
ast_data_add_structure(vm_state, data_state, state);
ast_data_add_int(data_state, "deleted", *(state->deleted));
ast_data_add_int(data_state, "heard", *(state->heard));
#endif
if (zone) {
data_zone = ast_data_add_node(data_user, "zone");
ast_data_add_structure(vm_zone, data_zone, zone);
}
return;
}
static int vm_data_provider_get(const struct ast_data_search *search,
struct ast_data *data_root)
{
struct ast_vm_user *user;
AST_LIST_LOCK(&users);
AST_LIST_TRAVERSE(&users, user, list) {
vm_users_data_provider_get_helper(search, data_root, user);
}
AST_LIST_UNLOCK(&users);
return 0;
}
static const struct ast_data_handler vm_data_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = vm_data_provider_get
};
static const struct ast_data_entry vm_data_providers[] = {
AST_DATA_ENTRY("asterisk/application/app_voicemail/voicemail", &vm_data_provider)
};
static void poll_subscribed_mailbox(struct mwi_sub *mwi_sub) static void poll_subscribed_mailbox(struct mwi_sub *mwi_sub)
{ {
int new = 0, old = 0, urgent = 0; int new = 0, old = 0, urgent = 0;
@ -12241,6 +12441,7 @@ static int unload_module(void)
res |= ast_unregister_application(app4); res |= ast_unregister_application(app4);
res |= ast_custom_function_unregister(&mailbox_exists_acf); res |= ast_custom_function_unregister(&mailbox_exists_acf);
res |= ast_manager_unregister("VoicemailUsersList"); res |= ast_manager_unregister("VoicemailUsersList");
res |= ast_data_unregister(NULL);
#ifdef TEST_FRAMEWORK #ifdef TEST_FRAMEWORK
res |= AST_TEST_UNREGISTER(test_voicemail_vmsayname); res |= AST_TEST_UNREGISTER(test_voicemail_vmsayname);
res |= AST_TEST_UNREGISTER(test_voicemail_msgcount); res |= AST_TEST_UNREGISTER(test_voicemail_msgcount);
@ -12301,6 +12502,7 @@ static int load_module(void)
return res; return res;
ast_cli_register_multiple(cli_voicemail, ARRAY_LEN(cli_voicemail)); ast_cli_register_multiple(cli_voicemail, ARRAY_LEN(cli_voicemail));
ast_data_register_multiple(vm_data_providers, ARRAY_LEN(vm_data_providers));
ast_install_vm_functions(has_voicemail, inboxcount, inboxcount2, messagecount, sayname); ast_install_vm_functions(has_voicemail, inboxcount, inboxcount2, messagecount, sayname);
ast_realtime_require_field("voicemail", "uniqueid", RQ_UINTEGER3, 11, "password", RQ_CHAR, 10, SENTINEL); ast_realtime_require_field("voicemail", "uniqueid", RQ_UINTEGER3, 11, "password", RQ_CHAR, 10, SENTINEL);

@ -137,6 +137,16 @@ Changes to manager version 1.1:
* NEW ACTIONS * NEW ACTIONS
------------- -------------
- Action: DataGet
Modules: data.c
Purpose:
To be able to retrieve the asterisk data tree.
Variables:
ActionID: <id> Action ID for this transaction. Will be returned.
Path: <data path> The path to the callback node to retrieve.
Filter: <filter> Which nodes to retrieve.
Search: <search> Search condition.
- Action: IAXregistry - Action: IAXregistry
Modules: chan_iax2 Modules: chan_iax2
Purpose: Purpose:

@ -35,6 +35,7 @@ int astobj2_init(void); /*!< Provided by astobj2.c */
int ast_file_init(void); /*!< Provided by file.c */ int ast_file_init(void); /*!< Provided by file.c */
int ast_features_init(void); /*!< Provided by features.c */ int ast_features_init(void); /*!< Provided by features.c */
void ast_autoservice_init(void); /*!< Provided by autoservice.c */ void ast_autoservice_init(void); /*!< Provided by autoservice.c */
int ast_data_init(void); /*!< Provided by data.c */
int ast_http_init(void); /*!< Provided by http.c */ int ast_http_init(void); /*!< Provided by http.c */
int ast_http_reload(void); /*!< Provided by http.c */ int ast_http_reload(void); /*!< Provided by http.c */
int ast_tps_init(void); /*!< Provided by taskprocessor.c */ int ast_tps_init(void); /*!< Provided by taskprocessor.c */

@ -148,6 +148,7 @@ extern "C" {
#include "asterisk/linkedlists.h" #include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h" #include "asterisk/stringfields.h"
#include "asterisk/datastore.h" #include "asterisk/datastore.h"
#include "asterisk/data.h"
#include "asterisk/channelstate.h" #include "asterisk/channelstate.h"
#include "asterisk/ccss.h" #include "asterisk/ccss.h"
@ -2758,6 +2759,26 @@ void ast_channel_queue_redirecting_update(struct ast_channel *chan, const struct
*/ */
int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int caller, int frame); int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int caller, int frame);
/*!
* \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.
* \retval <0 on error.
* \retval 0 on success.
*/
int ast_channel_data_add_structure(struct ast_data *tree, struct ast_channel *chan);
/*!
* \brief Compare to channel structures using the data api.
* \param[in] tree The search tree generated by the data api.
* \param[in] chan The channel to compare.
* \param[in] structure_name The name of the node of the channel structure.
* \retval 0 The structure matches.
* \retval 1 The structure doesn't matches.
*/
int ast_channel_data_cmp_structure(const struct ast_data_search *tree, struct ast_channel *chan,
const char *structure_name);
#include "asterisk/ccss.h" #include "asterisk/ccss.h"
/*! /*!

@ -0,0 +1,788 @@
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2009, Eliel C. Sardanons (LU1ALY) <eliels@gmail.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*!
* \file
* \brief Data retrieval API.
* \author Brett Bryant <brettbryant@gmail.com>
* \author Eliel C. Sardanons (LU1ALY) <eliels@gmail.com>
* \arg \ref AstDataRetrieval
*/
#ifndef ASTERISK_DATA_H
#define ASTERISK_DATA_H
/*!
* \page AstDataRetrieval The Asterisk DATA retrieval API.
*
* This module implements an abstraction for retrieving asterisk data and
* export it.
*
* \section USAGE
*
* \subsection Provider
*
* \b Register
*
* To register a callback use:
*
* \code
* static const struct ast_data_handler callback_handler = {
* .get = callback_handler_get_function,
* };
*
* ast_data_register("/node/path", &callback_handler);
* \endcode
*
* If you instead want to register multiple nodes at once use:
* \code
* static const struct ast_data_handler handler_struct1 = {
* .get = handler_callback_read,
* };
* ... other handlers ...
*
* static const struct ast_data_entry list_providers[] = {
* AST_DATA_ENTRY("/path1/node1", &handler_struct1),
* AST_DATA_ENTRY("/path2/node2", &handler_struct2),
* AST_DATA_ENTRY("/path3/node3", &handler_struct3),
* };
*
* ...
*
* ast_data_register_multiple(list_providers, ARRAY_LEN(list_providers));
* \endcode
*
* \b Unregister
*
* To unregister a callback function already registered you can just call:
*
* \code
* ast_data_unregister(NULL);
* \endcode
* And every node registered by the current module (file) will be unregistered.
* If you want to unregister a specific node use:
*
* \code
* ast_data_unregister("/node/path");
* \endcode
*
* \b Implementation
*
* A simple callback function implementation:
*
* \code
* #include <data.h>
*
* struct test_structure {
* int a;
* double b;
* };
*
* DATA_EXPORT_TEST_STRUCTURE(MEMBER) \
* MEMBER(test_structure, a, AST_DATA_INTEGER) \
* MEMBER(test_structure, b, AST_DATA_DOUBLE)
*
* AST_DATA_STRUCTURE(test_structure, DATA_EXPORT_TEST_STRUCTURE)
*
* static int my_callback_function(struct ast_data_search *search,
* struct ast_data *root_node)
* {
* struct ast_data *internal_node;
* struct test_structure ts = {
* .a = 10,
* .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;
* }
*
* ast_data_add_structure(test_structure, internal_node, ts);
*
* return 0;
* }
*
* \endcode
*
* \subsection Get
*
* \b Getting \b the \b tree
*
* To get the tree you need to create a query, a query is based on three parameters
* a \b path to the provider, a \b search condition and a \b filter condition.
* \code
* struct ast_data *result;
* struct ast_data_query query = {
* .path = "/asterisk/application/app_queue/queues",
* .search = "/queues/queue/name=queue1",
* .filter = "/queues/queue/name|wrapuptime|members/member/interface"
* };
*
* result = ast_data_get(&query);
* \endcode
*
* After using it you need to release the allocated memory of the returned tree:
* \code
* ast_data_free(result);
* \endcode
*
* \b Iterate
*
* To retrieve nodes from the tree, it is possible to iterate through the returned
* nodes of the tree using:
* \code
* struct ast_data_iterator *i;
* struct ast_data *internal_node;
*
* i = ast_data_iterator_init(result_tree, "path/node_name");
* while ((internal_node = ast_data_iterator_next(i))) {
* ... do something with node ...
* }
* ast_data_iterator_end(i);
* \endcode
* node_name is the name of the nodes to retrieve and path is the path to the internal
* nodes to retrieve (if needed).
*
* \b Retrieving
*
* After getting the node you where searching for, you will need to retrieve its value,
* to do that you may use one of the ast_data_retrieve_##type functions:
* \code
* int a = ast_data_retrieve_int(tree, "path/to/the/node");
* double b = ast_data_retrieve_dbl(tree, "path/to/the/node");
* unsigned int c = ast_data_retrieve_bool(tree, "path/to/the/node");
* char *d = ast_data_retrieve_string(tree, "path/to/the/node");
* struct sockaddr_in e = ast_data_retrieve_ipaddr(tree, "path/to/the/node");
* unsigned int f = ast_data_retrieve_uint(tree, "path/to/the/node");
* void *g = ast_data_retrieve_ptr(tree, "path/to/the/node");
* \endcode
*
*/
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
/*! \brief The data type of the data node. */
enum ast_data_type {
AST_DATA_CONTAINER,
AST_DATA_INTEGER,
AST_DATA_UNSIGNED_INTEGER,
AST_DATA_DOUBLE,
AST_DATA_BOOLEAN,
AST_DATA_STRING,
AST_DATA_IPADDR,
AST_DATA_POINTER
};
/*! \brief The Data API structures version. */
#define AST_DATA_HANDLER_VERSION 1
#define AST_DATA_QUERY_VERSION 1
/*! \brief opaque definition of an ast_data handler, a tree node. */
struct ast_data;
/*! \brief opaque definition of an ast_data_iterator handler. */
struct ast_data_iterator;
/*! \brief opaque definition of an ast_data_search structure. */
struct ast_data_search;
/*! \brief structure retrieved from a node, with the nodes content. */
struct ast_data_retrieve {
/*! \brief The type of the node retrieved. */
enum ast_data_type type;
union {
char *AST_DATA_STRING;
int AST_DATA_INTEGER;
double AST_DATA_DOUBLE;
unsigned int AST_DATA_UNSIGNED_INTEGER;
unsigned int AST_DATA_BOOLEAN;
void *AST_DATA_POINTER;
struct in_addr AST_DATA_IPADDR;
void *AST_DATA_CONTAINER;
} value;
};
/*!
* \brief The get callback definition.
*/
typedef int (*ast_data_get_cb)(const struct ast_data_search *search,
struct ast_data *root);
/*! \brief The structure of the node handler. */
struct ast_data_handler {
/*! \brief Structure version. */
uint32_t version;
/*! \brief Data get callback implementation. */
ast_data_get_cb get;
};
/*! \brief This entries are for multiple registers. */
struct ast_data_entry {
/*! \brief Path of the node to register. */
const char *path;
/*! \brief Data handler structure. */
const struct ast_data_handler *handler;
};
#define AST_DATA_ENTRY(__path, __handler) { .path = __path, .handler = __handler }
/*! \brief A query to the data API is specified in this structure. */
struct ast_data_query {
/*! \brief Data query version. */
uint32_t version;
/*! \brief Path to the node to retrieve. */
char *path;
/*! \brief Filter string, return the internal nodes specified here.
* Setting it to NULL will return every internal node. */
char *filter;
/*! \brief Search condition. */
char *search;
};
/*! \brief Map the members of a structure. */
struct ast_data_mapping_structure {
/*! \brief structure member name. */
const char *name;
/*! \brief structure member type. */
enum ast_data_type type;
/*! \brief member getter. */
union {
char *(*AST_DATA_STRING)(void *ptr);
int (*AST_DATA_INTEGER)(void *ptr);
double (*AST_DATA_DOUBLE)(void *ptr);
unsigned int (*AST_DATA_UNSIGNED_INTEGER)(void *ptr);
unsigned int (*AST_DATA_BOOLEAN)(void *ptr);
void *(*AST_DATA_POINTER)(void *ptr);
struct in_addr (*AST_DATA_IPADDR)(void *ptr);
void *(*AST_DATA_CONTAINER)(void *ptr);
} get;
};
/* Generate the structure and the functions to access the members of a structure. */
#define AST_DATA_STRUCTURE(__struct, __name) \
__name(__AST_DATA_MAPPING_FUNCTION); \
static const struct ast_data_mapping_structure __data_mapping_structure_##__struct[] = { \
__name(__AST_DATA_MAPPING_STRUCTURE) \
}
/* Generate the structure to access the members and setup the pointer of the getter. */
#define __AST_DATA_MAPPING_STRUCTURE(__structure, __member, __type) \
{ .name = #__member, .get.__type = data_mapping_structure_get_##__structure##__member, \
.type = __type },
/* based on the data type, specifify the type of return value for the getter function. */
#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_INTEGER(__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) \
__AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_BOOLEAN, unsigned int)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_POINTER(__structure, __member) \
__AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_POINTER, void *)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_IPADDR(__structure, __member) \
__AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_IPADDR, struct in_addr)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_DOUBLE(__structure, __member) \
__AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_DBL, double)
#define __AST_DATA_MAPPING_FUNCTION_AST_DATA_CONTAINER(__structure, __member) \
__AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, AST_DATA_CONTAINER, void *)
#define __AST_DATA_MAPPING_FUNCTION(__structure, __member, __type) \
__AST_DATA_MAPPING_FUNCTION_##__type(__structure, __member)
/* Create the function to retrieve a member of the structure. */
#define __AST_DATA_MAPPING_FUNCTION_TYPE(__structure, __member, __type, __real_type) \
static __real_type data_mapping_structure_get_##__structure##__member(void *ptr) { \
struct __structure *struct_##__member = (struct __structure *) ptr; \
return (__real_type) struct_##__member->__member; \
}
/*!
* \brief Register a data provider.
* \param[in] path The path of the node to register.
* \param[in] handler The structure defining this node handler.
* \param[in] registrar Who is registering this node.
* \param[in] mod The module registering this handler.
* \see ast_data_unregister
* \retval <0 on error.
* \retval 0 on success.
* \see __ast_data_unregister, __ast_data_register_multiple
*/
int __ast_data_register(const char *path, const struct ast_data_handler *handler,
const char *registrar, struct ast_module *mod);
#define ast_data_register(path, handler) __ast_data_register(path, handler, __FILE__, ast_module_info->self)
#define ast_data_register_core(path, handler) __ast_data_register(path, handler, __FILE__, NULL)
/*!
* \brief Register multiple data providers at once.
* \param[in] data_entries An array of data_entries structures.
* \param[in] entries The number of entries in the data_entries array.
* \param[in] registrar Who is registering this nodes.
* \param[in] mod The module registering this handlers.
* \retval <0 on error (none of the nodes are being registered on error).
* \retval 0 on success.
* \see __ast_data_register, __ast_data_unregister
*/
int __ast_data_register_multiple(const struct ast_data_entry *data_entries,
size_t entries, const char *registrar, struct ast_module *mod);
#define ast_data_register_multiple(data_entries, entries) \
__ast_data_register_multiple(data_entries, entries, __FILE__, ast_module_info->self)
#define ast_data_register_multiple_core(data_entries, entries) \
__ast_data_register_multiple(data_entries, entries, __FILE__, NULL)
/*!
* \brief Unregister a data provider.
* \param[in] path Which node to unregister, if path is NULL unregister every node
* registered by the passed 'registrar'.
* \param[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 ast_data_register
* \retval <0 on error.
* \retval 0 on success.
* \see __ast_data_register, __ast_data_register_multiple
*/
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.
*/
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);
/*!
* \brief Based on a search tree, evaluate every member of a structure against it.
* \param[in] search The search tree.
* \param[in] mapping The structure mapping.
* \param[in] mapping_len The lenght of the structure mapping.
* \param[in] structure The structure pointer.
* \param[in] structure_name The name of the structure to compare.
* \retval 0 If the structure matches.
* \retval 1 If the structure doesn't match.
*/
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);
#define ast_data_search_cmp_structure(search, structure_name, structure, structure_name_cmp) \
__ast_data_search_cmp_structure(search, __data_mapping_structure_##structure_name, \
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.
* \retval non-NULL The dynamically allocated requested sub-tree (it needs to be
* released using ast_data_free.
* \see ast_data_free, ast_data_get_xml
*/
struct ast_data *ast_data_get(const struct ast_data_query *query);
/*!
* \brief Retrieve a subtree from the asterisk data API in XML format..
* \param[in] query The query structure specifying what nodes to retrieve.
* \retval NULL on error.
* \retval non-NULL The dynamically allocated requested sub-tree (it needs to be
* released using ast_data_free.
* \see ast_data_free, ast_data_get
*/
struct ast_xml_doc *ast_data_get_xml(const struct ast_data_query *query);
/*!
* \brief Release the allocated memory of a tree.
* \param[in] root The sub-tree pointer returned by a call to ast_data_get.
* \see ast_data_get
*/
void ast_data_free(struct ast_data *root);
/*!
* \brief Get a node type.
* \param[in] res A pointer to the ast_data result set.
* \param[in] path A path to the node to get the type.
* \return The type of the requested node type.
*/
enum ast_data_type ast_data_retrieve_type(struct ast_data *res, const char *path);
/*!
* \brief Get the node name.
* \param[in] node The node pointer.
* \returns The node name.
*/
char *ast_data_retrieve_name(struct ast_data *node);
/*!
* \brief Add a container child.
* \param[in] root The root of the ast_data to insert into.
* \param[in] childname The name of the child element to be added.
* \retval NULL on error (memory exhaustion only).
* \retval non-NULL a newly allocated node.
*/
struct ast_data *ast_data_add_node(struct ast_data *root, const char *childname);
/*!
* \brief Add an 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.
* \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_int(struct ast_data *root, const char *childname,
int 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.
* \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_uint(struct ast_data *root, const char *childname,
unsigned int value);
/*!
* \brief Add a floating point 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] dbl 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_dbl(struct ast_data *root, const char *childname,
double dbl);
/*!
* \brief Add a ipv4 address 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] addr The ipv4 address value.
* \retval NULL on error (memory exhaustion only).
* \retval non-NULL a newly allocated node.
*/
struct ast_data *ast_data_add_ipaddr(struct ast_data *root, const char *childname,
struct in_addr addr);
/*!
* \brief Add a ptr 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] ptr The pointer value to add.
* \retval NULL on error (memory exhaustion only).
* \retval non-NULL a newly allocated node.
*/
struct ast_data *ast_data_add_ptr(struct ast_data *root, const char *childname,
void *ptr);
/*!
* \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.
* \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_str(struct ast_data *root, const char *childname,
const char *string);
/*!
* \brief Add a boolean 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_bool(struct ast_data *root, const char *childname,
unsigned int boolean);
/*!
* \brief Add a complete structure to a node.
* \param[in] root Where to add the structure.
* \param[in] mapping The structure mapping array.
* \param[in] mapping_len The lenght of the mapping array.
* \param[in] structure The structure pointer.
* \retval 0 on success.
* \retval 1 on error.
*/
int __ast_data_add_structure(struct ast_data *root,
const struct ast_data_mapping_structure *mapping,
size_t mapping_len, void *structure);
#define ast_data_add_structure(structure_name, root, structure) \
__ast_data_add_structure(root, __data_mapping_structure_##structure_name, \
ARRAY_LEN(__data_mapping_structure_##structure_name), structure)
/*!
* \brief Remove a node that was added using ast_data_add_
* \param[in] root The root node of the node to be removed.
* \param[in] child The node pointer to remove.
*/
void ast_data_remove_node(struct ast_data *root, struct ast_data *child);
/*!
* \brief Initialize an iterator.
* \param[in] tree The returned tree by a call to ast_data_get.
* \param[in] elements Which elements to iterate through.
* \retval NULL on error.
* \retval non-NULL A dinamically allocated iterator structure.
*/
struct ast_data_iterator *ast_data_iterator_init(struct ast_data *tree,
const char *elements);
/*!
* \brief Release (stop using) an iterator.
* \param[in] iterator The iterator created by ast_data_iterator_start.
* \see ast_data_iterator_start
*/
void ast_data_iterator_end(struct ast_data_iterator *iterator);
/*!
* \brief Get the next node of the tree.
* \param[in] iterator The iterator structure returned by ast_data_iterator_start.
* \retval NULL when no more nodes to return.
* \retval non-NULL A node of the ast_data tree.
* \see ast_data_iterator_start, ast_data_iterator_stop
*/
struct ast_data *ast_data_iterator_next(struct ast_data_iterator *iterator);
/*!
* \brief Retrieve a value from a node in the tree.
* \param[in] tree The structure returned by a call to ast_data_get.
* \param[in] path The path to the node.
* \param[out] content The node content.
* \retval 0 on success.
* \retval <0 on error.
*/
int ast_data_retrieve(struct ast_data *tree, const char *path, struct ast_data_retrieve *content);
/*!
* \brief Retrieve the integer 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 int ast_data_retrieve_int(struct ast_data *tree, const char *path)
{
struct ast_data_retrieve ret;
ast_data_retrieve(tree, path, &ret);
return ret.value.AST_DATA_INTEGER;
}
/*!
* \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.
* \returns The value of the node.
*/
static inline unsigned int ast_data_retrieve_bool(struct ast_data *tree, const char *path)
{
struct ast_data_retrieve ret;
ast_data_retrieve(tree, path, &ret);
return ret.value.AST_DATA_BOOLEAN;
}
/*!
* \brief Retrieve the unsigned integer 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 unsigned int ast_data_retrieve_uint(struct ast_data *tree, const char *path)
{
struct ast_data_retrieve ret;
ast_data_retrieve(tree, path, &ret);
return ret.value.AST_DATA_UNSIGNED_INTEGER;
}
/*!
* \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.
* \returns The value of the node.
*/
static inline const char *ast_data_retrieve_string(struct ast_data *tree, const char *path)
{
struct ast_data_retrieve ret;
ast_data_retrieve(tree, path, &ret);
return ret.value.AST_DATA_STRING;
}
/*!
* \brief Retrieve the ptr 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 void *ast_data_retrieve_ptr(struct ast_data *tree, const char *path)
{
struct ast_data_retrieve ret;
ast_data_retrieve(tree, path, &ret);
return ret.value.AST_DATA_POINTER;
}
/*!
* \brief Retrieve the double 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 double ast_data_retrieve_dbl(struct ast_data *tree, const char *path)
{
struct ast_data_retrieve ret;
ast_data_retrieve(tree, path, &ret);
return ret.value.AST_DATA_DOUBLE;
}
/*!
* \brief Retrieve the ipv4 address 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 struct in_addr ast_data_retrieve_ipaddr(struct ast_data *tree, const char *path)
{
struct ast_data_retrieve ret;
ast_data_retrieve(tree, path, &ret);
return ret.value.AST_DATA_IPADDR;
}
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#endif /* ASTERISK_DATA_H */

@ -90,6 +90,7 @@
* \arg \ref AstThreadStorage * \arg \ref AstThreadStorage
* \arg \ref DataStores * \arg \ref DataStores
* \arg \ref AstExtState * \arg \ref AstExtState
* \arg \ref AstDataRetrieval
* *
* \subsection model_txt Generic Model * \subsection model_txt Generic Model
* \verbinclude model.txt * \verbinclude model.txt

@ -24,7 +24,8 @@
struct ast_xml_node; struct ast_xml_node;
struct ast_xml_doc; struct ast_xml_doc;
/*! \brief Initialize the XML library implementation. /*!
* \brief Initialize the XML library implementation.
* This function is used to setup everything needed * This function is used to setup everything needed
* to start working with the xml implementation. * to start working with the xml implementation.
* \retval 0 On success. * \retval 0 On success.
@ -32,19 +33,61 @@ struct ast_xml_doc;
*/ */
int ast_xml_init(void); int ast_xml_init(void);
/*! \brief Cleanup library allocated global data. /*!
* \brief Cleanup library allocated global data.
* \retval 0 On success. * \retval 0 On success.
* \retval 1 On error. * \retval 1 On error.
*/ */
int ast_xml_finish(void); int ast_xml_finish(void);
/*! \brief Open an XML document. /*!
* \brief Open an XML document.
* \param filename Document path. * \param filename Document path.
* \retval NULL on error. * \retval NULL on error.
* \retval The ast_xml_doc reference to the open document. * \retval The ast_xml_doc reference to the open document.
*/ */
struct ast_xml_doc *ast_xml_open(char *filename); struct ast_xml_doc *ast_xml_open(char *filename);
/*!
* \brief Create a XML document.
* \retval NULL on error.
* \retval non-NULL The allocated document structure.
*/
struct ast_xml_doc *ast_xml_new(void);
/*!
* \brief Create a XML node.
* \param name The name of the node to be created.
* \retval NULL on error.
* \retval non-NULL The allocated node structe.
*/
struct ast_xml_node *ast_xml_new_node(const char *name);
/*!
* \brief Add a child node inside a passed parent node.
* \param parent The pointer of the parent node.
* \param child_name The name of the child node to add.
* \retval NULL on error.
* \retval non-NULL The created child node pointer.
*/
struct ast_xml_node *ast_xml_new_child(struct ast_xml_node *parent, const char *child_name);
/*!
* \brief Add a child node, to a specified parent node.
* \param parent Where to add the child node.
* \param child The child node to add.
* \retval NULL on error.
* \retval non-NULL The add child node on success.
*/
struct ast_xml_node *ast_xml_add_child(struct ast_xml_node *parent, struct ast_xml_node *child);
/*!
* \brief Close an already open document and free the used
* structure.
* \retval doc The document reference.
*/
void ast_xml_close(struct ast_xml_doc *doc);
/*! \brief Open an XML document that resides in memory. /*! \brief Open an XML document that resides in memory.
* \param buffer The address where the document is stored * \param buffer The address where the document is stored
* \size The number of bytes in the document * \size The number of bytes in the document
@ -53,35 +96,48 @@ struct ast_xml_doc *ast_xml_open(char *filename);
*/ */
struct ast_xml_doc *ast_xml_read_memory(char *buffer, size_t size); struct ast_xml_doc *ast_xml_read_memory(char *buffer, size_t size);
/*! \brief Close an already open document and free the used /*!
* structure. * \brief Specify the root node of a XML document.
* \retval doc The document reference. * \param doc The document pointer.
* \param node A pointer to the node we want to set as root node.
*/ */
void ast_xml_close(struct ast_xml_doc *doc); void ast_xml_set_root(struct ast_xml_doc *doc, struct ast_xml_node *node);
/*! \brief Get the document root node. /*!
* \brief Get the document root node.
* \param doc Document reference * \param doc Document reference
* \retval NULL on error * \retval NULL on error
* \retval The root node on success. * \retval The root node on success.
*/ */
struct ast_xml_node *ast_xml_get_root(struct ast_xml_doc *doc); struct ast_xml_node *ast_xml_get_root(struct ast_xml_doc *doc);
/*! \brief Free node /*!
* \brief Free node
* \param node Node to be released. * \param node Node to be released.
*/ */
void ast_xml_free_node(struct ast_xml_node *node); void ast_xml_free_node(struct ast_xml_node *node);
/*! \brief Free an attribute returned by ast_xml_get_attribute() /*!
* \brief Free an attribute returned by ast_xml_get_attribute()
* \param data pointer to be freed. * \param data pointer to be freed.
*/ */
void ast_xml_free_attr(const char *attribute); void ast_xml_free_attr(const char *attribute);
/*! \brief Free a content element that was returned by ast_xml_get_text() /*!
* \brief Get the document based on a node.
* \param node A node that is part of the dom.
* \returns The dom pointer where this node resides.
*/
struct ast_xml_doc *ast_xml_get_doc(struct ast_xml_node *node);
/*!
* \brief Free a content element that was returned by ast_xml_get_text()
* \param text text to be freed. * \param text text to be freed.
*/ */
void ast_xml_free_text(const char *text); void ast_xml_free_text(const char *text);
/*! \brief Get a node attribute by name /*!
* \brief Get a node attribute by name
* \param node Node where to search the attribute. * \param node Node where to search the attribute.
* \param attrname Attribute name. * \param attrname Attribute name.
* \retval NULL on error * \retval NULL on error
@ -89,7 +145,18 @@ void ast_xml_free_text(const char *text);
*/ */
const char *ast_xml_get_attribute(struct ast_xml_node *node, const char *attrname); const char *ast_xml_get_attribute(struct ast_xml_node *node, const char *attrname);
/*! \brief Find a node element by name. /*!
* \brief Set an attribute to a node.
* \param node In which node we want to insert the attribute.
* \param name The attribute name.
* \param value The attribute value.
* \retval 0 on success.
* \retval -1 on error.
*/
int ast_xml_set_attribute(struct ast_xml_node *node, const char *name, const char *value);
/*!
* \brief Find a node element by name.
* \param node This is the node starting point. * \param node This is the node starting point.
* \param name Node name to find. * \param name Node name to find.
* \param attrname attribute name to match (if NULL it won't be matched). * \param attrname attribute name to match (if NULL it won't be matched).
@ -101,28 +168,45 @@ struct ast_xml_node *ast_xml_find_element(struct ast_xml_node *root_node, const
struct ast_xml_ns *ast_xml_find_namespace(struct ast_xml_doc *doc, struct ast_xml_node *node, const char *ns_name); struct ast_xml_ns *ast_xml_find_namespace(struct ast_xml_doc *doc, struct ast_xml_node *node, const char *ns_name);
const char *ast_xml_get_ns_href(struct ast_xml_ns *ns); const char *ast_xml_get_ns_href(struct ast_xml_ns *ns);
/*! \brief Get an element content string. /*!
* \brief Get an element content string.
* \param node Node from where to get the string. * \param node Node from where to get the string.
* \retval NULL on error. * \retval NULL on error.
* \retval The text content of node. * \retval The text content of node.
*/ */
const char *ast_xml_get_text(struct ast_xml_node *node); const char *ast_xml_get_text(struct ast_xml_node *node);
/*! \brief Get the name of a node. */ /*!
* \brief Set an element content string.
* \param node Node from where to set the content string.
* \param content The text to insert in the node.
*/
void ast_xml_set_text(struct ast_xml_node *node, const char *content);
/*!
* \brief Get the name of a node. */
const char *ast_xml_node_get_name(struct ast_xml_node *node); const char *ast_xml_node_get_name(struct ast_xml_node *node);
/*! \brief Get the node's children. */ /*!
* \brief Get the node's children. */
struct ast_xml_node *ast_xml_node_get_children(struct ast_xml_node *node); struct ast_xml_node *ast_xml_node_get_children(struct ast_xml_node *node);
/*! \brief Get the next node in the same level. */ /*!
* \brief Get the next node in the same level. */
struct ast_xml_node *ast_xml_node_get_next(struct ast_xml_node *node); struct ast_xml_node *ast_xml_node_get_next(struct ast_xml_node *node);
/*! \brief Get the previous node in the same leve. */ /*!
* \brief Get the previous node in the same leve. */
struct ast_xml_node *ast_xml_node_get_prev(struct ast_xml_node *node); struct ast_xml_node *ast_xml_node_get_prev(struct ast_xml_node *node);
/*! \brief Get the parent of a specified node. */ /*!
* \brief Get the parent of a specified node. */
struct ast_xml_node *ast_xml_node_get_parent(struct ast_xml_node *node); struct ast_xml_node *ast_xml_node_get_parent(struct ast_xml_node *node);
/*!
* \brief Dump the specified document to a file. */
int ast_xml_doc_dump_file(FILE *output, struct ast_xml_doc *doc);
/* Features using ast_xml_ */ /* Features using ast_xml_ */
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
#define AST_XML_DOCS #define AST_XML_DOCS

@ -3611,6 +3611,12 @@ int main(int argc, char *argv[])
ast_xmldoc_load_documentation(); ast_xmldoc_load_documentation();
#endif #endif
/* initialize the data retrieval API */
if (ast_data_init()) {
printf ("%s", term_quit());
exit(1);
}
ast_channels_init(); ast_channels_init();
if ((moduleresult = load_modules(1))) { /* Load modules, pre-load only */ if ((moduleresult = load_modules(1))) { /* Load modules, pre-load only */

@ -65,6 +65,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/timing.h" #include "asterisk/timing.h"
#include "asterisk/autochan.h" #include "asterisk/autochan.h"
#include "asterisk/stringfields.h" #include "asterisk/stringfields.h"
#include "asterisk/data.h"
#ifdef HAVE_EPOLL #ifdef HAVE_EPOLL
#include <sys/epoll.h> #include <sys/epoll.h>
@ -133,6 +134,52 @@ static AST_RWLIST_HEAD_STATIC(backends, chanlist);
#define NUM_CHANNEL_BUCKETS 1567 #define NUM_CHANNEL_BUCKETS 1567
#endif #endif
#define DATA_EXPORT_CHANNEL(MEMBER) \
MEMBER(ast_channel, blockproc, AST_DATA_STRING) \
MEMBER(ast_channel, appl, AST_DATA_STRING) \
MEMBER(ast_channel, data, AST_DATA_STRING) \
MEMBER(ast_channel, name, AST_DATA_STRING) \
MEMBER(ast_channel, language, AST_DATA_STRING) \
MEMBER(ast_channel, musicclass, AST_DATA_STRING) \
MEMBER(ast_channel, accountcode, AST_DATA_STRING) \
MEMBER(ast_channel, peeraccount, AST_DATA_STRING) \
MEMBER(ast_channel, userfield, AST_DATA_STRING) \
MEMBER(ast_channel, call_forward, AST_DATA_STRING) \
MEMBER(ast_channel, uniqueid, AST_DATA_STRING) \
MEMBER(ast_channel, linkedid, AST_DATA_STRING) \
MEMBER(ast_channel, parkinglot, AST_DATA_STRING) \
MEMBER(ast_channel, hangupsource, AST_DATA_STRING) \
MEMBER(ast_channel, dialcontext, AST_DATA_STRING) \
MEMBER(ast_channel, _softhangup, AST_DATA_INTEGER) \
MEMBER(ast_channel, streamid, AST_DATA_INTEGER) \
MEMBER(ast_channel, vstreamid, AST_DATA_INTEGER) \
MEMBER(ast_channel, oldwriteformat, AST_DATA_INTEGER) \
MEMBER(ast_channel, _state, AST_DATA_INTEGER) \
MEMBER(ast_channel, rings, AST_DATA_INTEGER) \
MEMBER(ast_channel, priority, AST_DATA_INTEGER) \
MEMBER(ast_channel, macropriority, AST_DATA_INTEGER) \
MEMBER(ast_channel, amaflags, AST_DATA_INTEGER) \
MEMBER(ast_channel, adsicpe, AST_DATA_INTEGER) \
MEMBER(ast_channel, fin, AST_DATA_UNSIGNED_INTEGER) \
MEMBER(ast_channel, fout, AST_DATA_UNSIGNED_INTEGER) \
MEMBER(ast_channel, hangupcause, AST_DATA_INTEGER) \
MEMBER(ast_channel, flags, AST_DATA_UNSIGNED_INTEGER) \
MEMBER(ast_channel, nativeformats, AST_DATA_INTEGER) \
MEMBER(ast_channel, readformat, AST_DATA_INTEGER) \
MEMBER(ast_channel, writeformat, AST_DATA_INTEGER) \
MEMBER(ast_channel, rawreadformat, AST_DATA_INTEGER) \
MEMBER(ast_channel, rawwriteformat, AST_DATA_INTEGER) \
MEMBER(ast_channel, emulate_dtmf_duration, AST_DATA_UNSIGNED_INTEGER) \
MEMBER(ast_channel, visible_indication, AST_DATA_INTEGER) \
MEMBER(ast_channel, transfercapability, AST_DATA_INTEGER) \
MEMBER(ast_channel, context, AST_DATA_STRING) \
MEMBER(ast_channel, exten, AST_DATA_STRING) \
MEMBER(ast_channel, macrocontext, AST_DATA_STRING) \
MEMBER(ast_channel, macroexten, AST_DATA_STRING)
AST_DATA_STRUCTURE(ast_channel, DATA_EXPORT_CHANNEL);
/*! \brief All active channels on the system */ /*! \brief All active channels on the system */
static struct ao2_container *channels; static struct ao2_container *channels;
@ -211,6 +258,17 @@ struct ast_variable *ast_channeltype_list(void)
return var; return var;
} }
int ast_channel_data_add_structure(struct ast_data *tree, struct ast_channel *chan)
{
return ast_data_add_structure(ast_channel, tree, chan);
}
int ast_channel_data_cmp_structure(const struct ast_data_search *tree,
struct ast_channel *chan, const char *structure_name)
{
return ast_data_search_cmp_structure(tree, ast_channel, chan, structure_name);
}
/*! \brief Show channel types - CLI command */ /*! \brief Show channel types - CLI command */
static char *handle_cli_core_show_channeltypes(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) static char *handle_cli_core_show_channeltypes(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{ {
@ -6422,12 +6480,88 @@ static int ast_channel_hash_cb(const void *obj, const int flags)
return ast_str_case_hash(chan->name); return ast_str_case_hash(chan->name);
} }
/*!
* \internal
* \brief Implements the channels provider.
*/
static int data_channels_provider_handler(const struct ast_data_search *search,
struct ast_data *root)
{
struct ast_channel *c, *bc;
struct ast_channel_iterator *iter = NULL;
struct ast_data *data_channel, *data_bridged;
int channel_match, bridged_match;
channel_match = ast_data_search_has_condition(search,
"channel");
bridged_match = ast_data_search_has_condition(search,
"channel/bridged");
for (iter = ast_channel_iterator_all_new();
iter && (c = ast_channel_iterator_next(iter)); ast_channel_unref(c)) {
ast_channel_lock(c);
if (channel_match &&
ast_channel_data_cmp_structure(search, c, "channel")) {
ast_channel_unlock(c);
continue;
}
bc = ast_bridged_channel(c);
if (bridged_match && bc &&
ast_channel_data_cmp_structure(search, bc, "channel/bridged")) {
ast_channel_unlock(c);
continue;
}
data_channel = ast_data_add_node(root, "channel");
if (!data_channel) {
ast_channel_unlock(c);
continue;
}
ast_channel_data_add_structure(data_channel, c);
if (bc) {
data_bridged = ast_data_add_node(data_channel, "bridged");
if (!data_bridged) {
ast_channel_unlock(c);
continue;
}
ast_channel_data_add_structure(data_bridged, bc);
}
ast_channel_unlock(c);
}
if (iter) {
ast_channel_iterator_destroy(iter);
}
return 0;
}
/*!
* \internal
* \brief /asterisk/core/channels provider.
*/
static const struct ast_data_handler channels_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = data_channels_provider_handler
};
static const struct ast_data_entry channel_providers[] = {
AST_DATA_ENTRY("/asterisk/core/channels", &channels_provider),
};
void ast_channels_init(void) void ast_channels_init(void)
{ {
channels = ao2_container_alloc(NUM_CHANNEL_BUCKETS, channels = ao2_container_alloc(NUM_CHANNEL_BUCKETS,
ast_channel_hash_cb, ast_channel_cmp_cb); ast_channel_hash_cb, ast_channel_cmp_cb);
ast_cli_register_multiple(cli_channel, ARRAY_LEN(cli_channel)); ast_cli_register_multiple(cli_channel, ARRAY_LEN(cli_channel));
ast_data_register_multiple_core(channel_providers, ARRAY_LEN(channel_providers));
} }
/*! \brief Print call group and pickup group ---*/ /*! \brief Print call group and pickup group ---*/

File diff suppressed because it is too large Load Diff

@ -68,6 +68,46 @@ struct ast_xml_doc *ast_xml_open(char *filename)
return (struct ast_xml_doc *) doc; return (struct ast_xml_doc *) doc;
} }
struct ast_xml_doc *ast_xml_new(void)
{
xmlDoc *doc;
doc = xmlNewDoc((const xmlChar *) "1.0");
return (struct ast_xml_doc *) doc;
}
struct ast_xml_node *ast_xml_new_node(const char *name)
{
xmlNode *node;
if (!name) {
return NULL;
}
node = xmlNewNode(NULL, (const xmlChar *) name);
return (struct ast_xml_node *) node;
}
struct ast_xml_node *ast_xml_new_child(struct ast_xml_node *parent, const char *child_name)
{
xmlNode *child;
if (!parent || !child_name) {
return NULL;
}
child = xmlNewChild((xmlNode *) parent, NULL, (const xmlChar *) child_name, NULL);
return (struct ast_xml_node *) child;
}
struct ast_xml_node *ast_xml_add_child(struct ast_xml_node *parent, struct ast_xml_node *child)
{
if (!parent || !child) {
return NULL;
}
return (struct ast_xml_node *) xmlAddChild((xmlNode *) parent, (xmlNode *) child);
}
struct ast_xml_doc *ast_xml_read_memory(char *buffer, size_t size) struct ast_xml_doc *ast_xml_read_memory(char *buffer, size_t size)
{ {
xmlDoc *doc; xmlDoc *doc;
@ -97,6 +137,14 @@ void ast_xml_close(struct ast_xml_doc *doc)
doc = NULL; doc = NULL;
} }
void ast_xml_set_root(struct ast_xml_doc *doc, struct ast_xml_node *node)
{
if (!doc || !node) {
return;
}
xmlDocSetRootElement((xmlDoc *) doc, (xmlNode *) node);
}
struct ast_xml_node *ast_xml_get_root(struct ast_xml_doc *doc) struct ast_xml_node *ast_xml_get_root(struct ast_xml_doc *doc)
{ {
@ -152,6 +200,19 @@ const char *ast_xml_get_attribute(struct ast_xml_node *node, const char *attrnam
return (const char *) attrvalue; return (const char *) attrvalue;
} }
int ast_xml_set_attribute(struct ast_xml_node *node, const char *name, const char *value)
{
if (!name || !value) {
return -1;
}
if (!xmlSetProp((xmlNode *) node, (xmlChar *) name, (xmlChar *) value)) {
return -1;
}
return 0;
}
struct ast_xml_node *ast_xml_find_element(struct ast_xml_node *root_node, const char *name, const char *attrname, const char *attrvalue) struct ast_xml_node *ast_xml_find_element(struct ast_xml_node *root_node, const char *name, const char *attrname, const char *attrvalue)
{ {
struct ast_xml_node *cur; struct ast_xml_node *cur;
@ -184,6 +245,15 @@ struct ast_xml_node *ast_xml_find_element(struct ast_xml_node *root_node, const
return NULL; return NULL;
} }
struct ast_xml_doc *ast_xml_get_doc(struct ast_xml_node *node)
{
if (!node) {
return NULL;
}
return (struct ast_xml_doc *) ((xmlNode *)node)->doc;
}
struct ast_xml_ns *ast_xml_find_namespace(struct ast_xml_doc *doc, struct ast_xml_node *node, const char *ns_name) { struct ast_xml_ns *ast_xml_find_namespace(struct ast_xml_doc *doc, struct ast_xml_node *node, const char *ns_name) {
xmlNsPtr ns = xmlSearchNs((xmlDocPtr) doc, (xmlNodePtr) node, (xmlChar *) ns_name); xmlNsPtr ns = xmlSearchNs((xmlDocPtr) doc, (xmlNodePtr) node, (xmlChar *) ns_name);
return (struct ast_xml_ns *) ns; return (struct ast_xml_ns *) ns;
@ -203,6 +273,20 @@ const char *ast_xml_get_text(struct ast_xml_node *node)
return (const char *) xmlNodeGetContent((xmlNode *) node); return (const char *) xmlNodeGetContent((xmlNode *) node);
} }
void ast_xml_set_text(struct ast_xml_node *node, const char *content)
{
if (!node || !content) {
return;
}
xmlNodeSetContent((xmlNode *) node, (const xmlChar *) content);
}
int ast_xml_doc_dump_file(FILE *output, struct ast_xml_doc *doc)
{
return xmlDocDump(output, (xmlDocPtr)doc);
}
const char *ast_xml_node_get_name(struct ast_xml_node *node) const char *ast_xml_node_get_name(struct ast_xml_node *node)
{ {
return (const char *) ((xmlNode *) node)->name; return (const char *) ((xmlNode *) node)->name;

Loading…
Cancel
Save