From: helge Date: Tue, 12 Oct 2004 17:22:56 +0000 (+0000) Subject: changed handling of default method X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=984a43b09cf69f22b733c0a3124cf7aed2f398a6;p=sope changed handling of default method git-svn-id: http://svn.opengroupware.org/SOPE/trunk@248 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-appserver/NGObjWeb/Associations/WOValueAssociation.h b/sope-appserver/NGObjWeb/Associations/WOValueAssociation.h index e6374634..c3ccaa1a 100644 --- a/sope-appserver/NGObjWeb/Associations/WOValueAssociation.h +++ b/sope-appserver/NGObjWeb/Associations/WOValueAssociation.h @@ -18,13 +18,19 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ +// $Id: WOValueAssociation.h 1 2004-08-20 10:08:27Z znek $ #ifndef __NGObjWeb_WOValueAssociation_H__ #define __NGObjWeb_WOValueAssociation_H__ #include +/* + WOValueAssociation + + Represents a constant value. +*/ + @interface WOValueAssociation : WOAssociation < NSCoding, NSCopying > { id value; diff --git a/sope-appserver/NGObjWeb/Associations/WOValueAssociation.m b/sope-appserver/NGObjWeb/Associations/WOValueAssociation.m index f3caab5d..69ef5bed 100644 --- a/sope-appserver/NGObjWeb/Associations/WOValueAssociation.m +++ b/sope-appserver/NGObjWeb/Associations/WOValueAssociation.m @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #include "WOValueAssociation.h" #include "common.h" @@ -28,6 +27,8 @@ @implementation WOValueAssociation +static Class StrClass = Nil; + + (int)version { return [super version] /* v2 */; } @@ -35,6 +36,7 @@ NSAssert2([super version] == 2, @"invalid superclass (%@) version %i !", NSStringFromClass([self superclass]), [super version]); + StrClass = [NSString class]; } + (WOAssociation *)associationWithValue:(id)_value { @@ -120,7 +122,10 @@ case 1: return YES; case 2: return NO; default: - self->cacheFlags.boolValue = [self->value boolValue] ? 1 : 2; + if (self->value == nil) + self->cacheFlags.boolValue = 2; /* false */ + else + self->cacheFlags.boolValue = [self->value boolValue] ? 1 : 2; return self->cacheFlags.boolValue == 1 ? YES : NO; } } @@ -154,7 +159,7 @@ str = [NSMutableString stringWithCapacity:64]; [str appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; [str appendString:@" value="]; - if ([self->value isKindOfClass:[NSString class]]) { + if ([self->value isKindOfClass:StrClass]) { NSString *v = self->value; [str appendString:@"\""]; diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 93e410a2..8cae8af9 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,19 @@ +2004-10-12 Helge Hess + + * v4.3.64 + + * Associations/WOValueAssociation.m: small tweak for bool values of nil + + * SoObjects/SoObject.m: added baseURL support for appnames which end + with a slash + + * SoObjects/SoObjectMethodDispatcher.m: do not call default methods in + place, but rather redirect to the method URL (can be disabled with + the SoRedirectToDefaultMethods default) + + * SoObjects/SoObjectMethodDispatcher.m, SoObjects/SoApplication.m: + minor improvements to logging + 2004-10-12 Helge Hess * _WOStringTable.m: always open .strings files in ISO-Latin-1 encoding diff --git a/sope-appserver/NGObjWeb/Defaults.plist b/sope-appserver/NGObjWeb/Defaults.plist index e06361c4..961c0e23 100644 --- a/sope-appserver/NGObjWeb/Defaults.plist +++ b/sope-appserver/NGObjWeb/Defaults.plist @@ -150,6 +150,7 @@ SoPageInvocationDebugEnabled = NO; SoProductResourceManagerDebugEnabled = NO; SoRendererDebugEnabled = NO; + SoRedirectToDefaultMethods = YES; SoSecurityManagerDebugEnabled = NO; SoPreferredNamespacePrefixes = { "DAV:" = "D"; diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOForm.h b/sope-appserver/NGObjWeb/DynamicElements/WOForm.h index 7401fd63..86cb450f 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOForm.h +++ b/sope-appserver/NGObjWeb/DynamicElements/WOForm.h @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #ifndef __NGObjWeb_DynElem_WOForm_H__ #define __NGObjWeb_DynElem_WOForm_H__ diff --git a/sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.m b/sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.m index 70f14b59..9efd3285 100644 --- a/sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.m +++ b/sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.m @@ -32,7 +32,7 @@ unsigned len; id body; - [self logWithFormat:@"parse part %@ data: %@", _part, _data]; + [self debugWithFormat:@"parse part %@ data: %@", _part, _data]; len = [_data length]; bytes = [_data bytes]; @@ -50,8 +50,13 @@ return [body autorelease]; } +- (BOOL)isDebuggingEnabled { + return NO; +} + @end /* NGFormUrlBodyParser */ + @implementation NGHttpMultipartFormDataBodyParser + (int)version { @@ -64,8 +69,8 @@ } - (BOOL)parseImmediatlyWithDelegate:(id)_delegate - multipart:(id)_part data:(NSData *)_data { - + multipart:(id)_part data:(NSData *)_data +{ return YES; } diff --git a/sope-appserver/NGObjWeb/SoObjects/SoApplication.m b/sope-appserver/NGObjWeb/SoObjects/SoApplication.m index dd654cd5..3ac382ee 100644 --- a/sope-appserver/NGObjWeb/SoObjects/SoApplication.m +++ b/sope-appserver/NGObjWeb/SoObjects/SoApplication.m @@ -202,8 +202,10 @@ static BOOL debugLookup = NO; hack to allow "/myapp/folder/", it is a hack because it also allows /myapp/myapp/myapp/.../folder/ ... */ - if (v == nil && [self isApplicationNameLookup:_name inContext:_ctx]) + if (v == nil && [self isApplicationNameLookup:_name inContext:_ctx]) { v = self; + if (debugLookup) [self logWithFormat:@" => rewrote value: %@", self]; + } return v; } diff --git a/sope-appserver/NGObjWeb/SoObjects/SoObject.m b/sope-appserver/NGObjWeb/SoObjects/SoObject.m index b3d81996..b38e748e 100644 --- a/sope-appserver/NGObjWeb/SoObjects/SoObject.m +++ b/sope-appserver/NGObjWeb/SoObjects/SoObject.m @@ -348,7 +348,7 @@ static void _initialize(void) { /* a) direct access, eg /MyFolder */ /* b) access via app, eg /MyApp/so/MyFolder */ [ms appendString:[rq applicationName]]; - [ms appendString:@"/"]; + if (![ms hasSuffix:@"/"]) [ms appendString:@"/"]; /* done */ rootURL = [[ms copy] autorelease]; diff --git a/sope-appserver/NGObjWeb/SoObjects/SoObjectMethodDispatcher.m b/sope-appserver/NGObjWeb/SoObjects/SoObjectMethodDispatcher.m index ddc70e32..3315f51f 100644 --- a/sope-appserver/NGObjWeb/SoObjects/SoObjectMethodDispatcher.m +++ b/sope-appserver/NGObjWeb/SoObjects/SoObjectMethodDispatcher.m @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #include "SoObjectMethodDispatcher.h" #include "SoObject.h" @@ -34,14 +33,17 @@ @implementation SoObjectMethodDispatcher static BOOL debugOn = NO; +static BOOL useRedirectsForDefaultMethods = NO; + (void)initialize { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; static BOOL didInit = NO; if (didInit) return; didInit = YES; - + debugOn = [ud boolForKey:@"SoObjectMethodDispatcherDebugEnabled"]; + useRedirectsForDefaultMethods = + [ud boolForKey:@"SoRedirectToDefaultMethods"]; } - (id)initWithObject:(id)_object { @@ -91,14 +93,40 @@ static BOOL debugOn = NO; } else if ([[self->object soClass] hasKey:[rq method] inContext:_ctx]) { // TODO: I'm not sure whether this step is correct - /* the class has a GET method */ + /* the class has a GET/PUT/xxx method */ methodObject = [self->object lookupName:[rq method] inContext:_ctx acquire:NO]; } + else if (useRedirectsForDefaultMethods) { + /* + Redirect to a default method if available. + */ + NSString *defaultName; + + defaultName = [self->object defaultMethodNameInContext:_ctx]; + if ([defaultName isNotNull]) { + if ([defaultName length] > 0) { + WOResponse *r; + NSString *url; + + url = [self->object baseURLInContext:_ctx]; + if (![url hasSuffix:@"/"]) url = [url stringByAppendingString:@"/"]; + url = [url stringByAppendingString:defaultName]; + + r = [[_ctx response] retain]; + [r setStatus:302 /* moved */]; + [r setHeader:url forKey:@"location"]; + [pool release]; + return [r autorelease]; + } + } + } else { - // TODO: should we replace the methodObject with a redirect to the - // default method name? This would ensure proper URLs + /* + Note: this can lead to incorrect URLs if the base URL of the method is + not set (the method will run in the client URL). + */ methodObject = [self->object lookupDefaultMethod]; if (debugOn) [self debugWithFormat:@"using default method: %@", methodObject]; @@ -114,16 +142,29 @@ static BOOL debugOn = NO; } /* perform call */ - + if (methodObject == nil || ![methodObject isCallable]) { /* The object is neither callable nor does it have a default method, so we just pass it through. + + Note: you can run into situations where there is a methodObject, but + it isn't callable. Eg this situation can occur if the default + method name leads to an object which isn't a method (occured in + the OFS context if 'index' maps to an OFSFile which itself isn't + callable). */ resultObject = self->object; if (debugOn) { - [self debugWithFormat:@"got no method, using object as result: %@", - resultObject]; + if (methodObject == nil) { + [self debugWithFormat:@"got no method, using object as result: %@", + resultObject]; + } + else { + [self debugWithFormat: + @"method is not callable %@, using object as result: %@", + methodObject, resultObject]; + } } } else { diff --git a/sope-appserver/NGObjWeb/SoObjects/SoObjectRequestHandler.m b/sope-appserver/NGObjWeb/SoObjects/SoObjectRequestHandler.m index 6b12551a..f8af72cb 100644 --- a/sope-appserver/NGObjWeb/SoObjects/SoObjectRequestHandler.m +++ b/sope-appserver/NGObjWeb/SoObjects/SoObjectRequestHandler.m @@ -294,8 +294,10 @@ static NSString *rapidTurnAroundPath = nil; #if 0 /* - if we resolve in this location, we won't be able to resolve + If we resolve in this location, we won't be able to resolve application names like "Control_Panel". + + TODO: explain better! */ if ([object respondsToSelector:@selector(rootObjectInContext:)]) object = [object rootObjectInContext:_ctx]; diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index a3c02e77..7fa3a4aa 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=63 +SUBMINOR_VERSION:=64 # v4.3.42 requires libNGExtensions v4.3.116 # v4.3.40 requires libNGExtensions v4.3.115