mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-20 20:26:42 +00:00
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:
parent
5ff4f40d40
commit
1fbc464141
1 changed files with 60 additions and 6 deletions
|
@ -36,6 +36,7 @@
|
||||||
#import "GSTLS.h"
|
#import "GSTLS.h"
|
||||||
#import "GSURLPrivate.h"
|
#import "GSURLPrivate.h"
|
||||||
#import "GNUstepBase/GSMime.h"
|
#import "GNUstepBase/GSMime.h"
|
||||||
|
#import "GNUstepBase/NSData+GNUstepBase.h"
|
||||||
#import "GNUstepBase/NSString+GNUstepBase.h"
|
#import "GNUstepBase/NSString+GNUstepBase.h"
|
||||||
#import "GNUstepBase/NSURL+GNUstepBase.h"
|
#import "GNUstepBase/NSURL+GNUstepBase.h"
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@
|
||||||
#endif
|
#endif
|
||||||
#define USE_ZLIB 0
|
#define USE_ZLIB 0
|
||||||
|
|
||||||
|
|
||||||
#if USE_ZLIB
|
#if USE_ZLIB
|
||||||
#if defined(HAVE_ZLIB_H)
|
#if defined(HAVE_ZLIB_H)
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
@ -66,6 +68,61 @@ zfree(void *opaque, void *mem)
|
||||||
#endif
|
#endif
|
||||||
#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
|
@interface GSSocketStreamPair : NSObject
|
||||||
{
|
{
|
||||||
NSInputStream *ip;
|
NSInputStream *ip;
|
||||||
|
@ -887,8 +944,7 @@ static NSURLProtocol *placeholder = nil;
|
||||||
}
|
}
|
||||||
if (_debug)
|
if (_debug)
|
||||||
{
|
{
|
||||||
NSLog(@"%@ read %d bytes: '%*.*s'",
|
debugRead(self, readCount, buffer);
|
||||||
self, readCount, readCount, readCount, buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_parser == nil)
|
if (_parser == nil)
|
||||||
|
@ -1508,8 +1564,7 @@ static NSURLProtocol *placeholder = nil;
|
||||||
{
|
{
|
||||||
if (_debug == YES)
|
if (_debug == YES)
|
||||||
{
|
{
|
||||||
NSLog(@"%@ wrote %d bytes: '%*.*s'", self, written,
|
debugWrite(self, written, bytes + _writeOffset);
|
||||||
written, written, bytes + _writeOffset);
|
|
||||||
}
|
}
|
||||||
_writeOffset += written;
|
_writeOffset += written;
|
||||||
if (_writeOffset >= len)
|
if (_writeOffset >= len)
|
||||||
|
@ -1566,8 +1621,7 @@ static NSURLProtocol *placeholder = nil;
|
||||||
{
|
{
|
||||||
if (_debug == YES)
|
if (_debug == YES)
|
||||||
{
|
{
|
||||||
NSLog(@"%@ wrote %d bytes: '%*.*s'", self,
|
debugWrite(self, written, buffer);
|
||||||
written, written, written, buffer);
|
|
||||||
}
|
}
|
||||||
len -= written;
|
len -= written;
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue