Skip to content

Commit

Permalink
Fix libwebsockets build
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Nov 20, 2024
1 parent 78afc47 commit 4ab8291
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/mosquitto_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct mosquitto__client_msg;
#endif

#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS
# include <libwebsockets.h>
# define WS_PACKET_OFFSET LWS_PRE
#else
# define WS_PACKET_OFFSET 16
Expand Down
4 changes: 2 additions & 2 deletions lib/net_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ int net__socket_close(struct mosquitto *mosq)

assert(mosq);
#ifdef WITH_TLS
#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS
#if defined(WITH_BROKER) && defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS
if(!mosq->wsi)
#endif
{
Expand All @@ -217,7 +217,7 @@ int net__socket_close(struct mosquitto *mosq)
}
#endif

#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS
#if defined(WITH_BROKER) && defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS
if(mosq->wsi)
{
if(mosq->state != mosq_cs_disconnecting){
Expand Down
8 changes: 8 additions & 0 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,10 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload,
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: $CONTROL support not available (enable_control_api).");
#endif
}else if(!strcmp(token, "enable_proxy_protocol")){
#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS
log__printf(NULL, MOSQ_LOG_ERR, "Error: PROXY support not available with libwebsockets.");
return MOSQ_ERR_INVAL;
#endif
REQUIRE_LISTENER(token);
if(conf__parse_int(&token, "enable_proxy_protocol", &cur_listener->enable_proxy_protocol, &saveptr)) return MOSQ_ERR_INVAL;
if(cur_listener->enable_proxy_protocol < 1 || cur_listener->enable_proxy_protocol > 2){
Expand Down Expand Up @@ -2148,6 +2152,10 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload,
return MOSQ_ERR_INVAL;
}
}else if(!strcmp(token, "proxy_protocol_v2_require_tls")){
#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS
log__printf(NULL, MOSQ_LOG_ERR, "Error: PROXY support not available with libwebsockets.");
return MOSQ_ERR_INVAL;
#endif
REQUIRE_LISTENER(token);
if(conf__parse_bool(&token, "proxy_protocol_v2_require_tls", &cur_listener->proxy_protocol_v2_require_tls, &saveptr)) return MOSQ_ERR_INVAL;
}else if(!strcmp(token, "psk_file")){
Expand Down
6 changes: 6 additions & 0 deletions src/mux_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,15 @@ static void loop_handle_reads_writes(struct mosquitto *context, uint32_t events)
rc = http__write(context);
break;
#endif
#if !defined(WITH_WEBSOCKETS) || WITH_WEBSOCKETS == WS_IS_BUILTIN
/* Not supported with LWS */
case mosq_t_proxy_v2:
rc = packet__write(context);
break;
case mosq_t_proxy_v1:
rc = packet__write(context);
break;
#endif
default:
rc = MOSQ_ERR_INVAL;
break;
Expand Down Expand Up @@ -295,12 +298,15 @@ static void loop_handle_reads_writes(struct mosquitto *context, uint32_t events)
rc = http__read(context);
break;
#endif
#if !defined(WITH_WEBSOCKETS) || WITH_WEBSOCKETS == WS_IS_BUILTIN
/* Not supported with LWS */
case mosq_t_proxy_v2:
rc = proxy_v2__read(context);
break;
case mosq_t_proxy_v1:
rc = proxy_v1__read(context);
break;
#endif
default:
rc = MOSQ_ERR_INVAL;
break;
Expand Down
6 changes: 6 additions & 0 deletions src/mux_kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,15 @@ static void loop_handle_reads_writes(struct mosquitto *context, short event)
rc = http__write(context);
break;
#endif
#if !defined(WITH_WEBSOCKETS) || WITH_WEBSOCKETS == WS_IS_BUILTIN
/* Not supported with LWS */
case mosq_t_proxy_v2:
rc = packet__write(context);
break;
case mosq_t_proxy_v1:
rc = packet__write(context);
break;
#endif
default:
rc = MOSQ_ERR_INVAL;
break;
Expand Down Expand Up @@ -298,12 +301,15 @@ static void loop_handle_reads_writes(struct mosquitto *context, short event)
rc = http__read(context);
break;
#endif
#if !defined(WITH_WEBSOCKETS) || WITH_WEBSOCKETS == WS_IS_BUILTIN
/* Not supported with LWS */
case mosq_t_proxy_v2:
rc = proxy_v2__read(context);
break;
case mosq_t_proxy_v1:
rc = proxy_v1__read(context);
break;
#endif
default:
rc = MOSQ_ERR_INVAL;
break;
Expand Down
6 changes: 6 additions & 0 deletions src/mux_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,15 @@ static void loop_handle_reads_writes(void)
rc = http__write(context);
break;
#endif
#if !defined(WITH_WEBSOCKETS) || WITH_WEBSOCKETS == WS_IS_BUILTIN
/* Not supported with LWS */
case mosq_t_proxy_v2:
rc = packet__write(context);
break;
case mosq_t_proxy_v1:
rc = packet__write(context);
break;
#endif
default:
rc = MOSQ_ERR_INVAL;
break;
Expand Down Expand Up @@ -369,12 +372,15 @@ static void loop_handle_reads_writes(void)
rc = http__read(context);
break;
#endif
#if !defined(WITH_WEBSOCKETS) || WITH_WEBSOCKETS == WS_IS_BUILTIN
/* Not supported with LWS */
case mosq_t_proxy_v2:
rc = proxy_v2__read(context);
break;
case mosq_t_proxy_v1:
rc = proxy_v1__read(context);
break;
#endif
default:
rc = MOSQ_ERR_INVAL;
break;
Expand Down
3 changes: 3 additions & 0 deletions src/proxy_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "mosquitto_internal.h"
#include "net_mosq.h"

#if !defined(WITH_WEBSOCKETS) || WITH_WEBSOCKETS == WS_IS_BUILTIN

#define PROXY_V1_PACKET_LIMIT 108

const uint8_t signature4[11] = {'P', 'R', 'O', 'X', 'Y', ' ', 'T', 'C', 'P', '4', ' '};
Expand Down Expand Up @@ -153,3 +155,4 @@ int proxy_v1__read(struct mosquitto *context)

return MOSQ_ERR_SUCCESS;
}
#endif
3 changes: 3 additions & 0 deletions src/proxy_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "mosquitto_internal.h"
#include "net_mosq.h"

#if !defined(WITH_WEBSOCKETS) || WITH_WEBSOCKETS == WS_IS_BUILTIN

#define PROXY_CMD_LOCAL 0x00
#define PROXY_CMD_PROXY 0x01

Expand Down Expand Up @@ -304,3 +306,4 @@ int proxy_v2__read(struct mosquitto *context)

return MOSQ_ERR_SUCCESS;
}
#endif
4 changes: 2 additions & 2 deletions src/websockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,9 @@ void mosq_websockets_init(struct mosquitto__listener *listener, const struct mos
if(listener->socket_domain == AF_INET){
info.options |= LWS_SERVER_OPTION_DISABLE_IPV6;
}
info.max_http_header_data = conf->websockets_headers_size;
info.max_http_header_data = conf->packet_buffer_size;

user = mosquitto__calloc(1, sizeof(struct libws_mqtt_hack));
user = mosquitto_calloc(1, sizeof(struct libws_mqtt_hack));
if(!user){
mosquitto_FREE(p);
log__printf(NULL, MOSQ_LOG_ERR, "Out of memory.");
Expand Down

0 comments on commit 4ab8291

Please sign in to comment.