From 9e687b89a6b45607344a550fcab8f7ba182c8389 Mon Sep 17 00:00:00 2001 From: helge Date: Wed, 30 Jun 2004 08:05:07 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/trunk@92 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/Main/GNUmakefile | 4 +- SOGo/Main/SOGoAuthenticator.h | 36 ++++++++++ SOGo/Main/SOGoAuthenticator.m | 50 +++++++++++++ SOGo/Main/SOGoProductLoader.h | 41 +++++++++++ SOGo/Main/SOGoProductLoader.m | 131 ++++++++++++++++++++++++++++++++++ SOGo/Main/sogod.m | 73 +++++++++++++++++++ 6 files changed, 334 insertions(+), 1 deletion(-) create mode 100644 SOGo/Main/SOGoAuthenticator.h create mode 100644 SOGo/Main/SOGoAuthenticator.m create mode 100644 SOGo/Main/SOGoProductLoader.h create mode 100644 SOGo/Main/SOGoProductLoader.m diff --git a/SOGo/Main/GNUmakefile b/SOGo/Main/GNUmakefile index f376df0a..ffdb1401 100644 --- a/SOGo/Main/GNUmakefile +++ b/SOGo/Main/GNUmakefile @@ -5,7 +5,9 @@ include $(GNUSTEP_MAKEFILES)/common.make WOAPP_NAME = sogod sogod_OBJC_FILES += \ - sogod.m + sogod.m \ + SOGoProductLoader.m \ + SOGoAuthenticator.m \ sogod_RESOURCE_FILES += \ Version \ diff --git a/SOGo/Main/SOGoAuthenticator.h b/SOGo/Main/SOGoAuthenticator.h new file mode 100644 index 00000000..2d4476d8 --- /dev/null +++ b/SOGo/Main/SOGoAuthenticator.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2004 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. +*/ +// $Id$ + +#ifndef __Main_SOGoAuthenticator_H__ +#define __Main_SOGoAuthenticator_H__ + +#include + +@interface SOGoAuthenticator : SoHTTPAuthenticator +{ +} + ++ (id)sharedSOGoAuthenticator; + +@end + +#endif /* __Main_SOGoAuthenticator_H__ */ diff --git a/SOGo/Main/SOGoAuthenticator.m b/SOGo/Main/SOGoAuthenticator.m new file mode 100644 index 00000000..52de901c --- /dev/null +++ b/SOGo/Main/SOGoAuthenticator.m @@ -0,0 +1,50 @@ +/* + Copyright (C) 2004 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. +*/ +// $Id$ + +#include "SOGoAuthenticator.h" +#include "common.h" + +@implementation SOGoAuthenticator + +static SOGoAuthenticator *auth = nil; // THREAD + ++ (id)sharedSOGoAuthenticator { + if (auth == nil) + auth = [[self alloc] init]; + return auth; +} + +- (void)dealloc { + [super dealloc]; +} + +/* check credentials */ + +- (BOOL)checkLogin:(NSString *)_login password:(NSString *)_pwd { + if ([_login length] == 0) + return NO; + + /* we accept any password since it is checked by Apache in front */ + return YES; +} + +@end /* SOGoAuthenticator */ diff --git a/SOGo/Main/SOGoProductLoader.h b/SOGo/Main/SOGoProductLoader.h new file mode 100644 index 00000000..cf565572 --- /dev/null +++ b/SOGo/Main/SOGoProductLoader.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2004 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. +*/ +// $Id$ + +#ifndef __Main_SOGoProductLoader_H__ +#define __Main_SOGoProductLoader_H__ + +#import + +@interface SOGoProductLoader : NSObject +{ + NSString *productDirectoryName; +} + ++ (id)productLoader; + +/* operations */ + +- (void)loadProducts; + +@end + +#endif /* __Main_SOGoProductLoader_H__ */ diff --git a/SOGo/Main/SOGoProductLoader.m b/SOGo/Main/SOGoProductLoader.m new file mode 100644 index 00000000..7c0f487e --- /dev/null +++ b/SOGo/Main/SOGoProductLoader.m @@ -0,0 +1,131 @@ +/* + Copyright (C) 2004 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. +*/ +// $Id$ + +#include "SOGoProductLoader.h" +#include "common.h" + +@implementation SOGoProductLoader + ++ (id)productLoader { + return [[[self alloc] init] autorelease]; +} + +- (id)init { + if ((self = [super init])) { + self->productDirectoryName = @"SOGo"; + } + return self; +} + +- (void)dealloc { + [self->productDirectoryName release]; + [super dealloc]; +} + +/* loading */ + +- (NSArray *)productSearchPathes { + static NSArray *searchPathes = nil; + NSMutableArray *ma; + NSDictionary *env; + id tmp; + + if (searchPathes) + return searchPathes; + + env = [[NSProcessInfo processInfo] environment]; + ma = [NSMutableArray arrayWithCapacity:6]; + +#if COCOA_Foundation_LIBRARY + tmp = NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory, + NSAllDomainsMask, + YES); + if ([tmp count] > 0) { + NSEnumerator *e; + + e = [tmp objectEnumerator]; + while ((tmp = [e nextObject])) { + tmp = [tmp stringByAppendingPathComponent:self->productDirectoryName]; + if (![ma containsObject:tmp]) + [ma addObject:tmp]; + } + } +#else + if ((tmp = [env objectForKey:@"GNUSTEP_PATHPREFIX_LIST"]) == nil) + tmp = [env objectForKey:@"GNUSTEP_PATHLIST"]; + + tmp = [tmp componentsSeparatedByString:@":"]; + if ([tmp count] > 0) { + NSEnumerator *e; + + e = [tmp objectEnumerator]; + while ((tmp = [e nextObject])) { + tmp = [tmp stringByAppendingPathComponent:@"Library"]; + tmp = [tmp stringByAppendingPathComponent:self->productDirectoryName]; + if (![ma containsObject:tmp]) + [ma addObject:tmp]; + } + } + else { + NSLog(@"%s: empty library search path !", __PRETTY_FUNCTION__); + } +#endif + + searchPathes = [ma copy]; + + if ([searchPathes count] == 0) + NSLog(@"%s: no search pathes were found !", __PRETTY_FUNCTION__); + + return searchPathes; +} + +- (void)loadProducts { + SoProductRegistry *registry = nil; + NSFileManager *fm; + NSEnumerator *pathes; + NSString *lpath; + + registry = [SoProductRegistry sharedProductRegistry]; + fm = [NSFileManager defaultManager]; + + pathes = [[self productSearchPathes] objectEnumerator]; + while ((lpath = [pathes nextObject])) { + NSEnumerator *productNames; + NSString *productName; + + productNames = [[fm directoryContentsAtPath:lpath] objectEnumerator]; + + while ((productName = [productNames nextObject])) { + NSString *bpath; + + bpath = [lpath stringByAppendingPathComponent:productName]; + [self logWithFormat:@"register SOGo product: %@", + [bpath lastPathComponent]]; + [registry registerProductAtPath:bpath]; + } + } + + if (![registry loadAllProducts]) + [self logWithFormat:@"WARNING: could not load all products !"]; +} + +@end /* SOGoProductLoader */ diff --git a/SOGo/Main/sogod.m b/SOGo/Main/sogod.m index d48fda25..82b95fd4 100644 --- a/SOGo/Main/sogod.m +++ b/SOGo/Main/sogod.m @@ -28,16 +28,50 @@ @end +#include "SOGoAuthenticator.h" +#include "SOGoProductLoader.h" #include "common.h" @implementation SOGo +static unsigned int vMemSizeLimit = 0; + ++ (void)initialize { + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + id tmp; + + /* 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])) { + [[SOGoProductLoader productLoader] loadProducts]; + + /* setup some WebDAV type mappings required for Evolution */ + [EOQualifier registerValueClass:NSClassFromString(@"dateTime") + forTypeName:@"dateTime"]; + [EOQualifier registerValueClass:NSClassFromString(@"dateTime") + forTypeName:@"dateTime.tz"]; + } return self; } +/* authenticator */ + +- (id)authenticatorInContext:(WOContext *)_ctx { + return [SOGoAuthenticator sharedSOGoAuthenticator]; +} + /* name lookup */ - (BOOL)isUserName:(NSString *)_key inContext:(id)_ctx { @@ -89,6 +123,45 @@ 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; +} + @end /* SOGo */ -- 2.39.5