<p>Kevin Harwell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12998">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_mwi: use an ao2_global object for mwi containers<br><br>On shutdown it's possible for the unsolicited mwi container to be freed before<br>other dependent threads are done using it. This patch ensures this can no<br>longer happen by wrapping the container in an ao2_global object. The solicited<br>container was also changed too.<br><br>ASTERISK-28552<br><br>Change-Id: I8f812286dc19a34916acacd71ce2ec26e1042047<br>---<br>M res/res_pjsip_mwi.c<br>1 file changed, 142 insertions(+), 59 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/98/12998/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c</span><br><span>index 59016ff..d4ac68c 100644</span><br><span>--- a/res/res_pjsip_mwi.c</span><br><span>+++ b/res/res_pjsip_mwi.c</span><br><span>@@ -42,8 +42,9 @@</span><br><span> #include "asterisk/mwi.h"</span><br><span> </span><br><span> struct mwi_subscription;</span><br><span style="color: hsl(0, 100%, 40%);">-static struct ao2_container *unsolicited_mwi;</span><br><span style="color: hsl(0, 100%, 40%);">-static struct ao2_container *solicited_mwi;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+AO2_GLOBAL_OBJ_STATIC(mwi_unsolicited);</span><br><span style="color: hsl(120, 100%, 40%);">+AO2_GLOBAL_OBJ_STATIC(mwi_solicited);</span><br><span> </span><br><span> static char *default_voicemail_extension;</span><br><span> </span><br><span>@@ -588,13 +589,15 @@</span><br><span> }</span><br><span> </span><br><span> static int create_unsolicited_mwi_subscriptions(struct ast_sip_endpoint *endpoint,</span><br><span style="color: hsl(0, 100%, 40%);">- int recreate, int send_now);</span><br><span style="color: hsl(120, 100%, 40%);">+ int recreate, int send_now, struct ao2_container *unsolicited_mwi, struct ao2_container *solicited_mwi);</span><br><span> </span><br><span> static void mwi_subscription_shutdown(struct ast_sip_subscription *sub)</span><br><span> {</span><br><span> struct mwi_subscription *mwi_sub;</span><br><span> struct ast_datastore *mwi_datastore;</span><br><span> struct ast_sip_endpoint *endpoint = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *unsolicited_mwi;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *solicited_mwi;</span><br><span> </span><br><span> mwi_datastore = ast_sip_subscription_get_datastore(sub, MWI_DATASTORE);</span><br><span> if (!mwi_datastore) {</span><br><span>@@ -607,18 +610,25 @@</span><br><span> endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", mwi_sub->id);</span><br><span> </span><br><span> ao2_ref(mwi_datastore, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_unlink(solicited_mwi, mwi_sub);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ solicited_mwi = ao2_global_obj_ref(mwi_solicited);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (solicited_mwi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_unlink(solicited_mwi, mwi_sub);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> /*</span><br><span> * When a solicited subscription is removed it's possible an unsolicited one</span><br><span> * needs to be [re-]created. Attempt to establish unsolicited MWI.</span><br><span> */</span><br><span style="color: hsl(120, 100%, 40%);">+ unsolicited_mwi = ao2_global_obj_ref(mwi_unsolicited);</span><br><span> if (unsolicited_mwi && endpoint) {</span><br><span> ao2_lock(unsolicited_mwi);</span><br><span style="color: hsl(0, 100%, 40%);">- create_unsolicited_mwi_subscriptions(endpoint, 1, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+ create_unsolicited_mwi_subscriptions(endpoint, 1, 1, unsolicited_mwi, solicited_mwi);</span><br><span> ao2_unlock(unsolicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(unsolicited_mwi, -1);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(solicited_mwi);</span><br><span> ao2_cleanup(endpoint);</span><br><span> }</span><br><span> </span><br><span>@@ -684,6 +694,10 @@</span><br><span> *mwi_sub = NULL;</span><br><span> *mwi_stasis = NULL;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (!container) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> mwi_subs = ao2_find(container, ast_sorcery_object_get_id(endpoint),</span><br><span> OBJ_SEARCH_KEY | OBJ_MULTIPLE | OBJ_NOLOCK);</span><br><span> if (!mwi_subs) {</span><br><span>@@ -713,11 +727,13 @@</span><br><span> *</span><br><span> * \param endpoint The endpoint</span><br><span> * \param mailbox The mailbox</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param unsolicited_mwi A container of unsolicited mwi objects</span><br><span> *</span><br><span> * \retval 1 if a solicited subscription is allowed for the endpoint/mailbox</span><br><span> * 0 otherwise</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">-static int allow_and_or_replace_unsolicited(struct ast_sip_endpoint *endpoint, const char *mailbox)</span><br><span style="color: hsl(120, 100%, 40%);">+static int allow_and_or_replace_unsolicited(struct ast_sip_endpoint *endpoint, const char *mailbox,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *unsolicited_mwi)</span><br><span> {</span><br><span> struct mwi_subscription *mwi_sub;</span><br><span> struct mwi_stasis_subscription *mwi_stasis;</span><br><span>@@ -764,11 +780,14 @@</span><br><span> *</span><br><span> * \param endpoint The endpoint</span><br><span> * \param mailbox The mailbox</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param unsolicited_mwi A container of unsolicited mwi objects</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param solicited_mwi A container of solicited mwi objects</span><br><span> *</span><br><span> * \retval 1 if an unsolicited subscription is allowed for the endpoint/mailbox</span><br><span> * 0 otherwise</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">-static int is_unsolicited_allowed(struct ast_sip_endpoint *endpoint, const char *mailbox)</span><br><span style="color: hsl(120, 100%, 40%);">+static int is_unsolicited_allowed(struct ast_sip_endpoint *endpoint, const char *mailbox,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *unsolicited_mwi, struct ao2_container *solicited_mwi)</span><br><span> {</span><br><span> struct mwi_subscription *mwi_sub;</span><br><span> struct mwi_stasis_subscription *mwi_stasis;</span><br><span>@@ -834,28 +853,41 @@</span><br><span> struct ast_sip_endpoint *endpoint = arg;</span><br><span> char *mailboxes;</span><br><span> char *mailbox;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *unsolicited_mwi;</span><br><span> </span><br><span> if (ast_strlen_zero(aor->mailboxes)) {</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span> /* A reload could be taking place so lock while checking if allowed */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_lock(unsolicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+ unsolicited_mwi = ao2_global_obj_ref(mwi_unsolicited);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (unsolicited_mwi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_lock(unsolicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> mailboxes = ast_strdupa(aor->mailboxes);</span><br><span> while ((mailbox = ast_strip(strsep(&mailboxes, ",")))) {</span><br><span> if (ast_strlen_zero(mailbox)) {</span><br><span> continue;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!allow_and_or_replace_unsolicited(endpoint, mailbox)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!allow_and_or_replace_unsolicited(endpoint, mailbox, unsolicited_mwi)) {</span><br><span> ast_debug(1, "Endpoint '%s' already configured for unsolicited MWI for mailbox '%s'. "</span><br><span> "Denying MWI subscription to %s\n", ast_sorcery_object_get_id(endpoint), mailbox,</span><br><span> ast_sorcery_object_get_id(aor));</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_unlock(unsolicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (unsolicited_mwi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_unlock(unsolicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(unsolicited_mwi, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> return -1;</span><br><span> }</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_unlock(unsolicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (unsolicited_mwi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_unlock(unsolicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(unsolicited_mwi, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> return 0;</span><br><span> }</span><br><span>@@ -981,6 +1013,7 @@</span><br><span> const char *resource = ast_sip_subscription_get_resource_name(sip_sub);</span><br><span> struct mwi_subscription *sub;</span><br><span> struct ast_sip_endpoint *endpoint = ast_sip_subscription_get_endpoint(sip_sub);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *solicited_mwi;</span><br><span> </span><br><span> /* no aor in uri? subscribe to all on endpoint */</span><br><span> if (ast_strlen_zero(resource)) {</span><br><span>@@ -1001,7 +1034,12 @@</span><br><span> ast_sip_subscription_remove_datastore(sip_sub, MWI_DATASTORE);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ao2_link(solicited_mwi, sub);</span><br><span style="color: hsl(120, 100%, 40%);">+ solicited_mwi = ao2_global_obj_ref(mwi_solicited);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (solicited_mwi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_link(solicited_mwi, sub);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(solicited_mwi, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ao2_cleanup(sub);</span><br><span> ao2_cleanup(endpoint);</span><br><span> return 0;</span><br><span>@@ -1148,11 +1186,13 @@</span><br><span> * \param endpoint An endpoint object</span><br><span> * \param recreate Whether or not unsolicited subscriptions are potentially being recreated</span><br><span> * \param send_now Whether or not to send a notify once the subscription is created</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param unsolicited_mwi A container of unsolicited mwi objects</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param solicited_mwi A container of solicited mwi objects</span><br><span> *</span><br><span> * \retval 0</span><br><span> */</span><br><span> static int create_unsolicited_mwi_subscriptions(struct ast_sip_endpoint *endpoint,</span><br><span style="color: hsl(0, 100%, 40%);">- int recreate, int send_now)</span><br><span style="color: hsl(120, 100%, 40%);">+ int recreate, int send_now, struct ao2_container *unsolicited_mwi, struct ao2_container *solicited_mwi)</span><br><span> {</span><br><span> RAII_VAR(struct mwi_subscription *, aggregate_sub, NULL, ao2_cleanup);</span><br><span> char *mailboxes;</span><br><span>@@ -1187,14 +1227,16 @@</span><br><span> }</span><br><span> </span><br><span> /* Lock solicited so we don't potentially add to both containers */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_lock(solicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (solicited_mwi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_lock(solicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> mailboxes = ast_strdupa(endpoint->subscription.mwi.mailboxes);</span><br><span> while ((mailbox = ast_strip(strsep(&mailboxes, ",")))) {</span><br><span> struct mwi_subscription *sub;</span><br><span> struct mwi_stasis_subscription *mwi_stasis_sub;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!is_unsolicited_allowed(endpoint, mailbox)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!is_unsolicited_allowed(endpoint, mailbox, unsolicited_mwi, solicited_mwi)) {</span><br><span> continue;</span><br><span> }</span><br><span> </span><br><span>@@ -1234,13 +1276,16 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ao2_unlock(solicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (solicited_mwi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_unlock(solicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static int create_mwi_subscriptions_for_endpoint(void *obj, void *arg, int flags)</span><br><span style="color: hsl(120, 100%, 40%);">+static int create_mwi_subscriptions_for_endpoint(void *obj, void *arg, void *data, int flags)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- return create_unsolicited_mwi_subscriptions(obj, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ return create_unsolicited_mwi_subscriptions(obj, 0, 0, arg, data);</span><br><span> }</span><br><span> </span><br><span> static int unsubscribe(void *obj, void *arg, int flags)</span><br><span>@@ -1254,9 +1299,16 @@</span><br><span> </span><br><span> static void create_mwi_subscriptions(void)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *unsolicited_mwi;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *solicited_mwi;</span><br><span> struct ao2_container *endpoints;</span><br><span> struct ast_variable *var;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ unsolicited_mwi = ao2_global_obj_ref(mwi_unsolicited);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!unsolicited_mwi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> var = ast_variable_new("mailboxes !=", "", "");</span><br><span> </span><br><span> endpoints = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "endpoint",</span><br><span>@@ -1264,9 +1316,12 @@</span><br><span> </span><br><span> ast_variables_destroy(var);</span><br><span> if (!endpoints) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(unsolicited_mwi, -1);</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ solicited_mwi = ao2_global_obj_ref(mwi_solicited);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* We remove all the old stasis subscriptions first before applying the new configuration. This</span><br><span> * prevents a situation where there might be multiple overlapping stasis subscriptions for an</span><br><span> * endpoint for mailboxes. Though there may be mailbox changes during the gap between unsubscribing</span><br><span>@@ -1275,10 +1330,12 @@</span><br><span> */</span><br><span> ao2_lock(unsolicited_mwi);</span><br><span> ao2_callback(unsolicited_mwi, OBJ_NOLOCK | OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, unsubscribe, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_callback(endpoints, OBJ_NODATA, create_mwi_subscriptions_for_endpoint, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_callback_data(endpoints, OBJ_NODATA, create_mwi_subscriptions_for_endpoint, unsolicited_mwi, solicited_mwi);</span><br><span> ao2_unlock(unsolicited_mwi);</span><br><span> </span><br><span> ao2_ref(endpoints, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(solicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(unsolicited_mwi, -1);</span><br><span> }</span><br><span> </span><br><span> /*! \brief Function called to send MWI NOTIFY on any unsolicited mailboxes relating to this AOR */</span><br><span>@@ -1305,6 +1362,8 @@</span><br><span> char *id = ast_strdupa(ast_sorcery_object_get_id(contact));</span><br><span> char *aor = NULL;</span><br><span> struct ast_sip_endpoint *endpoint = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *unsolicited_mwi;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *solicited_mwi;</span><br><span> </span><br><span> if (contact->endpoint) {</span><br><span> endpoint = ao2_bump(contact->endpoint);</span><br><span>@@ -1319,10 +1378,20 @@</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ unsolicited_mwi = ao2_global_obj_ref(mwi_unsolicited);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!unsolicited_mwi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(endpoint);</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ solicited_mwi = ao2_global_obj_ref(mwi_solicited);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ao2_lock(unsolicited_mwi);</span><br><span style="color: hsl(0, 100%, 40%);">- create_mwi_subscriptions_for_endpoint(endpoint, NULL, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ create_unsolicited_mwi_subscriptions(endpoint, 0, 0, unsolicited_mwi, solicited_mwi);</span><br><span> ao2_unlock(unsolicited_mwi);</span><br><span> ao2_cleanup(endpoint);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(solicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(unsolicited_mwi, -1);</span><br><span> </span><br><span> aor = strsep(&id, ";@");</span><br><span> ao2_callback(unsolicited_mwi, OBJ_NODATA, send_contact_notify, aor);</span><br><span>@@ -1348,6 +1417,7 @@</span><br><span> struct mwi_subscription *mwi_sub;</span><br><span> struct ast_sip_endpoint *endpoint = NULL;</span><br><span> struct ast_sip_contact *found_contact;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *unsolicited_mwi;</span><br><span> </span><br><span> if (contact->endpoint) {</span><br><span> endpoint = ao2_bump(contact->endpoint);</span><br><span>@@ -1370,6 +1440,11 @@</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ unsolicited_mwi = ao2_global_obj_ref(mwi_unsolicited);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!unsolicited_mwi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ao2_lock(unsolicited_mwi);</span><br><span> mwi_subs = ao2_find(unsolicited_mwi, contact->endpoint_name,</span><br><span> OBJ_SEARCH_KEY | OBJ_MULTIPLE | OBJ_NOLOCK | OBJ_UNLINK);</span><br><span>@@ -1380,6 +1455,7 @@</span><br><span> ao2_iterator_destroy(mwi_subs);</span><br><span> }</span><br><span> ao2_unlock(unsolicited_mwi);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(unsolicited_mwi, -1);</span><br><span> }</span><br><span> </span><br><span> /*! \brief Observer for contacts so unsolicited MWI is sent when a contact changes */</span><br><span>@@ -1392,7 +1468,12 @@</span><br><span> /*! \brief Task invoked to send initial MWI NOTIFY for unsolicited */</span><br><span> static int send_initial_notify_all(void *obj)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_callback(unsolicited_mwi, OBJ_NODATA, send_notify, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *unsolicited_mwi = ao2_global_obj_ref(mwi_unsolicited);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (unsolicited_mwi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_callback(unsolicited_mwi, OBJ_NODATA, send_notify, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(unsolicited_mwi, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> return 0;</span><br><span> }</span><br><span>@@ -1440,8 +1521,38 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int unload_module(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *unsolicited_mwi;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_observer_remove(ast_sip_get_sorcery(), "global", &global_observer);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_observer_remove(ast_sip_get_sorcery(), "contact", &mwi_contact_observer);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ unsolicited_mwi = ao2_global_obj_replace(mwi_unsolicited, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (unsolicited_mwi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_callback(unsolicited_mwi, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, unsubscribe, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(unsolicited_mwi, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_global_obj_release(mwi_solicited);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_serializer_pool_destroy(mwi_serializer_pool)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Unload incomplete. Try again later\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ mwi_serializer_pool = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_unregister_subscription_handler(&mwi_handler);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(default_voicemail_extension);</span><br><span style="color: hsl(120, 100%, 40%);">+ default_voicemail_extension = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int load_module(void)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *mwi_container;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> CHECK_PJSIP_MODULE_LOADED();</span><br><span> </span><br><span> if (ast_sip_register_subscription_handler(&mwi_handler)) {</span><br><span>@@ -1454,22 +1565,23 @@</span><br><span> ast_log(AST_LOG_WARNING, "Failed to create MWI serializer pool. The default SIP pool will be used for MWI\n");</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- solicited_mwi = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MWI_BUCKETS,</span><br><span style="color: hsl(120, 100%, 40%);">+ mwi_container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MWI_BUCKETS,</span><br><span> mwi_sub_hash, NULL, mwi_sub_cmp);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!solicited_mwi) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_serializer_pool_destroy(mwi_serializer_pool);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sip_unregister_subscription_handler(&mwi_handler);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!mwi_container) {</span><br><span style="color: hsl(120, 100%, 40%);">+ unload_module();</span><br><span> return AST_MODULE_LOAD_DECLINE;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_global_obj_replace_unref(mwi_solicited, mwi_container);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(mwi_container, -1);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- unsolicited_mwi = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MWI_BUCKETS,</span><br><span style="color: hsl(120, 100%, 40%);">+ mwi_container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MWI_BUCKETS,</span><br><span> mwi_sub_hash, NULL, mwi_sub_cmp);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!unsolicited_mwi) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_serializer_pool_destroy(mwi_serializer_pool);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sip_unregister_subscription_handler(&mwi_handler);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(solicited_mwi, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!mwi_container) {</span><br><span style="color: hsl(120, 100%, 40%);">+ unload_module();</span><br><span> return AST_MODULE_LOAD_DECLINE;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_global_obj_replace_unref(mwi_unsolicited, mwi_container);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(mwi_container, -1);</span><br><span> </span><br><span> ast_sorcery_observer_add(ast_sip_get_sorcery(), "contact", &mwi_contact_observer);</span><br><span> ast_sorcery_observer_add(ast_sip_get_sorcery(), "global", &global_observer);</span><br><span>@@ -1492,35 +1604,6 @@</span><br><span> return AST_MODULE_LOAD_SUCCESS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static int unload_module(void)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sorcery_observer_remove(ast_sip_get_sorcery(), "global", &global_observer);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sorcery_observer_remove(ast_sip_get_sorcery(), "contact", &mwi_contact_observer);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (unsolicited_mwi) {</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_callback(unsolicited_mwi, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, unsubscribe, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(unsolicited_mwi, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- unsolicited_mwi = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (solicited_mwi) {</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(solicited_mwi, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- solicited_mwi = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_serializer_pool_destroy(mwi_serializer_pool)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Unload incomplete. Try again later\n");</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- mwi_serializer_pool = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sip_unregister_subscription_handler(&mwi_handler);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(default_voicemail_extension);</span><br><span style="color: hsl(0, 100%, 40%);">- default_voicemail_extension = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP MWI resource",</span><br><span> .support_level = AST_MODULE_SUPPORT_CORE,</span><br><span> .load = load_module,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/12998">change 12998</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/12998"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I8f812286dc19a34916acacd71ce2ec26e1042047 </div>
<div style="display:none"> Gerrit-Change-Number: 12998 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>