Remove deprecated files
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
/*!
|
||||
* restd.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_H
|
||||
#define _RESTD_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include "restd_server.h"
|
||||
#include "restd_http_handler.h"
|
||||
#include "restd_rest_handler.h"
|
||||
|
||||
#endif /*_RESTD_H */
|
||||
@@ -1,162 +0,0 @@
|
||||
/*!
|
||||
* restd_http_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_HTTP_HANDLER_H
|
||||
#define _RESTD_HTTP_HANDLER_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------*\
|
||||
| HTTP PROTOCOL SPECIFICS |
|
||||
\*----------------------------------------------------------------------------*/
|
||||
|
||||
/* HTTP PROTOCOL CODES */
|
||||
#define HTTP_PROTOCOL_09 "HTTP/0.9"
|
||||
#define HTTP_PROTOCOL_10 "HTTP/1.0"
|
||||
#define HTTP_PROTOCOL_11 "HTTP/1.1"
|
||||
|
||||
/* HTTP RESPONSE CODES */
|
||||
#define HTTP_NO_RESPONSE (0)
|
||||
#define HTTP_CODE_CONTINUE (100)
|
||||
#define HTTP_CODE_OK (200)
|
||||
#define HTTP_CODE_CREATED (201)
|
||||
#define HTTP_CODE_NO_CONTENT (204)
|
||||
#define HTTP_CODE_PARTIAL_CONTENT (206)
|
||||
#define HTTP_CODE_MULTI_STATUS (207)
|
||||
#define HTTP_CODE_MOVED_TEMPORARILY (302)
|
||||
#define HTTP_CODE_NOT_MODIFIED (304)
|
||||
#define HTTP_CODE_Brestd_REQUEST (400)
|
||||
#define HTTP_CODE_UNAUTHORIZED (401)
|
||||
#define HTTP_CODE_FORBIDDEN (403)
|
||||
#define HTTP_CODE_NOT_FOUND (404)
|
||||
#define HTTP_CODE_METHOD_NOT_ALLOWED (405)
|
||||
#define HTTP_CODE_REQUEST_TIME_OUT (408)
|
||||
#define HTTP_CODE_GONE (410)
|
||||
#define HTTP_CODE_REQUEST_URI_TOO_LONG (414)
|
||||
#define HTTP_CODE_LOCKED (423)
|
||||
#define HTTP_CODE_INTERNAL_SERVER_ERROR (500)
|
||||
#define HTTP_CODE_NOT_IMPLEMENTED (501)
|
||||
#define HTTP_CODE_SERVICE_UNAVAILABLE (503)
|
||||
|
||||
/* DEFAULT BEHAVIORS */
|
||||
#define HTTP_CRLF "\r\n"
|
||||
#define HTTP_DEF_CONTENTTYPE "application/octet-stream"
|
||||
|
||||
/*----------------------------------------------------------------------------*\
|
||||
| TYPEDEFS |
|
||||
\*----------------------------------------------------------------------------*/
|
||||
typedef struct restd_http_s restd_http_t;
|
||||
|
||||
/*!< Hook type */
|
||||
#define RESTD_HOOK_ALL (0) /*!< call on each and every phases */
|
||||
#define RESTD_HOOK_ON_CONNECT (1) /*!< call right after the establishment of connection */
|
||||
#define RESTD_HOOK_AFTER_REQUESTLINE (1 << 2) /*!< call after parsing request line */
|
||||
#define RESTD_HOOK_AFTER_HEADER (1 << 3) /*!< call after parsing all headers */
|
||||
#define RESTD_HOOK_ON_BODY (1 << 4) /*!< call on every time body data received */
|
||||
#define RESTD_HOOK_ON_REQUEST (1 << 5) /*!< call with complete request */
|
||||
#define RESTD_HOOK_ON_CLOSE (1 << 6) /*!< call right before closing or next request */
|
||||
#if 0
|
||||
enum restd_http_request_status_e
|
||||
{
|
||||
RESTD_HTTP_REQ_INIT = 0, /*!< initial state */
|
||||
RESTD_HTTP_REQ_REQUESTLINE_DONE, /*!< received 1st line */
|
||||
RESTD_HTTP_REQ_HEADER_DONE, /*!< received headers completely */
|
||||
RESTD_HTTP_REQ_DONE, /*!< received body completely. no more data expected */
|
||||
|
||||
RESTD_HTTP_ERROR, /*!< unrecoverable error found. */
|
||||
};
|
||||
#endif
|
||||
/*----------------------------------------------------------------------------*\
|
||||
| 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);
|
||||
extern struct evbuffer *restd_http_get_inbuf(restd_conn_t *conn);
|
||||
extern struct evbuffer *restd_http_get_outbuf(restd_conn_t *conn);
|
||||
|
||||
extern const char *restd_http_get_request_header(restd_conn_t *conn, const char *name);
|
||||
extern off_t restd_http_get_content_length(restd_conn_t *conn);
|
||||
extern size_t restd_http_get_content_length_stored(restd_conn_t *conn);
|
||||
extern void *restd_http_get_content(restd_conn_t *conn, size_t maxsize, size_t *storedsize);
|
||||
extern int restd_http_is_keepalive_request(restd_conn_t *conn);
|
||||
extern int http_parser(restd_http_t *http, struct evbuffer *in);
|
||||
|
||||
extern int restd_http_set_response_header(restd_conn_t *conn, const char *name, const char *value);
|
||||
extern const char *restd_http_get_response_header(restd_conn_t *conn, const char *name);
|
||||
extern int restd_http_set_response_code(restd_conn_t *conn, int code, const char *reason);
|
||||
extern int restd_http_set_response_content(restd_conn_t *conn, const char *contenttype, off_t size);
|
||||
|
||||
extern size_t restd_http_response(restd_conn_t *conn, int code, const char *contenttype, const void *data, off_t size);
|
||||
extern size_t restd_http_send_header(restd_conn_t *conn);
|
||||
extern size_t restd_http_send_data(restd_conn_t *conn, const void *data, size_t size);
|
||||
extern size_t restd_http_send_chunk(restd_conn_t *conn, const void *data, size_t size);
|
||||
|
||||
extern const char *restd_http_get_reason(int code);
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
| DATA STRUCTURES |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
struct restd_http_s
|
||||
{
|
||||
// HTTP Request
|
||||
struct
|
||||
{
|
||||
enum restd_http_request_status_e status; /*!< request status. */
|
||||
struct evbuffer *inbuf; /*!< input data buffer. */
|
||||
|
||||
// request line - available on REQ_REQUESTLINE_DONE.
|
||||
char *method; /*!< request method ex) GET */
|
||||
char *uri; /*!< url+query ex) /data%20path?query=the%20value */
|
||||
char *httpver; /*!< version ex) HTTP/1.1 */
|
||||
char *path; /*!< decoded path ex) /data path */
|
||||
char *query; /*!< query string ex) query=the%20value */
|
||||
|
||||
// request header - available on REQ_HEADER_DONE.
|
||||
qlisttbl_t *headers; /*!< parsed request header entries */
|
||||
char *host; /*!< host ex) www.domain.com or www.domain.com:8080 */
|
||||
char *domain; /*!< domain name ex) www.domain.com (no port number) */
|
||||
off_t contentlength; /*!< value of Content-Length header.*/
|
||||
size_t bodyin; /*!< bytes moved to in-buff */
|
||||
} request;
|
||||
|
||||
// HTTP Response
|
||||
struct
|
||||
{
|
||||
struct evbuffer *outbuf; /*!< output data buffer. */
|
||||
bool frozen_header; /*!< indicator whether we sent header out or not */
|
||||
|
||||
// response headers
|
||||
int code; /*!< response status-code */
|
||||
char *reason; /*!< reason-phrase */
|
||||
qlisttbl_t *headers; /*!< response header entries */
|
||||
off_t contentlength; /*!< content length in response */
|
||||
size_t bodyout; /*!< bytes added to out-buffer */
|
||||
} response;
|
||||
};
|
||||
|
||||
#endif /* _RESTD_HTTP_HANDLER_H */
|
||||
@@ -1,33 +0,0 @@
|
||||
/*!
|
||||
* 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);
|
||||
|
||||
#endif /* _RESTD_REST_HANDLER_H */
|
||||
@@ -1,176 +0,0 @@
|
||||
/*!
|
||||
* restd_server.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_SERVER_H
|
||||
#define _RESTD_SERVER_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <qlibc/qlibc.h>
|
||||
|
||||
/*------------------------------- TYPEDEFS ----------------------------------*/
|
||||
|
||||
typedef struct restd_server_s restd_server_t;
|
||||
typedef struct restd_conn_s restd_conn_t;
|
||||
|
||||
/*------------------------------- DEFINE ----------------------------------*/
|
||||
|
||||
/*
|
||||
* Return values of user callback.
|
||||
*/
|
||||
#define RESTD_OK (0) /*!< I'm done with this request. Escalate to other hooks. */
|
||||
#define RESTD_TAKEOVER (1) /*!< I'll handle the buffer directly this time, skip next hook */
|
||||
#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_ERROR_METHOD_NOT_ALLOWED (1)
|
||||
#define RESTD_ERROR_PATH_NOT_FOUND (2)
|
||||
|
||||
/*
|
||||
* 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, restd_conn_t *conn);
|
||||
typedef int (*restd_callback)(short event, restd_conn_t *conn, void *userdata);
|
||||
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. */
|
||||
|
||||
/**
|
||||
* Defaults
|
||||
*/
|
||||
#define RESTD_NUM_USERDATA (2) /*!< Number of userdata. Currently 0 is for userdata, 1 is for extra. */
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
| 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;
|
||||
};
|
||||
|
||||
/**
|
||||
* Connection structure.
|
||||
*/
|
||||
struct restd_conn_s
|
||||
{
|
||||
restd_server_t *server; /*!< reference pointer to server */
|
||||
struct bufferevent *buffer; /*!< reference pointer to buffer */
|
||||
struct evbuffer *in; /*!< in buffer */
|
||||
struct evbuffer *out; /*!< out buffer */
|
||||
int status; /*!< hook status such as AD_OK */
|
||||
|
||||
void *userdata[2]; /*!< userdata[0] for end user, userdata[1] for extra */
|
||||
restd_userdata_free_cb userdata_free_cb[2]; /*!< callback to release user data */
|
||||
char *method; /*!< request method. set by protocol handler */
|
||||
int id;
|
||||
};
|
||||
|
||||
/*
|
||||
* 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 |
|
||||
\*----------------------------------------------------------------------------*/
|
||||
enum restd_log_e restd_log_level(enum restd_log_e log_level);
|
||||
|
||||
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 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_call_hooks_handler(restd_server_t *server, restd_call_hook_cb 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);
|
||||
|
||||
#endif /* _RESTD_SERVER_H */
|
||||
Reference in New Issue
Block a user