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.
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];
}
/*
/* 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 {
didInit = YES;
NSDateClass = [NSDate class];
-
+
lm = [NGLoggerManager defaultLoggerManager];
logger = [lm loggerForDefaultKey:@"WODebuggingEnabled"];
perfLogger = [lm loggerForDefaultKey:@"WOProfileRequestHandler"];
-
+
ud = [NSUserDefaults standardUserDefaults];
doNotSetCookiePath = [ud boolForKey:@"WOUseGlobalCookiePath"];
}
/* logging */
-- (id)logger {
+- (id)debugLogger {
return logger;
}
-@end /* WORequestHandler */
-
-@implementation WORequestHandler(Cookies)
+/* Cookies */
- (void)addCookiesForSession:(WOSession *)_sn
toResponse:(WOResponse *)_response
[_response addCookie:cookie];
}
-@end /* WORequestHandler(Cookies) */
+@end /* WORequestHandler */
+
@implementation WORequest(DblClickBrowser)