2011-02-15 00:44:47 +01:00
|
|
|
/* NSObject+MAPIStore.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 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
|
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.
|
|
|
|
*/
|
|
|
|
|
2011-07-13 23:38:14 +02:00
|
|
|
#import <Foundation/NSAutoreleasePool.h>
|
2011-02-15 00:44:47 +01:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
2011-07-20 20:28:37 +02:00
|
|
|
#import "MAPIStoreTypes.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
|
|
|
|
#include <mapistore/mapistore.h>
|
2011-07-15 21:29:30 +02:00
|
|
|
#include <mapistore/mapistore_errors.h>
|
2011-02-15 00:44:47 +01:00
|
|
|
|
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
|
|
|
|
2011-07-13 23:38:14 +02:00
|
|
|
pool = [NSAutoreleasePool new];
|
2011-07-11 23:40:47 +02:00
|
|
|
wrapper = data;
|
2012-03-20 19:46:05 +01:00
|
|
|
// NSLog (@"destroying wrapped object (wrapper: %p; object: %p)...\n", wrapper, wrapper->MAPIStoreSOGoObject);
|
2011-07-11 23:40:47 +02:00
|
|
|
[wrapper->MAPIStoreSOGoObject release];
|
2011-07-13 23:38:14 +02:00
|
|
|
[pool release];
|
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-03-20 19:46:05 +01:00
|
|
|
wrapper->MAPIStoreSOGoObject = self;
|
|
|
|
[self retain];
|
|
|
|
// NSLog (@"returning wrapper: %p; object: %p", wrapper, self);
|
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;
|
|
|
|
}
|
|
|
|
|
2011-02-15 00:44:47 +01:00
|
|
|
@end
|