Add websockets_headers_size option

Signed-off-by: Pierre Fersing <pierre.fersing@bleemeo.com>
This commit is contained in:
Pierre Fersing 2017-10-03 18:25:35 +02:00 committed by Roger A. Light
parent 479d8e5f1a
commit 1aaf5f2348
6 changed files with 39 additions and 5 deletions

View File

@ -982,6 +982,18 @@
Defaults to 0.</para> Defaults to 0.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>websockets_headers_size</option> <replaceable>size</replaceable></term>
<listitem>
<para>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).</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect2> </refsect2>
<refsect2> <refsect2>

View File

@ -595,6 +595,14 @@
# libwebsockets documentation for more details. "log_type websockets" must also # libwebsockets documentation for more details. "log_type websockets" must also
# be enabled. # be enabled.
#websockets_log_level 0 #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 # If set to true, client connection and disconnection messages will be included
# in the log. # in the log.

View File

@ -2096,6 +2096,16 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
}else if(!strcmp(token, "websockets_log_level")){ }else if(!strcmp(token, "websockets_log_level")){
#ifdef WITH_WEBSOCKETS #ifdef WITH_WEBSOCKETS
if(conf__parse_int(&token, "websockets_log_level", &config->websockets_log_level, saveptr)) return MOSQ_ERR_INVAL; 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 #else
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Websockets support not available."); log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Websockets support not available.");
#endif #endif

View File

@ -330,7 +330,7 @@ int main(int argc, char *argv[])
} }
}else if(config.listeners[i].protocol == mp_websockets){ }else if(config.listeners[i].protocol == mp_websockets){
#ifdef WITH_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){ 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); log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to create websockets listener on port %d.", config.listeners[i].port);
return 1; return 1;

View File

@ -286,6 +286,7 @@ struct mosquitto__config {
char *user; char *user;
#ifdef WITH_WEBSOCKETS #ifdef WITH_WEBSOCKETS
int websockets_log_level; int websockets_log_level;
int websockets_headers_size;
bool have_websockets_listener; bool have_websockets_listener;
#endif #endif
#ifdef WITH_BRIDGE #ifdef WITH_BRIDGE
@ -672,9 +673,9 @@ DWORD WINAPI SigThreadProc(void* data);
* ============================================================ */ * ============================================================ */
#ifdef WITH_WEBSOCKETS #ifdef WITH_WEBSOCKETS
# if defined(LWS_LIBRARY_VERSION_NUMBER) # 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 # 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
#endif #endif
void do_disconnect(struct mosquitto_db *db, struct mosquitto *context); void do_disconnect(struct mosquitto_db *db, struct mosquitto *context);

View File

@ -690,7 +690,7 @@ static void log_wrap(int level, const char *line)
log__printf(NULL, MOSQ_LOG_WEBSOCKETS, "%s", l); 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 lws_context_creation_info info;
struct libwebsocket_protocols *p; struct libwebsocket_protocols *p;
@ -735,6 +735,9 @@ struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *li
if(listener->socket_domain == AF_INET){ if(listener->socket_domain == AF_INET){
info.options |= LWS_SERVER_OPTION_DISABLE_IPV6; 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)); user = mosquitto__calloc(1, sizeof(struct libws_mqtt_hack));
if(!user){ if(!user){
@ -760,7 +763,7 @@ struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *li
info.user = user; info.user = user;
listener->ws_protocol = p; 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); log__printf(NULL, MOSQ_LOG_INFO, "Opening websockets listen socket on port %d.", listener->port);
return libwebsocket_create_context(&info); return libwebsocket_create_context(&info);