|
|
@@ -111,35 +111,6 @@ checkstate: |
|
|
|
n = n - (m0 - buf); |
|
|
|
record_bytes_read = 0; |
|
|
|
goto checkstate; |
|
|
|
|
|
|
|
// Previous code for this case, but the state handling below should do the same thing with less duplication |
|
|
|
/* |
|
|
|
if (record_length + 4 > n - (m0 - buf)) { |
|
|
|
// The whole record isn't in this buffer, print what we have and continue with the loop. |
|
|
|
if (state == STATE_RESPONSE_RECORD) { |
|
|
|
fwrite(m0, 1, n - (m0 - buf), stdout); |
|
|
|
} |
|
|
|
record_bytes_read = n - (m0 - buf); |
|
|
|
} else { |
|
|
|
// The buffer contains the entire record. Print it, then adjust buf and go back to the beginning of the state processing. |
|
|
|
if (state == STATE_RESPONSE_RECORD) { |
|
|
|
fwrite(m0, 1, record_length, stdout); |
|
|
|
} |
|
|
|
if (memcmp(m0 + record_length, "\r\n\r\n", 4) != 0) { |
|
|
|
fprintf(stderr, "Error: end of block not found"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
m0 += record_length + 4; |
|
|
|
memmove(buf, m0, n - (m0 - buf)); |
|
|
|
n = n - (m0 - buf); |
|
|
|
// Fill the buffer back up to ensure that there's at least BUFSIZE bytes in the buffer so the next iteration has the full headers of the next record |
|
|
|
if (n < BUFSIZE) { |
|
|
|
n += fread(buf + n, 1, BUFSIZE, stdin); |
|
|
|
} |
|
|
|
state = STATE_BEFORE_RECORD; |
|
|
|
goto checkstate; |
|
|
|
} |
|
|
|
*/ |
|
|
|
} else { |
|
|
|
fprintf(stderr, "Error: expected header line, got something else\n"); |
|
|
|
return 1; |
|
|
|