From 3c5fdb4a1367d0570e64a3740a65516199815363 Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 11 Jul 2005 15:10:32 +0000 Subject: [PATCH] fixed a logging handler issue with WORequestHandler improved WOComponentRequestHandler git-svn-id: http://svn.opengroupware.org/SOPE/trunk@884 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 10 +++ .../NGObjWeb/OWViewRequestHandler.m | 2 +- sope-appserver/NGObjWeb/Version | 2 +- sope-appserver/NGObjWeb/WOApplication.m | 2 + sope-appserver/NGObjWeb/WOComponent.m | 2 +- .../NGObjWeb/WOComponentRequestHandler.m | 77 +++++++++++-------- sope-appserver/NGObjWeb/WORequestHandler.m | 13 ++-- 7 files changed, 68 insertions(+), 40 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 20644610..a4a03963 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,13 @@ +2005-07-11 Helge Hess + + * v4.5.171 + + * WOComponentRequestHandler.m: stabilized session handling to properly + deal with expired sessions and URLs without element-ids + + * WORequestHandler.m: properly register logger bound to + 'WODebuggingEnabled' as debugLogger, not as the regular logger + 2005-07-08 Helge Hess * SoObjects/SoHTTPAuthenticator.m: deprecated -authRealm, replaced with diff --git a/sope-appserver/NGObjWeb/OWViewRequestHandler.m b/sope-appserver/NGObjWeb/OWViewRequestHandler.m index 4a9b394b..55ae59aa 100644 --- a/sope-appserver/NGObjWeb/OWViewRequestHandler.m +++ b/sope-appserver/NGObjWeb/OWViewRequestHandler.m @@ -259,7 +259,7 @@ static BOOL perflog = NO; if (requestComponent == nil) { /* could not restore page ... */ response = [app handlePageRestorationErrorInContext:context]; - if (response) { + if (response != nil) { [self logWithFormat: @"returning because of page restoration error ..."]; return response; diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 105404a0..2b5113dc 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=170 +SUBMINOR_VERSION:=171 # v4.5.122 requires libNGExtensions v4.5.153 # v4.5.91 requires libNGExtensions v4.5.134 diff --git a/sope-appserver/NGObjWeb/WOApplication.m b/sope-appserver/NGObjWeb/WOApplication.m index 3c5b7bd7..62933fc6 100644 --- a/sope-appserver/NGObjWeb/WOApplication.m +++ b/sope-appserver/NGObjWeb/WOApplication.m @@ -801,6 +801,8 @@ static NSString *defaultCompRqHandlerClassName = @"WOComponentRequestHandler"; return [self handleSessionRestorationError]; } + // TODO: is it correct to return nil? + // TODO: we should return a page saying sorry with a cookie + redirect [self errorWithFormat:@"could not restore session for context %@", _ctx]; return nil; } diff --git a/sope-appserver/NGObjWeb/WOComponent.m b/sope-appserver/NGObjWeb/WOComponent.m index a6c86efa..97a4370b 100644 --- a/sope-appserver/NGObjWeb/WOComponent.m +++ b/sope-appserver/NGObjWeb/WOComponent.m @@ -82,7 +82,7 @@ static BOOL wakeupPageOnCreation = NO; ud = [NSUserDefaults standardUserDefaults]; lm = [NGLoggerManager defaultLoggerManager]; - + WOComponentClass = [WOComponent class]; NSDateClass = [NSDate class]; perfLogger = [lm loggerForDefaultKey:@"WOProfileElements"]; diff --git a/sope-appserver/NGObjWeb/WOComponentRequestHandler.m b/sope-appserver/NGObjWeb/WOComponentRequestHandler.m index 0d8027ef..22c0756f 100644 --- a/sope-appserver/NGObjWeb/WOComponentRequestHandler.m +++ b/sope-appserver/NGObjWeb/WOComponentRequestHandler.m @@ -4,7 +4,7 @@ This file is part of SOPE. SOPE 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 + the terms of the GNU Lesser General Pulic License as published by the Free Software Foundation; either version 2, or (at your option) any later version. @@ -53,28 +53,23 @@ inContext:(WOContext *)_ctx { WOApplication *app = [WOApplication application]; - WOResponse *response = nil; + WOSession *session; if (_sid == nil) { // invalid session ID (or no session-ID ?!, which is no error ?) */ - response = [app handleSessionRestorationErrorInContext:_ctx]; + return [app handleSessionRestorationErrorInContext:_ctx]; } - else { - WOSession *session = nil; + + if ((session = [app restoreSessionWithID:_sid inContext:_ctx]) != nil) { + /* awake restored session */ + [_ctx setSession:session]; + [session _awakeWithContext:_ctx]; - if ((session = [app restoreSessionWithID:_sid inContext:_ctx])) { - // awake restored session - [_ctx setSession:session]; - [session _awakeWithContext:_ctx]; - - [session awake]; - response = nil; - } - else { - response = [app handleSessionRestorationErrorInContext:_ctx]; - } + [session awake]; + return nil; } - return response; + + return [app handleSessionRestorationErrorInContext:_ctx]; } /* @@ -150,28 +145,50 @@ /* restore or create session */ if ([sessionID isNotNull]) { - response = [self restoreSessionWithID:sessionID inContext:context]; - session = response ? nil : [context session]; + if ((response = [self restoreSessionWithID:sessionID inContext:context])) + session = nil; + else { + /* + Note: this creates a _new_ session if the restoration handler did not + return a response! We check that below by comparing the session + IDs. + */ + session = [context session]; + } - //[self logWithFormat:@"restored session (id=%@): %@", sessionID, session]; + [self debugWithFormat:@"restored session (id=%@): %@", sessionID, session]; + + if (session && (![sessionID isEqualToString:[session sessionID]])) { + [self errorWithFormat:@"session-ids do not match (%@ vs %@)", + sessionID, [session sessionID]]; + } if ([session isNotNull]) { - /* awake stored page */ - component = [session restorePageForContextID:[context currentElementID]]; + NSString *eid; - if (component == nil) - response = [application handlePageRestorationErrorInContext:context]; -#if DEBUG - else { - [self logWithFormat:@"%s: restored request component: %@", - __PRETTY_FUNCTION__, component]; + /* + only try to restore a page if we still have the same session and if + the request contains an element-id (eg if we reconnect to the main + URL we do not have an element-id + */ + eid = [context currentElementID]; + if ([sessionID isEqualToString:[session sessionID]] && eid != nil) { + /* awake stored page from "old" session */ + component = [session restorePageForContextID:eid]; + + if (component == nil) { + [self logWithFormat:@"could not restore component from session: %@", + session]; + response = [application handlePageRestorationErrorInContext:context]; + } } -#endif + else /* a new session was created (but no restore-error response ret.) */ + component = [application pageWithName:nil inContext:context]; } else if (response == nil) { [[WOApplication application] warnWithFormat: @"got no session restoration error, " - @"but missing session !"]; + @"but missing session!"]; } } else { diff --git a/sope-appserver/NGObjWeb/WORequestHandler.m b/sope-appserver/NGObjWeb/WORequestHandler.m index a958082d..5f8e383c 100644 --- a/sope-appserver/NGObjWeb/WORequestHandler.m +++ b/sope-appserver/NGObjWeb/WORequestHandler.m @@ -64,11 +64,11 @@ static NGLogger *perfLogger = nil; didInit = YES; NSDateClass = [NSDate class]; - + lm = [NGLoggerManager defaultLoggerManager]; logger = [lm loggerForDefaultKey:@"WODebuggingEnabled"]; perfLogger = [lm loggerForDefaultKey:@"WOProfileRequestHandler"]; - + ud = [NSUserDefaults standardUserDefaults]; doNotSetCookiePath = [ud boolForKey:@"WOUseGlobalCookiePath"]; } @@ -328,13 +328,11 @@ static NGLogger *perfLogger = nil; /* logging */ -- (id)logger { +- (id)debugLogger { return logger; } -@end /* WORequestHandler */ - -@implementation WORequestHandler(Cookies) +/* Cookies */ - (void)addCookiesForSession:(WOSession *)_sn toResponse:(WOResponse *)_response @@ -386,7 +384,8 @@ static NGLogger *perfLogger = nil; [_response addCookie:cookie]; } -@end /* WORequestHandler(Cookies) */ +@end /* WORequestHandler */ + @implementation WORequest(DblClickBrowser) -- 2.39.5