fix(addressbook): reuse LDAP connection in CardDAV report

Fixes #5355
master
Francis Lachapelle 2021-09-29 16:00:10 -04:00
parent d181cc4d06
commit 3da633aebf
4 changed files with 90 additions and 19 deletions

View File

@ -1,6 +1,6 @@
/* SOGoContactSourceFolder.m - this file is part of SOGo
*
* Copyright (C) 2006-2016 Inverse inc.
* Copyright (C) 2006-2021 Inverse inc.
*
* 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
@ -351,7 +351,7 @@
{
[newRecord setObject: @"vcard" forKey: @"c_component"];
}
// Custom attribute for resource lookups. See LDAPSource.m.
data = [oldRecord objectForKey: @"isResource"];
if (data)
@ -375,7 +375,7 @@
if ([recordSource conformsToProtocol: @protocol (SOGoDNSource)] &&
[[(NSObject <SOGoDNSource>*) recordSource MSExchangeHostname] length])
[newRecord setObject: [NSNumber numberWithInt: 1] forKey: @"isMSExchange"];
return newRecord;
}
@ -652,9 +652,10 @@
NSString **propertiesArray;
NSMutableString *buffer;
NSDictionary *object;
id connection;
unsigned int count, max, propertiesCount;
baseURL = [self davURLAsString];
#warning review this when fixing http://www.scalableogo.org/bugs/view.php?id=276
if (![baseURL hasSuffix: @"/"])
@ -666,12 +667,15 @@
max = [refs length];
buffer = [NSMutableString stringWithCapacity: max*512];
domain = [[context activeUser] domain];
connection = [source connection];
for (count = 0; count < max; count++)
{
element = [refs objectAtIndex: count];
url = [[[element firstChild] nodeValue] stringByUnescapingURL];
cname = [self _deduceObjectNameFromURL: url fromBaseURL: baseURL];
object = [source lookupContactEntry: cname inDomain: domain];
object = [source lookupContactEntry: cname
inDomain: domain
usingConnection: connection];
if (object)
[self appendObject: object
properties: propertiesArray

View File

@ -1,6 +1,6 @@
/* LDAPSource.m - this file is part of SOGo
*
* Copyright (C) 2007-2019 Inverse inc.
* Copyright (C) 2007-2021 Inverse inc.
*
* 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
@ -437,7 +437,7 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses
//
//
//
- (NGLdapConnection *) _ldapConnection
- (id) connection
{
NGLdapConnection *ldapConnection;
NSString *value, *key;
@ -492,6 +492,11 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses
return ldapConnection;
}
- (NGLdapConnection *) _ldapConnection
{
return (NGLdapConnection *)[self connection];
}
- (NSString *) domain
{
return _domain;
@ -1317,11 +1322,12 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses
}
- (NGLdapEntry *) _lookupLDAPEntry: (EOQualifier *) theQualifier
usingConnection: (id) connection
{
NGLdapConnection *ldapConnection;
NSEnumerator *entries;
ldapConnection = [self _ldapConnection];
ldapConnection = (NGLdapConnection *)connection;
if ([_scope caseInsensitiveCompare: @"BASE"] == NSOrderedSame)
entries = [ldapConnection baseSearchAtBaseDN: _baseDN
@ -1339,8 +1345,15 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses
return [entries nextObject];
}
- (NGLdapEntry *) _lookupLDAPEntry: (EOQualifier *) theQualifier
{
return [self _lookupLDAPEntry: theQualifier
usingConnection: [self _ldapConnection]];
}
- (NSDictionary *) lookupContactEntry: (NSString *) theID
inDomain: (NSString *) theDomain
usingConnection: (id) connection
{
NGLdapEntry *ldapEntry;
EOQualifier *qualifier;
@ -1354,7 +1367,8 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses
s = [NSString stringWithFormat: @"(%@='%@')",
_IDField, SafeLDAPCriteria(theID)];
qualifier = [EOQualifier qualifierWithQualifierFormat: s];
ldapEntry = [self _lookupLDAPEntry: qualifier];
ldapEntry = [self _lookupLDAPEntry: qualifier
usingConnection: connection];
if (ldapEntry)
ldifRecord = [self _convertLDAPEntryToContact: ldapEntry];
}
@ -1362,6 +1376,14 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses
return ldifRecord;
}
- (NSDictionary *) lookupContactEntry: (NSString *) theID
inDomain: (NSString *) theDomain
{
return [self lookupContactEntry: theID
inDomain: theDomain
usingConnection: [self _ldapConnection]];
}
- (NSDictionary *) lookupContactEntryWithUIDorEmail: (NSString *) uid
inDomain: (NSString *) theDomain
{

View File

@ -1,8 +1,6 @@
/* SOGoSource.h - this file is part of SOGo
*
* Copyright (C) 2009-2012 Inverse inc.
*
* Author: Ludovic Marcotte <lmarcotte@inverse.ca>
* Copyright (C) 2009-2021 Inverse inc.
*
* 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
@ -41,6 +39,8 @@
- (NSString *) domain;
- (NSArray *) searchFields;
- (id) connection;
/* requires a "." to obtain the full list of contacts */
- (void) setListRequiresDot: (BOOL) aBool;
- (BOOL) listRequiresDot;
@ -58,6 +58,9 @@
- (NSDictionary *) lookupContactEntry: (NSString *) theID
inDomain: (NSString *) domain;
- (NSDictionary *) lookupContactEntry: (NSString *) theID
inDomain: (NSString *) domain
usingConnection: (id) connection;
- (NSDictionary *) lookupContactEntryWithUIDorEmail: (NSString *) entryID
inDomain: (NSString *) domain;

View File

@ -429,16 +429,27 @@
forKey: [NSString stringWithFormat: @"%@Access", module]];
}
- (id) connection
{
EOAdaptorChannel *channel;
GCSChannelManager *cm;
cm = [GCSChannelManager defaultChannelManager];
channel = [cm acquireOpenChannelForURL: _viewURL];
return channel;
}
- (NSDictionary *) _lookupContactEntry: (NSString *) theID
considerEmail: (BOOL) b
inDomain: (NSString *) domain
usingConnection: (id) connection
{
NSMutableDictionary *response;
NSMutableArray *qualifiers;
NSArray *fieldNames;
EOAdaptorChannel *channel;
EOQualifier *loginQualifier, *domainQualifier, *qualifier;
GCSChannelManager *cm;
NSMutableString *sql;
NSString *value, *field;
NSException *ex;
@ -447,8 +458,7 @@
response = nil;
theID = [theID stringByReplacingString: @"'" withString: @"''"];
cm = [GCSChannelManager defaultChannelManager];
channel = [cm acquireOpenChannelForURL: _viewURL];
channel = (EOAdaptorChannel *)connection;
if (channel)
{
qualifiers = [NSMutableArray arrayWithCapacity: [_loginFields count] + 1];
@ -659,7 +669,6 @@
}
else
[self errorWithFormat: @"could not run SQL '%@': %@", sql, ex];
[cm releaseChannel: channel];
}
else
[self errorWithFormat:@"failed to acquire channel for URL: %@",
@ -669,10 +678,43 @@
}
- (NSDictionary *) lookupContactEntry: (NSString *) theID
inDomain: (NSString *) domain
- (NSDictionary *) _lookupContactEntry: (NSString *) theID
considerEmail: (BOOL) b
inDomain: (NSString *) domain
{
return [self _lookupContactEntry: theID considerEmail: NO inDomain: domain];
EOAdaptorChannel *channel;
GCSChannelManager *cm;
NSDictionary *response;
cm = [GCSChannelManager defaultChannelManager];
channel = (EOAdaptorChannel *)[self connection];
response = [self _lookupContactEntry: theID
considerEmail: b
inDomain: domain
usingConnection: channel];
if (channel)
[cm releaseChannel: channel];
return response;
}
- (NSDictionary *) lookupContactEntry: (NSString *) theID
inDomain: (NSString *) domain
usingConnection: (id) connection
{
return [self _lookupContactEntry: theID
considerEmail: NO
inDomain: domain
usingConnection: connection];
}
- (NSDictionary *) lookupContactEntry: (NSString *) theID
inDomain: (NSString *) domain
{
return [self _lookupContactEntry: theID
considerEmail: NO
inDomain: domain];
}
- (NSDictionary *) lookupContactEntryWithUIDorEmail: (NSString *) entryID