[asterisk-commits] kmoore: branch kmoore/stasis-mwi r382466 - in /team/kmoore/stasis-mwi: apps/ ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Mar 5 12:47:22 CST 2013
Author: kmoore
Date: Tue Mar 5 12:47:17 2013
New Revision: 382466
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382466
Log:
Address mmichelson's comments and use new callback
Modified:
team/kmoore/stasis-mwi/apps/app_minivm.c
team/kmoore/stasis-mwi/apps/app_voicemail.c
team/kmoore/stasis-mwi/channels/chan_dahdi.c
team/kmoore/stasis-mwi/channels/chan_iax2.c
team/kmoore/stasis-mwi/channels/chan_mgcp.c
team/kmoore/stasis-mwi/channels/chan_sip.c
team/kmoore/stasis-mwi/channels/chan_skinny.c
team/kmoore/stasis-mwi/channels/chan_unistim.c
team/kmoore/stasis-mwi/channels/sig_pri.c
team/kmoore/stasis-mwi/include/asterisk/app.h
team/kmoore/stasis-mwi/main/app.c
team/kmoore/stasis-mwi/main/manager.c
team/kmoore/stasis-mwi/res/res_jabber.c
team/kmoore/stasis-mwi/res/res_xmpp.c
Modified: team/kmoore/stasis-mwi/apps/app_minivm.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/apps/app_minivm.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/apps/app_minivm.c (original)
+++ team/kmoore/stasis-mwi/apps/app_minivm.c Tue Mar 5 12:47:17 2013
@@ -2014,16 +2014,14 @@
static void queue_mwi_event(const char *mbx, const char *ctx, int urgent, int new, int old)
{
char *mailbox, *context;
- struct ast_str *uniqueid = ast_str_alloca(128);
mailbox = ast_strdupa(mbx);
context = ast_strdupa(ctx);
if (ast_strlen_zero(context)) {
context = "default";
}
- ast_str_set(&uniqueid, 0, "%s@%s", mbx, ctx);
-
- stasis_publish_mwi_state(ast_str_buffer(uniqueid), mailbox, context, new + urgent, old);
+
+ stasis_publish_mwi_state(mailbox, context, new + urgent, old);
}
/*!\internal
Modified: team/kmoore/stasis-mwi/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/apps/app_voicemail.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/apps/app_voicemail.c (original)
+++ team/kmoore/stasis-mwi/apps/app_voicemail.c Tue Mar 5 12:47:17 2013
@@ -999,6 +999,14 @@
const char *uniqueid;
};
+static void mwi_sub_task_dtor(struct mwi_sub_task *mwist)
+{
+ ast_free((void *) mwist->mailbox);
+ ast_free((void *) mwist->context);
+ ast_free((void *) mwist->uniqueid);
+ ast_free(mwist);
+}
+
static struct ast_taskprocessor *mwi_subscription_tps;
static AST_RWLIST_HEAD_STATIC(mwi_subs, mwi_sub);
@@ -7728,7 +7736,7 @@
context = "default";
}
- stasis_publish_mwi_state(box, mailbox, context, new + urgent, old);
+ stasis_publish_mwi_state(mailbox, context, new + urgent, old);
}
/*!
@@ -12575,10 +12583,7 @@
AST_RWLIST_WRLOCK(&mwi_subs);
AST_RWLIST_INSERT_TAIL(&mwi_subs, mwi_sub, entry);
AST_RWLIST_UNLOCK(&mwi_subs);
- ast_free((void *) p->mailbox);
- ast_free((void *) p->context);
- ast_free((void *) p->uniqueid);
- ast_free(p);
+ mwi_sub_task_dtor(p);
poll_subscribed_mailbox(mwi_sub);
return 0;
}
@@ -12604,7 +12609,6 @@
char *mailbox;
if ((mwist = ast_calloc(1, (sizeof(*mwist)))) == NULL) {
- ast_log(LOG_ERROR, "could not allocate a mwi_sub_task\n");
return;
}
@@ -12615,11 +12619,11 @@
mwist->uniqueid = ast_strdup(change->uniqueid);
if (ast_taskprocessor_push(mwi_subscription_tps, handle_subscribe, mwist) < 0) {
- ast_free(mwist);
- }
-}
-
-static void mwi_event_cb(void *userdata, struct stasis_topic *topic, struct stasis_message *msg)
+ mwi_sub_task_dtor(mwist);
+ }
+}
+
+static void mwi_event_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
{
struct stasis_subscription_change *change;
/* Only looking for subscription change notices here */
@@ -12642,7 +12646,7 @@
static int dump_cache(void *obj, void *arg, int flags)
{
struct stasis_message *msg = obj;
- mwi_event_cb(NULL, NULL, msg);
+ mwi_event_cb(NULL, NULL, NULL, msg);
return 0;
}
Modified: team/kmoore/stasis-mwi/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/chan_dahdi.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/channels/chan_dahdi.c (original)
+++ team/kmoore/stasis-mwi/channels/chan_dahdi.c Tue Mar 5 12:47:17 2013
@@ -502,7 +502,7 @@
static int dahdi_sendtext(struct ast_channel *c, const char *text);
-static void mwi_event_cb(void *userdata, struct stasis_topic *topic, struct stasis_message *msg)
+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
@@ -3761,7 +3761,7 @@
if (ast_strlen_zero(context))
context = "default";
- stasis_publish_mwi_state(mailbox_full, mailbox, context, thereornot, thereornot);
+ 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);
@@ -5404,8 +5404,8 @@
{
int new_msgs;
char *mailbox, *context;
- struct stasis_message *mwi_message;
- struct ast_str *uniqueid = ast_str_alloca(128);
+ 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, "@");
@@ -13217,7 +13217,7 @@
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(128);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
mailbox = context = ast_strdupa(tmp->mailbox);
strsep(&context, "@");
if (ast_strlen_zero(context))
Modified: team/kmoore/stasis-mwi/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/chan_iax2.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/channels/chan_iax2.c (original)
+++ team/kmoore/stasis-mwi/channels/chan_iax2.c Tue Mar 5 12:47:17 2013
@@ -1316,7 +1316,7 @@
}
}
-static void mwi_event_cb(void *userdata, struct stasis_topic *topic, struct stasis_message *msg)
+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
@@ -8745,8 +8745,8 @@
if (!ast_strlen_zero(p->mailbox)) {
int new, old;
char *mailbox, *context;
- struct stasis_message *msg;
- struct ast_str *uniqueid = ast_str_alloca(128);
+ 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, "@");
@@ -12668,7 +12668,7 @@
if (!ast_strlen_zero(peer->mailbox)) {
char *mailbox, *context;
- struct ast_str *uniqueid = ast_str_alloca(128);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
context = mailbox = ast_strdupa(peer->mailbox);
strsep(&context, "@");
Modified: team/kmoore/stasis-mwi/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/chan_mgcp.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/channels/chan_mgcp.c (original)
+++ team/kmoore/stasis-mwi/channels/chan_mgcp.c Tue Mar 5 12:47:17 2013
@@ -484,7 +484,7 @@
.func_channel_read = acf_channel_read,
};
-static void mwi_event_cb(void *userdata, struct stasis_topic *topic, struct stasis_message *msg)
+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
@@ -495,8 +495,8 @@
static int has_voicemail(struct mgcp_endpoint *p)
{
int new_msgs;
- struct stasis_message *msg;
- struct ast_str *uniqueid = ast_str_alloca(128);
+ 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);
@@ -3975,7 +3975,7 @@
struct mgcp_endpoint *e;
struct mgcp_subchannel *sub;
struct ast_variable *chanvars = NULL;
- struct ast_str *uniqueid = ast_str_alloca(128);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
/*char txident[80];*/
int i=0, y=0;
Modified: team/kmoore/stasis-mwi/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/chan_sip.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/channels/chan_sip.c (original)
+++ team/kmoore/stasis-mwi/channels/chan_sip.c Tue Mar 5 12:47:17 2013
@@ -1274,7 +1274,7 @@
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(void *, struct stasis_topic *, struct stasis_message *);
+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);
@@ -16504,9 +16504,13 @@
}
/*! \brief Receive MWI events that we have subscribed to */
-static void mwi_event_cb(void *userdata, struct stasis_topic *topic, struct stasis_message *msg)
+static void mwi_event_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
{
struct sip_peer *peer = userdata;
+ if (stasis_subscription_final_message(sub, msg)) {
+ ao2_cleanup(peer);
+ return;
+ }
if (stasis_mwi_state() == stasis_message_type(msg)) {
sip_send_mwi_to_peer(peer, 0);
}
@@ -24617,13 +24621,8 @@
if (!ast_strlen_zero(mailbox) && !ast_strlen_zero(c)) {
char *old = strsep(&c, " ");
char *new = strsep(&old, "/");
- int new_msgs = atoi(new);
- int old_msgs = atoi(old);
- char *context = "SIP_Remote";
- struct ast_str *uniqueid = ast_str_alloca(128);
-
- ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
- stasis_publish_mwi_state(ast_str_buffer(uniqueid), mailbox, context, new_msgs, old_msgs);
+
+ stasis_publish_mwi_state(mailbox, "SIP_Remote", atoi(new), atoi(old));
transmit_response(p, "200 OK", req);
} else {
@@ -27459,7 +27458,7 @@
static void add_peer_mwi_subs(struct sip_peer *peer)
{
struct sip_mailbox *mailbox;
- struct ast_str *uniqueid = ast_str_alloca(128);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
if (mailbox->event_sub) {
@@ -27469,6 +27468,7 @@
ast_str_reset(uniqueid);
ast_str_set(&uniqueid, 0, "%s@%s", mailbox->mailbox, S_OR(mailbox->context, "default"));
+ ao2_ref(peer, +1);
mailbox->event_sub = stasis_subscribe(stasis_mwi_topic(ast_str_buffer(uniqueid)), mwi_event_cb, peer);
}
}
@@ -28672,11 +28672,11 @@
{
struct sip_mailbox *mailbox;
int in_cache;
- struct ast_str *uniqueid = ast_str_alloca(128);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
in_cache = 0;
AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
- struct stasis_message *msg;
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
struct stasis_mwi_state *mwi_state;
ast_str_reset(uniqueid);
Modified: team/kmoore/stasis-mwi/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/chan_skinny.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/channels/chan_skinny.c (original)
+++ team/kmoore/stasis-mwi/channels/chan_skinny.c Tue Mar 5 12:47:17 2013
@@ -1611,7 +1611,7 @@
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(void *userdata, struct stasis_topic *topic, struct stasis_message *msg);
+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 @@
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(l, NULL, NULL);
+ 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 @@
send_callinfo(sub);
}
-static void mwi_event_cb(void *userdata, struct stasis_topic *topic, struct stasis_message *msg)
+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;
@@ -8251,7 +8251,7 @@
if (!ast_strlen_zero(l->mailbox)) {
char *cfg_mailbox, *cfg_context;
- struct ast_str *uniqueid = ast_str_alloca(128);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
cfg_context = cfg_mailbox = ast_strdupa(l->mailbox);
ast_verb(3, "Setting mailbox '%s' on line %s\n", cfg_mailbox, l->name);
Modified: team/kmoore/stasis-mwi/channels/chan_unistim.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/chan_unistim.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/channels/chan_unistim.c (original)
+++ team/kmoore/stasis-mwi/channels/chan_unistim.c Tue Mar 5 12:47:17 2013
@@ -5500,8 +5500,8 @@
{
int new;
char *mailbox, *context;
- struct stasis_message *msg;
- struct ast_str *uniqueid = ast_str_alloca(128);
+ 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, "@");
Modified: team/kmoore/stasis-mwi/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/sig_pri.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/channels/sig_pri.c (original)
+++ team/kmoore/stasis-mwi/channels/sig_pri.c Tue Mar 5 12:47:17 2013
@@ -8752,7 +8752,7 @@
*
* \return Nothing
*/
-static void sig_pri_mwi_event_cb(void *userdata, struct stasis_topic *topic, struct stasis_message *msg)
+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;
@@ -8806,11 +8806,11 @@
static void sig_pri_mwi_cache_update(struct sig_pri_span *pri)
{
int idx;
- struct ast_str *uniqueid = ast_str_alloca(128);
- struct stasis_message *msg;
+ 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;
@@ -8914,7 +8914,7 @@
char *saveptr;
char *prev_vm_number;
struct ast_str *mwi_description = ast_str_alloca(64);
- struct ast_str *uniqueid = ast_str_alloca(128);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
#endif /* defined(HAVE_PRI_MWI) */
#if defined(HAVE_PRI_MWI)
Modified: team/kmoore/stasis-mwi/include/asterisk/app.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/include/asterisk/app.h?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/include/asterisk/app.h (original)
+++ team/kmoore/stasis-mwi/include/asterisk/app.h Tue Mar 5 12:47:17 2013
@@ -1098,8 +1098,8 @@
* \retval -1 Failure
* \since 12
*/
-#define stasis_publish_mwi_state(uniqueid, mailbox, context, new_msgs, old_msgs) \
- stasis_publish_mwi_state_full(uniqueid, mailbox, context, new_msgs, old_msgs, NULL)
+#define stasis_publish_mwi_state(mailbox, context, new_msgs, old_msgs) \
+ stasis_publish_mwi_state_full(mailbox, context, new_msgs, old_msgs, NULL)
/*!
* \brief Publish a MWI state update via stasis with EID
@@ -1114,7 +1114,6 @@
* \since 12
*/
int stasis_publish_mwi_state_full(
- const char *uniqueid,
const char *mailbox,
const char *context,
int new_msgs,
@@ -1175,6 +1174,8 @@
* \since 12
*/
int app_init(void);
+
+#define AST_MAX_MAILBOX_UNIQUEID (AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2)
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
Modified: team/kmoore/stasis-mwi/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/main/app.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/main/app.c (original)
+++ team/kmoore/stasis-mwi/main/app.c Tue Mar 5 12:47:17 2013
@@ -2717,7 +2717,6 @@
}
int stasis_publish_mwi_state_full(
- const char *uniqueid,
const char *mailbox,
const char *context,
int new_msgs,
@@ -2726,13 +2725,19 @@
{
RAII_VAR(struct stasis_mwi_state *, mwi_state, NULL, ao2_cleanup);
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+ struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
+
+ ast_assert(!ast_strlen_zero(mailbox));
+ ast_assert(!ast_strlen_zero(context));
+
+ ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
mwi_state = ao2_alloc(sizeof(*mwi_state), mwi_state_dtor);
if (ast_string_field_init(mwi_state, 256)) {
return -1;
}
- ast_string_field_set(mwi_state, uniqueid, uniqueid);
+ ast_string_field_set(mwi_state, uniqueid, ast_str_buffer(uniqueid));
ast_string_field_set(mwi_state, mailbox, mailbox);
ast_string_field_set(mwi_state, context, context);
mwi_state->new_msgs = new_msgs;
@@ -2743,8 +2748,8 @@
stasis_message_eid_set(message, eid);
}
- ast_assert(stasis_mwi_topic(uniqueid) != NULL);
- stasis_publish(stasis_mwi_topic(uniqueid), message);
+ ast_assert(stasis_mwi_topic(ast_str_buffer(uniqueid)) != NULL);
+ stasis_publish(stasis_mwi_topic(ast_str_buffer(uniqueid)), message);
return 0;
}
Modified: team/kmoore/stasis-mwi/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/main/manager.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/main/manager.c (original)
+++ team/kmoore/stasis-mwi/main/manager.c Tue Mar 5 12:47:17 2013
@@ -7548,7 +7548,7 @@
channel_name, name, value, uniqueid);
}
-static void channel_event_cb(void *data, struct stasis_topic *topic, struct stasis_message *message)
+static void channel_event_cb(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *message)
{
if (stasis_message_type(message) == stasis_cache_update()) {
struct stasis_cache_update *update = stasis_message_data(message);
Modified: team/kmoore/stasis-mwi/res/res_jabber.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/res/res_jabber.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/res/res_jabber.c (original)
+++ team/kmoore/stasis-mwi/res/res_jabber.c Tue Mar 5 12:47:17 2013
@@ -3240,16 +3240,18 @@
* \param data void pointer to ast_client structure
* \return void
*/
-static void aji_mwi_cb(void *data, struct stasis_topic *topic, struct stasis_message *msg)
+static void aji_mwi_cb(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
{
const char *mailbox;
const char *context;
char oldmsgs[10];
char newmsgs[10];
- struct aji_client *client;
+ struct aji_client *client = data;
struct stasis_mwi_state *mwi_state;
- if (stasis_mwi_state() != stasis_message_type(msg)) {
+ if (stasis_subscription_final_message(sub, msg)) {
+ ASTOBJ_UNREF(client, ast_aji_client_destroy);
+ } else if (stasis_mwi_state() != stasis_message_type(msg)) {
return;
}
@@ -3260,7 +3262,6 @@
return;
}
- client = ASTOBJ_REF((struct aji_client *) data);
mwi_state = stasis_message_data(msg);
mailbox = mwi_state->mailbox;
@@ -3270,8 +3271,6 @@
snprintf(newmsgs, sizeof(newmsgs), "%d",
mwi_state->new_msgs);
aji_publish_mwi(client, mailbox, context, oldmsgs, newmsgs);
- ASTOBJ_UNREF(client, ast_aji_client_destroy);
-
}
/*!
* \brief Callback function for device state events
@@ -3308,6 +3307,7 @@
static void aji_init_event_distribution(struct aji_client *client)
{
if (!mwi_sub) {
+ client = ASTOBJ_REF(client);
mwi_sub = stasis_subscribe(stasis_mwi_topic_all(), aji_mwi_cb, client);
}
if (!device_state_sub) {
Modified: team/kmoore/stasis-mwi/res/res_xmpp.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/res/res_xmpp.c?view=diff&rev=382466&r1=382465&r2=382466
==============================================================================
--- team/kmoore/stasis-mwi/res/res_xmpp.c (original)
+++ team/kmoore/stasis-mwi/res/res_xmpp.c Tue Mar 5 12:47:17 2013
@@ -1319,14 +1319,17 @@
* \param data void pointer to ast_client structure
* \return void
*/
-static void xmpp_pubsub_mwi_cb(void *data, struct stasis_topic *topic, struct stasis_message *msg)
+static void xmpp_pubsub_mwi_cb(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
{
struct ast_xmpp_client *client = data;
const char *mailbox, *context;
char oldmsgs[10], newmsgs[10];
struct stasis_mwi_state *mwi_state;
- if (stasis_mwi_state() != stasis_message_type(msg)) {
+ if (stasis_subscription_final_message(sub, msg)) {
+ ao2_cleanup(client);
+ return;
+ } else if (stasis_mwi_state() != stasis_message_type(msg)) {
return;
}
@@ -1483,12 +1486,11 @@
return IKS_FILTER_EAT;
}
} else if (!strcasecmp(iks_name(item_content), "mailbox")) {
- char *uniqueid = ast_strdupa(item_id);
context = strsep(&item_id, "@");
sscanf(iks_find_cdata(item_content, "OLDMSGS"), "%10d", &oldmsgs);
sscanf(iks_find_cdata(item_content, "NEWMSGS"), "%10d", &newmsgs);
- stasis_publish_mwi_state_full(uniqueid, item_id, context, newmsgs, oldmsgs, &pubsub_eid);
+ stasis_publish_mwi_state_full(item_id, context, newmsgs, oldmsgs, &pubsub_eid);
return IKS_FILTER_EAT;
} else {
@@ -1594,6 +1596,8 @@
if (!(client->mwi_sub = stasis_subscribe(stasis_mwi_topic_all(), xmpp_pubsub_mwi_cb, client))) {
return;
}
+ /* bump the ref held by the subscription */
+ ao2_ref(client, +1);
if (ast_enable_distributed_devstate()) {
return;
More information about the asterisk-commits
mailing list