1 /* SOGoContactLDAPFolder.m - this file is part of SOGo
3 * Copyright (C) 2006 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSString.h>
27 #import <NGObjWeb/NSException+HTTP.h>
28 #import <NGObjWeb/SoObject.h>
29 #import <NGObjWeb/WOApplication.h>
30 #import <NGObjWeb/WOContext.h>
31 #import <NGObjWeb/WOContext+SoObjects.h>
32 #import <NGObjWeb/SoUser.h>
33 #import <EOControl/EOSortOrdering.h>
35 #import <SoObjects/SOGo/LDAPSource.h>
36 #import "SOGoContactLDIFEntry.h"
37 #import "SOGoContactLDAPFolder.h"
39 #define folderListingFields [NSArray arrayWithObjects: @"c_name", @"cn", \
43 @"sn", @"givenname", @"l", \
44 @"mail", @"telephonenumber", \
52 @implementation SOGoContactLDAPFolder
54 + (id <SOGoContactFolder>) contactFolderWithName: (NSString *) aName
55 andDisplayName: (NSString *) aDisplayName
56 inContainer: (SOGoObject *) aContainer
58 SOGoContactLDAPFolder *folder;
60 folder = [[self alloc] initWithName: aName
61 andDisplayName: aDisplayName
62 inContainer: aContainer];
70 if ((self = [super init]))
82 - (id <SOGoContactFolder>) initWithName: (NSString *) newName
83 andDisplayName: (NSString *) newDisplayName
84 inContainer: (SOGoObject *) newContainer
88 ASSIGN (name, newName);
89 ASSIGN (displayName, newDisplayName);
90 ASSIGN (container, newContainer);
98 [displayName release];
101 [ldapSource release];
105 - (void) setLDAPSource: (LDAPSource *) newLDAPSource
107 ASSIGN (ldapSource, newLDAPSource);
110 - (NSString *) displayName
115 - (NSString *) nameInContainer
120 - (id) lookupName: (NSString *) objectName
121 inContext: (WOContext *) lookupContext
122 acquire: (BOOL) acquire
125 NSDictionary *ldifEntry;
127 // NSLog (@"looking up name '%@'...", name);
129 /* first check attributes directly bound to the application */
130 obj = [super lookupName: objectName inContext: lookupContext acquire: NO];
133 ldifEntry = [ldapSource lookupContactEntry: objectName];
135 ? [SOGoContactLDIFEntry contactEntryWithName: name
136 withLDIFEntry: ldifEntry
138 : [NSException exceptionWithHTTPStatus: 404]);
144 - (NSArray *) toOneRelationshipKeys
146 return [ldapSource allEntryIDs];
149 - (NSArray *) lookupContactsWithFilter: (NSString *) filter
150 sortBy: (NSString *) sortKey
151 ordering: (NSComparisonResult) sortOrdering
153 NSArray *records, *result;
154 EOSortOrdering *ordering;
158 if (filter && [filter length] > 0)
160 records = [ldapSource fetchContactsMatching: filter];
162 = [EOSortOrdering sortOrderingWithKey: sortKey
163 selector: ((sortOrdering == NSOrderedDescending)
164 ? EOCompareCaseInsensitiveDescending
165 : EOCompareCaseInsensitiveAscending)];
167 = [records sortedArrayUsingKeyOrderArray:
168 [NSArray arrayWithObject: ordering]];
171 //[self debugWithFormat:@"fetched %i records.", [records count]];
175 - (NSString *) groupDavResourceType
177 return @"vcard-collection";
181 /* TODO: this might change one day when we support LDAP acls */
182 - (NSArray *) aclsForUser: (NSString *) uid