HTTPSource header search fix for boundary conditions.

CQTexperiment
vspader 2007-03-04 00:30:11 +00:00
parent ea4eb96c2a
commit 6f8d1b8e99
1 changed files with 40 additions and 37 deletions

View File

@ -56,15 +56,20 @@
- (int)read:(void *)buffer amount:(int)amount
{
int l = [_socket receive:buffer amount:amount];
if (!pastHeader) {
uint8_t *f = (uint8_t *)strnstr((const char *)buffer, "\r\n\r\n", l);
if (f)
{
const int delimeter_size = 4; //\r\n\r\n
int l = [_socket receive:buffer amount:amount];
uint8_t *f;
while(NULL == (f = (uint8_t *)strnstr((const char *)buffer, "\r\n\r\n", l))) {
//Need to check for boundary conditions
memmove(buffer, (uint8_t *)buffer + (l - delimeter_size), delimeter_size);
l = [_socket receive:((uint8_t *)buffer + delimeter_size) amount:(amount - delimeter_size)];
}
pastHeader = YES;
uint8_t *bufferOffset = f + 4; //\r\n\r\n
uint8_t *bufferOffset = f + delimeter_size;
uint8_t *bufferEnd = (uint8_t *)buffer + l;
int amountRemaining = bufferEnd - bufferOffset;
@ -84,10 +89,7 @@
return amountRemaining + [self read:((uint8_t *)buffer + amountRemaining) amount:(amount - amountRemaining)];
}
else {
//Keep searching for header. Note: NEED TO WATCH BOUNDARY CASES
return [self read:buffer amount:amount];
}
}
int l = [_socket receive:buffer amount:amount];
/*
//FOR TESTING ONLY
@ -99,6 +101,7 @@
byteCount += l;
return l;
}
}
- (void)close