]> err.no Git - sope/blobdiff - sope-appserver/NGObjWeb/WORequestHandler.m
added some WebDrive WebDAV properties
[sope] / sope-appserver / NGObjWeb / WORequestHandler.m
index faccd753074a9700e6e815744c37b9f036392843..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  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;
+  NGLoggerManager *lm;
+  static BOOL didInit = NO;
+
+  if (didInit)
+    return;
+  didInit = YES;
+
   NSDateClass = [NSDate class];
-  perflog = [[NSUserDefaults standardUserDefaults]
-                             boolForKey:@"WOProfileRequestHandler"];
+  
+  lm         = [NGLoggerManager defaultLoggerManager];
+  logger     = [lm loggerForDefaultKey:@"WODebuggingEnabled"];
+  perfLogger = [lm loggerForDefaultKey:@"WOProfileRequestHandler"];
+  
+  ud                 = [NSUserDefaults standardUserDefaults];
+  doNotSetCookiePath = [ud boolForKey:@"WOUseGlobalCookiePath"];
 }
 
 - (id)init {
   if ((self = [super init])) {
-    if ([[[NSUserDefaults standardUserDefaults]
-                          objectForKey:@"WORunMultithreaded"]
-                          boolValue]) {
+    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
+    
+    if ([ud boolForKey:@"WORunMultithreaded"])
       self->lock = [[NSRecursiveLock alloc] init];
-    }
   }
   return self;
 }
@@ -140,7 +154,7 @@ static Class NSDateClass = Nil;
     }
   }
   
-  if (perflog)
+  if (perfLogger)
     startHandling = [[NSDateClass date] timeIntervalSince1970];
   
   thread = [NSThread currentThread];
@@ -157,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 */
@@ -188,26 +202,23 @@ static Class NSDateClass = Nil;
         
         [[session retain] autorelease];
         
-        if (response)
+        if (response != nil)
           /* some kind of error response from above ... */
           goto responseDone;
-        
-        /* check double click browser cache ... */
-        if ((response = [self doubleClickResponseForContext:context]))
-          goto responseDone;
-        
+       
         if (session == nil) {
           /* session autocreation .. */
           if ([self autocreateSessionForRequest:_request]) {
             if (![app isRefusingNewSessions]) {
               session = [app _initializeSessionInContext:context];
-
-              [self logWithFormat:@"autocreated session: %@", session];
+             
+              [self debugWithFormat:@"autocreated session: %@", session];
               
               if (session == 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];
             }
@@ -232,12 +243,14 @@ static Class NSDateClass = Nil;
                          session:session
                          application:app];
         
-        session = ([context hasSession])
+        session = [context hasSession]
           ? [context session]
           : nil;
         
-        if (session) {
+        if (session != nil) {
           if ([session storesIDsInCookies]) {
+            if (logger != nil) /* Note: required! do not remove */
+             [self debugWithFormat:@"add cookie to session: %@", session];
             [self addCookiesForSession:session
                   toResponse:response
                   inContext:context];
@@ -248,6 +261,8 @@ static Class NSDateClass = Nil;
                 withResponse:response
                 application:app];
         }
+        else
+          [self debugWithFormat:@"no session to store."];
       }
       NS_HANDLER {
         response = [app handleException:localException inContext:context];
@@ -277,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]];
@@ -285,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];
@@ -311,74 +327,71 @@ 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];
-
-    {
-      NSString *tmp;
-      
-      if ((uri = [[_ctx request] applicationName]) == nil)
-        uri = [app name];
-      uri = [@"/" stringByAppendingString:uri];
+  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 ((tmp = [[_ctx request] adaptorPrefix]))
-        uri = [tmp stringByAppendingString: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)
 
 - (BOOL)isDoubleClickBrowser {
-  NSString *ua;
-  
-  if ((ua = [self headerForKey:@"user-agent"]) == nil)
-    return NO;
-
-  if ([ua rangeOfString:@"Konqueror"].length > 0)
-    return YES;
-  else if ([ua rangeOfString:@"MSIE"].length > 0)
-    return [ua rangeOfString:@"Mac"].length > 0 ? YES : NO;
-  else
-    return NO;
+  return NO;
 }
 
 @end /* WORequest(DblClickBrowser) */
@@ -386,30 +399,7 @@ static Class NSDateClass = Nil;
 @implementation WORequestHandler(Support)
 
 - (WOResponse *)doubleClickResponseForContext:(WOContext *)_ctx {
-  /* HACK check for duplicate requests send out by Konqueror and MacIE */
-  WORequest *rq;
-  NSArray *hack; /* 0: uri, 1: response */
-
-  rq = [_ctx request];
-  
-  if (![rq isDoubleClickBrowser])
-    return nil;
-
-  if (![_ctx hasSession])
-    return nil;
-  
-  /* look into page cache */
-  hack = [(WOSession *)[_ctx session] objectForKey:@"_lastResponseCacheHack"];
-  if (hack == nil)
-    return nil;
-  
-  if ([[hack objectAtIndex:0] isEqualToString:[rq uri]]) {
-    [[WOApplication application]
-                    logWithFormat:
-                      @"using response from dblclick cache hack ..."];
-    return [hack objectAtIndex:1];
-  }
-  
+  // DEPRECATED
   return nil;
 }
 
@@ -428,16 +418,6 @@ static Class NSDateClass = Nil;
   
   [_app saveSessionForContext:_ctx];
   
-  /* store response if strange double-click browser */
-  if (_response) {
-    if ([[_ctx request] isDoubleClickBrowser]) {
-      NSArray *hack; /* 0: uri, 1: response */
-      
-      hack = [NSArray arrayWithObjects:[[_ctx request] uri], _response, nil];
-      [_session setObject:hack forKey:@"_lastResponseCacheHack"];
-    }
-  }
-
   if (perflog) {
     NSTimeInterval rt;
     rt = [[NSDate date] timeIntervalSince1970] - startSaveSn;