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