wip
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
NADAL Jean-Baptiste
2020-02-07 21:54:46 +01:00
parent 2cc3ab0637
commit 4d3828a664
8 changed files with 313 additions and 11 deletions

114
src/rest/restd.h Normal file
View File

@@ -0,0 +1,114 @@
/*!
* restd.h
*
* Copyright (c) 2015-2020, 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: 07/02/2020
*
*/
#ifndef _RESTD_H
#define _RESTD_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <pthread.h>
#include <qlibc/qlibc.h>
/*------------------------------- TYPEDEFS ----------------------------------*/
typedef struct restd_server_s restd_server_t;
typedef struct restd_hook_s restd_hook_t;
/*------------------------------- INCLUDES ----------------------------------*/
extern restd_server_t *restd_server_new(void);
extern void restd_server_free(restd_server_t *server);
extern int restd_server_start(restd_server_t *server);
extern int restd_server_attach_event_loop(restd_server_t *server, struct event_base *ev_base);
extern void restd_server_set_option(restd_server_t *server, const char *key, const char *value);
extern void restd_server_register_hook_on_path(restd_server_t *server, const char *method, const char *path,
restd_callback cb, void *userdata);
/*------------------------------- DEFINES ------------------------------------*/
/*
* These flags are used for ad_log_level();
*/
enum restd_log_e
{
RESTD_LOG_DISABLE = 0,
RESTD_LOG_ERROR,
RESTD_LOG_WARN,
RESTD_LOG_INFO,
RESTD_LOG_DEBUG,
RESTD_LOG_DEBUG2,
};
/*---------------------------------------------------------------------------*\
| USER-CALLBACK |
\*---------------------------------------------------------------------------*/
/**
* User callback(hook) prototype.
*/
typedef int (*restd_call_hook_cb)(short event, void *conn);
typedef int (*restd_callback)(short event, void *conn, void *userdata);
typedef void (*restd_userdata_free_cb)(void *conn, void *userdata);
/*---------------------------------------------------------------------------*\
| DATA STRUCTURES |
\*---------------------------------------------------------------------------*/
/**
* Server info container.
*/
struct restd_server_s
{
int errcode; /*!< exit status. 0 for normal exit, non zero for error. */
pthread_t *thread; /*!< thread object. not null if server runs as a thread */
qhashtbl_t *options; /*!< server options */
qhashtbl_t *stats; /*!< internal statistics */
qlist_t *hooks; /*!< list of registered hooks */
struct evconnlistener *listener; /*!< listener */
struct event_base *evbase; /*!< event base */
struct bufferevent *notify_buffer; /*!< internal notification channel */
restd_call_hook_cb call_hooks;
restd_callback request_handler;
restd_callback error_handler;
};
/*
* User callback hook container.
*/
struct restd_hook_s
{
char *method;
char *path;
restd_callback cb;
void *userdata;
};
#endif /*_RESTD_H */