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;
/* move & copy operations */
- (void) copyToAttachment: (MAPIStoreAttachment *) newAttachment;
- (void) copyToAttachment: (MAPIStoreAttachment *) newAttachment inMemCtx: (TALLOC_CTX *) memCtx;
/* subclasses */
- (MAPIStoreEmbeddedMessage *) openEmbeddedMessage;

View File

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

View File

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

View File

@ -123,7 +123,8 @@
fromFolder: (MAPIStoreFolder *) sourceFolder
withMIDs: (uint64_t *) targetMids
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
withNewName: (NSString *) newFolderName

View File

@ -180,6 +180,8 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
- (void) dealloc
{
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
// [messageKeys release];
// [faiMessageKeys release];
// [folderKeys release];
@ -656,19 +658,23 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
return rc;
}
- (int) moveCopyMessageWithMID: (uint64_t) srcMid
fromFolder: (MAPIStoreFolder *) sourceFolder
withMID: (uint64_t) targetMid
andChangeKey: (struct Binary_r *) targetChangeKey
wantCopy: (uint8_t) wantCopy
// private method
- (int) _moveCopyMessageWithMID: (uint64_t) srcMid
fromFolder: (MAPIStoreFolder *) sourceFolder
withMID: (uint64_t) targetMid
andChangeKey: (struct Binary_r *) targetChangeKey
wantCopy: (uint8_t) wantCopy
inMemCtx: (TALLOC_CTX *) memCtx
{
int rc;
MAPIStoreMessage *sourceMsg, *destMsg;
TALLOC_CTX *memCtx;
//TALLOC_CTX *memCtx;
struct SRow aRow;
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
withMID: srcMid
forWriting: NO
@ -681,7 +687,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
if (rc != MAPISTORE_SUCCESS)
goto end;
[sourceMsg copyToMessage: destMsg];
[sourceMsg copyToMessage: destMsg inMemCtx: memCtx];
if (targetChangeKey)
{
@ -698,7 +704,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
rc = [sourceFolder deleteMessageWithMID: srcMid andFlags: 0];
end:
talloc_free (memCtx);
//talloc_free (memCtx);
return rc;
}
@ -709,6 +715,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
withMIDs: (uint64_t *) targetMids
andChangeKeys: (struct Binary_r **) targetChangeKeys
wantCopy: (uint8_t) wantCopy
inMemCtx: (TALLOC_CTX *) memCtx
{
int rc = MAPISTORE_SUCCESS;
NSUInteger count;
@ -717,6 +724,9 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
MAPIStoreMapping *mapping;
SOGoUser *ownerUser;
struct Binary_r *targetChangeKey;
//TALLOC_CTX *memCtx;
//memCtx = talloc_zero (NULL, TALLOC_CTX);
ownerUser = [[self userContext] sogoUser];
@ -738,11 +748,12 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
targetChangeKey = targetChangeKeys[count];
else
targetChangeKey = NULL;
rc = [self moveCopyMessageWithMID: srcMids[count]
fromFolder: sourceFolder
withMID: targetMids[count]
andChangeKey: targetChangeKey
wantCopy: wantCopy];
rc = [self _moveCopyMessageWithMID: srcMids[count]
fromFolder: sourceFolder
withMID: targetMids[count]
andChangeKey: targetChangeKey
wantCopy: wantCopy
inMemCtx: memCtx];
}
else
rc = MAPISTORE_ERR_NOT_FOUND;
@ -765,7 +776,9 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
}
else
rc = MAPISTORE_ERR_DENIED;
//talloc_free (memCtx);
return rc;
}
@ -785,6 +798,9 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
NSUInteger count, max;
NSString *childKey;
uint64_t fmid;
TALLOC_CTX *memCtx;
memCtx = talloc_zero (NULL, TALLOC_CTX);
/* 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
@ -807,7 +823,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
if (rc == MAPISTORE_SUCCESS)
{
newFolder = [targetFolder lookupFolder: childKey];
[self copyPropertiesToObject: newFolder];
[self copyPropertiesToObject: newFolder inMemCtx: memCtx];
pool = [NSAutoreleasePool new];
children = [self messageKeys];
@ -818,7 +834,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
message = [self lookupMessage: childKey];
targetMessage = [newFolder createMessage: NO];
[targetMessage setIsNew: YES];
[message copyToMessage: targetMessage];
[message copyToMessage: targetMessage inMemCtx: memCtx];
if (isMove)
{
fmid = [mapping idFromURL: [message url]];
@ -839,7 +855,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
message = [self lookupFAIMessage: childKey];
targetMessage = [newFolder createMessage: YES];
[targetMessage setIsNew: YES];
[message copyToMessage: targetMessage];
[message copyToMessage: targetMessage inMemCtx: memCtx];
if (isMove)
{
fmid = [mapping idFromURL: [message url]];
@ -882,6 +898,8 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe
else
rc = MAPISTORE_ERR_DENIED;
talloc_free (memCtx);
return rc;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -317,9 +317,9 @@ static Class NSExceptionK, MAPIStoreFolderK;
}
/* 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 SRow row;
enum MAPITAGS propTag;
@ -328,7 +328,7 @@ static Class NSExceptionK, MAPIStoreFolderK;
enum mapistore_error error;
void *data;
memCtx = talloc_zero (NULL, TALLOC_CTX);
//memCtx = talloc_zero (NULL, TALLOC_CTX);
[self getAvailableProperties: &availableProps inMemCtx: memCtx];
@ -369,8 +369,7 @@ static Class NSExceptionK, MAPIStoreFolderK;
}
[newObject addPropertiesFromRow: &row];
talloc_free (memCtx);
//talloc_free (memCtx);
}
/* subclasses */

View File

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

View File

@ -50,7 +50,8 @@ MAPIStoreTallocWrapperDestroy (void *data)
GSRegisterCurrentThread ();
pool = [NSAutoreleasePool new];
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];
[pool release];
GSUnregisterCurrentThread ();
@ -66,7 +67,7 @@ MAPIStoreTallocWrapperDestroy (void *data)
talloc_set_destructor ((void *) wrapper, MAPIStoreTallocWrapperDestroy);
wrapper->instance = self;
[self retain];
// NSLog (@"returning wrapper: %p; object: %p", wrapper, self);
NSLog (@"returning wrapper: %p; object: %p", wrapper, self);
return wrapper;
}