2011-02-24 21:30:01 +01:00
|
|
|
/* MAPIStoreGCSMessage.m - this file is part of SOGo
|
2011-02-07 18:49:47 +01:00
|
|
|
*
|
2012-08-17 21:04:57 +02:00
|
|
|
* Copyright (C) 2011-2012 Inverse inc
|
2011-02-07 18:49: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-07 18:49: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-10-14 21:42:16 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2012-03-16 22:05:41 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2011-07-28 02:55:50 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2011-12-01 23:36:16 +01:00
|
|
|
#import <NGObjWeb/SoSecurityManager.h>
|
2011-08-12 20:40:07 +02:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2012-10-13 15:59:13 +02:00
|
|
|
#import <NGExtensions/NSObject+Values.h>
|
2011-06-07 02:17:46 +02:00
|
|
|
#import <SOGo/SOGoContentObject.h>
|
2011-12-01 23:36:16 +01:00
|
|
|
#import <SOGo/SOGoPermissions.h>
|
2012-06-01 17:15:30 +02:00
|
|
|
#import <SOGo/SOGoUser.h>
|
2011-06-07 02:17:46 +02:00
|
|
|
|
2011-09-14 20:33:44 +02:00
|
|
|
#import "MAPIStoreContext.h"
|
2011-07-28 02:55:50 +02:00
|
|
|
#import "MAPIStoreGCSFolder.h"
|
2011-06-07 02:17:46 +02:00
|
|
|
#import "MAPIStoreTypes.h"
|
2012-01-29 20:55:21 +01:00
|
|
|
#import "MAPIStoreUserContext.h"
|
2011-09-20 21:38:23 +02:00
|
|
|
#import "NSData+MAPIStore.h"
|
2011-06-07 02:17:46 +02:00
|
|
|
|
2011-02-24 21:30:01 +01:00
|
|
|
#import "MAPIStoreGCSMessage.h"
|
2011-02-07 18:49:47 +01:00
|
|
|
|
2011-06-07 02:17:46 +02:00
|
|
|
#undef DEBUG
|
|
|
|
#include <mapistore/mapistore.h>
|
2011-09-20 21:38:23 +02:00
|
|
|
#include <mapistore/mapistore_errors.h>
|
2011-06-07 02:17:46 +02:00
|
|
|
|
2011-02-24 21:30:01 +01:00
|
|
|
@implementation MAPIStoreGCSMessage
|
2011-02-07 18:49:47 +01:00
|
|
|
|
2011-10-14 21:42:16 +02:00
|
|
|
- (NSDate *) creationTime
|
2011-06-07 02:17:46 +02:00
|
|
|
{
|
|
|
|
return [sogoObject creationDate];
|
|
|
|
}
|
|
|
|
|
2011-10-14 21:42:16 +02:00
|
|
|
- (NSDate *) lastModificationTime
|
2011-06-07 02:17:46 +02:00
|
|
|
{
|
|
|
|
return [sogoObject lastModified];
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagAccess: (void **) data // TODO
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-12-01 23:36:16 +01:00
|
|
|
{
|
|
|
|
MAPIStoreContext *context;
|
|
|
|
WOContext *woContext;
|
|
|
|
SoSecurityManager *sm;
|
2012-01-29 20:55:21 +01:00
|
|
|
MAPIStoreUserContext *userContext;
|
2011-12-01 23:36:16 +01:00
|
|
|
uint32_t access;
|
|
|
|
|
|
|
|
context = [self context];
|
2012-01-29 20:55:21 +01:00
|
|
|
userContext = [self userContext];
|
|
|
|
if ([[context activeUser] isEqual: [userContext sogoUser]])
|
2011-12-01 23:36:16 +01:00
|
|
|
access = 0x03;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sm = [SoSecurityManager sharedSecurityManager];
|
2012-01-29 20:55:21 +01:00
|
|
|
woContext = [userContext woContext];
|
2011-12-01 23:36:16 +01:00
|
|
|
|
|
|
|
access = 0;
|
|
|
|
if (![sm validatePermission: SoPerm_ChangeImagesAndFiles
|
|
|
|
onObject: sogoObject
|
|
|
|
inContext: woContext])
|
|
|
|
access |= 1;
|
|
|
|
if (![sm validatePermission: SoPerm_AccessContentsInformation
|
|
|
|
onObject: sogoObject
|
|
|
|
inContext: woContext])
|
|
|
|
access |= 2;
|
|
|
|
if (![sm validatePermission: SOGoPerm_DeleteObject
|
|
|
|
onObject: sogoObject
|
|
|
|
inContext: woContext])
|
|
|
|
access |= 4;
|
|
|
|
}
|
|
|
|
*data = MAPILongValue (memCtx, access);
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagAccessLevel: (void **) data // TODO
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-12-01 23:36:16 +01:00
|
|
|
{
|
|
|
|
MAPIStoreContext *context;
|
2012-01-29 20:55:21 +01:00
|
|
|
MAPIStoreUserContext *userContext;
|
2011-12-01 23:36:16 +01:00
|
|
|
WOContext *woContext;
|
|
|
|
SoSecurityManager *sm;
|
|
|
|
uint32_t accessLvl;
|
|
|
|
|
|
|
|
context = [self context];
|
2012-01-29 20:55:21 +01:00
|
|
|
userContext = [self userContext];
|
|
|
|
if ([[context activeUser] isEqual: [userContext sogoUser]])
|
2011-12-01 23:36:16 +01:00
|
|
|
accessLvl = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sm = [SoSecurityManager sharedSecurityManager];
|
2012-01-29 20:55:21 +01:00
|
|
|
woContext = [userContext woContext];
|
2011-12-01 23:36:16 +01:00
|
|
|
if (![sm validatePermission: SoPerm_ChangeImagesAndFiles
|
|
|
|
onObject: sogoObject
|
|
|
|
inContext: woContext])
|
|
|
|
accessLvl = 1;
|
|
|
|
else
|
|
|
|
accessLvl = 0;
|
|
|
|
}
|
|
|
|
*data = MAPILongValue (memCtx, accessLvl);
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagChangeKey: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-09-20 21:38:23 +02:00
|
|
|
{
|
|
|
|
int rc = MAPISTORE_SUCCESS;
|
|
|
|
NSData *changeKey;
|
2011-09-23 21:27:21 +02:00
|
|
|
MAPIStoreGCSFolder *parentFolder;
|
|
|
|
NSString *nameInContainer;
|
2011-09-20 21:38:23 +02:00
|
|
|
|
|
|
|
if (isNew)
|
|
|
|
rc = MAPISTORE_ERR_NOT_FOUND;
|
|
|
|
else
|
|
|
|
{
|
2011-09-23 21:27:21 +02:00
|
|
|
parentFolder = (MAPIStoreGCSFolder *)[self container];
|
|
|
|
nameInContainer = [self nameInContainer];
|
|
|
|
changeKey = [parentFolder changeKeyForMessageWithKey: nameInContainer];
|
|
|
|
if (!changeKey)
|
|
|
|
{
|
|
|
|
[parentFolder synchroniseCache];
|
|
|
|
changeKey = [parentFolder changeKeyForMessageWithKey: nameInContainer];
|
|
|
|
}
|
2015-11-16 13:56:04 +01:00
|
|
|
if (changeKey)
|
|
|
|
*data = [changeKey asBinaryInMemCtx: memCtx];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self warnWithFormat: @"No change key for %@ in folder %@",
|
|
|
|
nameInContainer,
|
|
|
|
[parentFolder url]
|
|
|
|
];
|
|
|
|
rc = MAPISTORE_ERR_NOT_FOUND;
|
|
|
|
}
|
2011-09-20 21:38:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagPredecessorChangeList: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-09-20 21:38:23 +02:00
|
|
|
{
|
|
|
|
int rc = MAPISTORE_SUCCESS;
|
|
|
|
NSData *changeList;
|
2012-03-12 06:56:32 +01:00
|
|
|
MAPIStoreGCSFolder *parentFolder;
|
2011-09-20 21:38:23 +02:00
|
|
|
|
|
|
|
if (isNew)
|
|
|
|
rc = MAPISTORE_ERR_NOT_FOUND;
|
|
|
|
else
|
|
|
|
{
|
2012-03-12 06:56:32 +01:00
|
|
|
parentFolder = (MAPIStoreGCSFolder *)[self container];
|
|
|
|
changeList = [parentFolder
|
|
|
|
predecessorChangeListForMessageWithKey: [self nameInContainer]];
|
|
|
|
if (!changeList)
|
|
|
|
{
|
|
|
|
[parentFolder synchroniseCache];
|
|
|
|
changeList = [parentFolder
|
|
|
|
predecessorChangeListForMessageWithKey: [self nameInContainer]];
|
|
|
|
}
|
2011-09-20 21:38:23 +02:00
|
|
|
if (!changeList)
|
|
|
|
abort ();
|
|
|
|
*data = [changeList asBinaryInMemCtx: memCtx];
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2011-07-28 02:55:50 +02:00
|
|
|
- (uint64_t) objectVersion
|
|
|
|
{
|
2011-10-07 20:30:15 +02:00
|
|
|
uint64_t version = ULLONG_MAX;
|
2012-10-13 15:59:13 +02:00
|
|
|
NSString *changeNumber;
|
2011-09-14 20:33:44 +02:00
|
|
|
|
2011-09-20 21:38:23 +02:00
|
|
|
if (!isNew)
|
2011-08-12 20:40:07 +02:00
|
|
|
{
|
|
|
|
changeNumber = [(MAPIStoreGCSFolder *) container
|
|
|
|
changeNumberForMessageWithKey: [self nameInContainer]];
|
|
|
|
if (!changeNumber)
|
|
|
|
{
|
|
|
|
[self warnWithFormat: @"attempting to get change number"
|
|
|
|
@" by synchronising folder..."];
|
|
|
|
[(MAPIStoreGCSFolder *) container synchroniseCache];
|
|
|
|
changeNumber = [(MAPIStoreGCSFolder *) container
|
|
|
|
changeNumberForMessageWithKey: [self nameInContainer]];
|
|
|
|
|
|
|
|
if (changeNumber)
|
|
|
|
[self logWithFormat: @"got one"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self errorWithFormat: @"still nothing. We crash!"];
|
2011-09-14 20:33:44 +02:00
|
|
|
abort();
|
2011-08-12 20:40:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
version = [changeNumber unsignedLongLongValue] >> 16;
|
|
|
|
}
|
2011-07-28 02:55:50 +02:00
|
|
|
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
2012-03-16 22:05:41 +01:00
|
|
|
- (void) updateVersions
|
|
|
|
{
|
2015-07-20 11:17:00 +02:00
|
|
|
/* Update ChangeKey and PredecessorChangeList on message's save */
|
|
|
|
NSData *newChangeKey, *predecessorChangeList;
|
2012-03-16 22:05:41 +01:00
|
|
|
|
|
|
|
newChangeKey = [properties objectForKey: MAPIPropertyKey (PR_CHANGE_KEY)];
|
2015-07-20 11:17:00 +02:00
|
|
|
predecessorChangeList = [properties objectForKey: MAPIPropertyKey (PR_PREDECESSOR_CHANGE_LIST)];
|
2012-03-16 22:05:41 +01:00
|
|
|
|
|
|
|
[(MAPIStoreGCSFolder *) container
|
2015-07-20 11:17:00 +02:00
|
|
|
updateVersionsForMessageWithKey: [self nameInContainer]
|
|
|
|
withChangeKey: newChangeKey
|
|
|
|
andPredecessorChangeList: predecessorChangeList];
|
2012-03-16 22:05:41 +01:00
|
|
|
}
|
|
|
|
|
2011-02-07 18:49:47 +01:00
|
|
|
@end
|