Some debugging added

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@11614 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2001-12-03 15:29:08 +00:00
parent 6bb527278f
commit 3e31f7a2e7
3 changed files with 70 additions and 22 deletions

View file

@ -4,6 +4,8 @@
maintain byte order and word size compatibility.
* Source/GSValue.m: ditto
* Testing/values.m: added encoding/decoding tests.
* Source/GSMime.m: Tidied handling of continuations a little.
* Source/GSHTTPURLHandle.m: Added some debug logging.
Sat Dec 1 10:11:18 2001 Nicola Pero <n.pero@mi.flashnet.it>

View file

@ -37,8 +37,11 @@
#include <Foundation/NSDebug.h>
#include <Foundation/GSMime.h>
#include <string.h>
#include <unistd.h>
#include <sys/file.h>
static NSString *httpVersion = @"1.1";
static BOOL debug = NO;
char emp[64] = {
'A','B','C','D','E','F','G','H','I','J','K','L','M',
@ -77,6 +80,33 @@ char emp[64] = {
static NSMutableDictionary *urlCache = nil;
static NSLock *urlLock = nil;
static void debugRead(NSData *data)
{
NSString *s = [NSString stringWithFormat: @"/tmp/GSHTTP.%d", getpid()];
int d = open([s cString], O_WRONLY|O_CREAT|O_APPEND, 0644);
if (d >= 0)
{
s = [NSString stringWithFormat: @"\nRead %@ -\n", [NSDate date]];
write(d, [s cString], [s cStringLength]);
write(d, [data bytes], [data length]);
close(d);
}
}
static void debugWrite(NSData *data)
{
NSString *s = [NSString stringWithFormat: @"/tmp/GSHTTP.%d", getpid()];
int d = open([s cString], O_WRONLY|O_CREAT|O_APPEND, 0644);
if (d >= 0)
{
s = [NSString stringWithFormat: @"\nWrite %@ -\n", [NSDate date]];
write(d, [s cString], [s cStringLength]);
write(d, [data bytes], [data length]);
close(d);
}
}
+ (NSURLHandle*) cachedHandleForURL: (NSURL*)newUrl
{
NSURLHandle *obj = nil;
@ -104,6 +134,11 @@ static NSLock *urlLock = nil;
}
}
+ (void) setDebug: (BOOL)flag
{
debug = flag;
}
- (void) dealloc
{
RELEASE(sock);
@ -160,6 +195,8 @@ static NSLock *urlLock = nil;
NSData *d;
d = [dict objectForKey: NSFileHandleNotificationDataItem];
if (debug == YES) debugRead(d);
[parser parse: d];
if ([parser isComplete] == YES)
{
@ -204,6 +241,7 @@ static NSLock *urlLock = nil;
GSMimeParser *p = [GSMimeParser new];
d = [dict objectForKey: NSFileHandleNotificationDataItem];
if (debug == YES) debugRead(d);
if ([d length] > 0)
{
@ -387,6 +425,7 @@ static NSLock *urlLock = nil;
NSString *cmd;
NSTimeInterval last = 0.0;
NSTimeInterval limit = 0.01;
NSData *buf;
NSDate *when;
NSString *status;
@ -415,8 +454,9 @@ static NSLock *urlLock = nil;
name: GSFileHandleWriteCompletionNotification
object: sock];
[sock writeInBackgroundAndNotify:
[cmd dataUsingEncoding: NSASCIIStringEncoding]];
buf = [cmd dataUsingEncoding: NSASCIIStringEncoding];
[sock writeInBackgroundAndNotify: buf];
if (debug == YES) debugWrite(buf);
when = [NSDate alloc];
while (tunnel == YES)
@ -544,6 +584,7 @@ static NSLock *urlLock = nil;
* Send request to server.
*/
[sock writeInBackgroundAndNotify: buf];
if (debug == YES) debugWrite(buf);
RELEASE(buf);
RELEASE(s);

View file

@ -812,8 +812,6 @@ parseCharacterSet(NSString *token)
}
if ([d length] > 0)
{
NSDictionary *info;
if (inBody == NO)
{
[data appendBytes: [d bytes] length: [d length]];
@ -848,28 +846,35 @@ parseCharacterSet(NSString *token)
*/
d = AUTORELEASE([data copy]);
[data setLength: 0];
}
/*
* We may have http continuation header(s)
*/
info = [[document headersNamed: @"http"] lastObject];
if (info != nil)
{
NSString *val;
val = [info objectForKey: NSHTTPPropertyStatusCodeKey];
if (val != nil)
/*
* If we have finished parsing the headers, we may have http
* continuation header(s), in which case, we must start parsing
* headers again.
*/
if (inBody == YES)
{
int v = [val intValue];
NSDictionary *info;
if (v >= 100 && v < 200)
info = [[document headersNamed: @"http"] lastObject];
if (info != nil)
{
/*
* This is an intermediary response ... so we have to
* restart the parsing operation!
*/
inBody = NO;
NSString *val;
val = [info objectForKey: NSHTTPPropertyStatusCodeKey];
if (val != nil)
{
int v = [val intValue];
if (v >= 100 && v < 200)
{
/*
* This is an intermediary response ... so we have
* to restart the parsing operation!
*/
inBody = NO;
}
}
}
}
}