Monotone-Parent: c852be1d5a70f9aa1ee5a5b4e45b30bd3ef86939

Monotone-Revision: 1ed44d9759e8a5f57b9c55905872081bf8fec785

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2011-06-03T23:53:30
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2011-06-03 23:53:30 +00:00
parent 8672091178
commit 3b0b350ff3
8 changed files with 80 additions and 77 deletions

View File

@@ -1,5 +1,12 @@
2011-06-03 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* OpenChange/MAPIStoreContext.m: MAPIStoreMapping instances are
now per-user instances rather than class singletons.
* OpenChange/MAPIStoreMapping.m: now makes use of the records
already present in indexing.tdb for building the initial mapping
dictionary.
* OpenChange/MAPIStoreSpoolerContext.[hm]: new context module,
which subclasses MAPIStoreSpoolerContext from
MAPIStoreFSBaseContext rather than MAPIStoreOutboxContext.

View File

@@ -23,6 +23,7 @@
#import <Foundation/NSData.h>
#import "MAPIStoreAttachment.h"
#import "MAPIStoreContext.h"
#import "MAPIStoreMapping.h"
#import "MAPIStoreMessage.h"
#import "MAPIStoreTypes.h"
@@ -33,15 +34,8 @@
#include <mapistore/mapistore.h>
#include <mapistore/mapistore_errors.h>
static MAPIStoreMapping *mapping;
@implementation MAPIStoreAttachment
+ (void) initialize
{
mapping = [MAPIStoreMapping sharedMapping];
}
- (void) setAID: (uint32_t) newAID
{
aid = newAID;
@@ -102,9 +96,12 @@ static MAPIStoreMapping *mapping;
andFlags: (enum OpenEmbeddedMessage_OpenModeFlags) flags
{
MAPIStoreAttachmentMessage *attMessage;
MAPIStoreMapping *mapping;
memset (mapistoreMsg, 0, sizeof (struct mapistore_message));
mapping = [[self context] mapping];
attMessage = [self openEmbeddedMessage];
if (attMessage)
*mid = [mapping idFromURL: [attMessage url]];

View File

@@ -53,6 +53,8 @@
NSURL *contextUrl;
uint64_t contextFid;
MAPIStoreMapping *mapping;
MAPIStoreAuthenticator *authenticator;
WOContext *woContext;
@@ -79,6 +81,7 @@
- (struct mapistore_connection_info *) connectionInfo;
- (WOContext *) woContext;
- (MAPIStoreMapping *) mapping;
- (void) setupRequest;
- (void) tearDownRequest;

View File

@@ -70,8 +70,8 @@
static Class NSDataK, NSStringK, MAPIStoreFAIMessageK;
static MAPIStoreMapping *mapping;
static NSMutableDictionary *contextClassMapping;
static NSMutableDictionary *userMAPIStoreMapping;
static void *ldbCtx = NULL;
@@ -86,8 +86,6 @@ static void *ldbCtx = NULL;
NSStringK = [NSString class];
MAPIStoreFAIMessageK = [MAPIStoreFAIMessage class];
mapping = [MAPIStoreMapping sharedMapping];
contextClassMapping = [NSMutableDictionary new];
classes = GSObjCAllSubclassesOfClass (self);
max = [classes count];
@@ -103,6 +101,8 @@ static void *ldbCtx = NULL;
NSStringFromClass (currentClass), moduleName);
}
}
userMAPIStoreMapping = [NSMutableDictionary new];
}
static inline MAPIStoreContext *
@@ -209,7 +209,7 @@ _prepareContextClass (struct mapistore_context *newMemCtx,
inMemCtx: (struct mapistore_context *) newMemCtx
{
struct loadparm_context *lpCtx;
MAPIStoreMapping *mapping;
NSString *username;
if ((self = [self init]))
{
@@ -221,7 +221,15 @@ _prepareContextClass (struct mapistore_context *newMemCtx,
ASSIGN (contextUrl, newUrl);
mapping = [MAPIStoreMapping sharedMapping];
username = [NSString stringWithUTF8String: newConnInfo->username];
mapping = [userMAPIStoreMapping objectForKey: username];
if (!mapping)
{
[self logWithFormat: @"generating mapping of ids for user '%@'",
username];
mapping = [MAPIStoreMapping mappingWithIndexing: newConnInfo->indexing];
[userMAPIStoreMapping setObject: mapping forKey: username];
}
if (![mapping urlFromID: newFid])
[mapping registerURL: [newUrl absoluteString]
withID: newFid];
@@ -254,6 +262,11 @@ _prepareContextClass (struct mapistore_context *newMemCtx,
return woContext;
}
- (MAPIStoreMapping *) mapping
{
return mapping;
}
- (void) setAuthenticator: (MAPIStoreAuthenticator *) newAuthenticator
{
ASSIGN (authenticator, newAuthenticator);
@@ -1332,8 +1345,6 @@ _prepareContextClass (struct mapistore_context *newMemCtx,
uint64_t mappingId;
uint32_t contextId;
mapping = [MAPIStoreMapping sharedMapping];
if (key)
childURL = [NSString stringWithFormat: @"%@%@", folderURL, key];
else

View File

@@ -23,7 +23,6 @@
#import <NGExtensions/NSObject+Logs.h>
#import "MAPIStoreFolder.h"
#import "MAPIStoreMapping.h"
#import "MAPIStoreTypes.h"
#import "MAPIStoreFolderTable.h"
@@ -35,13 +34,6 @@
@implementation MAPIStoreFolderTable
static MAPIStoreMapping *mapping;
+ (void) initialize
{
mapping = [MAPIStoreMapping sharedMapping];
}
- (id) init
{
if ((self = [super init]))

View File

@@ -32,9 +32,12 @@
{
NSMutableDictionary *mapping; /* FID/MID -> url */
NSMutableDictionary *reverseMapping; /* url -> FID/MID */
struct tdb_wrap *indexing;
}
+ (id) sharedMapping;
+ (id) mappingWithIndexing: (struct tdb_wrap *) indexing;
- (id) initWithIndexing: (struct tdb_wrap *) indexing;
- (NSString *) urlFromID: (uint64_t) idKey;

View File

@@ -28,22 +28,15 @@
#import <NGExtensions/NSObject+Logs.h>
#import "MAPIStoreTypes.h"
#import "MAPIStoreMapping.h"
#include <fcntl.h>
#include <tdb.h>
#include <talloc.h>
#include <tdb.h>
#include <tdb_wrap.h>
struct tdb_wrap {
struct tdb_context *tdb;
const char *name;
struct tdb_wrap *next, *prev;
};
extern struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx,
const char *name, int hash_size, int tdb_flags,
int open_flags, mode_t mode);
@implementation MAPIStoreMapping
static int
MAPIStoreMappingTDBTraverse (TDB_CONTEXT *ctx, TDB_DATA data1, TDB_DATA data2,
@@ -59,7 +52,7 @@ MAPIStoreMappingTDBTraverse (TDB_CONTEXT *ctx, TDB_DATA data1, TDB_DATA data2,
idVal = strtoll (idStr, NULL, 16);
idNbr = [NSNumber numberWithUnsignedLongLong: idVal];
uriStr = strdup ((const char *) data2.dptr);
uriStr = strndup ((const char *) data2.dptr, data2.dsize);
*(uriStr+(data2.dsize)) = 0;
uri = [NSString stringWithUTF8String: uriStr];
free (uriStr);
@@ -70,47 +63,39 @@ MAPIStoreMappingTDBTraverse (TDB_CONTEXT *ctx, TDB_DATA data1, TDB_DATA data2,
return 0;
}
static void
MAPIStoreMappingInitDictionary (NSMutableDictionary *mapping)
+ (id) mappingWithIndexing: (struct tdb_wrap *) indexing
{
struct tdb_wrap *wrap;
TDB_CONTEXT *context;
char *tdb_path;
id newMapping;
tdb_path = "/usr/local/samba/private/mapistore/openchange/indexing.tdb";
wrap = tdb_wrap_open(NULL, tdb_path, 0, TDB_NOLOCK, O_RDONLY, 0600);
if (wrap)
{
context = wrap->tdb;
tdb_traverse_read(wrap->tdb, MAPIStoreMappingTDBTraverse, mapping);
}
}
newMapping = [[self alloc] initWithIndexing: indexing];
[newMapping autorelease];
@implementation MAPIStoreMapping
+ (id) sharedMapping
{
static id sharedMapping = nil;
if (!sharedMapping)
sharedMapping = [self new];
return sharedMapping;
return newMapping;
}
- (id) init
{
if ((self = [super init]))
{
mapping = [NSMutableDictionary new];
reverseMapping = [NSMutableDictionary new];
indexing = NULL;
}
return self;
}
- (id) initWithIndexing: (struct tdb_wrap *) newIndexing
{
NSNumber *idNbr;
NSString *uri;
NSArray *keys;
NSUInteger count, max;
if ((self = [super init]))
if ((self = [self init]))
{
mapping = [NSMutableDictionary new];
MAPIStoreMappingInitDictionary (mapping);
reverseMapping = [NSMutableDictionary new];
indexing = newIndexing;
tdb_traverse_read (indexing->tdb, MAPIStoreMappingTDBTraverse, mapping);
keys = [mapping allKeys];
max = [keys count];
for (count = 0; count < max; count++)
@@ -144,7 +129,7 @@ MAPIStoreMappingInitDictionary (NSMutableDictionary *mapping)
{
NSNumber *idKey;
uint64_t idNbr;
idKey = [reverseMapping objectForKey: url];
if (idKey)
idNbr = [idKey unsignedLongLongValue];
@@ -159,13 +144,16 @@ MAPIStoreMappingInitDictionary (NSMutableDictionary *mapping)
{
NSNumber *idKey;
BOOL rc;
TDB_DATA key, dbuf;
idKey = [NSNumber numberWithUnsignedLongLong: idNbr];
if ([mapping objectForKey: idKey]
|| [reverseMapping objectForKey: urlString])
{
[self errorWithFormat: @"attempt to double register an entry ('%@', %lld)",
urlString, idNbr];
[self errorWithFormat:
@"attempt to double register an entry ('%@', %lld,"
@" 0x%.16"PRIx64")",
urlString, idNbr, idNbr];
rc = NO;
}
else
@@ -173,8 +161,18 @@ MAPIStoreMappingInitDictionary (NSMutableDictionary *mapping)
[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];
[self logWithFormat: @"registered url '%@' with id %lld (0x%.16"PRIx64")",
urlString, idNbr, idNbr];
/* Add the record given its fid and mapistore_uri */
key.dptr = (unsigned char *) talloc_asprintf(NULL, "0x%.16"PRIx64, idNbr);
key.dsize = strlen((const char *) key.dptr);
dbuf.dptr = (unsigned char *) talloc_strdup(NULL, [urlString UTF8String]);
dbuf.dsize = strlen((const char *) dbuf.dptr);
tdb_store (indexing->tdb, key, dbuf, TDB_INSERT);
talloc_free (key.dptr);
talloc_free (dbuf.dptr);
}
return rc;

View File

@@ -26,7 +26,6 @@
#import <SOGo/SOGoObject.h>
#import "MAPIStoreFolder.h"
#import "MAPIStoreMapping.h"
#import "MAPIStoreTypes.h"
#import "NSData+MAPIStore.h"
#import "NSString+MAPIStore.h"
@@ -35,13 +34,6 @@
@implementation MAPIStoreMessageTable
static MAPIStoreMapping *mapping;
+ (void) initialize
{
mapping = [MAPIStoreMapping sharedMapping];
}
- (void) setSortOrder: (const struct SSortOrderSet *) set
{
[self logWithFormat: @"unimplemented method: %@", NSStringFromSelector (_cmd)];