Merge "core: Remove 'Data Retrieval API'"

This commit is contained in:
Jenkins2 2017-07-07 15:42:56 -05:00 committed by Gerrit Code Review
commit d6c08cc559
19 changed files with 10 additions and 6114 deletions

View File

@ -23,6 +23,15 @@
=== UPGRADE-14.txt -- Upgrade info for 13 to 14
===========================================================
New in 15.0.0:
Core:
- The 'Data Retrieval API' has been removed. This API was not actively
maintained, was not added to new modules (such as res_pjsip), and there
exist better alternatives to acquire the same information, such as the
ARI. As a result, the 'DataGet' AMI action as well as the 'data get'
CLI command have been removed.
From 14.4.0 to 14.5.0:
Core:

View File

@ -69,7 +69,6 @@
#include "asterisk/dial.h"
#include "asterisk/causes.h"
#include "asterisk/paths.h"
#include "asterisk/data.h"
#include "asterisk/test.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_channels.h"
@ -8005,186 +8004,6 @@ static int load_config(int reload)
return sla_load_config(reload);
}
#define MEETME_DATA_EXPORT(MEMBER) \
MEMBER(ast_conference, confno, AST_DATA_STRING) \
MEMBER(ast_conference, dahdiconf, AST_DATA_INTEGER) \
MEMBER(ast_conference, users, AST_DATA_INTEGER) \
MEMBER(ast_conference, markedusers, AST_DATA_INTEGER) \
MEMBER(ast_conference, maxusers, AST_DATA_INTEGER) \
MEMBER(ast_conference, isdynamic, AST_DATA_BOOLEAN) \
MEMBER(ast_conference, locked, AST_DATA_BOOLEAN) \
MEMBER(ast_conference, recordingfilename, AST_DATA_STRING) \
MEMBER(ast_conference, recordingformat, AST_DATA_STRING) \
MEMBER(ast_conference, pin, AST_DATA_PASSWORD) \
MEMBER(ast_conference, pinadmin, AST_DATA_PASSWORD) \
MEMBER(ast_conference, start, AST_DATA_TIMESTAMP) \
MEMBER(ast_conference, endtime, AST_DATA_TIMESTAMP)
AST_DATA_STRUCTURE(ast_conference, MEETME_DATA_EXPORT);
#define MEETME_USER_DATA_EXPORT(MEMBER) \
MEMBER(ast_conf_user, user_no, AST_DATA_INTEGER) \
MEMBER(ast_conf_user, talking, AST_DATA_BOOLEAN) \
MEMBER(ast_conf_user, dahdichannel, AST_DATA_BOOLEAN) \
MEMBER(ast_conf_user, jointime, AST_DATA_TIMESTAMP) \
MEMBER(ast_conf_user, kicktime, AST_DATA_TIMESTAMP) \
MEMBER(ast_conf_user, timelimit, AST_DATA_MILLISECONDS) \
MEMBER(ast_conf_user, play_warning, AST_DATA_MILLISECONDS) \
MEMBER(ast_conf_user, warning_freq, AST_DATA_MILLISECONDS)
AST_DATA_STRUCTURE(ast_conf_user, MEETME_USER_DATA_EXPORT);
static int user_add_provider_cb(void *obj, void *arg, int flags)
{
struct ast_data *data_meetme_user;
struct ast_data *data_meetme_user_channel;
struct ast_data *data_meetme_user_volume;
struct ast_conf_user *user = obj;
struct ast_data *data_meetme_users = arg;
data_meetme_user = ast_data_add_node(data_meetme_users, "user");
if (!data_meetme_user) {
return 0;
}
/* user structure */
ast_data_add_structure(ast_conf_user, data_meetme_user, user);
/* user's channel */
data_meetme_user_channel = ast_data_add_node(data_meetme_user, "channel");
if (!data_meetme_user_channel) {
return 0;
}
ast_channel_data_add_structure(data_meetme_user_channel, user->chan, 1);
/* volume structure */
data_meetme_user_volume = ast_data_add_node(data_meetme_user, "listen-volume");
if (!data_meetme_user_volume) {
return 0;
}
ast_data_add_int(data_meetme_user_volume, "desired", user->listen.desired);
ast_data_add_int(data_meetme_user_volume, "actual", user->listen.actual);
data_meetme_user_volume = ast_data_add_node(data_meetme_user, "talk-volume");
if (!data_meetme_user_volume) {
return 0;
}
ast_data_add_int(data_meetme_user_volume, "desired", user->talk.desired);
ast_data_add_int(data_meetme_user_volume, "actual", user->talk.actual);
return 0;
}
/*!
* \internal
* \brief Implements the meetme data provider.
*/
static int meetme_data_provider_get(const struct ast_data_search *search,
struct ast_data *data_root)
{
struct ast_conference *cnf;
struct ast_data *data_meetme, *data_meetme_users;
AST_LIST_LOCK(&confs);
AST_LIST_TRAVERSE(&confs, cnf, list) {
data_meetme = ast_data_add_node(data_root, "meetme");
if (!data_meetme) {
continue;
}
ast_data_add_structure(ast_conference, data_meetme, cnf);
if (ao2_container_count(cnf->usercontainer)) {
data_meetme_users = ast_data_add_node(data_meetme, "users");
if (!data_meetme_users) {
ast_data_remove_node(data_root, data_meetme);
continue;
}
ao2_callback(cnf->usercontainer, OBJ_NODATA, user_add_provider_cb, data_meetme_users);
}
if (!ast_data_search_match(search, data_meetme)) {
ast_data_remove_node(data_root, data_meetme);
}
}
AST_LIST_UNLOCK(&confs);
return 0;
}
static const struct ast_data_handler meetme_data_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = meetme_data_provider_get
};
static const struct ast_data_entry meetme_data_providers[] = {
AST_DATA_ENTRY("asterisk/application/meetme/list", &meetme_data_provider),
};
#ifdef TEST_FRAMEWORK
AST_TEST_DEFINE(test_meetme_data_provider)
{
struct ast_channel *chan;
struct ast_conference *cnf;
struct ast_data *node;
struct ast_data_query query = {
.path = "/asterisk/application/meetme/list",
.search = "list/meetme/confno=9898"
};
switch (cmd) {
case TEST_INIT:
info->name = "meetme_get_data_test";
info->category = "/main/data/app_meetme/list/";
info->summary = "Meetme data provider unit test";
info->description =
"Tests whether the Meetme data provider implementation works as expected.";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
chan = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, "MeetMeTest");
if (!chan) {
ast_test_status_update(test, "Channel allocation failed\n");
return AST_TEST_FAIL;
}
ast_channel_unlock(chan);
cnf = build_conf("9898", "", "1234", 1, 1, 1, chan, test);
if (!cnf) {
ast_test_status_update(test, "Build of test conference 9898 failed\n");
ast_hangup(chan);
return AST_TEST_FAIL;
}
node = ast_data_get(&query);
if (!node) {
ast_test_status_update(test, "Data query for test conference 9898 failed\n");
dispose_conf(cnf);
ast_hangup(chan);
return AST_TEST_FAIL;
}
if (strcmp(ast_data_retrieve_string(node, "meetme/confno"), "9898")) {
ast_test_status_update(test, "Query returned the wrong conference\n");
dispose_conf(cnf);
ast_hangup(chan);
ast_data_free(node);
return AST_TEST_FAIL;
}
ast_data_free(node);
dispose_conf(cnf);
ast_hangup(chan);
return AST_TEST_PASS;
}
#endif
static int unload_module(void)
{
int res = 0;
@ -8201,11 +8020,6 @@ static int unload_module(void)
res |= ast_unregister_application(slastation_app);
res |= ast_unregister_application(slatrunk_app);
#ifdef TEST_FRAMEWORK
AST_TEST_UNREGISTER(test_meetme_data_provider);
#endif
ast_data_unregister(NULL);
ast_devstate_prov_del("Meetme");
ast_devstate_prov_del("SLA");
@ -8249,11 +8063,6 @@ static int load_module(void)
res |= ast_register_application_xml(slastation_app, sla_station_exec);
res |= ast_register_application_xml(slatrunk_app, sla_trunk_exec);
#ifdef TEST_FRAMEWORK
AST_TEST_REGISTER(test_meetme_data_provider);
#endif
ast_data_register_multiple(meetme_data_providers, ARRAY_LEN(meetme_data_providers));
res |= ast_devstate_prov_add("Meetme", meetmestate);
res |= ast_devstate_prov_add("SLA", sla_state);

View File

@ -99,7 +99,6 @@
#include "asterisk/taskprocessor.h"
#include "asterisk/aoc.h"
#include "asterisk/callerid.h"
#include "asterisk/data.h"
#include "asterisk/term.h"
#include "asterisk/dial.h"
#include "asterisk/stasis_channels.h"
@ -10896,275 +10895,6 @@ static struct ast_cli_entry cli_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, ringinuse, AST_DATA_BOOLEAN) \
MEMBER(call_queue, announce_to_first_user, AST_DATA_BOOLEAN) \
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, realtime, AST_DATA_BOOLEAN) \
MEMBER(call_queue, found, AST_DATA_BOOLEAN) \
MEMBER(call_queue, announcepositionlimit, AST_DATA_INTEGER) \
MEMBER(call_queue, announcefrequency, AST_DATA_SECONDS) \
MEMBER(call_queue, minannouncefrequency, AST_DATA_SECONDS) \
MEMBER(call_queue, periodicannouncefrequency, AST_DATA_SECONDS) \
MEMBER(call_queue, numperiodicannounce, AST_DATA_INTEGER) \
MEMBER(call_queue, randomperiodicannounce, AST_DATA_INTEGER) \
MEMBER(call_queue, roundingseconds, AST_DATA_SECONDS) \
MEMBER(call_queue, holdtime, AST_DATA_SECONDS) \
MEMBER(call_queue, talktime, AST_DATA_SECONDS) \
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_SECONDS) \
MEMBER(call_queue, retry, AST_DATA_SECONDS) \
MEMBER(call_queue, timeout, AST_DATA_SECONDS) \
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)
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, raise_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)
{
struct ao2_iterator im;
struct member *member;
struct queue_ent *qe;
struct ast_data *data_queue, *data_members = NULL, *enum_node;
struct ast_data *data_member, *data_callers = NULL, *data_caller, *data_caller_channel;
data_queue = ast_data_add_node(data_root, "queue");
if (!data_queue) {
return;
}
ast_data_add_structure(call_queue, data_queue, queue);
ast_data_add_str(data_queue, "strategy", int2strat(queue->strategy));
ast_data_add_int(data_queue, "membercount", ao2_container_count(queue->members));
/* announce position */
enum_node = ast_data_add_node(data_queue, "announceposition");
if (!enum_node) {
return;
}
switch (queue->announceposition) {
case ANNOUNCEPOSITION_LIMIT:
ast_data_add_str(enum_node, "text", "limit");
break;
case ANNOUNCEPOSITION_MORE_THAN:
ast_data_add_str(enum_node, "text", "more");
break;
case ANNOUNCEPOSITION_YES:
ast_data_add_str(enum_node, "text", "yes");
break;
case ANNOUNCEPOSITION_NO:
ast_data_add_str(enum_node, "text", "no");
break;
default:
ast_data_add_str(enum_node, "text", "unknown");
break;
}
ast_data_add_int(enum_node, "value", queue->announceposition);
/* add queue members */
im = ao2_iterator_init(queue->members, 0);
while ((member = ao2_iterator_next(&im))) {
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);
}
ao2_iterator_destroy(&im);
/* include the callers inside the result. */
if (queue->head) {
for (qe = queue->head; qe; qe = qe->next) {
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, 1);
}
}
/* if this queue doesn't match remove the added queue. */
if (!ast_data_search_match(search, data_queue)) {
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;
/* load realtime queues. */
cfg = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL);
if (cfg) {
char *category = NULL;
while ((category = ast_category_browse(cfg, category))) {
const char *queuename = ast_variable_retrieve(cfg, category, "name");
if ((queue = find_load_queue_rt_friendly(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 = find_load_queue_rt_friendly(queue->name);
if (!queue_realtime) {
ao2_unlock(queue);
queue_unref(queue);
continue;
}
queue_unref(queue_realtime);
}
queues_data_provider_get_helper(search, data_root, queue);
ao2_unlock(queue);
queue_unref(queue);
}
ao2_iterator_destroy(&i);
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/queue/list", &queues_data_provider),
};
static struct stasis_message_router *agent_router;
static struct stasis_forward *topic_forwarder;
@ -11222,8 +10952,6 @@ static int unload_module(void)
ast_custom_function_unregister(&queuewaitingcount_function);
ast_custom_function_unregister(&queuememberpenalty_function);
ast_data_unregister(NULL);
device_state_sub = stasis_unsubscribe_and_join(device_state_sub);
ast_extension_state_del(0, extension_state_cb);
@ -11302,8 +11030,6 @@ static int load_module(void)
reload_queue_members();
}
ast_data_register_multiple(queue_data_providers, ARRAY_LEN(queue_data_providers));
err |= ast_cli_register_multiple(cli_queue, ARRAY_LEN(cli_queue));
err |= ast_register_application_xml(app, queue_exec);
err |= ast_register_application_xml(app_aqm, aqm_exec);

View File

@ -12914,147 +12914,6 @@ static struct ast_cli_entry cli_voicemail[] = {
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_PASSWORD) \
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, fromstring, 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_PASSWORD) \
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, fromstring, 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);
/*!
* \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 int 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;
struct ast_data *data_state;
struct vm_zone *zone = NULL;
int urgentmsg = 0, newmsg = 0, oldmsg = 0;
char ext_context[256] = "";
data_user = ast_data_add_node(data_root, "user");
if (!data_user) {
return -1;
}
ast_data_add_structure(ast_vm_user, data_user, user);
AST_LIST_LOCK(&zones);
AST_LIST_TRAVERSE(&zones, zone, list) {
if (!strcmp(zone->name, user->zonetag)) {
break;
}
}
AST_LIST_UNLOCK(&zones);
/* state */
data_state = ast_data_add_node(data_user, "state");
if (!data_state) {
return -1;
}
snprintf(ext_context, sizeof(ext_context), "%s@%s", user->mailbox, user->context);
inboxcount2(ext_context, &urgentmsg, &newmsg, &oldmsg);
ast_data_add_int(data_state, "urgentmsg", urgentmsg);
ast_data_add_int(data_state, "newmsg", newmsg);
ast_data_add_int(data_state, "oldmsg", oldmsg);
if (zone) {
data_zone = ast_data_add_node(data_user, "zone");
ast_data_add_structure(vm_zone, data_zone, zone);
}
if (!ast_data_search_match(search, data_user)) {
ast_data_remove_node(data_root, data_user);
}
return 0;
}
static int vm_users_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_users_data_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = vm_users_data_provider_get
};
static const struct ast_data_entry vm_data_providers[] = {
AST_DATA_ENTRY("asterisk/application/voicemail/list", &vm_users_data_provider)
};
static void poll_subscribed_mailbox(struct mwi_sub *mwi_sub)
{
int new = 0, old = 0, urgent = 0;
@ -14997,7 +14856,6 @@ static int unload_module(void)
res |= ast_custom_function_unregister(&vm_info_acf);
res |= ast_manager_unregister("VoicemailUsersList");
res |= ast_manager_unregister("VoicemailRefresh");
res |= ast_data_unregister(NULL);
#ifdef TEST_FRAMEWORK
res |= AST_TEST_UNREGISTER(test_voicemail_vmsayname);
res |= AST_TEST_UNREGISTER(test_voicemail_msgcount);
@ -15107,7 +14965,6 @@ static int load_module(void)
}
ast_cli_register_multiple(cli_voicemail, ARRAY_LEN(cli_voicemail));
ast_data_register_multiple(vm_data_providers, ARRAY_LEN(vm_data_providers));
#ifdef TEST_FRAMEWORK
ast_install_vm_test_functions(vm_test_create_user, vm_test_destroy_user);

View File

@ -119,7 +119,6 @@
#include "asterisk/devicestate.h"
#include "asterisk/paths.h"
#include "asterisk/ccss.h"
#include "asterisk/data.h"
#include "asterisk/features_config.h"
#include "asterisk/bridge.h"
#include "asterisk/stasis_channels.h"
@ -791,78 +790,6 @@ const char * const subnames[] = {
"Threeway"
};
#define DATA_EXPORT_DAHDI_PVT(MEMBER) \
MEMBER(dahdi_pvt, cid_rxgain, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, rxgain, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, txgain, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, txdrc, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, rxdrc, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, adsi, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, answeronpolarityswitch, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, busydetect, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, callreturn, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, callwaiting, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, callwaitingcallerid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, cancallforward, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, canpark, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, confirmanswer, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, destroy, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, didtdd, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, dialednone, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, dialing, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, digital, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, dnd, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, echobreak, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, echocanbridged, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, echocanon, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, faxhandled, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, usefaxbuffers, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, bufferoverrideinuse, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, firstradio, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, hanguponpolarityswitch, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, hardwaredtmf, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, hidecallerid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, hidecalleridname, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, ignoredtmf, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, immediate, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, inalarm, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mate, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, outgoing, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, permcallwaiting, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, priindication_oob, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, priexclusive, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, pulse, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, pulsedial, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, restartpending, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, restrictcid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, threewaycalling, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, transfer, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, use_callerid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, use_callingpres, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, usedistinctiveringdetection, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, dahditrcallerid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, transfertobusy, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwimonitor_neon, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwimonitor_fsk, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwimonitor_rpas, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwimonitoractive, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwisendactive, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, inservice, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, locallyblocked, AST_DATA_UNSIGNED_INTEGER) \
MEMBER(dahdi_pvt, remotelyblocked, AST_DATA_UNSIGNED_INTEGER) \
MEMBER(dahdi_pvt, manages_span_alarms, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, use_smdi, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, context, AST_DATA_STRING) \
MEMBER(dahdi_pvt, defcontext, AST_DATA_STRING) \
MEMBER(dahdi_pvt, description, AST_DATA_STRING) \
MEMBER(dahdi_pvt, exten, AST_DATA_STRING) \
MEMBER(dahdi_pvt, language, AST_DATA_STRING) \
MEMBER(dahdi_pvt, mohinterpret, AST_DATA_STRING) \
MEMBER(dahdi_pvt, mohsuggest, AST_DATA_STRING) \
MEMBER(dahdi_pvt, parkinglot, AST_DATA_STRING)
AST_DATA_STRUCTURE(dahdi_pvt, DATA_EXPORT_DAHDI_PVT);
static struct dahdi_pvt *iflist = NULL; /*!< Main interface list start */
static struct dahdi_pvt *ifend = NULL; /*!< Main interface list end */
@ -17313,7 +17240,6 @@ static int __unload_module(void)
ast_manager_unregister("PRIDebugFileSet");
ast_manager_unregister("PRIDebugFileUnset");
#endif /* defined(HAVE_PRI) */
ast_data_unregister(NULL);
ast_channel_unregister(&dahdi_tech);
/* Hangup all interfaces if they have an owner */
@ -19355,163 +19281,6 @@ static int setup_dahdi(int reload)
return res;
}
/*!
* \internal
* \brief Callback used to generate the dahdi status tree.
* \param[in] search The search pattern tree.
* \retval NULL on error.
* \retval non-NULL The generated tree.
*/
static int dahdi_status_data_provider_get(const struct ast_data_search *search,
struct ast_data *data_root)
{
int ctl, res, span;
struct ast_data *data_span, *data_alarms;
struct dahdi_spaninfo s;
ctl = open("/dev/dahdi/ctl", O_RDWR);
if (ctl < 0) {
ast_log(LOG_ERROR, "No DAHDI found. Unable to open /dev/dahdi/ctl: %s\n", strerror(errno));
return -1;
}
for (span = 1; span < DAHDI_MAX_SPANS; ++span) {
s.spanno = span;
res = ioctl(ctl, DAHDI_SPANSTAT, &s);
if (res) {
continue;
}
data_span = ast_data_add_node(data_root, "span");
if (!data_span) {
continue;
}
ast_data_add_str(data_span, "description", s.desc);
/* insert the alarms status */
data_alarms = ast_data_add_node(data_span, "alarms");
if (!data_alarms) {
continue;
}
ast_data_add_bool(data_alarms, "BLUE", s.alarms & DAHDI_ALARM_BLUE);
ast_data_add_bool(data_alarms, "YELLOW", s.alarms & DAHDI_ALARM_YELLOW);
ast_data_add_bool(data_alarms, "RED", s.alarms & DAHDI_ALARM_RED);
ast_data_add_bool(data_alarms, "LOOPBACK", s.alarms & DAHDI_ALARM_LOOPBACK);
ast_data_add_bool(data_alarms, "RECOVER", s.alarms & DAHDI_ALARM_RECOVER);
ast_data_add_bool(data_alarms, "NOTOPEN", s.alarms & DAHDI_ALARM_NOTOPEN);
ast_data_add_int(data_span, "irqmisses", s.irqmisses);
ast_data_add_int(data_span, "bpviol", s.bpvcount);
ast_data_add_int(data_span, "crc4", s.crc4count);
ast_data_add_str(data_span, "framing", s.lineconfig & DAHDI_CONFIG_D4 ? "D4" :
s.lineconfig & DAHDI_CONFIG_ESF ? "ESF" :
s.lineconfig & DAHDI_CONFIG_CCS ? "CCS" :
"CAS");
ast_data_add_str(data_span, "coding", s.lineconfig & DAHDI_CONFIG_B8ZS ? "B8ZS" :
s.lineconfig & DAHDI_CONFIG_HDB3 ? "HDB3" :
s.lineconfig & DAHDI_CONFIG_AMI ? "AMI" :
"Unknown");
ast_data_add_str(data_span, "options", s.lineconfig & DAHDI_CONFIG_CRC4 ?
s.lineconfig & DAHDI_CONFIG_NOTOPEN ? "CRC4/YEL" : "CRC4" :
s.lineconfig & DAHDI_CONFIG_NOTOPEN ? "YEL" : "");
ast_data_add_str(data_span, "lbo", lbostr[s.lbo]);
/* if this span doesn't match remove it. */
if (!ast_data_search_match(search, data_span)) {
ast_data_remove_node(data_root, data_span);
}
}
close(ctl);
return 0;
}
/*!
* \internal
* \brief Callback used to generate the dahdi channels tree.
* \param[in] search The search pattern tree.
* \retval NULL on error.
* \retval non-NULL The generated tree.
*/
static int dahdi_channels_data_provider_get(const struct ast_data_search *search,
struct ast_data *data_root)
{
struct dahdi_pvt *tmp;
struct ast_data *data_channel;
ast_mutex_lock(&iflock);
for (tmp = iflist; tmp; tmp = tmp->next) {
data_channel = ast_data_add_node(data_root, "channel");
if (!data_channel) {
continue;
}
ast_data_add_structure(dahdi_pvt, data_channel, tmp);
/* if this channel doesn't match remove it. */
if (!ast_data_search_match(search, data_channel)) {
ast_data_remove_node(data_root, data_channel);
}
}
ast_mutex_unlock(&iflock);
return 0;
}
/*!
* \internal
* \brief Callback used to generate the dahdi channels tree.
* \param[in] search The search pattern tree.
* \retval NULL on error.
* \retval non-NULL The generated tree.
*/
static int dahdi_version_data_provider_get(const struct ast_data_search *search,
struct ast_data *data_root)
{
int pseudo_fd = -1;
struct dahdi_versioninfo vi = {
.version = "Unknown",
.echo_canceller = "Unknown"
};
if ((pseudo_fd = open("/dev/dahdi/ctl", O_RDONLY)) < 0) {
ast_log(LOG_ERROR, "Failed to open control file to get version.\n");
return -1;
}
if (ioctl(pseudo_fd, DAHDI_GETVERSION, &vi)) {
ast_log(LOG_ERROR, "Failed to get DAHDI version: %s\n", strerror(errno));
}
close(pseudo_fd);
ast_data_add_str(data_root, "value", vi.version);
ast_data_add_str(data_root, "echocanceller", vi.echo_canceller);
return 0;
}
static const struct ast_data_handler dahdi_status_data_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = dahdi_status_data_provider_get
};
static const struct ast_data_handler dahdi_channels_data_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = dahdi_channels_data_provider_get
};
static const struct ast_data_handler dahdi_version_data_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = dahdi_version_data_provider_get
};
static const struct ast_data_entry dahdi_data_providers[] = {
AST_DATA_ENTRY("asterisk/channel/dahdi/status", &dahdi_status_data_provider),
AST_DATA_ENTRY("asterisk/channel/dahdi/channels", &dahdi_channels_data_provider),
AST_DATA_ENTRY("asterisk/channel/dahdi/version", &dahdi_version_data_provider)
};
/*!
* \brief Load the module
*
@ -19608,8 +19377,6 @@ static int load_module(void)
#endif
ast_cli_register_multiple(dahdi_cli, ARRAY_LEN(dahdi_cli));
/* register all the data providers */
ast_data_register_multiple(dahdi_data_providers, ARRAY_LEN(dahdi_data_providers));
memset(round_robin, 0, sizeof(round_robin));
ast_manager_register_xml("DAHDITransfer", 0, action_transfer);
ast_manager_register_xml("DAHDIHangup", 0, action_transferhangup);

View File

@ -106,7 +106,6 @@
#include "asterisk/timing.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/test.h"
#include "asterisk/data.h"
#include "asterisk/security_events.h"
#include "asterisk/stasis_endpoints.h"
#include "asterisk/bridge.h"
@ -1950,19 +1949,6 @@ static int iax2_parse_allow_disallow(struct iax2_codec_pref *pref, iax2_format *
return res;
}
static int iax2_data_add_codecs(struct ast_data *root, const char *node_name, iax2_format formats)
{
int res;
struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!cap) {
return -1;
}
iax2_format_compatibility_bitfield2cap(formats, cap);
res = ast_data_add_codecs(root, node_name, cap);
ao2_ref(cap, -1);
return res;
}
/*!
* \note The only member of the peer passed here guaranteed to be set is the name field
*/
@ -14555,129 +14541,6 @@ static struct ast_cli_entry cli_iax2[] = {
#endif /* IAXTESTS */
};
#ifdef TEST_FRAMEWORK
AST_TEST_DEFINE(test_iax2_peers_get)
{
struct ast_data_query query = {
.path = "/asterisk/channel/iax2/peers",
.search = "peers/peer/name=test_peer_data_provider"
};
struct ast_data *node;
struct iax2_peer *peer;
switch (cmd) {
case TEST_INIT:
info->name = "iax2_peers_get_data_test";
info->category = "/main/data/iax2/peers/";
info->summary = "IAX2 peers data providers unit test";
info->description =
"Tests whether the IAX2 peers data provider implementation works as expected.";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
/* build a test peer */
peer = build_peer("test_peer_data_provider", NULL, NULL, 0);
if (!peer) {
return AST_TEST_FAIL;
}
peer->expiry= 1010;
ao2_link(peers, peer);
node = ast_data_get(&query);
if (!node) {
ao2_unlink(peers, peer);
peer_unref(peer);
return AST_TEST_FAIL;
}
/* check returned data node. */
if (strcmp(ast_data_retrieve_string(node, "peer/name"), "test_peer_data_provider")) {
ao2_unlink(peers, peer);
peer_unref(peer);
ast_data_free(node);
return AST_TEST_FAIL;
}
if (ast_data_retrieve_int(node, "peer/expiry") != 1010) {
ao2_unlink(peers, peer);
peer_unref(peer);
ast_data_free(node);
return AST_TEST_FAIL;
}
/* release resources */
ast_data_free(node);
ao2_unlink(peers, peer);
peer_unref(peer);
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_iax2_users_get)
{
struct ast_data_query query = {
.path = "/asterisk/channel/iax2/users",
.search = "users/user/name=test_user_data_provider"
};
struct ast_data *node;
struct iax2_user *user;
switch (cmd) {
case TEST_INIT:
info->name = "iax2_users_get_data_test";
info->category = "/main/data/iax2/users/";
info->summary = "IAX2 users data providers unit test";
info->description =
"Tests whether the IAX2 users data provider implementation works as expected.";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
user = build_user("test_user_data_provider", NULL, NULL, 0);
if (!user) {
ast_test_status_update(test, "Failed to build a test user\n");
return AST_TEST_FAIL;
}
user->amaflags = 1010;
ao2_link(users, user);
node = ast_data_get(&query);
if (!node) {
ast_test_status_update(test, "The data query to find our test user failed\n");
ao2_unlink(users, user);
user_unref(user);
return AST_TEST_FAIL;
}
if (strcmp(ast_data_retrieve_string(node, "user/name"), "test_user_data_provider")) {
ast_test_status_update(test, "Our data results did not return the test user created in the previous step.\n");
ao2_unlink(users, user);
user_unref(user);
ast_data_free(node);
return AST_TEST_FAIL;
}
if (ast_data_retrieve_int(node, "user/amaflags/value") != 1010) {
ast_test_status_update(test, "The amaflags field in our test user was '%d' not the expected value '1010'\n", ast_data_retrieve_int(node, "user/amaflags/value"));
ao2_unlink(users, user);
user_unref(user);
ast_data_free(node);
return AST_TEST_FAIL;
}
ast_data_free(node);
ao2_unlink(users, user);
user_unref(user);
return AST_TEST_PASS;
}
#endif
static void cleanup_thread_list(void *head)
{
AST_LIST_HEAD(iax2_thread_list, iax2_thread);
@ -14743,11 +14606,6 @@ static int __unload_module(void)
ast_manager_unregister( "IAXnetstats" );
ast_manager_unregister( "IAXregistry" );
ast_unregister_application(papp);
#ifdef TEST_FRAMEWORK
AST_TEST_UNREGISTER(test_iax2_peers_get);
AST_TEST_UNREGISTER(test_iax2_users_get);
#endif
ast_data_unregister(NULL);
ast_cli_unregister_multiple(cli_iax2, ARRAY_LEN(cli_iax2));
ast_unregister_switch(&iax2_switch);
ast_channel_unregister(&iax2_tech);
@ -14889,191 +14747,6 @@ container_fail:
return -1;
}
#define DATA_EXPORT_IAX2_PEER(MEMBER) \
MEMBER(iax2_peer, name, AST_DATA_STRING) \
MEMBER(iax2_peer, username, AST_DATA_STRING) \
MEMBER(iax2_peer, secret, AST_DATA_PASSWORD) \
MEMBER(iax2_peer, dbsecret, AST_DATA_PASSWORD) \
MEMBER(iax2_peer, outkey, AST_DATA_STRING) \
MEMBER(iax2_peer, regexten, AST_DATA_STRING) \
MEMBER(iax2_peer, context, AST_DATA_STRING) \
MEMBER(iax2_peer, peercontext, AST_DATA_STRING) \
MEMBER(iax2_peer, mailbox, AST_DATA_STRING) \
MEMBER(iax2_peer, mohinterpret, AST_DATA_STRING) \
MEMBER(iax2_peer, mohsuggest, AST_DATA_STRING) \
MEMBER(iax2_peer, inkeys, AST_DATA_STRING) \
MEMBER(iax2_peer, cid_num, AST_DATA_STRING) \
MEMBER(iax2_peer, cid_name, AST_DATA_STRING) \
MEMBER(iax2_peer, zonetag, AST_DATA_STRING) \
MEMBER(iax2_peer, parkinglot, AST_DATA_STRING) \
MEMBER(iax2_peer, expiry, AST_DATA_SECONDS) \
MEMBER(iax2_peer, callno, AST_DATA_INTEGER) \
MEMBER(iax2_peer, lastms, AST_DATA_MILLISECONDS) \
MEMBER(iax2_peer, maxms, AST_DATA_MILLISECONDS) \
MEMBER(iax2_peer, pokefreqok, AST_DATA_MILLISECONDS) \
MEMBER(iax2_peer, pokefreqnotok, AST_DATA_MILLISECONDS) \
MEMBER(iax2_peer, historicms, AST_DATA_INTEGER) \
MEMBER(iax2_peer, smoothing, AST_DATA_BOOLEAN) \
MEMBER(iax2_peer, maxcallno, AST_DATA_INTEGER)
AST_DATA_STRUCTURE(iax2_peer, DATA_EXPORT_IAX2_PEER);
static int peers_data_provider_get(const struct ast_data_search *search,
struct ast_data *data_root)
{
struct ast_data *data_peer;
struct iax2_peer *peer;
struct ao2_iterator i;
char status[20];
struct ast_str *encmethods = ast_str_alloca(256);
i = ao2_iterator_init(peers, 0);
while ((peer = ao2_iterator_next(&i))) {
data_peer = ast_data_add_node(data_root, "peer");
if (!data_peer) {
peer_unref(peer);
continue;
}
ast_data_add_structure(iax2_peer, data_peer, peer);
iax2_data_add_codecs(data_peer, "codecs", peer->capability);
peer_status(peer, status, sizeof(status));
ast_data_add_str(data_peer, "status", status);
ast_data_add_str(data_peer, "host", ast_sockaddr_stringify_host(&peer->addr));
ast_data_add_str(data_peer, "mask", ast_sockaddr_stringify_addr(&peer->mask));
ast_data_add_int(data_peer, "port", ast_sockaddr_port(&peer->addr));
ast_data_add_bool(data_peer, "trunk", ast_test_flag64(peer, IAX_TRUNK));
ast_data_add_bool(data_peer, "dynamic", ast_test_flag64(peer, IAX_DYNAMIC));
encmethods_to_str(peer->encmethods, &encmethods);
ast_data_add_str(data_peer, "encryption", peer->encmethods ? ast_str_buffer(encmethods) : "no");
peer_unref(peer);
if (!ast_data_search_match(search, data_peer)) {
ast_data_remove_node(data_root, data_peer);
}
}
ao2_iterator_destroy(&i);
return 0;
}
#define DATA_EXPORT_IAX2_USER(MEMBER) \
MEMBER(iax2_user, name, AST_DATA_STRING) \
MEMBER(iax2_user, dbsecret, AST_DATA_PASSWORD) \
MEMBER(iax2_user, accountcode, AST_DATA_STRING) \
MEMBER(iax2_user, mohinterpret, AST_DATA_STRING) \
MEMBER(iax2_user, mohsuggest, AST_DATA_STRING) \
MEMBER(iax2_user, inkeys, AST_DATA_STRING) \
MEMBER(iax2_user, language, AST_DATA_STRING) \
MEMBER(iax2_user, cid_num, AST_DATA_STRING) \
MEMBER(iax2_user, cid_name, AST_DATA_STRING) \
MEMBER(iax2_user, parkinglot, AST_DATA_STRING) \
MEMBER(iax2_user, maxauthreq, AST_DATA_INTEGER) \
MEMBER(iax2_user, curauthreq, AST_DATA_INTEGER)
AST_DATA_STRUCTURE(iax2_user, DATA_EXPORT_IAX2_USER);
static int users_data_provider_get(const struct ast_data_search *search,
struct ast_data *data_root)
{
struct ast_data *data_user, *data_authmethods, *data_enum_node;
struct iax2_user *user;
struct ao2_iterator i;
struct ast_str *auth;
char *pstr = "";
if (!(auth = ast_str_create(90))) {
ast_log(LOG_ERROR, "Unable to create temporary string for storing 'secret'\n");
return 0;
}
i = ao2_iterator_init(users, 0);
for (; (user = ao2_iterator_next(&i)); user_unref(user)) {
data_user = ast_data_add_node(data_root, "user");
if (!data_user) {
continue;
}
ast_data_add_structure(iax2_user, data_user, user);
iax2_data_add_codecs(data_user, "codecs", user->capability);
if (!ast_strlen_zero(user->secret)) {
ast_str_set(&auth, 0, "%s", user->secret);
} else if (!ast_strlen_zero(user->inkeys)) {
ast_str_set(&auth, 0, "Key: %s", user->inkeys);
} else {
ast_str_set(&auth, 0, "no secret");
}
ast_data_add_password(data_user, "secret", ast_str_buffer(auth));
ast_data_add_str(data_user, "context", user->contexts ? user->contexts->context : DEFAULT_CONTEXT);
/* authmethods */
data_authmethods = ast_data_add_node(data_user, "authmethods");
if (!data_authmethods) {
ast_data_remove_node(data_root, data_user);
continue;
}
ast_data_add_bool(data_authmethods, "rsa", user->authmethods & IAX_AUTH_RSA);
ast_data_add_bool(data_authmethods, "md5", user->authmethods & IAX_AUTH_MD5);
ast_data_add_bool(data_authmethods, "plaintext", user->authmethods & IAX_AUTH_PLAINTEXT);
/* amaflags */
data_enum_node = ast_data_add_node(data_user, "amaflags");
if (!data_enum_node) {
ast_data_remove_node(data_root, data_user);
continue;
}
ast_data_add_int(data_enum_node, "value", user->amaflags);
ast_data_add_str(data_enum_node, "text", ast_channel_amaflags2string(user->amaflags));
ast_data_add_bool(data_user, "access-control", ast_acl_list_is_empty(user->acl) ? 0 : 1);
if (ast_test_flag64(user, IAX_CODEC_NOCAP)) {
pstr = "REQ only";
} else if (ast_test_flag64(user, IAX_CODEC_NOPREFS)) {
pstr = "disabled";
} else {
pstr = ast_test_flag64(user, IAX_CODEC_USER_FIRST) ? "caller" : "host";
}
ast_data_add_str(data_user, "codec-preferences", pstr);
if (!ast_data_search_match(search, data_user)) {
ast_data_remove_node(data_root, data_user);
}
}
ao2_iterator_destroy(&i);
ast_free(auth);
return 0;
}
static const struct ast_data_handler peers_data_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = peers_data_provider_get
};
static const struct ast_data_handler users_data_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = users_data_provider_get
};
static const struct ast_data_entry iax2_data_providers[] = {
AST_DATA_ENTRY("asterisk/channel/iax2/peers", &peers_data_provider),
AST_DATA_ENTRY("asterisk/channel/iax2/users", &users_data_provider),
};
/*!
* \brief Load the module
*
@ -15173,13 +14846,6 @@ static int load_module(void)
return AST_MODULE_LOAD_DECLINE;
}
#ifdef TEST_FRAMEWORK
AST_TEST_REGISTER(test_iax2_peers_get);
AST_TEST_REGISTER(test_iax2_users_get);
#endif
/* Register AstData providers */
ast_data_register_multiple(iax2_data_providers, ARRAY_LEN(iax2_data_providers));
ast_cli_register_multiple(cli_iax2, ARRAY_LEN(cli_iax2));
ast_register_application_xml(papp, iax2_prov_app);

View File

@ -263,7 +263,6 @@
#include "asterisk/threadstorage.h"
#include "asterisk/translate.h"
#include "asterisk/ast_version.h"
#include "asterisk/data.h"
#include "asterisk/aoc.h"
#include "asterisk/message.h"
#include "sip/include/sip.h"
@ -34530,75 +34529,6 @@ AST_TEST_DEFINE(test_sip_mwi_subscribe_parse)
return res;
}
AST_TEST_DEFINE(test_sip_peers_get)
{
struct sip_peer *peer;
struct ast_data *node;
struct ast_data_query query = {
.path = "/asterisk/channel/sip/peers",
.search = "peers/peer/name=test_peer_data_provider"
};
switch (cmd) {
case TEST_INIT:
info->name = "sip_peers_get_data_test";
info->category = "/main/data/sip/peers/";
info->summary = "SIP peers data providers unit test";
info->description =
"Tests whether the SIP peers data provider implementation works as expected.";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
/* Create the peer that we will retrieve. */
peer = build_peer("test_peer_data_provider", NULL, NULL, 0, 0);
if (!peer) {
return AST_TEST_FAIL;
}
peer->type = SIP_TYPE_USER;
peer->call_limit = 10;
ao2_link(peers, peer);
/* retrieve the chan_sip/peers tree and check the created peer. */
node = ast_data_get(&query);
if (!node) {
ao2_unlink(peers, peer);
ao2_ref(peer, -1);
return AST_TEST_FAIL;
}
/* compare item. */
if (strcmp(ast_data_retrieve_string(node, "peer/name"), "test_peer_data_provider")) {
ao2_unlink(peers, peer);
ao2_ref(peer, -1);
ast_data_free(node);
return AST_TEST_FAIL;
}
if (strcmp(ast_data_retrieve_string(node, "peer/type"), "user")) {
ao2_unlink(peers, peer);
ao2_ref(peer, -1);
ast_data_free(node);
return AST_TEST_FAIL;
}
if (ast_data_retrieve_int(node, "peer/call_limit") != 10) {
ao2_unlink(peers, peer);
ao2_ref(peer, -1);
ast_data_free(node);
return AST_TEST_FAIL;
}
/* release resources */
ast_data_free(node);
ao2_unlink(peers, peer);
ao2_ref(peer, -1);
return AST_TEST_PASS;
}
/*!
* \brief Imitation TCP reception loop
*
@ -35130,170 +35060,6 @@ AST_TEST_DEFINE(get_in_brackets_const_test)
#endif
#define DATA_EXPORT_SIP_PEER(MEMBER) \
MEMBER(sip_peer, name, AST_DATA_STRING) \
MEMBER(sip_peer, secret, AST_DATA_PASSWORD) \
MEMBER(sip_peer, md5secret, AST_DATA_PASSWORD) \
MEMBER(sip_peer, remotesecret, AST_DATA_PASSWORD) \
MEMBER(sip_peer, context, AST_DATA_STRING) \
MEMBER(sip_peer, subscribecontext, AST_DATA_STRING) \
MEMBER(sip_peer, username, AST_DATA_STRING) \
MEMBER(sip_peer, accountcode, AST_DATA_STRING) \
MEMBER(sip_peer, tohost, AST_DATA_STRING) \
MEMBER(sip_peer, regexten, AST_DATA_STRING) \
MEMBER(sip_peer, fromuser, AST_DATA_STRING) \
MEMBER(sip_peer, fromdomain, AST_DATA_STRING) \
MEMBER(sip_peer, fullcontact, AST_DATA_STRING) \
MEMBER(sip_peer, cid_num, AST_DATA_STRING) \
MEMBER(sip_peer, cid_name, AST_DATA_STRING) \
MEMBER(sip_peer, vmexten, AST_DATA_STRING) \
MEMBER(sip_peer, language, AST_DATA_STRING) \
MEMBER(sip_peer, mohinterpret, AST_DATA_STRING) \
MEMBER(sip_peer, mohsuggest, AST_DATA_STRING) \
MEMBER(sip_peer, parkinglot, AST_DATA_STRING) \
MEMBER(sip_peer, useragent, AST_DATA_STRING) \
MEMBER(sip_peer, mwi_from, AST_DATA_STRING) \
MEMBER(sip_peer, engine, AST_DATA_STRING) \
MEMBER(sip_peer, unsolicited_mailbox, AST_DATA_STRING) \
MEMBER(sip_peer, is_realtime, AST_DATA_BOOLEAN) \
MEMBER(sip_peer, host_dynamic, AST_DATA_BOOLEAN) \
MEMBER(sip_peer, autoframing, AST_DATA_BOOLEAN) \
MEMBER(sip_peer, inuse, AST_DATA_INTEGER) \
MEMBER(sip_peer, ringing, AST_DATA_INTEGER) \
MEMBER(sip_peer, onhold, AST_DATA_INTEGER) \
MEMBER(sip_peer, call_limit, AST_DATA_INTEGER) \
MEMBER(sip_peer, t38_maxdatagram, AST_DATA_INTEGER) \
MEMBER(sip_peer, maxcallbitrate, AST_DATA_INTEGER) \
MEMBER(sip_peer, rtptimeout, AST_DATA_SECONDS) \
MEMBER(sip_peer, rtpholdtimeout, AST_DATA_SECONDS) \
MEMBER(sip_peer, rtpkeepalive, AST_DATA_SECONDS) \
MEMBER(sip_peer, lastms, AST_DATA_MILLISECONDS) \
MEMBER(sip_peer, maxms, AST_DATA_MILLISECONDS) \
MEMBER(sip_peer, qualifyfreq, AST_DATA_MILLISECONDS) \
MEMBER(sip_peer, timer_t1, AST_DATA_MILLISECONDS) \
MEMBER(sip_peer, timer_b, AST_DATA_MILLISECONDS) \
MEMBER(sip_peer, description, AST_DATA_STRING)
AST_DATA_STRUCTURE(sip_peer, DATA_EXPORT_SIP_PEER);
static int peers_data_provider_get(const struct ast_data_search *search,
struct ast_data *data_root)
{
struct sip_peer *peer;
struct ao2_iterator i;
struct ast_data *data_peer, *data_peer_mailboxes = NULL, *data_peer_mailbox, *enum_node;
struct ast_data *data_sip_options;
int total_mailboxes, x;
struct sip_mailbox *mailbox;
i = ao2_iterator_init(peers, 0);
while ((peer = ao2_iterator_next(&i))) {
ao2_lock(peer);
data_peer = ast_data_add_node(data_root, "peer");
if (!data_peer) {
ao2_unlock(peer);
ao2_ref(peer, -1);
continue;
}
ast_data_add_structure(sip_peer, data_peer, peer);
/* transfer mode */
enum_node = ast_data_add_node(data_peer, "allowtransfer");
if (!enum_node) {
ao2_unlock(peer);
ao2_ref(peer, -1);
continue;
}
ast_data_add_str(enum_node, "text", transfermode2str(peer->allowtransfer));
ast_data_add_int(enum_node, "value", peer->allowtransfer);
/* transports */
ast_data_add_str(data_peer, "transports", get_transport_list(peer->transports));
/* peer type */
if ((peer->type & SIP_TYPE_USER) && (peer->type & SIP_TYPE_PEER)) {
ast_data_add_str(data_peer, "type", "friend");
} else if (peer->type & SIP_TYPE_PEER) {
ast_data_add_str(data_peer, "type", "peer");
} else if (peer->type & SIP_TYPE_USER) {
ast_data_add_str(data_peer, "type", "user");
}
/* mailboxes */
total_mailboxes = 0;
AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
if (!total_mailboxes) {
data_peer_mailboxes = ast_data_add_node(data_peer, "mailboxes");
if (!data_peer_mailboxes) {
break;
}
total_mailboxes++;
}
data_peer_mailbox = ast_data_add_node(data_peer_mailboxes, "mailbox");
if (!data_peer_mailbox) {
continue;
}
ast_data_add_str(data_peer_mailbox, "id", mailbox->id);
}
/* amaflags */
enum_node = ast_data_add_node(data_peer, "amaflags");
if (!enum_node) {
ao2_unlock(peer);
ao2_ref(peer, -1);
continue;
}
ast_data_add_int(enum_node, "value", peer->amaflags);
ast_data_add_str(enum_node, "text", ast_channel_amaflags2string(peer->amaflags));
/* sip options */
data_sip_options = ast_data_add_node(data_peer, "sipoptions");
if (!data_sip_options) {
ao2_unlock(peer);
ao2_ref(peer, -1);
continue;
}
for (x = 0 ; x < ARRAY_LEN(sip_options); x++) {
ast_data_add_bool(data_sip_options, sip_options[x].text, peer->sipoptions & sip_options[x].id);
}
/* callingpres */
enum_node = ast_data_add_node(data_peer, "callingpres");
if (!enum_node) {
ao2_unlock(peer);
ao2_ref(peer, -1);
continue;
}
ast_data_add_int(enum_node, "value", peer->callingpres);
ast_data_add_str(enum_node, "text", ast_describe_caller_presentation(peer->callingpres));
/* codecs */
ast_data_add_codecs(data_peer, "codecs", peer->caps);
if (!ast_data_search_match(search, data_peer)) {
ast_data_remove_node(data_root, data_peer);
}
ao2_unlock(peer);
ao2_ref(peer, -1);
}
ao2_iterator_destroy(&i);
return 0;
}
static const struct ast_data_handler peers_data_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = peers_data_provider_get
};
static const struct ast_data_entry sip_data_providers[] = {
AST_DATA_ENTRY("asterisk/channel/sip/peers", &peers_data_provider),
};
static const struct ast_sip_api_tech chan_sip_api_provider = {
.version = AST_SIP_API_VERSION,
.name = "chan_sip",
@ -35414,15 +35180,11 @@ static int load_module(void)
}
#ifdef TEST_FRAMEWORK
AST_TEST_REGISTER(test_sip_peers_get);
AST_TEST_REGISTER(test_sip_mwi_subscribe_parse);
AST_TEST_REGISTER(test_tcp_message_fragmentation);
AST_TEST_REGISTER(get_in_brackets_const_test);
#endif
/* Register AstData providers */
ast_data_register_multiple(sip_data_providers, ARRAY_LEN(sip_data_providers));
/* Register all CLI functions for SIP */
ast_cli_register_multiple(cli_sip, ARRAY_LEN(cli_sip));
@ -35549,14 +35311,10 @@ static int unload_module(void)
#ifdef TEST_FRAMEWORK
ast_unregister_application(app_sipsendcustominfo);
AST_TEST_UNREGISTER(test_sip_peers_get);
AST_TEST_UNREGISTER(test_sip_mwi_subscribe_parse);
AST_TEST_UNREGISTER(test_tcp_message_fragmentation);
AST_TEST_UNREGISTER(get_in_brackets_const_test);
#endif
/* Unregister all the AstData providers */
ast_data_unregister(NULL);
/* Unregister CLI commands */
ast_cli_unregister_multiple(cli_sip, ARRAY_LEN(cli_sip));

View File

@ -44,7 +44,6 @@ int ast_named_locks_init(void); /*!< Provided by named_locks.c */
int ast_file_init(void); /*!< Provided by file.c */
int ast_features_init(void); /*!< Provided by features.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_reload(void); /*!< Provided by http.c */
int ast_tps_init(void); /*!< Provided by taskprocessor.c */

View File

@ -174,7 +174,7 @@ extern "C" {
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/datastore.h"
#include "asterisk/data.h"
#include "asterisk/format_cap.h"
#include "asterisk/channelstate.h"
#include "asterisk/ccss.h"
#include "asterisk/framehook.h"
@ -3838,27 +3838,6 @@ int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struc
*/
int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, 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.
* \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 add_bridged);
/*!
* \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);
/*!
* \since 1.8
* \brief Run a redirecting interception macro and update a channel's redirecting information

View File

@ -1,828 +0,0 @@
/*
* 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
#include "asterisk/frame.h"
#include "asterisk/format_cap.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
* };
*
* internal_node = ast_data_add_node(root_node, "test_node");
* if (!internal_node) {
* return -1;
* }
*
* 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;
* }
*
* \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_CHARACTER,
AST_DATA_PASSWORD,
AST_DATA_IPADDR,
AST_DATA_TIMESTAMP,
AST_DATA_SECONDS,
AST_DATA_MILLISECONDS,
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_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;
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_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);
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_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) \
__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_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_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 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_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.
* \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 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);
#ifdef HAVE_LIBXML2
/*!
* \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);
#endif
/*!
* \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 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.
* \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 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.
* \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_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] boolean 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 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.
* \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 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.
* \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;
}
/*!
* \brief Add the codec in the root node based on the format parameter.
* \param[in] root The astdata root node where to add the codec node.
* \param[in] node_name The name of the node where we are going to add the codec.
* \param[in] format The codec allowed.
* \return < 0 on error.
* \return 0 on success.
*/
int ast_data_add_codec(struct ast_data *root, const char *node_name, struct ast_format *format);
/*!
* \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, struct ast_format_cap *capability);
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#endif /* ASTERISK_DATA_H */

View File

@ -28,7 +28,6 @@
#include "asterisk/astobj2.h"
#include "asterisk/utils.h"
#include "asterisk/data.h"
/*!
* \brief Description of a tone
@ -242,12 +241,4 @@ 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 */

View File

@ -4560,7 +4560,6 @@ static void asterisk_daemon(int isroot, const char *runuser, const char *rungrou
check_init(app_init(), "App Core");
check_init(devstate_init(), "Device State Core");
check_init(ast_msg_init(), "Messaging API");
check_init(ast_data_init(), "Data Retrieval API");
check_init(ast_channels_init(), "Channel");
check_init(ast_endpoint_init(), "Endpoints");
check_init(ast_pickup_init(), "Call Pickup");

View File

@ -60,7 +60,6 @@
#include "asterisk/config.h"
#include "asterisk/cli.h"
#include "asterisk/stringfields.h"
#include "asterisk/data.h"
#include "asterisk/config_options.h"
#include "asterisk/json.h"
#include "asterisk/parking.h"

View File

@ -66,7 +66,6 @@
#include "asterisk/autochan.h"
#include "asterisk/stringfields.h"
#include "asterisk/global_datastores.h"
#include "asterisk/data.h"
#include "asterisk/channel_internal.h"
#include "asterisk/features.h"
#include "asterisk/bridge.h"
@ -7568,122 +7567,6 @@ int ast_plc_reload(void)
return 0;
}
/*!
* \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;
struct ast_channel_iterator *iter = NULL;
struct ast_data *data_channel;
for (iter = ast_channel_iterator_all_new();
iter && (c = ast_channel_iterator_next(iter)); ast_channel_unref(c)) {
ast_channel_lock(c);
data_channel = ast_data_add_node(root, "channel");
if (!data_channel) {
ast_channel_unlock(c);
continue;
}
if (ast_channel_data_add_structure(data_channel, c, 1) < 0) {
ast_log(LOG_ERROR, "Unable to add channel structure for channel: %s\n", ast_channel_name(c));
}
ast_channel_unlock(c);
if (!ast_data_search_match(search, data_channel)) {
ast_data_remove_node(root, data_channel);
}
}
if (iter) {
ast_channel_iterator_destroy(iter);
}
return 0;
}
/*!
* \internal
* \brief Implements the channeltypes provider.
*/
static int data_channeltypes_provider_handler(const struct ast_data_search *search,
struct ast_data *data_root)
{
struct chanlist *cl;
struct ast_data *data_type;
AST_RWLIST_RDLOCK(&backends);
AST_RWLIST_TRAVERSE(&backends, cl, list) {
data_type = ast_data_add_node(data_root, "type");
if (!data_type) {
continue;
}
ast_data_add_str(data_type, "name", cl->tech->type);
ast_data_add_str(data_type, "description", cl->tech->description);
ast_data_add_bool(data_type, "devicestate", cl->tech->devicestate ? 1 : 0);
ast_data_add_bool(data_type, "presencestate", cl->tech->presencestate ? 1 : 0);
ast_data_add_bool(data_type, "indications", cl->tech->indicate ? 1 : 0);
ast_data_add_bool(data_type, "transfer", cl->tech->transfer ? 1 : 0);
ast_data_add_bool(data_type, "send_digit_begin", cl->tech->send_digit_begin ? 1 : 0);
ast_data_add_bool(data_type, "send_digit_end", cl->tech->send_digit_end ? 1 : 0);
ast_data_add_bool(data_type, "call", cl->tech->call ? 1 : 0);
ast_data_add_bool(data_type, "hangup", cl->tech->hangup ? 1 : 0);
ast_data_add_bool(data_type, "answer", cl->tech->answer ? 1 : 0);
ast_data_add_bool(data_type, "read", cl->tech->read ? 1 : 0);
ast_data_add_bool(data_type, "write", cl->tech->write ? 1 : 0);
ast_data_add_bool(data_type, "send_text", cl->tech->send_text ? 1 : 0);
ast_data_add_bool(data_type, "send_image", cl->tech->send_image ? 1 : 0);
ast_data_add_bool(data_type, "send_html", cl->tech->send_html ? 1 : 0);
ast_data_add_bool(data_type, "exception", cl->tech->exception ? 1 : 0);
ast_data_add_bool(data_type, "early_bridge", cl->tech->early_bridge ? 1 : 0);
ast_data_add_bool(data_type, "fixup", cl->tech->fixup ? 1 : 0);
ast_data_add_bool(data_type, "setoption", cl->tech->setoption ? 1 : 0);
ast_data_add_bool(data_type, "queryoption", cl->tech->queryoption ? 1 : 0);
ast_data_add_bool(data_type, "write_video", cl->tech->write_video ? 1 : 0);
ast_data_add_bool(data_type, "write_text", cl->tech->write_text ? 1 : 0);
ast_data_add_bool(data_type, "func_channel_read", cl->tech->func_channel_read ? 1 : 0);
ast_data_add_bool(data_type, "func_channel_write", cl->tech->func_channel_write ? 1 : 0);
ast_data_add_bool(data_type, "get_pvt_uniqueid", cl->tech->get_pvt_uniqueid ? 1 : 0);
ast_data_add_bool(data_type, "cc_callback", cl->tech->cc_callback ? 1 : 0);
ast_data_add_codecs(data_type, "capabilities", cl->tech->capabilities);
if (!ast_data_search_match(search, data_type)) {
ast_data_remove_node(data_root, data_type);
}
}
AST_RWLIST_UNLOCK(&backends);
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
};
/*!
* \internal
* \brief /asterisk/core/channeltypes provider.
*/
static const struct ast_data_handler channeltypes_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = data_channeltypes_provider_handler
};
static const struct ast_data_entry channel_providers[] = {
AST_DATA_ENTRY("/asterisk/core/channels", &channels_provider),
AST_DATA_ENTRY("/asterisk/core/channeltypes", &channeltypes_provider),
};
/*!
* \internal
* \brief Print channel object key (name).
@ -7883,7 +7766,6 @@ static void channels_shutdown(void)
free_external_channelvars(&ami_vars);
free_external_channelvars(&ari_vars);
ast_data_unregister(NULL);
ast_cli_unregister_multiple(cli_channel, ARRAY_LEN(cli_channel));
if (channels) {
ao2_container_unregister("channels");
@ -7908,8 +7790,6 @@ int ast_channels_init(void)
ast_cli_register_multiple(cli_channel, ARRAY_LEN(cli_channel));
ast_data_register_multiple_core(channel_providers, ARRAY_LEN(channel_providers));
ast_plc_reload();
ast_register_cleanup(channels_shutdown);

View File

@ -40,7 +40,6 @@
#include "asterisk/paths.h"
#include "asterisk/channel.h"
#include "asterisk/channel_internal.h"
#include "asterisk/data.h"
#include "asterisk/endpoints.h"
#include "asterisk/indications.h"
#include "asterisk/stasis_cache_pattern.h"
@ -226,211 +225,6 @@ struct ast_channel {
/*! \brief The monotonically increasing integer counter for channel uniqueids */
static int uniqueint;
/* AST_DATA definitions, which will probably have to be re-thought since the channel will be opaque */
#if 0 /* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
#define DATA_EXPORT_CALLERID(MEMBER) \
MEMBER(ast_callerid, cid_dnid, AST_DATA_STRING) \
MEMBER(ast_callerid, cid_num, AST_DATA_STRING) \
MEMBER(ast_callerid, cid_name, AST_DATA_STRING) \
MEMBER(ast_callerid, cid_ani, AST_DATA_STRING) \
MEMBER(ast_callerid, cid_pres, AST_DATA_INTEGER) \
MEMBER(ast_callerid, cid_ani2, AST_DATA_INTEGER) \
MEMBER(ast_callerid, cid_tag, AST_DATA_STRING)
AST_DATA_STRUCTURE(ast_callerid, DATA_EXPORT_CALLERID);
#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, parkinglot, AST_DATA_STRING) \
MEMBER(ast_channel, hangupsource, AST_DATA_STRING) \
MEMBER(ast_channel, dialcontext, AST_DATA_STRING) \
MEMBER(ast_channel, rings, AST_DATA_INTEGER) \
MEMBER(ast_channel, priority, AST_DATA_INTEGER) \
MEMBER(ast_channel, macropriority, 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, emulate_dtmf_duration, AST_DATA_UNSIGNED_INTEGER) \
MEMBER(ast_channel, visible_indication, 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);
static void channel_data_add_flags(struct ast_data *tree,
struct ast_channel *chan)
{
ast_data_add_bool(tree, "DEFER_DTMF", ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_DTMF));
ast_data_add_bool(tree, "WRITE_INT", ast_test_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT));
ast_data_add_bool(tree, "BLOCKING", ast_test_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING));
ast_data_add_bool(tree, "ZOMBIE", ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE));
ast_data_add_bool(tree, "EXCEPTION", ast_test_flag(ast_channel_flags(chan), AST_FLAG_EXCEPTION));
ast_data_add_bool(tree, "MOH", ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH));
ast_data_add_bool(tree, "SPYING", ast_test_flag(ast_channel_flags(chan), AST_FLAG_SPYING));
ast_data_add_bool(tree, "IN_AUTOLOOP", ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP));
ast_data_add_bool(tree, "OUTGOING", ast_test_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING));
ast_data_add_bool(tree, "IN_DTMF", ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF));
ast_data_add_bool(tree, "EMULATE_DTMF", ast_test_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF));
ast_data_add_bool(tree, "END_DTMF_ONLY", ast_test_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY));
ast_data_add_bool(tree, "MASQ_NOSTREAM", ast_test_flag(ast_channel_flags(chan), AST_FLAG_MASQ_NOSTREAM));
ast_data_add_bool(tree, "BRIDGE_HANGUP_RUN", ast_test_flag(ast_channel_flags(chan), AST_FLAG_BRIDGE_HANGUP_RUN));
ast_data_add_bool(tree, "DISABLE_WORKAROUNDS", ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_WORKAROUNDS));
ast_data_add_bool(tree, "DISABLE_DEVSTATE_CACHE", ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE));
ast_data_add_bool(tree, "BRIDGE_DUAL_REDIRECT_WAIT", ast_test_flag(ast_channel_flags(chan), AST_FLAG_BRIDGE_DUAL_REDIRECT_WAIT));
ast_data_add_bool(tree, "ORIGINATED", ast_test_flag(ast_channel_flags(chan), AST_FLAG_ORIGINATED));
ast_data_add_bool(tree, "DEAD", ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEAD));
}
int ast_channel_data_add_structure(struct ast_data *tree,
struct ast_channel *chan, int add_bridged)
{
struct ast_data *data_bridged;
struct ast_data *data_cdr;
struct ast_data *data_flags;
struct ast_data *data_zones;
struct ast_data *enum_node;
struct ast_data *data_softhangup;
#if 0 /* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
struct ast_data *data_callerid;
char value_str[100];
#endif
if (!tree) {
return -1;
}
ast_data_add_structure(ast_channel, tree, chan);
if (add_bridged) {
RAII_VAR(struct ast_channel *, bc, ast_channel_bridge_peer(chan), ast_channel_cleanup);
if (bc) {
data_bridged = ast_data_add_node(tree, "bridged");
if (!data_bridged) {
return -1;
}
ast_channel_data_add_structure(data_bridged, bc, 0);
}
}
ast_data_add_str(tree, "uniqueid", ast_channel_uniqueid(chan));
ast_data_add_str(tree, "linkedid", ast_channel_linkedid(chan));
ast_data_add_codec(tree, "oldwriteformat", ast_channel_oldwriteformat(chan));
ast_data_add_codec(tree, "readformat", ast_channel_readformat(chan));
ast_data_add_codec(tree, "writeformat", ast_channel_writeformat(chan));
ast_data_add_codec(tree, "rawreadformat", ast_channel_rawreadformat(chan));
ast_data_add_codec(tree, "rawwriteformat", ast_channel_rawwriteformat(chan));
ast_data_add_codecs(tree, "nativeformats", ast_channel_nativeformats(chan));
/* state */
enum_node = ast_data_add_node(tree, "state");
if (!enum_node) {
return -1;
}
ast_data_add_str(enum_node, "text", ast_state2str(ast_channel_state(chan)));
ast_data_add_int(enum_node, "value", ast_channel_state(chan));
/* hangupcause */
enum_node = ast_data_add_node(tree, "hangupcause");
if (!enum_node) {
return -1;
}
ast_data_add_str(enum_node, "text", ast_cause2str(ast_channel_hangupcause(chan)));
ast_data_add_int(enum_node, "value", ast_channel_hangupcause(chan));
/* amaflags */
enum_node = ast_data_add_node(tree, "amaflags");
if (!enum_node) {
return -1;
}
ast_data_add_str(enum_node, "text", ast_channel_amaflags2string(ast_channel_amaflags(chan)));
ast_data_add_int(enum_node, "value", ast_channel_amaflags(chan));
/* transfercapability */
enum_node = ast_data_add_node(tree, "transfercapability");
if (!enum_node) {
return -1;
}
ast_data_add_str(enum_node, "text", ast_transfercapability2str(ast_channel_transfercapability(chan)));
ast_data_add_int(enum_node, "value", ast_channel_transfercapability(chan));
/* _softphangup */
data_softhangup = ast_data_add_node(tree, "softhangup");
if (!data_softhangup) {
return -1;
}
ast_data_add_bool(data_softhangup, "dev", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_DEV);
ast_data_add_bool(data_softhangup, "asyncgoto", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_ASYNCGOTO);
ast_data_add_bool(data_softhangup, "shutdown", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_SHUTDOWN);
ast_data_add_bool(data_softhangup, "timeout", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_TIMEOUT);
ast_data_add_bool(data_softhangup, "appunload", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_APPUNLOAD);
ast_data_add_bool(data_softhangup, "explicit", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_EXPLICIT);
/* channel flags */
data_flags = ast_data_add_node(tree, "flags");
if (!data_flags) {
return -1;
}
channel_data_add_flags(data_flags, chan);
ast_data_add_uint(tree, "timetohangup", ast_channel_whentohangup(chan)->tv_sec);
#if 0 /* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
/* callerid */
data_callerid = ast_data_add_node(tree, "callerid");
if (!data_callerid) {
return -1;
}
ast_data_add_structure(ast_callerid, data_callerid, &(chan->cid));
/* insert the callerid ton */
enum_node = ast_data_add_node(data_callerid, "cid_ton");
if (!enum_node) {
return -1;
}
ast_data_add_int(enum_node, "value", chan->cid.cid_ton);
snprintf(value_str, sizeof(value_str), "TON: %s/Plan: %s",
party_number_ton2str(chan->cid.cid_ton),
party_number_plan2str(chan->cid.cid_ton));
ast_data_add_str(enum_node, "text", value_str);
#endif
/* tone zone */
if (ast_channel_zone(chan)) {
data_zones = ast_data_add_node(tree, "zone");
if (!data_zones) {
return -1;
}
ast_tone_zone_data_add_structure(data_zones, ast_channel_zone(chan));
}
/* insert cdr */
data_cdr = ast_data_add_node(tree, "cdr");
if (!data_cdr) {
return -1;
}
return 0;
}
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);
}
/* ACCESSORS */
#define DEFINE_STRINGFIELD_SETTERS_FOR(field, publish, assert_on_null) \

File diff suppressed because it is too large Load Diff

View File

@ -41,23 +41,9 @@
#include "asterisk/cli.h"
#include "asterisk/module.h"
#include "asterisk/astobj2.h"
#include "asterisk/data.h"
#include "asterisk/_private.h" /* _init(), _reload() */
#define DATA_EXPORT_TONE_ZONE(MEMBER) \
MEMBER(ast_tone_zone, country, AST_DATA_STRING) \
MEMBER(ast_tone_zone, description, AST_DATA_STRING) \
MEMBER(ast_tone_zone, nrringcadence, AST_DATA_UNSIGNED_INTEGER)
AST_DATA_STRUCTURE(ast_tone_zone, DATA_EXPORT_TONE_ZONE);
#define DATA_EXPORT_TONE_ZONE_SOUND(MEMBER) \
MEMBER(ast_tone_zone_sound, name, AST_DATA_STRING) \
MEMBER(ast_tone_zone_sound, data, AST_DATA_STRING)
AST_DATA_STRUCTURE(ast_tone_zone_sound, DATA_EXPORT_TONE_ZONE_SOUND);
/* Globals */
static const char config[] = "indications.conf";
@ -1124,33 +1110,6 @@ static int ast_tone_zone_cmp(void *obj, void *arg, int flags)
CMP_MATCH | CMP_STOP : 0;
}
int ast_tone_zone_data_add_structure(struct ast_data *tree, struct ast_tone_zone *zone)
{
struct ast_data *data_zone_sound;
struct ast_tone_zone_sound *s;
ast_data_add_structure(ast_tone_zone, tree, zone);
if (AST_LIST_EMPTY(&zone->tones)) {
return 0;
}
data_zone_sound = ast_data_add_node(tree, "tones");
if (!data_zone_sound) {
return -1;
}
ast_tone_zone_lock(zone);
AST_LIST_TRAVERSE(&zone->tones, s, entry) {
ast_data_add_structure(ast_tone_zone_sound, data_zone_sound, s);
}
ast_tone_zone_unlock(zone);
return 0;
}
/*!
* \internal
* \brief Clean up resources on Asterisk shutdown

View File

@ -8306,56 +8306,6 @@ static void presence_state_cb(void *unused, struct stasis_subscription *sub, str
ast_free(hint_app);
}
/*!
* \internal
* \brief Implements the hints data provider.
*/
static int hints_data_provider_get(const struct ast_data_search *search,
struct ast_data *data_root)
{
struct ast_data *data_hint;
struct ast_hint *hint;
int watchers;
struct ao2_iterator i;
if (ao2_container_count(hints) == 0) {
return 0;
}
i = ao2_iterator_init(hints, 0);
for (; (hint = ao2_iterator_next(&i)); ao2_ref(hint, -1)) {
watchers = ao2_container_count(hint->callbacks);
data_hint = ast_data_add_node(data_root, "hint");
if (!data_hint) {
continue;
}
ast_data_add_str(data_hint, "extension", ast_get_extension_name(hint->exten));
ast_data_add_str(data_hint, "context", ast_get_context_name(ast_get_extension_context(hint->exten)));
ast_data_add_str(data_hint, "application", ast_get_extension_app(hint->exten));
ast_data_add_str(data_hint, "state", ast_extension_state2str(hint->laststate));
ast_data_add_str(data_hint, "presence_state", ast_presence_state2str(hint->last_presence_state));
ast_data_add_str(data_hint, "presence_subtype", S_OR(hint->last_presence_subtype, ""));
ast_data_add_str(data_hint, "presence_subtype", S_OR(hint->last_presence_message, ""));
ast_data_add_int(data_hint, "watchers", watchers);
if (!ast_data_search_match(search, data_hint)) {
ast_data_remove_node(data_root, data_hint);
}
}
ao2_iterator_destroy(&i);
return 0;
}
static const struct ast_data_handler hints_data_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = hints_data_provider_get
};
static const struct ast_data_entry pbx_data_providers[] = {
AST_DATA_ENTRY("asterisk/core/hints", &hints_data_provider),
};
static int action_extensionstatelist(struct mansession *s, const struct message *m)
{
const char *action_id = astman_get_header(m, "ActionID");
@ -8431,7 +8381,6 @@ static void unload_pbx(void)
ast_cli_unregister_multiple(pbx_cli, ARRAY_LEN(pbx_cli));
ast_custom_function_unregister(&exception_function);
ast_custom_function_unregister(&testtime_function);
ast_data_unregister(NULL);
}
int load_pbx(void)
@ -8445,7 +8394,6 @@ int load_pbx(void)
ast_verb(2, "Registering builtin functions:\n");
ast_cli_register_multiple(pbx_cli, ARRAY_LEN(pbx_cli));
ast_data_register_multiple_core(pbx_data_providers, ARRAY_LEN(pbx_data_providers));
__ast_custom_function_register(&exception_function, NULL);
__ast_custom_function_register(&testtime_function, NULL);

View File

@ -61,7 +61,6 @@
#include "asterisk/app.h"
#include "asterisk/strings.h"
#include "asterisk/threadstorage.h"
#include "asterisk/data.h"
struct odbc_class
{
@ -119,15 +118,6 @@ struct odbc_txn_frame {
char name[0]; /*!< Name of this transaction ID */
};
#define DATA_EXPORT_ODBC_CLASS(MEMBER) \
MEMBER(odbc_class, name, AST_DATA_STRING) \
MEMBER(odbc_class, dsn, AST_DATA_STRING) \
MEMBER(odbc_class, username, AST_DATA_STRING) \
MEMBER(odbc_class, password, AST_DATA_PASSWORD) \
MEMBER(odbc_class, forcecommit, AST_DATA_BOOLEAN)
AST_DATA_STRUCTURE(odbc_class, DATA_EXPORT_ODBC_CLASS);
const char *ast_odbc_isolation2text(int iso)
{
if (iso == SQL_TXN_READ_COMMITTED) {
@ -971,65 +961,6 @@ static odbc_status odbc_obj_connect(struct odbc_obj *obj)
return ODBC_SUCCESS;
}
/*!
* \internal
* \brief Implements the channels provider.
*/
static int data_odbc_provider_handler(const struct ast_data_search *search,
struct ast_data *root)
{
struct ao2_iterator aoi;
struct odbc_class *class;
struct ast_data *data_odbc_class, *data_odbc_connections;
struct ast_data *enum_node;
aoi = ao2_iterator_init(class_container, 0);
while ((class = ao2_iterator_next(&aoi))) {
data_odbc_class = ast_data_add_node(root, "class");
if (!data_odbc_class) {
ao2_ref(class, -1);
continue;
}
ast_data_add_structure(odbc_class, data_odbc_class, class);
data_odbc_connections = ast_data_add_node(data_odbc_class, "connections");
if (!data_odbc_connections) {
ao2_ref(class, -1);
continue;
}
/* isolation */
enum_node = ast_data_add_node(data_odbc_class, "isolation");
if (!enum_node) {
ao2_ref(class, -1);
continue;
}
ast_data_add_int(enum_node, "value", class->isolation);
ast_data_add_str(enum_node, "text", ast_odbc_isolation2text(class->isolation));
ao2_ref(class, -1);
if (!ast_data_search_match(search, data_odbc_class)) {
ast_data_remove_node(root, data_odbc_class);
}
}
ao2_iterator_destroy(&aoi);
return 0;
}
/*!
* \internal
* \brief /asterisk/res/odbc/listprovider.
*/
static const struct ast_data_handler odbc_provider = {
.version = AST_DATA_HANDLER_VERSION,
.get = data_odbc_provider_handler
};
static const struct ast_data_entry odbc_providers[] = {
AST_DATA_ENTRY("/asterisk/res/odbc", &odbc_provider),
};
static int reload(void)
{
struct odbc_cache_tables *table;
@ -1087,7 +1018,6 @@ static int load_module(void)
if (load_odbc_config() == -1)
return AST_MODULE_LOAD_DECLINE;
ast_cli_register_multiple(cli_odbc, ARRAY_LEN(cli_odbc));
ast_data_register_multiple(odbc_providers, ARRAY_LEN(odbc_providers));
ast_log(LOG_NOTICE, "res_odbc loaded.\n");
return 0;
}