From 56972b8e5337ba370e2fa4076da6deaed85726d3 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 19 Nov 2009 20:21:48 +0000 Subject: [PATCH] Monotone-Parent: cf528c32a864b21894f3e0902af7a6f58b27594a Monotone-Revision: b7300c32ea4332dc810095989c8cea185300c032 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2009-11-19T20:21:48 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 5 +++ SoObjects/SOGo/SOGoUserDefaults.m | 57 ++++++++++++++++++------------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 544bfd9b5..6d5e54f14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2009-11-19 Wolfgang Sourdeau + * SoObjects/SOGo/SOGoUserDefaults.m (-fetchJSONProfileFromDB): + extracted the conversion of property list values to JSON values + into a new separate method (-_convertPListToJSON:), that will be + invoked by -jsonRepresentation. + * SoObjects/SOGo/SQLSource.m (-checkLogin:andPassword:): (_lookupContactEntry:considerEmail:, -allEntryIDS) (_lookupContactEntry:consideringEmail:, fetchContactsMatching:): diff --git a/SoObjects/SOGo/SOGoUserDefaults.m b/SoObjects/SOGo/SOGoUserDefaults.m index 30634cde4..f08c4f276 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.m +++ b/SoObjects/SOGo/SOGoUserDefaults.m @@ -103,11 +103,10 @@ static NSString *uidColumnName = @"c_uid"; { GCSChannelManager *cm; EOAdaptorChannel *channel; - NSDictionary *row, *plist; + NSDictionary *row; NSException *ex; - NSString *sql, *value, *error; + NSString *sql, *value; NSArray *attrs; - NSData *plistData; value = nil; @@ -140,26 +139,6 @@ static NSString *uidColumnName = @"c_uid"; #warning The result is supposed to be unescaped, why re-unescaping it here ? value = [value stringByReplacingString: @"''" withString: @"'"]; value = [value stringByReplacingString: @"\\\\" withString: @"\\"]; - if (![value isJSONString]) - { - plistData = [value dataUsingEncoding: NSUTF8StringEncoding]; - plist = [NSPropertyListSerialization propertyListFromData: plistData - mutabilityOption: NSPropertyListMutableContainers - format: NULL - errorDescription: &error]; - if (plist) - { - [self logWithFormat: @"database value for '%@'" - @" (uid: '%@') is a plist", fieldName, uid]; - value = [plist jsonStringValue]; - } - else - { - [self errorWithFormat: @"failed to parse property list value" - @" (error: %@): %@", error, value]; - value = nil; - } - } } else { @@ -180,6 +159,36 @@ static NSString *uidColumnName = @"c_uid"; return value; } +- (NSString *) _convertPListToJSON: (NSString *) plistValue +{ + NSData *plistData; + NSDictionary *plist; + NSString *jsonValue, *error; + + plistData = [plistValue dataUsingEncoding: NSUTF8StringEncoding]; + plist = [NSPropertyListSerialization propertyListFromData: plistData + mutabilityOption: NSPropertyListMutableContainers + format: NULL + errorDescription: &error]; + if (plist) + { + [self logWithFormat: @"database value for '%@'" + @" (uid: '%@') is a plist", fieldName, uid]; + jsonValue = [plist jsonStringValue]; + } + else + { + [self errorWithFormat: @"failed to parse property list value" + @" (error: %@): %@", error, plistValue]; + jsonValue = nil; + } + + if (!jsonValue) + jsonValue = @"{}"; + + return jsonValue; +} + - (NSString *) jsonRepresentation { SOGoCache *cache; @@ -200,6 +209,8 @@ static NSString *uidColumnName = @"c_uid"; jsonValue = [self fetchJSONProfileFromDB]; if ([jsonValue length]) { + if (![jsonValue isJSONString]) + jsonValue = [self _convertPListToJSON: jsonValue]; defFlags.isNew = NO; if ([fieldName isEqualToString: @"c_defaults"]) [cache setUserDefaults: jsonValue forLogin: uid];