diff --git a/ChangeLog b/ChangeLog index 0038b6700..fadb5dcaf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2011-06-03 Wolfgang Sourdeau + * OpenChange/MAPIStoreContext.m: MAPIStoreMapping instances are + now per-user instances rather than class singletons. + + * OpenChange/MAPIStoreMapping.m: now makes use of the records + already present in indexing.tdb for building the initial mapping + dictionary. + * OpenChange/MAPIStoreSpoolerContext.[hm]: new context module, which subclasses MAPIStoreSpoolerContext from MAPIStoreFSBaseContext rather than MAPIStoreOutboxContext. diff --git a/OpenChange/MAPIStoreAttachment.m b/OpenChange/MAPIStoreAttachment.m index fb2098896..571c2fe13 100644 --- a/OpenChange/MAPIStoreAttachment.m +++ b/OpenChange/MAPIStoreAttachment.m @@ -23,6 +23,7 @@ #import #import "MAPIStoreAttachment.h" +#import "MAPIStoreContext.h" #import "MAPIStoreMapping.h" #import "MAPIStoreMessage.h" #import "MAPIStoreTypes.h" @@ -33,15 +34,8 @@ #include #include -static MAPIStoreMapping *mapping; - @implementation MAPIStoreAttachment -+ (void) initialize -{ - mapping = [MAPIStoreMapping sharedMapping]; -} - - (void) setAID: (uint32_t) newAID { aid = newAID; @@ -102,9 +96,12 @@ static MAPIStoreMapping *mapping; andFlags: (enum OpenEmbeddedMessage_OpenModeFlags) flags { MAPIStoreAttachmentMessage *attMessage; + MAPIStoreMapping *mapping; memset (mapistoreMsg, 0, sizeof (struct mapistore_message)); + mapping = [[self context] mapping]; + attMessage = [self openEmbeddedMessage]; if (attMessage) *mid = [mapping idFromURL: [attMessage url]]; diff --git a/OpenChange/MAPIStoreContext.h b/OpenChange/MAPIStoreContext.h index 5c799e9fb..16616313f 100644 --- a/OpenChange/MAPIStoreContext.h +++ b/OpenChange/MAPIStoreContext.h @@ -53,6 +53,8 @@ NSURL *contextUrl; uint64_t contextFid; + MAPIStoreMapping *mapping; + MAPIStoreAuthenticator *authenticator; WOContext *woContext; @@ -79,6 +81,7 @@ - (struct mapistore_connection_info *) connectionInfo; - (WOContext *) woContext; +- (MAPIStoreMapping *) mapping; - (void) setupRequest; - (void) tearDownRequest; diff --git a/OpenChange/MAPIStoreContext.m b/OpenChange/MAPIStoreContext.m index a6d850a15..4dbd58198 100644 --- a/OpenChange/MAPIStoreContext.m +++ b/OpenChange/MAPIStoreContext.m @@ -70,8 +70,8 @@ static Class NSDataK, NSStringK, MAPIStoreFAIMessageK; -static MAPIStoreMapping *mapping; static NSMutableDictionary *contextClassMapping; +static NSMutableDictionary *userMAPIStoreMapping; static void *ldbCtx = NULL; @@ -86,8 +86,6 @@ static void *ldbCtx = NULL; NSStringK = [NSString class]; MAPIStoreFAIMessageK = [MAPIStoreFAIMessage class]; - mapping = [MAPIStoreMapping sharedMapping]; - contextClassMapping = [NSMutableDictionary new]; classes = GSObjCAllSubclassesOfClass (self); max = [classes count]; @@ -103,6 +101,8 @@ static void *ldbCtx = NULL; NSStringFromClass (currentClass), moduleName); } } + + userMAPIStoreMapping = [NSMutableDictionary new]; } static inline MAPIStoreContext * @@ -209,7 +209,7 @@ _prepareContextClass (struct mapistore_context *newMemCtx, inMemCtx: (struct mapistore_context *) newMemCtx { struct loadparm_context *lpCtx; - MAPIStoreMapping *mapping; + NSString *username; if ((self = [self init])) { @@ -221,7 +221,15 @@ _prepareContextClass (struct mapistore_context *newMemCtx, ASSIGN (contextUrl, newUrl); - mapping = [MAPIStoreMapping sharedMapping]; + username = [NSString stringWithUTF8String: newConnInfo->username]; + mapping = [userMAPIStoreMapping objectForKey: username]; + if (!mapping) + { + [self logWithFormat: @"generating mapping of ids for user '%@'", + username]; + mapping = [MAPIStoreMapping mappingWithIndexing: newConnInfo->indexing]; + [userMAPIStoreMapping setObject: mapping forKey: username]; + } if (![mapping urlFromID: newFid]) [mapping registerURL: [newUrl absoluteString] withID: newFid]; @@ -254,6 +262,11 @@ _prepareContextClass (struct mapistore_context *newMemCtx, return woContext; } +- (MAPIStoreMapping *) mapping +{ + return mapping; +} + - (void) setAuthenticator: (MAPIStoreAuthenticator *) newAuthenticator { ASSIGN (authenticator, newAuthenticator); @@ -1332,8 +1345,6 @@ _prepareContextClass (struct mapistore_context *newMemCtx, uint64_t mappingId; uint32_t contextId; - mapping = [MAPIStoreMapping sharedMapping]; - if (key) childURL = [NSString stringWithFormat: @"%@%@", folderURL, key]; else diff --git a/OpenChange/MAPIStoreFolderTable.m b/OpenChange/MAPIStoreFolderTable.m index e492369f0..053a4d76a 100644 --- a/OpenChange/MAPIStoreFolderTable.m +++ b/OpenChange/MAPIStoreFolderTable.m @@ -23,7 +23,6 @@ #import #import "MAPIStoreFolder.h" -#import "MAPIStoreMapping.h" #import "MAPIStoreTypes.h" #import "MAPIStoreFolderTable.h" @@ -35,13 +34,6 @@ @implementation MAPIStoreFolderTable -static MAPIStoreMapping *mapping; - -+ (void) initialize -{ - mapping = [MAPIStoreMapping sharedMapping]; -} - - (id) init { if ((self = [super init])) diff --git a/OpenChange/MAPIStoreMapping.h b/OpenChange/MAPIStoreMapping.h index fa52509a3..d0e6c95ed 100644 --- a/OpenChange/MAPIStoreMapping.h +++ b/OpenChange/MAPIStoreMapping.h @@ -32,9 +32,12 @@ { NSMutableDictionary *mapping; /* FID/MID -> url */ NSMutableDictionary *reverseMapping; /* url -> FID/MID */ + struct tdb_wrap *indexing; } -+ (id) sharedMapping; ++ (id) mappingWithIndexing: (struct tdb_wrap *) indexing; + +- (id) initWithIndexing: (struct tdb_wrap *) indexing; - (NSString *) urlFromID: (uint64_t) idKey; diff --git a/OpenChange/MAPIStoreMapping.m b/OpenChange/MAPIStoreMapping.m index 4b01bcd5d..0636862e7 100644 --- a/OpenChange/MAPIStoreMapping.m +++ b/OpenChange/MAPIStoreMapping.m @@ -28,22 +28,15 @@ #import +#import "MAPIStoreTypes.h" + #import "MAPIStoreMapping.h" -#include -#include #include +#include +#include -struct tdb_wrap { - struct tdb_context *tdb; - - const char *name; - struct tdb_wrap *next, *prev; -}; - -extern struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, - const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode); +@implementation MAPIStoreMapping static int MAPIStoreMappingTDBTraverse (TDB_CONTEXT *ctx, TDB_DATA data1, TDB_DATA data2, @@ -59,7 +52,7 @@ MAPIStoreMappingTDBTraverse (TDB_CONTEXT *ctx, TDB_DATA data1, TDB_DATA data2, idVal = strtoll (idStr, NULL, 16); idNbr = [NSNumber numberWithUnsignedLongLong: idVal]; - uriStr = strdup ((const char *) data2.dptr); + uriStr = strndup ((const char *) data2.dptr, data2.dsize); *(uriStr+(data2.dsize)) = 0; uri = [NSString stringWithUTF8String: uriStr]; free (uriStr); @@ -70,47 +63,39 @@ MAPIStoreMappingTDBTraverse (TDB_CONTEXT *ctx, TDB_DATA data1, TDB_DATA data2, return 0; } -static void -MAPIStoreMappingInitDictionary (NSMutableDictionary *mapping) ++ (id) mappingWithIndexing: (struct tdb_wrap *) indexing { - struct tdb_wrap *wrap; - TDB_CONTEXT *context; - char *tdb_path; + id newMapping; - tdb_path = "/usr/local/samba/private/mapistore/openchange/indexing.tdb"; - wrap = tdb_wrap_open(NULL, tdb_path, 0, TDB_NOLOCK, O_RDONLY, 0600); - if (wrap) - { - context = wrap->tdb; - tdb_traverse_read(wrap->tdb, MAPIStoreMappingTDBTraverse, mapping); - } -} + newMapping = [[self alloc] initWithIndexing: indexing]; + [newMapping autorelease]; -@implementation MAPIStoreMapping - -+ (id) sharedMapping -{ - static id sharedMapping = nil; - - if (!sharedMapping) - sharedMapping = [self new]; - - return sharedMapping; + return newMapping; } - (id) init +{ + if ((self = [super init])) + { + mapping = [NSMutableDictionary new]; + reverseMapping = [NSMutableDictionary new]; + indexing = NULL; + } + + return self; +} + +- (id) initWithIndexing: (struct tdb_wrap *) newIndexing { NSNumber *idNbr; NSString *uri; NSArray *keys; NSUInteger count, max; - if ((self = [super init])) + if ((self = [self init])) { - mapping = [NSMutableDictionary new]; - MAPIStoreMappingInitDictionary (mapping); - reverseMapping = [NSMutableDictionary new]; - + indexing = newIndexing; + tdb_traverse_read (indexing->tdb, MAPIStoreMappingTDBTraverse, mapping); keys = [mapping allKeys]; max = [keys count]; for (count = 0; count < max; count++) @@ -144,7 +129,7 @@ MAPIStoreMappingInitDictionary (NSMutableDictionary *mapping) { NSNumber *idKey; uint64_t idNbr; - + idKey = [reverseMapping objectForKey: url]; if (idKey) idNbr = [idKey unsignedLongLongValue]; @@ -159,13 +144,16 @@ MAPIStoreMappingInitDictionary (NSMutableDictionary *mapping) { NSNumber *idKey; BOOL rc; + TDB_DATA key, dbuf; idKey = [NSNumber numberWithUnsignedLongLong: idNbr]; if ([mapping objectForKey: idKey] || [reverseMapping objectForKey: urlString]) { - [self errorWithFormat: @"attempt to double register an entry ('%@', %lld)", - urlString, idNbr]; + [self errorWithFormat: + @"attempt to double register an entry ('%@', %lld," + @" 0x%.16"PRIx64")", + urlString, idNbr, idNbr]; rc = NO; } else @@ -173,8 +161,18 @@ MAPIStoreMappingInitDictionary (NSMutableDictionary *mapping) [mapping setObject: urlString forKey: idKey]; [reverseMapping setObject: idKey forKey: urlString]; rc = YES; - [self logWithFormat: @"registered url '%@' with id %lld (0x%.8x)", - urlString, idNbr, (uint32_t) idNbr]; + [self logWithFormat: @"registered url '%@' with id %lld (0x%.16"PRIx64")", + urlString, idNbr, idNbr]; + + /* Add the record given its fid and mapistore_uri */ + key.dptr = (unsigned char *) talloc_asprintf(NULL, "0x%.16"PRIx64, idNbr); + key.dsize = strlen((const char *) key.dptr); + + dbuf.dptr = (unsigned char *) talloc_strdup(NULL, [urlString UTF8String]); + dbuf.dsize = strlen((const char *) dbuf.dptr); + tdb_store (indexing->tdb, key, dbuf, TDB_INSERT); + talloc_free (key.dptr); + talloc_free (dbuf.dptr); } return rc; diff --git a/OpenChange/MAPIStoreMessageTable.m b/OpenChange/MAPIStoreMessageTable.m index 057010768..f54f9d61b 100644 --- a/OpenChange/MAPIStoreMessageTable.m +++ b/OpenChange/MAPIStoreMessageTable.m @@ -26,7 +26,6 @@ #import #import "MAPIStoreFolder.h" -#import "MAPIStoreMapping.h" #import "MAPIStoreTypes.h" #import "NSData+MAPIStore.h" #import "NSString+MAPIStore.h" @@ -35,13 +34,6 @@ @implementation MAPIStoreMessageTable -static MAPIStoreMapping *mapping; - -+ (void) initialize -{ - mapping = [MAPIStoreMapping sharedMapping]; -} - - (void) setSortOrder: (const struct SSortOrderSet *) set { [self logWithFormat: @"unimplemented method: %@", NSStringFromSelector (_cmd)];