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
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_ */
*/
#include "AgenorUserDefaults.h"
+#include <GDLContentStore/GCSChannelManager.h>
#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 */
*/
#include "AgenorUserManager.h"
+#include "AgenorUserDefaults.h"
#include <NGExtensions/NGExtensions.h>
#include <NGLdap/NGLdap.h>
#include "SOGoLRUCache.h"
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"];
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 {
/* 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 */
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;
}
+2005-07-12 Helge Hess <helge.hess@opengroupware.org>
+
+ * 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 <helge.hess@opengroupware.org>
* v0.9.43
* 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 <helge.hess@opengroupware.org>
* WOContext+Agenor.m: use SOGoInternetDetectQualifier for detecting
Internet access level (v0.9.41)
-lXmlRpc -lDOM -lSaxObjC \
-lNGLdap
-ADDITIONAL_TOOL_LIBS += -lNGLdap
-
+ADDITIONAL_TOOL_LIBS += -lGDLContentStore -lNGLdap
# version file
-SUBMINOR_VERSION:=43
+SUBMINOR_VERSION:=44
# v0.9.34 requires libGDLContentStore v4.5.26
# v0.9.26 requires libOGoContentStore v0.9.13
[[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) {
/* 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);
doRead(defaults, key);
else if ([op isEqualToString:@"write"])
doWrite(defaults, key, value);
+ else if ([op isEqualToString:@"info"])
+ doInfo(defaults);
else
usage(args);
}