tweak logging in NSURLProtocol to cope with nul bytes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38950 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2015-08-29 21:13:14 +00:00
parent 5ff4f40d40
commit 1fbc464141

View file

@ -36,6 +36,7 @@
#import "GSTLS.h"
#import "GSURLPrivate.h"
#import "GNUstepBase/GSMime.h"
#import "GNUstepBase/NSData+GNUstepBase.h"
#import "GNUstepBase/NSString+GNUstepBase.h"
#import "GNUstepBase/NSURL+GNUstepBase.h"
@ -46,6 +47,7 @@
#endif
#define USE_ZLIB 0
#if USE_ZLIB
#if defined(HAVE_ZLIB_H)
#include <zlib.h>
@ -66,6 +68,61 @@ zfree(void *opaque, void *mem)
#endif
#endif
static void
debugRead(id handle, unsigned len, const unsigned char *ptr)
{
int pos;
NSData *data;
data = [[NSData alloc] initWithBytesNoCopy: (void*)ptr
length: len
freeWhenDone: NO];
for (pos = 0; pos < len; pos++)
{
if (0 == ptr[pos])
{
char *esc = [data escapedRepresentation: 0];
NSLog(@"Read for %p of %u bytes (escaped) - '%s'\n%@",
handle, len, esc, data);
free(esc);
RELEASE(data);
return;
}
}
NSLog(@"Read for %p of %d bytes - '%*.*s'\n%@",
handle, len, len, len, ptr, data);
RELEASE(data);
}
static void
debugWrite(id handle, unsigned len, const unsigned char *ptr)
{
int pos;
NSData *data;
data = [[NSData alloc] initWithBytesNoCopy: (void*)ptr
length: len
freeWhenDone: NO];
for (pos = 0; pos < len; pos++)
{
if (0 == ptr[pos])
{
char *esc = [data escapedRepresentation: 0];
NSLog(@"Write for %p of %u bytes (escaped) - '%s'\n%@",
handle, len, esc, data);
free(esc);
RELEASE(data);
return;
}
}
NSLog(@"Write for %p of %d bytes - '%*.*s'\n%@",
handle, len, len, len, ptr, data);
RELEASE(data);
}
@interface GSSocketStreamPair : NSObject
{
NSInputStream *ip;
@ -887,8 +944,7 @@ static NSURLProtocol *placeholder = nil;
}
if (_debug)
{
NSLog(@"%@ read %d bytes: '%*.*s'",
self, readCount, readCount, readCount, buffer);
debugRead(self, readCount, buffer);
}
if (_parser == nil)
@ -1508,8 +1564,7 @@ static NSURLProtocol *placeholder = nil;
{
if (_debug == YES)
{
NSLog(@"%@ wrote %d bytes: '%*.*s'", self, written,
written, written, bytes + _writeOffset);
debugWrite(self, written, bytes + _writeOffset);
}
_writeOffset += written;
if (_writeOffset >= len)
@ -1566,8 +1621,7 @@ static NSURLProtocol *placeholder = nil;
{
if (_debug == YES)
{
NSLog(@"%@ wrote %d bytes: '%*.*s'", self,
written, written, written, buffer);
debugWrite(self, written, buffer);
}
len -= written;
if (len > 0)