2014-05-07 22:27:00 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2009-2014 Roger Light <roger@atchoo.org>
|
|
|
|
|
|
|
|
All rights reserved. This program and the accompanying materials
|
|
|
|
are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
|
|
|
|
|
|
|
The Eclipse Public License is available at
|
|
|
|
http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
and the Eclipse Distribution License is available at
|
|
|
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
|
|
|
|
|
|
|
Contributors:
|
|
|
|
Roger Light - initial implementation and documentation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MQTT3_H
|
|
|
|
#define MQTT3_H
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <mosquitto_internal.h>
|
|
|
|
#include <mosquitto_plugin.h>
|
|
|
|
#include <mosquitto.h>
|
|
|
|
#include "tls_mosq.h"
|
|
|
|
#include "uthash.h"
|
|
|
|
|
|
|
|
#ifndef __GNUC__
|
|
|
|
#define __attribute__(attrib)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Log destinations */
|
|
|
|
#define MQTT3_LOG_NONE 0x00
|
|
|
|
#define MQTT3_LOG_SYSLOG 0x01
|
|
|
|
#define MQTT3_LOG_FILE 0x02
|
|
|
|
#define MQTT3_LOG_STDOUT 0x04
|
|
|
|
#define MQTT3_LOG_STDERR 0x08
|
|
|
|
#define MQTT3_LOG_TOPIC 0x10
|
|
|
|
#define MQTT3_LOG_ALL 0xFF
|
|
|
|
|
2014-06-29 22:16:10 +00:00
|
|
|
#define WEBSOCKET_CLIENT -2
|
|
|
|
|
2014-05-18 21:40:20 +00:00
|
|
|
enum mosquitto_protocol {
|
|
|
|
mp_mqtt,
|
|
|
|
mp_mqttsn,
|
|
|
|
mp_websockets
|
|
|
|
};
|
|
|
|
|
2014-05-07 22:27:00 +00:00
|
|
|
typedef uint64_t dbid_t;
|
|
|
|
|
|
|
|
struct _mqtt3_listener {
|
|
|
|
int fd;
|
|
|
|
char *host;
|
|
|
|
uint16_t port;
|
|
|
|
int max_connections;
|
|
|
|
char *mount_point;
|
2015-03-29 09:43:08 +00:00
|
|
|
mosq_sock_t *socks;
|
2014-05-07 22:27:00 +00:00
|
|
|
int sock_count;
|
|
|
|
int client_count;
|
2014-05-18 21:40:20 +00:00
|
|
|
enum mosquitto_protocol protocol;
|
2014-07-01 23:09:50 +00:00
|
|
|
bool use_username_as_clientid;
|
2014-05-07 22:27:00 +00:00
|
|
|
#ifdef WITH_TLS
|
|
|
|
char *cafile;
|
|
|
|
char *capath;
|
|
|
|
char *certfile;
|
|
|
|
char *keyfile;
|
|
|
|
char *ciphers;
|
|
|
|
char *psk_hint;
|
|
|
|
bool require_certificate;
|
|
|
|
SSL_CTX *ssl_ctx;
|
|
|
|
char *crlfile;
|
|
|
|
bool use_identity_as_username;
|
|
|
|
char *tls_version;
|
|
|
|
#endif
|
2014-05-18 21:40:20 +00:00
|
|
|
#ifdef WITH_WEBSOCKETS
|
|
|
|
struct libwebsocket_context *ws_context;
|
2014-09-08 17:21:53 +00:00
|
|
|
char *http_dir;
|
2014-09-17 20:50:08 +00:00
|
|
|
struct libwebsocket_protocols *ws_protocol;
|
2014-05-18 21:40:20 +00:00
|
|
|
#endif
|
2014-05-07 22:27:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct mqtt3_config {
|
|
|
|
char *config_file;
|
|
|
|
char *acl_file;
|
|
|
|
bool allow_anonymous;
|
|
|
|
bool allow_duplicate_messages;
|
|
|
|
bool allow_zero_length_clientid;
|
|
|
|
char *auto_id_prefix;
|
|
|
|
int auto_id_prefix_len;
|
|
|
|
int autosave_interval;
|
|
|
|
bool autosave_on_changes;
|
|
|
|
char *clientid_prefixes;
|
|
|
|
bool connection_messages;
|
|
|
|
bool daemon;
|
|
|
|
struct _mqtt3_listener default_listener;
|
|
|
|
struct _mqtt3_listener *listeners;
|
|
|
|
int listener_count;
|
|
|
|
int log_dest;
|
2014-11-02 21:49:33 +00:00
|
|
|
int log_facility;
|
2014-05-07 22:27:00 +00:00
|
|
|
int log_type;
|
|
|
|
bool log_timestamp;
|
|
|
|
char *log_file;
|
|
|
|
FILE *log_fptr;
|
2015-03-08 21:00:15 +00:00
|
|
|
uint32_t message_size_limit;
|
2014-05-07 22:27:00 +00:00
|
|
|
char *password_file;
|
|
|
|
bool persistence;
|
|
|
|
char *persistence_location;
|
|
|
|
char *persistence_file;
|
|
|
|
char *persistence_filepath;
|
|
|
|
time_t persistent_client_expiration;
|
|
|
|
char *pid_file;
|
|
|
|
char *psk_file;
|
|
|
|
bool queue_qos0_messages;
|
|
|
|
int retry_interval;
|
|
|
|
int sys_interval;
|
|
|
|
bool upgrade_outgoing_qos;
|
|
|
|
char *user;
|
|
|
|
bool verbose;
|
2015-02-13 22:57:49 +00:00
|
|
|
#ifdef WITH_WEBSOCKETS
|
|
|
|
int websockets_log_level;
|
2015-03-27 20:50:16 +00:00
|
|
|
bool have_websockets_listener;
|
2015-02-13 22:57:49 +00:00
|
|
|
#endif
|
2014-05-07 22:27:00 +00:00
|
|
|
#ifdef WITH_BRIDGE
|
|
|
|
struct _mqtt3_bridge *bridges;
|
|
|
|
int bridge_count;
|
|
|
|
#endif
|
|
|
|
char *auth_plugin;
|
|
|
|
struct mosquitto_auth_opt *auth_options;
|
|
|
|
int auth_option_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _mosquitto_subleaf {
|
|
|
|
struct _mosquitto_subleaf *prev;
|
|
|
|
struct _mosquitto_subleaf *next;
|
|
|
|
struct mosquitto *context;
|
|
|
|
int qos;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _mosquitto_subhier {
|
|
|
|
struct _mosquitto_subhier *children;
|
|
|
|
struct _mosquitto_subhier *next;
|
|
|
|
struct _mosquitto_subleaf *subs;
|
|
|
|
char *topic;
|
|
|
|
struct mosquitto_msg_store *retained;
|
|
|
|
};
|
|
|
|
|
2014-11-18 19:12:08 +00:00
|
|
|
struct mosquitto_msg_store_load{
|
2014-11-17 22:54:39 +00:00
|
|
|
UT_hash_handle hh;
|
2014-05-07 22:27:00 +00:00
|
|
|
dbid_t db_id;
|
2014-11-18 19:12:08 +00:00
|
|
|
struct mosquitto_msg_store *store;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mosquitto_msg_store{
|
|
|
|
struct mosquitto_msg_store *next;
|
|
|
|
struct mosquitto_msg_store *prev;
|
|
|
|
dbid_t db_id;
|
2014-05-07 22:27:00 +00:00
|
|
|
char *source_id;
|
|
|
|
char **dest_ids;
|
|
|
|
int dest_id_count;
|
2014-11-18 07:42:49 +00:00
|
|
|
int ref_count;
|
|
|
|
char *topic;
|
|
|
|
void *payload;
|
|
|
|
uint32_t payloadlen;
|
2014-05-07 22:27:00 +00:00
|
|
|
uint16_t source_mid;
|
2014-11-18 07:42:49 +00:00
|
|
|
uint16_t mid;
|
|
|
|
uint8_t qos;
|
|
|
|
bool retain;
|
2014-05-07 22:27:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct mosquitto_client_msg{
|
|
|
|
struct mosquitto_client_msg *next;
|
|
|
|
struct mosquitto_msg_store *store;
|
2014-11-18 07:42:49 +00:00
|
|
|
time_t timestamp;
|
2014-05-07 22:27:00 +00:00
|
|
|
uint16_t mid;
|
2014-11-18 07:42:49 +00:00
|
|
|
uint8_t qos;
|
2014-05-07 22:27:00 +00:00
|
|
|
bool retain;
|
|
|
|
enum mosquitto_msg_direction direction;
|
|
|
|
enum mosquitto_msg_state state;
|
|
|
|
bool dup;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _mosquitto_unpwd{
|
|
|
|
char *username;
|
|
|
|
char *password;
|
|
|
|
#ifdef WITH_TLS
|
|
|
|
unsigned int password_len;
|
|
|
|
unsigned int salt_len;
|
2014-11-18 07:42:49 +00:00
|
|
|
unsigned char *salt;
|
2014-05-07 22:27:00 +00:00
|
|
|
#endif
|
|
|
|
UT_hash_handle hh;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _mosquitto_acl{
|
|
|
|
struct _mosquitto_acl *next;
|
|
|
|
char *topic;
|
|
|
|
int access;
|
2014-05-08 22:03:15 +00:00
|
|
|
int ucount;
|
|
|
|
int ccount;
|
2014-05-07 22:27:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _mosquitto_acl_user{
|
|
|
|
struct _mosquitto_acl_user *next;
|
|
|
|
char *username;
|
|
|
|
struct _mosquitto_acl *acl;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _mosquitto_auth_plugin{
|
|
|
|
void *lib;
|
|
|
|
void *user_data;
|
|
|
|
int (*plugin_version)(void);
|
|
|
|
int (*plugin_init)(void **user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count);
|
|
|
|
int (*plugin_cleanup)(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count);
|
|
|
|
int (*security_init)(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload);
|
|
|
|
int (*security_cleanup)(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload);
|
|
|
|
int (*acl_check)(void *user_data, const char *clientid, const char *username, const char *topic, int access);
|
|
|
|
int (*unpwd_check)(void *user_data, const char *username, const char *password);
|
|
|
|
int (*psk_key_get)(void *user_data, const char *hint, const char *identity, char *key, int max_key_len);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mosquitto_db{
|
|
|
|
dbid_t last_db_id;
|
|
|
|
struct _mosquitto_subhier subs;
|
|
|
|
struct _mosquitto_unpwd *unpwd;
|
|
|
|
struct _mosquitto_acl_user *acl_list;
|
|
|
|
struct _mosquitto_acl *acl_patterns;
|
|
|
|
struct _mosquitto_unpwd *psk_id;
|
2014-06-23 16:57:35 +00:00
|
|
|
struct mosquitto *contexts_by_id;
|
|
|
|
struct mosquitto *contexts_by_sock;
|
|
|
|
struct mosquitto *contexts_for_free;
|
2014-11-18 23:34:54 +00:00
|
|
|
#ifdef WITH_BRIDGE
|
|
|
|
struct mosquitto **bridges;
|
|
|
|
#endif
|
2014-05-07 22:27:00 +00:00
|
|
|
struct _clientid_index_hash *clientid_index_hash;
|
|
|
|
struct mosquitto_msg_store *msg_store;
|
2014-11-18 19:12:08 +00:00
|
|
|
struct mosquitto_msg_store_load *msg_store_load;
|
2014-11-18 23:34:54 +00:00
|
|
|
#ifdef WITH_BRIDGE
|
|
|
|
int bridge_count;
|
|
|
|
#endif
|
2014-05-07 22:27:00 +00:00
|
|
|
int msg_store_count;
|
|
|
|
struct mqtt3_config *config;
|
|
|
|
int persistence_changes;
|
|
|
|
struct _mosquitto_auth_plugin auth_plugin;
|
2014-09-16 22:48:26 +00:00
|
|
|
#ifdef WITH_SYS_TREE
|
2014-05-07 22:27:00 +00:00
|
|
|
int subscription_count;
|
|
|
|
int retained_count;
|
2014-06-02 21:08:40 +00:00
|
|
|
#endif
|
2014-09-22 22:35:09 +00:00
|
|
|
struct mosquitto *ll_for_free;
|
2014-05-07 22:27:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum mqtt3_bridge_direction{
|
|
|
|
bd_out = 0,
|
|
|
|
bd_in = 1,
|
|
|
|
bd_both = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
enum mosquitto_bridge_start_type{
|
|
|
|
bst_automatic = 0,
|
|
|
|
bst_lazy = 1,
|
|
|
|
bst_manual = 2,
|
|
|
|
bst_once = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _mqtt3_bridge_topic{
|
|
|
|
char *topic;
|
|
|
|
int qos;
|
|
|
|
enum mqtt3_bridge_direction direction;
|
|
|
|
char *local_prefix;
|
|
|
|
char *remote_prefix;
|
|
|
|
char *local_topic; /* topic prefixed with local_prefix */
|
|
|
|
char *remote_topic; /* topic prefixed with remote_prefix */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bridge_address{
|
|
|
|
char *address;
|
|
|
|
int port;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _mqtt3_bridge{
|
|
|
|
char *name;
|
|
|
|
struct bridge_address *addresses;
|
|
|
|
int cur_address;
|
|
|
|
int address_count;
|
|
|
|
time_t primary_retry;
|
|
|
|
bool round_robin;
|
2014-11-18 07:42:49 +00:00
|
|
|
bool try_private;
|
|
|
|
bool try_private_accepted;
|
2014-05-07 22:27:00 +00:00
|
|
|
bool clean_session;
|
2014-11-18 07:42:49 +00:00
|
|
|
int keepalive;
|
2014-05-07 22:27:00 +00:00
|
|
|
struct _mqtt3_bridge_topic *topics;
|
|
|
|
int topic_count;
|
|
|
|
bool topic_remapping;
|
2015-01-27 17:12:36 +00:00
|
|
|
enum _mosquitto_protocol protocol_version;
|
2014-05-07 22:27:00 +00:00
|
|
|
time_t restart_t;
|
2014-08-16 20:31:12 +00:00
|
|
|
char *remote_clientid;
|
|
|
|
char *remote_username;
|
|
|
|
char *remote_password;
|
2014-06-10 22:30:15 +00:00
|
|
|
char *local_clientid;
|
2014-05-08 17:45:34 +00:00
|
|
|
char *local_username;
|
|
|
|
char *local_password;
|
2014-05-07 22:27:00 +00:00
|
|
|
bool notifications;
|
|
|
|
char *notification_topic;
|
|
|
|
enum mosquitto_bridge_start_type start_type;
|
|
|
|
int idle_timeout;
|
|
|
|
int restart_timeout;
|
|
|
|
int threshold;
|
|
|
|
bool lazy_reconnect;
|
2015-01-07 21:50:10 +00:00
|
|
|
bool attempt_unsubscribe;
|
2014-05-07 22:27:00 +00:00
|
|
|
#ifdef WITH_TLS
|
|
|
|
char *tls_cafile;
|
|
|
|
char *tls_capath;
|
|
|
|
char *tls_certfile;
|
|
|
|
char *tls_keyfile;
|
|
|
|
bool tls_insecure;
|
|
|
|
char *tls_version;
|
|
|
|
# ifdef REAL_WITH_TLS_PSK
|
|
|
|
char *tls_psk_identity;
|
|
|
|
char *tls_psk;
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2014-06-30 22:30:43 +00:00
|
|
|
#ifdef WITH_WEBSOCKETS
|
|
|
|
struct libws_mqtt_hack {
|
2014-09-08 17:21:53 +00:00
|
|
|
char *http_dir;
|
2014-06-30 22:30:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct libws_mqtt_data {
|
|
|
|
struct mosquitto *mosq;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2014-05-07 22:27:00 +00:00
|
|
|
#include <net_mosq.h>
|
|
|
|
|
|
|
|
/* ============================================================
|
|
|
|
* Main functions
|
|
|
|
* ============================================================ */
|
2015-03-29 09:43:08 +00:00
|
|
|
int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int listensock_count, int listener_max);
|
2014-05-07 22:27:00 +00:00
|
|
|
struct mosquitto_db *_mosquitto_get_db(void);
|
|
|
|
|
|
|
|
/* ============================================================
|
|
|
|
* Config functions
|
|
|
|
* ============================================================ */
|
|
|
|
/* Initialise config struct to default values. */
|
|
|
|
void mqtt3_config_init(struct mqtt3_config *config);
|
|
|
|
/* Parse command line options into config. */
|
|
|
|
int mqtt3_config_parse_args(struct mqtt3_config *config, int argc, char *argv[]);
|
|
|
|
/* Read configuration data from config->config_file into config.
|
|
|
|
* If reload is true, don't process config options that shouldn't be reloaded (listeners etc)
|
|
|
|
* Returns 0 on success, 1 if there is a configuration error or if a file cannot be opened.
|
|
|
|
*/
|
|
|
|
int mqtt3_config_read(struct mqtt3_config *config, bool reload);
|
|
|
|
/* Free all config data. */
|
|
|
|
void mqtt3_config_cleanup(struct mqtt3_config *config);
|
|
|
|
|
2015-02-08 22:06:11 +00:00
|
|
|
int drop_privileges(struct mqtt3_config *config, bool temporary);
|
|
|
|
int restore_privileges(void);
|
|
|
|
|
2014-05-07 22:27:00 +00:00
|
|
|
/* ============================================================
|
|
|
|
* Server send functions
|
|
|
|
* ============================================================ */
|
2014-05-31 14:20:40 +00:00
|
|
|
int _mosquitto_send_connack(struct mosquitto *context, int ack, int result);
|
2014-05-07 22:27:00 +00:00
|
|
|
int _mosquitto_send_suback(struct mosquitto *context, uint16_t mid, uint32_t payloadlen, const void *payload);
|
|
|
|
|
|
|
|
/* ============================================================
|
|
|
|
* Network functions
|
|
|
|
* ============================================================ */
|
2015-03-29 09:43:08 +00:00
|
|
|
int mqtt3_socket_accept(struct mosquitto_db *db, mosq_sock_t listensock);
|
2014-05-07 22:27:00 +00:00
|
|
|
int mqtt3_socket_listen(struct _mqtt3_listener *listener);
|
2015-03-29 09:43:08 +00:00
|
|
|
int _mosquitto_socket_get_address(mosq_sock_t sock, char *buf, int len);
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
/* ============================================================
|
|
|
|
* Read handling functions
|
|
|
|
* ============================================================ */
|
|
|
|
int mqtt3_packet_handle(struct mosquitto_db *db, struct mosquitto *context);
|
|
|
|
int mqtt3_handle_connack(struct mosquitto_db *db, struct mosquitto *context);
|
|
|
|
int mqtt3_handle_connect(struct mosquitto_db *db, struct mosquitto *context);
|
|
|
|
int mqtt3_handle_disconnect(struct mosquitto_db *db, struct mosquitto *context);
|
|
|
|
int mqtt3_handle_publish(struct mosquitto_db *db, struct mosquitto *context);
|
|
|
|
int mqtt3_handle_subscribe(struct mosquitto_db *db, struct mosquitto *context);
|
|
|
|
int mqtt3_handle_unsubscribe(struct mosquitto_db *db, struct mosquitto *context);
|
|
|
|
|
|
|
|
/* ============================================================
|
|
|
|
* Database handling
|
|
|
|
* ============================================================ */
|
|
|
|
int mqtt3_db_open(struct mqtt3_config *config, struct mosquitto_db *db);
|
|
|
|
int mqtt3_db_close(struct mosquitto_db *db);
|
|
|
|
#ifdef WITH_PERSISTENCE
|
2014-11-17 23:46:02 +00:00
|
|
|
int mqtt3_db_backup(struct mosquitto_db *db, bool shutdown);
|
2014-05-07 22:27:00 +00:00
|
|
|
int mqtt3_db_restore(struct mosquitto_db *db);
|
|
|
|
#endif
|
|
|
|
void mqtt3_db_limits_set(int inflight, int queued);
|
|
|
|
/* Return the number of in-flight messages in count. */
|
|
|
|
int mqtt3_db_message_count(int *count);
|
2014-11-17 23:46:02 +00:00
|
|
|
int mqtt3_db_message_delete(struct mosquitto_db *db, struct mosquitto *context, uint16_t mid, enum mosquitto_msg_direction dir);
|
2014-05-07 22:27:00 +00:00
|
|
|
int mqtt3_db_message_insert(struct mosquitto_db *db, struct mosquitto *context, uint16_t mid, enum mosquitto_msg_direction dir, int qos, bool retain, struct mosquitto_msg_store *stored);
|
|
|
|
int mqtt3_db_message_release(struct mosquitto_db *db, struct mosquitto *context, uint16_t mid, enum mosquitto_msg_direction dir);
|
|
|
|
int mqtt3_db_message_update(struct mosquitto *context, uint16_t mid, enum mosquitto_msg_direction dir, enum mosquitto_msg_state state);
|
2014-11-17 23:46:02 +00:00
|
|
|
int mqtt3_db_message_write(struct mosquitto_db *db, struct mosquitto *context);
|
|
|
|
int mqtt3_db_messages_delete(struct mosquitto_db *db, struct mosquitto *context);
|
2014-05-07 22:27:00 +00:00
|
|
|
int mqtt3_db_messages_easy_queue(struct mosquitto_db *db, struct mosquitto *context, const char *topic, int qos, uint32_t payloadlen, const void *payload, int retain);
|
2014-11-20 21:13:21 +00:00
|
|
|
int mqtt3_db_messages_queue(struct mosquitto_db *db, const char *source_id, const char *topic, int qos, int retain, struct mosquitto_msg_store **stored);
|
2014-05-07 22:27:00 +00:00
|
|
|
int mqtt3_db_message_store(struct mosquitto_db *db, const char *source, uint16_t source_mid, const char *topic, int qos, uint32_t payloadlen, const void *payload, int retain, struct mosquitto_msg_store **stored, dbid_t store_id);
|
|
|
|
int mqtt3_db_message_store_find(struct mosquitto *context, uint16_t mid, struct mosquitto_msg_store **stored);
|
2014-11-18 19:12:08 +00:00
|
|
|
void mosquitto__db_msg_store_add(struct mosquitto_db *db, struct mosquitto_msg_store *store);
|
|
|
|
void mosquitto__db_msg_store_remove(struct mosquitto_db *db, struct mosquitto_msg_store *store);
|
2014-11-19 20:59:10 +00:00
|
|
|
void mosquitto__db_msg_store_deref(struct mosquitto_db *db, struct mosquitto_msg_store **store);
|
2014-11-18 19:12:08 +00:00
|
|
|
void mosquitto__db_msg_store_clean(struct mosquitto_db *db);
|
2014-05-07 22:27:00 +00:00
|
|
|
/* Check all messages waiting on a client reply and resend if timeout has been exceeded. */
|
|
|
|
int mqtt3_db_message_timeout_check(struct mosquitto_db *db, unsigned int timeout);
|
2014-11-17 23:46:02 +00:00
|
|
|
int mqtt3_db_message_reconnect_reset(struct mosquitto_db *db, struct mosquitto *context);
|
2014-05-07 22:27:00 +00:00
|
|
|
int mqtt3_retain_queue(struct mosquitto_db *db, struct mosquitto *context, const char *sub, int sub_qos);
|
|
|
|
void mqtt3_db_sys_update(struct mosquitto_db *db, int interval, time_t start_time);
|
|
|
|
void mqtt3_db_vacuum(void);
|
|
|
|
|
|
|
|
/* ============================================================
|
|
|
|
* Subscription functions
|
|
|
|
* ============================================================ */
|
|
|
|
int mqtt3_sub_add(struct mosquitto_db *db, struct mosquitto *context, const char *sub, int qos, struct _mosquitto_subhier *root);
|
|
|
|
int mqtt3_sub_remove(struct mosquitto_db *db, struct mosquitto *context, const char *sub, struct _mosquitto_subhier *root);
|
|
|
|
int mqtt3_sub_search(struct mosquitto_db *db, struct _mosquitto_subhier *root, const char *source_id, const char *topic, int qos, int retain, struct mosquitto_msg_store *stored);
|
|
|
|
void mqtt3_sub_tree_print(struct _mosquitto_subhier *root, int level);
|
2014-10-09 22:28:16 +00:00
|
|
|
int mqtt3_subs_clean_session(struct mosquitto_db *db, struct mosquitto *context);
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
/* ============================================================
|
|
|
|
* Context functions
|
|
|
|
* ============================================================ */
|
2015-03-29 09:43:08 +00:00
|
|
|
struct mosquitto *mqtt3_context_init(struct mosquitto_db *db, mosq_sock_t sock);
|
2014-05-07 22:27:00 +00:00
|
|
|
void mqtt3_context_cleanup(struct mosquitto_db *db, struct mosquitto *context, bool do_free);
|
|
|
|
void mqtt3_context_disconnect(struct mosquitto_db *db, struct mosquitto *context);
|
2014-09-22 22:35:09 +00:00
|
|
|
void mosquitto__add_context_to_disused(struct mosquitto_db *db, struct mosquitto *context);
|
|
|
|
void mosquitto__free_disused_contexts(struct mosquitto_db *db);
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
/* ============================================================
|
|
|
|
* Logging functions
|
|
|
|
* ============================================================ */
|
2015-02-05 22:44:38 +00:00
|
|
|
int mqtt3_log_init(struct mqtt3_config *config);
|
|
|
|
int mqtt3_log_close(struct mqtt3_config *config);
|
2014-05-07 22:27:00 +00:00
|
|
|
int _mosquitto_log_printf(struct mosquitto *mosq, int level, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
|
|
|
|
|
|
|
|
/* ============================================================
|
|
|
|
* Bridge functions
|
|
|
|
* ============================================================ */
|
|
|
|
#ifdef WITH_BRIDGE
|
|
|
|
int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge);
|
|
|
|
int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context);
|
|
|
|
void mqtt3_bridge_packet_cleanup(struct mosquitto *context);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ============================================================
|
|
|
|
* Security related functions
|
|
|
|
* ============================================================ */
|
|
|
|
int mosquitto_security_module_init(struct mosquitto_db *db);
|
|
|
|
int mosquitto_security_module_cleanup(struct mosquitto_db *db);
|
|
|
|
|
|
|
|
int mosquitto_security_init(struct mosquitto_db *db, bool reload);
|
|
|
|
int mosquitto_security_apply(struct mosquitto_db *db);
|
|
|
|
int mosquitto_security_cleanup(struct mosquitto_db *db, bool reload);
|
|
|
|
int mosquitto_acl_check(struct mosquitto_db *db, struct mosquitto *context, const char *topic, int access);
|
|
|
|
int mosquitto_unpwd_check(struct mosquitto_db *db, const char *username, const char *password);
|
|
|
|
int mosquitto_psk_key_get(struct mosquitto_db *db, const char *hint, const char *identity, char *key, int max_key_len);
|
|
|
|
|
|
|
|
int mosquitto_security_init_default(struct mosquitto_db *db, bool reload);
|
|
|
|
int mosquitto_security_apply_default(struct mosquitto_db *db);
|
|
|
|
int mosquitto_security_cleanup_default(struct mosquitto_db *db, bool reload);
|
|
|
|
int mosquitto_acl_check_default(struct mosquitto_db *db, struct mosquitto *context, const char *topic, int access);
|
|
|
|
int mosquitto_unpwd_check_default(struct mosquitto_db *db, const char *username, const char *password);
|
|
|
|
int mosquitto_psk_key_get_default(struct mosquitto_db *db, const char *hint, const char *identity, char *key, int max_key_len);
|
|
|
|
|
|
|
|
/* ============================================================
|
|
|
|
* Window service related functions
|
|
|
|
* ============================================================ */
|
|
|
|
#if defined(WIN32) || defined(__CYGWIN__)
|
|
|
|
void service_install(void);
|
|
|
|
void service_uninstall(void);
|
|
|
|
void service_run(void);
|
|
|
|
#endif
|
|
|
|
|
2014-05-06 09:47:00 +00:00
|
|
|
/* ============================================================
|
|
|
|
* Websockets related functions
|
|
|
|
* ============================================================ */
|
|
|
|
#ifdef WITH_WEBSOCKETS
|
2015-02-13 22:57:49 +00:00
|
|
|
struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listener, int log_level);
|
2014-05-06 09:47:00 +00:00
|
|
|
#endif
|
2014-07-03 00:00:57 +00:00
|
|
|
void do_disconnect(struct mosquitto_db *db, struct mosquitto *context);
|
2014-05-06 09:47:00 +00:00
|
|
|
|
2014-05-07 22:27:00 +00:00
|
|
|
#endif
|