From: helge Date: Mon, 7 May 2007 13:26:15 +0000 (+0000) Subject: code cleanups X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=173dd2df78ffcc47ba62a9e22be6c9ac843d1410;p=sope code cleanups git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1478 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 706496b7..fe257e1e 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,7 @@ +2007-05-07 Helge Hess + + * NGHttp+WO.m, WORequest.m, NGHttp: minor code cleanups (v4.7.9) + 2007-05-07 Helge Hess * WOSession.m: do not attempt to process 'nil' keys when working on diff --git a/sope-appserver/NGObjWeb/NGHttp+WO.m b/sope-appserver/NGObjWeb/NGHttp+WO.m index d3bd3b08..151158d7 100644 --- a/sope-appserver/NGObjWeb/NGHttp+WO.m +++ b/sope-appserver/NGObjWeb/NGHttp+WO.m @@ -1,5 +1,6 @@ /* - Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2000-2007 SKYRIX Software AG + Copyright (C) 2007 Helge Hess This file is part of SOPE. @@ -47,7 +48,7 @@ static Class NSArrayClass = Nil; [self setBody:[_request content]]; /* transfer cookies */ - if ([[_request cookies] count] > 0) + if ([[_request cookies] isNotEmpty]) [self warnWithFormat:@"cannot transfer cookies to NGHttpRequest yet !"]; /* transfer headers !!! */ @@ -198,7 +199,7 @@ static Class NSArrayClass = Nil; cookieValue = [(NGHttpCookie *)_cookie value]; if ([cookieValue isKindOfClass:[NSArray class]]) { - if ([cookieValue count] == 0) + if (![cookieValue isNotEmpty]) cookieValue = @""; else if ([cookieValue count] == 1) cookieValue = [[cookieValue objectAtIndex:0] stringValue]; @@ -346,12 +347,12 @@ static Class DispClass = Nil; char *uribuf; const char *p = uribuf; NGHashMap *map; - + if ((s = [self uri]) == nil) return formContent; if ([s rangeOfString:@"?"].length == 0) return formContent; - + urilen = [s cStringLength]; p = uribuf = malloc(urilen + 4); [s getCString:uribuf]; // UNICODE? @@ -364,7 +365,7 @@ static Class DispClass = Nil; p++; // skip the '?' map = NGDecodeUrlFormParameters((unsigned char *)p, strlen((char *)p)); if (uribuf != NULL) free(uribuf); uribuf = NULL; p = NULL; - + if (map == nil) return formContent; if (formContent == nil) @@ -378,15 +379,15 @@ static Class DispClass = Nil; tmp = formContent; formContent = [[NGMutableHashMap alloc] initWithHashMap:tmp]; - [tmp release]; + [tmp release]; tmp = nil; keys = [map keyEnumerator]; - while ((key = [keys nextObject])) { + while ((key = [keys nextObject]) != nil) { NSEnumerator *values; id value; values = [map objectEnumeratorForKey:key]; - while ((value = [values nextObject])) + while ((value = [values nextObject]) != nil) [formContent addObject:value forKey:key]; } } @@ -397,14 +398,14 @@ static Class DispClass = Nil; tmp = formContent; formContent = [[NGMutableHashMap alloc] initWithDictionary:tmp]; [tmp release]; - + keys = [map keyEnumerator]; - while ((key = [keys nextObject])) { + while ((key = [keys nextObject]) != nil) { NSEnumerator *values; id value; values = [map objectEnumeratorForKey:key]; - while ((value = [values nextObject])) + while ((value = [values nextObject]) != nil) [formContent addObject:value forKey:key]; } } @@ -414,10 +415,8 @@ static Class DispClass = Nil; - (NGHashMap *)formParameters { id formContent; - if (multipartFormData == nil) { - multipartFormData = [NGMimeType mimeType:@"multipart/form-data"]; - multipartFormData = [multipartFormData retain]; - } + if (multipartFormData == nil) + multipartFormData = [[NGMimeType mimeType:@"multipart/form-data"] retain]; if ([[self methodName] isEqualToString:@"POST"]) { NGMimeType *contentType = [self contentType]; diff --git a/sope-appserver/NGObjWeb/NGHttp/ChangeLog b/sope-appserver/NGObjWeb/NGHttp/ChangeLog index 274e4f30..7fd5a360 100644 --- a/sope-appserver/NGObjWeb/NGHttp/ChangeLog +++ b/sope-appserver/NGObjWeb/NGHttp/ChangeLog @@ -1,3 +1,7 @@ +2007-05-07 Helge Hess + + * NGHttpMessageParser.m: minor code cleanups, use -warnWithFormat: + 2006-11-23 Wolfgang Sourdeau * NGHttpRequest.[hm]: added DeltaV HTTP methods diff --git a/sope-appserver/NGObjWeb/NGHttp/NGHttpMessageParser.m b/sope-appserver/NGObjWeb/NGHttp/NGHttpMessageParser.m index 98b30aa3..ba097d50 100644 --- a/sope-appserver/NGObjWeb/NGHttp/NGHttpMessageParser.m +++ b/sope-appserver/NGObjWeb/NGHttp/NGHttpMessageParser.m @@ -1,5 +1,6 @@ /* - Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2000-2007 SKYRIX Software AG + Copyright (C) 2007 Helge Hess This file is part of SOPE. @@ -188,9 +189,8 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { return NO; if (i >= 15) { - NSLog(@"WARNING: truncated request method " - @"(may not longer than 15 chars): %s", - buf); + [self warnWithFormat:@"truncated request method " + @"(may not longer than 15 chars): %s", buf]; } self->methodName = [[NSString alloc] initWithCString:buf length:i]; @@ -226,8 +226,8 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { c = _readByte(self); /* read LF */ if ((c != 10) && (c != -1)) { - NSLog(@"WARNING(%s): missed LF after CR (got %i)\n", - __PRETTY_FUNCTION__, c); + [self warnWithFormat:@"%s: missed LF after CR (got %i)\n", + __PRETTY_FUNCTION__, c]; } } @@ -302,9 +302,9 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { return NO; if (i >= 15) { - NSLog(@"WARNING: truncated request method " + [self warnWithFormat:@"truncated request method " @"(may not longer than 15 chars): %s", - buf); + buf]; } self->methodName = [[NSString alloc] initWithCString:buf length:i]; @@ -319,7 +319,7 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { { /* process path */ NSMutableData *data = nil; - data = [[NSMutableData allocWithZone:[self zone]] initWithCapacity:256]; + data = [[NSMutableData allocWithZone:NULL] initWithCapacity:256]; do { NGAddChar(data, c); c = _readByte(self); @@ -331,7 +331,7 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { return NO; } - self->uri = [[NSString allocWithZone:[self zone]] + self->uri = [[NSString allocWithZone:NULL] initWithCString:[data bytes] length:[data length]]; RELEASE(data); data = nil; } @@ -348,7 +348,7 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { c = _readByte(self); // read LF if (c != 10) - NSLog(@"WARNING: expected LF after CR in request line, got %i", c); + [self warnWithFormat:@"expected LF after CR in request line, got %i", c]; self->version = @"HTTP/0.9"; } @@ -372,12 +372,12 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { } if (i >= 15) { - NSLog(@"WARNING: truncated protocol version " - @"(may not be longer than 15 chars): %s", buf); + [self warnWithFormat:@"truncated protocol version " + @"(may not be longer than 15 chars): %s", buf]; } - self->version = [[NSString allocWithZone:[self zone]] - initWithCString:buf length:i]; + self->version = + [[NSString allocWithZone:NULL] initWithCString:buf length:i]; /* and now read all remaining chars (spaces and CRLF..) */ while ((c != 10) && (c != -1)) @@ -427,9 +427,9 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { return NO; if (i >= 15) { - NSLog(@"WARNING: truncated response version " + [self warnWithFormat:@"truncated response version " @"(may not longer than 15 chars): %s", - buf); + buf]; } self->version = [[NSString alloc] initWithCString:buf length:i]; @@ -457,9 +457,9 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { return NO; if (i >= 5) { - NSLog(@"WARNING: truncated response status " - @"(may not longer than 3 chars): %s", - buf); + [self warnWithFormat:@"truncated response status " + @"(may not longer than 3 chars): %s", + buf]; } self->status = atoi(buf); @@ -476,7 +476,7 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { c = _readByte(self); // read LF if (c != 10) - NSLog(@"WARNING: expected LF after CR in request line, got %i", c); + [self warnWithFormat:@"expected LF after CR in request line, got %i", c]; } else { // HTTP reason text next // to be done .. @@ -531,7 +531,7 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { id clenValues; if (_part == nil) { - NSLog(@"WARNING(%s:%i): got no part !", __PRETTY_FUNCTION__, __LINE__); + [self warnWithFormat:@"%s:%i: got no part!", __PRETTY_FUNCTION__,__LINE__]; return; } @@ -549,9 +549,9 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { else { /* parse until EOF */ #if 0 - NSLog(@"WARNING(%s): parsing until EOF, " + [self warnWithFormat:@"%s: parsing until EOF, " @"missed content-length header in part %@..", - __PRETTY_FUNCTION__, _part); + __PRETTY_FUNCTION__, _part]; #endif doParse = YES; } @@ -562,8 +562,8 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { rq = (NGHttpRequest *)_part; #if DEBUG if (![rq isKindOfClass:[NGHttpRequest class]]) { - NSLog(@"ERROR(%s:%i): got invalid part for request parsing !", - __PRETTY_FUNCTION__, __LINE__); + [self errorWithFormat:@"%s:%i: got invalid part for request parsing !", + __PRETTY_FUNCTION__, __LINE__]; } #endif @@ -575,8 +575,8 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { case NGHttpMethod_UNLOCK: /* never parse body of the requests above */ if ([rq contentLength] > 0) { - [self logWithFormat: - @"WARNING: expected no content with this method !"]; + [self warnWithFormat: + @"expected no content with this method !"]; } doParse = NO; break; @@ -624,7 +624,7 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { { NGHttpRequest *request = nil; - request = [[NGHttpRequest allocWithZone:[self zone]] + request = [[NGHttpRequest allocWithZone:NULL] initWithMethod:_method uri:_uri header:_header @@ -638,7 +638,7 @@ static inline int _skipLWSP(NGHttpMessageParser *self, int _c) { { NGHttpResponse *response = nil; - response = [[NGHttpResponse allocWithZone:[self zone]] + response = [[NGHttpResponse allocWithZone:NULL] initWithStatus:_code reason:_text header:_header diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 78e42d46..831b62d1 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=8 +SUBMINOR_VERSION:=9 # v4.5.234 requires libDOM v4.5.21 # v4.5.214 requires libNGExtensions v4.5.179 diff --git a/sope-appserver/NGObjWeb/WORequest.m b/sope-appserver/NGObjWeb/WORequest.m index 421947d3..e9c004a7 100644 --- a/sope-appserver/NGObjWeb/WORequest.m +++ b/sope-appserver/NGObjWeb/WORequest.m @@ -1,5 +1,6 @@ /* - Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2000-2007 SKYRIX Software AG + Copyright (C) 2007 Helge Hess This file is part of SOPE. @@ -116,21 +117,23 @@ static BOOL debugOn = NO; char *uri; NSString *serverUrl; + // TBD: do not use cString ... uriLen = [self->_uri cStringLength]; - uriBuf = uri = malloc(uriLen + 1); + uriBuf = uri = malloc(uriLen + 4 /* some extra safety ;-) */); [self->_uri getCString:uriBuf]; uriBuf[uriLen] = '\0'; /* determine adaptor prefix */ - if ((serverUrl = [self headerForKey:@"x-webobjects-adaptor-prefix"])) - self->adaptorPrefix = [serverUrl copyWithZone:[self zone]]; + if ((serverUrl = [self headerForKey:@"x-webobjects-adaptor-prefix"]) != nil) + self->adaptorPrefix = [serverUrl copyWithZone:NULL]; if (self->adaptorPrefix == nil) self->adaptorPrefix = @""; - - /* new parse */ - if (uri) { + + /* new parse */ + + if (uri != nil) { const char *start = NULL; /* skip adaptor prefix */ @@ -192,7 +195,7 @@ static BOOL debugOn = NO; /* parsing done (found '\0') */ done: ; // required for MacOSX-S - if (uriBuf) free(uriBuf); + if (uriBuf != nil) free(uriBuf); } }