From 946ad356a78e4666e636e4f328dad977283cc88e Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 13 Dec 2010 16:28:18 +0000 Subject: [PATCH] Monotone-Parent: 5b2308236e314d73f37013a208e925564c2b223e Monotone-Revision: c4fe19a1a6dc722f667408c4597a414722b94c7d Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-12-13T16:28:18 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 10 ++ OpenChange/SOGoMAPIFSFolder.h | 47 +++++++ OpenChange/SOGoMAPIFSFolder.m | 216 +++++++++++++++++++++++++++++++++ OpenChange/SOGoMAPIFSMessage.h | 39 ++++++ OpenChange/SOGoMAPIFSMessage.m | 99 +++++++++++++++ 5 files changed, 411 insertions(+) create mode 100644 OpenChange/SOGoMAPIFSFolder.h create mode 100644 OpenChange/SOGoMAPIFSFolder.m create mode 100644 OpenChange/SOGoMAPIFSMessage.h create mode 100644 OpenChange/SOGoMAPIFSMessage.m diff --git a/ChangeLog b/ChangeLog index 7b283c6e1..f976832ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-12-13 Wolfgang Sourdeau + + * OpenChange/SOGoMAPIFSFolder.[hm]: new class module that + implements a SOGoFolder subclass that stores and retrives data + to/and from the file system in the form of a plist. + + * OpenChange/SOGoMAPIFSMessage.[hm]: new class module that + implements a SOGoObject subclass that stores and retrives data + to/and from the file system in the form of a plist. + 2010-12-09 Ludovic Marcotte * SoObject/SOGo/SQLSource.m - added SHA password diff --git a/OpenChange/SOGoMAPIFSFolder.h b/OpenChange/SOGoMAPIFSFolder.h new file mode 100644 index 000000000..b59c558a5 --- /dev/null +++ b/OpenChange/SOGoMAPIFSFolder.h @@ -0,0 +1,47 @@ +/* SOGoMAPIFSFolder.h - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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 3, 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. + */ + +#ifndef SOGOMAPIFSFOLDER_H +#define SOGOMAPIFSFOLDER_H + +#import + +@class NSURL; + +@class SOGoMAPIFSMessage; + +@interface SOGoMAPIFSFolder : SOGoFolder +{ + NSString *directory; + BOOL directoryIsSane; +} + ++ (id) folderWithURL: (NSURL *) url; +- (id) initWithURL: (NSURL *) url; + +- (NSString *) directory; + +- (SOGoMAPIFSMessage *) newMessage; + +@end + +#endif /* SOGOMAPIFSFOLDER_H */ diff --git a/OpenChange/SOGoMAPIFSFolder.m b/OpenChange/SOGoMAPIFSFolder.m new file mode 100644 index 000000000..29156553a --- /dev/null +++ b/OpenChange/SOGoMAPIFSFolder.m @@ -0,0 +1,216 @@ +/* SOGoMAPIFSFolder.m - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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 3, 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 +#import +#import +#import +#import +#import + +#import + +#import "SOGoMAPIFSMessage.h" + +#import "SOGoMAPIFSFolder.h" + +#undef DEBUG +#include +#include +#include +#include + +static NSString *privateDir = nil; + +@implementation SOGoMAPIFSFolder + ++ (void) initialize +{ + struct loadparm_context *lpCtx; + const char *cPrivateDir; + + if (!privateDir) + { + lpCtx = loadparm_init_global (true); + cPrivateDir = lpcfg_private_dir (lpCtx); + privateDir = [NSString stringWithUTF8String: cPrivateDir]; + [privateDir retain]; + } +} + ++ (id) folderWithURL: (NSURL *) url +{ + SOGoMAPIFSFolder *newFolder; + + newFolder = [[self alloc] initWithURL: url]; + [newFolder autorelease]; + + return newFolder; +} + +- (id) init +{ + if ((self = [super init])) + { + directory = nil; + directoryIsSane = NO; + } + + return self; +} + +- (void) dealloc +{ + [directory release]; + [super dealloc]; +} + +- (id) initWithURL: (NSURL *) url +{ + NSString *path; + + if ((self = [self init])) + { + path = [url path]; + if (![path hasSuffix: @"/"]) + path = [NSString stringWithFormat: @"%@/", path]; + directory = [NSString stringWithFormat: @"%@/SOGo/%@/%@%@", + privateDir, [url user], [url host], path]; + [self logWithFormat: @"directory: %@", directory]; + [directory retain]; + ASSIGN (nameInContainer, [path stringByDeletingLastPathComponent]); + } + + return self; +} + +- (NSString *) directory +{ + return directory; +} + +- (SOGoMAPIFSMessage *) newMessage +{ + NSString *filename; + + filename = [NSString stringWithFormat: @"%@.plist", + [SOGoObject globallyUniqueObjectId]]; + + return [SOGoMAPIFSMessage objectWithName: filename inContainer: self]; +} + +- (void) _ensureDirectorySanity +{ + NSFileManager *fm; + NSDictionary *attributes; + BOOL isDir; + + fm = [NSFileManager defaultManager]; + if ([fm fileExistsAtPath: directory isDirectory: &isDir]) + { + if (!isDir) + [NSException raise: @"MAPIStoreIOException" + format: @"object at path '%@' is not a directory", + directory]; + } + else + { + attributes + = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: 0700] + forKey: NSFilePosixPermissions]; + [fm createDirectoryAtPath: directory + attributes: attributes]; + } + + directoryIsSane = YES; +} + +- (NSArray *) _objectsInDirectory: (BOOL) dirs +{ + NSFileManager *fm; + NSArray *contents; + NSMutableArray *files; + NSUInteger count, max; + NSString *file, *fullName; + BOOL isDir; + + if (!directoryIsSane) + [self _ensureDirectorySanity]; + + fm = [NSFileManager defaultManager]; + contents = [fm directoryContentsAtPath: directory]; + max = [contents count]; + files = [NSMutableArray arrayWithCapacity: max]; + for (count = 0; count < max; count++) + { + file = [contents objectAtIndex: count]; + fullName = [directory stringByAppendingPathComponent: file]; + if ([fm fileExistsAtPath: fullName + isDirectory: &isDir] + && dirs == isDir) + [files addObject: file]; + } + + return files; +} + +- (NSArray *) toManyRelationshipKeys +{ + return [self _objectsInDirectory: YES]; +} + +- (NSArray *) toOneRelationshipKeys +{ + return [self _objectsInDirectory: NO]; +} + +- (id) lookupName: (NSString *) fileName + inContext: (WOContext *) woContext + acquire: (BOOL) acquire +{ + NSFileManager *fm; + NSString *fullName; + id object; + BOOL isDir; + + if (!directoryIsSane) + [self _ensureDirectorySanity]; + + fm = [NSFileManager defaultManager]; + fullName = [directory stringByAppendingPathComponent: fileName]; + if ([fm fileExistsAtPath: fullName + isDirectory: &isDir]) + { + if (isDir) + object = [SOGoMAPIFSFolder objectWithName: fileName + inContainer: self]; + else + object = [SOGoMAPIFSMessage objectWithName: fileName + inContainer: self]; + } + else + object = nil; + + return object; +} + +@end diff --git a/OpenChange/SOGoMAPIFSMessage.h b/OpenChange/SOGoMAPIFSMessage.h new file mode 100644 index 000000000..04aaf0b75 --- /dev/null +++ b/OpenChange/SOGoMAPIFSMessage.h @@ -0,0 +1,39 @@ +/* SOGoMAPIFSMessage.h - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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 3, 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. + */ + +#ifndef SOGOMAPIFSMESSAGE_H +#define SOGOMAPIFSMESSAGE_H + +#import + +@class NSDictionary; + +@interface SOGoMAPIFSMessage : SOGoObject +{ + NSDictionary *properties; +} + +- (NSDictionary *) properties; + +@end + +#endif /* SOGOMAPIFSMESSAGE_H */ diff --git a/OpenChange/SOGoMAPIFSMessage.m b/OpenChange/SOGoMAPIFSMessage.m new file mode 100644 index 000000000..329475bed --- /dev/null +++ b/OpenChange/SOGoMAPIFSMessage.m @@ -0,0 +1,99 @@ +/* SOGoMAPIFSMessage.m - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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 3, 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 +#import +#import + +#import + +#import "SOGoMAPIFSFolder.h" + +#import "SOGoMAPIFSMessage.h" + +@implementation SOGoMAPIFSMessage + +- (id) init +{ + if ((self = [super init])) + { + properties = nil; + } + + return self; +} + +- (void) dealloc +{ + [properties release]; + [super dealloc]; +} + +- (NSDictionary *) properties +{ + NSString *filePath; + + if (!properties) + { + filePath = [[container directory] + stringByAppendingPathComponent: nameInContainer]; + properties = [[NSDictionary alloc] + initWithContentsOfFile: filePath]; + } + + return properties; +} + +- (void) setMAPIProperties: (NSDictionary *) newProperties +{ + ASSIGN (properties, newProperties); +} + +- (void) MAPISave +{ + NSString *filePath; + + [self logWithFormat: @"-MAPISave"]; + + filePath = [[container directory] + stringByAppendingPathComponent: nameInContainer]; + if (![properties writeToFile: filePath atomically: YES]) + [NSException raise: @"MAPIStoreIOException" + format: @"could not save message"]; +} + +- (NSString *) davEntityTag +{ + NSDictionary *attributes; + NSFileManager *fm; + NSString *filePath; + + fm = [NSFileManager defaultManager]; + + filePath = [[container directory] + stringByAppendingPathComponent: nameInContainer]; + attributes = [fm fileAttributesAtPath: filePath traverseLink: NO]; + + return [NSString stringWithFormat: @"%p", attributes]; +} + +@end