]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
When IMAP variables were changed during a reload, Voicemail did not use the new values.
authorTilghman Lesher <tilghman@meg.abyt.es>
Tue, 22 Sep 2009 21:37:03 +0000 (21:37 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Tue, 22 Sep 2009 21:37:03 +0000 (21:37 +0000)
This change introduces a configuration version variable, which ensures that
connections with the old values are not reused but are allowed to expire
normally.
(closes issue #15934)
 Reported by: viniciusfontes
 Patches:
       20090922__issue15934.diff.txt uploaded by tilghman (license 14)
 Tested by: viniciusfontes

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@219816 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_voicemail.c

index e6f3ab4ae7337e849de701b499972277fe520630..2c57e522e0410645ee02ddb4e6d0127155261052 100644 (file)
@@ -117,6 +117,7 @@ static char imapflags[128];
 static char imapfolder[64];
 static char authuser[32];
 static char authpassword[42];
+static int imapversion = 1;
 
 static int expungeonhangup = 1;
 static char delimiter = '\0';
@@ -350,6 +351,7 @@ struct ast_vm_user {
        char imapuser[80];      /* IMAP server login */
        char imappassword[80];  /* IMAP server password if authpassword not defined */
        char imapvmshareid[80]; /* Shared mailbox ID to use rather than the dialed one */
+       int imapversion;                 /*!< If configuration changes, use the new values */
 #endif
        double volgain;         /*!< Volume gain for voicemails sent via email */
        AST_LIST_ENTRY(ast_vm_user) list;
@@ -385,6 +387,7 @@ struct vm_state {
        MAILSTREAM *mailstream;
        int vmArrayIndex;
        char imapuser[80]; /* IMAP server login */
+       int imapversion;
        int interactive;
        unsigned int quota_limit;
        unsigned int quota_usage;
@@ -625,10 +628,13 @@ static void apply_option(struct ast_vm_user *vmu, const char *var, const char *v
 #ifdef IMAP_STORAGE
        } else if (!strcasecmp(var, "imapuser")) {
                ast_copy_string(vmu->imapuser, value, sizeof(vmu->imapuser));
+               vmu->imapversion = imapversion;
        } else if (!strcasecmp(var, "imappassword") || !strcasecmp(var, "imapsecret")) {
                ast_copy_string(vmu->imappassword, value, sizeof(vmu->imappassword));
+               vmu->imapversion = imapversion;
        } else if (!strcasecmp(var, "imapvmshareid")) {
                ast_copy_string(vmu->imapvmshareid, value, sizeof(vmu->imapvmshareid));
+               vmu->imapversion = imapversion;
 #endif
        } else if (!strcasecmp(var, "delete") || !strcasecmp(var, "deletevoicemail")) {
                ast_set2_flag(vmu, ast_true(value), VM_DELETE); 
@@ -730,10 +736,13 @@ static void apply_options_full(struct ast_vm_user *retval, struct ast_variable *
 #ifdef IMAP_STORAGE
                } else if (!strcasecmp(tmp->name, "imapuser")) {
                        ast_copy_string(retval->imapuser, tmp->value, sizeof(retval->imapuser));
+                       retval->imapversion = imapversion;
                } else if (!strcasecmp(tmp->name, "imappassword") || !strcasecmp(tmp->name, "imapsecret")) {
                        ast_copy_string(retval->imappassword, tmp->value, sizeof(retval->imappassword));
+                       retval->imapversion = imapversion;
                } else if (!strcasecmp(tmp->name, "imapvmshareid")) {
                        ast_copy_string(retval->imapvmshareid, tmp->value, sizeof(retval->imapvmshareid));
+                       retval->imapversion = imapversion;
 #endif
                } else
                        apply_option(retval, tmp->name, tmp->value);
@@ -780,6 +789,11 @@ static struct ast_vm_user *find_user(struct ast_vm_user *ivm, const char *contex
                context = "default";
 
        AST_LIST_TRAVERSE(&users, cur, list) {
+#ifdef IMAP_STORAGE
+               if (cur->imapversion != imapversion) {
+                       continue;
+               }
+#endif
                if (ast_test_flag((&globalflags), VM_SEARCH) && !strcasecmp(mailbox, cur->mailbox))
                        break;
                if (context && (!strcasecmp(context, cur->context)) && (!strcasecmp(mailbox, cur->mailbox)))
@@ -1057,6 +1071,7 @@ static int imap_retrieve_file(const char *dir, const int msgnum, const struct as
                 * and should have its msgArray properly set up.
                 */
                ast_log(LOG_ERROR, "Couldn't find a vm_state for mailbox %s!!! Oh no!\n", vmu->mailbox);
+               return -1;
        }
        
        make_file(vms->fn, sizeof(vms->fn), dir, msgnum);
@@ -1546,6 +1561,8 @@ static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu, int box)
        int ret;
 
        ast_copy_string(vms->imapuser,vmu->imapuser, sizeof(vms->imapuser));
+       vms->imapversion = vmu->imapversion;
+
        if (option_debug > 2)
                ast_log(LOG_DEBUG,"Before init_mailstream, user is %s\n",vmu->imapuser);
        ret = init_mailstream(vms, box);
@@ -1915,6 +1932,7 @@ static struct vm_state *create_vm_state_from_user(struct ast_vm_user *vmu)
        ast_copy_string(vms_p->username, vmu->mailbox, sizeof(vms_p->username)); /* save for access from interactive entry point */
        ast_copy_string(vms_p->context, vmu->context, sizeof(vms_p->context));
        vms_p->mailstream = NIL; /* save for access from interactive entry point */
+       vms_p->imapversion = vmu->imapversion;
        if (option_debug > 4)
                ast_log(LOG_DEBUG,"Copied %s to %s\n",vmu->imapuser,vms_p->imapuser);
        vms_p->updated = 1;
@@ -1939,7 +1957,7 @@ static struct vm_state *get_vm_state_by_imapuser(char *user, int interactive)
        ast_mutex_lock(&vmstate_lock);
        vlist = vmstates;
        while (vlist) {
-               if (vlist->vms) {
+               if (vlist->vms && vlist->vms->imapversion == imapversion) {
                        if (vlist->vms->imapuser) {
                                if (!strcmp(vlist->vms->imapuser,user)) {
                                        if (interactive == 2) {
@@ -1984,7 +2002,7 @@ static struct vm_state *get_vm_state_by_mailbox(const char *mailbox, const char
                ast_log(LOG_DEBUG, "Mailbox set to %s\n",mailbox);
        while (vlist) {
                if (vlist->vms) {
-                       if (vlist->vms->username && vlist->vms->context) {
+                       if (vlist->vms->username && vlist->vms->context && vlist->vms->imapversion == imapversion) {
                                if (option_debug > 2)
                                        ast_log(LOG_DEBUG, "    comparing mailbox %s (i=%d) to vmstate mailbox %s (i=%d)\n",mailbox,interactive,vlist->vms->username,vlist->vms->interactive);
                                if (!strcmp(vlist->vms->username,mailbox) && !(strcmp(vlist->vms->context, local_context))) {
@@ -8466,6 +8484,8 @@ static int load_config(void)
                        mail_parameters(NIL, SET_CLOSETIMEOUT, (void *) DEFAULT_IMAP_TCP_TIMEOUT);
                }
 
+               /* Increment configuration version */
+               imapversion++;
 #endif
                /* External voicemail notify application */