]> err.no Git - sope/blobdiff - sope-appserver/NGObjWeb/WODirectActionRequestHandler.m
increased element nesting depth
[sope] / sope-appserver / NGObjWeb / WODirectActionRequestHandler.m
index a73aa3800fd1054ee5ea2a75069d4b43540537d6..e9b1e930c8a9cdbc25c0c7174142636831066837 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.
 */
 #  include <objc/objc-class.h>
 #endif
 
+static BOOL  usePool = NO;
 static BOOL  perflog = NO;
+static BOOL  debugOn = NO;
 static Class NSDateClass = Nil;
 
-//#define USE_POOLS 1
-
 @implementation WODirectActionRequestHandler
 
 + (int)version {
   return [super version] + 0 /* 2 */;
 }
 + (void)initialize {
+  NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
+  
   NSAssert2([super version] == 2,
             @"invalid superclass (%@) version %i !",
             NSStringFromClass([self superclass]), [super version]);
 
   NSDateClass = [NSDate class];
-  perflog = [[NSUserDefaults standardUserDefaults]
-                             boolForKey:@"WOProfileDirectActionRequestHandler"];
+  perflog = [ud boolForKey:@"WOProfileDirectActionRequestHandler"];
 }
 
 - (NSString *)loggingPrefix {
@@ -62,14 +63,14 @@ static Class NSDateClass = Nil;
 
 /*
   The request handler part of a direct action URI looks like this:
-
+  
     [actionClass/]actionName[?key=value&key=value&...]
 */
 
 - (BOOL)isComponentClass:(Class)_clazz {
   if (_clazz == Nil) 
     return NO;
-  while ((_clazz = _clazz->super_class)) {
+  while ((_clazz = _clazz->super_class) != Nil) {
     if (_clazz == [WOComponent    class]) return YES;
     if (_clazz == [WODirectAction class]) return NO;
     if (_clazz == [NSObject       class]) return NO;
@@ -85,6 +86,7 @@ static Class NSDateClass = Nil;
   
   if (actionClass == Nil)
     return nil;
+  
   if (![self isComponentClass:actionClass]) {
     /* create direct action object */
     id actionObject;
@@ -121,16 +123,16 @@ static Class NSDateClass = Nil;
   session:(WOSession *)session
   application:(WOApplication *)app
 {
-#if USE_POOLS
-  NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init];
-#endif
-  NSString      *actionClassName;
-  NSString      *actionName;
-  WOResponse    *response;
-  NSArray       *handlerPath;
-  Class         actionClass = Nil;
+  NSAutoreleasePool   *pool2;
+  NSString            *actionClassName;
+  NSString            *actionName;
+  WOResponse          *response;
+  NSArray             *handlerPath;
+  Class               actionClass = Nil;
   WODirectAction      *actionObject = nil;
   id<WOActionResults> result = nil;
+
+  pool2 = usePool ? [[NSAutoreleasePool alloc] init] : nil;
   
   *(&result) = nil;
   *(&response)        = nil;
@@ -142,11 +144,12 @@ static Class NSDateClass = Nil;
   
   handlerPath = [_request requestHandlerPathArray];
 
-#if DEBUG_DIRECT_ACTION
-  [self debugWithFormat:@"path=%@ array=%@",
+  if (debugOn) {
+    [self debugWithFormat:@"path=%@ array=%@",
           [_request requestHandlerPath], handlerPath];
-#endif
-
+  }
+  
+  // TODO: fix OGo bug #1028
   switch ([handlerPath count]) {
     case 0:
       actionClassName = @"DirectAction";
@@ -164,10 +167,11 @@ static Class NSDateClass = Nil;
     default:
       actionClassName = [handlerPath objectAtIndex:0];
       actionName      = [handlerPath objectAtIndex:1];
-#if 0
-      NSLog(@"invalid direction action URL: %@",
-              [_request requestHandlerPath]);
-#endif
+      // TODO: set path info in ctx?
+      if (debugOn) {
+       [self logWithFormat:@"invalid direction action URL: %@",
+                [_request requestHandlerPath]];
+      }
       break;
   }
 
@@ -180,11 +184,11 @@ static Class NSDateClass = Nil;
     actionClass = [WODirectAction class];
   }
   
-#if DEBUG_DIRECT_ACTION
-  [self debugWithFormat:
-          @"[direct action request handler] class=%@ action=%@ ..",
-          actionClassName, actionName];
-#endif
+  if (debugOn) {
+    [self debugWithFormat:
+           @"[direct action request handler] class=%@ action=%@ ..",
+            actionClassName, actionName];
+  }
   
   /* process request */
   
@@ -238,11 +242,11 @@ static Class NSDateClass = Nil;
       [session lock];
     }
     
-#if USE_POOLS
-    session = [session retain];
-    [pool2 release]; pool2 = nil;
-    session = [session autorelease];
-#endif
+    if (usePool) {
+      session = [session retain];
+      [pool2 release]; pool2 = nil;
+      session = [session autorelease];
+    }
     response = [response autorelease];
   }