2011-02-24 21:30:01 +01:00
|
|
|
/* MAPIStoreGCSMessage.m - this file is part of SOGo
|
2011-02-07 18:49:47 +01:00
|
|
|
*
|
|
|
|
* 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-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>
|
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>
|
2011-06-07 02:17:46 +02:00
|
|
|
#import <SOGo/SOGoContentObject.h>
|
2011-12-01 23:36:16 +01:00
|
|
|
#import <SOGo/SOGoPermissions.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];
|
|
|
|
}
|
|
|
|
|
2011-12-01 23:36:16 +01:00
|
|
|
- (int) getPrAccess: (void **) data // TODO
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPrAccessLevel: (void **) data // TODO
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-09-20 21:38:23 +02:00
|
|
|
- (int) getPrChangeKey: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
2011-09-20 21:38:23 +02:00
|
|
|
if (!changeKey)
|
|
|
|
abort ();
|
|
|
|
*data = [changeKey asBinaryInMemCtx: memCtx];
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPrPredecessorChangeList: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
int rc = MAPISTORE_SUCCESS;
|
|
|
|
NSData *changeList;
|
|
|
|
|
|
|
|
if (isNew)
|
|
|
|
rc = MAPISTORE_ERR_NOT_FOUND;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
changeList = [(MAPIStoreGCSFolder *)[self container]
|
|
|
|
predecessorChangeListForMessageWithKey: [self nameInContainer]];
|
|
|
|
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;
|
2011-07-28 02:55:50 +02:00
|
|
|
NSNumber *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;
|
|
|
|
}
|
|
|
|
|
2011-02-07 18:49:47 +01:00
|
|
|
@end
|