2011-02-15 00:44:47 +01:00
|
|
|
/* NSObject+MAPIStore.m - this file is part of SOGo
|
|
|
|
*
|
2012-08-17 21:04:57 +02:00
|
|
|
* Copyright (C) 2011-2012 Inverse inc
|
2011-02-15 00:44:47 +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
|
2011-08-12 17:02:01 +02:00
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
2011-02-15 00:44:47 +01:00
|
|
|
* 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 <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
2011-11-22 18:48:46 +01:00
|
|
|
#import "NSArray+MAPIStore.h"
|
2011-02-15 00:44:47 +01:00
|
|
|
#import "NSData+MAPIStore.h"
|
2011-05-30 23:12:56 +02:00
|
|
|
#import "NSDate+MAPIStore.h"
|
2011-02-15 00:44:47 +01:00
|
|
|
#import "NSValue+MAPIStore.h"
|
|
|
|
#import "NSString+MAPIStore.h"
|
|
|
|
|
|
|
|
#import "NSObject+MAPIStore.h"
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
2011-07-11 17:29:04 +02:00
|
|
|
@implementation NSObject (MAPIStoreTallocHelpers)
|
|
|
|
|
2012-03-20 19:46:05 +01:00
|
|
|
static int
|
|
|
|
MAPIStoreTallocWrapperDestroy (void *data)
|
2011-07-11 17:29:04 +02:00
|
|
|
{
|
2011-07-11 23:40:47 +02:00
|
|
|
struct MAPIStoreTallocWrapper *wrapper;
|
2011-07-13 23:38:14 +02:00
|
|
|
NSAutoreleasePool *pool;
|
2011-07-11 17:29:04 +02:00
|
|
|
|
2014-06-24 15:28:42 +02:00
|
|
|
// GSRegisterCurrentThread ();
|
2011-07-13 23:38:14 +02:00
|
|
|
pool = [NSAutoreleasePool new];
|
2011-07-11 23:40:47 +02:00
|
|
|
wrapper = data;
|
2013-03-13 20:04:11 +01:00
|
|
|
//NSLog (@"destroying wrapped object (wrapper: %p; object: %p (%@))...\n", wrapper, wrapper->instance, NSStringFromClass([wrapper->instance class]));
|
2012-06-30 09:30:44 +02:00
|
|
|
[wrapper->instance release];
|
2011-07-13 23:38:14 +02:00
|
|
|
[pool release];
|
2014-06-24 15:28:42 +02:00
|
|
|
// GSUnregisterCurrentThread ();
|
2011-07-11 17:29:04 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (struct MAPIStoreTallocWrapper *) tallocWrapper: (TALLOC_CTX *) tallocCtx
|
|
|
|
{
|
|
|
|
struct MAPIStoreTallocWrapper *wrapper;
|
|
|
|
|
|
|
|
wrapper = talloc_zero (tallocCtx, struct MAPIStoreTallocWrapper);
|
|
|
|
talloc_set_destructor ((void *) wrapper, MAPIStoreTallocWrapperDestroy);
|
2012-06-30 09:30:44 +02:00
|
|
|
wrapper->instance = self;
|
2012-03-20 19:46:05 +01:00
|
|
|
[self retain];
|
2013-03-13 20:04:11 +01:00
|
|
|
//NSLog (@"returning wrapper: %p; object: %p (%@)", wrapper, self, NSStringFromClass([self class]));
|
2011-07-11 17:29:04 +02:00
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2011-02-15 00:44:47 +01:00
|
|
|
@implementation NSObject (MAPIStoreDataTypes)
|
|
|
|
|
2011-11-22 18:48:46 +01:00
|
|
|
- (int) getValue: (void **) data
|
|
|
|
forTag: (enum MAPITAGS) propTag
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-02-15 00:44:47 +01:00
|
|
|
{
|
|
|
|
uint16_t valueType;
|
2011-07-15 21:29:30 +02:00
|
|
|
int rc = MAPISTORE_SUCCESS;
|
2011-02-15 00:44:47 +01:00
|
|
|
|
|
|
|
// [self logWithFormat: @"property %.8x found", propTag];
|
|
|
|
valueType = (propTag & 0xffff);
|
|
|
|
switch (valueType)
|
|
|
|
{
|
|
|
|
case PT_NULL:
|
|
|
|
*data = NULL;
|
|
|
|
break;
|
|
|
|
case PT_SHORT:
|
|
|
|
*data = [(NSNumber *) self asShortInMemCtx: memCtx];
|
|
|
|
break;
|
|
|
|
case PT_LONG:
|
|
|
|
*data = [(NSNumber *) self asLongInMemCtx: memCtx];
|
|
|
|
break;
|
2011-05-31 07:07:45 +02:00
|
|
|
case PT_I8:
|
|
|
|
*data = [(NSNumber *) self asI8InMemCtx: memCtx];
|
|
|
|
break;
|
2011-02-15 00:44:47 +01:00
|
|
|
case PT_BOOLEAN:
|
|
|
|
*data = [(NSNumber *) self asBooleanInMemCtx: memCtx];
|
|
|
|
break;
|
|
|
|
case PT_DOUBLE:
|
|
|
|
*data = [(NSNumber *) self asDoubleInMemCtx: memCtx];
|
|
|
|
break;
|
|
|
|
case PT_UNICODE:
|
|
|
|
case PT_STRING8:
|
|
|
|
*data = [(NSString *) self asUnicodeInMemCtx: memCtx];
|
|
|
|
break;
|
|
|
|
case PT_SYSTIME:
|
|
|
|
*data = [(NSCalendarDate * ) self asFileTimeInMemCtx: memCtx];
|
|
|
|
break;
|
|
|
|
case PT_BINARY:
|
2012-01-09 23:12:16 +01:00
|
|
|
case PT_SVREID:
|
2011-04-20 00:31:37 +02:00
|
|
|
*data = [(NSData *) self asBinaryInMemCtx: memCtx];
|
2011-02-15 00:44:47 +01:00
|
|
|
break;
|
|
|
|
case PT_CLSID:
|
|
|
|
*data = [(NSData *) self asGUIDInMemCtx: memCtx];
|
|
|
|
break;
|
2011-11-22 20:53:53 +01:00
|
|
|
case PT_MV_LONG:
|
|
|
|
*data = [(NSArray *) self asMVLongInMemCtx: memCtx];
|
|
|
|
break;
|
2011-11-22 18:48:46 +01:00
|
|
|
case PT_MV_UNICODE:
|
2011-11-22 20:43:14 +01:00
|
|
|
*data = [(NSArray *) self asMVUnicodeInMemCtx: memCtx];
|
2011-11-22 18:48:46 +01:00
|
|
|
break;
|
2011-11-22 20:43:46 +01:00
|
|
|
case PT_MV_BINARY:
|
|
|
|
*data = [(NSArray *) self asMVBinaryInMemCtx: memCtx];
|
|
|
|
break;
|
2011-11-22 18:48:46 +01:00
|
|
|
|
2011-02-15 00:44:47 +01:00
|
|
|
default:
|
|
|
|
[self errorWithFormat: @"object type not handled: %d (0x%.4x)",
|
|
|
|
valueType, valueType];
|
2011-11-22 18:48:46 +01:00
|
|
|
abort();
|
2011-02-15 00:44:47 +01:00
|
|
|
*data = NULL;
|
2011-07-15 21:29:30 +02:00
|
|
|
rc = MAPISTORE_ERR_NOT_FOUND;
|
2011-02-15 00:44:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2011-07-20 20:28:37 +02:00
|
|
|
/* helper getters */
|
|
|
|
- (int) getEmptyString: (void **) data inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
*data = [@"" asUnicodeInMemCtx: memCtx];
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getLongZero: (void **) data inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
*data = MAPILongValue (memCtx, 0);
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getYes: (void **) data inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
*data = MAPIBoolValue (memCtx, YES);
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getNo: (void **) data inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
*data = MAPIBoolValue (memCtx, NO);
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-07-20 17:26:15 +02:00
|
|
|
- (int) getSMTPAddrType: (void **) data inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
*data = [@"SMTP" asUnicodeInMemCtx: memCtx];
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-02-15 00:44:47 +01:00
|
|
|
@end
|
2012-07-19 21:06:46 +02:00
|
|
|
|
|
|
|
@implementation NSObject (MAPIStoreProperties)
|
|
|
|
|
|
|
|
+ (enum mapistore_error) getAvailableProperties: (struct SPropTagArray **) propertiesP
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
struct SPropTagArray *properties;
|
|
|
|
const MAPIStorePropertyGetter *classGetters;
|
|
|
|
NSUInteger count;
|
|
|
|
enum MAPITAGS propTag;
|
2012-10-10 14:42:44 +02:00
|
|
|
uint16_t propId;
|
2012-07-19 21:06:46 +02:00
|
|
|
|
|
|
|
properties = talloc_zero (memCtx, struct SPropTagArray);
|
|
|
|
properties->aulPropTag = talloc_array (properties, enum MAPITAGS,
|
|
|
|
MAPIStoreSupportedPropertiesCount);
|
|
|
|
classGetters = MAPIStorePropertyGettersForClass (self);
|
|
|
|
for (count = 0; count < MAPIStoreSupportedPropertiesCount; count++)
|
|
|
|
{
|
|
|
|
propTag = MAPIStoreSupportedProperties[count];
|
2012-10-10 14:42:44 +02:00
|
|
|
propId = (propTag >> 16) & 0xffff;
|
|
|
|
if (classGetters[propId])
|
2012-07-19 21:06:46 +02:00
|
|
|
{
|
|
|
|
properties->aulPropTag[properties->cValues] = propTag;
|
|
|
|
properties->cValues++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*propertiesP = properties;
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-07-20 16:36:05 +02:00
|
|
|
+ (void) fillAvailableProperties: (struct SPropTagArray *) properties
|
|
|
|
withExclusions: (BOOL *) exclusions
|
|
|
|
{
|
|
|
|
TALLOC_CTX *localMemCtx;
|
|
|
|
struct SPropTagArray *subProperties;
|
|
|
|
uint16_t propId;
|
|
|
|
NSUInteger count;
|
|
|
|
|
|
|
|
localMemCtx = talloc_zero (NULL, TALLOC_CTX);
|
|
|
|
[self getAvailableProperties: &subProperties inMemCtx: localMemCtx];
|
|
|
|
for (count = 0; count < subProperties->cValues; count++)
|
|
|
|
{
|
2012-10-10 14:42:44 +02:00
|
|
|
propId = (subProperties->aulPropTag[count] >> 16) & 0xffff;
|
2012-07-20 16:36:05 +02:00
|
|
|
if (!exclusions[propId])
|
|
|
|
{
|
|
|
|
properties->aulPropTag[properties->cValues]
|
|
|
|
= subProperties->aulPropTag[count];
|
|
|
|
properties->cValues++;
|
|
|
|
exclusions[propId] = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
talloc_free (localMemCtx);
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:06:46 +02:00
|
|
|
- (enum mapistore_error) getAvailableProperties: (struct SPropTagArray **) propertiesP
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
NSUInteger count;
|
|
|
|
struct SPropTagArray *availableProps;
|
|
|
|
enum MAPITAGS propTag;
|
|
|
|
|
|
|
|
availableProps = talloc_zero (memCtx, struct SPropTagArray);
|
|
|
|
availableProps->aulPropTag = talloc_array (availableProps, enum MAPITAGS,
|
|
|
|
MAPIStoreSupportedPropertiesCount);
|
|
|
|
for (count = 0; count < MAPIStoreSupportedPropertiesCount; count++)
|
|
|
|
{
|
|
|
|
propTag = MAPIStoreSupportedProperties[count];
|
|
|
|
if ([self canGetProperty: propTag])
|
|
|
|
{
|
|
|
|
availableProps->aulPropTag[availableProps->cValues] = propTag;
|
|
|
|
availableProps->cValues++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*propertiesP = availableProps;
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) canGetProperty: (enum MAPITAGS) propTag
|
|
|
|
{
|
2012-10-10 14:42:44 +02:00
|
|
|
uint16_t propId;
|
2012-07-19 21:06:46 +02:00
|
|
|
const IMP *classGetters;
|
|
|
|
|
|
|
|
classGetters = (IMP *) MAPIStorePropertyGettersForClass (isa);
|
2012-10-10 14:42:44 +02:00
|
|
|
propId = (propTag >> 16) & 0xffff;
|
2012-07-19 21:06:46 +02:00
|
|
|
|
2012-10-10 14:42:44 +02:00
|
|
|
return (classGetters[propId] != NULL);
|
2012-07-19 21:06:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|