From: helge Date: Wed, 16 Jun 2004 12:45:03 +0000 (+0000) Subject: committed initial dbd X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31fbefab7e8f8c65e073f32b21f0878f777d5049;p=scalable-opengroupware.org committed initial dbd git-svn-id: http://svn.opengroupware.org/SOGo/trunk@38 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/dbd/DHostView.m b/dbd/DHostView.m new file mode 100644 index 00000000..37698adf --- /dev/null +++ b/dbd/DHostView.m @@ -0,0 +1,101 @@ +// $Id$ + +#include + +@class EOAdaptorChannel; + +@interface DHostView : SoComponent +{ + EOAdaptorChannel *channel; + NSArray *userNames; + NSArray *databaseNames; + id item; +} + +@end + +#include "DSoHost.h" +#include "common.h" + +@interface EOAdaptorChannel(ModelFetching) +- (NSArray *)describeUserNames; +- (NSArray *)describeDatabaseNames; +@end + +@implementation DHostView + +- (void)dealloc { + if ([self->channel isOpen]) + [self->channel closeChannel]; + [self->channel release]; + + [self->userNames release]; + [self->databaseNames release]; + [self->item release]; + [super dealloc]; +} + +/* notifications */ + +- (void)sleep { + if ([self->channel isOpen]) + [self->channel closeChannel]; + + [super sleep]; +} + +/* DB things */ + +- (EOAdaptor *)adaptor { + return [(DSoHost *)[self clientObject] adaptorInContext:[self context]]; +} + +- (EOAdaptorChannel *)channel { + EOAdaptorContext *ctx; + + if (self->channel) + return self->channel; + + ctx = [[self adaptor] createAdaptorContext]; + self->channel = [[ctx createAdaptorChannel] retain]; + if (![self->channel openChannel]) { + [self->channel release]; + self->channel = nil; + } + + return self->channel; +} + +/* accessors */ + +- (void)setItem:(id)_item { + ASSIGN(self->item, _item); +} +- (id)item { + return self->item; +} + +- (NSArray *)userNames { + if (self->userNames == nil) + self->userNames = [[[self channel] describeUserNames] copy]; + return self->userNames; +} + +- (NSArray *)databaseNames { + if (self->databaseNames == nil) + self->databaseNames = [[[self channel] describeDatabaseNames] copy]; + return self->databaseNames; +} + +/* derived accessors */ + +// Note: it suxx that we need to write code for that ... + +- (NSString *)dbLink { + return [@"Databases/" stringByAppendingString:[self item]]; +} +- (NSString *)userLink { + return [@"Users/" stringByAppendingString:[self item]]; +} + +@end /* DHostView */ diff --git a/dbd/DHostView.wox b/dbd/DHostView.wox new file mode 100644 index 00000000..474210d1 --- /dev/null +++ b/dbd/DHostView.wox @@ -0,0 +1,21 @@ + + + +Host:
+Port:
+ +

Databases

+ +
  • +
    + +

    Users

    + +
  • +
    + +
    diff --git a/dbd/DSoAuthenticator.h b/dbd/DSoAuthenticator.h new file mode 100644 index 00000000..263761c4 --- /dev/null +++ b/dbd/DSoAuthenticator.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#ifndef __dbd_DSoAuthenticator_H__ +#define __dbd_DSoAuthenticator_H__ + +#include + +/* + DSoAuthenticator + + Authenticator based on PostgreSQL authentication. +*/ + +@interface DSoAuthenticator : SoHTTPAuthenticator +{ + NSString *hostname; + int port; + NSString *dbname; +} + ++ (id)authenticatorWithHostName:(NSString *)_hostname port:(int)_port; ++ (id)authenticatorWithHostName:(NSString *)_hostname port:(int)_port + databaseName:(NSString *)_dbname; + +@end + +#endif /* __dbd_DSoAuthenticator_H__ */ diff --git a/dbd/DSoAuthenticator.m b/dbd/DSoAuthenticator.m new file mode 100644 index 00000000..5b872393 --- /dev/null +++ b/dbd/DSoAuthenticator.m @@ -0,0 +1,139 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#include "DSoAuthenticator.h" +#include "common.h" +#include + +/* + Things to note: + - authenticators themselves are _not_ bound to a context or a SOPE + traversal path + - because of that we need to duplicate some stuff + => or use a separate layer which handles uniquing +*/ + +@implementation DSoAuthenticator + +// TODO: might want to cache authenticator objects ... + +- (id)initWithHostName:(NSString *)_hostname port:(int)_port + databaseName:(NSString *)_dbname +{ + if ((self = [super init])) { + self->hostname = [_hostname copy]; + self->port = _port; + self->dbname = [_dbname copy]; + } + return self; +} + ++ (id)authenticatorWithHostName:(NSString *)_hostname port:(int)_port { + return [[[self alloc] initWithHostName:_hostname port:_port + databaseName:nil] autorelease]; +} ++ (id)authenticatorWithHostName:(NSString *)_hostname port:(int)_port + databaseName:(NSString *)_dbname +{ + return [[[self alloc] initWithHostName:_hostname port:_port + databaseName:_dbname] autorelease]; +} + +- (void)dealloc { + [self->hostname release]; + [self->dbname release]; + [super dealloc]; +} + +/* realm */ + +- (NSString *)authRealm { + /* + the HTTP authentication realm, we use the database info (default is the + application name, but in our case we can be more specific) + */ + if (self->dbname == nil) + return self->hostname; + + return [[self->dbname stringByAppendingString:@"@"] + stringByAppendingString:self->hostname]; +} + +/* adaptor setup */ + +- (NSString *)defaultDatabase { + /* template1 is supposed to exist always (#postgresql channel ;-) */ + return @"template1"; +} + +- (EOAdaptor *)adaptorForLogin:(NSString *)_login password:(NSString *)_pwd { + EOAdaptor *adaptor; + NSDictionary *condict; + NSString *dbn; + + if ((adaptor = [EOAdaptor adaptorWithName:@"PostgreSQL72"]) == nil) + return nil; + + if (![_login isNotNull]) _login = @""; + if (![_pwd isNotNull]) _pwd = @""; + + dbn = [self->dbname isNotNull] ? self->dbname : [self defaultDatabase]; + + // TODO: ignores port + condict = [[NSDictionary alloc] initWithObjectsAndKeys: + self->hostname, @"hostName", + _login, @"userName", + _pwd, @"password", + dbn, @"databaseName", + nil]; + [adaptor setConnectionDictionary:condict]; + [condict release]; + return adaptor; +} + +/* check credentials */ + +- (BOOL)checkLogin:(NSString *)_login password:(NSString *)_pwd { + EOAdaptor *adaptor; + EOAdaptorContext *adctx; + EOAdaptorChannel *adch; + BOOL ok; + + [self logWithFormat:@"check login: %@", _login]; + + /* create all necessary objects */ + + adaptor = [self adaptorForLogin:_login password:_pwd]; + adctx = [adaptor createAdaptorContext]; + adch = [adctx createAdaptorChannel]; + + [self logWithFormat:@" channel: %@", adch]; + + /* open channel to check whether credentials are valid */ + + if ((ok = [adch openChannel])) + [adch closeChannel]; + + return ok; +} + +@end /* DSoAuthenticator */ diff --git a/dbd/DSoDatabase.h b/dbd/DSoDatabase.h new file mode 100644 index 00000000..e7402e8f --- /dev/null +++ b/dbd/DSoDatabase.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#ifndef __dbd_DSoDatabase_H__ +#define __dbd_DSoDatabase_H__ + +#include "DSoObject.h" + +@interface DSoDatabase : DSoObject +{ + NSString *hostName; + int port; + NSString *databaseName; +} + +- (id)initWithHostName:(NSString *)_hostname port:(int)_port + databaseName:(NSString *)_dbname; + +@end + +#endif /* __dbd_DSoDatabase_H__ */ diff --git a/dbd/DSoDatabase.m b/dbd/DSoDatabase.m new file mode 100644 index 00000000..8e82fa1c --- /dev/null +++ b/dbd/DSoDatabase.m @@ -0,0 +1,66 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#include "DSoDatabase.h" +#include "DSoAuthenticator.h" +#include "common.h" + +@implementation DSoDatabase + +- (id)initWithHostName:(NSString *)_hostname port:(int)_port + databaseName:(NSString *)_dbname +{ + if ((self = [super init])) { + self->hostName = [_hostname copy]; + self->databaseName = [_dbname copy]; + self->port = _port > 0 ? _port : 5432; + } + return self; +} + +- (void)dealloc { + [self->databaseName release]; + [self->hostName release]; + [super dealloc]; +} + +/* accessors */ + +- (NSString *)hostName { + return self->hostName; +} +- (int)port { + return self->port; +} + +- (NSString *)databaseName { + return self->databaseName; +} + +/* authentication */ + +- (id)authenticatorInContext:(id)_ctx { + return [DSoAuthenticator authenticatorWithHostName:[self hostName] + port:[self port] databaseName:[self databaseName]]; +} + +@end /* DSoDatabase */ diff --git a/dbd/DSoDatabaseManager.h b/dbd/DSoDatabaseManager.h new file mode 100644 index 00000000..188a95fb --- /dev/null +++ b/dbd/DSoDatabaseManager.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#ifndef __dbd_DSoDatabaseManager_H__ +#define __dbd_DSoDatabaseManager_H__ + +#include "DSoObject.h" + +@class DSoHost; + +@interface DSoDatabaseManager : DSoObject +{ + DSoHost *host; +} + +- (id)initWithContainer:(DSoHost *)_container; + +@end + +#endif /* __dbd_DSoDatabaseManager_H__ */ diff --git a/dbd/DSoDatabaseManager.m b/dbd/DSoDatabaseManager.m new file mode 100644 index 00000000..abd51d90 --- /dev/null +++ b/dbd/DSoDatabaseManager.m @@ -0,0 +1,57 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#include "DSoDatabaseManager.h" +#include "DSoHost.h" +#include "common.h" + +@implementation DSoDatabaseManager + +- (id)initWithContainer:(DSoHost *)_container { + if ((self = [super init])) { + self->host = [_container retain]; + } + return self; +} +- (id)init { + return [self initWithContainer:nil]; +} + +- (void)dealloc { + [self->host release]; + [super dealloc]; +} + +/* name lookup */ + +- (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag { + id obj; + + if ((obj = [super lookupName:_key inContext:_ctx acquire:_flag])) + return obj; + + // TODO: create DSoDatabase object + + return nil; +} + +@end /* DSoDatabaseManager */ diff --git a/dbd/DSoField.h b/dbd/DSoField.h new file mode 100644 index 00000000..b0283fd4 --- /dev/null +++ b/dbd/DSoField.h @@ -0,0 +1,34 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#ifndef __dbd_DSoField_H__ +#define __dbd_DSoField_H__ + +#include "DSoObject.h" + +@interface DSoField : DSoObject +{ +} + +@end + +#endif /* __dbd_DSoField_H__ */ diff --git a/dbd/DSoField.m b/dbd/DSoField.m new file mode 100644 index 00000000..2d3a57a7 --- /dev/null +++ b/dbd/DSoField.m @@ -0,0 +1,32 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#include "DSoField.h" +#include "common.h" + +@implementation DSoField + +- (void)dealloc { + [super dealloc]; +} + +@end /* DSoField */ diff --git a/dbd/DSoHost.h b/dbd/DSoHost.h new file mode 100644 index 00000000..cd0bbd10 --- /dev/null +++ b/dbd/DSoHost.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#ifndef __dbd_DSoHost_H__ +#define __dbd_DSoHost_H__ + +#include "DSoObject.h" + +@class NSString; + +@interface DSoHost : DSoObject +{ + NSString *hostName; + int port; +} + ++ (id)dHostWithName:(NSString *)_key port:(int)_port; +- (id)initWithHostName:(NSString *)_key port:(int)_port; + +/* accessors */ + +- (NSString *)hostName; +- (int)port; + +/* support */ + +- (EOAdaptor *)adaptorInContext:(WOContext *)_ctx; + +@end + +#endif /* __dbd_DSoHost_H__ */ diff --git a/dbd/DSoHost.m b/dbd/DSoHost.m new file mode 100644 index 00000000..b0038db2 --- /dev/null +++ b/dbd/DSoHost.m @@ -0,0 +1,82 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#include "DSoHost.h" +#include "DSoAuthenticator.h" +#include "DSoDatabaseManager.h" +#include "DSoUserManager.h" +#include "common.h" + +@implementation DSoHost + ++ (id)dHostWithName:(NSString *)_key port:(int)_port { + return [[[self alloc] initWithHostName:_key port:_port] autorelease]; +} +- (id)initWithHostName:(NSString *)_key port:(int)_port { + if ((self = [super init])) { + self->hostName = [_key copy]; + self->port = _port > 0 ? _port : 5432; + } + return self; +} + +- (void)dealloc { + [self->hostName release]; + [super dealloc]; +} + +/* accessors */ + +- (NSString *)hostName { + return self->hostName; +} +- (int)port { + return self->port; +} + +/* support */ + +- (EOAdaptor *)adaptorInContext:(WOContext *)_ctx { + return [self adaptorForHostName:[self hostName] port:[self port] + databaseName:nil inContext:_ctx]; +} + +/* authentication */ + +- (id)authenticatorInContext:(id)_ctx { + return [DSoAuthenticator authenticatorWithHostName:[self hostName] + port:[self port]]; +} + +/* names */ + +- (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag { + /* We only need to deal with two fix keys here :-) */ + if ([_key isEqualToString:@"Databases"]) + return [[[DSoDatabaseManager alloc] initWithContainer:self] autorelease]; + if ([_key isEqualToString:@"Users"]) + return [[[DSoUserManager alloc] initWithContainer:self] autorelease]; + + return [super lookupName:_key inContext:_ctx acquire:_flag]; +} + +@end /* DSoHost */ diff --git a/dbd/DSoObject.h b/dbd/DSoObject.h new file mode 100644 index 00000000..4c8ae957 --- /dev/null +++ b/dbd/DSoObject.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#ifndef __dbd_DSoObject_H__ +#define __dbd_DSoObject_H__ + +#import + +@class NSString; +@class EOAdaptor; +@class WOContext; + +@interface DSoObject : NSObject +{ +} + +- (EOAdaptor *)adaptorForHostName:(NSString *)_hname port:(int)_port + databaseName:(NSString *)_dbname inContext:(WOContext *)_ctx; + +@end + +#endif /* __dbd_DSoObject_H__ */ diff --git a/dbd/DSoObject.m b/dbd/DSoObject.m new file mode 100644 index 00000000..f71d6d99 --- /dev/null +++ b/dbd/DSoObject.m @@ -0,0 +1,103 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#include "DSoObject.h" +#include "common.h" +#include +#include + +@implementation DSoObject + +- (void)dealloc { + [super dealloc]; +} + +/* common methods */ + +- (NSString *)defaultDatabase { + /* template1 is supposed to exist always (#postgresql channel ;-) */ + return @"template1"; +} + +- (EOAdaptor *)adaptorForHostName:(NSString *)_hname port:(int)_port + databaseName:(NSString *)_dbname inContext:(WOContext *)_ctx +{ + EOAdaptor *adaptor; + NSDictionary *condict; + NSString *login = nil, *pwd = nil, *auth; + NSArray *creds; + + if ((adaptor = [EOAdaptor adaptorWithName:@"PostgreSQL72"]) == nil) { + [self logWithFormat:@"missing PostgreSQL72 adaptor"]; + return nil; + } + + /* extract login/password */ + + if ((auth = [[_ctx request] headerForKey:@"authorization"]) == nil) { + [self logWithFormat:@"missing 'authorization' .."]; + return nil; + } + creds = [SoHTTPAuthenticator parseCredentials:auth]; + if ([creds count] < 2) { + [self logWithFormat:@"cannot use credentials: %@", creds]; + return nil; + } + login = [creds objectAtIndex:0]; + pwd = [creds objectAtIndex:1]; + + /* create adaptor */ + + _dbname = [_dbname isNotNull] ? _dbname : [self defaultDatabase]; + + // TODO: ignores port + condict = [[NSDictionary alloc] initWithObjectsAndKeys: + _hname, @"hostName", + login, @"userName", + pwd, @"password", + _dbname, @"databaseName", + nil]; + [adaptor setConnectionDictionary:condict]; + [condict release]; + return adaptor; +} + +#if 0 +- (id)GETAction:(id)_ctx { + /* per default, return nothing ... */ + WOResponse *r = [(WOContext *)_ctx response]; + NSString *defName; + + if ((defName = [self defaultMethodNameInContext:_ctx])) { + [r setStatus:302 /* moved */]; + [r setHeader:[[self baseURL] stringByAppendingPathComponent:defName] + forKey:@"location"]; + return r; + } + + [r setStatus:200 /* Ok */]; + [self logWithFormat:@"GET on folder, just saying OK"]; + return r; +} +#endif + +@end /* DSoObject */ diff --git a/dbd/DSoTable.h b/dbd/DSoTable.h new file mode 100644 index 00000000..1ac86c03 --- /dev/null +++ b/dbd/DSoTable.h @@ -0,0 +1,34 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#ifndef __dbd_DSoTable_H__ +#define __dbd_DSoTable_H__ + +#include "DSoObject.h" + +@interface DSoTable : DSoObject +{ +} + +@end + +#endif /* __dbd_DSoTable_H__ */ diff --git a/dbd/DSoTable.m b/dbd/DSoTable.m new file mode 100644 index 00000000..d72fa3fc --- /dev/null +++ b/dbd/DSoTable.m @@ -0,0 +1,32 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#include "DSoTable.h" +#include "common.h" + +@implementation DSoTable + +- (void)dealloc { + [super dealloc]; +} + +@end /* DSoTable */ diff --git a/dbd/DSoUser.h b/dbd/DSoUser.h new file mode 100644 index 00000000..cab69c34 --- /dev/null +++ b/dbd/DSoUser.h @@ -0,0 +1,34 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#ifndef __dbd_DSoUser_H__ +#define __dbd_DSoUser_H__ + +#include "DSoObject.h" + +@interface DSoUser : DSoObject +{ +} + +@end + +#endif /* __dbd_DSoUser_H__ */ diff --git a/dbd/DSoUser.m b/dbd/DSoUser.m new file mode 100644 index 00000000..634b201a --- /dev/null +++ b/dbd/DSoUser.m @@ -0,0 +1,32 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#include "DSoUser.h" +#include "common.h" + +@implementation DSoUser + +- (void)dealloc { + [super dealloc]; +} + +@end /* DSoUser */ diff --git a/dbd/DSoUserManager.h b/dbd/DSoUserManager.h new file mode 100644 index 00000000..b8830cf6 --- /dev/null +++ b/dbd/DSoUserManager.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#ifndef __dbd_DSoUserManager_H__ +#define __dbd_DSoUserManager_H__ + +#include "DSoObject.h" + +@class DSoHost; + +@interface DSoUserManager : DSoObject +{ + DSoHost *host; +} + +- (id)initWithContainer:(DSoHost *)_container; + +@end + +#endif /* __dbd_DSoUserManager_H__ */ diff --git a/dbd/DSoUserManager.m b/dbd/DSoUserManager.m new file mode 100644 index 00000000..00a34662 --- /dev/null +++ b/dbd/DSoUserManager.m @@ -0,0 +1,57 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#include "DSoUserManager.h" +#include "DSoHost.h" +#include "common.h" + +@implementation DSoUserManager + +- (id)initWithContainer:(DSoHost *)_container { + if ((self = [super init])) { + self->host = [_container retain]; + } + return self; +} +- (id)init { + return [self initWithContainer:nil]; +} + +- (void)dealloc { + [self->host release]; + [super dealloc]; +} + +/* name lookup */ + +- (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag { + id obj; + + if ((obj = [super lookupName:_key inContext:_ctx acquire:_flag])) + return obj; + + // TODO: create DSoUser object + + return nil; +} + +@end /* DSoUserManager */ diff --git a/dbd/Frame.m b/dbd/Frame.m new file mode 100644 index 00000000..c4757b1e --- /dev/null +++ b/dbd/Frame.m @@ -0,0 +1,11 @@ +// $Id$ + +#include + +@interface Frame : SoComponent +@end + +#include "common.h" + +@implementation Frame +@end /* Frame */ diff --git a/dbd/Frame.wox b/dbd/Frame.wox new file mode 100644 index 00000000..cf8d7bdf --- /dev/null +++ b/dbd/Frame.wox @@ -0,0 +1,20 @@ + + + + + DB Testdaemon (<var:string value="context.page.name"/>) + + + + + + + + + + + diff --git a/dbd/GNUmakefile b/dbd/GNUmakefile new file mode 100644 index 00000000..3be382c5 --- /dev/null +++ b/dbd/GNUmakefile @@ -0,0 +1,40 @@ +# $Id: GNUmakefile,v 1.13 2004/06/08 11:41:13 helge Exp $ + +include $(GNUSTEP_MAKEFILES)/common.make + +WOAPP_NAME = dbd + +dbd_OBJC_FILES += \ + dbd.m \ + \ + Frame.m \ + MainPage.m \ + DSoAuthenticator.m \ + \ + DSoObject.m \ + DSoHost.m \ + DSoTable.m \ + DSoDatabase.m \ + DSoDatabaseManager.m \ + DSoUser.m \ + DSoUserManager.m \ + DSoField.m \ + \ + DHostView.m \ + +dbd_RESOURCE_FILES += \ + Version \ + product.plist \ + \ + Frame.wox \ + MainPage.wox \ + \ + DHostView.wox \ + +dbd_WEBSERVER_RESOURCE_FILES += + +ADDITIONAL_TOOL_LIBS += -lGDLAccess + +-include GNUmakefile.preamble +include $(GNUSTEP_MAKEFILES)/woapp.make +-include GNUmakefile.postamble diff --git a/dbd/MainPage.m b/dbd/MainPage.m new file mode 100644 index 00000000..6407bf40 --- /dev/null +++ b/dbd/MainPage.m @@ -0,0 +1,87 @@ +// $Id$ + +#include + +@interface MainPage : SoComponent +{ + NSString *hostName; + NSString *databaseName; +} + +@end + +#include "common.h" + +@implementation MainPage + +- (id)initWithContext:(id)_ctx { + if ((self = [super initWithContext:_ctx])) { + self->hostName = @"localhost"; + } + return self; +} + +- (void)dealloc { + [self->hostName release]; + [self->databaseName release]; + [super dealloc]; +} + +/* accessors */ + +- (void)setHostName:(NSString *)_value { + ASSIGNCOPY(self->hostName, _value); +} +- (NSString *)hostName { + return self->hostName; +} + +- (void)setDatabaseName:(NSString *)_value { + ASSIGNCOPY(self->databaseName, _value); +} +- (NSString *)databaseName { + return self->databaseName; +} + +/* actions */ + +- (id)connectAction { + NSString *url; + + [self takeFormValuesForKeys:@"databaseName", @"hostName", nil]; + + if ([[self hostName] length] == 0) + return nil; + + url = [@"/" stringByAppendingString:[[self hostName] stringByEscapingURL]]; + if ([[self databaseName] length] > 0) { + url = [url stringByAppendingString:@"/Databases/"]; + url = [url stringByAppendingString: + [[self databaseName] stringByEscapingURL]]; + } + + url = [[self context] urlWithRequestHandlerKey:@"so" + path:url queryString:nil]; + return [self redirectToLocation:url]; +} + +/* response generation */ + +- (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { + NSString *rhk; + + rhk = [[_ctx request] requestHandlerKey]; + if ([rhk length]==0 || [[self application] requestHandlerForKey:rhk]==nil) { + /* a small hack to redirect to a valid URL */ + NSString *url; + + url = [_ctx urlWithRequestHandlerKey:@"so" path:@"/" queryString:nil]; + [_response setStatus:302 /* moved */]; + [_response setHeader:url forKey:@"location"]; + return; + } + + [super appendToResponse:_response inContext:_ctx]; +} + +@end /* MainPage */ diff --git a/dbd/MainPage.wox b/dbd/MainPage.wox new file mode 100644 index 00000000..17e7c93f --- /dev/null +++ b/dbd/MainPage.wox @@ -0,0 +1,33 @@ + + + + ClientObject: + +
    + + + + + + + + + + + + + + + + + + +
    Host:
    User:
    Database:
    +
    + +
    diff --git a/dbd/README b/dbd/README new file mode 100644 index 00000000..c82916aa --- /dev/null +++ b/dbd/README @@ -0,0 +1,55 @@ +# $Id$ + +PostgreSQL Browser +================== + +Intention: +- fix open SOPE issues +- fix PostgreSQL issues, prepare low-level storage +- work towards SOGo from a storage point of view (with UI-X coming down from a + UI point of view) + +SOPE Hierarchy +- /DBHOST/Databases/MYDB/MYTABLE/MYFIELD +- /DBHOST/Users/MYUSER + +Class Hierarchy + DSoObject + DSoHost "DBHOST" + DSoTable "MYTABLE" + DSoDatabase "MYDB" + DSoDatabaseManager "Database" + DSoUser "MYUSER" + DSoUserManager "Users" + DSoField "MYFIELD" + +Tricks used +=========== + +- small hack in MainPage.m to make a redirect to a "valid" WO URL if the + request-handler-key is missing + - should be made by SOPE itself? + +- own authenticator object + - two different authenticators (with dbname available and without) + +- a hack in the SoApplication -lookupName: to differentiate between + 'hostnames' and resources + +- in DSoObject we extract login/password from the basic auth + - SOPE does all the authentication for SOPE level objects, but if we + want to reuse passwords, we need to do that manually + - we reuse an HTTP parsing method from SoHTTPAuthenticator + +- could -sleep to tear down transient state (not used) + - -sleep is called by the SoObjectRequestHandler + - Note: also supports -_sleepWithContext: + +- note that the EOAdaptor is created by the object, but the channel is created + by the method (the component) + - the object itself is not really active, the methods should be active + - the distinction here is blur, in general I would avoid methods which would + require an [[WOApplication application] context] + +- we are not really clever with DSoUserManager and DSoDatabaseManager, + those two classes are basically identical diff --git a/dbd/Version b/dbd/Version new file mode 100644 index 00000000..1b77c541 --- /dev/null +++ b/dbd/Version @@ -0,0 +1,3 @@ +# $Id: Version,v 1.1 2003/11/24 01:24:40 helge Exp $ + +SUBMINOR_VERSION:=1 diff --git a/dbd/common.h b/dbd/common.h new file mode 100644 index 00000000..ea6a4dbf --- /dev/null +++ b/dbd/common.h @@ -0,0 +1,34 @@ +/* + Copyright (C) 2002-2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#import + +#if NeXT_Foundation_LIBRARY || COCOA_Foundation_LIBRARY +# include +# include +#endif + +#include +#include +#include + +#include diff --git a/dbd/dbd.css b/dbd/dbd.css new file mode 100644 index 00000000..0a8b8b60 --- /dev/null +++ b/dbd/dbd.css @@ -0,0 +1,29 @@ +/* dbd UI Stylesheet */ + +body { + color: #000000; + font-family: Arial, Helvetica, Verdana, Geneva, Tahoma, sans-serif; + font-size: 10pt; + background-color: #FFFFFF; + margin: 0px; + margin-top: 0px; + margin-bottom: 0px; + margin-left: 0px; + margin-right: 0px; +} + +a:link { + color: #0033CC; + font-family: Arial, Helvetica, Verdana, Geneva, Tahoma, sans-serif; + text-decoration: none; +} +a:visited { + color: #660066; + font-family: Arial, Helvetica, Verdana, Geneva, Tahoma, sans-serif; + text-decoration: none; +} +a:hover { + color: #FF0000; + font-family: Arial, Helvetica, Verdana, Geneva, Tahoma, sans-serif; + text-decoration: underline; +} diff --git a/dbd/dbd.m b/dbd/dbd.m new file mode 100644 index 00000000..6dfa0bb9 --- /dev/null +++ b/dbd/dbd.m @@ -0,0 +1,110 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#include + +@interface DBDaemon : SoApplication +{ +} + +@end + +#include "DSoHost.h" +#include "common.h" + +@implementation DBDaemon + +- (id)init { + if ((self = [super init])) { + } + return self; +} + +/* name lookup */ + +- (id)lookupHost:(NSString *)_key inContext:(id)_ctx { + NSRange r; + NSString *hostName; + int port; + + r = [_key rangeOfString:@":"]; + if (r.length == 0) { + hostName = _key; + port = 5432; + } + else { + hostName = [_key substringToIndex:r.location]; + port = [[_key substringFromIndex:(r.location + r.length)] intValue]; + } + return [DSoHost dHostWithName:hostName port:port]; +} + +- (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag { + NSRange r; + id obj; + + /* first check attributes directly bound to the application */ + if ((obj = [super lookupName:_key inContext:_ctx acquire:_flag])) + return obj; + + /* + The problem is, that at this point we still get request for resources, + eg 'favicon.ico'. + The hack here is to check for a dot in the key, but we should find a way + to catch that in a more sensible way. + + One way to check for a valid key would be to check whether the key is a + valid hostname, but I would like to avoid that for performance reasons. + */ + r = [_key rangeOfString:@"."]; + if (r.length == 0) + return [self lookupHost:_key inContext:_ctx]; + + return nil; +} + +/* exception handling */ + +- (WOResponse *)handleException:(NSException *)_exc + inContext:(WOContext *)_ctx +{ + printf("EXCEPTION: %s\n", [[_exc description] cString]); + abort(); +} + +@end /* DBDaemon */ + + +int main(int argc, char **argv, char **env) { + NSAutoreleasePool *pool; + + pool = [[NSAutoreleasePool alloc] init]; +#if LIB_FOUNDATION_LIBRARY + [NSProcessInfo initializeWithArguments:argv count:argc environment:env]; +#endif + [NGBundleManager defaultBundleManager]; + + WOWatchDogApplicationMain(@"DBDaemon", argc, (void*)argv); + + [pool release]; + return 0; +} diff --git a/dbd/product.plist b/dbd/product.plist new file mode 100644 index 00000000..8a02ae0f --- /dev/null +++ b/dbd/product.plist @@ -0,0 +1,79 @@ +{ + publicResources = ( + "dbd.css" + ); + + classes = { + DBDaemon = { + superclass = "SoApplication"; + protectedBy = "View"; + defaultAccess = "allow"; + defaultRoles = { + "View" = "Anonymous"; + "WebDAV Access" = "Authenticated"; + }; + methods = { + "index" = { + protectedBy = "View"; + pageName = "MainPage"; + }; + "connect" = { + protectedBy = "View"; + pageName = "MainPage"; + actionName = "connect"; + }; + }; + }; + + DSoObject = { + protectedBy = "View"; + defaultAccess = "allow"; + defaultRoles = { + "View" = "Authenticated"; + "WebDAV Access" = "Authenticated"; + }; + methods = { + }; + }; + + DSoHost = { + superclass = "DSoObject"; + methods = { + "index" = { + protectedBy = "View"; + pageName = "DHostView"; + }; + }; + }; + DSoTable = { + superclass = "DSoObject"; + methods = { + }; + }; + DSoDatabase = { + superclass = "DSoObject"; + methods = { + }; + }; + DSoDatabaseManager = { + superclass = "DSoObject"; + methods = { + }; + }; + DSoUser = { + superclass = "DSoObject"; + methods = { + }; + }; + DSoUserManager = { + superclass = "DSoObject"; + methods = { + }; + }; + DSoField = { + superclass = "DSoObject"; + methods = { + }; + }; + }; +}