21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

headerlen -= (*datalen + 2);<br />

if (*datalen > 0) {<br />

if (!(data = (char *)malloc(*datalen))) goto end_error;<br />

memcpy(data, tmp + 4, *datalen);<br />

}<br />

break;<br />

}<br />

}<br />

}<br />

/* Examine the headers to determine whether or not to continue. If we are to<br />

* continue, look for a content-length header to find out how much data we're<br />

* going to get. If there is no content-length header, we'll have to read<br />

* until the remote server closes the connection.<br />

*/<br />

if (!strncasecmp(headers, "HTTP/1.", 7)) {<br />

if (!(tmp = strchr(headers, ' '))) goto end_error;<br />

if (strncmp(tmp + 1, "200 ", 4) && strncmp(tmp + 1, "200\r\n", 5))<br />

goto end_error;<br />

for (tmp = strstr(headers, "\r\n"); tmp; tmp = strstr(tmp + 2, "\r\n")) {<br />

if (strncasecmp(tmp + 2, "content-length: ", 16)) continue;<br />

content_length = atoi(tmp + 18);<br />

break;<br />

}<br />

} else goto end_error;<br />

/* Continuously read and accumulate data from the remote server. Finish when<br />

* we've read up to the content-length that we received. If we didn't receive<br />

* a content-length, read until the remote server closes the connection.<br />

*/<br />

while (!content_length || *datalen < content_length) {<br />

FD_ZERO(&rmask);<br />

FD_SET(sd, &rmask);<br />

FD_ZERO(&wmask);<br />

if (BIO_should_write(conn)) FD_SET(sd, &wmask);<br />

if (select(FD_SETSIZE, &rmask, &wmask, 0, 0)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!