11 changed files with 149 additions and 58 deletions
-
8ChangeLog
-
1include/cbuf.h
-
3include/http/message.h
-
6include/http/request.h
-
8src/Makefile.am
-
10src/cbuf/empty.c
-
28src/http/message/get_version.c
-
32src/http/message/has_valid_version.c
-
31src/http/request/has_valid_method.c
-
61src/http/request/parser/get_request_line.c
-
19src/http/request/parser/parse.c
@ -0,0 +1,10 @@ |
|||||
|
#include "cbuf.h" |
||||
|
|
||||
|
void |
||||
|
cbufEmpty(Cbuf this) |
||||
|
{ |
||||
|
this->bused = 0; |
||||
|
this->read = this->write; |
||||
|
} |
||||
|
|
||||
|
// vim: set ts=4 sw=4: |
||||
@ -0,0 +1,28 @@ |
|||||
|
#include <string.h> |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
#include "http/message.h" |
||||
|
|
||||
|
int |
||||
|
httpMessageGetVersion(HttpMessage this, int * major, int * minor) |
||||
|
{ |
||||
|
char * major_ptr = this->version + 5; |
||||
|
char * minor_ptr = strchr(major_ptr, '.') + 1; |
||||
|
char version[] = "\0\0\0"; |
||||
|
|
||||
|
if (NULL == minor_ptr || |
||||
|
((minor_ptr - major_ptr - 1) > 2) || |
||||
|
strlen(minor_ptr) > 2) |
||||
|
return -1; |
||||
|
|
||||
|
memcpy(version, major_ptr, minor_ptr - major_ptr - 1); |
||||
|
*major = atoi(version); |
||||
|
|
||||
|
memset(version, 0, 3); |
||||
|
strcpy(version, minor_ptr); |
||||
|
*minor = atoi(version); |
||||
|
|
||||
|
return ((*major)<<7)|(*minor); |
||||
|
} |
||||
|
|
||||
|
// vim: set ts=4 sw=4: |
||||
@ -0,0 +1,32 @@ |
|||||
|
#include <string.h> |
||||
|
|
||||
|
#include "http/message.h" |
||||
|
|
||||
|
int |
||||
|
httpMessageHasValidVersion(HttpMessage this) |
||||
|
{ |
||||
|
int major; |
||||
|
int minor; |
||||
|
|
||||
|
if (NULL == this->version) |
||||
|
return 0; |
||||
|
|
||||
|
if (8 > strlen(this->version)) |
||||
|
return 0; |
||||
|
|
||||
|
if (0 > httpMessageGetVersion(this, &major, &minor)) |
||||
|
return 0; |
||||
|
|
||||
|
if (0 != memcmp("HTTP/", this->version, sizeof("HTTP/")-1)) |
||||
|
return 0; |
||||
|
|
||||
|
if (1 != major) |
||||
|
return 0; |
||||
|
|
||||
|
if (0 > minor || 1 < minor) |
||||
|
return 0; |
||||
|
|
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
// vim: set ts=4 sw=4: |
||||
@ -0,0 +1,31 @@ |
|||||
|
#include <string.h> |
||||
|
|
||||
|
#include "http/request.h" |
||||
|
|
||||
|
char * http_method[N_HTTP_METHOD] = { |
||||
|
"OPTIONS", |
||||
|
"GET", |
||||
|
"HEAD", |
||||
|
"POST", |
||||
|
"PUT", |
||||
|
"DELETE", |
||||
|
"TRACE", |
||||
|
"CONNECT"}; |
||||
|
|
||||
|
int |
||||
|
httpRequestHasValidMethod(HttpRequest this) |
||||
|
{ |
||||
|
int i; |
||||
|
|
||||
|
if (NULL == this->method) |
||||
|
return 0; |
||||
|
|
||||
|
for (i=0; i<N_HTTP_METHOD; i++) { |
||||
|
if (0 == strcmp(http_method[i], this->method)) |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
return (i != N_HTTP_METHOD); |
||||
|
} |
||||
|
|
||||
|
// vim: set ts=4 sw=4: |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue