Commit abc5dd2a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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

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