]> err.no Git - sope/blobdiff - sope-appserver/NGObjWeb/WOComponentRequestHandler.m
major improvements in resource/template lookup with SoProduct's
[sope] / sope-appserver / NGObjWeb / WOComponentRequestHandler.m
index da440f135dc2a025f314a3026f7223ecea4861a1..0d8027ef78a1358e381ba240c66c28230c24bd59 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.
 */
 - (void)_setCurrentContext:(WOContext *)_ctx;
 @end
 
+@interface WORequestHandler(URI)
+- (BOOL)doesRejectFavicon;
+@end
+
 @implementation WOComponentRequestHandler
 
 + (int)version {
 */
 
 - (WOResponse *)handleRequest:(WORequest *)_request {
+  // TODO: this should be integrated into the WORequestHandler default
+  //       mechanism
   NSString      *sessionID        = nil;
   WOApplication *application      = nil;
-  WOContext     *context          = nil;
+  WOContext     *context;
   WOResponse    *response         = nil;
   WOSession     *session          = nil;
   WOComponent   *component        = nil;
   NSString      *handlerPath      = nil;
 
   if (_request == nil) return nil;
-
+  
+  if ([self doesRejectFavicon] && [[_request uri] isNotNull]) {
+    // TODO: code copied from WORequestHandler ...
+    if ([@"/favicon.ico" isEqualToString:[_request uri]]) {
+      response = [WOResponse responseWithRequest:_request];
+      [response setStatus:404 /* not found */];
+      [self debugWithFormat:@"rejected favicon request: %@", [_request uri]];
+      return response;
+    }
+  }
+  
   application = [WOApplication application];
   handlerPath = [_request requestHandlerPath];
-
+  
 #if 0
-  NSLog(@"[component request handler] path=%@ ..", handlerPath);
+  [self logWithFormat:@"[component request handler] path: '%@'", handlerPath];
 #endif
 
   if (![application allowsConcurrentRequestHandling]) {
   if ([sessionID length] == 0)
     sessionID = [application sessionIDFromRequest:_request];
   
-#if 0
-  NSLog(@"%s: made context %@ (cid=%@, sn=%@) ..", __PRETTY_FUNCTION__
-        context, [context contextID], sessionID);
+#if 1
+  [self logWithFormat:@"%s: made context %@ (cid=%@, sn=%@) ..",
+         __PRETTY_FUNCTION__, context, [context contextID], sessionID];
 #endif
   
   [application awake];
   
   /* restore or create session */
-  if (sessionID) {
+  if ([sessionID isNotNull]) {
     response = [self restoreSessionWithID:sessionID inContext:context];
-    session = response ? nil : [context session];
+    session  = response ? nil : [context session];
+    
+    //[self logWithFormat:@"restored session (id=%@): %@", sessionID, session];
     
-    if (session) {
+    if ([session isNotNull]) {
       /* awake stored page */
       component = [session restorePageForContextID:[context currentElementID]];
       
         response = [application handlePageRestorationErrorInContext:context];
 #if DEBUG
       else {
-        NSLog(@"%s: restored request component %@", __PRETTY_FUNCTION__,
-              component);
+       [self logWithFormat:@"%s: restored request component: %@", 
+               __PRETTY_FUNCTION__, component];
       }
 #endif
     }
   else {
     /* create new session */
     session = [application _initializeSessionInContext:context];
-    if (session) {
+    if ([session isNotNull]) {
       /* awake created session */
       [session awake];
       component = [application pageWithName:nil inContext:context];
     
     /* run invoke-action phase */
     newPage = [application invokeActionForRequest:_request inContext:context];
-
+    
     /* process resulting page */
     if (newPage == nil) {
       if ((newPage = [context page]) == nil) {
     else if ([newPage isKindOfClass:[WOComponent class]])
       [context setPage:newPage];
 
-#if DEBUG
     [self debugWithFormat:@"%s: new page: %@", __PRETTY_FUNCTION__, newPage];
-#endif
     
     /* generate response */
-#if 1 /* new code, ensure that _fixupResponse is called */
+    
     response = [self generateResponseForComponent:[context page]
                     inContext:context
                     application:application];
-#else /* old code */
-    response = [context response];
-    [application appendToResponse:response inContext:context];
-#endif
   }
   else {
     [self warnWithFormat:@"%s: did not enter request/response transaction ...",
             __PRETTY_FUNCTION__];
   }
-
+  
   /* tear down */
 
   /* sleep objects */
   [session sleep];
   
   /* save objects */
-  if (session) {
+  
+  if (session != nil) {
     if ([context savePageRequired])
       [session savePage:[context page]];
     
-    NSLog(@"saving session %@", [session sessionID]);
+    [self logWithFormat:@"saving session %@", [session sessionID]];
+    
+    if ([session storesIDsInCookies]) {
+      [self logWithFormat:@"add cookie to session: %@", session];
+      [self addCookiesForSession:session
+           toResponse:response
+           inContext:context];
+    }
+    
+#if 1
     [application saveSessionForContext:context];
+#else
+    [self saveSession:session
+         inContext:context
+         withResponse:response
+         application:application];
+#endif
   }
   
   [application sleep];