From: helge Date: Sat, 9 Feb 2008 14:52:58 +0000 (+0000) Subject: properly write HTTP headers on MacOS 10.5 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3901d612fa9f0766aebc7738145917e16275f54f;p=sope properly write HTTP headers on MacOS 10.5 git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1599 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-core/NGStreams/ChangeLog b/sope-core/NGStreams/ChangeLog index aa19ac03..bab4db4d 100644 --- a/sope-core/NGStreams/ChangeLog +++ b/sope-core/NGStreams/ChangeLog @@ -1,3 +1,8 @@ +2008-02-09 Helge Hess + + * NGCTextStream.m: fixed -writeString: on MacOS > 10.4, use + -maximumLengthOfBytesUsingEncoding: (v4.7.56) + 2007-12-03 Helge Hess * NGCTextStream.m: replaced usage of getCString on MacOS > 10.4 diff --git a/sope-core/NGStreams/NGCTextStream.m b/sope-core/NGStreams/NGCTextStream.m index 3e40a3df..cb9bee41 100644 --- a/sope-core/NGStreams/NGCTextStream.m +++ b/sope-core/NGStreams/NGCTextStream.m @@ -1,6 +1,6 @@ /* - Copyright (C) 2000-2007 SKYRIX Software AG - Copyright (C) 2007 Helge Hess + Copyright (C) 2000-2008 SKYRIX Software AG + Copyright (C) 2007-2008 Helge Hess This file is part of SOPE. @@ -110,8 +110,11 @@ static void _flushAtExit(void) { [self release]; return nil; } - if ((self = [super init])) { + if ((self = [super init]) != nil) { self->source = [_stream retain]; + + /* On MacOS 10.5 this is per default 30 aka MacOS Roman */ + self->encoding = [NSString defaultCStringEncoding]; #ifdef __APPLE__ //# warning no selector caching on MacOSX ... @@ -256,7 +259,8 @@ static void _flushAtExit(void) { autorelease]; } -// NGTextOutputStream + +/* NGTextOutputStream */ - (BOOL)writeCharacter:(unichar)_character { unsigned char c; @@ -266,16 +270,16 @@ static void _flushAtExit(void) { // character is not in range of maximum system encoding [NSException raise:@"NGCTextStreamEncodingException" format: - @"called writeCharacter: with character code (0x%X) exceeding" - @" the maximum system character code (0x%X)", + @"called writeCharacter: with character code (0x%X)" + @" exceeding the maximum system character code (0x%X)", _character, ((sizeof(unsigned char) * 256) - 1)]; } c = _character; - if (writeBytes) { - res = writeBytes(self->source, @selector(writeBytes:count:), - &c, sizeof(unsigned char)); + if (self->writeBytes != NULL) { + res = self->writeBytes(self->source, @selector(writeBytes:count:), + &c, sizeof(unsigned char)); } else res = [self->source writeBytes:&c count:sizeof(unsigned char)]; @@ -293,22 +297,30 @@ static void _flushAtExit(void) { unsigned toGo; #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 - NSStringEncoding enc = [NSString defaultCStringEncoding]; - - // TBD: better use -maximumLengthOf... and then search for \0 - if ((toGo = [_string lengthOfBytesUsingEncoding:enc]) == 0) + if ((toGo = [_string maximumLengthOfBytesUsingEncoding:self->encoding]) == 0) return YES; - - buf = str = calloc(toGo + 1, sizeof(unsigned char)); - [_string getCString:(char *)str maxLength:toGo encoding:enc]; + + buf = str = calloc(toGo + 2, sizeof(unsigned char)); + // Note: maxLength INCLUDES the 0-terminator. And -getCString: does + // 0-terminate the buffer + if (![_string getCString:(char *)str maxLength:(toGo + 1) + encoding:self->encoding]) { + NSLog(@"ERROR(%s): failed to extract cString in defaultCStringEncoding(%i)" + @" from NSString: '%@'\n", __PRETTY_FUNCTION__, + self->encoding, _string); + return NO; + } + + // we need to update the *real* (not the max) length + toGo = strlen((char *)str); #else if ((toGo = [_string cStringLength]) == 0) return YES; - buf = str = calloc(toGo + 1, sizeof(unsigned char)); + buf = str = calloc(toGo + 2, sizeof(unsigned char)); [_string getCString:(char *)str]; -#endif str[toGo] = '\0'; +#endif NS_DURING { while (toGo > 0) { diff --git a/sope-core/NGStreams/NGStreams/NGCTextStream.h b/sope-core/NGStreams/NGStreams/NGCTextStream.h index f2529a68..9388710e 100644 --- a/sope-core/NGStreams/NGStreams/NGCTextStream.h +++ b/sope-core/NGStreams/NGStreams/NGCTextStream.h @@ -1,5 +1,6 @@ /* - Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2000-2008 SKYRIX Software AG + Copyright (C) 2008 Helge Hess This file is part of SOPE. @@ -56,6 +57,7 @@ NGStreams_EXPORT void NGInitTextStdio(void); NGIOReadMethodType readBytes; NGIOWriteMethodType writeBytes; BOOL (*flushBuffer)(id, SEL); + NSStringEncoding encoding; } + (id)textStreamWithInputSource:(id)_source; diff --git a/sope-core/NGStreams/Version b/sope-core/NGStreams/Version index 1e1b1b4f..0d71e766 100644 --- a/sope-core/NGStreams/Version +++ b/sope-core/NGStreams/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=55 +SUBMINOR_VERSION:=56