]> err.no Git - sope/blobdiff - sope-appserver/NGObjWeb/WORequestHandler.m
hotfix
[sope] / sope-appserver / NGObjWeb / WORequestHandler.m
index 4a96f5c8c20407a7ef01748fe601a2e275ffaa8c..c050fc0fc89fac729bad8ddb5e331f1449c61e77 100644 (file)
@@ -1,20 +1,20 @@
 /*
-  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"];
 }
 
@@ -142,7 +154,7 @@ static Class NSDateClass = Nil;
     }
   }
   
-  if (perflog)
+  if (perfLogger)
     startHandling = [[NSDateClass date] timeIntervalSince1970];
   
   thread = [NSThread currentThread];
@@ -159,7 +171,7 @@ static Class NSDateClass = Nil;
   {
     /* setup context */
     context = [WOContext contextWithRequest:_request];
-    NSAssert(context,    @"no context assigned ..");
+    NSAssert(context, @"no context assigned ..");
     [app _setCurrentContext:context];
     
     /* check session id */
@@ -206,6 +218,7 @@ static Class NSDateClass = Nil;
                 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];
             }
@@ -236,7 +249,8 @@ static Class NSDateClass = Nil;
         
         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];
@@ -247,8 +261,8 @@ static Class NSDateClass = Nil;
                 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];
@@ -278,7 +292,7 @@ static Class NSDateClass = Nil;
   [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]];
@@ -286,10 +300,11 @@ static Class NSDateClass = Nil;
   }
   [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];
@@ -312,60 +327,66 @@ static Class NSDateClass = Nil;
   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)