1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-08-07 16:02:55 +03:00

Websockets always compiled in

This commit is contained in:
Lammert Bies
2016-12-26 14:27:34 +01:00
parent bd64c27326
commit 9a14a1bfa1
17 changed files with 7 additions and 87 deletions

View File

@@ -83,7 +83,7 @@ ifneq ($(OS),Windows_NT)
OS:=$(shell uname -s) OS:=$(shell uname -s)
endif endif
DFLAGS = -DUSE_STACK_SIZE=102400 -DUSE_WEBSOCKET DFLAGS = -DUSE_STACK_SIZE=102400
INCDIR = include/ INCDIR = include/
LIBDIR = lib/ LIBDIR = lib/

View File

@@ -5,6 +5,7 @@ Release Notes v2.0 (work in progress)
Changes Changes
------- -------
- Websocket support is always compiled in and switched on/off at runtime
- Added NULL checking to all uses of context configuration settings - Added NULL checking to all uses of context configuration settings
- IPv6 support is now always available - IPv6 support is now always available
- Combined three send file functions into `httplib_send_file()`. - Combined three send file functions into `httplib_send_file()`.

View File

@@ -531,7 +531,6 @@ LIBHTTP_API int httplib_write(struct httplib_connection *, const void *buf, size
a request simultaneously. a request simultaneously.
Send data to a websocket client wrapped in a websocket frame. Send data to a websocket client wrapped in a websocket frame.
This function is available when LibHTTP is compiled with -DUSE_WEBSOCKET
Return: Return:
0 when the connection has been closed 0 when the connection has been closed
@@ -546,7 +545,6 @@ LIBHTTP_API int httplib_websocket_write(struct httplib_connection *conn, int opc
a request simultaneously. a request simultaneously.
Send data to a websocket server wrapped in a masked websocket frame. Send data to a websocket server wrapped in a masked websocket frame.
This function is available when LibHTTP is compiled with -DUSE_WEBSOCKET
Return: Return:
0 when the connection has been closed 0 when the connection has been closed
@@ -572,12 +570,12 @@ LIBHTTP_API void httplib_unlock_context(struct httplib_context *ctx);
/* Opcodes, from http://tools.ietf.org/html/rfc6455 */ /* Opcodes, from http://tools.ietf.org/html/rfc6455 */
enum { enum {
WEBSOCKET_OPCODE_CONTINUATION = 0x0, WEBSOCKET_OPCODE_CONTINUATION = 0x0,
WEBSOCKET_OPCODE_TEXT = 0x1, WEBSOCKET_OPCODE_TEXT = 0x1,
WEBSOCKET_OPCODE_BINARY = 0x2, WEBSOCKET_OPCODE_BINARY = 0x2,
WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8, WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
WEBSOCKET_OPCODE_PING = 0x9, WEBSOCKET_OPCODE_PING = 0x9,
WEBSOCKET_OPCODE_PONG = 0xa WEBSOCKET_OPCODE_PONG = 0xA
}; };
@@ -959,7 +957,6 @@ LIBHTTP_API int httplib_get_response(struct httplib_connection *conn, char *ebuf
1 serve files (NO_FILES not set) 1 serve files (NO_FILES not set)
2 support HTTPS (NO_SSL not set) 2 support HTTPS (NO_SSL not set)
4 support CGI (NO_CGI not set) 4 support CGI (NO_CGI not set)
16 support WebSocket (USE_WEBSOCKET set)
128 support caching (NO_CACHING not set) 128 support caching (NO_CACHING not set)
The result is undefined for all other feature values. The result is undefined for all other feature values.

View File

@@ -47,9 +47,6 @@ unsigned httplib_check_feature( unsigned feature ) {
#if !defined(NO_CGI) #if !defined(NO_CGI)
| 0x0004u | 0x0004u
#endif #endif
#if defined(USE_WEBSOCKET)
| 0x0010u
#endif
#if !defined(NO_CACHING) #if !defined(NO_CACHING)
| 0x0080u | 0x0080u
#endif #endif

View File

@@ -64,13 +64,9 @@ struct httplib_option XX_httplib_config_options[] = {
{ "ssl_cipher_list", CONFIG_TYPE_STRING, NULL }, { "ssl_cipher_list", CONFIG_TYPE_STRING, NULL },
{ "ssl_protocol_version", CONFIG_TYPE_NUMBER, "0" }, { "ssl_protocol_version", CONFIG_TYPE_NUMBER, "0" },
{ "ssl_short_trust", CONFIG_TYPE_BOOLEAN, "no" }, { "ssl_short_trust", CONFIG_TYPE_BOOLEAN, "no" },
#if defined(USE_WEBSOCKET)
{ "websocket_timeout_ms", CONFIG_TYPE_NUMBER, "30000" }, { "websocket_timeout_ms", CONFIG_TYPE_NUMBER, "30000" },
#endif
{ "decode_url", CONFIG_TYPE_BOOLEAN, "yes" }, { "decode_url", CONFIG_TYPE_BOOLEAN, "yes" },
#if defined(USE_WEBSOCKET)
{ "websocket_root", CONFIG_TYPE_DIRECTORY, NULL }, { "websocket_root", CONFIG_TYPE_DIRECTORY, NULL },
#endif
{ "access_control_allow_origin", CONFIG_TYPE_STRING, "*" }, { "access_control_allow_origin", CONFIG_TYPE_STRING, "*" },
{ "error_pages", CONFIG_TYPE_DIRECTORY, NULL }, { "error_pages", CONFIG_TYPE_DIRECTORY, NULL },
{ "tcp_nodelay", CONFIG_TYPE_NUMBER, "0" }, { "tcp_nodelay", CONFIG_TYPE_NUMBER, "0" },

View File

@@ -38,7 +38,6 @@
struct httplib_connection *httplib_connect_websocket_client( const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, httplib_websocket_data_handler data_func, httplib_websocket_close_handler close_func, void *user_data ) { struct httplib_connection *httplib_connect_websocket_client( const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, httplib_websocket_data_handler data_func, httplib_websocket_close_handler close_func, void *user_data ) {
#if defined(USE_WEBSOCKET)
struct httplib_connection *conn; struct httplib_connection *conn;
struct httplib_context *newctx; struct httplib_context *newctx;
struct websocket_client_thread_data *thread_data; struct websocket_client_thread_data *thread_data;
@@ -153,19 +152,5 @@ struct httplib_connection *httplib_connect_websocket_client( const char *host, i
} }
return conn; return conn;
#else
UNUSED_PARAMETER(host);
UNUSED_PARAMETER(port);
UNUSED_PARAMETER(use_ssl);
UNUSED_PARAMETER(error_buffer);
UNUSED_PARAMETER(error_buffer_size);
UNUSED_PARAMETER(path);
UNUSED_PARAMETER(origin);
UNUSED_PARAMETER(user_data);
UNUSED_PARAMETER(data_func);
UNUSED_PARAMETER(close_func);
return NULL;
#endif
} /* httplib_connect_websocket_client */ } /* httplib_connect_websocket_client */

View File

@@ -361,7 +361,6 @@ no_callback_resource:
} }
else { else {
#if defined(USE_WEBSOCKET)
XX_httplib_handle_websocket_request( conn, XX_httplib_handle_websocket_request( conn,
path, path,
is_callback_resource, is_callback_resource,
@@ -370,7 +369,6 @@ no_callback_resource:
ws_data_handler, ws_data_handler,
ws_close_handler, ws_close_handler,
callback_data ); callback_data );
#endif
} }
return; return;
@@ -380,8 +378,6 @@ no_callback_resource:
* 8. handle websocket requests * 8. handle websocket requests
*/ */
#if defined(USE_WEBSOCKET)
if ( is_websocket_request ) { if ( is_websocket_request ) {
if ( is_script_resource ) { if ( is_script_resource ) {
@@ -399,7 +395,6 @@ no_callback_resource:
} }
else else
#endif
#if defined(NO_FILES) #if defined(NO_FILES)

View File

@@ -34,8 +34,6 @@
* request on a connection. * request on a connection.
*/ */
#if defined(USE_WEBSOCKET)
void XX_httplib_handle_websocket_request( struct httplib_connection *conn, const char *path, int is_callback_resource, httplib_websocket_connect_handler ws_connect_handler, httplib_websocket_ready_handler ws_ready_handler, httplib_websocket_data_handler ws_data_handler, httplib_websocket_close_handler ws_close_handler, void *cbData ) { void XX_httplib_handle_websocket_request( struct httplib_connection *conn, const char *path, int is_callback_resource, httplib_websocket_connect_handler ws_connect_handler, httplib_websocket_ready_handler ws_ready_handler, httplib_websocket_data_handler ws_data_handler, httplib_websocket_close_handler ws_close_handler, void *cbData ) {
const char *websock_key; const char *websock_key;
@@ -187,5 +185,3 @@ void XX_httplib_handle_websocket_request( struct httplib_connection *conn, const
if ( ws_close_handler ) ws_close_handler( conn, cbData ); if ( ws_close_handler ) ws_close_handler( conn, cbData );
} /* XX_httplib_handle_websocket_request */ } /* XX_httplib_handle_websocket_request */
#endif /* USE_WEBSOCKET */

View File

@@ -78,16 +78,10 @@ void XX_httplib_interpret_uri( struct httplib_connection *conn, char *filename,
*is_script_resource = false; *is_script_resource = false;
*is_put_or_delete_request = XX_httplib_is_put_or_delete_method( conn ); *is_put_or_delete_request = XX_httplib_is_put_or_delete_method( conn );
#if defined(USE_WEBSOCKET)
*is_websocket_request = XX_httplib_is_websocket_protocol( conn ); *is_websocket_request = XX_httplib_is_websocket_protocol( conn );
#if !defined(NO_FILES) #if !defined(NO_FILES)
if ( *is_websocket_request && conn->ctx->cfg[WEBSOCKET_ROOT] != NULL ) root = conn->ctx->cfg[WEBSOCKET_ROOT]; if ( *is_websocket_request && conn->ctx->cfg[WEBSOCKET_ROOT] != NULL ) root = conn->ctx->cfg[WEBSOCKET_ROOT];
#endif /* !NO_FILES */
#else /* USE_WEBSOCKET */
*is_websocket_request = false;
#endif /* USE_WEBSOCKET */
#if !defined(NO_FILES)
/* /*
* Note that root == NULL is a regular use case here. This occurs, * Note that root == NULL is a regular use case here. This occurs,
* if all requests are handled by callbacks, so the WEBSOCKET_ROOT * if all requests are handled by callbacks, so the WEBSOCKET_ROOT

View File

@@ -37,7 +37,6 @@
bool XX_httplib_is_websocket_protocol( const struct httplib_connection *conn ) { bool XX_httplib_is_websocket_protocol( const struct httplib_connection *conn ) {
#if defined(USE_WEBSOCKET)
const char *upgrade; const char *upgrade;
const char *connection; const char *connection;
@@ -68,12 +67,4 @@ bool XX_httplib_is_websocket_protocol( const struct httplib_connection *conn ) {
return true; return true;
#else /* defined(USE_WEBSOCKET) */
UNUSED_PARAMETER(conn);
return false;
#endif /* defined(USE_WEBSOCKET) */
} /* XX_httplib_is_websocket_protocol */ } /* XX_httplib_is_websocket_protocol */

View File

@@ -431,17 +431,9 @@ enum {
SSL_CIPHER_LIST, SSL_CIPHER_LIST,
SSL_PROTOCOL_VERSION, SSL_PROTOCOL_VERSION,
SSL_SHORT_TRUST, SSL_SHORT_TRUST,
#if defined(USE_WEBSOCKET)
WEBSOCKET_TIMEOUT, WEBSOCKET_TIMEOUT,
#endif
DECODE_URL, DECODE_URL,
#if defined(USE_WEBSOCKET)
WEBSOCKET_ROOT, WEBSOCKET_ROOT,
#endif
ACCESS_CONTROL_ALLOW_ORIGIN, ACCESS_CONTROL_ALLOW_ORIGIN,
ERROR_PAGES, ERROR_PAGES,
CONFIG_TCP_NODELAY, /* Prepended CONFIG_ to avoid conflict with the CONFIG_TCP_NODELAY, /* Prepended CONFIG_ to avoid conflict with the

View File

@@ -33,8 +33,6 @@
* The function XX_httplib_read_websocket() reads from a websocket connection. * The function XX_httplib_read_websocket() reads from a websocket connection.
*/ */
#if defined(USE_WEBSOCKET)
void XX_httplib_read_websocket( struct httplib_connection *conn, httplib_websocket_data_handler ws_data_handler, void *callback_data ) { void XX_httplib_read_websocket( struct httplib_connection *conn, httplib_websocket_data_handler ws_data_handler, void *callback_data ) {
/* Pointer to the beginning of the portion of the incoming websocket /* Pointer to the beginning of the portion of the incoming websocket
@@ -277,5 +275,3 @@ void XX_httplib_read_websocket( struct httplib_connection *conn, httplib_websock
XX_httplib_set_thread_name( "worker" ); XX_httplib_set_thread_name( "worker" );
} /* XX_httplib_read_websocket */ } /* XX_httplib_read_websocket */
#endif /* !USE_WEBSOCKET */

View File

@@ -38,8 +38,6 @@
* a websocket connection. * a websocket connection.
*/ */
#if defined(USE_WEBSOCKET)
int XX_httplib_send_websocket_handshake( struct httplib_connection *conn, const char *websock_key ) { int XX_httplib_send_websocket_handshake( struct httplib_connection *conn, const char *websock_key ) {
static const char *magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; static const char *magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
@@ -117,5 +115,3 @@ int XX_httplib_send_websocket_handshake( struct httplib_connection *conn, const
return 1; return 1;
} /* XX_httplib_send_websocket_handshake */ } /* XX_httplib_send_websocket_handshake */
#endif /* !USE_WEBSOCKET */

View File

@@ -34,8 +34,6 @@
* connects as a client to a remote websocket server. * connects as a client to a remote websocket server.
*/ */
#if defined(USE_WEBSOCKET)
LIBHTTP_THREAD XX_httplib_websocket_client_thread( void *data ) { LIBHTTP_THREAD XX_httplib_websocket_client_thread( void *data ) {
struct websocket_client_thread_data *cdata; struct websocket_client_thread_data *cdata;
@@ -63,5 +61,3 @@ LIBHTTP_THREAD XX_httplib_websocket_client_thread( void *data ) {
return LIBHTTP_THREAD_RETNULL; return LIBHTTP_THREAD_RETNULL;
} /* XX_httplib_websocket_client_thread */ } /* XX_httplib_websocket_client_thread */
#endif /* USE_WEBSOCKET */

View File

@@ -28,8 +28,6 @@
#include "httplib_main.h" #include "httplib_main.h"
#include "httplib_utils.h" #include "httplib_utils.h"
#if defined(USE_WEBSOCKET)
static void mask_data( const char *in, size_t in_len, uint32_t masking_key, char *out ); static void mask_data( const char *in, size_t in_len, uint32_t masking_key, char *out );
/* /*
@@ -104,5 +102,3 @@ static void mask_data( const char *in, size_t in_len, uint32_t masking_key, char
} }
} /* mask_data */ } /* mask_data */
#endif /* !USE_WEBSOCKET */

View File

@@ -34,12 +34,8 @@
* connection. * connection.
*/ */
#if defined(USE_WEBSOCKET)
int httplib_websocket_write( struct httplib_connection *conn, int opcode, const char *data, size_t dataLen ) { int httplib_websocket_write( struct httplib_connection *conn, int opcode, const char *data, size_t dataLen ) {
return XX_httplib_websocket_write_exec( conn, opcode, data, dataLen, 0 ); return XX_httplib_websocket_write_exec( conn, opcode, data, dataLen, 0 );
} /* httplib_websocket_write */ } /* httplib_websocket_write */
#endif /* USE_WEBSOCKET */

View File

@@ -34,8 +34,6 @@
* writing data over a websocket connectin to a remote peer. * writing data over a websocket connectin to a remote peer.
*/ */
#if defined(USE_WEBSOCKET)
int XX_httplib_websocket_write_exec( struct httplib_connection *conn, int opcode, const char *data, size_t data_len, uint32_t masking_key ) { int XX_httplib_websocket_write_exec( struct httplib_connection *conn, int opcode, const char *data, size_t data_len, uint32_t masking_key ) {
unsigned char header[14]; unsigned char header[14];
@@ -118,5 +116,3 @@ int XX_httplib_websocket_write_exec( struct httplib_connection *conn, int opcode
return retval; return retval;
} /* XX_httplib_websocket_write_exec */ } /* XX_httplib_websocket_write_exec */
#endif /* !USE_WEBSOCKET */