2006-08-09 23:11:49 +02:00
|
|
|
/*
|
2017-12-23 10:37:12 +01:00
|
|
|
Copyright (C) 2006-2017 Inverse inc.
|
2006-08-09 23:11:49 +02:00
|
|
|
|
2011-07-29 15:26:14 +02:00
|
|
|
This file is part of SOGo.
|
2006-08-09 23:11:49 +02:00
|
|
|
|
2011-07-29 15:26:14 +02:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2006-08-09 23:11:49 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
2011-07-29 15:26:14 +02:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2006-08-09 23:11:49 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2016-02-20 05:19:07 +01:00
|
|
|
License along with SOGo; see the file COPYING. If not, write to the
|
2006-08-09 23:11:49 +02:00
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
|
2007-07-22 22:44:46 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
|
|
|
#import <NGObjWeb/SoObject+SoDAV.h>
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2007-10-17 00:14:37 +02:00
|
|
|
#import <NGExtensions/NSString+misc.h>
|
2010-08-12 16:02:21 +02:00
|
|
|
#import <SaxObjC/XMLNamespaces.h>
|
2016-02-20 05:19:07 +01:00
|
|
|
#import <EOControl/EOFetchSpecification.h>
|
2007-07-22 22:44:46 +02:00
|
|
|
#import <EOControl/EOQualifier.h>
|
|
|
|
#import <EOControl/EOSortOrdering.h>
|
2010-08-12 16:02:21 +02:00
|
|
|
|
|
|
|
#import <NGCards/CardGroup.h>
|
2006-08-09 23:11:49 +02:00
|
|
|
#import <GDLContentStore/GCSFolder.h>
|
|
|
|
|
2010-08-12 16:02:21 +02:00
|
|
|
#import <SOGo/DOMNode+SOGo.h>
|
2008-03-07 23:12:40 +01:00
|
|
|
#import <SOGo/SOGoCache.h>
|
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
|
|
|
#import <SOGo/NSString+Utilities.h>
|
2010-08-12 16:02:21 +02:00
|
|
|
#import <SOGo/NSObject+DAV.h>
|
2011-12-30 21:39:07 +01:00
|
|
|
#import <SOGo/WORequest+SOGo.h>
|
2008-03-07 23:12:40 +01:00
|
|
|
|
2006-08-09 23:11:49 +02:00
|
|
|
#import "SOGoContactGCSEntry.h"
|
2008-03-07 23:12:40 +01:00
|
|
|
#import "SOGoContactGCSList.h"
|
|
|
|
|
2006-08-09 23:11:49 +02:00
|
|
|
#import "SOGoContactGCSFolder.h"
|
|
|
|
|
2010-05-05 20:49:29 +02:00
|
|
|
static NSArray *folderListingFields = nil;
|
2006-08-14 22:36:36 +02:00
|
|
|
|
2006-08-09 23:11:49 +02:00
|
|
|
@implementation SOGoContactGCSFolder
|
|
|
|
|
2010-05-05 20:49:29 +02:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (!folderListingFields)
|
|
|
|
folderListingFields = [[NSArray alloc] initWithObjects: @"c_name",
|
|
|
|
@"c_cn", @"c_givenname", @"c_sn",
|
|
|
|
@"c_screenname", @"c_o",
|
|
|
|
@"c_mail", @"c_telephonenumber",
|
2010-11-01 20:32:19 +01:00
|
|
|
@"c_categories",
|
2017-12-23 10:37:12 +01:00
|
|
|
@"c_component",
|
|
|
|
@"c_hascertificate", nil];
|
2010-05-05 20:49:29 +02:00
|
|
|
}
|
|
|
|
|
2015-08-17 22:21:10 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
baseCardDAVURL = nil;
|
|
|
|
basePublicCardDAVURL = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[baseCardDAVURL release];
|
|
|
|
[basePublicCardDAVURL release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2017-11-21 21:56:16 +01:00
|
|
|
- (NSArray *) searchFields
|
|
|
|
{
|
|
|
|
static NSArray *searchFields = nil;
|
|
|
|
|
|
|
|
if (!searchFields)
|
|
|
|
{
|
|
|
|
// "name" expands to c_sn, c_givenname and c_cn
|
|
|
|
searchFields = [NSArray arrayWithObjects: @"name", @"c_mail", @"c_categories", @"c_o", nil];
|
|
|
|
[searchFields retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return searchFields;
|
|
|
|
}
|
|
|
|
|
2008-03-07 23:12:40 +01:00
|
|
|
- (Class) objectClassForContent: (NSString *) content
|
2006-08-09 23:11:49 +02:00
|
|
|
{
|
2008-03-07 23:12:40 +01:00
|
|
|
CardGroup *cardEntry;
|
|
|
|
NSString *firstTag;
|
|
|
|
Class objectClass;
|
2006-08-11 00:03:48 +02:00
|
|
|
|
2008-03-07 23:12:40 +01:00
|
|
|
objectClass = Nil;
|
|
|
|
|
|
|
|
cardEntry = [CardGroup parseSingleFromSource: content];
|
|
|
|
if (cardEntry)
|
|
|
|
{
|
|
|
|
firstTag = [[cardEntry tag] uppercaseString];
|
|
|
|
if ([firstTag isEqualToString: @"VCARD"])
|
|
|
|
objectClass = [SOGoContactGCSEntry class];
|
|
|
|
else if ([firstTag isEqualToString: @"VLIST"])
|
|
|
|
objectClass = [SOGoContactGCSList class];
|
|
|
|
}
|
|
|
|
|
|
|
|
return objectClass;
|
|
|
|
}
|
|
|
|
|
2008-06-13 22:18:03 +02:00
|
|
|
- (Class) objectClassForComponentName: (NSString *) componentName
|
|
|
|
{
|
|
|
|
Class objectClass;
|
2010-08-12 16:02:21 +02:00
|
|
|
|
2008-06-13 22:18:03 +02:00
|
|
|
if ([componentName isEqualToString: @"vcard"])
|
|
|
|
objectClass = [SOGoContactGCSEntry class];
|
|
|
|
else if ([componentName isEqualToString: @"vlist"])
|
|
|
|
objectClass = [SOGoContactGCSList class];
|
|
|
|
else
|
|
|
|
objectClass = Nil;
|
|
|
|
|
|
|
|
return objectClass;
|
|
|
|
}
|
|
|
|
|
2008-03-07 23:12:40 +01:00
|
|
|
- (Class) objectClassForResourceNamed: (NSString *) name
|
|
|
|
{
|
|
|
|
EOQualifier *qualifier;
|
|
|
|
NSArray *records;
|
|
|
|
NSString *component;
|
|
|
|
Class objectClass;
|
|
|
|
|
2016-12-09 16:45:44 +01:00
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat: @"c_name = %@", [name asSafeSQLString]];
|
2008-03-07 23:12:40 +01:00
|
|
|
records = [[self ocsFolder] fetchFields: [NSArray arrayWithObject: @"c_component"]
|
|
|
|
matchingQualifier: qualifier];
|
|
|
|
|
|
|
|
if ([records count])
|
2006-08-11 00:03:48 +02:00
|
|
|
{
|
2008-03-07 23:12:40 +01:00
|
|
|
component = [[records objectAtIndex: 0] valueForKey: @"c_component"];
|
2008-06-13 22:18:03 +02:00
|
|
|
objectClass = [self objectClassForComponentName: component];
|
2006-08-11 00:03:48 +02:00
|
|
|
}
|
2008-03-07 23:12:40 +01:00
|
|
|
else
|
|
|
|
objectClass = Nil;
|
|
|
|
|
|
|
|
return objectClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) requestNamedIsHandledLater: (NSString *) name
|
|
|
|
{
|
|
|
|
return [name isEqualToString: @"OPTIONS"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) lookupName: (NSString *)_key
|
|
|
|
inContext: (id)_ctx
|
|
|
|
acquire: (BOOL)_flag
|
|
|
|
{
|
|
|
|
id obj;
|
|
|
|
NSString *url;
|
|
|
|
BOOL handledLater;
|
|
|
|
|
|
|
|
/* first check attributes directly bound to the application */
|
|
|
|
handledLater = [self requestNamedIsHandledLater: _key];
|
|
|
|
if (handledLater)
|
|
|
|
obj = nil;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
obj = [super lookupName:_key inContext:_ctx acquire:NO];
|
|
|
|
if (!obj)
|
|
|
|
{
|
|
|
|
if ([self isValidContentName: _key])
|
|
|
|
{
|
|
|
|
url = [[[_ctx request] uri] urlWithoutParameters];
|
|
|
|
if ([url hasSuffix: @"AsContact"])
|
|
|
|
obj = [SOGoContactGCSEntry objectWithName: _key
|
|
|
|
inContainer: self];
|
|
|
|
else if ([url hasSuffix: @"AsList"])
|
|
|
|
obj = [SOGoContactGCSList objectWithName: _key
|
|
|
|
inContainer: self];
|
2008-07-15 22:21:40 +02:00
|
|
|
[obj setIsNew: YES];
|
2008-03-07 23:12:40 +01:00
|
|
|
}
|
|
|
|
}
|
2011-11-21 15:15:14 +01:00
|
|
|
if (!obj || ([obj isKindOfClass: [SOGoContactGCSList class]] && [[_ctx request] isMacOSXAddressBookApp]))
|
2008-03-07 23:12:40 +01:00
|
|
|
obj = [NSException exceptionWithHTTPStatus:404 /* Not Found */];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj)
|
|
|
|
[[SOGoCache sharedCache] registerObject: obj
|
|
|
|
withName: _key
|
|
|
|
inContainer: container];
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2016-02-20 05:19:07 +01:00
|
|
|
- (EOQualifier *) qualifierForFilter: (NSString *) filter
|
2017-11-21 21:56:16 +01:00
|
|
|
onCriteria: (NSArray *) criteria
|
2006-08-09 23:11:49 +02:00
|
|
|
{
|
2017-11-21 21:56:16 +01:00
|
|
|
NSEnumerator *criteriaList;
|
|
|
|
NSMutableArray *filters;
|
|
|
|
NSString *filterFormat, *currentCriteria, *qs;
|
2006-08-09 23:11:49 +02:00
|
|
|
EOQualifier *qualifier;
|
|
|
|
|
2017-11-21 21:56:16 +01:00
|
|
|
qualifier = nil;
|
2010-10-26 22:19:37 +02:00
|
|
|
if ([filter length] > 0)
|
2006-08-09 23:11:49 +02:00
|
|
|
{
|
2016-12-09 16:45:44 +01:00
|
|
|
filter = [filter asSafeSQLString];
|
2017-11-21 21:56:16 +01:00
|
|
|
filters = [NSMutableArray array];
|
|
|
|
filterFormat = [NSString stringWithFormat: @"(%%@ isCaseInsensitiveLike: '%%%%%@%%%%')", filter];
|
|
|
|
if (criteria)
|
|
|
|
criteriaList = [criteria objectEnumerator];
|
2010-10-26 22:19:37 +02:00
|
|
|
else
|
2017-11-21 21:56:16 +01:00
|
|
|
criteriaList = [[self searchFields] objectEnumerator];
|
2010-10-26 22:19:37 +02:00
|
|
|
|
2017-11-21 21:56:16 +01:00
|
|
|
while (( currentCriteria = [criteriaList nextObject] ))
|
|
|
|
{
|
|
|
|
if ([currentCriteria isEqualToString: @"name"])
|
|
|
|
{
|
|
|
|
[filters addObject: @"c_sn"];
|
|
|
|
[filters addObject: @"c_givenname"];
|
|
|
|
[filters addObject: @"c_cn"];
|
|
|
|
}
|
|
|
|
else if ([[self searchFields] containsObject: currentCriteria])
|
|
|
|
[filters addObject: currentCriteria];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([filters count])
|
|
|
|
{
|
|
|
|
qs = [[[filters uniqueObjects] stringsWithFormat: filterFormat] componentsJoinedByString: @" OR "];
|
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
|
|
|
|
}
|
2006-08-09 23:11:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return qualifier;
|
|
|
|
}
|
|
|
|
|
2014-08-20 21:14:40 +02:00
|
|
|
/**
|
|
|
|
* Normalize keys of dictionary representing a contact.
|
|
|
|
* @param contactRecord a dictionary with pairs from the quick table
|
|
|
|
* @see [UIxContactView dataAction]
|
|
|
|
*/
|
2009-02-06 21:09:56 +01:00
|
|
|
- (void) fixupContactRecord: (NSMutableDictionary *) contactRecord
|
|
|
|
{
|
|
|
|
NSString *data;
|
|
|
|
|
2014-08-20 21:14:40 +02:00
|
|
|
// c_categories => categories
|
|
|
|
data = [contactRecord objectForKey: @"c_categories"];
|
|
|
|
if ([data length])
|
|
|
|
[contactRecord setObject: data forKey: @"categories"];
|
|
|
|
|
|
|
|
// c_name => id
|
|
|
|
data = [contactRecord objectForKey: @"c_name"];
|
|
|
|
if ([data length])
|
|
|
|
[contactRecord setObject: data forKey: @"id"];
|
|
|
|
|
2016-02-20 05:19:07 +01:00
|
|
|
// c_cn
|
2009-02-06 21:09:56 +01:00
|
|
|
data = [contactRecord objectForKey: @"c_cn"];
|
2015-07-27 18:47:40 +02:00
|
|
|
if (![data length])
|
2014-09-03 20:19:46 +02:00
|
|
|
{
|
|
|
|
data = [contactRecord keysWithFormat: @"%{c_givenname} %{c_sn}"];
|
|
|
|
if ([data length] > 1)
|
|
|
|
{
|
|
|
|
[contactRecord setObject: data forKey: @"c_cn"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data = [contactRecord objectForKey: @"c_o"];
|
|
|
|
[contactRecord setObject: data forKey: @"c_cn"];
|
|
|
|
}
|
|
|
|
}
|
2014-08-20 21:14:40 +02:00
|
|
|
|
2016-02-20 05:19:07 +01:00
|
|
|
// c_screenname
|
2014-09-03 20:19:46 +02:00
|
|
|
if (![contactRecord objectForKey: @"c_screenname"])
|
|
|
|
[contactRecord setObject: @"" forKey: @"c_screenname"];
|
2014-08-20 21:14:40 +02:00
|
|
|
|
|
|
|
// c_mail => emails[]
|
|
|
|
data = [contactRecord objectForKey: @"c_mail"];
|
|
|
|
if ([data length])
|
2009-02-06 21:09:56 +01:00
|
|
|
{
|
2016-05-25 16:25:53 +02:00
|
|
|
NSArray *values;
|
2014-08-20 21:14:40 +02:00
|
|
|
NSDictionary *email;
|
2016-05-25 16:25:53 +02:00
|
|
|
NSMutableArray *emails;
|
|
|
|
NSString *type, *value;
|
|
|
|
int i, max;
|
|
|
|
|
|
|
|
values = [data componentsSeparatedByString: @","];
|
|
|
|
max = [values count];
|
|
|
|
emails = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
for (i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
type = (i == 0)? @"pref" : @"home";
|
|
|
|
value = [values objectAtIndex: i];
|
|
|
|
email = [NSDictionary dictionaryWithObjectsAndKeys: type, @"type", value, @"value", nil];
|
|
|
|
[emails addObject: email];
|
|
|
|
}
|
|
|
|
[contactRecord setObject: emails forKey: @"emails"];
|
2009-02-06 21:09:56 +01:00
|
|
|
}
|
2014-09-03 20:19:46 +02:00
|
|
|
else
|
2016-02-20 05:19:07 +01:00
|
|
|
{
|
|
|
|
[contactRecord setObject: @"" forKey: @"c_mail"];
|
|
|
|
[contactRecord setObject: [NSArray array] forKey: @"emails"];
|
|
|
|
}
|
2009-02-06 21:09:56 +01:00
|
|
|
|
2016-02-20 05:19:07 +01:00
|
|
|
// c_telephonenumber => phones[]
|
2014-08-20 21:14:40 +02:00
|
|
|
data = [contactRecord objectForKey: @"c_telephonenumber"];
|
|
|
|
if ([data length])
|
|
|
|
{
|
|
|
|
NSDictionary *phonenumber;
|
|
|
|
phonenumber = [NSDictionary dictionaryWithObjectsAndKeys: @"pref", @"type", data, @"value", nil];
|
|
|
|
[contactRecord setObject: [NSArray arrayWithObject: phonenumber] forKey: @"phones"];
|
|
|
|
}
|
2014-09-03 20:19:46 +02:00
|
|
|
else
|
2016-02-20 05:19:07 +01:00
|
|
|
{
|
|
|
|
[contactRecord setObject: @"" forKey: @"c_telephonenumber"];
|
|
|
|
[contactRecord setObject: [NSArray array] forKey: @"phones"];
|
|
|
|
}
|
2009-02-06 21:09:56 +01:00
|
|
|
}
|
|
|
|
|
2007-07-24 21:57:51 +02:00
|
|
|
- (NSArray *) _flattenedRecords: (NSArray *) records
|
|
|
|
{
|
|
|
|
NSMutableArray *newRecords;
|
|
|
|
NSEnumerator *oldRecords;
|
|
|
|
NSDictionary *oldRecord;
|
|
|
|
NSMutableDictionary *newRecord;
|
|
|
|
|
|
|
|
newRecords = [NSMutableArray arrayWithCapacity: [records count]];
|
|
|
|
|
|
|
|
oldRecords = [records objectEnumerator];
|
|
|
|
oldRecord = [oldRecords nextObject];
|
|
|
|
while (oldRecord)
|
|
|
|
{
|
2009-02-06 21:09:56 +01:00
|
|
|
newRecord = [NSMutableDictionary dictionaryWithDictionary: oldRecord];
|
|
|
|
[self fixupContactRecord: newRecord];
|
2007-07-24 21:57:51 +02:00
|
|
|
[newRecords addObject: newRecord];
|
|
|
|
oldRecord = [oldRecords nextObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
return newRecords;
|
|
|
|
}
|
|
|
|
|
2010-04-23 17:53:54 +02:00
|
|
|
/* This method returns the quick entry corresponding to the name passed as
|
|
|
|
parameter. */
|
2009-10-28 18:48:22 +01:00
|
|
|
- (NSDictionary *) lookupContactWithName: (NSString *) aName
|
|
|
|
{
|
2010-04-23 17:53:54 +02:00
|
|
|
NSArray *dbRecords;
|
|
|
|
NSMutableDictionary *record;
|
2009-10-28 18:48:22 +01:00
|
|
|
EOQualifier *qualifier;
|
|
|
|
NSString *qs;
|
|
|
|
|
|
|
|
record = nil;
|
|
|
|
|
|
|
|
if (aName && [aName length] > 0)
|
|
|
|
{
|
2016-12-09 16:45:44 +01:00
|
|
|
aName = [aName asSafeSQLString];
|
2010-04-23 17:53:54 +02:00
|
|
|
qs = [NSString stringWithFormat: @"(c_name='%@')", aName];
|
2009-10-28 18:48:22 +01:00
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
|
2010-04-23 17:53:54 +02:00
|
|
|
dbRecords = [[self ocsFolder] fetchFields: folderListingFields
|
2009-10-28 18:48:22 +01:00
|
|
|
matchingQualifier: qualifier];
|
|
|
|
if ([dbRecords count] > 0)
|
2010-04-23 17:53:54 +02:00
|
|
|
{
|
|
|
|
record = [dbRecords objectAtIndex: 0];
|
|
|
|
[self fixupContactRecord: record];
|
|
|
|
}
|
2009-10-28 18:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return record;
|
|
|
|
}
|
|
|
|
|
2012-02-11 08:08:02 +01:00
|
|
|
/*
|
|
|
|
* GCS folder are personal folders and are not associated to a domain.
|
|
|
|
* The domain is therefore ignored.
|
|
|
|
*/
|
2007-11-05 15:51:50 +01:00
|
|
|
- (NSArray *) lookupContactsWithFilter: (NSString *) filter
|
2017-11-21 21:56:16 +01:00
|
|
|
onCriteria: (NSArray *) criteria
|
2007-11-05 15:51:50 +01:00
|
|
|
sortBy: (NSString *) sortKey
|
|
|
|
ordering: (NSComparisonResult) sortOrdering
|
2012-02-11 08:08:02 +01:00
|
|
|
inDomain: (NSString *) domain
|
2007-10-10 20:44:26 +02:00
|
|
|
{
|
2010-04-23 17:53:54 +02:00
|
|
|
NSArray *dbRecords, *records;
|
2007-11-05 15:51:50 +01:00
|
|
|
EOQualifier *qualifier;
|
|
|
|
EOSortOrdering *ordering;
|
2007-10-10 20:44:26 +02:00
|
|
|
|
2016-02-20 05:19:07 +01:00
|
|
|
qualifier = [self qualifierForFilter: filter onCriteria: criteria];
|
2010-04-23 17:53:54 +02:00
|
|
|
dbRecords = [[self ocsFolder] fetchFields: folderListingFields
|
2016-02-20 05:19:07 +01:00
|
|
|
matchingQualifier: qualifier];
|
2007-10-10 20:44:26 +02:00
|
|
|
|
2007-11-05 15:51:50 +01:00
|
|
|
if ([dbRecords count] > 0)
|
2007-10-10 20:44:26 +02:00
|
|
|
{
|
2007-11-05 15:51:50 +01:00
|
|
|
records = [self _flattenedRecords: dbRecords];
|
|
|
|
ordering
|
|
|
|
= [EOSortOrdering sortOrderingWithKey: sortKey
|
|
|
|
selector: ((sortOrdering == NSOrderedDescending)
|
|
|
|
? EOCompareCaseInsensitiveDescending
|
|
|
|
: EOCompareCaseInsensitiveAscending)];
|
|
|
|
records
|
|
|
|
= [records sortedArrayUsingKeyOrderArray:
|
|
|
|
[NSArray arrayWithObject: ordering]];
|
2007-10-10 20:44:26 +02:00
|
|
|
}
|
|
|
|
else
|
2007-11-05 15:51:50 +01:00
|
|
|
records = nil;
|
2007-10-10 20:44:26 +02:00
|
|
|
|
2007-11-05 15:51:50 +01:00
|
|
|
[self debugWithFormat:@"fetched %i records.", [records count]];
|
|
|
|
return records;
|
2007-10-10 20:44:26 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 05:19:07 +01:00
|
|
|
- (NSArray *) lookupContactsWithQualifier: (EOQualifier *) qualifier
|
|
|
|
{
|
|
|
|
return [self lookupContactsFields: folderListingFields
|
|
|
|
withQualifier: qualifier
|
|
|
|
andOrderings: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) lookupContactsFields: (NSArray *) fields
|
|
|
|
withQualifier: (EOQualifier *) qualifier
|
|
|
|
andOrderings: (NSArray *) orderings
|
|
|
|
{
|
|
|
|
NSArray *dbRecords, *records;
|
|
|
|
EOFetchSpecification *spec;
|
|
|
|
|
|
|
|
spec = [EOFetchSpecification fetchSpecificationWithEntityName: [[self ocsFolder] folderName]
|
|
|
|
qualifier: qualifier
|
|
|
|
sortOrderings: orderings];
|
|
|
|
|
|
|
|
dbRecords = [[self ocsFolder] fetchFields: fields
|
|
|
|
fetchSpecification: spec
|
|
|
|
ignoreDeleted: YES];
|
|
|
|
|
|
|
|
if ([dbRecords count] > 0 && fields == folderListingFields)
|
|
|
|
records = [self _flattenedRecords: dbRecords];
|
|
|
|
else
|
|
|
|
records = dbRecords;
|
|
|
|
|
|
|
|
[self debugWithFormat:@"fetched %i records.", [records count]];
|
|
|
|
return records;
|
|
|
|
}
|
|
|
|
|
2010-08-12 16:02:21 +02:00
|
|
|
- (NSDictionary *) davSQLFieldsTable
|
2007-10-10 20:44:26 +02:00
|
|
|
{
|
2010-08-12 16:02:21 +02:00
|
|
|
static NSMutableDictionary *davSQLFieldsTable = nil;
|
|
|
|
|
|
|
|
if (!davSQLFieldsTable)
|
|
|
|
{
|
|
|
|
davSQLFieldsTable = [[super davSQLFieldsTable] mutableCopy];
|
|
|
|
[davSQLFieldsTable setObject: @"c_content" forKey: @"{urn:ietf:params:xml:ns:carddav}address-data"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return davSQLFieldsTable;
|
2007-10-10 20:44:26 +02:00
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (NSString *) groupDavResourceType
|
|
|
|
{
|
|
|
|
return @"vcard-collection";
|
|
|
|
}
|
|
|
|
|
2007-12-06 23:48:41 +01:00
|
|
|
- (NSArray *) davResourceType
|
|
|
|
{
|
|
|
|
NSMutableArray *resourceType;
|
|
|
|
NSArray *cardDavCollection;
|
|
|
|
|
|
|
|
cardDavCollection
|
|
|
|
= [NSArray arrayWithObjects: @"addressbook",
|
|
|
|
@"urn:ietf:params:xml:ns:carddav", nil];
|
|
|
|
resourceType = [NSMutableArray arrayWithArray: [super davResourceType]];
|
|
|
|
[resourceType addObject: cardDavCollection];
|
|
|
|
|
|
|
|
return resourceType;
|
|
|
|
}
|
|
|
|
|
2010-08-12 16:02:21 +02:00
|
|
|
- (id) davAddressbookMultiget: (id) queryContext
|
|
|
|
{
|
|
|
|
return [self performMultigetInContext: queryContext
|
|
|
|
inNamespace: @"urn:ietf:params:xml:ns:carddav"];
|
|
|
|
}
|
|
|
|
|
2007-09-17 05:42:16 +02:00
|
|
|
/* sorting */
|
|
|
|
- (NSComparisonResult) compare: (id) otherFolder
|
|
|
|
{
|
|
|
|
NSComparisonResult comparison;
|
|
|
|
|
|
|
|
if ([NSStringFromClass([otherFolder class])
|
2009-09-25 16:42:33 +02:00
|
|
|
isEqualToString: @"SOGoContactSourceFolder"])
|
2007-09-17 05:42:16 +02:00
|
|
|
comparison = NSOrderedAscending;
|
|
|
|
else
|
|
|
|
comparison = [super compare: otherFolder];
|
|
|
|
|
|
|
|
return comparison;
|
|
|
|
}
|
|
|
|
|
2006-08-09 23:11:49 +02:00
|
|
|
/* folder type */
|
|
|
|
|
2007-02-09 22:21:35 +01:00
|
|
|
- (NSString *) folderType
|
|
|
|
{
|
|
|
|
return @"Contact";
|
|
|
|
}
|
|
|
|
|
2010-08-12 16:02:21 +02:00
|
|
|
/* TODO: multiget reorg */
|
|
|
|
- (NSString *) _nodeTagForProperty: (NSString *) property
|
|
|
|
{
|
|
|
|
NSString *namespace, *nodeName, *nsRep;
|
|
|
|
NSRange nsEnd;
|
|
|
|
|
|
|
|
nsEnd = [property rangeOfString: @"}"];
|
|
|
|
namespace
|
|
|
|
= [property substringFromRange: NSMakeRange (1, nsEnd.location - 1)];
|
|
|
|
nodeName = [property substringFromIndex: nsEnd.location + 1];
|
|
|
|
if ([namespace isEqualToString: XMLNS_CARDDAV])
|
|
|
|
nsRep = @"C";
|
|
|
|
else
|
|
|
|
nsRep = @"D";
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"%@:%@", nsRep, nodeName];
|
|
|
|
}
|
|
|
|
|
2015-08-17 22:21:10 +02:00
|
|
|
- (NSString *) _baseCardDAVURL
|
|
|
|
{
|
|
|
|
NSString *davURL;
|
|
|
|
|
|
|
|
if (!baseCardDAVURL)
|
|
|
|
{
|
|
|
|
davURL = [[self realDavURL] absoluteString];
|
|
|
|
if ([davURL hasSuffix: @"/"])
|
|
|
|
baseCardDAVURL = [davURL substringToIndex: [davURL length] - 1];
|
|
|
|
else
|
|
|
|
baseCardDAVURL = davURL;
|
|
|
|
[baseCardDAVURL retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return baseCardDAVURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) cardDavURL
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%@/", [self _baseCardDAVURL]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _basePublicCardDAVURL
|
|
|
|
{
|
|
|
|
NSString *davURL;
|
|
|
|
|
|
|
|
if (!basePublicCardDAVURL)
|
|
|
|
{
|
|
|
|
davURL = [[self publicDavURL] absoluteString];
|
|
|
|
if ([davURL hasSuffix: @"/"])
|
|
|
|
basePublicCardDAVURL = [davURL substringToIndex: [davURL length] - 1];
|
|
|
|
else
|
|
|
|
basePublicCardDAVURL = davURL;
|
|
|
|
[basePublicCardDAVURL retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return basePublicCardDAVURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) publicCardDavURL
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%@/", [self _basePublicCardDAVURL]];
|
|
|
|
}
|
|
|
|
|
2006-08-09 23:11:49 +02:00
|
|
|
@end /* SOGoContactGCSFolder */
|