diff --git a/Makefile b/Makefile index 9f28d004..9194da56 100644 --- a/Makefile +++ b/Makefile @@ -83,7 +83,7 @@ ifneq ($(OS),Windows_NT) OS:=$(shell uname -s) endif -DFLAGS = -DUSE_STACK_SIZE=102400 -DUSE_WEBSOCKET +DFLAGS = -DUSE_STACK_SIZE=102400 INCDIR = include/ LIBDIR = lib/ diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 821e00fc..77094a9e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -5,6 +5,7 @@ Release Notes v2.0 (work in progress) Changes ------- +- Websocket support is always compiled in and switched on/off at runtime - Added NULL checking to all uses of context configuration settings - IPv6 support is now always available - Combined three send file functions into `httplib_send_file()`. diff --git a/include/libhttp.h b/include/libhttp.h index 960f09a8..27014771 100644 --- a/include/libhttp.h +++ b/include/libhttp.h @@ -531,7 +531,6 @@ LIBHTTP_API int httplib_write(struct httplib_connection *, const void *buf, size a request simultaneously. Send data to a websocket client wrapped in a websocket frame. - This function is available when LibHTTP is compiled with -DUSE_WEBSOCKET Return: 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. Send data to a websocket server wrapped in a masked websocket frame. - This function is available when LibHTTP is compiled with -DUSE_WEBSOCKET Return: 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 */ enum { - WEBSOCKET_OPCODE_CONTINUATION = 0x0, - WEBSOCKET_OPCODE_TEXT = 0x1, - WEBSOCKET_OPCODE_BINARY = 0x2, + WEBSOCKET_OPCODE_CONTINUATION = 0x0, + WEBSOCKET_OPCODE_TEXT = 0x1, + WEBSOCKET_OPCODE_BINARY = 0x2, WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8, - WEBSOCKET_OPCODE_PING = 0x9, - WEBSOCKET_OPCODE_PONG = 0xa + WEBSOCKET_OPCODE_PING = 0x9, + 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) 2 support HTTPS (NO_SSL not set) 4 support CGI (NO_CGI not set) - 16 support WebSocket (USE_WEBSOCKET set) 128 support caching (NO_CACHING not set) The result is undefined for all other feature values. diff --git a/src/httplib_check_feature.c b/src/httplib_check_feature.c index 5c4538e9..af771d5e 100644 --- a/src/httplib_check_feature.c +++ b/src/httplib_check_feature.c @@ -47,9 +47,6 @@ unsigned httplib_check_feature( unsigned feature ) { #if !defined(NO_CGI) | 0x0004u #endif -#if defined(USE_WEBSOCKET) - | 0x0010u -#endif #if !defined(NO_CACHING) | 0x0080u #endif diff --git a/src/httplib_config_options.c b/src/httplib_config_options.c index 6afcbe72..a08dbfc3 100644 --- a/src/httplib_config_options.c +++ b/src/httplib_config_options.c @@ -64,13 +64,9 @@ struct httplib_option XX_httplib_config_options[] = { { "ssl_cipher_list", CONFIG_TYPE_STRING, NULL }, { "ssl_protocol_version", CONFIG_TYPE_NUMBER, "0" }, { "ssl_short_trust", CONFIG_TYPE_BOOLEAN, "no" }, -#if defined(USE_WEBSOCKET) { "websocket_timeout_ms", CONFIG_TYPE_NUMBER, "30000" }, -#endif { "decode_url", CONFIG_TYPE_BOOLEAN, "yes" }, -#if defined(USE_WEBSOCKET) { "websocket_root", CONFIG_TYPE_DIRECTORY, NULL }, -#endif { "access_control_allow_origin", CONFIG_TYPE_STRING, "*" }, { "error_pages", CONFIG_TYPE_DIRECTORY, NULL }, { "tcp_nodelay", CONFIG_TYPE_NUMBER, "0" }, diff --git a/src/httplib_connect_websocket_client.c b/src/httplib_connect_websocket_client.c index 8e1317c3..0fae92d6 100644 --- a/src/httplib_connect_websocket_client.c +++ b/src/httplib_connect_websocket_client.c @@ -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 ) { -#if defined(USE_WEBSOCKET) struct httplib_connection *conn; struct httplib_context *newctx; struct websocket_client_thread_data *thread_data; @@ -153,19 +152,5 @@ struct httplib_connection *httplib_connect_websocket_client( const char *host, i } 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 */ diff --git a/src/httplib_handle_request.c b/src/httplib_handle_request.c index d9fdc46c..ec9601cd 100644 --- a/src/httplib_handle_request.c +++ b/src/httplib_handle_request.c @@ -361,7 +361,6 @@ no_callback_resource: } else { -#if defined(USE_WEBSOCKET) XX_httplib_handle_websocket_request( conn, path, is_callback_resource, @@ -370,7 +369,6 @@ no_callback_resource: ws_data_handler, ws_close_handler, callback_data ); -#endif } return; @@ -380,8 +378,6 @@ no_callback_resource: * 8. handle websocket requests */ -#if defined(USE_WEBSOCKET) - if ( is_websocket_request ) { if ( is_script_resource ) { @@ -399,7 +395,6 @@ no_callback_resource: } else -#endif #if defined(NO_FILES) diff --git a/src/httplib_handle_websocket_request.c b/src/httplib_handle_websocket_request.c index 92436e26..b88e82a3 100644 --- a/src/httplib_handle_websocket_request.c +++ b/src/httplib_handle_websocket_request.c @@ -34,8 +34,6 @@ * 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 ) { 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 ); } /* XX_httplib_handle_websocket_request */ - -#endif /* USE_WEBSOCKET */ diff --git a/src/httplib_interpret_uri.c b/src/httplib_interpret_uri.c index 11647ee2..18a742a6 100644 --- a/src/httplib_interpret_uri.c +++ b/src/httplib_interpret_uri.c @@ -78,16 +78,10 @@ void XX_httplib_interpret_uri( struct httplib_connection *conn, char *filename, *is_script_resource = false; *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 ); #if !defined(NO_FILES) 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, * if all requests are handled by callbacks, so the WEBSOCKET_ROOT diff --git a/src/httplib_is_websocket_protocol.c b/src/httplib_is_websocket_protocol.c index e0f530e3..5427542f 100644 --- a/src/httplib_is_websocket_protocol.c +++ b/src/httplib_is_websocket_protocol.c @@ -37,7 +37,6 @@ bool XX_httplib_is_websocket_protocol( const struct httplib_connection *conn ) { -#if defined(USE_WEBSOCKET) const char *upgrade; const char *connection; @@ -68,12 +67,4 @@ bool XX_httplib_is_websocket_protocol( const struct httplib_connection *conn ) { return true; -#else /* defined(USE_WEBSOCKET) */ - - UNUSED_PARAMETER(conn); - - return false; - -#endif /* defined(USE_WEBSOCKET) */ - } /* XX_httplib_is_websocket_protocol */ diff --git a/src/httplib_main.h b/src/httplib_main.h index d56e0aac..70bfee79 100644 --- a/src/httplib_main.h +++ b/src/httplib_main.h @@ -431,17 +431,9 @@ enum { SSL_CIPHER_LIST, SSL_PROTOCOL_VERSION, SSL_SHORT_TRUST, - -#if defined(USE_WEBSOCKET) WEBSOCKET_TIMEOUT, -#endif - DECODE_URL, - -#if defined(USE_WEBSOCKET) WEBSOCKET_ROOT, -#endif - ACCESS_CONTROL_ALLOW_ORIGIN, ERROR_PAGES, CONFIG_TCP_NODELAY, /* Prepended CONFIG_ to avoid conflict with the diff --git a/src/httplib_read_websocket.c b/src/httplib_read_websocket.c index 8c4f062a..b5f8f6a2 100644 --- a/src/httplib_read_websocket.c +++ b/src/httplib_read_websocket.c @@ -33,8 +33,6 @@ * 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 ) { /* 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_read_websocket */ - -#endif /* !USE_WEBSOCKET */ diff --git a/src/httplib_send_websocket_handshake.c b/src/httplib_send_websocket_handshake.c index 3bc68c84..6c668558 100644 --- a/src/httplib_send_websocket_handshake.c +++ b/src/httplib_send_websocket_handshake.c @@ -38,8 +38,6 @@ * a websocket connection. */ -#if defined(USE_WEBSOCKET) - int XX_httplib_send_websocket_handshake( struct httplib_connection *conn, const char *websock_key ) { 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; } /* XX_httplib_send_websocket_handshake */ - -#endif /* !USE_WEBSOCKET */ diff --git a/src/httplib_websocket_client_thread.c b/src/httplib_websocket_client_thread.c index 580a958d..2fb0ca7a 100644 --- a/src/httplib_websocket_client_thread.c +++ b/src/httplib_websocket_client_thread.c @@ -34,8 +34,6 @@ * connects as a client to a remote websocket server. */ -#if defined(USE_WEBSOCKET) - LIBHTTP_THREAD XX_httplib_websocket_client_thread( void *data ) { struct websocket_client_thread_data *cdata; @@ -63,5 +61,3 @@ LIBHTTP_THREAD XX_httplib_websocket_client_thread( void *data ) { return LIBHTTP_THREAD_RETNULL; } /* XX_httplib_websocket_client_thread */ - -#endif /* USE_WEBSOCKET */ diff --git a/src/httplib_websocket_client_write.c b/src/httplib_websocket_client_write.c index bc63f6ef..d0e60b97 100644 --- a/src/httplib_websocket_client_write.c +++ b/src/httplib_websocket_client_write.c @@ -28,8 +28,6 @@ #include "httplib_main.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 ); /* @@ -104,5 +102,3 @@ static void mask_data( const char *in, size_t in_len, uint32_t masking_key, char } } /* mask_data */ - -#endif /* !USE_WEBSOCKET */ diff --git a/src/httplib_websocket_write.c b/src/httplib_websocket_write.c index f891da91..64eb6c50 100644 --- a/src/httplib_websocket_write.c +++ b/src/httplib_websocket_write.c @@ -34,12 +34,8 @@ * connection. */ -#if defined(USE_WEBSOCKET) - 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 ); } /* httplib_websocket_write */ - -#endif /* USE_WEBSOCKET */ diff --git a/src/httplib_websocket_write_exec.c b/src/httplib_websocket_write_exec.c index 14578e30..ab93b3d3 100644 --- a/src/httplib_websocket_write_exec.c +++ b/src/httplib_websocket_write_exec.c @@ -34,8 +34,6 @@ * 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 ) { unsigned char header[14]; @@ -118,5 +116,3 @@ int XX_httplib_websocket_write_exec( struct httplib_connection *conn, int opcode return retval; } /* XX_httplib_websocket_write_exec */ - -#endif /* !USE_WEBSOCKET */