HTTPSource header search fix for boundary conditions.
parent
ea4eb96c2a
commit
6f8d1b8e99
|
@ -56,15 +56,20 @@
|
||||||
|
|
||||||
- (int)read:(void *)buffer amount:(int)amount
|
- (int)read:(void *)buffer amount:(int)amount
|
||||||
{
|
{
|
||||||
int l = [_socket receive:buffer amount:amount];
|
|
||||||
|
|
||||||
if (!pastHeader) {
|
if (!pastHeader) {
|
||||||
uint8_t *f = (uint8_t *)strnstr((const char *)buffer, "\r\n\r\n", l);
|
const int delimeter_size = 4; //\r\n\r\n
|
||||||
if (f)
|
|
||||||
{
|
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;
|
pastHeader = YES;
|
||||||
|
|
||||||
uint8_t *bufferOffset = f + 4; //\r\n\r\n
|
uint8_t *bufferOffset = f + delimeter_size;
|
||||||
uint8_t *bufferEnd = (uint8_t *)buffer + l;
|
uint8_t *bufferEnd = (uint8_t *)buffer + l;
|
||||||
int amountRemaining = bufferEnd - bufferOffset;
|
int amountRemaining = bufferEnd - bufferOffset;
|
||||||
|
|
||||||
|
@ -84,10 +89,7 @@
|
||||||
return amountRemaining + [self read:((uint8_t *)buffer + amountRemaining) amount:(amount - amountRemaining)];
|
return amountRemaining + [self read:((uint8_t *)buffer + amountRemaining) amount:(amount - amountRemaining)];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//Keep searching for header. Note: NEED TO WATCH BOUNDARY CASES
|
int l = [_socket receive:buffer amount:amount];
|
||||||
return [self read:buffer amount:amount];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//FOR TESTING ONLY
|
//FOR TESTING ONLY
|
||||||
|
@ -99,6 +101,7 @@
|
||||||
byteCount += l;
|
byteCount += l;
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)close
|
- (void)close
|
||||||
|
|
Loading…
Reference in New Issue