diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index 434bd16a82..a721d7b17f 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -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; diff --git a/channels/chan_dahdi.h b/channels/chan_dahdi.h index 212a0bf380..d84be510bd 100644 --- a/channels/chan_dahdi.h +++ b/channels/chan_dahdi.h @@ -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 diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index a7b2f269f3..30f949624e 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -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) { diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index fa3a081469..2c8c5253bf 100644 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -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) { diff --git a/channels/chan_sip.c b/channels/chan_sip.c index cd0db387af..eef0d417a2 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -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()); } } } diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c index fb31c9ffd0..17bc0390dc 100644 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -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); diff --git a/channels/sig_pri.c b/channels/sig_pri.c index 102e3c4fc1..a8c042f771 100644 --- a/channels/sig_pri.c +++ b/channels/sig_pri.c @@ -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)) { diff --git a/channels/sig_pri.h b/channels/sig_pri.h index 8c9babd4ec..497e834c44 100644 --- a/channels/sig_pri.h +++ b/channels/sig_pri.h @@ -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. */ diff --git a/channels/sip/include/sip.h b/channels/sip/include/sip.h index 86f8967c40..4ee204134a 100644 --- a/channels/sip/include/sip.h +++ b/channels/sip/include/sip.h @@ -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; diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c index abd7ac0a50..2ea5f89dd1 100644 --- a/res/res_pjsip_mwi.c +++ b/res/res_pjsip_mwi.c @@ -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; }