[asterisk-commits] mmichelson: branch mmichelson/pub_sub r385682 - /team/mmichelson/pub_sub/res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 15 09:12:09 CDT 2013
Author: mmichelson
Date: Mon Apr 15 09:12:04 2013
New Revision: 385682
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385682
Log:
Make unsolicited MWI not use the pubsub API at all.
In tests, I found that phones were not cool with being sent
in-dialog unsolicited MWI NOTIFYs. They would respond with a 481
and not update the display on the phone to indicate the new state
of the mailbox.
With this change, we make use of the ast_sip_create_request()
and ast_sip_send_request() API calls in order to send unsolicited
MWI NOTIFYs to the correct endpoints.
Modified:
team/mmichelson/pub_sub/res/res_sip_mwi.c
team/mmichelson/pub_sub/res/res_sip_pubsub.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=385682&r1=385681&r2=385682
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_mwi.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_mwi.c Mon Apr 15 09:12:04 2013
@@ -148,11 +148,20 @@
/* Safe strcpy */
strcpy(sub->id, endpoint_id);
- sub->sip_sub = ast_sip_create_subscription(&mwi_handler,
- role, endpoint, NULL);
- if (!sub->sip_sub) {
- ao2_cleanup(sub);
- return NULL;
+ /* Unsolicited MWI doesn't actually result in a SIP subscription being
+ * created. This is because a SIP subscription associates with a dialog.
+ * Most devices expect unsolicited MWI NOTIFYs to appear out of dialog. If
+ * they receive an in-dialog MWI NOTIFY (i.e. with a to-tag), then they
+ * will reject the NOTIFY with a 481, thus resulting in message-waiting
+ * state not being updated on the device
+ */
+ if (is_solicited) {
+ sub->sip_sub = ast_sip_create_subscription(&mwi_handler,
+ role, endpoint, NULL);
+ if (!sub->sip_sub) {
+ ao2_cleanup(sub);
+ return NULL;
+ }
}
sub->stasis_subs = ao2_container_alloc(STASIS_BUCKETS, stasis_sub_hash, stasis_sub_cmp);
@@ -201,6 +210,46 @@
counter->old_msgs += mwi_state->old_msgs;
counter->new_msgs += mwi_state->new_msgs;
return 0;
+}
+
+static void send_unsolicited_mwi_notify(struct mwi_subscription *sub, pjsip_evsub_state state, const char *reason,
+ const pjsip_media_type *mwi_type, const pj_str_t *body_text)
+{
+ RAII_VAR(struct ast_sip_endpoint *, endpoint, ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(),
+ "endpoint", sub->id), ao2_cleanup);
+ const char *state_name;
+ pjsip_msg_body *msg_body;
+ pjsip_sub_state_hdr *sub_state;
+ pjsip_tx_data *tdata;
+ const pjsip_hdr *allow_events = pjsip_evsub_get_allow_events_hdr(NULL);
+ if (!endpoint) {
+ ast_log(LOG_WARNING, "Unable to send unsolicited MWI to %s because endpoint does not exist\n",
+ sub->id);
+ return;
+ }
+ if (ast_sip_create_request("NOTIFY", NULL, endpoint, NULL, &tdata)) {
+ ast_log(LOG_WARNING, "Unable to create unsolicited NOTIFY request to endpoint %s\n", sub->id);
+ return;
+ }
+ switch (state) {
+ case PJSIP_EVSUB_STATE_ACTIVE:
+ state_name = "active";
+ break;
+ case PJSIP_EVSUB_STATE_TERMINATED:
+ default:
+ state_name = "terminated";
+ break;
+ }
+ sub_state = pjsip_sub_state_hdr_create(tdata->pool);
+ pj_cstr(&sub_state->sub_state, state_name);
+ if (reason) {
+ pj_cstr(&sub_state->reason_param, reason);
+ }
+ pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) sub_state);
+ pjsip_msg_add_hdr(tdata->msg, pjsip_hdr_shallow_clone(tdata->pool, allow_events));
+ msg_body = pjsip_msg_body_create(tdata->pool, &mwi_type->type, &mwi_type->subtype, body_text);
+ tdata->msg->body = msg_body;
+ ast_sip_send_request(tdata, NULL, endpoint);
}
static void send_mwi_notify(struct mwi_subscription *sub, pjsip_evsub_state state, const char *reason)
@@ -225,7 +274,6 @@
pj_cstr(&reason_str, reason);
reason_str_ptr = &reason_str;
}
- /* XXX Not sure if the \r\n is actually necessary */
ast_str_append(&body, 0, "Messages-Waiting: %s\r\n", counter.new_msgs ? "yes" : "no");
ast_str_append(&body, 0, "Voice-Message: %d/%d (0/0)\r\n", counter.new_msgs, counter.old_msgs);
pj_cstr(&pj_body, ast_str_buffer(body));
@@ -239,22 +287,14 @@
&pj_body,
&tdata) != PJ_SUCCESS) {
ast_log(LOG_WARNING, "Unable to create MWI NOTIFY request.\n");
+ return;
+ }
+ if (ast_sip_subscription_send_request(sub->sip_sub, tdata) != PJ_SUCCESS) {
+ ast_log(LOG_NOTICE, "Unable to send MWI NOTIFY request\n");
+ return;
}
} else {
- pjsip_msg_body *msg_body;
- if (pjsip_evsub_notify(ast_sip_subscription_get_evsub(sub->sip_sub),
- state,
- NULL,
- reason_str_ptr,
- &tdata) != PJ_SUCCESS) {
- ast_log(LOG_WARNING, "Unable to create MWI NOTIFY request.\n");
- }
- msg_body = pjsip_msg_body_create(tdata->pool, &mwi_type.type, &mwi_type.subtype, &pj_body);
- tdata->msg->body = msg_body;
- }
-
- if (ast_sip_subscription_send_request(sub->sip_sub, tdata) != PJ_SUCCESS) {
- ast_log(LOG_NOTICE, "Unable to send MWI NOTIFY request\n");
+ send_unsolicited_mwi_notify(sub, state, reason, &mwi_type, &pj_body);
}
}
Modified: team/mmichelson/pub_sub/res/res_sip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/res/res_sip_pubsub.c?view=diff&rev=385682&r1=385681&r2=385682
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_pubsub.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_pubsub.c Mon Apr 15 09:12:04 2013
@@ -408,6 +408,7 @@
handler = find_handler(event, accept, accept_header->count);
if (!handler) {
+ ast_log(LOG_WARNING, "No registered handler for event %s\n", event);
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 489, NULL, NULL, NULL);
return PJ_TRUE;
}
More information about the asterisk-commits
mailing list