This commit is contained in:
NADAL Jean-Baptiste
2019-12-23 18:27:18 +01:00
parent 14d3faae8d
commit 798bea32ab
9 changed files with 206 additions and 37 deletions

View File

@@ -0,0 +1,93 @@
/*!
* restd_rest_handler.c
*
* Copyright (c) 2015-2019, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 23/12/2019
*
*/
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
/*------------------------------- INCLUDES ----------------------------------*/
#include <string.h>
#include <stdbool.h>
#include <event2/buffer.h>
#include "restd_server.h"
#include "restd_http_handler.h"
#include "restd_rest_handler.h"
#include "macro.h"
/*! ----------------------------------------------------------------------------
* @fn restd_rest_handler
*
* @brief Main function to manage http request.
*/
int restd_rest_handler(short event, restd_conn_t *conn, void *userdata)
{
bool found = false;
DEBUG("JBN call_hooks: event 0x%x", event);
restd_http_t *http = (restd_http_t *)restd_conn_get_extra(conn);
qlist_t *hooks = conn->server->hooks;
qlist_obj_t obj;
bzero((void *)&obj, sizeof(qlist_obj_t));
while (hooks->getnext(hooks, &obj, false) == true)
{
DEBUG(">>>>>>>>>\n");
restd_hook_t *hook = (restd_hook_t *)obj.data;
if (hook->cb)
{
DEBUG("JBN call_hooks: method: %s - %s \n", hook->method, conn->method);
DEBUG("JBN call_hooks: path: %s - %s\n", hook->path, http->request.path);
if ((hook->method == NULL) || (conn->method == NULL) || (strcmp(hook->method, conn->method) != 0))
{
DEBUG("JBN - ca va pas 1 \n");
continue;
}
if ((hook->path == NULL) || (http->request.path == NULL) || (strcmp(hook->path, http->request.path) != 0))
{
DEBUG("JBN - ca va pas 2 \n");
continue;
}
DEBUG("JBN FOUND !!!!\n");
return RESTD_OK;
//int status = hook->cb(event, conn, hook->userdata);
//if (status != RESTD_OK)
//{
// return status;
//}
}
}
if (found == false)
{
printf("Call error handler...\n");
return RESTD_NOT_ALLOWED;
}
DEBUG("JBN call_hooks - DONE\n");
return RESTD_OK;
}