|
|
|
@ -54,24 +54,16 @@ POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
#define WS_SERV_BUF_SIZE 4096
|
|
|
|
|
#define WS_TX_BUF_SIZE (WS_SERV_BUF_SIZE*2)
|
|
|
|
|
|
|
|
|
|
#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,
|
|
|
|
|
struct lws *wsi,
|
|
|
|
|
enum lws_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,
|
|
|
|
|
struct lws *wsi,
|
|
|
|
|
enum lws_callback_reasons reason,
|
|
|
|
|
void *user,
|
|
|
|
|
void *in,
|
|
|
|
|
size_t len);
|
|
|
|
@ -86,79 +78,43 @@ struct libws_http_data {
|
|
|
|
|
FILE *fptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct libwebsocket_protocols protocols[] = {
|
|
|
|
|
static struct lws_protocols protocols[] = {
|
|
|
|
|
/* first protocol must always be HTTP handler */
|
|
|
|
|
{
|
|
|
|
|
"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
|
|
|
|
|
#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
|
|
|
|
|
WS_TX_BUF_SIZE /* tx_packet_size v2.3.0 */
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"mqtt",
|
|
|
|
|
callback_mqtt,
|
|
|
|
|
sizeof(struct libws_mqtt_data),
|
|
|
|
|
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
|
|
|
|
|
1, /* id */
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LWS_LIBRARY_VERSION_NUMBER
|
|
|
|
|
NULL, /* user v1.4 on */
|
|
|
|
|
# if LWS_LIBRARY_VERSION_NUMBER >= 2003000
|
|
|
|
|
WS_TX_BUF_SIZE /* tx_packet_size v2.3.0 */
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"mqttv3.1",
|
|
|
|
|
callback_mqtt,
|
|
|
|
|
sizeof(struct libws_mqtt_data),
|
|
|
|
|
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
|
|
|
|
|
2, /* id */
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LWS_LIBRARY_VERSION_NUMBER
|
|
|
|
|
NULL, /* user v1.4 on */
|
|
|
|
|
# if LWS_LIBRARY_VERSION_NUMBER >= 2003000
|
|
|
|
|
WS_TX_BUF_SIZE /* tx_packet_size v2.3.0 */
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -171,13 +127,9 @@ 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,
|
|
|
|
|
struct lws *wsi,
|
|
|
|
|
enum lws_callback_reasons reason,
|
|
|
|
|
void *user,
|
|
|
|
|
void *in,
|
|
|
|
|
size_t len)
|
|
|
|
@ -187,7 +139,7 @@ static int callback_mqtt(struct libwebsocket_context *context,
|
|
|
|
|
size_t txlen;
|
|
|
|
|
int count;
|
|
|
|
|
unsigned int ucount;
|
|
|
|
|
const struct libwebsocket_protocols *p;
|
|
|
|
|
const struct lws_protocols *p;
|
|
|
|
|
struct libws_mqtt_data *u = (struct libws_mqtt_data *)user;
|
|
|
|
|
size_t pos;
|
|
|
|
|
uint8_t *buf;
|
|
|
|
@ -198,15 +150,12 @@ static int callback_mqtt(struct libwebsocket_context *context,
|
|
|
|
|
case LWS_CALLBACK_ESTABLISHED:
|
|
|
|
|
mosq = context__init(WEBSOCKET_CLIENT);
|
|
|
|
|
if(mosq){
|
|
|
|
|
p = libwebsockets_get_protocol(wsi);
|
|
|
|
|
p = lws_get_protocol(wsi);
|
|
|
|
|
mosq->listener = p->user;
|
|
|
|
|
if(!mosq->listener){
|
|
|
|
|
mosquitto__free(mosq);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
#if !defined(LWS_LIBRARY_VERSION_NUMBER)
|
|
|
|
|
mosq->ws_context = context;
|
|
|
|
|
#endif
|
|
|
|
|
mosq->wsi = wsi;
|
|
|
|
|
#ifdef WITH_TLS
|
|
|
|
|
if(in){
|
|
|
|
@ -220,7 +169,7 @@ static int callback_mqtt(struct libwebsocket_context *context,
|
|
|
|
|
}else{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
easy_address(libwebsocket_get_socket_fd(wsi), mosq);
|
|
|
|
|
easy_address(lws_get_socket_fd(wsi), mosq);
|
|
|
|
|
if(!mosq->address){
|
|
|
|
|
/* getpeername and inet_ntop failed and not a bridge */
|
|
|
|
|
mosquitto__free(mosq);
|
|
|
|
@ -236,7 +185,7 @@ static int callback_mqtt(struct libwebsocket_context *context,
|
|
|
|
|
u->mosq = NULL;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
mosq->sock = libwebsocket_get_socket_fd(wsi);
|
|
|
|
|
mosq->sock = lws_get_socket_fd(wsi);
|
|
|
|
|
HASH_ADD(hh_sock, db.contexts_by_sock, sock, sizeof(mosq->sock), mosq);
|
|
|
|
|
mux__add_in(mosq);
|
|
|
|
|
break;
|
|
|
|
@ -289,19 +238,19 @@ static int callback_mqtt(struct libwebsocket_context *context,
|
|
|
|
|
if(packet->pos == 0 && packet->to_process == packet->packet_length){
|
|
|
|
|
/* First time this packet has been dealt with.
|
|
|
|
|
* libwebsockets requires that the payload has
|
|
|
|
|
* LWS_SEND_BUFFER_PRE_PADDING space available before the
|
|
|
|
|
* actual data and LWS_SEND_BUFFER_POST_PADDING afterwards.
|
|
|
|
|
* LWS_PRE space available before the
|
|
|
|
|
* actual data.
|
|
|
|
|
* We've already made the payload big enough to allow this,
|
|
|
|
|
* but need to move it into position here. */
|
|
|
|
|
memmove(&packet->payload[LWS_SEND_BUFFER_PRE_PADDING], packet->payload, packet->packet_length);
|
|
|
|
|
packet->pos += LWS_SEND_BUFFER_PRE_PADDING;
|
|
|
|
|
memmove(&packet->payload[LWS_PRE], packet->payload, packet->packet_length);
|
|
|
|
|
packet->pos += LWS_PRE;
|
|
|
|
|
}
|
|
|
|
|
if(packet->to_process > WS_TX_BUF_SIZE){
|
|
|
|
|
txlen = WS_TX_BUF_SIZE;
|
|
|
|
|
}else{
|
|
|
|
|
txlen = packet->to_process;
|
|
|
|
|
}
|
|
|
|
|
count = libwebsocket_write(wsi, &packet->payload[packet->pos], txlen, LWS_WRITE_BINARY);
|
|
|
|
|
count = lws_write(wsi, &packet->payload[packet->pos], txlen, LWS_WRITE_BINARY);
|
|
|
|
|
if(count < 0){
|
|
|
|
|
if (mosq->state == mosq_cs_disconnect_ws
|
|
|
|
|
|| mosq->state == mosq_cs_disconnecting
|
|
|
|
@ -355,7 +304,7 @@ static int callback_mqtt(struct libwebsocket_context *context,
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if(mosq->current_out_packet){
|
|
|
|
|
libwebsocket_callback_on_writable(mosq->ws_context, mosq->wsi);
|
|
|
|
|
lws_callback_on_writable(mosq->wsi);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
@ -438,7 +387,7 @@ static int callback_mqtt(struct libwebsocket_context *context,
|
|
|
|
|
if(mosq->state != mosq_cs_disconnecting){
|
|
|
|
|
mosquitto__set_state(mosq, mosq_cs_disconnect_ws);
|
|
|
|
|
}
|
|
|
|
|
libwebsocket_callback_on_writable(mosq->ws_context, mosq->wsi);
|
|
|
|
|
lws_callback_on_writable(mosq->wsi);
|
|
|
|
|
} else if (rc) {
|
|
|
|
|
do_disconnect(mosq, MOSQ_ERR_CONN_LOST);
|
|
|
|
|
return -1;
|
|
|
|
@ -455,10 +404,7 @@ 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,
|
|
|
|
|
struct lws *wsi,
|
|
|
|
|
const char *in,
|
|
|
|
|
const char *http_dir)
|
|
|
|
|
{
|
|
|
|
@ -473,7 +419,7 @@ static char *http__canonical_filename(
|
|
|
|
|
}
|
|
|
|
|
filename = mosquitto__malloc(slen);
|
|
|
|
|
if(!filename){
|
|
|
|
|
libwebsockets_return_http_status(context, wsi, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL);
|
|
|
|
|
lws_return_http_status(wsi, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if(((char *)in)[inlen-1] == '/'){
|
|
|
|
@ -488,7 +434,7 @@ static char *http__canonical_filename(
|
|
|
|
|
filename_canonical = _fullpath(NULL, filename, 0);
|
|
|
|
|
mosquitto__free(filename);
|
|
|
|
|
if(!filename_canonical){
|
|
|
|
|
libwebsockets_return_http_status(context, wsi, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL);
|
|
|
|
|
lws_return_http_status(wsi, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
@ -496,13 +442,13 @@ static char *http__canonical_filename(
|
|
|
|
|
mosquitto__free(filename);
|
|
|
|
|
if(!filename_canonical){
|
|
|
|
|
if(errno == EACCES){
|
|
|
|
|
libwebsockets_return_http_status(context, wsi, HTTP_STATUS_FORBIDDEN, NULL);
|
|
|
|
|
lws_return_http_status(wsi, HTTP_STATUS_FORBIDDEN, NULL);
|
|
|
|
|
}else if(errno == EINVAL || errno == EIO || errno == ELOOP){
|
|
|
|
|
libwebsockets_return_http_status(context, wsi, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL);
|
|
|
|
|
lws_return_http_status(wsi, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL);
|
|
|
|
|
}else if(errno == ENAMETOOLONG){
|
|
|
|
|
libwebsockets_return_http_status(context, wsi, HTTP_STATUS_REQ_URI_TOO_LONG, NULL);
|
|
|
|
|
lws_return_http_status(wsi, HTTP_STATUS_REQ_URI_TOO_LONG, NULL);
|
|
|
|
|
}else if(errno == ENOENT || errno == ENOTDIR){
|
|
|
|
|
libwebsockets_return_http_status(context, wsi, HTTP_STATUS_NOT_FOUND, NULL);
|
|
|
|
|
lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
@ -510,7 +456,7 @@ static char *http__canonical_filename(
|
|
|
|
|
if(strncmp(http_dir, filename_canonical, strlen(http_dir))){
|
|
|
|
|
/* Requested file isn't within http_dir, deny access. */
|
|
|
|
|
free(filename_canonical);
|
|
|
|
|
libwebsockets_return_http_status(context, wsi, HTTP_STATUS_FORBIDDEN, NULL);
|
|
|
|
|
lws_return_http_status(wsi, HTTP_STATUS_FORBIDDEN, NULL);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -518,13 +464,9 @@ static char *http__canonical_filename(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#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,
|
|
|
|
|
struct lws *wsi,
|
|
|
|
|
enum lws_callback_reasons reason,
|
|
|
|
|
void *user,
|
|
|
|
|
void *in,
|
|
|
|
|
size_t len)
|
|
|
|
@ -549,11 +491,7 @@ 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;
|
|
|
|
|
}
|
|
|
|
@ -566,26 +504,22 @@ static int callback_http(struct libwebsocket_context *context,
|
|
|
|
|
|
|
|
|
|
/* Forbid POST */
|
|
|
|
|
if(lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI)){
|
|
|
|
|
libwebsockets_return_http_status(context, wsi, HTTP_STATUS_METHOD_NOT_ALLOWED, NULL);
|
|
|
|
|
lws_return_http_status(wsi, HTTP_STATUS_METHOD_NOT_ALLOWED, NULL);
|
|
|
|
|
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");
|
|
|
|
|
if(!u->fptr){
|
|
|
|
|
free(filename_canonical);
|
|
|
|
|
libwebsockets_return_http_status(context, wsi, HTTP_STATUS_NOT_FOUND, NULL);
|
|
|
|
|
lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if(fstat(fileno(u->fptr), &filestat) < 0){
|
|
|
|
|
free(filename_canonical);
|
|
|
|
|
libwebsockets_return_http_status(context, wsi, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL);
|
|
|
|
|
lws_return_http_status(wsi, HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL);
|
|
|
|
|
fclose(u->fptr);
|
|
|
|
|
u->fptr = NULL;
|
|
|
|
|
return -1;
|
|
|
|
@ -601,11 +535,11 @@ static int callback_http(struct libwebsocket_context *context,
|
|
|
|
|
buflen = (size_t)snprintf((char *)buf, 4096, "HTTP/1.0 302 OK\r\n"
|
|
|
|
|
"Location: %s/\r\n\r\n",
|
|
|
|
|
(char *)in);
|
|
|
|
|
return libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP);
|
|
|
|
|
return lws_write(wsi, buf, buflen, LWS_WRITE_HTTP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if((filestat.st_mode & S_IFREG) != S_IFREG){
|
|
|
|
|
libwebsockets_return_http_status(context, wsi, HTTP_STATUS_FORBIDDEN, NULL);
|
|
|
|
|
lws_return_http_status(wsi, HTTP_STATUS_FORBIDDEN, NULL);
|
|
|
|
|
fclose(u->fptr);
|
|
|
|
|
u->fptr = NULL;
|
|
|
|
|
free(filename_canonical);
|
|
|
|
@ -619,12 +553,12 @@ static int callback_http(struct libwebsocket_context *context,
|
|
|
|
|
"Server: mosquitto\r\n"
|
|
|
|
|
"Content-Length: %u\r\n\r\n",
|
|
|
|
|
(unsigned int)filestat.st_size);
|
|
|
|
|
if(libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP) < 0){
|
|
|
|
|
if(lws_write(wsi, buf, buflen, LWS_WRITE_HTTP) < 0){
|
|
|
|
|
fclose(u->fptr);
|
|
|
|
|
u->fptr = NULL;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
libwebsocket_callback_on_writable(context, wsi);
|
|
|
|
|
lws_callback_on_writable(wsi);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LWS_CALLBACK_HTTP_BODY:
|
|
|
|
@ -649,7 +583,7 @@ static int callback_http(struct libwebsocket_context *context,
|
|
|
|
|
u->fptr = NULL;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
rc = libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP);
|
|
|
|
|
rc = lws_write(wsi, buf, buflen, LWS_WRITE_HTTP);
|
|
|
|
|
if(rc < 0){
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
@ -667,7 +601,7 @@ static int callback_http(struct libwebsocket_context *context,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}while(u->fptr && !lws_send_pipe_choked(wsi));
|
|
|
|
|
libwebsocket_callback_on_writable(context, wsi);
|
|
|
|
|
lws_callback_on_writable(wsi);
|
|
|
|
|
}else{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
@ -718,10 +652,10 @@ 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, const struct mosquitto__config *conf)
|
|
|
|
|
struct lws_context *mosq_websockets_init(struct mosquitto__listener *listener, const struct mosquitto__config *conf)
|
|
|
|
|
{
|
|
|
|
|
struct lws_context_creation_info info;
|
|
|
|
|
struct libwebsocket_protocols *p;
|
|
|
|
|
struct lws_protocols *p;
|
|
|
|
|
size_t protocol_count;
|
|
|
|
|
int i;
|
|
|
|
|
struct libws_mqtt_hack *user;
|
|
|
|
@ -729,7 +663,7 @@ struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *li
|
|
|
|
|
/* Count valid protocols */
|
|
|
|
|
for(protocol_count=0; protocols[protocol_count].name; protocol_count++);
|
|
|
|
|
|
|
|
|
|
p = mosquitto__calloc(protocol_count+1, sizeof(struct libwebsocket_protocols));
|
|
|
|
|
p = mosquitto__calloc(protocol_count+1, sizeof(struct lws_protocols));
|
|
|
|
|
if(!p){
|
|
|
|
|
log__printf(NULL, MOSQ_LOG_ERR, "Out of memory.");
|
|
|
|
|
return NULL;
|
|
|
|
@ -754,22 +688,18 @@ struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *li
|
|
|
|
|
info.ssl_private_key_filepath = listener->keyfile;
|
|
|
|
|
info.ssl_cipher_list = listener->ciphers;
|
|
|
|
|
#if defined(WITH_WEBSOCKETS) && LWS_LIBRARY_VERSION_NUMBER>=3001000
|
|
|
|
|
info->tls_1_3_plus_cipher_list = listener->ciphers_tls13;
|
|
|
|
|
info.tls1_3_plus_cipher_list = listener->ciphers_tls13;
|
|
|
|
|
#endif
|
|
|
|
|
if(listener->require_certificate){
|
|
|
|
|
info.options |= LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if LWS_LIBRARY_VERSION_MAJOR>1
|
|
|
|
|
info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
|
|
|
|
#endif
|
|
|
|
|
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){
|
|
|
|
@ -793,15 +723,13 @@ struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *li
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info.user = user;
|
|
|
|
|
#if defined(LWS_LIBRARY_VERSION_NUMBER) && LWS_LIBRARY_VERSION_NUMBER>=2004000
|
|
|
|
|
info.pt_serv_buf_size = WS_SERV_BUF_SIZE;
|
|
|
|
|
#endif
|
|
|
|
|
listener->ws_protocol = p;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
return lws_create_context(&info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|