From 572ab4496e7abd3d775b2634609bf2f8f0d0791c Mon Sep 17 00:00:00 2001 From: Thomas Porzelt Date: Fri, 11 Sep 2009 18:27:43 +0200 Subject: [PATCH] fix state machine bug which would lead to failed request even though there was no error --- src/client.c | 8 ++++---- src/weighttp.c | 2 +- src/weighttp.h | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/client.c b/src/client.c index 098cca4..9b6f25c 100644 --- a/src/client.c +++ b/src/client.c @@ -249,7 +249,7 @@ void client_state_machine(Client *client) { if (client->state == CLIENT_END) goto start; else - break; + return; } } else { /* disconnect */ @@ -343,7 +343,7 @@ static uint8_t client_parse(Client *client) { if (strncmp(str, "Content-Length: ", sizeof("Content-Length: ")-1) == 0) { /* content length header */ - client->content_length = atoi(str + sizeof("Content-Length: ") - 1); + client->content_length = str_to_uint64(str + sizeof("Content-Length: ") - 1); } else if (strncmp(str, "Connection: ", sizeof("Connection: ")-1) == 0) { /* connection header */ str += sizeof("Connection: ") - 1; @@ -375,8 +375,8 @@ static uint8_t client_parse(Client *client) { //printf("parse (BODY)\n"); /* do nothing, just consume the data */ /*printf("content-l: %"PRIu64", header: %d, recevied: %"PRIu64"\n", - client->content_length, client->header_size, client->bytes_received); - client->buffer_offset = 0;*/ + client->content_length, client->header_size, client->bytes_received);*/ + client->buffer_offset = 0; if (client->content_length == -1) return 0; diff --git a/src/weighttp.c b/src/weighttp.c index 565564c..8385c16 100644 --- a/src/weighttp.c +++ b/src/weighttp.c @@ -139,7 +139,7 @@ static char *forge_request(char *url, char keep_alive, char **host, uint16_t *po return req; } -static uint64_t str_to_uint64(char *str) { +uint64_t str_to_uint64(char *str) { uint64_t i; for (i = 0; *str; str++) { diff --git a/src/weighttp.h b/src/weighttp.h index ad47465..2ebbf12 100644 --- a/src/weighttp.h +++ b/src/weighttp.h @@ -57,4 +57,6 @@ struct Config { struct addrinfo *saddr; }; +uint64_t str_to_uint64(char *str); + #endif