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 /* 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 * 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 * it under the terms of the GNU General Public License as published by
@ -652,6 +652,7 @@
NSString **propertiesArray; NSString **propertiesArray;
NSMutableString *buffer; NSMutableString *buffer;
NSDictionary *object; NSDictionary *object;
id connection;
unsigned int count, max, propertiesCount; unsigned int count, max, propertiesCount;
@ -666,12 +667,15 @@
max = [refs length]; max = [refs length];
buffer = [NSMutableString stringWithCapacity: max*512]; buffer = [NSMutableString stringWithCapacity: max*512];
domain = [[context activeUser] domain]; domain = [[context activeUser] domain];
connection = [source connection];
for (count = 0; count < max; count++) for (count = 0; count < max; count++)
{ {
element = [refs objectAtIndex: count]; element = [refs objectAtIndex: count];
url = [[[element firstChild] nodeValue] stringByUnescapingURL]; url = [[[element firstChild] nodeValue] stringByUnescapingURL];
cname = [self _deduceObjectNameFromURL: url fromBaseURL: baseURL]; cname = [self _deduceObjectNameFromURL: url fromBaseURL: baseURL];
object = [source lookupContactEntry: cname inDomain: domain]; object = [source lookupContactEntry: cname
inDomain: domain
usingConnection: connection];
if (object) if (object)
[self appendObject: object [self appendObject: object
properties: propertiesArray properties: propertiesArray

View File

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

View File

@ -1,8 +1,6 @@
/* SOGoSource.h - this file is part of SOGo /* SOGoSource.h - this file is part of SOGo
* *
* Copyright (C) 2009-2012 Inverse inc. * Copyright (C) 2009-2021 Inverse inc.
*
* Author: Ludovic Marcotte <lmarcotte@inverse.ca>
* *
* This file is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -41,6 +39,8 @@
- (NSString *) domain; - (NSString *) domain;
- (NSArray *) searchFields; - (NSArray *) searchFields;
- (id) connection;
/* requires a "." to obtain the full list of contacts */ /* requires a "." to obtain the full list of contacts */
- (void) setListRequiresDot: (BOOL) aBool; - (void) setListRequiresDot: (BOOL) aBool;
- (BOOL) listRequiresDot; - (BOOL) listRequiresDot;
@ -58,6 +58,9 @@
- (NSDictionary *) lookupContactEntry: (NSString *) theID - (NSDictionary *) lookupContactEntry: (NSString *) theID
inDomain: (NSString *) domain; inDomain: (NSString *) domain;
- (NSDictionary *) lookupContactEntry: (NSString *) theID
inDomain: (NSString *) domain
usingConnection: (id) connection;
- (NSDictionary *) lookupContactEntryWithUIDorEmail: (NSString *) entryID - (NSDictionary *) lookupContactEntryWithUIDorEmail: (NSString *) entryID
inDomain: (NSString *) domain; inDomain: (NSString *) domain;

View File

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