Refactored build system and library includes
This commit is contained in:
+29
-96
@@ -1,107 +1,40 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* aisl.h - header file for AISL library, part of AISLing Technology
|
||||
/*
|
||||
* <aisl/aisl.h>
|
||||
*
|
||||
* Copyright (c) 2017 by Löwenware Ltd. (https://lowenware.com/)
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd.
|
||||
*
|
||||
* Authors and maintainers:
|
||||
* Ilja Kartaschoff <ik@lowenware.com>
|
||||
* Project homepage: https://lowenware.com/aisl/
|
||||
*
|
||||
* DOCUMENTATION
|
||||
* This file is not designed to be used as a documentation, but for looking at
|
||||
* the precise values of constants and definitions.
|
||||
* Please, for documentation refer to web page https://lowenware.com/aisling/ or
|
||||
* file READEME.md from library source package.
|
||||
*
|
||||
* LICENSE and DISCLAIMER
|
||||
*
|
||||
* -------------------------------------------------------------------------- */
|
||||
*/
|
||||
|
||||
#ifndef _AISL_H_
|
||||
#define _AISL_H_
|
||||
#ifndef AISL_H_17EF1616_A00F_49C9_92B6_273AB13BF279
|
||||
#define AISL_H_17EF1616_A00F_49C9_92B6_273AB13BF279
|
||||
|
||||
/* system includes ---------------------------------------------------------- */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
/* aisl includes ------------------------------------------------------------ */
|
||||
/* AISL configuration structure */
|
||||
#include <aisl/config.h>
|
||||
|
||||
/* AISL status codes and utilities */
|
||||
#include <aisl/status.h>
|
||||
|
||||
/* AISL callbacks definitions */
|
||||
#include <aisl/callback.h>
|
||||
|
||||
/* AISL events enumeration and utilities*/
|
||||
#include <aisl/event.h>
|
||||
|
||||
/* AISL instancing, initialization and processing */
|
||||
#include <aisl/instance.h>
|
||||
|
||||
/* Embedded HTTP(s) servers */
|
||||
#include <aisl/server.h>
|
||||
|
||||
/* HTTP(s) clients */
|
||||
#include <aisl/client.h>
|
||||
|
||||
/* HTTP(s) streaming */
|
||||
#include <aisl/stream.h>
|
||||
#include <aisl/handle.h>
|
||||
|
||||
/* HTTP constants and utilities */
|
||||
#include <aisl/http.h>
|
||||
|
||||
|
||||
|
||||
/* Control calls ------------------------------------------------------------ */
|
||||
|
||||
/* DEPRECATED, use aisl_handle_new instead
|
||||
* */
|
||||
aisl_status_t
|
||||
aisl_init();
|
||||
|
||||
/* DEPRECATED, use aisl_handle_free instead
|
||||
* */
|
||||
void
|
||||
aisl_release();
|
||||
|
||||
/* Tell library what socket should be opened. Could be called multiple times.
|
||||
* This function only save passed data. In fact, sockets are being opened only
|
||||
* inside aisl_run loop.
|
||||
* @address : host or IP to listen
|
||||
* @port : port to listen
|
||||
* */
|
||||
|
||||
aisl_status_t
|
||||
aisl_select(const char *address, int port);
|
||||
|
||||
/* Start main loop
|
||||
* @result : exit code
|
||||
* */
|
||||
aisl_status_t
|
||||
aisl_run( int * flags );
|
||||
|
||||
/* Event calls -------------------------------------------------------------- */
|
||||
|
||||
/* Add callback to be executed after timeout. If callback function will return
|
||||
* true, callback will be kept in main loop and raised again, otherwise it will
|
||||
* be removed
|
||||
* @cb : callback function: bool callback (void * u_data)
|
||||
* @usec : delay in milliseconds
|
||||
* @data : user-defined data to be passed to callback
|
||||
* */
|
||||
aisl_status_t
|
||||
aisl_delay(aisl_callback_t cb, uint32_t msec, void *u_data);
|
||||
|
||||
/* Add event listener
|
||||
* @source : pointer to event source
|
||||
* @e_id : event identifier
|
||||
* @cb : callback to be executed
|
||||
* */
|
||||
aisl_status_t
|
||||
aisl_listen(void *source, aisl_event_t e_id, aisl_callback_t cb);
|
||||
|
||||
/* Raise event
|
||||
* @source : pointer to event source data
|
||||
* @e_id : event identifier
|
||||
* @... : custom event data
|
||||
* @result : true if event was handled, false otherwise
|
||||
* */
|
||||
bool
|
||||
aisl_raise(void *source, aisl_event_t e_id, ... );
|
||||
|
||||
/* input stream functions --------------------------------------------------- */
|
||||
|
||||
|
||||
const char *
|
||||
aisl_header_get(aisl_stream_t stream, const char *key);
|
||||
|
||||
const char *
|
||||
aisl_header_get_by_index(aisl_stream_t stream, const char **key, uint32_t i);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
||||
#endif /* !AISL_H */
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* <aisl/callback.h>
|
||||
*
|
||||
* Copyright (c) 2017 by Löwenware Ltd.
|
||||
*
|
||||
* Project homepage: https://lowenware.com/aisl/
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AISL_CALLBACK_H_E99458C9_CCAA_4CAC_97F8_41E8869EE26F
|
||||
#define AISL_CALLBACK_H_E99458C9_CCAA_4CAC_97F8_41E8869EE26F
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <aisl/server.h>
|
||||
#include <aisl/client.h>
|
||||
#include <aisl/stream.h>
|
||||
#include <aisl/http.h>
|
||||
|
||||
#define AISL_CALLBACK(x) ((aisl_callback_t) x)
|
||||
|
||||
|
||||
/* void-type callback */
|
||||
typedef void
|
||||
(* aisl_callback_t) (void);
|
||||
|
||||
|
||||
/* real type callbacks */
|
||||
|
||||
typedef bool
|
||||
(*aisl_server_open_t)( aisl_server_t server, int flags );
|
||||
|
||||
typedef bool
|
||||
(*aisl_server_error_t)( aisl_server_t server, int flags, const char * details );
|
||||
|
||||
typedef bool
|
||||
(*aisl_client_connect_t)( aisl_server_t server, aisl_client_t client );
|
||||
|
||||
typedef bool
|
||||
(*aisl_client_disconnect_t)( aisl_server_t server, aisl_client_t client );
|
||||
|
||||
typedef bool
|
||||
(*aisl_client_timeout_t)( aisl_server_t server, aisl_client_t client );
|
||||
|
||||
typedef bool
|
||||
(*aisl_stream_open_t)( aisl_stream_t stream,
|
||||
aisl_http_method_t method,
|
||||
const char * path,
|
||||
const char * query );
|
||||
|
||||
typedef bool
|
||||
(*aisl_stream_header_t)( aisl_stream_t stream,
|
||||
const char * key,
|
||||
const char * val );
|
||||
|
||||
typedef bool
|
||||
(*aisl_stream_input_t)( aisl_stream_t stream, char * data, int len );
|
||||
|
||||
typedef bool
|
||||
(*aisl_stream_request_t)( aisl_stream_t stream );
|
||||
|
||||
typedef bool
|
||||
(*aisl_stream_output_t)( aisl_stream_t stream, uint32_t buffer_space );
|
||||
|
||||
typedef bool
|
||||
(*aisl_stream_close_t)( aisl_stream_t stream );
|
||||
|
||||
typedef bool
|
||||
(*aisl_stream_error_t)( aisl_stream_t stream, const char * details );
|
||||
|
||||
typedef bool
|
||||
(*aisl_custom_event_t)( void * source, va_list vl );
|
||||
|
||||
#endif /* !AISL_CALLBACK_H */
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* <aisl/server.h>
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd.
|
||||
*
|
||||
* Project homepage: https://lowenware.com/aisl/
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AISL_CLIENT_H_A6C37DCF_2183_4F22_A5A0_668311757A08
|
||||
#define AISL_CLIENT_H_A6C37DCF_2183_4F22_A5A0_668311757A08
|
||||
|
||||
typedef struct aisl_client * aisl_client_t;
|
||||
|
||||
#endif /* !AISL_CLIENT_H */
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* <aisl/config.h>
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd.
|
||||
*
|
||||
* Project homepage: https://lowenware.com/aisl/
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AISL_CONFIG_H_DB67A89B_5CAF_4A5F_AEB1_6DB9F84827D6
|
||||
#define AISL_CONFIG_H_DB67A89B_5CAF_4A5F_AEB1_6DB9F84827D6
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
struct aisl_config
|
||||
{
|
||||
uint32_t servers_spool_size;
|
||||
uint32_t clients_spool_size;
|
||||
uint32_t ssl_spool_size;
|
||||
uint32_t events_spool_size;
|
||||
uint32_t initial_buffer_size;
|
||||
uint32_t clients_accept_limit;
|
||||
};
|
||||
|
||||
typedef struct aisl_config * aisl_config_t;
|
||||
|
||||
#endif /* !AISL_CONFIG_H */
|
||||
+29
-115
@@ -1,128 +1,42 @@
|
||||
#ifndef _AISL_EVENT_H_
|
||||
#define _AISL_EVENT_H_
|
||||
/*
|
||||
* <aisl/event.h>
|
||||
*
|
||||
* Copyright (c) 2017 by Löwenware Ltd.
|
||||
*
|
||||
* Project homepage: https://lowenware.com/aisl/
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <aisl/stream.h>
|
||||
#include <aisl/status.h>
|
||||
#include <aisl/http.h>
|
||||
#ifndef AISL_EVENT_H_E99458C9_CCAA_4CAC_97F8_41E8869EE26F
|
||||
#define AISL_EVENT_H_E99458C9_CCAA_4CAC_97F8_41E8869EE26F
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#include <stdint.h>
|
||||
|
||||
typedef unsigned int aisl_event_t;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
typedef enum
|
||||
enum
|
||||
{
|
||||
AISL_SERVER_OPEN = 100,
|
||||
AISL_SERVER_ERROR = 190,
|
||||
AISL_SERVER_OPEN = 100
|
||||
, AISL_SERVER_ERROR = 190
|
||||
|
||||
AISL_CLIENT_CONNECT = 200,
|
||||
AISL_CLIENT_DISCONNECT = 210,
|
||||
AISL_CLIENT_TIMEOUT = 220,
|
||||
, AISL_CLIENT_CONNECT = 200
|
||||
, AISL_CLIENT_DISCONNECT = 210
|
||||
, AISL_CLIENT_TIMEOUT = 220
|
||||
|
||||
AISL_STREAM_OPEN = 300, /* 5 - headers recieved */
|
||||
AISL_STREAM_HEADER = 310, /* 5 - headers recieved */
|
||||
AISL_STREAM_INPUT = 320, /* 6 - chunk of data transmission */
|
||||
AISL_STREAM_REQUEST = 330, /* 7 - data received, response required */
|
||||
AISL_STREAM_OUTPUT = 340,/* event for long-size responses optimal handling */
|
||||
AISL_STREAM_CLOSE = 350,
|
||||
AISL_STREAM_ERROR = 390, /* 8 - bad request */
|
||||
, AISL_STREAM_OPEN = 300
|
||||
, AISL_STREAM_HEADER = 310
|
||||
, AISL_STREAM_INPUT = 320
|
||||
, AISL_STREAM_REQUEST = 330
|
||||
, AISL_STREAM_OUTPUT = 340
|
||||
, AISL_STREAM_CLOSE = 350
|
||||
, AISL_STREAM_ERROR = 390
|
||||
|
||||
AISL_EVENTS_CUSTOM = 999
|
||||
, AISL_EVENTS_CUSTOM = 1000
|
||||
|
||||
} aisl_event_id_t;
|
||||
};
|
||||
|
||||
typedef uint32_t aisl_event_t;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/* AISL_SERVER_OPEN event handler */
|
||||
typedef bool
|
||||
(*aisl_server_open_t)( aisl_server_t server,
|
||||
int flags );
|
||||
|
||||
/* AISL_SERVER_ERROR event handler */
|
||||
typedef bool
|
||||
(*aisl_server_error_t)( aisl_server_t server,
|
||||
int flags,
|
||||
const char * details );
|
||||
|
||||
/* AISL_CLIENT_CONNECT event handler */
|
||||
typedef bool
|
||||
(*aisl_client_connect_t)( aisl_server_t server,
|
||||
aisl_client_t client );
|
||||
|
||||
/* AISL_CLIENT_DISCONNECT event handler */
|
||||
typedef bool
|
||||
(*aisl_client_disconnect_t)( aisl_server_t server,
|
||||
aisl_client_t client );
|
||||
|
||||
/* AISL_CLIENT_DISCONNECT event handler */
|
||||
typedef bool
|
||||
(*aisl_client_timeout_t)( aisl_server_t server,
|
||||
aisl_client_t client );
|
||||
|
||||
/* AISL_STREAM_OPEN event handler */
|
||||
typedef bool
|
||||
(*aisl_stream_open_t)( aisl_stream_t s,
|
||||
aisl_http_method_t method,
|
||||
const char * path,
|
||||
const char * query );
|
||||
|
||||
typedef bool
|
||||
(*aisl_stream_header_t)( aisl_stream_t s,
|
||||
const char * key,
|
||||
const char * value );
|
||||
|
||||
|
||||
/* AISL_STREAM_INPUT event handler */
|
||||
typedef bool
|
||||
(*aisl_stream_input_t)( aisl_stream_t s,
|
||||
char * data,
|
||||
int len );
|
||||
|
||||
/* AISL_STREAM_REQUEST event handler */
|
||||
typedef bool
|
||||
(*aisl_stream_request_t)( aisl_stream_t s );
|
||||
|
||||
/* AISL_STREAM_OUTPUT event handler */
|
||||
typedef bool
|
||||
(*aisl_stream_output_t)( aisl_stream_t s,
|
||||
uint32_t buffer_space );
|
||||
|
||||
typedef bool
|
||||
(*aisl_stream_close_t)( aisl_stream_t s );
|
||||
|
||||
/* AISL_STREAM_ERROR event handler */
|
||||
typedef bool
|
||||
(*aisl_stream_error_t)( aisl_stream_t s,
|
||||
const char * details );
|
||||
|
||||
/* CUSTOM event_handler */
|
||||
typedef bool
|
||||
(*aisl_custom_event_t)( void * source,
|
||||
va_list vl );
|
||||
|
||||
/* on delay timeout */
|
||||
typedef bool
|
||||
(*aisl_delay_timeout_t)( void * u_data );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/* type for event callbacks to use in structures and function prototypes */
|
||||
typedef bool
|
||||
(* aisl_callback_t) (void);
|
||||
|
||||
/* cast callback as aisl_callback_t */
|
||||
#define AISL_CALLBACK(x) ((aisl_callback_t) x)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
aisl_event_get_text( aisl_event_t e_id );
|
||||
aisl_event_get_text( aisl_event_t event );
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
||||
#endif /* !AISL_EVENT_H */
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
#ifndef _AISL_HANDLE_H_
|
||||
#define _AISL_HANDLE_H_
|
||||
|
||||
#include <aisl/status.h>
|
||||
#include <aisl/event.h>
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#define AISL_FLAG_SSL (1<<0)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct aisl_handle * aisl_handle_t;
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
aisl_handle_t
|
||||
aisl_handle_new(size_t min_clients, size_t buffer_size);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
aisl_handle_t
|
||||
aisl_handle_from_stream( aisl_stream_t s );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
aisl_handle_free( aisl_handle_t self );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
aisl_status_t
|
||||
aisl_bind( aisl_handle_t self, const char * address, int port, int flags );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
aisl_status_t
|
||||
aisl_set_ssl( aisl_handle_t self, const char * server_name,
|
||||
const char * key_file,
|
||||
const char * crt_file );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
aisl_status_t
|
||||
aisl_set_callback( aisl_handle_t self,
|
||||
void * source,
|
||||
aisl_event_t e_id,
|
||||
aisl_callback_t cb );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool
|
||||
aisl_raise_event( aisl_handle_t self,
|
||||
void * source,
|
||||
aisl_event_t e_id,
|
||||
... );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
aisl_status_t
|
||||
aisl_run_cycle( aisl_handle_t self );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
aisl_handle_get_error( aisl_handle_t self );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
aisl_sleep( aisl_handle_t self, unsigned long usec );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
||||
+74
-74
@@ -1,104 +1,104 @@
|
||||
#ifndef _AISL_HTTP_H_
|
||||
#define _AISL_HTTP_H_
|
||||
/*
|
||||
* aisl/http.h
|
||||
*
|
||||
* Copyright (c) 2017 by Löwenware Ltd.
|
||||
*
|
||||
* Project homepage: https://lowenware.com/aisl/
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AISL_HTTP_H_2BB40A17_5EB3_438B_8A98_EB3C68BA3A45
|
||||
#define AISL_HTTP_H_2BB40A17_5EB3_438B_8A98_EB3C68BA3A45
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
AISL_HTTP_1_0,
|
||||
AISL_HTTP_1_1,
|
||||
AISL_HTTP_2_0
|
||||
AISL_HTTP_1_0
|
||||
, AISL_HTTP_1_1
|
||||
, AISL_HTTP_2_0
|
||||
|
||||
} aisl_http_version_t;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
typedef enum
|
||||
{
|
||||
AISL_HTTP_GET
|
||||
, AISL_HTTP_PUT
|
||||
, AISL_HTTP_POST
|
||||
, AISL_HTTP_HEAD
|
||||
, AISL_HTTP_TRACE
|
||||
, AISL_HTTP_DELETE
|
||||
, AISL_HTTP_OPTIONS
|
||||
, AISL_HTTP_CONNECT
|
||||
|
||||
typedef enum {
|
||||
AISL_HTTP_GET,
|
||||
AISL_HTTP_PUT,
|
||||
AISL_HTTP_POST,
|
||||
AISL_HTTP_HEAD,
|
||||
AISL_HTTP_TRACE,
|
||||
AISL_HTTP_DELETE,
|
||||
AISL_HTTP_OPTIONS,
|
||||
AISL_HTTP_CONNECT,
|
||||
|
||||
AISL_HTTP_PRI
|
||||
, AISL_HTTP_PRI
|
||||
|
||||
} aisl_http_method_t;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
/* informational ------------------------------ */
|
||||
AISL_HTTP_CONTINUE = 100,
|
||||
AISL_HTTP_SWITCHING_PROTOCOLS,
|
||||
/* Successful --------------------------------- */
|
||||
AISL_HTTP_OK = 200,
|
||||
AISL_HTTP_CREATED,
|
||||
AISL_HTTP_ACCEPTED,
|
||||
AISL_HTTP_NON_AUTHORITATIVE_INFORMATION,
|
||||
AISL_HTTP_NO_CONTENT,
|
||||
AISL_HTTP_RESET_CONTENT,
|
||||
AISL_HTTP_PARTIAL_CONTENT,
|
||||
/* redirection -------------------------------- */
|
||||
AISL_HTTP_MULTIPLE_CHOICES = 300,
|
||||
AISL_HTTP_MOVED_PERMANENTLY,
|
||||
AISL_HTTP_FOUND,
|
||||
AISL_HTTP_SEE_OTHER,
|
||||
AISL_HTTP_NOT_MODIFIED,
|
||||
AISL_HTTP_USE_PROXY,
|
||||
AISL_HTTP_UNUSED,
|
||||
AISL_HTTP_TEMPORARY_REDIRECT,
|
||||
/* client error ------------------------------- */
|
||||
AISL_HTTP_BAD_REQUEST = 400,
|
||||
AISL_HTTP_UNAUTHORIZED,
|
||||
AISL_HTTP_PAYMENT_REQUIRED,
|
||||
AISL_HTTP_FORBIDDEN,
|
||||
AISL_HTTP_NOT_FOUND,
|
||||
AISL_HTTP_METHOD_NOT_ALLOWED,
|
||||
AISL_HTTP_NOT_ACCEPTABLE,
|
||||
AISL_HTTP_PROXY_AUTHENTICATION_REQUIRED,
|
||||
AISL_HTTP_REQUEST_TIMEOUT,
|
||||
AISL_HTTP_CONFLICT,
|
||||
AISL_HTTP_GONE,
|
||||
AISL_HTTP_LENGTH_REQUIRED,
|
||||
AISL_HTTP_PRECONDITION_FAILED,
|
||||
AISL_HTTP_REQUEST_ENTITY_TOO_LARGE,
|
||||
AISL_HTTP_REQUEST_URI_TOO_LONG,
|
||||
AISL_HTTP_UNSUPPORTED_MEDIA_TYPE,
|
||||
AISL_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE,
|
||||
AISL_HTTP_EXPECTATION_FAILED,
|
||||
/* server error ------------------------------- */
|
||||
AISL_HTTP_INTERNAL_SERVER_ERROR = 500,
|
||||
AISL_HTTP_NOT_IMPLEMENTED,
|
||||
AISL_HTTP_BAD_GATEWAY,
|
||||
AISL_HTTP_SERVICE_UNAVAILABLE,
|
||||
AISL_HTTP_GATEWAY_TIMEOUT,
|
||||
AISL_HTTP_VERSION_NOT_SUPPORTED
|
||||
AISL_HTTP_CONTINUE = 100
|
||||
, AISL_HTTP_SWITCHING_PROTOCOLS
|
||||
|
||||
, AISL_HTTP_OK = 200
|
||||
, AISL_HTTP_CREATED
|
||||
, AISL_HTTP_ACCEPTED
|
||||
, AISL_HTTP_NON_AUTHORITATIVE_INFORMATION
|
||||
, AISL_HTTP_NO_CONTENT
|
||||
, AISL_HTTP_RESET_CONTENT
|
||||
, AISL_HTTP_PARTIAL_CONTENT
|
||||
|
||||
, AISL_HTTP_MULTIPLE_CHOICES = 300
|
||||
, AISL_HTTP_MOVED_PERMANENTLY
|
||||
, AISL_HTTP_FOUND
|
||||
, AISL_HTTP_SEE_OTHER
|
||||
, AISL_HTTP_NOT_MODIFIED
|
||||
, AISL_HTTP_USE_PROXY
|
||||
, AISL_HTTP_UNUSED
|
||||
, AISL_HTTP_TEMPORARY_REDIRECT
|
||||
|
||||
, AISL_HTTP_BAD_REQUEST = 400
|
||||
, AISL_HTTP_UNAUTHORIZED
|
||||
, AISL_HTTP_PAYMENT_REQUIRED
|
||||
, AISL_HTTP_FORBIDDEN
|
||||
, AISL_HTTP_NOT_FOUND
|
||||
, AISL_HTTP_METHOD_NOT_ALLOWED
|
||||
, AISL_HTTP_NOT_ACCEPTABLE
|
||||
, AISL_HTTP_PROXY_AUTHENTICATION_REQUIRED
|
||||
, AISL_HTTP_REQUEST_TIMEOUT
|
||||
, AISL_HTTP_CONFLICT
|
||||
, AISL_HTTP_GONE
|
||||
, AISL_HTTP_LENGTH_REQUIRED
|
||||
, AISL_HTTP_PRECONDITION_FAILED
|
||||
, AISL_HTTP_REQUEST_ENTITY_TOO_LARGE
|
||||
, AISL_HTTP_REQUEST_URI_TOO_LONG
|
||||
, AISL_HTTP_UNSUPPORTED_MEDIA_TYPE
|
||||
, AISL_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE
|
||||
, AISL_HTTP_EXPECTATION_FAILED
|
||||
|
||||
, AISL_HTTP_INTERNAL_SERVER_ERROR = 500
|
||||
, AISL_HTTP_NOT_IMPLEMENTED
|
||||
, AISL_HTTP_BAD_GATEWAY
|
||||
, AISL_HTTP_SERVICE_UNAVAILABLE
|
||||
, AISL_HTTP_GATEWAY_TIMEOUT
|
||||
, AISL_HTTP_VERSION_NOT_SUPPORTED
|
||||
|
||||
} aisl_http_response_t;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
const char *
|
||||
aisl_http_version_to_string(aisl_http_version_t version);
|
||||
aisl_http_version_to_string( aisl_http_version_t version );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
aisl_http_response_to_string(aisl_http_response_t code);
|
||||
aisl_http_response_to_string( aisl_http_response_t code );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
aisl_http_secure_to_string( int is_secure );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
aisl_http_method_to_string( aisl_http_method_t method );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
||||
#endif /* !AISL_HTTP_H */
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* <aisl/instance.h>
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd.
|
||||
*
|
||||
* Project homepage: https://lowenware.com/aisl/
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef INSTANCE_H_60576F41_454C_4189_B91A_F40501132230
|
||||
#define INSTANCE_H_60576F41_454C_4189_B91A_F40501132230
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
typedef struct aisl_instance * aisl_instance_t;
|
||||
|
||||
|
||||
/* Initialization functions */
|
||||
|
||||
aisl_instance_t
|
||||
aisl_new( aisl_config_t * config );
|
||||
|
||||
|
||||
void
|
||||
aisl_free( aisl_instance_t instance );
|
||||
|
||||
|
||||
aisl_server_t
|
||||
aisl_listen( aisl_instance_t instance,
|
||||
const char * address,
|
||||
uint16_t port );
|
||||
|
||||
|
||||
#ifdef AISL_WITH_SSL
|
||||
|
||||
aisl_status_t
|
||||
aisl_set_ssl( aisl_instance_t instance,
|
||||
const char * hostname,
|
||||
const char * key_file,
|
||||
const char * crt_file );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aisl_set_callback( aisl_instance_t instance,
|
||||
void * source,
|
||||
aisl_event_t e_id,
|
||||
aisl_callback_t cb );
|
||||
|
||||
|
||||
/* Control functions */
|
||||
|
||||
aisl_status_t
|
||||
aisl_run_cycle( aisl_instance_t instance );
|
||||
|
||||
|
||||
const char *
|
||||
aisl_get_error( aisl_instance_t instance );
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aisl_sleep( aisl_instance_t instance, uint32_t usec );
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aisl_raise( aisl_instance_t instance, aisl_event_t event, ...);
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aisl_raisev( aisl_instance_t instance, aisl_event_t event, va_list args);
|
||||
|
||||
#endif /* !INSTANCE_H */
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* <aisl/server.h>
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd.
|
||||
*
|
||||
* Project homepage: https://lowenware.com/aisl/
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AISL_SERVER_H_CC564608_7A05_4B31_9E7E_32750BC60768
|
||||
#define AISL_SERVER_H_CC564608_7A05_4B31_9E7E_32750BC60768
|
||||
|
||||
typedef struct aisl_server * aisl_server_t;
|
||||
|
||||
|
||||
#ifdef AISL_WITH_SSL
|
||||
|
||||
aisl_status_t
|
||||
aisl_server_set_ssl( aisl_server_t server, bool value );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* !AISL_SERVER_H */
|
||||
+18
-13
@@ -1,24 +1,29 @@
|
||||
#ifndef _AISL_STATUS_H_
|
||||
#define _AISL_STATUS_H_
|
||||
/*
|
||||
* <aisl/status.h>
|
||||
*
|
||||
* Copyright (c) 2017 by Löwenware Ltd.
|
||||
*
|
||||
* Project homepage: https://lowenware.com/aisl/
|
||||
*
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#ifndef AISL_STATUS_H_BF7E4434_A711_4D7C_B3AE_1BA2E1A020EF
|
||||
#define AISL_STATUS_H_BF7E4434_A711_4D7C_B3AE_1BA2E1A020EF
|
||||
|
||||
typedef enum {
|
||||
|
||||
AISL_EXTCALL_ERROR = -3,
|
||||
AISL_SYSCALL_ERROR = -2,
|
||||
AISL_MALLOC_ERROR = -1,
|
||||
typedef enum
|
||||
{
|
||||
AISL_EXTCALL_ERROR = -3
|
||||
, AISL_SYSCALL_ERROR = -2
|
||||
, AISL_MALLOC_ERROR = -1
|
||||
|
||||
AISL_SUCCESS = 0,
|
||||
AISL_IDLE = 1
|
||||
, AISL_SUCCESS = 0
|
||||
, AISL_IDLE = 1
|
||||
|
||||
} aisl_status_t;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
aisl_status_to_string(aisl_status_t status);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
||||
#endif /* !AISL_STATUS_H */
|
||||
|
||||
+83
-151
@@ -1,172 +1,104 @@
|
||||
#ifndef _AISL_STREAM_H_
|
||||
#define _AISL_STREAM_H_
|
||||
/*
|
||||
* <aisl/stream.h>
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd.
|
||||
*
|
||||
* Project homepage: https://lowenware.com/aisl/
|
||||
*
|
||||
*/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
/* Library statuses */
|
||||
/* HTTP requests */
|
||||
#include <aisl/http.h>
|
||||
#include <aisl/status.h>
|
||||
#ifndef STREAM_H_4D8EB622_3CE0_4F1B_AC1F_B27CCB5C2EDC
|
||||
#define STREAM_H_4D8EB622_3CE0_4F1B_AC1F_B27CCB5C2EDC
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct sockaddr_in * aisl_server_t;
|
||||
typedef struct sockaddr_in * aisl_client_t;
|
||||
|
||||
struct aisl_stream
|
||||
{
|
||||
/* DO NOT USE PROPERTIES DIRECTLY IN NEW CODE */
|
||||
|
||||
struct sockaddr_in *client;
|
||||
|
||||
const char *host;
|
||||
const char *path;
|
||||
const char *query;
|
||||
const char *scheme;
|
||||
|
||||
void *u_ptr; /* pointer to bind custom data to stream */
|
||||
|
||||
aisl_http_method_t request_method;
|
||||
};
|
||||
|
||||
/* pointer to stream descriptor */
|
||||
typedef struct aisl_stream * aisl_stream_t;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/* start response to client
|
||||
* this function should be called before any header or content function
|
||||
* necessary protocol headers as well as Content-Type and Content-Length
|
||||
* will be set automaticaly
|
||||
* @stream : stream instance
|
||||
* @status : HTTP response status code (default 200)
|
||||
* @content_type : string with content type (default text/html), NULL -> no
|
||||
* @content_length : length of content, 0 = no content
|
||||
* */
|
||||
aisl_status_t
|
||||
aisl_response(aisl_stream_t stream, aisl_http_response_t status_code,
|
||||
const char *content_type,
|
||||
uint32_t content_length);
|
||||
|
||||
/* send all buffered data to client
|
||||
* ALL responses should always be finished with calling of this method
|
||||
* @stream : stream instance
|
||||
* */
|
||||
aisl_status_t
|
||||
aisl_flush(aisl_stream_t stream);
|
||||
|
||||
/* header functions --------------------------------------------------------- */
|
||||
|
||||
/* add custom header to stream
|
||||
* this function should be called before content functions
|
||||
* @stream : stream instance
|
||||
* @key : header key string
|
||||
* @value : header value string
|
||||
* */
|
||||
int
|
||||
aisl_header(aisl_stream_t stream, const char *key, const char *value);
|
||||
|
||||
/* add custom header to stream
|
||||
* this function should be called before content functions
|
||||
* @stream : stream instance
|
||||
* @key : header key string
|
||||
* @f_value : value format string, same as for printf function
|
||||
* @... : arguments according to f_value string
|
||||
* */
|
||||
int
|
||||
aisl_header_printf(aisl_stream_t stream, const char *key,
|
||||
const char *f_value, ...);
|
||||
|
||||
/* add custom header to stream
|
||||
* this function should be called before content functions
|
||||
* @stream : stream instance
|
||||
* @key : header key string
|
||||
* @f_value : value format string, same as for printf function
|
||||
* @args : arguments macro according to f_value string
|
||||
* */
|
||||
int
|
||||
aisl_header_vprintf(aisl_stream_t stream, const char *key,
|
||||
const char *format,
|
||||
va_list args);
|
||||
|
||||
|
||||
/* data response functions -------------------------------------------------- */
|
||||
|
||||
/* response formated data to client
|
||||
* @stream : stream instance
|
||||
* @format : format string, same as for printf
|
||||
* @... : arguments according to format string
|
||||
* @result : number of responed bytes
|
||||
* */
|
||||
int
|
||||
aisl_printf(aisl_stream_t stream, const char *format, ...);
|
||||
|
||||
|
||||
/* response formated data to client
|
||||
* @stream : stream instance
|
||||
* @format : format string, same as for printf
|
||||
* @args : arguments macro according to format string
|
||||
* @result : number of responed bytes
|
||||
* */
|
||||
int
|
||||
aisl_vprintf(aisl_stream_t stream, const char *format, va_list args);
|
||||
|
||||
/* response characters to client
|
||||
* @stream : stream instance
|
||||
* @data : characters to be sent
|
||||
* @d_len : number of characters to send
|
||||
* @result : number of responed bytes
|
||||
* */
|
||||
int
|
||||
aisl_write(aisl_stream_t s, const char *data, int d_len);
|
||||
|
||||
/* response string to client
|
||||
* @string : string to be sent
|
||||
* @stream : stream instance
|
||||
* @result : number of responed bytes
|
||||
* */
|
||||
int
|
||||
aisl_puts(const char *string, aisl_stream_t stream);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
aisl_cancel(aisl_stream_t s);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Stream helpers */
|
||||
|
||||
bool
|
||||
aisl_is_secure(aisl_stream_t s);
|
||||
aisl_is_secure( aisl_stream_t stream );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void *
|
||||
aisl_get_context(aisl_stream_t s);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
aisl_set_context(aisl_stream_t s, void * u_ptr);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
aisl_client_t
|
||||
aisl_get_client(aisl_stream_t s);
|
||||
aisl_get_client( aisl_stream_t stream );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
aisl_server_t
|
||||
aisl_get_server(aisl_stream_t s);
|
||||
aisl_get_server( aisl_stream_t stream );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
aisl_http_version_t
|
||||
aisl_get_http_version(aisl_stream_t s);
|
||||
aisl_get_http_version( aisl_stream_t stream );
|
||||
|
||||
|
||||
aisl_instance_t
|
||||
aisl_stream_get_instance( aisl_stream_t s );
|
||||
|
||||
|
||||
/* Context functions */
|
||||
|
||||
void *
|
||||
aisl_get_context( aisl_stream_t stream );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
aisl_reject( aisl_stream_t s);
|
||||
aisl_set_context( aisl_stream_t stream, void * context );
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
||||
/* Stream control functions */
|
||||
|
||||
aisl_status_t
|
||||
aisl_flush( aisl_stream_t stream );
|
||||
|
||||
|
||||
void
|
||||
aisl_cancel( aisl_stream_t stream );
|
||||
|
||||
|
||||
void
|
||||
aisl_reject( aisl_stream_t stream );
|
||||
|
||||
|
||||
/* Response functions */
|
||||
|
||||
aisl_status_t
|
||||
aisl_response( aisl_stream_t stream,
|
||||
aisl_http_response_t status_code,
|
||||
const char * content_type,
|
||||
uint32_t content_length);
|
||||
|
||||
|
||||
int
|
||||
aisl_header( aisl_stream_t stream, const char *key, const char *value );
|
||||
|
||||
|
||||
int
|
||||
aisl_header_printf( aisl_stream_t stream,
|
||||
const char * key,
|
||||
const char * format,
|
||||
... );
|
||||
|
||||
|
||||
int
|
||||
aisl_header_vprintf( aisl_stream_t stream,
|
||||
const char * key,
|
||||
const char * format,
|
||||
va_list args );
|
||||
|
||||
|
||||
int
|
||||
aisl_printf( aisl_stream_t stream, const char * format, ... );
|
||||
|
||||
|
||||
int
|
||||
aisl_vprintf( aisl_stream_t stream, const char * format, va_list args );
|
||||
|
||||
|
||||
int
|
||||
aisl_write( aisl_stream_t stream, const char * data, int d_len );
|
||||
|
||||
|
||||
int
|
||||
aisl_puts( const char * str_data, aisl_stream_t stream );
|
||||
|
||||
#endif /* !AISL_STREAM_H */
|
||||
|
||||
Reference in New Issue
Block a user