]> err.no Git - sope/blobdiff - sope-appserver/NGObjWeb/WOSimpleHTTPParser.m
fixed duplicate -awake
[sope] / sope-appserver / NGObjWeb / WOSimpleHTTPParser.m
index 25471b1fd9b0a029581c88243f9e2a423eba7ec3..dba94fa583e96e1a31db203f11aeb2b3fbab0263 100644 (file)
@@ -1,24 +1,23 @@
 /*
-  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.
 */
-// $Id$
 
 #include "WOSimpleHTTPParser.h"
 #include <NGObjWeb/WOResponse.h>
@@ -30,8 +29,8 @@
 static Class NSStringClass  = Nil;
 static BOOL  debugOn        = NO;
 static BOOL  heavyDebugOn   = NO;
-static int   fileIOBoundary = 16384;
-static int   maxUploadSize  = 256 * 1024; /* 256MB */
+static int   fileIOBoundary = 0;
+static int   maxUploadSize  = 0;
 
 + (int)version {
   return 1;
@@ -43,7 +42,12 @@ static int   maxUploadSize  = 256 * 1024; /* 256MB */
   heavyDebugOn   = [ud boolForKey:@"WOSimpleHTTPParserHeavyDebugEnabled"];
   fileIOBoundary = [ud integerForKey:@"WOSimpleHTTPParserFileIOBoundary"];
   maxUploadSize  = [ud integerForKey:@"WOSimpleHTTPParserMaxUploadSizeInKB"];
-
+  
+  if (maxUploadSize == 0)
+    maxUploadSize = 256 * 1024; /* 256MB */
+  if (fileIOBoundary == 0)
+    fileIOBoundary = 16384;
+  
   if (debugOn) {
     NSLog(@"WOSimpleHTTPParser: max-upload-size:  %dKB", maxUploadSize);
     NSLog(@"WOSimpleHTTPParser: file-IO boundary: %d",   fileIOBoundary);
@@ -62,8 +66,9 @@ static int   maxUploadSize  = 256 * 1024; /* 256MB */
     self->readBytes = (void *)
       [(NSObject *)self->io methodForSelector:@selector(readBytes:count:)];
     if (self->readBytes == NULL) {
-      NSLog(@"WARNING(%s): got invalid stream object: %@", __PRETTY_FUNCTION__,
-           self->io);
+      [self warnWithFormat:@"(%s): got invalid stream object: %@",
+        __PRETTY_FUNCTION__,
+             self->io];
       [self release];
       return nil;
     }
@@ -128,9 +133,9 @@ static int   maxUploadSize  = 256 * 1024; /* 256MB */
        static BOOL didLog = NO;
        if (!didLog) {
          didLog = YES;
-         NSLog(@"WARNING(%s): reallocated the HTTP line buffer %i times, "
-               @"consider increasing the default line buffer size!",
-               __PRETTY_FUNCTION__, reallocCount);
+         [self warnWithFormat:@"(%s): reallocated the HTTP line buffer %i times, "
+            @"consider increasing the default line buffer size!",
+            __PRETTY_FUNCTION__, reallocCount];
        }
       }
       
@@ -460,16 +465,16 @@ static NSString *stringForHeaderName(unsigned char *p) {
     
     if (*p == ' ' || *p == '\t') {
       // TODO: implement folding (remember last header-key, add string)
-      [self logWithFormat:
-              @"ERROR(%s): got a folded HTTP header line, cannot process!",
-             __PRETTY_FUNCTION__];
+      [self errorWithFormat:
+              @"(%s): got a folded HTTP header line, cannot process!",
+              __PRETTY_FUNCTION__];
       continue;
     }
     
     /* find key/value separator */
     if ((v = index(p, ':')) == NULL) {
-      [self logWithFormat:@"WARNING: got malformed header line: '%s'",
-             self->lineBuffer];
+      [self warnWithFormat:@"got malformed header line: '%s'",
+              self->lineBuffer];
       continue;
     }
     
@@ -537,18 +542,19 @@ static NSString *stringForHeaderName(unsigned char *p) {
        readToEOF = NO;
       
       if (readToEOF) {
-       [self logWithFormat:
-               @"WARNING: not processing entity of request "
-               @"without contentlen!"];
+        [self warnWithFormat:
+                @"not processing entity of request without contentlen!"];
       }
     }
   }
   else if (self->clen > maxUploadSize*1024) {
     /* entity is too large */
+    NSString *s;
+
+    s = [NSString stringWithFormat:@"The maximum HTTP transaction size was "
+                  @"exceeded (%d vs %d)", self->clen, maxUploadSize * 1024];
     return [NSException exceptionWithName:@"LimitException"
-                       reason:
-                         @"the maximum HTTP transaction size was exceeded"
-                       userInfo:nil];
+                       reason:s userInfo:nil];
   }
   else if (self->clen > fileIOBoundary) {
     /* we are streaming the content to a file and use a memory mapped data */
@@ -564,7 +570,7 @@ static NSString *stringForHeaderName(unsigned char *p) {
     fn = [[NSProcessInfo processInfo] temporaryFileName];
     
     if ((t = fopen([fn cString], "w")) == NULL) {
-      [self logWithFormat:@"ERROR: could not open temporary file '%@'!", fn];
+      [self errorWithFormat:@"could not open temporary file '%@'!", fn];
       
       /* read into memory as a fallback ... */