diff --git a/ChangeLog b/ChangeLog index 3d95262ff..5597515e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2011-03-07 Wolfgang Sourdeau + * OpenChange/MAPIStoreContext.m (_prepareContextClass): now takes + the context fid as argument. + + * OpenChange/MAPIStore*Context.m (+registerFixedMappings): removed + method, made obsolete by the fact that we now receive the context + fid during initialization. + * OpenChange/MAPIStoreFAIMessageTable.[hm]: restored class module in order to reenable proper class testing during notifications. diff --git a/OpenChange/MAPIStoreCalendarContext.m b/OpenChange/MAPIStoreCalendarContext.m index 6a5665b68..b3cbb2899 100644 --- a/OpenChange/MAPIStoreCalendarContext.m +++ b/OpenChange/MAPIStoreCalendarContext.m @@ -34,12 +34,6 @@ return @"calendar"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@calendar/" - withID: 0x190001]; -} - - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreCalendarFolder baseFolderWithURL: newURL @@ -47,12 +41,4 @@ [baseFolder retain]; } - -- (int) readCount: (uint32_t *) rowCount - ofTableType: (uint8_t) tableType - inFID: (uint64_t) fid -{ - return [super readCount: rowCount ofTableType: tableType inFID: fid]; -} - @end diff --git a/OpenChange/MAPIStoreCommonViewsContext.m b/OpenChange/MAPIStoreCommonViewsContext.m index 6b711a233..9ced47e14 100644 --- a/OpenChange/MAPIStoreCommonViewsContext.m +++ b/OpenChange/MAPIStoreCommonViewsContext.m @@ -33,10 +33,4 @@ return @"common-views"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@common-views/" - withID: 0xc0001]; -} - @end diff --git a/OpenChange/MAPIStoreContactsContext.m b/OpenChange/MAPIStoreContactsContext.m index 079564270..4a266ac30 100644 --- a/OpenChange/MAPIStoreContactsContext.m +++ b/OpenChange/MAPIStoreContactsContext.m @@ -34,12 +34,6 @@ return @"contacts"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@contacts/" - withID: 0x1a0001]; -} - - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreContactsFolder baseFolderWithURL: newURL diff --git a/OpenChange/MAPIStoreContext.h b/OpenChange/MAPIStoreContext.h index c2c4c3539..a7b408729 100644 --- a/OpenChange/MAPIStoreContext.h +++ b/OpenChange/MAPIStoreContext.h @@ -49,7 +49,8 @@ { struct mapistore_context *memCtx; - NSString *uri; + NSURL *contextUrl; + uint64_t contextFid; MAPIStoreAuthenticator *authenticator; WOContext *woContext; @@ -61,10 +62,12 @@ } + (id) contextFromURI: (const char *) newUri + andFID: (uint64_t) fid inMemCtx: (struct mapistore_context *) newMemCtx; -- (void) setURI: (NSString *) newUri - andMemCtx: (struct mapistore_context *) newMemCtx; +- (id) initFromURL: (NSURL *) newUri + andFID: (uint64_t) fid + inMemCtx: (struct mapistore_context *) newMemCtx; - (void) setAuthenticator: (MAPIStoreAuthenticator *) newAuthenticator; - (MAPIStoreAuthenticator *) authenticator; @@ -156,7 +159,6 @@ /* subclass methods */ + (NSString *) MAPIModuleName; -+ (void) registerFixedMappings: (MAPIStoreMapping *) storeMapping; - (void) setupBaseFolder: (NSURL *) newURL; /* proof of concept */ diff --git a/OpenChange/MAPIStoreContext.m b/OpenChange/MAPIStoreContext.m index b001421c3..d413361cc 100644 --- a/OpenChange/MAPIStoreContext.m +++ b/OpenChange/MAPIStoreContext.m @@ -106,7 +106,8 @@ static void *ldbCtx = NULL; static inline MAPIStoreContext * _prepareContextClass (struct mapistore_context *newMemCtx, - Class contextClass, NSURL *url) + Class contextClass, + NSURL *url, uint64_t fid) { static NSMutableDictionary *registration = nil; MAPIStoreContext *context; @@ -116,14 +117,11 @@ _prepareContextClass (struct mapistore_context *newMemCtx, registration = [NSMutableDictionary new]; if (![registration objectForKey: contextClass]) - { - [contextClass registerFixedMappings: mapping]; - [registration setObject: [NSNull null] - forKey: contextClass]; - } + [registration setObject: [NSNull null] + forKey: contextClass]; - context = [contextClass new]; - [context setURI: [url absoluteString] andMemCtx: newMemCtx]; + context = [[contextClass alloc] initFromURL: url andFID: fid + inMemCtx: newMemCtx]; [context autorelease]; authenticator = [MAPIStoreAuthenticator new]; @@ -140,6 +138,7 @@ _prepareContextClass (struct mapistore_context *newMemCtx, } + (id) contextFromURI: (const char *) newUri + andFID: (uint64_t) fid inMemCtx: (struct mapistore_context *) newMemCtx { MAPIStoreContext *context; @@ -167,7 +166,8 @@ _prepareContextClass (struct mapistore_context *newMemCtx, if (contextClass) context = _prepareContextClass (newMemCtx, contextClass, - baseURL); + baseURL, + fid); else NSLog (@"ERROR: unrecognized module name '%@'", module); } @@ -189,7 +189,7 @@ _prepareContextClass (struct mapistore_context *newMemCtx, woContext = [WOContext contextWithRequest: nil]; [woContext retain]; baseFolder = nil; - uri = nil; + contextUrl = nil; } [self logWithFormat: @"-init"]; @@ -197,6 +197,35 @@ _prepareContextClass (struct mapistore_context *newMemCtx, return self; } +- (id) initFromURL: (NSURL *) newUrl + andFID: (uint64_t) newFid + inMemCtx: (struct mapistore_context *) newMemCtx +{ + struct loadparm_context *lpCtx; + MAPIStoreMapping *mapping; + + if ((self = [self init])) + { + if (!ldbCtx) + { + lpCtx = loadparm_init (newMemCtx); + ldbCtx = mapiproxy_server_openchange_ldb_init (lpCtx); + } + + ASSIGN (contextUrl, newUrl); + + mapping = [MAPIStoreMapping sharedMapping]; + if (![mapping urlFromID: newFid]) + [mapping registerURL: [newUrl absoluteString] + withID: newFid]; + contextFid = newFid; + + memCtx = newMemCtx; + } + + return self; +} + - (void) dealloc { [self logWithFormat: @"-dealloc"]; @@ -207,26 +236,11 @@ _prepareContextClass (struct mapistore_context *newMemCtx, [woContext release]; [authenticator release]; - [uri release]; + [contextUrl release]; [super dealloc]; } -- (void) setURI: (NSString *) newUri - andMemCtx: (struct mapistore_context *) newMemCtx -{ - struct loadparm_context *lpCtx; - - if (!ldbCtx) - { - lpCtx = loadparm_init (newMemCtx); - ldbCtx = mapiproxy_server_openchange_ldb_init (lpCtx); - } - - ASSIGN (uri, newUri); - memCtx = newMemCtx; -} - - (WOContext *) woContext { return woContext; @@ -835,13 +849,14 @@ _prepareContextClass (struct mapistore_context *newMemCtx, withTableType: (uint8_t) tableType { int rc; - NSString *objectURL; + NSString *objectURL, *url; // TDB_DATA key, dbuf; + url = [contextUrl absoluteString]; objectURL = [mapping urlFromID: fmid]; if (objectURL) { - if ([objectURL hasPrefix: uri]) + if ([objectURL hasPrefix: url]) { *path = [[objectURL substringFromIndex: 7] asUnicodeInMemCtx: memCtx]; @@ -853,7 +868,7 @@ _prepareContextClass (struct mapistore_context *newMemCtx, { [self logWithFormat: @"context (%@, %@) does not contain" @" found fmid: 0x%.16x", - objectURL, uri, fmid]; + objectURL, url, fmid]; *path = NULL; rc = MAPI_E_NOT_FOUND; } @@ -1295,7 +1310,7 @@ _prepareContextClass (struct mapistore_context *newMemCtx, withFMID: (uint64_t) fmid { int rc; - NSString *currentURL; + NSString *currentURL, *url; NSMutableArray *nsFolderList; uint64_t fid; @@ -1303,15 +1318,16 @@ _prepareContextClass (struct mapistore_context *newMemCtx, rc = MAPI_E_SUCCESS; + url = [contextUrl absoluteString]; currentURL = [mapping urlFromID: fmid]; - if (currentURL && ![currentURL isEqualToString: uri] - && [currentURL hasPrefix: uri]) + if (currentURL && ![currentURL isEqualToString: url] + && [currentURL hasPrefix: url]) { nsFolderList = [NSMutableArray arrayWithCapacity: 32]; [self extractChildNameFromURL: currentURL andFolderURLAt: ¤tURL]; while (currentURL && rc == MAPI_E_SUCCESS - && ![currentURL isEqualToString: uri]) + && ![currentURL isEqualToString: url]) { fid = [mapping idFromURL: currentURL]; if (fid == NSNotFound) @@ -1329,7 +1345,7 @@ _prepareContextClass (struct mapistore_context *newMemCtx, if (rc != MAPI_E_NOT_FOUND) { - fid = [mapping idFromURL: uri]; + fid = [mapping idFromURL: url]; [nsFolderList addObject: [NSNumber numberWithUnsignedLongLong: fid]]; [self logWithFormat: @"resulting folder list: %@", nsFolderList]; *folders_list = [nsFolderList asFoldersListInCtx: memCtx]; @@ -1513,10 +1529,6 @@ _prepareContextClass (struct mapistore_context *newMemCtx, return nil; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) storeMapping -{ -} - - (void) setupBaseFolder: (NSURL *) newURL { [self subclassResponsibility: _cmd]; diff --git a/OpenChange/MAPIStoreDeferredActionsContext.m b/OpenChange/MAPIStoreDeferredActionsContext.m index e31546842..02bd8699b 100644 --- a/OpenChange/MAPIStoreDeferredActionsContext.m +++ b/OpenChange/MAPIStoreDeferredActionsContext.m @@ -33,10 +33,4 @@ return @"deferred-actions"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@deferred-actions/" - withID: 0xb0001]; -} - @end diff --git a/OpenChange/MAPIStoreFreebusyContext.m b/OpenChange/MAPIStoreFreebusyContext.m index 77b5d21b6..ea506e5fc 100644 --- a/OpenChange/MAPIStoreFreebusyContext.m +++ b/OpenChange/MAPIStoreFreebusyContext.m @@ -37,25 +37,4 @@ return @"freebusy"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@freebusy/" - withID: 0x70001]; -} - -// - (void) setupModuleFolder -// { -// SOGoUserFolder *userFolder; - -// userFolder = [SOGoUserFolder objectWithName: [authenticator username] -// inContainer: MAPIApp]; -// [parentFoldersBag addObject: userFolder]; -// [woContext setClientObject: userFolder]; - -// moduleFolder = [userFolder lookupName: @"Calendar" -// inContext: woContext -// acquire: NO]; -// [moduleFolder retain]; -// } - @end diff --git a/OpenChange/MAPIStoreJournalContext.m b/OpenChange/MAPIStoreJournalContext.m index 7982c2f21..309fd56d2 100644 --- a/OpenChange/MAPIStoreJournalContext.m +++ b/OpenChange/MAPIStoreJournalContext.m @@ -33,10 +33,4 @@ return @"journal"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@journal/" - withID: 0x1b0001]; -} - @end diff --git a/OpenChange/MAPIStoreMailContext.m b/OpenChange/MAPIStoreMailContext.m index 22d84cb01..8c94c3015 100644 --- a/OpenChange/MAPIStoreMailContext.m +++ b/OpenChange/MAPIStoreMailContext.m @@ -43,12 +43,6 @@ return @"inbox"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@inbox/" - withID: 0x160001]; -} - - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreInboxFolder baseFolderWithURL: newURL @@ -65,12 +59,6 @@ return @"sent-items"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@sent-items/" - withID: 0x140001]; -} - - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreSentItemsFolder baseFolderWithURL: newURL @@ -87,12 +75,6 @@ return @"drafts"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@inbox/" - withID: 0x1e0001]; -} - - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreDraftsFolder baseFolderWithURL: newURL @@ -109,12 +91,6 @@ return @"deleted-items"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@deleted-items/" - withID: 0x170001]; -} - - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreDeletedItemsFolder baseFolderWithURL: newURL @@ -131,12 +107,6 @@ return @"outbox"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@outbox/" - withID: 0x150001]; -} - - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreOutboxFolder baseFolderWithURL: newURL @@ -150,13 +120,7 @@ + (NSString *) MAPIModuleName { - return @"spooler"; -} - -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@spooler/" - withID: 0x120001]; + return @"spooler-queue"; } @end diff --git a/OpenChange/MAPIStoreMapping.m b/OpenChange/MAPIStoreMapping.m index d600728f4..4b01bcd5d 100644 --- a/OpenChange/MAPIStoreMapping.m +++ b/OpenChange/MAPIStoreMapping.m @@ -76,14 +76,14 @@ MAPIStoreMappingInitDictionary (NSMutableDictionary *mapping) struct tdb_wrap *wrap; TDB_CONTEXT *context; char *tdb_path; - int rc; tdb_path = "/usr/local/samba/private/mapistore/openchange/indexing.tdb"; wrap = tdb_wrap_open(NULL, tdb_path, 0, TDB_NOLOCK, O_RDONLY, 0600); - - context = wrap->tdb; - rc = tdb_traverse_read(wrap->tdb, MAPIStoreMappingTDBTraverse, mapping); - + if (wrap) + { + context = wrap->tdb; + tdb_traverse_read(wrap->tdb, MAPIStoreMappingTDBTraverse, mapping); + } } @implementation MAPIStoreMapping diff --git a/OpenChange/MAPIStoreNotesContext.m b/OpenChange/MAPIStoreNotesContext.m index b4cc38714..7171f7da0 100644 --- a/OpenChange/MAPIStoreNotesContext.m +++ b/OpenChange/MAPIStoreNotesContext.m @@ -34,12 +34,6 @@ return @"notes"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@notes/" - withID: 0x1c0001]; -} - - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreNotesFolder baseFolderWithURL: newURL diff --git a/OpenChange/MAPIStoreRemindersContext.m b/OpenChange/MAPIStoreRemindersContext.m index cd51d4943..262633ed5 100644 --- a/OpenChange/MAPIStoreRemindersContext.m +++ b/OpenChange/MAPIStoreRemindersContext.m @@ -33,10 +33,4 @@ return @"reminders"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@reminders/" - withID: 0x180001]; -} - @end diff --git a/OpenChange/MAPIStoreSOGo.m b/OpenChange/MAPIStoreSOGo.m index c46b21e8c..ec880b846 100644 --- a/OpenChange/MAPIStoreSOGo.m +++ b/OpenChange/MAPIStoreSOGo.m @@ -102,7 +102,8 @@ sogo_init (void) */ static int -sogo_create_context(TALLOC_CTX *mem_ctx, const char *uri, void **private_data) +sogo_create_context(TALLOC_CTX *mem_ctx, const char *uri, uint64_t fid, + void **private_data) { NSAutoreleasePool *pool; sogo_context *cContext; @@ -117,8 +118,8 @@ sogo_create_context(TALLOC_CTX *mem_ctx, const char *uri, void **private_data) MAPIStoreContextK = NSClassFromString (@"MAPIStoreContext"); if (MAPIStoreContextK) { - context = [MAPIStoreContextK contextFromURI: uri - inMemCtx: mem_ctx]; + context = [MAPIStoreContextK contextFromURI: uri andFID: fid + inMemCtx: mem_ctx]; [context retain]; cContext = talloc_zero(mem_ctx, sogo_context); diff --git a/OpenChange/MAPIStoreScheduleContext.m b/OpenChange/MAPIStoreScheduleContext.m index ed9b42791..4b0af83d6 100644 --- a/OpenChange/MAPIStoreScheduleContext.m +++ b/OpenChange/MAPIStoreScheduleContext.m @@ -33,10 +33,4 @@ return @"schedule"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@schedule/" - withID: 0xe0001]; -} - @end diff --git a/OpenChange/MAPIStoreSearchContext.m b/OpenChange/MAPIStoreSearchContext.m index cc39b7572..3820eb22e 100644 --- a/OpenChange/MAPIStoreSearchContext.m +++ b/OpenChange/MAPIStoreSearchContext.m @@ -33,10 +33,4 @@ return @"search"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@search/" - withID: 0xd0001]; -} - @end diff --git a/OpenChange/MAPIStoreShortcutsContext.m b/OpenChange/MAPIStoreShortcutsContext.m index 55dd266bf..66a7aa1ce 100644 --- a/OpenChange/MAPIStoreShortcutsContext.m +++ b/OpenChange/MAPIStoreShortcutsContext.m @@ -33,10 +33,4 @@ return @"shortcuts"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@shortcuts/" - withID: 0xf0001]; -} - @end diff --git a/OpenChange/MAPIStoreTasksContext.m b/OpenChange/MAPIStoreTasksContext.m index fa75dda9c..1d71c56da 100644 --- a/OpenChange/MAPIStoreTasksContext.m +++ b/OpenChange/MAPIStoreTasksContext.m @@ -34,12 +34,6 @@ return @"tasks"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@tasks/" - withID: 0x1d0001]; -} - - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreTasksFolder baseFolderWithURL: newURL diff --git a/OpenChange/MAPIStoreViewsContext.m b/OpenChange/MAPIStoreViewsContext.m index f5eec2d58..a5a9a9940 100644 --- a/OpenChange/MAPIStoreViewsContext.m +++ b/OpenChange/MAPIStoreViewsContext.m @@ -33,10 +33,4 @@ return @"views"; } -+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping -{ - [mapping registerURL: @"sogo://openchange:openchange@views/" - withID: 0x110001]; -} - @end