Skip to content

Commit

Permalink
fix(addressbook): reuse LDAP connection in CardDAV report
Browse files Browse the repository at this point in the history
Fixes #5355
  • Loading branch information
cgx committed Sep 29, 2021
1 parent d181cc4 commit 3da633a
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 18 deletions.
14 changes: 9 additions & 5 deletions SoObjects/Contacts/SOGoContactSourceFolder.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -351,7 +351,7 @@ - (NSDictionary *) _flattenedRecord: (NSDictionary *) oldRecord
{
[newRecord setObject: @"vcard" forKey: @"c_component"];
}

// Custom attribute for resource lookups. See LDAPSource.m.
data = [oldRecord objectForKey: @"isResource"];
if (data)
Expand All @@ -375,7 +375,7 @@ - (NSDictionary *) _flattenedRecord: (NSDictionary *) oldRecord
if ([recordSource conformsToProtocol: @protocol (SOGoDNSource)] &&
[[(NSObject <SOGoDNSource>*) recordSource MSExchangeHostname] length])
[newRecord setObject: [NSNumber numberWithInt: 1] forKey: @"isMSExchange"];

return newRecord;
}

Expand Down Expand Up @@ -652,9 +652,10 @@ - (void) _appendComponentProperties: (NSArray *) properties
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: @"/"])
Expand All @@ -666,12 +667,15 @@ - (void) _appendComponentProperties: (NSArray *) properties
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
Expand Down
30 changes: 26 additions & 4 deletions SoObjects/SOGo/LDAPSource.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -437,7 +437,7 @@ - (BOOL) _setupEncryption: (NGLdapConnection *) theConnection
//
//
//
- (NGLdapConnection *) _ldapConnection
- (id) connection
{
NGLdapConnection *ldapConnection;
NSString *value, *key;
Expand Down Expand Up @@ -492,6 +492,11 @@ - (NGLdapConnection *) _ldapConnection
return ldapConnection;
}

- (NGLdapConnection *) _ldapConnection
{
return (NGLdapConnection *)[self connection];
}

- (NSString *) domain
{
return _domain;
Expand Down Expand Up @@ -1317,11 +1322,12 @@ - (NSArray *) fetchContactsMatching: (NSString *) match
}

- (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
Expand All @@ -1339,8 +1345,15 @@ - (NGLdapEntry *) _lookupLDAPEntry: (EOQualifier *) theQualifier
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;
Expand All @@ -1354,14 +1367,23 @@ - (NSDictionary *) lookupContactEntry: (NSString *) theID
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];
}

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
{
Expand Down
9 changes: 6 additions & 3 deletions SoObjects/SOGo/SOGoSource.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down
54 changes: 48 additions & 6 deletions SoObjects/SOGo/SQLSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -429,16 +429,27 @@ - (void) _fillConstraintsForModule: (NSString *) 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
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;
Expand All @@ -447,8 +458,7 @@ - (NSDictionary *) _lookupContactEntry: (NSString *) theID
response = nil;

theID = [theID stringByReplacingString: @"'" withString: @"''"];
cm = [GCSChannelManager defaultChannelManager];
channel = [cm acquireOpenChannelForURL: _viewURL];
channel = (EOAdaptorChannel *)connection;
if (channel)
{
qualifiers = [NSMutableArray arrayWithCapacity: [_loginFields count] + 1];
Expand Down Expand Up @@ -659,7 +669,6 @@ - (NSDictionary *) _lookupContactEntry: (NSString *) theID
}
else
[self errorWithFormat: @"could not run SQL '%@': %@", sql, ex];
[cm releaseChannel: channel];
}
else
[self errorWithFormat:@"failed to acquire channel for URL: %@",
Expand All @@ -669,10 +678,43 @@ - (NSDictionary *) _lookupContactEntry: (NSString *) theID
}


- (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
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
Expand Down

0 comments on commit 3da633a

Please sign in to comment.