Update to version 1.0.5
This commit is contained in:
+27
-97
@@ -1,107 +1,37 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* aisl.h - header file for AISL library, part of AISLing Technology
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017 by Löwenware Ltd. (https://lowenware.com/)
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
* Authors and maintainers:
|
||||
* Ilja Kartaschoff <ik@lowenware.com>
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file aisl/aisl.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief Meta header file of 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
|
||||
*
|
||||
* -------------------------------------------------------------------------- */
|
||||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#ifndef _AISL_H_
|
||||
#define _AISL_H_
|
||||
#ifndef AISL_H_17EF1616_A00F_49C9_92B6_273AB13BF279
|
||||
#define AISL_H_17EF1616_A00F_49C9_92B6_273AB13BF279
|
||||
|
||||
/* system includes ---------------------------------------------------------- */
|
||||
/* AISL configuration structure */
|
||||
#include <aisl/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <arpa/inet.h>
|
||||
/* AISL types and stringifiers */
|
||||
#include <aisl/types.h>
|
||||
|
||||
/* aisl includes ------------------------------------------------------------ */
|
||||
/* AISL instancing, initialization and processing */
|
||||
#include <aisl/instance.h>
|
||||
|
||||
#include <aisl/status.h>
|
||||
#include <aisl/event.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>
|
||||
#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,74 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file aisl/client.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief Declarations of #AislCLient functions
|
||||
*
|
||||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#ifndef AISL_CLIENT_H_A6C37DCF_2183_4F22_A5A0_668311757A08
|
||||
#define AISL_CLIENT_H_A6C37DCF_2183_4F22_A5A0_668311757A08
|
||||
|
||||
#include <aisl/types.h>
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets #AislServer instance associated with client.
|
||||
* @param client an #AislClient instance pointer.
|
||||
* @return an associated #AislServer pointer.
|
||||
*/
|
||||
AislServer
|
||||
aisl_client_get_server(AislClient client);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets security connection status.
|
||||
* @param client an #AislClient instance pointer.
|
||||
* @return true if SSL is enabled and false if disabled.
|
||||
*/
|
||||
bool
|
||||
aisl_client_is_secure(AislClient client);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets client's connection state.
|
||||
* @param client an #AislClient instance pointer.
|
||||
* @return true if client is online and false if is offline.
|
||||
*/
|
||||
bool
|
||||
aisl_client_is_online(AislClient client);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Forcefully closes client's connection.
|
||||
* @param client an #AislClient instance pointer.
|
||||
*/
|
||||
void
|
||||
aisl_client_disconnect(AislClient client);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets HTTP protocol version.
|
||||
* @param client an #AislClient instance pointer.
|
||||
* @return HTTP protocol version
|
||||
*/
|
||||
AislHttpVersion
|
||||
aisl_client_get_http_version(AislClient client);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Copies #AislClient network address to provided sockaddr_in structure.
|
||||
* @param client an #AislClient instance pointer.
|
||||
* @param address a pointer to a sockaddr_in structure
|
||||
*/
|
||||
void
|
||||
aisl_client_get_address(AislClient client, struct sockaddr_in *address);
|
||||
|
||||
#endif /* !AISL_CLIENT_H */
|
||||
@@ -0,0 +1,64 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file aisl/config.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief Declarations of AISL configuration structures
|
||||
*
|
||||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#ifndef AISL_CONFIG_H_DB67A89B_5CAF_4A5F_AEB1_6DB9F84827D6
|
||||
#define AISL_CONFIG_H_DB67A89B_5CAF_4A5F_AEB1_6DB9F84827D6
|
||||
|
||||
#include <aisl/types.h>
|
||||
|
||||
#define AISL_CFG_DEFAULTS \
|
||||
.client_spool_size = 32 \
|
||||
, .initial_buffer_size = 16536 \
|
||||
, .client_accept_limit = 1024 \
|
||||
, .client_silence_timeout = 30 \
|
||||
|
||||
|
||||
/** @brief Server configuration structure
|
||||
*/
|
||||
struct aisl_cfg_srv {
|
||||
const char *host; /**< server IP to listen */
|
||||
uint16_t port; /**< server port to listen */
|
||||
bool secure; /**< shall server use TLS */
|
||||
};
|
||||
|
||||
|
||||
/** @brief SSL configuration structure
|
||||
*/
|
||||
struct aisl_cfg_ssl {
|
||||
const char *host; /**< secure server hostname */
|
||||
const char *key_file; /**< path to SSL key file */
|
||||
const char *crt_file; /**< path to SSL certificate file */
|
||||
};
|
||||
|
||||
|
||||
/** @brief AISL initial configuration structure
|
||||
*/
|
||||
struct aisl_cfg {
|
||||
AislCallback callback; /**< A pointer to #AislCallback event handler */
|
||||
void *p_ctx; /**< User defined context for #AislCallback */
|
||||
|
||||
const struct aisl_cfg_srv *srv; /**< A pointer to array of #aisl_cfg_srv */
|
||||
const struct aisl_cfg_ssl *ssl; /**< A pointer to array of #aisl_cfg_ssl */
|
||||
|
||||
int srv_cnt; /**< Size of #aisl_cfg_srv array */
|
||||
int ssl_cnt; /**< Size of #aisl_cfg_ssl array */
|
||||
|
||||
int client_spool_size; /**< Initial size of client spool */
|
||||
int initial_buffer_size; /**< Initial size of communication buffer */
|
||||
int client_accept_limit; /**< Maximal number of concurent clients */
|
||||
int client_silence_timeout; /**< Client silence timeout */
|
||||
};
|
||||
|
||||
#endif /* !AISL_CONFIG_H */
|
||||
@@ -1,128 +0,0 @@
|
||||
#ifndef _AISL_EVENT_H_
|
||||
#define _AISL_EVENT_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <aisl/stream.h>
|
||||
#include <aisl/status.h>
|
||||
#include <aisl/http.h>
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
typedef unsigned int aisl_event_t;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
AISL_SERVER_OPEN = 100,
|
||||
AISL_SERVER_ERROR = 190,
|
||||
|
||||
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_EVENTS_CUSTOM = 999
|
||||
|
||||
} aisl_event_id_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 );
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -1,104 +0,0 @@
|
||||
#ifndef _AISL_HTTP_H_
|
||||
#define _AISL_HTTP_H_
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
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,
|
||||
|
||||
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_response_t;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
aisl_http_version_to_string(aisl_http_version_t version);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
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
|
||||
@@ -0,0 +1,66 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file aisl/instance.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief Declarations of #AislInstance functions
|
||||
*
|
||||
* @see https://lowenware.com/aisl/
|
||||
|
||||
*/
|
||||
|
||||
#ifndef AISL_INSTANCE_H_60576F41_454C_4189_B91A_F40501132230
|
||||
#define AISL_INSTANCE_H_60576F41_454C_4189_B91A_F40501132230
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <aisl/types.h>
|
||||
#include <aisl/config.h>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Allocates new AISL instance.
|
||||
*
|
||||
* @param cfg a pointer to #aisl_cfg_t structure.
|
||||
* @return an #AislInstance instance pointer.
|
||||
*/
|
||||
AislInstance
|
||||
aisl_new(const struct aisl_cfg *cfg);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Frees previously allocated pointer of AISL instance.
|
||||
* @param instance a pointer to #AislInstance instance.
|
||||
*/
|
||||
void
|
||||
aisl_free(AislInstance instance);
|
||||
|
||||
|
||||
/**
|
||||
* @brief A core function doing all the library routines.
|
||||
* Designed to be called inside application main loop
|
||||
* @param instance a pointer to #AislInstance instance.
|
||||
* @return #AislStatus code.
|
||||
*/
|
||||
AislStatus
|
||||
aisl_run_cycle(AislInstance instance);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function to sleep CPU if nothing to do.
|
||||
* Calls select on all the opened sockets inside.
|
||||
* @param instance a pointer to #AislInstance instance.
|
||||
* @param usec a number of miliseconds to wait for any data on sockets.
|
||||
* @return #AislStatus code.
|
||||
*/
|
||||
AislStatus
|
||||
aisl_sleep(AislInstance instance, uint32_t usec);
|
||||
|
||||
|
||||
#endif /* !AISL_INSTANCE_H */
|
||||
@@ -0,0 +1,48 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file aisl/server.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief Declarations of #AislServer functions
|
||||
*
|
||||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#ifndef AISL_SERVER_H_CC564608_7A05_4B31_9E7E_32750BC60768
|
||||
#define AISL_SERVER_H_CC564608_7A05_4B31_9E7E_32750BC60768
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <aisl/types.h>
|
||||
|
||||
/**
|
||||
* @brief Function to get appropriate AISL instance pointer from server pointer.
|
||||
* @param server an #AislServer pointer.
|
||||
* @return an #AislInstance instance pointer.
|
||||
*/
|
||||
AislInstance
|
||||
aisl_server_get_instance(AislServer server);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Copies server listen address information to sockaddr_in structure.
|
||||
* @param server an #AislServer pointer.
|
||||
* @param address a pointer to sockaddr_in structure.
|
||||
*/
|
||||
void
|
||||
aisl_server_get_address(AislServer server, struct sockaddr_in *address);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function to get on and off status of SSL for the #AislServer.
|
||||
* @param server an #AislServer pointer.
|
||||
* @return a boolean value representing SSL enabled/disabled state.
|
||||
*/
|
||||
bool
|
||||
aisl_server_get_ssl(AislServer server);
|
||||
|
||||
#endif /* !AISL_SERVER_H */
|
||||
@@ -1,24 +0,0 @@
|
||||
#ifndef _AISL_STATUS_H_
|
||||
#define _AISL_STATUS_H_
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
typedef enum {
|
||||
|
||||
AISL_EXTCALL_ERROR = -3,
|
||||
AISL_SYSCALL_ERROR = -2,
|
||||
AISL_MALLOC_ERROR = -1,
|
||||
|
||||
AISL_SUCCESS = 0,
|
||||
AISL_IDLE = 1
|
||||
|
||||
} aisl_status_t;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
aisl_status_to_string(aisl_status_t status);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
||||
+181
-154
@@ -1,172 +1,199 @@
|
||||
#ifndef _AISL_STREAM_H_
|
||||
#define _AISL_STREAM_H_
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
/* Library statuses */
|
||||
/* HTTP requests */
|
||||
#include <aisl/http.h>
|
||||
#include <aisl/status.h>
|
||||
/**
|
||||
* @file aisl/stream.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief Declarations of #AislStream functions
|
||||
*
|
||||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
#ifndef AISL_STREAM_H_4D8EB622_3CE0_4F1B_AC1F_B27CCB5C2EDC
|
||||
#define AISL_STREAM_H_4D8EB622_3CE0_4F1B_AC1F_B27CCB5C2EDC
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <aisl/types.h>
|
||||
|
||||
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);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define aisl_stream_get_instance aisl_get_instance
|
||||
|
||||
/** @brief Gets a value of #AislStream security flag
|
||||
* @param stream an #AislStream instance
|
||||
* @return is true if stream is encrypted and false otherwise
|
||||
*/
|
||||
bool
|
||||
aisl_is_secure(aisl_stream_t s);
|
||||
aisl_is_secure(AislStream stream);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/** @brief Gets an #AislClient instance associated with the stream
|
||||
* @param stream an #AislStream instance
|
||||
* @return an #AislClient instance pointer
|
||||
*/
|
||||
AislClient
|
||||
aisl_get_client(AislStream stream);
|
||||
|
||||
|
||||
/** @brief Gets an #AislServer instance associated with the stream
|
||||
* @param stream an #AislStream instance
|
||||
* @return an #AislServer instance pointer
|
||||
*/
|
||||
AislServer
|
||||
aisl_get_server(AislStream stream);
|
||||
|
||||
|
||||
/** @brief Gets an #AislHttpVersion of the stream
|
||||
* @param stream an #AislStream instance
|
||||
* @return an #AislHttpVersion value
|
||||
*/
|
||||
AislHttpVersion
|
||||
aisl_get_http_version(AislStream stream);
|
||||
|
||||
|
||||
/** @brief Gets an #AislInstance pointer associated with the stream
|
||||
* @param stream an #AislStream instance
|
||||
* @return an #AislInstance pointer
|
||||
*/
|
||||
AislInstance
|
||||
aisl_get_instance(AislStream s);
|
||||
|
||||
|
||||
/** @brief Gets the stream context previously set with #aisl_set_context
|
||||
* @param stream an #AislStream instance
|
||||
* @return a pointer to the stream context
|
||||
*/
|
||||
void *
|
||||
aisl_get_context(aisl_stream_t s);
|
||||
aisl_get_context(AislStream stream);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/** @brief Associate a context pointer with the stream until its lifetime.
|
||||
* Previously allocated data should be free'd on #AISL_EVENT_STREAM_CLOSE if
|
||||
* not needed anymore.
|
||||
* @param stream an #AislStream instance
|
||||
* @param context a pointer to any user-defined data
|
||||
*/
|
||||
void
|
||||
aisl_set_context(aisl_stream_t s, void * u_ptr);
|
||||
aisl_set_context(AislStream stream, void *context);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
aisl_client_t
|
||||
aisl_get_client(aisl_stream_t s);
|
||||
/** @brief A call to start stream data transmission to a client
|
||||
* @param stream an #AislStream instance
|
||||
* @return a #AislStatus displaying if stream is ready to be proceed by teh engine
|
||||
*/
|
||||
AislStatus
|
||||
aisl_flush(AislStream stream);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
aisl_server_t
|
||||
aisl_get_server(aisl_stream_t s);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
aisl_http_version_t
|
||||
aisl_get_http_version(aisl_stream_t s);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/** @brief A call to reject the stream. In HTTP 1.X it also closes client's connection
|
||||
* @param stream an #AislStream instance
|
||||
*/
|
||||
void
|
||||
aisl_reject( aisl_stream_t s);
|
||||
aisl_reject(AislStream stream);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
||||
/** @brief A call to begin the HTTP response
|
||||
* @param stream an #AislStream instance
|
||||
* @param status_code of the HTTP response
|
||||
* @param content_length in bytes or #AISL_AUTO_LENGTH if length is not knonw yet
|
||||
* @return #AislStatus code
|
||||
*/
|
||||
AislStatus
|
||||
aisl_response(AislStream stream,
|
||||
AislHttpResponse status_code,
|
||||
uint64_t content_length);
|
||||
|
||||
|
||||
/** @brief Adds HTTP header to the stream buffer
|
||||
* @param stream an #AislStream instance
|
||||
* @param key of HTTP header
|
||||
* @param value of HTTP header
|
||||
* @return a length of data added to the stream buffer
|
||||
*/
|
||||
int
|
||||
aisl_header(AislStream stream, const char *key, const char *value);
|
||||
|
||||
|
||||
/** @brief Adds printf-like formatted HTTP header to the stream buffer
|
||||
* @param stream an #AislStream instance
|
||||
* @param key of HTTP header
|
||||
* @param format of HTTP header value
|
||||
* @return a length of data added to the stream buffer
|
||||
*/
|
||||
int
|
||||
aisl_header_printf(AislStream stream,
|
||||
const char *key,
|
||||
const char *format,
|
||||
... );
|
||||
|
||||
|
||||
/** @brief Adds vprintf-like formatted HTTP header to the stream buffer
|
||||
* @param stream an #AislStream instance
|
||||
* @param key of HTTP header
|
||||
* @param format of HTTP header value
|
||||
* @param args list for HTTP header value construction
|
||||
* @return a length of data added to the stream buffer
|
||||
*/
|
||||
int
|
||||
aisl_header_vprintf(AislStream stream,
|
||||
const char *key,
|
||||
const char *format,
|
||||
va_list args );
|
||||
|
||||
|
||||
/** @brief Adds printf-like formatted HTTP response to the stream buffer
|
||||
* @param stream an #AislStream instance
|
||||
* @param format of the HTTP response
|
||||
* @return a length of data added to the stream buffer
|
||||
*/
|
||||
int
|
||||
aisl_printf(AislStream stream, const char *format, ...);
|
||||
|
||||
|
||||
/** @brief Adds vprintf-like formatted HTTP response to the stream buffer
|
||||
* @param stream an #AislStream instance
|
||||
* @param format of the HTTP response
|
||||
* @param args list for HTTP response construction
|
||||
* @return a length of data added to the stream buffer
|
||||
*/
|
||||
int
|
||||
aisl_vprintf(AislStream stream, const char *format, va_list args);
|
||||
|
||||
|
||||
/** @brief Adds data of the HTTP response to the stream buffer
|
||||
* @param stream an #AislStream instance
|
||||
* @param data a pointer to HTTP response data array
|
||||
* @param d_len size of the HTTP response data array
|
||||
* @return a length of data added to the stream buffer
|
||||
*/
|
||||
int
|
||||
aisl_write(AislStream stream, const char *data, int d_len);
|
||||
|
||||
|
||||
/** @brief Adds a null-terminated string to the stream buffer
|
||||
* @param str_data the HTTP response string
|
||||
* @param stream an #AislStream instance
|
||||
* @return a length of data added to the stream buffer
|
||||
*/
|
||||
int
|
||||
aisl_puts(const char *str_data, AislStream stream);
|
||||
|
||||
|
||||
/** @brief Switches triggering of #AISL_EVENT_STREAM_OUTPUT
|
||||
* @param stream an #AislStream instance
|
||||
* @param value a true to enable or false to disable (default) triggering
|
||||
*/
|
||||
void
|
||||
aisl_set_output_event(AislStream stream, bool value);
|
||||
|
||||
|
||||
/** @brief Gets state of the #AISL_EVENT_STREAM_OUTPUT triggering
|
||||
* @param stream an #AislStream instance
|
||||
* @return true if triggering is enabled and flase otherwise
|
||||
*/
|
||||
bool
|
||||
aisl_get_output_event(AislStream stream);
|
||||
|
||||
#endif /* !AISL_STREAM_H */
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file aisl/types.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief Declarations of AISL types
|
||||
*
|
||||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#ifndef AISL_TYPES_H_86A9DBA7_C0E6_4CF4_8A64_DAAD4A81031B
|
||||
#define AISL_TYPES_H_86A9DBA7_C0E6_4CF4_8A64_DAAD4A81031B
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define AISL_AUTO_LENGTH (~0)
|
||||
|
||||
/** type casts */
|
||||
#define AISL_CALLBACK(x) ((AislCallback) x)
|
||||
|
||||
|
||||
/** @brief AISL Instance */
|
||||
typedef struct aisl_instance * AislInstance;
|
||||
|
||||
/** @brief HTTP(s) Server */
|
||||
typedef struct aisl_server * AislServer;
|
||||
|
||||
/** @brief HTTP(s) Client */
|
||||
typedef struct aisl_client * AislClient;
|
||||
|
||||
/** @brief Server<->Client Stream */
|
||||
typedef struct aisl_stream * AislStream;
|
||||
|
||||
|
||||
/** status return codes */
|
||||
typedef enum {
|
||||
AISL_INPUT_ERROR = -4
|
||||
, AISL_EXTCALL_ERROR = -3
|
||||
, AISL_SYSCALL_ERROR = -2
|
||||
, AISL_MALLOC_ERROR = -1
|
||||
|
||||
, AISL_SUCCESS = 0
|
||||
, AISL_IDLE = 1
|
||||
} AislStatus;
|
||||
|
||||
|
||||
/** @brief Converts #AislStatus code to a null terminated string
|
||||
* @param status an #AislStatus code
|
||||
* @return pointer to the string representing #AislStatus
|
||||
*/
|
||||
const char *
|
||||
aisl_status_to_string(AislStatus status);
|
||||
|
||||
|
||||
/** @brief HTTP version enumeration */
|
||||
typedef enum {
|
||||
AISL_HTTP_0_9 = 0x0009
|
||||
, AISL_HTTP_1_0 = 0x0100
|
||||
, AISL_HTTP_1_1 = 0x0101
|
||||
, AISL_HTTP_2_0 = 0x0200
|
||||
} AislHttpVersion;
|
||||
|
||||
|
||||
/** @brief Converts #AislHttpVersion code to a null terminated string
|
||||
* @param version an #AislHttpVersion code
|
||||
* @return pointer to the string representing #AislHttpVersion
|
||||
*/
|
||||
const char *
|
||||
aisl_http_version_to_string(AislHttpVersion version);
|
||||
|
||||
|
||||
/** HTTP method enumeration */
|
||||
typedef enum {
|
||||
AISL_HTTP_METHOD_UNKNOWN
|
||||
, 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
|
||||
} AislHttpMethod;
|
||||
|
||||
|
||||
/** @brief Converts #AislHttpMethod code to a null terminated string
|
||||
* @param method an #AislHttpMethod code
|
||||
* @return pointer to the string representing #AislHttpMethod
|
||||
*/
|
||||
const char *
|
||||
aisl_http_method_to_string(AislHttpMethod method);
|
||||
|
||||
|
||||
/** @brief HTTP response status enumeration */
|
||||
typedef enum {
|
||||
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
|
||||
} AislHttpResponse;
|
||||
|
||||
|
||||
/** @brief Converts #AislHttpResponse code to a null terminated string
|
||||
* @param code an #AislHttpResponse code
|
||||
* @return pointer to the string representing #AislHttpResponse
|
||||
*/
|
||||
const char *
|
||||
aisl_http_response_to_string(AislHttpResponse code);
|
||||
|
||||
|
||||
/** @brief AISL events enumeration */
|
||||
typedef enum {
|
||||
AISL_EVENT_SERVER_READY = 100
|
||||
, AISL_EVENT_SERVER_ERROR = 190
|
||||
|
||||
, AISL_EVENT_CLIENT_CONNECT = 200
|
||||
, AISL_EVENT_CLIENT_DISCONNECT = 210
|
||||
|
||||
, AISL_EVENT_STREAM_OPEN = 300
|
||||
, AISL_EVENT_STREAM_HEADER = 310
|
||||
, AISL_EVENT_STREAM_INPUT = 320
|
||||
, AISL_EVENT_STREAM_REQUEST = 330
|
||||
, AISL_EVENT_STREAM_OUTPUT = 340
|
||||
, AISL_EVENT_STREAM_CLOSE = 350
|
||||
, AISL_EVENT_STREAM_ERROR = 390
|
||||
} AislEvent;
|
||||
|
||||
|
||||
/** @brief generic AISL event structure */
|
||||
struct aisl_evt {
|
||||
void *source; /**< Pointer to an event source: #AislServer, #AislClient, #AislStream */
|
||||
AislEvent code; /**< Event code */
|
||||
AislStatus status; /**< Event status */
|
||||
};
|
||||
|
||||
|
||||
/** @brief event handler callback definition
|
||||
* @param evt a pointer to an #aisl_evt structure
|
||||
* @param ctx a pointer to a context defined by user (see #aisl_cfg)
|
||||
*/
|
||||
typedef void
|
||||
(* AislCallback) (const struct aisl_evt *evt, void *ctx);
|
||||
|
||||
|
||||
/** @brief AISL event structue passed on stream opening */
|
||||
struct aisl_evt_open {
|
||||
struct aisl_evt evt; /**< generic #aisl_evt structure */
|
||||
const char *path; /**< HTTP request path */
|
||||
const char *query; /**< HTTP request query (GET params) */
|
||||
AislHttpMethod http_method; /**< HTTP request method */
|
||||
};
|
||||
|
||||
|
||||
/** @brief AISL event structue passed on HTTP header reception */
|
||||
struct aisl_evt_header {
|
||||
struct aisl_evt evt; /**< generic #aisl_evt structure */
|
||||
const char *key; /**< low case HTTP header name */
|
||||
const char *value; /**< HTTP header string */
|
||||
};
|
||||
|
||||
|
||||
/** @brief AISL event structue passed on HTTP request data part received */
|
||||
struct aisl_evt_input {
|
||||
struct aisl_evt evt; /**< generic #aisl_evt structure */
|
||||
const char *data; /**< a pointer to received data array */
|
||||
int32_t size; /**< data array size */
|
||||
};
|
||||
|
||||
|
||||
/** @brief Converts #AislEvent code to a null terminated string
|
||||
* @param evt an #AislEvent code
|
||||
* @return pointer to the string representing #AislEvent
|
||||
*/
|
||||
const char *
|
||||
aisl_event_to_string(AislEvent evt);
|
||||
|
||||
#endif /* !AISL_TYPES_H */
|
||||
Reference in New Issue
Block a user