2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
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.
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
23 #include "SOGoContactFolder.h"
24 #include <SOGo/SOGoCustomGroupFolder.h>
25 #include <SOGoLogic/AgenorUserManager.h>
26 #include <OGoContentStore/OCSFolder.h>
27 #include <NGiCal/NGiCal.h>
32 @implementation SOGoContactFolder
34 static BOOL debugOn = YES;
36 + (NSString *)globallyUniqueObjectId {
38 4C08AE1A-A808-11D8-AC5A-000393BBAFF6
39 SOGo-Web-28273-18283-288182
40 printf( "%x", *(int *) &f);
43 static int sequence = 0;
44 static float rndm = 0;
47 if (pid == 0) { /* break if we fork ;-) */
52 f = [[NSDate date] timeIntervalSince1970];
53 return [NSString stringWithFormat:@"%0X-%0X-%0X-%0X",
54 pid, *(int *)&f, sequence++, random];
63 - (BOOL)isValidContactName:(NSString *)_key {
64 if ([_key length] == 0)
70 - (id)contactWithName:(NSString *)_key inContext:(id)_ctx {
71 static Class ctClass = Nil;
75 ctClass = NSClassFromString(@"SOGoContactObject");
77 [self errorWithFormat:@"missing SOGoContactObject class!"];
81 ct = [[ctClass alloc] initWithName:_key inContainer:self];
82 return [ct autorelease];
85 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
88 /* first check attributes directly bound to the application */
89 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
92 if ([self isValidContactName:_key])
93 return [self contactWithName:_key inContext:_ctx];
95 /* return 404 to stop acquisition */
96 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
101 - (NSArray *)fixupRecords:(NSArray *)_records {
105 - (NSArray *)fetchCoreInfos {
106 NSArray *fields, *records;
108 fields = [NSArray arrayWithObjects:
110 @"sn", @"givenname", @"l",
111 @"mail", @"telephonenumber",
113 records = [[self ocsFolder] fetchFields:fields matchingQualifier:nil];
114 if (records == nil) {
115 [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
118 records = [self fixupRecords:records];
120 [self logWithFormat:@"fetched %i records.", [records count]];
126 - (id)GETAction:(WOContext *)_ctx {
127 // TODO: I guess this should really be done by SOPE (redirect to
132 uri = [[_ctx request] uri];
133 if (![uri hasSuffix:@"/"]) uri = [uri stringByAppendingString:@"/"];
134 uri = [uri stringByAppendingString:@"view"];
137 [r setStatus:302 /* moved */];
138 [r setHeader:uri forKey:@"location"];
142 @end /* SOGoContactFolder */