2006-08-09 23:22:26 +02:00
|
|
|
/* SOGoContactLDAPFolder.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
2007-05-09 21:19:30 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
|
|
|
#import <NGObjWeb/SoObject.h>
|
2006-08-09 23:22:26 +02:00
|
|
|
#import <NGObjWeb/WOApplication.h>
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGObjWeb/SoUser.h>
|
2007-05-09 21:19:30 +02:00
|
|
|
#import <EOControl/EOSortOrdering.h>
|
2007-06-01 07:53:22 +02:00
|
|
|
#import <SaxObjC/XMLNamespaces.h>
|
2006-08-09 23:22:26 +02:00
|
|
|
|
2007-05-09 21:19:30 +02:00
|
|
|
#import <SoObjects/SOGo/LDAPSource.h>
|
|
|
|
#import "SOGoContactLDIFEntry.h"
|
2006-08-09 23:22:26 +02:00
|
|
|
#import "SOGoContactLDAPFolder.h"
|
|
|
|
|
2006-08-14 22:35:11 +02:00
|
|
|
#define folderListingFields [NSArray arrayWithObjects: @"c_name", @"cn", \
|
2006-09-26 20:53:42 +02:00
|
|
|
@"displayName", \
|
2006-10-27 19:47:10 +02:00
|
|
|
@"streetAddress", \
|
2007-04-02 22:06:53 +02:00
|
|
|
@"o", \
|
2006-08-14 22:35:11 +02:00
|
|
|
@"sn", @"givenname", @"l", \
|
|
|
|
@"mail", @"telephonenumber", \
|
|
|
|
@"mailNickname", \
|
|
|
|
@"sAMAccountName", \
|
2007-04-17 15:45:03 +02:00
|
|
|
@"uid", \
|
2006-08-14 22:35:11 +02:00
|
|
|
nil]
|
|
|
|
|
2006-08-09 23:22:26 +02:00
|
|
|
@class WOContext;
|
|
|
|
|
|
|
|
@implementation SOGoContactLDAPFolder
|
|
|
|
|
|
|
|
+ (id <SOGoContactFolder>) contactFolderWithName: (NSString *) aName
|
|
|
|
andDisplayName: (NSString *) aDisplayName
|
|
|
|
inContainer: (SOGoObject *) aContainer
|
|
|
|
{
|
|
|
|
SOGoContactLDAPFolder *folder;
|
|
|
|
|
|
|
|
folder = [[self alloc] initWithName: aName
|
|
|
|
andDisplayName: aDisplayName
|
|
|
|
inContainer: aContainer];
|
|
|
|
[folder autorelease];
|
|
|
|
|
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2007-05-09 21:19:30 +02:00
|
|
|
displayName = nil;
|
2006-08-09 23:22:26 +02:00
|
|
|
entries = nil;
|
2007-05-09 21:19:30 +02:00
|
|
|
ldapSource = nil;
|
2007-07-20 22:21:59 +02:00
|
|
|
ignoreSoObjectHunger = NO;
|
2006-08-09 23:22:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-05-09 21:19:30 +02:00
|
|
|
- (id <SOGoContactFolder>) initWithName: (NSString *) newName
|
|
|
|
andDisplayName: (NSString *) newDisplayName
|
|
|
|
inContainer: (SOGoObject *) newContainer
|
2006-08-09 23:22:26 +02:00
|
|
|
{
|
2007-06-01 22:45:16 +02:00
|
|
|
if ((self = [self initWithName: newName
|
|
|
|
inContainer: newContainer]))
|
|
|
|
{
|
|
|
|
ASSIGN (displayName, newDisplayName);
|
|
|
|
}
|
2007-05-09 21:19:30 +02:00
|
|
|
|
2006-08-09 23:22:26 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-05-09 21:19:30 +02:00
|
|
|
[displayName release];
|
2007-04-17 15:45:03 +02:00
|
|
|
[entries release];
|
2007-05-09 21:19:30 +02:00
|
|
|
[ldapSource release];
|
2006-08-09 23:22:26 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-05-09 21:19:30 +02:00
|
|
|
- (void) setLDAPSource: (LDAPSource *) newLDAPSource
|
2006-08-09 23:22:26 +02:00
|
|
|
{
|
2007-05-09 21:19:30 +02:00
|
|
|
ASSIGN (ldapSource, newLDAPSource);
|
2006-08-09 23:22:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) displayName
|
|
|
|
{
|
|
|
|
return displayName;
|
|
|
|
}
|
|
|
|
|
2007-05-09 21:19:30 +02:00
|
|
|
- (id) lookupName: (NSString *) objectName
|
2007-04-11 21:08:58 +02:00
|
|
|
inContext: (WOContext *) lookupContext
|
2006-08-09 23:22:26 +02:00
|
|
|
acquire: (BOOL) acquire
|
|
|
|
{
|
|
|
|
id obj;
|
2007-05-09 21:19:30 +02:00
|
|
|
NSDictionary *ldifEntry;
|
2006-08-09 23:22:26 +02:00
|
|
|
|
2006-10-27 19:47:10 +02:00
|
|
|
// NSLog (@"looking up name '%@'...", name);
|
2006-08-09 23:22:26 +02:00
|
|
|
|
|
|
|
/* first check attributes directly bound to the application */
|
2007-07-20 22:21:59 +02:00
|
|
|
ignoreSoObjectHunger = YES;
|
2007-05-09 21:19:30 +02:00
|
|
|
obj = [super lookupName: objectName inContext: lookupContext acquire: NO];
|
2007-07-20 22:21:59 +02:00
|
|
|
ignoreSoObjectHunger = NO;
|
2006-08-09 23:22:26 +02:00
|
|
|
if (!obj)
|
|
|
|
{
|
2007-05-09 21:19:30 +02:00
|
|
|
ldifEntry = [ldapSource lookupContactEntry: objectName];
|
|
|
|
obj = ((ldifEntry)
|
2007-06-01 22:45:16 +02:00
|
|
|
? [SOGoContactLDIFEntry contactEntryWithName: objectName
|
2007-05-09 21:19:30 +02:00
|
|
|
withLDIFEntry: ldifEntry
|
|
|
|
inContainer: self]
|
|
|
|
: [NSException exceptionWithHTTPStatus: 404]);
|
2006-08-09 23:22:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) toOneRelationshipKeys
|
|
|
|
{
|
2007-07-20 22:21:59 +02:00
|
|
|
NSArray *keys;
|
|
|
|
|
|
|
|
if (ignoreSoObjectHunger)
|
|
|
|
keys = nil;
|
|
|
|
else
|
|
|
|
keys = [ldapSource allEntryIDs];
|
|
|
|
|
|
|
|
return keys;
|
2006-08-09 23:22:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) lookupContactsWithFilter: (NSString *) filter
|
|
|
|
sortBy: (NSString *) sortKey
|
|
|
|
ordering: (NSComparisonResult) sortOrdering
|
|
|
|
{
|
2007-05-09 21:19:30 +02:00
|
|
|
NSArray *records, *result;
|
2006-08-09 23:22:26 +02:00
|
|
|
EOSortOrdering *ordering;
|
|
|
|
|
|
|
|
result = nil;
|
|
|
|
|
|
|
|
if (filter && [filter length] > 0)
|
|
|
|
{
|
2007-05-09 21:19:30 +02:00
|
|
|
records = [ldapSource fetchContactsMatching: filter];
|
2006-08-09 23:22:26 +02:00
|
|
|
ordering
|
|
|
|
= [EOSortOrdering sortOrderingWithKey: sortKey
|
|
|
|
selector: ((sortOrdering == NSOrderedDescending)
|
|
|
|
? EOCompareCaseInsensitiveDescending
|
|
|
|
: EOCompareCaseInsensitiveAscending)];
|
|
|
|
result
|
|
|
|
= [records sortedArrayUsingKeyOrderArray:
|
|
|
|
[NSArray arrayWithObject: ordering]];
|
|
|
|
}
|
|
|
|
|
|
|
|
//[self debugWithFormat:@"fetched %i records.", [records count]];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-06-01 07:52:37 +02:00
|
|
|
- (NSArray *) davResourceType
|
2006-12-14 22:20:13 +01:00
|
|
|
{
|
2007-06-01 07:52:37 +02:00
|
|
|
NSArray *rType, *groupDavCollection;
|
|
|
|
|
|
|
|
groupDavCollection = [NSArray arrayWithObjects: @"vcard-collection",
|
|
|
|
XMLNS_GROUPDAV, nil];
|
|
|
|
rType = [NSArray arrayWithObjects: @"collection", groupDavCollection, nil];
|
|
|
|
|
|
|
|
return rType;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) davContentType
|
|
|
|
{
|
|
|
|
return @"httpd/unix-directory";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) davIsCollection
|
|
|
|
{
|
|
|
|
return YES;
|
2006-12-14 22:20:13 +01:00
|
|
|
}
|
|
|
|
|
2007-06-01 22:45:16 +02:00
|
|
|
- (NSString *) davDisplayName
|
|
|
|
{
|
|
|
|
return displayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isFolderish
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-04-25 00:43:33 +02:00
|
|
|
/* acls */
|
|
|
|
/* TODO: this might change one day when we support LDAP acls */
|
|
|
|
- (NSArray *) aclsForUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2006-08-09 23:22:26 +02:00
|
|
|
@end
|