[asterisk-commits] tilghman: branch 1.6.0 r165806 - in /branches/1.6.0: ./ apps/app_voicemail.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Dec 18 15:56:27 CST 2008
Author: tilghman
Date: Thu Dec 18 15:56:27 2008
New Revision: 165806
URL: http://svn.digium.com/view/asterisk?view=rev&rev=165806
Log:
Merged revisions 165797 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r165797 | tilghman | 2008-12-18 15:41:02 -0600 (Thu, 18 Dec 2008) | 15 lines
Merged revisions 165767 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r165767 | tilghman | 2008-12-18 15:14:47 -0600 (Thu, 18 Dec 2008) | 8 lines
Add mutexes around accesses to the IMAP library interface. This prevents
certain crashes, especially when shared mailboxes are used.
(closes issue #13653)
Reported by: howardwilkinson
Patches:
asterisk-1.4.21.2-appvoicemail-sharedimap-lock.patch uploaded by howardwilkinson (license 590)
Tested by: jpeeler
........
................
Modified:
branches/1.6.0/ (props changed)
branches/1.6.0/apps/app_voicemail.c
Propchange: branches/1.6.0/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.
Modified: branches/1.6.0/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/apps/app_voicemail.c?view=diff&rev=165806&r1=165805&r2=165806
==============================================================================
--- branches/1.6.0/apps/app_voicemail.c (original)
+++ branches/1.6.0/apps/app_voicemail.c Thu Dec 18 15:56:27 2008
@@ -45,7 +45,7 @@
***/
/*** MAKEOPTS
-<category name="MENUSELECT_OPTS_app_voicemail" displayname="Voicemail Build Options" positive_output="yes" remove_on_change="apps/app_voicemail.o apps/app_directory.o">
+<category name="MENUSELECT_OPTS_app_voicemail" displayname="Voicemail Build Options" positive_output="yes" remove_on_change="apps/app_voicemail.o apps/app_voicemail.so apps/app_directory.o apps/app_directory.so">
<member name="ODBC_STORAGE" displayname="Storage of Voicemail using ODBC">
<depend>unixodbc</depend>
<depend>ltdl</depend>
@@ -1147,7 +1147,9 @@
ast_debug(3, "deleting msgnum %d, which is mailbox message %lu\n", msgnum, messageNum);
/* delete message */
snprintf(arg, sizeof(arg), "%lu", messageNum);
+ ast_mutex_lock(&vms->lock);
mail_setflag(vms->mailstream, arg, "\\DELETED");
+ ast_mutex_unlock(&vms->lock);
}
static int imap_retrieve_greeting (const char *dir, const int msgnum, struct ast_vm_user *vmu)
@@ -1179,9 +1181,11 @@
return -1;
}
+ ast_mutex_lock(&vms_p->lock);
ret = init_mailstream(vms_p, GREETINGS_FOLDER);
if (!vms_p->mailstream) {
ast_log(LOG_ERROR, "IMAP mailstream is NULL\n");
+ ast_mutex_unlock(&vms_p->lock);
return -1;
}
@@ -1193,6 +1197,7 @@
attachment = ast_strdupa(body->nested.part->next->body.parameter->value);
} else {
ast_log(LOG_ERROR, "There is no file attached to this IMAP message.\n");
+ ast_mutex_unlock(&vms_p->lock);
return -1;
}
filename = strsep(&attachment, ".");
@@ -1200,9 +1205,11 @@
ast_copy_string(vms_p->fn, dir, sizeof(vms_p->fn));
vms_p->msgArray[vms_p->curmsg] = i + 1;
save_body(body, vms_p, "2", attachment);
+ ast_mutex_unlock(&vms_p->lock);
return 0;
}
}
+ ast_mutex_unlock(&vms_p->lock);
return -1;
}
@@ -1267,7 +1274,9 @@
}
/* This will only work for new messages... */
+ ast_mutex_lock(&vms->lock);
header_content = mail_fetchheader (vms->mailstream, vms->msgArray[msgnum]);
+ ast_mutex_unlock(&vms->lock);
/* empty string means no valid header */
if (ast_strlen_zero(header_content)) {
ast_log (LOG_ERROR,"Could not fetch header for message number %ld\n",vms->msgArray[msgnum]);
@@ -1275,8 +1284,10 @@
goto exit;
}
+ ast_mutex_lock(&vms->lock);
mail_fetchstructure (vms->mailstream,vms->msgArray[msgnum],&body);
-
+ ast_mutex_unlock(&vms->lock);
+
/* We have the body, now we extract the file name of the first attachment. */
if (body->nested.part && body->nested.part->next && body->nested.part->next->body.parameter->value) {
attachedfilefmt = ast_strdupa(body->nested.part->next->body.parameter->value);
@@ -1455,12 +1466,6 @@
int ret = 0;
int fold = folder_int(folder);
- /* If URGENT, then look at INBOX */
- if (fold == 11) {
- fold = NEW_FOLDER;
- urgent = 1;
- }
-
if (ast_strlen_zero(mailbox))
return 0;
@@ -1515,6 +1520,7 @@
return -1;
}
if (ret == 0) {
+ ast_mutex_lock(&vms_p->lock);
pgm = mail_newsearchpgm ();
hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailbox);
pgm->header = hdr;
@@ -1540,10 +1546,13 @@
vms_p->oldmessages = vms_p->vmArrayIndex;
/* Freeing the searchpgm also frees the searchhdr */
mail_free_searchpgm(&pgm);
+ ast_mutex_unlock(&vms_p->lock);
vms_p->updated = 0;
return vms_p->vmArrayIndex;
- } else {
+ } else {
+ ast_mutex_lock(&vms_p->lock);
mail_ping(vms_p->mailstream);
+ ast_mutex_unlock(&vms_p->lock);
}
return 0;
}
@@ -1665,8 +1674,12 @@
return -1;
}
snprintf(messagestring, sizeof(messagestring), "%ld", sendvms->msgArray[msgnum]);
- if ((mail_copy(sendvms->mailstream, messagestring, (char *) mbox(imbox)) == T))
+ ast_mutex_lock(&sendvms->lock);
+ if ((mail_copy(sendvms->mailstream, messagestring, (char *) mbox(imbox)) == T)) {
+ ast_mutex_unlock(&sendvms->lock);
return 0;
+ }
+ ast_mutex_unlock(&sendvms->lock);
ast_log(LOG_WARNING, "Unable to copy message from mailbox %s to mailbox %s\n", vmu->mailbox, recip->mailbox);
return -1;
}
@@ -1802,6 +1815,7 @@
check_quota(vms,(char *)mbox(box));
}
+ ast_mutex_lock(&vms->lock);
pgm = mail_newsearchpgm();
/* Check IMAP folder for Asterisk messages only... */
@@ -1833,6 +1847,7 @@
vms->lastmsg = vms->vmArrayIndex - 1;
mail_free_searchpgm(&pgm);
+ ast_mutex_unlock(&vms->lock);
return 0;
}
@@ -1841,9 +1856,9 @@
FILE *output;
output = fopen (filename, "w");
- if (fwrite(buffer, len, 1, output) < len) {
+ if (fwrite(buffer, len, 1, output) != 1) {
if (ferror(output)) {
- ast_log(LOG_ERROR, "Short write while writing e-mail body.\n");
+ ast_log(LOG_ERROR, "Short write while writing e-mail body: %s.\n", strerror(errno));
}
}
fclose (output);
@@ -2319,7 +2334,9 @@
if (!body || body == NIL)
return -1;
+ ast_mutex_lock(&vms->lock);
body_content = mail_fetchbody (vms->mailstream, vms->msgArray[vms->curmsg], section, &len);
+ ast_mutex_unlock(&vms->lock);
if (body_content != NIL) {
snprintf(filename, sizeof(filename), "%s.%s", vms->fn, format);
/* ast_log (LOG_DEBUG,body_content); */
@@ -2334,6 +2351,7 @@
*
* Determines the delimiter character that is used by the underlying IMAP based mail store.
*/
+/* MUTEX should already be held */
static void get_mailbox_delimiter(MAILSTREAM *stream) {
char tmp[50];
snprintf(tmp, sizeof(tmp), "{%s}", imapserver);
@@ -2348,6 +2366,7 @@
* Calls imap_getquotaroot, which will populate its results into the vm_state vms input structure.
*/
static void check_quota(struct vm_state *vms, char *mailbox) {
+ ast_mutex_lock(&vms->lock);
mail_parameters(NULL, SET_QUOTA, (void *) mm_parsequota);
ast_debug(3, "Mailbox name set to: %s, about to check quotas\n", mailbox);
if (vms && vms->mailstream != NULL) {
@@ -2355,6 +2374,7 @@
} else {
ast_log(LOG_WARNING, "Mailstream not available for mailbox: %s\n", mailbox);
}
+ ast_mutex_unlock(&vms->lock);
}
#endif /* IMAP_STORAGE */
@@ -4595,17 +4615,23 @@
/* simple. huh? */
char sequence[10];
char mailbox[256];
+ int res;
+
/* get the real IMAP message number for this message */
snprintf(sequence, sizeof(sequence), "%ld", vms->msgArray[msg]);
ast_debug(3, "Copying sequence %s to mailbox %s\n", sequence, mbox(box));
+ ast_mutex_lock(&vms->lock);
+
if (box == OLD_FOLDER) {
mail_setflag(vms->mailstream, sequence, "\\Seen");
} else if (box == NEW_FOLDER) {
mail_clearflag(vms->mailstream, sequence, "\\Seen");
}
- if (!strcasecmp(mbox(NEW_FOLDER), vms->curbox) && (box == NEW_FOLDER || box == OLD_FOLDER))
+ if (!strcasecmp(mbox(NEW_FOLDER), vms->curbox) && (box == NEW_FOLDER || box == OLD_FOLDER)) {
+ ast_mutex_unlock(&vms->lock);
return 0;
+ }
/* Create the folder if it don't exist */
imap_mailbox_name(mailbox, sizeof(mailbox), vms, box, 1); /* Get the full mailbox name */
ast_debug(5, "Checking if folder exists: %s\n",mailbox);
@@ -4613,7 +4639,9 @@
ast_debug(5, "Folder exists.\n");
else
ast_log(LOG_NOTICE, "Folder %s created!\n",mbox(box));
- return !mail_copy(vms->mailstream, sequence, (char *)mbox(box));
+ res = !mail_copy(vms->mailstream, sequence, (char *)mbox(box));
+ ast_mutex_unlock(&vms->lock);
+ return res;
#else
char *dir = vms->curdir;
char *username = vms->username;
@@ -5967,7 +5995,8 @@
ast_log(LOG_ERROR, "Failed to procure file name from directory passed. You should never see this.\n");
return -1;
}
-
+
+ ast_mutex_lock(&vms->lock);
for (i = 0; i < vms->mailstream->nmsgs; i++) {
mail_fetchstructure(vms->mailstream, i + 1, &body);
/* We have the body, now we extract the file name of the first attachment. */
@@ -5975,6 +6004,7 @@
attachment = ast_strdupa(body->nested.part->next->body.parameter->value);
} else {
ast_log(LOG_ERROR, "There is no file attached to this IMAP message.\n");
+ ast_mutex_unlock(&vms->lock);
return -1;
}
filename = strsep(&attachment, ".");
@@ -5984,6 +6014,7 @@
}
}
mail_expunge(vms->mailstream);
+ ast_mutex_unlock(&vms->lock);
return 0;
}
@@ -8186,12 +8217,14 @@
/* expunge message - use UID Expunge if supported on IMAP server*/
ast_debug(3, "*** Checking if we can expunge, deleted set to %d, expungeonhangup set to %d\n", deleted, expungeonhangup);
if (vmu && deleted == 1 && expungeonhangup == 1) {
+ ast_mutex_lock(&vms.lock);
#ifdef HAVE_IMAP_TK2006
if (LEVELUIDPLUS (vms.mailstream)) {
mail_expunge_full(vms.mailstream, NIL, EX_UID);
} else
#endif
mail_expunge(vms.mailstream);
+ ast_mutex_unlock(&vms.lock);
}
/* before we delete the state, we should copy pertinent info
* back to the persistent model */
More information about the asterisk-commits
mailing list