From b572f22aee813b0c74127bd7046db4b30cef7158 Mon Sep 17 00:00:00 2001 From: helge Date: Sun, 5 Sep 2004 20:59:47 +0000 Subject: [PATCH] enhanced NGBundleManager search path processing, fixed some issues in NGObjWeb resource manager git-svn-id: http://svn.opengroupware.org/SOPE/trunk@105 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 5 + sope-appserver/NGObjWeb/Version | 2 +- .../NGObjWeb/WOResourceRequestHandler.m | 30 +++- sope-appserver/NGObjWeb/common.h | 4 - sope-core/NGExtensions/ChangeLog | 10 ++ sope-core/NGExtensions/NGBundleManager.m | 169 +++++++++++------- .../NGExtensions/NGBundleManager.h | 26 ++- sope-core/NGExtensions/NGHashMap.m | 31 +--- sope-core/NGExtensions/Version | 4 +- sope-core/NGExtensions/common.h | 6 +- 10 files changed, 159 insertions(+), 128 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index cbc3c286..af2e3678 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,8 @@ +2004-09-05 Helge Hess + + * WOResourceRequestHandler.m: added some debug logging, send a 404 + instead of a 500 if a resource could not be found (v4.3.25) + 2004-09-02 Helge Hess * wo*.make: when copying bundles to the install location, ensure that diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 08f45011..7dbad158 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=24 +SUBMINOR_VERSION:=25 # v4.2.413 requires libSaxObjC v4.2.33 # v4.2.341 requires libNGExtensions v4.2.77 diff --git a/sope-appserver/NGObjWeb/WOResourceRequestHandler.m b/sope-appserver/NGObjWeb/WOResourceRequestHandler.m index ef6d526d..32d6eff7 100644 --- a/sope-appserver/NGObjWeb/WOResourceRequestHandler.m +++ b/sope-appserver/NGObjWeb/WOResourceRequestHandler.m @@ -1,7 +1,7 @@ /* - Copyright (C) 2000-2003 SKYRIX Software AG + Copyright (C) 2000-2004 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$ #include @@ -39,6 +38,8 @@ @implementation WOResourceRequestHandler +static BOOL debugOn = NO; + + (int)version { return [super version] + 0 /* v2 */; } @@ -57,6 +58,8 @@ NSString *resourcePath; NSData *data; + if (debugOn) [self logWithFormat:@"handle WS request: %@", _request]; + if (_request == nil) return nil; *(&app) = [WOApplication application]; @@ -64,8 +67,11 @@ /* check for WebServerResources requests ... */ - if ([handlerPath count] < 1) + if ([handlerPath count] < 1) { + if (debugOn) [self logWithFormat:@"path to short: '%@'", handlerPath]; return nil; + } + if (debugOn) [self logWithFormat:@" check path: '%@'", handlerPath]; /* ok, found a resource request */ @@ -88,15 +94,25 @@ pathForResourceNamed:resourceName inFramework:nil languages:languages]; + if (debugOn) [self logWithFormat:@" resource path: '%@'", resourcePath]; - data = resourcePath + data = (resourcePath != nil) ? [NSData dataWithContentsOfFile:resourcePath] : nil; if (data == nil) { response = [WOResponse responseWithRequest:_request]; [response setStatus:404]; /* not found */ - return nil; + [response setHeader:@"text/html" forKey:@"content-type"]; + [response appendContentString:@"

Resource not found

"];
+    [response appendContentHTMLString:@"Name: "];
+    [response appendContentHTMLString:resourceName];
+    [response appendContentHTMLString:@"\nLanguages: "];
+    [response appendContentHTMLString:[languages description]];
+    [response appendContentHTMLString:@"\nResourceManager: "];
+    [response appendContentHTMLString:[[app resourceManager] description]];
+    [response appendContentString:@"
"]; + return response; } //NSLog(@"shall deliver %@", resourcePath); @@ -127,6 +143,8 @@ - (WOResponse *)handleRequest:(WORequest *)_request { NSArray *handlerPath = nil; + if (debugOn) [self logWithFormat:@"handle request: %@", _request]; + if ([[_request requestHandlerKey] isEqualToString:@"WebServerResources"]) return [self _handleWebServerResourcesRequest:_request]; diff --git a/sope-appserver/NGObjWeb/common.h b/sope-appserver/NGObjWeb/common.h index d414186f..581a783d 100644 --- a/sope-appserver/NGObjWeb/common.h +++ b/sope-appserver/NGObjWeb/common.h @@ -31,10 +31,6 @@ #include #include -#if LIB_FOUNDATION_LIBRARY -# import -#endif - #if NeXT_Foundation_LIBRARY # include # include diff --git a/sope-core/NGExtensions/ChangeLog b/sope-core/NGExtensions/ChangeLog index 5c7b98bc..50e287cb 100644 --- a/sope-core/NGExtensions/ChangeLog +++ b/sope-core/NGExtensions/ChangeLog @@ -1,3 +1,13 @@ +2004-09-05 Helge Hess + + * v4.3.112 + + * NGBundleManager.m: code cleanups, added -setBundleSearchPaths: and + -bundleSearchPaths to allow bundle path modifications from code + + * NGHashMap.m: removed libFoundation specific exception handling, the + same exceptions are now thrown for all runtimes + 2004-08-30 Helge Hess * NGBundleManager.m: fixed yet another bug in NGBundleManager path diff --git a/sope-core/NGExtensions/NGBundleManager.m b/sope-core/NGExtensions/NGBundleManager.m index 3d1fbdab..cf04d950 100644 --- a/sope-core/NGExtensions/NGBundleManager.m +++ b/sope-core/NGExtensions/NGBundleManager.m @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id: NGBundleManager.m 4 2004-08-20 17:04:31Z helge $ #include "NGBundleManager.h" #include "common.h" @@ -35,6 +34,12 @@ # include #endif +#if LIB_FOUNDATION_LIBRARY +@interface NSBundle(UsedPrivates) ++ (BOOL)isFlattenedDirLayout; +@end +#endif + #if NeXT_RUNTIME || APPLE_RUNTIME #include @@ -120,7 +125,9 @@ static Class _classLoadHook(const char *_name) { bundle = [manager bundleForClassNamed:[NSString stringWithCString:_name]]; if (bundle) { - //NSLog(@"%s: found bundle %@", __PRETTY_FUNCTION__, [bundle bundlePath]); +#if 0 + NSLog(@"%s: found bundle %@", __PRETTY_FUNCTION__, [bundle bundlePath]); +#endif if ([manager loadBundle:bundle]) { Class clazz; @@ -205,6 +212,12 @@ static BOOL _selectClassByVersion(NSString *_resourceName, static NGBundleManager *defaultManager = nil; static BOOL debugOn = NO; +#if defined(__MINGW32__) +static NSString *NGEnvVarPathSeparator = @";"; +#else +static NSString *NGEnvVarPathSeparator = @":"; +#endif + + (void)initialize { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; @@ -245,37 +258,42 @@ static BOOL debugOn = NO; return defaultManager; } -- (void)_setupBundleSearchPathes { - NSProcessInfo *pi; - NSUserDefaults *ud; - id paths; - NSString *path; +/* setup bundle search path */ - pi = [NSProcessInfo processInfo]; +- (void)_addMainBundlePathToPathArray:(NSMutableArray *)_paths { + NSProcessInfo *pi; + NSString *path; - /* setup bundle search path */ - - self->bundleSearchPaths = [[NSMutableArray alloc] init]; - - // first add main-bundle path + pi = [NSProcessInfo processInfo]; + path = [[pi arguments] objectAtIndex:0]; + path = [path stringByDeletingLastPathComponent]; - path = [[[pi arguments] objectAtIndex:0] stringByDeletingLastPathComponent]; if ([path isEqual:@""]) - path = @"."; + path = @"."; #if WITH_GNUSTEP else { - /* The path is the complete path to the executable, including the - processor, the OS and the library combo. Strip these directories - from the main bundle's path. */ - path = [[[path stringByDeletingLastPathComponent] - stringByDeletingLastPathComponent] - stringByDeletingLastPathComponent]; + // TODO: to be correct this would need to read the bundle-info + // NSExecutable?! + /* + The path is the complete path to the executable, including the + processor, the OS and the library combo. Strip these directories + from the main bundle's path. + */ +#if LIB_FOUNDATION_LIBRARY + if (![NSBundle isFlattenedDirLayout]) +#endif + path = [[[path stringByDeletingLastPathComponent] + stringByDeletingLastPathComponent] + stringByDeletingLastPathComponent]; } #endif - [self->bundleSearchPaths addObject:path]; - - // look into NGBundlePath default - + [_paths addObject:path]; +} + +- (void)_addBundlePathDefaultToPathArray:(NSMutableArray *)_paths { + NSUserDefaults *ud; + id paths; + if ((ud = [NSUserDefaults standardUserDefaults]) == nil) { // got this with gstep-base during the port, apparently it happens // if the bundle manager is created inside the setup process of @@ -285,62 +303,68 @@ static BOOL debugOn = NO; abort(); #endif } - - paths = [ud arrayForKey:@"NGBundlePath"]; - if (paths == nil) { - paths = [ud stringForKey:@"NGBundlePath"]; - if (paths) { -#if defined(__MINGW32__) - paths = [paths componentsSeparatedByString:@";"]; -#else - paths = [paths componentsSeparatedByString:@":"]; -#endif - } + + if ((paths = [ud arrayForKey:@"NGBundlePath"]) == nil) { + if ((paths = [ud stringForKey:@"NGBundlePath"]) != nil) + paths = [paths componentsSeparatedByString:NGEnvVarPathSeparator]; } - if (paths) - [self->bundleSearchPaths addObjectsFromArray:paths]; + if (paths != nil) + [_paths addObjectsFromArray:paths]; else if (debugOn) NSLog(@"Note: NGBundlePath default is not configured."); - - /* look into environment */ +} +- (void)_addEnvironmentPathToPathArray:(NSMutableArray *)_paths { + NSProcessInfo *pi; + id paths; + + pi = [NSProcessInfo processInfo]; paths = [[pi environment] objectForKey:@"NGBundlePath"]; - if (paths) { -#if defined(__MINGW32__) - paths = [paths componentsSeparatedByString:@";"]; -#else - paths = [paths componentsSeparatedByString:@":"]; -#endif - } - if (paths) [self->bundleSearchPaths addObjectsFromArray:paths]; + if (paths) + paths = [paths componentsSeparatedByString:NGEnvVarPathSeparator]; + if (paths) [_paths addObjectsFromArray:paths]; +} - /* add standard bundle paths */ - { +- (void)_addGNUstepPathsToPathArray:(NSMutableArray *)_paths { #if !GNUSTEP #else - // TODO: whats that supposed to do? - // TODO: replace with proper path locator function! - NSDictionary *env; - NSString *p; - unsigned i, count; - id tmp; + // TODO: whats that supposed to do? + // TODO: replace with proper path locator function! + NSDictionary *env; + NSString *p; + unsigned i, count; + id tmp; - env = [[NSProcessInfo processInfo] environment]; + env = [[NSProcessInfo processInfo] environment]; - if ((tmp = [env objectForKey:@"GNUSTEP_PATHPREFIX_LIST"]) == nil) - tmp = [env objectForKey:@"GNUSTEP_PATHLIST"]; - tmp = [tmp componentsSeparatedByString:@":"]; + if ((tmp = [env objectForKey:@"GNUSTEP_PATHPREFIX_LIST"]) == nil) + tmp = [env objectForKey:@"GNUSTEP_PATHLIST"]; + tmp = [tmp componentsSeparatedByString:@":"]; - for (i = 0, count = [tmp count]; i < count; i++) { - p = [tmp objectAtIndex:i]; - p = [p stringByAppendingPathComponent:@"Library"]; - p = [p stringByAppendingPathComponent:@"Bundles"]; - if ([self->bundleSearchPaths containsObject:p]) continue; + for (i = 0, count = [tmp count]; i < count; i++) { + p = [tmp objectAtIndex:i]; + p = [p stringByAppendingPathComponent:@"Library"]; + p = [p stringByAppendingPathComponent:@"Bundles"]; + if ([self->bundleSearchPaths containsObject:p]) continue; - if (p) [self->bundleSearchPaths addObject:p]; - } -#endif + if (p) [self->bundleSearchPaths addObject:p]; } +#endif +} + +- (void)_setupBundleSearchPathes { + NSProcessInfo *pi; + + pi = [NSProcessInfo processInfo]; + + /* setup bundle search path */ + + self->bundleSearchPaths = [[NSMutableArray alloc] initWithCapacity:16]; + + [self _addMainBundlePathToPathArray:self->bundleSearchPaths]; + [self _addBundlePathDefaultToPathArray:self->bundleSearchPaths]; + [self _addEnvironmentPathToPathArray:self->bundleSearchPaths]; + [self _addGNUstepPathsToPathArray:self->bundleSearchPaths]; #if DEBUG && NeXT_Foundation_LIBRARY && 0 NSLog(@"%s: bundle search pathes:\n%@", __PRETTY_FUNCTION__, @@ -424,6 +448,15 @@ static BOOL debugOn = NO; [super dealloc]; } +/* accessors */ + +- (void)setBundleSearchPaths:(NSArray *)_paths { + ASSIGNCOPY(self->bundleSearchPaths, _paths); +} +- (NSArray *)bundleSearchPaths { + return self->bundleSearchPaths; +} + /* registering bundles */ - (void)registerBundle:(NSBundle *)_bundle diff --git a/sope-core/NGExtensions/NGExtensions/NGBundleManager.h b/sope-core/NGExtensions/NGExtensions/NGBundleManager.h index 8077be0f..441fa1e7 100644 --- a/sope-core/NGExtensions/NGExtensions/NGBundleManager.h +++ b/sope-core/NGExtensions/NGExtensions/NGBundleManager.h @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #ifndef __NGExtensions_NGBundleManager_H__ #define __NGExtensions_NGBundleManager_H__ @@ -96,9 +95,12 @@ typedef BOOL (*NGBundleResourceSelector)(NSString *_resourceName, + (id)defaultBundleManager; -/* - * bundle access - */ +/* accessors */ + +- (void)setBundleSearchPaths:(NSArray *)_paths; +- (NSArray *)bundleSearchPaths; + +/* bundle access */ - (NSBundle *)bundleWithName:(NSString *)name type:(NSString *)_type; - (NSBundle *)bundleWithName:(NSString *)name; // type=='bundle' @@ -106,9 +108,7 @@ typedef BOOL (*NGBundleResourceSelector)(NSString *_resourceName, - (NSBundle *)bundleForClass:(Class)aClass; - (NSBundle *)bundleWithPath:(NSString *)path; -/* - * dependencies - */ +/* dependencies */ /* returns the names of the bundles required by the bundle */ - (NSArray *)bundlesRequiredByBundle:(NSBundle *)_bundle; @@ -119,21 +119,15 @@ typedef BOOL (*NGBundleResourceSelector)(NSString *_resourceName, /* returns the names of the classes required by the bundle */ - (NSArray *)classesRequiredByBundle:(NSBundle *)_bundle; -/* - * loading - */ +/* loading */ - (id)loadBundle:(NSBundle *)_bundle; -/* - * bundle manager object - */ +/* bundle manager object */ - (id)principalObjectOfBundle:(NSBundle *)_bundle; -/* - * resources - */ +/* resources */ - (NSDictionary *)configForResource:(id)_resource ofType:(NSString *)_type providedByBundle:(NSBundle *)_bundle; diff --git a/sope-core/NGExtensions/NGHashMap.m b/sope-core/NGExtensions/NGHashMap.m index c6394a28..ea3ce23b 100644 --- a/sope-core/NGExtensions/NGHashMap.m +++ b/sope-core/NGExtensions/NGHashMap.m @@ -18,15 +18,11 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ +// $Id: NGHashMap.m 4 2004-08-20 17:04:31Z helge $ #include "NGHashMap.h" #include "common.h" -#if LIB_FOUNDATION_LIBRARY -# import -#endif - #if !LIB_FOUNDATION_LIBRARY @interface NSException(SetUI) /* allowed on Jaguar ? */ - (void)setUserInfo:(NSDictionary *)_ui; @@ -411,17 +407,10 @@ static inline unsigned __countObjectsForKey(NGHashMap *self, id _key) { return nil; if ((_index < list->count) == 0) { -#if LIB_FOUNDATION_LIBRARY - NSException *exc = [[IndexOutOfRangeException alloc] - initForSize:list->count index:_index]; - [exc setUserInfo: - [NSDictionary dictionaryWithObject:self forKey:@"object"]]; - [exc raise]; -#else [NSException raise:NSRangeException format:@"index %d out of range for key %@ of length %d", _index, _key, list->count]; -#endif + return nil; } while (_index--) @@ -731,16 +720,10 @@ static inline unsigned __countObjectsForKey(NGHashMap *self, id _key) { checkForAddErrorMessage(self, _objects[0],_key); if ((root = [self __structForKey:_key]) == NULL) { if (_index > 0) { -#if LIB_FOUNDATION_LIBRARY - NSException *exc = [[IndexOutOfRangeException alloc] - initForSize:0 index:_index]; - [exc setUserInfo:[NSDictionary dictionaryWithObject:self forKey:@"map"]]; - [exc raise]; -#else [NSException raise:NSRangeException format:@"index %d out of range in map 0x%08X", _index, self]; -#endif + return; } root = initLListElement(_objects[0], NULL); @@ -749,16 +732,10 @@ static inline unsigned __countObjectsForKey(NGHashMap *self, id _key) { } else { if (!(_index < root->count)) { -#if LIB_FOUNDATION_LIBRARY - NSException *exc = [[IndexOutOfRangeException alloc] - initForSize:root->count index:_index]; - [exc setUserInfo:[NSDictionary dictionaryWithObject:self forKey:@"map"]]; - [exc raise]; -#else [NSException raise:NSRangeException format:@"index %d out of range in map 0x%08X length %d", _index, self, root->count]; -#endif + return; } root->count += _count; diff --git a/sope-core/NGExtensions/Version b/sope-core/NGExtensions/Version index b2e6649f..1ddcd53e 100644 --- a/sope-core/NGExtensions/Version +++ b/sope-core/NGExtensions/Version @@ -1,5 +1,5 @@ -# $Id$ +# version -SUBMINOR_VERSION:=111 +SUBMINOR_VERSION:=112 # v4.2.72 requires libEOControl v4.2.39 diff --git a/sope-core/NGExtensions/common.h b/sope-core/NGExtensions/common.h index 01d1a0df..633a9423 100644 --- a/sope-core/NGExtensions/common.h +++ b/sope-core/NGExtensions/common.h @@ -1,7 +1,7 @@ /* - Copyright (C) 2000-2003 SKYRIX Software AG + Copyright (C) 2000-2004 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$ #ifndef __NGExtensions_common_h__ #define __NGExtensions_common_h__ @@ -58,7 +57,6 @@ # import # import # import -# import #endif #ifndef ASSIGN -- 2.39.5