From ab5af8f0b9818389f7fdd91feded6f81fbbced84 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 14 Aug 2018 17:20:22 +0100 Subject: [PATCH] Fix building for libwebsockets < 1.6. --- ChangeLog.txt | 1 + src/loop.c | 4 ++ src/mosquitto_broker_internal.h | 5 +- src/websockets.c | 89 ++++++++++++++++++++++----------- 4 files changed, 69 insertions(+), 30 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index ab1202b6..52357fa5 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -23,6 +23,7 @@ Broker: - Fix `use_identity_as_username true` not working. Closes #833. - Fix UNSUBACK messages not being logged. Closes #903. - Fix possible endian issue when reading the `memory_limit` option. +- Fix building for libwebsockets < 1.6. Library: - Fix some places where return codes were incorrect, including to the diff --git a/src/loop.c b/src/loop.c index 6f967b60..78c5da65 100644 --- a/src/loop.c +++ b/src/loop.c @@ -681,7 +681,11 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol wspoll.events = pollfds[context->pollfd_index].events; wspoll.revents = pollfds[context->pollfd_index].revents; #endif +#ifdef LWS_LIBRARY_VERSION_NUMBER lws_service_fd(lws_get_context(context->wsi), &wspoll); +#else + lws_service_fd(context->ws_context, &wspoll); +#endif continue; } #endif diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 5117e106..c6bc4bed 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -33,11 +33,14 @@ Contributors: # define libwebsocket_get_socket_fd(A) lws_get_socket_fd((A)) # define libwebsockets_return_http_status(A, B, C, D) lws_return_http_status((B), (C), (D)) # define libwebsockets_get_protocol(A) lws_get_protocol((A)) - # define libwebsocket_context lws_context # define libwebsocket_protocols lws_protocols # define libwebsocket_callback_reasons lws_callback_reasons # define libwebsocket lws +# else +# define lws_pollfd pollfd +# define lws_service_fd(A, B) libwebsocket_service_fd((A), (B)) +# define lws_pollargs libwebsocket_pollargs # endif #endif diff --git a/src/websockets.c b/src/websockets.c index 1e513ae0..1ab02a9b 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -80,53 +80,77 @@ struct libws_http_data { static struct libwebsocket_protocols protocols[] = { /* first protocol must always be HTTP handler */ { - "http-only", - callback_http, - sizeof (struct libws_http_data), - 0, -#ifdef LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD - 0, + "http-only", /* name */ + callback_http, /* lws_callback_function */ + sizeof (struct libws_http_data), /* per_session_data_size */ + 0, /* rx_buffer_size */ +#ifndef LWS_LIBRARY_VERSION_NUMBER + 0, /* no_buffer_all_partial_tx v1.3 only */ #endif - NULL, -#if !defined(LWS_LIBRARY_VERSION_NUMBER) - 0 +#ifdef LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD + 0, /* id */ +#endif +#ifdef LWS_LIBRARY_VERSION_NUMBER + NULL, /* user v1.4 on */ +# if LWS_LIBRARY_VERSION_NUMBER >= 2003000 + 0 /* tx_packet_size v2.3.0 */ +# endif #endif }, { "mqtt", callback_mqtt, sizeof(struct libws_mqtt_data), - 0, -#ifdef LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD - 1, + 0, /* rx_buffer_size */ +#ifndef LWS_LIBRARY_VERSION_NUMBER + 0, /* no_buffer_all_partial_tx v1.3 only */ #endif - NULL, -#if !defined(LWS_LIBRARY_VERSION_NUMBER) - 0 +#ifdef LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD + 1, /* id */ +#endif +#ifdef LWS_LIBRARY_VERSION_NUMBER + NULL, /* user v1.4 on */ +# if LWS_LIBRARY_VERSION_NUMBER >= 2003000 + 0 /* tx_packet_size v2.3.0 */ +# endif #endif }, { "mqttv3.1", callback_mqtt, sizeof(struct libws_mqtt_data), - 0, -#ifdef LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD - 1, + 0, /* rx_buffer_size */ +#ifndef LWS_LIBRARY_VERSION_NUMBER + 0, /* no_buffer_all_partial_tx v1.3 only */ #endif - NULL, -#if !defined(LWS_LIBRARY_VERSION_NUMBER) - 0 +#ifdef LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD + 2, /* id */ +#endif +#ifdef LWS_LIBRARY_VERSION_NUMBER + NULL, /* user v1.4 on */ +# if LWS_LIBRARY_VERSION_NUMBER >= 2003000 + 0 /* tx_packet_size v2.3.0 */ +# endif #endif }, -#ifdef LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD -# if defined(LWS_LIBRARY_VERSION_NUMBER) - { NULL, NULL, 0, 0, 0, NULL} -# else - { NULL, NULL, 0, 0, 0, NULL, 0} -# endif -#else - { NULL, NULL, 0, 0, NULL, 0} + { + NULL, + NULL, + 0, + 0, /* rx_buffer_size */ +#ifndef LWS_LIBRARY_VERSION_NUMBER + 0, /* no_buffer_all_partial_tx v1.3 only */ #endif +#ifdef LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD + 0, /* id */ +#endif +#ifdef LWS_LIBRARY_VERSION_NUMBER + NULL, /* user v1.4 on */ +# if LWS_LIBRARY_VERSION_NUMBER >= 2003000 + 0 /* tx_packet_size v2.3.0 */ +# endif +#endif + } }; static void easy_address(int sock, struct mosquitto *mosq) @@ -409,6 +433,9 @@ static int callback_mqtt(struct libwebsocket_context *context, static char *http__canonical_filename( +#ifndef LWS_LIBRARY_VERSION_NUMBER + struct libwebsocket_context *context, +#endif struct libwebsocket *wsi, const char *in, const char *http_dir) @@ -521,7 +548,11 @@ static int callback_http(struct libwebsocket_context *context, return -1; } +#if defined(LWS_LIBRARY_VERSION_NUMBER) filename_canonical = http__canonical_filename(wsi, (char *)in, http_dir); +#else + filename_canonical = http__canonical_filename(context, wsi, (char *)in, http_dir); +#endif if(!filename_canonical) return -1; u->fptr = fopen(filename_canonical, "rb");