From c33821349e4e3277cee177f1d1ae847e18c3db55 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Mon, 24 Jan 2011 18:02:12 +0000 Subject: [PATCH] See Changelog. Monotone-Parent: 7644c155b02b86d417852ac59361714181ec8c18 Monotone-Revision: 66faeac6511d176fd1b35b6a0a5b8cbb20b0b2d1 Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2011-01-24T18:02:12 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 8 +++++++ SoObjects/SOGo/LDAPSource.h | 5 +++-- SoObjects/SOGo/LDAPSource.m | 36 ++++++++++++++++++++++---------- SoObjects/SOGo/SOGoUserManager.m | 5 ++++- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80e169a81..18153f1f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-01-24 Francis Lachapelle + + * SoObjects/SOGo/LDAPSource.m (_qualifierForFilter:): added + support for the parameter "SearchFieldNames" that can be added to + the source defaults to specify which LDAP attributes to use when + filtering contacts. It defaults to the previous values, ie sn, + displayname, and telephonenumber. + 2011-01-21 Francis Lachapelle * SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.m diff --git a/SoObjects/SOGo/LDAPSource.h b/SoObjects/SOGo/LDAPSource.h index 907249200..e77d5746a 100644 --- a/SoObjects/SOGo/LDAPSource.h +++ b/SoObjects/SOGo/LDAPSource.h @@ -1,6 +1,6 @@ /* LDAPSource.h - this file is part of SOGo * - * Copyright (C) 2007-2010 Inverse inc. + * Copyright (C) 2007-2011 Inverse inc. * * Author: Wolfgang Sourdeau * Ludovic Marcotte @@ -52,7 +52,7 @@ NSString *IDField; /* the first part of a user DN */ NSString *CNField; NSString *UIDField; - NSArray *mailFields; + NSArray *mailFields, *searchFields; NSString *IMAPHostField; NSArray *bindFields; BOOL _bindAsCurrentUser; @@ -81,6 +81,7 @@ CNField: (NSString *) newCNField UIDField: (NSString *) newUIDField mailFields: (NSArray *) newMailFields + searchFields: (NSArray *) newSearchFields IMAPHostField: (NSString *) newIMAPHostField andBindFields: (id) newBindFields; diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index b73082a27..1069e4049 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -1,6 +1,6 @@ /* LDAPSource.m - this file is part of SOGo * - * Copyright (C) 2007-2010 Inverse inc. + * Copyright (C) 2007-2011 Inverse inc. * * Author: Wolfgang Sourdeau * Ludovic Marcotte @@ -158,6 +158,8 @@ static NSArray *commonSearchFields; UIDField = @"uid"; mailFields = [NSArray arrayWithObject: @"mail"]; [mailFields retain]; + searchFields = [NSArray arrayWithObjects: @"sn", @"displayname", @"telephonenumber", nil]; + [searchFields retain]; IMAPHostField = nil; bindFields = nil; _scope = @"sub"; @@ -184,6 +186,7 @@ static NSArray *commonSearchFields; [CNField release]; [UIDField release]; [mailFields release]; + [searchFields release]; [IMAPHostField release]; [bindFields release]; [_filter release]; @@ -218,6 +221,7 @@ static NSArray *commonSearchFields; CNField: [udSource objectForKey: @"CNFieldName"] UIDField: [udSource objectForKey: @"UIDFieldName"] mailFields: [udSource objectForKey: @"MailFieldNames"] + searchFields: [udSource objectForKey: @"SearchFieldNames"] IMAPHostField: [udSource objectForKey: @"IMAPHostFieldName"] andBindFields: [udSource objectForKey: @"bindFields"]]; @@ -299,6 +303,7 @@ static NSArray *commonSearchFields; CNField: (NSString *) newCNField UIDField: (NSString *) newUIDField mailFields: (NSArray *) newMailFields + searchFields: (NSArray *) newSearchFields IMAPHostField: (NSString *) newIMAPHostField andBindFields: (id) newBindFields { @@ -313,6 +318,8 @@ static NSArray *commonSearchFields; ASSIGN (IMAPHostField, newIMAPHostField); if (newMailFields) ASSIGN (mailFields, newMailFields); + if (newSearchFields) + ASSIGN (searchFields, newSearchFields); if (newBindFields) { // Before SOGo v1.2.0, bindFields was a comma-separated list @@ -580,28 +587,35 @@ static NSArray *commonSearchFields; } -/* contact management */ +/** + * Search for contacts matching some string. + * @param filter The string to search for + * @see fetchContactsMatching: + * @return A EOQualifier matching the filter + */ - (EOQualifier *) _qualifierForFilter: (NSString *) filter { - NSString *mailFormat, *fieldFormat, *escapedFilter; + NSMutableArray *fields; + NSString *searchFormat, *fieldFormat, *escapedFilter; EOQualifier *qualifier; NSMutableString *qs; escapedFilter = SafeLDAPCriteria(filter); if ([escapedFilter length] > 0) { - fieldFormat = [NSString stringWithFormat: @"(%%@='%@*')", escapedFilter]; - mailFormat = [[mailFields stringsWithFormat: fieldFormat] - componentsJoinedByString: @" OR "]; - qs = [NSMutableString string]; if ([escapedFilter isEqualToString: @"."]) [qs appendFormat: @"(%@='*')", CNField]; else - [qs appendFormat: @"(%@='%@*') OR (sn='%@*') OR (displayName='%@*')" - @"OR %@ OR (telephoneNumber='*%@*')", - CNField, escapedFilter, escapedFilter, escapedFilter, mailFormat, - escapedFilter]; + { + fieldFormat = [NSString stringWithFormat: @"(%%@='%@*')", escapedFilter]; + fields = [NSMutableArray arrayWithArray: searchFields]; + [fields addObjectsFromArray: mailFields]; + searchFormat = [[[fields uniqueObjects] stringsWithFormat: fieldFormat] + componentsJoinedByString: @" OR "]; + [qs appendFormat: @"(%@='%@*') OR %@", + CNField, escapedFilter, searchFormat]; + } if (_filter && [_filter length]) [qs appendFormat: @" AND %@", _filter]; diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index fdbfa34d9..04fee5dd1 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -1,6 +1,6 @@ /* SOGoUserManager.m - this file is part of SOGo * - * Copyright (C) 2007-2010 Inverse inc. + * Copyright (C) 2007-2011 Inverse inc. * * Author: Wolfgang Sourdeau * @@ -132,6 +132,9 @@ value = [udSource objectForKey: @"MailFieldNames"]; if (value) [metadata setObject: value forKey: @"MailFieldNames"]; + value = [udSource objectForKey: @"SearchFieldNames"]; + if (value) + [metadata setObject: value forKey: @"SearchFieldNames"]; [_sourcesMetadata setObject: metadata forKey: sourceID]; } else