wip
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "restd_server.h"
|
||||
#include "restd_http_handler.h"
|
||||
#include "restd_rest_handler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
||||
@@ -124,7 +124,7 @@ struct restd_http_s
|
||||
struct
|
||||
{
|
||||
enum restd_http_request_status_e status; /*!< request status. */
|
||||
struct evbuffer *inbuf; /*!< input data buffer. */
|
||||
struct evbuffer *inbuf; /*!< input data buffer. */
|
||||
|
||||
// request line - available on REQ_REQUESTLINE_DONE.
|
||||
char *method; /*!< request method ex) GET */
|
||||
|
||||
33
lib/include/restd_rest_handler.h
Normal file
33
lib/include/restd_rest_handler.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*!
|
||||
* restd_rest_handler.h
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _RESTD_REST_HANDLER_H
|
||||
#define _RESTD_REST_HANDLER_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
extern int restd_rest_handler(short event, restd_conn_t *conn, void *userdata);
|
||||
|
||||
#endif /* _RESTD_REST_HANDLER_H */
|
||||
@@ -47,6 +47,9 @@ typedef struct restd_conn_s restd_conn_t;
|
||||
#define RESTD_DONE (2) /*!< We're done with this request but keep the connection open. */
|
||||
#define RESTD_CLOSE (3) /*!< We're done with this request. Close as soon as we sent all data out. */
|
||||
|
||||
#define RESTD_NOT_ALLOWED (4)
|
||||
#define RESTD_NOT_FOUND (5)
|
||||
|
||||
/*
|
||||
* These flags are used for ad_log_level();
|
||||
*/
|
||||
@@ -73,17 +76,17 @@ typedef void (*restd_userdata_free_cb)(restd_conn_t *conn, void *userdata);
|
||||
/**
|
||||
* Event types
|
||||
*/
|
||||
#define RESTD_EVENT_INIT (1) /*!< Call once upon new connection. */
|
||||
#define RESTD_EVENT_READ (1 << 1) /*!< Call on read */
|
||||
#define RESTD_EVENT_WRITE (1 << 2) /*!< Call on write. */
|
||||
#define RESTD_EVENT_CLOSE (1 << 3) /*!< Call before closing. */
|
||||
#define RESTD_EVENT_TIMEOUT (1 << 4) /*!< Timeout indicator, this flag will be set with AD_EVENT_CLOSE. */
|
||||
#define RESTD_EVENT_SHUTDOWN (1 << 5) /*!< Shutdown indicator, this flag will be set with AD_EVENT_CLOSE. */
|
||||
#define RESTD_EVENT_INIT (1) /*!< Call once upon new connection. */
|
||||
#define RESTD_EVENT_READ (1 << 1) /*!< Call on read */
|
||||
#define RESTD_EVENT_WRITE (1 << 2) /*!< Call on write. */
|
||||
#define RESTD_EVENT_CLOSE (1 << 3) /*!< Call before closing. */
|
||||
#define RESTD_EVENT_TIMEOUT (1 << 4) /*!< Timeout indicator, this flag will be set with AD_EVENT_CLOSE. */
|
||||
#define RESTD_EVENT_SHUTDOWN (1 << 5) /*!< Shutdown indicator, this flag will be set with AD_EVENT_CLOSE. */
|
||||
|
||||
/**
|
||||
* Defaults
|
||||
*/
|
||||
#define RESTD_NUM_USERDATA (2) /*!< Number of userdata. Currently 0 is for userdata, 1 is for extra. */
|
||||
#define RESTD_NUM_USERDATA (2) /*!< Number of userdata. Currently 0 is for userdata, 1 is for extra. */
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
| DATA STRUCTURES |
|
||||
@@ -104,6 +107,8 @@ struct restd_server_s
|
||||
struct event_base *evbase; /*!< event base */
|
||||
|
||||
struct bufferevent *notify_buffer; /*!< internal notification channel */
|
||||
restd_callback request_handler;
|
||||
restd_callback error_handler;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -122,6 +127,18 @@ struct restd_conn_s
|
||||
char *method; /*!< request method. set by protocol handler */
|
||||
};
|
||||
|
||||
/*
|
||||
* User callback hook container.
|
||||
*/
|
||||
typedef struct restd_hook_s restd_hook_t;
|
||||
struct restd_hook_s
|
||||
{
|
||||
char *method;
|
||||
char *path;
|
||||
restd_callback cb;
|
||||
void *userdata;
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*\
|
||||
| PUBLIC FUNCTIONS |
|
||||
\*----------------------------------------------------------------------------*/
|
||||
@@ -135,10 +152,16 @@ extern void restd_server_set_option(restd_server_t *server, const char *key, con
|
||||
extern char *restd_server_get_option(restd_server_t *server, const char *key);
|
||||
extern int restd_server_get_option_int(restd_server_t *server, const char *key);
|
||||
|
||||
extern void restd_server_register_request_handler(restd_server_t *server, restd_callback cb);
|
||||
extern void restd_server_register_error_handler(restd_server_t *server, restd_callback cb);
|
||||
|
||||
extern void restd_server_register_hook(restd_server_t *server, restd_callback cb, void *userdata);
|
||||
extern void restd_server_register_hook_on_method(restd_server_t *server, const char *method,
|
||||
restd_callback cb, void *userdata);
|
||||
|
||||
extern void restd_server_register_hook_on_path(restd_server_t *server, const char *method, const char *path,
|
||||
restd_callback cb, void *userdata);
|
||||
|
||||
extern void *restd_conn_set_extra(restd_conn_t *conn, const void *extra, restd_userdata_free_cb free_cb);
|
||||
extern void *restd_conn_get_extra(restd_conn_t *conn);
|
||||
extern void restd_conn_set_method(restd_conn_t *conn, char *method);
|
||||
|
||||
Reference in New Issue
Block a user