Switch to initialization by config and new event model
This commit is contained in:
@@ -45,7 +45,7 @@ aisl_client_is_online(aisl_client_t client);
|
||||
* @param client an #aisl_client_t instance pointer.
|
||||
*/
|
||||
void
|
||||
aisl_client_close(aisl_client_t client);
|
||||
aisl_client_disconnect(aisl_client_t client);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+46
-14
@@ -10,29 +10,61 @@
|
||||
#ifndef AISL_CONFIG_H_DB67A89B_5CAF_4A5F_AEB1_6DB9F84827D6
|
||||
#define AISL_CONFIG_H_DB67A89B_5CAF_4A5F_AEB1_6DB9F84827D6
|
||||
|
||||
#include <stdint.h>
|
||||
#include <aisl/types.h>
|
||||
|
||||
#define AISL_CONFIG_DEFAULT \
|
||||
{ \
|
||||
.server_spool_size = 1 \
|
||||
#define AISL_CFG_DEFAULT \
|
||||
{ \
|
||||
.callback = NULL \
|
||||
, .p_ctx = NULL \
|
||||
, .srv = NULL \
|
||||
, .ssl = NULL \
|
||||
, .srv_cnt = 0 \
|
||||
, .ssl_cnt = 0 \
|
||||
, .client_spool_size = 32 \
|
||||
, .ssl_spool_size = 1 \
|
||||
, .initial_buffer_size = 16536 \
|
||||
, .client_accept_limit = 1024 \
|
||||
, .client_silence_timeout = 30 \
|
||||
} \
|
||||
} \
|
||||
|
||||
|
||||
struct aisl_config
|
||||
struct aisl_cfg_srv
|
||||
{
|
||||
uint32_t server_spool_size;
|
||||
uint32_t client_spool_size;
|
||||
uint32_t ssl_spool_size;
|
||||
uint32_t initial_buffer_size;
|
||||
uint32_t client_accept_limit;
|
||||
uint32_t client_silence_timeout;
|
||||
const char * host;
|
||||
uint16_t port;
|
||||
bool secure;
|
||||
};
|
||||
|
||||
typedef struct aisl_config * aisl_config_t;
|
||||
typedef struct aisl_cfg_srv * aisl_cfg_srv_t;
|
||||
|
||||
|
||||
struct aisl_cfg_ssl
|
||||
{
|
||||
const char * host;
|
||||
const char * key_file;
|
||||
const char * crt_file;
|
||||
};
|
||||
|
||||
typedef struct aisl_cfg_ssl * aisl_cfg_ssl_t;
|
||||
|
||||
|
||||
struct aisl_cfg
|
||||
{
|
||||
/* event handlers */
|
||||
aisl_callback_t callback;
|
||||
void * p_ctx;
|
||||
|
||||
aisl_cfg_srv_t srv;
|
||||
aisl_cfg_ssl_t ssl;
|
||||
|
||||
int srv_cnt;
|
||||
int ssl_cnt;
|
||||
|
||||
int client_spool_size;
|
||||
int initial_buffer_size;
|
||||
int client_accept_limit;
|
||||
int client_silence_timeout;
|
||||
};
|
||||
|
||||
typedef struct aisl_cfg * aisl_cfg_t;
|
||||
|
||||
#endif /* !AISL_CONFIG_H */
|
||||
|
||||
+2
-60
@@ -20,11 +20,11 @@
|
||||
/**
|
||||
* @brief Allocates new AISL instance.
|
||||
*
|
||||
* @param config a pointer to #aisl_config structure.
|
||||
* @param cfg a pointer to #aisl_cfg_t structure.
|
||||
* @return an #aisl_t instance pointer.
|
||||
*/
|
||||
aisl_t
|
||||
aisl_new( aisl_config_t config );
|
||||
aisl_new( aisl_cfg_t cfg );
|
||||
|
||||
|
||||
/**
|
||||
@@ -35,56 +35,6 @@ void
|
||||
aisl_free( aisl_t instance );
|
||||
|
||||
|
||||
/**
|
||||
* @brief Allocates and registers HTTP server instance.
|
||||
* @param instance a pointer to #aisl_t instance.
|
||||
* @param address a null-terminated ip or hostname string.
|
||||
* @param port a number of port to listen.
|
||||
* @return a pointer representing HTTP server.
|
||||
*/
|
||||
aisl_server_t
|
||||
aisl_listen( aisl_t instance, const char * address, uint16_t port );
|
||||
|
||||
|
||||
#ifndef AISL_WITHOUT_SSL
|
||||
|
||||
/**
|
||||
* @brief Sets pair of SSL certificate and key for domain name.
|
||||
* @param instance a pointer to #aisl_t instance.
|
||||
* @param domain a null-terminated string with domain name.
|
||||
* @param key_file a null-terminated string with path to private SSL key file.
|
||||
* @param crt_file a null-terminated string with path to SSL certificate file.
|
||||
* @return #aisl_status_t code.
|
||||
*/
|
||||
aisl_status_t
|
||||
aisl_set_ssl( aisl_t instance,
|
||||
const char * domain,
|
||||
const char * key_file,
|
||||
const char * crt_file );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Registers a callback for event and its source.
|
||||
* If source is NULL, then callback will be executed for all events of specified
|
||||
* type.
|
||||
*
|
||||
* Typical sources are:
|
||||
* - #aisl_server_t,
|
||||
* - #aisl_client_t,
|
||||
* - #aisl_stream_t;
|
||||
*
|
||||
* @param instance a pointer to #aisl_t instance.
|
||||
* @param event a code of event.
|
||||
* @param callback a pointer to function that will be triggered on event.
|
||||
*/
|
||||
void
|
||||
aisl_set_callback( aisl_t instance,
|
||||
aisl_event_t event,
|
||||
aisl_callback_t callback );
|
||||
|
||||
|
||||
/**
|
||||
* @brief A core function doing all the library routines.
|
||||
* Designed to be called inside application main loop
|
||||
@@ -106,12 +56,4 @@ aisl_status_t
|
||||
aisl_sleep( aisl_t instance, uint32_t usec );
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get last error message.
|
||||
* @param instance a pointer to #aisl_t instance.
|
||||
* @return a null-terminated string with error message.
|
||||
*/
|
||||
const char *
|
||||
aisl_get_error( aisl_t instance );
|
||||
|
||||
#endif /* !AISL_INSTANCE_H */
|
||||
|
||||
@@ -31,17 +31,6 @@ void
|
||||
aisl_server_get_address( aisl_server_t server, struct sockaddr_in * address);
|
||||
|
||||
|
||||
#ifndef AISL_WITHOUT_SSL
|
||||
|
||||
/**
|
||||
* @brief Function to switch on and off SSL for the #aisl_server_t.
|
||||
* @param server an #aisl_server_t pointer.
|
||||
* @param value a boolean value representing SSL enabled/disabled state.
|
||||
*/
|
||||
void
|
||||
aisl_server_set_ssl( aisl_server_t server, bool value );
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function to get on and off status of SSL for the #aisl_server_t.
|
||||
* @param server an #aisl_server_t pointer.
|
||||
@@ -50,6 +39,4 @@ aisl_server_set_ssl( aisl_server_t server, bool value );
|
||||
bool
|
||||
aisl_server_get_ssl( aisl_server_t server );
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* !AISL_SERVER_H */
|
||||
|
||||
+50
-60
@@ -27,9 +27,6 @@
|
||||
/* AISL Instance */
|
||||
typedef struct aisl * aisl_t;
|
||||
|
||||
/* Event Identifier */
|
||||
typedef uint32_t aisl_event_t;
|
||||
|
||||
/* HTTP(s) Server */
|
||||
typedef struct aisl_server * aisl_server_t;
|
||||
|
||||
@@ -39,10 +36,6 @@ typedef struct aisl_client * aisl_client_t;
|
||||
/* Server<->Client Stream */
|
||||
typedef struct aisl_stream * aisl_stream_t;
|
||||
|
||||
/* void type event callback */
|
||||
typedef void
|
||||
(* aisl_callback_t) (void);
|
||||
|
||||
|
||||
/* status return codes */
|
||||
typedef enum
|
||||
@@ -64,6 +57,7 @@ aisl_status_to_string(aisl_status_t status);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Generic HTTP Enumerations */
|
||||
|
||||
typedef enum
|
||||
@@ -156,16 +150,15 @@ const char *
|
||||
aisl_http_response_to_string( aisl_http_response_t code );
|
||||
|
||||
|
||||
/* Built-in Events IDs */
|
||||
/* Events */
|
||||
|
||||
enum
|
||||
typedef enum
|
||||
{
|
||||
AISL_EVENT_SERVER_OPEN = 100
|
||||
, AISL_EVENT_SERVER_ERROR = 190
|
||||
|
||||
, AISL_EVENT_CLIENT_CONNECT = 200
|
||||
, AISL_EVENT_CLIENT_DISCONNECT = 210
|
||||
, AISL_EVENT_CLIENT_TIMEOUT = 220
|
||||
|
||||
, AISL_EVENT_STREAM_OPEN = 300
|
||||
, AISL_EVENT_STREAM_HEADER = 310
|
||||
@@ -175,62 +168,59 @@ enum
|
||||
, AISL_EVENT_STREAM_CLOSE = 350
|
||||
, AISL_EVENT_STREAM_ERROR = 390
|
||||
|
||||
} aisl_evt_code_t;
|
||||
|
||||
|
||||
struct aisl_evt
|
||||
{
|
||||
void * source;
|
||||
aisl_evt_code_t code;
|
||||
aisl_status_t status;
|
||||
};
|
||||
|
||||
typedef struct aisl_evt * aisl_evt_t;
|
||||
|
||||
|
||||
/* void type event callback */
|
||||
typedef void
|
||||
(* aisl_callback_t) (aisl_evt_t const evt, void * p_ctx);
|
||||
|
||||
|
||||
struct aisl_evt_stream_open
|
||||
{
|
||||
struct aisl_evt evt;
|
||||
const char * path;
|
||||
const char * query;
|
||||
aisl_http_method_t http_method;
|
||||
};
|
||||
|
||||
typedef struct aisl_evt_stream_open * aisl_evt_stream_open_t;
|
||||
|
||||
|
||||
struct aisl_evt_stream_header
|
||||
{
|
||||
struct aisl_evt evt;
|
||||
const char * key;
|
||||
const char * value;
|
||||
};
|
||||
|
||||
typedef struct aisl_evt_stream_header * aisl_evt_stream_header_t;
|
||||
|
||||
|
||||
struct aisl_evt_stream_input
|
||||
{
|
||||
struct aisl_evt evt;
|
||||
const char * data;
|
||||
int32_t size;
|
||||
};
|
||||
|
||||
typedef struct aisl_evt_stream_input * aisl_evt_stream_input_t;
|
||||
|
||||
#ifndef WITHOUT_STRINGIFIERS
|
||||
|
||||
const char *
|
||||
aisl_event_to_string( aisl_event_t event );
|
||||
aisl_evt_code_to_string( aisl_evt_code_t evt_code );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* real type event callbacks */
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_source_event_t)( void * source );
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_server_open_t)( aisl_server_t server );
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_server_error_t)( aisl_server_t server );
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_client_connect_t)( aisl_client_t client );
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_client_disconnect_t)( aisl_client_t client );
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_client_timeout_t)( aisl_client_t client );
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_stream_open_t)( aisl_stream_t stream,
|
||||
aisl_http_method_t method,
|
||||
const char * path,
|
||||
const char * query );
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_stream_header_t)( aisl_stream_t stream,
|
||||
const char * key,
|
||||
const char * val );
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_stream_input_t)( aisl_stream_t stream,
|
||||
const char * data,
|
||||
int32_t len );
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_stream_request_t)( aisl_stream_t stream );
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_stream_output_t)( aisl_stream_t stream );
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_stream_close_t)( aisl_stream_t stream );
|
||||
|
||||
typedef bool
|
||||
(*aisl_on_stream_error_t)( aisl_stream_t stream );
|
||||
|
||||
#endif /* !AISL_TYPES_H */
|
||||
|
||||
Reference in New Issue
Block a user