[asterisk-commits] mmichelson: branch mmichelson/pub_sub r385821 - /team/mmichelson/pub_sub/res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 15 16:48:10 CDT 2013
Author: mmichelson
Date: Mon Apr 15 16:48:08 2013
New Revision: 385821
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385821
Log:
Add a few more comments/fixes.
One more go and then this will be ready for review.
Modified:
team/mmichelson/pub_sub/res/res_sip_mwi.c
Modified: team/mmichelson/pub_sub/res/res_sip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/res/res_sip_mwi.c?view=diff&rev=385821&r1=385820&r2=385821
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_mwi.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_mwi.c Mon Apr 15 16:48:08 2013
@@ -80,44 +80,6 @@
/*! The mailbox corresponding with the MWI subscription. Used as a hash key */
char mailbox[1];
};
-
-static void mwi_stasis_cb(void *userdata, struct stasis_subscription *sub,
- struct stasis_topic *topic, struct stasis_message *msg);
-
-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;
-
- mwi_stasis_sub = ao2_alloc(sizeof(*mwi_stasis_sub) + strlen(mailbox), NULL);
- if (!mwi_stasis_sub) {
- return NULL;
- }
-
- topic = stasis_mwi_topic(mailbox);
-
- /* Safe strcpy */
- strcpy(mwi_stasis_sub->mailbox, mailbox);
- ao2_ref(mwi_sub, +1);
- ast_debug(3, "Creating stasis MWI subscription to mailbox %s for endpoint %s\n", mailbox, mwi_sub->id);
- mwi_stasis_sub->stasis_sub = stasis_subscribe(topic, mwi_stasis_cb, mwi_sub);
- return mwi_stasis_sub;
-}
-
-static int stasis_sub_hash(const void *obj, int flags)
-{
- const struct mwi_stasis_subscription *mwi_stasis = obj;
-
- return ast_str_hash(mwi_stasis->mailbox);
-}
-
-static int stasis_sub_cmp(void *obj, void *arg, int flags)
-{
- struct mwi_stasis_subscription *mwi_stasis1 = obj;
- struct mwi_stasis_subscription *mwi_stasis2 = arg;
-
- return strcmp(mwi_stasis1->mailbox, mwi_stasis2->mailbox) ? 0 : CMP_MATCH;
-}
/*!
* \brief A subscription for MWI
@@ -148,6 +110,44 @@
char id[1];
};
+static void mwi_stasis_cb(void *userdata, struct stasis_subscription *sub,
+ struct stasis_topic *topic, struct stasis_message *msg);
+
+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;
+
+ mwi_stasis_sub = ao2_alloc(sizeof(*mwi_stasis_sub) + strlen(mailbox), NULL);
+ if (!mwi_stasis_sub) {
+ return NULL;
+ }
+
+ topic = stasis_mwi_topic(mailbox);
+
+ /* Safe strcpy */
+ strcpy(mwi_stasis_sub->mailbox, mailbox);
+ ao2_ref(mwi_sub, +1);
+ ast_debug(3, "Creating stasis MWI subscription to mailbox %s for endpoint %s\n", mailbox, mwi_sub->id);
+ mwi_stasis_sub->stasis_sub = stasis_subscribe(topic, mwi_stasis_cb, mwi_sub);
+ return mwi_stasis_sub;
+}
+
+static int stasis_sub_hash(const void *obj, int flags)
+{
+ const struct mwi_stasis_subscription *mwi_stasis = obj;
+
+ return ast_str_hash(mwi_stasis->mailbox);
+}
+
+static int stasis_sub_cmp(void *obj, void *arg, int flags)
+{
+ struct mwi_stasis_subscription *mwi_stasis1 = obj;
+ struct mwi_stasis_subscription *mwi_stasis2 = arg;
+
+ return strcmp(mwi_stasis1->mailbox, mwi_stasis2->mailbox) ? 0 : CMP_MATCH;
+}
+
static void mwi_subscription_destructor(void *obj)
{
struct mwi_subscription *sub = obj;
@@ -289,7 +289,6 @@
static void send_mwi_notify(struct mwi_subscription *sub, pjsip_evsub_state state, const char *reason)
{
- pj_str_t reason_str;
const pj_str_t *reason_str_ptr = NULL;
static pjsip_media_type mwi_type = {
.type = { "application", 11 },
@@ -301,6 +300,7 @@
};
RAII_VAR(struct ast_str *, body, ast_str_create(64), ast_free_ptr);
pjsip_tx_data *tdata;
+ pj_str_t reason_str;
pj_str_t pj_body;
ao2_callback(sub->stasis_subs, OBJ_NODATA, get_message_count, &counter);
@@ -314,8 +314,8 @@
pj_cstr(&pj_body, ast_str_buffer(body));
ast_debug(5, "Sending %s MWI NOTIFY to endpoint %s, new messages: %d, old messages: %d\n",
- sub->is_solicited ? "solicited" : "unsolicited", sub->id, counter.new_messages,
- counter.old_messages);
+ sub->is_solicited ? "solicited" : "unsolicited", sub->id, counter.new_msgs,
+ counter.old_msgs);
if (sub->is_solicited) {
if (pjsip_mwi_notify(ast_sip_subscription_get_evsub(sub->sip_sub),
@@ -511,7 +511,6 @@
struct mwi_subscription *mwi_sub = userdata;
if (stasis_subscription_final_message(sub, msg)) {
- ast_debug(3, "Stasis subscription for mailbox %s has ended. Removing MWI subscription\n", sub->mailbox);
ao2_cleanup(mwi_sub);
return;
}
@@ -535,12 +534,8 @@
return 0;
}
- /* MWI is an interesting case because the NOTIFYs we send are
- * unsolicited. We get around the requirement of needing an
- * incoming SUBSCRIBE by pretending that we are the subscriber
- */
if (endpoint->aggregate_mwi) {
- aggregate_sub = mwi_subscription_alloc(endpoint, AST_SIP_SUBSCRIBER, 0, NULL);
+ aggregate_sub = mwi_subscription_alloc(endpoint, AST_SIP_NOTIFIER, 0, NULL);
if (!aggregate_sub) {
return 0;
}
More information about the asterisk-commits
mailing list