From 9d1acad76b611cc2400d00da0b60fd75d07d6263 Mon Sep 17 00:00:00 2001 From: Russell Bryant <russell@russellbryant.com> Date: Thu, 9 Aug 2007 17:07:36 +0000 Subject: [PATCH] Fix a problem that I had introduced into MWI handling. I had ignored the mailbox context. Now, all related MWI event dealings pay attention to the context as well. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@78747 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_voicemail.c | 11 +++++++---- channels/chan_iax2.c | 17 +++++++++++++++-- channels/chan_mgcp.c | 17 +++++++++++++++-- channels/chan_sip.c | 24 +++++++++++++++++++++--- channels/chan_zap.c | 17 +++++++++++++++-- include/asterisk/event_defs.h | 6 ++++++ 6 files changed, 79 insertions(+), 13 deletions(-) diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index ae2fa2f940..aba3347177 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -3997,15 +3997,17 @@ static int vm_forwardoptions(struct ast_channel *chan, struct ast_vm_user *vmu, static void queue_mwi_event(const char *mbox, int new, int old) { struct ast_event *event; - char *mailbox; + char *mailbox, *context; /* Strip off @default */ - mailbox = ast_strdupa(mbox); - if (strstr(mailbox, "@default")) - mailbox = strsep(&mailbox, "@"); + context = mailbox = ast_strdupa(mbox); + strsep(&context, "@"); + 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, new, AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, old, AST_EVENT_IE_END))) { @@ -4014,6 +4016,7 @@ static void queue_mwi_event(const char *mbox, int new, int old) ast_event_queue_and_cache(event, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, + AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_END); } diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 5137d2af12..30c79e47cd 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -6054,9 +6054,16 @@ static int update_registry(const char *name, struct sockaddr_in *sin, int callno if (!ast_strlen_zero(p->mailbox)) { struct ast_event *event; int new, old; + char *mailbox, *context; + + context = mailbox = ast_strdupa(p->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, p->mailbox, + 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_OLDMSGS, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_END); @@ -9315,8 +9322,14 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st ast_free_ha(oldha); if (!ast_strlen_zero(peer->mailbox)) { + char *mailbox, *context; + mailbox = ast_strdupa(peer->mailbox); + strsep(&context, "@"); + if (ast_strlen_zero(context)) + context = "default"; peer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, NULL, - AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, peer->mailbox, + AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox, + AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context, AST_EVENT_IE_END); } diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index 198c964ad8..f5e38ddf1f 100644 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -468,9 +468,16 @@ static int has_voicemail(struct mgcp_endpoint *p) { int new_msgs; struct ast_event *event; + char *mailbox, *context; + + context = mailbox = ast_strdupa(p->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, p->mailbox, + 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); @@ -3692,8 +3699,14 @@ static struct mgcp_gateway *build_gateway(char *cat, struct ast_variable *v) ast_copy_string(e->musicclass, musicclass, sizeof(e->musicclass)); ast_copy_string(e->mailbox, mailbox, sizeof(e->mailbox)); if (!ast_strlen_zero(e->mailbox)) { + char *mailbox, *context; + context = mailbox = ast_strdupa(e->mailbox); + strsep(&context, "@"); + if (ast_strlen_zero(context)) + context = "default"; e->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, NULL, - AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, e->mailbox, + 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); } diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 8800a60ba9..ab875b1a9a 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -15756,8 +15756,14 @@ static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, p->subscribed = MWI_NOTIFICATION; if (ast_test_flag(&authpeer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY)) { + char *mailbox, *context; + context = mailbox = ast_strdupa(authpeer->mailbox); + strsep(&context, "@"); + if (ast_strlen_zero(context)) + context = "default"; authpeer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, authpeer, - AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, authpeer->mailbox, + 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 (authpeer->mwipvt && authpeer->mwipvt != p) /* Destroy old PVT if this is a new one */ @@ -16244,9 +16250,15 @@ static int sip_send_mwi_to_peer(struct sip_peer *peer, const struct ast_event *e return 0; if (!event) { + char *mailbox, *context = NULL; /* Check the event cache for the mailbox info */ + context = mailbox = ast_strdupa(peer->mailbox); + strsep(&context, "@"); + if (ast_strlen_zero(context)) + context = "default"; event = cache_event = ast_event_get_cached(AST_EVENT_MWI, - AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, peer->mailbox, + 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_OLDMSGS, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_END); @@ -17488,8 +17500,14 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str * subscribe to it now. */ if (!ast_test_flag(&peer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY) && !ast_strlen_zero(peer->mailbox)) { + char *mailbox, *context; + context = mailbox = ast_strdupa(peer->mailbox); + strsep(&context, "@"); + if (ast_strlen_zero(context)) + context = "default"; peer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, peer, - AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, peer->mailbox, + AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox, + AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context, AST_EVENT_IE_END); /* 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 diff --git a/channels/chan_zap.c b/channels/chan_zap.c index 1426f456a1..4152f0e192 100644 --- a/channels/chan_zap.c +++ b/channels/chan_zap.c @@ -1850,9 +1850,16 @@ static int has_voicemail(struct zt_pvt *p) { int new_msgs; struct ast_event *event; + char *mailbox, *context; + + mailbox = context = ast_strdupa(p->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, p->mailbox, + 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); @@ -7850,8 +7857,14 @@ static struct zt_pvt *mkintf(int channel, struct zt_chan_conf conf, struct zt_pr ast_copy_string(tmp->cid_name, conf.chan.cid_name, sizeof(tmp->cid_name)); ast_copy_string(tmp->mailbox, conf.chan.mailbox, sizeof(tmp->mailbox)); if (!ast_strlen_zero(tmp->mailbox)) { + char *mailbox, *context; + 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, NULL, - AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, tmp->mailbox, + 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); } diff --git a/include/asterisk/event_defs.h b/include/asterisk/event_defs.h index 2627bae8df..9aadaebf60 100644 --- a/include/asterisk/event_defs.h +++ b/include/asterisk/event_defs.h @@ -103,6 +103,12 @@ enum ast_event_ie_type { * this IE is a part of. */ AST_EVENT_IE_STATE = 0x08, + /*! + * \brief Context IE + * Used by AST_EVENT_MWI + * Payload type: str + */ + AST_EVENT_IE_CONTEXT = 0x09, }; /*! -- GitLab