aisl/include/aisl/types.h

244 lines
5.0 KiB
C

/*
* <aisl/types.h>
*
* Copyright (c) 2017-2019 by Löwenware Ltd.
*
* Project homepage: 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>
/* type casts */
#define AISL_CALLBACK(x) ((aisl_callback_t) x)
/* 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;
/* HTTP(s) Client */
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
{
AISL_EXTCALL_ERROR = -3
, AISL_SYSCALL_ERROR = -2
, AISL_MALLOC_ERROR = -1
, AISL_SUCCESS = 0
, AISL_IDLE = 1
} aisl_status_t;
#ifdef WITH_STRINGIFIERS
const char *
aisl_status_to_string(aisl_status_t status);
#endif
/* Generic HTTP Enumerations */
typedef enum
{
AISL_HTTP_1_0
, AISL_HTTP_1_1
, AISL_HTTP_2_0
} aisl_http_version_t;
#ifdef WITH_STRINGIFIERS
const char *
aisl_http_version_to_string( aisl_http_version_t version );
#endif
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;
#ifdef WITH_STRINGIFIERS
const char *
aisl_http_method_to_string( aisl_http_method_t method );
#endif
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
} aisl_http_response_t;
#ifdef WITH_STRINGIFIERS
const char *
aisl_http_response_to_string( aisl_http_response_t code );
#endif
#ifdef WITH_STRINGIFIERS
const char *
aisl_http_secure_to_string( bool is_secure );
#endif
/* Built-in Events IDs */
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
, 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
, AISL_EVENTS_CUSTOM = 1000
};
#ifdef WITH_STRINGIFIERS
const char *
aisl_event_to_string( aisl_event_t event );
#endif
/* real type event callbacks */
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, char * data, size_t len );
typedef bool
(*aisl_on_stream_request_t)( aisl_stream_t stream );
typedef bool
(*aisl_on_stream_output_t)( aisl_stream_t stream, size_t buffer_space );
typedef bool
(*aisl_on_stream_close_t)( aisl_stream_t stream );
typedef bool
(*aisl_on_stream_error_t)( aisl_stream_t stream );
typedef bool
(*aisl_on_custom_event_t)( void * source, va_list vl );
#endif /* !AISL_TYPES_H */