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:
2
Makefile
2
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/
|
||||
|
@@ -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()`.
|
||||
|
@@ -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
|
||||
@@ -577,7 +575,7 @@ enum {
|
||||
WEBSOCKET_OPCODE_BINARY = 0x2,
|
||||
WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
|
||||
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)
|
||||
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.
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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" },
|
||||
|
@@ -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 */
|
||||
|
@@ -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)
|
||||
|
||||
|
@@ -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 */
|
||||
|
@@ -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
|
||||
|
@@ -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 */
|
||||
|
@@ -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
|
||||
|
@@ -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 */
|
||||
|
@@ -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 */
|
||||
|
@@ -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 */
|
||||
|
@@ -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 */
|
||||
|
@@ -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 */
|
||||
|
@@ -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 */
|
||||
|
Reference in New Issue
Block a user