Skip to content

Commit

Permalink
Add support for libwebsockets 1.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Dec 19, 2015
1 parent c5a3764 commit 7aa653c
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -9,6 +12,7 @@ Clients:
- Fix "mosquitto_pub -l" stripping the final character on a line. Closes
#483981.


1.4.5 - 20151108
================

Expand Down
4 changes: 4 additions & 0 deletions lib/mosquitto_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/net_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ and the Eclipse Distribution License is available at
extern unsigned long g_pub_msgs_sent;
# endif
# ifdef WITH_WEBSOCKETS
# include <lws_config.h>
# include <libwebsockets.h>
# endif
#else
Expand Down
1 change: 1 addition & 0 deletions src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ and the Eclipse Distribution License is available at
#include <time.h>

#ifdef WITH_WEBSOCKETS
# include <lws_config.h>
# include <libwebsockets.h>
#endif

Expand Down
1 change: 1 addition & 0 deletions src/mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ and the Eclipse Distribution License is available at
#include <tcpd.h>
#endif
#ifdef WITH_WEBSOCKETS
# include <lws_config.h>
# include <libwebsockets.h>
#endif

Expand Down
24 changes: 24 additions & 0 deletions src/mosquitto_broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ and the Eclipse Distribution License is available at
#include <config.h>
#include <stdio.h>

#ifdef WITH_WEBSOCKETS
# include <lws_config.h>
# include <libwebsockets.h>

# 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 <mosquitto_internal.h>
#include <mosquitto_plugin.h>
#include <mosquitto.h>
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/read_handle_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ and the Eclipse Distribution License is available at
#endif

#ifdef WITH_WEBSOCKETS
#include <libwebsockets.h>
# include <lws_config.h>
# include <libwebsockets.h>
#endif

#ifdef WITH_SYS_TREE
Expand Down
34 changes: 34 additions & 0 deletions src/websockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ POSSIBILITY OF SUCH DAMAGE.

#ifdef WITH_WEBSOCKETS

#include <lws_config.h>
#include <libwebsockets.h>
#include "mosquitto_internal.h"
#include "mosquitto_broker.h"
Expand All @@ -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,
Expand Down Expand Up @@ -95,7 +105,9 @@ static struct libwebsocket_protocols protocols[] = {
0,
#endif
NULL,
#if !defined(LWS_LIBRARY_VERSION_NUMBER)
0
#endif
},
{
"mqtt",
Expand All @@ -106,7 +118,9 @@ static struct libwebsocket_protocols protocols[] = {
1,
#endif
NULL,
#if !defined(LWS_LIBRARY_VERSION_NUMBER)
0
#endif
},
{
"mqttv3.1",
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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{
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down

0 comments on commit 7aa653c

Please sign in to comment.