Skip to content

Commit

Permalink
Add websockets_headers_size option
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fersing <[email protected]>
  • Loading branch information
PierreF authored and ralight committed Feb 28, 2019
1 parent 479d8e5 commit 1aaf5f2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
12 changes: 12 additions & 0 deletions man/mosquitto.conf.5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,18 @@
Defaults to 0.</para>
</listitem>
</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>
</refsect2>
<refsect2>
Expand Down
8 changes: 8 additions & 0 deletions mosquitto.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/mosquitto_broker_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/websockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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){
Expand All @@ -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);
Expand Down

0 comments on commit 1aaf5f2

Please sign in to comment.