summaryrefslogtreecommitdiffhomepage
path: root/request.c
diff options
context:
space:
mode:
Diffstat (limited to 'request.c')
-rw-r--r--request.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/request.c b/request.c
index f6f8a78..e8f47b0 100644
--- a/request.c
+++ b/request.c
@@ -7,6 +7,9 @@
#include <string.h>
#include <unistd.h>
+#include <lauxlib.h>
+#include <lua.h>
+
#include "http.h"
static const int REQUEST_DATA_SIZE = 4096;
@@ -15,7 +18,7 @@ static const int MAX_HEADERS = 30;
/// Allocates and initializes request structure.
/// \return Pointer to initialized request or NULL in case of an error
/// \see /free_request
-struct request * new_request(void)
+struct request * new_request(lua_State * L)
{
struct request * request = malloc(sizeof(struct request));
@@ -35,13 +38,16 @@ struct request * new_request(void)
return NULL;
}
+ request->lua = lua_newthread(L);
+ request->reference = luaL_ref(L, LUA_REGISTRYINDEX);
+
return request;
}
/// Releases memory used by the request and the request itself.
/// \param request Request to free
/// \see /new_request
-void free_request(struct request * request)
+void free_request(lua_State * L, struct request * request)
{
if (NULL != request->data)
{
@@ -53,6 +59,8 @@ void free_request(struct request * request)
free(request->headerv);
}
+ luaL_unref(L, LUA_REGISTRYINDEX, request->reference);
+
free(request);
}
@@ -60,11 +68,11 @@ void free_request(struct request * request)
/// \param fd Client socket
/// \param request Pointer to current request context of handled client
/// \return Number of bytes parsed, -1 if an error occured or 0 if expects more data
-int parse_request(const int fd, struct request ** request)
+int parse_request(lua_State * L, const int fd, struct request ** request)
{
if (NULL == *request)
{
- *request = new_request();
+ *request = new_request(L);
if (NULL == *request)
{
return -1;