diff --git a/ChangeLog b/ChangeLog index 024724735..d96ff2e4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2010-11-22 Wolfgang Sourdeau + * OpenChange/MAPIStoreContext.m (_contextClassFromModule) + (_prepareContextClass): new static functions for clearing up + +contextFromURI:inMemCtx:. + (+registerFixedMappings:): new subclassable method. + (_prepareContextClass): the static mappings are now initialized + from the context class themselves, via the use of an unique + invocation of registerFixedMappings: when the class is + instantiated first. + * OpenChange/SOGoTaskObject+MAPIStore.m (-setMAPIProperties:): the start date must be taken from the 0x811e0040 property rather than "PR_START_DATE" (contrary to the event properties), we now handle diff --git a/OpenChange/MAPIStoreCalendarContext.m b/OpenChange/MAPIStoreCalendarContext.m index 5071f1d23..caf7309ae 100644 --- a/OpenChange/MAPIStoreCalendarContext.m +++ b/OpenChange/MAPIStoreCalendarContext.m @@ -29,6 +29,7 @@ #import "MAPIApplication.h" #import "MAPIStoreAuthenticator.h" +#import "MAPIStoreMapping.h" #import "NSCalendarDate+MAPIStore.h" #import "NSString+MAPIStore.h" #import "SOGoGCSFolder+MAPIStore.h" @@ -40,6 +41,12 @@ @implementation MAPIStoreCalendarContext ++ (void) registerFixedMappings: (MAPIStoreMapping *) mapping +{ + [mapping registerURL: @"sogo://openchange:openchange@calendar/personal" + withID: 0x190001]; +} + - (void) setupModuleFolder { id userFolder; diff --git a/OpenChange/MAPIStoreContactsContext.m b/OpenChange/MAPIStoreContactsContext.m index 68e5a2b40..f2ae738b2 100644 --- a/OpenChange/MAPIStoreContactsContext.m +++ b/OpenChange/MAPIStoreContactsContext.m @@ -32,6 +32,7 @@ #import "MAPIApplication.h" #import "MAPIStoreAuthenticator.h" +#import "MAPIStoreMapping.h" #import "NSString+MAPIStore.h" #import "SOGoGCSFolder+MAPIStore.h" @@ -42,6 +43,12 @@ @implementation MAPIStoreContactsContext ++ (void) registerFixedMappings: (MAPIStoreMapping *) mapping +{ + [mapping registerURL: @"sogo://openchange:openchange@contacts/personal" + withID: 0x1a0001]; +} + - (void) setupModuleFolder { id userFolder; diff --git a/OpenChange/MAPIStoreContext.h b/OpenChange/MAPIStoreContext.h index 3ec26d06d..0da4207e5 100644 --- a/OpenChange/MAPIStoreContext.h +++ b/OpenChange/MAPIStoreContext.h @@ -130,6 +130,7 @@ extern uint64_t *MAPILongLongValue (void *, uint64_t); withFlags: (uint8_t) flags; /* subclass methods */ ++ (void) registerFixedMappings: (MAPIStoreMapping *) storeMapping; - (NSArray *) getFolderMessageKeys: (SOGoFolder *) folder; diff --git a/OpenChange/MAPIStoreContext.m b/OpenChange/MAPIStoreContext.m index af7fbd1b5..1724ac6f8 100644 --- a/OpenChange/MAPIStoreContext.m +++ b/OpenChange/MAPIStoreContext.m @@ -73,6 +73,7 @@ /* sogo://username:password@{contacts,calendar,tasks,journal,notes,mail}/dossier/id */ static Class SOGoObjectK, SOGoMailAccountK, SOGoMailFolderK; +static Class NSArrayK; static MAPIStoreMapping *mapping = nil; @@ -81,14 +82,80 @@ static MAPIStoreMapping *mapping = nil; SOGoObjectK = [SOGoObject class]; SOGoMailAccountK = [SOGoMailAccount class]; SOGoMailFolderK = [SOGoMailFolder class]; + NSArrayK = [NSArray class]; mapping = [MAPIStoreMapping sharedMapping]; } ++ (void) registerFixedMappings: (MAPIStoreMapping *) storeMapping +{ +} + +static inline NSString * +_contextClassFromModule (NSString *module) +{ + NSString *contextClass; + + if ([module isEqualToString: @"mail"]) + contextClass = @"MAPIStoreMailContext"; + else if ([module isEqualToString: @"contacts"]) + contextClass = @"MAPIStoreContactsContext"; + else if ([module isEqualToString: @"calendar"]) + contextClass = @"MAPIStoreCalendarContext"; + else if ([module isEqualToString: @"tasks"]) + contextClass = @"MAPIStoreTasksContext"; + else if ([module isEqualToString: @"freebusy"]) + contextClass = @"MAPIStoreFreebusyContext"; + else + { + NSLog (@"ERROR: unrecognized module name '%@'", module); + contextClass = nil; + } + + return contextClass; +} + +static inline MAPIStoreContext * +_prepareContextClass (struct mapistore_context *newMemCtx, + NSString *contextClass, NSString *completeURLString, + NSString *username, NSString *password) +{ + MAPIStoreContext *context; + MAPIStoreAuthenticator *authenticator; + static NSMutableDictionary *registration = nil; + Class contextK; + + if (!registration) + registration = [NSMutableDictionary new]; + + contextK = NSClassFromString (contextClass); + if (![registration objectForKey: contextClass]) + { + [contextK registerFixedMappings: mapping]; + [registration setObject: [NSNull null] + forKey: contextClass]; + } + + context = [contextK new]; + [context setURI: completeURLString andMemCtx: newMemCtx]; + [context autorelease]; + + authenticator = [MAPIStoreAuthenticator new]; + [authenticator setUsername: username]; + [authenticator setPassword: password]; + [context setAuthenticator: authenticator]; + [authenticator release]; + + [context setupRequest]; + [context setupModuleFolder]; + [context tearDownRequest]; + + return context; +} + + (id) contextFromURI: (const char *) newUri inMemCtx: (struct mapistore_context *) newMemCtx { MAPIStoreContext *context; - MAPIStoreAuthenticator *authenticator; NSString *contextClass, *module, *completeURLString, *urlString; NSURL *baseURL; @@ -106,38 +173,13 @@ static MAPIStoreMapping *mapping = nil; module = [baseURL host]; if (module) { - if ([module isEqualToString: @"mail"]) - contextClass = @"MAPIStoreMailContext"; - else if ([module isEqualToString: @"contacts"]) - contextClass = @"MAPIStoreContactsContext"; - else if ([module isEqualToString: @"calendar"]) - contextClass = @"MAPIStoreCalendarContext"; - else if ([module isEqualToString: @"tasks"]) - contextClass = @"MAPIStoreTasksContext"; - else if ([module isEqualToString: @"freebusy"]) - contextClass = @"MAPIStoreFreebusyContext"; - else - { - NSLog (@"ERROR: unrecognized module name '%@'", module); - contextClass = nil; - } - + contextClass = _contextClassFromModule (module); if (contextClass) - { - context = [NSClassFromString (contextClass) new]; - [context setURI: completeURLString andMemCtx: newMemCtx]; - [context autorelease]; - - authenticator = [MAPIStoreAuthenticator new]; - [authenticator setUsername: [baseURL user]]; - [authenticator setPassword: [baseURL password]]; - [context setAuthenticator: authenticator]; - [authenticator release]; - - [context setupRequest]; - [context setupModuleFolder]; - [context tearDownRequest]; - } + context = _prepareContextClass (newMemCtx, + contextClass, + completeURLString, + [baseURL user], + [baseURL password]); } } else @@ -531,7 +573,7 @@ static MAPIStoreMapping *mapping = nil; ids = nil; } - if ([ids isKindOfClass: [NSArray class]]) + if ([ids isKindOfClass: NSArrayK]) { rc = MAPI_E_SUCCESS; *rowCount = [ids count]; diff --git a/OpenChange/MAPIStoreFreebusyContext.m b/OpenChange/MAPIStoreFreebusyContext.m index 237db42ed..c171e6f49 100644 --- a/OpenChange/MAPIStoreFreebusyContext.m +++ b/OpenChange/MAPIStoreFreebusyContext.m @@ -26,11 +26,18 @@ #import "MAPIApplication.h" #import "MAPIStoreAuthenticator.h" +#import "MAPIStoreMapping.h" #import "MAPIStoreFreebusyContext.h" @implementation MAPIStoreFreebusyContext ++ (void) registerFixedMappings: (MAPIStoreMapping *) mapping +{ + [mapping registerURL: @"sogo://openchange:openchange@freebusy/" + withID: 0x70001]; +} + - (void) setupModuleFolder { id userFolder; diff --git a/OpenChange/MAPIStoreMailContext.m b/OpenChange/MAPIStoreMailContext.m index d76ac4bcf..b0da4647d 100644 --- a/OpenChange/MAPIStoreMailContext.m +++ b/OpenChange/MAPIStoreMailContext.m @@ -34,6 +34,7 @@ #import "MAPIApplication.h" #import "MAPIStoreAuthenticator.h" +#import "MAPIStoreMapping.h" #import "NSData+MAPIStore.h" #import "NSCalendarDate+MAPIStore.h" #import "NSString+MAPIStore.h" @@ -48,6 +49,14 @@ @implementation MAPIStoreMailContext ++ (void) registerFixedMappings: (MAPIStoreMapping *) mapping +{ + [mapping registerURL: @"sogo://openchange:openchange@mail/folderINBOX" + withID: 0x160001]; + [mapping registerURL: @"sogo://openchange:openchange@mail/folderxxxc0001" + withID: 0x0c0001]; +} + - (void) setupModuleFolder { id userFolder, accountsFolder; diff --git a/OpenChange/MAPIStoreMapping.m b/OpenChange/MAPIStoreMapping.m index b09910d8f..54cd1abb0 100644 --- a/OpenChange/MAPIStoreMapping.m +++ b/OpenChange/MAPIStoreMapping.m @@ -44,23 +44,12 @@ return sharedMapping; } -- (void) _setupFixedMapping -{ - [self registerURL: @"sogo://openchange:openchange@mail/folderINBOX" withID: 0x160001]; - [self registerURL: @"sogo://openchange:openchange@mail/folderxxxc0001" withID: 0x0c0001]; - [self registerURL: @"sogo://openchange:openchange@contacts/personal" withID: 0x1a0001]; - [self registerURL: @"sogo://openchange:openchange@calendar/personal" withID: 0x190001]; - [self registerURL: @"sogo://openchange:openchange@tasks/personal" withID: 0x1d0001]; - [self registerURL: @"sogo://openchange:openchange@freebusy/" withID: 0x70001]; -} - - (id) init { if ((self = [super init])) { mapping = [NSMutableDictionary new]; reverseMapping = [NSMutableDictionary new]; - [self _setupFixedMapping]; } return self; diff --git a/OpenChange/MAPIStoreTasksContext.m b/OpenChange/MAPIStoreTasksContext.m index ba09672b7..ad18c5f6c 100644 --- a/OpenChange/MAPIStoreTasksContext.m +++ b/OpenChange/MAPIStoreTasksContext.m @@ -27,6 +27,7 @@ #import "MAPIApplication.h" #import "MAPIStoreAuthenticator.h" +#import "MAPIStoreMapping.h" #import "NSCalendarDate+MAPIStore.h" #import "NSString+MAPIStore.h" #import "SOGoGCSFolder+MAPIStore.h" @@ -38,6 +39,12 @@ @implementation MAPIStoreTasksContext ++ (void) registerFixedMappings: (MAPIStoreMapping *) mapping +{ + [mapping registerURL: @"sogo://openchange:openchange@tasks/personal" + withID: 0x1d0001]; +} + - (void) setupModuleFolder { id userFolder;