diff --git a/ChangeLog b/ChangeLog index 4dbb3e697..8467a01d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-05-09 Wolfgang Sourdeau + * SoObjects/Contacts/SOGoContactLDAPFolder.m + ([SOGoContactLDAPFolder + +contactFolderWithName:aNameandDisplayName:aDisplayNameinContainer:aContainer]): + no longer manage LDAP connections. The requests are forwarded to + the relevant LDAPSource instead. + * SoObjects/Contacts/SOGoContactFolders.m ([SOGoContactFolders -appendSystemSources]): pass LDAPSource objects to SOGoContactLDAPFolder instances. diff --git a/SoObjects/Contacts/SOGoContactLDAPFolder.h b/SoObjects/Contacts/SOGoContactLDAPFolder.h index 88a89063f..e6805070a 100644 --- a/SoObjects/Contacts/SOGoContactLDAPFolder.h +++ b/SoObjects/Contacts/SOGoContactLDAPFolder.h @@ -23,34 +23,25 @@ #ifndef SOGOCONTACTLDAPFOLDER_H #define SOGOCONTACTLDAPFOLDER_H -#import #import "SOGoContactFolder.h" -@class NSString, NSArray; -@class NGLdapConnection; +@class NSMutableDictionary; + +@class LDAPSource; @interface SOGoContactLDAPFolder : SOGoObject { - NGLdapConnection *connection; - NSString *contactIdentifier; - NSString *userIdentifier; - NSString *rootDN; + NSString *name; NSString *displayName; + id container; + LDAPSource *ldapSource; NSMutableDictionary *entries; } -- (NGLdapConnection *) LDAPconnection; - -- (void) setDisplayName: (NSString *) aDisplayName; -- (NSString *) displayName; - -- (void) LDAPSetHostname: (NSString *) aHostname - setPort: (int) aPort - setBindDN: (NSString *) aBindDN - setBindPW: (NSString *) aBindPW - setContactIdentifier: (NSString *) aCI - setUserIdentifier: (NSString *) aUI - setRootDN: (NSString *) aRootDN; +- (id ) initWithName: (NSString *) newName + andDisplayName: (NSString *) newDisplayName + inContainer: (SOGoObject *) newContainer; +- (void) setLDAPSource: (LDAPSource *) newLdapSource; @end diff --git a/SoObjects/Contacts/SOGoContactLDAPFolder.m b/SoObjects/Contacts/SOGoContactLDAPFolder.m index b15ed3033..75c198947 100644 --- a/SoObjects/Contacts/SOGoContactLDAPFolder.m +++ b/SoObjects/Contacts/SOGoContactLDAPFolder.m @@ -21,25 +21,19 @@ */ #import -#import - #import #import +#import +#import #import #import #import #import +#import -#import -#import -#import - -#import "common.h" - -#import "NGLdapEntry+Contact.h" - -#import "SOGoContactLDAPEntry.h" +#import +#import "SOGoContactLDIFEntry.h" #import "SOGoContactLDAPFolder.h" #define folderListingFields [NSArray arrayWithObjects: @"c_name", @"cn", \ @@ -75,44 +69,42 @@ { if ((self = [super init])) { - connection = nil; - contactIdentifier = nil; - userIdentifier = nil; - rootDN = nil; + name = nil; + displayName = nil; + container = nil; entries = nil; + ldapSource = nil; } return self; } -- (id ) initWithName: (NSString *) aName - andDisplayName: (NSString *) aDisplayName - inContainer: (SOGoObject *) aContainer +- (id ) initWithName: (NSString *) newName + andDisplayName: (NSString *) newDisplayName + inContainer: (SOGoObject *) newContainer { - if ((self = [self initWithName: aName - inContainer: aContainer])) - [self setDisplayName: aDisplayName]; - + self = [self init]; + + ASSIGN (name, newName); + ASSIGN (displayName, newDisplayName); + ASSIGN (container, newContainer); + return self; } - (void) dealloc { - [connection release]; - [contactIdentifier release]; - [userIdentifier release]; - [rootDN release]; + [name release]; + [displayName release]; + [container release]; [entries release]; + [ldapSource release]; [super dealloc]; } -- (void) setDisplayName: (NSString *) aDisplayName +- (void) setLDAPSource: (LDAPSource *) newLDAPSource { - if (displayName) - [displayName release]; - displayName = aDisplayName; - if (displayName) - [displayName retain]; + ASSIGN (ldapSource, newLDAPSource); } - (NSString *) displayName @@ -120,178 +112,30 @@ return displayName; } -- (void) LDAPSetHostname: (NSString *) aHostname - setPort: (int) aPort - setBindDN: (NSString *) aBindDN - setBindPW: (NSString *) aBindPW - setContactIdentifier: (NSString *) aCI - setUserIdentifier: (NSString *) aUI - setRootDN: (NSString *) aRootDN; +- (NSString *) nameInContainer { - connection = [[NGLdapConnection alloc] initWithHostName: aHostname - port: aPort]; - [connection bindWithMethod: nil - binddn: aBindDN - credentials: aBindPW]; - - if (rootDN) - [rootDN release]; - rootDN = [aRootDN copy]; - if (contactIdentifier) - [contactIdentifier release]; - contactIdentifier = [aCI copy]; - if (userIdentifier) - [userIdentifier release]; - userIdentifier = [aUI copy]; + return name; } -- (NGLdapConnection *) LDAPconnection -{ - return connection; -} - -- (NGLdapAttribute *) _attrWithName: (NSString *) aName -{ - return [[[NGLdapAttribute alloc] initWithAttributeName: aName] autorelease]; -} - -- (NSArray *) _searchAttributes -{ - return [NSArray arrayWithObjects: - contactIdentifier, - userIdentifier, - @"title", - @"company", - @"o", - @"displayName", - @"modifytimestamp", - @"mozillaHomeState", - @"mozillaHomeUrl", - @"homeurl", - @"st", - @"region", - @"mozillaCustom2", - @"custom2", - @"mozillaHomeCountryName", - @"description", - @"notes", - @"department", - @"departmentnumber", - @"ou", - @"orgunit", - @"mobile", - @"cellphone", - @"carphone", - @"mozillaCustom1", - @"custom1", - @"mozillaNickname", - @"xmozillanickname", - @"mozillaWorkUrl", - @"workurl", - @"fax", - @"facsimileTelephoneNumber", - @"telephoneNumber", - @"mozillaHomeStreet", - @"mozillaSecondEmail", - @"xmozillasecondemail", - @"mozillaCustom4", - @"custom4", - @"nsAIMid", - @"nscpaimscreenname", - @"street", - @"streetAddress", - @"postOfficeBox", - @"homePhone", - @"cn", - @"commonname", - @"givenName", - @"mozillaHomePostalCode", - @"mozillaHomeLocalityName", - @"mozillaWorkStreet2", - @"mozillaUseHtmlMail", - @"xmozillausehtmlmail", - @"mozillaHomeStreet2", - @"postalCode", - @"zip", - @"c", - @"countryname", - @"pager", - @"pagerphone", - @"mail", - @"sn", - @"surname", - @"mozillaCustom3", - @"custom3", - @"l", - @"locality", - @"birthyear", - @"serialNumber", - @"calFBURL", - nil]; -} - -- (void) _loadEntries: (NSString *) entryId -{ - NSEnumerator *contacts; - NGLdapEntry *entry; - NSString *key; - - if (!entries) - entries = [NSMutableDictionary new]; - - if (entryId) - { - if (![entries objectForKey: entryId]) - { - entry - = [connection entryAtDN: - [NSString stringWithFormat: @"%@=%@,%@", - contactIdentifier, entryId, rootDN] - attributes: [self _searchAttributes]]; - if (entry) - [entries setObject: entry forKey: entryId]; - } - } - else - { - contacts = [connection deepSearchAtBaseDN: rootDN - qualifier: nil - attributes: [self _searchAttributes]]; - if (contacts) - { - entry = [contacts nextObject]; - while (entry) - { - key = [[entry attributeWithName: contactIdentifier] - stringValueAtIndex: 0]; - if (key && ![entries objectForKey: key]) - [entries setObject: entry forKey: key]; - entry = [contacts nextObject]; - } - } - } -} - -- (id) lookupName: (NSString *) name +- (id) lookupName: (NSString *) objectName inContext: (WOContext *) lookupContext acquire: (BOOL) acquire { id obj; - NGLdapEntry *entry; + NSDictionary *ldifEntry; // NSLog (@"looking up name '%@'...", name); /* first check attributes directly bound to the application */ - obj = [super lookupName: name inContext: lookupContext acquire: NO]; + obj = [super lookupName: objectName inContext: lookupContext acquire: NO]; if (!obj) { - [self _loadEntries: name]; - entry = [entries objectForKey: name]; - obj = ((entry) - ? [SOGoContactLDAPEntry contactEntryWithName: name - withLDAPEntry: entry - inContainer: self] - : [NSException exceptionWithHTTPStatus: 404]); + ldifEntry = [ldapSource lookupContactEntry: objectName]; + obj = ((ldifEntry) + ? [SOGoContactLDIFEntry contactEntryWithName: name + withLDIFEntry: ldifEntry + inContainer: self] + : [NSException exceptionWithHTTPStatus: 404]); } return obj; @@ -299,83 +143,21 @@ - (NSArray *) toOneRelationshipKeys { - [self _loadEntries: nil]; - - return [entries allKeys]; -} - -- (id ) lookupContactWithId: (NSString *) recordId -{ - NGLdapEntry *entry; - - [self _loadEntries: recordId]; - - entry = [entries objectForKey: recordId]; - return ((entry) - ? [SOGoContactLDAPEntry contactEntryWithName: recordId - withLDAPEntry: entry - inContainer: self] - : nil); -} - -- (EOQualifier *) _qualifierForFilter: (NSString *) filter -{ - NSString *qs; - EOQualifier *qualifier; - - if (filter && [filter length] > 0) - { - if ([filter isEqualToString: @"."]) - qs = @"(cn='*')"; - else - qs = [NSString stringWithFormat: - @"(cn='%@*')" - @"OR (sn='%@*')" - @"OR (displayName='%@*')" - @"OR (mail='%@*')" - @"OR (telephoneNumber='*%@*')", - filter, filter, filter, filter, filter]; - qualifier = [EOQualifier qualifierWithQualifierFormat: qs]; - } - else - qualifier = nil; - - return qualifier; + return [ldapSource allEntryIDs]; } - (NSArray *) lookupContactsWithFilter: (NSString *) filter sortBy: (NSString *) sortKey ordering: (NSComparisonResult) sortOrdering { - NSMutableArray *records; - NSArray *result; - NGLdapEntry *entry; - NSEnumerator *contacts; + NSArray *records, *result; EOSortOrdering *ordering; result = nil; if (filter && [filter length] > 0) { - NSLog (@"%@: fetching records matching '%@', sorted by '%@'" - @" in order %d", - self, filter, sortKey, sortOrdering); - - records = [NSMutableArray new]; - [records autorelease]; - - contacts = [connection deepSearchAtBaseDN: rootDN - qualifier: [self _qualifierForFilter: filter] - attributes: folderListingFields]; - entry = [contacts nextObject]; - while (entry) - { - [records addObject: [entry asDictionaryWithAttributeNames: nil - withUID: userIdentifier - andCName: contactIdentifier]]; - entry = [contacts nextObject]; - } - + records = [ldapSource fetchContactsMatching: filter]; ordering = [EOSortOrdering sortOrderingWithKey: sortKey selector: ((sortOrdering == NSOrderedDescending)