From 14eaf1f7facda0e36d3585006ed962af59de4635 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 27 Oct 2011 15:59:50 +0000 Subject: [PATCH] Monotone-Parent: 55b27cea4512267428af5613642488fa4b4f83fb Monotone-Revision: 674dec9c0680a0ce5418d7dc05b15bc69a65f379 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-10-27T15:59:50 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 14 +++++++ OpenChange/MAPIStoreFSMessage.m | 8 +++- OpenChange/MAPIStoreObject.h | 2 + OpenChange/MAPIStoreObject.m | 65 +++++++++++++++++++++------------ 4 files changed, 64 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 94e1f8762..be95adc1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2011-10-27 Wolfgang Sourdeau + * OpenChange/MAPIStoreObject.m (-canGetProperty:): new method that + determines whether a property can be requested on a + MAPIStoreObject instance or descendant thereof, in order to take + different ways of fetching properties into account, whether + through a dynamic getter or some dictionary... + (-getAvailableProperties:inMemCtx:): now compute the returned + array based on the result of invocations of -[self + canGetProperty:]. + + * OpenChange/MAPIStoreFSMessage.m + (+getAvailableProperties:inMemCtx:): fixed a leak by attaching the + array of enum MAPITAGS to "properties". + (-canGetProperty:): overriden method. + * OpenChange/MAPIStoreVolatileMessage.m: MAPIStoreMemMessage renamed to MAPIStoreVolatileMessage. diff --git a/OpenChange/MAPIStoreFSMessage.m b/OpenChange/MAPIStoreFSMessage.m index 6d2d3a3ef..dd6b2c231 100644 --- a/OpenChange/MAPIStoreFSMessage.m +++ b/OpenChange/MAPIStoreFSMessage.m @@ -49,7 +49,7 @@ properties = talloc_zero (memCtx, struct SPropTagArray); properties->cValues = MAPIStoreSupportedPropertiesCount + 8; - properties->aulPropTag = talloc_array (NULL, enum MAPITAGS, + properties->aulPropTag = talloc_array (properties, enum MAPITAGS, MAPIStoreSupportedPropertiesCount + 8); for (count = 0; count < MAPIStoreSupportedPropertiesCount; count++) @@ -65,6 +65,12 @@ return MAPISTORE_SUCCESS; } +- (BOOL) canGetProperty: (enum MAPITAGS) propTag +{ + return ([[sogoObject properties] objectForKey: MAPIPropertyKey (propTag)] + || [super canGetProperty: propTag]); +} + - (void) save { uint64_t newVersion; diff --git a/OpenChange/MAPIStoreObject.h b/OpenChange/MAPIStoreObject.h index f5d89bb17..31ace625c 100644 --- a/OpenChange/MAPIStoreObject.h +++ b/OpenChange/MAPIStoreObject.h @@ -82,6 +82,8 @@ /* properties */ +- (BOOL) canGetProperty: (enum MAPITAGS) propTag; + - (void) addProperties: (NSDictionary *) newProperties; - (NSDictionary *) properties; - (void) resetProperties; diff --git a/OpenChange/MAPIStoreObject.m b/OpenChange/MAPIStoreObject.m index 8b7212289..bc831acf5 100644 --- a/OpenChange/MAPIStoreObject.m +++ b/OpenChange/MAPIStoreObject.m @@ -247,30 +247,19 @@ static Class NSExceptionK, MAPIStoreFolderK; MAPIStorePropertyGetter method = NULL; uint16_t propValue; SEL methodSel; - const char *propName; + id value; int rc = MAPISTORE_ERR_NOT_FOUND; - propValue = (propTag & 0xffff0000) >> 16; - methodSel = MAPIStoreSelectorForPropertyGetter (propValue); - - method = (MAPIStorePropertyGetter) classGetters[propValue]; - if (method) - rc = method (self, methodSel, data, memCtx); + value = [properties objectForKey: MAPIPropertyKey (propTag)]; + if (value) + rc = [value getMAPIValue: data forTag: propTag inMemCtx: memCtx]; else { - *data = NULL; - - if (methodSel) - { - propName = get_proptag_name (propTag); - if (!propName) - propName = ""; - // [self warnWithFormat: - // @"unimplemented selector (%@) for %s (0x%.8x)", - // NSStringFromSelector (methodSel), propName, propTag]; - } - // else - // [self warnWithFormat: @"unsupported property tag: 0x%.8x", propTag]; + propValue = (propTag & 0xffff0000) >> 16; + methodSel = MAPIStoreSelectorForPropertyGetter (propValue); + method = (MAPIStorePropertyGetter) classGetters[propValue]; + if (method) + rc = method (self, methodSel, data, memCtx); } return rc; @@ -411,7 +400,36 @@ static Class NSExceptionK, MAPIStoreFolderK; - (int) getAvailableProperties: (struct SPropTagArray **) propertiesP inMemCtx: (TALLOC_CTX *) memCtx { - return [isa getAvailableProperties: propertiesP inMemCtx: memCtx]; + NSUInteger count; + struct SPropTagArray *availableProps; + enum MAPITAGS propTag; + + availableProps = talloc_zero (memCtx, struct SPropTagArray); + availableProps->aulPropTag = talloc_array (availableProps, enum MAPITAGS, + MAPIStoreSupportedPropertiesCount); + for (count = 0; count < MAPIStoreSupportedPropertiesCount; count++) + { + propTag = MAPIStoreSupportedProperties[count]; + if ([self canGetProperty: propTag]) + { + availableProps->aulPropTag[availableProps->cValues] = propTag; + availableProps->cValues++; + } + } + + *propertiesP = availableProps; + + return MAPISTORE_SUCCESS; +} + +- (BOOL) canGetProperty: (enum MAPITAGS) propTag +{ + uint16_t propValue; + + propValue = (propTag & 0xffff0000) >> 16; + + return (classGetters[propValue] + || [properties objectForKey: MAPIPropertyKey (propTag)]); } - (int) getProperties: (struct mapistore_property_data *) data @@ -426,7 +444,6 @@ static Class NSExceptionK, MAPIStoreFolderK; withTag: tags[count] inMemCtx: memCtx]; - return MAPISTORE_SUCCESS; } @@ -439,7 +456,7 @@ static Class NSExceptionK, MAPIStoreFolderK; { cValue = aRow->lpProps + counter; [properties setObject: NSObjectFromSPropValue (cValue) - forKey: MAPIPropertyKey (cValue->ulPropTag)]; + forKey: MAPIPropertyKey (cValue->ulPropTag)]; } return MAPISTORE_SUCCESS; @@ -464,7 +481,7 @@ static Class NSExceptionK, MAPIStoreFolderK; - (NSString *) loggingPrefix { return [NSString stringWithFormat:@"<%@:%p:%@>", - NSStringFromClass(isa), self, [self nameInContainer]]; + NSStringFromClass (isa), self, [self nameInContainer]]; } @end