diff --git a/ChangeLog.txt b/ChangeLog.txt index 5f299bf2da..10e312fc00 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,9 @@ 1.4.6 - ================ +Broker: +- Add support for libwebsockets 1.6. + Client library: - Fix _mosquitto_socketpair() on Windows, reducing the chance of delays when publishing. Closes #483979. @@ -9,6 +12,7 @@ Clients: - Fix "mosquitto_pub -l" stripping the final character on a line. Closes #483981. + 1.4.5 - 20151108 ================ diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index 75d5b2ee6b..da369168ca 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -207,8 +207,12 @@ struct mosquitto { int sub_count; int pollfd_index; # ifdef WITH_WEBSOCKETS +# if defined(LWS_LIBRARY_VERSION_NUMBER) + struct lws *wsi; +# else struct libwebsocket_context *ws_context; struct libwebsocket *wsi; +# endif # endif #else # ifdef WITH_SOCKS diff --git a/lib/net_mosq.c b/lib/net_mosq.c index 4c258a472e..a2db4b10b0 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -68,6 +68,7 @@ and the Eclipse Distribution License is available at extern unsigned long g_pub_msgs_sent; # endif # ifdef WITH_WEBSOCKETS +# include # include # endif #else diff --git a/src/loop.c b/src/loop.c index a5f624b39a..b3af85e151 100644 --- a/src/loop.c +++ b/src/loop.c @@ -37,6 +37,7 @@ and the Eclipse Distribution License is available at #include #ifdef WITH_WEBSOCKETS +# include # include #endif diff --git a/src/mosquitto.c b/src/mosquitto.c index eaf439535e..0bedfd3422 100644 --- a/src/mosquitto.c +++ b/src/mosquitto.c @@ -43,6 +43,7 @@ and the Eclipse Distribution License is available at #include #endif #ifdef WITH_WEBSOCKETS +# include # include #endif diff --git a/src/mosquitto_broker.h b/src/mosquitto_broker.h index 19498a0b54..7e4e654966 100644 --- a/src/mosquitto_broker.h +++ b/src/mosquitto_broker.h @@ -20,6 +20,26 @@ and the Eclipse Distribution License is available at #include #include +#ifdef WITH_WEBSOCKETS +# include +# include + +# if defined(LWS_LIBRARY_VERSION_NUMBER) +# define libwebsocket_callback_on_writable(A, B) lws_callback_on_writable((B)) +# define libwebsocket_service(A, B) lws_service((A), (B)) +# define libwebsocket_create_context(A) lws_create_context((A)) +# define libwebsocket_context_destroy(A) lws_context_destroy((A)) +# define libwebsocket_write(A, B, C, D) lws_write((A), (B), (C), (D)) +# 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 libwebsocket_context lws_context +# define libwebsocket_protocols lws_protocols +# define libwebsocket_callback_reasons lws_callback_reasons +# define libwebsocket lws +# endif +#endif + #include #include #include @@ -482,7 +502,11 @@ void service_run(void); * Websockets related functions * ============================================================ */ #ifdef WITH_WEBSOCKETS +# if defined(LWS_LIBRARY_VERSION_NUMBER) +struct lws_context *mosq_websockets_init(struct _mqtt3_listener *listener, int log_level); +# else struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listener, int log_level); +# endif #endif void do_disconnect(struct mosquitto_db *db, struct mosquitto *context); diff --git a/src/read_handle_server.c b/src/read_handle_server.c index 973d9aaaa7..8b0df1be4b 100644 --- a/src/read_handle_server.c +++ b/src/read_handle_server.c @@ -32,7 +32,8 @@ and the Eclipse Distribution License is available at #endif #ifdef WITH_WEBSOCKETS -#include +# include +# include #endif #ifdef WITH_SYS_TREE diff --git a/src/websockets.c b/src/websockets.c index a1f61e89a2..2c6f2c81f4 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -29,6 +29,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef WITH_WEBSOCKETS +#include #include #include "mosquitto_internal.h" #include "mosquitto_broker.h" @@ -49,13 +50,22 @@ extern unsigned long g_pub_msgs_sent; #endif extern struct mosquitto_db int_db; +#if defined(LWS_LIBRARY_VERSION_NUMBER) +static int callback_mqtt( +#else static int callback_mqtt(struct libwebsocket_context *context, +#endif struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, void *user, void *in, size_t len); + +#if defined(LWS_LIBRARY_VERSION_NUMBER) +static int callback_http( +#else static int callback_http(struct libwebsocket_context *context, +#endif struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, void *user, @@ -95,7 +105,9 @@ static struct libwebsocket_protocols protocols[] = { 0, #endif NULL, +#if !defined(LWS_LIBRARY_VERSION_NUMBER) 0 +#endif }, { "mqtt", @@ -106,7 +118,9 @@ static struct libwebsocket_protocols protocols[] = { 1, #endif NULL, +#if !defined(LWS_LIBRARY_VERSION_NUMBER) 0 +#endif }, { "mqttv3.1", @@ -117,10 +131,16 @@ static struct libwebsocket_protocols protocols[] = { 1, #endif NULL, +#if !defined(LWS_LIBRARY_VERSION_NUMBER) 0 +#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} #endif @@ -135,7 +155,11 @@ static void easy_address(int sock, struct mosquitto *mosq) } } +#if defined(LWS_LIBRARY_VERSION_NUMBER) +static int callback_mqtt( +#else static int callback_mqtt(struct libwebsocket_context *context, +#endif struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, void *user, @@ -158,7 +182,9 @@ static int callback_mqtt(struct libwebsocket_context *context, case LWS_CALLBACK_ESTABLISHED: mosq = mqtt3_context_init(db, WEBSOCKET_CLIENT); if(mosq){ +#if !defined(LWS_LIBRARY_VERSION_NUMBER) mosq->ws_context = context; +#endif mosq->wsi = wsi; u->mosq = mosq; }else{ @@ -342,7 +368,11 @@ static int callback_mqtt(struct libwebsocket_context *context, } +#if defined(LWS_LIBRARY_VERSION_NUMBER) +static int callback_http( +#else static int callback_http(struct libwebsocket_context *context, +#endif struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, void *user, @@ -368,7 +398,11 @@ static int callback_http(struct libwebsocket_context *context, return -1; } +#if defined(LWS_LIBRARY_VERSION_NUMBER) + hack = (struct libws_mqtt_hack *)lws_context_user(lws_get_context(wsi)); +#else hack = (struct libws_mqtt_hack *)libwebsocket_context_user(context); +#endif if(!hack){ return -1; }