diff options
40 files changed, 1557 insertions, 6820 deletions
@@ -18,6 +18,26 @@ app_queue been defined. ------------------------------------------------------------------------------ +--- Functionality changes from Asterisk 14.6.0 to Asterisk 14.7.0 ------------ +------------------------------------------------------------------------------ + +res_musiconhold +------------------ + * By default, when res_musiconhold reloads or unloads, it sends a HUP signal + to custom applications (and all descendants), waits 100ms, then sends a + TERM signal, waits 100ms, then finally sends a KILL signal. An application + which is interacting with an external device and/or spawns children of its + own may not be able to exit cleanly in the default times, expecially if sent + a KILL signal, or if it's children are getting signals directly from + res_musiconhoild. To allow extra time, the 'kill_escalation_delay' + class option can be used to set the number of milliseconds res_musiconhold + waits before escalating kill signals, with the default being the current + 100ms. To control to whom the signals are sent, the "kill_method" + class option can be set to "process_group" (the default, existing behavior), + which sends signals to the application and its descendants directly, or + "process" which sends signals only to the application itself. + +------------------------------------------------------------------------------ --- Functionality changes from Asterisk 14.5.0 to Asterisk 14.6.0 ------------ ------------------------------------------------------------------------------ @@ -40,6 +60,10 @@ res_pjsip whether to notify dialog-info state 'early' or 'confirmed' on Ringing when already INUSE. + * The endpoint option 'dtmf_mode' has a new option 'auto_dtmf' added. This + mode works similar to 'auto' except uses DTMF INFO as fallback instead of + INBAND. + res_agi ------------------ * The EAGI() application will now look for a dialplan variable named @@ -59,6 +83,14 @@ chan_pjsip from the SDP, unless the remote side sends a different codec and we will switch to match. +Build System +------------------ + * Added a new PJPROJECT_CONFIGURE_OPTS environment variable which can be used + to pass arbitrary options to the bundled pjproject configure. + + * Automatically set the bundled pjproject configure --host and --build + options to match those supplied for the asterisk configure. + ------------------------------------------------------------------------------ --- Functionality changes from Asterisk 14.4.0 to Asterisk 14.5.0 ------------ ------------------------------------------------------------------------------ diff --git a/UPGRADE.txt b/UPGRADE.txt index 62bb80182..eb05b035e 100644 --- a/UPGRADE.txt +++ b/UPGRADE.txt @@ -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: diff --git a/apps/app_meetme.c b/apps/app_meetme.c index 71ca9dc9f..d98c418c3 100644 --- a/apps/app_meetme.c +++ b/apps/app_meetme.c @@ -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); diff --git a/apps/app_queue.c b/apps/app_queue.c index f158a4caa..f7e0996ac 100644 --- a/apps/app_queue.c +++ b/apps/app_queue.c @@ -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" @@ -793,16 +792,6 @@ <ref type="function">QUEUE_MEMBER_PENALTY</ref> </see-also> </function> - <manager name="Queues" language="en_US"> - <synopsis> - Queues. - </synopsis> - <syntax> - </syntax> - <description> - <para>Show queues information.</para> - </description> - </manager> <manager name="QueueStatus" language="en_US"> <synopsis> Show queue status. @@ -8301,6 +8290,9 @@ stop: } else if (qcontinue) { reason = QUEUE_CONTINUE; res = 0; + } else if (reason == QUEUE_LEAVEEMPTY) { + /* Return back to dialplan, don't hang up */ + res = 0; } } else if (qe.valid_digits) { ast_queue_log(args.queuename, ast_channel_uniqueid(chan), "NONE", "EXITWITHKEY", @@ -9728,19 +9720,6 @@ static char *queue_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a return __queues_show(NULL, a->fd, a->argc, a->argv); } -/*!\brief callback to display queues status in manager - \addtogroup Group_AMI - */ -static int manager_queues_show(struct mansession *s, const struct message *m) -{ - static const char * const a[] = { "queue", "show" }; - - __queues_show(s, -1, 2, a); - astman_append(s, "\r\n\r\n"); /* Properly terminate Manager output */ - - return RESULT_SUCCESS; -} - static int manager_queue_rule_show(struct mansession *s, const struct message *m) { const char *rule = astman_get_header(m, "Rule"); @@ -9949,6 +9928,7 @@ static int manager_queues_status(struct mansession *s, const struct message *m) "ConnectedLineNum: %s\r\n" "ConnectedLineName: %s\r\n" "Wait: %ld\r\n" + "Priority: %d\r\n" "%s" "\r\n", q->name, pos++, ast_channel_name(qe->chan), ast_channel_uniqueid(qe->chan), @@ -9956,7 +9936,7 @@ static int manager_queues_status(struct mansession *s, const struct message *m) S_COR(ast_channel_caller(qe->chan)->id.name.valid, ast_channel_caller(qe->chan)->id.name.str, "unknown"), S_COR(ast_channel_connected(qe->chan)->id.number.valid, ast_channel_connected(qe->chan)->id.number.str, "unknown"), S_COR(ast_channel_connected(qe->chan)->id.name.valid, ast_channel_connected(qe->chan)->id.name.str, "unknown"), - (long) (now - qe->start), idText); + (long) (now - qe->start), qe->prio, idText); ++q_items; } } @@ -10893,275 +10873,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; @@ -11191,7 +10902,6 @@ static int unload_module(void) ast_cli_unregister_multiple(cli_queue, ARRAY_LEN(cli_queue)); ast_manager_unregister("QueueStatus"); - ast_manager_unregister("Queues"); ast_manager_unregister("QueueRule"); ast_manager_unregister("QueueSummary"); ast_manager_unregister("QueueAdd"); @@ -11219,8 +10929,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); @@ -11299,8 +11007,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); @@ -11309,7 +11015,6 @@ static int load_module(void) err |= ast_register_application_xml(app_upqm, upqm_exec); err |= ast_register_application_xml(app_ql, ql_exec); err |= ast_register_application_xml(app_qupd, qupd_exec); - err |= ast_manager_register_xml("Queues", 0, manager_queues_show); err |= ast_manager_register_xml("QueueStatus", 0, manager_queues_status); err |= ast_manager_register_xml("QueueSummary", 0, manager_queues_summary); err |= ast_manager_register_xml("QueueAdd", EVENT_FLAG_AGENT, manager_add_queue_member); diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 783cab69e..956b951fd 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -3779,12 +3779,12 @@ static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data) SQLHSTMT stmt; res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { + if (!SQL_SUCCEEDED(res)) { ast_log(AST_LOG_WARNING, "SQL Alloc Handle failed!\n"); return NULL; } res = SQLPrepare(stmt, (unsigned char *) gps->sql, SQL_NTS); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { + if (!SQL_SUCCEEDED(res)) { ast_log(AST_LOG_WARNING, "SQL Prepare failed![%s]\n", gps->sql); SQLFreeHandle(SQL_HANDLE_STMT, stmt); return NULL; @@ -3826,14 +3826,14 @@ static void odbc_update_msg_id(char *dir, int msg_num, char *msg_id) * \brief Retrieves a file from an ODBC data store. * \param dir the path to the file to be retrieved. * \param msgnum the message number, such as within a mailbox folder. - * + * * This method is used by the RETRIEVE macro when mailboxes are stored in an ODBC back end. * The purpose is to get the message from the database store to the local file system, so that the message may be played, or the information file may be read. * * The file is looked up by invoking a SQL on the odbc_table (default 'voicemessages') using the dir and msgnum input parameters. * The output is the message information file with the name msgnum and the extension .txt * and the message file with the extension of its format, in the directory with base file name of the msgnum. - * + * * \return 0 on success, -1 on error. */ static int retrieve_file(char *dir, int msgnum) @@ -3846,7 +3846,7 @@ static int retrieve_file(char *dir, int msgnum) SQLSMALLINT colcount = 0; SQLHSTMT stmt; char sql[PATH_MAX]; - char fmt[80]=""; + char fmt[80] = ""; char *c; char coltitle[256]; SQLSMALLINT collen; @@ -3862,144 +3862,139 @@ static int retrieve_file(char *dir, int msgnum) char msgnums[80]; char *argv[] = { dir, msgnums }; struct generic_prepare_struct gps = { .sql = sql, .argc = 2, .argv = argv }; - struct odbc_obj *obj; + obj = ast_odbc_request_obj(odbc_database, 0); - if (obj) { - ast_copy_string(fmt, vmfmts, sizeof(fmt)); - c = strchr(fmt, '|'); - if (c) - *c = '\0'; - if (!strcasecmp(fmt, "wav49")) - strcpy(fmt, "WAV"); - snprintf(msgnums, sizeof(msgnums), "%d", msgnum); - if (msgnum > -1) - make_file(fn, sizeof(fn), dir, msgnum); - else - ast_copy_string(fn, dir, sizeof(fn)); + if (!obj) { + ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); + return -1; + } - /* Create the information file */ - snprintf(full_fn, sizeof(full_fn), "%s.txt", fn); - - if (!(f = fopen(full_fn, "w+"))) { - ast_log(AST_LOG_WARNING, "Failed to open/create '%s'\n", full_fn); - goto yuck; - } - - snprintf(full_fn, sizeof(full_fn), "%s.%s", fn, fmt); - snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE dir=? AND msgnum=?", odbc_table); - stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); - if (!stmt) { - ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); - ast_odbc_release_obj(obj); - goto yuck; - } - res = SQLFetch(stmt); - if (res == SQL_NO_DATA) { - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; - } else if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { + ast_copy_string(fmt, vmfmts, sizeof(fmt)); + c = strchr(fmt, '|'); + if (c) + *c = '\0'; + if (!strcasecmp(fmt, "wav49")) + strcpy(fmt, "WAV"); + + snprintf(msgnums, sizeof(msgnums), "%d", msgnum); + if (msgnum > -1) + make_file(fn, sizeof(fn), dir, msgnum); + else + ast_copy_string(fn, dir, sizeof(fn)); + + /* Create the information file */ + snprintf(full_fn, sizeof(full_fn), "%s.txt", fn); + + if (!(f = fopen(full_fn, "w+"))) { + ast_log(AST_LOG_WARNING, "Failed to open/create '%s'\n", full_fn); + goto bail; + } + + snprintf(full_fn, sizeof(full_fn), "%s.%s", fn, fmt); + snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE dir=? AND msgnum=?", odbc_table); + + stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); + if (!stmt) { + ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); + goto bail; + } + + res = SQLFetch(stmt); + if (!SQL_SUCCEEDED(res)) { + if (res != SQL_NO_DATA) { ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; } - fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC, VOICEMAIL_FILE_MODE); - if (fd < 0) { - ast_log(AST_LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno)); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; - } - res = SQLNumResultCols(stmt, &colcount); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; - } - if (f) - fprintf(f, "[message]\n"); - for (x = 0; x < colcount; x++) { - rowdata[0] = '\0'; - colsize = 0; - collen = sizeof(coltitle); - res = SQLDescribeCol(stmt, x + 1, (unsigned char *) coltitle, sizeof(coltitle), &collen, - &datatype, &colsize, &decimaldigits, &nullable); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; - } - if (!strcasecmp(coltitle, "recording")) { - off_t offset; - res = SQLGetData(stmt, x + 1, SQL_BINARY, rowdata, 0, &colsize2); - fdlen = colsize2; - if (fd > -1) { - char tmp[1]=""; - lseek(fd, fdlen - 1, SEEK_SET); - if (write(fd, tmp, 1) != 1) { - close(fd); - fd = -1; - continue; - } - /* Read out in small chunks */ - for (offset = 0; offset < colsize2; offset += CHUNKSIZE) { - if ((fdm = mmap(NULL, CHUNKSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == MAP_FAILED) { - ast_log(AST_LOG_WARNING, "Could not mmap the output file: %s (%d)\n", strerror(errno), errno); - SQLFreeHandle(SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; - } else { - res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, CHUNKSIZE, NULL); - munmap(fdm, CHUNKSIZE); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); - unlink(full_fn); - SQLFreeHandle(SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; - } - } + goto bail_with_handle; + } + + fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC, VOICEMAIL_FILE_MODE); + if (fd < 0) { + ast_log(AST_LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno)); + goto bail_with_handle; + } + + res = SQLNumResultCols(stmt, &colcount); + if (!SQL_SUCCEEDED(res)) { + ast_log(AST_LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql); + goto bail_with_handle; + } + + fprintf(f, "[message]\n"); + for (x = 0; x < colcount; x++) { + rowdata[0] = '\0'; + colsize = 0; + collen = sizeof(coltitle); + res = SQLDescribeCol(stmt, x + 1, (unsigned char *) coltitle, sizeof(coltitle), &collen, + &datatype, &colsize, &decimaldigits, &nullable); + if (!SQL_SUCCEEDED(res)) { + ast_log(AST_LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql); + goto bail_with_handle; + } + if (!strcasecmp(coltitle, "recording")) { + off_t offset; + res = SQLGetData(stmt, x + 1, SQL_BINARY, rowdata, 0, &colsize2); + fdlen = colsize2; + if (fd > -1) { + char tmp[1] = ""; + lseek(fd, fdlen - 1, SEEK_SET); + if (write(fd, tmp, 1) != 1) { + close(fd); + fd = -1; + continue; + } + /* Read out in small chunks */ + for (offset = 0; offset < colsize2; offset += CHUNKSIZE) { + if ((fdm = mmap(NULL, CHUNKSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == MAP_FAILED) { + ast_log(AST_LOG_WARNING, "Could not mmap the output file: %s (%d)\n", strerror(errno), errno); + goto bail_with_handle; } - if (truncate(full_fn, fdlen) < 0) { - ast_log(LOG_WARNING, "Unable to truncate '%s': %s\n", full_fn, strerror(errno)); + res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, CHUNKSIZE, NULL); + munmap(fdm, CHUNKSIZE); + if (!SQL_SUCCEEDED(res)) { + ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); + unlink(full_fn); + goto bail_with_handle; } } - } else { - res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); - if ((res == SQL_NULL_DATA) && (!strcasecmp(coltitle, "msg_id"))) { - char msg_id[MSG_ID_LEN]; - generate_msg_id(msg_id); - snprintf(rowdata, sizeof(rowdata), "%s", msg_id); - odbc_update_msg_id(dir, msgnum, msg_id); - } else if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Get Data error! coltitle=%s\n[%s]\n\n", coltitle, sql); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; + if (truncate(full_fn, fdlen) < 0) { + ast_log(LOG_WARNING, "Unable to truncate '%s': %s\n", full_fn, strerror(errno)); } - if (strcasecmp(coltitle, "msgnum") && strcasecmp(coltitle, "dir") && f) - fprintf(f, "%s=%s\n", coltitle, rowdata); + } + } else { + res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); + if (res == SQL_NULL_DATA && !strcasecmp(coltitle, "msg_id")) { + char msg_id[MSG_ID_LEN]; + generate_msg_id(msg_id); + snprintf(rowdata, sizeof(rowdata), "%s", msg_id); + odbc_update_msg_id(dir, msgnum, msg_id); + } else if (!SQL_SUCCEEDED(res)) { + ast_log(AST_LOG_WARNING, "SQL Get Data error! coltitle=%s\n[%s]\n\n", coltitle, sql); + goto bail_with_handle; + } + if (strcasecmp(coltitle, "msgnum") && strcasecmp(coltitle, "dir")) { + fprintf(f, "%s=%s\n", coltitle, rowdata); } } - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - } else - ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); -yuck: + } + +bail_with_handle: + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + +bail: if (f) fclose(f); if (fd > -1) close(fd); + + ast_odbc_release_obj(obj); + return x - 1; } /*! * \brief Determines the highest message number in use for a given user and mailbox folder. - * \param vmu + * \param vmu * \param dir the folder the mailbox folder to look for messages. Used to construct the SQL where clause. * * This method is used when mailboxes are stored in an ODBC back end. @@ -4010,58 +4005,61 @@ yuck: */ static int last_message_index(struct ast_vm_user *vmu, char *dir) { - int x = 0; + int x = -1; int res; SQLHSTMT stmt; char sql[PATH_MAX]; char rowdata[20]; char *argv[] = { dir }; struct generic_prepare_struct gps = { .sql = sql, .argc = 1, .argv = argv }; - struct odbc_obj *obj; + obj = ast_odbc_request_obj(odbc_database, 0); - if (obj) { - snprintf(sql, sizeof(sql), "SELECT msgnum FROM %s WHERE dir=? order by msgnum desc", odbc_table); + if (!obj) { + ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); + return -1; + } - stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); - if (!stmt) { - ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); - ast_odbc_release_obj(obj); - goto yuck; + snprintf(sql, sizeof(sql), "SELECT msgnum FROM %s WHERE dir=? order by msgnum desc", odbc_table); + + stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); + if (!stmt) { + ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); + goto bail; + } + + res = SQLFetch(stmt); + if (!SQL_SUCCEEDED(res)) { + if (res == SQL_NO_DATA) { + ast_log(AST_LOG_DEBUG, "Directory '%s' has no messages and therefore no index was retrieved.\n", dir); + } else { + ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); } - res = SQLFetch(stmt); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - if (res == SQL_NO_DATA) { - ast_log(AST_LOG_DEBUG, "Directory '%s' has no messages and therefore no index was retrieved.\n", dir); - } else { - ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); - } + goto bail_with_handle; + } - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; - } - res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; - } - if (sscanf(rowdata, "%30d", &x) != 1) - ast_log(AST_LOG_WARNING, "Failed to read message index!\n"); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - return x; - } else - ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); -yuck: - return x - 1; + res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); + if (!SQL_SUCCEEDED(res)) { + ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); + goto bail_with_handle; + } + + if (sscanf(rowdata, "%30d", &x) != 1) { + ast_log(AST_LOG_WARNING, "Failed to read message index!\n"); + } + +bail_with_handle: + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + +bail: + ast_odbc_release_obj(obj); + + return x; } /*! * \brief Determines if the specified message exists. - * \param dir the folder the mailbox folder to look for messages. + * \param dir the folder the mailbox folder to look for messages. * \param msgnum the message index to query for. * * This method is used when mailboxes are stored in an ODBC back end. @@ -4078,39 +4076,43 @@ static int message_exists(char *dir, int msgnum) char msgnums[20]; char *argv[] = { dir, msgnums }; struct generic_prepare_struct gps = { .sql = sql, .argc = 2, .argv = argv }; - struct odbc_obj *obj; + obj = ast_odbc_request_obj(odbc_database, 0); - if (obj) { - snprintf(msgnums, sizeof(msgnums), "%d", msgnum); - snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir=? AND msgnum=?", odbc_table); - stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); - if (!stmt) { - ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); - ast_odbc_release_obj(obj); - goto yuck; - } - res = SQLFetch(stmt); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; - } - res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; - } - if (sscanf(rowdata, "%30d", &x) != 1) - ast_log(AST_LOG_WARNING, "Failed to read message count!\n"); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - } else + if (!obj) { ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); -yuck: + return 0; + } + + snprintf(msgnums, sizeof(msgnums), "%d", msgnum); + snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir=? AND msgnum=?", odbc_table); + stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); + if (!stmt) { + ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); + goto bail; + } + + res = SQLFetch(stmt); + if (!SQL_SUCCEEDED(res)) { + ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); + goto bail_with_handle; + } + + res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); + if (!SQL_SUCCEEDED(res)) { + ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); + goto bail_with_handle; + } + + if (sscanf(rowdata, "%30d", &x) != 1) { + ast_log(AST_LOG_WARNING, "Failed to read message count!\n"); + } + +bail_with_handle: + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + +bail: + ast_odbc_release_obj(obj); return x; } @@ -4125,48 +4127,50 @@ yuck: */ static int count_messages(struct ast_vm_user *vmu, char *dir) { - int x = 0; + int x = -1; int res; SQLHSTMT stmt; char sql[PATH_MAX]; char rowdata[20]; char *argv[] = { dir }; struct generic_prepare_struct gps = { .sql = sql, .argc = 1, .argv = argv }; - struct odbc_obj *obj; + obj = ast_odbc_request_obj(odbc_database, 0); - if (obj) { - snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir=?", odbc_table); - stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); - if (!stmt) { - ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); - ast_odbc_release_obj(obj); - goto yuck; - } - res = SQLFetch(stmt); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; - } - res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - goto yuck; - } - if (sscanf(rowdata, "%30d", &x) != 1) - ast_log(AST_LOG_WARNING, "Failed to read message count!\n"); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - return x; - } else + if (!obj) { ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); -yuck: - return x - 1; + return -1; + } + + snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir=?", odbc_table); + stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); + if (!stmt) { + ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); + goto bail; + } + + res = SQLFetch(stmt); + if (!SQL_SUCCEEDED(res)) { + ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); + goto bail_with_handle; + } + res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); + if (!SQL_SUCCEEDED(res)) { + ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); + goto bail_with_handle; + } + + if (sscanf(rowdata, "%30d", &x) != 1) { + ast_log(AST_LOG_WARNING, "Failed to read message count!\n"); + } + +bail_with_handle: + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + +bail: + ast_odbc_release_obj(obj); + return x; } /*! @@ -4176,7 +4180,7 @@ yuck: * * This method is used when mailboxes are stored in an ODBC back end. * The specified message is directly deleted from the database 'voicemessages' table. - * + * * \return the value greater than zero on success to indicate the number of messages, less than zero on error. */ static void delete_file(const char *sdir, int smsg) @@ -4188,21 +4192,25 @@ static void delete_file(const char *sdir, int smsg) struct generic_prepare_struct gps = { .sql = sql, .argc = 2, .argv = argv }; struct odbc_obj *obj; - argv[0] = ast_strdupa(sdir); - obj = ast_odbc_request_obj(odbc_database, 0); - if (obj) { - snprintf(msgnums, sizeof(msgnums), "%d", smsg); - snprintf(sql, sizeof(sql), "DELETE FROM %s WHERE dir=? AND msgnum=?", odbc_table); - stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); - if (!stmt) - ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); - else - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - } else + if (!obj) { ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); - return; + return; + } + + argv[0] = ast_strdupa(sdir); + + snprintf(msgnums, sizeof(msgnums), "%d", smsg); + snprintf(sql, sizeof(sql), "DELETE FROM %s WHERE dir=? AND msgnum=?", odbc_table); + stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); + if (!stmt) { + ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); + } else { + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + } + ast_odbc_release_obj(obj); + + return; } /*! @@ -4230,19 +4238,22 @@ static void copy_file(char *sdir, int smsg, char *ddir, int dmsg, char *dmailbox generate_msg_id(msg_id); delete_file(ddir, dmsg); obj = ast_odbc_request_obj(odbc_database, 0); - if (obj) { - snprintf(msgnums, sizeof(msgnums), "%d", smsg); - snprintf(msgnumd, sizeof(msgnumd), "%d", dmsg); - snprintf(sql, sizeof(sql), "INSERT INTO %s (dir, msgnum, msg_id, context, macrocontext, callerid, origtime, duration, recording, flag, mailboxuser, mailboxcontext) SELECT ?,?,?,context,macrocontext,callerid,origtime,duration,recording,flag,?,? FROM %s WHERE dir=? AND msgnum=?", odbc_table, odbc_table); - stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); - if (!stmt) - ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s] (You probably don't have MySQL 4.1 or later installed)\n\n", sql); - else - SQLFreeHandle(SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - } else + if (!obj) { ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); - return; + return; + } + + snprintf(msgnums, sizeof(msgnums), "%d", smsg); + snprintf(msgnumd, sizeof(msgnumd), "%d", dmsg); + snprintf(sql, sizeof(sql), "INSERT INTO %s (dir, msgnum, msg_id, context, macrocontext, callerid, origtime, duration, recording, flag, mailboxuser, mailboxcontext) SELECT ?,?,?,context,macrocontext,callerid,origtime,duration,recording,flag,?,? FROM %s WHERE dir=? AND msgnum=?", odbc_table, odbc_table); + stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); + if (!stmt) + ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s] (You probably don't have MySQL 4.1 or later installed)\n\n", sql); + else + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + ast_odbc_release_obj(obj); + + return; } struct insert_data { @@ -4271,9 +4282,8 @@ static SQLHSTMT insert_data_cb(struct odbc_obj *obj, void *vdata) SQLHSTMT stmt; res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { + if (!SQL_SUCCEEDED(res)) { ast_log(AST_LOG_WARNING, "SQL Alloc Handle failed!\n"); - SQLFreeHandle(SQL_HANDLE_STMT, stmt); return NULL; } @@ -4293,7 +4303,7 @@ static SQLHSTMT insert_data_cb(struct odbc_obj *obj, void *vdata) SQLBindParameter(stmt, 13, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(data->category), 0, (void *) data->category, 0, NULL); } res = SQLExecDirect(stmt, (unsigned char *) data->sql, SQL_NTS); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { + if (!SQL_SUCCEEDED(res)) { ast_log(AST_LOG_WARNING, "SQL Direct Execute failed!\n"); SQLFreeHandle(SQL_HANDLE_STMT, stmt); return NULL; @@ -4310,7 +4320,7 @@ static SQLHSTMT insert_data_cb(struct odbc_obj *obj, void *vdata) * \param msgnum the message index for the message to be stored. * * This method is used when mailboxes are stored in an ODBC back end. - * The message sound file and information file is looked up on the file system. + * The message sound file and information file is looked up on the file system. * A SQL query is invoked to store the message into the (MySQL) database. * * \return the zero on success -1 on error. @@ -4335,7 +4345,9 @@ static int store_file(const char *dir, const char *mailboxuser, const char *mail struct ast_flags config_flags = { CONFIG_FLAG_NOCACHE }; delete_file(dir, msgnum); - if (!(obj = ast_odbc_request_obj(odbc_database, 0))) { + + obj = ast_odbc_request_obj(odbc_database, 0); + if (!obj) { ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); return -1; } @@ -4398,25 +4410,25 @@ static int store_file(const char *dir, const char *mailboxuser, const char *mail ast_log(AST_LOG_WARNING, "Memory map failed for sound file '%s'!\n", full_fn); res = -1; break; - } + } idata.data = fdm; idata.datalen = idata.indlen = fdlen; - if (!ast_strlen_zero(idata.category)) - snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext,flag,msg_id,category) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", odbc_table); + if (!ast_strlen_zero(idata.category)) + snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext,flag,msg_id,category) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", odbc_table); else snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext,flag,msg_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", odbc_table); if ((stmt = ast_odbc_direct_execute(obj, insert_data_cb, &idata))) { - SQLFreeHandle (SQL_HANDLE_STMT, stmt); + SQLFreeHandle(SQL_HANDLE_STMT, stmt); } else { ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); res = -1; } } while (0); - if (obj) { - ast_odbc_release_obj(obj); - } + + ast_odbc_release_obj(obj); + if (valid_config(cfg)) ast_config_destroy(cfg); if (fdm != MAP_FAILED) @@ -4450,20 +4462,23 @@ static void rename_file(char *sdir, int smsg, char *mailboxuser, char *mailboxco struct generic_prepare_struct gps = { .sql = sql, .argc = 6, .argv = argv }; delete_file(ddir, dmsg); + obj = ast_odbc_request_obj(odbc_database, 0); - if (obj) { - snprintf(msgnums, sizeof(msgnums), "%d", smsg); - snprintf(msgnumd, sizeof(msgnumd), "%d", dmsg); - snprintf(sql, sizeof(sql), "UPDATE %s SET dir=?, msgnum=?, mailboxuser=?, mailboxcontext=? WHERE dir=? AND msgnum=?", odbc_table); - stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); - if (!stmt) - ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); - else - SQLFreeHandle(SQL_HANDLE_STMT, stmt); - ast_odbc_release_obj(obj); - } else + if (!obj) { ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); - return; + return; + } + + snprintf(msgnums, sizeof(msgnums), "%d", smsg); + snprintf(msgnumd, sizeof(msgnumd), "%d", dmsg); + snprintf(sql, sizeof(sql), "UPDATE %s SET dir=?, msgnum=?, mailboxuser=?, mailboxcontext=? WHERE dir=? AND msgnum=?", odbc_table); + stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); + if (!stmt) + ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); + else + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + ast_odbc_release_obj(obj); + return; } /*! @@ -5663,17 +5678,48 @@ static void free_zone(struct vm_zone *z) } #ifdef ODBC_STORAGE -static int inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs) + +static int count_messages_in_folder(struct odbc_obj *odbc, const char *context, const char *mailbox, const char *folder, int *messages) { - int x = -1; int res; - SQLHSTMT stmt = NULL; char sql[PATH_MAX]; char rowdata[20]; + SQLHSTMT stmt = NULL; + struct generic_prepare_struct gps = { .sql = sql, .argc = 0 }; + + if (!messages) { + return 0; + } + + snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, mailbox, folder); + if (!(stmt = ast_odbc_prepare_and_execute(odbc, generic_prepare, &gps))) { + ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); + return 1; + } + res = SQLFetch(stmt); + if (!SQL_SUCCEEDED(res)) { + ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + return 1; + } + res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); + if (!SQL_SUCCEEDED(res)) { + ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + return 1; + } + + *messages = atoi(rowdata); + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + + return 0; +} + +static int inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs) +{ char tmp[PATH_MAX] = ""; - struct odbc_obj *obj = NULL; + struct odbc_obj *obj; char *context; - struct generic_prepare_struct gps = { .sql = sql, .argc = 0 }; if (newmsgs) *newmsgs = 0; @@ -5715,87 +5761,28 @@ static int inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int * } else context = "default"; - if ((obj = ast_odbc_request_obj(odbc_database, 0))) { - do { - if (newmsgs) { - snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, tmp, "INBOX"); - if (!(stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps))) { - ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); - break; - } - res = SQLFetch(stmt); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); - break; - } - res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); - break; - } - *newmsgs = atoi(rowdata); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - } - - if (oldmsgs) { - snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, tmp, "Old"); - if (!(stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps))) { - ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); - break; - } - res = SQLFetch(stmt); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); - break; - } - res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); - break; - } - SQLFreeHandle(SQL_HANDLE_STMT, stmt); - *oldmsgs = atoi(rowdata); - } - - if (urgentmsgs) { - snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, tmp, "Urgent"); - if (!(stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps))) { - ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); - break; - } - res = SQLFetch(stmt); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); - break; - } - res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); - break; - } - *urgentmsgs = atoi(rowdata); - } - - x = 0; - } while (0); - } else { + obj = ast_odbc_request_obj(odbc_database, 0); + if (!obj) { ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); + return -1; } - if (stmt) { - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - } - if (obj) { - ast_odbc_release_obj(obj); + if (count_messages_in_folder(obj, context, tmp, "INBOX", newmsgs) + || count_messages_in_folder(obj, context, tmp, "Old", oldmsgs) + || count_messages_in_folder(obj, context, tmp, "Urgent", urgentmsgs)) { + ast_log(AST_LOG_WARNING, "Failed to obtain message count for mailbox %s@%s\n", + tmp, context); } - return x; + + ast_odbc_release_obj(obj); + return 0; } /*! * \brief Gets the number of messages that exist in a mailbox folder. * \param mailbox_id * \param folder - * + * * This method is used when ODBC backend is used. * \return The number of messages in this mailbox folder (zero or more). */ @@ -5822,37 +5809,39 @@ static int messagecount(const char *mailbox_id, const char *folder) } obj = ast_odbc_request_obj(odbc_database, 0); - if (obj) { - if (!strcmp(folder, "INBOX")) { - snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/INBOX' OR dir = '%s%s/%s/Urgent'", odbc_table, VM_SPOOL_DIR, context, mailbox, VM_SPOOL_DIR, context, mailbox); - } else { - snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, mailbox, folder); - } - stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); - if (!stmt) { - ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); - goto yuck; - } - res = SQLFetch(stmt); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - goto yuck; - } - res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); - if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - goto yuck; - } - nummsgs = atoi(rowdata); - SQLFreeHandle (SQL_HANDLE_STMT, stmt); - } else + if (!obj) { ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database); + return 0; + } -yuck: - if (obj) - ast_odbc_release_obj(obj); + if (!strcmp(folder, "INBOX")) { + snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/INBOX' OR dir = '%s%s/%s/Urgent'", odbc_table, VM_SPOOL_DIR, context, mailbox, VM_SPOOL_DIR, context, mailbox); + } else { + snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, mailbox, folder); + } + + stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps); + if (!stmt) { + ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); + goto bail; + } + res = SQLFetch(stmt); + if (!SQL_SUCCEEDED(res)) { + ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql); + goto bail_with_handle; + } + res = SQLGetData(stmt, 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL); + if (!SQL_SUCCEEDED(res)) { + ast_log(AST_LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); + goto bail_with_handle; + } + nummsgs = atoi(rowdata); + +bail_with_handle: + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + +bail: + ast_odbc_release_obj(obj); return nummsgs; } @@ -12914,147 +12903,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 +14845,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 +14954,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); diff --git a/bridges/bridge_native_rtp.c b/bridges/bridge_native_rtp.c index 4af93bfca..02b27e123 100644 --- a/bridges/bridge_native_rtp.c +++ b/bridges/bridge_native_rtp.c @@ -44,76 +44,214 @@ #include "asterisk/frame.h" #include "asterisk/rtp_engine.h" -/*! \brief Internal structure which contains information about bridged RTP channels */ -struct native_rtp_bridge_data { +/*! \brief Internal structure which contains bridged RTP channel hook data */ +struct native_rtp_framehook_data { /*! \brief Framehook used to intercept certain control frames */ int id; /*! \brief Set when this framehook has been detached */ unsigned int detached; }; -/*! \brief Internal helper function which gets all RTP information (glue and instances) relating to the given channels */ -static enum ast_rtp_glue_result native_rtp_bridge_get(struct ast_channel *c0, struct ast_channel *c1, struct ast_rtp_glue **glue0, - struct ast_rtp_glue **glue1, struct ast_rtp_instance **instance0, struct ast_rtp_instance **instance1, - struct ast_rtp_instance **vinstance0, struct ast_rtp_instance **vinstance1) +struct rtp_glue_stream { + /*! \brief RTP instance */ + struct ast_rtp_instance *instance; + /*! \brief glue result */ + enum ast_rtp_glue_result result; +}; + +struct rtp_glue_data { + /*! + * \brief glue callbacks + * + * \note The glue data is considered valid if cb is not NULL. + */ + struct ast_rtp_glue *cb; + struct rtp_glue_stream audio; + struct rtp_glue_stream video; + /*! Combined glue result of both bridge channels. */ + enum ast_rtp_glue_result result; +}; + +/*! \brief Internal structure which contains instance information about bridged RTP channels */ +struct native_rtp_bridge_channel_data { + /*! \brief Channel's hook data */ + struct native_rtp_framehook_data *hook_data; + /*! + * \brief Glue callbacks to bring remote channel streams back to Asterisk. + * \note NULL if channel streams are local. + */ + struct ast_rtp_glue *remote_cb; + /*! \brief Channel's cached RTP glue information */ + struct rtp_glue_data glue; +}; + +static void rtp_glue_data_init(struct rtp_glue_data *glue) { - enum ast_rtp_glue_result audio_glue0_res; - enum ast_rtp_glue_result video_glue0_res; - enum ast_rtp_glue_result audio_glue1_res; - enum ast_rtp_glue_result video_glue1_res; + glue->cb = NULL; + glue->audio.instance = NULL; + glue->audio.result = AST_RTP_GLUE_RESULT_FORBID; + glue->video.instance = NULL; + glue->video.result = AST_RTP_GLUE_RESULT_FORBID; + glue->result = AST_RTP_GLUE_RESULT_FORBID; +} - if (!(*glue0 = ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) || - !(*glue1 = ast_rtp_instance_get_glue(ast_channel_tech(c1)->type))) { - return AST_RTP_GLUE_RESULT_FORBID; +static void rtp_glue_data_destroy(struct rtp_glue_data *glue) +{ + if (!glue) { + return; } + ao2_cleanup(glue->audio.instance); + ao2_cleanup(glue->video.instance); +} + +static void rtp_glue_data_reset(struct rtp_glue_data *glue) +{ + rtp_glue_data_destroy(glue); + rtp_glue_data_init(glue); +} + +static void native_rtp_bridge_channel_data_free(struct native_rtp_bridge_channel_data *data) +{ + ast_debug(2, "Destroying channel tech_pvt data %p\n", data); - audio_glue0_res = (*glue0)->get_rtp_info(c0, instance0); - video_glue0_res = (*glue0)->get_vrtp_info ? (*glue0)->get_vrtp_info(c0, vinstance0) : AST_RTP_GLUE_RESULT_FORBID; + /* + * hook_data will probably already have been unreferenced by the framehook detach + * and the pointer set to null. + */ + ao2_cleanup(data->hook_data); - audio_glue1_res = (*glue1)->get_rtp_info(c1, instance1); - video_glue1_res = (*glue1)->get_vrtp_info ? (*glue1)->get_vrtp_info(c1, vinstance1) : AST_RTP_GLUE_RESULT_FORBID; + rtp_glue_data_reset(&data->glue); + ast_free(data); +} + +static struct native_rtp_bridge_channel_data *native_rtp_bridge_channel_data_alloc(void) +{ + struct native_rtp_bridge_channel_data *data; + + data = ast_calloc(1, sizeof(*data)); + if (data) { + rtp_glue_data_init(&data->glue); + } + return data; +} + +/*! + * \internal + * \brief Helper function which gets all RTP information (glue and instances) relating to the given channels + * + * \retval 0 on success. + * \retval -1 on error. + */ +static int rtp_glue_data_get(struct ast_channel *c0, struct rtp_glue_data *glue0, + struct ast_channel *c1, struct rtp_glue_data *glue1) +{ + struct ast_rtp_glue *cb0; + struct ast_rtp_glue *cb1; + enum ast_rtp_glue_result combined_result; + + cb0 = ast_rtp_instance_get_glue(ast_channel_tech(c0)->type); + cb1 = ast_rtp_instance_get_glue(ast_channel_tech(c1)->type); + if (!cb0 || !cb1) { + /* One or both channels doesn't have any RTP glue registered. */ + return -1; + } + + /* The glue callbacks bump the RTP instance refcounts for us. */ + + glue0->cb = cb0; + glue0->audio.result = cb0->get_rtp_info(c0, &glue0->audio.instance); + glue0->video.result = cb0->get_vrtp_info + ? cb0->get_vrtp_info(c0, &glue0->video.instance) : AST_RTP_GLUE_RESULT_FORBID; + + glue1->cb = cb1; + glue1->audio.result = cb1->get_rtp_info(c1, &glue1->audio.instance); + glue1->video.result = cb1->get_vrtp_info + ? cb1->get_vrtp_info(c1, &glue1->video.instance) : AST_RTP_GLUE_RESULT_FORBID; + + /* + * Now determine the combined glue result. + */ /* Apply any limitations on direct media bridging that may be present */ - if (audio_glue0_res == audio_glue1_res && audio_glue1_res == AST_RTP_GLUE_RESULT_REMOTE) { - if ((*glue0)->allow_rtp_remote && !((*glue0)->allow_rtp_remote(c0, *instance1))) { + if (glue0->audio.result == glue1->audio.result && glue1->audio.result == AST_RTP_GLUE_RESULT_REMOTE) { + if (glue0->cb->allow_rtp_remote && !glue0->cb->allow_rtp_remote(c0, glue1->audio.instance)) { /* If the allow_rtp_remote indicates that remote isn't allowed, revert to local bridge */ - audio_glue0_res = audio_glue1_res = AST_RTP_GLUE_RESULT_LOCAL; - } else if ((*glue1)->allow_rtp_remote && !((*glue1)->allow_rtp_remote(c1, *instance0))) { - audio_glue0_res = audio_glue1_res = AST_RTP_GLUE_RESULT_LOCAL; + glue0->audio.result = glue1->audio.result = AST_RTP_GLUE_RESULT_LOCAL; + } else if (glue1->cb->allow_rtp_remote && !glue1->cb->allow_rtp_remote(c1, glue0->audio.instance)) { + glue0->audio.result = glue1->audio.result = AST_RTP_GLUE_RESULT_LOCAL; } } - if (video_glue0_res == video_glue1_res && video_glue1_res == AST_RTP_GLUE_RESULT_REMOTE) { - if ((*glue0)->allow_vrtp_remote && !((*glue0)->allow_vrtp_remote(c0, *instance1))) { - /* if the allow_vrtp_remote indicates that remote isn't allowed, revert to local bridge */ - video_glue0_res = video_glue1_res = AST_RTP_GLUE_RESULT_LOCAL; - } else if ((*glue1)->allow_vrtp_remote && !((*glue1)->allow_vrtp_remote(c1, *instance0))) { - video_glue0_res = video_glue1_res = AST_RTP_GLUE_RESULT_LOCAL; + if (glue0->video.result == glue1->video.result && glue1->video.result == AST_RTP_GLUE_RESULT_REMOTE) { + if (glue0->cb->allow_vrtp_remote && !glue0->cb->allow_vrtp_remote(c0, glue1->video.instance)) { + /* If the allow_vrtp_remote indicates that remote isn't allowed, revert to local bridge */ + glue0->video.result = glue1->video.result = AST_RTP_GLUE_RESULT_LOCAL; + } else if (glue1->cb->allow_vrtp_remote && !glue1->cb->allow_vrtp_remote(c1, glue0->video.instance)) { + glue0->video.result = glue1->video.result = AST_RTP_GLUE_RESULT_LOCAL; } } /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */ - if (video_glue0_res != AST_RTP_GLUE_RESULT_FORBID - && (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE - || video_glue0_res != AST_RTP_GLUE_RESULT_REMOTE)) { - audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID; + if (glue0->video.result != AST_RTP_GLUE_RESULT_FORBID + && (glue0->audio.result != AST_RTP_GLUE_RESULT_REMOTE + || glue0->video.result != AST_RTP_GLUE_RESULT_REMOTE)) { + glue0->audio.result = AST_RTP_GLUE_RESULT_FORBID; } - if (video_glue1_res != AST_RTP_GLUE_RESULT_FORBID - && (audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE - || video_glue1_res != AST_RTP_GLUE_RESULT_REMOTE)) { - audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID; + if (glue1->video.result != AST_RTP_GLUE_RESULT_FORBID + && (glue1->audio.result != AST_RTP_GLUE_RESULT_REMOTE + || glue1->video.result != AST_RTP_GLUE_RESULT_REMOTE)) { + glue1->audio.result = AST_RTP_GLUE_RESULT_FORBID; } /* The order of preference is: forbid, local, and remote. */ - if (audio_glue0_res == AST_RTP_GLUE_RESULT_FORBID || - audio_glue1_res == AST_RTP_GLUE_RESULT_FORBID) { + if (glue0->audio.result == AST_RTP_GLUE_RESULT_FORBID + || glue1->audio.result == AST_RTP_GLUE_RESULT_FORBID) { /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */ - return AST_RTP_GLUE_RESULT_FORBID; - } else if (audio_glue0_res == AST_RTP_GLUE_RESULT_LOCAL || - audio_glue1_res == AST_RTP_GLUE_RESULT_LOCAL) { - return AST_RTP_GLUE_RESULT_LOCAL; + combined_result = AST_RTP_GLUE_RESULT_FORBID; + } else if (glue0->audio.result == AST_RTP_GLUE_RESULT_LOCAL + || glue1->audio.result == AST_RTP_GLUE_RESULT_LOCAL) { + combined_result = AST_RTP_GLUE_RESULT_LOCAL; } else { - return AST_RTP_GLUE_RESULT_REMOTE; + combined_result = AST_RTP_GLUE_RESULT_REMOTE; + } + glue0->result = combined_result; + glue1->result = combined_result; + + return 0; +} + +/*! + * \internal + * \brief Get the current RTP native bridge combined glue result. + * \since 15.0.0 + * + * \param c0 First bridge channel + * \param c1 Second bridge channel + * + * \note Both channels must be locked when calling this function. + * + * \return Current combined glue result. + */ +static enum ast_rtp_glue_result rtp_glue_get_current_combined_result(struct ast_channel *c0, + struct ast_channel *c1) +{ + struct rtp_glue_data glue_a; + struct rtp_glue_data glue_b; + struct rtp_glue_data *glue0; + struct rtp_glue_data *glue1; + enum ast_rtp_glue_result combined_result; + + rtp_glue_data_init(&glue_a); + glue0 = &glue_a; + rtp_glue_data_init(&glue_b); + glue1 = &glue_b; + if (rtp_glue_data_get(c0, glue0, c1, glue1)) { + return AST_RTP_GLUE_RESULT_FORBID; } + + combined_result = glue0->result; + rtp_glue_data_destroy(glue0); + rtp_glue_data_destroy(glue1); + return combined_result; } /*! @@ -129,52 +267,91 @@ static void native_rtp_bridge_start(struct ast_bridge *bridge, struct ast_channe { struct ast_bridge_channel *bc0 = AST_LIST_FIRST(&bridge->channels); struct ast_bridge_channel *bc1 = AST_LIST_LAST(&bridge->channels); - enum ast_rtp_glue_result native_type = AST_RTP_GLUE_RESULT_FORBID; - struct ast_rtp_glue *glue0, *glue1; - RAII_VAR(struct ast_rtp_instance *, instance0, NULL, ao2_cleanup); - RAII_VAR(struct ast_rtp_instance *, instance1, NULL, ao2_cleanup); - RAII_VAR(struct ast_rtp_instance *, vinstance0, NULL, ao2_cleanup); - RAII_VAR(struct ast_rtp_instance *, vinstance1, NULL, ao2_cleanup); - RAII_VAR(struct ast_rtp_instance *, tinstance0, NULL, ao2_cleanup); - RAII_VAR(struct ast_rtp_instance *, tinstance1, NULL, ao2_cleanup); - RAII_VAR(struct ast_format_cap *, cap0, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup); - RAII_VAR(struct ast_format_cap *, cap1, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup); + struct native_rtp_bridge_channel_data *data0; + struct native_rtp_bridge_channel_data *data1; + struct rtp_glue_data *glue0; + struct rtp_glue_data *glue1; + struct ast_format_cap *cap0; + struct ast_format_cap *cap1; + enum ast_rtp_glue_result native_type; if (bc0 == bc1) { return; } + data0 = bc0->tech_pvt; + data1 = bc1->tech_pvt; + if (!data0 || !data1) { + /* Not all channels are joined with the bridge tech yet */ + return; + } + glue0 = &data0->glue; + glue1 = &data1->glue; ast_channel_lock_both(bc0->chan, bc1->chan); - if (!bc0->suspended && !bc1->suspended) { - native_type = native_rtp_bridge_get(bc0->chan, bc1->chan, &glue0, &glue1, &instance0, &instance1, &vinstance0, &vinstance1); + + if (!glue0->cb || !glue1->cb) { + /* + * Somebody doesn't have glue data so the bridge isn't running + * + * Actually neither side should have glue data. + */ + ast_assert(!glue0->cb && !glue1->cb); + + if (rtp_glue_data_get(bc0->chan, glue0, bc1->chan, glue1)) { + /* + * This might happen if one of the channels got masqueraded + * at a critical time. It's a bit of a stretch even then + * since the channel is in a bridge. + */ + goto done; + } } + ast_debug(2, "Bridge '%s'. Tech starting '%s' and '%s' with target '%s'\n", + bridge->uniqueid, ast_channel_name(bc0->chan), ast_channel_name(bc1->chan), + target ? ast_channel_name(target) : "none"); + + native_type = glue0->result; + switch (native_type) { case AST_RTP_GLUE_RESULT_LOCAL: - if (ast_rtp_instance_get_engine(instance0)->local_bridge) { - ast_rtp_instance_get_engine(instance0)->local_bridge(instance0, instance1); + if (ast_rtp_instance_get_engine(glue0->audio.instance)->local_bridge) { + ast_rtp_instance_get_engine(glue0->audio.instance)->local_bridge(glue0->audio.instance, glue1->audio.instance); } - if (ast_rtp_instance_get_engine(instance1)->local_bridge) { - ast_rtp_instance_get_engine(instance1)->local_bridge(instance1, instance0); + if (ast_rtp_instance_get_engine(glue1->audio.instance)->local_bridge) { + ast_rtp_instance_get_engine(glue1->audio.instance)->local_bridge(glue1->audio.instance, glue0->audio.instance); } - ast_rtp_instance_set_bridged(instance0, instance1); - ast_rtp_instance_set_bridged(instance1, instance0); + ast_rtp_instance_set_bridged(glue0->audio.instance, glue1->audio.instance); + ast_rtp_instance_set_bridged(glue1->audio.instance, glue0->audio.instance); ast_verb(4, "Locally RTP bridged '%s' and '%s' in stack\n", ast_channel_name(bc0->chan), ast_channel_name(bc1->chan)); break; - case AST_RTP_GLUE_RESULT_REMOTE: - if (glue0->get_codec) { - glue0->get_codec(bc0->chan, cap0); + cap0 = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT); + cap1 = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT); + if (!cap0 || !cap1) { + ao2_cleanup(cap0); + ao2_cleanup(cap1); + break; } - if (glue1->get_codec) { - glue1->get_codec(bc1->chan, cap1); + + if (glue0->cb->get_codec) { + glue0->cb->get_codec(bc0->chan, cap0); + } + if (glue1->cb->get_codec) { + glue1->cb->get_codec(bc1->chan, cap1); } - /* If we have a target, it's the channel that received the UNHOLD or UPDATE_RTP_PEER frame and was told to resume */ + /* + * If we have a target, it's the channel that received the UNHOLD or + * UPDATE_RTP_PEER frame and was told to resume + */ if (!target) { - glue0->update_peer(bc0->chan, instance1, vinstance1, tinstance1, cap1, 0); - glue1->update_peer(bc1->chan, instance0, vinstance0, tinstance0, cap0, 0); + /* Send both channels to remote */ + data0->remote_cb = glue0->cb; + data1->remote_cb = glue1->cb; + glue0->cb->update_peer(bc0->chan, glue1->audio.instance, glue1->video.instance, NULL, cap1, 0); + glue1->cb->update_peer(bc1->chan, glue0->audio.instance, glue0->video.instance, NULL, cap0, 0); ast_verb(4, "Remotely bridged '%s' and '%s' - media will flow directly between them\n", ast_channel_name(bc0->chan), ast_channel_name(bc1->chan)); } else { @@ -184,51 +361,121 @@ static void native_rtp_bridge_start(struct ast_bridge *bridge, struct ast_channe * already set up to handle the new media path or will have its own set of updates independent * of this pass. */ + ast_debug(2, "Bridge '%s'. Sending '%s' back to remote\n", + bridge->uniqueid, ast_channel_name(target)); if (bc0->chan == target) { - glue0->update_peer(bc0->chan, instance1, vinstance1, tinstance1, cap1, 0); + data0->remote_cb = glue0->cb; + glue0->cb->update_peer(bc0->chan, glue1->audio.instance, glue1->video.instance, NULL, cap1, 0); } else { - glue1->update_peer(bc1->chan, instance0, vinstance0, tinstance0, cap0, 0); + data1->remote_cb = glue1->cb; + glue1->cb->update_peer(bc1->chan, glue0->audio.instance, glue0->video.instance, NULL, cap0, 0); } } + + ao2_cleanup(cap0); + ao2_cleanup(cap1); break; case AST_RTP_GLUE_RESULT_FORBID: break; } + if (native_type != AST_RTP_GLUE_RESULT_REMOTE) { + /* Bring any remaining channels back to us. */ + if (data0->remote_cb) { + ast_debug(2, "Bridge '%s'. Bringing back '%s' to us\n", + bridge->uniqueid, ast_channel_name(bc0->chan)); + data0->remote_cb->update_peer(bc0->chan, NULL, NULL, NULL, NULL, 0); + data0->remote_cb = NULL; + } + if (data1->remote_cb) { + ast_debug(2, "Bridge '%s'. Bringing back '%s' to us\n", + bridge->uniqueid, ast_channel_name(bc1->chan)); + data1->remote_cb->update_peer(bc1->chan, NULL, NULL, NULL, NULL, 0); + data1->remote_cb = NULL; + } + } + +done: ast_channel_unlock(bc0->chan); ast_channel_unlock(bc1->chan); } +/*! + * \internal + * \brief Stop native RTP bridging of two channels + * + * \param bridge The bridge that had native RTP bridging happening on it + * \param target If remote RTP bridging, the channel that is held. + * + * \note The first channel to leave the bridge triggers the cleanup for both channels + */ static void native_rtp_bridge_stop(struct ast_bridge *bridge, struct ast_channel *target) { struct ast_bridge_channel *bc0 = AST_LIST_FIRST(&bridge->channels); struct ast_bridge_channel *bc1 = AST_LIST_LAST(&bridge->channels); - enum ast_rtp_glue_result native_type; - struct ast_rtp_glue *glue0, *glue1 = NULL; - RAII_VAR(struct ast_rtp_instance *, instance0, NULL, ao2_cleanup); - RAII_VAR(struct ast_rtp_instance *, instance1, NULL, ao2_cleanup); - RAII_VAR(struct ast_rtp_instance *, vinstance0, NULL, ao2_cleanup); - RAII_VAR(struct ast_rtp_instance *, vinstance1, NULL, ao2_cleanup); + struct native_rtp_bridge_channel_data *data0; + struct native_rtp_bridge_channel_data *data1; + struct rtp_glue_data *glue0; + struct rtp_glue_data *glue1; if (bc0 == bc1) { return; } + data0 = bc0->tech_pvt; + data1 = bc1->tech_pvt; + if (!data0 || !data1) { + /* Not all channels are joined with the bridge tech */ + return; + } + glue0 = &data0->glue; + glue1 = &data1->glue; + + ast_debug(2, "Bridge '%s'. Tech stopping '%s' and '%s' with target '%s'\n", + bridge->uniqueid, ast_channel_name(bc0->chan), ast_channel_name(bc1->chan), + target ? ast_channel_name(target) : "none"); + + if (!glue0->cb || !glue1->cb) { + /* + * Somebody doesn't have glue data so the bridge isn't running + * + * Actually neither side should have glue data. + */ + ast_assert(!glue0->cb && !glue1->cb); + /* At most one channel can be left at the remote endpoint here. */ + ast_assert(!data0->remote_cb || !data1->remote_cb); + + /* Bring selected channel streams back to us */ + if (data0->remote_cb && (!target || target == bc0->chan)) { + ast_channel_lock(bc0->chan); + ast_debug(2, "Bridge '%s'. Bringing back '%s' to us\n", + bridge->uniqueid, ast_channel_name(bc0->chan)); + data0->remote_cb->update_peer(bc0->chan, NULL, NULL, NULL, NULL, 0); + data0->remote_cb = NULL; + ast_channel_unlock(bc0->chan); + } + if (data1->remote_cb && (!target || target == bc1->chan)) { + ast_channel_lock(bc1->chan); + ast_debug(2, "Bridge '%s'. Bringing back '%s' to us\n", + bridge->uniqueid, ast_channel_name(bc1->chan)); + data1->remote_cb->update_peer(bc1->chan, NULL, NULL, NULL, NULL, 0); + data1->remote_cb = NULL; + ast_channel_unlock(bc1->chan); + } + return; + } ast_channel_lock_both(bc0->chan, bc1->chan); - native_type = native_rtp_bridge_get(bc0->chan, bc1->chan, &glue0, &glue1, &instance0, &instance1, &vinstance0, &vinstance1); - switch (native_type) { + switch (glue0->result) { case AST_RTP_GLUE_RESULT_LOCAL: - if (ast_rtp_instance_get_engine(instance0)->local_bridge) { - ast_rtp_instance_get_engine(instance0)->local_bridge(instance0, NULL); - } - if (instance1 && ast_rtp_instance_get_engine(instance1)->local_bridge) { - ast_rtp_instance_get_engine(instance1)->local_bridge(instance1, NULL); + if (ast_rtp_instance_get_engine(glue0->audio.instance)->local_bridge) { + ast_rtp_instance_get_engine(glue0->audio.instance)->local_bridge(glue0->audio.instance, NULL); } - ast_rtp_instance_set_bridged(instance0, NULL); - if (instance1) { - ast_rtp_instance_set_bridged(instance1, NULL); + if (ast_rtp_instance_get_engine(glue1->audio.instance)->local_bridge) { + ast_rtp_instance_get_engine(glue1->audio.instance)->local_bridge(glue1->audio.instance, NULL); } + ast_rtp_instance_set_bridged(glue0->audio.instance, NULL); + ast_rtp_instance_set_bridged(glue1->audio.instance, NULL); break; case AST_RTP_GLUE_RESULT_REMOTE: if (target) { @@ -236,10 +483,38 @@ static void native_rtp_bridge_stop(struct ast_bridge *bridge, struct ast_channel * If a target was provided, it is being put on hold and should expect to * receive media from Asterisk instead of what it was previously connected to. */ + ast_debug(2, "Bridge '%s'. Bringing back '%s' to us\n", + bridge->uniqueid, ast_channel_name(target)); if (bc0->chan == target) { - glue0->update_peer(bc0->chan, NULL, NULL, NULL, NULL, 0); + data0->remote_cb = NULL; + glue0->cb->update_peer(bc0->chan, NULL, NULL, NULL, NULL, 0); + } else { + data1->remote_cb = NULL; + glue1->cb->update_peer(bc1->chan, NULL, NULL, NULL, NULL, 0); + } + } else { + data0->remote_cb = NULL; + data1->remote_cb = NULL; + /* + * XXX We don't want to bring back the channels if we are + * switching to T.38. We have received a reinvite on one channel + * and we will be sending a reinvite on the other to start T.38. + * If we bring the streams back now we confuse the chan_pjsip + * channel driver processing the incoming T.38 reinvite with + * reinvite glare. I think this is really a bug in chan_pjsip + * that this exception case is working around. + */ + if (rtp_glue_get_current_combined_result(bc0->chan, bc1->chan) + != AST_RTP_GLUE_RESULT_FORBID) { + ast_debug(2, "Bridge '%s'. Bringing back '%s' and '%s' to us\n", + bridge->uniqueid, ast_channel_name(bc0->chan), + ast_channel_name(bc1->chan)); + glue0->cb->update_peer(bc0->chan, NULL, NULL, NULL, NULL, 0); + glue1->cb->update_peer(bc1->chan, NULL, NULL, NULL, NULL, 0); } else { - glue1->update_peer(bc1->chan, NULL, NULL, NULL, NULL, 0); + ast_debug(2, "Bridge '%s'. Skip bringing back '%s' and '%s' to us\n", + bridge->uniqueid, ast_channel_name(bc0->chan), + ast_channel_name(bc1->chan)); } } break; @@ -247,10 +522,8 @@ static void native_rtp_bridge_stop(struct ast_bridge *bridge, struct ast_channel break; } - if (!target && native_type != AST_RTP_GLUE_RESULT_FORBID) { - glue0->update_peer(bc0->chan, NULL, NULL, NULL, NULL, 0); - glue1->update_peer(bc1->chan, NULL, NULL, NULL, NULL, 0); - } + rtp_glue_data_reset(glue0); + rtp_glue_data_reset(glue1); ast_debug(2, "Discontinued RTP bridging of '%s' and '%s' - media will flow through Asterisk core\n", ast_channel_name(bc0->chan), ast_channel_name(bc1->chan)); @@ -259,11 +532,15 @@ static void native_rtp_bridge_stop(struct ast_bridge *bridge, struct ast_channel ast_channel_unlock(bc1->chan); } -/*! \brief Frame hook that is called to intercept hold/unhold */ -static struct ast_frame *native_rtp_framehook(struct ast_channel *chan, struct ast_frame *f, enum ast_framehook_event event, void *data) +/*! + * \internal + * \brief Frame hook that is called to intercept hold/unhold + */ +static struct ast_frame *native_rtp_framehook(struct ast_channel *chan, + struct ast_frame *f, enum ast_framehook_event event, void *data) { RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup); - struct native_rtp_bridge_data *native_data = data; + struct native_rtp_framehook_data *native_data = data; if (!f || (event != AST_FRAMEHOOK_EVENT_WRITE)) { return f; @@ -293,39 +570,49 @@ static struct ast_frame *native_rtp_framehook(struct ast_channel *chan, struct a } ast_bridge_unlock(bridge); ast_channel_lock(chan); - } return f; } -/*! \brief Callback function which informs upstream if we are consuming a frame of a specific type */ +/*! + * \internal + * \brief Callback function which informs upstream if we are consuming a frame of a specific type + */ static int native_rtp_framehook_consume(void *data, enum ast_frame_type type) { return (type == AST_FRAME_CONTROL ? 1 : 0); } -/*! \brief Internal helper function which checks whether the channels are compatible with our native bridging */ +/*! + * \internal + * \brief Internal helper function which checks whether a channel is compatible with our native bridging + */ static int native_rtp_bridge_capable(struct ast_channel *chan) { return !ast_channel_has_hook_requiring_audio(chan); } +/*! + * \internal + * \brief Internal helper function which checks whether both channels are compatible with our native bridging + */ static int native_rtp_bridge_compatible_check(struct ast_bridge *bridge, struct ast_bridge_channel *bc0, struct ast_bridge_channel *bc1) { enum ast_rtp_glue_result native_type; - struct ast_rtp_glue *glue0; - struct ast_rtp_glue *glue1; - RAII_VAR(struct ast_rtp_instance *, instance0, NULL, ao2_cleanup); - RAII_VAR(struct ast_rtp_instance *, instance1, NULL, ao2_cleanup); - RAII_VAR(struct ast_rtp_instance *, vinstance0, NULL, ao2_cleanup); - RAII_VAR(struct ast_rtp_instance *, vinstance1, NULL, ao2_cleanup); - RAII_VAR(struct ast_format_cap *, cap0, NULL, ao2_cleanup); - RAII_VAR(struct ast_format_cap *, cap1, NULL, ao2_cleanup); int read_ptime0; int read_ptime1; int write_ptime0; int write_ptime1; + struct rtp_glue_data glue_a; + struct rtp_glue_data glue_b; + RAII_VAR(struct ast_format_cap *, cap0, NULL, ao2_cleanup); + RAII_VAR(struct ast_format_cap *, cap1, NULL, ao2_cleanup); + RAII_VAR(struct rtp_glue_data *, glue0, NULL, rtp_glue_data_destroy); + RAII_VAR(struct rtp_glue_data *, glue1, NULL, rtp_glue_data_destroy); + + ast_debug(1, "Bridge '%s'. Checking compatability for channels '%s' and '%s'\n", + bridge->uniqueid, ast_channel_name(bc0->chan), ast_channel_name(bc1->chan)); if (!native_rtp_bridge_capable(bc0->chan)) { ast_debug(1, "Bridge '%s' can not use native RTP bridge as channel '%s' has features which prevent it\n", @@ -339,8 +626,17 @@ static int native_rtp_bridge_compatible_check(struct ast_bridge *bridge, struct return 0; } - native_type = native_rtp_bridge_get(bc0->chan, bc1->chan, &glue0, &glue1, - &instance0, &instance1, &vinstance0, &vinstance1); + rtp_glue_data_init(&glue_a); + glue0 = &glue_a; + rtp_glue_data_init(&glue_b); + glue1 = &glue_b; + if (rtp_glue_data_get(bc0->chan, glue0, bc1->chan, glue1)) { + ast_debug(1, "Bridge '%s' can not use native RTP bridge as could not get details\n", + bridge->uniqueid); + return 0; + } + native_type = glue0->result; + if (native_type == AST_RTP_GLUE_RESULT_FORBID) { ast_debug(1, "Bridge '%s' can not use native RTP bridge as it was forbidden while getting details\n", bridge->uniqueid); @@ -348,25 +644,25 @@ static int native_rtp_bridge_compatible_check(struct ast_bridge *bridge, struct } if (ao2_container_count(bc0->features->dtmf_hooks) - && ast_rtp_instance_dtmf_mode_get(instance0)) { + && ast_rtp_instance_dtmf_mode_get(glue0->audio.instance)) { ast_debug(1, "Bridge '%s' can not use native RTP bridge as channel '%s' has DTMF hooks\n", bridge->uniqueid, ast_channel_name(bc0->chan)); return 0; } if (ao2_container_count(bc1->features->dtmf_hooks) - && ast_rtp_instance_dtmf_mode_get(instance1)) { + && ast_rtp_instance_dtmf_mode_get(glue1->audio.instance)) { ast_debug(1, "Bridge '%s' can not use native RTP bridge as channel '%s' has DTMF hooks\n", bridge->uniqueid, ast_channel_name(bc1->chan)); return 0; } if (native_type == AST_RTP_GLUE_RESULT_LOCAL - && (ast_rtp_instance_get_engine(instance0)->local_bridge - != ast_rtp_instance_get_engine(instance1)->local_bridge - || (ast_rtp_instance_get_engine(instance0)->dtmf_compatible - && !ast_rtp_instance_get_engine(instance0)->dtmf_compatible(bc0->chan, - instance0, bc1->chan, instance1)))) { + && (ast_rtp_instance_get_engine(glue0->audio.instance)->local_bridge + != ast_rtp_instance_get_engine(glue1->audio.instance)->local_bridge + || (ast_rtp_instance_get_engine(glue0->audio.instance)->dtmf_compatible + && !ast_rtp_instance_get_engine(glue0->audio.instance)->dtmf_compatible(bc0->chan, + glue0->audio.instance, bc1->chan, glue1->audio.instance)))) { ast_debug(1, "Bridge '%s' can not use local native RTP bridge as local bridge or DTMF is not compatible\n", bridge->uniqueid); return 0; @@ -379,11 +675,11 @@ static int native_rtp_bridge_compatible_check(struct ast_bridge *bridge, struct } /* Make sure that codecs match */ - if (glue0->get_codec) { - glue0->get_codec(bc0->chan, cap0); + if (glue0->cb->get_codec) { + glue0->cb->get_codec(bc0->chan, cap0); } - if (glue1->get_codec) { - glue1->get_codec(bc1->chan, cap1); + if (glue1->cb->get_codec) { + glue1->cb->get_codec(bc1->chan, cap1); } if (ast_format_cap_count(cap0) != 0 && ast_format_cap_count(cap1) != 0 @@ -413,6 +709,10 @@ static int native_rtp_bridge_compatible_check(struct ast_bridge *bridge, struct return 1; } +/*! + * \internal + * \brief Called by the bridge core "compatible' callback + */ static int native_rtp_bridge_compatible(struct ast_bridge *bridge) { struct ast_bridge_channel *bc0; @@ -437,10 +737,13 @@ static int native_rtp_bridge_compatible(struct ast_bridge *bridge) return is_compatible; } -/*! \brief Helper function which adds frame hook to bridge channel */ +/*! + * \internal + * \brief Helper function which adds frame hook to bridge channel + */ static int native_rtp_bridge_framehook_attach(struct ast_bridge_channel *bridge_channel) { - struct native_rtp_bridge_data *data = ao2_alloc(sizeof(*data), NULL); + struct native_rtp_bridge_channel_data *data = bridge_channel->tech_pvt; static struct ast_framehook_interface hook = { .version = AST_FRAMEHOOK_INTERFACE_VERSION, .event_cb = native_rtp_framehook, @@ -449,45 +752,82 @@ static int native_rtp_bridge_framehook_attach(struct ast_bridge_channel *bridge_ .disable_inheritance = 1, }; - if (!data) { + ast_assert(data->hook_data == NULL); + data->hook_data = ao2_alloc_options(sizeof(*data->hook_data), NULL, + AO2_ALLOC_OPT_LOCK_NOLOCK); + if (!data->hook_data) { return -1; } + ast_debug(2, "Bridge '%s'. Attaching hook data %p to '%s'\n", + bridge_channel->bridge->uniqueid, data, ast_channel_name(bridge_channel->chan)); + ast_channel_lock(bridge_channel->chan); - hook.data = ao2_bump(data); - data->id = ast_framehook_attach(bridge_channel->chan, &hook); + /* We're giving 1 ref to the framehook and keeping the one from the alloc for ourselves */ + hook.data = ao2_bump(data->hook_data); + data->hook_data->id = ast_framehook_attach(bridge_channel->chan, &hook); ast_channel_unlock(bridge_channel->chan); - if (data->id < 0) { - /* We need to drop both the reference we hold, and the one the framehook would hold */ - ao2_ref(data, -2); + if (data->hook_data->id < 0) { + /* + * We need to drop both the reference we hold in data, + * and the one the framehook would hold. + */ + ao2_ref(data->hook_data, -2); + data->hook_data = NULL; + return -1; } - bridge_channel->tech_pvt = data; - return 0; } -/*! \brief Helper function which removes frame hook from bridge channel */ +/*! + * \internal + * \brief Helper function which removes frame hook from bridge channel + */ static void native_rtp_bridge_framehook_detach(struct ast_bridge_channel *bridge_channel) { - RAII_VAR(struct native_rtp_bridge_data *, data, bridge_channel->tech_pvt, ao2_cleanup); + struct native_rtp_bridge_channel_data *data = bridge_channel->tech_pvt; - if (!data) { + if (!data || !data->hook_data) { return; } + ast_debug(2, "Bridge '%s'. Detaching hook data %p from '%s'\n", + bridge_channel->bridge->uniqueid, data->hook_data, ast_channel_name(bridge_channel->chan)); + ast_channel_lock(bridge_channel->chan); - ast_framehook_detach(bridge_channel->chan, data->id); - data->detached = 1; + ast_framehook_detach(bridge_channel->chan, data->hook_data->id); + data->hook_data->detached = 1; ast_channel_unlock(bridge_channel->chan); - bridge_channel->tech_pvt = NULL; + ao2_cleanup(data->hook_data); + data->hook_data = NULL; } +/*! + * \internal + * \brief Called by the bridge core 'join' callback for each channel joining he bridge + */ static int native_rtp_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel) { - native_rtp_bridge_framehook_detach(bridge_channel); + ast_debug(2, "Bridge '%s'. Channel '%s' is joining bridge tech\n", + bridge->uniqueid, ast_channel_name(bridge_channel->chan)); + + ast_assert(bridge_channel->tech_pvt == NULL); + + if (bridge_channel->suspended) { + /* The channel will rejoin when it is unsuspended */ + return 0; + } + + bridge_channel->tech_pvt = native_rtp_bridge_channel_data_alloc(); + if (!bridge_channel->tech_pvt) { + return -1; + } + if (native_rtp_bridge_framehook_attach(bridge_channel)) { + native_rtp_bridge_channel_data_free(bridge_channel->tech_pvt); + bridge_channel->tech_pvt = NULL; return -1; } @@ -495,15 +835,46 @@ static int native_rtp_bridge_join(struct ast_bridge *bridge, struct ast_bridge_c return 0; } +/*! + * \internal + * \brief Add the channel back into the bridge + */ static void native_rtp_bridge_unsuspend(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel) { + ast_debug(2, "Bridge '%s'. Channel '%s' is unsuspended back to bridge tech\n", + bridge->uniqueid, ast_channel_name(bridge_channel->chan)); native_rtp_bridge_join(bridge, bridge_channel); } +/*! + * \internal + * \brief Leave the bridge + */ static void native_rtp_bridge_leave(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel) { + ast_debug(2, "Bridge '%s'. Channel '%s' is leaving bridge tech\n", + bridge->uniqueid, ast_channel_name(bridge_channel->chan)); + + if (!bridge_channel->tech_pvt) { + return; + } + native_rtp_bridge_framehook_detach(bridge_channel); native_rtp_bridge_stop(bridge, NULL); + + native_rtp_bridge_channel_data_free(bridge_channel->tech_pvt); + bridge_channel->tech_pvt = NULL; +} + +/*! + * \internal + * \brief Suspend the channel from the bridge + */ +static void native_rtp_bridge_suspend(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel) +{ + ast_debug(2, "Bridge '%s'. Channel '%s' is suspending from bridge tech\n", + bridge->uniqueid, ast_channel_name(bridge_channel->chan)); + native_rtp_bridge_leave(bridge, bridge_channel); } static int native_rtp_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame) @@ -548,7 +919,7 @@ static struct ast_bridge_technology native_rtp_bridge = { .join = native_rtp_bridge_join, .unsuspend = native_rtp_bridge_unsuspend, .leave = native_rtp_bridge_leave, - .suspend = native_rtp_bridge_leave, + .suspend = native_rtp_bridge_suspend, .write = native_rtp_bridge_write, .compatible = native_rtp_bridge_compatible, }; diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index 72fbe6e0c..4f717ffac 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -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 */ @@ -19356,163 +19282,6 @@ static int setup_dahdi(int reload) } /*! - * \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 * * Module loading including tests for configuration or dependencies. @@ -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); diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index d15b55d72..f40873e9d 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -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); diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c index 7cab42873..fc59c900c 100644 --- a/channels/chan_pjsip.c +++ b/channels/chan_pjsip.c @@ -1372,8 +1372,7 @@ static int update_connected_line_information(void *data) int generate_new_sdp; method = session->endpoint->id.refresh_method; - if (session->inv_session->invite_tsx - && (session->inv_session->options & PJSIP_INV_SUPPORT_UPDATE)) { + if (session->inv_session->options & PJSIP_INV_SUPPORT_UPDATE) { method = AST_SIP_SESSION_REFRESH_METHOD_UPDATE; } @@ -1962,6 +1961,12 @@ static int chan_pjsip_digit_begin(struct ast_channel *chan, char digit) ast_rtp_instance_dtmf_begin(media->rtp, digit); break; + case AST_SIP_DTMF_AUTO_INFO: + if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_NONE)) { + return -1; + } + ast_rtp_instance_dtmf_begin(media->rtp, digit); + break; case AST_SIP_DTMF_NONE: break; case AST_SIP_DTMF_INBAND: @@ -2063,6 +2068,20 @@ static int chan_pjsip_digit_end(struct ast_channel *ast, char digit, unsigned in media = channel->session->active_media_state->default_session[AST_MEDIA_TYPE_AUDIO]; switch (channel->session->endpoint->dtmf) { + case AST_SIP_DTMF_AUTO_INFO: + { + if (!media || !media->rtp) { + return -1; + } + if (ast_rtp_instance_dtmf_mode_get(media->rtp) != AST_RTP_DTMF_MODE_NONE) { + ast_debug(3, "Told to send end of digit on Auto-Info channel %s RFC4733 negotiated so using it.\n", ast_channel_name(ast)); + ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration); + break; + } + /* If RFC_4733 was not negotiated, fail through to the DTMF_INFO processing */ + ast_debug(3, "Told to send end of digit on Auto-Info channel %s RFC4733 NOT negotiated using INFO instead.\n", ast_channel_name(ast)); + } + case AST_SIP_DTMF_INFO: { struct info_dtmf_data *dtmf_data = info_dtmf_data_alloc(channel->session, digit, duration); @@ -2095,14 +2114,15 @@ static int chan_pjsip_digit_end(struct ast_channel *ast, char digit, unsigned in } ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration); - break; - case AST_SIP_DTMF_AUTO: - if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_INBAND)) { - return -1; - } - - ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration); - break; + break; + case AST_SIP_DTMF_AUTO: + if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_INBAND)) { + return -1; + } + + ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration); + break; + case AST_SIP_DTMF_NONE: break; diff --git a/channels/chan_sip.c b/channels/chan_sip.c index aaeb01e13..f2daf2b8f 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -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" @@ -33278,17 +33277,17 @@ static int reload_config(enum channelreloadreason reason) /* If TCP is running on a different IP than UDP, then add it too */ if (!ast_sockaddr_isnull(&sip_tcp_desc.local_address) && - !ast_sockaddr_cmp(&bindaddr, &sip_tcp_desc.local_address)) { + ast_sockaddr_cmp_addr(&bindaddr, &sip_tcp_desc.local_address)) { add_sip_domain(ast_sockaddr_stringify_addr(&sip_tcp_desc.local_address), SIP_DOMAIN_AUTO, NULL); } /* If TLS is running on a different IP than UDP and TCP, then add that too */ if (!ast_sockaddr_isnull(&sip_tls_desc.local_address) && - !ast_sockaddr_cmp(&bindaddr, &sip_tls_desc.local_address) && - !ast_sockaddr_cmp(&sip_tcp_desc.local_address, + ast_sockaddr_cmp_addr(&bindaddr, &sip_tls_desc.local_address) && + ast_sockaddr_cmp_addr(&sip_tcp_desc.local_address, &sip_tls_desc.local_address)) { - add_sip_domain(ast_sockaddr_stringify_addr(&sip_tcp_desc.local_address), + add_sip_domain(ast_sockaddr_stringify_addr(&sip_tls_desc.local_address), SIP_DOMAIN_AUTO, NULL); } @@ -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)); diff --git a/configs/samples/musiconhold.conf.sample b/configs/samples/musiconhold.conf.sample index b2980fc1d..741bde603 100644 --- a/configs/samples/musiconhold.conf.sample +++ b/configs/samples/musiconhold.conf.sample @@ -97,3 +97,26 @@ directory=moh ;mode=custom ;directory=/var/lib/asterisk/mohmp3 ;application=/site/sw/bin/madplay -Q -o raw:- --mono -R 8000 -a -12 + +; By default, when res_musiconhold reloads or unloads, it sends a HUP signal +; to custom applications (and all descendants), waits 100ms, then sends a +; TERM signal, waits 100ms, then finally sends a KILL signal. An application +; which is interacting with an external device and/or spawns children of its +; own may not be able to exit cleanly in the default times, expecially if sent +; a KILL signal, or if it's children are getting signals directly from +; res_musiconhoild. To allow extra time, the 'kill_escalation_delay' +; class option can be used to set the number of milliseconds res_musiconhold +; waits before escalating kill signals, with the default being the current +; 100ms. To control to whom the signals are sent, the "kill_method" +; class option can be set to "process_group" (the default, existing behavior), +; which sends signals to the application and its descendants directly, or +; "process" which sends signals only to the application itself. + +;[sox_from_device] +;mode=custom +;directory=/var/lib/asterisk/mohmp3 +;application=/usr/bin/sox -q -t alsa -c 2 -r 48000 hw:1 -c 1 -r 8000 -t raw -s - +; Wait 500ms before escalating kill signals +;kill_escalation_delay=500 +; Send signals to just the child process instead of all descendants +;kill_method=process diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample index ed5f93e71..c05938ea5 100644 --- a/configs/samples/pjsip.conf.sample +++ b/configs/samples/pjsip.conf.sample @@ -608,8 +608,15 @@ ;direct_media_glare_mitigation=none ; Mitigation of direct media re INVITE ; glare (default: "none") ;direct_media_method=invite ; Direct Media method type (default: "invite") -;connected_line_method=invite ; Connected line method type (default: - ; "invite") +;connected_line_method=invite ; Connected line method type. + ; When set to "invite", check the remote's + ; Allow header and if UPDATE is allowed, send + ; UPDATE instead of INVITE to avoid SDP + ; renegotiation. If UPDATE is not Allowed, + ; send INVITE. + ; If set to "update", send UPDATE regardless + ; of what the remote Allows. + ; (default: "invite") ;direct_media=yes ; Determines whether media may flow directly between ; endpoints (default: "yes") ;disable_direct_media_on_nat=no ; Disable direct media session refreshes when @@ -1219,6 +1219,7 @@ PJPROJECT_LIB PBX_PJPROJECT PJPROJECT_DIR PJPROJECT_BUNDLED +PJPROJECT_CONFIGURE_OPTS AST_C_COMPILER_FAMILY AST_CLANG_BLOCKS AST_CLANG_BLOCKS_LIBS @@ -1355,7 +1356,6 @@ infodir docdir oldincludedir includedir -runstatedir localstatedir sharedstatedir sysconfdir @@ -1484,6 +1484,7 @@ CXX CXXFLAGS CCC CXXCPP +PJPROJECT_CONFIGURE_OPTS PKG_CONFIG PKG_CONFIG_PATH PKG_CONFIG_LIBDIR @@ -1539,7 +1540,6 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -1792,15 +1792,6 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; - -runstatedir | --runstatedir | --runstatedi | --runstated \ - | --runstate | --runstat | --runsta | --runst | --runs \ - | --run | --ru | --r) - ac_prev=runstatedir ;; - -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ - | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ - | --run=* | --ru=* | --r=*) - runstatedir=$ac_optarg ;; - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1938,7 +1929,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir runstatedir + libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -2091,7 +2082,6 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -2242,6 +2232,8 @@ Some influential environment variables: CXX C++ compiler command CXXFLAGS C++ compiler flags CXXCPP C++ preprocessor + PJPROJECT_CONFIGURE_OPTS + Additional configure options to pass to bundled pjproject PKG_CONFIG path to pkg-config utility PKG_CONFIG_PATH directories to add to pkg-config's search path @@ -9315,20 +9307,33 @@ $as_echo "configuring" >&6; } as_fn_error $? "cat is required to build bundled pjproject" "$LINENO" 5 fi + + this_host=$(./config.sub $(./config.guess)) + if test "$build" != "$this_host" ; then + PJPROJECT_CONFIGURE_OPTS+=" --build=$build" + fi + if test "$host" != "$this_host" ; then + PJPROJECT_CONFIGURE_OPTS+=" --host=$host" + fi + export TAR PATCH SED NM EXTERNALS_CACHE_DIR DOWNLOAD_TO_STDOUT DOWNLOAD_TIMEOUT DOWNLOAD MD5 CAT - ${GNU_MAKE} --quiet --no-print-directory -C ${PJPROJECT_DIR} EXTERNALS_CACHE_DIR=${EXTERNALS_CACHE_DIR} configure + export NOISY_BUILD + ${GNU_MAKE} --quiet --no-print-directory -C ${PJPROJECT_DIR} \ + PJPROJECT_CONFIGURE_OPTS="$PJPROJECT_CONFIGURE_OPTS" \ + EXTERNALS_CACHE_DIR="${EXTERNALS_CACHE_DIR}" \ + configure if test $? -ne 0 ; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5 $as_echo "failed" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: Unable to configure ${PJPROJECT_DIR}" >&5 $as_echo "$as_me: Unable to configure ${PJPROJECT_DIR}" >&6;} - as_fn_error $? "Run \"${GNU_MAKE} -C ${PJPROJECT_DIR} NOISY_BUILD=yes configure\" to see error details." "$LINENO" 5 + as_fn_error $? "Re-run the ./configure command with 'NOISY_BUILD=yes' appended to see error details." "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for bundled pjproject" >&5 $as_echo_n "checking for bundled pjproject... " >&6; } - PJPROJECT_INCLUDE=$(${GNU_MAKE} --quiet --no-print-directory -C ${PJPROJECT_DIR} EXTERNALS_CACHE_DIR=${EXTERNALS_CACHE_DIR} echo_cflags) + PJPROJECT_INCLUDE=$(${GNU_MAKE} --quiet --no-print-directory -C ${PJPROJECT_DIR} PJPROJECT_CONFIGURE_OPTS="$PJPROJECT_CONFIGURE_OPTS" EXTERNALS_CACHE_DIR="${EXTERNALS_CACHE_DIR}" echo_cflags) PJPROJECT_CFLAGS="$PJPROJECT_INCLUDE" PBX_PJPROJECT=1 @@ -14910,7 +14915,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -14956,7 +14961,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -14980,7 +14985,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -15025,7 +15030,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -15049,7 +15054,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; diff --git a/contrib/ast-db-manage/config/versions/164abbd708c_add_auto_info_to_endpoint_dtmf_mode.py b/contrib/ast-db-manage/config/versions/164abbd708c_add_auto_info_to_endpoint_dtmf_mode.py new file mode 100644 index 000000000..20cab2f38 --- /dev/null +++ b/contrib/ast-db-manage/config/versions/164abbd708c_add_auto_info_to_endpoint_dtmf_mode.py @@ -0,0 +1,58 @@ +"""Add auto_info to endpoint dtmf_mode + +Revision ID: 164abbd708c +Revises: 39959b9c2566 +Create Date: 2017-06-19 13:55:15.354706 + +""" + +# revision identifiers, used by Alembic. +revision = '164abbd708c' +down_revision = '39959b9c2566' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects.postgresql import ENUM + +OLD_ENUM = ['rfc4733', 'inband', 'info', 'auto'] +NEW_ENUM = ['rfc4733', 'inband', 'info', 'auto', 'auto_info'] + +old_type = sa.Enum(*OLD_ENUM, name='pjsip_dtmf_mode_values_v2') +new_type = sa.Enum(*NEW_ENUM, name='pjsip_dtmf_mode_values_v3') + +def upgrade(): + context = op.get_context() + + # Upgrading to this revision WILL clear your directmedia values. + if context.bind.dialect.name != 'postgresql': + op.alter_column('ps_endpoints', 'dtmf_mode', + type_=new_type, + existing_type=old_type) + else: + enum = ENUM('rfc4733', 'inband', 'info', 'auto', 'auto_info', + name='pjsip_dtmf_mode_values_v3') + enum.create(op.get_bind(), checkfirst=False) + + op.execute('ALTER TABLE ps_endpoints ALTER COLUMN dtmf_mode TYPE' + ' pjsip_dtmf_mode_values_v3 USING' + ' dtmf_mode::text::pjsip_dtmf_mode_values_v3') + + ENUM(name="pjsip_dtmf_mode_values_v2").drop(op.get_bind(), checkfirst=False) + +def downgrade(): + context = op.get_context() + + if context.bind.dialect.name != 'postgresql': + op.alter_column('ps_endpoints', 'dtmf_mode', + type_=old_type, + existing_type=new_type) + else: + enum = ENUM('rfc4733', 'inband', 'info', 'auto', + name='pjsip_dtmf_mode_values_v2') + enum.create(op.get_bind(), checkfirst=False) + + op.execute('ALTER TABLE ps_endpoints ALTER COLUMN dtmf_mode TYPE' + ' pjsip_dtmf_mode_values USING' + ' dtmf_mode::text::pjsip_dtmf_mode_values_v2') + + ENUM(name="pjsip_dtmf_mode_values_v3").drop(op.get_bind(), checkfirst=False) diff --git a/include/asterisk/_private.h b/include/asterisk/_private.h index b3c2b2002..e989b16fd 100644 --- a/include/asterisk/_private.h +++ b/include/asterisk/_private.h @@ -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 */ diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index 005803d5c..197cc990d 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -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" @@ -3839,27 +3839,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 * \deprecated You should use the ast_channel_redirecting_sub() function instead. diff --git a/include/asterisk/data.h b/include/asterisk/data.h deleted file mode 100644 index d6da1f7d6..000000000 --- a/include/asterisk/data.h +++ /dev/null @@ -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 */ diff --git a/include/asterisk/indications.h b/include/asterisk/indications.h index b02be1fdf..309954b05 100644 --- a/include/asterisk/indications.h +++ b/include/asterisk/indications.h @@ -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 */ diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h index f907effcf..2cd27d37f 100644 --- a/include/asterisk/res_pjsip.h +++ b/include/asterisk/res_pjsip.h @@ -365,6 +365,8 @@ enum ast_sip_dtmf_mode { AST_SIP_DTMF_INFO, /*! Use SIP 4733 if supported by the other side or INBAND if not */ AST_SIP_DTMF_AUTO, + /*! Use SIP 4733 if supported by the other side or INFO DTMF (blech) if not */ + AST_SIP_DTMF_AUTO_INFO, }; /*! diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h index 5f439163f..36f499b50 100644 --- a/include/asterisk/rtp_engine.h +++ b/include/asterisk/rtp_engine.h @@ -640,12 +640,13 @@ struct ast_rtp_glue { /*! * \brief Used to prevent two channels from remotely bridging audio rtp if the channel tech has a * reason for prohibiting it based on qualities that need to be compared from both channels. - * \note This function may be NULL for a given channel driver. This should be accounted for and if that is the case, function this is not used. + * \note This function may be NULL for a given channel driver. This should be accounted for and if that is the case, this function is not used. */ int (*allow_rtp_remote)(struct ast_channel *chan1, struct ast_rtp_instance *instance); /*! * \brief Callback for retrieving the RTP instance carrying video * \note This function increases the reference count on the returned RTP instance. + * \note This function may be NULL for a given channel driver. This should be accounted for and if that is the case, this function is not used. */ enum ast_rtp_glue_result (*get_vrtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance); /*! @@ -658,11 +659,15 @@ struct ast_rtp_glue { /*! * \brief Callback for retrieving the RTP instance carrying text * \note This function increases the reference count on the returned RTP instance. + * \note This function may be NULL for a given channel driver. This should be accounted for and if that is the case, this function is not used. */ enum ast_rtp_glue_result (*get_trtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance); /*! Callback for updating the destination that the remote side should send RTP to */ int (*update_peer)(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, const struct ast_format_cap *cap, int nat_active); - /*! Callback for retrieving codecs that the channel can do. Result returned in result_cap. */ + /*! + * \brief Callback for retrieving codecs that the channel can do. Result returned in result_cap. + * \note This function may be NULL for a given channel driver. This should be accounted for and if that is the case, this function is not used. + */ void (*get_codec)(struct ast_channel *chan, struct ast_format_cap *result_cap); /*! Linked list information */ AST_RWLIST_ENTRY(ast_rtp_glue) entry; diff --git a/main/asterisk.c b/main/asterisk.c index 16313ea68..04298385a 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -3681,7 +3681,9 @@ static void ast_readconfig(void) /* Set the maximum amount of open files */ } else if (!strcasecmp(v->name, "maxfiles")) { ast_option_maxfiles = atoi(v->value); - set_ulimit(ast_option_maxfiles); + if (!ast_opt_remote) { + set_ulimit(ast_option_maxfiles); + } /* What user to run as */ } else if (!strcasecmp(v->name, "runuser")) { ast_copy_string(cfg_paths.run_user, v->value, sizeof(cfg_paths.run_user)); @@ -4560,7 +4562,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"); diff --git a/main/cdr.c b/main/cdr.c index 214af2cbc..1817e80a7 100644 --- a/main/cdr.c +++ b/main/cdr.c @@ -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" diff --git a/main/channel.c b/main/channel.c index c7c2b9d1e..811826f1c 100644 --- a/main/channel.c +++ b/main/channel.c @@ -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" @@ -3262,8 +3261,12 @@ int ast_waitfordigit_full(struct ast_channel *c, int timeout_ms, int audiofd, in } else if (rchan) { int res; struct ast_frame *f = ast_read(c); - if (!f) + + if (!f) { + ast_channel_clear_flag(c, AST_FLAG_END_DTMF_ONLY); + return -1; + } switch (f->frametype) { case AST_FRAME_DTMF_BEGIN: @@ -7566,122 +7569,6 @@ int ast_plc_reload(void) /*! * \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). * \since 12.0.0 * @@ -7879,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"); @@ -7904,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); diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c index 5e7df8983..d31ce94d8 100644 --- a/main/channel_internal_api.c +++ b/main/channel_internal_api.c @@ -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) \ diff --git a/main/data.c b/main/data.c deleted file mode 100644 index 15aca8b9d..000000000 --- a/main/data.c +++ /dev/null @@ -1,3346 +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> - */ - -/*** MODULEINFO - <support_level>core</support_level> - ***/ - -#include "asterisk.h" - -#include "asterisk/_private.h" - -#include <regex.h> - -#include "asterisk/module.h" -#include "asterisk/utils.h" -#include "asterisk/lock.h" -#include "asterisk/data.h" -#include "asterisk/astobj2.h" -#include "asterisk/xml.h" -#include "asterisk/cli.h" -#include "asterisk/term.h" -#include "asterisk/manager.h" -#include "asterisk/test.h" -#include "asterisk/frame.h" -#include "asterisk/codec.h" - -/*** DOCUMENTATION - <manager name="DataGet" language="en_US"> - <synopsis> - Retrieve the data api tree. - </synopsis> - <syntax> - <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" /> - <parameter name="Path" required="true" /> - <parameter name="Search" /> - <parameter name="Filter" /> - </syntax> - <description> - <para>Retrieve the data api tree.</para> - </description> - </manager> - ***/ - -#define NUM_DATA_NODE_BUCKETS 59 -#define NUM_DATA_RESULT_BUCKETS 59 -#define NUM_DATA_SEARCH_BUCKETS 59 -#define NUM_DATA_FILTER_BUCKETS 59 - -/*! \brief The last compatible version. */ -static const uint32_t latest_handler_compatible_version = 0; - -/*! \brief The last compatible version. */ -static const uint32_t latest_query_compatible_version = 0; - -/*! \brief Current handler structure version. */ -static const uint32_t current_handler_version = AST_DATA_HANDLER_VERSION; - -/*! \brief Current query structure version. */ -static const uint32_t current_query_version = AST_DATA_QUERY_VERSION; - -/*! \brief The data tree to be returned by the callbacks and - managed by functions local to this file. */ -struct ast_data { - enum ast_data_type type; - - /*! \brief The node content. */ - union { - int32_t sint; - uint32_t uint; - double dbl; - unsigned int boolean; - char *str; - char character; - struct in_addr ipaddr; - void *ptr; - } payload; - - /*! \brief The filter node that depends on the current node, - * this is used only when creating the result tree. */ - const struct data_filter *filter; - - /*! \brief The list of nodes inside this node. */ - struct ao2_container *children; - /*! \brief The name of the node. */ - char name[0]; -}; - -/*! \brief Type of comparisons allow in the search string. */ -enum data_search_comparison { - DATA_CMP_UNKNOWN, - DATA_CMP_EQ, /* = */ - DATA_CMP_NEQ, /* != */ - DATA_CMP_GT, /* > */ - DATA_CMP_GE, /* >= */ - DATA_CMP_LT, /* < */ - DATA_CMP_LE /* <= */ -}; - -/*! \brief The list of nodes with their search requirement. */ -struct ast_data_search { - /*! \brief The value of the comparison. */ - char *value; - /*! \brief The type of comparison. */ - enum data_search_comparison cmp_type; - /*! \brief reference another node. */ - struct ao2_container *children; - /*! \brief The name of the node we are trying to compare. */ - char name[0]; -}; - -struct data_filter; - -/*! \brief The filter node. */ -struct data_filter { - /*! \brief node childrens. */ - struct ao2_container *children; - /*! \brief glob list */ - AST_LIST_HEAD_NOLOCK(glob_list_t, data_filter) glob_list; - /*! \brief glob list entry */ - AST_LIST_ENTRY(data_filter) list; - /*! \brief node name. */ - char name[0]; -}; - -/*! \brief A data container node pointing to the registered handler. */ -struct data_provider { - /*! \brief node content handler. */ - const struct ast_data_handler *handler; - /*! \brief Module providing this handler. */ - struct ast_module *module; - /*! \brief children nodes. */ - struct ao2_container *children; - /*! \brief Who registered this node. */ - const char *registrar; - /*! \brief Node name. */ - char name[0]; -}; - -/*! \brief This structure is used by the iterator. */ -struct ast_data_iterator { - /*! \brief The internal iterator. */ - struct ao2_iterator internal_iterator; - /*! \brief The last returned node. */ - struct ast_data *last; - /*! \brief The iterator pattern. */ - const char *pattern; - /*! \brief The compiled patter. */ - regex_t regex_pattern; - /*! \brief is a regular expression. */ - unsigned int is_pattern:1; -}; - -struct { - /*! \brief The asterisk data main content structure. */ - struct ao2_container *container; - /*! \brief asterisk data locking mechanism. */ - ast_rwlock_t lock; -} root_data; - -static void __data_result_print_cli(int fd, const struct ast_data *root, uint32_t depth); - -/*! - * \internal - * \brief Common string hash function. - * \see ast_data_init - */ -static int data_provider_hash(const void *obj, const int flags) -{ - const struct data_provider *node = obj; - return ast_str_case_hash(node->name); -} - -/*! - * \internal - * \brief Compare two data_provider's. - * \see ast_data_init - */ -static int data_provider_cmp(void *obj1, void *obj2, int flags) -{ - struct data_provider *node1 = obj1, *node2 = obj2; - return strcasecmp(node1->name, node2->name) ? 0 : CMP_MATCH; -} - -/*! - * \internal - * \brief Common string hash function for data nodes - */ -static int data_result_hash(const void *obj, const int flags) -{ - const struct ast_data *node = obj; - return ast_str_hash(node->name); -} - -/*! - * \internal - * \brief Common string comparison function - */ -static int data_result_cmp(void *obj, void *arg, int flags) -{ - struct ast_data *node1 = obj, *node2 = arg; - return strcasecmp(node1->name, node2->name) ? 0 : CMP_MATCH; -} - -/*! - * \internal - * \brief Lock the data registered handlers structure for writing. - * \see data_unlock - */ -#define data_write_lock() ast_rwlock_wrlock(&root_data.lock) - -/*! - * \internal - * \brief Lock the data registered handlers structure for reading. - * \see data_unlock - */ -#define data_read_lock() ast_rwlock_rdlock(&root_data.lock) - -/*! - * \internal - * \brief Unlock the data registered handlers structure. - */ -#define data_unlock() ast_rwlock_unlock(&root_data.lock) - -/*! - * \internal - * \brief Check if a version is compatible with the current core. - * \param[in] structure_version The current structure version. - * \param[in] latest_compatible The latest compatible version. - * \param[in] current The current Data API version. - * \retval 1 If the module is compatible. - * \retval 0 If the module is NOT compatible. - */ -static int data_structure_compatible(int structure_version, uint32_t latest_compatible, - uint32_t current) -{ - if (structure_version >= latest_compatible && structure_version <= current) { - return 1; - } - - ast_log(LOG_ERROR, "A module is not compatible with the" - "current data api version\n"); - - return 0; -} - -/*! - * \internal - * \brief Get the next node name in a path (/node1/node2) - * Avoid null nodes like //node1//node2/node3. - * \param[in] path The path where we are going to search for the next node name. - * \retval The next node name we found inside the given path. - * \retval NULL if there are no more node names. - */ -static char *next_node_name(char **path) -{ - char *res; - - do { - res = strsep(path, "/"); - } while (res && ast_strlen_zero(res)); - - return res; -} - -/*! - * \internal - * \brief Release the memory allocated by a call to ao2_alloc. - */ -static void data_provider_destructor(void *obj) -{ - struct data_provider *provider = obj; - - ao2_ref(provider->children, -1); -} - -/*! - * \internal - * \brief Create a new data node. - * \param[in] name The name of the node we are going to create. - * \param[in] handler The handler registered for this node. - * \param[in] registrar The name of the registrar. - * \retval NULL on error. - * \retval The allocated data node structure. - */ -static struct data_provider *data_provider_new(const char *name, - const struct ast_data_handler *handler, const char *registrar) -{ - struct data_provider *node; - size_t namelen; - - namelen = strlen(name) + 1; - - node = ao2_alloc(sizeof(*node) + namelen, data_provider_destructor); - if (!node) { - return NULL; - } - - node->handler = handler; - node->registrar = registrar; - strcpy(node->name, name); - - /* initialize the childrens container. */ - if (!(node->children = ao2_container_alloc(NUM_DATA_NODE_BUCKETS, - data_provider_hash, data_provider_cmp))) { - ao2_ref(node, -1); - return NULL; - } - - return node; -} - -/*! - * \internal - * \brief Add a child node named 'name' to the 'parent' node. - * \param[in] parent Where to add the child node. - * \param[in] name The name of the child node. - * \param[in] handler The handler structure. - * \param[in] registrar Who registered this node. - * \retval NULL on error. - * \retval A newly allocated child in parent. - */ -static struct data_provider *data_provider_add_child(struct ao2_container *parent, - const char *name, const struct ast_data_handler *handler, const char *registrar) -{ - struct data_provider *child; - - child = data_provider_new(name, handler, registrar); - if (!child) { - return NULL; - } - - ao2_link(parent, child); - - return child; -} - -/*! - * \internal - * \brief Find a child node, based on his name. - * \param[in] parent Where to find the node. - * \param[in] name The node name to find. - * \param[in] registrar Also check if the node was being used by this registrar. - * \retval NULL if a node wasn't found. - * \retval The node found. - * \note Remember to decrement the ref count of the returned node after using it. - */ -static struct data_provider *data_provider_find(struct ao2_container *parent, - const char *name, const char *registrar) -{ - struct data_provider *find_node, *found; - - /* XXX avoid allocating a new data node for searching... */ - find_node = data_provider_new(name, NULL, NULL); - if (!find_node) { - return NULL; - } - - found = ao2_find(parent, find_node, OBJ_POINTER); - - /* free the created node used for searching. */ - ao2_ref(find_node, -1); - - if (found && found->registrar && registrar) { - if (strcmp(found->registrar, registrar)) { - /* if the name doesn't match, do not return this node. */ - ast_debug(1, "Registrar doesn't match, node was registered" - " by '%s' and we are searching for '%s'\n", - found->registrar, registrar); - ao2_ref(found, -1); - return NULL; - } - } - - return found; -} - -/*! - * \internal - * \brief Release a group of nodes. - * \param[in] parent The parent node. - * \param[in] path The path of nodes to release. - * \param[in] registrar Who registered this node. - * \retval <0 on error. - * \retval 0 on success. - * \see data_provider_create - */ -static int data_provider_release(struct ao2_container *parent, const char *path, - const char *registrar) -{ - char *node_name, *rpath; - struct data_provider *child; - int ret = 0; - - rpath = ast_strdupa(path); - - node_name = next_node_name(&rpath); - if (!node_name) { - return -1; - } - - child = data_provider_find(parent, node_name, registrar); - if (!child) { - return -1; - } - - /* if this is not a terminal node. */ - if (!child->handler && rpath) { - ret = data_provider_release(child->children, rpath, registrar); - } - - /* if this node is empty, unlink it. */ - if (!ret && !ao2_container_count(child->children)) { - ao2_unlink(parent, child); - } - - ao2_ref(child, -1); - - return ret; -} - -/*! - * \internal - * \brief Release every node registered by 'registrar'. - * \param[in] parent The parent node. - * \param[in] registrar - * \see __ast_data_unregister - */ -static void data_provider_release_all(struct ao2_container *parent, - const char *registrar) -{ - struct ao2_iterator i; - struct data_provider *node; - - i = ao2_iterator_init(parent, 0); - while ((node = ao2_iterator_next(&i))) { - if (!node->handler) { - /* this is a non-terminal node, go inside it. */ - data_provider_release_all(node->children, registrar); - if (!ao2_container_count(node->children)) { - /* if this node was left empty, unlink it. */ - ao2_unlink(parent, node); - } - } else { - if (!strcmp(node->registrar, registrar)) { - /* if the registrars match, release it! */ - ao2_unlink(parent, node); - } - } - ao2_ref(node, -1); - } - ao2_iterator_destroy(&i); - -} - -/*! - * \internal - * \brief Create the middle nodes for the specified path (asterisk/testnode1/childnode) - * \param[in] parent Where to add the middle nodes structure. - * \param[in] path The path of nodes to add. - * \param[in] registrar Who is trying to create this node provider. - * \retval NULL on error. - * \retval The created node. - * \see data_provider_release - */ -static struct data_provider *data_provider_create(struct ao2_container *parent, - const char *path, const char *registrar) -{ - char *rpath, *node_name; - struct data_provider *child, *ret = NULL; - - rpath = ast_strdupa(path); - - node_name = next_node_name(&rpath); - if (!node_name) { - /* no more nodes to create. */ - return NULL; - } - - child = data_provider_find(parent, node_name, NULL); - - if (!child) { - /* nodes without handler are non-terminal nodes. */ - child = data_provider_add_child(parent, node_name, NULL, registrar); - } - - if (rpath) { - ret = data_provider_create(child->children, rpath, registrar); - if (ret) { - ao2_ref(child, -1); - } - } - - return ret ? ret : child; -} - -int __ast_data_register(const char *path, const struct ast_data_handler *handler, - const char *registrar, struct ast_module *mod) -{ - struct data_provider *node; - - if (!path) { - return -1; - } - - /* check if the handler structure is compatible. */ - if (!data_structure_compatible(handler->version, - latest_handler_compatible_version, - current_handler_version)) { - return -1; - } - - /* create the node structure for the registered handler. */ - data_write_lock(); - - node = data_provider_create(root_data.container, path, registrar); - if (!node) { - ast_log(LOG_ERROR, "Unable to create the specified path (%s) " - "for '%s'.\n", path, registrar); - data_unlock(); - return -1; - } - - if (ao2_container_count(node->children) || node->handler) { - ast_log(LOG_ERROR, "The node '%s' was already registered. " - "We were unable to register '%s' for registrar '%s'.\n", - node->name, path, registrar); - ao2_ref(node, -1); - data_unlock(); - return -1; - } - - /* add handler to that node. */ - node->handler = handler; - node->module = mod; - - ao2_ref(node, -1); - - data_unlock(); - - return 0; -} - -int __ast_data_register_multiple(const struct ast_data_entry *data_entries, - size_t entries, const char *registrar, struct ast_module *mod) -{ - int i, res; - - for (i = 0; i < entries; i++) { - res = __ast_data_register(data_entries[i].path, data_entries[i].handler, - registrar, mod); - if (res) { - /* unregister all the already registered nodes, and make - * this an atomic action. */ - while ((--i) >= 0) { - __ast_data_unregister(data_entries[i].path, registrar); - } - return -1; - } - } - - return 0; -} - -int __ast_data_unregister(const char *path, const char *registrar) -{ - int ret = 0; - - data_write_lock(); - if (path) { - ret = data_provider_release(root_data.container, path, registrar); - } else { - data_provider_release_all(root_data.container, registrar); - } - data_unlock(); - - if (path && ret) { - ast_log(LOG_ERROR, "Unable to unregister '%s' for '%s'\n", - path, registrar); - } - - return ret; -} - -/*! - * \internal - * \brief Is a char used to specify a comparison? - * \param[in] a Character to evaluate. - * \retval 1 It is a char used to specify a comparison. - * \retval 0 It is NOT a char used to specify a comparison. - */ -static int data_search_comparison_char(char a) -{ - switch (a) { - case '!': - case '=': - case '<': - case '>': - return 1; - } - - return 0; -} - -/*! - * \internal - * \brief Get the type of comparison. - */ -static enum data_search_comparison data_search_comparison_type(const char *comparison) -{ - if (!strcmp(comparison, "=")) { - return DATA_CMP_EQ; - } else if (!strcmp(comparison, "!=")) { - return DATA_CMP_NEQ; - } else if (!strcmp(comparison, "<")) { - return DATA_CMP_LT; - } else if (!strcmp(comparison, ">")) { - return DATA_CMP_GT; - } else if (!strcmp(comparison, "<=")) { - return DATA_CMP_LE; - } else if (!strcmp(comparison, ">=")) { - return DATA_CMP_GE; - } - - return DATA_CMP_UNKNOWN; -} - -/*! - * \internal - * \brief Common string hash function for data nodes - */ -static int data_search_hash(const void *obj, const int flags) -{ - const struct ast_data_search *node = obj; - return ast_str_hash(node->name); -} - -/*! - * \internal - * \brief Common string comparison function - */ -static int data_search_cmp(void *obj, void *arg, int flags) -{ - struct ast_data_search *node1 = obj, *node2 = arg; - return strcasecmp(node1->name, node2->name) ? 0 : CMP_MATCH; -} - -/*! - * \internal - * \brief Destroy the ao2 search node. - */ -static void data_search_destructor(void *obj) -{ - struct ast_data_search *node = obj; - - if (node->value) { - ast_free(node->value); - } - - ao2_ref(node->children, -1); -} - -/*! - * \internal - * \brief Allocate a search node. - * \retval NULL on error. - * \retval non-NULL The allocated search node structure. - */ -static struct ast_data_search *data_search_alloc(const char *name) -{ - struct ast_data_search *res; - size_t name_len = strlen(name) + 1; - - res = ao2_alloc(sizeof(*res) + name_len, data_search_destructor); - if (!res) { - return NULL; - } - - res->children = ao2_container_alloc(NUM_DATA_SEARCH_BUCKETS, data_search_hash, - data_search_cmp); - - if (!res->children) { - ao2_ref(res, -1); - return NULL; - } - - strcpy(res->name, name); - - return res; -} - -/*! - * \internal - * \brief Find a child node, based on his name. - * \param[in] parent Where to find the node. - * \param[in] name The node name to find. - * \retval NULL if a node wasn't found. - * \retval The node found. - * \note Remember to decrement the ref count of the returned node after using it. - */ -static struct ast_data_search *data_search_find(struct ao2_container *parent, - const char *name) -{ - struct ast_data_search *find_node, *found; - - find_node = data_search_alloc(name); - if (!find_node) { - return NULL; - } - - found = ao2_find(parent, find_node, OBJ_POINTER); - - /* free the created node used for searching. */ - ao2_ref(find_node, -1); - - return found; -} - -/*! - * \internal - * \brief Add a child node named 'name' to the 'parent' node. - * \param[in] parent Where to add the child node. - * \param[in] name The name of the child node. - * \retval NULL on error. - * \retval A newly allocated child in parent. - */ -static struct ast_data_search *data_search_add_child(struct ao2_container *parent, - const char *name) -{ - struct ast_data_search *child; - - child = data_search_alloc(name); - if (!child) { - return NULL; - } - - ao2_link(parent, child); - - return child; -} - -/*! - * \internal - * \brief Create the middle nodes for the specified path (asterisk/testnode1/childnode) - * \param[in] parent Where to add the middle nodes structure. - * \param[in] path The path of nodes to add. - * \retval NULL on error. - * \retval The created node. - */ -static struct ast_data_search *data_search_create(struct ao2_container *parent, - const char *path) -{ - char *rpath, *node_name; - struct ast_data_search *child = NULL; - struct ao2_container *current = parent; - - rpath = ast_strdupa(path); - - node_name = next_node_name(&rpath); - while (node_name) { - child = data_search_find(current, node_name); - if (!child) { - child = data_search_add_child(current, node_name); - } - ao2_ref(child, -1); - current = child->children; - node_name = next_node_name(&rpath); - } - - return child; -} - -/*! - * \internal - * \brief Allocate a tree with the search string parsed. - * \param[in] search_string The search string. - * \retval NULL on error. - * \retval non-NULL A dynamically allocated search tree. - */ -static struct ast_data_search *data_search_generate(const char *search_string) -{ - struct ast_str *name, *value, *comparison; - char *elements, *search_string_dup, *saveptr; - int i; - struct ast_data_search *root, *child; - enum data_search_comparison cmp_type; - size_t search_string_len; - - if (!search_string) { - ast_log(LOG_ERROR, "You must pass a valid search string.\n"); - return NULL; - } - - search_string_len = strlen(search_string); - - name = ast_str_create(search_string_len); - if (!name) { - return NULL; - } - value = ast_str_create(search_string_len); - if (!value) { - ast_free(name); - return NULL; - } - comparison = ast_str_create(search_string_len); - if (!comparison) { - ast_free(name); - ast_free(value); - return NULL; - } - - search_string_dup = ast_strdupa(search_string); - - /* Create the root node (just used as a container) */ - root = data_search_alloc("/"); - if (!root) { - ast_free(name); - ast_free(value); - ast_free(comparison); - return NULL; - } - - for (elements = strtok_r(search_string_dup, ",", &saveptr); elements; - elements = strtok_r(NULL, ",", &saveptr)) { - /* Parse the name */ - ast_str_reset(name); - for (i = 0; !data_search_comparison_char(elements[i]) && - elements[i]; i++) { - ast_str_append(&name, 0, "%c", elements[i]); - } - - /* check if the syntax is ok. */ - if (!data_search_comparison_char(elements[i])) { - /* if this is the end of the string, then this is - * an error! */ - ast_log(LOG_ERROR, "Invalid search string!\n"); - continue; - } - - /* parse the comparison string. */ - ast_str_reset(comparison); - for (; data_search_comparison_char(elements[i]) && elements[i]; i++) { - ast_str_append(&comparison, 0, "%c", elements[i]); - } - - /* parse the value string. */ - ast_str_reset(value); - for (; elements[i]; i++) { - ast_str_append(&value, 0, "%c", elements[i]); - } - - cmp_type = data_search_comparison_type(ast_str_buffer(comparison)); - if (cmp_type == DATA_CMP_UNKNOWN) { - ast_log(LOG_ERROR, "Invalid comparison '%s'\n", - ast_str_buffer(comparison)); - continue; - } - - /* add this node to the tree. */ - child = data_search_create(root->children, ast_str_buffer(name)); - if (child) { - child->cmp_type = cmp_type; - child->value = ast_strdup(ast_str_buffer(value)); - } - } - - ast_free(name); - ast_free(value); - ast_free(comparison); - - return root; -} - -/*! - * \internal - * \brief Release the allocated memory for the search tree. - * \param[in] search The search tree root node. - */ -static void data_search_release(struct ast_data_search *search) -{ - ao2_ref(search, -1); -} - -/*! - * \internal - * \brief Based on the kind of comparison and the result in cmpval, return - * if it matches. - * \param[in] cmpval A result returned by a strcmp() for example. - * \param[in] comparison_type The kind of comparison (<,>,=,!=,...) - * \retval 1 If the comparison doesn't match. - * \retval 0 If the comparison matches. - */ -static inline int data_search_comparison_result(int cmpval, - enum data_search_comparison comparison_type) -{ - switch (comparison_type) { - case DATA_CMP_GE: - if (cmpval >= 0) { - return 0; - } - break; - case DATA_CMP_LE: - if (cmpval <= 0) { - return 0; - } - break; - case DATA_CMP_EQ: - if (cmpval == 0) { - return 0; - } - break; - case DATA_CMP_NEQ: - if (cmpval != 0) { - return 0; - } - break; - case DATA_CMP_LT: - if (cmpval < 0) { - return 0; - } - break; - case DATA_CMP_GT: - if (cmpval > 0) { - return 0; - } - break; - case DATA_CMP_UNKNOWN: - break; - } - return 1; -} - -/*! - * \internal - * \brief Get an internal node, from the search tree. - * \param[in] node A node container. - * \param[in] path The path to the needed internal node. - * \retval NULL if the internal node is not found. - * \retval non-NULL the internal node with path 'path'. - */ -static struct ast_data_search *data_search_get_node(const struct ast_data_search *node, - const char *path) -{ - char *savepath, *node_name; - struct ast_data_search *child, *current = (struct ast_data_search *) node; - - if (!node) { - return NULL; - } - - savepath = ast_strdupa(path); - node_name = next_node_name(&savepath); - - while (node_name) { - child = data_search_find(current->children, node_name); - if (current != node) { - ao2_ref(current, -1); - } - if (!child) { - return NULL; - }; - current = child; - node_name = next_node_name(&savepath); - } - - return current; -} - -/*! - * \internal - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current string value. - * .search = "somename=somestring" - * name = "somename" - * value is the current value of something and will be evaluated against "somestring". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] value The value to compare. - * \returns The strcmp return value. - */ -static int data_search_cmp_string(const struct ast_data_search *root, const char *name, - char *value) -{ - struct ast_data_search *child; - enum data_search_comparison cmp_type; - int ret; - - child = data_search_get_node(root, name); - if (!child) { - return 0; - } - - ret = strcmp(value, child->value); - cmp_type = child->cmp_type; - - ao2_ref(child, -1); - - return data_search_comparison_result(ret, cmp_type); -} - -/*! - * \internal - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current pointer address value. - * .search = "something=0x32323232" - * name = "something" - * value is the current value of something and will be evaluated against "0x32323232". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] ptr The pointer address to compare. - * \returns The (value - current_value) result. - */ -static int data_search_cmp_ptr(const struct ast_data_search *root, const char *name, - void *ptr) -{ - struct ast_data_search *child; - enum data_search_comparison cmp_type; - void *node_ptr; - - child = data_search_get_node(root, name); - if (!child) { - return 0; - } - - cmp_type = child->cmp_type; - - if (sscanf(child->value, "%p", &node_ptr) <= 0) { - ao2_ref(child, -1); - return 1; - } - - ao2_ref(child, -1); - - return data_search_comparison_result((node_ptr - ptr), cmp_type); -} - -/*! - * \internal - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current ipv4 address value. - * .search = "something=192.168.2.2" - * name = "something" - * value is the current value of something and will be evaluated against "192.168.2.2". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] addr The ipv4 address value to compare. - * \returns The (value - current_value) result. - */ -static int data_search_cmp_ipaddr(const struct ast_data_search *root, const char *name, - struct in_addr addr) -{ - struct ast_data_search *child; - enum data_search_comparison cmp_type; - struct in_addr node_addr; - - child = data_search_get_node(root, name); - if (!child) { - return 0; - } - cmp_type = child->cmp_type; - - inet_aton(child->value, &node_addr); - - ao2_ref(child, -1); - - return data_search_comparison_result((node_addr.s_addr - addr.s_addr), cmp_type); -} - -/*! - * \internal - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current boolean value. - * .search = "something=true" - * name = "something" - * value is the current value of something and will be evaluated against "true". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] value The boolean value to compare. - * \returns The (value - current_value) result. - */ -static int data_search_cmp_bool(const struct ast_data_search *root, const char *name, - unsigned int value) -{ - struct ast_data_search *child; - unsigned int node_value; - enum data_search_comparison cmp_type; - - child = data_search_get_node(root, name); - if (!child) { - return 0; - } - - node_value = abs(ast_true(child->value)); - cmp_type = child->cmp_type; - - ao2_ref(child, -1); - - return data_search_comparison_result(value - node_value, cmp_type); -} - -/*! - * \internal - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current double value. - * .search = "something=222" - * name = "something" - * value is the current value of something and will be evaluated against "222". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] value The double value to compare. - * \returns The (value - current_value) result. - */ -static int data_search_cmp_dbl(const struct ast_data_search *root, const char *name, - double value) -{ - struct ast_data_search *child; - double node_value; - enum data_search_comparison cmp_type; - - child = data_search_get_node(root, name); - if (!child) { - return 0; - } - - node_value = strtod(child->value, NULL); - cmp_type = child->cmp_type; - - ao2_ref(child, -1); - - return data_search_comparison_result(value - node_value, cmp_type); -} - -/*! - * \internal - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current unsigned integer value. - * .search = "something=10" - * name = "something" - * value is the current value of something and will be evaluated against "10". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] value The unsigned value to compare. - * \returns The strcmp return value. - */ -static int data_search_cmp_uint(const struct ast_data_search *root, const char *name, - unsigned int value) -{ - struct ast_data_search *child; - unsigned int node_value; - enum data_search_comparison cmp_type; - - child = data_search_get_node(root, name); - if (!child) { - return 0; - } - - node_value = atoi(child->value); - cmp_type = child->cmp_type; - - ao2_ref(child, -1); - - return data_search_comparison_result(value - node_value, cmp_type); -} - -/*! - * \internal - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current signed integer value. - * .search = "something=10" - * name = "something" - * value is the current value of something and will be evaluated against "10". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] value The value to compare. - * \returns The strcmp return value. - */ -static int data_search_cmp_int(const struct ast_data_search *root, const char *name, - int value) -{ - struct ast_data_search *child; - int node_value; - enum data_search_comparison cmp_type; - - child = data_search_get_node(root, name); - if (!child) { - return 0; - } - - node_value = atoi(child->value); - cmp_type = child->cmp_type; - - ao2_ref(child, -1); - - return data_search_comparison_result(value - node_value, cmp_type); -} - -/*! - * \internal - * \brief Based on a search tree, evaluate the specified 'name' inside the tree with the - * current character value. - * .search = "something=c" - * name = "something" - * value is the current value of something and will be evaluated against "c". - * \param[in] root The root node pointer of the search tree. - * \param[in] name The name of the specific. - * \param[in] value The boolean value to compare. - * \returns The (value - current_value) result. - */ -static int data_search_cmp_char(const struct ast_data_search *root, const char *name, - char value) -{ - struct ast_data_search *child; - char node_value; - enum data_search_comparison cmp_type; - - child = data_search_get_node(root, name); - if (!child) { - return 0; - } - - node_value = *(child->value); - cmp_type = child->cmp_type; - - ao2_ref(child, -1); - - return data_search_comparison_result(value - node_value, cmp_type); -} - -/*! - * \internal - * \brief Get the member pointer, from a mapping structure, based on its name. - * \XXX We will need to improve performance here!!. - * \retval <0 if the member was not found. - * \retval >=0 The member position in the mapping structure. - */ -static inline int data_search_mapping_find(const struct ast_data_mapping_structure *map, - size_t mapping_len, - const char *member_name) -{ - int i; - - for (i = 0; i < mapping_len; i++) { - if (!strcmp(map[i].name, member_name)) { - return i; - } - } - - return -1; -} - -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) -{ - struct ao2_iterator i; - struct ast_data_search *node, *struct_children; - int member, notmatch = 0; - - if (!search) { - return 0; - } - - struct_children = data_search_get_node(search, structure_name); - if (!struct_children) { - return 0; - } - - i = ao2_iterator_init(struct_children->children, 0); - while ((node = ao2_iterator_next(&i))) { - member = data_search_mapping_find(mapping, mapping_len, node->name); - if (member < 0) { - /* the structure member name doesn't match! */ - ao2_ref(node, -1); - ao2_ref(struct_children, -1); - ao2_iterator_destroy(&i); - return 0; - } - - notmatch = 0; - switch (mapping[member].type) { - case AST_DATA_PASSWORD: - notmatch = data_search_cmp_string(struct_children, - node->name, - mapping[member].get.AST_DATA_PASSWORD(structure)); - break; - case AST_DATA_TIMESTAMP: - notmatch = data_search_cmp_uint(struct_children, - node->name, - mapping[member].get.AST_DATA_TIMESTAMP(structure)); - break; - case AST_DATA_SECONDS: - notmatch = data_search_cmp_uint(struct_children, - node->name, - mapping[member].get.AST_DATA_SECONDS(structure)); - break; - case AST_DATA_MILLISECONDS: - notmatch = data_search_cmp_uint(struct_children, - node->name, - mapping[member].get.AST_DATA_MILLISECONDS(structure)); - break; - case AST_DATA_STRING: - notmatch = data_search_cmp_string(struct_children, - node->name, - mapping[member].get.AST_DATA_STRING(structure)); - break; - case AST_DATA_CHARACTER: - notmatch = data_search_cmp_char(struct_children, - node->name, - mapping[member].get.AST_DATA_CHARACTER(structure)); - break; - case AST_DATA_INTEGER: - notmatch = data_search_cmp_int(struct_children, - node->name, - mapping[member].get.AST_DATA_INTEGER(structure)); - break; - case AST_DATA_BOOLEAN: - notmatch = data_search_cmp_bool(struct_children, - node->name, - mapping[member].get.AST_DATA_BOOLEAN(structure)); - break; - case AST_DATA_UNSIGNED_INTEGER: - notmatch = data_search_cmp_uint(struct_children, - node->name, - mapping[member].get.AST_DATA_UNSIGNED_INTEGER(structure)); - break; - case AST_DATA_DOUBLE: - notmatch = data_search_cmp_dbl(struct_children, - node->name, - mapping[member].get.AST_DATA_DOUBLE(structure)); - break; - case AST_DATA_IPADDR: - notmatch = data_search_cmp_ipaddr(struct_children, - node->name, - mapping[member].get.AST_DATA_IPADDR(structure)); - break; - case AST_DATA_POINTER: - notmatch = data_search_cmp_ptr(struct_children, - node->name, - mapping[member].get.AST_DATA_POINTER(structure)); - break; - case AST_DATA_CONTAINER: - break; - } - - ao2_ref(node, -1); - } - ao2_iterator_destroy(&i); - - ao2_ref(struct_children, -1); - - return notmatch; -} - -/*! - * \internal - * \brief Release the memory allocated by a call to ao2_alloc. - */ -static void data_result_destructor(void *obj) -{ - struct ast_data *root = obj; - - switch (root->type) { - case AST_DATA_PASSWORD: - case AST_DATA_STRING: - ast_free(root->payload.str); - ao2_ref(root->children, -1); - break; - case AST_DATA_POINTER: - case AST_DATA_CHARACTER: - case AST_DATA_CONTAINER: - case AST_DATA_INTEGER: - case AST_DATA_TIMESTAMP: - case AST_DATA_SECONDS: - case AST_DATA_MILLISECONDS: - case AST_DATA_UNSIGNED_INTEGER: - case AST_DATA_DOUBLE: - case AST_DATA_BOOLEAN: - case AST_DATA_IPADDR: - ao2_ref(root->children, -1); - break; - } -} - -static struct ast_data *data_result_create(const char *name) -{ - struct ast_data *res; - size_t namelen; - - namelen = ast_strlen_zero(name) ? 1 : strlen(name) + 1; - - res = ao2_alloc(sizeof(*res) + namelen, data_result_destructor); - if (!res) { - return NULL; - } - - strcpy(res->name, namelen ? name : ""); - - /* initialize the children container */ - res->children = ao2_container_alloc(NUM_DATA_RESULT_BUCKETS, data_result_hash, - data_result_cmp); - if (!res->children) { - ao2_ref(res, -1); - return NULL; - } - - /* set this node as a container. */ - res->type = AST_DATA_CONTAINER; - - return res; -} - -/*! - * \internal - * \brief Find a child node, based on its name. - * \param[in] root The starting point. - * \param[in] name The child name. - * \retval NULL if the node wasn't found. - * \retval non-NULL the node we were looking for. - */ -static struct ast_data *data_result_find_child(struct ast_data *root, const char *name) -{ - struct ast_data *found, *find_node; - - find_node = data_result_create(name); - if (!find_node) { - return NULL; - } - - found = ao2_find(root->children, find_node, OBJ_POINTER); - - /* release the temporary created node used for searching. */ - ao2_ref(find_node, -1); - - return found; -} - -int ast_data_search_match(const struct ast_data_search *search, struct ast_data *data) -{ - struct ao2_iterator i, ii; - struct ast_data_search *s, *s_child; - struct ast_data *d_child; - int notmatch = 1; - - if (!search) { - return 1; - } - - s_child = data_search_find(search->children, data->name); - if (!s_child) { - /* nothing to compare */ - ao2_ref(s_child, -1); - return 1; - } - - i = ao2_iterator_init(s_child->children, 0); - while ((s = ao2_iterator_next(&i))) { - if (!ao2_container_count(s->children)) { - /* compare this search node with every data node */ - d_child = data_result_find_child(data, s->name); - if (!d_child) { - ao2_ref(s, -1); - notmatch = 1; - continue; - } - - switch (d_child->type) { - case AST_DATA_PASSWORD: - case AST_DATA_STRING: - notmatch = data_search_cmp_string(s_child, d_child->name, - d_child->payload.str); - break; - case AST_DATA_CHARACTER: - notmatch = data_search_cmp_char(s_child, d_child->name, - d_child->payload.character); - break; - case AST_DATA_INTEGER: - notmatch = data_search_cmp_int(s_child, d_child->name, - d_child->payload.sint); - break; - case AST_DATA_BOOLEAN: - notmatch = data_search_cmp_bool(s_child, d_child->name, - d_child->payload.boolean); - break; - case AST_DATA_UNSIGNED_INTEGER: - notmatch = data_search_cmp_uint(s_child, d_child->name, - d_child->payload.uint); - break; - case AST_DATA_TIMESTAMP: - case AST_DATA_SECONDS: - case AST_DATA_MILLISECONDS: - case AST_DATA_DOUBLE: - notmatch = data_search_cmp_uint(s_child, d_child->name, - d_child->payload.dbl); - break; - case AST_DATA_IPADDR: - notmatch = data_search_cmp_ipaddr(s_child, d_child->name, - d_child->payload.ipaddr); - break; - case AST_DATA_POINTER: - notmatch = data_search_cmp_ptr(s_child, d_child->name, - d_child->payload.ptr); - break; - case AST_DATA_CONTAINER: - break; - } - ao2_ref(d_child, -1); - } else { - ii = ao2_iterator_init(data->children, 0); - while ((d_child = ao2_iterator_next(&ii))) { - if (strcmp(d_child->name, s->name)) { - ao2_ref(d_child, -1); - continue; - } - if (!(notmatch = !ast_data_search_match(s_child, d_child))) { - /* do not continue if we have a match. */ - ao2_ref(d_child, -1); - break; - } - ao2_ref(d_child, -1); - } - ao2_iterator_destroy(&ii); - } - ao2_ref(s, -1); - if (notmatch) { - /* do not continue if we don't have a match. */ - break; - } - } - ao2_iterator_destroy(&i); - - ao2_ref(s_child, -1); - - return !notmatch; -} - -/*! - * \internal - * \brief Get an internal node, from the result set. - * \param[in] node A node container. - * \param[in] path The path to the needed internal node. - * \retval NULL if the internal node is not found. - * \retval non-NULL the internal node with path 'path'. - */ -static struct ast_data *data_result_get_node(struct ast_data *node, - const char *path) -{ - char *savepath, *node_name; - struct ast_data *child, *current = node; - - savepath = ast_strdupa(path); - node_name = next_node_name(&savepath); - - while (node_name) { - child = data_result_find_child(current, node_name); - if (current != node) { - ao2_ref(current, -1); - } - if (!child) { - return NULL; - } - current = child; - node_name = next_node_name(&savepath); - } - - /* do not increment the refcount of the returned object. */ - if (current != node) { - ao2_ref(current, -1); - } - - return current; -} - -/*! - * \internal - * \brief Add a child to the specified root node. - * \param[in] root The root node pointer. - * \param[in] child The child to add to the root node. - */ -static void data_result_add_child(struct ast_data *root, struct ast_data *child) -{ - ao2_link(root->children, child); -} - -/*! - * \internal - * \brief Common string hash function for data nodes - */ -static int data_filter_hash(const void *obj, const int flags) -{ - const struct data_filter *node = obj; - return ast_str_hash(node->name); -} - -/*! - * \internal - * \brief Common string comparison function - */ -static int data_filter_cmp(void *obj, void *arg, int flags) -{ - struct data_filter *node1 = obj, *node2 = arg; - return strcasecmp(node1->name, node2->name) ? 0 : CMP_MATCH; -} - -/*! - * \internal - * \brief Destroy a data filter tree. - * \param[in] obj Data filter list to be destroyed. - */ -static void data_filter_destructor(void *obj) -{ - struct data_filter *filter = obj, *globres; - - while ((globres = AST_LIST_REMOVE_HEAD(&(filter->glob_list), list))) { - ao2_ref(globres, -1); - } - - ao2_ref(filter->children, -1); -} - -/*! - * \internal - * \brief Allocate a filter node. - * \retval NULL on error. - * \retval non-NULL The allocated search node structure. - */ -static struct data_filter *data_filter_alloc(const char *name) -{ - char *globname, *token; - struct data_filter *res, *globfilter; - size_t name_len = strlen(name) + 1; - - res = ao2_alloc(sizeof(*res) + name_len, data_filter_destructor); - if (!res) { - return NULL; - } - - res->children = ao2_container_alloc(NUM_DATA_FILTER_BUCKETS, data_filter_hash, - data_filter_cmp); - - if (!res->children) { - ao2_ref(res, -1); - return NULL; - } - - strcpy(res->name, name); - - if (strchr(res->name, '*')) { - globname = ast_strdupa(res->name); - - while ((token = strsep(&globname, "*"))) { - globfilter = data_filter_alloc(token); - AST_LIST_INSERT_TAIL(&(res->glob_list), globfilter, list); - } - } - - return res; -} - -/*! - * \internal - * \brief Release a filter tree. - * \param[in] filter The filter tree root node. - */ -static void data_filter_release(struct data_filter *filter) -{ - ao2_ref(filter, -1); -} - -/*! - * \internal - * \brief Find a child node, based on his name. - * \param[in] parent Where to find the node. - * \param[in] name The node name to find. - * \retval NULL if a node wasn't found. - * \retval The node found. - * \note Remember to decrement the ref count of the returned node after using it. - */ -static struct data_filter *data_filter_find(struct ao2_container *parent, - const char *name) -{ - int i, olend, orend, globfound; - size_t name_len = strlen(name), glob_len; - struct ao2_iterator iter; - struct data_filter *find_node, *found, *globres; - - find_node = data_filter_alloc(name); - if (!find_node) { - return NULL; - } - - found = ao2_find(parent, find_node, OBJ_POINTER); - - /* free the created node used for searching. */ - ao2_ref(find_node, -1); - - if (found) { - return found; - } - - iter = ao2_iterator_init(parent, 0); - while ((found = ao2_iterator_next(&iter))) { - if (!AST_LIST_EMPTY(&(found->glob_list))) { - i = 0; - globfound = 1; - - olend = ast_strlen_zero(AST_LIST_FIRST(&(found->glob_list))->name); - orend = ast_strlen_zero(AST_LIST_LAST(&(found->glob_list))->name); - - AST_LIST_TRAVERSE(&(found->glob_list), globres, list) { - if (!*globres->name) { - continue; - } - - glob_len = strlen(globres->name); - - if (!i && !olend) { - if (strncasecmp(name, globres->name, glob_len)) { - globfound = 0; - break; - } - - i += glob_len; - continue; - } - - for (globfound = 0; name_len - i >= glob_len; ++i) { - if (!strncasecmp(name + i, globres->name, glob_len)) { - globfound = 1; - i += glob_len; - break; - } - } - - if (!globfound) { - break; - } - } - - if (globfound && (i == name_len || orend)) { - ao2_iterator_destroy(&iter); - return found; - } - } - - ao2_ref(found, -1); - } - ao2_iterator_destroy(&iter); - - return NULL; -} - -/*! - * \internal - * \brief Add a child to the specified node. - * \param[in] root The root node where to add the child. - * \param[in] name The name of the node to add. - * \note Remember to decrement the ref count after using the returned node. - */ -static struct data_filter *data_filter_add_child(struct ao2_container *root, - char *name) -{ - struct data_filter *node; - - node = data_filter_find(root, name); - if (node) { - return node; - } - - node = data_filter_alloc(name); - if (!node) { - return NULL; - } - - ao2_link(root, node); - - return node; -} - -/*! - * \internal - * \brief Add a node to a filter list from a path - * \param[in] Filter list to add the path onto. - * \param[in] The path to add into the filter list. - * \retval NULL on error. - * \retval non-NULL A tree with the wanted nodes. - */ -static int data_filter_add_nodes(struct ao2_container *root, char *path) -{ - struct data_filter *node; - char *savepath, *saveptr, *token, *node_name; - int ret = 0; - - if (!path) { - return 0; - } - - savepath = ast_strdupa(path); - - node_name = next_node_name(&savepath); - - if (!node_name) { - return 0; - } - - for (token = strtok_r(node_name, "|", &saveptr); - token; token = strtok_r(NULL, "|", &saveptr)) { - node = data_filter_add_child(root, token); - if (!node) { - continue; - } - data_filter_add_nodes(node->children, savepath); - ret = 1; - ao2_ref(node, -1); - } - - return ret; -} - -/*! - * \internal - * \brief Generate a filter list based on a filter string provided by the API user. - * \param[in] A filter string to create a filter from. - */ -static struct data_filter *data_filter_generate(const char *constfilter) -{ - struct data_filter *filter = NULL; - char *strfilter, *token, *saveptr; - int node_added = 0; - - if (!constfilter) { - return NULL; - } - - strfilter = ast_strdupa(constfilter); - - filter = data_filter_alloc("/"); - if (!filter) { - return NULL; - } - - for (token = strtok_r(strfilter, ",", &saveptr); token; - token = strtok_r(NULL, ",", &saveptr)) { - node_added = data_filter_add_nodes(filter->children, token); - } - - if (!node_added) { - ao2_ref(filter, -1); - return NULL; - } - - return filter; -} - -/*! - * \internal - * \brief Generate all the tree from a specified provider. - * \param[in] query The query executed. - * \param[in] root_provider The provider specified in the path of the query. - * \param[in] parent_node_name The root node name. - * \retval NULL on error. - * \retval non-NULL The generated result tree. - */ -static struct ast_data *data_result_generate_node(const struct ast_data_query *query, - const struct data_provider *root_provider, - const char *parent_node_name, - const struct ast_data_search *search, - const struct data_filter *filter) -{ - struct ast_data *generated, *node; - struct ao2_iterator i; - struct data_provider *provider; - struct ast_data_search *search_child = NULL; - struct data_filter *filter_child; - - node = data_result_create(parent_node_name); - if (!node) { - ast_log(LOG_ERROR, "Unable to allocate '%s' node\n", parent_node_name); - return NULL; - } - - if (root_provider->module) { - ast_module_ref(root_provider->module); - } - - /* if this is a terminal node, just run the callback function. */ - if (root_provider->handler && root_provider->handler->get) { - node->filter = filter; - root_provider->handler->get(search, node); - if (root_provider->module) { - ast_module_unref(root_provider->module); - } - return node; - } - - if (root_provider->module) { - ast_module_unref(root_provider->module); - } - - /* if this is not a terminal node, generate every child node. */ - i = ao2_iterator_init(root_provider->children, 0); - while ((provider = ao2_iterator_next(&i))) { - filter_child = NULL; - generated = NULL; - - /* get the internal search node. */ - if (search) { - search_child = data_search_find(search->children, provider->name); - } - /* get the internal filter node. */ - if (filter) { - filter_child = data_filter_find(filter->children, provider->name); - } - - if (!filter || filter_child) { - /* only generate the internal node, if we have something to - * generate based on the filtering string. */ - generated = data_result_generate_node(query, provider, - provider->name, - search_child, filter_child); - } - - /* decrement the refcount of the internal search node. */ - if (search_child) { - ao2_ref(search_child, -1); - } - - /* decrement the refcount of the internal filter node. */ - if (filter_child) { - ao2_ref(filter_child, -1); - } - - if (generated) { - data_result_add_child(node, generated); - ao2_ref(generated, -1); - } - - ao2_ref(provider, -1); - } - ao2_iterator_destroy(&i); - - return node; -} - -/*! - * \internal - * \brief Generate a result tree based on a query. - * \param[in] query The complete query structure. - * \param[in] search_path The path to retrieve. - * \retval NULL on error. - * \retval non-NULL The generated data result. - */ -static struct ast_data *data_result_generate(const struct ast_data_query *query, - const char *search_path) -{ - char *node_name, *tmp_path; - struct data_provider *provider_child, *tmp_provider_child; - struct ast_data *result, *result_filtered; - struct ast_data_search *search = NULL, *search_child = NULL; - struct data_filter *filter = NULL, *filter_child = NULL; - - if (!search_path) { - /* generate all the trees?. */ - return NULL; - } - - tmp_path = ast_strdupa(search_path); - - /* start searching the root node name */ - node_name = next_node_name(&tmp_path); - if (!node_name) { - return NULL; - } - provider_child = data_provider_find(root_data.container, node_name, NULL); - - /* continue with the rest of the path. */ - while (provider_child) { - node_name = next_node_name(&tmp_path); - if (!node_name) { - break; - } - - tmp_provider_child = data_provider_find(provider_child->children, - node_name, NULL); - - /* release the reference from this child */ - ao2_ref(provider_child, -1); - - provider_child = tmp_provider_child; - } - - if (!provider_child) { - ast_log(LOG_ERROR, "Invalid path '%s', '%s' not found.\n", - tmp_path, node_name); - return NULL; - } - - /* generate the search tree. */ - if (query->search) { - search = data_search_generate(query->search); - if (search) { - search_child = data_search_find(search->children, - provider_child->name); - } - } - - /* generate the filter tree. */ - if (query->filter) { - filter = data_filter_generate(query->filter); - if (filter) { - filter_child = data_filter_find(filter->children, - provider_child->name); - } - } - - result = data_result_generate_node(query, provider_child, provider_child->name, - search_child, filter_child); - - /* release the requested provider. */ - ao2_ref(provider_child, -1); - - /* release the generated search tree. */ - if (search_child) { - ao2_ref(search_child, -1); - } - - if (filter_child) { - ao2_ref(filter_child, -1); - } - - if (search) { - data_search_release(search); - } - - result_filtered = result; - - /* release the generated filter tree. */ - if (filter) { - data_filter_release(filter); - } - - return result_filtered; -} - -struct ast_data *ast_data_get(const struct ast_data_query *query) -{ - struct ast_data *res; - - /* check compatibility */ - if (!data_structure_compatible(query->version, latest_query_compatible_version, - current_query_version)) { - return NULL; - } - - data_read_lock(); - res = data_result_generate(query, query->path); - data_unlock(); - - if (!res) { - ast_log(LOG_ERROR, "Unable to get data from %s\n", query->path); - return NULL; - } - - return res; -} - -#ifdef HAVE_LIBXML2 -/*! - * \internal - * \brief Helper function to move an ast_data tree to xml. - * \param[in] parent_data The initial ast_data node to be passed to xml. - * \param[out] parent_xml The root node to insert the xml. - */ -static void data_get_xml_add_child(struct ast_data *parent_data, - struct ast_xml_node *parent_xml) -{ - struct ao2_iterator i; - struct ast_data *node; - struct ast_xml_node *child_xml; - char node_content[256]; - - i = ao2_iterator_init(parent_data->children, 0); - while ((node = ao2_iterator_next(&i))) { - child_xml = ast_xml_new_node(node->name); - if (!child_xml) { - ao2_ref(node, -1); - continue; - } - - switch (node->type) { - case AST_DATA_CONTAINER: - data_get_xml_add_child(node, child_xml); - break; - case AST_DATA_PASSWORD: - ast_xml_set_text(child_xml, node->payload.str); - break; - case AST_DATA_TIMESTAMP: - snprintf(node_content, sizeof(node_content), "%u", - node->payload.uint); - ast_xml_set_text(child_xml, node_content); - break; - case AST_DATA_SECONDS: - snprintf(node_content, sizeof(node_content), "%u", - node->payload.uint); - ast_xml_set_text(child_xml, node_content); - break; - case AST_DATA_MILLISECONDS: - snprintf(node_content, sizeof(node_content), "%u", - node->payload.uint); - ast_xml_set_text(child_xml, node_content); - break; - case AST_DATA_STRING: - ast_xml_set_text(child_xml, node->payload.str); - break; - case AST_DATA_CHARACTER: - snprintf(node_content, sizeof(node_content), "%c", - node->payload.character); - ast_xml_set_text(child_xml, node_content); - break; - case AST_DATA_INTEGER: - snprintf(node_content, sizeof(node_content), "%d", - node->payload.sint); - ast_xml_set_text(child_xml, node_content); - break; - case AST_DATA_UNSIGNED_INTEGER: - snprintf(node_content, sizeof(node_content), "%u", - node->payload.uint); - ast_xml_set_text(child_xml, node_content); - break; - case AST_DATA_DOUBLE: - snprintf(node_content, sizeof(node_content), "%f", - node->payload.dbl); - ast_xml_set_text(child_xml, node_content); - break; - case AST_DATA_BOOLEAN: - if (node->payload.boolean) { - ast_xml_set_text(child_xml, "true"); - } else { - ast_xml_set_text(child_xml, "false"); - } - break; - case AST_DATA_POINTER: - snprintf(node_content, sizeof(node_content), "%p", - node->payload.ptr); - ast_xml_set_text(child_xml, node_content); - break; - case AST_DATA_IPADDR: - snprintf(node_content, sizeof(node_content), "%s", - ast_inet_ntoa(node->payload.ipaddr)); - ast_xml_set_text(child_xml, node_content); - break; - } - ast_xml_add_child(parent_xml, child_xml); - - ao2_ref(node, -1); - } - ao2_iterator_destroy(&i); - -} - -struct ast_xml_doc *ast_data_get_xml(const struct ast_data_query *query) -{ - struct ast_xml_doc *doc; - struct ast_xml_node *root; - struct ast_data *res; - - res = ast_data_get(query); - if (!res) { - return NULL; - } - - doc = ast_xml_new(); - if (!doc) { - ast_data_free(res); - return NULL; - } - - root = ast_xml_new_node(res->name); - if (!root) { - ast_xml_close(doc); - } - - ast_xml_set_root(doc, root); - - data_get_xml_add_child(res, root); - - ast_data_free(res); - - return doc; -} -#endif - -enum ast_data_type ast_data_retrieve_type(struct ast_data *node, const char *path) -{ - struct ast_data *internal; - - internal = data_result_get_node(node, path); - if (!internal) { - return -1; - } - - return internal->type; -} - -char *ast_data_retrieve_name(struct ast_data *node) -{ - return node->name; -} - -/*! - * \internal - * \brief Insert a child node inside a passed parent node. - * \param root Where we are going to insert the child node. - * \param name The name of the child node to add. - * \param type The type of content inside the child node. - * \param ptr The actual content of the child node. - * \retval NULL on error. - * \retval non-NULL The added child node pointer. - */ -static struct ast_data *__ast_data_add(struct ast_data *root, const char *name, - enum ast_data_type type, void *ptr) -{ - struct ast_data *node; - struct data_filter *filter, *filter_child = NULL; - - if (!root || !root->children) { - /* invalid data result node. */ - return NULL; - } - - /* check if we need to add this node, based on the filter. */ - if (root->filter) { - filter = data_filter_find(root->filter->children, name); - if (!filter) { - return NULL; - } - ao2_ref(filter, -1); - } - - node = data_result_create(name); - if (!node) { - return NULL; - } - - node->type = type; - - switch (type) { - case AST_DATA_BOOLEAN: - node->payload.boolean = *(unsigned int *) ptr; - break; - case AST_DATA_INTEGER: - node->payload.sint = *(int *) ptr; - break; - case AST_DATA_TIMESTAMP: - case AST_DATA_SECONDS: - case AST_DATA_MILLISECONDS: - case AST_DATA_UNSIGNED_INTEGER: - node->payload.uint = *(unsigned int *) ptr; - break; - case AST_DATA_DOUBLE: - node->payload.dbl = *(double *) ptr; - break; - case AST_DATA_PASSWORD: - case AST_DATA_STRING: - node->payload.str = (char *) ptr; - break; - case AST_DATA_CHARACTER: - node->payload.character = *(char *) ptr; - break; - case AST_DATA_POINTER: - node->payload.ptr = ptr; - break; - case AST_DATA_IPADDR: - node->payload.ipaddr = *(struct in_addr *) ptr; - break; - case AST_DATA_CONTAINER: - if (root->filter) { - filter_child = data_filter_find(root->filter->children, name); - if (filter_child) { - /* do not increment the refcount because it is not neccesary. */ - ao2_ref(filter_child, -1); - } - } - node->filter = filter_child; - break; - default: - break; - } - - data_result_add_child(root, node); - - ao2_ref(node, -1); - - return node; -} - -struct ast_data *ast_data_add_node(struct ast_data *root, const char *name) -{ - return __ast_data_add(root, name, AST_DATA_CONTAINER, NULL); -} - -struct ast_data *ast_data_add_int(struct ast_data *root, const char *name, int value) -{ - return __ast_data_add(root, name, AST_DATA_INTEGER, &value); -} - -struct ast_data *ast_data_add_char(struct ast_data *root, const char *name, char value) -{ - return __ast_data_add(root, name, AST_DATA_CHARACTER, &value); -} - -struct ast_data *ast_data_add_uint(struct ast_data *root, const char *name, - unsigned int value) -{ - return __ast_data_add(root, name, AST_DATA_UNSIGNED_INTEGER, &value); -} - -struct ast_data *ast_data_add_dbl(struct ast_data *root, const char *childname, - double dbl) -{ - return __ast_data_add(root, childname, AST_DATA_DOUBLE, &dbl); -} - -struct ast_data *ast_data_add_bool(struct ast_data *root, const char *childname, - unsigned int boolean) -{ - return __ast_data_add(root, childname, AST_DATA_BOOLEAN, &boolean); -} - -struct ast_data *ast_data_add_ipaddr(struct ast_data *root, const char *childname, - struct in_addr addr) -{ - return __ast_data_add(root, childname, AST_DATA_IPADDR, &addr); -} - -struct ast_data *ast_data_add_ptr(struct ast_data *root, const char *childname, - void *ptr) -{ - return __ast_data_add(root, childname, AST_DATA_POINTER, ptr); -} - -struct ast_data *ast_data_add_timestamp(struct ast_data *root, const char *childname, - unsigned int timestamp) -{ - return __ast_data_add(root, childname, AST_DATA_TIMESTAMP, ×tamp); -} - -struct ast_data *ast_data_add_seconds(struct ast_data *root, const char *childname, - unsigned int seconds) -{ - return __ast_data_add(root, childname, AST_DATA_SECONDS, &seconds); -} - -struct ast_data *ast_data_add_milliseconds(struct ast_data *root, const char *childname, - unsigned int milliseconds) -{ - return __ast_data_add(root, childname, AST_DATA_MILLISECONDS, &milliseconds); -} - -struct ast_data *ast_data_add_password(struct ast_data *root, const char *childname, - const char *value) -{ - char *name; - size_t namelen = 1 + (ast_strlen_zero(value) ? 0 : strlen(value)); - struct ast_data *res; - - if (!(name = ast_malloc(namelen))) { - return NULL; - } - - strcpy(name, (ast_strlen_zero(value) ? "" : value)); - - res = __ast_data_add(root, childname, AST_DATA_PASSWORD, name); - if (!res) { - ast_free(name); - } - - return res; -} - -struct ast_data *ast_data_add_str(struct ast_data *root, const char *childname, - const char *value) -{ - char *name; - size_t namelen = 1 + (ast_strlen_zero(value) ? 0 : strlen(value)); - struct ast_data *res; - - if (!(name = ast_malloc(namelen))) { - return NULL; - } - - strcpy(name, (ast_strlen_zero(value) ? "" : value)); - - res = __ast_data_add(root, childname, AST_DATA_STRING, name); - if (!res) { - ast_free(name); - } - - return res; -} - -int __ast_data_add_structure(struct ast_data *root, - const struct ast_data_mapping_structure *mapping, size_t mapping_len, - void *structure) -{ - int i; - - for (i = 0; i < mapping_len; i++) { - switch (mapping[i].type) { - case AST_DATA_INTEGER: - ast_data_add_int(root, mapping[i].name, - mapping[i].get.AST_DATA_INTEGER(structure)); - break; - case AST_DATA_UNSIGNED_INTEGER: - ast_data_add_uint(root, mapping[i].name, - mapping[i].get.AST_DATA_UNSIGNED_INTEGER(structure)); - break; - case AST_DATA_DOUBLE: - ast_data_add_dbl(root, mapping[i].name, - mapping[i].get.AST_DATA_DOUBLE(structure)); - break; - case AST_DATA_BOOLEAN: - ast_data_add_bool(root, mapping[i].name, - mapping[i].get.AST_DATA_BOOLEAN(structure)); - break; - case AST_DATA_PASSWORD: - ast_data_add_password(root, mapping[i].name, - mapping[i].get.AST_DATA_PASSWORD(structure)); - break; - case AST_DATA_TIMESTAMP: - ast_data_add_timestamp(root, mapping[i].name, - mapping[i].get.AST_DATA_TIMESTAMP(structure)); - break; - case AST_DATA_SECONDS: - ast_data_add_seconds(root, mapping[i].name, - mapping[i].get.AST_DATA_SECONDS(structure)); - break; - case AST_DATA_MILLISECONDS: - ast_data_add_milliseconds(root, mapping[i].name, - mapping[i].get.AST_DATA_MILLISECONDS(structure)); - break; - case AST_DATA_STRING: - ast_data_add_str(root, mapping[i].name, - mapping[i].get.AST_DATA_STRING(structure)); - break; - case AST_DATA_CHARACTER: - ast_data_add_char(root, mapping[i].name, - mapping[i].get.AST_DATA_CHARACTER(structure)); - break; - case AST_DATA_CONTAINER: - break; - case AST_DATA_IPADDR: - ast_data_add_ipaddr(root, mapping[i].name, - mapping[i].get.AST_DATA_IPADDR(structure)); - break; - case AST_DATA_POINTER: - ast_data_add_ptr(root, mapping[i].name, - mapping[i].get.AST_DATA_POINTER(structure)); - break; - } - } - - return 0; -} - -void ast_data_remove_node(struct ast_data *root, struct ast_data *child) -{ - ao2_unlink(root->children, child); -} - -void ast_data_free(struct ast_data *root) -{ - /* destroy it, this will destroy all the internal nodes. */ - ao2_ref(root, -1); -} - -struct ast_data_iterator *ast_data_iterator_init(struct ast_data *tree, - const char *elements) -{ - struct ast_data_iterator *iterator; - struct ao2_iterator i; - struct ast_data *internal = tree; - char *path, *ptr = NULL; - - if (!elements) { - return NULL; - } - - /* tree is the node we want to use to iterate? or we are going - * to iterate thow an internal node? */ - path = ast_strdupa(elements); - - ptr = strrchr(path, '/'); - if (ptr) { - *ptr = '\0'; - internal = data_result_get_node(tree, path); - if (!internal) { - return NULL; - } - } - - iterator = ast_calloc(1, sizeof(*iterator)); - if (!iterator) { - return NULL; - } - - i = ao2_iterator_init(internal->children, 0); - - iterator->pattern = (ptr ? strrchr(elements, '/') + 1 : elements); - - /* is the last node a regular expression?, compile it! */ - if (!regcomp(&(iterator->regex_pattern), iterator->pattern, - REG_EXTENDED | REG_NOSUB | REG_ICASE)) { - iterator->is_pattern = 1; - } - - iterator->internal_iterator = i; - - return iterator; -} - -void ast_data_iterator_end(struct ast_data_iterator *iterator) -{ - /* decrement the reference counter. */ - if (iterator->last) { - ao2_ref(iterator->last, -1); - } - - /* release the generated pattern. */ - if (iterator->is_pattern) { - regfree(&(iterator->regex_pattern)); - } - - ao2_iterator_destroy(&(iterator->internal_iterator)); - - ast_free(iterator); - iterator = NULL; -} - -struct ast_data *ast_data_iterator_next(struct ast_data_iterator *iterator) -{ - struct ast_data *res; - - if (iterator->last) { - /* release the last retrieved node reference. */ - ao2_ref(iterator->last, -1); - } - - while ((res = ao2_iterator_next(&iterator->internal_iterator))) { - /* if there is no node name pattern specified, return - * the next node. */ - if (!iterator->pattern) { - break; - } - - /* if the pattern is a regular expression, check if this node - * matches. */ - if (iterator->is_pattern && !regexec(&(iterator->regex_pattern), - res->name, 0, NULL, 0)) { - break; - } - - /* if there is a pattern specified, check if this node matches - * the wanted node names. */ - if (!iterator->is_pattern && (iterator->pattern && - !strcasecmp(res->name, iterator->pattern))) { - break; - } - - ao2_ref(res, -1); - } - - iterator->last = res; - - return res; -} - -int ast_data_retrieve(struct ast_data *tree, const char *path, - struct ast_data_retrieve *content) -{ - struct ast_data *node; - - if (!content) { - return -1; - } - - node = data_result_get_node(tree, path); - if (!node) { - ast_log(LOG_ERROR, "Invalid internal node %s\n", path); - return -1; - } - - content->type = node->type; - switch (node->type) { - case AST_DATA_STRING: - content->value.AST_DATA_STRING = node->payload.str; - break; - case AST_DATA_PASSWORD: - content->value.AST_DATA_PASSWORD = node->payload.str; - break; - case AST_DATA_TIMESTAMP: - content->value.AST_DATA_TIMESTAMP = node->payload.uint; - break; - case AST_DATA_SECONDS: - content->value.AST_DATA_SECONDS = node->payload.uint; - break; - case AST_DATA_MILLISECONDS: - content->value.AST_DATA_MILLISECONDS = node->payload.uint; - break; - case AST_DATA_CHARACTER: - content->value.AST_DATA_CHARACTER = node->payload.character; - break; - case AST_DATA_INTEGER: - content->value.AST_DATA_INTEGER = node->payload.sint; - break; - case AST_DATA_UNSIGNED_INTEGER: - content->value.AST_DATA_UNSIGNED_INTEGER = node->payload.uint; - break; - case AST_DATA_BOOLEAN: - content->value.AST_DATA_BOOLEAN = node->payload.boolean; - break; - case AST_DATA_IPADDR: - content->value.AST_DATA_IPADDR = node->payload.ipaddr; - break; - case AST_DATA_DOUBLE: - content->value.AST_DATA_DOUBLE = node->payload.dbl; - break; - case AST_DATA_CONTAINER: - break; - case AST_DATA_POINTER: - content->value.AST_DATA_POINTER = node->payload.ptr; - break; - } - - return 0; -} - -/*! - * \internal - * \brief One color for each node type. - */ -static const struct { - enum ast_data_type type; - int color; -} data_result_color[] = { - { AST_DATA_STRING, COLOR_BLUE }, - { AST_DATA_PASSWORD, COLOR_BRBLUE }, - { AST_DATA_TIMESTAMP, COLOR_CYAN }, - { AST_DATA_SECONDS, COLOR_MAGENTA }, - { AST_DATA_MILLISECONDS, COLOR_BRMAGENTA }, - { AST_DATA_CHARACTER, COLOR_GRAY }, - { AST_DATA_INTEGER, COLOR_RED }, - { AST_DATA_UNSIGNED_INTEGER, COLOR_RED }, - { AST_DATA_DOUBLE, COLOR_RED }, - { AST_DATA_BOOLEAN, COLOR_BRRED }, - { AST_DATA_CONTAINER, COLOR_GREEN }, - { AST_DATA_IPADDR, COLOR_BROWN }, - { AST_DATA_POINTER, COLOR_YELLOW }, -}; - -/*! - * \internal - * \brief Get the color configured for a specific node type. - * \param[in] type The node type. - * \returns The color specified for the passed type. - */ -static int data_result_get_color(enum ast_data_type type) -{ - int i; - for (i = 0; i < ARRAY_LEN(data_result_color); i++) { - if (data_result_color[i].type == type) { - return data_result_color[i].color; - } - } - - return COLOR_BLUE; -} - -/*! - * \internal - * \brief Print a node to the CLI. - * \param[in] fd The CLI file descriptor. - * \param[in] node The node to print. - * \param[in] depth The actual node depth in the tree. - */ -static void data_result_print_cli_node(int fd, const struct ast_data *node, uint32_t depth) -{ - int i; - struct ast_str *tabs, *output; - - tabs = ast_str_create(depth * 10 + 1); - if (!tabs) { - return; - } - ast_str_reset(tabs); - for (i = 0; i < depth; i++) { - ast_str_append(&tabs, 0, " "); - } - - output = ast_str_create(20); - if (!output) { - ast_free(tabs); - return; - } - - ast_str_reset(output); - ast_term_color_code(&output, data_result_get_color(node->type), 0); - - switch (node->type) { - case AST_DATA_POINTER: - ast_str_append(&output, 0, "%s%s: %p\n", ast_str_buffer(tabs), - node->name, node->payload.ptr); - break; - case AST_DATA_PASSWORD: - ast_str_append(&output, 0, "%s%s: \"%s\"\n", - ast_str_buffer(tabs), - node->name, - node->payload.str); - break; - case AST_DATA_STRING: - ast_str_append(&output, 0, "%s%s: \"%s\"\n", - ast_str_buffer(tabs), - node->name, - node->payload.str); - break; - case AST_DATA_CHARACTER: - ast_str_append(&output, 0, "%s%s: \'%c\'\n", - ast_str_buffer(tabs), - node->name, - node->payload.character); - break; - case AST_DATA_CONTAINER: - ast_str_append(&output, 0, "%s%s\n", ast_str_buffer(tabs), - node->name); - break; - case AST_DATA_TIMESTAMP: - ast_str_append(&output, 0, "%s%s: %u\n", ast_str_buffer(tabs), - node->name, - node->payload.uint); - break; - case AST_DATA_SECONDS: - ast_str_append(&output, 0, "%s%s: %u\n", ast_str_buffer(tabs), - node->name, - node->payload.uint); - break; - case AST_DATA_MILLISECONDS: - ast_str_append(&output, 0, "%s%s: %u\n", ast_str_buffer(tabs), - node->name, - node->payload.uint); - break; - case AST_DATA_INTEGER: - ast_str_append(&output, 0, "%s%s: %d\n", ast_str_buffer(tabs), - node->name, - node->payload.sint); - break; - case AST_DATA_UNSIGNED_INTEGER: - ast_str_append(&output, 0, "%s%s: %u\n", ast_str_buffer(tabs), - node->name, - node->payload.uint); - break; - case AST_DATA_DOUBLE: - ast_str_append(&output, 0, "%s%s: %lf\n", ast_str_buffer(tabs), - node->name, - node->payload.dbl); - break; - case AST_DATA_BOOLEAN: - ast_str_append(&output, 0, "%s%s: %s\n", ast_str_buffer(tabs), - node->name, - ((node->payload.boolean) ? "True" : "False")); - break; - case AST_DATA_IPADDR: - ast_str_append(&output, 0, "%s%s: %s\n", ast_str_buffer(tabs), - node->name, - ast_inet_ntoa(node->payload.ipaddr)); - break; - } - - ast_free(tabs); - - ast_term_color_code(&output, 0, 0); - - ast_cli(fd, "%s", ast_str_buffer(output)); - - ast_free(output); - - if (node->type == AST_DATA_CONTAINER) { - __data_result_print_cli(fd, node, depth + 1); - } -} - -/*! - * \internal - * \brief Print out an ast_data tree to the CLI. - * \param[in] fd The CLI file descriptor. - * \param[in] root The root node of the tree. - * \param[in] depth Actual depth. - */ - -static void __data_result_print_cli(int fd, const struct ast_data *root, uint32_t depth) -{ - struct ao2_iterator iter; - struct ast_data *node; - - if (root->type == AST_DATA_CONTAINER) { - iter = ao2_iterator_init(root->children, 0); - while ((node = ao2_iterator_next(&iter))) { - data_result_print_cli_node(fd, node, depth + 1); - ao2_ref(node, -1); - } - ao2_iterator_destroy(&iter); - } else { - data_result_print_cli_node(fd, root, depth); - } -} - -/*! - * \internal - * \brief - * \param[in] fd The CLI file descriptor. - * \param[in] root The root node of the tree. - */ -static void data_result_print_cli(int fd, const struct ast_data *root) -{ - ast_cli(fd, COLORIZE_FMT "\n", COLORIZE(data_result_get_color(root->type), 0, root->name)); - - __data_result_print_cli(fd, root, 0); - - ast_cli(fd, "\n"); -} - -/*! - * \internal - * \brief Handle the CLI command "data get". - */ -static char *handle_cli_data_get(struct ast_cli_entry *e, int cmd, - struct ast_cli_args *a) -{ - struct ast_data_query query = { - .version = AST_DATA_QUERY_VERSION - }; - struct ast_data *tree; - - switch (cmd) { - case CLI_INIT: - e->command = "data get"; - e->usage = "" - "Usage: data get <path> [<search> [<filter>]]\n" - " Get the tree based on a path.\n"; - return NULL; - case CLI_GENERATE: - return NULL; - } - - if (a->argc < e->args + 1) { - return CLI_SHOWUSAGE; - } - - query.path = (char *) a->argv[e->args]; - - if (a->argc > e->args + 1) { - query.search = (char *) a->argv[e->args + 1]; - } - - if (a->argc > e->args + 2) { - query.filter = (char *) a->argv[e->args + 2]; - } - - tree = ast_data_get(&query); - if (!tree) { - return CLI_FAILURE; - } - - data_result_print_cli(a->fd, tree); - - ast_data_free(tree); - - return CLI_SUCCESS; -} - -/*! - * \internal - * \brief Print the list of data providers. - * \param[in] fd The CLI file descriptor. - * \param[in] name The last node visited name. - * \param[in] container The childrens of the last node. - * \param[in] path The path to the current node. - */ -static void data_provider_print_cli(int fd, const char *name, - struct ao2_container *container, struct ast_str *path) -{ - struct ao2_iterator i; - struct ast_str *current_path; - struct data_provider *provider; - - current_path = ast_str_create(60); - if (!current_path) { - return; - } - - ast_str_reset(current_path); - if (path) { - ast_str_set(¤t_path, 0, "%s/%s", ast_str_buffer(path), name); - } else { - ast_str_set(¤t_path, 0, "%s", name); - } - - i = ao2_iterator_init(container, 0); - while ((provider = ao2_iterator_next(&i))) { - if (provider->handler) { - /* terminal node, print it. */ - ast_cli(fd, "%s/%s (", ast_str_buffer(current_path), - provider->name); - if (provider->handler->get) { - ast_cli(fd, "get"); - } - ast_cli(fd, ") [%s]\n", provider->registrar); - } - data_provider_print_cli(fd, provider->name, provider->children, - current_path); - ao2_ref(provider, -1); - } - ao2_iterator_destroy(&i); - - ast_free(current_path); -} - -/*! - * \internal - * \brief Handle CLI command "data show providers" - */ -static char *handle_cli_data_show_providers(struct ast_cli_entry *e, int cmd, - struct ast_cli_args *a) -{ - switch (cmd) { - case CLI_INIT: - e->command = "data show providers"; - e->usage = "" - "Usage: data show providers\n" - " Show the list of registered providers\n"; - return NULL; - case CLI_GENERATE: - return NULL; - } - - data_read_lock(); - data_provider_print_cli(a->fd, "", root_data.container, NULL); - data_unlock(); - - return CLI_SUCCESS; -} - -/*! - * \internal - * \brief Data API CLI commands. - */ -static struct ast_cli_entry cli_data[] = { - AST_CLI_DEFINE(handle_cli_data_get, "Data API get"), - AST_CLI_DEFINE(handle_cli_data_show_providers, "Show data providers") -}; - -/*! - * \internal - * \brief Output a tree to the AMI. - * \param[in] s AMI session. - * \param[in] name The root node name. - * \param[in] container The root container. - * \param[in] path The current path. - */ -static void data_result_manager_output(struct mansession *s, const char *name, - struct ao2_container *container, struct ast_str *path, int id) -{ - struct ao2_iterator i; - struct ast_str *current_path; - struct ast_data *node; - int current_id = id; - - current_path = ast_str_create(60); - if (!current_path) { - return; - } - - ast_str_reset(current_path); - if (path) { - ast_str_set(¤t_path, 0, "%s.%s", ast_str_buffer(path), name); - } else { - ast_str_set(¤t_path, 0, "%s", name); - } - - i = ao2_iterator_init(container, 0); - while ((node = ao2_iterator_next(&i))) { - /* terminal node, print it. */ - if (node->type != AST_DATA_CONTAINER) { - astman_append(s, "%d-%s.%s", id, ast_str_buffer(current_path), - node->name); - } - switch (node->type) { - case AST_DATA_CONTAINER: - data_result_manager_output(s, node->name, node->children, current_path, ++current_id); - break; - case AST_DATA_INTEGER: - astman_append(s, ": %d\r\n", node->payload.sint); - break; - case AST_DATA_TIMESTAMP: - case AST_DATA_SECONDS: - case AST_DATA_MILLISECONDS: - case AST_DATA_UNSIGNED_INTEGER: - astman_append(s, ": %u\r\n", node->payload.uint); - break; - case AST_DATA_PASSWORD: - astman_append(s, ": %s\r\n", node->payload.str); - break; - case AST_DATA_STRING: - astman_append(s, ": %s\r\n", node->payload.str); - break; - case AST_DATA_CHARACTER: - astman_append(s, ": %c\r\n", node->payload.character); - break; - case AST_DATA_IPADDR: - astman_append(s, ": %s\r\n", ast_inet_ntoa(node->payload.ipaddr)); - break; - case AST_DATA_POINTER: - break; - case AST_DATA_DOUBLE: - astman_append(s, ": %f\r\n", node->payload.dbl); - break; - case AST_DATA_BOOLEAN: - astman_append(s, ": %s\r\n", - (node->payload.boolean ? "True" : "False")); - break; - } - - ao2_ref(node, -1); - } - ao2_iterator_destroy(&i); - - ast_free(current_path); -} - -/*! - * \internal - * \brief Implements the manager action: "DataGet". - */ -static int manager_data_get(struct mansession *s, const struct message *m) -{ - const char *path = astman_get_header(m, "Path"); - const char *search = astman_get_header(m, "Search"); - const char *filter = astman_get_header(m, "Filter"); - const char *id = astman_get_header(m, "ActionID"); - struct ast_data *res; - struct ast_data_query query = { - .version = AST_DATA_QUERY_VERSION, - .path = (char *) path, - .search = (char *) search, - .filter = (char *) filter, - }; - - if (ast_strlen_zero(path)) { - astman_send_error(s, m, "'Path' parameter not specified"); - return 0; - } - - res = ast_data_get(&query); - if (!res) { - astman_send_error(s, m, "No data returned"); - return 0; - } - - astman_append(s, "Event: DataGet Tree\r\n"); - if (!ast_strlen_zero(id)) { - astman_append(s, "ActionID: %s\r\n", id); - } - data_result_manager_output(s, res->name, res->children, NULL, 0); - astman_append(s, "\r\n"); - - ast_data_free(res); - - return RESULT_SUCCESS; -} - -static int data_add_codec(struct ast_data *codecs, struct ast_format *format) { - struct ast_data *codec; - struct ast_codec *tmp; - - tmp = ast_codec_get_by_id(ast_format_get_codec_id(format)); - if (!tmp) { - return -1; - } - - codec = ast_data_add_node(codecs, "codec"); - if (!codec) { - ao2_ref(tmp, -1); - return -1; - } - - ast_data_add_str(codec, "name", tmp->name); - ast_data_add_int(codec, "samplespersecond", tmp->sample_rate); - ast_data_add_str(codec, "description", tmp->description); - ast_data_add_int(codec, "frame_length", tmp->minimum_bytes); - ao2_ref(tmp, -1); - - return 0; -} - -int ast_data_add_codec(struct ast_data *root, const char *node_name, struct ast_format *format) -{ - struct ast_data *codecs; - - codecs = ast_data_add_node(root, node_name); - if (!codecs) { - return -1; - } - - return data_add_codec(codecs, format); -} - -int ast_data_add_codecs(struct ast_data *root, const char *node_name, struct ast_format_cap *cap) -{ - struct ast_data *codecs; - size_t i; - size_t count; - - codecs = ast_data_add_node(root, node_name); - if (!codecs) { - return -1; - } - - count = ast_format_cap_count(cap); - for (i = 0; i < count; ++i) { - struct ast_format *fmt; - - fmt = ast_format_cap_get_format(cap, i); - if (!fmt) { - return -1; - } - - if (data_add_codec(codecs, fmt)) { - ao2_ref(fmt, -1); - return -1; - } - - ao2_ref(fmt, -1); - } - - return 0; -} - -#ifdef TEST_FRAMEWORK - -/*! - * \internal - * \brief Structure used to test how to add a complete structure, - * and how to compare it. - */ -struct test_structure { - int a_int; - unsigned int b_bool:1; - char *c_str; - unsigned int a_uint; -}; - -/*! - * \internal - * \brief test_structure mapping. - */ -#define DATA_EXPORT_TEST_STRUCTURE(MEMBER) \ - MEMBER(test_structure, a_int, AST_DATA_INTEGER) \ - MEMBER(test_structure, b_bool, AST_DATA_BOOLEAN) \ - MEMBER(test_structure, c_str, AST_DATA_STRING) \ - MEMBER(test_structure, a_uint, AST_DATA_UNSIGNED_INTEGER) - -AST_DATA_STRUCTURE(test_structure, DATA_EXPORT_TEST_STRUCTURE); - -/*! - * \internal - * \brief Callback implementation. - */ -static int test_data_full_provider(const struct ast_data_search *search, - struct ast_data *root) -{ - struct ast_data *test_structure; - struct test_structure local_test_structure = { - .a_int = 10, - .b_bool = 1, - .c_str = "test string", - .a_uint = 20 - }; - - test_structure = ast_data_add_node(root, "test_structure"); - if (!test_structure) { - ast_debug(1, "Internal data api error\n"); - return 0; - } - - /* add the complete structure. */ - ast_data_add_structure(test_structure, test_structure, &local_test_structure); - - if (!ast_data_search_match(search, test_structure)) { - ast_data_remove_node(root, test_structure); - } - - return 0; -} - -/*! - * \internal - * \brief Handler definition for the full provider. - */ -static const struct ast_data_handler full_provider = { - .version = AST_DATA_HANDLER_VERSION, - .get = test_data_full_provider -}; - -/*! - * \internal - * \brief Structure used to define multiple providers at once. - */ -static const struct ast_data_entry test_providers[] = { - AST_DATA_ENTRY("test/node1/node11/node111", &full_provider) -}; - -AST_TEST_DEFINE(test_data_get) -{ - struct ast_data *res, *node; - struct ast_data_iterator *i; - struct ast_data_query query = { - .version = AST_DATA_QUERY_VERSION, - .path = "test/node1/node11/node111", - .search = "node111/test_structure/a_int=10", - .filter = "node111/test_structure/a*int" - }; - - switch (cmd) { - case TEST_INIT: - info->name = "data_test"; - info->category = "/main/data/"; - info->summary = "Data API unit test"; - info->description = - "Tests whether data API get implementation works as expected."; - return AST_TEST_NOT_RUN; - case TEST_EXECUTE: - break; - } - - ast_data_register_multiple_core(test_providers, ARRAY_LEN(test_providers)); - - res = ast_data_get(&query); - if (!res) { - ast_test_status_update(test, "Unable to get tree."); - ast_data_unregister("test/node1/node11/node111"); - return AST_TEST_FAIL; - } - - /* initiate the iterator and check for errors. */ - i = ast_data_iterator_init(res, "test_structure/"); - if (!i) { - ast_test_status_update(test, "Unable to initiate the iterator."); - ast_data_free(res); - ast_data_unregister("test/node1/node11/node111"); - return AST_TEST_FAIL; - } - - /* walk the returned nodes. */ - while ((node = ast_data_iterator_next(i))) { - if (!strcmp(ast_data_retrieve_name(node), "a_int")) { - if (ast_data_retrieve_int(node, "/") != 10) { - ast_data_iterator_end(i); - ast_data_free(res); - ast_data_unregister("test/node1/node11/node111"); - return AST_TEST_FAIL; - } - } else if (!strcmp(ast_data_retrieve_name(node), "a_uint")) { - if (ast_data_retrieve_uint(node, "/") != 20) { - ast_data_iterator_end(i); - ast_data_free(res); - ast_data_unregister("test/node1/node11/node111"); - return AST_TEST_FAIL; - } - } - } - - /* finish the iterator. */ - ast_data_iterator_end(i); - - ast_data_free(res); - - ast_data_unregister("test/node1/node11/node111"); - - return AST_TEST_PASS; -} - -#endif - -/*! - * \internal - * \brief Clean up resources on Asterisk shutdown - */ -static void data_shutdown(void) -{ - ast_manager_unregister("DataGet"); - ast_cli_unregister_multiple(cli_data, ARRAY_LEN(cli_data)); - ao2_t_ref(root_data.container, -1, "Unref root_data.container in data_shutdown"); - root_data.container = NULL; - ast_rwlock_destroy(&root_data.lock); - AST_TEST_UNREGISTER(test_data_get); -} - -int ast_data_init(void) -{ - int res = 0; - - ast_rwlock_init(&root_data.lock); - - if (!(root_data.container = ao2_container_alloc(NUM_DATA_NODE_BUCKETS, - data_provider_hash, data_provider_cmp))) { - return -1; - } - - res |= ast_cli_register_multiple(cli_data, ARRAY_LEN(cli_data)); - - res |= ast_manager_register_xml_core("DataGet", 0, manager_data_get); - - AST_TEST_REGISTER(test_data_get); - - ast_register_cleanup(data_shutdown); - - return res; -} diff --git a/main/http.c b/main/http.c index ea85a2823..7191eb524 100644 --- a/main/http.c +++ b/main/http.c @@ -508,7 +508,7 @@ void ast_http_send(struct ast_tcptls_session_instance *ser, send_content = method != AST_HTTP_HEAD || status_code >= 400; /* send http header */ - ast_iostream_printf(ser->stream, + if (ast_iostream_printf(ser->stream, "HTTP/1.1 %d %s\r\n" "%s" "Date: %s\r\n" @@ -526,13 +526,16 @@ void ast_http_send(struct ast_tcptls_session_instance *ser, http_header ? ast_str_buffer(http_header) : "", content_length, send_content && out && ast_str_strlen(out) ? ast_str_buffer(out) : "" - ); + ) <= 0) { + ast_debug(1, "ast_iostream_printf() failed: %s\n", strerror(errno)); + close_connection = 1; + } /* send content */ - if (send_content && fd) { + if (!close_connection && send_content && fd) { while ((len = read(fd, buf, sizeof(buf))) > 0) { if (ast_iostream_write(ser->stream, buf, len) != len) { - ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); + ast_debug(1, "ast_iostream_write() failed: %s\n", strerror(errno)); close_connection = 1; break; } diff --git a/main/indications.c b/main/indications.c index 0af6668cf..8940a37b0 100644 --- a/main/indications.c +++ b/main/indications.c @@ -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 diff --git a/main/json.c b/main/json.c index a28dbb2e2..9004978b4 100644 --- a/main/json.c +++ b/main/json.c @@ -823,6 +823,7 @@ struct ast_json *ast_json_vpack(char const *format, va_list ap) ast_log(LOG_ERROR, "Error building JSON from '%s': %s.\n", format, error.text); + ast_log_backtrace(); } } return r; diff --git a/main/pbx.c b/main/pbx.c index ccfba054e..2366b72b0 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -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); diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index be50e9cee..e4bb7a2d9 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -159,6 +159,11 @@ struct moh_files_state { static struct ast_flags global_flags[1] = {{0}}; /*!< global MOH_ flags */ +enum kill_methods { + KILL_METHOD_PROCESS_GROUP = 0, + KILL_METHOD_PROCESS +}; + struct mohclass { char name[MAX_MUSICCLASS]; char dir[256]; @@ -179,6 +184,10 @@ struct mohclass { int pid; time_t start; pthread_t thread; + /*! Millisecond delay between kill attempts */ + size_t kill_delay; + /*! Kill method */ + enum kill_methods kill_method; /*! Source of audio */ int srcfd; /*! Generic timer */ @@ -680,6 +689,51 @@ static int spawn_mp3(struct mohclass *class) return fds[0]; } +static int killer(pid_t pid, int signum, enum kill_methods kill_method) +{ + switch (kill_method) { + case KILL_METHOD_PROCESS_GROUP: + return killpg(pid, signum); + case KILL_METHOD_PROCESS: + return kill(pid, signum); + } + + return -1; +} + +static void killpid(int pid, size_t delay, enum kill_methods kill_method) +{ + if (killer(pid, SIGHUP, kill_method) < 0) { + if (errno == ESRCH) { + return; + } + ast_log(LOG_WARNING, "Unable to send a SIGHUP to MOH process '%d'?!!: %s\n", pid, strerror(errno)); + } else { + ast_debug(1, "Sent HUP to pid %d%s\n", pid, + kill_method == KILL_METHOD_PROCESS_GROUP ? " and all children" : " only"); + } + usleep(delay); + if (killer(pid, SIGTERM, kill_method) < 0) { + if (errno == ESRCH) { + return; + } + ast_log(LOG_WARNING, "Unable to terminate MOH process '%d'?!!: %s\n", pid, strerror(errno)); + } else { + ast_debug(1, "Sent TERM to pid %d%s\n", pid, + kill_method == KILL_METHOD_PROCESS_GROUP ? " and all children" : " only"); + } + usleep(delay); + if (killer(pid, SIGKILL, kill_method) < 0) { + if (errno == ESRCH) { + return; + } + ast_log(LOG_WARNING, "Unable to kill MOH process '%d'?!!: %s\n", pid, strerror(errno)); + } else { + ast_debug(1, "Sent KILL to pid %d%s\n", pid, + kill_method == KILL_METHOD_PROCESS_GROUP ? " and all children" : " only"); + } +} + static void *monmp3thread(void *data) { #define MOH_MS_INTERVAL 100 @@ -755,28 +809,7 @@ static void *monmp3thread(void *data) class->srcfd = -1; pthread_testcancel(); if (class->pid > 1) { - do { - if (killpg(class->pid, SIGHUP) < 0) { - if (errno == ESRCH) { - break; - } - ast_log(LOG_WARNING, "Unable to send a SIGHUP to MOH process?!!: %s\n", strerror(errno)); - } - usleep(100000); - if (killpg(class->pid, SIGTERM) < 0) { - if (errno == ESRCH) { - break; - } - ast_log(LOG_WARNING, "Unable to terminate MOH process?!!: %s\n", strerror(errno)); - } - usleep(100000); - if (killpg(class->pid, SIGKILL) < 0) { - if (errno == ESRCH) { - break; - } - ast_log(LOG_WARNING, "Unable to kill MOH process?!!: %s\n", strerror(errno)); - } - } while (0); + killpid(class->pid, class->kill_delay, class->kill_method); class->pid = 0; } } else { @@ -1357,6 +1390,7 @@ static struct mohclass *_moh_class_malloc(const char *file, int line, const char if (class) { class->format = ao2_bump(ast_format_slin); class->srcfd = -1; + class->kill_delay = 100000; } return class; @@ -1610,44 +1644,22 @@ static void moh_class_destructor(void *obj) if (class->pid > 1) { char buff[8192]; - int bytes, tbytes = 0, stime = 0, pid = 0; + int bytes, tbytes = 0, stime = 0; ast_debug(1, "killing %d!\n", class->pid); stime = time(NULL) + 2; - pid = class->pid; - class->pid = 0; - - /* Back when this was just mpg123, SIGKILL was fine. Now we need - * to give the process a reason and time enough to kill off its - * children. */ - do { - if (killpg(pid, SIGHUP) < 0) { - ast_log(LOG_WARNING, "Unable to send a SIGHUP to MOH process?!!: %s\n", strerror(errno)); - } - usleep(100000); - if (killpg(pid, SIGTERM) < 0) { - if (errno == ESRCH) { - break; - } - ast_log(LOG_WARNING, "Unable to terminate MOH process?!!: %s\n", strerror(errno)); - } - usleep(100000); - if (killpg(pid, SIGKILL) < 0) { - if (errno == ESRCH) { - break; - } - ast_log(LOG_WARNING, "Unable to kill MOH process?!!: %s\n", strerror(errno)); - } - } while (0); + killpid(class->pid, class->kill_delay, class->kill_method); while ((ast_wait_for_input(class->srcfd, 100) > 0) && (bytes = read(class->srcfd, buff, 8192)) && time(NULL) < stime) { tbytes = tbytes + bytes; } - ast_debug(1, "mpg123 pid %d and child died after %d bytes read\n", pid, tbytes); + ast_debug(1, "mpg123 pid %d and child died after %d bytes read\n", + class->pid, tbytes); + class->pid = 0; close(class->srcfd); class->srcfd = -1; } @@ -1752,6 +1764,49 @@ static int load_moh_classes(int reload) /* For compatibility with the past, we overwrite any name=name * with the context [name]. */ ast_copy_string(class->name, cat, sizeof(class->name)); + for (var = ast_variable_browse(cfg, cat); var; var = var->next) { + if (!strcasecmp(var->name, "mode")) { + ast_copy_string(class->mode, var->value, sizeof(class->mode)); + } else if (!strcasecmp(var->name, "directory")) { + ast_copy_string(class->dir, var->value, sizeof(class->dir)); + } else if (!strcasecmp(var->name, "application")) { + ast_copy_string(class->args, var->value, sizeof(class->args)); + } else if (!strcasecmp(var->name, "announcement")) { + ast_copy_string(class->announcement, var->value, sizeof(class->announcement)); + ast_set_flag(class, MOH_ANNOUNCEMENT); + } else if (!strcasecmp(var->name, "digit") && (isdigit(*var->value) || strchr("*#", *var->value))) { + class->digit = *var->value; + } else if (!strcasecmp(var->name, "random")) { + ast_set2_flag(class, ast_true(var->value), MOH_RANDOMIZE); + } else if (!strcasecmp(var->name, "sort") && !strcasecmp(var->value, "random")) { + ast_set_flag(class, MOH_RANDOMIZE); + } else if (!strcasecmp(var->name, "sort") && !strcasecmp(var->value, "alpha")) { + ast_set_flag(class, MOH_SORTALPHA); + } else if (!strcasecmp(var->name, "format")) { + ao2_cleanup(class->format); + class->format = ast_format_cache_get(var->value); + if (!class->format) { + ast_log(LOG_WARNING, "Unknown format '%s' -- defaulting to SLIN\n", var->value); + class->format = ao2_bump(ast_format_slin); + } + } else if (!strcasecmp(var->name, "kill_escalation_delay")) { + if (sscanf(var->value, "%zu", &class->kill_delay) == 1) { + class->kill_delay *= 1000; + } else { + ast_log(LOG_WARNING, "kill_escalation_delay '%s' is invalid. Setting to 100ms\n", var->value); + class->kill_delay = 100000; + } + } else if (!strcasecmp(var->name, "kill_method")) { + if (!strcasecmp(var->value, "process")) { + class->kill_method = KILL_METHOD_PROCESS; + } else if (!strcasecmp(var->value, "process_group")){ + class->kill_method = KILL_METHOD_PROCESS_GROUP; + } else { + ast_log(LOG_WARNING, "kill_method '%s' is invalid. Setting to 'process_group'\n", var->value); + class->kill_method = KILL_METHOD_PROCESS_GROUP; + } + } + } if (ast_strlen_zero(class->dir)) { if (!strcasecmp(class->mode, "custom")) { @@ -1884,6 +1939,9 @@ static char *handle_cli_moh_show_classes(struct ast_cli_entry *e, int cmd, struc ast_cli(a->fd, "\tDirectory: %s\n", S_OR(class->dir, "<none>")); if (ast_test_flag(class, MOH_CUSTOM)) { ast_cli(a->fd, "\tApplication: %s\n", S_OR(class->args, "<none>")); + ast_cli(a->fd, "\tKill Escalation Delay: %zu ms\n", class->kill_delay / 1000); + ast_cli(a->fd, "\tKill Method: %s\n", + class->kill_method == KILL_METHOD_PROCESS ? "process" : "process_group"); } if (strcasecmp(class->mode, "files")) { ast_cli(a->fd, "\tFormat: %s\n", ast_format_get_name(class->format)); diff --git a/res/res_odbc.c b/res/res_odbc.c index 0b81bc639..24f63a92e 100644 --- a/res/res_odbc.c +++ b/res/res_odbc.c @@ -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; } diff --git a/res/res_pjsip.c b/res/res_pjsip.c index e717fdb40..6e389d5f3 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -193,11 +193,18 @@ <description> <para>Method used when updating connected line information.</para> <enumlist> - <enum name="invite" /> + <enum name="invite"> + <para>When set to <literal>invite</literal>, check the remote's Allow header and + if UPDATE is allowed, send UPDATE instead of INVITE to avoid SDP + renegotiation. If UPDATE is not Allowed, send INVITE.</para> + </enum> <enum name="reinvite"> <para>Alias for the <literal>invite</literal> value.</para> </enum> - <enum name="update" /> + <enum name="update"> + <para>If set to <literal>update</literal>, send UPDATE regardless of what the remote + Allows. </para> + </enum> </enumlist> </description> </configOption> @@ -229,6 +236,9 @@ <enum name="auto"> <para>DTMF is sent as RFC 4733 if the other side supports it or as INBAND if not.</para> </enum> + <enum name="auto_info"> + <para>DTMF is sent as RFC 4733 if the other side supports it or as SIP INFO if not.</para> + </enum> </enumlist> </description> </configOption> @@ -3081,6 +3091,14 @@ pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, /* Update the dialog with the new local URI, we do it afterwards so we can use the dialog pool for construction */ pj_strdup_with_null(dlg->pool, &dlg->local.info_str, &local_uri); dlg->local.info->uri = pjsip_parse_uri(dlg->pool, dlg->local.info_str.ptr, dlg->local.info_str.slen, 0); + if (!dlg->local.info->uri) { + ast_log(LOG_ERROR, + "Could not parse URI '%s' for endpoint '%s'\n", + dlg->local.info_str.ptr, ast_sorcery_object_get_id(endpoint)); + dlg->sess_count--; + pjsip_dlg_terminate(dlg); + return NULL; + } dlg->local.contact = pjsip_parse_hdr(dlg->pool, &HCONTACT, local_uri.ptr, local_uri.slen, NULL); diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c index 56a8419a8..ef3e05b06 100644 --- a/res/res_pjsip/pjsip_configuration.c +++ b/res/res_pjsip/pjsip_configuration.c @@ -371,6 +371,8 @@ static int dtmf_handler(const struct aco_option *opt, struct ast_variable *var, endpoint->dtmf = AST_SIP_DTMF_RFC_4733; } else if (!strcasecmp(var->value, "inband")) { endpoint->dtmf = AST_SIP_DTMF_INBAND; + } else if (!strcasecmp(var->value, "auto_info")) { + endpoint->dtmf = AST_SIP_DTMF_AUTO_INFO; } else if (!strcasecmp(var->value, "info")) { endpoint->dtmf = AST_SIP_DTMF_INFO; } else if (!strcasecmp(var->value, "auto")) { @@ -395,8 +397,11 @@ static int dtmf_to_str(const void *obj, const intptr_t *args, char **buf) *buf = "inband"; break; case AST_SIP_DTMF_INFO : *buf = "info"; break; - case AST_SIP_DTMF_AUTO : + case AST_SIP_DTMF_AUTO : *buf = "auto"; break; + case AST_SIP_DTMF_AUTO_INFO : + *buf = "auto_info"; + break; default: *buf = "none"; } @@ -1143,6 +1148,37 @@ static int tos_video_to_str(const void *obj, const intptr_t *args, char **buf) return 0; } +static int from_user_handler(const struct aco_option *opt, + struct ast_variable *var, void *obj) +{ + struct ast_sip_endpoint *endpoint = obj; + /* Valid non-alphanumeric characters for URI */ + char *valid_uri_marks = "-_.!~*`()"; + const char *val; + + for (val = var->value; *val; val++) { + if (!strchr(valid_uri_marks, *val) && !isdigit(*val) && !isalpha(*val)) { + ast_log(LOG_ERROR, "Error configuring endpoint '%s' - '%s' field " + "contains invalid character '%c'\n", + ast_sorcery_object_get_id(endpoint), var->name, *val); + return -1; + } + } + + ast_string_field_set(endpoint, fromuser, var->value); + + return 0; +} + +static int from_user_to_str(const void *obj, const intptr_t *args, char **buf) +{ + const struct ast_sip_endpoint *endpoint = obj; + + *buf = ast_strdup(endpoint->fromuser); + + return 0; +} + static int set_var_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) { @@ -1913,7 +1949,7 @@ int ast_res_pjsip_initialize_configuration(void) ast_sorcery_object_field_register(sip_sorcery, "endpoint", "cos_video", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_endpoint, media.cos_video)); ast_sorcery_object_field_register(sip_sorcery, "endpoint", "allow_subscribe", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, subscription.allow)); ast_sorcery_object_field_register(sip_sorcery, "endpoint", "sub_min_expiry", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_endpoint, subscription.minexpiry)); - ast_sorcery_object_field_register(sip_sorcery, "endpoint", "from_user", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, fromuser)); + ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "from_user", "", from_user_handler, from_user_to_str, NULL, 0, 0); ast_sorcery_object_field_register(sip_sorcery, "endpoint", "from_domain", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, fromdomain)); ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mwi_from_user", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, subscription.mwi.fromuser)); ast_sorcery_object_field_register(sip_sorcery, "endpoint", "rtp_engine", "asterisk", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, media.rtp.engine)); diff --git a/res/res_pjsip/pjsip_distributor.c b/res/res_pjsip/pjsip_distributor.c index cca26a83c..cf1b04a8b 100644 --- a/res/res_pjsip/pjsip_distributor.c +++ b/res/res_pjsip/pjsip_distributor.c @@ -150,62 +150,189 @@ static struct ast_taskprocessor *find_request_serializer(pjsip_rx_data *rdata) /*! Dialog-specific information the distributor uses */ struct distributor_dialog_data { + /*! dialog_associations ao2 container key */ + pjsip_dialog *dlg; /*! Serializer to distribute tasks to for this dialog */ struct ast_taskprocessor *serializer; /*! Endpoint associated with this dialog */ struct ast_sip_endpoint *endpoint; }; +#define DIALOG_ASSOCIATIONS_BUCKETS 251 + +static struct ao2_container *dialog_associations; + /*! * \internal + * \brief Compute a hash value on an arbitrary buffer. + * \since 13.17.0 * - * \note Call this with the dialog locked + * \param[in] pos The buffer to add to the hash + * \param[in] len The buffer length to add to the hash + * \param[in] hash The hash value to add to + * + * \details + * This version of the function is for when you need to compute a + * hash of more than one buffer. + * + * This famous hash algorithm was written by Dan Bernstein and is + * commonly used. + * + * \sa http://www.cse.yorku.ca/~oz/hash.html */ -static struct distributor_dialog_data *distributor_dialog_data_alloc(pjsip_dialog *dlg) +static int buf_hash_add(const char *pos, size_t len, int hash) { - struct distributor_dialog_data *dist; + while (len--) { + hash = hash * 33 ^ *pos++; + } + + return hash; +} + +/*! + * \internal + * \brief Compute a hash value on an arbitrary buffer. + * \since 13.17.0 + * + * \param[in] pos The buffer to add to the hash + * \param[in] len The buffer length to add to the hash + * + * \details + * This version of the function is for when you need to compute a + * hash of more than one buffer. + * + * This famous hash algorithm was written by Dan Bernstein and is + * commonly used. + * + * \sa http://www.cse.yorku.ca/~oz/hash.html + */ +static int buf_hash(const char *pos, size_t len) +{ + return buf_hash_add(pos, len, 5381); +} - dist = PJ_POOL_ZALLOC_T(dlg->pool, struct distributor_dialog_data); - pjsip_dlg_set_mod_data(dlg, distributor_mod.id, dist); +static int dialog_associations_hash(const void *obj, int flags) +{ + const struct distributor_dialog_data *object; + union { + const pjsip_dialog *dlg; + const char buf[sizeof(pjsip_dialog *)]; + } key; - return dist; + switch (flags & OBJ_SEARCH_MASK) { + case OBJ_SEARCH_KEY: + key.dlg = obj; + break; + case OBJ_SEARCH_OBJECT: + object = obj; + key.dlg = object->dlg; + break; + default: + /* Hash can only work on something with a full key. */ + ast_assert(0); + return 0; + } + return ast_str_hash_restrict(buf_hash(key.buf, sizeof(key.buf))); +} + +static int dialog_associations_cmp(void *obj, void *arg, int flags) +{ + const struct distributor_dialog_data *object_left = obj; + const struct distributor_dialog_data *object_right = arg; + const pjsip_dialog *right_key = arg; + int cmp = 0; + + switch (flags & OBJ_SEARCH_MASK) { + case OBJ_SEARCH_OBJECT: + right_key = object_right->dlg; + /* Fall through */ + case OBJ_SEARCH_KEY: + if (object_left->dlg == right_key) { + cmp = CMP_MATCH; + } + break; + case OBJ_SEARCH_PARTIAL_KEY: + /* There is no such thing for this container. */ + ast_assert(0); + break; + default: + cmp = 0; + break; + } + return cmp; } void ast_sip_dialog_set_serializer(pjsip_dialog *dlg, struct ast_taskprocessor *serializer) { struct distributor_dialog_data *dist; - SCOPED_LOCK(lock, dlg, pjsip_dlg_inc_lock, pjsip_dlg_dec_lock); - dist = pjsip_dlg_get_mod_data(dlg, distributor_mod.id); + ao2_wrlock(dialog_associations); + dist = ao2_find(dialog_associations, dlg, OBJ_SEARCH_KEY | OBJ_NOLOCK); if (!dist) { - dist = distributor_dialog_data_alloc(dlg); + if (serializer) { + dist = ao2_alloc(sizeof(*dist), NULL); + if (dist) { + dist->dlg = dlg; + dist->serializer = serializer; + ao2_link_flags(dialog_associations, dist, OBJ_NOLOCK); + ao2_ref(dist, -1); + } + } + } else { + ao2_lock(dist); + dist->serializer = serializer; + if (!dist->serializer && !dist->endpoint) { + ao2_unlink_flags(dialog_associations, dist, OBJ_NOLOCK); + } + ao2_unlock(dist); + ao2_ref(dist, -1); } - dist->serializer = serializer; + ao2_unlock(dialog_associations); } void ast_sip_dialog_set_endpoint(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint) { struct distributor_dialog_data *dist; - SCOPED_LOCK(lock, dlg, pjsip_dlg_inc_lock, pjsip_dlg_dec_lock); - dist = pjsip_dlg_get_mod_data(dlg, distributor_mod.id); + ao2_wrlock(dialog_associations); + dist = ao2_find(dialog_associations, dlg, OBJ_SEARCH_KEY | OBJ_NOLOCK); if (!dist) { - dist = distributor_dialog_data_alloc(dlg); + if (endpoint) { + dist = ao2_alloc(sizeof(*dist), NULL); + if (dist) { + dist->dlg = dlg; + dist->endpoint = endpoint; + ao2_link_flags(dialog_associations, dist, OBJ_NOLOCK); + ao2_ref(dist, -1); + } + } + } else { + ao2_lock(dist); + dist->endpoint = endpoint; + if (!dist->serializer && !dist->endpoint) { + ao2_unlink_flags(dialog_associations, dist, OBJ_NOLOCK); + } + ao2_unlock(dist); + ao2_ref(dist, -1); } - dist->endpoint = endpoint; + ao2_unlock(dialog_associations); } struct ast_sip_endpoint *ast_sip_dialog_get_endpoint(pjsip_dialog *dlg) { struct distributor_dialog_data *dist; - SCOPED_LOCK(lock, dlg, pjsip_dlg_inc_lock, pjsip_dlg_dec_lock); + struct ast_sip_endpoint *endpoint; - dist = pjsip_dlg_get_mod_data(dlg, distributor_mod.id); - if (!dist || !dist->endpoint) { - return NULL; + dist = ao2_find(dialog_associations, dlg, OBJ_SEARCH_KEY); + if (dist) { + ao2_lock(dist); + endpoint = ao2_bump(dist->endpoint); + ao2_unlock(dist); + ao2_ref(dist, -1); + } else { + endpoint = NULL; } - ao2_ref(dist->endpoint, +1); - return dist->endpoint; + return endpoint; } static pjsip_dialog *find_dialog(pjsip_rx_data *rdata) @@ -237,7 +364,7 @@ static pjsip_dialog *find_dialog(pjsip_rx_data *rdata) pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_cancel_method) || rdata->msg_info.to->tag.slen != 0) { dlg = pjsip_ua_find_dialog(&rdata->msg_info.cid->id, local_tag, - remote_tag, PJ_TRUE); + remote_tag, PJ_FALSE); if (dlg) { return dlg; } @@ -275,11 +402,6 @@ static pjsip_dialog *find_dialog(pjsip_rx_data *rdata) pj_mutex_unlock(tsx->mutex); #endif - if (!dlg) { - return NULL; - } - - pjsip_dlg_inc_lock(dlg); return dlg; } @@ -302,16 +424,7 @@ static pjsip_dialog *find_dialog(pjsip_rx_data *rdata) */ static int pjstr_hash_add(pj_str_t *str, int hash) { - size_t len; - const char *pos; - - len = pj_strlen(str); - pos = pj_strbuf(str); - while (len--) { - hash = hash * 33 ^ *pos++; - } - - return hash; + return buf_hash_add(pj_strbuf(str), pj_strlen(str), hash); } /*! @@ -350,7 +463,7 @@ struct ast_taskprocessor *ast_sip_get_distributor_serializer(pjsip_rx_data *rdat /* Compute the hash from the SIP message call-id and remote-tag */ hash = pjstr_hash(&rdata->msg_info.cid->id); hash = pjstr_hash_add(remote_tag, hash); - hash = abs(hash); + hash = ast_str_hash_restrict(hash); serializer = ao2_bump(distributor_pool[hash % ARRAY_LEN(distributor_pool)]); if (serializer) { @@ -385,17 +498,18 @@ static pj_bool_t distributor(pjsip_rx_data *rdata) dlg = find_dialog(rdata); if (dlg) { - ast_debug(3, "Searching for serializer on dialog %s for %s\n", + ast_debug(3, "Searching for serializer associated with dialog %s for %s\n", dlg->obj_name, pjsip_rx_data_get_info(rdata)); - dist = pjsip_dlg_get_mod_data(dlg, distributor_mod.id); + dist = ao2_find(dialog_associations, dlg, OBJ_SEARCH_KEY); if (dist) { + ao2_lock(dist); serializer = ao2_bump(dist->serializer); + ao2_unlock(dist); if (serializer) { - ast_debug(3, "Found serializer %s on dialog %s\n", + ast_debug(3, "Found serializer %s associated with dialog %s\n", ast_taskprocessor_name(serializer), dlg->obj_name); } } - pjsip_dlg_dec_lock(dlg); } if (serializer) { @@ -417,6 +531,7 @@ static pj_bool_t distributor(pjsip_rx_data *rdata) /* We have a BYE or CANCEL request without a serializer. */ pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, PJSIP_SC_CALL_TSX_DOES_NOT_EXIST, NULL, NULL, NULL); + ao2_cleanup(dist); return PJ_TRUE; } else { if (ast_taskprocessor_alert_get()) { @@ -431,6 +546,7 @@ static pj_bool_t distributor(pjsip_rx_data *rdata) */ ast_debug(3, "Taskprocessor overload alert: Ignoring '%s'.\n", pjsip_rx_data_get_info(rdata)); + ao2_cleanup(dist); return PJ_TRUE; } @@ -438,10 +554,17 @@ static pj_bool_t distributor(pjsip_rx_data *rdata) serializer = ast_sip_get_distributor_serializer(rdata); } - pjsip_rx_data_clone(rdata, 0, &clone); + if (pjsip_rx_data_clone(rdata, 0, &clone) != PJ_SUCCESS) { + ast_taskprocessor_unreference(serializer); + ao2_cleanup(dist); + return PJ_TRUE; + } if (dist) { + ao2_lock(dist); clone->endpt_info.mod_data[endpoint_mod.id] = ao2_bump(dist->endpoint); + ao2_unlock(dist); + ao2_cleanup(dist); } if (ast_sip_push_task(serializer, distribute, clone)) { @@ -837,7 +960,7 @@ static int suspects_compare(void *obj, void *arg, int flags) /* Fall through */ case OBJ_SEARCH_KEY: if (strcmp(object_left->src_name, right_key) == 0) { - cmp = CMP_MATCH | CMP_STOP; + cmp = CMP_MATCH; } break; case OBJ_SEARCH_PARTIAL_KEY: @@ -852,15 +975,25 @@ static int suspects_compare(void *obj, void *arg, int flags) return cmp; } -static int suspects_hash(const void *obj, int flags) { - const struct unidentified_request *object_left = obj; +static int suspects_hash(const void *obj, int flags) +{ + const struct unidentified_request *object; + const char *key; - if (flags & OBJ_SEARCH_OBJECT) { - return ast_str_hash(object_left->src_name); - } else if (flags & OBJ_SEARCH_KEY) { - return ast_str_hash(obj); + switch (flags & OBJ_SEARCH_MASK) { + case OBJ_SEARCH_KEY: + key = obj; + break; + case OBJ_SEARCH_OBJECT: + object = obj; + key = object->src_name; + break; + default: + /* Hash can only work on something with a full key. */ + ast_assert(0); + return 0; } - return -1; + return ast_str_hash(key); } static struct ao2_container *cli_unid_get_container(const char *regex) @@ -1078,6 +1211,14 @@ int ast_sip_initialize_distributor(void) return -1; } + dialog_associations = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, + DIALOG_ASSOCIATIONS_BUCKETS, dialog_associations_hash, NULL, + dialog_associations_cmp); + if (!dialog_associations) { + ast_sip_destroy_distributor(); + return -1; + } + if (distributor_pool_setup()) { ast_sip_destroy_distributor(); return -1; @@ -1156,5 +1297,6 @@ void ast_sip_destroy_distributor(void) distributor_pool_shutdown(); + ao2_cleanup(dialog_associations); ao2_cleanup(unidentified_requests); } diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c index 03fef40cf..a49130868 100644 --- a/res/res_pjsip_sdp_rtp.c +++ b/res/res_pjsip_sdp_rtp.c @@ -207,7 +207,7 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me ice->stop(session_media->rtp); } - if (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO) { + if (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO || session->endpoint->dtmf == AST_SIP_DTMF_AUTO_INFO) { ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_RFC2833); ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_DTMF, 1); } else if (session->endpoint->dtmf == AST_SIP_DTMF_INBAND) { @@ -230,7 +230,7 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me } static void get_codecs(struct ast_sip_session *session, const struct pjmedia_sdp_media *stream, struct ast_rtp_codecs *codecs, - struct ast_sip_session_media *session_media) + struct ast_sip_session_media *session_media) { pjmedia_sdp_attr *attr; pjmedia_sdp_rtpmap *rtpmap; @@ -296,6 +296,16 @@ static void get_codecs(struct ast_sip_session *session, const struct pjmedia_sdp if (!tel_event && (session->endpoint->dtmf == AST_SIP_DTMF_AUTO)) { ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_INBAND); } + + if (session->endpoint->dtmf == AST_SIP_DTMF_AUTO_INFO) { + if (tel_event) { + ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_RFC2833); + } else { + ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_NONE); + } + } + + /* Get the packetization, if it exists */ if ((attr = pjmedia_sdp_media_find_attr2(stream, "ptime", NULL))) { unsigned long framing = pj_strtoul(pj_strltrim(&attr->value)); @@ -404,7 +414,8 @@ static int set_caps(struct ast_sip_session *session, ast_set_read_format(session->channel, ast_channel_readformat(session->channel)); ast_set_write_format(session->channel, ast_channel_writeformat(session->channel)); } - if ((session->endpoint->dtmf == AST_SIP_DTMF_AUTO) + + if ( ((session->endpoint->dtmf == AST_SIP_DTMF_AUTO) || (session->endpoint->dtmf == AST_SIP_DTMF_AUTO_INFO) ) && (ast_rtp_instance_dtmf_mode_get(session_media->rtp) == AST_RTP_DTMF_MODE_RFC2833) && (session->dsp)) { dsp_features = ast_dsp_get_features(session->dsp); @@ -1136,7 +1147,7 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as pj_str_t stmp; pjmedia_sdp_attr *attr; int index = 0; - int noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO) ? AST_RTP_DTMF : 0; + int noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO || session->endpoint->dtmf == AST_SIP_DTMF_AUTO_INFO) ? AST_RTP_DTMF : 0; int min_packet_size = 0, max_packet_size = 0; int rtp_code; RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup); diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c index dc09166a7..30efb2ca6 100644 --- a/res/res_rtp_asterisk.c +++ b/res/res_rtp_asterisk.c @@ -319,6 +319,7 @@ struct ast_rtp { ast_cond_t cond; /*!< ICE/TURN condition for signaling */ struct ice_wrap *ice; /*!< ao2 wrapped ICE session */ + enum ast_rtp_ice_role role; /*!< Our role in ICE negotiation */ pj_turn_sock *turn_rtp; /*!< RTP TURN relay */ pj_turn_sock *turn_rtcp; /*!< RTCP TURN relay */ pj_turn_state_t turn_state; /*!< Current state of the TURN relay session */ @@ -685,7 +686,6 @@ static void ice_wrap_dtor(void *vdoomed) static int ice_reset_session(struct ast_rtp_instance *instance) { struct ast_rtp *rtp = ast_rtp_instance_get_data(instance); - pj_ice_sess_role role = rtp->ice->real_ice->role; int res; ast_debug(3, "Resetting ICE for RTP instance '%p'\n", instance); @@ -697,8 +697,9 @@ static int ice_reset_session(struct ast_rtp_instance *instance) ast_debug(3, "Recreating ICE session %s (%d) for RTP instance '%p'\n", ast_sockaddr_stringify(&rtp->ice_original_rtp_addr), rtp->ice_port, instance); res = ice_create(instance, &rtp->ice_original_rtp_addr, rtp->ice_port, 1); if (!res) { - /* Preserve the role that the old ICE session used */ - pj_ice_sess_change_role(rtp->ice->real_ice, role); + /* Use the current expected role for the ICE session */ + pj_ice_sess_change_role(rtp->ice->real_ice, rtp->role == AST_RTP_ICE_ROLE_CONTROLLED ? + PJ_ICE_SESS_ROLE_CONTROLLED : PJ_ICE_SESS_ROLE_CONTROLLING); } /* If we only have one component now, and we previously set up TURN for RTCP, @@ -769,6 +770,8 @@ static void ast_rtp_ice_start(struct ast_rtp_instance *instance) ast_debug(3, "Proposed == active candidates for RTP instance '%p'\n", instance); ao2_cleanup(rtp->ice_proposed_remote_candidates); rtp->ice_proposed_remote_candidates = NULL; + /* If this ICE session is being preserved then go back to the role it currently is */ + rtp->role = rtp->ice->real_ice->role; return; } @@ -942,10 +945,7 @@ static void ast_rtp_ice_set_role(struct ast_rtp_instance *instance, enum ast_rtp return; } - pj_thread_register_check(); - - pj_ice_sess_change_role(rtp->ice->real_ice, role == AST_RTP_ICE_ROLE_CONTROLLED ? - PJ_ICE_SESS_ROLE_CONTROLLED : PJ_ICE_SESS_ROLE_CONTROLLING); + rtp->role = role; } /*! \pre instance is locked */ @@ -1295,6 +1295,8 @@ static void ast_rtp_ice_turn_request(struct ast_rtp_instance *instance, enum ast pj_turn_session_info info; struct ast_sockaddr local, loop; pj_status_t status; + pj_turn_sock_cfg turn_sock_cfg; + struct ice_wrap *ice; ast_rtp_instance_get_local_address(instance, &local); if (ast_sockaddr_is_ipv4(&local)) { @@ -1357,11 +1359,20 @@ static void ast_rtp_ice_turn_request(struct ast_rtp_instance *instance, enum ast pj_stun_config_init(&stun_config, &cachingpool.factory, 0, rtp->ioqueue->ioqueue, rtp->ioqueue->timerheap); + /* Use ICE session group lock for TURN session to avoid deadlock */ + pj_turn_sock_cfg_default(&turn_sock_cfg); + ice = rtp->ice; + if (ice) { + turn_sock_cfg.grp_lock = ice->real_ice->grp_lock; + ao2_ref(ice, +1); + } + /* Release the instance lock to avoid deadlock with PJPROJECT group lock */ ao2_unlock(instance); status = pj_turn_sock_create(&stun_config, ast_sockaddr_is_ipv4(&addr) ? pj_AF_INET() : pj_AF_INET6(), conn_type, - turn_cb, NULL, instance, turn_sock); + turn_cb, &turn_sock_cfg, instance, turn_sock); + ao2_cleanup(ice); if (status != PJ_SUCCESS) { ast_log(LOG_WARNING, "Could not create a TURN client socket\n"); ao2_lock(instance); @@ -2532,6 +2543,17 @@ static int __rtp_recvfrom(struct ast_rtp_instance *instance, void *buf, size_t s return -1; } if (!rtp->passthrough) { + /* If a unidirectional ICE negotiation occurs then lock on to the source of the + * ICE traffic and use it as the target. This will occur if the remote side only + * wants to receive media but never send to us. + */ + if (!rtp->ice_active_remote_candidates && !rtp->ice_proposed_remote_candidates) { + if (rtcp) { + ast_sockaddr_copy(&rtp->rtcp->them, sa); + } else { + ast_rtp_instance_set_remote_address(instance, sa); + } + } return 0; } rtp->passthrough = 0; diff --git a/third-party/configure.m4 b/third-party/configure.m4 index 635446638..55b72daf9 100644 --- a/third-party/configure.m4 +++ b/third-party/configure.m4 @@ -1,4 +1,7 @@ - +# +# If this file is changed, be sure to run ASTTOPDIR/bootstrap.sh +# before committing. +# AC_DEFUN([THIRD_PARTY_CONFIGURE], [ diff --git a/third-party/pjproject/Makefile.rules b/third-party/pjproject/Makefile.rules index 3f99c8a8f..acd766218 100644 --- a/third-party/pjproject/Makefile.rules +++ b/third-party/pjproject/Makefile.rules @@ -1,8 +1,11 @@ PJPROJECT_URL ?= https://raw.githubusercontent.com/asterisk/third-party/master/pjproject/$(PJPROJECT_VERSION) +# PJPROJECT_CONFIGURE_OPTS could come from the command line or could be +# set/modified by configure.m4 if the build or host tuples aren't the same +# as the current build environment (cross-compile). # Even though we're not installing pjproject, we're setting prefix to /opt/pjproject to be safe -PJPROJECT_CONFIG_OPTS = --prefix=/opt/pjproject \ +PJPROJECT_CONFIG_OPTS = $(PJPROJECT_CONFIGURE_OPTS) --prefix=/opt/pjproject \ --disable-speex-codec \ --disable-speex-aec \ --disable-speex-aec \ diff --git a/third-party/pjproject/configure.m4 b/third-party/pjproject/configure.m4 index a5e9fca60..709a706a1 100644 --- a/third-party/pjproject/configure.m4 +++ b/third-party/pjproject/configure.m4 @@ -1,3 +1,8 @@ +# +# If this file is changed, be sure to run ASTTOPDIR/bootstrap.sh +# before committing. +# + AC_DEFUN([_PJPROJECT_CONFIGURE], [ if test "${ac_mandatory_list#*PJPROJECT*}" != "$ac_mandatory_list" ; then @@ -35,17 +40,30 @@ AC_DEFUN([_PJPROJECT_CONFIGURE], AC_MSG_ERROR(cat is required to build bundled pjproject) fi + AC_ARG_VAR([PJPROJECT_CONFIGURE_OPTS],[Additional configure options to pass to bundled pjproject]) + this_host=$(./config.sub $(./config.guess)) + if test "$build" != "$this_host" ; then + PJPROJECT_CONFIGURE_OPTS+=" --build=$build" + fi + if test "$host" != "$this_host" ; then + PJPROJECT_CONFIGURE_OPTS+=" --host=$host" + fi + export TAR PATCH SED NM EXTERNALS_CACHE_DIR DOWNLOAD_TO_STDOUT DOWNLOAD_TIMEOUT DOWNLOAD MD5 CAT - ${GNU_MAKE} --quiet --no-print-directory -C ${PJPROJECT_DIR} EXTERNALS_CACHE_DIR=${EXTERNALS_CACHE_DIR} configure + export NOISY_BUILD + ${GNU_MAKE} --quiet --no-print-directory -C ${PJPROJECT_DIR} \ + PJPROJECT_CONFIGURE_OPTS="$PJPROJECT_CONFIGURE_OPTS" \ + EXTERNALS_CACHE_DIR="${EXTERNALS_CACHE_DIR}" \ + configure if test $? -ne 0 ; then AC_MSG_RESULT(failed) AC_MSG_NOTICE(Unable to configure ${PJPROJECT_DIR}) - AC_MSG_ERROR(Run "${GNU_MAKE} -C ${PJPROJECT_DIR} NOISY_BUILD=yes configure" to see error details.) + AC_MSG_ERROR(Re-run the ./configure command with 'NOISY_BUILD=yes' appended to see error details.) fi AC_MSG_CHECKING(for bundled pjproject) - PJPROJECT_INCLUDE=$(${GNU_MAKE} --quiet --no-print-directory -C ${PJPROJECT_DIR} EXTERNALS_CACHE_DIR=${EXTERNALS_CACHE_DIR} echo_cflags) + PJPROJECT_INCLUDE=$(${GNU_MAKE} --quiet --no-print-directory -C ${PJPROJECT_DIR} PJPROJECT_CONFIGURE_OPTS="$PJPROJECT_CONFIGURE_OPTS" EXTERNALS_CACHE_DIR="${EXTERNALS_CACHE_DIR}" echo_cflags) PJPROJECT_CFLAGS="$PJPROJECT_INCLUDE" PBX_PJPROJECT=1 diff --git a/third-party/pjproject/patches/0070-Set-PJSIP_INV_SUPPORT_UPDATE-correctly-in-pjsip_inv_.patch b/third-party/pjproject/patches/0070-Set-PJSIP_INV_SUPPORT_UPDATE-correctly-in-pjsip_inv_.patch new file mode 100644 index 000000000..9238e3ec9 --- /dev/null +++ b/third-party/pjproject/patches/0070-Set-PJSIP_INV_SUPPORT_UPDATE-correctly-in-pjsip_inv_.patch @@ -0,0 +1,29 @@ +From 1193681959816effa121c4470748d5faa3a59272 Mon Sep 17 00:00:00 2001 +From: George Joseph <gjoseph@digium.com> +Date: Thu, 29 Jun 2017 13:42:10 -0600 +Subject: [PATCH] Set PJSIP_INV_SUPPORT_UPDATE correctly in + pjsip_inv_verify_request3 + +pjsip_inv_verify_request3 was setting rem_options when UPDATE was +detected in the Allow header. That's just an internal variable and +doesn't go anywhere. It's '*options' that needs to be set. +--- + pjsip/src/pjsip-ua/sip_inv.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/pjsip/src/pjsip-ua/sip_inv.c b/pjsip/src/pjsip-ua/sip_inv.c +index fbc8ebe..6db7e6b 100644 +--- a/pjsip/src/pjsip-ua/sip_inv.c ++++ b/pjsip/src/pjsip-ua/sip_inv.c +@@ -1237,7 +1237,7 @@ PJ_DEF(pj_status_t) pjsip_inv_verify_request3(pjsip_rx_data *rdata, + + if (i != allow->count) { + /* UPDATE is present in Allow */ +- rem_option |= PJSIP_INV_SUPPORT_UPDATE; ++ *options |= PJSIP_INV_SUPPORT_UPDATE; + } + + } +-- +2.9.4 + |