summaryrefslogtreecommitdiff
path: root/channels
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2013-03-16 15:45:58 +0000
committerKinsey Moore <kmoore@digium.com>2013-03-16 15:45:58 +0000
commit99aa02d17f7f1815f9a2abf75282f815a975cd67 (patch)
tree5ebb9cf3ddecd7153afb9e30f767d170c44b2142 /channels
parent5d45596f6257b86189bef2dfaf5d9cc0b001fa46 (diff)
Transition MWI to Stasis-core
Remove MWI's dependency on the event system by moving it to Stasis-core. This also introduces forwarding topic pools in Stasis-core which aggregate many dynamically allocated topics into a single primary topic. Review: https://reviewboard.asterisk.org/r/2368/ (closes issue ASTERISK-21097) Patch-by: Kinsey Moore git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@383284 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_dahdi.c63
-rw-r--r--channels/chan_iax2.c53
-rw-r--r--channels/chan_mgcp.c47
-rw-r--r--channels/chan_sip.c71
-rw-r--r--channels/chan_skinny.c38
-rw-r--r--channels/chan_unistim.c17
-rw-r--r--channels/sig_pri.c56
-rw-r--r--channels/sig_pri.h2
-rw-r--r--channels/sip/include/sip.h2
9 files changed, 199 insertions, 150 deletions
diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index e077e8422..15075ebf2 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -502,7 +502,7 @@ static enum ast_bridge_result dahdi_bridge(struct ast_channel *c0, struct ast_ch
static int dahdi_sendtext(struct ast_channel *c, const char *text);
-static void mwi_event_cb(const struct ast_event *event, void *userdata)
+static void mwi_event_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
{
/* 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
@@ -1215,7 +1215,7 @@ struct dahdi_pvt {
*/
char mailbox[AST_MAX_EXTENSION];
/*! \brief Opaque event subscription parameters for message waiting indication support. */
- struct ast_event_sub *mwi_event_sub;
+ struct stasis_subscription *mwi_event_sub;
/*! \brief Delayed dialing for E911. Overlap digits for ISDN. */
char dialdest[256];
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI
@@ -3753,7 +3753,6 @@ struct sig_ss7_callback sig_ss7_callbacks =
static void notify_message(char *mailbox_full, int thereornot)
{
char s[sizeof(mwimonitornotify) + 80];
- struct ast_event *event;
char *mailbox, *context;
/* Strip off @default */
@@ -3762,16 +3761,7 @@ static void notify_message(char *mailbox_full, int thereornot)
if (ast_strlen_zero(context))
context = "default";
- if (!(event = ast_event_new(AST_EVENT_MWI,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
- AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, thereornot,
- AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, thereornot,
- AST_EVENT_IE_END))) {
- return;
- }
-
- ast_event_queue_and_cache(event);
+ stasis_publish_mwi_state(mailbox, context, thereornot, thereornot);
if (!ast_strlen_zero(mailbox) && !ast_strlen_zero(mwimonitornotify)) {
snprintf(s, sizeof(s), "%s %s %d", mwimonitornotify, mailbox, thereornot);
@@ -5413,24 +5403,25 @@ static int send_cwcidspill(struct dahdi_pvt *p)
static int has_voicemail(struct dahdi_pvt *p)
{
int new_msgs;
- struct ast_event *event;
char *mailbox, *context;
+ RAII_VAR(struct stasis_message *, mwi_message, NULL, ao2_cleanup);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
mailbox = context = ast_strdupa(p->mailbox);
strsep(&context, "@");
- if (ast_strlen_zero(context))
+ if (ast_strlen_zero(context)) {
context = "default";
+ }
- event = ast_event_get_cached(AST_EVENT_MWI,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
- AST_EVENT_IE_END);
+ ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
+ mwi_message = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_message(), ast_str_buffer(uniqueid));
- if (event) {
- new_msgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
- ast_event_destroy(event);
- } else
+ if (mwi_message) {
+ struct stasis_mwi_state *mwi_state = stasis_message_data(mwi_message);
+ new_msgs = mwi_state->new_msgs;
+ } else {
new_msgs = ast_app_has_voicemail(p->mailbox, NULL);
+ }
return new_msgs;
}
@@ -5965,10 +5956,12 @@ static void destroy_dahdi_pvt(struct dahdi_pvt *pvt)
}
}
ast_free(p->cidspill);
- if (p->use_smdi)
+ if (p->use_smdi) {
ast_smdi_interface_unref(p->smdi_iface);
- if (p->mwi_event_sub)
- ast_event_unsubscribe(p->mwi_event_sub);
+ }
+ if (p->mwi_event_sub) {
+ p->mwi_event_sub = stasis_unsubscribe(p->mwi_event_sub);
+ }
if (p->vars) {
ast_variables_destroy(p->vars);
}
@@ -5981,8 +5974,9 @@ static void destroy_dahdi_pvt(struct dahdi_pvt *pvt)
ast_mutex_destroy(&p->lock);
dahdi_close_sub(p, SUB_REAL);
- if (p->owner)
+ if (p->owner) {
ast_channel_tech_pvt_set(p->owner, NULL);
+ }
ast_free(p);
}
@@ -13226,15 +13220,20 @@ static struct dahdi_pvt *mkintf(int channel, const struct dahdi_chan_conf *conf,
ast_copy_string(tmp->mailbox, conf->chan.mailbox, sizeof(tmp->mailbox));
if (channel != CHAN_PSEUDO && !ast_strlen_zero(tmp->mailbox)) {
char *mailbox, *context;
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
+ struct stasis_topic *mailbox_specific_topic;
+
mailbox = context = ast_strdupa(tmp->mailbox);
strsep(&context, "@");
if (ast_strlen_zero(context))
context = "default";
- tmp->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, "Dahdi MWI subscription", NULL,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
- AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
- AST_EVENT_IE_END);
+
+ ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
+
+ mailbox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+ if (mailbox_specific_topic) {
+ tmp->mwi_event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, NULL);
+ }
}
#ifdef HAVE_DAHDI_LINEREVERSE_VMWI
tmp->mwisend_setting = conf->chan.mwisend_setting;
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 5a307bf0c..7280c480e 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -533,7 +533,7 @@ struct iax2_peer {
int expire; /*!< Schedule entry for expiry */
int expiry; /*!< How soon to expire */
- iax2_format capability; /*!< Capability */
+ iax2_format capability; /*!< Capability */
/* Qualification */
int callno; /*!< Call number of POKE request */
@@ -545,12 +545,12 @@ struct iax2_peer {
int pokefreqnotok; /*!< How often to check when the host has been determined to be down */
int historicms; /*!< How long recent average responses took */
int smoothing; /*!< Sample over how many units to determine historic ms */
- uint16_t maxcallno; /*!< Max call number limit for this peer. Set on registration */
+ uint16_t maxcallno; /*!< Max call number limit for this peer. Set on registration */
- struct ast_event_sub *mwi_event_sub;
+ struct stasis_subscription *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 */
+ enum calltoken_peer_enum calltoken_required; /*!< Is calltoken validation required or not, can be YES, NO, or AUTO */
};
#define IAX2_TRUNK_PREFACE (sizeof(struct iax_frame) + sizeof(struct ast_iax2_meta_hdr) + sizeof(struct ast_iax2_meta_trunk_hdr))
@@ -1316,7 +1316,7 @@ static void iax2_lock_owner(int callno)
}
}
-static void mwi_event_cb(const struct ast_event *event, void *userdata)
+static void mwi_event_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
{
/* 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
@@ -8743,23 +8743,24 @@ static int update_registry(struct sockaddr_in *sin, int callno, char *devtype, i
iax_ie_append_short(&ied, IAX_IE_REFRESH, p->expiry);
iax_ie_append_addr(&ied, IAX_IE_APPARENT_ADDR, &peer_addr);
if (!ast_strlen_zero(p->mailbox)) {
- struct ast_event *event;
int new, old;
char *mailbox, *context;
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
context = mailbox = ast_strdupa(p->mailbox);
strsep(&context, "@");
- if (ast_strlen_zero(context))
+ if (ast_strlen_zero(context)) {
context = "default";
+ }
+
+ ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
+ msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_message(), ast_str_buffer(uniqueid));
- event = ast_event_get_cached(AST_EVENT_MWI,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
- AST_EVENT_IE_END);
- if (event) {
- new = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
- old = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS);
- ast_event_destroy(event);
+ if (msg) {
+ struct stasis_mwi_state *mwi_state = stasis_message_data(msg);
+ new = mwi_state->new_msgs;
+ old = mwi_state->old_msgs;
} else { /* Fall back on checking the mailbox directly */
ast_app_inboxcount(p->mailbox, &new, &old);
}
@@ -12392,8 +12393,9 @@ static void peer_destructor(void *obj)
if (peer->dnsmgr)
ast_dnsmgr_release(peer->dnsmgr);
- if (peer->mwi_event_sub)
- ast_event_unsubscribe(peer->mwi_event_sub);
+ if (peer->mwi_event_sub) {
+ peer->mwi_event_sub = stasis_unsubscribe(peer->mwi_event_sub);
+ }
ast_string_field_free_memory(peer);
}
@@ -12667,14 +12669,21 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
if (!ast_strlen_zero(peer->mailbox)) {
char *mailbox, *context;
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
+ struct stasis_topic *mailbox_specific_topic;
+
context = mailbox = ast_strdupa(peer->mailbox);
strsep(&context, "@");
- if (ast_strlen_zero(context))
+ if (ast_strlen_zero(context)) {
context = "default";
- peer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, "IAX MWI subscription", NULL,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
- AST_EVENT_IE_END);
+ }
+
+ ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
+
+ mailbox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+ if (mailbox_specific_topic) {
+ peer->mwi_event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, NULL);
+ }
}
if (subscribe_acl_change) {
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index 0c3dac607..65a53900e 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -82,6 +82,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/event.h"
#include "asterisk/chanvars.h"
#include "asterisk/pktccops.h"
+#include "asterisk/stasis.h"
/*
* Define to work around buggy dlink MGCP phone firmware which
@@ -342,7 +343,7 @@ struct mgcp_endpoint {
char curtone[80]; /*!< Current tone */
char mailbox[AST_MAX_EXTENSION];
char parkinglot[AST_MAX_CONTEXT]; /*!< Parkinglot */
- struct ast_event_sub *mwi_event_sub;
+ struct stasis_subscription *mwi_event_sub;
ast_group_t callgroup;
ast_group_t pickupgroup;
int callwaiting;
@@ -483,7 +484,7 @@ static struct ast_channel_tech mgcp_tech = {
.func_channel_read = acf_channel_read,
};
-static void mwi_event_cb(const struct ast_event *event, void *userdata)
+static void mwi_event_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
{
/* 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
@@ -494,24 +495,26 @@ static void mwi_event_cb(const struct ast_event *event, void *userdata)
static int has_voicemail(struct mgcp_endpoint *p)
{
int new_msgs;
- struct ast_event *event;
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
char *mbox, *cntx;
cntx = mbox = ast_strdupa(p->mailbox);
strsep(&cntx, "@");
- if (ast_strlen_zero(cntx))
+ if (ast_strlen_zero(cntx)) {
cntx = "default";
+ }
- event = ast_event_get_cached(AST_EVENT_MWI,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, cntx,
- AST_EVENT_IE_END);
+ ast_str_set(&uniqueid, 0, "%s@%s", mbox, cntx);
- if (event) {
- new_msgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
- ast_event_destroy(event);
- } else
+ msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state(), ast_str_buffer(uniqueid));
+
+ if (msg) {
+ struct stasis_mwi_state *mwi_state = stasis_message_data(msg);
+ new_msgs = mwi_state->new_msgs;
+ } else {
new_msgs = ast_app_has_voicemail(p->mailbox, NULL);
+ }
return new_msgs;
}
@@ -3972,6 +3975,7 @@ static struct mgcp_gateway *build_gateway(char *cat, struct ast_variable *v)
struct mgcp_endpoint *e;
struct mgcp_subchannel *sub;
struct ast_variable *chanvars = NULL;
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
/*char txident[80];*/
int i=0, y=0;
@@ -4168,16 +4172,20 @@ static struct mgcp_gateway *build_gateway(char *cat, struct ast_variable *v)
ast_copy_string(e->parkinglot, parkinglot, sizeof(e->parkinglot));
if (!ast_strlen_zero(e->mailbox)) {
char *mbox, *cntx;
+ struct stasis_topic *mailbox_specific_topic;
+
cntx = mbox = ast_strdupa(e->mailbox);
strsep(&cntx, "@");
if (ast_strlen_zero(cntx)) {
cntx = "default";
}
- e->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, "MGCP MWI subscription", NULL,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, cntx,
- AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
- AST_EVENT_IE_END);
+ ast_str_reset(uniqueid);
+ ast_str_set(&uniqueid, 0, "%s@%s", mbox, cntx);
+
+ maibox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+ if (mailbox_specific_topic) {
+ e->mwi_event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, NULL);
+ }
}
snprintf(e->rqnt_ident, sizeof(e->rqnt_ident), "%08lx", ast_random());
e->msgstate = -1;
@@ -4516,8 +4524,9 @@ static void destroy_endpoint(struct mgcp_endpoint *e)
ast_free(s);
}
- if (e->mwi_event_sub)
- ast_event_unsubscribe(e->mwi_event_sub);
+ if (e->mwi_event_sub) {
+ e->mwi_event_sub = stasis_unsubscribe(e->mwi_event_sub);
+ }
if (e->chanvars) {
ast_variables_destroy(e->chanvars);
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 631c1db5d..28e8d4d35 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -294,6 +294,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "sip/include/dialplan_functions.h"
#include "sip/include/security_events.h"
#include "asterisk/sip_api.h"
+#include "asterisk/app.h"
/*** DOCUMENTATION
<application name="SIPDtmfMode" language="en_US">
@@ -1275,7 +1276,7 @@ static int sip_poke_noanswer(const void *data);
static int sip_poke_peer(struct sip_peer *peer, int force);
static void sip_poke_all_peers(void);
static void sip_peer_hold(struct sip_pvt *p, int hold);
-static void mwi_event_cb(const struct ast_event *, void *);
+static void mwi_event_cb(void *, struct stasis_subscription *, struct stasis_topic *, struct stasis_message *);
static void network_change_event_cb(const struct ast_event *, void *);
static void acl_change_event_cb(const struct ast_event *event, void *userdata);
static void sip_keepalive_all_peers(void);
@@ -5225,8 +5226,9 @@ static void register_peer_exten(struct sip_peer *peer, int onoff)
/*! Destroy mailbox subscriptions */
static void destroy_mailbox(struct sip_mailbox *mailbox)
{
- if (mailbox->event_sub)
- ast_event_unsubscribe(mailbox->event_sub);
+ if (mailbox->event_sub) {
+ mailbox->event_sub = stasis_unsubscribe(mailbox->event_sub);
+ }
ast_free(mailbox);
}
@@ -16644,11 +16646,16 @@ static void sip_peer_hold(struct sip_pvt *p, int hold)
}
/*! \brief Receive MWI events that we have subscribed to */
-static void mwi_event_cb(const struct ast_event *event, void *userdata)
+static void mwi_event_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
{
struct sip_peer *peer = userdata;
-
- sip_send_mwi_to_peer(peer, 0);
+ if (stasis_subscription_final_message(sub, msg)) {
+ ao2_cleanup(peer);
+ return;
+ }
+ if (stasis_mwi_state_message() == stasis_message_type(msg)) {
+ sip_send_mwi_to_peer(peer, 0);
+ }
}
static void network_change_event_subscribe(void)
@@ -24787,16 +24794,9 @@ static int handle_request_notify(struct sip_pvt *p, struct sip_request *req, str
if (!ast_strlen_zero(mailbox) && !ast_strlen_zero(c)) {
char *old = strsep(&c, " ");
char *new = strsep(&old, "/");
- struct ast_event *event;
- if ((event = ast_event_new(AST_EVENT_MWI,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, "SIP_Remote",
- AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, atoi(new),
- AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, atoi(old),
- AST_EVENT_IE_END))) {
- ast_event_queue_and_cache(event);
- }
+ stasis_publish_mwi_state(mailbox, "SIP_Remote", atoi(new), atoi(old));
+
transmit_response(p, "200 OK", req);
} else {
transmit_response(p, "489 Bad event", req);
@@ -27617,16 +27617,20 @@ static int handle_request_publish(struct sip_pvt *p, struct sip_request *req, st
static void add_peer_mwi_subs(struct sip_peer *peer)
{
struct sip_mailbox *mailbox;
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
- if (mailbox->event_sub) {
- ast_event_unsubscribe(mailbox->event_sub);
- }
+ struct stasis_topic *mailbox_specific_topic;
+ mailbox->event_sub = stasis_unsubscribe(mailbox->event_sub);
+
+ ast_str_reset(uniqueid);
+ ast_str_set(&uniqueid, 0, "%s@%s", mailbox->mailbox, S_OR(mailbox->context, "default"));
- mailbox->event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, "SIP mbox event", peer,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox->mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, S_OR(mailbox->context, "default"),
- AST_EVENT_IE_END);
+ mailbox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+ if (mailbox_specific_topic) {
+ ao2_ref(peer, +1);
+ mailbox->event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, peer);
+ }
}
}
@@ -28832,19 +28836,24 @@ static int get_cached_mwi(struct sip_peer *peer, int *new, int *old)
{
struct sip_mailbox *mailbox;
int in_cache;
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
in_cache = 0;
AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
- struct ast_event *event;
- event = ast_event_get_cached(AST_EVENT_MWI,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox->mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, S_OR(mailbox->context, "default"),
- AST_EVENT_IE_END);
- if (!event)
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+ struct stasis_mwi_state *mwi_state;
+
+ ast_str_reset(uniqueid);
+ ast_str_set(&uniqueid, 0, "%s@%s", mailbox->mailbox, S_OR(mailbox->context, "default"));
+
+ msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_message(), ast_str_buffer(uniqueid));
+ if (!msg) {
continue;
- *new += ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
- *old += ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS);
- ast_event_destroy(event);
+ }
+
+ mwi_state = stasis_message_data(msg);
+ *new += mwi_state->new_msgs;
+ *old += mwi_state->old_msgs;
in_cache = 1;
}
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index c974caee8..6045a09f0 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -1442,7 +1442,7 @@ struct skinny_line {
SKINNY_LINE_OPTIONS
ast_mutex_t lock;
struct skinny_container *container;
- struct ast_event_sub *mwi_event_sub; /* Event based MWI */
+ struct stasis_subscription *mwi_event_sub; /* Event based MWI */
struct skinny_subchannel *activesub;
AST_LIST_HEAD(, skinny_subchannel) sub;
AST_LIST_HEAD(, skinny_subline) sublines;
@@ -1611,7 +1611,7 @@ static int skinny_indicate(struct ast_channel *ast, int ind, const void *data, s
static int skinny_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
static int skinny_senddigit_begin(struct ast_channel *ast, char digit);
static int skinny_senddigit_end(struct ast_channel *ast, char digit, unsigned int duration);
-static void mwi_event_cb(const struct ast_event *event, void *userdata);
+static void mwi_event_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg);
static int skinny_dialer_cb(const void *data);
static int skinny_reload(void);
@@ -2261,7 +2261,7 @@ static int skinny_register(struct skinny_req *req, struct skinnysession *s)
manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: Skinny\r\nPeer: Skinny/%s@%s\r\nPeerStatus: Registered\r\n", l->name, d->name);
register_exten(l);
/* initialize MWI on line and device */
- mwi_event_cb(0, l);
+ mwi_event_cb(l, NULL, NULL, NULL);
AST_LIST_TRAVERSE(&l->sublines, subline, list) {
ast_extension_state_add(subline->context, subline->exten, skinny_extensionstate_cb, subline->container);
}
@@ -3507,7 +3507,7 @@ static void update_connectedline(struct skinny_subchannel *sub, const void *data
send_callinfo(sub);
}
-static void mwi_event_cb(const struct ast_event *event, void *userdata)
+static void mwi_event_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
{
struct skinny_line *l = userdata;
struct skinny_device *d = l->device;
@@ -3518,8 +3518,9 @@ static void mwi_event_cb(const struct ast_event *event, void *userdata)
return;
}
- if (event) {
- l->newmsgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
+ if (msg && stasis_mwi_state_message() == stasis_message_type(msg)) {
+ struct stasis_mwi_state *mwi_state = stasis_message_data(msg);
+ l->newmsgs = mwi_state->new_msgs;
}
if (l->newmsgs) {
@@ -8250,16 +8251,22 @@ static struct skinny_line *config_line(const char *lname, struct ast_variable *v
if (!ast_strlen_zero(l->mailbox)) {
char *cfg_mailbox, *cfg_context;
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
+ struct stasis_topic *mailbox_specific_topic;
+
cfg_context = cfg_mailbox = ast_strdupa(l->mailbox);
ast_verb(3, "Setting mailbox '%s' on line %s\n", cfg_mailbox, l->name);
strsep(&cfg_context, "@");
- if (ast_strlen_zero(cfg_context))
- cfg_context = "default";
- l->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, "skinny MWI subsciption", l,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, cfg_mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, cfg_context,
- AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
- AST_EVENT_IE_END);
+ if (ast_strlen_zero(cfg_context)) {
+ cfg_context = "default";
+ }
+
+ ast_str_set(&uniqueid, 0, "%s@%s", cfg_mailbox, cfg_context);
+
+ mailbox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+ if (mailbox_specific_topic) {
+ l->mwi_event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, l);
+ }
}
if (!ast_strlen_zero(vmexten) && ast_strlen_zero(l->vmexten)) {
@@ -8694,8 +8701,9 @@ static int unload_module(void)
}
ast_mutex_unlock(&sub->lock);
}
- if (l->mwi_event_sub)
- ast_event_unsubscribe(l->mwi_event_sub);
+ if (l->mwi_event_sub) {
+ l->mwi_event_sub = stasis_unsubscribe(l->mwi_event_sub);
+ }
ast_mutex_unlock(&l->lock);
manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: Skinny\r\nPeer: Skinny/%s@%s\r\nPeerStatus: Unregistered\r\n", l->name, d->name);
unregister_exten(l);
diff --git a/channels/chan_unistim.c b/channels/chan_unistim.c
index b4ec9e455..130549c01 100644
--- a/channels/chan_unistim.c
+++ b/channels/chan_unistim.c
@@ -5500,23 +5500,24 @@ static int unistim_sendtext(struct ast_channel *ast, const char *text)
/*--- unistim_send_mwi_to_peer: Send message waiting indication ---*/
static int unistim_send_mwi_to_peer(struct unistim_line *peer, unsigned int tick)
{
- struct ast_event *event;
int new;
char *mailbox, *context;
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
context = mailbox = ast_strdupa(peer->mailbox);
strsep(&context, "@");
if (ast_strlen_zero(context)) {
context = "default";
}
- event = ast_event_get_cached(AST_EVENT_MWI,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
- AST_EVENT_IE_END);
- if (event) {
- new = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
- ast_event_destroy(event);
+ ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
+
+ msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_message(), ast_str_buffer(uniqueid));
+
+ if (msg) {
+ struct stasis_mwi_state *mwi_state = stasis_message_data(msg);
+ new = mwi_state->new_msgs;
} else { /* Fall back on checking the mailbox directly */
new = ast_app_has_voicemail(peer->mailbox, "INBOX");
}
diff --git a/channels/sig_pri.c b/channels/sig_pri.c
index e01ceadd3..e3b9b3fb6 100644
--- a/channels/sig_pri.c
+++ b/channels/sig_pri.c
@@ -8752,23 +8752,30 @@ static void sig_pri_send_mwi_indication(struct sig_pri_span *pri, const char *vm
*
* \return Nothing
*/
-static void sig_pri_mwi_event_cb(const struct ast_event *event, void *userdata)
+static void sig_pri_mwi_event_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
{
struct sig_pri_span *pri = userdata;
const char *mbox_context;
const char *mbox_number;
int num_messages;
int idx;
+ struct stasis_mwi_state *mwi_state;
- mbox_number = ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX);
+ if (stasis_mwi_state_message() != stasis_message_type(msg)) {
+ return;
+ }
+
+ mwi_state = stasis_message_data(msg);
+
+ mbox_number = mwi_state->mailbox;
if (ast_strlen_zero(mbox_number)) {
return;
}
- mbox_context = ast_event_get_ie_str(event, AST_EVENT_IE_CONTEXT);
+ mbox_context = mwi_state->context;
if (ast_strlen_zero(mbox_context)) {
return;
}
- num_messages = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
+ num_messages = mwi_state->new_msgs;
for (idx = 0; idx < ARRAY_LEN(pri->mbox); ++idx) {
if (!pri->mbox[idx].sub) {
@@ -8799,27 +8806,28 @@ static void sig_pri_mwi_event_cb(const struct ast_event *event, void *userdata)
static void sig_pri_mwi_cache_update(struct sig_pri_span *pri)
{
int idx;
- int num_messages;
- struct ast_event *event;
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
+ struct stasis_mwi_state *mwi_state;
for (idx = 0; idx < ARRAY_LEN(pri->mbox); ++idx) {
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
if (!pri->mbox[idx].sub) {
/* Mailbox slot is empty */
continue;
}
- event = ast_event_get_cached(AST_EVENT_MWI,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, pri->mbox[idx].number,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, pri->mbox[idx].context,
- AST_EVENT_IE_END);
- if (!event) {
+ ast_str_reset(uniqueid);
+ ast_str_set(&uniqueid, 0, "%s@%s", pri->mbox[idx].number, pri->mbox[idx].context);
+
+ msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_message(), ast_str_buffer(uniqueid));
+ if (!msg) {
/* No cached event for this mailbox. */
continue;
}
- num_messages = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
+
+ mwi_state = stasis_message_data(msg);
sig_pri_send_mwi_indication(pri, pri->mbox[idx].vm_number, pri->mbox[idx].number,
- pri->mbox[idx].context, num_messages);
- ast_event_destroy(event);
+ pri->mbox[idx].context, mwi_state->new_msgs);
}
}
#endif /* defined(HAVE_PRI_MWI) */
@@ -8841,7 +8849,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 = ast_event_unsubscribe(pri->mbox[idx].sub);
+ pri->mbox[idx].sub = stasis_unsubscribe(pri->mbox[idx].sub);
}
}
#endif /* defined(HAVE_PRI_MWI) */
@@ -8905,13 +8913,14 @@ int sig_pri_start_pri(struct sig_pri_span *pri)
char *saveptr;
char *prev_vm_number;
struct ast_str *mwi_description = ast_str_alloca(64);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
#endif /* defined(HAVE_PRI_MWI) */
#if defined(HAVE_PRI_MWI)
/* Prepare the mbox[] for use. */
for (i = 0; i < ARRAY_LEN(pri->mbox); ++i) {
if (pri->mbox[i].sub) {
- pri->mbox[i].sub = ast_event_unsubscribe(pri->mbox[i].sub);
+ pri->mbox[i].sub = stasis_unsubscribe(pri->mbox[i].sub);
}
}
#endif /* defined(HAVE_PRI_MWI) */
@@ -8951,6 +8960,7 @@ int sig_pri_start_pri(struct sig_pri_span *pri)
for (i = 0; i < ARRAY_LEN(pri->mbox); ++i) {
char *mbox_number;
char *mbox_context;
+ struct stasis_topic *mailbox_specific_topic;
mbox_number = strsep(&saveptr, ",");
if (!mbox_number) {
@@ -8976,13 +8986,17 @@ int sig_pri_start_pri(struct sig_pri_span *pri)
/* Fill the mbox[] element. */
pri->mbox[i].number = mbox_number;
pri->mbox[i].context = mbox_context;
+
+ ast_str_reset(uniqueid);
+ ast_str_set(&uniqueid, 0, "%s@%s", mbox_number, mbox_context);
+
ast_str_set(&mwi_description, -1, "%s span %d[%d] MWI mailbox %s@%s",
sig_pri_cc_type_name, pri->span, i, mbox_number, mbox_context);
- pri->mbox[i].sub = ast_event_subscribe(AST_EVENT_MWI, sig_pri_mwi_event_cb,
- ast_str_buffer(mwi_description), pri,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mbox_number,
- AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, mbox_context,
- AST_EVENT_IE_END);
+
+ mailbox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+ if (mailbox_specific_topic) {
+ pri->mbox[i].sub = stasis_subscribe(mailbox_specific_topic, 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.",
sig_pri_cc_type_name, pri->span, mbox_number, mbox_context);
diff --git a/channels/sig_pri.h b/channels/sig_pri.h
index 4de9077e7..db052862d 100644
--- a/channels/sig_pri.h
+++ b/channels/sig_pri.h
@@ -405,7 +405,7 @@ struct sig_pri_mbox {
* \brief MWI mailbox event subscription.
* \note NULL if mailbox not configured.
*/
- struct ast_event_sub *sub;
+ struct stasis_subscription *sub;
/*! \brief Mailbox number */
const char *number;
/*! \brief Mailbox context. */
diff --git a/channels/sip/include/sip.h b/channels/sip/include/sip.h
index e5177bd6a..6eb2f29a5 100644
--- a/channels/sip/include/sip.h
+++ b/channels/sip/include/sip.h
@@ -1262,7 +1262,7 @@ struct sip_pkt {
*/
struct sip_mailbox {
/*! Associated MWI subscription */
- struct ast_event_sub *event_sub;
+ struct stasis_subscription *event_sub;
AST_LIST_ENTRY(sip_mailbox) entry;
unsigned int delme:1;
char *context;