]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
MWI: Update modules that subscribe to MWI to use new API calls
authorKevin Harwell <kharwell@digium.com>
Wed, 12 Jun 2019 18:11:42 +0000 (13:11 -0500)
committerKevin Harwell <kharwell@digium.com>
Mon, 8 Jul 2019 23:12:49 +0000 (18:12 -0500)
The MWI core recently got some new API calls that make tracking MWI state
lifetime more reliable. This patch updates those modules that subscribe to
specific MWI topics to use the new API. Specifically, these modules now
subscribe to both MWI topics and MWI state.

ASTERISK-28442

Change-Id: I32bef880b647246823dbccdf44a98d384fcabfbd

channels/chan_dahdi.c
channels/chan_dahdi.h
channels/chan_iax2.c
channels/chan_mgcp.c
channels/chan_sip.c
channels/chan_skinny.c
channels/sig_pri.c
channels/sig_pri.h
channels/sip/include/sip.h
res/res_pjsip_mwi.c

index 434bd16a82001bbc665f1a49dbd08baa91a48e5d..a721d7b17f300ed4e40c9ac1aee85b7ddb2be780 100644 (file)
@@ -5540,7 +5540,7 @@ static void destroy_dahdi_pvt(struct dahdi_pvt *pvt)
                ao2_cleanup(p->smdi_iface);
        }
        if (p->mwi_event_sub) {
-               p->mwi_event_sub = stasis_unsubscribe(p->mwi_event_sub);
+               p->mwi_event_sub = ast_mwi_unsubscribe(p->mwi_event_sub);
        }
        if (p->vars) {
                ast_variables_destroy(p->vars);
@@ -12607,18 +12607,11 @@ static struct dahdi_pvt *mkintf(int channel, const struct dahdi_chan_conf *conf,
                tmp->cid_subaddr[0] = '\0';
                ast_copy_string(tmp->mailbox, conf->chan.mailbox, sizeof(tmp->mailbox));
                if (channel != CHAN_PSEUDO && !ast_strlen_zero(tmp->mailbox)) {
-                       struct stasis_topic *mailbox_specific_topic;
-
-                       mailbox_specific_topic = ast_mwi_topic(tmp->mailbox);
-                       if (mailbox_specific_topic) {
-                               /* This module does not handle MWI in an event-based manner.  However, it
-                                * subscribes to MWI for each mailbox that is configured so that the core
-                                * knows that we care about it.  Then, chan_dahdi will get the MWI from the
-                                * event cache instead of checking the mailbox directly. */
-                               tmp->mwi_event_sub = stasis_subscribe_pool(mailbox_specific_topic, stasis_subscription_cb_noop, NULL);
-                               stasis_subscription_accept_message_type(tmp->mwi_event_sub, ast_mwi_state_type());
-                               stasis_subscription_set_filter(tmp->mwi_event_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
-                       }
+                       /* This module does not handle MWI in an event-based manner.  However, it
+                        * subscribes to MWI for each mailbox that is configured so that the core
+                        * knows that we care about it.  Then, chan_dahdi will get the MWI from the
+                        * event cache instead of checking the mailbox directly. */
+                       tmp->mwi_event_sub = ast_mwi_subscribe_pool(tmp->mailbox, stasis_subscription_cb_noop, NULL);
                }
 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
                tmp->mwisend_setting = conf->chan.mwisend_setting;
index 212a0bf380bb7455e3079381b2cc156260317f9e..d84be510bd8cfad40e5ba5e517f502bef6dd271b 100644 (file)
@@ -653,7 +653,7 @@ struct dahdi_pvt {
         */
        char mailbox[AST_MAX_MAILBOX_UNIQUEID];
        /*! \brief Opaque event subscription parameters for message waiting indication support. */
-       struct stasis_subscription *mwi_event_sub;
+       struct ast_mwi_subscriber *mwi_event_sub;
        /*! \brief Delayed dialing for E911.  Overlap digits for ISDN. */
        char dialdest[256];
 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
index a7b2f269f3cd4aa5ca0692ae843a35d2ea7382ba..30f949624ea7a6439af0794628e983713805d219 100644 (file)
@@ -582,7 +582,7 @@ struct iax2_peer {
        int smoothing;                                  /*!< Sample over how many units to determine historic ms */
        uint16_t maxcallno;                             /*!< Max call number limit for this peer.  Set on registration */
 
-       struct stasis_subscription *mwi_event_sub;      /*!< This subscription lets pollmailboxes know which mailboxes need to be polled */
+       struct ast_mwi_subscriber *mwi_event_sub;       /*!< This subscription lets pollmailboxes know which mailboxes need to be polled */
 
        struct ast_acl_list *acl;
        enum calltoken_peer_enum calltoken_required;    /*!< Is calltoken validation required or not, can be YES, NO, or AUTO */
@@ -12764,7 +12764,9 @@ static void peer_destructor(void *obj)
        if (peer->dnsmgr)
                ast_dnsmgr_release(peer->dnsmgr);
 
-       peer->mwi_event_sub = stasis_unsubscribe(peer->mwi_event_sub);
+       if (peer->mwi_event_sub) {
+               peer->mwi_event_sub = ast_mwi_unsubscribe(peer->mwi_event_sub);
+       }
 
        ast_string_field_free_memory(peer);
 
@@ -13069,17 +13071,10 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
        }
 
        if (!ast_strlen_zero(peer->mailbox) && !peer->mwi_event_sub) {
-               struct stasis_topic *mailbox_specific_topic;
-
-               mailbox_specific_topic = ast_mwi_topic(peer->mailbox);
-               if (mailbox_specific_topic) {
-                       /* The MWI subscriptions exist just so the core knows we care about those
-                        * mailboxes.  However, we just grab the events out of the cache when it
-                        * is time to send MWI, since it is only sent with a REGACK. */
-                       peer->mwi_event_sub = stasis_subscribe_pool(mailbox_specific_topic, stasis_subscription_cb_noop, NULL);
-                       stasis_subscription_accept_message_type(peer->mwi_event_sub, ast_mwi_state_type());
-                       stasis_subscription_set_filter(peer->mwi_event_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
-               }
+               /* The MWI subscriptions exist just so the core knows we care about those
+                * mailboxes.  However, we just grab the events out of the cache when it
+                * is time to send MWI, since it is only sent with a REGACK. */
+               peer->mwi_event_sub = ast_mwi_subscribe_pool(peer->mailbox, stasis_subscription_cb_noop, NULL);
        }
 
        if (subscribe_acl_change) {
index fa3a0814697a1720393c7aefbba56cc72b5886d5..2c8c5253bf9c19c8844a37e2472a4c971e506dd4 100644 (file)
@@ -346,7 +346,7 @@ struct mgcp_endpoint {
        char curtone[80];                       /*!< Current tone */
        char mailbox[AST_MAX_EXTENSION];
        char parkinglot[AST_MAX_CONTEXT];   /*!< Parkinglot */
-       struct stasis_subscription *mwi_event_sub;
+       struct ast_mwi_subscriber *mwi_event_sub;
        ast_group_t callgroup;
        ast_group_t pickupgroup;
        int callwaiting;
@@ -4234,18 +4234,11 @@ static struct mgcp_gateway *build_gateway(char *cat, struct ast_variable *v)
                                ast_copy_string(e->mailbox, mailbox, sizeof(e->mailbox));
                                ast_copy_string(e->parkinglot, parkinglot, sizeof(e->parkinglot));
                                if (!ast_strlen_zero(e->mailbox)) {
-                                       struct stasis_topic *mailbox_specific_topic;
-
-                                       mailbox_specific_topic = ast_mwi_topic(e->mailbox);
-                                       if (mailbox_specific_topic) {
-                                               /* This module does not handle MWI in an event-based manner.  However, it
-                                                * subscribes to MWI for each mailbox that is configured so that the core
-                                                * knows that we care about it.  Then, chan_mgcp will get the MWI from the
-                                                * event cache instead of checking the mailbox directly. */
-                                               e->mwi_event_sub = stasis_subscribe_pool(mailbox_specific_topic, stasis_subscription_cb_noop, NULL);
-                                               stasis_subscription_accept_message_type(e->mwi_event_sub, ast_mwi_state_type());
-                                               stasis_subscription_set_filter(e->mwi_event_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
-                                       }
+                                       /* This module does not handle MWI in an event-based manner.  However, it
+                                        * subscribes to MWI for each mailbox that is configured so that the core
+                                        * knows that we care about it.  Then, chan_mgcp will get the MWI from the
+                                        * event cache instead of checking the mailbox directly. */
+                                       e->mwi_event_sub = ast_mwi_subscribe_pool(e->mailbox, stasis_subscription_cb_noop, NULL);
                                }
                                snprintf(e->rqnt_ident, sizeof(e->rqnt_ident), "%08lx", (unsigned long)ast_random());
                                e->msgstate = -1;
@@ -4587,7 +4580,7 @@ static void destroy_endpoint(struct mgcp_endpoint *e)
        }
 
        if (e->mwi_event_sub) {
-               e->mwi_event_sub = stasis_unsubscribe(e->mwi_event_sub);
+               e->mwi_event_sub = ast_mwi_unsubscribe(e->mwi_event_sub);
        }
 
        if (e->chanvars) {
index cd0db387afd9e8194b1f7051ea19694226fb9865..eef0d417a25927bfac6c0f3c13a66330fbc6a28f 100644 (file)
@@ -5251,7 +5251,7 @@ static void register_peer_exten(struct sip_peer *peer, int onoff)
 static void destroy_mailbox(struct sip_mailbox *mailbox)
 {
        if (mailbox->event_sub) {
-               mailbox->event_sub = stasis_unsubscribe_and_join(mailbox->event_sub);
+               mailbox->event_sub = ast_mwi_unsubscribe_and_join(mailbox->event_sub);
        }
        ast_free(mailbox);
 }
@@ -28384,18 +28384,14 @@ static void add_peer_mwi_subs(struct sip_peer *peer)
        struct sip_mailbox *mailbox;
 
        AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
-               struct stasis_topic *mailbox_specific_topic;
-
                if (mailbox->status != SIP_MAILBOX_STATUS_NEW) {
                        continue;
                }
-
-               mailbox_specific_topic = ast_mwi_topic(mailbox->id);
-               if (mailbox_specific_topic) {
-                       mailbox->event_sub = stasis_subscribe_pool(mailbox_specific_topic, mwi_event_cb, peer);
-                       stasis_subscription_accept_message_type(mailbox->event_sub, ast_mwi_state_type());
-                       stasis_subscription_accept_message_type(mailbox->event_sub, stasis_subscription_change_type());
-                       stasis_subscription_set_filter(mailbox->event_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
+               mailbox->event_sub = ast_mwi_subscribe_pool(mailbox->id, mwi_event_cb, peer);
+               if (mailbox->event_sub) {
+                       stasis_subscription_accept_message_type(
+                               ast_mwi_subscriber_subscription(mailbox->event_sub),
+                               stasis_subscription_change_type());
                }
        }
 }
index fb31c9ffd03f6e0eaf943375f6621ab175c85e72..17bc0390dc1c07a737fa00ae3e74dca1ef467936 100644 (file)
@@ -1466,7 +1466,7 @@ struct skinny_line {
        SKINNY_LINE_OPTIONS
        ast_mutex_t lock;
        struct skinny_container *container;
-       struct stasis_subscription *mwi_event_sub; /* Event based MWI */
+       struct ast_mwi_subscriber *mwi_event_sub; /* Event based MWI */
        struct skinny_subchannel *activesub;
        AST_LIST_HEAD(, skinny_subchannel) sub;
        AST_LIST_HEAD(, skinny_subline) sublines;
@@ -8328,16 +8328,8 @@ static struct skinny_line *config_line(const char *lname, struct ast_variable *v
        config_parse_variables(TYPE_LINE, l, v);
 
        if (!ast_strlen_zero(l->mailbox)) {
-               struct stasis_topic *mailbox_specific_topic;
-
                ast_verb(3, "Setting mailbox '%s' on line %s\n", l->mailbox, l->name);
-
-               mailbox_specific_topic = ast_mwi_topic(l->mailbox);
-               if (mailbox_specific_topic) {
-                       l->mwi_event_sub = stasis_subscribe_pool(mailbox_specific_topic, mwi_event_cb, l);
-                       stasis_subscription_accept_message_type(l->mwi_event_sub, ast_mwi_state_type());
-                       stasis_subscription_set_filter(l->mwi_event_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
-               }
+               l->mwi_event_sub = ast_mwi_subscribe_pool(l->mailbox, mwi_event_cb, l);
        }
 
        if (!ast_strlen_zero(vmexten) && ast_strlen_zero(l->vmexten)) {
@@ -8640,7 +8632,7 @@ int skinny_reload(void)
                   will happen below. */
                while ((l = AST_LIST_REMOVE_HEAD(&d->lines, list))) {
                        if (l->mwi_event_sub) {
-                               l->mwi_event_sub = stasis_unsubscribe(l->mwi_event_sub);
+                               l->mwi_event_sub = ast_mwi_unsubscribe(l->mwi_event_sub);
                        }
                }
                /* Delete all speeddials for this device */
@@ -8797,7 +8789,7 @@ static int unload_module(void)
                                skinny_unlocksub(sub);
                        }
                        if (l->mwi_event_sub) {
-                               l->mwi_event_sub = stasis_unsubscribe_and_join(l->mwi_event_sub);
+                               l->mwi_event_sub = ast_mwi_unsubscribe_and_join(l->mwi_event_sub);
                        }
                        ast_mutex_unlock(&l->lock);
                        unregister_exten(l);
index 102e3c4fc13a9c2b9b64220816830cb00ba720bf..a8c042f771354dcc8f1c2b8a719050b173cc76d3 100644 (file)
@@ -8982,7 +8982,7 @@ void sig_pri_stop_pri(struct sig_pri_span *pri)
 #if defined(HAVE_PRI_MWI)
        for (idx = 0; idx < ARRAY_LEN(pri->mbox); ++idx) {
                if (pri->mbox[idx].sub) {
-                       pri->mbox[idx].sub = stasis_unsubscribe_and_join(pri->mbox[idx].sub);
+                       pri->mbox[idx].sub = ast_mwi_unsubscribe_and_join(pri->mbox[idx].sub);
                }
        }
 #endif /* defined(HAVE_PRI_MWI) */
@@ -9051,7 +9051,7 @@ int sig_pri_start_pri(struct sig_pri_span *pri)
        /* Prepare the mbox[] for use. */
        for (i = 0; i < ARRAY_LEN(pri->mbox); ++i) {
                if (pri->mbox[i].sub) {
-                       pri->mbox[i].sub = stasis_unsubscribe(pri->mbox[i].sub);
+                       pri->mbox[i].sub = ast_mwi_unsubscribe(pri->mbox[i].sub);
                }
        }
 #endif /* defined(HAVE_PRI_MWI) */
@@ -9108,7 +9108,6 @@ int sig_pri_start_pri(struct sig_pri_span *pri)
        saveptr = pri->mwi_mailboxes;
        for (i = 0; i < ARRAY_LEN(pri->mbox); ++i) {
                char *mbox_id;
-               struct stasis_topic *mailbox_specific_topic;
 
                mbox_id = strsep(&saveptr, ",");
                if (mbox_id) {
@@ -9127,16 +9126,10 @@ int sig_pri_start_pri(struct sig_pri_span *pri)
                        continue;
                }
 
-               mailbox_specific_topic = ast_mwi_topic(mbox_id);
-               if (mailbox_specific_topic) {
-                       pri->mbox[i].sub = stasis_subscribe_pool(mailbox_specific_topic, sig_pri_mwi_event_cb, pri);
-               }
+               pri->mbox[i].sub = ast_mwi_subscribe_pool(mbox_id, sig_pri_mwi_event_cb, pri);
                if (!pri->mbox[i].sub) {
                        ast_log(LOG_ERROR, "%s span %d could not subscribe to MWI events for %s(%s).\n",
                                sig_pri_cc_type_name, pri->span, pri->mbox[i].vm_box, mbox_id);
-               } else {
-                       stasis_subscription_accept_message_type(pri->mbox[i].sub, ast_mwi_state_type());
-                       stasis_subscription_set_filter(pri->mbox[i].sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
                }
 #if defined(HAVE_PRI_MWI_V2)
                if (ast_strlen_zero(pri->mbox[i].vm_number)) {
index 8c9babd4ec7b53c6857a3ca5302d9c47e41bafc4..497e834c443dc93c18b43769a3a5b41abdb551c4 100644 (file)
@@ -424,7 +424,7 @@ struct sig_pri_mbox {
         * \brief MWI mailbox event subscription.
         * \note NULL if mailbox not configured.
         */
-       struct stasis_subscription *sub;
+       struct ast_mwi_subscriber *sub;
        /*! \brief Mailbox uniqueid. */
        const char *uniqueid;
        /*! \brief Mailbox number sent to span. */
index 86f8967c402c8bb72c3541e1e6332529d817e319..4ee204134a9d29d6a0188b6f2395e53e79eca2fc 100644 (file)
@@ -1252,7 +1252,7 @@ enum sip_mailbox_status {
  */
 struct sip_mailbox {
        /*! Associated MWI subscription */
-       struct stasis_subscription *event_sub;
+       struct ast_mwi_subscriber *event_sub;
        AST_LIST_ENTRY(sip_mailbox) entry;
        struct sip_peer *peer;
        enum sip_mailbox_status status;
index abd7ac0a50f6bf88eeafd0e2596daf1ea8a52041..2ea5f89dd17050cf513e90708836a412d8bc5fb2 100644 (file)
@@ -90,7 +90,7 @@ static struct ast_sip_subscription_handler mwi_handler = {
  */
 struct mwi_stasis_subscription {
        /*! The MWI stasis subscription */
-       struct stasis_subscription *stasis_sub;
+       struct ast_mwi_subscriber *mwi_subscriber;
        /*! The mailbox corresponding with the MWI subscription. Used as a hash key */
        char mailbox[1];
 };
@@ -243,7 +243,6 @@ static void mwi_stasis_cb(void *userdata, struct stasis_subscription *sub,
 static struct mwi_stasis_subscription *mwi_stasis_subscription_alloc(const char *mailbox, struct mwi_subscription *mwi_sub)
 {
        struct mwi_stasis_subscription *mwi_stasis_sub;
-       struct stasis_topic *topic;
 
        if (!mwi_sub) {
                return NULL;
@@ -254,26 +253,22 @@ static struct mwi_stasis_subscription *mwi_stasis_subscription_alloc(const char
                return NULL;
        }
 
-       topic = ast_mwi_topic(mailbox);
-
        /* Safe strcpy */
        strcpy(mwi_stasis_sub->mailbox, mailbox);
 
-       ast_debug(3, "Creating stasis MWI subscription to mailbox %s for endpoint %s.  Topic: '%s':%p %d\n",
-               mailbox, mwi_sub->id, stasis_topic_name(topic), topic, (int)ao2_ref(topic, 0));
        ao2_ref(mwi_sub, +1);
-       mwi_stasis_sub->stasis_sub = stasis_subscribe_pool(topic, mwi_stasis_cb, mwi_sub);
-       ao2_ref(topic, -1);
-
-       if (!mwi_stasis_sub->stasis_sub) {
+       mwi_stasis_sub->mwi_subscriber = ast_mwi_subscribe_pool(mailbox, mwi_stasis_cb, mwi_sub);
+       if (!mwi_stasis_sub->mwi_subscriber) {
                /* Failed to subscribe. */
                ao2_ref(mwi_stasis_sub, -1);
                ao2_ref(mwi_sub, -1);
-               mwi_stasis_sub = NULL;
+               return NULL;
        }
-       stasis_subscription_accept_message_type(mwi_stasis_sub->stasis_sub, ast_mwi_state_type());
-       stasis_subscription_accept_message_type(mwi_stasis_sub->stasis_sub, stasis_subscription_change_type());
-       stasis_subscription_set_filter(mwi_stasis_sub->stasis_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
+
+       stasis_subscription_accept_message_type(
+               ast_mwi_subscriber_subscription(mwi_stasis_sub->mwi_subscriber),
+               stasis_subscription_change_type());
+
        return mwi_stasis_sub;
 }
 
@@ -433,21 +428,19 @@ static int mwi_sub_cmp(void *obj, void *arg, int flags)
 
 static int get_message_count(void *obj, void *arg, int flags)
 {
-       struct stasis_message *msg;
        struct mwi_stasis_subscription *mwi_stasis = obj;
        struct ast_sip_message_accumulator *counter = arg;
        struct ast_mwi_state *mwi_state;
 
-       msg = stasis_cache_get(ast_mwi_state_cache(), ast_mwi_state_type(), mwi_stasis->mailbox);
-       if (!msg) {
+       mwi_state = ast_mwi_subscriber_data(mwi_stasis->mwi_subscriber);
+       if (!mwi_state) {
                return 0;
        }
 
-       mwi_state = stasis_message_data(msg);
        counter->old_msgs += mwi_state->old_msgs;
        counter->new_msgs += mwi_state->new_msgs;
 
-       ao2_ref(msg, -1);
+       ao2_ref(mwi_state, -1);
 
        return 0;
 }
@@ -683,10 +676,11 @@ static void send_mwi_notify(struct mwi_subscription *sub)
 static int unsubscribe_stasis(void *obj, void *arg, int flags)
 {
        struct mwi_stasis_subscription *mwi_stasis = obj;
-       if (mwi_stasis->stasis_sub) {
+       if (mwi_stasis->mwi_subscriber) {
                ast_debug(3, "Removing stasis subscription to mailbox %s\n", mwi_stasis->mailbox);
-               mwi_stasis->stasis_sub = stasis_unsubscribe_and_join(mwi_stasis->stasis_sub);
+               mwi_stasis->mwi_subscriber = ast_mwi_unsubscribe_and_join(mwi_stasis->mwi_subscriber);
        }
+
        return CMP_MATCH;
 }