Monotone-Parent: 652fb1324338399d044d5f01bb158d94080a27c0

Monotone-Revision: ea84b0da49761a54044bb70c2502171c1b981e86

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2010-10-26T18:20:46
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2010-10-26 18:20:46 +00:00
parent 25fa112832
commit 3743b78fff
11 changed files with 49 additions and 41 deletions

View File

@ -1,3 +1,15 @@
2010-10-26 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* SoObjects/SOGo/NSString+Utilities.m (-objectFromJSONString): new
method replacing the one below in a more generic way. I.e. the
method will accept any JSON object as input and not only
dictionaries.
* SoObjects/SOGo/NSDictionary+BSJSONAdditions.m
(+dictionaryWithJSONString:): removed method, replaced with
the more generic -[NSString objectFromJSONString] in
NSString+Utilities.
2010-10-25 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* SoObjects/SOGo/SOGoUserDefaults.m (-setContactCategories)

View File

@ -41,9 +41,3 @@ extern const int jsonDoNotIndent;
- (NSString *)jsonIndentStringForLevel:(int)level;
@end
@interface NSMutableDictionary (BSJSONAdditions)
+ (NSMutableDictionary *)dictionaryWithJSONString:(NSString *)jsonString;
@end

View File

@ -188,24 +188,3 @@ const int jsonDoNotIndent = -1;
}
@end
@implementation NSMutableDictionary (BSJSONAdditions)
+ (NSMutableDictionary *) dictionaryWithJSONString: (NSString *) jsonString
{
NSScanner *scanner;
NSMutableDictionary *dictionary;
dictionary = nil;
if ([jsonString length] > 0)
{
scanner = [[NSScanner alloc] initWithString: jsonString];
[scanner scanJSONObject:&dictionary];
[scanner autorelease];
}
return dictionary;
}
@end

View File

@ -26,6 +26,7 @@
#import <Foundation/NSString.h>
@class NSDictionary;
@class NSObject;
@interface NSString (SOGoURLExtension)
@ -65,6 +66,8 @@
- (BOOL) isJSONString;
- (id) objectFromJSONString;
@end
#endif /* NSSTRING_URL_H */

View File

@ -34,6 +34,7 @@
#import "NSArray+Utilities.h"
#import "NSDictionary+BSJSONAdditions.h"
#import "NSDictionary+URL.h"
#import "NSScanner+BSJSONAdditions.h"
#import "NSString+Utilities.h"
@ -505,9 +506,28 @@ static NSMutableCharacterSet *safeLDIFStartChars = nil;
NSDictionary *jsonData;
#warning this method is a quick and dirty way of detecting the file-format
jsonData = [NSMutableDictionary dictionaryWithJSONString: self];
jsonData = [self objectFromJSONString];
return (jsonData != nil);
}
- (id) objectFromJSONString
{
NSScanner *scanner;
NSObject *object;
object = nil;
if ([self length] > 0)
{
scanner = [[NSScanner alloc] initWithString: self];
if (![scanner scanJSONValue: &object])
object = nil;
[scanner autorelease];
}
return object;
}
@end

View File

@ -141,7 +141,7 @@
jsonSession = [cache CASSessionWithTicket: ticket];
if ([jsonSession length])
{
sessionDict = [NSMutableDictionary dictionaryWithJSONString: jsonSession];
sessionDict = [jsonSession objectFromJSONString];
ASSIGN (login, [sessionDict objectForKey: @"login"]);
ASSIGN (pgt, [sessionDict objectForKey: @"pgt"]);
ASSIGN (identifier, [sessionDict objectForKey: @"identifier"]);

View File

@ -49,6 +49,7 @@
#import <NGExtensions/NSObject+Logs.h>
#import "NSDictionary+BSJSONAdditions.h"
#import "NSString+Utilities.h"
#import "SOGoObject.h"
#import "SOGoSystemDefaults.h"
#import "SOGoUser.h"
@ -498,7 +499,7 @@ static memcached_st *handle = NULL;
s = [self _valuesOfType: @"acl" forKey: thePath];
if (s)
return [NSMutableDictionary dictionaryWithJSONString: s];
return [s objectFromJSONString];
return nil;
}

View File

@ -29,8 +29,9 @@
#import <Foundation/NSValue.h>
#import <NGExtensions/NSObject+Logs.h>
#import "NSDictionary+BSJSONAdditions.h"
#import "NSArray+Utilities.h"
#import "NSDictionary+BSJSONAdditions.h"
#import "NSString+Utilities.h"
#import "SOGoDomainDefaults.h"
#import "SOGoSource.h"
#import "SOGoSystemDefaults.h"
@ -416,7 +417,7 @@
BOOL checkOK;
jsonUser = [[SOGoCache sharedCache] userAttributesForLogin: _login];
currentUser = [NSMutableDictionary dictionaryWithJSONString: jsonUser];
currentUser = [jsonUser objectFromJSONString];
dictPassword = [currentUser objectForKey: @"password"];
if (currentUser && dictPassword)
checkOK = ([dictPassword isEqualToString: _pwd]);
@ -458,7 +459,7 @@
BOOL didChange;
jsonUser = [[SOGoCache sharedCache] userAttributesForLogin: login];
currentUser = [NSMutableDictionary dictionaryWithJSONString: jsonUser];
currentUser = [jsonUser objectFromJSONString];
dictPassword = [currentUser objectForKey: @"password"];
if ([self _sourceChangePasswordForLogin: login
@ -638,7 +639,7 @@
// Remove the "@" prefix used to identified groups in the ACL tables.
aUID = [uid hasPrefix: @"@"] ? [uid substringFromIndex: 1] : uid;
jsonUser = [[SOGoCache sharedCache] userAttributesForLogin: aUID];
currentUser = [NSMutableDictionary dictionaryWithJSONString: jsonUser];
currentUser = [jsonUser objectFromJSONString];
if (!([currentUser objectForKey: @"emails"]
&& [currentUser objectForKey: @"cn"]))
{

View File

@ -195,7 +195,7 @@
defFlags.modified = NO;
[values release];
jsonValue = [self jsonRepresentation];
values = [NSMutableDictionary dictionaryWithJSONString: jsonValue];
values = [jsonValue objectFromJSONString];
if (values)
[values retain];
else

View File

@ -43,8 +43,7 @@
#import <Appointments/SOGoAppointmentFolders.h>
#import <SOGo/NSDictionary+Utilities.h>
#import <SOGo/NSDictionary+BSJSONAdditions.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoCache.h>
#import <SOGo/SOGoCASSession.h>
#import <SOGo/SOGoDomainDefaults.h>
@ -408,7 +407,7 @@
WOCookie *authCookie;
request = [context request];
message = [NSMutableDictionary dictionaryWithJSONString: [request contentAsString]];
message = [[request contentAsString] objectFromJSONString];
username = [message objectForKey: @"userName"];
password = [message objectForKey: @"password"];
newPassword = [message objectForKey: @"newPassword"];

View File

@ -55,7 +55,6 @@
#import <Appointments/SOGoAppointmentOccurence.h>
#import <Appointments/SOGoTaskObject.h>
#import <SOGo/NSArray+Utilities.h>
#import <SOGo/NSDictionary+BSJSONAdditions.h>
#import <SOGo/NSDictionary+Utilities.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoUser.h>
@ -1727,8 +1726,8 @@ RANGE(2);
if ([json length])
{
attendees = [NSArray array];
attendeesData = [NSMutableDictionary dictionaryWithJSONString: json];
if (attendeesData)
attendeesData = [json objectFromJSONString];
if (attendeesData && [attendeesData isKindOfClass: [NSDictionary class]])
{
newAttendees = [NSMutableArray array];
attendees = [attendeesData allValues];