Commit cc7a81e9 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Tollef Fog Heen

Go over this code once more, and fix various nits.

parent 2481d4b6
......@@ -107,7 +107,7 @@ synth_body(const char *len, int rnd)
AN(len);
i = strtoul(len, NULL, 0);
assert(i > 0);
b = malloc(i + 1);
b = malloc(i + 1L);
AN(b);
l = k = '!';
for (j = 0; j < i; j++) {
......@@ -333,7 +333,7 @@ http_splitheader(struct http *hp, int req)
*/
static int
http_rxchar_eof(struct http *hp, int n)
http_rxchar(struct http *hp, int n, int eof)
{
int i;
struct pollfd pfd[1];
......@@ -343,21 +343,25 @@ http_rxchar_eof(struct http *hp, int n)
pfd[0].events = POLLIN;
pfd[0].revents = 0;
i = poll(pfd, 1, hp->timeout);
if (i < 0)
if (i == 0)
vtc_log(hp->vl, 0, "HTTP rx timeout (fd:%d %u ms)",
hp->fd, hp->timeout);
if (i < 0)
vtc_log(hp->vl, 0, "HTTP rx failed (fd:%d poll: %s)",
hp->fd, strerror(errno));
assert(i > 0);
if (pfd[0].revents & ~POLLIN)
vtc_log(hp->vl, 4, "HTTP rx poll (fd:%d revents: %x)",
hp->fd, pfd[0].revents);
assert(hp->prxbuf + n < hp->nrxbuf);
i = read(hp->fd, hp->rxbuf + hp->prxbuf, n);
if (i == 0)
if (!(pfd[0].revents & POLLIN))
vtc_log(hp->vl, 4,
"HTTP rx poll (fd:%d revents: %x n=%d, i=%d)",
hp->fd, pfd[0].revents, n, i);
if (i == 0 && eof)
return (i);
if (i <= 0)
if (i == 0)
vtc_log(hp->vl, 0, "HTTP rx EOF (fd:%d read: %s)",
hp->fd, strerror(errno));
if (i < 0)
vtc_log(hp->vl, 0, "HTTP rx failed (fd:%d read: %s)",
hp->fd, strerror(errno));
hp->prxbuf += i;
......@@ -367,17 +371,6 @@ http_rxchar_eof(struct http *hp, int n)
return (1);
}
static void
http_rxchar(struct http *hp, int n)
{
int i;
i = http_rxchar_eof(hp, n);
if (i <= 0)
vtc_log(hp->vl, 0, "HTTP rx failed (%s)", strerror(errno));
assert(i > 0);
}
static int
http_rxchunk(struct http *hp)
{
......@@ -386,7 +379,7 @@ http_rxchunk(struct http *hp)
l = hp->prxbuf;
do
http_rxchar(hp, 1);
(void)http_rxchar(hp, 1, 0);
while (hp->rxbuf[hp->prxbuf - 1] != '\n');
vtc_dump(hp->vl, 4, "len", hp->rxbuf + l, -1);
i = strtoul(hp->rxbuf + l, &q, 16);
......@@ -400,12 +393,12 @@ http_rxchunk(struct http *hp)
assert(*q == '\0' || vct_islws(*q));
hp->prxbuf = l;
if (i > 0) {
http_rxchar(hp, i);
(void)http_rxchar(hp, i, 0);
vtc_dump(hp->vl, 4, "chunk",
hp->rxbuf + l, i);
}
l = hp->prxbuf;
http_rxchar(hp, 2);
(void)http_rxchar(hp, 2, 0);
if(!vct_iscrlf(hp->rxbuf[l]))
vtc_log(hp->vl, 0,
"Wrong chunk tail[0] = %02x",
......@@ -433,7 +426,7 @@ http_swallow_body(struct http *hp, char * const *hh, int body)
p = http_find_header(hh, "content-length");
if (p != NULL) {
l = strtoul(p, NULL, 0);
http_rxchar(hp, l);
(void)http_rxchar(hp, l, 0);
vtc_dump(hp->vl, 4, "body", hp->body, l);
hp->bodyl = l;
sprintf(hp->bodylen, "%d", l);
......@@ -452,7 +445,7 @@ http_swallow_body(struct http *hp, char * const *hh, int body)
if (body) {
hp->body = hp->rxbuf + hp->prxbuf;
do {
i = http_rxchar_eof(hp, 1);
i = http_rxchar(hp, 1, 1);
ll += i;
} while (i > 0);
vtc_dump(hp->vl, 4, "rxeof", hp->body, ll);
......@@ -475,7 +468,7 @@ http_rxhdr(struct http *hp)
hp->prxbuf = 0;
hp->body = NULL;
while (1) {
http_rxchar(hp, 1);
(void)http_rxchar(hp, 1, 0);
p = hp->rxbuf + hp->prxbuf - 1;
for (i = 0; p > hp->rxbuf; p--) {
if (*p != '\n')
......@@ -533,7 +526,7 @@ cmd_http_rxresp(CMD_ARGS)
#define TRUST_ME(ptr) ((void*)(uintptr_t)(ptr))
#define OVERHEAD 64
#define OVERHEAD 64L
static void
......@@ -942,7 +935,7 @@ cmd_http_sendhex(CMD_ARGS)
if (!vct_ishex(buf[0]) || !vct_ishex(buf[1]))
vtc_log(hp->vl, 0, "Illegal Hex char \"%c%c\"",
buf[0], buf[1]);
p[i] = strtoul(buf, NULL, 16);
p[i] = (uint8_t)strtoul(buf, NULL, 16);
}
vtc_hexdump(hp->vl, 4, "sendhex", (void*)p, i);
j = write(hp->fd, p, i);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment