mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-04-16 10:48:50 +00:00
initial import of the SOGo OpenChange backend
Monotone-Parent: 5f57280bc0c8371b942a310b60e1dfa1a790fb84 Monotone-Revision: 3afb1a5821a35e93f30a0c82c6e0594ea2285efb Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-10-01T18:54:30 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
136
OpenChange/MAPIStoreMapping.m
Normal file
136
OpenChange/MAPIStoreMapping.m
Normal file
@@ -0,0 +1,136 @@
|
||||
/* MAPIStoreMapping.m - this file is part of $PROJECT_NAME_HERE$
|
||||
*
|
||||
* Copyright (C) 2010 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
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* 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 <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSValue.h>
|
||||
|
||||
#import <NGExtensions/NSObject+Logs.h>
|
||||
|
||||
#import "MAPIStoreMapping.h"
|
||||
|
||||
static const uint64_t idIncrement = 0x010000; /* we choose a high enough id to avoid any clash with system folders */
|
||||
static uint64_t idCounter = 0x200001;
|
||||
|
||||
@implementation MAPIStoreMapping
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
mapping = [NSMutableDictionary new];
|
||||
reverseMapping = [NSMutableDictionary new];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[mapping release];
|
||||
[reverseMapping release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString *) urlFromID: (uint64_t) idNbr
|
||||
{
|
||||
NSNumber *key;
|
||||
|
||||
key = [NSNumber numberWithUnsignedLongLong: idNbr];
|
||||
|
||||
return [mapping objectForKey: key];
|
||||
}
|
||||
|
||||
- (uint64_t) idFromURL: (NSString *) url
|
||||
{
|
||||
NSNumber *idKey;
|
||||
uint64_t idNbr;
|
||||
|
||||
idKey = [reverseMapping objectForKey: url];
|
||||
if (idKey)
|
||||
idNbr = [idKey unsignedLongLongValue];
|
||||
else
|
||||
idNbr = NSNotFound;
|
||||
|
||||
return idNbr;
|
||||
}
|
||||
|
||||
- (BOOL) registerURL: (NSString *) urlString
|
||||
withID: (uint64_t) idNbr
|
||||
{
|
||||
NSNumber *idKey;
|
||||
BOOL rc;
|
||||
|
||||
idKey = [NSNumber numberWithUnsignedLongLong: idNbr];
|
||||
if ([mapping objectForKey: idKey] || [reverseMapping objectForKey: urlString]) {
|
||||
[self errorWithFormat: @"attempt to double register an entry ('%@', %lld)",
|
||||
urlString, idNbr];
|
||||
rc = NO;
|
||||
}
|
||||
else {
|
||||
[mapping setObject: urlString forKey: idKey];
|
||||
[reverseMapping setObject: idKey forKey: urlString];
|
||||
rc = YES;
|
||||
[self logWithFormat: @"registered url '%@' with id %lld (0x%.8x)",
|
||||
urlString, idNbr, (uint32_t) idNbr];
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
- (void) registerURL: (NSString *) urlString
|
||||
{
|
||||
uint64_t idNbr;
|
||||
|
||||
// newID = openchangedb_get_new_folderID();
|
||||
if (![reverseMapping objectForKey: urlString]) {
|
||||
if ([urlString isEqualToString: @"sogo://openchange:openchange@mail/folderINBOX"]) {
|
||||
idNbr = 0x160001;
|
||||
if (![self registerURL: urlString withID: idNbr])
|
||||
[self errorWithFormat: @"Unable to register root folder: %@",
|
||||
urlString];
|
||||
}
|
||||
// else if ([urlString isEqualToString: @"sogo://openchange:openchange@mail/folderSent"]) {
|
||||
// idNbr = 0x140001;
|
||||
// idCounter = idNbr;
|
||||
// }
|
||||
else if ([urlString isEqualToString: @"sogo://openchange:openchange@contacts/personal"]) {
|
||||
idNbr = 0x1a0001;
|
||||
if (![self registerURL: urlString withID: idNbr])
|
||||
[self errorWithFormat: @"Unable to register root folder: %@",
|
||||
urlString];
|
||||
}
|
||||
else if ([urlString isEqualToString: @"sogo://openchange:openchange@calendar/personal"]) {
|
||||
idNbr = 0x190001;
|
||||
if (![self registerURL: urlString withID: idNbr])
|
||||
[self errorWithFormat: @"Unable to register root folder: %@",
|
||||
urlString];
|
||||
}
|
||||
else {
|
||||
idCounter += idIncrement;
|
||||
while (![self registerURL: urlString withID: idCounter])
|
||||
idCounter += idIncrement;
|
||||
}
|
||||
// [self _registerURL: urlString withID: newID];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user