From: helge Date: Tue, 12 Jul 2005 12:00:41 +0000 (+0000) Subject: work on user defaults X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d68af04a5a16502cd76c12f8176f2b182e5dc241;p=scalable-opengroupware.org work on user defaults git-svn-id: http://svn.opengroupware.org/SOGo/trunk@717 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/Main/README b/SOGo/Main/README index bcefbd26..287be76c 100644 --- a/SOGo/Main/README +++ b/SOGo/Main/README @@ -27,6 +27,10 @@ SOGoInternetDetectQualifier Note: all header field names are lowercase Testing: -SOGoInternetDetectQualifier '"host = \"agenor.opengroupware.org\""' +AgenorProfileURL +- configure database location of the user profile + eg: http://postgres:@agenor-db:5432/test/sogo_user_profile + What it does ============ - provides locale support diff --git a/SOGo/SoObjects/SOGo/AgenorUserDefaults.h b/SOGo/SoObjects/SOGo/AgenorUserDefaults.h index cbffb82f..19c0fd66 100644 --- a/SOGo/SoObjects/SOGo/AgenorUserDefaults.h +++ b/SOGo/SoObjects/SOGo/AgenorUserDefaults.h @@ -31,11 +31,38 @@ information for users in the database. */ +@class NSString, NSURL, NSUserDefaults, NSArray, NSDictionary, NSData; + @interface AgenorUserDefaults : NSObject { + NSUserDefaults *parent; + NSURL *url; NSString *uid; } +- (id)initWithTableURL:(NSURL *)_url uid:(NSString *)_uid; + +/* value access */ + +- (void)setObject:(id)_value forKey:(NSString *)_key; +- (id)objectForKey:(NSString *)_key; +- (void)removeObjectForKey:(NSString *)_key; + +/* typed accessors */ + +- (NSArray *)arrayForKey:(NSString *)_key; +- (NSDictionary *)dictionaryForKey:(NSString *)_key; +- (NSData *)dataForKey:(NSString *)_key; +- (NSArray *)stringArrayForKey:(NSString *)_key; +- (NSString *)stringForKey:(NSString *)_key; +- (BOOL)boolForKey:(NSString *)_key; +- (float)floatForKey:(NSString *)_key; +- (int)integerForKey:(NSString *)_key; + +- (void)setBool:(BOOL)value forKey:(NSString *)_key; +- (void)setFloat:(float)value forKey:(NSString *)_key; +- (void)setInteger:(int)value forKey:(NSString *)_key; + @end #endif /* __AgenorUserDefaults_H_ */ diff --git a/SOGo/SoObjects/SOGo/AgenorUserDefaults.m b/SOGo/SoObjects/SOGo/AgenorUserDefaults.m index 18f6980b..98991886 100644 --- a/SOGo/SoObjects/SOGo/AgenorUserDefaults.m +++ b/SOGo/SoObjects/SOGo/AgenorUserDefaults.m @@ -20,13 +20,165 @@ */ #include "AgenorUserDefaults.h" +#include #include "common.h" @implementation AgenorUserDefaults +- (id)initWithTableURL:(NSURL *)_url uid:(NSString *)_uid { + if ((self = [super init])) { + if (_url == nil || [_uid length] < 1) { + [self errorWithFormat:@"tried to create AgenorUserDefaults w/o args!"]; + [self release]; + return nil; + } + + self->parent = [[NSUserDefaults standardUserDefaults] retain]; + self->url = [_url copy]; + self->uid = [_uid copy]; + } + return self; +} +- (id)init { + return [self initWithTableURL:nil uid:nil]; +} + - (void)dealloc { + [self->parent release]; + [self->url release]; [self->uid release]; [super dealloc]; } +/* accessors */ + +- (NSURL *)tableURL { + return self->url; +} +- (NSString *)uid { + return self->uid; +} + +- (NSUserDefaults *)parentDefaults { + return self->parent; +} + +/* operation */ + +- (BOOL)fill { + GCSChannelManager *cm; + EOAdaptorChannel *channel; + + cm = [GCSChannelManager defaultChannelManager]; + if ((channel = [cm acquireOpenChannelForURL:[self tableURL]]) == nil) { + [self errorWithFormat:@"failed to acquire channel for URL: %@", + [self tableURL]]; + return NO; + } + + [self logWithFormat:@"do work on: %@", channel]; + + [cm releaseChannel:channel]; + return YES; +} + +/* value access */ + +- (void)setObject:(id)_value forKey:(NSString *)_key { + [self logWithFormat:@"TODO(%s): %@", __PRETTY_FUNCTION__, _key]; +} +- (id)objectForKey:(NSString *)_key { + [self logWithFormat:@"TODO(%s): %@", __PRETTY_FUNCTION__, _key]; + [self fill]; + return nil; +} + +- (void)removeObjectForKey:(NSString *)_key { + [self setObject:nil forKey:_key]; +} + +/* typed accessors */ + +- (NSArray *)arrayForKey:(NSString *)_key { + id obj = [self objectForKey:_key]; + return [obj isKindOfClass:[NSArray class]] ? obj : nil; +} + +- (NSDictionary *)dictionaryForKey:(NSString *)_key { + id obj = [self objectForKey:_key]; + return [obj isKindOfClass:[NSDictionary class]] ? obj : nil; +} + +- (NSData *)dataForKey:(NSString *)_key { + id obj = [self objectForKey:_key]; + return [obj isKindOfClass:[NSData class]] ? obj : nil; +} + +- (NSArray *)stringArrayForKey:(NSString *)_key { + id obj = [self objectForKey:_key]; + int n; + Class strClass = [NSString class]; + + if (![obj isKindOfClass:[NSArray class]]) + return nil; + + for (n = [obj count]-1; n >= 0; n--) { + if (![[obj objectAtIndex:n] isKindOfClass:strClass]) + return nil; + } + return obj; +} + +- (NSString *)stringForKey:(NSString *)_key { + id obj = [self objectForKey:_key]; + return [obj isKindOfClass:[NSString class]] ? obj : nil; +} + +- (BOOL)boolForKey:(NSString *)_key { + id obj; + + if ((obj = [self objectForKey:_key]) == nil) + return NO; + if ([obj isKindOfClass:[NSString class]]) { + if ([obj compare:@"YES" options:NSCaseInsensitiveSearch] == NSOrderedSame) + return YES; + } + if ([obj respondsToSelector:@selector(intValue)]) + return [obj intValue] ? YES : NO; + return NO; +} + +- (float)floatForKey:(NSString *)_key { + id obj = [self stringForKey:_key]; + return (obj != nil) ? [obj floatValue] : 0.0; +} +- (int)integerForKey:(NSString *)_key { + id obj = [self stringForKey:_key]; + return (obj != nil) ? [obj intValue] : 0; +} + +- (void)setBool:(BOOL)value forKey:(NSString *)_key { + [self setObject:(value ? @"YES" : @"NO") forKey:_key]; +} +- (void)setFloat:(float)value forKey:(NSString *)_key { + [self setObject:[NSString stringWithFormat:@"%f", value] forKey:_key]; +} +- (void)setInteger:(int)value forKey:(NSString *)_key { + [self setObject:[NSString stringWithFormat:@"%d", value] forKey:_key]; +} + +/* description */ + +- (NSString *)description { + NSMutableString *ms; + + ms = [NSMutableString stringWithCapacity:16]; + [ms appendFormat:@"<0x%08X[%@]>", self, NSStringFromClass([self class])]; + [ms appendFormat:@" uid=%@", self->uid]; + [ms appendFormat:@" url=%@", [self->url absoluteString]]; + [ms appendFormat:@" parent=0x%08X", self->parent]; + [ms appendString:@">"]; + return ms; +} + @end /* AgenorUserDefaults */ diff --git a/SOGo/SoObjects/SOGo/AgenorUserManager.m b/SOGo/SoObjects/SOGo/AgenorUserManager.m index dfafce34..4bff3b52 100644 --- a/SOGo/SoObjects/SOGo/AgenorUserManager.m +++ b/SOGo/SoObjects/SOGo/AgenorUserManager.m @@ -20,6 +20,7 @@ */ #include "AgenorUserManager.h" +#include "AgenorUserDefaults.h" #include #include #include "SOGoLRUCache.h" @@ -51,16 +52,18 @@ static NSString *defaultMailDomain = @"equipement.gouv.fr"; static NSString *shareLDAPClass = @"mineqMelBoite"; static NSString *shareLoginSeparator = @".-."; static NSString *mailEmissionAttrName = @"mineqMelmailEmission"; +static NSURL *AgenorProfileURL = nil; static NSArray *fromEMailAttrs = nil; + (void)initialize { static BOOL didInit = NO; NSUserDefaults *ud; + NSString *tmp; - if (didInit) - return; + if (didInit) return; didInit = YES; + ud = [NSUserDefaults standardUserDefaults]; debugOn = [ud boolForKey:@"SOGoUserManagerDebugEnabled"]; @@ -81,6 +84,15 @@ static NSArray *fromEMailAttrs = nil; fromEMailAttrs = [[NSArray alloc] initWithObjects:mailEmissionAttrName, nil]; + + /* profile database URL */ + + if ((tmp = [ud stringForKey:@"AgenorProfileURL"]) == nil) + NSLog(@"ERROR: no 'AgenorProfileURL' database URL configured!"); + else if ((AgenorProfileURL = [[NSURL alloc] initWithString:tmp]) == nil) + NSLog(@"ERROR: could not parse AgenorProfileURL: '%@'", tmp); + else + NSLog(@"Note: using profile at: %@", [AgenorProfileURL absoluteString]); } + (id)sharedUserManager { @@ -783,8 +795,19 @@ static NSArray *fromEMailAttrs = nil; /* defaults */ - (NSUserDefaults *)getUserDefaultsForUID:(NSString *)_uid { - [self logWithFormat:@"TODO: implement!"]; - return nil; + id defaults; + + if (AgenorProfileURL == nil) { + [self warnWithFormat: + @"no profile configured, cannot retrieve defaults for user: '%@'", + _uid]; + return nil; + } + + /* Note: do not cache, otherwise updates can be quite tricky */ + defaults = [[[AgenorUserDefaults alloc] + initWithTableURL:AgenorProfileURL uid:_uid] autorelease]; + return defaults; } /* debugging */ @@ -799,7 +822,8 @@ static NSArray *fromEMailAttrs = nil; NSMutableString *ms; ms = [NSMutableString stringWithCapacity:16]; - [ms appendFormat:@"<0x%08X[%@]>", self, NSStringFromClass([self class])]; + [ms appendFormat:@"<0x%08X[%@]", self, NSStringFromClass([self class])]; + [ms appendString:@">"]; return ms; } diff --git a/SOGo/SoObjects/SOGo/ChangeLog b/SOGo/SoObjects/SOGo/ChangeLog index 131e1f43..c676c8cb 100644 --- a/SOGo/SoObjects/SOGo/ChangeLog +++ b/SOGo/SoObjects/SOGo/ChangeLog @@ -1,3 +1,15 @@ +2005-07-12 Helge Hess + + * v0.9.44 + + * AgenorUserDefaults.m: added typed value accessors and proper + initializers + + * AgenorUserManager.m: added 'AgenorProfileURL' default to configure + the database location of the user profile table + + * finished agenor_defaults tool + 2005-07-12 Helge Hess * v0.9.43 @@ -20,8 +32,6 @@ * AgenorUserManager.m: added -getSharedMailboxEMailsForUID: method to discover the shared emails the user is allowed to post from, added caching of shared emails and Cyrus-logins - -2005-07-08 Helge Hess * WOContext+Agenor.m: use SOGoInternetDetectQualifier for detecting Internet access level (v0.9.41) diff --git a/SOGo/SoObjects/SOGo/GNUmakefile.preamble b/SOGo/SoObjects/SOGo/GNUmakefile.preamble index 07d977f9..1173adf2 100644 --- a/SOGo/SoObjects/SOGo/GNUmakefile.preamble +++ b/SOGo/SoObjects/SOGo/GNUmakefile.preamble @@ -24,5 +24,4 @@ libSOGo_LIBRARIES_DEPEND_UPON += \ -lXmlRpc -lDOM -lSaxObjC \ -lNGLdap -ADDITIONAL_TOOL_LIBS += -lNGLdap - +ADDITIONAL_TOOL_LIBS += -lGDLContentStore -lNGLdap diff --git a/SOGo/SoObjects/SOGo/Version b/SOGo/SoObjects/SOGo/Version index 381f32bc..7fdb0b30 100644 --- a/SOGo/SoObjects/SOGo/Version +++ b/SOGo/SoObjects/SOGo/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=43 +SUBMINOR_VERSION:=44 # v0.9.34 requires libGDLContentStore v4.5.26 # v0.9.26 requires libOGoContentStore v0.9.13 diff --git a/SOGo/SoObjects/SOGo/agenor_defaults.m b/SOGo/SoObjects/SOGo/agenor_defaults.m index 0ba83f52..e7a18bc4 100644 --- a/SOGo/SoObjects/SOGo/agenor_defaults.m +++ b/SOGo/SoObjects/SOGo/agenor_defaults.m @@ -27,12 +27,31 @@ static void usage(NSArray *args) { [[args objectAtIndex:0] cString]); } +static void doInfo(NSUserDefaults *defaults) { + printf("defaults for: '%s'\n", [[defaults valueForKey:@"uid"] cString]); + printf(" profile table: '%s'\n", + [[[defaults valueForKey:@"tableURL"] absoluteString] cString]); +} + static void doRead(NSUserDefaults *defaults, NSString *key) { - NSLog(@"TODO READ: %@", key); + id value; + + if ((value = [defaults objectForKey:key]) == nil) { + fprintf(stderr, "There is no key '%s' in the Agenor profile!\n", + [key cString]); + return; + } + + printf("%s\n", [[value description] cString]); } static void doWrite(NSUserDefaults *defaults, NSString *key, NSString *value) { - NSLog(@"TODO WRITE: %@", key, value); + [defaults setObject:value forKey:key]; + + if (![defaults synchronize]) { + fprintf(stderr, "Failed to synchronize defaults with profile!\n"); + return; + } } static void doIt(NSArray *args) { @@ -42,16 +61,24 @@ static void doIt(NSArray *args) { /* extract arguments */ - if ([args count] < 4) { + if ([args count] < 3) { usage(args); return; } uid = [args objectAtIndex:1]; op = [args objectAtIndex:2]; - key = [args objectAtIndex:3]; + key = nil; value = nil; + if ([op isEqualToString:@"write"] || [op isEqualToString:@"read"]) { + if ([args count] < 4) { + usage(args); + return; + } + key = [args objectAtIndex:3]; + } + if ([op isEqualToString:@"write"]) { if ([args count] < 5) { usage(args); @@ -75,6 +102,8 @@ static void doIt(NSArray *args) { doRead(defaults, key); else if ([op isEqualToString:@"write"]) doWrite(defaults, key, value); + else if ([op isEqualToString:@"info"]) + doInfo(defaults); else usage(args); }