Monotone-Parent: 652fb1324338399d044d5f01bb158d94080a27c0

Monotone-Revision: ea84b0da49761a54044bb70c2502171c1b981e86

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2010-10-26T18:20:46
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2010-10-26 18:20:46 +00:00
parent 25fa112832
commit 3743b78fff
11 changed files with 49 additions and 41 deletions
@@ -41,9 +41,3 @@ extern const int jsonDoNotIndent;
- (NSString *)jsonIndentStringForLevel:(int)level;
@end
@interface NSMutableDictionary (BSJSONAdditions)
+ (NSMutableDictionary *)dictionaryWithJSONString:(NSString *)jsonString;
@end
@@ -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
+3
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 */
+21 -1
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
+1 -1
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"]);
+2 -1
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;
}
+5 -4
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"]))
{
+1 -1
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