move_copy_messages now uses the openchange's memory context.

This fixes strange crashes when dealing with invitations and
other stuff. More work will need to be done in this regard. Also
kept the old code just in case for now. Will be cleaned up shortly
after more people test it.
pull/7/head
Ludovic Marcotte 2012-12-03 09:18:17 -05:00
parent 5500f99312
commit 2017536beb
12 changed files with 75 additions and 41 deletions

View File

@ -48,7 +48,7 @@
- (NSData *) mimeAttachTag; - (NSData *) mimeAttachTag;
/* move & copy operations */ /* move & copy operations */
- (void) copyToAttachment: (MAPIStoreAttachment *) newAttachment; - (void) copyToAttachment: (MAPIStoreAttachment *) newAttachment inMemCtx: (TALLOC_CTX *) memCtx;
/* subclasses */ /* subclasses */
- (MAPIStoreEmbeddedMessage *) openEmbeddedMessage; - (MAPIStoreEmbeddedMessage *) openEmbeddedMessage;

View File

@ -152,13 +152,13 @@
return ULLONG_MAX; return ULLONG_MAX;
} }
- (void) copyToAttachment: (MAPIStoreAttachment *) newAttachment - (void) copyToAttachment: (MAPIStoreAttachment *) newAttachment inMemCtx: (TALLOC_CTX *) memCtx
{ {
void *attachMethod; void *attachMethod;
enum mapistore_error error; enum mapistore_error error;
MAPIStoreEmbeddedMessage *embeddedMessage, *newEmbeddedMessage; MAPIStoreEmbeddedMessage *embeddedMessage, *newEmbeddedMessage;
[self copyPropertiesToObject: newAttachment]; [self copyPropertiesToObject: newAttachment inMemCtx: memCtx];
attachMethod = NULL; attachMethod = NULL;
error = [self getProperty: &attachMethod error = [self getProperty: &attachMethod
@ -170,7 +170,7 @@
{ {
embeddedMessage = [self openEmbeddedMessage]; embeddedMessage = [self openEmbeddedMessage];
newEmbeddedMessage = [newAttachment createEmbeddedMessage]; newEmbeddedMessage = [newAttachment createEmbeddedMessage];
[embeddedMessage copyToMessage: newEmbeddedMessage]; [embeddedMessage copyToMessage: newEmbeddedMessage inMemCtx: memCtx];
} }
talloc_free (attachMethod); talloc_free (attachMethod);
} }

View File

@ -63,6 +63,8 @@
SOGoAppointmentObject *newEntry; SOGoAppointmentObject *newEntry;
NSString *name; NSString *name;
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
name = [NSString stringWithFormat: @"%@.ics", name = [NSString stringWithFormat: @"%@.ics",
[SOGoObject globallyUniqueObjectId]]; [SOGoObject globallyUniqueObjectId]];
newEntry = [SOGoAppointmentObject objectWithName: name newEntry = [SOGoAppointmentObject objectWithName: name

View File

@ -123,7 +123,8 @@
fromFolder: (MAPIStoreFolder *) sourceFolder fromFolder: (MAPIStoreFolder *) sourceFolder
withMIDs: (uint64_t *) targetMids withMIDs: (uint64_t *) targetMids
andChangeKeys: (struct Binary_r **) targetChangeKeys andChangeKeys: (struct Binary_r **) targetChangeKeys
wantCopy: (uint8_t) want_copy; wantCopy: (uint8_t) want_copy
inMemCtx: (TALLOC_CTX *) memCtx;
- (enum mapistore_error) moveCopyToFolder: (MAPIStoreFolder *) targetFolder - (enum mapistore_error) moveCopyToFolder: (MAPIStoreFolder *) targetFolder
withNewName: (NSString *) newFolderName withNewName: (NSString *) newFolderName

View File

@ -180,6 +180,8 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
- (void) dealloc - (void) dealloc
{ {
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
// [messageKeys release]; // [messageKeys release];
// [faiMessageKeys release]; // [faiMessageKeys release];
// [folderKeys release]; // [folderKeys release];
@ -656,19 +658,23 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
return rc; return rc;
} }
- (int) moveCopyMessageWithMID: (uint64_t) srcMid // private method
fromFolder: (MAPIStoreFolder *) sourceFolder - (int) _moveCopyMessageWithMID: (uint64_t) srcMid
withMID: (uint64_t) targetMid fromFolder: (MAPIStoreFolder *) sourceFolder
andChangeKey: (struct Binary_r *) targetChangeKey withMID: (uint64_t) targetMid
wantCopy: (uint8_t) wantCopy andChangeKey: (struct Binary_r *) targetChangeKey
wantCopy: (uint8_t) wantCopy
inMemCtx: (TALLOC_CTX *) memCtx
{ {
int rc; int rc;
MAPIStoreMessage *sourceMsg, *destMsg; MAPIStoreMessage *sourceMsg, *destMsg;
TALLOC_CTX *memCtx; //TALLOC_CTX *memCtx;
struct SRow aRow; struct SRow aRow;
struct SPropValue property; struct SPropValue property;
memCtx = talloc_zero (NULL, TALLOC_CTX); [self logWithFormat: @"-moveCopyMessageWithMID: 0x%.16llx .. withMID: 0x%.16llx .. wantCopy: %d", srcMid, targetMid, wantCopy];
//memCtx = talloc_zero (NULL, TALLOC_CTX);
rc = [sourceFolder openMessage: &sourceMsg rc = [sourceFolder openMessage: &sourceMsg
withMID: srcMid withMID: srcMid
forWriting: NO forWriting: NO
@ -681,7 +687,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
if (rc != MAPISTORE_SUCCESS) if (rc != MAPISTORE_SUCCESS)
goto end; goto end;
[sourceMsg copyToMessage: destMsg]; [sourceMsg copyToMessage: destMsg inMemCtx: memCtx];
if (targetChangeKey) if (targetChangeKey)
{ {
@ -698,7 +704,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
rc = [sourceFolder deleteMessageWithMID: srcMid andFlags: 0]; rc = [sourceFolder deleteMessageWithMID: srcMid andFlags: 0];
end: end:
talloc_free (memCtx); //talloc_free (memCtx);
return rc; return rc;
} }
@ -709,6 +715,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
withMIDs: (uint64_t *) targetMids withMIDs: (uint64_t *) targetMids
andChangeKeys: (struct Binary_r **) targetChangeKeys andChangeKeys: (struct Binary_r **) targetChangeKeys
wantCopy: (uint8_t) wantCopy wantCopy: (uint8_t) wantCopy
inMemCtx: (TALLOC_CTX *) memCtx
{ {
int rc = MAPISTORE_SUCCESS; int rc = MAPISTORE_SUCCESS;
NSUInteger count; NSUInteger count;
@ -717,6 +724,9 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
MAPIStoreMapping *mapping; MAPIStoreMapping *mapping;
SOGoUser *ownerUser; SOGoUser *ownerUser;
struct Binary_r *targetChangeKey; struct Binary_r *targetChangeKey;
//TALLOC_CTX *memCtx;
//memCtx = talloc_zero (NULL, TALLOC_CTX);
ownerUser = [[self userContext] sogoUser]; ownerUser = [[self userContext] sogoUser];
@ -738,11 +748,12 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
targetChangeKey = targetChangeKeys[count]; targetChangeKey = targetChangeKeys[count];
else else
targetChangeKey = NULL; targetChangeKey = NULL;
rc = [self moveCopyMessageWithMID: srcMids[count] rc = [self _moveCopyMessageWithMID: srcMids[count]
fromFolder: sourceFolder fromFolder: sourceFolder
withMID: targetMids[count] withMID: targetMids[count]
andChangeKey: targetChangeKey andChangeKey: targetChangeKey
wantCopy: wantCopy]; wantCopy: wantCopy
inMemCtx: memCtx];
} }
else else
rc = MAPISTORE_ERR_NOT_FOUND; rc = MAPISTORE_ERR_NOT_FOUND;
@ -766,6 +777,8 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
else else
rc = MAPISTORE_ERR_DENIED; rc = MAPISTORE_ERR_DENIED;
//talloc_free (memCtx);
return rc; return rc;
} }
@ -785,6 +798,9 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
NSUInteger count, max; NSUInteger count, max;
NSString *childKey; NSString *childKey;
uint64_t fmid; uint64_t fmid;
TALLOC_CTX *memCtx;
memCtx = talloc_zero (NULL, TALLOC_CTX);
/* TODO: one possible issue with this algorithm is that moved messages will /* TODO: one possible issue with this algorithm is that moved messages will
lack a version number and will all be assigned a new one, even though lack a version number and will all be assigned a new one, even though
@ -807,7 +823,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
if (rc == MAPISTORE_SUCCESS) if (rc == MAPISTORE_SUCCESS)
{ {
newFolder = [targetFolder lookupFolder: childKey]; newFolder = [targetFolder lookupFolder: childKey];
[self copyPropertiesToObject: newFolder]; [self copyPropertiesToObject: newFolder inMemCtx: memCtx];
pool = [NSAutoreleasePool new]; pool = [NSAutoreleasePool new];
children = [self messageKeys]; children = [self messageKeys];
@ -818,7 +834,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
message = [self lookupMessage: childKey]; message = [self lookupMessage: childKey];
targetMessage = [newFolder createMessage: NO]; targetMessage = [newFolder createMessage: NO];
[targetMessage setIsNew: YES]; [targetMessage setIsNew: YES];
[message copyToMessage: targetMessage]; [message copyToMessage: targetMessage inMemCtx: memCtx];
if (isMove) if (isMove)
{ {
fmid = [mapping idFromURL: [message url]]; fmid = [mapping idFromURL: [message url]];
@ -839,7 +855,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
message = [self lookupFAIMessage: childKey]; message = [self lookupFAIMessage: childKey];
targetMessage = [newFolder createMessage: YES]; targetMessage = [newFolder createMessage: YES];
[targetMessage setIsNew: YES]; [targetMessage setIsNew: YES];
[message copyToMessage: targetMessage]; [message copyToMessage: targetMessage inMemCtx: memCtx];
if (isMove) if (isMove)
{ {
fmid = [mapping idFromURL: [message url]]; fmid = [mapping idFromURL: [message url]];
@ -882,6 +898,8 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
else else
rc = MAPISTORE_ERR_DENIED; rc = MAPISTORE_ERR_DENIED;
talloc_free (memCtx);
return rc; return rc;
} }

View File

@ -929,6 +929,8 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP)
withMIDs: (uint64_t *) targetMids withMIDs: (uint64_t *) targetMids
andChangeKeys: (struct Binary_r **) targetChangeKeys andChangeKeys: (struct Binary_r **) targetChangeKeys
wantCopy: (uint8_t) wantCopy wantCopy: (uint8_t) wantCopy
inMemCtx: (TALLOC_CTX *) memCtx
{ {
NGImap4Connection *connection; NGImap4Connection *connection;
NGImap4Client *client; NGImap4Client *client;
@ -946,7 +948,8 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP)
return [super moveCopyMessagesWithMIDs: srcMids andCount: midCount return [super moveCopyMessagesWithMIDs: srcMids andCount: midCount
fromFolder: sourceFolder withMIDs: targetMids fromFolder: sourceFolder withMIDs: targetMids
andChangeKeys: targetChangeKeys andChangeKeys: targetChangeKeys
wantCopy: wantCopy]; wantCopy: wantCopy
inMemCtx: memCtx];
/* Conversion of mids to IMAP uids */ /* Conversion of mids to IMAP uids */
mapping = [self mapping]; mapping = [self mapping];

View File

@ -71,7 +71,7 @@
- (NSArray *) activeUserRoles; - (NSArray *) activeUserRoles;
/* move & copy internal ops */ /* move & copy internal ops */
- (void) copyToMessage: (MAPIStoreMessage *) newMessage; - (void) copyToMessage: (MAPIStoreMessage *) newMessage inMemCtx: (TALLOC_CTX *) memCtx;
/* subclasses */ /* subclasses */
- (void) save; - (void) save;

View File

@ -139,6 +139,8 @@ rtf2html (NSData *compressedRTF)
- (id) init - (id) init
{ {
[self logWithFormat: @"METHOD '%s' (%d) (%d)", __FUNCTION__, __LINE__, self];
if ((self = [super init])) if ((self = [super init]))
{ {
attachmentParts = [NSMutableDictionary new]; attachmentParts = [NSMutableDictionary new];
@ -151,6 +153,7 @@ rtf2html (NSData *compressedRTF)
- (void) dealloc - (void) dealloc
{ {
[self logWithFormat: @"METHOD '%s' (%d) (%d)", __FUNCTION__, __LINE__, self];
[activeUserRoles release]; [activeUserRoles release];
[attachmentKeys release]; [attachmentKeys release];
[attachmentParts release]; [attachmentParts release];
@ -437,17 +440,19 @@ rtf2html (NSData *compressedRTF)
andType: MAPISTORE_MESSAGE_TABLE]; andType: MAPISTORE_MESSAGE_TABLE];
} }
- (void) copyToMessage: (MAPIStoreMessage *) newMessage - (void) copyToMessage: (MAPIStoreMessage *) newMessage inMemCtx: (TALLOC_CTX *) memCtx;
{ {
TALLOC_CTX *memCtx; //TALLOC_CTX *memCtx;
struct mapistore_message *messageData; struct mapistore_message *messageData;
NSArray *keys; NSArray *keys;
NSUInteger count, max; NSUInteger count, max;
NSString *key; NSString *key;
MAPIStoreAttachment *attachment, *newAttachment; MAPIStoreAttachment *attachment, *newAttachment;
memCtx = talloc_zero (NULL, TALLOC_CTX); [self logWithFormat: @"METHOD '%s' (%d) (%d)", __FUNCTION__, __LINE__, self];
//memCtx = talloc_zero (NULL, TALLOC_CTX);
/* message headers and recipients */ /* message headers and recipients */
[self getMessageData: &messageData inMemCtx: memCtx]; [self getMessageData: &messageData inMemCtx: memCtx];
@ -456,7 +461,7 @@ rtf2html (NSData *compressedRTF)
andColumns: messageData->columns]; andColumns: messageData->columns];
/* properties */ /* properties */
[self copyPropertiesToObject: newMessage]; [self copyPropertiesToObject: newMessage inMemCtx: memCtx];
/* attachments */ /* attachments */
keys = [self attachmentKeys]; keys = [self attachmentKeys];
@ -466,10 +471,10 @@ rtf2html (NSData *compressedRTF)
key = [keys objectAtIndex: count]; key = [keys objectAtIndex: count];
attachment = [self lookupAttachment: key]; attachment = [self lookupAttachment: key];
newAttachment = [newMessage createAttachment]; newAttachment = [newMessage createAttachment];
[attachment copyToAttachment: newAttachment]; [attachment copyToAttachment: newAttachment inMemCtx: memCtx];
} }
talloc_free (memCtx); //talloc_free (memCtx);
} }
- (enum mapistore_error) saveMessage - (enum mapistore_error) saveMessage
@ -485,6 +490,8 @@ rtf2html (NSData *compressedRTF)
BOOL userIsOwner; BOOL userIsOwner;
MAPIStoreMessage *mainMessage; MAPIStoreMessage *mainMessage;
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
context = [self context]; context = [self context];
ownerUser = [[self userContext] sogoUser]; ownerUser = [[self userContext] sogoUser];
userIsOwner = [[context activeUser] isEqual: ownerUser]; userIsOwner = [[context activeUser] isEqual: ownerUser];

View File

@ -91,7 +91,7 @@
inMemCtx: (TALLOC_CTX *) memCtx; inMemCtx: (TALLOC_CTX *) memCtx;
/* move and copy operations */ /* move and copy operations */
- (void) copyPropertiesToObject: (MAPIStoreObject *) newObject; - (void) copyPropertiesToObject: (MAPIStoreObject *) newObject inMemCtx: (TALLOC_CTX *) memCtx;
/* subclasses */ /* subclasses */
- (NSString *) nameInContainer; - (NSString *) nameInContainer;

View File

@ -317,9 +317,9 @@ static Class NSExceptionK, MAPIStoreFolderK;
} }
/* move and copy operations */ /* move and copy operations */
- (void) copyPropertiesToObject: (MAPIStoreObject *) newObject - (void) copyPropertiesToObject: (MAPIStoreObject *) newObject inMemCtx: (TALLOC_CTX *) memCtx
{ {
TALLOC_CTX *memCtx; //TALLOC_CTX *memCtx;
struct SPropTagArray *availableProps; struct SPropTagArray *availableProps;
struct SRow row; struct SRow row;
enum MAPITAGS propTag; enum MAPITAGS propTag;
@ -328,7 +328,7 @@ static Class NSExceptionK, MAPIStoreFolderK;
enum mapistore_error error; enum mapistore_error error;
void *data; void *data;
memCtx = talloc_zero (NULL, TALLOC_CTX); //memCtx = talloc_zero (NULL, TALLOC_CTX);
[self getAvailableProperties: &availableProps inMemCtx: memCtx]; [self getAvailableProperties: &availableProps inMemCtx: memCtx];
@ -369,8 +369,7 @@ static Class NSExceptionK, MAPIStoreFolderK;
} }
[newObject addPropertiesFromRow: &row]; [newObject addPropertiesFromRow: &row];
talloc_free (memCtx); //talloc_free (memCtx);
} }
/* subclasses */ /* subclasses */

View File

@ -95,6 +95,7 @@ sogo_backend_init (void)
defaults using the system encoding rather than honouring defaults using the system encoding rather than honouring
the encoding specified in the file. */ the encoding specified in the file. */
putenv ("GNUSTEP_STRING_ENCODING=NSUTF8StringEncoding"); putenv ("GNUSTEP_STRING_ENCODING=NSUTF8StringEncoding");
//putenv ("NSZombieEnabled=YES");
[NSProcessInfo initializeWithArguments: argv [NSProcessInfo initializeWithArguments: argv
count: 1 count: 1
@ -565,7 +566,8 @@ sogo_folder_delete_message(void *folder_object, uint64_t mid, uint8_t flags)
} }
static enum mapistore_error static enum mapistore_error
sogo_folder_move_copy_messages(void *folder_object, sogo_folder_move_copy_messages(TALLOC_CTX *mem_ctx,
void *folder_object,
void *source_folder_object, void *source_folder_object,
uint32_t mid_count, uint32_t mid_count,
uint64_t *src_mids, uint64_t *t_mids, uint64_t *src_mids, uint64_t *t_mids,
@ -594,7 +596,8 @@ sogo_folder_move_copy_messages(void *folder_object,
fromFolder: sourceFolder fromFolder: sourceFolder
withMIDs: t_mids withMIDs: t_mids
andChangeKeys: target_change_keys andChangeKeys: target_change_keys
wantCopy: want_copy]; wantCopy: want_copy
inMemCtx: mem_ctx];
[pool release]; [pool release];
GSUnregisterCurrentThread (); GSUnregisterCurrentThread ();
} }

View File

@ -50,7 +50,8 @@ MAPIStoreTallocWrapperDestroy (void *data)
GSRegisterCurrentThread (); GSRegisterCurrentThread ();
pool = [NSAutoreleasePool new]; pool = [NSAutoreleasePool new];
wrapper = data; wrapper = data;
// NSLog (@"destroying wrapped object (wrapper: %p; object: %p)...\n", wrapper, wrapper->MAPIStoreSOGoObject); //NSLog (@"destroying wrapped object (wrapper: %p; object: %p)...\n", wrapper, wrapper->MAPIStoreSOGoObject);
NSLog (@"destroying wrapped object (wrapper: %p)", wrapper);
[wrapper->instance release]; [wrapper->instance release];
[pool release]; [pool release];
GSUnregisterCurrentThread (); GSUnregisterCurrentThread ();
@ -66,7 +67,7 @@ MAPIStoreTallocWrapperDestroy (void *data)
talloc_set_destructor ((void *) wrapper, MAPIStoreTallocWrapperDestroy); talloc_set_destructor ((void *) wrapper, MAPIStoreTallocWrapperDestroy);
wrapper->instance = self; wrapper->instance = self;
[self retain]; [self retain];
// NSLog (@"returning wrapper: %p; object: %p", wrapper, self); NSLog (@"returning wrapper: %p; object: %p", wrapper, self);
return wrapper; return wrapper;
} }