<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14832">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_voicemail: Fix pollmailboxes<br><br>The name of the voicemail context was overwriting the name of the<br>subscribed mailbox. Fix by simplifying how we create the MWI<br>subscription.<br><br>ASTERISK-29029 #close<br><br>Change-Id: Ie8a7db6a0b68f3995b0846bbb733a21909ba44e5<br>---<br>M apps/app_voicemail.c<br>1 file changed, 23 insertions(+), 49 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c</span><br><span>index b8849da..0c7cd1e 100644</span><br><span>--- a/apps/app_voicemail.c</span><br><span>+++ b/apps/app_voicemail.c</span><br><span>@@ -1032,23 +1032,9 @@</span><br><span>   int old_new;</span><br><span>         int old_old;</span><br><span>         char *uniqueid;</span><br><span style="color: hsl(0, 100%, 40%);">- char mailbox[0];</span><br><span style="color: hsl(120, 100%, 40%);">+      char *mailbox;</span><br><span> };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-struct mwi_sub_task {</span><br><span style="color: hsl(0, 100%, 40%);">-   const char *mailbox;</span><br><span style="color: hsl(0, 100%, 40%);">-    const char *context;</span><br><span style="color: hsl(0, 100%, 40%);">-    const char *uniqueid;</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static void mwi_sub_task_dtor(struct mwi_sub_task *mwist)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-       ast_free((void *) mwist->mailbox);</span><br><span style="color: hsl(0, 100%, 40%);">-   ast_free((void *) mwist->context);</span><br><span style="color: hsl(0, 100%, 40%);">-   ast_free((void *) mwist->uniqueid);</span><br><span style="color: hsl(0, 100%, 40%);">-  ast_free(mwist);</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static struct ast_taskprocessor *mwi_subscription_tps;</span><br><span> </span><br><span> static AST_RWLIST_HEAD_STATIC(mwi_subs, mwi_sub);</span><br><span>@@ -13259,6 +13245,7 @@</span><br><span> static void mwi_sub_destroy(struct mwi_sub *mwi_sub)</span><br><span> {</span><br><span>  ast_free(mwi_sub->uniqueid);</span><br><span style="color: hsl(120, 100%, 40%);">+       ast_free(mwi_sub->mailbox);</span><br><span>       ast_free(mwi_sub);</span><br><span> }</span><br><span> </span><br><span>@@ -13337,35 +13324,12 @@</span><br><span> </span><br><span> static int handle_subscribe(void *datap)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-    unsigned int len;</span><br><span style="color: hsl(0, 100%, 40%);">-       struct mwi_sub *mwi_sub;</span><br><span style="color: hsl(0, 100%, 40%);">-        struct mwi_sub_task *p = datap;</span><br><span style="color: hsl(0, 100%, 40%);">- size_t context_len;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-     len = sizeof(*mwi_sub) + 1;</span><br><span style="color: hsl(0, 100%, 40%);">-     if (!ast_strlen_zero(p->mailbox))</span><br><span style="color: hsl(0, 100%, 40%);">-            len += strlen(p->mailbox);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-   context_len = strlen(p->context) + 1; /* Allow for seperator */</span><br><span style="color: hsl(0, 100%, 40%);">-      if (!ast_strlen_zero(p->context))</span><br><span style="color: hsl(0, 100%, 40%);">-            len += context_len;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-     if (!(mwi_sub = ast_calloc(1, len)))</span><br><span style="color: hsl(0, 100%, 40%);">-            return -1;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-      mwi_sub->uniqueid = ast_strdup(p->uniqueid);</span><br><span style="color: hsl(0, 100%, 40%);">-      if (!ast_strlen_zero(p->mailbox))</span><br><span style="color: hsl(0, 100%, 40%);">-            strcpy(mwi_sub->mailbox, p->mailbox);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-     if (!ast_strlen_zero(p->context)) {</span><br><span style="color: hsl(0, 100%, 40%);">-          strcat(mwi_sub->mailbox, "@");</span><br><span style="color: hsl(0, 100%, 40%);">-             ast_copy_string(mwi_sub->mailbox, p->context, context_len);</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(120, 100%, 40%);">+     struct mwi_sub *mwi_sub = datap;</span><br><span> </span><br><span>         AST_RWLIST_WRLOCK(&mwi_subs);</span><br><span>    AST_RWLIST_INSERT_TAIL(&mwi_subs, mwi_sub, entry);</span><br><span>       AST_RWLIST_UNLOCK(&mwi_subs);</span><br><span style="color: hsl(0, 100%, 40%);">-       mwi_sub_task_dtor(p);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>      poll_subscribed_mailbox(mwi_sub);</span><br><span>    return 0;</span><br><span> }</span><br><span>@@ -13386,29 +13350,39 @@</span><br><span> </span><br><span> static void mwi_sub_event_cb(struct stasis_subscription_change *change)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-  struct mwi_sub_task *mwist;</span><br><span style="color: hsl(120, 100%, 40%);">+   struct mwi_sub *mwi_sub;</span><br><span>     const char *topic;</span><br><span>   char *context;</span><br><span>       char *mailbox;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-      mwist = ast_calloc(1, (sizeof(*mwist)));</span><br><span style="color: hsl(0, 100%, 40%);">-        if (!mwist) {</span><br><span style="color: hsl(120, 100%, 40%);">+ mwi_sub = ast_calloc(1, sizeof(*mwi_sub));</span><br><span style="color: hsl(120, 100%, 40%);">+    if (!mwi_sub) {</span><br><span>              return;</span><br><span>      }</span><br><span> </span><br><span>        /* The topic name is prefixed with "mwi:all/" as this is a pool topic */</span><br><span>   topic = stasis_topic_name(change->topic) + 8;</span><br><span>     if (separate_mailbox(ast_strdupa(topic), &mailbox, &context)) {</span><br><span style="color: hsl(0, 100%, 40%);">-         ast_free(mwist);</span><br><span style="color: hsl(120, 100%, 40%);">+              mwi_sub_destroy(mwi_sub);</span><br><span>            return;</span><br><span>      }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   mwist->mailbox = ast_strdup(mailbox);</span><br><span style="color: hsl(0, 100%, 40%);">-        mwist->context = ast_strdup(context);</span><br><span style="color: hsl(0, 100%, 40%);">-        mwist->uniqueid = ast_strdup(change->uniqueid);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* separate_mailbox() guarantees a non-NULL, non-empty mailbox and context */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_asprintf(&mwi_sub->mailbox, "%s@%s", mailbox, context) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+             mwi_sub_destroy(mwi_sub);</span><br><span style="color: hsl(120, 100%, 40%);">+             return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   if (ast_taskprocessor_push(mwi_subscription_tps, handle_subscribe, mwist) < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-             mwi_sub_task_dtor(mwist);</span><br><span style="color: hsl(120, 100%, 40%);">+     /* The stasis subscription uniqueid will never be NULL */</span><br><span style="color: hsl(120, 100%, 40%);">+     mwi_sub->uniqueid = ast_strdup(change->uniqueid);</span><br><span style="color: hsl(120, 100%, 40%);">+       if (!mwi_sub->uniqueid) {</span><br><span style="color: hsl(120, 100%, 40%);">+          mwi_sub_destroy(mwi_sub);</span><br><span style="color: hsl(120, 100%, 40%);">+             return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (ast_taskprocessor_push(mwi_subscription_tps, handle_subscribe, mwi_sub) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+         mwi_sub_destroy(mwi_sub);</span><br><span style="color: hsl(120, 100%, 40%);">+             return;</span><br><span>      }</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14832">change 14832</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/14832"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: Ie8a7db6a0b68f3995b0846bbb733a21909ba44e5 </div>
<div style="display:none"> Gerrit-Change-Number: 14832 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>