[Home]

Summary:ASTERISK-17997: When subscribing mwi to an unsolicited mailbox the first notification is incorrect
Reporter:rsw686 (rsw686)Labels:
Date Opened:2011-06-11 23:40:47Date Closed:2011-06-27 10:41:36
Priority:MinorRegression?
Status:Closed/CompleteComponents:Channels/chan_sip/Subscriptions
Versions:1.8.4 Frequency of
Occurrence
Related
Issues:
is caused byASTERISK-16149 MWI NOTIFY is not being sent to phones subscribed to events
Environment:Attachments:( 0) asterisk-1.8.4.2-sip-mwi-event.patch
( 1) asterisk-1.8.4.2-sip-mwi-event-v2.patch
( 2) jira_asterisk_17997_v1.8.patch
Description:I have the following in sip.conf. A remotepeer subscribed to mwi with the unsolicited option and a local phone subscribed to the remote mailbox. The notify message-summary events are sent correctly except for the first one when subscribing, which will always be 0. This means the phone mwi indicator will be wrong until the mailbox read/unread count changes and the event is fired.
{code}
[remotepeer]
unsolicited=100

[localphone]
mailbox=100@SIP_Remote
{code}
Look at the code in chan_sip.c handle_request_subscribe
{code}
if (p->subscribed == MWI_NOTIFICATION) {
ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
transmit_response(p, "200 OK", req);
if (p->relatedpeer) { /* Send first notification */
ao2_lock(p->relatedpeer); /* was WRLOCK */
sip_send_mwi_to_peer(p->relatedpeer, NULL, 0);
ao2_unlock(p->relatedpeer);
}
{code}
and then at sip_send_mwi_to_peer(struct sip_peer *peer, const struct ast_event *event, int cache_only)
{code}
if (event) {
newmsgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
oldmsgs = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS);
} else if (!cache_only) { /* Fall back to manually checking the mailbox */
struct ast_str *mailbox_str = ast_str_alloca(512);
peer_mailboxes_to_str(&mailbox_str, peer);
ast_app_inboxcount(mailbox_str->str, &newmsgs, &oldmsgs);
} else {
get_cached_mwi(peer, &newmsgs, &oldmsgs);
}
{code}
For the initial subscribe cache_only is 0 so we check the actual mailbox. For unsolicited mailboxes the message count is only available in the event cache since it doesn't have a mailbox. In another call to sip_send_mwi_to_peer we see the following
{code}
/* Send MWI from the event cache only.  This is so we can send initial
* MWI if app_voicemail got loaded before chan_sip.  If it is the other
* way, then we will get events when app_voicemail gets loaded. */
sip_send_mwi_to_peer(peer, NULL, 1);
{code}
This leads me to believe that manually checking the mailbox is legacy code from before the mwi event system. I have attached a proposed patch to remove the cache_only and either used the supplied event or fallback to the event cache. I have tested the patch mailboxes from app_voicemail and the unsolicited option and message-summary notifications are working properly.
Comments:By: rsw686 (rsw686) 2011-06-12 00:17:51.486-0500

Looks like this is a regression from ASTERISK-16149. I have attached a v2 patch that reverts one chunk from the previous issue. This resolves the problem and seems to be the correct solution. It checks the cache first and only reverts to counting messages if the cache doesn't contain the mailbox.

By: Richard Mudgett (rmudgett) 2011-06-24 18:07:59.856-0500

[^jira_asterisk_17997_v1.8.patch] should fix the issue without partially re-breaking ASTERISK-16149.

By: rsw686 (rsw686) 2011-06-24 20:02:20.466-0500

Just tested jira_asterisk_17997_v1.8.patch and I can confirm this resolves the issue. Thanks!

By: David Brillert (aragon) 2011-06-27 10:14:59.678-0500

rmudgett:

I would like ext 6003 to have a mailbox = 6003 and also monitor mwi for 6010.

But

If
[6003]
mailbox         =  6003@default, 6010@default
Then MWI for 6003 fails to light

If
[6003]
mailbox         =  6010@default
Then MWI for 6003 will light when 6010 receives msg

The only conclusion I can really make is that mwi for 6003 only lights if I do not include 6003 in sip.conf [6003] i.e.
mailbox         =  6010@default

By: Richard Mudgett (rmudgett) 2011-06-27 10:39:54.400-0500

Committed to trunk -r324915.

Merged revisions 324914 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8

........
 r324914 | rmudgett | 2011-06-27 10:37:19 -0500 (Mon, 27 Jun 2011) | 21 lines

 When subscribing MWI to an unsolicited mailbox the first notification is incorrect.

 A remote peer subscribed to MWI with the unsolicited option and a local
 phone subscribed to the remote mailbox.  The notify message-summary events
 are sent correctly except for the first one when subscribing, which will
 always be 0.  This means the phone MWI indicator will be wrong until the
 mailbox read/unread count changes and the event is fired.

 Looks like this is a regression from ASTERISK-16149.

 * Fix the logic to check the cache and if allowed then fallback to
 manually counting mailbox messages.

 (closes issue ASTERISK-17997)
 Reported by: rsw686
 Patches:
       jira_asterisk_17997_v1.8.patch (license #5621) uploaded by rmudgett
 Tested by: rsw686

 JIRA SWP-3551
........