2011-02-24 21:27:55 +01:00
|
|
|
/* MAPIStoreObject.m - this file is part of SOGo
|
|
|
|
*
|
2012-08-17 21:04:57 +02:00
|
|
|
* Copyright (C) 2011-2012 Inverse inc
|
2011-02-24 21:27:55 +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-24 21:27:55 +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.
|
|
|
|
*/
|
|
|
|
|
2012-06-01 17:15:30 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
2012-03-30 21:58:16 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2011-02-24 21:27:55 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
#import <SOGo/SOGoObject.h>
|
2011-07-19 23:49:37 +02:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
2011-02-24 21:27:55 +01:00
|
|
|
|
2011-06-07 02:17:46 +02:00
|
|
|
#import "MAPIStoreContext.h"
|
2011-02-24 21:27:55 +01:00
|
|
|
#import "MAPIStoreFolder.h"
|
2011-04-13 21:59:04 +02:00
|
|
|
#import "MAPIStorePropertySelectors.h"
|
2011-02-24 21:27:55 +01:00
|
|
|
#import "MAPIStoreTypes.h"
|
2012-01-29 20:55:21 +01:00
|
|
|
#import "MAPIStoreUserContext.h"
|
2011-06-07 02:17:46 +02:00
|
|
|
#import "NSDate+MAPIStore.h"
|
2011-02-24 21:27:55 +01:00
|
|
|
#import "NSData+MAPIStore.h"
|
2011-07-20 20:28:37 +02:00
|
|
|
#import "NSObject+MAPIStore.h"
|
2011-02-24 21:27:55 +01:00
|
|
|
#import "NSString+MAPIStore.h"
|
|
|
|
|
|
|
|
#import "MAPIStoreObject.h"
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <talloc.h>
|
|
|
|
#include <gen_ndr/exchange.h>
|
|
|
|
#include <mapistore/mapistore.h>
|
|
|
|
#include <mapistore/mapistore_errors.h>
|
|
|
|
|
|
|
|
@implementation MAPIStoreObject
|
|
|
|
|
|
|
|
static Class NSExceptionK, MAPIStoreFolderK;
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
NSExceptionK = [NSExceptionK class];
|
|
|
|
MAPIStoreFolderK = [MAPIStoreFolder class];
|
|
|
|
}
|
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
+ (id) mapiStoreObjectInContainer: (MAPIStoreObject *) newContainer
|
2011-02-24 21:27:55 +01:00
|
|
|
{
|
|
|
|
id newObject;
|
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
newObject = [[self alloc] initInContainer: newContainer];
|
2011-02-24 21:27:55 +01:00
|
|
|
[newObject autorelease];
|
|
|
|
|
|
|
|
return newObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2011-04-13 21:59:04 +02:00
|
|
|
classGetters = (IMP *) MAPIStorePropertyGettersForClass (isa);
|
2011-02-24 21:27:55 +01:00
|
|
|
parentContainersBag = [NSMutableArray new];
|
|
|
|
container = nil;
|
2011-10-26 17:15:17 +02:00
|
|
|
properties = [NSMutableDictionary new];
|
2012-07-20 16:36:05 +02:00
|
|
|
proxies = [NSMutableArray new];
|
2011-02-24 21:27:55 +01:00
|
|
|
}
|
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
// [self logWithFormat: @"-init"];
|
2011-07-13 23:41:58 +02:00
|
|
|
|
2011-02-24 21:27:55 +01:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
- (id) initInContainer: (MAPIStoreObject *) newContainer
|
2011-02-24 21:27:55 +01:00
|
|
|
{
|
|
|
|
if ((self = [self init]))
|
|
|
|
{
|
|
|
|
ASSIGN (container, newContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2012-06-29 19:59:38 +02:00
|
|
|
// [self logWithFormat: @"-dealloc"];
|
2012-07-20 16:36:05 +02:00
|
|
|
[proxies release];
|
2011-10-26 17:15:17 +02:00
|
|
|
[properties release];
|
2011-02-24 21:27:55 +01:00
|
|
|
[parentContainersBag release];
|
|
|
|
[container release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (MAPIStoreObject *) container
|
|
|
|
{
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
- (MAPIStoreContext *) context
|
2011-02-24 21:27:55 +01:00
|
|
|
{
|
2012-06-29 19:59:38 +02:00
|
|
|
return (MAPIStoreContext *) [container context];
|
2011-02-24 21:27:55 +01:00
|
|
|
}
|
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
- (MAPIStoreUserContext *) userContext
|
|
|
|
{
|
|
|
|
return [[self context] userContext];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (MAPIStoreMapping *) mapping
|
|
|
|
{
|
|
|
|
return [[self userContext] mapping];
|
|
|
|
}
|
|
|
|
|
2012-07-19 22:31:15 +02:00
|
|
|
- (NSString *) url
|
|
|
|
{
|
2012-09-07 18:46:18 +02:00
|
|
|
NSString *containerURL, *urlName, *format;
|
2012-07-19 22:31:15 +02:00
|
|
|
|
|
|
|
containerURL = (NSString *) [container url];
|
|
|
|
if ([containerURL hasSuffix: @"/"])
|
|
|
|
format = @"%@%@";
|
|
|
|
else
|
|
|
|
format = @"%@/%@";
|
|
|
|
|
2012-09-07 18:46:18 +02:00
|
|
|
urlName = [[self nameInContainer]
|
|
|
|
stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
|
|
|
|
return [NSString stringWithFormat: format, containerURL, urlName];
|
2012-07-19 22:31:15 +02:00
|
|
|
}
|
|
|
|
|
2011-02-24 21:27:55 +01:00
|
|
|
/* helpers */
|
|
|
|
|
2011-10-26 17:15:17 +02:00
|
|
|
- (void) addProperties: (NSDictionary *) newNewProperties
|
2011-02-24 21:27:55 +01:00
|
|
|
{
|
2011-10-26 17:15:17 +02:00
|
|
|
[properties addEntriesFromDictionary: newNewProperties];
|
2011-02-24 21:27:55 +01:00
|
|
|
}
|
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
- (NSMutableDictionary *) properties
|
2011-02-24 21:27:55 +01:00
|
|
|
{
|
2011-10-26 17:15:17 +02:00
|
|
|
return properties;
|
2011-02-24 21:27:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getProperty: (void **) data
|
|
|
|
withTag: (enum MAPITAGS) propTag
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-02-24 21:27:55 +01:00
|
|
|
{
|
2011-04-13 21:59:04 +02:00
|
|
|
MAPIStorePropertyGetter method = NULL;
|
|
|
|
uint16_t propValue;
|
2011-04-20 00:24:03 +02:00
|
|
|
SEL methodSel;
|
2011-10-27 17:59:50 +02:00
|
|
|
id value;
|
2011-04-13 21:59:04 +02:00
|
|
|
int rc = MAPISTORE_ERR_NOT_FOUND;
|
2012-07-19 21:28:44 +02:00
|
|
|
NSUInteger count, max;
|
2011-04-20 00:24:03 +02:00
|
|
|
|
2011-10-27 17:59:50 +02:00
|
|
|
value = [properties objectForKey: MAPIPropertyKey (propTag)];
|
|
|
|
if (value)
|
2011-11-22 18:48:46 +01:00
|
|
|
rc = [value getValue: data forTag: propTag inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
else
|
2011-02-24 21:27:55 +01:00
|
|
|
{
|
2011-10-27 17:59:50 +02:00
|
|
|
propValue = (propTag & 0xffff0000) >> 16;
|
|
|
|
methodSel = MAPIStoreSelectorForPropertyGetter (propValue);
|
|
|
|
method = (MAPIStorePropertyGetter) classGetters[propValue];
|
|
|
|
if (method)
|
|
|
|
rc = method (self, methodSel, data, memCtx);
|
2011-02-24 21:27:55 +01:00
|
|
|
}
|
|
|
|
|
2012-07-19 21:28:44 +02:00
|
|
|
if (rc == MAPISTORE_ERR_NOT_FOUND)
|
|
|
|
{
|
|
|
|
max = [proxies count];
|
|
|
|
for (count = 0; rc == MAPISTORE_ERR_NOT_FOUND && count < max; count++)
|
|
|
|
rc = [[proxies objectAtIndex: count]
|
|
|
|
getProperty: data
|
|
|
|
withTag: propTag
|
|
|
|
inMemCtx: memCtx];
|
|
|
|
}
|
|
|
|
|
2011-02-24 21:27:55 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagCreationTime: (void **) data
|
2012-06-29 19:59:38 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-06-07 02:17:46 +02:00
|
|
|
{
|
|
|
|
*data = [[self creationTime] asFileTimeInMemCtx: memCtx];
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagLastModificationTime: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-06-07 02:17:46 +02:00
|
|
|
{
|
|
|
|
*data = [[self lastModificationTime] asFileTimeInMemCtx: memCtx];
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-10-27 17:59:50 +02:00
|
|
|
- (BOOL) canGetProperty: (enum MAPITAGS) propTag
|
|
|
|
{
|
|
|
|
uint16_t propValue;
|
2012-07-20 16:36:05 +02:00
|
|
|
BOOL canGetProperty;
|
|
|
|
NSUInteger count, max;
|
2011-10-27 17:59:50 +02:00
|
|
|
|
2012-10-10 14:42:44 +02:00
|
|
|
propValue = (propTag >> 16) & 0xffff;
|
2011-10-27 17:59:50 +02:00
|
|
|
|
2012-07-20 16:36:05 +02:00
|
|
|
canGetProperty = (classGetters[propValue]
|
|
|
|
|| [properties objectForKey: MAPIPropertyKey (propTag)]);
|
|
|
|
max = [proxies count];
|
|
|
|
for (count = 0; !canGetProperty && count < max; count++)
|
|
|
|
canGetProperty = [[proxies objectAtIndex: count] canGetProperty: propTag];
|
|
|
|
|
|
|
|
return canGetProperty;
|
2011-04-19 23:57:52 +02:00
|
|
|
}
|
|
|
|
|
2011-02-24 21:27:55 +01:00
|
|
|
- (int) getProperties: (struct mapistore_property_data *) data
|
|
|
|
withTags: (enum MAPITAGS *) tags
|
|
|
|
andCount: (uint16_t) columnCount
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-02-24 21:27:55 +01:00
|
|
|
{
|
|
|
|
uint16_t count;
|
|
|
|
|
|
|
|
for (count = 0; count < columnCount; count++)
|
|
|
|
data[count].error = [self getProperty: &data[count].data
|
2011-07-11 23:40:47 +02:00
|
|
|
withTag: tags[count]
|
|
|
|
inMemCtx: memCtx];
|
2011-02-24 21:27:55 +01:00
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:28:44 +02:00
|
|
|
- (void) addProxy: (MAPIStoreObjectProxy *) newProxy
|
|
|
|
{
|
|
|
|
[proxies addObject: newProxy];
|
|
|
|
}
|
|
|
|
|
2011-10-26 17:15:17 +02:00
|
|
|
- (int) addPropertiesFromRow: (struct SRow *) aRow
|
2011-02-24 21:27:55 +01:00
|
|
|
{
|
|
|
|
struct SPropValue *cValue;
|
|
|
|
NSUInteger counter;
|
2011-11-07 16:07:37 +01:00
|
|
|
NSMutableDictionary *newProperties;
|
2012-03-30 21:58:16 +02:00
|
|
|
id value;
|
|
|
|
|
2011-11-07 16:07:37 +01:00
|
|
|
newProperties = [NSMutableDictionary dictionaryWithCapacity: aRow->cValues];
|
2011-02-24 21:27:55 +01:00
|
|
|
for (counter = 0; counter < aRow->cValues; counter++)
|
|
|
|
{
|
|
|
|
cValue = aRow->lpProps + counter;
|
2012-03-30 21:58:16 +02:00
|
|
|
value = NSObjectFromSPropValue (cValue);
|
2014-12-29 19:20:16 +01:00
|
|
|
if (value == nil)
|
|
|
|
continue;
|
|
|
|
|
2012-03-30 21:58:16 +02:00
|
|
|
switch (cValue->ulPropTag & 0xffff)
|
|
|
|
{
|
|
|
|
case PT_STRING8:
|
|
|
|
case PT_MV_STRING8:
|
|
|
|
[self warnWithFormat:
|
|
|
|
@"attempting to set string property as PR_STRING8: %.8x",
|
|
|
|
cValue->ulPropTag];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
[newProperties setObject: value
|
2011-11-07 16:07:37 +01:00
|
|
|
forKey: MAPIPropertyKey (cValue->ulPropTag)];
|
2011-02-24 21:27:55 +01:00
|
|
|
}
|
|
|
|
|
2011-11-07 16:07:37 +01:00
|
|
|
[self addProperties: newProperties];
|
|
|
|
|
2011-02-24 21:27:55 +01:00
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-09-18 20:03:07 +02:00
|
|
|
//
|
|
|
|
// The GlobCnt is 6 bytes long.
|
|
|
|
//
|
2012-06-29 19:59:38 +02:00
|
|
|
- (NSData *) getReplicaKeyFromGlobCnt: (uint64_t) objectCnt
|
|
|
|
{
|
|
|
|
struct mapistore_connection_info *connInfo;
|
|
|
|
NSMutableData *replicaKey;
|
|
|
|
char buffer[6];
|
|
|
|
NSUInteger count;
|
|
|
|
|
|
|
|
connInfo = [[self context] connectionInfo];
|
|
|
|
|
|
|
|
for (count = 0; count < 6; count++)
|
|
|
|
{
|
|
|
|
buffer[count] = objectCnt & 0xff;
|
|
|
|
objectCnt >>= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
replicaKey = [NSMutableData dataWithCapacity: 22];
|
|
|
|
[replicaKey appendBytes: &connInfo->replica_guid
|
|
|
|
length: sizeof (struct GUID)];
|
|
|
|
[replicaKey appendBytes: buffer length: 6];
|
|
|
|
|
|
|
|
return replicaKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getReplicaKey: (void **) data
|
|
|
|
fromGlobCnt: (uint64_t) objectCnt
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
*data = [[self getReplicaKeyFromGlobCnt: objectCnt] asBinaryInMemCtx: memCtx];
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-08-15 03:02:08 +02:00
|
|
|
/* move and copy operations */
|
2012-12-03 15:18:17 +01:00
|
|
|
- (void) copyPropertiesToObject: (MAPIStoreObject *) newObject inMemCtx: (TALLOC_CTX *) memCtx
|
2012-08-15 03:02:08 +02:00
|
|
|
{
|
2012-12-03 15:18:17 +01:00
|
|
|
//TALLOC_CTX *memCtx;
|
2012-08-15 03:02:08 +02:00
|
|
|
struct SPropTagArray *availableProps;
|
|
|
|
struct SRow row;
|
|
|
|
enum MAPITAGS propTag;
|
|
|
|
bool *exclusions;
|
|
|
|
NSUInteger count;
|
|
|
|
enum mapistore_error error;
|
|
|
|
void *data;
|
|
|
|
|
2012-12-03 15:18:17 +01:00
|
|
|
//memCtx = talloc_zero (NULL, TALLOC_CTX);
|
2012-08-15 03:02:08 +02:00
|
|
|
|
|
|
|
[self getAvailableProperties: &availableProps inMemCtx: memCtx];
|
|
|
|
|
|
|
|
/* We exclude identity and versioning properties to facilitate copy
|
|
|
|
operations. If they need to be set (move operations), the caller will need
|
|
|
|
to take care of them. */
|
|
|
|
exclusions = talloc_array (memCtx, bool, 65536);
|
2012-10-10 14:42:44 +02:00
|
|
|
exclusions[(PidTagRowType >> 16) & 0xffff] = true;
|
|
|
|
exclusions[(PidTagInstanceKey >> 16) & 0xffff] = true;
|
|
|
|
exclusions[(PidTagInstanceNum >> 16) & 0xffff] = true;
|
|
|
|
exclusions[(PidTagInstID >> 16) & 0xffff] = true;
|
|
|
|
exclusions[(PidTagAttachNumber >> 16) & 0xffff] = true;
|
|
|
|
exclusions[(PidTagFolderId >> 16) & 0xffff] = true;
|
|
|
|
exclusions[(PidTagMid >> 16) & 0xffff] = true;
|
|
|
|
exclusions[(PidTagSourceKey >> 16) & 0xffff] = true;
|
|
|
|
exclusions[(PidTagParentSourceKey >> 16) & 0xffff] = true;
|
|
|
|
exclusions[(PidTagParentFolderId >> 16) & 0xffff] = true;
|
|
|
|
exclusions[(PidTagChangeKey >> 16) & 0xffff] = true;
|
|
|
|
exclusions[(PidTagChangeNumber >> 16) & 0xffff] = true;
|
|
|
|
exclusions[(PidTagPredecessorChangeList >> 16) & 0xffff] = true;
|
2012-08-15 03:02:08 +02:00
|
|
|
|
|
|
|
row.cValues = 0;
|
|
|
|
row.lpProps = talloc_array (memCtx, struct SPropValue, 65535);
|
|
|
|
|
|
|
|
for (count = 0; count < availableProps->cValues; count++)
|
|
|
|
{
|
|
|
|
propTag = availableProps->aulPropTag[count];
|
2012-10-10 14:42:44 +02:00
|
|
|
if (!exclusions[(propTag >> 16) & 0xffff])
|
2012-08-15 03:02:08 +02:00
|
|
|
{
|
|
|
|
error = [self getProperty: &data withTag: propTag inMemCtx: memCtx];
|
|
|
|
if (error == MAPISTORE_SUCCESS && data)
|
|
|
|
{
|
2012-10-10 14:42:44 +02:00
|
|
|
set_SPropValue_proptag (row.lpProps + row.cValues, propTag,
|
|
|
|
data);
|
2012-08-15 03:02:08 +02:00
|
|
|
row.cValues++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[newObject addPropertiesFromRow: &row];
|
|
|
|
|
2012-12-03 15:18:17 +01:00
|
|
|
//talloc_free (memCtx);
|
2012-08-15 03:02:08 +02:00
|
|
|
}
|
|
|
|
|
2011-02-24 21:27:55 +01:00
|
|
|
/* subclasses */
|
2012-07-19 22:31:15 +02:00
|
|
|
- (NSString *) nameInContainer
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2011-06-07 02:17:46 +02:00
|
|
|
- (NSDate *) creationTime
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) lastModificationTime
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2011-07-28 02:47:02 +02:00
|
|
|
/* logging */
|
|
|
|
- (NSString *) loggingPrefix
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:@"<%@:%p:%@>",
|
2011-10-27 17:59:50 +02:00
|
|
|
NSStringFromClass (isa), self, [self nameInContainer]];
|
2011-07-28 02:47:02 +02:00
|
|
|
}
|
|
|
|
|
2011-02-24 21:27:55 +01:00
|
|
|
@end
|