From: helge Date: Sun, 10 Oct 2004 13:37:36 +0000 (+0000) Subject: fixed umlaut issue on MacOSX X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8a5dd52f379dff1aa531eae2e56903bf06566a0;p=sope fixed umlaut issue on MacOSX git-svn-id: http://svn.opengroupware.org/SOPE/trunk@239 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 9a9ff266..759c20c7 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,8 @@ +2004-10-10 Helge Hess + + * NGHttp: fixed umlaut decoding on MacOSX, removed some unused code + (v4.3.58) + 2004-10-08 Helge Hess * WebDAV/SoObjectDataSource.m: ensure that the child key used for diff --git a/sope-appserver/NGObjWeb/NGHttp/ChangeLog b/sope-appserver/NGObjWeb/NGHttp/ChangeLog index 8610f695..01dcb7df 100644 --- a/sope-appserver/NGObjWeb/NGHttp/ChangeLog +++ b/sope-appserver/NGObjWeb/NGHttp/ChangeLog @@ -1,3 +1,10 @@ +2004-10-10 Helge Hess + + * NGUrlFormCoder.m: print a warning if the deprecated + -stringByApplyingURLEncoding method is used instead of + -stringByEscapingURL, removed unused isURLSafeChar() function, fixed + decoding of form values containing umlauts on MacOSX + 2004-09-21 Marcus Mueller * NGHttp.xcode: minor changes diff --git a/sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.h b/sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.h index ab380700..66caae30 100644 --- a/sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.h +++ b/sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.h @@ -1,7 +1,7 @@ /* - Copyright (C) 2000-2003 SKYRIX Software AG + Copyright (C) 2000-2004 SKYRIX Software AG - This file is part of OGo + This file is part of OpenGroupware.org. OGo 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 @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #ifndef __NGHttp_NGHttpBodyParser_H__ #define __NGHttp_NGHttpBodyParser_H__ diff --git a/sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.m b/sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.m index c3e4f04d..70f14b59 100644 --- a/sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.m +++ b/sope-appserver/NGObjWeb/NGHttp/NGHttpBodyParser.m @@ -1,7 +1,7 @@ /* - Copyright (C) 2000-2003 SKYRIX Software AG + Copyright (C) 2000-2004 SKYRIX Software AG - This file is part of OGo + This file is part of OpenGroupware.org. OGo 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 @@ -18,23 +18,26 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ -#import "common.h" -#import "NGHttpBodyParser.h" -#import "NGUrlFormCoder.h" +#include "NGHttpBodyParser.h" +#include "NGUrlFormCoder.h" +#include "common.h" @implementation NGFormUrlBodyParser -- (id)parseBodyOfPart:(id)_part data:(NSData *)_data delegate:(id)_d { +- (id)parseBodyOfPart:(id)_part data:(NSData *)_data + delegate:(id)_d +{ const char *bytes; unsigned len; id body; + [self logWithFormat:@"parse part %@ data: %@", _part, _data]; + len = [_data length]; bytes = [_data bytes]; - - // cut off spaces at the end + + /* cut off spaces at the end */ while (len > 0) { if ((bytes[len - 1] == '\r') || (bytes[len - 1] == '\n')) len--; @@ -42,7 +45,7 @@ break; } if (len == 0) return nil; - + body = NGDecodeUrlFormParameters(bytes, len); return [body autorelease]; } @@ -66,7 +69,9 @@ return YES; } -- (id)parseBodyOfPart:(id)_part data:(NSData *)_data delegate:(id)_d { +- (id)parseBodyOfPart:(id)_part data:(NSData *)_data + delegate:(id)_d +{ NGMimeMultipartBody *body; body = [super parseBodyOfPart:_part data:_data delegate:_d]; diff --git a/sope-appserver/NGObjWeb/NGHttp/NGUrlFormCoder.h b/sope-appserver/NGObjWeb/NGHttp/NGUrlFormCoder.h index 57593b7b..c6594e02 100644 --- a/sope-appserver/NGObjWeb/NGHttp/NGUrlFormCoder.h +++ b/sope-appserver/NGObjWeb/NGHttp/NGUrlFormCoder.h @@ -1,7 +1,7 @@ /* - Copyright (C) 2000-2003 SKYRIX Software AG + Copyright (C) 2000-2004 SKYRIX Software AG - This file is part of OGo + This file is part of OpenGroupware.org. OGo 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 @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #ifndef __NGHttp_NGUrlFormCoder_H__ #define __NGHttp_NGUrlFormCoder_H__ @@ -33,8 +32,10 @@ The _buffer parameter starts with the string after the '?' in a URI, that is, the buffer is _not_ the complete URI. The function returns a retained hashmap. + + TODO: should be moved to NGExtensions */ -NGHashMap *NGDecodeUrlFormParameters(const char *_buffer, unsigned _len); +NGHashMap *NGDecodeUrlFormParameters(const unsigned char *_buf, unsigned _len); #if 0 /* do not use, use NGExtensions/NSString+misc.h ... */ @interface NSString(FormURLCoding) diff --git a/sope-appserver/NGObjWeb/NGHttp/NGUrlFormCoder.m b/sope-appserver/NGObjWeb/NGHttp/NGUrlFormCoder.m index 7f3748a2..f30a7dc4 100644 --- a/sope-appserver/NGObjWeb/NGHttp/NGUrlFormCoder.m +++ b/sope-appserver/NGObjWeb/NGHttp/NGUrlFormCoder.m @@ -1,7 +1,7 @@ /* - Copyright (C) 2000-2003 SKYRIX Software AG + Copyright (C) 2000-2004 SKYRIX Software AG - This file is part of OGo + This file is part of OpenGroupware.org. OGo 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 @@ -18,28 +18,13 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ -#import "common.h" -#import "NGUrlFormCoder.h" +#include "NGUrlFormCoder.h" +#include "common.h" -static inline BOOL isURLSafeChar(unsigned char _c) { - if ((_c > 64) && (_c < 91)) - return YES; +static BOOL debugDecoding = NO; - if ((_c > 96) && (_c < 123)) - return YES; - - if (_c == 95) - return YES; - - if ((_c > 47) && (_c < 58)) - return YES; - - return NO; -} - -static inline int _valueOfHexChar(unsigned char _c) { +static __inline__ int _valueOfHexChar(unsigned char _c) { switch (_c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -58,7 +43,9 @@ static inline int _valueOfHexChar(unsigned char _c) { } } -static inline unsigned _unescapeUrl(const char *_src, unsigned _len, char *_dest) { +static __inline__ unsigned +_unescapeUrl(const char *_src, unsigned _len, char *_dest) +{ register unsigned i, i2; for (i = 0, i2 = 0; i < _len; i++, i2++) { @@ -83,13 +70,42 @@ static inline unsigned _unescapeUrl(const char *_src, unsigned _len, char *_dest return i2; // return unescaped length } -NGHashMap *NGDecodeUrlFormParameters(const char *_buffer, unsigned _len) { - Class StrClass = [NSString class]; +static Class StrClass = Nil; + +static __inline__ NSString *urlStringFromBuffer(const unsigned char *buffer, + unsigned len) +{ + // TODO: we assume ISO-Latin-1/Unicode encoding, which might be wrong +#if LIB_FOUNDATION_LIBRARY + return [[StrClass alloc] initWithCString:buffer length:len]; +#else + register signed int i; + unichar *s; + NSString *value; + + s = malloc((len + 2) * sizeof(unichar)); + for (i = len - 1; i >= 0; i--) + s[i] = buffer[i]; + value = [[StrClass alloc] initWithCharacters:s length:len]; + if (s != NULL) free(s); + + if (debugDecoding) { + NSLog(@"decoded data len %d value (len=%d): %@", + len, [value length], value); + } + return value; +#endif +} + +NGHashMap *NGDecodeUrlFormParameters(const unsigned char *_buffer, + unsigned _len) +{ NGMutableHashMap *dict = nil; unsigned pos = 0; if (_len == 0) return nil; - + + if (StrClass == Nil) StrClass = [NSString class]; dict = [[NGMutableHashMap alloc] initWithCapacity:16]; do { @@ -103,15 +119,8 @@ NGHashMap *NGDecodeUrlFormParameters(const char *_buffer, unsigned _len) { pos++; len = _unescapeUrl(&(_buffer[tmp]), (pos - tmp), buffer); - if (len > 0) { - key = [[StrClass allocWithZone:[dict zone]] - initWithCString:buffer length:len]; - } - else - key = @""; - - //NSLog(@"read key %@", key); - + key = len > 0 ? urlStringFromBuffer(buffer, len) : @""; + if (pos < _len) { // value pending NSCAssert(_buffer[pos] == '=', @"invalid parser state .."); pos++; // skip '=' @@ -122,16 +131,8 @@ NGHashMap *NGDecodeUrlFormParameters(const char *_buffer, unsigned _len) { pos++; } - len = _unescapeUrl(&(_buffer[tmp]), (pos - tmp), buffer); - - if (len > 0) { - value = [[StrClass allocWithZone:[dict zone]] - initWithCString:buffer length:len]; - } - else - value = @""; - - //NSLog(@"read value: %@", value); + len = _unescapeUrl(&(_buffer[tmp]), (pos - tmp), buffer); + value = len > 0 ? urlStringFromBuffer(buffer, len) : @""; // skip '&' if (_buffer[pos] == '&' || _buffer[pos] == '?') pos++; @@ -144,8 +145,8 @@ NGHashMap *NGDecodeUrlFormParameters(const char *_buffer, unsigned _len) { if (key) [dict addObject:value forKey:key]; - RELEASE(key); key = nil; - RELEASE(value); value = nil; + [key release]; key = nil; + [value release]; value = nil; } while (pos < _len); @@ -155,40 +156,10 @@ NGHashMap *NGDecodeUrlFormParameters(const char *_buffer, unsigned _len) { @implementation NSString(FormURLCoding) - (NSString *)stringByApplyingURLEncoding { -#if 1 /* NGExtensions/NSString+misc.h */ + NSLog(@"Note: Called deprecated -stringByApplyingURLEncoding method " + @"(use -stringByEscapingURL instead)", __PRETTY_FUNCTION__); return [self stringByEscapingURL]; -#else - char *buf, *encBuf; - unsigned clen, i, j; - - if ((clen = [self cStringLength]) == 0) - return self; - - buf = malloc(clen + 1); - [self getCString:buf]; buf[clen] = '\0'; - - encBuf = malloc(clen * 3 + 1); - - for (i = 0, j = 0; i < clen; i++) { - register unsigned char c = buf[i]; - - if (isURLSafeChar(c)) { - encBuf[j] = c; - j++; - } - else if (c == ' ') { - encBuf[j] = '+'; - j++; - } - else { - sprintf(&(encBuf[j]), "%%%02X", (int)c); - j += 3; - } - } - return [NSString stringWithCString:encBuf length:j]; - /* was buggy, does not release encbuf .. */ -#endif } @end /* NSString(FormURLCoding) */ diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index dbfcd8ee..83f5ba03 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=57 +SUBMINOR_VERSION:=58 # v4.3.42 requires libNGExtensions v4.3.116 # v4.3.40 requires libNGExtensions v4.3.115