From fb9eb09c95e75ed1e893aa92aa93ac8aa3aca48c Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Tue, 23 Dec 2008 22:39:56 +0000 Subject: [PATCH] See ChangeLog Monotone-Parent: 216cfb18d3e04f9ead5aaae0aa501e44f20b18df Monotone-Revision: 04df0eebf5080524a4b02c414640106afe5e4ca3 Monotone-Author: ludovic@Sophos.ca Monotone-Date: 2008-12-23T22:39:56 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 3 ++ SoObjects/SOGo/SOGoObject.h | 3 +- SoObjects/SOGo/SOGoObject.m | 104 ++++++++++++++++++++++++++---------- 3 files changed, 81 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c9d8451c..2c0094e50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,9 @@ This is useful when verifying the freebusy of meeting participants as we must not strip the c_partstates/c_partmails fields. + * SoObjects/SOGo/SOGoObject.{h,m} + We now permit two parameters during the user-list + REPORT in order to avoid LDAP lookups. 2008-12-23 Francis Lachapelle diff --git a/SoObjects/SOGo/SOGoObject.h b/SoObjects/SOGo/SOGoObject.h index afaf8ad00..324357bf4 100644 --- a/SoObjects/SOGo/SOGoObject.h +++ b/SoObjects/SOGo/SOGoObject.h @@ -148,7 +148,8 @@ SEL SOGoSelectorForPropertySetter (NSString *property); - (SOGoWebDAVValue *) davCurrentUserPrivilegeSet; /* inverse dav extensions for acls */ -- (NSString *) davRecordForUser: (NSString *) user; +- (NSString *) davRecordForUser: (NSString *) user + parameters: (NSArray *) params; /* description */ diff --git a/SoObjects/SOGo/SOGoObject.m b/SoObjects/SOGo/SOGoObject.m index 992a15449..2b5c706b5 100644 --- a/SoObjects/SOGo/SOGoObject.m +++ b/SoObjects/SOGo/SOGoObject.m @@ -1353,34 +1353,52 @@ SEL SOGoSelectorForPropertySetter (NSString *property) /* dav acls */ - (NSString *) davRecordForUser: (NSString *) user + parameters: (NSArray *) params { NSMutableString *userRecord; SOGoUser *sogoUser; - NSString *cn, *email; userRecord = [NSMutableString string]; [userRecord appendFormat: @"%@", [user stringByEscapingXMLString]]; sogoUser = [SOGoUser userWithLogin: user roles: nil]; - cn = [sogoUser cn]; - if (!cn) - cn = user; - [userRecord appendFormat: @"%@", - [cn stringByEscapingXMLString]]; - email = [[sogoUser allEmails] objectAtIndex: 0]; - if (email) - [userRecord appendFormat: @"%@", - [email stringByEscapingXMLString]]; + + if (![params containsObject: @"nocn"]) + { + NSString *cn; + + cn = [sogoUser cn]; + if (!cn) + cn = user; + [userRecord appendFormat: @"%@", + [cn stringByEscapingXMLString]]; + } + + if (![params containsObject: @"noemail"]) + { + NSString *email; + + email = [[sogoUser allEmails] objectAtIndex: 0]; + if (email) + [userRecord appendFormat: @"%@", + [email stringByEscapingXMLString]]; + } return userRecord; } -- (NSString *) _davAclUserListQuery +- (NSString *) _davAclUserListQuery: (NSString *) theParameters { NSMutableString *userList; NSString *defaultUserID, *currentUserID; NSEnumerator *users; + NSArray *params; + + if (theParameters && [theParameters length]) + params = [[theParameters lowercaseString] componentsSeparatedByString: @","]; + else + params = [NSArray array]; userList = [NSMutableString string]; @@ -1390,9 +1408,14 @@ SEL SOGoSelectorForPropertySetter (NSString *property) [defaultUserID stringByEscapingXMLString]]; users = [[self aclUsers] objectEnumerator]; while ((currentUserID = [users nextObject])) - if (![currentUserID isEqualToString: defaultUserID]) - [userList appendFormat: @"%@", - [self davRecordForUser: currentUserID]]; + { + if (![currentUserID isEqualToString: defaultUserID]) + { + [userList appendFormat: @"%@", + [self davRecordForUser: currentUserID + parameters: params]]; + } + } return userList; } @@ -1441,8 +1464,30 @@ SEL SOGoSelectorForPropertySetter (NSString *property) { node = [childNodes objectAtIndex: 0]; nodeName = [node localName]; + + // + // We support parameters during the user-list REPORT. + // We do that in order to avoid looking up from the LDAP + // the CN and the EMAIL address of the users that are + // returned in the REPORT's response. That can be slow if + // the LDAP server used for authentication is slow and this + // information might not be necessary for scripting purposes. + // + // The following parameters are supported: + // + // nocn - avoid returning the CN + // noemail - avoid returning the EMAIL address + // + // Both can be specified using: + // + // params=nocn,noemail + // if ([nodeName isEqualToString: @"user-list"]) - result = [self _davAclUserListQuery]; + { + result = [self _davAclUserListQuery: [[[node attributes] + namedItem: @"params"] + nodeValue]]; + } else if ([nodeName isEqualToString: @"roles"]) { attrs = [node attributes]; @@ -1471,10 +1516,11 @@ SEL SOGoSelectorForPropertySetter (NSString *property) if ([user length]) allUsers = [NSArray arrayWithObject: user]; - else { - userAttr = [attrs namedItem: @"users"]; - allUsers = [[userAttr nodeValue] componentsSeparatedByString: @","]; - } + else + { + userAttr = [attrs namedItem: @"users"]; + allUsers = [[userAttr nodeValue] componentsSeparatedByString: @","]; + } allRoles = [self _davGetRolesFromRequest: node]; for (i = 0; i < [allUsers count]; i++) @@ -1515,11 +1561,12 @@ SEL SOGoSelectorForPropertySetter (NSString *property) { if ([self addUserInAcls: [allUsers objectAtIndex: i]]) result = @""; - else { - result = nil; - break; - } - } + else + { + result = nil; + break; + } + } } // // See the comment for add-user / add-users @@ -1543,10 +1590,11 @@ SEL SOGoSelectorForPropertySetter (NSString *property) { if ([self removeUserFromAcls: [allUsers objectAtIndex: i]]) result = @""; - else { - result = nil; - break; - } + else + { + result = nil; + break; + } } } }