/*
- Copyright (C) 2000-2004 SKYRIX Software AG
+ Copyright (C) 2000-2005 SKYRIX Software AG
- This file is part of OpenGroupware.org.
+ This file is part of SOPE.
- OGo is free software; you can redistribute it and/or modify it under
+ 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
Free Software Foundation; either version 2, or (at your option) any
later version.
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with OGo; see the file COPYING. If not, write to the
+ License along with SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
@implementation WORequestHandler
-static BOOL doNotSetCookiePath = NO;
-static BOOL perflog = NO;
-static Class NSDateClass = Nil;
+static BOOL doNotSetCookiePath = NO;
+static Class NSDateClass = Nil;
+static NGLogger *logger = nil;
+static NGLogger *perfLogger = nil;
+ (int)version {
return 2;
}
+ (void)initialize {
- NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
-
+ NSUserDefaults *ud;
+ NGLoggerManager *lm;
+ static BOOL didInit = NO;
+
+ if (didInit)
+ return;
+ didInit = YES;
+
NSDateClass = [NSDate class];
- perflog = [ud boolForKey:@"WOProfileRequestHandler"];
+
+ lm = [NGLoggerManager defaultLoggerManager];
+ logger = [lm loggerForDefaultKey:@"WODebuggingEnabled"];
+ perfLogger = [lm loggerForDefaultKey:@"WOProfileRequestHandler"];
+
+ ud = [NSUserDefaults standardUserDefaults];
doNotSetCookiePath = [ud boolForKey:@"WOUseGlobalCookiePath"];
}
}
}
- if (perflog)
+ if (perfLogger)
startHandling = [[NSDateClass date] timeIntervalSince1970];
thread = [NSThread currentThread];
{
/* setup context */
context = [WOContext contextWithRequest:_request];
- NSAssert(context, @"no context assigned ..");
+ NSAssert(context, @"no context assigned ..");
[app _setCurrentContext:context];
/* check session id */
response =[app handleSessionRestorationErrorInContext:context];
}
else { /* app refuses new sessions */
+ // TODO: this already failed once, will it return null again?
[self logWithFormat:@"app is refusing new sessions ..."];
response = [app handleSessionRestorationErrorInContext:context];
}
if (session != nil) {
if ([session storesIDsInCookies]) {
- [self debugWithFormat:@"add cookie to session: %@", session];
+ if (logger != nil) /* Note: required! do not remove */
+ [self debugWithFormat:@"add cookie to session: %@", session];
[self addCookiesForSession:session
toResponse:response
inContext:context];
withResponse:response
application:app];
}
- else
- [self debugWithFormat:@"no session to store."];
+ else
+ [self debugWithFormat:@"no session to store."];
}
NS_HANDLER {
response = [app handleException:localException inContext:context];
[app lock];
if ([app isRefusingNewSessions] &&
([app activeSessionsCount] < [app minimumActiveSessionsCount])) {
- [self debugWithFormat:
+ [self logWithFormat:
@"application terminates because it refuses new sessions and "
@"the active session count (%i) is below the minimum (%i).",
[app activeSessionsCount], [app minimumActiveSessionsCount]];
}
[app unlock];
- if (perflog) {
+ if (perfLogger) {
NSTimeInterval rt;
rt = [[NSDateClass date] timeIntervalSince1970] - startHandling;
- [self debugWithFormat:@"handleRequest took %4.3fs.", rt < 0.0 ? -1.0 : rt];
+ [perfLogger logWithFormat:@"handleRequest took %4.3fs.",
+ rt < 0.0 ? -1.0 : rt];
}
return [response autorelease];
return nil;
}
-@end /* WORequestHandler */
+/* logging */
+
+- (id)debugLogger {
+ return logger;
+}
-@implementation WORequestHandler(Cookies)
+/* Cookies */
- (void)addCookiesForSession:(WOSession *)_sn
toResponse:(WOResponse *)_response
inContext:(WOContext *)_ctx
{
- if ([_sn storesIDsInCookies]) {
- WOApplication *app;
- NSString *cookieName = nil;
- WOCookie *cookie = nil;
- NSString *uri;
- NSString *value;
-
- app = [WOApplication application];
- cookieName = [app name];
-
- if (!doNotSetCookiePath) {
- NSString *tmp;
+ WOApplication *app;
+ WOCookie *cookie = nil;
+ NSString *uri;
+ NSString *value;
+
+ if (![_sn storesIDsInCookies])
+ return;
+
+ app = [WOApplication application];
+
+ // TODO: there is a DUP of this section in OpenGroupware.m to set an
+ // expiration cookie
+ if (!doNotSetCookiePath) {
+ NSString *tmp;
- if ((uri = [[_ctx request] applicationName]) == nil)
- uri = [app name];
- uri = [@"/" stringByAppendingString:uri];
- if ((tmp = [[_ctx request] adaptorPrefix]))
- uri = [tmp stringByAppendingString:uri];
- }
- else
- uri = @"/";
-
-#if 0
- uri = [_ctx urlSessionPrefix];
- uri = [_ctx urlWithRequestHandlerKey:
- [WOApplication componentRequestHandlerKey]
- path:@"/"
- queryString:nil];
+ if ((uri = [[_ctx request] applicationName]) == nil)
+ uri = [app name];
+ uri = [@"/" stringByAppendingString:uri];
+ if ((tmp = [[_ctx request] adaptorPrefix]))
+ uri = [tmp stringByAppendingString:uri];
+ }
+ else
+ uri = @"/";
+
+#if 0 // TODO: explain!
+ uri = [_ctx urlSessionPrefix];
+ uri = [_ctx urlWithRequestHandlerKey:
+ [WOApplication componentRequestHandlerKey]
+ path:@"/"
+ queryString:nil];
#endif
- value = [_sn isTerminating]
- ? (id)@"nil"
- : [_sn sessionID];
+ value = [_sn isTerminating]
+ ? (NSString *)@"nil"
+ : [_sn sessionID];
- cookie = [WOCookie cookieWithName:cookieName
- value:value
- path:uri
- domain:[_sn domainForIDCookies]
- expires:[_sn expirationDateForIDCookies]
- isSecure:NO];
- if (cookie)
- [_response addCookie:cookie];
- }
+ cookie = [WOCookie cookieWithName:[app name]
+ value:value
+ path:uri
+ domain:[_sn domainForIDCookies]
+ expires:[_sn expirationDateForIDCookies]
+ isSecure:NO];
+ if (cookie != nil)
+ [_response addCookie:cookie];
}
-@end /* WORequestHandler(Cookies) */
+@end /* WORequestHandler */
+
@implementation WORequest(DblClickBrowser)