2014-01-10 20:12:53 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2014, Inverse inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
2014-01-13 17:46:32 +01:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the Inverse inc. nor the
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2014-01-10 20:12:53 +01:00
|
|
|
|
|
|
|
*/
|
|
|
|
#include "NSString+ActiveSync.h"
|
|
|
|
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSCalendarDate.h>
|
2014-02-03 16:24:33 +01:00
|
|
|
#include <Foundation/NSData.h>
|
2014-01-10 20:12:53 +01:00
|
|
|
#include <Foundation/NSDate.h>
|
2014-12-29 22:19:10 +01:00
|
|
|
#include <Foundation/NSTimeZone.h>
|
2014-01-10 20:12:53 +01:00
|
|
|
|
2014-02-04 21:03:02 +01:00
|
|
|
#include <SOGo/NSString+Utilities.h>
|
2014-10-16 15:35:15 +02:00
|
|
|
#include <SOGo/NSData+Crypto.h>
|
2014-02-04 21:03:02 +01:00
|
|
|
|
2014-10-16 15:35:15 +02:00
|
|
|
#include <NGExtensions/NGBase64Coding.h>
|
2014-01-24 22:33:31 +01:00
|
|
|
#include <NGExtensions/NSString+misc.h>
|
|
|
|
|
2014-10-16 15:35:15 +02:00
|
|
|
static NSArray *easCommandCodes = nil;
|
2014-11-04 19:50:10 +01:00
|
|
|
static NSArray *easCommandParameters = nil;
|
2014-10-16 15:35:15 +02:00
|
|
|
|
2014-01-10 20:12:53 +01:00
|
|
|
@implementation NSString (ActiveSync)
|
|
|
|
|
2015-08-03 09:48:06 +02:00
|
|
|
//
|
|
|
|
// This is a copy from NSString+XMLEscaping.m from SOPE.
|
|
|
|
// The difference here is that we use wchar_t instead of unichar.
|
|
|
|
// This is needed to get the rigth numeric character reference.
|
|
|
|
// e.g. SMILING FACE WITH OPEN MOUTH
|
|
|
|
// ok: wchar_t -> 😃 wrong: unichar -> � �
|
|
|
|
//
|
|
|
|
// We avoir naming it like the one in SOPE since if the ActiveSync
|
|
|
|
// bundle is loaded, it'll overwrite the one provided by SOPE.
|
|
|
|
//
|
|
|
|
- (NSString *) _stringByEscapingXMLStringUsingCharacters {
|
|
|
|
register unsigned i, len, j;
|
|
|
|
register wchar_t *buf;
|
|
|
|
const wchar_t *chars;
|
|
|
|
unsigned escapeCount;
|
|
|
|
|
|
|
|
if ([self length] == 0) return @"";
|
|
|
|
|
|
|
|
NSData *data = [self dataUsingEncoding:NSUTF32StringEncoding];
|
|
|
|
chars = [data bytes];
|
|
|
|
len = [data length]/4;
|
|
|
|
|
|
|
|
/* check for characters to escape ... */
|
|
|
|
for (i = 0, escapeCount = 0; i < len; i++) {
|
|
|
|
switch (chars[i]) {
|
|
|
|
case '&': case '"': case '<': case '>': case '\r':
|
|
|
|
escapeCount++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (chars[i] > 127)
|
|
|
|
escapeCount++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (escapeCount == 0 ) {
|
|
|
|
/* nothing to escape ... */
|
|
|
|
return [[self copy] autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = calloc((len + 5) + (escapeCount * 16), sizeof(wchar_t));
|
|
|
|
for (i = 0, j = 0; i < len; i++) {
|
|
|
|
switch (chars[i]) {
|
|
|
|
/* escape special chars */
|
|
|
|
case '\r':
|
|
|
|
buf[j] = '&'; j++; buf[j] = '#'; j++; buf[j] = '1'; j++;
|
|
|
|
buf[j] = '3'; j++; buf[j] = ';'; j++;
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
buf[j] = '&'; j++; buf[j] = 'a'; j++; buf[j] = 'm'; j++;
|
|
|
|
buf[j] = 'p'; j++; buf[j] = ';'; j++;
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
buf[j] = '&'; j++; buf[j] = 'q'; j++; buf[j] = 'u'; j++;
|
|
|
|
buf[j] = 'o'; j++; buf[j] = 't'; j++; buf[j] = ';'; j++;
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
buf[j] = '&'; j++; buf[j] = 'l'; j++; buf[j] = 't'; j++;
|
|
|
|
buf[j] = ';'; j++;
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
buf[j] = '&'; j++; buf[j] = 'g'; j++; buf[j] = 't'; j++;
|
|
|
|
buf[j] = ';'; j++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* escape big chars */
|
|
|
|
if (chars[i] > 127) {
|
|
|
|
unsigned char nbuf[32];
|
|
|
|
unsigned int k;
|
|
|
|
|
|
|
|
sprintf((char *)nbuf, "&#%i;", (int)chars[i]);
|
|
|
|
for (k = 0; nbuf[k] != '\0'; k++) {
|
|
|
|
buf[j] = nbuf[k];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (chars[i] == 0x9 || chars[i] == 0xA || chars[i] == 0xD || chars[i] >= 0x20) { // ignore any unsupported control character
|
|
|
|
/* nothing to escape */
|
|
|
|
buf[j] = chars[i];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self = [[NSString alloc] initWithBytesNoCopy: buf
|
|
|
|
length: (j*sizeof(wchar_t))
|
|
|
|
encoding: NSUTF32StringEncoding
|
|
|
|
freeWhenDone: YES];
|
|
|
|
|
|
|
|
return [self autorelease];
|
|
|
|
}
|
|
|
|
|
2014-02-17 14:39:48 +01:00
|
|
|
- (NSString *) sanitizedServerIdWithType: (SOGoMicrosoftActiveSyncFolderType) folderType
|
|
|
|
{
|
|
|
|
if (folderType == ActiveSyncEventFolder)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = [self length];
|
|
|
|
|
|
|
|
if (len > 4 && [self hasSuffix: @".ics"])
|
|
|
|
return [self substringToIndex: len-4];
|
|
|
|
else
|
|
|
|
return [NSString stringWithFormat: @"%@.ics", self];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-02-17 16:01:44 +01:00
|
|
|
- (NSString *) activeSyncRepresentationInContext: (WOContext *) context
|
2014-02-04 21:03:02 +01:00
|
|
|
{
|
2015-08-03 09:48:06 +02:00
|
|
|
return [self _stringByEscapingXMLStringUsingCharacters];
|
2014-02-04 21:03:02 +01:00
|
|
|
}
|
|
|
|
|
2014-01-10 20:12:53 +01:00
|
|
|
- (int) activeSyncFolderType
|
|
|
|
{
|
|
|
|
if ([self isEqualToString: @"inbox"])
|
|
|
|
return 2;
|
|
|
|
else if ([self isEqualToString: @"draft"])
|
|
|
|
return 3;
|
|
|
|
else if ([self isEqualToString: @"sent"])
|
|
|
|
return 5;
|
|
|
|
else if ([self isEqualToString: @"trash"])
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) realCollectionIdWithFolderType: (SOGoMicrosoftActiveSyncFolderType *) folderType;
|
|
|
|
{
|
2014-02-03 16:24:33 +01:00
|
|
|
NSString *realCollectionId, *v;
|
2014-01-10 20:12:53 +01:00
|
|
|
|
|
|
|
*folderType = ActiveSyncGenericFolder;
|
2014-02-03 16:24:33 +01:00
|
|
|
v = [self stringByUnescapingURL];
|
2014-01-10 20:12:53 +01:00
|
|
|
|
2014-02-03 16:24:33 +01:00
|
|
|
if ([v hasPrefix: @"vevent/"])
|
2014-01-10 20:12:53 +01:00
|
|
|
{
|
2014-02-03 16:24:33 +01:00
|
|
|
realCollectionId = [v substringFromIndex: 7];
|
2014-01-10 20:12:53 +01:00
|
|
|
*folderType = ActiveSyncEventFolder;
|
|
|
|
}
|
2014-02-03 16:24:33 +01:00
|
|
|
else if ([v hasPrefix: @"vtodo/"])
|
2014-01-10 20:12:53 +01:00
|
|
|
{
|
2014-02-03 16:24:33 +01:00
|
|
|
realCollectionId = [v substringFromIndex: 6];
|
2014-01-10 20:12:53 +01:00
|
|
|
*folderType = ActiveSyncTaskFolder;
|
|
|
|
}
|
2014-02-03 16:24:33 +01:00
|
|
|
else if ([v hasPrefix: @"vcard/"])
|
2014-01-10 20:12:53 +01:00
|
|
|
{
|
2014-02-03 16:24:33 +01:00
|
|
|
realCollectionId = [v substringFromIndex: 6];
|
2014-01-10 20:12:53 +01:00
|
|
|
*folderType = ActiveSyncContactFolder;
|
|
|
|
}
|
2014-02-03 16:24:33 +01:00
|
|
|
else if ([v hasPrefix: @"mail/"])
|
2014-01-10 20:12:53 +01:00
|
|
|
{
|
2014-02-03 16:24:33 +01:00
|
|
|
realCollectionId = [[v stringByUnescapingURL] substringFromIndex: 5];
|
2014-01-10 20:12:53 +01:00
|
|
|
*folderType = ActiveSyncMailFolder;
|
|
|
|
}
|
2014-02-03 16:24:33 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
realCollectionId = nil;
|
|
|
|
}
|
2014-01-10 20:12:53 +01:00
|
|
|
|
|
|
|
return realCollectionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// 2014-01-16T05:00:00.000Z
|
|
|
|
//
|
|
|
|
// See http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSCalendarDate.html#method$NSCalendarDate-initWithString$calendarFormat$ for the format details.
|
|
|
|
//
|
|
|
|
- (NSCalendarDate *) calendarDate
|
|
|
|
{
|
2014-12-29 22:19:10 +01:00
|
|
|
NSString *s;
|
2014-01-10 20:12:53 +01:00
|
|
|
id o;
|
|
|
|
|
2014-12-29 22:19:10 +01:00
|
|
|
// We force parsing in the GMT timezone. If we don't do that, the date will be parsed
|
|
|
|
// in the default timezone.
|
|
|
|
s = [NSString stringWithFormat: @"%@ GMT", self];
|
|
|
|
o = [NSCalendarDate dateWithString: s calendarFormat: @"%Y%m%dT%H%M%SZ %Z"];
|
2014-01-10 20:12:53 +01:00
|
|
|
|
|
|
|
if (!o)
|
2014-12-29 22:19:10 +01:00
|
|
|
o = [NSCalendarDate dateWithString: s calendarFormat: @"%Y-%m-%dT%H:%M:%S.%FZ %Z"];
|
|
|
|
|
2014-01-10 20:12:53 +01:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2014-01-13 16:18:20 +01:00
|
|
|
- (NSString *) _valueForParameter: (NSString *) theParameter
|
2014-01-10 20:12:53 +01:00
|
|
|
{
|
2014-10-16 15:35:15 +02:00
|
|
|
NSMutableArray *components;
|
2014-01-10 20:12:53 +01:00
|
|
|
NSString *s;
|
|
|
|
int i;
|
|
|
|
|
2014-10-16 15:35:15 +02:00
|
|
|
components = [NSMutableArray arrayWithArray: [[[self componentsSeparatedByString: @"?"] lastObject] componentsSeparatedByString: @"&"]];
|
|
|
|
|
|
|
|
// We handle BASE64 encoded queryStrings. See http://msdn.microsoft.com/en-us/library/ee160227%28v=exchg.80%29.aspx for details.
|
|
|
|
if ([components count] == 1)
|
|
|
|
{
|
2014-11-04 19:50:10 +01:00
|
|
|
NSString *deviceType, *parameterValue;
|
2014-10-16 15:35:15 +02:00
|
|
|
NSData *queryString;
|
|
|
|
|
2014-11-04 19:50:10 +01:00
|
|
|
int cmd_code, deviceid_length, policy_length, devicetype_length, parameter_code, parameter_length, i;
|
2014-10-16 15:35:15 +02:00
|
|
|
const char* qs_bytes;
|
|
|
|
|
|
|
|
queryString = [[components objectAtIndex: 0] dataByDecodingBase64];
|
2014-11-22 14:14:31 +01:00
|
|
|
|
|
|
|
if (![queryString length])
|
|
|
|
return nil;
|
|
|
|
|
2014-10-16 15:35:15 +02:00
|
|
|
qs_bytes = (const char*)[queryString bytes];
|
|
|
|
|
|
|
|
if (!easCommandCodes)
|
|
|
|
{
|
|
|
|
easCommandCodes = [NSArray arrayWithObjects:@"Sync", @"SendMail", @"SmartForward", @"SmartReply", @"GetAttachment", @"na", @"na", @"na", @"na",
|
|
|
|
@"FolderSync", @"FolderCreate", @"FolderDelete", @"FolderUpdate", @"MoveItems", @"GetItemEstimate", @"MeetingResponse",
|
|
|
|
@"Search", @"Settings", @"Ping", @"ItemOperations", @"Provision", @"ResolveRecipients", @"ValidateCert", nil];
|
|
|
|
RETAIN(easCommandCodes);
|
|
|
|
}
|
|
|
|
|
2014-11-04 19:50:10 +01:00
|
|
|
if (!easCommandParameters)
|
|
|
|
{
|
|
|
|
easCommandParameters = [NSArray arrayWithObjects:@"AttachmentName", @"CollectionId", @"na", @"ItemId", @"LongId", @"na", @"Occurrence", @"Options", @"User", nil];
|
|
|
|
RETAIN(easCommandParameters);
|
|
|
|
}
|
|
|
|
|
2014-10-16 15:35:15 +02:00
|
|
|
// Command code, 1 byte, ie.: cmd=
|
|
|
|
cmd_code = qs_bytes[1];
|
2014-11-04 19:50:10 +01:00
|
|
|
[components addObject: [NSString stringWithFormat: @"cmd=%@", [easCommandCodes objectAtIndex: cmd_code]]];
|
2014-10-16 15:35:15 +02:00
|
|
|
|
|
|
|
// Device ID length and Device ID (variable)
|
|
|
|
deviceid_length = qs_bytes[4];
|
2014-11-04 19:50:10 +01:00
|
|
|
[components addObject: [NSString stringWithFormat: @"deviceId=%@", [[NSData encodeDataAsHexString: [queryString subdataWithRange: NSMakeRange(5, deviceid_length)]] uppercaseString]]];
|
2014-10-16 15:35:15 +02:00
|
|
|
|
|
|
|
// Device type length and type (variable)
|
|
|
|
policy_length = qs_bytes[5+deviceid_length];
|
|
|
|
devicetype_length = qs_bytes[5+deviceid_length+1+policy_length];
|
2014-11-04 19:50:10 +01:00
|
|
|
deviceType = [[NSString alloc] initWithData: [queryString subdataWithRange: NSMakeRange(5+deviceid_length+1+policy_length+1, devicetype_length)]
|
|
|
|
encoding: NSASCIIStringEncoding];
|
2014-10-16 15:35:15 +02:00
|
|
|
AUTORELEASE(deviceType);
|
|
|
|
|
2014-11-04 19:50:10 +01:00
|
|
|
[components addObject: [NSString stringWithFormat: @"deviceType=%@", deviceType]];
|
|
|
|
|
|
|
|
// Command Parameters
|
|
|
|
i = 5+deviceid_length+1+policy_length+1+devicetype_length;
|
|
|
|
|
|
|
|
while (i < [queryString length])
|
|
|
|
{
|
|
|
|
parameter_code = qs_bytes[i];
|
|
|
|
parameter_length = qs_bytes[i+1];
|
|
|
|
parameterValue = [[NSString alloc] initWithData: [queryString subdataWithRange: NSMakeRange(i+1+1, parameter_length)]
|
|
|
|
encoding: NSASCIIStringEncoding];
|
|
|
|
|
|
|
|
AUTORELEASE(parameterValue);
|
|
|
|
|
|
|
|
// parameter_code 7 == Options
|
|
|
|
// http://msdn.microsoft.com/en-us/library/ee237789(v=exchg.80).aspx
|
|
|
|
if (parameter_code == 7)
|
|
|
|
[components addObject: [NSString stringWithFormat: @"%@=%@", [easCommandParameters objectAtIndex: parameter_code],
|
|
|
|
([parameterValue isEqualToString: @"\001"]) ? @"SaveInSent" : @"AcceptMultiPart"]];
|
|
|
|
else
|
|
|
|
[components addObject: [NSString stringWithFormat: @"%@=%@", [easCommandParameters objectAtIndex: parameter_code], parameterValue]];
|
|
|
|
|
|
|
|
i = i + 1 + 1 + parameter_length;
|
|
|
|
}
|
2014-10-16 15:35:15 +02:00
|
|
|
}
|
2014-01-10 20:12:53 +01:00
|
|
|
|
|
|
|
for (i = 0; i < [components count]; i++)
|
|
|
|
{
|
|
|
|
s = [components objectAtIndex: i];
|
|
|
|
|
2014-01-13 16:18:20 +01:00
|
|
|
if ([[s uppercaseString] hasPrefix: theParameter])
|
|
|
|
return [s substringFromIndex: [theParameter length]];
|
2014-01-10 20:12:53 +01:00
|
|
|
}
|
2014-01-13 16:18:20 +01:00
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This method extracts the "DeviceId" from a URI:
|
|
|
|
//
|
|
|
|
// /SOGo/Microsoft-Server-ActiveSync?Cmd=FolderSync&User=sogo10&DeviceId=SEC17CD1A3E9E3F2&DeviceType=SAMSUNGSGHI317M
|
|
|
|
//
|
|
|
|
- (NSString *) deviceId
|
|
|
|
{
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [self _valueForParameter: @"DEVICEID="];
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
s = @"Unknown";
|
2014-01-10 20:12:53 +01:00
|
|
|
|
2014-01-13 16:18:20 +01:00
|
|
|
return s;
|
2014-01-10 20:12:53 +01:00
|
|
|
}
|
2014-01-13 16:18:20 +01:00
|
|
|
|
2014-03-19 16:30:18 +01:00
|
|
|
//
|
|
|
|
// This method extracts the "DeviceType" from a URI:
|
|
|
|
//
|
|
|
|
// /SOGo/Microsoft-Server-ActiveSync?Cmd=FolderSync&User=sogo10&DeviceId=SEC17CD1A3E9E3F2&DeviceType=SAMSUNGSGHI317M
|
|
|
|
//
|
|
|
|
- (NSString *) deviceType
|
|
|
|
{
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [self _valueForParameter: @"DEVICETYPE="];
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
s = @"Unknown";
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-06-09 15:25:06 +02:00
|
|
|
// This method extracts the "AttachmentName" from a URI:
|
|
|
|
//
|
|
|
|
// /SOGo/Microsoft-Server-ActiveSync?Cmd=GetAttachment&User=sogo&DeviceId=HTCa04b4932597acd3f2dc1a918b9728&DeviceType=htcvision&AttachmentName=mail/TestFldr/8/2
|
|
|
|
//
|
|
|
|
- (NSString *) attachmentName
|
|
|
|
{
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [self _valueForParameter: @"ATTACHMENTNAME="];
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
s = @"Unknown";
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-13 16:18:20 +01:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
- (NSString *) command
|
|
|
|
{
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [self _valueForParameter: @"CMD="];
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
s = @"Unknown";
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2015-02-26 23:53:58 +01:00
|
|
|
- (NSString *) itemid
|
|
|
|
{
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [self _valueForParameter: @"ITEMID="];
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
s = @"Unknown";
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) collectionid
|
|
|
|
{
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [self _valueForParameter: @"COLLECTIONID="];
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
s = @"Unknown";
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2015-03-30 15:42:32 +02:00
|
|
|
- (BOOL) acceptsMultiPart
|
|
|
|
{
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [self _valueForParameter: @"OPTIONS="];
|
|
|
|
|
|
|
|
if (s && [s rangeOfString: @"AcceptMultiPart" options: NSCaseInsensitiveSearch].location != NSNotFound)
|
|
|
|
return YES;
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2015-02-26 23:53:58 +01:00
|
|
|
|
2014-02-03 16:24:33 +01:00
|
|
|
//
|
|
|
|
// FIXME: combine with our OpenChange code.
|
|
|
|
//
|
|
|
|
- (char) _decodeHexByte: (char) byteChar
|
|
|
|
{
|
|
|
|
char newByte;
|
|
|
|
|
|
|
|
if (byteChar >= 48 && byteChar <= 57)
|
|
|
|
newByte = (uint8_t) byteChar - 48;
|
|
|
|
else if (byteChar >= 65 && byteChar <= 70)
|
|
|
|
newByte = (uint8_t) byteChar - 55;
|
|
|
|
else if (byteChar >= 97 && byteChar <= 102)
|
|
|
|
newByte = (uint8_t) byteChar - 87;
|
|
|
|
else
|
|
|
|
newByte = -1;
|
|
|
|
|
|
|
|
return newByte;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FIXME: combine with our OpenChange code.
|
|
|
|
//
|
|
|
|
- (BOOL) _decodeHexByte: (uint8_t *) byte
|
|
|
|
atPos: (NSUInteger) pos
|
|
|
|
{
|
|
|
|
BOOL error = NO;
|
|
|
|
char newByte;
|
|
|
|
unichar byteChar;
|
|
|
|
|
|
|
|
byteChar = [self characterAtIndex: pos];
|
|
|
|
if (byteChar < 256)
|
|
|
|
{
|
|
|
|
newByte = [self _decodeHexByte: (char) byteChar];
|
|
|
|
if (newByte == -1)
|
|
|
|
error = YES;
|
|
|
|
else
|
|
|
|
*byte = newByte;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error = YES;
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FIXME: combine with our OpenChange code.
|
|
|
|
//
|
|
|
|
- (BOOL) _decodeHexPair: (uint8_t *) byte
|
|
|
|
atPos: (NSUInteger) pos
|
|
|
|
{
|
|
|
|
BOOL error;
|
|
|
|
uint8_t lowValue, highValue;
|
|
|
|
|
|
|
|
error = [self _decodeHexByte: &highValue atPos: pos];
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
error = [self _decodeHexByte: &lowValue atPos: pos + 1];
|
|
|
|
if (!error)
|
|
|
|
*byte = highValue << 4 | lowValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FIXME: combine with our OpenChange code.
|
|
|
|
//
|
|
|
|
- (NSData *) convertHexStringToBytes
|
|
|
|
{
|
|
|
|
NSUInteger count, strLen, bytesLen;
|
|
|
|
uint8_t *bytes, *currentByte;
|
|
|
|
NSData *decoded = nil;
|
|
|
|
BOOL error = NO;
|
|
|
|
|
|
|
|
strLen = [self length];
|
|
|
|
if ((strLen % 2) == 0)
|
|
|
|
{
|
|
|
|
bytesLen = strLen / 2;
|
|
|
|
bytes = NSZoneCalloc (NULL, bytesLen, sizeof (uint8_t));
|
|
|
|
currentByte = bytes;
|
|
|
|
for (count = 0; !error && count < strLen; count += 2)
|
|
|
|
{
|
|
|
|
error = [self _decodeHexPair: currentByte atPos: count];
|
|
|
|
currentByte++;
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
NSZoneFree (NULL, bytes);
|
|
|
|
else
|
|
|
|
decoded = [NSData dataWithBytesNoCopy: bytes
|
|
|
|
length: bytesLen
|
|
|
|
freeWhenDone: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
}
|
|
|
|
|
2014-01-10 20:12:53 +01:00
|
|
|
@end
|