2007-11-08 20:56:18 +01:00
|
|
|
/* WORequest+SOGo.m - this file is part of SOGo
|
|
|
|
*
|
2010-03-19 14:08:15 +01:00
|
|
|
* Copyright (C) 2007-2010 Inverse inc.
|
2007-11-08 20:56:18 +01:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2008-11-05 18:26:02 +01:00
|
|
|
#import <Foundation/NSArray.h>
|
2008-07-09 23:09:08 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
|
2007-11-08 20:56:18 +01:00
|
|
|
#import <NGObjWeb/SoObjectRequestHandler.h>
|
|
|
|
#import <NGObjWeb/WOApplication.h>
|
2009-07-20 20:20:44 +02:00
|
|
|
#import <NGObjWeb/WEClientCapabilities.h>
|
2009-12-09 00:19:16 +01:00
|
|
|
#import <NGObjWeb/WORequest+So.h>
|
2007-11-08 20:56:18 +01:00
|
|
|
|
2008-07-09 23:09:08 +02:00
|
|
|
#import <DOM/DOMProtocols.h>
|
|
|
|
|
2007-11-08 20:56:18 +01:00
|
|
|
#import "WORequest+SOGo.h"
|
|
|
|
|
|
|
|
@implementation WORequest (SOGoSOPEUtilities)
|
|
|
|
|
|
|
|
- (BOOL) handledByDefaultHandler
|
|
|
|
{
|
|
|
|
#warning this should be changed someday
|
2010-06-02 18:44:09 +02:00
|
|
|
return ![[self requestHandlerKey] isEqualToString:@"dav"];
|
2007-11-08 20:56:18 +01:00
|
|
|
}
|
|
|
|
|
2008-07-09 23:09:08 +02:00
|
|
|
- (NSArray *) _propertiesOfElement: (id <DOMElement>) startElement
|
|
|
|
underTag: (NSString *) tag
|
|
|
|
{
|
|
|
|
id <DOMNodeList> list;
|
|
|
|
id <DOMElement> tagElement;
|
|
|
|
NSObject <DOMNode> *currentNode;
|
|
|
|
NSMutableArray *properties;
|
|
|
|
unsigned int count, max;
|
|
|
|
|
|
|
|
properties = nil;
|
|
|
|
|
|
|
|
list = [startElement getElementsByTagName: tag];
|
|
|
|
if ([list length])
|
|
|
|
{
|
|
|
|
tagElement = [list objectAtIndex: 0];
|
|
|
|
list = [tagElement getElementsByTagName: @"prop"];
|
|
|
|
if ([list length])
|
|
|
|
{
|
|
|
|
tagElement = [list objectAtIndex: 0];
|
|
|
|
properties = [NSMutableArray array];
|
|
|
|
list = [tagElement childNodes];
|
|
|
|
max = [list length];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
currentNode = [list objectAtIndex: count];
|
|
|
|
if ([currentNode conformsToProtocol: @protocol (DOMElement)])
|
|
|
|
[properties addObject: currentNode];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) davPatchedPropertiesWithTopTag: (NSString *) topTag
|
|
|
|
{
|
|
|
|
NSMutableDictionary *patchedProperties;
|
|
|
|
NSArray *props;
|
|
|
|
id <DOMDocument> element;
|
|
|
|
id <DOMElement> startElement;
|
|
|
|
NSObject <DOMNodeList> *list;
|
|
|
|
|
|
|
|
patchedProperties = nil;
|
|
|
|
if (!topTag)
|
|
|
|
topTag = @"propertyupdate";
|
|
|
|
element = [self contentAsDOMDocument];
|
|
|
|
list = [element getElementsByTagName: topTag];
|
|
|
|
if ([list length])
|
|
|
|
{
|
|
|
|
startElement = [list objectAtIndex: 0];
|
|
|
|
patchedProperties = [NSMutableDictionary dictionary];
|
|
|
|
props = [self _propertiesOfElement: startElement
|
|
|
|
underTag: @"set"];
|
|
|
|
if (props)
|
|
|
|
[patchedProperties setObject: props forKey: @"set"];
|
|
|
|
props = [self _propertiesOfElement: startElement
|
|
|
|
underTag: @"remove"];
|
|
|
|
if (props)
|
|
|
|
[patchedProperties setObject: props forKey: @"remove"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return patchedProperties;
|
|
|
|
}
|
|
|
|
|
2010-08-20 14:49:16 +02:00
|
|
|
/* So many different DAV libraries... */
|
2009-08-27 23:14:54 +02:00
|
|
|
- (BOOL) isAppleDAVWithSubstring: (NSString *) osSubstring
|
2009-07-20 20:20:44 +02:00
|
|
|
{
|
|
|
|
WEClientCapabilities *cc;
|
|
|
|
BOOL rc;
|
2009-08-27 23:14:54 +02:00
|
|
|
NSRange r;
|
2009-07-20 20:20:44 +02:00
|
|
|
|
|
|
|
cc = [self clientCapabilities];
|
|
|
|
if ([[cc userAgentType] isEqualToString: @"AppleDAVAccess"])
|
|
|
|
{
|
2009-08-27 23:14:54 +02:00
|
|
|
r = [[cc userAgent] rangeOfString: osSubstring];
|
|
|
|
rc = (r.location != NSNotFound);
|
2009-07-20 20:20:44 +02:00
|
|
|
}
|
2009-08-27 23:14:54 +02:00
|
|
|
else
|
|
|
|
rc = NO;
|
2009-07-20 20:20:44 +02:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-08-27 23:14:54 +02:00
|
|
|
- (BOOL) isIPhone
|
|
|
|
{
|
2011-10-17 19:14:06 +02:00
|
|
|
return [self isAppleDAVWithSubstring: @"iPhone/"]
|
|
|
|
|| [self isAppleDAVWithSubstring: @"iOS/"];
|
2009-08-27 23:14:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isICal
|
|
|
|
{
|
|
|
|
return [self isAppleDAVWithSubstring: @"Mac OS X/10."];
|
|
|
|
}
|
2009-07-20 20:20:44 +02:00
|
|
|
|
2011-11-21 15:15:14 +01:00
|
|
|
//
|
|
|
|
// sogod[22188] -[WEClientCapabilities initWithRequest:]: Unknown WebClient: user-agent='CalendarStore/5.0.1 (1139.14); iCal/5.0.1 (1547.4); Mac OS X/10.7.2 (11C74)'
|
|
|
|
//
|
|
|
|
//
|
2009-10-21 23:17:11 +02:00
|
|
|
- (BOOL) isICal4
|
|
|
|
{
|
2011-11-21 15:15:14 +01:00
|
|
|
return ([self isAppleDAVWithSubstring: @"iCal/4."] ||
|
|
|
|
[self isAppleDAVWithSubstring: @"iCal/5."]);
|
2009-10-21 23:17:11 +02:00
|
|
|
}
|
|
|
|
|
2011-11-21 15:15:14 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Starting from 10.7, we see something like:
|
|
|
|
//
|
|
|
|
// sogod[27330] -[WEClientCapabilities initWithRequest:]: Unknown WebClient: user-agent='AddressBook/6.1 (1062) CardDAVPlugin/196 CFNetwork/520.2.5 Mac_OS_X/10.7.2 (11C74)'
|
|
|
|
//
|
2010-08-20 14:49:16 +02:00
|
|
|
- (BOOL) isMacOSXAddressBookApp
|
2010-08-11 21:23:51 +02:00
|
|
|
{
|
|
|
|
WEClientCapabilities *cc;
|
2011-11-21 15:15:14 +01:00
|
|
|
BOOL b;
|
2010-08-11 21:23:51 +02:00
|
|
|
|
|
|
|
cc = [self clientCapabilities];
|
|
|
|
|
2011-11-21 15:15:14 +01:00
|
|
|
b = [[cc userAgent] rangeOfString: @"CFNetwork"].location != NSNotFound &&
|
|
|
|
([[cc userAgent] rangeOfString: @"Darwin"].location != NSNotFound ||
|
|
|
|
[[cc userAgent] rangeOfString: @"AddressBook"].location != NSNotFound);
|
|
|
|
|
|
|
|
return b;
|
2010-08-11 21:23:51 +02:00
|
|
|
}
|
|
|
|
|
2010-08-20 14:49:16 +02:00
|
|
|
- (BOOL) isIPhoneAddressBookApp
|
|
|
|
{
|
|
|
|
WEClientCapabilities *cc;
|
|
|
|
|
|
|
|
cc = [self clientCapabilities];
|
|
|
|
|
|
|
|
return ([[cc userAgent] rangeOfString: @"DataAccess/1.0"].location
|
|
|
|
!= NSNotFound);
|
|
|
|
}
|
|
|
|
|
2007-11-08 20:56:18 +01:00
|
|
|
@end
|