From e3c7bdd5d8a653d3dd8e2a33517eb5668c86e573 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Tue, 17 May 2016 13:41:33 -0400 Subject: [PATCH] Revert "Remove listRequiresDot option from *Source classes" This reverts commit 6b2ec7a2e75084359af75bcd3f473084eed09467. --- SoObjects/Contacts/SOGoContactSourceFolder.m | 29 +++++++--- SoObjects/SOGo/LDAPSource.h | 2 + SoObjects/SOGo/LDAPSource.m | 59 +++++++++++++------- SoObjects/SOGo/SOGoSource.h | 4 ++ SoObjects/SOGo/SQLSource.m | 11 ++++ 5 files changed, 77 insertions(+), 28 deletions(-) diff --git a/SoObjects/Contacts/SOGoContactSourceFolder.m b/SoObjects/Contacts/SOGoContactSourceFolder.m index 464a787c4..bf4f30bd8 100644 --- a/SoObjects/Contacts/SOGoContactSourceFolder.m +++ b/SoObjects/Contacts/SOGoContactSourceFolder.m @@ -353,15 +353,26 @@ NSArray *records, *result; EOSortOrdering *ordering; - records = [source fetchContactsMatching: filter inDomain: domain]; - [childRecords setObjects: records forKeys: [records objectsForKey: @"c_name" - notFoundMarker: nil]]; - records = [self _flattenedRecords: records]; - ordering = [EOSortOrdering sortOrderingWithKey: sortKey - selector: ((sortOrdering == NSOrderedDescending) - ? EOCompareCaseInsensitiveDescending - : EOCompareCaseInsensitiveAscending)]; - result = [records sortedArrayUsingKeyOrderArray: [NSArray arrayWithObject: ordering]]; + result = nil; + + if (([filter length] > 0 && [criteria isEqualToString: @"name_or_address"]) + || ![source listRequiresDot]) + { + records = [source fetchContactsMatching: filter + inDomain: domain]; + [childRecords setObjects: records + forKeys: [records objectsForKey: @"c_name" + notFoundMarker: nil]]; + records = [self _flattenedRecords: records]; + ordering + = [EOSortOrdering sortOrderingWithKey: sortKey + selector: ((sortOrdering == NSOrderedDescending) + ? EOCompareCaseInsensitiveDescending + : EOCompareCaseInsensitiveAscending)]; + result + = [records sortedArrayUsingKeyOrderArray: + [NSArray arrayWithObject: ordering]]; + } return result; } diff --git a/SoObjects/SOGo/LDAPSource.h b/SoObjects/SOGo/LDAPSource.h index 4958b0cee..9081196be 100644 --- a/SoObjects/SOGo/LDAPSource.h +++ b/SoObjects/SOGo/LDAPSource.h @@ -65,6 +65,8 @@ NSString *SieveHostField; NSArray *bindFields; + BOOL listRequiresDot; + NSString *domain; NSString *contactInfoAttribute; diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index 32553fe2d..2fa8f3773 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -110,6 +110,7 @@ static Class NSStringK; _scope = @"sub"; _filter = nil; _userPasswordAlgorithm = nil; + listRequiresDot = YES; searchAttributes = nil; passwordPolicy = NO; @@ -200,6 +201,9 @@ static Class NSStringK; kindField: [udSource objectForKey: @"KindFieldName"] andMultipleBookingsField: [udSource objectForKey: @"MultipleBookingsFieldName"]]; + dotValue = [udSource objectForKey: @"listRequiresDot"]; + if (dotValue) + [self setListRequiresDot: [dotValue boolValue]]; [self setContactMapping: [udSource objectForKey: @"mapping"] andObjectClasses: [udSource objectForKey: @"objectClasses"]]; @@ -367,6 +371,16 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses ASSIGN(multipleBookingsField, [newMultipleBookingsField lowercaseString]); } +- (void) setListRequiresDot: (BOOL) aBool +{ + listRequiresDot = aBool; +} + +- (BOOL) listRequiresDot +{ + return listRequiresDot; +} + - (void) setContactMapping: (NSDictionary *) newMapping andObjectClasses: (NSArray *) newObjectClasses { @@ -776,13 +790,15 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses qualifier = [EOQualifier qualifierWithQualifierFormat: qs]; } - else + else if (!listRequiresDot) { qs = [NSMutableString stringWithFormat: @"(%@='*')", CNField]; if ([_filter length]) [qs appendFormat: @" AND %@", _filter]; qualifier = [EOQualifier qualifierWithQualifierFormat: qs]; } + else + qualifier = nil; return qualifier; } @@ -1173,25 +1189,29 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses contacts = [NSMutableArray array]; - ldapConnection = [self _ldapConnection]; - qualifier = [self _qualifierForFilter: match]; - // attributes = [self _searchAttributes]; - attributes = [NSArray arrayWithObject: @"*"]; + if ([match length] > 0 || !listRequiresDot) + { + ldapConnection = [self _ldapConnection]; + qualifier = [self _qualifierForFilter: match]; + // attributes = [self _searchAttributes]; + attributes = [NSArray arrayWithObject: @"*"]; - if ([_scope caseInsensitiveCompare: @"BASE"] == NSOrderedSame) - entries = [ldapConnection baseSearchAtBaseDN: baseDN - qualifier: qualifier - attributes: attributes]; - else if ([_scope caseInsensitiveCompare: @"ONE"] == NSOrderedSame) - entries = [ldapConnection flatSearchAtBaseDN: baseDN - qualifier: qualifier - attributes: attributes]; - else /* we do it like before */ - entries = [ldapConnection deepSearchAtBaseDN: baseDN - qualifier: qualifier - attributes: attributes]; - while ((currentEntry = [entries nextObject])) - [contacts addObject: [self _convertLDAPEntryToContact: currentEntry]]; + if ([_scope caseInsensitiveCompare: @"BASE"] == NSOrderedSame) + entries = [ldapConnection baseSearchAtBaseDN: baseDN + qualifier: qualifier + attributes: attributes]; + else if ([_scope caseInsensitiveCompare: @"ONE"] == NSOrderedSame) + entries = [ldapConnection flatSearchAtBaseDN: baseDN + qualifier: qualifier + attributes: attributes]; + else /* we do it like before */ + entries = [ldapConnection deepSearchAtBaseDN: baseDN + qualifier: qualifier + attributes: attributes]; + while ((currentEntry = [entries nextObject])) + [contacts addObject: + [self _convertLDAPEntryToContact: currentEntry]]; + } return contacts; } @@ -1701,6 +1721,7 @@ _makeLDAPChanges (NGLdapConnection *ldapConnection, bindFields: nil kindField: nil andMultipleBookingsField: nil]; + [ab setListRequiresDot: NO]; [ab setModifiers: modifier]; [sources addObject: ab]; [ab release]; diff --git a/SoObjects/SOGo/SOGoSource.h b/SoObjects/SOGo/SOGoSource.h index 16ff54d19..d59a81086 100644 --- a/SoObjects/SOGo/SOGoSource.h +++ b/SoObjects/SOGo/SOGoSource.h @@ -41,6 +41,10 @@ - (NSString *) domain; +/* requires a "." to obtain the full list of contacts */ +- (void) setListRequiresDot: (BOOL) aBool; +- (BOOL) listRequiresDot; + - (BOOL) checkLogin: (NSString *) _login password: (NSString *) _pwd perr: (SOGoPasswordPolicyError *) _perr diff --git a/SoObjects/SOGo/SQLSource.m b/SoObjects/SOGo/SQLSource.m index 9665cea2a..307348f80 100644 --- a/SoObjects/SOGo/SQLSource.m +++ b/SoObjects/SOGo/SQLSource.m @@ -851,6 +851,17 @@ return _sourceID; } +- (void) setListRequiresDot: (BOOL) newListRequiresDot +{ +} + +- (BOOL) listRequiresDot +{ + /* This method is not implemented for SQLSource. It must enable a mechanism + where using "." is not required to list the content of addressbooks. */ + return YES; +} + /* card editing */ - (void) setModifiers: (NSArray *) newModifiers {