mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-20 02:45:25 +00:00
Monotone-Parent: 90fa2838afb37a071037bbb22e7b90cd8d61b44b
Monotone-Revision: 4c0fc5d33efdd8411e429def927e91bded7ff3d5 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-09-20T19:28:21 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
2011-09-20 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* OpenChange/NSData+MAPIStore.m (+dataWithXID: asXIDInMemCtx:):
|
||||
new method to handle XID structs.
|
||||
(-appendUInt8, -appendUInt32): new methods to easily append
|
||||
integer values.
|
||||
|
||||
2011-09-19 Ludovic Marcotte <lmarcotte@inverse.ca>
|
||||
|
||||
* OpenChange/MAPIStoreDraftsMessage.m: (_commitProperties)
|
||||
|
||||
@@ -39,6 +39,16 @@
|
||||
+ (id) dataWithGUID: (const struct GUID *) guid;
|
||||
- (struct GUID *) asGUIDInMemCtx: (void *) memCtx;
|
||||
|
||||
+ (id) dataWithXID: (const struct XID *) xid;
|
||||
- (struct XID *) asXIDInMemCtx: (void *) memCtx;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSMutableData (MAPIStoreDataTypes)
|
||||
|
||||
- (void) appendUInt8: (uint8_t) value;
|
||||
- (void) appendUInt32: (uint32_t) value;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* NSDATA_MAPISTORE_H */
|
||||
|
||||
@@ -82,39 +82,112 @@
|
||||
return flatUID;
|
||||
}
|
||||
|
||||
static void _fillFlatUIDWithGUID (struct FlatUID_r *flatUID, const struct GUID *guid)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
+ (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);
|
||||
_fillFlatUIDWithGUID (&flatUID, guid);
|
||||
|
||||
return [self dataWithFlatUID: &flatUID];
|
||||
}
|
||||
|
||||
- (void) _extractGUID: (struct GUID *) guid
|
||||
{
|
||||
uint8_t *bytes;
|
||||
|
||||
bytes = (uint8_t *) [self bytes];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
- (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);
|
||||
[self _extractGUID: guid];
|
||||
|
||||
return guid;
|
||||
}
|
||||
|
||||
+ (id) dataWithXID: (const struct XID *) xid
|
||||
{
|
||||
NSMutableData *xidData;
|
||||
struct FlatUID_r flatUID;
|
||||
|
||||
_fillFlatUIDWithGUID (&flatUID, &xid->GUID);
|
||||
|
||||
xidData = [NSMutableData dataWithCapacity: 16 + xid->Size];
|
||||
[xidData appendBytes: flatUID.ab length: 16];
|
||||
[xidData appendBytes: xid->Data length: xid->Size];
|
||||
|
||||
return xidData;
|
||||
}
|
||||
|
||||
- (struct XID *) asXIDInMemCtx: (void *) memCtx
|
||||
{
|
||||
struct XID *xid;
|
||||
NSUInteger max;
|
||||
|
||||
max = [self length];
|
||||
if (max > 16)
|
||||
{
|
||||
xid = talloc_zero (memCtx, struct XID);
|
||||
|
||||
[self _extractGUID: &xid->GUID];
|
||||
|
||||
xid->Size = max - 16;
|
||||
xid->Data = talloc_memdup (xid, [self bytes] + 16, xid->Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
xid = NULL;
|
||||
abort ();
|
||||
}
|
||||
|
||||
return xid;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSMutableData (MAPIStoreDataTypes)
|
||||
|
||||
- (void) appendUInt8: (uint8_t) value
|
||||
{
|
||||
[self appendBytes: (char *) &value length: 1];
|
||||
}
|
||||
|
||||
- (void) appendUInt32: (uint32_t) value
|
||||
{
|
||||
NSUInteger count;
|
||||
char bytes[4];
|
||||
|
||||
for (count = 0; count < 4; count++)
|
||||
{
|
||||
bytes[count] = value & 0xff;
|
||||
value >>= 8;
|
||||
}
|
||||
|
||||
[self appendBytes: bytes length: 4];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user