4e60090b52
Monotone-Revision: f097a1cc5cb254dca09ba971f32de7339f109a97 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-12-30T14:47:27 Monotone-Branch: ca.inverse.sogo
121 lines
3.3 KiB
Objective-C
121 lines
3.3 KiB
Objective-C
/* NSData+MAPIStore.m - this file is part of SOGo
|
|
*
|
|
* Copyright (C) 2010 Inverse inc.
|
|
*
|
|
* 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 3, 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.
|
|
*/
|
|
|
|
#import "NSData+MAPIStore.h"
|
|
|
|
#undef DEBUG
|
|
#include <stdbool.h>
|
|
#include <gen_ndr/exchange.h>
|
|
#include <talloc.h>
|
|
|
|
@implementation NSData (MAPIStoreDataTypes)
|
|
|
|
+ (id) dataWithBinary: (const struct Binary_r *) binData
|
|
{
|
|
return [NSData dataWithBytes: binData->lpb length: binData->cb];
|
|
}
|
|
|
|
- (struct Binary_r *) asBinaryInMemCtx: (void *) memCtx
|
|
{
|
|
struct Binary_r *binary;
|
|
uint8_t *lpb;
|
|
|
|
binary = talloc_zero (memCtx, struct Binary_r);
|
|
binary->cb = [self length];
|
|
lpb = talloc_array (binary, uint8_t, binary->cb);
|
|
[self getBytes: lpb];
|
|
binary->lpb = lpb;
|
|
|
|
return binary;
|
|
}
|
|
|
|
+ (id) dataWithShortBinary: (const struct SBinary_short *) binData
|
|
{
|
|
return [NSData dataWithBytes: binData->lpb length: binData->cb];
|
|
}
|
|
|
|
- (struct SBinary_short *) asShortBinaryInMemCtx: (void *) memCtx
|
|
{
|
|
struct SBinary_short *binary;
|
|
uint8_t *lpb;
|
|
|
|
binary = talloc_zero (memCtx, struct SBinary_short);
|
|
binary->cb = [self length];
|
|
lpb = talloc_array (binary, uint8_t, binary->cb);
|
|
[self getBytes: lpb];
|
|
binary->lpb = lpb;
|
|
|
|
return binary;
|
|
}
|
|
|
|
+ (id) dataWithFlatUID: (const struct FlatUID_r *) flatUID
|
|
{
|
|
return [NSData dataWithBytes: flatUID->ab length: 16];
|
|
}
|
|
|
|
- (struct FlatUID_r *) asFlatUIDInMemCtx: (void *) memCtx
|
|
{
|
|
struct FlatUID_r *flatUID;
|
|
|
|
flatUID = talloc_zero (memCtx, struct FlatUID_r);
|
|
[self getBytes: flatUID->ab];
|
|
|
|
return flatUID;
|
|
}
|
|
|
|
+ (id) dataWithGUID: (const struct GUID *) guid
|
|
{
|
|
struct FlatUID_r flatUID;
|
|
|
|
flatUID.ab[0] = (guid->time_low & 0xFF);
|
|
flatUID.ab[1] = ((guid->time_low >> 8) & 0xFF);
|
|
flatUID.ab[2] = ((guid->time_low >> 16) & 0xFF);
|
|
flatUID.ab[3] = ((guid->time_low >> 24) & 0xFF);
|
|
flatUID.ab[4] = (guid->time_mid & 0xFF);
|
|
flatUID.ab[5] = ((guid->time_mid >> 8) & 0xFF);
|
|
flatUID.ab[6] = (guid->time_hi_and_version & 0xFF);
|
|
flatUID.ab[7] = ((guid->time_hi_and_version >> 8) & 0xFF);
|
|
memcpy (flatUID.ab + 8, guid->clock_seq, sizeof (uint8_t) * 2);
|
|
memcpy (flatUID.ab + 10, guid->node, sizeof (uint8_t) * 6);
|
|
|
|
return [self dataWithFlatUID: &flatUID];
|
|
}
|
|
|
|
- (struct GUID *) asGUIDInMemCtx: (void *) memCtx
|
|
{
|
|
struct GUID *guid;
|
|
uint8_t bytes[16];
|
|
|
|
[self getBytes: bytes];
|
|
|
|
guid = talloc_zero (memCtx, struct GUID);
|
|
guid->time_low = (bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0]);
|
|
guid->time_mid = (bytes[5] << 8 | bytes[4]);
|
|
guid->time_hi_and_version = (bytes[7] << 8 | bytes[6]);
|
|
memcpy (guid->clock_seq, bytes + 8, sizeof (uint8_t) * 2);
|
|
memcpy (guid->node, bytes + 10, sizeof (uint8_t) * 6);
|
|
|
|
return guid;
|
|
}
|
|
|
|
@end
|