]> err.no Git - scalable-opengroupware.org/blob - Misc/dbd/DSoObject.m
e6ea9297337baa3b04738393e923840d5c9405cc
[scalable-opengroupware.org] / Misc / dbd / DSoObject.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "DSoObject.h"
24 #include "common.h"
25 #include <NGObjWeb/SoHTTPAuthenticator.h>
26 #include <GDLAccess/GDLAccess.h>
27
28 @implementation DSoObject
29
30 - (void)dealloc {
31   [super dealloc];
32 }
33
34 /* common methods */
35
36 - (NSString *)defaultDatabase {
37   /* template1 is supposed to exist always (#postgresql channel ;-) */
38   return @"template1";
39 }
40
41 - (EOAdaptor *)adaptorForHostName:(NSString *)_hname port:(int)_port
42   databaseName:(NSString *)_dbname inContext:(WOContext *)_ctx
43 {
44   EOAdaptor    *adaptor;
45   NSDictionary *condict;
46   NSString     *login = nil, *pwd = nil, *auth;
47   NSArray      *creds;
48   
49   if ((adaptor = [EOAdaptor adaptorWithName:@"PostgreSQL72"]) == nil) {
50     [self logWithFormat:@"missing PostgreSQL72 adaptor"];
51     return nil;
52   }
53   
54   /* extract login/password */
55
56   if ((auth = [[_ctx request] headerForKey:@"authorization"]) == nil) {
57     [self logWithFormat:@"missing 'authorization' .."];
58     return nil;
59   }
60   creds = [SoHTTPAuthenticator parseCredentials:auth];
61   if ([creds count] < 2) {
62     [self logWithFormat:@"cannot use credentials: %@", creds];
63     return nil;
64   }
65   login = [creds objectAtIndex:0];
66   pwd   = [creds objectAtIndex:1];
67   
68   /* create adaptor */
69   
70   _dbname = [_dbname isNotNull] ? _dbname : [self defaultDatabase];
71   
72   // TODO: ignores port
73   condict = [[NSDictionary alloc] initWithObjectsAndKeys:
74                                     _hname,  @"hostName",
75                                     login,   @"userName",
76                                     pwd,     @"password",
77                                     _dbname, @"databaseName",
78                                   nil];
79   [adaptor setConnectionDictionary:condict];
80   [condict release];
81   return adaptor;
82 }
83
84 #if 0
85 - (id)GETAction:(id)_ctx {
86   /* per default, return nothing ... */
87   WOResponse *r = [(WOContext *)_ctx response];
88   NSString   *defName;
89   
90   if ((defName = [self defaultMethodNameInContext:_ctx])) {
91     [r setStatus:302 /* moved */];
92     [r setHeader:[[self baseURL] stringByAppendingPathComponent:defName]
93        forKey:@"location"];
94     return r;
95   }
96   
97   [r setStatus:200 /* Ok */];
98   [self logWithFormat:@"GET on folder, just saying OK"];
99   return r;
100 }
101 #endif
102
103 /* OSX hack */
104
105 - (id)valueForUndefinedKey:(NSString *)_key {
106   [self debugWithFormat:@"queried undefined key: '%@'", _key];
107   return nil;
108 }
109
110 - (BOOL)isCollection {
111   return YES;
112 }
113
114 @end /* DSoObject */