From: helge Date: Tue, 14 Mar 2006 16:50:44 +0000 (+0000) Subject: generate relative action links if possible X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c42f274e2eeb70cc64747b658ff87c4ca5b747f;p=sope generate relative action links if possible fixed a log crasher in keypath association code cleanups git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1228 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-appserver/NGObjWeb/Associations/WOKeyPathAssociation.m b/sope-appserver/NGObjWeb/Associations/WOKeyPathAssociation.m index fd06a27e..f7cb400c 100644 --- a/sope-appserver/NGObjWeb/Associations/WOKeyPathAssociation.m +++ b/sope-appserver/NGObjWeb/Associations/WOKeyPathAssociation.m @@ -792,15 +792,17 @@ static BOOL _setValue(WOKeyPathAssociation *self, id _value, id root) { SEL setSel = _getSetSel(info->ckey, info->keyLen); if (![object respondsToSelector:setSel]) { -#if 1 +#if 0 [self errorWithFormat:@"Could not set value for key '%s', " - @"object %@ doesn't respond to %@.", - self, info->ckey, object, - setSel ? NSStringFromSelector(setSel) : @""]; + @"object %@ doesn't respond to %@.", + info->ckey, object, + setSel ? NSStringFromSelector(setSel) : @""]; #endif return NO; } - else { + + /* object responds to the selector */ + { WOSetMethodType sm; if ((sm.method = [object methodForSelector:setSel]) != NULL) { diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index b6400efc..774b6123 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,16 @@ +2006-03-14 Helge Hess + + * v4.5.224 + + * Associations/WOKeyPathAssociation.m: fixed a crasher in a debug log + + * WOContext.m: changed to generate relative component action URLs in + case the request already was a valid component action URL. added a + way to detect whether the context session is a fresh one. + + * WOComponentRequestHandler.m, WOApplication.m: minor code cleanups, + use -isNotEmpty + 2006-03-12 Helge Hess * v4.5.223 diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOImage.m b/sope-appserver/NGObjWeb/DynamicElements/WOImage.m index 69e4725e..cc18cf76 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOImage.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOImage.m @@ -394,7 +394,8 @@ #endif return; -#if __APPLE__ +#if __APPLE__ + // TODO: same issue with gcc 4.1 on Linux ... // make Tiger GCC happy [super dealloc]; #endif diff --git a/sope-appserver/NGObjWeb/NGHttp/NGHttpRequest.m b/sope-appserver/NGObjWeb/NGHttp/NGHttpRequest.m index 96b416da..2f1f88c5 100644 --- a/sope-appserver/NGObjWeb/NGHttp/NGHttpRequest.m +++ b/sope-appserver/NGObjWeb/NGHttp/NGHttpRequest.m @@ -90,7 +90,8 @@ NSString *methodNames[] = { return self->method; } - (NSString *)methodName { - return (self->method < NGHttpMethod_last) ? methodNames[self->method] : nil; + return (self->method < NGHttpMethod_last) + ? methodNames[self->method] : (NSString *)nil; } - (NSString *)path { diff --git a/sope-appserver/NGObjWeb/NGObjWeb/WOContext.h b/sope-appserver/NGObjWeb/NGObjWeb/WOContext.h index 8d64a544..b2725626 100644 --- a/sope-appserver/NGObjWeb/NGObjWeb/WOContext.h +++ b/sope-appserver/NGObjWeb/NGObjWeb/WOContext.h @@ -1,5 +1,6 @@ /* Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2006 Helge Hess This file is part of SOPE. @@ -78,7 +79,8 @@ int inForm:1; int xmlStyleEmptyElements:1; int allowEmptyAttributes:1; - int reserved:28; + int hasNewSession:1; /* session was created during the run */ + int reserved:27; } wcFlags; @protected @@ -176,6 +178,8 @@ @interface WOContext(SOPEAdditions) +- (BOOL)hasNewSession; + /* languages for resource lookup (non-WO) */ - (NSArray *)resourceLookupLanguages; diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 3f449745..f5718974 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=223 +SUBMINOR_VERSION:=224 # v4.5.214 requires libNGExtensions v4.5.179 # v4.5.122 requires libNGExtensions v4.5.153 diff --git a/sope-appserver/NGObjWeb/WOApplication.m b/sope-appserver/NGObjWeb/WOApplication.m index b71baa1d..a79b5871 100644 --- a/sope-appserver/NGObjWeb/WOApplication.m +++ b/sope-appserver/NGObjWeb/WOApplication.m @@ -1,5 +1,6 @@ /* Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2006 Helge Hess This file is part of SOPE. @@ -192,7 +193,7 @@ static NSString *defaultCompRqHandlerClassName = @"WOComponentRequestHandler"; pi = [NSProcessInfo processInfo]; env = [pi environment]; - if ([env objectForKey:@"GNUSTEP_SYSTEM_ROOT"] != nil) { + if ([[env objectForKey:@"GNUSTEP_SYSTEM_ROOT"] isNotNull]) { isFlattened = [[[env objectForKey:@"GNUSTEP_FLATTENED"] lowercaseString] isEqualToString:@"yes"]; } @@ -248,7 +249,7 @@ static NSString *defaultCompRqHandlerClassName = @"WOComponentRequestHandler"; - (id)initWithName:(NSString *)_name { [WOApplication _initializeWOApp]; - if ((self = [super init])) { + if ((self = [super init]) != nil) { NSUserDefaults *ud; WORequestHandler *rh; NSString *rk; @@ -502,7 +503,7 @@ static NSString *defaultCompRqHandlerClassName = @"WOComponentRequestHandler"; WOSession *sn; sn = [self createSessionForRequest:[_ctx request]]; - [_ctx setSession:sn]; + [_ctx setNewSession:sn]; if ([sn respondsToSelector:@selector(prepare)]) { #if DEBUG @@ -526,7 +527,7 @@ static NSString *defaultCompRqHandlerClassName = @"WOComponentRequestHandler"; /* first look into form values */ if ((sessionId = [_request formValueForKey:WORequestValueSessionID])!=nil) { - if ([sessionId length] > 0) + if ([sessionId isNotEmpty]) return sessionId; } @@ -537,12 +538,12 @@ static NSString *defaultCompRqHandlerClassName = @"WOComponentRequestHandler"; e = [(id)sessionId objectEnumerator]; while ((sessionId = [e nextObject]) != nil) { - if ([sessionId length] > 0 && ![sessionId isEqual:@"nil"]) + if ([sessionId isNotEmpty] && ![sessionId isEqual:@"nil"]) return sessionId; } } else { - if ([sessionId length] > 0 && ![sessionId isEqual:@"nil"]) + if ([sessionId isNotEmpty] && ![sessionId isEqual:@"nil"]) return sessionId; } } @@ -599,7 +600,7 @@ static NSString *defaultCompRqHandlerClassName = @"WOComponentRequestHandler"; } else { session = [store restoreSessionWithID:_sid request:[_ctx request]]; - if (session) { + if ([session isNotNull]) { [_ctx setSession:session]; [session _awakeWithContext:_ctx]; } @@ -829,9 +830,9 @@ static NSString *defaultCompRqHandlerClassName = @"WOComponentRequestHandler"; ud = [NSUserDefaults standardUserDefaults]; p = [ud stringForKey:@"WODefaultResourceManager"]; - rmClass = ([p length] == 0) - ? [WOResourceManager class] - : NSClassFromString(p); + rmClass = [p isNotEmpty] + ? NSClassFromString(p) + : [WOResourceManager class]; if (rmClass == Nil) { [self errorWithFormat: diff --git a/sope-appserver/NGObjWeb/WOComponentRequestHandler.m b/sope-appserver/NGObjWeb/WOComponentRequestHandler.m index 6e49f3e2..70b5bf3f 100644 --- a/sope-appserver/NGObjWeb/WOComponentRequestHandler.m +++ b/sope-appserver/NGObjWeb/WOComponentRequestHandler.m @@ -52,9 +52,10 @@ - (WOResponse *)restoreSessionWithID:(NSString *)_sid inContext:(WOContext *)_ctx { - WOApplication *app = [WOApplication application]; + WOApplication *app; WOSession *session; + app = [WOApplication application]; if (_sid == nil) { // invalid session ID (or no session-ID ?!, which is no error ?) */ return [app handleSessionRestorationErrorInContext:_ctx]; @@ -124,16 +125,16 @@ session/context.element-id */ - if ([handlerPath length] > 0) { + if ([handlerPath isNotEmpty]) { NSArray *spath = [_request requestHandlerPathArray]; - + if ([spath count] > 1) [context setRequestSenderID:[spath objectAtIndex:1]]; - if ([spath count] > 0) + if ([spath isNotEmpty]) sessionID = [spath objectAtIndex:0]; } - if ([sessionID length] == 0) + if (![sessionID isNotEmpty]) sessionID = [application sessionIDFromRequest:_request]; #if 1 @@ -144,7 +145,7 @@ [application awake]; /* restore or create session */ - if ([sessionID isNotNull]) { + if ([sessionID isNotEmpty]) { if ((response = [self restoreSessionWithID:sessionID inContext:context])) session = nil; else { diff --git a/sope-appserver/NGObjWeb/WOContext+private.h b/sope-appserver/NGObjWeb/WOContext+private.h index e1c110d9..51b4e773 100644 --- a/sope-appserver/NGObjWeb/WOContext+private.h +++ b/sope-appserver/NGObjWeb/WOContext+private.h @@ -1,5 +1,6 @@ /* Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2006 Helge Hess This file is part of SOPE. @@ -41,6 +42,7 @@ extern void WOContext_leaveComponent(WOContext *_ctx, WOComponent *_component); - (WODynamicElement *)componentContent; - (void)setSession:(WOSession *)_session; +- (void)setNewSession:(WOSession *)_session; - (void)setPage:(WOComponent *)_page; - (void)setResponse:(WOResponse *)_response; diff --git a/sope-appserver/NGObjWeb/WOContext.m b/sope-appserver/NGObjWeb/WOContext.m index 6209859b..eb205819 100644 --- a/sope-appserver/NGObjWeb/WOContext.m +++ b/sope-appserver/NGObjWeb/WOContext.m @@ -1,5 +1,6 @@ /* - Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2000-2006 SKYRIX Software AG + Copyright (C) 2006 Helge Hess This file is part of SOPE. @@ -28,7 +29,7 @@ #include #include #include -#import +#include #include "WOElementID.h" #include "common.h" #include @@ -288,19 +289,26 @@ static NSString *WOApplicationSuffix = nil; [super dealloc]; } +/* session */ + - (void)setSession:(WOSession *)_session { ASSIGN(self->session, _session); } +- (void)setNewSession:(WOSession *)_session { + [self setSession:_session]; + self->wcFlags.hasNewSession = 1; +} - (id)session { - // in WO4 -session creates a new session if none is associated + /* in WO4 -session creates a new session if none is associated */ if (self->session == nil) { [[self application] _initializeSessionInContext:self]; - if (self->session == nil) + if (self->session == nil) { [self logWithFormat:@"%s: missing session for context ..", __PRETTY_FUNCTION__]; + } } return self->session; @@ -335,6 +343,11 @@ static NSString *WOApplicationSuffix = nil; - (BOOL)hasSession { return (self->session != nil) ? YES : NO; } +- (BOOL)hasNewSession { + if (!self->wcFlags.hasNewSession) + return NO; + return [self hasSession]; +} - (BOOL)savePageRequired { return self->wcFlags.savePageRequired ? YES : NO; @@ -615,7 +628,7 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) { return; else if (WOGetKVCGetMethod(self, _key) == NULL) { if (_value == nil) - _value = [EONull null]; + _value = [NSNull null]; if (self->variables == nil) { self->variables = @@ -811,11 +824,20 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) { // 26% -urlWithRequestHandler... // 21% -elementID (was 40% !! :-) // ~20% mutable string ops + + /* + This makes the request handler save the page in the session at the + end of the request (only necessary if the page generates URLs which + refer the context). + */ + self->wcFlags.savePageRequired = 1; + if (newCURLStyle) { + // TODO: who uses that? Its not enabled per default + // TODO: what does this do? NSMutableString *qs; NSString *p; - self->wcFlags.savePageRequired = 1; qs = [MutableStrClass stringWithCapacity:64]; [qs appendString:WORequestValueSenderID]; @@ -846,8 +868,19 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) { static NSMutableString *url = nil; // THREAD static IMP addStr = NULL; NSString *s; + NSString *coRqhKey; + + coRqhKey = [WOAppClass componentRequestHandlerKey]; + + /* + Optimization: use relative URL if the request already was a component + action (with a valid session) + */ + if (!self->wcFlags.hasNewSession) { + if ([[self->request requestHandlerKey] isEqualToString:coRqhKey]) + return [self->elementID elementID]; + } - self->wcFlags.savePageRequired = 1; if (url == nil) { url = [[MutableStrClass alloc] initWithCapacity:256]; addStr = [url methodForSelector:@selector(appendString:)]; @@ -855,7 +888,7 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) { } else [url setString:@"/"]; - + /* Note: component actions *always* require sessions to be able to locate the request component ! @@ -864,8 +897,7 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) { addStr(url, @selector(appendString:), @"/"); addStr(url, @selector(appendString:), [self->elementID elementID]); - s = [self urlWithRequestHandlerKey: - [WOAppClass componentRequestHandlerKey] + s = [self urlWithRequestHandlerKey:coRqhKey path:url queryString:nil]; return s; }