summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2020-05-02 14:48:14 +0200
committerAki <please@ignore.pl>2020-05-02 14:48:14 +0200
commit890ed2ce61a20e7ae14070fc1a76b24e248d0d08 (patch)
tree74578e0767b06c7a7641d9ae8205dff00fedb326
parentcb558e648250eb886bcadbec7da6dc650ebe7839 (diff)
downloadplop-890ed2ce61a20e7ae14070fc1a76b24e248d0d08.zip
plop-890ed2ce61a20e7ae14070fc1a76b24e248d0d08.tar.gz
plop-890ed2ce61a20e7ae14070fc1a76b24e248d0d08.tar.bz2
Added initial method parsing
-rw-r--r--http.c14
-rw-r--r--http.h2
-rw-r--r--plop.c4
3 files changed, 18 insertions, 2 deletions
diff --git a/http.c b/http.c
index 264c7b5..6eda100 100644
--- a/http.c
+++ b/http.c
@@ -82,6 +82,20 @@ int parse_request(const int fd, struct request * const request)
return -1; // TODO: Handle errors properly
}
+ for (int i = 0; i < NUMBER_OF_METHODS; ++i)
+ {
+ if (0 == strncmp(method_str[i], buffer, strlen(method_str[i])))
+ {
+ request->method = i;
+ break;
+ }
+
+ if (NUMBER_OF_METHODS - 1 == i)
+ {
+ // TODO: 501 Not Implemented
+ }
+ }
+
request->body = malloc(length + 1);
memcpy(request->body, buffer, length);
request->body[length] = 0;
diff --git a/http.h b/http.h
index 5a9283e..8134b1d 100644
--- a/http.h
+++ b/http.h
@@ -10,6 +10,8 @@ enum method
METHOD_DELETE,
METHOD_OPTIONS,
METHOD_PATCH,
+ NUMBER_OF_METHODS,
+ METHOD_INVALID,
};
struct request
diff --git a/plop.c b/plop.c
index 9e44ab7..669ac1a 100644
--- a/plop.c
+++ b/plop.c
@@ -86,10 +86,10 @@ int handle_client(struct pollfd * pfd, const int shift_by)
return -1; // TODO: Handle errors properly
}
- struct request request = {0};
+ struct request request = {METHOD_INVALID, NULL};
parse_request(pfd->fd, &request);
- if (-1 == respond_with_body(pfd->fd, STATUS_OK, request.body))
+ if (-1 == respond_with_body(pfd->fd, STATUS_OK, method_str[request.method]))
{
// TODO: Handle errors properly
}