wip
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
NADAL Jean-Baptiste
2020-01-17 17:53:43 +01:00
parent 17cdd989e8
commit 9acd116ab2
5 changed files with 87 additions and 48 deletions

View File

@@ -91,6 +91,8 @@ enum restd_http_request_status_e
/*----------------------------------------------------------------------------*\
| PUBLIC FUNCTIONS |
\*----------------------------------------------------------------------------*/
extern restd_http_t *http_new(struct evbuffer *out);
extern void http_free_cb(restd_conn_t *conn, void *userdata);
extern int restd_http_handler(short event, restd_conn_t *conn, void *userdata);
extern enum restd_http_request_status_e restd_http_get_status(restd_conn_t *conn);

View File

@@ -41,9 +41,7 @@
#include "macro.h"
#ifndef _DOXYGEN_SKIP
static restd_http_t *http_new(struct evbuffer *out);
static void http_free(restd_http_t *http);
static void http_free_cb(restd_conn_t *conn, void *userdata);
static size_t http_add_inbuf(struct evbuffer *buffer, restd_http_t *http,
size_t maxsize);
@@ -535,7 +533,7 @@ const char *restd_http_get_reason(int code)
*****************************************************************************/
#ifndef _DOXYGEN_SKIP
static restd_http_t *http_new(struct evbuffer *out)
restd_http_t *http_new(struct evbuffer *out)
{
// Create a new connection container.
restd_http_t *http = NEW_OBJECT(restd_http_t);
@@ -599,7 +597,7 @@ static void http_free(restd_http_t *http)
/*--------------------------------------------------------------------------*/
static void http_free_cb(restd_conn_t *conn, void *userdata)
void http_free_cb(restd_conn_t *conn, void *userdata)
{
http_free((restd_http_t *)userdata);
}

View File

@@ -28,6 +28,7 @@
/*------------------------------- INCLUDES ----------------------------------*/
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
@@ -172,12 +173,45 @@ static bool contain(const char *src, const char *dest, int len)
/*! ----------------------------------------------------------------------------
* @fn restd_rest_handler
*
* @brief Main function to manage http request.
* @brief Main function to manage rest request.
*/
int restd_rest_handler(short event, restd_conn_t *conn, void *userdata)
{
if (event & RESTD_EVENT_INIT)
{
DEBUG("==> HTTP INIT");
restd_http_t *http = http_new(conn->out);
if (http == NULL)
return RESTD_CLOSE;
restd_conn_set_extra(conn, http, http_free_cb);
return RESTD_OK;
}
else if (event & RESTD_EVENT_READ)
{
DEBUG("==> HTTP READ");
return RESTD_OK;
}
else if (event & RESTD_EVENT_WRITE)
{
DEBUG("==> HTTP WRITE");
return RESTD_OK;
}
else if (event & RESTD_EVENT_CLOSE)
{
DEBUG("==> HTTP CLOSE=%x (TIMEOUT=%d, SHUTDOWN=%d)",
event, event & RESTD_EVENT_TIMEOUT, event & RESTD_EVENT_SHUTDOWN);
return RESTD_OK;
}
BUG_EXIT();
return RESTD_CLOSE;
}
int restd_rest_handler2(short event, restd_conn_t *conn, void *userdata)
{
int reason = RESTD_ERROR_PATH_NOT_FOUND;
DEBUG("********restd_rest_handler: event 0x%x", event);
DEBUG("ZOB********restd_rest_handler: event 0x%x", event);
restd_http_t *http = (restd_http_t *)restd_conn_get_extra(conn);
char *root_path;
qlist_t *hooks = conn->server->hooks;
@@ -189,9 +223,9 @@ int restd_rest_handler(short event, restd_conn_t *conn, void *userdata)
restd_hook_t *hook = (restd_hook_t *)obj.data;
if (hook->cb)
{
// DEBUG("call_hooks: method: %s - %s \n", hook->method, conn->method);
// DEBUG("call_hooks: path: %s - %s\n", hook->path, http->request.path);
// DEBUG("HOOK FOUND !!!!\n");
DEBUG("ZOB call_hooks: method: %s - %s \n", hook->method, conn->method);
DEBUG("call_hooks: path: %s - %s\n", hook->path, http->request.path);
DEBUG("HOOK FOUND !!!!\n");
if ((hook->method == NULL) || (conn->method == NULL) || (strcmp(hook->method, conn->method) != 0))
{
// DEBUG("Hook found but method failed.\n");