Browse Source

now stuff seems to work correct even if read does not provide a complete request (tested with telnet)

master
Georg Hopp 14 years ago
parent
commit
68e9682380
  1. 2
      include/http/request_parser.h
  2. 28
      src/http/request_parser.c

2
include/http/request_parser.h

@ -9,7 +9,7 @@
typedef enum e_HttpRequestState {
HTTP_REQUEST_GARBAGE=0,
HTTP_REQUEST_START,
HTTP_REQUEST_REQEUST_LINE_DONE,
HTTP_REQUEST_REQUEST_LINE_DONE,
HTTP_REQUEST_HEADERS_DONE,
HTTP_REQUEST_DONE
} HttpRequestState;

28
src/http/request_parser.c

@ -134,7 +134,7 @@ void
httpRequestParserParse(HttpRequestParser this)
{
static HttpRequest request = NULL;
char * data = this->buffer;
static char * data; // static pointer to unprocessed data
char * line;
int cont = 1;
static int header_idx;
@ -143,6 +143,7 @@ httpRequestParserParse(HttpRequestParser this)
switch(this->state) {
case HTTP_REQUEST_GARBAGE:
puts("==skip garbage==");
data = this->buffer; // initialize static pointer
httpRequestSkip(&data);
request = new(HttpRequest);
@ -188,10 +189,10 @@ httpRequestParserParse(HttpRequestParser this)
}
header_idx = 0;
this->state = HTTP_REQUEST_REQEUST_LINE_DONE;
this->state = HTTP_REQUEST_REQUEST_LINE_DONE;
break;
case HTTP_REQUEST_REQEUST_LINE_DONE:
case HTTP_REQUEST_REQUEST_LINE_DONE:
puts("==read header==");
if (NULL == (line = httpRequestLineGet(&data))) {
cont = 0;
@ -223,25 +224,40 @@ httpRequestParserParse(HttpRequestParser this)
case HTTP_REQUEST_HEADERS_DONE:
puts("==headers done==");
/**
* @TODO: here comes the body handling
*/
this->state = HTTP_REQUEST_DONE;
break;
case HTTP_REQUEST_DONE:
puts("==request done==");
/**
* enqueue current request
*/
this->request_queue->requests[(this->request_queue->nrequests)++] =
request;
/**
* remove processed stuff from input buffer.
*/
memmove(this->buffer,
data,
this->buffer_used - (data - this->buffer) + 1);
this->buffer_used -= data - this->buffer;
/**
* dont continue loop if input buffer is empty
*/
if (0 == this->buffer_used) {
cont = 0;
}
this->request_queue->requests[(this->request_queue->nrequests)++] =
request;
/**
* prepare for next request
*/
this->state = HTTP_REQUEST_GARBAGE;
break;

Loading…
Cancel
Save