From 1aaf5f2348d437a1f18a8a7349fb0027ae6ab242 Mon Sep 17 00:00:00 2001 From: Pierre Fersing Date: Tue, 3 Oct 2017 18:25:35 +0200 Subject: [PATCH] Add websockets_headers_size option Signed-off-by: Pierre Fersing --- man/mosquitto.conf.5.xml | 12 ++++++++++++ mosquitto.conf | 8 ++++++++ src/conf.c | 10 ++++++++++ src/mosquitto.c | 2 +- src/mosquitto_broker_internal.h | 5 +++-- src/websockets.c | 7 +++++-- 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/man/mosquitto.conf.5.xml b/man/mosquitto.conf.5.xml index def5406c..3ca2aa57 100644 --- a/man/mosquitto.conf.5.xml +++ b/man/mosquitto.conf.5.xml @@ -982,6 +982,18 @@ Defaults to 0. + + size + + Change the websockets headers size. This is a + global option, it is not possible to set per + listener. This is the value passed to libwebsockets + max_http_header_data which is used for the buffer size + to process HTTP headers. See the libwebsockets documention + for more details. A value of 0 (the default) means to + use libwebsockets' default (which is 1024). + + diff --git a/mosquitto.conf b/mosquitto.conf index ed71c7f4..dd26faea 100644 --- a/mosquitto.conf +++ b/mosquitto.conf @@ -595,6 +595,14 @@ # libwebsockets documentation for more details. "log_type websockets" must also # be enabled. #websockets_log_level 0 +# +# Change the websockets headers size. This is a global option, it is not +# possible to set per listener. This is the value passed to libwebsockets +# max_http_header_data which is used for the buffer size to process HTTP +# headers. See the libwebsockets documentation for more details. +# A value of 0 (the default) means to use libwebsockets' default (which is +# 1024). +#websockets_headers_size 0 # If set to true, client connection and disconnection messages will be included # in the log. diff --git a/src/conf.c b/src/conf.c index 941becb3..9c54bce5 100644 --- a/src/conf.c +++ b/src/conf.c @@ -2096,6 +2096,16 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct }else if(!strcmp(token, "websockets_log_level")){ #ifdef WITH_WEBSOCKETS if(conf__parse_int(&token, "websockets_log_level", &config->websockets_log_level, saveptr)) return MOSQ_ERR_INVAL; +#else + log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Websockets support not available."); +#endif + }else if(!strcmp(token, "websockets_headers_size")){ +#ifdef WITH_WEBSOCKETS +#if defined(LWS_LIBRARY_VERSION_NUMBER) && LWS_LIBRARY_VERSION_NUMBER>=1007000 + if(conf__parse_int(&token, "websockets_headers_size", &config->websockets_headers_size, saveptr)) return MOSQ_ERR_INVAL; +#else + log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Websockets headers size require libwebsocket 1.7+"); +#endif #else log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Websockets support not available."); #endif diff --git a/src/mosquitto.c b/src/mosquitto.c index 85a4d8fe..429f6bef 100644 --- a/src/mosquitto.c +++ b/src/mosquitto.c @@ -330,7 +330,7 @@ int main(int argc, char *argv[]) } }else if(config.listeners[i].protocol == mp_websockets){ #ifdef WITH_WEBSOCKETS - config.listeners[i].ws_context = mosq_websockets_init(&config.listeners[i], config.websockets_log_level); + config.listeners[i].ws_context = mosq_websockets_init(&config.listeners[i], &config); if(!config.listeners[i].ws_context){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to create websockets listener on port %d.", config.listeners[i].port); return 1; diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index dfbe0fa5..5351fd12 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -286,6 +286,7 @@ struct mosquitto__config { char *user; #ifdef WITH_WEBSOCKETS int websockets_log_level; + int websockets_headers_size; bool have_websockets_listener; #endif #ifdef WITH_BRIDGE @@ -672,9 +673,9 @@ DWORD WINAPI SigThreadProc(void* data); * ============================================================ */ #ifdef WITH_WEBSOCKETS # if defined(LWS_LIBRARY_VERSION_NUMBER) -struct lws_context *mosq_websockets_init(struct mosquitto__listener *listener, int log_level); +struct lws_context *mosq_websockets_init(struct mosquitto__listener *listener, const struct mosquitto__config *conf); # else -struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *listener, int log_level); +struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *listener, const struct mosquitto__config *conf); # endif #endif void do_disconnect(struct mosquitto_db *db, struct mosquitto *context); diff --git a/src/websockets.c b/src/websockets.c index 8362a237..628f63a7 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -690,7 +690,7 @@ static void log_wrap(int level, const char *line) log__printf(NULL, MOSQ_LOG_WEBSOCKETS, "%s", l); } -struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *listener, int log_level) +struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *listener, const struct mosquitto__config *conf) { struct lws_context_creation_info info; struct libwebsocket_protocols *p; @@ -735,6 +735,9 @@ struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *li if(listener->socket_domain == AF_INET){ info.options |= LWS_SERVER_OPTION_DISABLE_IPV6; } +#if defined(LWS_LIBRARY_VERSION_NUMBER) && LWS_LIBRARY_VERSION_NUMBER>=1007000 + info.max_http_header_data = conf->websockets_headers_size; +#endif user = mosquitto__calloc(1, sizeof(struct libws_mqtt_hack)); if(!user){ @@ -760,7 +763,7 @@ struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *li info.user = user; listener->ws_protocol = p; - lws_set_log_level(log_level, log_wrap); + lws_set_log_level(conf->websockets_log_level, log_wrap); log__printf(NULL, MOSQ_LOG_INFO, "Opening websockets listen socket on port %d.", listener->port); return libwebsocket_create_context(&info);