From 048828752e92dcc048538448dbb0cf4e490a50b9 Mon Sep 17 00:00:00 2001 From: helge Date: Thu, 10 Feb 2005 13:53:05 +0000 Subject: [PATCH] some work on making sogod a daemon git-svn-id: http://svn.opengroupware.org/SOGo/trunk@538 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/Main/ChangeLog | 5 + SOGo/Main/GNUmakefile | 21 ++- SOGo/Main/MainUIProduct.m | 31 ++++ SOGo/Main/README | 10 +- SOGo/Main/SOGo.m | 265 +++++++++++++++++++++++++++++++ SOGo/Main/Version | 4 +- SOGo/Main/sogod.m | 248 +---------------------------- SOGo/UI/Common/CommonUIProduct.m | 7 +- SOGo/UI/Common/GNUmakefile | 2 +- 9 files changed, 332 insertions(+), 261 deletions(-) create mode 100644 SOGo/Main/MainUIProduct.m create mode 100644 SOGo/Main/SOGo.m diff --git a/SOGo/Main/ChangeLog b/SOGo/Main/ChangeLog index 0ba22288..66155c52 100644 --- a/SOGo/Main/ChangeLog +++ b/SOGo/Main/ChangeLog @@ -1,3 +1,8 @@ +2005-02-10 Helge Hess + + * sogod.m: moved application class to own file, started to work on + daemon/product separation (v0.9.19) + 2004-01-07 Marcus Mueller * {English/French}.lproj/default.strings: changed encoding from diff --git a/SOGo/Main/GNUmakefile b/SOGo/Main/GNUmakefile index 255f223b..e66147a7 100644 --- a/SOGo/Main/GNUmakefile +++ b/SOGo/Main/GNUmakefile @@ -2,15 +2,27 @@ include $(GNUSTEP_MAKEFILES)/common.make -WOAPP_NAME = sogod +WOAPP_NAME = sogod +BUNDLE_NAME = MainUI +BUNDLE_EXTENSION = .SOGo +BUNDLE_INSTALL_DIR = $(GNUSTEP_USER_ROOT)/Library/SOGo -sogod_LANGUAGES = English French +# daemon tool sogod_OBJC_FILES += \ sogod.m \ + SOGo.m \ SOGoProductLoader.m \ SOGoAuthenticator.m \ - \ + +# product + +MainUI_PRINCIPAL_CLASS = MainUIProduct + +sogod_LANGUAGES = English French + +sogod_OBJC_FILES += \ + MainUIProduct.m \ SOGoRootPage.m \ SOGoUserHomePage.m \ SOGoGroupPage.m \ @@ -28,8 +40,7 @@ sogod_RESOURCE_FILES += \ sogod_LOCALIZED_RESOURCE_FILES += \ Locale default.strings -sogod_WEBSERVER_RESOURCE_FILES += - -include GNUmakefile.preamble include $(GNUSTEP_MAKEFILES)/woapp.make +#include $(GNUSTEP_MAKEFILES)/bundle.make -include GNUmakefile.postamble diff --git a/SOGo/Main/MainUIProduct.m b/SOGo/Main/MainUIProduct.m new file mode 100644 index 00000000..bf13ead4 --- /dev/null +++ b/SOGo/Main/MainUIProduct.m @@ -0,0 +1,31 @@ +/* + 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. +*/ + +#import + +@interface MainUIProduct : NSObject +{ +} + +@end + +@implementation MainUIProduct +@end /* MainUIProduct */ diff --git a/SOGo/Main/README b/SOGo/Main/README index ec1f05d1..7e6d556b 100644 --- a/SOGo/Main/README +++ b/SOGo/Main/README @@ -1,5 +1,3 @@ -# $Id$ - SOGo ==== @@ -17,3 +15,11 @@ Defaults SOGoCrashOnSessionCreate - bool - crash the server if a session is created => useful for debugging + +What it does +============ +- provides locale support +- preloads the SOGo products (SOGoProductLoader) +- provides the root object (the application object with user lookup) +- sets the authenticator +- does some process limits and restart support diff --git a/SOGo/Main/SOGo.m b/SOGo/Main/SOGo.m new file mode 100644 index 00000000..eeb869e4 --- /dev/null +++ b/SOGo/Main/SOGo.m @@ -0,0 +1,265 @@ +/* + 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. +*/ + +#include + +@interface SOGo : SoApplication +{ + NSMutableDictionary *localeLUT; +} + +- (NSDictionary *)currentLocaleConsideringLanguages:(NSArray *)_langs; +- (NSDictionary *)localeForLanguageNamed:(NSString *)_name; + +@end + +#include "SOGoAuthenticator.h" +#include "SOGoProductLoader.h" +#include +#include "common.h" + +@implementation SOGo + +static unsigned int vMemSizeLimit = 0; +static BOOL doCrashOnSessionCreate = NO; + ++ (void)initialize { + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + id tmp; + + doCrashOnSessionCreate = [ud boolForKey:@"SOGoCrashOnSessionCreate"]; + + /* vMem size check - default is 200MB */ + + tmp = [ud objectForKey:@"SxVMemLimit"]; + vMemSizeLimit = (tmp != nil) + ? [tmp intValue] + : 200; + if (vMemSizeLimit > 0) { + NSLog(@"Note: vmem size check enabled: shutting down app when " + @"vmem > %d MB", vMemSizeLimit); + } +} + +- (id)init { + if ((self = [super init])) { + self->localeLUT = [[NSMutableDictionary alloc] initWithCapacity:2]; + [[SOGoProductLoader productLoader] loadProducts]; + +#if 0 /* enable, if we added the value class */ + /* setup some WebDAV type mappings required for Evolution */ + [EOQualifier registerValueClass:NSClassFromString(@"dateTime") + forTypeName:@"dateTime"]; + [EOQualifier registerValueClass:NSClassFromString(@"dateTime") + forTypeName:@"dateTime.tz"]; +#endif + + } + return self; +} + +- (void)dealloc { + [self->localeLUT release]; + [super dealloc]; +} + +/* authenticator */ + +- (id)authenticatorInContext:(WOContext *)_ctx { + return [SOGoAuthenticator sharedSOGoAuthenticator]; +} + +/* name lookup */ + +- (BOOL)isUserName:(NSString *)_key inContext:(id)_ctx { + if ([_key length] < 1) + return NO; + + if (isdigit([_key characterAtIndex:0])) + return NO; + + return YES; +} + +- (id)lookupUser:(NSString *)_key inContext:(id)_ctx { + return [[[SOGoUserFolder alloc] initWithName:_key inContainer:self] + autorelease]; +} + +- (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag { + id obj; + + /* put locale info into the context in case it's not there */ + if (![_ctx valueForKey:@"locale"]) { + NSArray *langs; + NSDictionary *locale; + + langs = [[(WOContext *)_ctx request] browserLanguages]; + locale = [self currentLocaleConsideringLanguages:langs]; + [_ctx takeValue:locale forKey:@"locale"]; + } + +#if 0 // znek: explain why you did that? + /* set SoRootURL */ + if ([_ctx valueForKey:@"SoRootURL"] == nil) { + [_ctx takeValue:@"/sogod.woa/so/" forKey:@"SoRootURL"]; + } +#endif + + /* 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]; + + return nil; +} + +/* WebDAV */ + +- (NSString *)davDisplayName { + /* this is used in the UI, eg in the navigation */ + return @"SOGo"; +} + +/* exception handling */ + +- (WOResponse *)handleException:(NSException *)_exc + inContext:(WOContext *)_ctx +{ + printf("EXCEPTION: %s\n", [[_exc description] cString]); + abort(); +} + +/* runtime maintenance */ + +- (void)checkIfDaemonHasToBeShutdown { + unsigned int limit, vmem; + + if ((limit = vMemSizeLimit) == 0) + return; + + vmem = [[NSProcessInfo processInfo] virtualMemorySize]/1048576; + + if (vmem > limit) { + [self logWithFormat: + @"terminating app, vMem size limit (%d MB) has been reached" + @" (currently %d MB)", + limit, vmem]; + [self terminate]; + } +} + +- (WOResponse *)dispatchRequest:(WORequest *)_request { + static NSArray *runLoopModes = nil; + WOResponse *resp; + + resp = [super dispatchRequest:_request]; + + if ([self isTerminating]) + return resp; + + if (runLoopModes == nil) + runLoopModes = [[NSArray alloc] initWithObjects:NSDefaultRunLoopMode, nil]; + + // TODO: a bit complicated? (-perform:afterDelay: doesn't work?) + [[NSRunLoop currentRunLoop] performSelector: + @selector(checkIfDaemonHasToBeShutdown) + target:self argument:nil + order:1 modes:runLoopModes]; + return resp; +} + +/* session management */ + +- (WOSession *)createSessionForRequest:(WORequest *)_request { + [self warnWithFormat:@"session creation requested!"]; + if (doCrashOnSessionCreate) + abort(); + return [super createSessionForRequest:_request]; +} + +/* localization */ + +- (NSDictionary *)currentLocaleConsideringLanguages:(NSArray *)_langs { + unsigned i, count; + + /* assume _langs is ordered by priority */ + count = [_langs count]; + for (i = 0; i < count; i++) { + NSString *lname; + NSDictionary *locale; + + lname = [_langs objectAtIndex:i]; + locale = [self localeForLanguageNamed:lname]; + if (locale) + return locale; + } + /* no appropriate language, fallback to default */ + return [self localeForLanguageNamed:@"English"]; +} + +- (NSDictionary *)localeForLanguageNamed:(NSString *)_name { + NSString *lpath; + id data; + NSDictionary *locale; + + NSAssert(_name != nil, @"_name MUST NOT be nil!"); + if((locale = [self->localeLUT objectForKey:_name]) != nil) + return locale; + lpath = [[self resourceManager] + pathForResourceNamed:@"Locale" + inFramework:nil + languages:[NSArray arrayWithObject:_name]]; + + data = [NSData dataWithContentsOfFile:lpath]; + if(data == nil) { + NSLog(@"%s didn't find locale with name:%@", + __PRETTY_FUNCTION__, + _name); + return nil; + } + data = [[[NSString alloc] initWithData:data + encoding:NSUTF8StringEncoding] autorelease]; + locale = [data propertyList]; + if(locale == nil) { + NSLog(@"%s couldn't load locale with name:%@", + __PRETTY_FUNCTION__, + _name); + return nil; + } + [self->localeLUT setObject:locale forKey:_name]; + return locale; +} + +@end /* SOGo */ diff --git a/SOGo/Main/Version b/SOGo/Main/Version index 676aa604..7ad8ae0c 100644 --- a/SOGo/Main/Version +++ b/SOGo/Main/Version @@ -1,5 +1,5 @@ -# $Id$ +# Version file -SUBMINOR_VERSION:=18 +SUBMINOR_VERSION:=19 # v0.9.16 requires NGExtensions v4.5.136 diff --git a/SOGo/Main/sogod.m b/SOGo/Main/sogod.m index 6758f0c6..314a248c 100644 --- a/SOGo/Main/sogod.m +++ b/SOGo/Main/sogod.m @@ -1,5 +1,5 @@ /* - Copyright (C) 2004 SKYRIX Software AG + Copyright (C) 2004-2005 SKYRIX Software AG This file is part of OpenGroupware.org. @@ -18,254 +18,10 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ -#include - -@interface SOGo : SoApplication -{ - NSMutableDictionary *localeLUT; -} - -- (NSDictionary *)currentLocaleConsideringLanguages:(NSArray *)_langs; -- (NSDictionary *)localeForLanguageNamed:(NSString *)_name; - -@end - -#include "SOGoAuthenticator.h" -#include "SOGoProductLoader.h" -#include +#include #include "common.h" -@implementation SOGo - -static unsigned int vMemSizeLimit = 0; -static BOOL doCrashOnSessionCreate = NO; - -+ (void)initialize { - NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - id tmp; - - doCrashOnSessionCreate = [ud boolForKey:@"SOGoCrashOnSessionCreate"]; - - /* vMem size check - default is 200MB */ - - tmp = [ud objectForKey:@"SxVMemLimit"]; - vMemSizeLimit = (tmp != nil) - ? [tmp intValue] - : 200; - if (vMemSizeLimit > 0) { - NSLog(@"Note: vmem size check enabled: shutting down app when " - @"vmem > %d MB", vMemSizeLimit); - } -} - -- (id)init { - if ((self = [super init])) { - self->localeLUT = [[NSMutableDictionary alloc] initWithCapacity:2]; - [[SOGoProductLoader productLoader] loadProducts]; - -#if 0 /* enable, if we added the value class */ - /* setup some WebDAV type mappings required for Evolution */ - [EOQualifier registerValueClass:NSClassFromString(@"dateTime") - forTypeName:@"dateTime"]; - [EOQualifier registerValueClass:NSClassFromString(@"dateTime") - forTypeName:@"dateTime.tz"]; -#endif - - } - return self; -} - -- (void)dealloc { - [self->localeLUT release]; - [super dealloc]; -} - -/* authenticator */ - -- (id)authenticatorInContext:(WOContext *)_ctx { - return [SOGoAuthenticator sharedSOGoAuthenticator]; -} - -/* name lookup */ - -- (BOOL)isUserName:(NSString *)_key inContext:(id)_ctx { - if ([_key length] < 1) - return NO; - - if (isdigit([_key characterAtIndex:0])) - return NO; - - return YES; -} - -- (id)lookupUser:(NSString *)_key inContext:(id)_ctx { - return [[[SOGoUserFolder alloc] initWithName:_key inContainer:self] - autorelease]; -} - -- (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag { - id obj; - - /* put locale info into the context in case it's not there */ - if (![_ctx valueForKey:@"locale"]) { - NSArray *langs; - NSDictionary *locale; - - langs = [[(WOContext *)_ctx request] browserLanguages]; - locale = [self currentLocaleConsideringLanguages:langs]; - [_ctx takeValue:locale forKey:@"locale"]; - } - -#if 0 // znek: explain why you did that? - /* set SoRootURL */ - if ([_ctx valueForKey:@"SoRootURL"] == nil) { - [_ctx takeValue:@"/sogod.woa/so/" forKey:@"SoRootURL"]; - } -#endif - - /* 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]; - - return nil; -} - -/* WebDAV */ - -- (NSString *)davDisplayName { - /* this is used in the UI, eg in the navigation */ - return @"SOGo"; -} - -/* exception handling */ - -- (WOResponse *)handleException:(NSException *)_exc - inContext:(WOContext *)_ctx -{ - printf("EXCEPTION: %s\n", [[_exc description] cString]); - abort(); -} - -/* runtime maintenance */ - -- (void)checkIfDaemonHasToBeShutdown { - unsigned int limit, vmem; - - if ((limit = vMemSizeLimit) == 0) - return; - - vmem = [[NSProcessInfo processInfo] virtualMemorySize]/1048576; - - if (vmem > limit) { - [self logWithFormat: - @"terminating app, vMem size limit (%d MB) has been reached" - @" (currently %d MB)", - limit, vmem]; - [self terminate]; - } -} - -- (WOResponse *)dispatchRequest:(WORequest *)_request { - static NSArray *runLoopModes = nil; - WOResponse *resp; - - resp = [super dispatchRequest:_request]; - - if ([self isTerminating]) - return resp; - - if (runLoopModes == nil) - runLoopModes = [[NSArray alloc] initWithObjects:NSDefaultRunLoopMode, nil]; - - // TODO: a bit complicated? (-perform:afterDelay: doesn't work?) - [[NSRunLoop currentRunLoop] performSelector: - @selector(checkIfDaemonHasToBeShutdown) - target:self argument:nil - order:1 modes:runLoopModes]; - return resp; -} - -/* session management */ - -- (WOSession *)createSessionForRequest:(WORequest *)_request { - [self warnWithFormat:@"session creation requested!"]; - if (doCrashOnSessionCreate) - abort(); - return [super createSessionForRequest:_request]; -} - -/* localization */ - -- (NSDictionary *)currentLocaleConsideringLanguages:(NSArray *)_langs { - unsigned i, count; - - /* assume _langs is ordered by priority */ - count = [_langs count]; - for (i = 0; i < count; i++) { - NSString *lname; - NSDictionary *locale; - - lname = [_langs objectAtIndex:i]; - locale = [self localeForLanguageNamed:lname]; - if (locale) - return locale; - } - /* no appropriate language, fallback to default */ - return [self localeForLanguageNamed:@"English"]; -} - -- (NSDictionary *)localeForLanguageNamed:(NSString *)_name { - NSString *lpath; - id data; - NSDictionary *locale; - - NSAssert(_name != nil, @"_name MUST NOT be nil!"); - if((locale = [self->localeLUT objectForKey:_name]) != nil) - return locale; - lpath = [[self resourceManager] - pathForResourceNamed:@"Locale" - inFramework:nil - languages:[NSArray arrayWithObject:_name]]; - - data = [NSData dataWithContentsOfFile:lpath]; - if(data == nil) { - NSLog(@"%s didn't find locale with name:%@", - __PRETTY_FUNCTION__, - _name); - return nil; - } - data = [[[NSString alloc] initWithData:data - encoding:NSUTF8StringEncoding] autorelease]; - locale = [data propertyList]; - if(locale == nil) { - NSLog(@"%s couldn't load locale with name:%@", - __PRETTY_FUNCTION__, - _name); - return nil; - } - [self->localeLUT setObject:locale forKey:_name]; - return locale; -} - -@end /* SOGo */ - - int main(int argc, char **argv, char **env) { NSAutoreleasePool *pool; diff --git a/SOGo/UI/Common/CommonUIProduct.m b/SOGo/UI/Common/CommonUIProduct.m index b5a4da4a..884787df 100644 --- a/SOGo/UI/Common/CommonUIProduct.m +++ b/SOGo/UI/Common/CommonUIProduct.m @@ -1,7 +1,7 @@ /* - Copyright (C) 2000-2003 SKYRIX Software AG + Copyright (C) 2004-2005 SKYRIX Software AG - This file is part of OGo + 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 @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id: CommonUIProduct.m,v 1.1 2003/11/24 01:24:40 helge Exp $ #import @@ -28,7 +27,5 @@ @end -#include "common.h" - @implementation CommonUIProduct @end /* CommonUIProduct */ diff --git a/SOGo/UI/Common/GNUmakefile b/SOGo/UI/Common/GNUmakefile index 4806938e..2ba14261 100644 --- a/SOGo/UI/Common/GNUmakefile +++ b/SOGo/UI/Common/GNUmakefile @@ -1,4 +1,4 @@ -# $Id: GNUmakefile,v 1.2 2003/12/09 17:38:42 helge Exp $ +# GNUstep makefile include $(GNUSTEP_MAKEFILES)/common.make -- 2.39.5