summaryrefslogtreecommitdiffhomepage
path: root/http.c
diff options
context:
space:
mode:
Diffstat (limited to 'http.c')
-rw-r--r--http.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/http.c b/http.c
index 978af38..264c7b5 100644
--- a/http.c
+++ b/http.c
@@ -1,6 +1,8 @@
#include "http.h"
+#include <errno.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
@@ -59,3 +61,30 @@ int respond_with_body(const int fd, const enum status status, const char * body)
return send(fd, body, strlen(body), 0);
}
+
+///
+/// \param fd
+/// \param request
+/// \return
+int parse_request(const int fd, struct request * const request)
+{
+ char buffer[10240];
+
+ int length = recv(fd, buffer, 10240, 0);
+
+ if (-1 == length && EWOULDBLOCK != errno && EAGAIN != errno)
+ {
+ return -1;
+ }
+
+ if (0 == length)
+ {
+ return -1; // TODO: Handle errors properly
+ }
+
+ request->body = malloc(length + 1);
+ memcpy(request->body, buffer, length);
+ request->body[length] = 0;
+
+ return length;
+}