From 1af8b32fdf1588b2533eb311d1c36b1d2398902b Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Fri, 9 Mar 2012 23:10:27 +0100 Subject: [PATCH] Some fixes: - skipNonAlpha now really skips NON alpha chars - parserBody now reads the MIN of want to what's available - changed the order in body read...an 0 nbody leads to immediate completion, than the first check is if the buffer is empty and only if it's not data is read. fixes #20 --- src/cbuf/skip_non_alpha.c | 2 +- src/http/parser/body.c | 4 ++-- src/http/parser/parse.c | 31 ++++++++++++++++--------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/cbuf/skip_non_alpha.c b/src/cbuf/skip_non_alpha.c index 0021d18..72ef3aa 100644 --- a/src/cbuf/skip_non_alpha.c +++ b/src/cbuf/skip_non_alpha.c @@ -27,7 +27,7 @@ void cbufSkipNonAlpha(Cbuf this) { - while(0 > this->bused && isalpha(*cbufGetRead(this))) + while(0 < this->bused && !isalpha(*cbufGetRead(this))) cbufIncRead(this, 1); } diff --git a/src/http/parser/body.c b/src/http/parser/body.c index 8557217..6901c8d 100644 --- a/src/http/parser/body.c +++ b/src/http/parser/body.c @@ -28,7 +28,7 @@ #include "http/parser.h" #include "cbuf.h" -#define MAX(a,b) (((a) > (b))? (a) : (b)) +#define MIN(a,b) (((a) < (b))? (a) : (b)) size_t httpParserBody(HttpParser this, const char * buf, size_t nbuf) @@ -37,7 +37,7 @@ httpParserBody(HttpParser this, const char * buf, size_t nbuf) HttpMessage current = this->current; if (current->dbody < current->nbody) { - len = MAX(current->nbody - current->dbody, nbuf); + len = MIN(current->nbody - current->dbody, nbuf); memcpy(current->body, buf, len); diff --git a/src/http/parser/parse.c b/src/http/parser/parse.c index b4f2a2e..ef20c6b 100644 --- a/src/http/parser/parse.c +++ b/src/http/parser/parse.c @@ -120,23 +120,24 @@ httpParserParse(void * _this, Stream st) break; case HTTP_MESSAGE_HEADERS_DONE: - { - cbufIncRead( - this->buffer, - httpParserBody( - this, - cbufGetRead(this->buffer), - this->buffer->bused)); - - if (cbufIsEmpty(this->buffer)) { - cbufRelease(this->buffer); - this->ourLock = FALSE; - } + if (this->current->dbody == this->current->nbody) { + this->state = HTTP_MESSAGE_DONE; + break; + } - if (this->current->dbody == this->current->nbody) { - this->state = HTTP_MESSAGE_DONE; - } + if (cbufIsEmpty(this->buffer)) { + cbufRelease(this->buffer); + this->ourLock = FALSE; + cont = 0; + break; } + + cbufIncRead( + this->buffer, + httpParserBody( + this, + cbufGetRead(this->buffer), + this->buffer->bused)); break; case HTTP_MESSAGE_DONE: