2007-11-08 20:56:18 +01:00
|
|
|
/* WORequest+SOGo.m - this file is part of SOGo
|
|
|
|
*
|
2015-01-09 15:04:15 +01:00
|
|
|
* Copyright (C) 2007-2015 Inverse inc.
|
2007-11-08 20:56:18 +01:00
|
|
|
*
|
|
|
|
* 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-07-09 23:09:08 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
|
2007-11-08 20:56:18 +01:00
|
|
|
#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
|
2014-01-10 20:10:16 +01:00
|
|
|
return !([[self requestHandlerKey] isEqualToString: @"dav"] || [[self requestHandlerKey] isEqualToString: @"Microsoft-Server-ActiveSync"]);
|
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
|
|
|
}
|
|
|
|
|
2015-01-09 15:04:15 +01:00
|
|
|
//
|
|
|
|
// Mac+OS+X/10.10.1 (14B25) CalendarAgent/315
|
2020-12-01 21:36:51 +01:00
|
|
|
// macOS/11.0.1 (20B50) CalendarAgent/954
|
2015-01-09 15:04:15 +01:00
|
|
|
//
|
2009-08-27 23:14:54 +02:00
|
|
|
- (BOOL) isICal
|
|
|
|
{
|
2020-12-02 15:27:56 +01:00
|
|
|
WEClientCapabilities *cc;
|
|
|
|
|
|
|
|
cc = [self clientCapabilities];
|
|
|
|
|
2011-11-30 15:28:54 +01:00
|
|
|
return ([self isAppleDAVWithSubstring: @"Mac OS X/10."]
|
2014-09-15 20:08:54 +02:00
|
|
|
|| [self isAppleDAVWithSubstring: @"Mac_OS_X/"]
|
2015-01-09 15:04:15 +01:00
|
|
|
|| [self isAppleDAVWithSubstring: @"Mac+OS+X/"]
|
2020-12-01 21:36:51 +01:00
|
|
|
|| [self isAppleDAVWithSubstring: @"macOS/"]
|
|
|
|
|| [self isAppleDAVWithSubstring: @"CoreDAV/"]
|
|
|
|
|| [[cc userAgent] rangeOfString: @"DAVx5"].location != NSNotFound);
|
2009-08-27 23:14:54 +02:00
|
|
|
}
|
2009-07-20 20:20:44 +02:00
|
|
|
|
2011-11-21 15:15:14 +01:00
|
|
|
//
|
2012-09-04 19:46:23 +02:00
|
|
|
// CalendarStore/5.0.1 (1139.14); iCal/5.0.1 (1547.4); Mac OS X/10.7.2 (11C74)
|
|
|
|
// CalendarStore/5.0.3 (1204.1); iCal/5.0.3 (1605.3); Mac OS X/10.7.4 (11E53)
|
|
|
|
// Mac OS X/10.8 (12A269) Calendar/1639
|
|
|
|
// Mac OS X/10.8 (12A269) CalendarAgent/47
|
|
|
|
// Mac OS X/10.8.1 (12B19) CalendarAgent/47
|
2020-12-01 21:36:51 +01:00
|
|
|
// macOS/11.0.1 (20B50) CalendarAgent/954
|
2011-11-21 15:15:14 +01:00
|
|
|
//
|
2009-10-21 23:17:11 +02:00
|
|
|
- (BOOL) isICal4
|
|
|
|
{
|
2011-11-30 15:28:54 +01:00
|
|
|
return ([self isAppleDAVWithSubstring: @"iCal/4."]
|
|
|
|
|| [self isAppleDAVWithSubstring: @"iCal/5."]
|
2012-09-04 19:46:23 +02:00
|
|
|
|| [self isAppleDAVWithSubstring: @"CoreDAV/"]
|
|
|
|
|| [self isAppleDAVWithSubstring: @"Calendar/"]
|
|
|
|
|| [self isAppleDAVWithSubstring: @"CalendarAgent/"]);
|
2009-10-21 23:17:11 +02:00
|
|
|
}
|
|
|
|
|
2013-01-09 17:39:29 +01:00
|
|
|
// For 10.6, we see:
|
|
|
|
//
|
|
|
|
// Address%20Book/883 CFNetwork/454.12.4 Darwin/10.8.0 (i386) (iMac11%2C3)
|
2011-11-21 15:15:14 +01:00
|
|
|
//
|
2012-09-04 19:46:23 +02:00
|
|
|
// For 10.7, we see:
|
|
|
|
//
|
2013-01-09 17:39:29 +01:00
|
|
|
// AddressBook/6.0 (1043) CardDAVPlugin/182 CFNetwork/520.0.13 Mac_OS_X/10.7.1 (11B26)
|
2012-09-04 19:46:23 +02:00
|
|
|
// AddressBook/6.1 (1062) CardDAVPlugin/196 CFNetwork/520.2.5 Mac_OS_X/10.7.2 (11C74)
|
2013-01-09 17:39:29 +01:00
|
|
|
// AddressBook/6.1 (1083) CardDAVPlugin/200 CFNetwork/520.3.2 Mac_OS_X/10.7.3 (11D50d)
|
2012-09-04 19:46:23 +02:00
|
|
|
// AddressBook/6.1.2 (1090) CardDAVPlugin/200 CFNetwork/520.4.3 Mac_OS_X/10.7.4 (11E53)
|
2013-01-09 17:39:29 +01:00
|
|
|
// AddressBook/6.1.3 (1091) CardDAVPlugin/200 CFNetwork/520.5.1 Mac_OS_X/10.7.5 (11G56)
|
2011-11-21 15:15:14 +01:00
|
|
|
//
|
2012-09-04 19:46:23 +02:00
|
|
|
// For 10.8, we see:
|
|
|
|
//
|
|
|
|
// Mac OS X/10.8 (12A269) AddressBook/1143
|
|
|
|
// Mac OS X/10.8.1 (12B19) AddressBook/1143
|
2013-01-09 17:39:29 +01:00
|
|
|
// Mac OS X/10.8.2 (12C60) AddressBook/1167
|
2011-11-21 15:15:14 +01:00
|
|
|
//
|
2020-12-01 21:36:51 +01:00
|
|
|
// For 10.14, we see:
|
|
|
|
//
|
|
|
|
// Mac OS X/10.14.6 (18G6042) AddressBookCore/1
|
|
|
|
//
|
|
|
|
// For 11.0, we see:
|
|
|
|
//
|
|
|
|
// macOS/11.0.1 (20B50) AddressBookCore/2452
|
|
|
|
//
|
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];
|
|
|
|
|
2013-01-09 17:39:29 +01:00
|
|
|
b = (
|
2015-11-03 23:02:45 +01:00
|
|
|
(
|
|
|
|
[[cc userAgent] rangeOfString: @"CFNetwork"].location != NSNotFound
|
|
|
|
&& [[cc userAgent] rangeOfString: @"Darwin"].location != NSNotFound
|
|
|
|
)
|
|
|
|
||
|
|
|
|
(
|
|
|
|
[[cc userAgent] rangeOfString: @"CFNetwork"].location != NSNotFound
|
|
|
|
&& [[cc userAgent] rangeOfString: @"AddressBook"].location != NSNotFound
|
|
|
|
)
|
|
|
|
||
|
|
|
|
(
|
|
|
|
[[cc userAgent] rangeOfString: @"Mac OS X"].location != NSNotFound
|
|
|
|
&& [[cc userAgent] rangeOfString: @"AddressBook"].location != NSNotFound
|
|
|
|
)
|
2020-12-01 21:36:51 +01:00
|
|
|
||
|
|
|
|
(
|
|
|
|
[[cc userAgent] rangeOfString: @"macOS"].location != NSNotFound
|
|
|
|
&& [[cc userAgent] rangeOfString: @"AddressBookCore"].location != NSNotFound
|
|
|
|
)
|
|
|
|
);
|
2011-11-21 15:15:14 +01:00
|
|
|
|
|
|
|
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];
|
|
|
|
|
2012-03-09 18:12:59 +01:00
|
|
|
return ([[cc userAgent] rangeOfString: @"DataAccess/1.0"].location != NSNotFound ||
|
2020-12-01 21:36:51 +01:00
|
|
|
[[cc userAgent] rangeOfString: @"dataaccessd/1.0"].location != NSNotFound); // Since iOS 5.0.1
|
2010-08-20 14:49:16 +02:00
|
|
|
}
|
|
|
|
|
2012-06-29 22:17:20 +02:00
|
|
|
- (BOOL) isAndroid
|
|
|
|
{
|
|
|
|
WEClientCapabilities *cc;
|
|
|
|
|
|
|
|
cc = [self clientCapabilities];
|
|
|
|
|
|
|
|
// CardDAV-Sync (Android) (like iOS/5.0.1 (9A405) dataaccessd/1.0) gzip
|
|
|
|
return ([[cc userAgent] rangeOfString: @"Android"].location != NSNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-08 20:56:18 +01:00
|
|
|
@end
|