2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo 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 Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-06-29 23:56:21 +02:00
|
|
|
#import <Foundation/NSDebug.h>
|
|
|
|
#import <Foundation/NSData.h>
|
2008-06-13 22:01:10 +02:00
|
|
|
#import <Foundation/NSDate.h>
|
2007-06-29 23:56:21 +02:00
|
|
|
#import <Foundation/NSProcessInfo.h>
|
|
|
|
#import <Foundation/NSRunLoop.h>
|
|
|
|
#import <Foundation/NSURL.h>
|
|
|
|
#import <Foundation/NSUserDefaults.h>
|
|
|
|
|
|
|
|
#import <GDLAccess/EOAdaptorChannel.h>
|
|
|
|
#import <GDLContentStore/GCSChannelManager.h>
|
|
|
|
|
|
|
|
#import <NGObjWeb/SoApplication.h>
|
|
|
|
#import <NGObjWeb/SoClassSecurityInfo.h>
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
|
|
|
|
#import <NGExtensions/NGBundleManager.h>
|
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
#import <NGExtensions/NSProcessInfo+misc.h>
|
2007-11-04 23:31:50 +01:00
|
|
|
#import <NGExtensions/NSString+Encoding.h>
|
2008-05-03 01:14:26 +02:00
|
|
|
#import <NGExtensions/NSString+misc.h>
|
2007-06-29 23:56:21 +02:00
|
|
|
|
|
|
|
#import <WEExtensions/WEResourceManager.h>
|
|
|
|
|
2008-01-16 19:57:58 +01:00
|
|
|
#import <SoObjects/SOGo/SOGoCache.h>
|
2007-09-04 17:41:14 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoDAVAuthenticator.h>
|
|
|
|
#import <SoObjects/SOGo/SOGoPermissions.h>
|
2007-06-29 23:56:21 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUserFolder.h>
|
2007-07-04 22:07:52 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2007-09-04 17:41:14 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoWebAuthenticator.h>
|
2007-11-08 20:56:18 +01:00
|
|
|
#import <SoObjects/SOGo/WORequest+SOGo.h>
|
2007-06-29 23:56:21 +02:00
|
|
|
|
2007-08-08 16:55:27 +02:00
|
|
|
#import "build.h"
|
2007-06-29 23:56:21 +02:00
|
|
|
#import "SOGoProductLoader.h"
|
2007-12-03 15:13:10 +01:00
|
|
|
#import "NSException+Stacktrace.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@interface SOGo : SoApplication
|
|
|
|
{
|
2007-06-29 23:56:21 +02:00
|
|
|
NSMutableDictionary *localeLUT;
|
2008-01-16 19:57:58 +01:00
|
|
|
SOGoCache *cache;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (NSDictionary *) currentLocaleConsideringLanguages:(NSArray *)_langs;
|
|
|
|
- (NSDictionary *) localeForLanguageNamed:(NSString *)_name;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGo
|
|
|
|
|
|
|
|
static unsigned int vMemSizeLimit = 0;
|
|
|
|
static BOOL doCrashOnSessionCreate = NO;
|
2007-06-29 23:56:21 +02:00
|
|
|
static BOOL hasCheckedTables = NO;
|
2008-06-13 22:01:10 +02:00
|
|
|
static BOOL debugRequests = NO;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
#ifdef GNUSTEP_BASE_LIBRARY
|
|
|
|
static BOOL debugObjectAllocation = NO;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
2006-12-14 22:20:13 +01:00
|
|
|
SoClassSecurityInfo *sInfo;
|
|
|
|
NSArray *basicRoles;
|
2006-06-15 21:34:10 +02:00
|
|
|
id tmp;
|
2007-08-08 16:55:27 +02:00
|
|
|
|
|
|
|
NSLog (@"starting SOGo (build %@)", SOGoBuildDate);
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
doCrashOnSessionCreate = [ud boolForKey:@"SOGoCrashOnSessionCreate"];
|
2007-04-16 19:36:56 +02:00
|
|
|
#ifdef GNUSTEP_BASE_LIBRARY
|
|
|
|
debugObjectAllocation = [ud boolForKey: @"SOGoDebugObjectAllocation"];
|
|
|
|
if (debugObjectAllocation)
|
|
|
|
{
|
|
|
|
NSLog (@"activating stats on object allocation");
|
|
|
|
GSDebugAllocationActive (YES);
|
|
|
|
}
|
|
|
|
#endif
|
2008-06-13 22:01:10 +02:00
|
|
|
debugRequests = [ud boolForKey: @"SOGoDebugRequests"];
|
2006-06-15 21:34:10 +02:00
|
|
|
/* vMem size check - default is 200MB */
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
tmp = [ud objectForKey: @"SxVMemLimit"];
|
|
|
|
vMemSizeLimit = ((tmp != nil) ? [tmp intValue] : 200);
|
|
|
|
if (vMemSizeLimit > 0)
|
2006-06-15 21:34:10 +02:00
|
|
|
NSLog(@"Note: vmem size check enabled: shutting down app when "
|
|
|
|
@"vmem > %d MB", vMemSizeLimit);
|
|
|
|
#if LIB_FOUNDATION_LIBRARY
|
|
|
|
if ([ud boolForKey:@"SOGoEnableDoubleReleaseCheck"])
|
2007-04-16 19:36:56 +02:00
|
|
|
[NSAutoreleasePool enableDoubleReleaseCheck: YES];
|
2006-06-15 21:34:10 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* SoClass security declarations */
|
2006-12-14 22:20:13 +01:00
|
|
|
sInfo = [self soClassSecurityInfo];
|
2006-06-15 21:34:10 +02:00
|
|
|
/* require View permission to access the root (bound to authenticated ...) */
|
2007-09-07 00:11:59 +02:00
|
|
|
// [sInfo declareObjectProtected: SoPerm_View];
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* to allow public access to all contained objects (subkeys) */
|
2006-12-14 22:20:13 +01:00
|
|
|
[sInfo setDefaultAccess: @"allow"];
|
|
|
|
|
|
|
|
basicRoles = [NSArray arrayWithObjects: SoRole_Authenticated,
|
|
|
|
SOGoRole_FreeBusy, nil];
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* require Authenticated role for View and WebDAV */
|
2006-12-14 22:20:13 +01:00
|
|
|
[sInfo declareRoles: basicRoles asDefaultForPermission: SoPerm_View];
|
|
|
|
[sInfo declareRoles: basicRoles asDefaultForPermission: SoPerm_WebDAVAccess];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
WOResourceManager *rm;
|
|
|
|
|
|
|
|
/* ensure core SoClass'es are setup */
|
|
|
|
[$(@"SOGoObject") soClass];
|
|
|
|
[$(@"SOGoContentObject") soClass];
|
|
|
|
[$(@"SOGoFolder") soClass];
|
|
|
|
|
|
|
|
/* setup locale cache */
|
|
|
|
localeLUT = [[NSMutableDictionary alloc] initWithCapacity:2];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
/* load products */
|
|
|
|
[[SOGoProductLoader productLoader] loadProducts];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
/* setup resource manager */
|
|
|
|
rm = [[WEResourceManager alloc] init];
|
|
|
|
[self setResourceManager:rm];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[localeLUT release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-12-07 21:34:29 +01:00
|
|
|
- (NSString *) _sqlScriptFromTableFile: (NSString *) fileName
|
|
|
|
withTableName: (NSString *) tableName
|
2007-06-29 23:56:21 +02:00
|
|
|
{
|
2007-12-07 21:34:29 +01:00
|
|
|
NSString *script;
|
|
|
|
|
|
|
|
|
|
|
|
return script;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _sqlScriptForTable: (NSString *) tableName
|
|
|
|
withType: (NSString *) tableType
|
|
|
|
andFileSuffix: (NSString *) fileSuffix
|
|
|
|
{
|
|
|
|
NSString *tableFile, *descFile;
|
2007-06-29 23:56:21 +02:00
|
|
|
NGBundleManager *bm;
|
|
|
|
NSBundle *bundle;
|
|
|
|
unsigned int length;
|
|
|
|
|
|
|
|
bm = [NGBundleManager defaultBundleManager];
|
2007-08-13 23:27:20 +02:00
|
|
|
|
2007-12-07 21:34:29 +01:00
|
|
|
bundle = [bm bundleWithName: @"MainUI" type: @"SOGo"];
|
|
|
|
length = [tableType length] - 3;
|
|
|
|
tableFile = [tableType substringToIndex: length];
|
|
|
|
descFile
|
|
|
|
= [bundle pathForResource: [NSString stringWithFormat: @"%@-%@",
|
|
|
|
tableFile, fileSuffix]
|
|
|
|
ofType: @"sql"];
|
|
|
|
if (!descFile)
|
|
|
|
descFile = [bundle pathForResource: tableFile ofType: @"sql"];
|
|
|
|
|
|
|
|
return [[NSString stringWithContentsOfFile: descFile]
|
|
|
|
stringByReplacingString: @"@{tableName}"
|
|
|
|
withString: tableName];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _checkTableWithCM: (GCSChannelManager *) cm
|
|
|
|
tableURL: (NSString *) url
|
|
|
|
andType: (NSString *) tableType
|
|
|
|
{
|
|
|
|
NSString *tableName, *fileSuffix, *tableScript;
|
|
|
|
EOAdaptorChannel *tc;
|
|
|
|
NSURL *channelURL;
|
|
|
|
|
2007-08-13 23:27:20 +02:00
|
|
|
channelURL = [NSURL URLWithString: url];
|
|
|
|
fileSuffix = [channelURL scheme];
|
|
|
|
tc = [cm acquireOpenChannelForURL: channelURL];
|
2007-06-29 23:56:21 +02:00
|
|
|
|
|
|
|
tableName = [url lastPathComponent];
|
|
|
|
if ([tc evaluateExpressionX:
|
2007-12-07 21:34:29 +01:00
|
|
|
[NSString stringWithFormat: @"SELECT count(*) FROM %@",
|
|
|
|
tableName]])
|
2007-06-29 23:56:21 +02:00
|
|
|
{
|
2007-12-07 21:34:29 +01:00
|
|
|
tableScript = [self _sqlScriptForTable: tableName
|
|
|
|
withType: tableType
|
|
|
|
andFileSuffix: fileSuffix];
|
|
|
|
if (![tc evaluateExpressionX: tableScript])
|
2007-06-29 23:56:21 +02:00
|
|
|
[self logWithFormat: @"table '%@' successfully created!", tableName];
|
|
|
|
}
|
2007-07-03 16:17:31 +02:00
|
|
|
else
|
|
|
|
[tc cancelFetch];
|
2007-06-29 23:56:21 +02:00
|
|
|
|
|
|
|
[cm releaseChannel: tc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) _checkMandatoryTables
|
|
|
|
{
|
|
|
|
GCSChannelManager *cm;
|
|
|
|
NSString *urlStrings[] = {@"AgenorProfileURL", @"OCSFolderInfoURL", nil};
|
|
|
|
NSString **urlString;
|
|
|
|
NSString *value;
|
|
|
|
NSUserDefaults *ud;
|
|
|
|
BOOL ok;
|
|
|
|
|
|
|
|
ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
ok = YES;
|
|
|
|
cm = [GCSChannelManager defaultChannelManager];
|
|
|
|
|
|
|
|
urlString = urlStrings;
|
|
|
|
while (ok && *urlString)
|
|
|
|
{
|
|
|
|
value = [ud stringForKey: *urlString];
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
[self _checkTableWithCM: cm tableURL: value andType: *urlString];
|
|
|
|
urlString++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSLog (@"No value specified for '%@'", *urlString);
|
|
|
|
ok = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) run
|
|
|
|
{
|
|
|
|
if (!hasCheckedTables)
|
|
|
|
{
|
|
|
|
hasCheckedTables = YES;
|
|
|
|
[self _checkMandatoryTables];
|
|
|
|
}
|
|
|
|
[super run];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* authenticator */
|
|
|
|
|
2007-09-05 00:02:29 +02:00
|
|
|
- (id) authenticatorInContext: (WOContext *) context
|
2007-04-16 19:36:56 +02:00
|
|
|
{
|
2007-09-04 17:41:14 +02:00
|
|
|
id authenticator;
|
|
|
|
|
2007-11-08 20:56:18 +01:00
|
|
|
if ([[context request] handledByDefaultHandler])
|
2007-09-04 17:41:14 +02:00
|
|
|
authenticator = [SOGoWebAuthenticator sharedSOGoWebAuthenticator];
|
2007-11-08 20:56:18 +01:00
|
|
|
else
|
|
|
|
authenticator = [SOGoDAVAuthenticator sharedSOGoDAVAuthenticator];
|
2007-09-04 17:41:14 +02:00
|
|
|
|
|
|
|
return authenticator;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* name lookup */
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (BOOL) isUserName: (NSString *) _key
|
|
|
|
inContext: (id) _ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
if ([_key length] < 1)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-07-04 22:07:52 +02:00
|
|
|
- (id) lookupUser: (NSString *) _key
|
|
|
|
inContext: (id)_ctx
|
|
|
|
{
|
|
|
|
SOGoUser *user;
|
|
|
|
id userFolder;
|
|
|
|
|
|
|
|
user = [SOGoUser userWithLogin: _key roles: nil];
|
|
|
|
if (user)
|
|
|
|
userFolder = [$(@"SOGoUserFolder") objectWithName: _key
|
|
|
|
inContainer: self];
|
|
|
|
else
|
|
|
|
userFolder = nil;
|
|
|
|
|
|
|
|
return userFolder;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (void) _setupLocaleInContext: (WOContext *) _ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSArray *langs;
|
|
|
|
NSDictionary *locale;
|
|
|
|
|
|
|
|
if ([[_ctx valueForKey:@"locale"] isNotNull])
|
|
|
|
return;
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
langs = [[_ctx request] browserLanguages];
|
2006-06-15 21:34:10 +02:00
|
|
|
locale = [self currentLocaleConsideringLanguages:langs];
|
|
|
|
[_ctx takeValue:locale forKey:@"locale"];
|
|
|
|
}
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (id) lookupName: (NSString *) _key
|
|
|
|
inContext: (id) _ctx
|
|
|
|
acquire: (BOOL) _flag
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
id obj;
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
#ifdef GNUSTEP_BASE_LIBRARY
|
|
|
|
if (debugObjectAllocation)
|
|
|
|
NSLog(@"objects allocated\n%s", GSDebugAllocationList (YES));
|
|
|
|
#endif
|
2006-06-15 21:34:10 +02:00
|
|
|
/* put locale info into the context in case it's not there */
|
|
|
|
[self _setupLocaleInContext:_ctx];
|
|
|
|
|
|
|
|
/* first check attributes directly bound to the application */
|
|
|
|
if ((obj = [super lookupName:_key inContext:_ctx acquire:_flag]))
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
/*
|
|
|
|
The problem is, that at this point we still get request for resources,
|
|
|
|
eg 'favicon.ico'.
|
|
|
|
|
|
|
|
Addition: we also get queries for various other methods, like "GET" if
|
|
|
|
no method was provided in the query path.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ([_key isEqualToString:@"favicon.ico"])
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
if ([self isUserName:_key inContext:_ctx])
|
|
|
|
return [self lookupUser:_key inContext:_ctx];
|
2007-07-04 22:07:52 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* WebDAV */
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (NSString *) davDisplayName
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* this is used in the UI, eg in the navigation */
|
|
|
|
return @"SOGo";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exception handling */
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (WOResponse *) handleException: (NSException *) _exc
|
|
|
|
inContext: (WOContext *) _ctx
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
|
|
|
printf("EXCEPTION: %s\n", [[_exc description] cString]);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* runtime maintenance */
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (void) checkIfDaemonHasToBeShutdown
|
|
|
|
{
|
|
|
|
unsigned int vmem;
|
|
|
|
|
|
|
|
if (vMemSizeLimit > 0)
|
|
|
|
{
|
|
|
|
vmem = [[NSProcessInfo processInfo] virtualMemorySize]/1048576;
|
|
|
|
|
|
|
|
if (vmem > vMemSizeLimit)
|
|
|
|
{
|
|
|
|
[self logWithFormat:
|
|
|
|
@"terminating app, vMem size limit (%d MB) has been reached"
|
|
|
|
@" (currently %d MB)",
|
|
|
|
vMemSizeLimit, vmem];
|
|
|
|
// if (debugObjectAllocation)
|
|
|
|
// [self _dumpClassAllocation];
|
|
|
|
[self terminate];
|
|
|
|
}
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (WOResponse *) dispatchRequest: (WORequest *) _request
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
static NSArray *runLoopModes = nil;
|
|
|
|
WOResponse *resp;
|
2008-06-13 22:01:10 +02:00
|
|
|
NSDate *startDate, *endDate;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-13 22:01:10 +02:00
|
|
|
if (debugRequests)
|
|
|
|
{
|
|
|
|
[self logWithFormat: @"starting method '%@' on uri '%@'",
|
|
|
|
[_request method], [_request uri]];
|
|
|
|
startDate = [NSDate date];
|
|
|
|
}
|
2008-06-19 20:26:33 +02:00
|
|
|
|
|
|
|
// sleep (1);
|
2008-01-16 19:57:58 +01:00
|
|
|
cache = [SOGoCache sharedCache];
|
2007-04-16 19:36:56 +02:00
|
|
|
resp = [super dispatchRequest: _request];
|
2008-01-16 19:57:58 +01:00
|
|
|
[SOGoCache killCache];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-13 22:01:10 +02:00
|
|
|
if (debugRequests)
|
|
|
|
{
|
|
|
|
endDate = [NSDate date];
|
|
|
|
[self logWithFormat: @"request took %f seconds to execute",
|
|
|
|
[endDate timeIntervalSinceDate: startDate]];
|
|
|
|
}
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
if (![self isTerminating])
|
|
|
|
{
|
|
|
|
if (!runLoopModes)
|
|
|
|
runLoopModes = [[NSArray alloc] initWithObjects: NSDefaultRunLoopMode, nil];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
// TODO: a bit complicated? (-perform:afterDelay: doesn't work?)
|
|
|
|
[[NSRunLoop currentRunLoop] performSelector:
|
|
|
|
@selector (checkIfDaemonHasToBeShutdown)
|
|
|
|
target: self argument: nil
|
|
|
|
order:1 modes:runLoopModes];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* session management */
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (id) createSessionForRequest: (WORequest *) _request
|
|
|
|
{
|
|
|
|
[self warnWithFormat: @"session creation requested!"];
|
2006-06-15 21:34:10 +02:00
|
|
|
if (doCrashOnSessionCreate)
|
|
|
|
abort();
|
|
|
|
return [super createSessionForRequest:_request];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* localization */
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (NSDictionary *) currentLocaleConsideringLanguages: (NSArray *) langs
|
|
|
|
{
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
NSString *lname;
|
|
|
|
NSDictionary *locale;
|
|
|
|
|
|
|
|
enumerator = [langs objectEnumerator];
|
|
|
|
lname = nil;
|
|
|
|
locale = nil;
|
|
|
|
lname = [enumerator nextObject];
|
|
|
|
while (lname && !locale)
|
|
|
|
{
|
|
|
|
locale = [self localeForLanguageNamed: lname];
|
|
|
|
lname = [enumerator nextObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!locale)
|
|
|
|
locale = [self localeForLanguageNamed: @"English"];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* no appropriate language, fallback to default */
|
2007-04-16 19:36:56 +02:00
|
|
|
return locale;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (NSString *) pathToLocaleForLanguageNamed: (NSString *) _name
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
static Class MainProduct = Nil;
|
|
|
|
NSString *lpath;
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
lpath = [[self resourceManager] pathForResourceNamed: @"Locale"
|
|
|
|
inFramework: nil
|
|
|
|
languages: [NSArray arrayWithObject:_name]];
|
|
|
|
if (![lpath length])
|
|
|
|
{
|
|
|
|
if (!MainProduct)
|
|
|
|
{
|
|
|
|
MainProduct = $(@"MainUIProduct");
|
|
|
|
if (!MainProduct)
|
|
|
|
[self errorWithFormat: @"did not find MainUIProduct class!"];
|
|
|
|
}
|
|
|
|
|
|
|
|
lpath = [(id) MainProduct pathToLocaleForLanguageNamed: _name];
|
|
|
|
if (![lpath length])
|
|
|
|
lpath = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lpath;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (NSDictionary *) localeForLanguageNamed: (NSString *) _name
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *lpath;
|
|
|
|
id data;
|
|
|
|
NSDictionary *locale;
|
2007-04-16 19:36:56 +02:00
|
|
|
|
|
|
|
locale = nil;
|
|
|
|
if ([_name length] > 0)
|
|
|
|
{
|
|
|
|
locale = [localeLUT objectForKey: _name];
|
|
|
|
if (!locale)
|
|
|
|
{
|
|
|
|
lpath = [self pathToLocaleForLanguageNamed:_name];
|
|
|
|
if (lpath)
|
|
|
|
{
|
|
|
|
data = [NSData dataWithContentsOfFile: lpath];
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
data = [[[NSString alloc] initWithData: data
|
|
|
|
encoding: NSUTF8StringEncoding] autorelease];
|
|
|
|
locale = [data propertyList];
|
|
|
|
if (locale)
|
|
|
|
[localeLUT setObject: locale forKey: _name];
|
|
|
|
else
|
|
|
|
[self logWithFormat:@"%s couldn't load locale with name:%@",
|
|
|
|
__PRETTY_FUNCTION__,
|
|
|
|
_name];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[self logWithFormat:@"%s didn't find locale with name: %@",
|
|
|
|
__PRETTY_FUNCTION__,
|
|
|
|
_name];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[self errorWithFormat:@"did not find Locale for language: %@", _name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2006-06-15 21:34:10 +02:00
|
|
|
[self errorWithFormat:@"%s: name parameter must not be nil!",
|
2007-04-16 19:36:56 +02:00
|
|
|
__PRETTY_FUNCTION__];
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return locale;
|
|
|
|
}
|
|
|
|
|
2008-05-03 01:14:26 +02:00
|
|
|
- (NSURL *) _urlPreferringParticle: (NSString *) expected
|
|
|
|
overThisOne: (NSString *) possible
|
|
|
|
{
|
|
|
|
NSURL *serverURL, *url;
|
|
|
|
NSMutableArray *path;
|
|
|
|
NSString *baseURL, *urlMethod;
|
|
|
|
WOContext *context;
|
|
|
|
|
|
|
|
context = [self context];
|
|
|
|
serverURL = [context serverURL];
|
|
|
|
baseURL = [[self baseURLInContext: context] stringByUnescapingURL];
|
|
|
|
path = [NSMutableArray arrayWithArray: [baseURL componentsSeparatedByString:
|
|
|
|
@"/"]];
|
|
|
|
if ([baseURL hasPrefix: @"http"])
|
|
|
|
{
|
|
|
|
[path removeObjectAtIndex: 1];
|
|
|
|
[path removeObjectAtIndex: 0];
|
|
|
|
[path replaceObjectAtIndex: 0 withObject: @""];
|
|
|
|
}
|
|
|
|
urlMethod = [path objectAtIndex: 2];
|
|
|
|
if (![urlMethod isEqualToString: expected])
|
|
|
|
{
|
|
|
|
if ([urlMethod isEqualToString: possible])
|
|
|
|
[path replaceObjectAtIndex: 2 withObject: expected];
|
|
|
|
else
|
|
|
|
[path insertObject: expected atIndex: 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
url = [[NSURL alloc] initWithScheme: [serverURL scheme]
|
|
|
|
host: [serverURL host]
|
|
|
|
path: [path componentsJoinedByString: @"/"]];
|
|
|
|
[url autorelease];
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSURL *) davURL
|
|
|
|
{
|
|
|
|
return [self _urlPreferringParticle: @"dav" overThisOne: @"so"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSURL *) soURL
|
|
|
|
{
|
|
|
|
return [self _urlPreferringParticle: @"so" overThisOne: @"dav"];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* name (used by the WEResourceManager) */
|
|
|
|
|
2007-04-16 19:36:56 +02:00
|
|
|
- (NSString *) name
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return @"SOGo-0.9";
|
|
|
|
}
|
|
|
|
|
|
|
|
@end /* SOGo */
|