2014-05-08 00:27:00 +02:00
|
|
|
/*
|
2021-11-03 23:08:24 +01:00
|
|
|
Copyright (c) 2010-2021 Roger Light <roger@atchoo.org>
|
2014-05-08 00:27:00 +02:00
|
|
|
|
|
|
|
|
All rights reserved. This program and the accompanying materials
|
2020-11-25 18:34:21 +01:00
|
|
|
are made available under the terms of the Eclipse Public License 2.0
|
2014-05-08 00:27:00 +02:00
|
|
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
2021-10-05 16:20:37 +02:00
|
|
|
|
2014-05-08 00:27:00 +02:00
|
|
|
The Eclipse Public License is available at
|
2020-11-25 18:34:21 +01:00
|
|
|
https://www.eclipse.org/legal/epl-2.0/
|
2014-05-08 00:27:00 +02:00
|
|
|
and the Eclipse Distribution License is available at
|
|
|
|
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
2021-10-05 16:20:37 +02:00
|
|
|
|
2021-01-20 12:46:18 +01:00
|
|
|
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
2020-12-01 19:21:59 +01:00
|
|
|
|
2014-05-08 00:27:00 +02:00
|
|
|
Contributors:
|
|
|
|
|
Roger Light - initial implementation and documentation.
|
2017-07-27 19:43:09 +02:00
|
|
|
Tatsuzo Osawa - Add epoll.
|
2014-05-08 00:27:00 +02:00
|
|
|
*/
|
|
|
|
|
|
2016-03-13 19:43:13 +01:00
|
|
|
#ifndef MOSQUITTO_INTERNAL_H
|
|
|
|
|
#define MOSQUITTO_INTERNAL_H
|
2014-05-08 00:27:00 +02:00
|
|
|
|
2015-04-29 22:37:47 +02:00
|
|
|
#include "config.h"
|
2014-05-08 00:27:00 +02:00
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
# include <winsock2.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_TLS
|
2015-01-15 21:11:14 +01:00
|
|
|
# include <openssl/ssl.h>
|
|
|
|
|
#else
|
|
|
|
|
# include <time.h>
|
2014-05-08 00:27:00 +02:00
|
|
|
#endif
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2024-10-12 18:00:40 +02:00
|
|
|
#include <pthread_compat.h>
|
2014-05-08 00:27:00 +02:00
|
|
|
|
|
|
|
|
#ifdef WITH_SRV
|
|
|
|
|
# include <ares.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef WIN32
|
2025-09-17 12:06:50 +02:00
|
|
|
# if _MSC_VER < 1600
|
|
|
|
|
typedef unsigned char uint8_t;
|
|
|
|
|
typedef unsigned short uint16_t;
|
|
|
|
|
typedef unsigned int uint32_t;
|
|
|
|
|
typedef unsigned long long uint64_t;
|
|
|
|
|
# else
|
|
|
|
|
# include <stdint.h>
|
|
|
|
|
# endif
|
2014-05-08 00:27:00 +02:00
|
|
|
#else
|
2025-09-17 12:06:50 +02:00
|
|
|
# include <stdint.h>
|
2014-05-08 00:27:00 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "mosquitto.h"
|
2024-03-17 08:58:45 +01:00
|
|
|
#include "mosquitto/libcommon_time.h"
|
2014-05-08 00:27:00 +02:00
|
|
|
#ifdef WITH_BROKER
|
2017-02-06 23:39:39 +01:00
|
|
|
# ifdef __linux__
|
|
|
|
|
# include <netdb.h>
|
|
|
|
|
# endif
|
2014-06-23 18:57:35 +02:00
|
|
|
# include "uthash.h"
|
2022-12-23 00:04:48 +01:00
|
|
|
struct mosquitto__client_msg;
|
2014-05-08 00:27:00 +02:00
|
|
|
#endif
|
|
|
|
|
|
2021-09-10 00:55:33 +02:00
|
|
|
#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS
|
2024-11-20 15:30:11 +01:00
|
|
|
# include <libwebsockets.h>
|
2021-09-10 00:55:33 +02:00
|
|
|
# define WS_PACKET_OFFSET LWS_PRE
|
|
|
|
|
#else
|
|
|
|
|
# define WS_PACKET_OFFSET 16
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-03-29 11:43:08 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
|
typedef SOCKET mosq_sock_t;
|
|
|
|
|
#else
|
|
|
|
|
typedef int mosq_sock_t;
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-07-25 20:10:28 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
|
# define WINDOWS_SET_ERRNO() \
|
2026-01-07 16:04:06 +01:00
|
|
|
do{ \
|
|
|
|
|
errno = WSAGetLastError(); \
|
|
|
|
|
}while(0)
|
|
|
|
|
# define WINDOWS_SET_ERRNO_RW() \
|
2025-09-17 12:06:50 +02:00
|
|
|
if(errno != EAGAIN){ \
|
|
|
|
|
errno = WSAGetLastError(); \
|
|
|
|
|
}
|
2025-07-25 20:10:28 +02:00
|
|
|
#else
|
|
|
|
|
# define WINDOWS_SET_ERRNO()
|
2026-01-07 16:04:06 +01:00
|
|
|
# define WINDOWS_SET_ERRNO_RW()
|
2025-07-25 20:10:28 +02:00
|
|
|
#endif
|
|
|
|
|
|
2021-11-15 23:29:19 +01:00
|
|
|
#define SAFE_PRINT(A) (A)?(A):"null"
|
2025-09-17 12:06:50 +02:00
|
|
|
#define SAFE_FREE(A) do{ free(A); (A) = NULL;}while(0)
|
2021-11-15 23:29:19 +01:00
|
|
|
|
2024-03-18 16:29:40 +01:00
|
|
|
#define MSG_EXPIRY_INFINITE UINT32_MAX
|
|
|
|
|
|
2014-05-08 00:27:00 +02:00
|
|
|
enum mosquitto_msg_direction {
|
|
|
|
|
mosq_md_in = 0,
|
2025-09-17 12:06:50 +02:00
|
|
|
mosq_md_out = 1,
|
2014-05-08 00:27:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum mosquitto_msg_state {
|
|
|
|
|
mosq_ms_invalid = 0,
|
|
|
|
|
mosq_ms_publish_qos0 = 1,
|
|
|
|
|
mosq_ms_publish_qos1 = 2,
|
|
|
|
|
mosq_ms_wait_for_puback = 3,
|
|
|
|
|
mosq_ms_publish_qos2 = 4,
|
|
|
|
|
mosq_ms_wait_for_pubrec = 5,
|
|
|
|
|
mosq_ms_resend_pubrel = 6,
|
|
|
|
|
mosq_ms_wait_for_pubrel = 7,
|
|
|
|
|
mosq_ms_resend_pubcomp = 8,
|
|
|
|
|
mosq_ms_wait_for_pubcomp = 9,
|
|
|
|
|
mosq_ms_send_pubrec = 10,
|
2025-09-17 12:06:50 +02:00
|
|
|
mosq_ms_queued = 11,
|
2026-01-21 17:58:42 +01:00
|
|
|
|
|
|
|
|
mosq_ms_any = 255,
|
|
|
|
|
/* max value allowed is 255 */
|
2014-05-08 00:27:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum mosquitto_client_state {
|
|
|
|
|
mosq_cs_new = 0,
|
|
|
|
|
mosq_cs_connected = 1,
|
|
|
|
|
mosq_cs_disconnecting = 2,
|
2019-09-24 12:54:05 +02:00
|
|
|
mosq_cs_active = 3,
|
2014-05-08 00:27:00 +02:00
|
|
|
mosq_cs_connect_pending = 4,
|
2014-06-30 00:16:10 +02:00
|
|
|
mosq_cs_connect_srv = 5,
|
2014-07-09 00:16:34 +02:00
|
|
|
mosq_cs_disconnect_ws = 6,
|
2014-09-30 01:56:57 +02:00
|
|
|
mosq_cs_disconnected = 7,
|
|
|
|
|
mosq_cs_socks5_new = 8,
|
|
|
|
|
mosq_cs_socks5_start = 9,
|
|
|
|
|
mosq_cs_socks5_request = 10,
|
|
|
|
|
mosq_cs_socks5_reply = 11,
|
|
|
|
|
mosq_cs_socks5_auth_ok = 12,
|
|
|
|
|
mosq_cs_socks5_userpass_reply = 13,
|
|
|
|
|
mosq_cs_socks5_send_userpass = 14,
|
2015-01-06 18:35:12 +01:00
|
|
|
mosq_cs_expiring = 15,
|
2018-08-15 18:27:59 +02:00
|
|
|
mosq_cs_duplicate = 17, /* client that has been taken over by another with the same id */
|
2019-02-27 10:22:00 +01:00
|
|
|
mosq_cs_disconnect_with_will = 18,
|
2019-03-12 23:47:48 +01:00
|
|
|
mosq_cs_disused = 19, /* client that has been added to the disused list to be freed */
|
2019-04-04 23:08:55 +02:00
|
|
|
mosq_cs_authenticating = 20, /* Client has sent CONNECT but is still undergoing extended authentication */
|
|
|
|
|
mosq_cs_reauthenticating = 21, /* Client is undergoing reauthentication and shouldn't do anything else until complete */
|
2021-03-25 16:16:39 +01:00
|
|
|
mosq_cs_delayed_auth = 22, /* Client is awaiting an authentication result from a plugin */
|
2014-05-08 00:27:00 +02:00
|
|
|
};
|
|
|
|
|
|
2015-04-19 23:10:59 +02:00
|
|
|
enum mosquitto__protocol {
|
2014-05-08 00:27:00 +02:00
|
|
|
mosq_p_invalid = 0,
|
2021-08-04 18:30:24 +02:00
|
|
|
mosq_p_mqtts = 1,
|
|
|
|
|
mosq_p_mqtt31 = 3,
|
|
|
|
|
mosq_p_mqtt311 = 4,
|
2018-09-19 12:13:50 +02:00
|
|
|
mosq_p_mqtt5 = 5,
|
2014-05-08 00:27:00 +02:00
|
|
|
};
|
|
|
|
|
|
2016-05-18 15:05:08 +02:00
|
|
|
enum mosquitto__threaded_state {
|
2025-09-17 12:06:50 +02:00
|
|
|
mosq_ts_none, /* No threads in use */
|
|
|
|
|
mosq_ts_self, /* Threads started by libmosquitto */
|
|
|
|
|
mosq_ts_external, /* Threads started by external code */
|
2016-05-18 15:05:08 +02:00
|
|
|
};
|
|
|
|
|
|
2015-04-19 23:10:59 +02:00
|
|
|
enum mosquitto__transport {
|
2014-05-08 00:27:00 +02:00
|
|
|
mosq_t_invalid = 0,
|
|
|
|
|
mosq_t_tcp = 1,
|
|
|
|
|
mosq_t_ws = 2,
|
2021-09-10 00:55:33 +02:00
|
|
|
mosq_t_sctp = 3,
|
|
|
|
|
mosq_t_http = 4, /* not valid for MQTT, just as a ws precursor */
|
2024-04-10 12:58:02 +02:00
|
|
|
mosq_t_proxy_v2 = 5, /* not valid for MQTT, just as a PROXY protocol v2 precursor */
|
2024-08-17 10:08:11 +02:00
|
|
|
mosq_t_proxy_v1 = 6, /* not valid for MQTT, just as a PROXY protocol v1 precursor */
|
2014-05-08 00:27:00 +02:00
|
|
|
};
|
|
|
|
|
|
2021-03-22 15:53:16 +01:00
|
|
|
/* Alias direction - local <-> remote */
|
|
|
|
|
#define ALIAS_DIR_L2R 1
|
|
|
|
|
#define ALIAS_DIR_R2L 2
|
2019-01-18 22:30:34 +01:00
|
|
|
|
2025-09-17 12:06:50 +02:00
|
|
|
struct mosquitto__alias {
|
2019-01-18 22:30:34 +01:00
|
|
|
char *topic;
|
|
|
|
|
uint16_t alias;
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-06 15:47:16 +01:00
|
|
|
struct session_expiry_list {
|
|
|
|
|
struct mosquitto *context;
|
|
|
|
|
struct session_expiry_list *prev;
|
|
|
|
|
struct session_expiry_list *next;
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-17 12:06:50 +02:00
|
|
|
struct mosquitto__packet {
|
2015-04-19 23:10:59 +02:00
|
|
|
struct mosquitto__packet *next;
|
2014-05-08 00:27:00 +02:00
|
|
|
uint32_t remaining_length;
|
|
|
|
|
uint32_t packet_length;
|
|
|
|
|
uint32_t to_process;
|
|
|
|
|
uint32_t pos;
|
2014-11-18 08:42:49 +01:00
|
|
|
uint16_t mid;
|
|
|
|
|
uint8_t command;
|
2015-03-27 02:07:48 +01:00
|
|
|
int8_t remaining_count;
|
2021-06-30 15:53:34 +02:00
|
|
|
uint8_t payload[];
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-17 12:06:50 +02:00
|
|
|
struct mosquitto__packet_in {
|
2021-06-30 15:53:34 +02:00
|
|
|
uint8_t *payload;
|
|
|
|
|
uint32_t remaining_mult;
|
|
|
|
|
uint32_t remaining_length;
|
|
|
|
|
uint32_t packet_length;
|
|
|
|
|
uint32_t to_process;
|
|
|
|
|
uint32_t pos;
|
2024-11-11 18:06:50 +01:00
|
|
|
uint16_t packet_buffer_to_process;
|
|
|
|
|
uint16_t packet_buffer_pos;
|
|
|
|
|
uint16_t packet_buffer_size;
|
2021-06-30 15:53:34 +02:00
|
|
|
uint8_t command;
|
2024-11-11 18:06:50 +01:00
|
|
|
uint8_t *packet_buffer;
|
2021-06-30 15:53:34 +02:00
|
|
|
int8_t remaining_count;
|
2014-05-08 00:27:00 +02:00
|
|
|
};
|
|
|
|
|
|
2025-09-17 12:06:50 +02:00
|
|
|
struct mosquitto_message_all {
|
2014-05-08 00:27:00 +02:00
|
|
|
struct mosquitto_message_all *next;
|
2019-04-13 23:59:29 +02:00
|
|
|
struct mosquitto_message_all *prev;
|
2018-11-02 00:50:54 +01:00
|
|
|
mosquitto_property *properties;
|
2014-05-08 00:27:00 +02:00
|
|
|
enum mosquitto_msg_state state;
|
|
|
|
|
bool dup;
|
|
|
|
|
struct mosquitto_message msg;
|
2019-01-22 18:51:57 +01:00
|
|
|
uint32_t expiry_interval;
|
2014-05-08 00:27:00 +02:00
|
|
|
};
|
|
|
|
|
|
2018-08-09 21:37:33 +02:00
|
|
|
#ifdef WITH_TLS
|
2019-02-26 18:11:29 +01:00
|
|
|
enum mosquitto__keyform {
|
2018-08-09 21:37:33 +02:00
|
|
|
mosq_k_pem = 0,
|
|
|
|
|
mosq_k_engine = 1,
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-05-21 15:35:43 +02:00
|
|
|
struct will_delay_list {
|
|
|
|
|
struct mosquitto *context;
|
|
|
|
|
struct will_delay_list *prev;
|
|
|
|
|
struct will_delay_list *next;
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-17 12:06:50 +02:00
|
|
|
struct mosquitto_msg_data {
|
2019-04-13 23:59:29 +02:00
|
|
|
#ifdef WITH_BROKER
|
2022-12-23 00:04:48 +01:00
|
|
|
struct mosquitto__client_msg *inflight;
|
|
|
|
|
struct mosquitto__client_msg *queued;
|
2021-09-22 18:13:45 +02:00
|
|
|
long inflight_bytes;
|
|
|
|
|
long inflight_bytes12;
|
|
|
|
|
int inflight_count;
|
|
|
|
|
int inflight_count12;
|
|
|
|
|
long queued_bytes;
|
|
|
|
|
long queued_bytes12;
|
|
|
|
|
int queued_count;
|
|
|
|
|
int queued_count12;
|
2019-04-13 23:59:29 +02:00
|
|
|
#else
|
|
|
|
|
struct mosquitto_message_all *inflight;
|
|
|
|
|
int queue_len;
|
|
|
|
|
# ifdef WITH_THREADING
|
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
int inflight_quota;
|
|
|
|
|
uint16_t inflight_maximum;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2021-09-10 00:55:33 +02:00
|
|
|
#define WS_CONTINUATION 0x00
|
|
|
|
|
#define WS_TEXT 0x01
|
|
|
|
|
#define WS_BINARY 0x02
|
|
|
|
|
#define WS_CLOSE 0x08
|
|
|
|
|
#define WS_PING 0x09
|
|
|
|
|
#define WS_PONG 0x0A
|
|
|
|
|
|
2022-06-14 23:29:05 +02:00
|
|
|
#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_BUILTIN
|
2025-09-17 12:06:50 +02:00
|
|
|
struct ws_data {
|
2021-09-10 00:55:33 +02:00
|
|
|
struct mosquitto__packet *out_packet;
|
|
|
|
|
char *http_path;
|
2022-01-14 00:34:42 +01:00
|
|
|
char *accept_key;
|
2021-09-10 00:55:33 +02:00
|
|
|
uint64_t payloadlen;
|
|
|
|
|
ssize_t pos;
|
|
|
|
|
int http_header_size;
|
|
|
|
|
uint8_t maskingkey[4];
|
|
|
|
|
uint8_t disconnect_reason;
|
|
|
|
|
uint8_t opcode;
|
|
|
|
|
uint8_t mask;
|
|
|
|
|
uint8_t mask_bytes;
|
|
|
|
|
uint8_t payloadlen_bytes;
|
|
|
|
|
bool is_client;
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-09-17 12:06:50 +02:00
|
|
|
struct proxy_data {
|
2024-04-10 12:58:02 +02:00
|
|
|
uint8_t *buf;
|
|
|
|
|
char *cipher;
|
|
|
|
|
char *tls_version;
|
|
|
|
|
uint16_t len;
|
|
|
|
|
uint16_t pos;
|
|
|
|
|
int8_t cmd;
|
|
|
|
|
uint8_t fam;
|
|
|
|
|
bool have_tls;
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-17 12:06:50 +02:00
|
|
|
struct client_stats {
|
2021-11-18 12:15:51 +01:00
|
|
|
uint64_t messages_received;
|
|
|
|
|
uint64_t messages_sent;
|
|
|
|
|
uint64_t messages_dropped;
|
|
|
|
|
};
|
|
|
|
|
|
2014-05-08 00:27:00 +02:00
|
|
|
struct mosquitto {
|
2021-03-09 11:03:27 +01:00
|
|
|
#if defined(WITH_BROKER) && (defined(WITH_EPOLL) || defined(WITH_KQUEUE))
|
2020-11-05 17:10:50 +01:00
|
|
|
/* This *must* be the first element in the struct. */
|
|
|
|
|
int ident;
|
|
|
|
|
#endif
|
2015-03-29 11:43:08 +02:00
|
|
|
mosq_sock_t sock;
|
|
|
|
|
#ifndef WITH_BROKER
|
|
|
|
|
mosq_sock_t sockpairR, sockpairW;
|
2017-02-06 23:39:39 +01:00
|
|
|
#endif
|
2020-12-10 13:52:11 +01:00
|
|
|
uint32_t maximum_packet_size;
|
2017-02-08 23:30:00 +01:00
|
|
|
#if defined(__GLIBC__) && defined(WITH_ADNS)
|
2017-02-06 23:39:39 +01:00
|
|
|
struct gaicb *adns; /* For getaddrinfo_a */
|
2021-09-10 00:55:33 +02:00
|
|
|
#endif
|
2021-08-05 17:15:28 +02:00
|
|
|
uint64_t last_cmsg_id;
|
2022-06-14 23:29:05 +02:00
|
|
|
#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_BUILTIN
|
2021-09-10 00:55:33 +02:00
|
|
|
struct ws_data wsd;
|
2014-05-08 00:27:00 +02:00
|
|
|
#endif
|
2015-04-19 23:10:59 +02:00
|
|
|
enum mosquitto__protocol protocol;
|
2014-05-08 00:27:00 +02:00
|
|
|
char *address;
|
|
|
|
|
char *id;
|
|
|
|
|
char *username;
|
|
|
|
|
char *password;
|
2025-02-03 12:10:09 +01:00
|
|
|
unsigned id_hashv;
|
2014-05-08 00:27:00 +02:00
|
|
|
uint16_t keepalive;
|
2015-02-13 22:17:11 +01:00
|
|
|
uint16_t last_mid;
|
2026-02-13 13:18:47 +01:00
|
|
|
uint16_t password_len;
|
2014-05-08 00:27:00 +02:00
|
|
|
enum mosquitto_client_state state;
|
2021-09-10 00:55:33 +02:00
|
|
|
uint8_t transport;
|
2014-05-08 00:27:00 +02:00
|
|
|
time_t last_msg_in;
|
2016-02-28 18:24:43 +01:00
|
|
|
time_t next_msg_out;
|
2014-05-08 00:27:00 +02:00
|
|
|
time_t ping_t;
|
2021-06-30 15:53:34 +02:00
|
|
|
struct mosquitto__packet_in in_packet;
|
2015-04-19 23:10:59 +02:00
|
|
|
struct mosquitto__packet *out_packet;
|
2018-10-24 15:07:09 +02:00
|
|
|
struct mosquitto_message_all *will;
|
2021-03-22 15:53:16 +01:00
|
|
|
struct mosquitto__alias *aliases_l2r;
|
|
|
|
|
struct mosquitto__alias *aliases_r2l;
|
2019-05-21 15:35:43 +02:00
|
|
|
struct will_delay_list *will_delay_entry;
|
2021-03-22 15:53:16 +01:00
|
|
|
uint16_t alias_count_l2r;
|
|
|
|
|
uint16_t alias_count_r2l;
|
|
|
|
|
uint16_t alias_max_l2r;
|
2019-02-25 23:28:51 +01:00
|
|
|
uint32_t will_delay_interval;
|
2021-05-21 16:38:29 +02:00
|
|
|
int out_packet_count;
|
2022-06-02 09:44:08 +02:00
|
|
|
int64_t out_packet_bytes;
|
2019-02-25 23:28:51 +01:00
|
|
|
time_t will_delay_time;
|
2014-05-08 00:27:00 +02:00
|
|
|
#ifdef WITH_TLS
|
|
|
|
|
SSL *ssl;
|
|
|
|
|
SSL_CTX *ssl_ctx;
|
2021-08-31 16:59:40 +02:00
|
|
|
#ifndef WITH_BROKER
|
|
|
|
|
SSL_CTX *user_ssl_ctx;
|
|
|
|
|
#endif
|
2014-05-08 00:27:00 +02:00
|
|
|
char *tls_cafile;
|
|
|
|
|
char *tls_capath;
|
|
|
|
|
char *tls_certfile;
|
|
|
|
|
char *tls_keyfile;
|
|
|
|
|
int (*tls_pw_callback)(char *buf, int size, int rwflag, void *userdata);
|
|
|
|
|
char *tls_version;
|
|
|
|
|
char *tls_ciphers;
|
2021-03-29 06:54:46 +02:00
|
|
|
char *tls_13_ciphers;
|
2014-05-08 00:27:00 +02:00
|
|
|
char *tls_psk;
|
|
|
|
|
char *tls_psk_identity;
|
2020-12-01 12:51:13 +01:00
|
|
|
char *tls_engine;
|
|
|
|
|
char *tls_engine_kpass_sha1;
|
|
|
|
|
char *tls_alpn;
|
2014-11-18 08:42:49 +01:00
|
|
|
int tls_cert_reqs;
|
2014-05-08 00:27:00 +02:00
|
|
|
bool tls_insecure;
|
2018-04-11 17:34:24 +02:00
|
|
|
bool ssl_ctx_defaults;
|
2017-06-09 15:52:50 +02:00
|
|
|
bool tls_ocsp_required;
|
2020-12-01 12:51:13 +01:00
|
|
|
bool tls_use_os_certs;
|
2019-02-26 18:11:29 +01:00
|
|
|
enum mosquitto__keyform tls_keyform;
|
2014-05-08 00:27:00 +02:00
|
|
|
#endif
|
|
|
|
|
bool want_write;
|
2025-11-24 00:11:56 +01:00
|
|
|
bool run;
|
2014-05-08 00:27:00 +02:00
|
|
|
#if defined(WITH_THREADING) && !defined(WITH_BROKER)
|
|
|
|
|
pthread_mutex_t callback_mutex;
|
|
|
|
|
pthread_mutex_t log_callback_mutex;
|
|
|
|
|
pthread_mutex_t msgtime_mutex;
|
|
|
|
|
pthread_mutex_t out_packet_mutex;
|
|
|
|
|
pthread_mutex_t state_mutex;
|
2015-04-03 08:48:55 +02:00
|
|
|
pthread_mutex_t mid_mutex;
|
2014-05-08 00:27:00 +02:00
|
|
|
pthread_t thread_id;
|
|
|
|
|
#endif
|
2018-11-27 11:02:10 +01:00
|
|
|
bool clean_start;
|
2019-03-06 15:47:16 +01:00
|
|
|
time_t session_expiry_time;
|
2020-12-10 13:52:11 +01:00
|
|
|
uint32_t session_expiry_interval;
|
2014-05-08 00:27:00 +02:00
|
|
|
#ifdef WITH_BROKER
|
2021-10-06 10:54:02 +02:00
|
|
|
bool in_by_id;
|
2014-11-18 08:42:49 +01:00
|
|
|
bool is_dropping;
|
2014-05-08 00:27:00 +02:00
|
|
|
bool is_bridge;
|
2022-03-01 17:24:54 +01:00
|
|
|
bool is_persisted;
|
2015-05-16 20:03:12 +02:00
|
|
|
struct mosquitto__bridge *bridge;
|
2019-04-13 23:59:29 +02:00
|
|
|
struct mosquitto_msg_data msgs_in;
|
|
|
|
|
struct mosquitto_msg_data msgs_out;
|
2015-04-19 23:10:59 +02:00
|
|
|
struct mosquitto__acl_user *acl_list;
|
2015-05-16 20:03:12 +02:00
|
|
|
struct mosquitto__listener *listener;
|
2015-04-19 23:10:59 +02:00
|
|
|
struct mosquitto__packet *out_packet_last;
|
2022-11-03 15:07:07 +01:00
|
|
|
struct mosquitto__subleaf **subs;
|
2019-04-04 11:55:24 +02:00
|
|
|
char *auth_method;
|
2022-11-03 09:17:34 +01:00
|
|
|
int subs_capacity; /* allocated size of the subs instance */
|
2022-11-02 11:14:37 +01:00
|
|
|
int subs_count; /* number of currently active subscriptions */
|
2020-12-10 13:52:11 +01:00
|
|
|
# ifndef WITH_EPOLL
|
2014-11-18 08:42:49 +01:00
|
|
|
int pollfd_index;
|
2020-12-10 13:52:11 +01:00
|
|
|
# endif
|
2014-05-06 11:47:00 +02:00
|
|
|
# ifdef WITH_WEBSOCKETS
|
2021-09-10 00:55:33 +02:00
|
|
|
# if WITH_WEBSOCKETS == WS_IS_LWS
|
2015-12-19 02:21:17 +01:00
|
|
|
struct lws *wsi;
|
2021-09-10 00:55:33 +02:00
|
|
|
# endif
|
2014-05-06 11:47:00 +02:00
|
|
|
# endif
|
2019-04-03 11:50:19 +02:00
|
|
|
bool assigned_id;
|
2014-05-08 00:27:00 +02:00
|
|
|
#else
|
2014-09-30 01:56:57 +02:00
|
|
|
# ifdef WITH_SOCKS
|
|
|
|
|
char *socks5_host;
|
2020-10-17 02:23:08 +02:00
|
|
|
uint16_t socks5_port;
|
2014-09-30 01:56:57 +02:00
|
|
|
char *socks5_username;
|
|
|
|
|
char *socks5_password;
|
|
|
|
|
# endif
|
2014-05-08 00:27:00 +02:00
|
|
|
void *userdata;
|
2019-04-13 23:59:29 +02:00
|
|
|
struct mosquitto_msg_data msgs_in;
|
|
|
|
|
struct mosquitto_msg_data msgs_out;
|
2025-04-16 15:23:16 +02:00
|
|
|
LIBMOSQ_CB_pre_connect on_pre_connect;
|
|
|
|
|
LIBMOSQ_CB_connect on_connect;
|
|
|
|
|
LIBMOSQ_CB_connect_with_flags on_connect_with_flags;
|
|
|
|
|
LIBMOSQ_CB_connect_v5 on_connect_v5;
|
|
|
|
|
LIBMOSQ_CB_disconnect on_disconnect;
|
|
|
|
|
LIBMOSQ_CB_disconnect_v5 on_disconnect_v5;
|
|
|
|
|
LIBMOSQ_CB_publish on_publish;
|
|
|
|
|
LIBMOSQ_CB_publish_v5 on_publish_v5;
|
|
|
|
|
LIBMOSQ_CB_message on_message;
|
|
|
|
|
LIBMOSQ_CB_message_v5 on_message_v5;
|
|
|
|
|
LIBMOSQ_CB_subscribe on_subscribe;
|
|
|
|
|
LIBMOSQ_CB_subscribe_v5 on_subscribe_v5;
|
|
|
|
|
LIBMOSQ_CB_unsubscribe on_unsubscribe;
|
|
|
|
|
LIBMOSQ_CB_unsubscribe_v5 on_unsubscribe_v5;
|
|
|
|
|
LIBMOSQ_CB_unsubscribe2_v5 on_unsubscribe2_v5;
|
|
|
|
|
LIBMOSQ_CB_ext_auth on_ext_auth;
|
|
|
|
|
LIBMOSQ_CB_log on_log;
|
2020-03-12 11:29:11 +01:00
|
|
|
/*void (*on_error)();*/
|
2014-05-08 00:27:00 +02:00
|
|
|
char *host;
|
|
|
|
|
char *bind_address;
|
2019-09-04 23:20:13 +02:00
|
|
|
unsigned int reconnects;
|
2014-05-08 00:27:00 +02:00
|
|
|
unsigned int reconnect_delay;
|
|
|
|
|
unsigned int reconnect_delay_max;
|
2021-03-13 18:30:13 +01:00
|
|
|
int callback_depth;
|
|
|
|
|
uint16_t port;
|
2021-01-14 15:10:28 +01:00
|
|
|
bool disable_socketpair;
|
2014-05-08 00:27:00 +02:00
|
|
|
bool reconnect_exponential_backoff;
|
2022-08-15 23:17:00 +02:00
|
|
|
bool request_disconnect;
|
2016-05-18 15:05:08 +02:00
|
|
|
char threaded;
|
2015-04-19 23:10:59 +02:00
|
|
|
struct mosquitto__packet *out_packet_last;
|
2020-10-14 12:21:41 +02:00
|
|
|
mosquitto_property *connect_properties;
|
2014-05-08 00:27:00 +02:00
|
|
|
# ifdef WITH_SRV
|
|
|
|
|
ares_channel achan;
|
|
|
|
|
# endif
|
2019-04-13 23:59:29 +02:00
|
|
|
#endif
|
2020-12-01 17:08:05 +01:00
|
|
|
uint8_t max_qos;
|
2019-11-07 12:58:43 +01:00
|
|
|
uint8_t retain_available;
|
2019-12-18 14:47:34 +01:00
|
|
|
bool tcp_nodelay;
|
2021-09-10 00:55:33 +02:00
|
|
|
#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_BUILTIN
|
|
|
|
|
char *http_request;
|
|
|
|
|
#endif
|
2014-06-23 18:57:35 +02:00
|
|
|
|
|
|
|
|
#ifdef WITH_BROKER
|
|
|
|
|
UT_hash_handle hh_id;
|
|
|
|
|
UT_hash_handle hh_sock;
|
2014-09-23 00:35:09 +02:00
|
|
|
struct mosquitto *for_free_next;
|
2019-03-06 15:47:16 +01:00
|
|
|
struct session_expiry_list *expiry_list_item;
|
2020-12-01 23:38:59 +01:00
|
|
|
uint16_t remote_port;
|
2021-10-12 15:26:41 +02:00
|
|
|
# ifndef WITH_OLD_KEEPALIVE
|
|
|
|
|
struct mosquitto *keepalive_next;
|
|
|
|
|
struct mosquitto *keepalive_prev;
|
2025-07-25 20:10:28 +02:00
|
|
|
time_t keepalive_add_time;
|
2021-10-12 15:26:41 +02:00
|
|
|
# endif
|
2021-11-18 12:15:51 +01:00
|
|
|
struct client_stats stats;
|
2014-06-23 18:57:35 +02:00
|
|
|
#endif
|
2021-03-09 11:03:27 +01:00
|
|
|
#ifdef WITH_EPOLL
|
2017-07-27 19:43:09 +02:00
|
|
|
uint32_t events;
|
2021-03-09 11:03:27 +01:00
|
|
|
#elif defined(WITH_KQUEUE)
|
|
|
|
|
short events;
|
|
|
|
|
#else
|
|
|
|
|
uint32_t events;
|
|
|
|
|
#endif
|
2024-04-10 12:58:02 +02:00
|
|
|
struct proxy_data proxy;
|
2014-05-08 00:27:00 +02:00
|
|
|
};
|
|
|
|
|
|
2015-08-17 17:22:44 +02:00
|
|
|
#define STREMPTY(str) (str[0] == '\0')
|
|
|
|
|
|
2018-11-22 19:07:52 +01:00
|
|
|
void do_client_disconnect(struct mosquitto *mosq, int reason_code, const mosquitto_property *properties);
|
2018-11-22 18:31:17 +01:00
|
|
|
|
2014-05-08 00:27:00 +02:00
|
|
|
#endif
|