mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-11-21 23:12:40 +00:00
- external patch
Monotone-Parent: ba5973b414572fb5f085f8980182645843a42958 Monotone-Revision: ecf850422f6e93462013857de0eaef9e5ed5eb02 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-11-05T14:51:50 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
1 parent
5ede94bbaa
commit
cc0237bc45
8 files changed
+317
-160
No files matched your search
@@ -25,16 +25,12 @@
|
||||
#import <NGObjWeb/NSException+HTTP.h>
|
||||
#import <NGObjWeb/SoObject+SoDAV.h>
|
||||
#import <NGObjWeb/WOContext.h>
|
||||
#import <NGObjWeb/WOResponse.h>
|
||||
#import <NGObjWeb/WORequest.h>
|
||||
#import <NGExtensions/NSObject+Logs.h>
|
||||
#import <NGExtensions/NSString+misc.h>
|
||||
#import <EOControl/EOQualifier.h>
|
||||
#import <EOControl/EOSortOrdering.h>
|
||||
#import <GDLContentStore/GCSFolder.h>
|
||||
#import <DOM/DOMProtocols.h>
|
||||
#import <SaxObjC/SaxObjC.h>
|
||||
#import <SaxObjC/XMLNamespaces.h>
|
||||
|
||||
#import <SoObjects/SOGo/NSDictionary+Utilities.h>
|
||||
#import "SOGoContactGCSEntry.h"
|
||||
@@ -71,6 +67,7 @@
|
||||
|
||||
isPut = NO;
|
||||
obj = [super lookupName:_key inContext:_ctx acquire:NO];
|
||||
|
||||
if (!obj)
|
||||
{
|
||||
if ([[[_ctx request] method] isEqualToString: @"PUT"])
|
||||
@@ -174,74 +171,38 @@
|
||||
return newRecords;
|
||||
}
|
||||
|
||||
- (BOOL) _isValidFilter: (NSString *) theString
|
||||
- (NSArray *) lookupContactsWithFilter: (NSString *) filter
|
||||
sortBy: (NSString *) sortKey
|
||||
ordering: (NSComparisonResult) sortOrdering
|
||||
{
|
||||
if ([theString caseInsensitiveCompare: @"sn"] == NSOrderedSame)
|
||||
return YES;
|
||||
NSArray *fields, *dbRecords, *records;
|
||||
EOQualifier *qualifier;
|
||||
EOSortOrdering *ordering;
|
||||
|
||||
if ([theString caseInsensitiveCompare: @"givenname"] == NSOrderedSame)
|
||||
return YES;
|
||||
fields = folderListingFields;
|
||||
qualifier = [self _qualifierForFilter: filter];
|
||||
dbRecords = [[self ocsFolder] fetchFields: fields
|
||||
matchingQualifier: qualifier];
|
||||
|
||||
if ([theString caseInsensitiveCompare: @"mail"] == NSOrderedSame)
|
||||
return YES;
|
||||
|
||||
if ([theString caseInsensitiveCompare: @"telephonenumber"] == NSOrderedSame)
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSDictionary *) _parseContactFilter: (id <DOMElement>) filterElement
|
||||
{
|
||||
NSMutableDictionary *filterData;
|
||||
id <DOMNode> parentNode;
|
||||
id <DOMNodeList> ranges;
|
||||
|
||||
parentNode = [filterElement parentNode];
|
||||
|
||||
if ([[parentNode tagName] isEqualToString: @"filter"] &&
|
||||
[self _isValidFilter: [filterElement attribute: @"name"]])
|
||||
if ([dbRecords count] > 0)
|
||||
{
|
||||
ranges = [filterElement getElementsByTagName: @"text-match"];
|
||||
|
||||
if ([ranges count] && [[[ranges objectAtIndex: 0] childNodes] count])
|
||||
{
|
||||
filterData = [NSMutableDictionary new];
|
||||
[filterData autorelease];
|
||||
[filterData setObject: [[[[ranges objectAtIndex: 0] childNodes] lastObject] data]
|
||||
forKey: [filterElement attribute: @"name"]];
|
||||
}
|
||||
records = [self _flattenedRecords: dbRecords];
|
||||
ordering
|
||||
= [EOSortOrdering sortOrderingWithKey: sortKey
|
||||
selector: ((sortOrdering == NSOrderedDescending)
|
||||
? EOCompareCaseInsensitiveDescending
|
||||
: EOCompareCaseInsensitiveAscending)];
|
||||
records
|
||||
= [records sortedArrayUsingKeyOrderArray:
|
||||
[NSArray arrayWithObject: ordering]];
|
||||
}
|
||||
else
|
||||
filterData = nil;
|
||||
records = nil;
|
||||
// else
|
||||
//[self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
|
||||
|
||||
return filterData;
|
||||
}
|
||||
|
||||
#warning filters is leaked here
|
||||
- (NSArray *) _parseContactFilters: (id <DOMElement>) parentNode
|
||||
{
|
||||
NSEnumerator *children;
|
||||
id<DOMElement> node;
|
||||
NSMutableArray *filters;
|
||||
NSDictionary *filter;
|
||||
|
||||
filters = [NSMutableArray new];
|
||||
|
||||
children = [[parentNode getElementsByTagName: @"prop-filter"]
|
||||
objectEnumerator];
|
||||
|
||||
node = [children nextObject];
|
||||
|
||||
while (node)
|
||||
{
|
||||
filter = [self _parseContactFilter: node];
|
||||
if (filter)
|
||||
[filters addObject: filter];
|
||||
node = [children nextObject];
|
||||
}
|
||||
|
||||
return filters;
|
||||
[self debugWithFormat:@"fetched %i records.", [records count]];
|
||||
return records;
|
||||
}
|
||||
|
||||
- (void) appendObject: (NSDictionary *) object
|
||||
@@ -280,99 +241,6 @@
|
||||
[r appendContentString: @" </D:response>\r\n"];
|
||||
}
|
||||
|
||||
- (void) _appendComponentsMatchingFilters: (NSArray *) filters
|
||||
toResponse: (WOResponse *) response
|
||||
{
|
||||
unsigned int count, max;
|
||||
NSDictionary *currentFilter, *contact;
|
||||
NSEnumerator *contacts;
|
||||
NSString *baseURL;
|
||||
|
||||
baseURL = [self baseURLInContext: context];
|
||||
|
||||
max = [filters count];
|
||||
for (count = 0; count < max; count++)
|
||||
{
|
||||
currentFilter = [filters objectAtIndex: count];
|
||||
contacts = [[self lookupContactsWithFilter: [[currentFilter allValues] lastObject]
|
||||
sortBy: @"c_givenname"
|
||||
ordering: NSOrderedDescending]
|
||||
objectEnumerator];
|
||||
|
||||
while ((contact = [contacts nextObject]))
|
||||
{
|
||||
[self appendObject: contact
|
||||
withBaseURL: baseURL
|
||||
toREPORTResponse: response];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *) lookupContactsWithFilter: (NSString *) filter
|
||||
sortBy: (NSString *) sortKey
|
||||
ordering: (NSComparisonResult) sortOrdering
|
||||
{
|
||||
NSArray *fields, *dbRecords, *records;
|
||||
EOQualifier *qualifier;
|
||||
EOSortOrdering *ordering;
|
||||
|
||||
fields = folderListingFields;
|
||||
qualifier = [self _qualifierForFilter: filter];
|
||||
dbRecords = [[self ocsFolder] fetchFields: fields
|
||||
matchingQualifier: qualifier];
|
||||
|
||||
if ([dbRecords count] > 0)
|
||||
{
|
||||
records = [self _flattenedRecords: dbRecords];
|
||||
ordering
|
||||
= [EOSortOrdering sortOrderingWithKey: sortKey
|
||||
selector: ((sortOrdering == NSOrderedDescending)
|
||||
? EOCompareCaseInsensitiveDescending
|
||||
: EOCompareCaseInsensitiveAscending)];
|
||||
records
|
||||
= [records sortedArrayUsingKeyOrderArray:
|
||||
[NSArray arrayWithObject: ordering]];
|
||||
}
|
||||
else
|
||||
records = nil;
|
||||
// else
|
||||
// [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
|
||||
|
||||
[self debugWithFormat:@"fetched %i records.", [records count]];
|
||||
return records;
|
||||
}
|
||||
|
||||
- (NSArray *) davNamespaces
|
||||
{
|
||||
return [NSArray arrayWithObject: @"urn:ietf:params:xml:ns:carddav"];
|
||||
}
|
||||
|
||||
- (id) davAddressbookQuery: (id) queryContext
|
||||
{
|
||||
WOResponse *r;
|
||||
NSArray *filters;
|
||||
id <DOMDocument> document;
|
||||
|
||||
r = [context response];
|
||||
[r setStatus: 207];
|
||||
[r setContentEncoding: NSUTF8StringEncoding];
|
||||
[r setHeader: @"text/xml; charset=\"utf-8\"" forKey: @"content-type"];
|
||||
[r setHeader: @"no-cache" forKey: @"pragma"];
|
||||
[r setHeader: @"no-cache" forKey: @"cache-control"];
|
||||
[r appendContentString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"];
|
||||
[r appendContentString: @"<D:multistatus xmlns:D=\"DAV:\""
|
||||
@" xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\r\n"];
|
||||
|
||||
document = [[context request] contentAsDOMDocument];
|
||||
filters = [self _parseContactFilters: [document documentElement]];
|
||||
|
||||
[self _appendComponentsMatchingFilters: filters
|
||||
toResponse: r];
|
||||
[r appendContentString:@"</D:multistatus>\r\n"];
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
- (NSArray *) davComplianceClassesInContext: (id)_ctx
|
||||
{
|
||||
NSMutableArray *classes;
|
||||
@@ -390,6 +258,11 @@
|
||||
return classes;
|
||||
}
|
||||
|
||||
- (NSArray *) davNamespaces
|
||||
{
|
||||
return [NSArray arrayWithObject: @"urn:ietf:params:xml:ns:carddav"];
|
||||
}
|
||||
|
||||
- (NSString *) groupDavResourceType
|
||||
{
|
||||
return @"vcard-collection";
|
||||
|
||||
Reference in new issue
Block a user