2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2013, Digium, Inc.
6 * Matt Jordan <mjordan@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
25 #include "asterisk/res_pjsip.h"
26 #include "asterisk/channel.h"
27 #include "asterisk/pbx.h"
28 #include "asterisk/astobj2.h"
29 #include "asterisk/cli.h"
30 #include "asterisk/time.h"
31 #include "include/res_pjsip_private.h"
33 #define DEFAULT_LANGUAGE "en"
34 #define DEFAULT_ENCODING "text/plain"
35 #define QUALIFIED_BUCKETS 211
39 * \brief Create a ast_sip_contact_status object.
41 static void *contact_status_alloc(const char *name)
43 struct ast_sip_contact_status *status = ast_sorcery_generic_alloc(sizeof(*status), NULL);
46 ast_log(LOG_ERROR, "Unable to allocate ast_sip_contact_status\n");
50 status->status = UNAVAILABLE;
57 * \brief Retrieve a ast_sip_contact_status object from sorcery creating
60 static struct ast_sip_contact_status *find_or_create_contact_status(const struct ast_sip_contact *contact)
62 struct ast_sip_contact_status *status = ast_sorcery_retrieve_by_id(
63 ast_sip_get_sorcery(), CONTACT_STATUS,
64 ast_sorcery_object_get_id(contact));
70 if (!(status = ast_sorcery_alloc(
71 ast_sip_get_sorcery(), CONTACT_STATUS,
72 ast_sorcery_object_get_id(contact)))) {
74 ast_log(LOG_ERROR, "Unable to create ast_sip_contact_status for contact %s\n",
79 if (ast_sorcery_create(ast_sip_get_sorcery(), status)) {
80 ast_log(LOG_ERROR, "Unable to persist ast_sip_contact_status for contact %s\n",
90 * \brief Update an ast_sip_contact_status's elements.
92 static void update_contact_status(const struct ast_sip_contact *contact,
93 enum ast_sip_contact_status_type value)
95 RAII_VAR(struct ast_sip_contact_status *, status,
96 find_or_create_contact_status(contact), ao2_cleanup);
98 RAII_VAR(struct ast_sip_contact_status *, update, ast_sorcery_alloc(
99 ast_sip_get_sorcery(), CONTACT_STATUS,
100 ast_sorcery_object_get_id(status)), ao2_cleanup);
103 ast_log(LOG_ERROR, "Unable to create update ast_sip_contact_status for contact %s\n",
108 update->status = value;
110 /* if the contact is available calculate the rtt as
111 the diff between the last start time and "now" */
112 update->rtt = update->status ?
113 ast_tvdiff_us(ast_tvnow(), status->rtt_start) : 0;
115 update->rtt_start = ast_tv(0, 0);
117 if (ast_sorcery_update(ast_sip_get_sorcery(), update)) {
118 ast_log(LOG_ERROR, "Unable to update ast_sip_contact_status for contact %s\n",
125 * \brief Initialize the start time on a contact status so the round
126 * trip time can be calculated upon a valid response.
128 static void init_start_time(const struct ast_sip_contact *contact)
130 RAII_VAR(struct ast_sip_contact_status *, status,
131 find_or_create_contact_status(contact), ao2_cleanup);
133 RAII_VAR(struct ast_sip_contact_status *, update, ast_sorcery_alloc(
134 ast_sip_get_sorcery(), CONTACT_STATUS,
135 ast_sorcery_object_get_id(status)), ao2_cleanup);
138 ast_log(LOG_ERROR, "Unable to create update ast_sip_contact_status for contact %s\n",
143 update->rtt_start = ast_tvnow();
145 if (ast_sorcery_update(ast_sip_get_sorcery(), update)) {
146 ast_log(LOG_ERROR, "Unable to update ast_sip_contact_status for contact %s\n",
153 * \brief Match a container contact object with the contact sorcery id looking for.
155 * \param obj pointer to the (user-defined part) of an object.
156 * \param arg callback argument from ao2_callback()
157 * \param flags flags from ao2_callback()
159 * \return Values are a combination of enum _cb_results.
161 static int match_contact_id(void *obj, void *arg, int flags)
163 struct ast_sip_contact *contact = obj;
164 const char *looking_for = arg;
166 return strcmp(ast_sorcery_object_get_id(contact), looking_for) ? 0 : CMP_MATCH;
171 * \brief For an endpoint try to match the given contact sorcery id.
173 static int on_endpoint(void *obj, void *arg, int flags)
175 struct ast_sip_endpoint *endpoint = obj;
176 struct ast_sip_contact *contact;
177 char *looking_for = arg;
181 if (!arg || ast_strlen_zero(endpoint->aors)) {
185 aors = ast_strdupa(endpoint->aors);
187 while ((aor_name = strsep(&aors, ","))) {
188 RAII_VAR(struct ast_sip_aor *, aor,
189 ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
190 RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
192 if (!aor || !(contacts = ast_sip_location_retrieve_aor_contacts(aor))) {
196 contact = ao2_callback(contacts, 0, match_contact_id, looking_for);
198 ao2_ref(contact, -1);
208 * \brief Find an endpoint associated with the given contact.
210 static struct ast_sip_endpoint *find_an_endpoint(struct ast_sip_contact *contact)
212 RAII_VAR(struct ao2_container *, endpoints, ast_sip_get_endpoints(), ao2_cleanup);
213 char *looking_for = (char *) ast_sorcery_object_get_id(contact);
215 return ao2_callback(endpoints, 0, on_endpoint, looking_for);
220 * \brief Receive an response to the qualify contact request.
222 static void qualify_contact_cb(void *token, pjsip_event *e)
224 struct ast_sip_contact *contact = token;
226 switch(e->body.tsx_state.type) {
227 case PJSIP_EVENT_TRANSPORT_ERROR:
228 case PJSIP_EVENT_TIMER:
229 update_contact_status(contact, UNAVAILABLE);
232 update_contact_status(contact, AVAILABLE);
235 ao2_cleanup(contact);
240 * \brief Attempt to qualify the contact
242 * \details Sends a SIP OPTIONS request to the given contact in order to make
243 * sure that contact is available.
245 static int qualify_contact(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact)
247 pjsip_tx_data *tdata;
248 RAII_VAR(struct ast_sip_endpoint *, endpoint_local, NULL, ao2_cleanup);
250 if (contact->authenticate_qualify) {
251 endpoint_local = ao2_bump(endpoint);
252 if (!endpoint_local) {
254 * Find the "first" endpoint to completely qualify the contact - any
255 * endpoint that is associated with the contact should do.
257 endpoint_local = find_an_endpoint(contact);
258 if (!endpoint_local) {
259 ast_log(LOG_ERROR, "Unable to find an endpoint to qualify contact %s\n",
266 if (ast_sip_create_request("OPTIONS", NULL, NULL, NULL, contact, &tdata)) {
267 ast_log(LOG_ERROR, "Unable to create request to qualify contact %s\n",
272 /* If an outbound proxy is specified set it on this request */
273 if (!ast_strlen_zero(contact->outbound_proxy) &&
274 ast_sip_set_outbound_proxy(tdata, contact->outbound_proxy)) {
275 pjsip_tx_data_dec_ref(tdata);
276 ast_log(LOG_ERROR, "Unable to apply outbound proxy on request to qualify contact %s\n",
281 init_start_time(contact);
283 ao2_ref(contact, +1);
284 if (ast_sip_send_request(tdata, NULL, endpoint_local, contact, qualify_contact_cb)
286 ast_log(LOG_ERROR, "Unable to send request to qualify contact %s\n",
288 ao2_ref(contact, -1);
297 * \brief Scheduling context for sending QUALIFY request at specified intervals.
299 static struct ast_sched_context *sched;
303 * \brief Container to hold all actively scheduled qualifies.
305 static struct ao2_container *sched_qualifies;
309 * \brief Structure to hold qualify contact scheduling information.
312 /*! The scheduling id */
314 /*! The the contact being checked */
315 struct ast_sip_contact *contact;
320 * \brief Destroy the scheduled data and remove from scheduler.
322 static void sched_data_destructor(void *obj)
324 struct sched_data *data = obj;
325 ao2_cleanup(data->contact);
329 * \brief Create the scheduling data object.
331 static struct sched_data *sched_data_create(struct ast_sip_contact *contact)
333 struct sched_data *data = ao2_alloc(sizeof(*data), sched_data_destructor);
336 ast_log(LOG_ERROR, "Unable to create schedule qualify data\n");
340 data->contact = contact;
341 ao2_ref(data->contact, +1);
348 * \brief Send a qualify contact request within a threaded task.
350 static int qualify_contact_task(void *obj)
352 RAII_VAR(struct ast_sip_contact *, contact, obj, ao2_cleanup);
353 return qualify_contact(NULL, contact);
358 * \brief Send a scheduled qualify contact request.
360 static int qualify_contact_sched(const void *obj)
362 struct sched_data *data = (struct sched_data *)obj;
364 ao2_ref(data->contact, +1);
365 if (ast_sip_push_task(NULL, qualify_contact_task, data->contact)) {
366 ao2_ref(data->contact, -1);
371 return data->contact->qualify_frequency * 1000;
376 * \brief Set up a scheduled qualify contact check.
378 static void schedule_qualify(struct ast_sip_contact *contact)
380 RAII_VAR(struct sched_data *, data, sched_data_create(contact), ao2_cleanup);
387 if ((data->id = ast_sched_add_variable(
388 sched, contact->qualify_frequency * 1000,
389 qualify_contact_sched, data, 1)) < 0) {
392 ast_log(LOG_ERROR, "Unable to schedule qualify for contact %s\n",
397 ao2_link(sched_qualifies, data);
402 * \brief Remove the contact from the scheduler.
404 static void unschedule_qualify(struct ast_sip_contact *contact)
406 struct sched_data *data;
408 data = ao2_find(sched_qualifies, contact, OBJ_UNLINK | OBJ_SEARCH_KEY);
413 AST_SCHED_DEL_UNREF(sched, data->id, ao2_cleanup(data));
419 * \brief Qualify the given contact and set up scheduling if configured.
421 static void qualify_and_schedule(struct ast_sip_contact *contact)
423 unschedule_qualify(contact);
425 if (contact->qualify_frequency) {
426 ao2_ref(contact, +1);
427 ast_sip_push_task(NULL, qualify_contact_task, contact);
429 schedule_qualify(contact);
435 * \brief A new contact has been created make sure it is available.
437 static void contact_created(const void *obj)
439 qualify_and_schedule((struct ast_sip_contact *)obj);
444 * \brief A contact has been deleted remove status tracking.
446 static void contact_deleted(const void *obj)
448 struct ast_sip_contact *contact = (struct ast_sip_contact *)obj;
449 RAII_VAR(struct ast_sip_contact_status *, status, NULL, ao2_cleanup);
451 unschedule_qualify(contact);
453 if (!(status = ast_sorcery_retrieve_by_id(
454 ast_sip_get_sorcery(), CONTACT_STATUS,
455 ast_sorcery_object_get_id(contact)))) {
459 if (ast_sorcery_delete(ast_sip_get_sorcery(), status)) {
460 ast_log(LOG_ERROR, "Unable to delete ast_sip_contact_status for contact %s\n",
465 static const struct ast_sorcery_observer contact_observer = {
466 .created = contact_created,
467 .deleted = contact_deleted
470 static pj_bool_t options_start(void)
472 if (!(sched = ast_sched_context_create()) ||
473 ast_sched_start_thread(sched)) {
480 static pj_bool_t options_stop(void)
482 ast_sorcery_observer_remove(ast_sip_get_sorcery(), "contact", &contact_observer);
484 ao2_t_ref(sched_qualifies, -1, "Remove scheduled qualifies on module stop");
487 ast_sched_context_destroy(sched);
493 static pj_status_t send_options_response(pjsip_rx_data *rdata, int code)
495 pjsip_endpoint *endpt = ast_sip_get_pjsip_endpoint();
496 pjsip_dialog *dlg = pjsip_rdata_get_dlg(rdata);
497 pjsip_transaction *trans = pjsip_rdata_get_tsx(rdata);
498 pjsip_tx_data *tdata;
499 const pjsip_hdr *hdr;
500 pjsip_response_addr res_addr;
503 /* Make the response object */
504 if ((status = ast_sip_create_response(rdata, code, NULL, &tdata) != PJ_SUCCESS)) {
505 ast_log(LOG_ERROR, "Unable to create response (%d)\n", status);
509 /* Add appropriate headers */
510 if ((hdr = pjsip_endpt_get_capability(endpt, PJSIP_H_ACCEPT, NULL))) {
511 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)pjsip_hdr_clone(tdata->pool, hdr));
513 if ((hdr = pjsip_endpt_get_capability(endpt, PJSIP_H_ALLOW, NULL))) {
514 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)pjsip_hdr_clone(tdata->pool, hdr));
516 if ((hdr = pjsip_endpt_get_capability(endpt, PJSIP_H_SUPPORTED, NULL))) {
517 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)pjsip_hdr_clone(tdata->pool, hdr));
521 * XXX TODO: pjsip doesn't care a lot about either of these headers -
522 * while it provides specific methods to create them, they are defined
523 * to be the standard string header creation. We never did add them
524 * in chan_sip, although RFC 3261 says they SHOULD. Hard coded here.
526 ast_sip_add_header(tdata, "Accept-Encoding", DEFAULT_ENCODING);
527 ast_sip_add_header(tdata, "Accept-Language", DEFAULT_LANGUAGE);
530 status = pjsip_dlg_send_response(dlg, trans, tdata);
532 /* Get where to send request. */
533 if ((status = pjsip_get_response_addr(
534 tdata->pool, rdata, &res_addr)) != PJ_SUCCESS) {
535 ast_log(LOG_ERROR, "Unable to get response address (%d)\n",
538 pjsip_tx_data_dec_ref(tdata);
541 status = ast_sip_send_response(&res_addr, tdata,
542 ast_pjsip_rdata_get_endpoint(rdata));
545 if (status != PJ_SUCCESS) {
546 ast_log(LOG_ERROR, "Unable to send response (%d)\n", status);
552 static pj_bool_t options_on_rx_request(pjsip_rx_data *rdata)
554 RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
556 pjsip_sip_uri *sip_ruri;
557 char exten[AST_MAX_EXTENSION];
559 if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method,
560 &pjsip_options_method)) {
564 if (!(endpoint = ast_pjsip_rdata_get_endpoint(rdata))) {
568 ruri = rdata->msg_info.msg->line.req.uri;
569 if (!PJSIP_URI_SCHEME_IS_SIP(ruri) && !PJSIP_URI_SCHEME_IS_SIPS(ruri)) {
570 send_options_response(rdata, 416);
574 sip_ruri = pjsip_uri_get_uri(ruri);
575 ast_copy_pj_str(exten, &sip_ruri->user, sizeof(exten));
577 if (ast_shutting_down()) {
578 send_options_response(rdata, 503);
579 } else if (!ast_exists_extension(NULL, endpoint->context, exten, 1, NULL)) {
580 send_options_response(rdata, 404);
582 send_options_response(rdata, 200);
587 static pjsip_module options_module = {
588 .name = {"Options Module", 14},
590 .priority = PJSIP_MOD_PRIORITY_APPLICATION,
591 .start = options_start,
592 .stop = options_stop,
593 .on_rx_request = options_on_rx_request,
598 * \brief Send qualify request to the given contact.
600 static int cli_on_contact(void *obj, void *arg, void *data, int flags)
602 struct ast_sip_contact *contact = obj;
603 struct ast_sip_endpoint *endpoint = data;
606 ast_cli(*cli_fd, " contact %s\n", contact->uri);
607 qualify_contact(endpoint, contact);
612 * \brief Data pushed to threadpool to qualify endpoints from the CLI
614 struct qualify_data {
615 /*! Endpoint that is being qualified */
616 struct ast_sip_endpoint *endpoint;
617 /*! CLI File descriptor for printing messages */
621 static struct qualify_data *qualify_data_alloc(struct ast_sip_endpoint *endpoint, int cli_fd)
623 struct qualify_data *qual_data;
625 qual_data = ast_malloc(sizeof(*qual_data));
630 qual_data->endpoint = ao2_bump(endpoint);
631 qual_data->cli_fd = cli_fd;
635 static void qualify_data_destroy(struct qualify_data *qual_data)
637 ao2_cleanup(qual_data->endpoint);
643 * \brief For an endpoint iterate over and qualify all aors/contacts
645 static int cli_qualify_contacts(void *data)
647 char *aor_name, *aors;
648 RAII_VAR(struct qualify_data *, qual_data, data, qualify_data_destroy);
649 struct ast_sip_endpoint *endpoint = qual_data->endpoint;
650 int cli_fd = qual_data->cli_fd;
651 const char *endpoint_name = ast_sorcery_object_get_id(endpoint);
653 if (ast_strlen_zero(endpoint->aors)) {
654 ast_cli(cli_fd, "Endpoint %s has no AoR's configured\n",
659 aors = ast_strdupa(endpoint->aors);
661 while ((aor_name = strsep(&aors, ","))) {
662 RAII_VAR(struct ast_sip_aor *, aor,
663 ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
664 RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
666 if (!aor || !(contacts = ast_sip_location_retrieve_aor_contacts(aor))) {
670 ast_cli(cli_fd, "Sending qualify to endpoint %s\n", endpoint_name);
671 ao2_callback_data(contacts, OBJ_NODATA, cli_on_contact, &cli_fd, endpoint);
676 static char *cli_qualify(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
678 RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
679 const char *endpoint_name;
680 struct qualify_data *qual_data;
684 e->command = "pjsip qualify";
686 "Usage: pjsip qualify <endpoint>\n"
687 " Send a SIP OPTIONS request to all contacts on the endpoint.\n";
694 return CLI_SHOWUSAGE;
697 endpoint_name = a->argv[2];
699 if (!(endpoint = ast_sorcery_retrieve_by_id(
700 ast_sip_get_sorcery(), "endpoint", endpoint_name))) {
701 ast_cli(a->fd, "Unable to retrieve endpoint %s\n", endpoint_name);
705 qual_data = qualify_data_alloc(endpoint, a->fd);
710 if (ast_sip_push_task(NULL, cli_qualify_contacts, qual_data)) {
711 qualify_data_destroy(qual_data);
720 * \brief Send qualify request to the given contact.
722 static int ami_contact_cb(void *obj, void *arg, int flags)
724 struct ast_sip_contact *contact = obj;
725 ao2_ref(contact, +1);
726 if (ast_sip_push_task(NULL, qualify_contact_task, contact)) {
727 ao2_cleanup(contact);
732 static int ami_sip_qualify(struct mansession *s, const struct message *m)
734 const char *endpoint_name = astman_get_header(m, "Endpoint");
735 RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
736 char *aor_name, *aors;
738 if (ast_strlen_zero(endpoint_name)) {
739 astman_send_error(s, m, "Endpoint parameter missing.");
743 endpoint = ast_sorcery_retrieve_by_id(
744 ast_sip_get_sorcery(),
748 astman_send_error(s, m, "Unable to retrieve endpoint\n");
752 /* send a qualify for all contacts registered with the endpoint */
753 if (ast_strlen_zero(endpoint->aors)) {
754 astman_send_error(s, m, "No AoRs configured for endpoint\n");
758 aors = ast_strdupa(endpoint->aors);
760 while ((aor_name = strsep(&aors, ","))) {
761 RAII_VAR(struct ast_sip_aor *, aor,
762 ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
763 RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
765 if (!aor || !(contacts = ast_sip_location_retrieve_aor_contacts(aor))) {
769 ao2_callback(contacts, OBJ_NODATA, ami_contact_cb, NULL);
772 astman_send_ack(s, m, "Endpoint found, will qualify");
776 static struct ast_cli_entry cli_options[] = {
777 AST_CLI_DEFINE(cli_qualify, "Send an OPTIONS request to a PJSIP endpoint")
780 static int sched_qualifies_hash_fn(const void *obj, int flags)
782 const struct sched_data *object;
783 const struct ast_sip_contact *key;
785 switch (flags & OBJ_SEARCH_MASK) {
789 case OBJ_SEARCH_OBJECT:
791 key = object->contact;
794 /* Hash can only work on something with a full key. */
798 return ast_str_hash(ast_sorcery_object_get_id(key));
801 static int sched_qualifies_cmp_fn(void *obj, void *arg, int flags)
803 const struct sched_data *object_left = obj;
804 const struct sched_data *object_right = arg;
805 struct ast_sip_contact *right_key = arg;
808 switch (flags & OBJ_SEARCH_MASK) {
809 case OBJ_SEARCH_OBJECT:
810 right_key = object_right->contact;
813 cmp = strcmp(ast_sorcery_object_get_id(object_left->contact),
814 ast_sorcery_object_get_id(right_key));
816 case OBJ_SEARCH_PARTIAL_KEY:
817 /* Not supported by container. */
822 * What arg points to is specific to this traversal callback
823 * and has no special meaning to astobj2.
832 * At this point the traversal callback is identical to a sorted
838 int ast_sip_initialize_sorcery_qualify(void)
840 struct ast_sorcery *sorcery = ast_sip_get_sorcery();
842 /* initialize sorcery ast_sip_contact_status resource */
843 ast_sorcery_apply_default(sorcery, CONTACT_STATUS, "memory", NULL);
845 if (ast_sorcery_internal_object_register(sorcery, CONTACT_STATUS,
846 contact_status_alloc, NULL, NULL)) {
847 ast_log(LOG_ERROR, "Unable to register ast_sip_contact_status in sorcery\n");
851 ast_sorcery_object_field_register_nodoc(sorcery, CONTACT_STATUS, "rtt", "0", OPT_UINT_T,
852 1, FLDSET(struct ast_sip_contact_status, status));
853 ast_sorcery_object_field_register_nodoc(sorcery, CONTACT_STATUS, "rtt", "0", OPT_UINT_T,
854 1, FLDSET(struct ast_sip_contact_status, rtt));
859 static int qualify_and_schedule_cb(void *obj, void *arg, int flags)
861 struct ast_sip_contact *contact = obj;
862 struct ast_sip_aor *aor = arg;
864 contact->qualify_frequency = aor->qualify_frequency;
865 contact->authenticate_qualify = aor->authenticate_qualify;
867 qualify_and_schedule(contact);
874 * \brief Qualify and schedule an endpoint's contacts
876 * \details For the given endpoint retrieve its list of aors, qualify all
877 * contacts, and schedule for checks if configured.
879 static int qualify_and_schedule_all_cb(void *obj, void *arg, int flags)
881 struct ast_sip_endpoint *endpoint = obj;
882 char *aor_name, *aors;
884 if (ast_strlen_zero(endpoint->aors)) {
888 aors = ast_strdupa(endpoint->aors);
890 while ((aor_name = strsep(&aors, ","))) {
891 RAII_VAR(struct ast_sip_aor *, aor,
892 ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
893 struct ao2_container *contacts;
895 if (!aor || !(contacts = ast_sip_location_retrieve_aor_contacts(aor))) {
899 ao2_callback(contacts, OBJ_NODATA, qualify_and_schedule_cb, aor);
900 ao2_ref(contacts, -1);
906 static void qualify_and_schedule_all(void)
908 struct ao2_container *endpoints = ast_sip_get_endpoints();
914 ao2_callback(endpoints, OBJ_NODATA,
915 qualify_and_schedule_all_cb, NULL);
916 ao2_ref(endpoints, -1);
919 int ast_res_pjsip_init_options_handling(int reload)
921 const pj_str_t STR_OPTIONS = { "OPTIONS", 7 };
924 qualify_and_schedule_all();
928 if (!(sched_qualifies = ao2_t_container_alloc(
929 QUALIFIED_BUCKETS, sched_qualifies_hash_fn, sched_qualifies_cmp_fn,
930 "Create container for scheduled qualifies"))) {
934 if (pjsip_endpt_register_module(ast_sip_get_pjsip_endpoint(), &options_module) != PJ_SUCCESS) {
939 if (pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(), NULL, PJSIP_H_ALLOW, NULL, 1, &STR_OPTIONS) != PJ_SUCCESS) {
940 pjsip_endpt_unregister_module(ast_sip_get_pjsip_endpoint(), &options_module);
944 if (ast_sorcery_observer_add(ast_sip_get_sorcery(), "contact", &contact_observer)) {
945 ast_log(LOG_WARNING, "Unable to add contact observer\n");
949 qualify_and_schedule_all();
950 ast_cli_register_multiple(cli_options, ARRAY_LEN(cli_options));
951 ast_manager_register2("PJSIPQualify", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, ami_sip_qualify, NULL, NULL, NULL);
956 void ast_res_pjsip_cleanup_options_handling(void)
958 ast_cli_unregister_multiple(cli_options, ARRAY_LEN(cli_options));
959 ast_manager_unregister("PJSIPQualify");