|
|
|
@ -10,7 +10,7 @@ |
|
|
|
#include "http/request_parser.h" |
|
|
|
#include "interface/class.h" |
|
|
|
#include "interface/stream_reader.h" |
|
|
|
//#include "http/request.h" |
|
|
|
#include "http/request.h" |
|
|
|
//#include "http/request_queue.h" |
|
|
|
|
|
|
|
static |
|
|
|
@ -122,27 +122,25 @@ inline |
|
|
|
void |
|
|
|
httpRequestSkip(char ** data) |
|
|
|
{ |
|
|
|
for (; 0 != **data && ! isalpha(**data); *data++); |
|
|
|
for (; 0 != **data && ! isalpha(**data); (*data)++); |
|
|
|
} |
|
|
|
|
|
|
|
static |
|
|
|
void |
|
|
|
httpRequestParserParse(HttpRequestParser this) |
|
|
|
{ |
|
|
|
//static HttpRequest request = NULL; |
|
|
|
static HttpRequest request = NULL; |
|
|
|
char * data = this->buffer; |
|
|
|
char * line; |
|
|
|
int cont = 1; |
|
|
|
|
|
|
|
//if(NULL == HttpRequest) { |
|
|
|
// request = new(HttpRequest); |
|
|
|
//} |
|
|
|
static int header_idx; |
|
|
|
|
|
|
|
while(cont) { |
|
|
|
switch(this->state) { |
|
|
|
case HTTP_REQUEST_GARBAGE: |
|
|
|
puts("==skip garbage=="); |
|
|
|
httpRequestSkip(&data); |
|
|
|
request = new(HttpRequest); |
|
|
|
|
|
|
|
this->state = HTTP_REQUEST_START; |
|
|
|
break; |
|
|
|
@ -153,8 +151,43 @@ httpRequestParserParse(HttpRequestParser this) |
|
|
|
cont = 0; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
char * delim = strchr(line, ' '); |
|
|
|
|
|
|
|
if (NULL != delim) { |
|
|
|
*delim = 0; |
|
|
|
request->method = malloc(strlen(line) + 1); |
|
|
|
strcpy(request->method, line); |
|
|
|
line = delim + 1; |
|
|
|
|
|
|
|
for (; *line == ' ' && *line != 0; line++); |
|
|
|
|
|
|
|
if (0 != *line) { |
|
|
|
delim = strchr(line, ' '); |
|
|
|
|
|
|
|
if (NULL != delim) { |
|
|
|
*delim = 0; |
|
|
|
request->uri = malloc(strlen(line) + 1); |
|
|
|
strcpy(request->uri, line); |
|
|
|
line = delim + 1; |
|
|
|
|
|
|
|
for (; *line == ' ' && *line != 0; line++); |
|
|
|
|
|
|
|
if (0 != *line) { |
|
|
|
request->http_version = malloc(strlen(line) + 1); |
|
|
|
strcpy(request->http_version, line); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
printf("%s\n", line); |
|
|
|
printf("method: %s\n", request->method); |
|
|
|
printf("uri: %s\n", request->uri); |
|
|
|
printf("version: %s\n", request->http_version); |
|
|
|
|
|
|
|
header_idx = 0; |
|
|
|
this->state = HTTP_REQUEST_REQEUST_LINE_DONE; |
|
|
|
break; |
|
|
|
|
|
|
|
@ -170,11 +203,36 @@ httpRequestParserParse(HttpRequestParser this) |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
printf("%s\n", line); |
|
|
|
{ |
|
|
|
char * delim = strchr(line, ':'); |
|
|
|
|
|
|
|
*delim = 0; |
|
|
|
(request->header)[header_idx].name = malloc(strlen(line) + 1); |
|
|
|
strcpy((request->header)[header_idx].name, line); |
|
|
|
|
|
|
|
line = delim + 1; |
|
|
|
for (; *line == ' ' && *line != 0; line++); |
|
|
|
|
|
|
|
(request->header)[header_idx].value = malloc(strlen(line) + 1); |
|
|
|
strcpy((request->header)[header_idx].value, line); |
|
|
|
} |
|
|
|
|
|
|
|
header_idx++; |
|
|
|
break; |
|
|
|
|
|
|
|
case HTTP_REQUEST_HEADERS_DONE: |
|
|
|
puts("==headers done=="); |
|
|
|
|
|
|
|
{ |
|
|
|
int i; |
|
|
|
|
|
|
|
for (i=0; i<header_idx; i++) { |
|
|
|
printf("header-name: %s\n", (request->header)[i].name); |
|
|
|
printf("header-value: %s\n", (request->header)[i].value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
printf("%s\n", line); |
|
|
|
this->state = HTTP_REQUEST_DONE; |
|
|
|
break; |
|
|
|
|
|
|
|
@ -191,6 +249,7 @@ httpRequestParserParse(HttpRequestParser this) |
|
|
|
cont = 0; |
|
|
|
} |
|
|
|
|
|
|
|
delete(&request); |
|
|
|
this->state = HTTP_REQUEST_GARBAGE; |
|
|
|
|
|
|
|
break; |
|
|
|
|