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
|
2009-12-09 00:19:16 +01:00
|
|
|
return ![self isSoWebDAVRequest];
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
return [self isAppleDAVWithSubstring: @"iPhone/"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isICal
|
|
|
|
{
|
|
|
|
return [self isAppleDAVWithSubstring: @"Mac OS X/10."];
|
|
|
|
}
|
2009-07-20 20:20:44 +02:00
|
|
|
|
2009-10-21 23:17:11 +02:00
|
|
|
- (BOOL) isICal4
|
|
|
|
{
|
|
|
|
return [self isAppleDAVWithSubstring: @"iCal/4."];
|
|
|
|
}
|
|
|
|
|
2007-11-08 20:56:18 +01:00
|
|
|
@end
|