From 71ceb81f8fa9406f5de4cdbef4cecd5175ec0ce9 Mon Sep 17 00:00:00 2001 From: Younghyun Joo Date: Mon, 23 Feb 2015 18:38:23 +0900 Subject: [PATCH] [PPM] Set the Iotivity Code Format 1. Excute the format script Change-Id: I2aa09fcec6a4641dea44fbffbd6692e0deadf86a Signed-off-by: Younghyun Joo Reviewed-on: https://gerrit.iotivity.org/gerrit/397 Tested-by: jenkins-iotivity Reviewed-by: yunhee.hwang --- .../lib/cpluff/libcpluff/cpluffdef.h | 2 +- .../protocol-plugin/plugin-manager/src/Config.cpp | 2 +- .../protocol-plugin/plugin-manager/src/Plugin.h | 2 +- .../plugins/mqtt-fan/lib/cpp/mosquittopp.cpp | 549 +++++++-------- .../plugins/mqtt-fan/lib/cpp/mosquittopp.h | 143 ++-- .../plugins/mqtt-fan/lib/dummypthread.h | 4 +- .../plugins/mqtt-fan/lib/messages_mosq.h | 12 +- .../plugins/mqtt-fan/lib/mosquitto.h | 769 +++++++++++---------- .../plugins/mqtt-fan/lib/mosquitto_internal.h | 303 ++++---- .../plugins/mqtt-fan/lib/net_mosq.h | 6 +- .../plugins/mqtt-fan/lib/send_mosq.h | 12 +- .../plugins/mqtt-fan/lib/will_mosq.h | 3 +- .../plugins/mqtt-light/lib/cpp/mosquittopp.cpp | 549 +++++++-------- .../plugins/mqtt-light/lib/cpp/mosquittopp.h | 143 ++-- .../plugins/mqtt-light/lib/dummypthread.h | 4 +- .../plugins/mqtt-light/lib/messages_mosq.h | 12 +- .../plugins/mqtt-light/lib/mosquitto.h | 769 +++++++++++---------- .../plugins/mqtt-light/lib/mosquitto_internal.h | 303 ++++---- .../plugins/mqtt-light/lib/net_mosq.h | 6 +- .../plugins/mqtt-light/lib/send_mosq.h | 12 +- .../plugins/mqtt-light/lib/will_mosq.h | 3 +- 21 files changed, 1863 insertions(+), 1745 deletions(-) diff --git a/service/protocol-plugin/lib/cpluff/libcpluff/cpluffdef.h b/service/protocol-plugin/lib/cpluff/libcpluff/cpluffdef.h index c529386..b27b241 100644 --- a/service/protocol-plugin/lib/cpluff/libcpluff/cpluffdef.h +++ b/service/protocol-plugin/lib/cpluff/libcpluff/cpluffdef.h @@ -1,7 +1,7 @@ /*------------------------------------------------------------------------- * C-Pluff, a plug-in framework for C * Copyright 2007 Johannes Lehtinen - * + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation diff --git a/service/protocol-plugin/plugin-manager/src/Config.cpp b/service/protocol-plugin/plugin-manager/src/Config.cpp index d473421..b8c5941 100644 --- a/service/protocol-plugin/plugin-manager/src/Config.cpp +++ b/service/protocol-plugin/plugin-manager/src/Config.cpp @@ -51,7 +51,7 @@ PMRESULT Config::loadConfigFile(const std::string configfilepath) { // Read the xml file std::ifstream xmlFile(configfilepath.c_str()); - if(!xmlFile.good()) + if (!xmlFile.good()) { return PM_S_FALSE; } diff --git a/service/protocol-plugin/plugin-manager/src/Plugin.h b/service/protocol-plugin/plugin-manager/src/Plugin.h index d360cf0..4b5fd22 100644 --- a/service/protocol-plugin/plugin-manager/src/Plugin.h +++ b/service/protocol-plugin/plugin-manager/src/Plugin.h @@ -128,7 +128,7 @@ namespace OIC private: friend class CpluffAdapter; friend class FelixAdapter; - /** + /** * Set key, value. key is attribute name. * * @param key is atrribute name. diff --git a/service/protocol-plugin/plugins/mqtt-fan/lib/cpp/mosquittopp.cpp b/service/protocol-plugin/plugins/mqtt-fan/lib/cpp/mosquittopp.cpp index fa4e436..dafb375 100644 --- a/service/protocol-plugin/plugins/mqtt-fan/lib/cpp/mosquittopp.cpp +++ b/service/protocol-plugin/plugins/mqtt-fan/lib/cpp/mosquittopp.cpp @@ -31,275 +31,284 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -namespace mosqpp { - -static void on_connect_wrapper(struct mosquitto *mosq, void *userdata, int rc) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_connect(rc); -} - -static void on_disconnect_wrapper(struct mosquitto *mosq, void *userdata, int rc) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_disconnect(rc); -} - -static void on_publish_wrapper(struct mosquitto *mosq, void *userdata, int mid) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_publish(mid); -} - -static void on_message_wrapper(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_message(message); -} - -static void on_subscribe_wrapper(struct mosquitto *mosq, void *userdata, int mid, int qos_count, const int *granted_qos) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_subscribe(mid, qos_count, granted_qos); -} - -static void on_unsubscribe_wrapper(struct mosquitto *mosq, void *userdata, int mid) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_unsubscribe(mid); -} - - -static void on_log_wrapper(struct mosquitto *mosq, void *userdata, int level, const char *str) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_log(level, str); -} - -int lib_version(int *major, int *minor, int *revision) -{ - if(major) *major = LIBMOSQUITTO_MAJOR; - if(minor) *minor = LIBMOSQUITTO_MINOR; - if(revision) *revision = LIBMOSQUITTO_REVISION; - return LIBMOSQUITTO_VERSION_NUMBER; -} - -int lib_init() -{ - return mosquitto_lib_init(); -} - -int lib_cleanup() -{ - return mosquitto_lib_cleanup(); -} - -const char* strerror(int mosq_errno) -{ - return mosquitto_strerror(mosq_errno); -} - -const char* connack_string(int connack_code) -{ - return mosquitto_connack_string(connack_code); -} - -int sub_topic_tokenise(const char *subtopic, char ***topics, int *count) -{ - return mosquitto_sub_topic_tokenise(subtopic, topics, count); -} - -int sub_topic_tokens_free(char ***topics, int count) -{ - return mosquitto_sub_topic_tokens_free(topics, count); -} - -int topic_matches_sub(const char *sub, const char *topic, bool *result) -{ - return mosquitto_topic_matches_sub(sub, topic, result); -} - -mosquittopp::mosquittopp(const char *id, bool clean_session) -{ - m_mosq = mosquitto_new(id, clean_session, this); - mosquitto_connect_callback_set(m_mosq, on_connect_wrapper); - mosquitto_disconnect_callback_set(m_mosq, on_disconnect_wrapper); - mosquitto_publish_callback_set(m_mosq, on_publish_wrapper); - mosquitto_message_callback_set(m_mosq, on_message_wrapper); - mosquitto_subscribe_callback_set(m_mosq, on_subscribe_wrapper); - mosquitto_unsubscribe_callback_set(m_mosq, on_unsubscribe_wrapper); - mosquitto_log_callback_set(m_mosq, on_log_wrapper); -} - -mosquittopp::~mosquittopp() -{ - mosquitto_destroy(m_mosq); -} - -int mosquittopp::reinitialise(const char *id, bool clean_session) -{ - int rc; - rc = mosquitto_reinitialise(m_mosq, id, clean_session, this); - if(rc == MOSQ_ERR_SUCCESS){ - mosquitto_connect_callback_set(m_mosq, on_connect_wrapper); - mosquitto_disconnect_callback_set(m_mosq, on_disconnect_wrapper); - mosquitto_publish_callback_set(m_mosq, on_publish_wrapper); - mosquitto_message_callback_set(m_mosq, on_message_wrapper); - mosquitto_subscribe_callback_set(m_mosq, on_subscribe_wrapper); - mosquitto_unsubscribe_callback_set(m_mosq, on_unsubscribe_wrapper); - mosquitto_log_callback_set(m_mosq, on_log_wrapper); - } - return rc; -} - -int mosquittopp::connect(const char *host, int port, int keepalive) -{ - return mosquitto_connect(m_mosq, host, port, keepalive); -} - -int mosquittopp::connect(const char *host, int port, int keepalive, const char *bind_address) -{ - return mosquitto_connect_bind(m_mosq, host, port, keepalive, bind_address); -} - -int mosquittopp::connect_async(const char *host, int port, int keepalive) -{ - return mosquitto_connect_async(m_mosq, host, port, keepalive); -} - -int mosquittopp::connect_async(const char *host, int port, int keepalive, const char *bind_address) -{ - return mosquitto_connect_bind_async(m_mosq, host, port, keepalive, bind_address); -} - -int mosquittopp::reconnect() -{ - return mosquitto_reconnect(m_mosq); -} - -int mosquittopp::reconnect_async() -{ - return mosquitto_reconnect_async(m_mosq); -} - -int mosquittopp::disconnect() -{ - return mosquitto_disconnect(m_mosq); -} - -int mosquittopp::socket() -{ - return mosquitto_socket(m_mosq); -} - -int mosquittopp::will_set(const char *topic, int payloadlen, const void *payload, int qos, bool retain) -{ - return mosquitto_will_set(m_mosq, topic, payloadlen, payload, qos, retain); -} - -int mosquittopp::will_clear() -{ - return mosquitto_will_clear(m_mosq); -} - -int mosquittopp::username_pw_set(const char *username, const char *password) -{ - return mosquitto_username_pw_set(m_mosq, username, password); -} - -int mosquittopp::publish(int *mid, const char *topic, int payloadlen, const void *payload, int qos, bool retain) -{ - return mosquitto_publish(m_mosq, mid, topic, payloadlen, payload, qos, retain); -} - -void mosquittopp::reconnect_delay_set(unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff) -{ - mosquitto_reconnect_delay_set(m_mosq, reconnect_delay, reconnect_delay_max, reconnect_exponential_backoff); -} - -int mosquittopp::max_inflight_messages_set(unsigned int max_inflight_messages) -{ - return mosquitto_max_inflight_messages_set(m_mosq, max_inflight_messages); -} - -void mosquittopp::message_retry_set(unsigned int message_retry) -{ - mosquitto_message_retry_set(m_mosq, message_retry); -} - -int mosquittopp::subscribe(int *mid, const char *sub, int qos) -{ - return mosquitto_subscribe(m_mosq, mid, sub, qos); -} - -int mosquittopp::unsubscribe(int *mid, const char *sub) -{ - return mosquitto_unsubscribe(m_mosq, mid, sub); -} - -int mosquittopp::loop(int timeout, int max_packets) -{ - return mosquitto_loop(m_mosq, timeout, max_packets); -} - -int mosquittopp::loop_misc() -{ - return mosquitto_loop_misc(m_mosq); -} - -int mosquittopp::loop_read(int max_packets) -{ - return mosquitto_loop_read(m_mosq, max_packets); -} - -int mosquittopp::loop_write(int max_packets) -{ - return mosquitto_loop_write(m_mosq, max_packets); -} - -int mosquittopp::loop_forever(int timeout, int max_packets) -{ - return mosquitto_loop_forever(m_mosq, timeout, max_packets); -} - -int mosquittopp::loop_start() -{ - return mosquitto_loop_start(m_mosq); -} - -int mosquittopp::loop_stop(bool force) -{ - return mosquitto_loop_stop(m_mosq, force); -} - -bool mosquittopp::want_write() -{ - return mosquitto_want_write(m_mosq); -} - -void mosquittopp::user_data_set(void *userdata) -{ - mosquitto_user_data_set(m_mosq, userdata); -} - -int mosquittopp::tls_set(const char *cafile, const char *capath, const char *certfile, const char *keyfile, int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)) -{ - return mosquitto_tls_set(m_mosq, cafile, capath, certfile, keyfile, pw_callback); -} - -int mosquittopp::tls_opts_set(int cert_reqs, const char *tls_version, const char *ciphers) -{ - return mosquitto_tls_opts_set(m_mosq, cert_reqs, tls_version, ciphers); -} - -int mosquittopp::tls_insecure_set(bool value) -{ - return mosquitto_tls_insecure_set(m_mosq, value); -} - -int mosquittopp::tls_psk_set(const char *psk, const char *identity, const char *ciphers) -{ - return mosquitto_tls_psk_set(m_mosq, psk, identity, ciphers); -} +namespace mosqpp +{ + + static void on_connect_wrapper(struct mosquitto *mosq, void *userdata, int rc) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_connect(rc); + } + + static void on_disconnect_wrapper(struct mosquitto *mosq, void *userdata, int rc) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_disconnect(rc); + } + + static void on_publish_wrapper(struct mosquitto *mosq, void *userdata, int mid) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_publish(mid); + } + + static void on_message_wrapper(struct mosquitto *mosq, void *userdata, + const struct mosquitto_message *message) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_message(message); + } + + static void on_subscribe_wrapper(struct mosquitto *mosq, void *userdata, int mid, int qos_count, + const int *granted_qos) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_subscribe(mid, qos_count, granted_qos); + } + + static void on_unsubscribe_wrapper(struct mosquitto *mosq, void *userdata, int mid) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_unsubscribe(mid); + } + + + static void on_log_wrapper(struct mosquitto *mosq, void *userdata, int level, const char *str) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_log(level, str); + } + + int lib_version(int *major, int *minor, int *revision) + { + if (major) *major = LIBMOSQUITTO_MAJOR; + if (minor) *minor = LIBMOSQUITTO_MINOR; + if (revision) *revision = LIBMOSQUITTO_REVISION; + return LIBMOSQUITTO_VERSION_NUMBER; + } + + int lib_init() + { + return mosquitto_lib_init(); + } + + int lib_cleanup() + { + return mosquitto_lib_cleanup(); + } + + const char *strerror(int mosq_errno) + { + return mosquitto_strerror(mosq_errno); + } + + const char *connack_string(int connack_code) + { + return mosquitto_connack_string(connack_code); + } + + int sub_topic_tokenise(const char *subtopic, char ***topics, int *count) + { + return mosquitto_sub_topic_tokenise(subtopic, topics, count); + } + + int sub_topic_tokens_free(char ***topics, int count) + { + return mosquitto_sub_topic_tokens_free(topics, count); + } + + int topic_matches_sub(const char *sub, const char *topic, bool *result) + { + return mosquitto_topic_matches_sub(sub, topic, result); + } + + mosquittopp::mosquittopp(const char *id, bool clean_session) + { + m_mosq = mosquitto_new(id, clean_session, this); + mosquitto_connect_callback_set(m_mosq, on_connect_wrapper); + mosquitto_disconnect_callback_set(m_mosq, on_disconnect_wrapper); + mosquitto_publish_callback_set(m_mosq, on_publish_wrapper); + mosquitto_message_callback_set(m_mosq, on_message_wrapper); + mosquitto_subscribe_callback_set(m_mosq, on_subscribe_wrapper); + mosquitto_unsubscribe_callback_set(m_mosq, on_unsubscribe_wrapper); + mosquitto_log_callback_set(m_mosq, on_log_wrapper); + } + + mosquittopp::~mosquittopp() + { + mosquitto_destroy(m_mosq); + } + + int mosquittopp::reinitialise(const char *id, bool clean_session) + { + int rc; + rc = mosquitto_reinitialise(m_mosq, id, clean_session, this); + if (rc == MOSQ_ERR_SUCCESS) + { + mosquitto_connect_callback_set(m_mosq, on_connect_wrapper); + mosquitto_disconnect_callback_set(m_mosq, on_disconnect_wrapper); + mosquitto_publish_callback_set(m_mosq, on_publish_wrapper); + mosquitto_message_callback_set(m_mosq, on_message_wrapper); + mosquitto_subscribe_callback_set(m_mosq, on_subscribe_wrapper); + mosquitto_unsubscribe_callback_set(m_mosq, on_unsubscribe_wrapper); + mosquitto_log_callback_set(m_mosq, on_log_wrapper); + } + return rc; + } + + int mosquittopp::connect(const char *host, int port, int keepalive) + { + return mosquitto_connect(m_mosq, host, port, keepalive); + } + + int mosquittopp::connect(const char *host, int port, int keepalive, const char *bind_address) + { + return mosquitto_connect_bind(m_mosq, host, port, keepalive, bind_address); + } + + int mosquittopp::connect_async(const char *host, int port, int keepalive) + { + return mosquitto_connect_async(m_mosq, host, port, keepalive); + } + + int mosquittopp::connect_async(const char *host, int port, int keepalive, const char *bind_address) + { + return mosquitto_connect_bind_async(m_mosq, host, port, keepalive, bind_address); + } + + int mosquittopp::reconnect() + { + return mosquitto_reconnect(m_mosq); + } + + int mosquittopp::reconnect_async() + { + return mosquitto_reconnect_async(m_mosq); + } + + int mosquittopp::disconnect() + { + return mosquitto_disconnect(m_mosq); + } + + int mosquittopp::socket() + { + return mosquitto_socket(m_mosq); + } + + int mosquittopp::will_set(const char *topic, int payloadlen, const void *payload, int qos, + bool retain) + { + return mosquitto_will_set(m_mosq, topic, payloadlen, payload, qos, retain); + } + + int mosquittopp::will_clear() + { + return mosquitto_will_clear(m_mosq); + } + + int mosquittopp::username_pw_set(const char *username, const char *password) + { + return mosquitto_username_pw_set(m_mosq, username, password); + } + + int mosquittopp::publish(int *mid, const char *topic, int payloadlen, const void *payload, int qos, + bool retain) + { + return mosquitto_publish(m_mosq, mid, topic, payloadlen, payload, qos, retain); + } + + void mosquittopp::reconnect_delay_set(unsigned int reconnect_delay, + unsigned int reconnect_delay_max, bool reconnect_exponential_backoff) + { + mosquitto_reconnect_delay_set(m_mosq, reconnect_delay, reconnect_delay_max, + reconnect_exponential_backoff); + } + + int mosquittopp::max_inflight_messages_set(unsigned int max_inflight_messages) + { + return mosquitto_max_inflight_messages_set(m_mosq, max_inflight_messages); + } + + void mosquittopp::message_retry_set(unsigned int message_retry) + { + mosquitto_message_retry_set(m_mosq, message_retry); + } + + int mosquittopp::subscribe(int *mid, const char *sub, int qos) + { + return mosquitto_subscribe(m_mosq, mid, sub, qos); + } + + int mosquittopp::unsubscribe(int *mid, const char *sub) + { + return mosquitto_unsubscribe(m_mosq, mid, sub); + } + + int mosquittopp::loop(int timeout, int max_packets) + { + return mosquitto_loop(m_mosq, timeout, max_packets); + } + + int mosquittopp::loop_misc() + { + return mosquitto_loop_misc(m_mosq); + } + + int mosquittopp::loop_read(int max_packets) + { + return mosquitto_loop_read(m_mosq, max_packets); + } + + int mosquittopp::loop_write(int max_packets) + { + return mosquitto_loop_write(m_mosq, max_packets); + } + + int mosquittopp::loop_forever(int timeout, int max_packets) + { + return mosquitto_loop_forever(m_mosq, timeout, max_packets); + } + + int mosquittopp::loop_start() + { + return mosquitto_loop_start(m_mosq); + } + + int mosquittopp::loop_stop(bool force) + { + return mosquitto_loop_stop(m_mosq, force); + } + + bool mosquittopp::want_write() + { + return mosquitto_want_write(m_mosq); + } + + void mosquittopp::user_data_set(void *userdata) + { + mosquitto_user_data_set(m_mosq, userdata); + } + + int mosquittopp::tls_set(const char *cafile, const char *capath, const char *certfile, + const char *keyfile, int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)) + { + return mosquitto_tls_set(m_mosq, cafile, capath, certfile, keyfile, pw_callback); + } + + int mosquittopp::tls_opts_set(int cert_reqs, const char *tls_version, const char *ciphers) + { + return mosquitto_tls_opts_set(m_mosq, cert_reqs, tls_version, ciphers); + } + + int mosquittopp::tls_insecure_set(bool value) + { + return mosquitto_tls_insecure_set(m_mosq, value); + } + + int mosquittopp::tls_psk_set(const char *psk, const char *identity, const char *ciphers) + { + return mosquitto_tls_psk_set(m_mosq, psk, identity, ciphers); + } } diff --git a/service/protocol-plugin/plugins/mqtt-fan/lib/cpp/mosquittopp.h b/service/protocol-plugin/plugins/mqtt-fan/lib/cpp/mosquittopp.h index 41537b6..8e3cabf 100644 --- a/service/protocol-plugin/plugins/mqtt-fan/lib/cpp/mosquittopp.h +++ b/service/protocol-plugin/plugins/mqtt-fan/lib/cpp/mosquittopp.h @@ -38,85 +38,92 @@ This product includes software written by Tim Hudson (tjh@cryptsoft.com) #define _MOSQUITTOPP_H_ #ifdef _WIN32 -# ifdef mosquittopp_EXPORTS -# define mosqpp_EXPORT __declspec(dllexport) -# else -# define mosqpp_EXPORT __declspec(dllimport) -# endif +# ifdef mosquittopp_EXPORTS +# define mosqpp_EXPORT __declspec(dllexport) +# else +# define mosqpp_EXPORT __declspec(dllimport) +# endif #else -# define mosqpp_EXPORT +# define mosqpp_EXPORT #endif #include #include #include "../mosquitto.h" -namespace mosqpp { +namespace mosqpp +{ -mosqpp_EXPORT const char *strerror(int mosq_errno); -mosqpp_EXPORT const char *connack_string(int connack_code); -mosqpp_EXPORT int sub_topic_tokenise(const char *subtopic, char ***topics, int *count); -mosqpp_EXPORT int sub_topic_tokens_free(char ***topics, int count); -mosqpp_EXPORT int lib_version(int *major, int *minor, int *revision); -mosqpp_EXPORT int lib_init(); -mosqpp_EXPORT int lib_cleanup(); -mosqpp_EXPORT int topic_matches_sub(const char *sub, const char *topic, bool *result); + mosqpp_EXPORT const char *strerror(int mosq_errno); + mosqpp_EXPORT const char *connack_string(int connack_code); + mosqpp_EXPORT int sub_topic_tokenise(const char *subtopic, char ***topics, int *count); + mosqpp_EXPORT int sub_topic_tokens_free(char ***topics, int count); + mosqpp_EXPORT int lib_version(int *major, int *minor, int *revision); + mosqpp_EXPORT int lib_init(); + mosqpp_EXPORT int lib_cleanup(); + mosqpp_EXPORT int topic_matches_sub(const char *sub, const char *topic, bool *result); -/* - * Class: mosquittopp - * - * A mosquitto client class. This is a C++ wrapper class for the mosquitto C - * library. Please see mosquitto.h for details of the functions. - */ -class mosqpp_EXPORT mosquittopp { - private: - struct mosquitto *m_mosq; - public: - mosquittopp(const char *id=NULL, bool clean_session=true); - ~mosquittopp(); + /* + * Class: mosquittopp + * + * A mosquitto client class. This is a C++ wrapper class for the mosquitto C + * library. Please see mosquitto.h for details of the functions. + */ + class mosqpp_EXPORT mosquittopp + { + private: + struct mosquitto *m_mosq; + public: + mosquittopp(const char *id = NULL, bool clean_session = true); + ~mosquittopp(); + + int reinitialise(const char *id, bool clean_session); + int socket(); + int will_set(const char *topic, int payloadlen = 0, const void *payload = NULL, int qos = 0, + bool retain = false); + int will_clear(); + int username_pw_set(const char *username, const char *password = NULL); + int connect(const char *host, int port = 1883, int keepalive = 60); + int connect_async(const char *host, int port = 1883, int keepalive = 60); + int connect(const char *host, int port, int keepalive, const char *bind_address); + int connect_async(const char *host, int port, int keepalive, const char *bind_address); + int reconnect(); + int reconnect_async(); + int disconnect(); + int publish(int *mid, const char *topic, int payloadlen = 0, const void *payload = NULL, + int qos = 0, bool retain = false); + int subscribe(int *mid, const char *sub, int qos = 0); + int unsubscribe(int *mid, const char *sub); + void reconnect_delay_set(unsigned int reconnect_delay, unsigned int reconnect_delay_max, + bool reconnect_exponential_backoff); + int max_inflight_messages_set(unsigned int max_inflight_messages); + void message_retry_set(unsigned int message_retry); + void user_data_set(void *userdata); + int tls_set(const char *cafile, const char *capath = NULL, const char *certfile = NULL, + const char *keyfile = NULL, int (*pw_callback)(char *buf, int size, int rwflag, + void *userdata) = NULL); + int tls_opts_set(int cert_reqs, const char *tls_version = NULL, const char *ciphers = NULL); + int tls_insecure_set(bool value); + int tls_psk_set(const char *psk, const char *identity, const char *ciphers = NULL); - int reinitialise(const char *id, bool clean_session); - int socket(); - int will_set(const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); - int will_clear(); - int username_pw_set(const char *username, const char *password=NULL); - int connect(const char *host, int port=1883, int keepalive=60); - int connect_async(const char *host, int port=1883, int keepalive=60); - int connect(const char *host, int port, int keepalive, const char *bind_address); - int connect_async(const char *host, int port, int keepalive, const char *bind_address); - int reconnect(); - int reconnect_async(); - int disconnect(); - int publish(int *mid, const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); - int subscribe(int *mid, const char *sub, int qos=0); - int unsubscribe(int *mid, const char *sub); - void reconnect_delay_set(unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff); - int max_inflight_messages_set(unsigned int max_inflight_messages); - void message_retry_set(unsigned int message_retry); - void user_data_set(void *userdata); - int tls_set(const char *cafile, const char *capath=NULL, const char *certfile=NULL, const char *keyfile=NULL, int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)=NULL); - int tls_opts_set(int cert_reqs, const char *tls_version=NULL, const char *ciphers=NULL); - int tls_insecure_set(bool value); - int tls_psk_set(const char *psk, const char *identity, const char *ciphers=NULL); + int loop(int timeout = -1, int max_packets = 1); + int loop_misc(); + int loop_read(int max_packets = 1); + int loop_write(int max_packets = 1); + int loop_forever(int timeout = -1, int max_packets = 1); + int loop_start(); + int loop_stop(bool force = false); + bool want_write(); - int loop(int timeout=-1, int max_packets=1); - int loop_misc(); - int loop_read(int max_packets=1); - int loop_write(int max_packets=1); - int loop_forever(int timeout=-1, int max_packets=1); - int loop_start(); - int loop_stop(bool force=false); - bool want_write(); - - virtual void on_connect(int rc) {return;}; - virtual void on_disconnect(int rc) {return;}; - virtual void on_publish(int mid) {return;}; - virtual void on_message(const struct mosquitto_message *message) {return;}; - virtual void on_subscribe(int mid, int qos_count, const int *granted_qos) {return;}; - virtual void on_unsubscribe(int mid) {return;}; - virtual void on_log(int level, const char *str) {return;}; - virtual void on_error() {return;}; -}; + virtual void on_connect(int rc) {return;}; + virtual void on_disconnect(int rc) {return;}; + virtual void on_publish(int mid) {return;}; + virtual void on_message(const struct mosquitto_message *message) {return;}; + virtual void on_subscribe(int mid, int qos_count, const int *granted_qos) {return;}; + virtual void on_unsubscribe(int mid) {return;}; + virtual void on_log(int level, const char *str) {return;}; + virtual void on_error() {return;}; + }; } #endif diff --git a/service/protocol-plugin/plugins/mqtt-fan/lib/dummypthread.h b/service/protocol-plugin/plugins/mqtt-fan/lib/dummypthread.h index 31f3251..e71f525 100644 --- a/service/protocol-plugin/plugins/mqtt-fan/lib/dummypthread.h +++ b/service/protocol-plugin/plugins/mqtt-fan/lib/dummypthread.h @@ -7,7 +7,7 @@ #define pthread_mutex_init(A, B) #define pthread_mutex_destroy(A) -#define pthread_mutex_lock(A) -#define pthread_mutex_unlock(A) +#define pthread_mutex_lock(A) +#define pthread_mutex_unlock(A) #endif diff --git a/service/protocol-plugin/plugins/mqtt-fan/lib/messages_mosq.h b/service/protocol-plugin/plugins/mqtt-fan/lib/messages_mosq.h index b9d0c8e..eebea23 100644 --- a/service/protocol-plugin/plugins/mqtt-fan/lib/messages_mosq.h +++ b/service/protocol-plugin/plugins/mqtt-fan/lib/messages_mosq.h @@ -34,11 +34,15 @@ POSSIBILITY OF SUCH DAMAGE. void _mosquitto_message_cleanup_all(struct mosquitto *mosq); void _mosquitto_message_cleanup(struct mosquitto_message_all **message); -int _mosquitto_message_delete(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir); -void _mosquitto_message_queue(struct mosquitto *mosq, struct mosquitto_message_all *message, enum mosquitto_msg_direction dir); +int _mosquitto_message_delete(struct mosquitto *mosq, uint16_t mid, + enum mosquitto_msg_direction dir); +void _mosquitto_message_queue(struct mosquitto *mosq, struct mosquitto_message_all *message, + enum mosquitto_msg_direction dir); void _mosquitto_messages_reconnect_reset(struct mosquitto *mosq); -int _mosquitto_message_remove(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir, struct mosquitto_message_all **message); +int _mosquitto_message_remove(struct mosquitto *mosq, uint16_t mid, + enum mosquitto_msg_direction dir, struct mosquitto_message_all **message); void _mosquitto_message_retry_check(struct mosquitto *mosq); -int _mosquitto_message_out_update(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_state state); +int _mosquitto_message_out_update(struct mosquitto *mosq, uint16_t mid, + enum mosquitto_msg_state state); #endif diff --git a/service/protocol-plugin/plugins/mqtt-fan/lib/mosquitto.h b/service/protocol-plugin/plugins/mqtt-fan/lib/mosquitto.h index 27506eb..ca3bf12 100644 --- a/service/protocol-plugin/plugins/mqtt-fan/lib/mosquitto.h +++ b/service/protocol-plugin/plugins/mqtt-fan/lib/mosquitto.h @@ -42,25 +42,25 @@ extern "C" { #endif #if defined(WIN32) && !defined(WITH_BROKER) -# ifdef libmosquitto_EXPORTS -# define libmosq_EXPORT __declspec(dllexport) -# else -# define libmosq_EXPORT __declspec(dllimport) -# endif +# ifdef libmosquitto_EXPORTS +# define libmosq_EXPORT __declspec(dllexport) +# else +# define libmosq_EXPORT __declspec(dllimport) +# endif #else -# define libmosq_EXPORT +# define libmosq_EXPORT #endif #ifdef WIN32 -# ifndef __cplusplus -# define bool char -# define true 1 -# define false 0 -# endif +# ifndef __cplusplus +# define bool char +# define true 1 +# define false 0 +# endif #else -# ifndef __cplusplus -# include -# endif +# ifndef __cplusplus +# include +# endif #endif #define LIBMOSQUITTO_MAJOR 1 @@ -81,48 +81,50 @@ extern "C" { #define MOSQ_LOG_ALL 0xFFFF /* Error values */ -enum mosq_err_t { - MOSQ_ERR_CONN_PENDING = -1, - MOSQ_ERR_SUCCESS = 0, - MOSQ_ERR_NOMEM = 1, - MOSQ_ERR_PROTOCOL = 2, - MOSQ_ERR_INVAL = 3, - MOSQ_ERR_NO_CONN = 4, - MOSQ_ERR_CONN_REFUSED = 5, - MOSQ_ERR_NOT_FOUND = 6, - MOSQ_ERR_CONN_LOST = 7, - MOSQ_ERR_TLS = 8, - MOSQ_ERR_PAYLOAD_SIZE = 9, - MOSQ_ERR_NOT_SUPPORTED = 10, - MOSQ_ERR_AUTH = 11, - MOSQ_ERR_ACL_DENIED = 12, - MOSQ_ERR_UNKNOWN = 13, - MOSQ_ERR_ERRNO = 14, - MOSQ_ERR_EAI = 15 +enum mosq_err_t +{ + MOSQ_ERR_CONN_PENDING = -1, + MOSQ_ERR_SUCCESS = 0, + MOSQ_ERR_NOMEM = 1, + MOSQ_ERR_PROTOCOL = 2, + MOSQ_ERR_INVAL = 3, + MOSQ_ERR_NO_CONN = 4, + MOSQ_ERR_CONN_REFUSED = 5, + MOSQ_ERR_NOT_FOUND = 6, + MOSQ_ERR_CONN_LOST = 7, + MOSQ_ERR_TLS = 8, + MOSQ_ERR_PAYLOAD_SIZE = 9, + MOSQ_ERR_NOT_SUPPORTED = 10, + MOSQ_ERR_AUTH = 11, + MOSQ_ERR_ACL_DENIED = 12, + MOSQ_ERR_UNKNOWN = 13, + MOSQ_ERR_ERRNO = 14, + MOSQ_ERR_EAI = 15 }; /* MQTT specification restricts client ids to a maximum of 23 characters */ #define MOSQ_MQTT_ID_MAX_LENGTH 23 -struct mosquitto_message{ - int mid; - char *topic; - void *payload; - int payloadlen; - int qos; - bool retain; +struct mosquitto_message +{ + int mid; + char *topic; + void *payload; + int payloadlen; + int qos; + bool retain; }; struct mosquitto; /* * Topic: Threads - * libmosquitto provides thread safe operation, with the exception of - * which is not thread safe. + * libmosquitto provides thread safe operation, with the exception of + * which is not thread safe. */ /*************************************************** * Important note - * + * * The following functions that deal with network operations will return * MOSQ_ERR_SUCCESS on success, but this does not mean that the operation has * taken place. An attempt will be made to write the network data, but if the @@ -157,10 +159,10 @@ struct mosquitto; * be returned in this variable. * * Returns: - * LIBMOSQUITTO_VERSION_NUMBER, which is a unique number based on the major, - * minor and revision values. + * LIBMOSQUITTO_VERSION_NUMBER, which is a unique number based on the major, + * minor and revision values. * See Also: - * , + * , */ libmosq_EXPORT int mosquitto_lib_version(int *major, int *minor, int *revision); @@ -172,10 +174,10 @@ libmosq_EXPORT int mosquitto_lib_version(int *major, int *minor, int *revision); * This function is *not* thread safe. * * Returns: - * MOSQ_ERR_SUCCESS - always + * MOSQ_ERR_SUCCESS - always * * See Also: - * , + * , */ libmosq_EXPORT int mosquitto_lib_init(void); @@ -185,10 +187,10 @@ libmosq_EXPORT int mosquitto_lib_init(void); * Call to free resources associated with the library. * * Returns: - * MOSQ_ERR_SUCCESS - always + * MOSQ_ERR_SUCCESS - always * * See Also: - * , + * , */ libmosq_EXPORT int mosquitto_lib_cleanup(void); @@ -198,9 +200,9 @@ libmosq_EXPORT int mosquitto_lib_cleanup(void); * Create a new mosquitto client instance. * * Parameters: - * id - String to use as the client id. If NULL, a random client id - * will be generated. If id is NULL, clean_session must be true. - * clean_session - set to true to instruct the broker to clean all messages + * id - String to use as the client id. If NULL, a random client id + * will be generated. If id is NULL, clean_session must be true. + * clean_session - set to true to instruct the broker to clean all messages * and subscriptions on disconnect, false to instruct it to * keep them. See the man page mqtt(7) for more details. * Note that a client will never discard its own outgoing @@ -209,30 +211,30 @@ libmosq_EXPORT int mosquitto_lib_cleanup(void); * Use to reset a client to its * original state. * Must be set to true if the id parameter is NULL. - * obj - A user pointer that will be passed as an argument to any + * obj - A user pointer that will be passed as an argument to any * callbacks that are specified. * * Returns: - * Pointer to a struct mosquitto on success. - * NULL on failure. Interrogate errno to determine the cause for the failure: + * Pointer to a struct mosquitto on success. + * NULL on failure. Interrogate errno to determine the cause for the failure: * - ENOMEM on out of memory. * - EINVAL on invalid input parameters. * * See Also: - * , , + * , , */ libmosq_EXPORT struct mosquitto *mosquitto_new(const char *id, bool clean_session, void *obj); -/* +/* * Function: mosquitto_destroy * * Use to free memory associated with a mosquitto client instance. * * Parameters: - * mosq - a struct mosquitto pointer to free. + * mosq - a struct mosquitto pointer to free. * * See Also: - * , + * , */ libmosq_EXPORT void mosquitto_destroy(struct mosquitto *mosq); @@ -245,63 +247,65 @@ libmosq_EXPORT void mosquitto_destroy(struct mosquitto *mosq); * same as the output of . * * Parameters: - * mosq - a valid mosquitto instance. - * id - string to use as the client id. If NULL, a random client id - * will be generated. If id is NULL, clean_session must be true. - * clean_session - set to true to instruct the broker to clean all messages + * mosq - a valid mosquitto instance. + * id - string to use as the client id. If NULL, a random client id + * will be generated. If id is NULL, clean_session must be true. + * clean_session - set to true to instruct the broker to clean all messages * and subscriptions on disconnect, false to instruct it to * keep them. See the man page mqtt(7) for more details. * Must be set to true if the id parameter is NULL. - * obj - A user pointer that will be passed as an argument to any + * obj - A user pointer that will be passed as an argument to any * callbacks that are specified. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * See Also: - * , + * , */ -libmosq_EXPORT int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_session, void *obj); +libmosq_EXPORT int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, + bool clean_session, void *obj); -/* +/* * Function: mosquitto_will_set * * Configure will information for a mosquitto instance. By default, clients do * not have a will. This must be called before calling . * * Parameters: - * mosq - a valid mosquitto instance. - * topic - the topic on which to publish the will. - * payloadlen - the size of the payload (bytes). Valid values are between 0 and + * mosq - a valid mosquitto instance. + * topic - the topic on which to publish the will. + * payloadlen - the size of the payload (bytes). Valid values are between 0 and * 268,435,455. - * payload - pointer to the data to send. If payloadlen > 0 this must be a + * payload - pointer to the data to send. If payloadlen > 0 this must be a * valid memory location. - * qos - integer value 0, 1 or 2 indicating the Quality of Service to be + * qos - integer value 0, 1 or 2 indicating the Quality of Service to be * used for the will. - * retain - set to true to make the will a retained message. + * retain - set to true to make the will a retained message. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large. */ -libmosq_EXPORT int mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain); +libmosq_EXPORT int mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, + const void *payload, int qos, bool retain); -/* +/* * Function: mosquitto_will_clear * * Remove a previously configured will. This must be called before calling * . * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. */ libmosq_EXPORT int mosquitto_will_clear(struct mosquitto *mosq); @@ -317,18 +321,19 @@ libmosq_EXPORT int mosquitto_will_clear(struct mosquitto *mosq); * This is must be called before calling . * * Parameters: - * mosq - a valid mosquitto instance. - * username - the username to send as a string, or NULL to disable + * mosq - a valid mosquitto instance. + * username - the username to send as a string, or NULL to disable * authentication. - * password - the password to send as a string. Set to NULL when username is - * valid in order to send just a username. + * password - the password to send as a string. Set to NULL when username is + * valid in order to send just a username. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. */ -libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char *username, const char *password); +libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char *username, + const char *password); /* * Function: mosquitto_connect @@ -336,55 +341,57 @@ libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char * Connect to an MQTT broker. * * Parameters: - * mosq - a valid mosquitto instance. - * host - the hostname or ip address of the broker to connect to. - * port - the network port to connect to. Usually 1883. - * keepalive - the number of seconds after which the broker should send a PING + * mosq - a valid mosquitto instance. + * host - the hostname or ip address of the broker to connect to. + * port - the network port to connect to. Usually 1883. + * keepalive - the number of seconds after which the broker should send a PING * message to the client if no other messages have been exchanged * in that time. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , , , + * , , , , */ -libmosq_EXPORT int mosquitto_connect(struct mosquitto *mosq, const char *host, int port, int keepalive); +libmosq_EXPORT int mosquitto_connect(struct mosquitto *mosq, const char *host, int port, + int keepalive); /* * Function: mosquitto_connect_bind * * Connect to an MQTT broker. This extends the functionality of * by adding the bind_address parameter. Use this function - * if you need to restrict network communication over a particular interface. + * if you need to restrict network communication over a particular interface. * * Parameters: - * mosq - a valid mosquitto instance. - * host - the hostname or ip address of the broker to connect to. - * port - the network port to connect to. Usually 1883. - * keepalive - the number of seconds after which the broker should send a PING + * mosq - a valid mosquitto instance. + * host - the hostname or ip address of the broker to connect to. + * port - the network port to connect to. Usually 1883. + * keepalive - the number of seconds after which the broker should send a PING * message to the client if no other messages have been exchanged * in that time. * bind_address - the hostname or ip address of the local network interface to * bind to. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , + * , , */ -libmosq_EXPORT int mosquitto_connect_bind(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address); +libmosq_EXPORT int mosquitto_connect_bind(struct mosquitto *mosq, const char *host, int port, + int keepalive, const char *bind_address); /* * Function: mosquitto_connect_async @@ -397,25 +404,26 @@ libmosq_EXPORT int mosquitto_connect_bind(struct mosquitto *mosq, const char *ho * May be called before or after . * * Parameters: - * mosq - a valid mosquitto instance. - * host - the hostname or ip address of the broker to connect to. - * port - the network port to connect to. Usually 1883. - * keepalive - the number of seconds after which the broker should send a PING + * mosq - a valid mosquitto instance. + * host - the hostname or ip address of the broker to connect to. + * port - the network port to connect to. Usually 1883. + * keepalive - the number of seconds after which the broker should send a PING * message to the client if no other messages have been exchanged * in that time. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , , , + * , , , , */ -libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *host, int port, int keepalive); +libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *host, int port, + int keepalive); /* * Function: mosquitto_connect_async @@ -427,32 +435,33 @@ libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *h * * This extends the functionality of by adding the * bind_address parameter. Use this function if you need to restrict network - * communication over a particular interface. + * communication over a particular interface. * * May be called before or after . * * Parameters: - * mosq - a valid mosquitto instance. - * host - the hostname or ip address of the broker to connect to. - * port - the network port to connect to. Usually 1883. - * keepalive - the number of seconds after which the broker should send a PING + * mosq - a valid mosquitto instance. + * host - the hostname or ip address of the broker to connect to. + * port - the network port to connect to. Usually 1883. + * keepalive - the number of seconds after which the broker should send a PING * message to the client if no other messages have been exchanged * in that time. * bind_address - the hostname or ip address of the local network interface to * bind to. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , + * , , */ -libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address); +libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int port, + int keepalive, const char *bind_address); /* * Function: mosquitto_connect_srv @@ -464,31 +473,32 @@ libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const ch * * This extends the functionality of by adding the * bind_address parameter. Use this function if you need to restrict network - * communication over a particular interface. + * communication over a particular interface. * * May be called before or after . * * Parameters: - * mosq - a valid mosquitto instance. - * host - the hostname or ip address of the broker to connect to. - * keepalive - the number of seconds after which the broker should send a PING + * mosq - a valid mosquitto instance. + * host - the hostname or ip address of the broker to connect to. + * keepalive - the number of seconds after which the broker should send a PING * message to the client if no other messages have been exchanged * in that time. * bind_address - the hostname or ip address of the local network interface to * bind to. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , + * , , */ -libmosq_EXPORT int mosquitto_connect_srv(struct mosquitto *mosq, const char *host, int keepalive, const char *bind_address); +libmosq_EXPORT int mosquitto_connect_srv(struct mosquitto *mosq, const char *host, int keepalive, + const char *bind_address); /* * Function: mosquitto_reconnect @@ -499,25 +509,25 @@ libmosq_EXPORT int mosquitto_connect_srv(struct mosquitto *mosq, const char *hos * connection has been lost. It uses the values that were provided in the * call. It must not be called before * . - * + * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , + * , , */ libmosq_EXPORT int mosquitto_reconnect(struct mosquitto *mosq); @@ -530,25 +540,25 @@ libmosq_EXPORT int mosquitto_reconnect(struct mosquitto *mosq); * connection has been lost. It uses the values that were provided in the * or calls. It must not be * called before . - * + * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , + * , */ libmosq_EXPORT int mosquitto_reconnect_async(struct mosquitto *mosq); @@ -558,50 +568,51 @@ libmosq_EXPORT int mosquitto_reconnect_async(struct mosquitto *mosq); * Disconnect from the broker. * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. */ libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq); -/* +/* * Function: mosquitto_publish * * Publish a message on a given topic. - * + * * Parameters: - * mosq - a valid mosquitto instance. - * mid - pointer to an int. If not NULL, the function will set this + * mosq - a valid mosquitto instance. + * mid - pointer to an int. If not NULL, the function will set this * to the message id of this particular message. This can be then * used with the publish callback to determine when the message * has been sent. * Note that although the MQTT protocol doesn't use message ids * for messages with QoS=0, libmosquitto assigns them message ids * so they can be tracked with this parameter. - * payloadlen - the size of the payload (bytes). Valid values are between 0 and + * payloadlen - the size of the payload (bytes). Valid values are between 0 and * 268,435,455. - * payload - pointer to the data to send. If payloadlen > 0 this must be a + * payload - pointer to the data to send. If payloadlen > 0 this must be a * valid memory location. - * qos - integer value 0, 1 or 2 indicating the Quality of Service to be + * qos - integer value 0, 1 or 2 indicating the Quality of Service to be * used for the message. - * retain - set to true to make the message retained. + * retain - set to true to make the message retained. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. - * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the * broker. - * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large. + * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large. * - * See Also: - * + * See Also: + * */ -libmosq_EXPORT int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int payloadlen, const void *payload, int qos, bool retain); +libmosq_EXPORT int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, + int payloadlen, const void *payload, int qos, bool retain); /* * Function: mosquitto_subscribe @@ -609,19 +620,19 @@ libmosq_EXPORT int mosquitto_publish(struct mosquitto *mosq, int *mid, const cha * Subscribe to a topic. * * Parameters: - * mosq - a valid mosquitto instance. - * mid - a pointer to an int. If not NULL, the function will set this to - * the message id of this particular message. This can be then used - * with the subscribe callback to determine when the message has been - * sent. - * sub - the subscription pattern. - * qos - the requested Quality of Service for this subscription. + * mosq - a valid mosquitto instance. + * mid - a pointer to an int. If not NULL, the function will set this to + * the message id of this particular message. This can be then used + * with the subscribe callback to determine when the message has been + * sent. + * sub - the subscription pattern. + * qos - the requested Quality of Service for this subscription. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. */ libmosq_EXPORT int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const char *sub, int qos); @@ -631,18 +642,18 @@ libmosq_EXPORT int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const c * Unsubscribe from a topic. * * Parameters: - * mosq - a valid mosquitto instance. - * mid - a pointer to an int. If not NULL, the function will set this to - * the message id of this particular message. This can be then used - * with the unsubscribe callback to determine when the message has been - * sent. - * sub - the unsubscription pattern. + * mosq - a valid mosquitto instance. + * mid - a pointer to an int. If not NULL, the function will set this to + * the message id of this particular message. This can be then used + * with the unsubscribe callback to determine when the message has been + * sent. + * sub - the unsubscription pattern. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. */ libmosq_EXPORT int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub); @@ -653,29 +664,30 @@ libmosq_EXPORT int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const * Useful for preserving a message received in the on_message() callback. * * Parameters: - * dst - a pointer to a valid mosquitto_message struct to copy to. - * src - a pointer to a valid mosquitto_message struct to copy from. + * dst - a pointer to a valid mosquitto_message struct to copy to. + * src - a pointer to a valid mosquitto_message struct to copy from. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * See Also: - * + * */ -libmosq_EXPORT int mosquitto_message_copy(struct mosquitto_message *dst, const struct mosquitto_message *src); +libmosq_EXPORT int mosquitto_message_copy(struct mosquitto_message *dst, + const struct mosquitto_message *src); /* * Function: mosquitto_message_free - * + * * Completely free a mosquitto_message struct. * * Parameters: - * message - pointer to a mosquitto_message pointer to free. + * message - pointer to a mosquitto_message pointer to free. * * See Also: - * + * */ libmosq_EXPORT void mosquitto_message_free(struct mosquitto_message **message); @@ -699,29 +711,29 @@ libmosq_EXPORT void mosquitto_message_free(struct mosquitto_message **message); * . * * Threads: - * + * * Parameters: - * mosq - a valid mosquitto instance. - * timeout - Maximum number of milliseconds to wait for network activity - * in the select() call before timing out. Set to 0 for instant - * return. Set negative to use the default of 1000ms. - * max_packets - this parameter is currently unused and should be set to 1 for - * future compatibility. - * + * mosq - a valid mosquitto instance. + * timeout - Maximum number of milliseconds to wait for network activity + * in the select() call before timing out. Set to 0 for instant + * return. Set negative to use the default of 1000ms. + * max_packets - this parameter is currently unused and should be set to 1 for + * future compatibility. + * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost. - * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the + * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the * broker. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * See Also: - * , , + * , , */ libmosq_EXPORT int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets); @@ -737,27 +749,27 @@ libmosq_EXPORT int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_p * * Parameters: * mosq - a valid mosquitto instance. - * timeout - Maximum number of milliseconds to wait for network activity - * in the select() call before timing out. Set to 0 for instant - * return. Set negative to use the default of 1000ms. - * max_packets - this parameter is currently unused and should be set to 1 for - * future compatibility. + * timeout - Maximum number of milliseconds to wait for network activity + * in the select() call before timing out. Set to 0 for instant + * return. Set negative to use the default of 1000ms. + * max_packets - this parameter is currently unused and should be set to 1 for + * future compatibility. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost. - * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the + * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the * broker. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , + * , */ libmosq_EXPORT int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets); @@ -772,12 +784,12 @@ libmosq_EXPORT int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, i * mosq - a valid mosquitto instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOT_SUPPORTED - if thread support is not available. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOT_SUPPORTED - if thread support is not available. * * See Also: - * , , , + * , , , */ libmosq_EXPORT int mosquitto_loop_start(struct mosquitto *mosq); @@ -792,16 +804,16 @@ libmosq_EXPORT int mosquitto_loop_start(struct mosquitto *mosq); * * Parameters: * mosq - a valid mosquitto instance. - * force - set to true to force thread cancellation. If false, - * must have already been called. + * force - set to true to force thread cancellation. If false, + * must have already been called. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOT_SUPPORTED - if thread support is not available. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOT_SUPPORTED - if thread support is not available. * * See Also: - * , + * , */ libmosq_EXPORT int mosquitto_loop_stop(struct mosquitto *mosq, bool force); @@ -812,10 +824,10 @@ libmosq_EXPORT int mosquitto_loop_stop(struct mosquitto *mosq, bool force); * include a mosquitto client in your own select() calls. * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * Returns: - * The socket for the mosquitto client or -1 on failure. + * The socket for the mosquitto client or -1 on failure. */ libmosq_EXPORT int mosquitto_socket(struct mosquitto *mosq); @@ -827,25 +839,25 @@ libmosq_EXPORT int mosquitto_socket(struct mosquitto *mosq); * monitoring the client network socket for activity yourself. * * Parameters: - * mosq - a valid mosquitto instance. - * max_packets - this parameter is currently unused and should be set to 1 for - * future compatibility. + * mosq - a valid mosquitto instance. + * max_packets - this parameter is currently unused and should be set to 1 for + * future compatibility. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost. - * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the + * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the * broker. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , + * , , */ libmosq_EXPORT int mosquitto_loop_read(struct mosquitto *mosq, int max_packets); @@ -857,25 +869,25 @@ libmosq_EXPORT int mosquitto_loop_read(struct mosquitto *mosq, int max_packets); * monitoring the client network socket for activity yourself. * * Parameters: - * mosq - a valid mosquitto instance. - * max_packets - this parameter is currently unused and should be set to 1 for - * future compatibility. + * mosq - a valid mosquitto instance. + * max_packets - this parameter is currently unused and should be set to 1 for + * future compatibility. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost. - * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the + * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the * broker. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , , + * , , , */ libmosq_EXPORT int mosquitto_loop_write(struct mosquitto *mosq, int max_packets); @@ -890,15 +902,15 @@ libmosq_EXPORT int mosquitto_loop_write(struct mosquitto *mosq, int max_packets) * to be retried, so should be called fairly frequently. * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. * * See Also: - * , , + * , , */ libmosq_EXPORT int mosquitto_loop_misc(struct mosquitto *mosq); @@ -908,10 +920,10 @@ libmosq_EXPORT int mosquitto_loop_misc(struct mosquitto *mosq); * Returns true if there is data ready to be written on the socket. * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * See Also: - * , , + * , , */ libmosq_EXPORT bool mosquitto_want_write(struct mosquitto *mosq); @@ -954,17 +966,17 @@ libmosq_EXPORT bool mosquitto_want_write(struct mosquitto *mosq); * instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * See Also: - * , , + * , , */ libmosq_EXPORT int mosquitto_tls_set(struct mosquitto *mosq, - const char *cafile, const char *capath, - const char *certfile, const char *keyfile, - int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)); + const char *cafile, const char *capath, + const char *certfile, const char *keyfile, + int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)); /* * Function: mosquitto_tls_insecure_set @@ -985,11 +997,11 @@ libmosq_EXPORT int mosquitto_tls_set(struct mosquitto *mosq, * the connection is insecure. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. * * See Also: - * + * */ libmosq_EXPORT int mosquitto_tls_insecure_set(struct mosquitto *mosq, bool value); @@ -1000,32 +1012,33 @@ libmosq_EXPORT int mosquitto_tls_insecure_set(struct mosquitto *mosq, bool value * * Parameters: * mosq - a valid mosquitto instance. - * cert_reqs - an integer defining the verification requirements the client - * will impose on the server. This can be one of: - * * SSL_VERIFY_NONE (0): the server will not be verified in any way. - * * SSL_VERIFY_PEER (1): the server certificate will be verified - * and the connection aborted if the verification fails. - * The default and recommended value is SSL_VERIFY_PEER. Using - * SSL_VERIFY_NONE provides no security. - * tls_version - the version of the SSL/TLS protocol to use as a string. If NULL, - * the default value is used. The default value and the - * available values depend on the version of openssl that the - * library was compiled against. For openssl >= 1.0.1, the - * available options are tlsv1.2, tlsv1.1 and tlsv1, with tlv1.2 - * as the default. For openssl < 1.0.1, only tlsv1 is available. - * ciphers - a string describing the ciphers available for use. See the - * "openssl ciphers" tool for more information. If NULL, the - * default ciphers will be used. + * cert_reqs - an integer defining the verification requirements the client + * will impose on the server. This can be one of: + * * SSL_VERIFY_NONE (0): the server will not be verified in any way. + * * SSL_VERIFY_PEER (1): the server certificate will be verified + * and the connection aborted if the verification fails. + * The default and recommended value is SSL_VERIFY_PEER. Using + * SSL_VERIFY_NONE provides no security. + * tls_version - the version of the SSL/TLS protocol to use as a string. If NULL, + * the default value is used. The default value and the + * available values depend on the version of openssl that the + * library was compiled against. For openssl >= 1.0.1, the + * available options are tlsv1.2, tlsv1.1 and tlsv1, with tlv1.2 + * as the default. For openssl < 1.0.1, only tlsv1 is available. + * ciphers - a string describing the ciphers available for use. See the + * "openssl ciphers" tool for more information. If NULL, the + * default ciphers will be used. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * See Also: - * + * */ -libmosq_EXPORT int mosquitto_tls_opts_set(struct mosquitto *mosq, int cert_reqs, const char *tls_version, const char *ciphers); +libmosq_EXPORT int mosquitto_tls_opts_set(struct mosquitto *mosq, int cert_reqs, + const char *tls_version, const char *ciphers); /* * Function: mosquitto_tls_psk_set @@ -1040,21 +1053,22 @@ libmosq_EXPORT int mosquitto_tls_opts_set(struct mosquitto *mosq, int cert_reqs, * psk - the pre-shared-key in hex format with no leading "0x". * identity - the identity of this client. May be used as the username * depending on the server settings. - * ciphers - a string describing the PSK ciphers available for use. See the - * "openssl ciphers" tool for more information. If NULL, the - * default ciphers will be used. + * ciphers - a string describing the PSK ciphers available for use. See the + * "openssl ciphers" tool for more information. If NULL, the + * default ciphers will be used. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * See Also: - * + * */ -libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk, const char *identity, const char *ciphers); +libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk, + const char *identity, const char *ciphers); -/* +/* * Function: mosquitto_connect_callback_set * * Set the connect callback. This is called when the broker sends a CONNACK @@ -1076,14 +1090,15 @@ libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk * * 3 - connection refused (broker unavailable) * * 4-255 - reserved for future use */ -libmosq_EXPORT void mosquitto_connect_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int)); - +libmosq_EXPORT void mosquitto_connect_callback_set(struct mosquitto *mosq, + void (*on_connect)(struct mosquitto *, void *, int)); + /* * Function: mosquitto_disconnect_callback_set * * Set the disconnect callback. This is called when the broker has received the * DISCONNECT command and has disconnected the client. - * + * * Parameters: * mosq - a valid mosquitto instance. * on_disconnect - a callback function in the following form: @@ -1096,14 +1111,15 @@ libmosq_EXPORT void mosquitto_connect_callback_set(struct mosquitto *mosq, void * means the client has called . Any other value * indicates that the disconnect is unexpected. */ -libmosq_EXPORT void mosquitto_disconnect_callback_set(struct mosquitto *mosq, void (*on_disconnect)(struct mosquitto *, void *, int)); - +libmosq_EXPORT void mosquitto_disconnect_callback_set(struct mosquitto *mosq, + void (*on_disconnect)(struct mosquitto *, void *, int)); + /* * Function: mosquitto_publish_callback_set * * Set the publish callback. This is called when a message initiated with * has been sent to the broker successfully. - * + * * Parameters: * mosq - a valid mosquitto instance. * on_publish - a callback function in the following form: @@ -1114,14 +1130,15 @@ libmosq_EXPORT void mosquitto_disconnect_callback_set(struct mosquitto *mosq, vo * obj - the user data provided in * mid - the message id of the sent message. */ -libmosq_EXPORT void mosquitto_publish_callback_set(struct mosquitto *mosq, void (*on_publish)(struct mosquitto *, void *, int)); +libmosq_EXPORT void mosquitto_publish_callback_set(struct mosquitto *mosq, + void (*on_publish)(struct mosquitto *, void *, int)); /* * Function: mosquitto_message_callback_set * * Set the message callback. This is called when a message is received from the * broker. - * + * * Parameters: * mosq - a valid mosquitto instance. * on_message - a callback function in the following form: @@ -1135,16 +1152,17 @@ libmosq_EXPORT void mosquitto_publish_callback_set(struct mosquitto *mosq, void * should make copies of any of the data it requires. * * See Also: - * + * */ -libmosq_EXPORT void mosquitto_message_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *)); +libmosq_EXPORT void mosquitto_message_callback_set(struct mosquitto *mosq, + void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *)); /* * Function: mosquitto_subscribe_callback_set * * Set the subscribe callback. This is called when the broker responds to a * subscription request. - * + * * Parameters: * mosq - a valid mosquitto instance. * on_subscribe - a callback function in the following form: @@ -1158,14 +1176,15 @@ libmosq_EXPORT void mosquitto_message_callback_set(struct mosquitto *mosq, void * granted_qos - an array of integers indicating the granted QoS for each of * the subscriptions. */ -libmosq_EXPORT void mosquitto_subscribe_callback_set(struct mosquitto *mosq, void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *)); +libmosq_EXPORT void mosquitto_subscribe_callback_set(struct mosquitto *mosq, + void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *)); /* * Function: mosquitto_unsubscribe_callback_set * * Set the unsubscribe callback. This is called when the broker responds to a * unsubscription request. - * + * * Parameters: * mosq - a valid mosquitto instance. * on_unsubscribe - a callback function in the following form: @@ -1176,7 +1195,8 @@ libmosq_EXPORT void mosquitto_subscribe_callback_set(struct mosquitto *mosq, voi * obj - the user data provided in * mid - the message id of the unsubscribe message. */ -libmosq_EXPORT void mosquitto_unsubscribe_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int)); +libmosq_EXPORT void mosquitto_unsubscribe_callback_set(struct mosquitto *mosq, + void (*on_unsubscribe)(struct mosquitto *, void *, int)); /* * Function: mosquitto_log_callback_set @@ -1192,14 +1212,15 @@ libmosq_EXPORT void mosquitto_unsubscribe_callback_set(struct mosquitto *mosq, v * mosq - the mosquitto instance making the callback. * obj - the user data provided in * level - the log message level from the values: - * MOSQ_LOG_INFO - * MOSQ_LOG_NOTICE - * MOSQ_LOG_WARNING - * MOSQ_LOG_ERR - * MOSQ_LOG_DEBUG - * str - the message string. + * MOSQ_LOG_INFO + * MOSQ_LOG_NOTICE + * MOSQ_LOG_WARNING + * MOSQ_LOG_ERR + * MOSQ_LOG_DEBUG + * str - the message string. */ -libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on_log)(struct mosquitto *, void *, int, const char *)); +libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, + void (*on_log)(struct mosquitto *, void *, int, const char *)); /* * Function: mosquitto_reconnect_delay_set @@ -1215,12 +1236,12 @@ libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on * set an upper bound on the delay with reconnect_delay_max. * * Example 1: - * delay=2, delay_max=10, exponential_backoff=False - * Delays would be: 2, 4, 6, 8, 10, 10, ... + * delay=2, delay_max=10, exponential_backoff=False + * Delays would be: 2, 4, 6, 8, 10, 10, ... * * Example 2: - * delay=3, delay_max=30, exponential_backoff=True - * Delays would be: 3, 6, 12, 24, 30, 30, ... + * delay=3, delay_max=30, exponential_backoff=True + * Delays would be: 3, 6, 12, 24, 30, 30, ... * * Parameters: * mosq - a valid mosquitto instance. @@ -1233,10 +1254,11 @@ libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on * exponential backoff. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. */ -libmosq_EXPORT int mosquitto_reconnect_delay_set(struct mosquitto *mosq, unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff); +libmosq_EXPORT int mosquitto_reconnect_delay_set(struct mosquitto *mosq, + unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff); /* * Function: mosquitto_max_inflight_messages_set @@ -1258,17 +1280,18 @@ libmosq_EXPORT int mosquitto_reconnect_delay_set(struct mosquitto *mosq, unsigne * to 20. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. */ -libmosq_EXPORT int mosquitto_max_inflight_messages_set(struct mosquitto *mosq, unsigned int max_inflight_messages); +libmosq_EXPORT int mosquitto_max_inflight_messages_set(struct mosquitto *mosq, + unsigned int max_inflight_messages); /* * Function: mosquitto_message_retry_set * * Set the number of seconds to wait before retrying messages. This applies to * publish messages with QoS>0. May be called at any time. - * + * * Parameters: * mosq - a valid mosquitto instance. * message_retry - the number of seconds to wait for a response before @@ -1287,8 +1310,8 @@ libmosq_EXPORT void mosquitto_message_retry_set(struct mosquitto *mosq, unsigned * * Parameters: * mosq - a valid mosquitto instance. - * obj - A user pointer that will be passed as an argument to any callbacks - * that are specified. + * obj - A user pointer that will be passed as an argument to any callbacks + * that are specified. */ libmosq_EXPORT void mosquitto_user_data_set(struct mosquitto *mosq, void *obj); @@ -1306,10 +1329,10 @@ libmosq_EXPORT void mosquitto_user_data_set(struct mosquitto *mosq, void *obj); * Call to obtain a const string description of a mosquitto error number. * * Parameters: - * mosq_errno - a mosquitto error number. + * mosq_errno - a mosquitto error number. * * Returns: - * A constant string describing the error. + * A constant string describing the error. */ libmosq_EXPORT const char *mosquitto_strerror(int mosq_errno); @@ -1319,10 +1342,10 @@ libmosq_EXPORT const char *mosquitto_strerror(int mosq_errno); * Call to obtain a const string description of an MQTT connection result. * * Parameters: - * connack_code - an MQTT connection result. + * connack_code - an MQTT connection result. * * Returns: - * A constant string describing the result. + * A constant string describing the result. */ libmosq_EXPORT const char *mosquitto_connack_string(int connack_code); @@ -1356,20 +1379,20 @@ libmosq_EXPORT const char *mosquitto_connack_string(int connack_code); * topics[4] = "hierarchy" * * Parameters: - * subtopic - the subscription/topic to tokenise - * topics - a pointer to store the array of strings - * count - an int pointer to store the number of items in the topics array. + * subtopic - the subscription/topic to tokenise + * topics - a pointer to store the array of strings + * count - an int pointer to store the number of items in the topics array. * * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * Example: * * > char **topics; * > int topic_count; * > int i; - * > + * > * > mosquitto_sub_topic_tokenise("$SYS/broker/uptime", &topics, &topic_count); * > * > for(i=0; i } * * See Also: - * + * */ libmosq_EXPORT int mosquitto_sub_topic_tokenise(const char *subtopic, char ***topics, int *count); @@ -1387,15 +1410,15 @@ libmosq_EXPORT int mosquitto_sub_topic_tokenise(const char *subtopic, char ***to * Free memory that was allocated in . * * Parameters: - * topics - pointer to string array. - * count - count of items in string array. + * topics - pointer to string array. + * count - count of items in string array. * * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if the input parameters were invalid. * * See Also: - * + * */ libmosq_EXPORT int mosquitto_sub_topic_tokens_free(char ***topics, int count); @@ -1410,15 +1433,15 @@ libmosq_EXPORT int mosquitto_sub_topic_tokens_free(char ***topics, int count); * non/matching would not match the subscription non/+/+ * * Parameters: - * sub - subscription string to check topic against. - * topic - topic to check. - * result - bool pointer to hold result. Will be set to true if the topic - * matches the subscription. + * sub - subscription string to check topic against. + * topic - topic to check. + * result - bool pointer to hold result. Will be set to true if the topic + * matches the subscription. * * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. */ libmosq_EXPORT int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result); diff --git a/service/protocol-plugin/plugins/mqtt-fan/lib/mosquitto_internal.h b/service/protocol-plugin/plugins/mqtt-fan/lib/mosquitto_internal.h index f3d5fde..523b1d9 100644 --- a/service/protocol-plugin/plugins/mqtt-fan/lib/mosquitto_internal.h +++ b/service/protocol-plugin/plugins/mqtt-fan/lib/mosquitto_internal.h @@ -52,16 +52,16 @@ POSSIBILITY OF SUCH DAMAGE. #endif #ifdef WIN32 -# 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 -# endif +# 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 +# endif #else -# include +# include #endif #include "mosquitto.h" @@ -70,172 +70,181 @@ POSSIBILITY OF SUCH DAMAGE. struct mosquitto_client_msg; #endif -enum mosquitto_msg_direction { - mosq_md_in = 0, - mosq_md_out = 1 +enum mosquitto_msg_direction +{ + mosq_md_in = 0, + mosq_md_out = 1 }; -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, - mosq_ms_queued = 11 +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, + mosq_ms_queued = 11 }; -enum mosquitto_client_state { - mosq_cs_new = 0, - mosq_cs_connected = 1, - mosq_cs_disconnecting = 2, - mosq_cs_connect_async = 3, - mosq_cs_connect_pending = 4, - mosq_cs_connect_srv = 5 +enum mosquitto_client_state +{ + mosq_cs_new = 0, + mosq_cs_connected = 1, + mosq_cs_disconnecting = 2, + mosq_cs_connect_async = 3, + mosq_cs_connect_pending = 4, + mosq_cs_connect_srv = 5 }; -enum _mosquitto_protocol { - mosq_p_invalid = 0, - mosq_p_mqtt31 = 1, - mosq_p_mqtt311 = 2, - mosq_p_mqtts = 3 +enum _mosquitto_protocol +{ + mosq_p_invalid = 0, + mosq_p_mqtt31 = 1, + mosq_p_mqtt311 = 2, + mosq_p_mqtts = 3 }; -enum _mosquitto_transport { - mosq_t_invalid = 0, - mosq_t_tcp = 1, - mosq_t_ws = 2, - mosq_t_sctp = 3 +enum _mosquitto_transport +{ + mosq_t_invalid = 0, + mosq_t_tcp = 1, + mosq_t_ws = 2, + mosq_t_sctp = 3 }; -struct _mosquitto_packet{ - uint8_t command; - uint8_t have_remaining; - uint8_t remaining_count; - uint16_t mid; - uint32_t remaining_mult; - uint32_t remaining_length; - uint32_t packet_length; - uint32_t to_process; - uint32_t pos; - uint8_t *payload; - struct _mosquitto_packet *next; +struct _mosquitto_packet +{ + uint8_t command; + uint8_t have_remaining; + uint8_t remaining_count; + uint16_t mid; + uint32_t remaining_mult; + uint32_t remaining_length; + uint32_t packet_length; + uint32_t to_process; + uint32_t pos; + uint8_t *payload; + struct _mosquitto_packet *next; }; -struct mosquitto_message_all{ - struct mosquitto_message_all *next; - time_t timestamp; - //enum mosquitto_msg_direction direction; - enum mosquitto_msg_state state; - bool dup; - struct mosquitto_message msg; +struct mosquitto_message_all +{ + struct mosquitto_message_all *next; + time_t timestamp; + //enum mosquitto_msg_direction direction; + enum mosquitto_msg_state state; + bool dup; + struct mosquitto_message msg; }; -struct mosquitto { +struct mosquitto +{ #ifndef WIN32 - int sock; + int sock; # ifndef WITH_BROKER - int sockpairR, sockpairW; + int sockpairR, sockpairW; # endif #else - SOCKET sock; + SOCKET sock; # ifndef WITH_BROKER - SOCKET sockpairR, sockpairW; + SOCKET sockpairR, sockpairW; # endif #endif - enum _mosquitto_protocol protocol; - char *address; - char *id; - char *username; - char *password; - uint16_t keepalive; - bool clean_session; - enum mosquitto_client_state state; - time_t last_msg_in; - time_t last_msg_out; - time_t ping_t; - uint16_t last_mid; - struct _mosquitto_packet in_packet; - struct _mosquitto_packet *current_out_packet; - struct _mosquitto_packet *out_packet; - struct mosquitto_message *will; + enum _mosquitto_protocol protocol; + char *address; + char *id; + char *username; + char *password; + uint16_t keepalive; + bool clean_session; + enum mosquitto_client_state state; + time_t last_msg_in; + time_t last_msg_out; + time_t ping_t; + uint16_t last_mid; + struct _mosquitto_packet in_packet; + struct _mosquitto_packet *current_out_packet; + struct _mosquitto_packet *out_packet; + struct mosquitto_message *will; #ifdef WITH_TLS - SSL *ssl; - SSL_CTX *ssl_ctx; - char *tls_cafile; - char *tls_capath; - char *tls_certfile; - char *tls_keyfile; - int (*tls_pw_callback)(char *buf, int size, int rwflag, void *userdata); - int tls_cert_reqs; - char *tls_version; - char *tls_ciphers; - char *tls_psk; - char *tls_psk_identity; - bool tls_insecure; + SSL *ssl; + SSL_CTX *ssl_ctx; + char *tls_cafile; + char *tls_capath; + char *tls_certfile; + char *tls_keyfile; + int (*tls_pw_callback)(char *buf, int size, int rwflag, void *userdata); + int tls_cert_reqs; + char *tls_version; + char *tls_ciphers; + char *tls_psk; + char *tls_psk_identity; + bool tls_insecure; #endif - bool want_write; + bool want_write; #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 current_out_packet_mutex; - pthread_mutex_t state_mutex; - pthread_mutex_t in_message_mutex; - pthread_mutex_t out_message_mutex; - pthread_t thread_id; + 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 current_out_packet_mutex; + pthread_mutex_t state_mutex; + pthread_mutex_t in_message_mutex; + pthread_mutex_t out_message_mutex; + pthread_t thread_id; #endif #ifdef WITH_BROKER - bool is_bridge; - struct _mqtt3_bridge *bridge; - struct mosquitto_client_msg *msgs; - struct mosquitto_client_msg *last_msg; - int msg_count; - int msg_count12; - struct _mosquitto_acl_user *acl_list; - struct _mqtt3_listener *listener; - time_t disconnect_t; - int pollfd_index; - int db_index; - struct _mosquitto_packet *out_packet_last; - bool is_dropping; + bool is_bridge; + struct _mqtt3_bridge *bridge; + struct mosquitto_client_msg *msgs; + struct mosquitto_client_msg *last_msg; + int msg_count; + int msg_count12; + struct _mosquitto_acl_user *acl_list; + struct _mqtt3_listener *listener; + time_t disconnect_t; + int pollfd_index; + int db_index; + struct _mosquitto_packet *out_packet_last; + bool is_dropping; #else - void *userdata; - bool in_callback; - unsigned int message_retry; - time_t last_retry_check; - struct mosquitto_message_all *in_messages; - struct mosquitto_message_all *in_messages_last; - struct mosquitto_message_all *out_messages; - struct mosquitto_message_all *out_messages_last; - void (*on_connect)(struct mosquitto *, void *userdata, int rc); - void (*on_disconnect)(struct mosquitto *, void *userdata, int rc); - void (*on_publish)(struct mosquitto *, void *userdata, int mid); - void (*on_message)(struct mosquitto *, void *userdata, const struct mosquitto_message *message); - void (*on_subscribe)(struct mosquitto *, void *userdata, int mid, int qos_count, const int *granted_qos); - void (*on_unsubscribe)(struct mosquitto *, void *userdata, int mid); - void (*on_log)(struct mosquitto *, void *userdata, int level, const char *str); - //void (*on_error)(); - char *host; - int port; - int in_queue_len; - int out_queue_len; - char *bind_address; - unsigned int reconnect_delay; - unsigned int reconnect_delay_max; - bool reconnect_exponential_backoff; - bool threaded; - struct _mosquitto_packet *out_packet_last; - int inflight_messages; - int max_inflight_messages; + void *userdata; + bool in_callback; + unsigned int message_retry; + time_t last_retry_check; + struct mosquitto_message_all *in_messages; + struct mosquitto_message_all *in_messages_last; + struct mosquitto_message_all *out_messages; + struct mosquitto_message_all *out_messages_last; + void (*on_connect)(struct mosquitto *, void *userdata, int rc); + void (*on_disconnect)(struct mosquitto *, void *userdata, int rc); + void (*on_publish)(struct mosquitto *, void *userdata, int mid); + void (*on_message)(struct mosquitto *, void *userdata, const struct mosquitto_message *message); + void (*on_subscribe)(struct mosquitto *, void *userdata, int mid, int qos_count, + const int *granted_qos); + void (*on_unsubscribe)(struct mosquitto *, void *userdata, int mid); + void (*on_log)(struct mosquitto *, void *userdata, int level, const char *str); + //void (*on_error)(); + char *host; + int port; + int in_queue_len; + int out_queue_len; + char *bind_address; + unsigned int reconnect_delay; + unsigned int reconnect_delay_max; + bool reconnect_exponential_backoff; + bool threaded; + struct _mosquitto_packet *out_packet_last; + int inflight_messages; + int max_inflight_messages; # ifdef WITH_SRV - ares_channel achan; + ares_channel achan; # endif #endif }; diff --git a/service/protocol-plugin/plugins/mqtt-fan/lib/net_mosq.h b/service/protocol-plugin/plugins/mqtt-fan/lib/net_mosq.h index 96f89a1..f8bd07f 100644 --- a/service/protocol-plugin/plugins/mqtt-fan/lib/net_mosq.h +++ b/service/protocol-plugin/plugins/mqtt-fan/lib/net_mosq.h @@ -71,9 +71,11 @@ void _mosquitto_net_cleanup(void); void _mosquitto_packet_cleanup(struct _mosquitto_packet *packet); int _mosquitto_packet_queue(struct mosquitto *mosq, struct _mosquitto_packet *packet); -int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking); +int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, + const char *bind_address, bool blocking); int _mosquitto_socket_close(struct mosquitto *mosq); -int _mosquitto_try_connect(const char *host, uint16_t port, int *sock, const char *bind_address, bool blocking); +int _mosquitto_try_connect(const char *host, uint16_t port, int *sock, const char *bind_address, + bool blocking); int _mosquitto_socket_nonblock(int sock); int _mosquitto_socketpair(int *sp1, int *sp2); diff --git a/service/protocol-plugin/plugins/mqtt-fan/lib/send_mosq.h b/service/protocol-plugin/plugins/mqtt-fan/lib/send_mosq.h index 35e8544..c49a5c7 100644 --- a/service/protocol-plugin/plugins/mqtt-fan/lib/send_mosq.h +++ b/service/protocol-plugin/plugins/mqtt-fan/lib/send_mosq.h @@ -32,8 +32,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "mosquitto.h" int _mosquitto_send_simple_command(struct mosquitto *mosq, uint8_t command); -int _mosquitto_send_command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, bool dup); -int _mosquitto_send_real_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); +int _mosquitto_send_command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, + bool dup); +int _mosquitto_send_real_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, + uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); int _mosquitto_send_connect(struct mosquitto *mosq, uint16_t keepalive, bool clean_session); int _mosquitto_send_disconnect(struct mosquitto *mosq); @@ -41,10 +43,12 @@ int _mosquitto_send_pingreq(struct mosquitto *mosq); int _mosquitto_send_pingresp(struct mosquitto *mosq); int _mosquitto_send_puback(struct mosquitto *mosq, uint16_t mid); int _mosquitto_send_pubcomp(struct mosquitto *mosq, uint16_t mid); -int _mosquitto_send_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); +int _mosquitto_send_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, + uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); int _mosquitto_send_pubrec(struct mosquitto *mosq, uint16_t mid); int _mosquitto_send_pubrel(struct mosquitto *mosq, uint16_t mid, bool dup); -int _mosquitto_send_subscribe(struct mosquitto *mosq, int *mid, bool dup, const char *topic, uint8_t topic_qos); +int _mosquitto_send_subscribe(struct mosquitto *mosq, int *mid, bool dup, const char *topic, + uint8_t topic_qos); int _mosquitto_send_unsubscribe(struct mosquitto *mosq, int *mid, bool dup, const char *topic); #endif diff --git a/service/protocol-plugin/plugins/mqtt-fan/lib/will_mosq.h b/service/protocol-plugin/plugins/mqtt-fan/lib/will_mosq.h index 61d0a79..8891c2e 100644 --- a/service/protocol-plugin/plugins/mqtt-fan/lib/will_mosq.h +++ b/service/protocol-plugin/plugins/mqtt-fan/lib/will_mosq.h @@ -33,7 +33,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "mosquitto.h" #include "mosquitto_internal.h" -int _mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain); +int _mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, + const void *payload, int qos, bool retain); int _mosquitto_will_clear(struct mosquitto *mosq); #endif diff --git a/service/protocol-plugin/plugins/mqtt-light/lib/cpp/mosquittopp.cpp b/service/protocol-plugin/plugins/mqtt-light/lib/cpp/mosquittopp.cpp index fa4e436..dafb375 100644 --- a/service/protocol-plugin/plugins/mqtt-light/lib/cpp/mosquittopp.cpp +++ b/service/protocol-plugin/plugins/mqtt-light/lib/cpp/mosquittopp.cpp @@ -31,275 +31,284 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -namespace mosqpp { - -static void on_connect_wrapper(struct mosquitto *mosq, void *userdata, int rc) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_connect(rc); -} - -static void on_disconnect_wrapper(struct mosquitto *mosq, void *userdata, int rc) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_disconnect(rc); -} - -static void on_publish_wrapper(struct mosquitto *mosq, void *userdata, int mid) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_publish(mid); -} - -static void on_message_wrapper(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_message(message); -} - -static void on_subscribe_wrapper(struct mosquitto *mosq, void *userdata, int mid, int qos_count, const int *granted_qos) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_subscribe(mid, qos_count, granted_qos); -} - -static void on_unsubscribe_wrapper(struct mosquitto *mosq, void *userdata, int mid) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_unsubscribe(mid); -} - - -static void on_log_wrapper(struct mosquitto *mosq, void *userdata, int level, const char *str) -{ - class mosquittopp *m = (class mosquittopp *)userdata; - m->on_log(level, str); -} - -int lib_version(int *major, int *minor, int *revision) -{ - if(major) *major = LIBMOSQUITTO_MAJOR; - if(minor) *minor = LIBMOSQUITTO_MINOR; - if(revision) *revision = LIBMOSQUITTO_REVISION; - return LIBMOSQUITTO_VERSION_NUMBER; -} - -int lib_init() -{ - return mosquitto_lib_init(); -} - -int lib_cleanup() -{ - return mosquitto_lib_cleanup(); -} - -const char* strerror(int mosq_errno) -{ - return mosquitto_strerror(mosq_errno); -} - -const char* connack_string(int connack_code) -{ - return mosquitto_connack_string(connack_code); -} - -int sub_topic_tokenise(const char *subtopic, char ***topics, int *count) -{ - return mosquitto_sub_topic_tokenise(subtopic, topics, count); -} - -int sub_topic_tokens_free(char ***topics, int count) -{ - return mosquitto_sub_topic_tokens_free(topics, count); -} - -int topic_matches_sub(const char *sub, const char *topic, bool *result) -{ - return mosquitto_topic_matches_sub(sub, topic, result); -} - -mosquittopp::mosquittopp(const char *id, bool clean_session) -{ - m_mosq = mosquitto_new(id, clean_session, this); - mosquitto_connect_callback_set(m_mosq, on_connect_wrapper); - mosquitto_disconnect_callback_set(m_mosq, on_disconnect_wrapper); - mosquitto_publish_callback_set(m_mosq, on_publish_wrapper); - mosquitto_message_callback_set(m_mosq, on_message_wrapper); - mosquitto_subscribe_callback_set(m_mosq, on_subscribe_wrapper); - mosquitto_unsubscribe_callback_set(m_mosq, on_unsubscribe_wrapper); - mosquitto_log_callback_set(m_mosq, on_log_wrapper); -} - -mosquittopp::~mosquittopp() -{ - mosquitto_destroy(m_mosq); -} - -int mosquittopp::reinitialise(const char *id, bool clean_session) -{ - int rc; - rc = mosquitto_reinitialise(m_mosq, id, clean_session, this); - if(rc == MOSQ_ERR_SUCCESS){ - mosquitto_connect_callback_set(m_mosq, on_connect_wrapper); - mosquitto_disconnect_callback_set(m_mosq, on_disconnect_wrapper); - mosquitto_publish_callback_set(m_mosq, on_publish_wrapper); - mosquitto_message_callback_set(m_mosq, on_message_wrapper); - mosquitto_subscribe_callback_set(m_mosq, on_subscribe_wrapper); - mosquitto_unsubscribe_callback_set(m_mosq, on_unsubscribe_wrapper); - mosquitto_log_callback_set(m_mosq, on_log_wrapper); - } - return rc; -} - -int mosquittopp::connect(const char *host, int port, int keepalive) -{ - return mosquitto_connect(m_mosq, host, port, keepalive); -} - -int mosquittopp::connect(const char *host, int port, int keepalive, const char *bind_address) -{ - return mosquitto_connect_bind(m_mosq, host, port, keepalive, bind_address); -} - -int mosquittopp::connect_async(const char *host, int port, int keepalive) -{ - return mosquitto_connect_async(m_mosq, host, port, keepalive); -} - -int mosquittopp::connect_async(const char *host, int port, int keepalive, const char *bind_address) -{ - return mosquitto_connect_bind_async(m_mosq, host, port, keepalive, bind_address); -} - -int mosquittopp::reconnect() -{ - return mosquitto_reconnect(m_mosq); -} - -int mosquittopp::reconnect_async() -{ - return mosquitto_reconnect_async(m_mosq); -} - -int mosquittopp::disconnect() -{ - return mosquitto_disconnect(m_mosq); -} - -int mosquittopp::socket() -{ - return mosquitto_socket(m_mosq); -} - -int mosquittopp::will_set(const char *topic, int payloadlen, const void *payload, int qos, bool retain) -{ - return mosquitto_will_set(m_mosq, topic, payloadlen, payload, qos, retain); -} - -int mosquittopp::will_clear() -{ - return mosquitto_will_clear(m_mosq); -} - -int mosquittopp::username_pw_set(const char *username, const char *password) -{ - return mosquitto_username_pw_set(m_mosq, username, password); -} - -int mosquittopp::publish(int *mid, const char *topic, int payloadlen, const void *payload, int qos, bool retain) -{ - return mosquitto_publish(m_mosq, mid, topic, payloadlen, payload, qos, retain); -} - -void mosquittopp::reconnect_delay_set(unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff) -{ - mosquitto_reconnect_delay_set(m_mosq, reconnect_delay, reconnect_delay_max, reconnect_exponential_backoff); -} - -int mosquittopp::max_inflight_messages_set(unsigned int max_inflight_messages) -{ - return mosquitto_max_inflight_messages_set(m_mosq, max_inflight_messages); -} - -void mosquittopp::message_retry_set(unsigned int message_retry) -{ - mosquitto_message_retry_set(m_mosq, message_retry); -} - -int mosquittopp::subscribe(int *mid, const char *sub, int qos) -{ - return mosquitto_subscribe(m_mosq, mid, sub, qos); -} - -int mosquittopp::unsubscribe(int *mid, const char *sub) -{ - return mosquitto_unsubscribe(m_mosq, mid, sub); -} - -int mosquittopp::loop(int timeout, int max_packets) -{ - return mosquitto_loop(m_mosq, timeout, max_packets); -} - -int mosquittopp::loop_misc() -{ - return mosquitto_loop_misc(m_mosq); -} - -int mosquittopp::loop_read(int max_packets) -{ - return mosquitto_loop_read(m_mosq, max_packets); -} - -int mosquittopp::loop_write(int max_packets) -{ - return mosquitto_loop_write(m_mosq, max_packets); -} - -int mosquittopp::loop_forever(int timeout, int max_packets) -{ - return mosquitto_loop_forever(m_mosq, timeout, max_packets); -} - -int mosquittopp::loop_start() -{ - return mosquitto_loop_start(m_mosq); -} - -int mosquittopp::loop_stop(bool force) -{ - return mosquitto_loop_stop(m_mosq, force); -} - -bool mosquittopp::want_write() -{ - return mosquitto_want_write(m_mosq); -} - -void mosquittopp::user_data_set(void *userdata) -{ - mosquitto_user_data_set(m_mosq, userdata); -} - -int mosquittopp::tls_set(const char *cafile, const char *capath, const char *certfile, const char *keyfile, int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)) -{ - return mosquitto_tls_set(m_mosq, cafile, capath, certfile, keyfile, pw_callback); -} - -int mosquittopp::tls_opts_set(int cert_reqs, const char *tls_version, const char *ciphers) -{ - return mosquitto_tls_opts_set(m_mosq, cert_reqs, tls_version, ciphers); -} - -int mosquittopp::tls_insecure_set(bool value) -{ - return mosquitto_tls_insecure_set(m_mosq, value); -} - -int mosquittopp::tls_psk_set(const char *psk, const char *identity, const char *ciphers) -{ - return mosquitto_tls_psk_set(m_mosq, psk, identity, ciphers); -} +namespace mosqpp +{ + + static void on_connect_wrapper(struct mosquitto *mosq, void *userdata, int rc) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_connect(rc); + } + + static void on_disconnect_wrapper(struct mosquitto *mosq, void *userdata, int rc) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_disconnect(rc); + } + + static void on_publish_wrapper(struct mosquitto *mosq, void *userdata, int mid) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_publish(mid); + } + + static void on_message_wrapper(struct mosquitto *mosq, void *userdata, + const struct mosquitto_message *message) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_message(message); + } + + static void on_subscribe_wrapper(struct mosquitto *mosq, void *userdata, int mid, int qos_count, + const int *granted_qos) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_subscribe(mid, qos_count, granted_qos); + } + + static void on_unsubscribe_wrapper(struct mosquitto *mosq, void *userdata, int mid) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_unsubscribe(mid); + } + + + static void on_log_wrapper(struct mosquitto *mosq, void *userdata, int level, const char *str) + { + class mosquittopp *m = (class mosquittopp *)userdata; + m->on_log(level, str); + } + + int lib_version(int *major, int *minor, int *revision) + { + if (major) *major = LIBMOSQUITTO_MAJOR; + if (minor) *minor = LIBMOSQUITTO_MINOR; + if (revision) *revision = LIBMOSQUITTO_REVISION; + return LIBMOSQUITTO_VERSION_NUMBER; + } + + int lib_init() + { + return mosquitto_lib_init(); + } + + int lib_cleanup() + { + return mosquitto_lib_cleanup(); + } + + const char *strerror(int mosq_errno) + { + return mosquitto_strerror(mosq_errno); + } + + const char *connack_string(int connack_code) + { + return mosquitto_connack_string(connack_code); + } + + int sub_topic_tokenise(const char *subtopic, char ***topics, int *count) + { + return mosquitto_sub_topic_tokenise(subtopic, topics, count); + } + + int sub_topic_tokens_free(char ***topics, int count) + { + return mosquitto_sub_topic_tokens_free(topics, count); + } + + int topic_matches_sub(const char *sub, const char *topic, bool *result) + { + return mosquitto_topic_matches_sub(sub, topic, result); + } + + mosquittopp::mosquittopp(const char *id, bool clean_session) + { + m_mosq = mosquitto_new(id, clean_session, this); + mosquitto_connect_callback_set(m_mosq, on_connect_wrapper); + mosquitto_disconnect_callback_set(m_mosq, on_disconnect_wrapper); + mosquitto_publish_callback_set(m_mosq, on_publish_wrapper); + mosquitto_message_callback_set(m_mosq, on_message_wrapper); + mosquitto_subscribe_callback_set(m_mosq, on_subscribe_wrapper); + mosquitto_unsubscribe_callback_set(m_mosq, on_unsubscribe_wrapper); + mosquitto_log_callback_set(m_mosq, on_log_wrapper); + } + + mosquittopp::~mosquittopp() + { + mosquitto_destroy(m_mosq); + } + + int mosquittopp::reinitialise(const char *id, bool clean_session) + { + int rc; + rc = mosquitto_reinitialise(m_mosq, id, clean_session, this); + if (rc == MOSQ_ERR_SUCCESS) + { + mosquitto_connect_callback_set(m_mosq, on_connect_wrapper); + mosquitto_disconnect_callback_set(m_mosq, on_disconnect_wrapper); + mosquitto_publish_callback_set(m_mosq, on_publish_wrapper); + mosquitto_message_callback_set(m_mosq, on_message_wrapper); + mosquitto_subscribe_callback_set(m_mosq, on_subscribe_wrapper); + mosquitto_unsubscribe_callback_set(m_mosq, on_unsubscribe_wrapper); + mosquitto_log_callback_set(m_mosq, on_log_wrapper); + } + return rc; + } + + int mosquittopp::connect(const char *host, int port, int keepalive) + { + return mosquitto_connect(m_mosq, host, port, keepalive); + } + + int mosquittopp::connect(const char *host, int port, int keepalive, const char *bind_address) + { + return mosquitto_connect_bind(m_mosq, host, port, keepalive, bind_address); + } + + int mosquittopp::connect_async(const char *host, int port, int keepalive) + { + return mosquitto_connect_async(m_mosq, host, port, keepalive); + } + + int mosquittopp::connect_async(const char *host, int port, int keepalive, const char *bind_address) + { + return mosquitto_connect_bind_async(m_mosq, host, port, keepalive, bind_address); + } + + int mosquittopp::reconnect() + { + return mosquitto_reconnect(m_mosq); + } + + int mosquittopp::reconnect_async() + { + return mosquitto_reconnect_async(m_mosq); + } + + int mosquittopp::disconnect() + { + return mosquitto_disconnect(m_mosq); + } + + int mosquittopp::socket() + { + return mosquitto_socket(m_mosq); + } + + int mosquittopp::will_set(const char *topic, int payloadlen, const void *payload, int qos, + bool retain) + { + return mosquitto_will_set(m_mosq, topic, payloadlen, payload, qos, retain); + } + + int mosquittopp::will_clear() + { + return mosquitto_will_clear(m_mosq); + } + + int mosquittopp::username_pw_set(const char *username, const char *password) + { + return mosquitto_username_pw_set(m_mosq, username, password); + } + + int mosquittopp::publish(int *mid, const char *topic, int payloadlen, const void *payload, int qos, + bool retain) + { + return mosquitto_publish(m_mosq, mid, topic, payloadlen, payload, qos, retain); + } + + void mosquittopp::reconnect_delay_set(unsigned int reconnect_delay, + unsigned int reconnect_delay_max, bool reconnect_exponential_backoff) + { + mosquitto_reconnect_delay_set(m_mosq, reconnect_delay, reconnect_delay_max, + reconnect_exponential_backoff); + } + + int mosquittopp::max_inflight_messages_set(unsigned int max_inflight_messages) + { + return mosquitto_max_inflight_messages_set(m_mosq, max_inflight_messages); + } + + void mosquittopp::message_retry_set(unsigned int message_retry) + { + mosquitto_message_retry_set(m_mosq, message_retry); + } + + int mosquittopp::subscribe(int *mid, const char *sub, int qos) + { + return mosquitto_subscribe(m_mosq, mid, sub, qos); + } + + int mosquittopp::unsubscribe(int *mid, const char *sub) + { + return mosquitto_unsubscribe(m_mosq, mid, sub); + } + + int mosquittopp::loop(int timeout, int max_packets) + { + return mosquitto_loop(m_mosq, timeout, max_packets); + } + + int mosquittopp::loop_misc() + { + return mosquitto_loop_misc(m_mosq); + } + + int mosquittopp::loop_read(int max_packets) + { + return mosquitto_loop_read(m_mosq, max_packets); + } + + int mosquittopp::loop_write(int max_packets) + { + return mosquitto_loop_write(m_mosq, max_packets); + } + + int mosquittopp::loop_forever(int timeout, int max_packets) + { + return mosquitto_loop_forever(m_mosq, timeout, max_packets); + } + + int mosquittopp::loop_start() + { + return mosquitto_loop_start(m_mosq); + } + + int mosquittopp::loop_stop(bool force) + { + return mosquitto_loop_stop(m_mosq, force); + } + + bool mosquittopp::want_write() + { + return mosquitto_want_write(m_mosq); + } + + void mosquittopp::user_data_set(void *userdata) + { + mosquitto_user_data_set(m_mosq, userdata); + } + + int mosquittopp::tls_set(const char *cafile, const char *capath, const char *certfile, + const char *keyfile, int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)) + { + return mosquitto_tls_set(m_mosq, cafile, capath, certfile, keyfile, pw_callback); + } + + int mosquittopp::tls_opts_set(int cert_reqs, const char *tls_version, const char *ciphers) + { + return mosquitto_tls_opts_set(m_mosq, cert_reqs, tls_version, ciphers); + } + + int mosquittopp::tls_insecure_set(bool value) + { + return mosquitto_tls_insecure_set(m_mosq, value); + } + + int mosquittopp::tls_psk_set(const char *psk, const char *identity, const char *ciphers) + { + return mosquitto_tls_psk_set(m_mosq, psk, identity, ciphers); + } } diff --git a/service/protocol-plugin/plugins/mqtt-light/lib/cpp/mosquittopp.h b/service/protocol-plugin/plugins/mqtt-light/lib/cpp/mosquittopp.h index 41537b6..8e3cabf 100644 --- a/service/protocol-plugin/plugins/mqtt-light/lib/cpp/mosquittopp.h +++ b/service/protocol-plugin/plugins/mqtt-light/lib/cpp/mosquittopp.h @@ -38,85 +38,92 @@ This product includes software written by Tim Hudson (tjh@cryptsoft.com) #define _MOSQUITTOPP_H_ #ifdef _WIN32 -# ifdef mosquittopp_EXPORTS -# define mosqpp_EXPORT __declspec(dllexport) -# else -# define mosqpp_EXPORT __declspec(dllimport) -# endif +# ifdef mosquittopp_EXPORTS +# define mosqpp_EXPORT __declspec(dllexport) +# else +# define mosqpp_EXPORT __declspec(dllimport) +# endif #else -# define mosqpp_EXPORT +# define mosqpp_EXPORT #endif #include #include #include "../mosquitto.h" -namespace mosqpp { +namespace mosqpp +{ -mosqpp_EXPORT const char *strerror(int mosq_errno); -mosqpp_EXPORT const char *connack_string(int connack_code); -mosqpp_EXPORT int sub_topic_tokenise(const char *subtopic, char ***topics, int *count); -mosqpp_EXPORT int sub_topic_tokens_free(char ***topics, int count); -mosqpp_EXPORT int lib_version(int *major, int *minor, int *revision); -mosqpp_EXPORT int lib_init(); -mosqpp_EXPORT int lib_cleanup(); -mosqpp_EXPORT int topic_matches_sub(const char *sub, const char *topic, bool *result); + mosqpp_EXPORT const char *strerror(int mosq_errno); + mosqpp_EXPORT const char *connack_string(int connack_code); + mosqpp_EXPORT int sub_topic_tokenise(const char *subtopic, char ***topics, int *count); + mosqpp_EXPORT int sub_topic_tokens_free(char ***topics, int count); + mosqpp_EXPORT int lib_version(int *major, int *minor, int *revision); + mosqpp_EXPORT int lib_init(); + mosqpp_EXPORT int lib_cleanup(); + mosqpp_EXPORT int topic_matches_sub(const char *sub, const char *topic, bool *result); -/* - * Class: mosquittopp - * - * A mosquitto client class. This is a C++ wrapper class for the mosquitto C - * library. Please see mosquitto.h for details of the functions. - */ -class mosqpp_EXPORT mosquittopp { - private: - struct mosquitto *m_mosq; - public: - mosquittopp(const char *id=NULL, bool clean_session=true); - ~mosquittopp(); + /* + * Class: mosquittopp + * + * A mosquitto client class. This is a C++ wrapper class for the mosquitto C + * library. Please see mosquitto.h for details of the functions. + */ + class mosqpp_EXPORT mosquittopp + { + private: + struct mosquitto *m_mosq; + public: + mosquittopp(const char *id = NULL, bool clean_session = true); + ~mosquittopp(); + + int reinitialise(const char *id, bool clean_session); + int socket(); + int will_set(const char *topic, int payloadlen = 0, const void *payload = NULL, int qos = 0, + bool retain = false); + int will_clear(); + int username_pw_set(const char *username, const char *password = NULL); + int connect(const char *host, int port = 1883, int keepalive = 60); + int connect_async(const char *host, int port = 1883, int keepalive = 60); + int connect(const char *host, int port, int keepalive, const char *bind_address); + int connect_async(const char *host, int port, int keepalive, const char *bind_address); + int reconnect(); + int reconnect_async(); + int disconnect(); + int publish(int *mid, const char *topic, int payloadlen = 0, const void *payload = NULL, + int qos = 0, bool retain = false); + int subscribe(int *mid, const char *sub, int qos = 0); + int unsubscribe(int *mid, const char *sub); + void reconnect_delay_set(unsigned int reconnect_delay, unsigned int reconnect_delay_max, + bool reconnect_exponential_backoff); + int max_inflight_messages_set(unsigned int max_inflight_messages); + void message_retry_set(unsigned int message_retry); + void user_data_set(void *userdata); + int tls_set(const char *cafile, const char *capath = NULL, const char *certfile = NULL, + const char *keyfile = NULL, int (*pw_callback)(char *buf, int size, int rwflag, + void *userdata) = NULL); + int tls_opts_set(int cert_reqs, const char *tls_version = NULL, const char *ciphers = NULL); + int tls_insecure_set(bool value); + int tls_psk_set(const char *psk, const char *identity, const char *ciphers = NULL); - int reinitialise(const char *id, bool clean_session); - int socket(); - int will_set(const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); - int will_clear(); - int username_pw_set(const char *username, const char *password=NULL); - int connect(const char *host, int port=1883, int keepalive=60); - int connect_async(const char *host, int port=1883, int keepalive=60); - int connect(const char *host, int port, int keepalive, const char *bind_address); - int connect_async(const char *host, int port, int keepalive, const char *bind_address); - int reconnect(); - int reconnect_async(); - int disconnect(); - int publish(int *mid, const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); - int subscribe(int *mid, const char *sub, int qos=0); - int unsubscribe(int *mid, const char *sub); - void reconnect_delay_set(unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff); - int max_inflight_messages_set(unsigned int max_inflight_messages); - void message_retry_set(unsigned int message_retry); - void user_data_set(void *userdata); - int tls_set(const char *cafile, const char *capath=NULL, const char *certfile=NULL, const char *keyfile=NULL, int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)=NULL); - int tls_opts_set(int cert_reqs, const char *tls_version=NULL, const char *ciphers=NULL); - int tls_insecure_set(bool value); - int tls_psk_set(const char *psk, const char *identity, const char *ciphers=NULL); + int loop(int timeout = -1, int max_packets = 1); + int loop_misc(); + int loop_read(int max_packets = 1); + int loop_write(int max_packets = 1); + int loop_forever(int timeout = -1, int max_packets = 1); + int loop_start(); + int loop_stop(bool force = false); + bool want_write(); - int loop(int timeout=-1, int max_packets=1); - int loop_misc(); - int loop_read(int max_packets=1); - int loop_write(int max_packets=1); - int loop_forever(int timeout=-1, int max_packets=1); - int loop_start(); - int loop_stop(bool force=false); - bool want_write(); - - virtual void on_connect(int rc) {return;}; - virtual void on_disconnect(int rc) {return;}; - virtual void on_publish(int mid) {return;}; - virtual void on_message(const struct mosquitto_message *message) {return;}; - virtual void on_subscribe(int mid, int qos_count, const int *granted_qos) {return;}; - virtual void on_unsubscribe(int mid) {return;}; - virtual void on_log(int level, const char *str) {return;}; - virtual void on_error() {return;}; -}; + virtual void on_connect(int rc) {return;}; + virtual void on_disconnect(int rc) {return;}; + virtual void on_publish(int mid) {return;}; + virtual void on_message(const struct mosquitto_message *message) {return;}; + virtual void on_subscribe(int mid, int qos_count, const int *granted_qos) {return;}; + virtual void on_unsubscribe(int mid) {return;}; + virtual void on_log(int level, const char *str) {return;}; + virtual void on_error() {return;}; + }; } #endif diff --git a/service/protocol-plugin/plugins/mqtt-light/lib/dummypthread.h b/service/protocol-plugin/plugins/mqtt-light/lib/dummypthread.h index 31f3251..e71f525 100644 --- a/service/protocol-plugin/plugins/mqtt-light/lib/dummypthread.h +++ b/service/protocol-plugin/plugins/mqtt-light/lib/dummypthread.h @@ -7,7 +7,7 @@ #define pthread_mutex_init(A, B) #define pthread_mutex_destroy(A) -#define pthread_mutex_lock(A) -#define pthread_mutex_unlock(A) +#define pthread_mutex_lock(A) +#define pthread_mutex_unlock(A) #endif diff --git a/service/protocol-plugin/plugins/mqtt-light/lib/messages_mosq.h b/service/protocol-plugin/plugins/mqtt-light/lib/messages_mosq.h index b9d0c8e..eebea23 100644 --- a/service/protocol-plugin/plugins/mqtt-light/lib/messages_mosq.h +++ b/service/protocol-plugin/plugins/mqtt-light/lib/messages_mosq.h @@ -34,11 +34,15 @@ POSSIBILITY OF SUCH DAMAGE. void _mosquitto_message_cleanup_all(struct mosquitto *mosq); void _mosquitto_message_cleanup(struct mosquitto_message_all **message); -int _mosquitto_message_delete(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir); -void _mosquitto_message_queue(struct mosquitto *mosq, struct mosquitto_message_all *message, enum mosquitto_msg_direction dir); +int _mosquitto_message_delete(struct mosquitto *mosq, uint16_t mid, + enum mosquitto_msg_direction dir); +void _mosquitto_message_queue(struct mosquitto *mosq, struct mosquitto_message_all *message, + enum mosquitto_msg_direction dir); void _mosquitto_messages_reconnect_reset(struct mosquitto *mosq); -int _mosquitto_message_remove(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir, struct mosquitto_message_all **message); +int _mosquitto_message_remove(struct mosquitto *mosq, uint16_t mid, + enum mosquitto_msg_direction dir, struct mosquitto_message_all **message); void _mosquitto_message_retry_check(struct mosquitto *mosq); -int _mosquitto_message_out_update(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_state state); +int _mosquitto_message_out_update(struct mosquitto *mosq, uint16_t mid, + enum mosquitto_msg_state state); #endif diff --git a/service/protocol-plugin/plugins/mqtt-light/lib/mosquitto.h b/service/protocol-plugin/plugins/mqtt-light/lib/mosquitto.h index 27506eb..ca3bf12 100644 --- a/service/protocol-plugin/plugins/mqtt-light/lib/mosquitto.h +++ b/service/protocol-plugin/plugins/mqtt-light/lib/mosquitto.h @@ -42,25 +42,25 @@ extern "C" { #endif #if defined(WIN32) && !defined(WITH_BROKER) -# ifdef libmosquitto_EXPORTS -# define libmosq_EXPORT __declspec(dllexport) -# else -# define libmosq_EXPORT __declspec(dllimport) -# endif +# ifdef libmosquitto_EXPORTS +# define libmosq_EXPORT __declspec(dllexport) +# else +# define libmosq_EXPORT __declspec(dllimport) +# endif #else -# define libmosq_EXPORT +# define libmosq_EXPORT #endif #ifdef WIN32 -# ifndef __cplusplus -# define bool char -# define true 1 -# define false 0 -# endif +# ifndef __cplusplus +# define bool char +# define true 1 +# define false 0 +# endif #else -# ifndef __cplusplus -# include -# endif +# ifndef __cplusplus +# include +# endif #endif #define LIBMOSQUITTO_MAJOR 1 @@ -81,48 +81,50 @@ extern "C" { #define MOSQ_LOG_ALL 0xFFFF /* Error values */ -enum mosq_err_t { - MOSQ_ERR_CONN_PENDING = -1, - MOSQ_ERR_SUCCESS = 0, - MOSQ_ERR_NOMEM = 1, - MOSQ_ERR_PROTOCOL = 2, - MOSQ_ERR_INVAL = 3, - MOSQ_ERR_NO_CONN = 4, - MOSQ_ERR_CONN_REFUSED = 5, - MOSQ_ERR_NOT_FOUND = 6, - MOSQ_ERR_CONN_LOST = 7, - MOSQ_ERR_TLS = 8, - MOSQ_ERR_PAYLOAD_SIZE = 9, - MOSQ_ERR_NOT_SUPPORTED = 10, - MOSQ_ERR_AUTH = 11, - MOSQ_ERR_ACL_DENIED = 12, - MOSQ_ERR_UNKNOWN = 13, - MOSQ_ERR_ERRNO = 14, - MOSQ_ERR_EAI = 15 +enum mosq_err_t +{ + MOSQ_ERR_CONN_PENDING = -1, + MOSQ_ERR_SUCCESS = 0, + MOSQ_ERR_NOMEM = 1, + MOSQ_ERR_PROTOCOL = 2, + MOSQ_ERR_INVAL = 3, + MOSQ_ERR_NO_CONN = 4, + MOSQ_ERR_CONN_REFUSED = 5, + MOSQ_ERR_NOT_FOUND = 6, + MOSQ_ERR_CONN_LOST = 7, + MOSQ_ERR_TLS = 8, + MOSQ_ERR_PAYLOAD_SIZE = 9, + MOSQ_ERR_NOT_SUPPORTED = 10, + MOSQ_ERR_AUTH = 11, + MOSQ_ERR_ACL_DENIED = 12, + MOSQ_ERR_UNKNOWN = 13, + MOSQ_ERR_ERRNO = 14, + MOSQ_ERR_EAI = 15 }; /* MQTT specification restricts client ids to a maximum of 23 characters */ #define MOSQ_MQTT_ID_MAX_LENGTH 23 -struct mosquitto_message{ - int mid; - char *topic; - void *payload; - int payloadlen; - int qos; - bool retain; +struct mosquitto_message +{ + int mid; + char *topic; + void *payload; + int payloadlen; + int qos; + bool retain; }; struct mosquitto; /* * Topic: Threads - * libmosquitto provides thread safe operation, with the exception of - * which is not thread safe. + * libmosquitto provides thread safe operation, with the exception of + * which is not thread safe. */ /*************************************************** * Important note - * + * * The following functions that deal with network operations will return * MOSQ_ERR_SUCCESS on success, but this does not mean that the operation has * taken place. An attempt will be made to write the network data, but if the @@ -157,10 +159,10 @@ struct mosquitto; * be returned in this variable. * * Returns: - * LIBMOSQUITTO_VERSION_NUMBER, which is a unique number based on the major, - * minor and revision values. + * LIBMOSQUITTO_VERSION_NUMBER, which is a unique number based on the major, + * minor and revision values. * See Also: - * , + * , */ libmosq_EXPORT int mosquitto_lib_version(int *major, int *minor, int *revision); @@ -172,10 +174,10 @@ libmosq_EXPORT int mosquitto_lib_version(int *major, int *minor, int *revision); * This function is *not* thread safe. * * Returns: - * MOSQ_ERR_SUCCESS - always + * MOSQ_ERR_SUCCESS - always * * See Also: - * , + * , */ libmosq_EXPORT int mosquitto_lib_init(void); @@ -185,10 +187,10 @@ libmosq_EXPORT int mosquitto_lib_init(void); * Call to free resources associated with the library. * * Returns: - * MOSQ_ERR_SUCCESS - always + * MOSQ_ERR_SUCCESS - always * * See Also: - * , + * , */ libmosq_EXPORT int mosquitto_lib_cleanup(void); @@ -198,9 +200,9 @@ libmosq_EXPORT int mosquitto_lib_cleanup(void); * Create a new mosquitto client instance. * * Parameters: - * id - String to use as the client id. If NULL, a random client id - * will be generated. If id is NULL, clean_session must be true. - * clean_session - set to true to instruct the broker to clean all messages + * id - String to use as the client id. If NULL, a random client id + * will be generated. If id is NULL, clean_session must be true. + * clean_session - set to true to instruct the broker to clean all messages * and subscriptions on disconnect, false to instruct it to * keep them. See the man page mqtt(7) for more details. * Note that a client will never discard its own outgoing @@ -209,30 +211,30 @@ libmosq_EXPORT int mosquitto_lib_cleanup(void); * Use to reset a client to its * original state. * Must be set to true if the id parameter is NULL. - * obj - A user pointer that will be passed as an argument to any + * obj - A user pointer that will be passed as an argument to any * callbacks that are specified. * * Returns: - * Pointer to a struct mosquitto on success. - * NULL on failure. Interrogate errno to determine the cause for the failure: + * Pointer to a struct mosquitto on success. + * NULL on failure. Interrogate errno to determine the cause for the failure: * - ENOMEM on out of memory. * - EINVAL on invalid input parameters. * * See Also: - * , , + * , , */ libmosq_EXPORT struct mosquitto *mosquitto_new(const char *id, bool clean_session, void *obj); -/* +/* * Function: mosquitto_destroy * * Use to free memory associated with a mosquitto client instance. * * Parameters: - * mosq - a struct mosquitto pointer to free. + * mosq - a struct mosquitto pointer to free. * * See Also: - * , + * , */ libmosq_EXPORT void mosquitto_destroy(struct mosquitto *mosq); @@ -245,63 +247,65 @@ libmosq_EXPORT void mosquitto_destroy(struct mosquitto *mosq); * same as the output of . * * Parameters: - * mosq - a valid mosquitto instance. - * id - string to use as the client id. If NULL, a random client id - * will be generated. If id is NULL, clean_session must be true. - * clean_session - set to true to instruct the broker to clean all messages + * mosq - a valid mosquitto instance. + * id - string to use as the client id. If NULL, a random client id + * will be generated. If id is NULL, clean_session must be true. + * clean_session - set to true to instruct the broker to clean all messages * and subscriptions on disconnect, false to instruct it to * keep them. See the man page mqtt(7) for more details. * Must be set to true if the id parameter is NULL. - * obj - A user pointer that will be passed as an argument to any + * obj - A user pointer that will be passed as an argument to any * callbacks that are specified. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * See Also: - * , + * , */ -libmosq_EXPORT int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_session, void *obj); +libmosq_EXPORT int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, + bool clean_session, void *obj); -/* +/* * Function: mosquitto_will_set * * Configure will information for a mosquitto instance. By default, clients do * not have a will. This must be called before calling . * * Parameters: - * mosq - a valid mosquitto instance. - * topic - the topic on which to publish the will. - * payloadlen - the size of the payload (bytes). Valid values are between 0 and + * mosq - a valid mosquitto instance. + * topic - the topic on which to publish the will. + * payloadlen - the size of the payload (bytes). Valid values are between 0 and * 268,435,455. - * payload - pointer to the data to send. If payloadlen > 0 this must be a + * payload - pointer to the data to send. If payloadlen > 0 this must be a * valid memory location. - * qos - integer value 0, 1 or 2 indicating the Quality of Service to be + * qos - integer value 0, 1 or 2 indicating the Quality of Service to be * used for the will. - * retain - set to true to make the will a retained message. + * retain - set to true to make the will a retained message. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large. */ -libmosq_EXPORT int mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain); +libmosq_EXPORT int mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, + const void *payload, int qos, bool retain); -/* +/* * Function: mosquitto_will_clear * * Remove a previously configured will. This must be called before calling * . * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. */ libmosq_EXPORT int mosquitto_will_clear(struct mosquitto *mosq); @@ -317,18 +321,19 @@ libmosq_EXPORT int mosquitto_will_clear(struct mosquitto *mosq); * This is must be called before calling . * * Parameters: - * mosq - a valid mosquitto instance. - * username - the username to send as a string, or NULL to disable + * mosq - a valid mosquitto instance. + * username - the username to send as a string, or NULL to disable * authentication. - * password - the password to send as a string. Set to NULL when username is - * valid in order to send just a username. + * password - the password to send as a string. Set to NULL when username is + * valid in order to send just a username. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. */ -libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char *username, const char *password); +libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char *username, + const char *password); /* * Function: mosquitto_connect @@ -336,55 +341,57 @@ libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char * Connect to an MQTT broker. * * Parameters: - * mosq - a valid mosquitto instance. - * host - the hostname or ip address of the broker to connect to. - * port - the network port to connect to. Usually 1883. - * keepalive - the number of seconds after which the broker should send a PING + * mosq - a valid mosquitto instance. + * host - the hostname or ip address of the broker to connect to. + * port - the network port to connect to. Usually 1883. + * keepalive - the number of seconds after which the broker should send a PING * message to the client if no other messages have been exchanged * in that time. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , , , + * , , , , */ -libmosq_EXPORT int mosquitto_connect(struct mosquitto *mosq, const char *host, int port, int keepalive); +libmosq_EXPORT int mosquitto_connect(struct mosquitto *mosq, const char *host, int port, + int keepalive); /* * Function: mosquitto_connect_bind * * Connect to an MQTT broker. This extends the functionality of * by adding the bind_address parameter. Use this function - * if you need to restrict network communication over a particular interface. + * if you need to restrict network communication over a particular interface. * * Parameters: - * mosq - a valid mosquitto instance. - * host - the hostname or ip address of the broker to connect to. - * port - the network port to connect to. Usually 1883. - * keepalive - the number of seconds after which the broker should send a PING + * mosq - a valid mosquitto instance. + * host - the hostname or ip address of the broker to connect to. + * port - the network port to connect to. Usually 1883. + * keepalive - the number of seconds after which the broker should send a PING * message to the client if no other messages have been exchanged * in that time. * bind_address - the hostname or ip address of the local network interface to * bind to. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , + * , , */ -libmosq_EXPORT int mosquitto_connect_bind(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address); +libmosq_EXPORT int mosquitto_connect_bind(struct mosquitto *mosq, const char *host, int port, + int keepalive, const char *bind_address); /* * Function: mosquitto_connect_async @@ -397,25 +404,26 @@ libmosq_EXPORT int mosquitto_connect_bind(struct mosquitto *mosq, const char *ho * May be called before or after . * * Parameters: - * mosq - a valid mosquitto instance. - * host - the hostname or ip address of the broker to connect to. - * port - the network port to connect to. Usually 1883. - * keepalive - the number of seconds after which the broker should send a PING + * mosq - a valid mosquitto instance. + * host - the hostname or ip address of the broker to connect to. + * port - the network port to connect to. Usually 1883. + * keepalive - the number of seconds after which the broker should send a PING * message to the client if no other messages have been exchanged * in that time. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , , , + * , , , , */ -libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *host, int port, int keepalive); +libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *host, int port, + int keepalive); /* * Function: mosquitto_connect_async @@ -427,32 +435,33 @@ libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *h * * This extends the functionality of by adding the * bind_address parameter. Use this function if you need to restrict network - * communication over a particular interface. + * communication over a particular interface. * * May be called before or after . * * Parameters: - * mosq - a valid mosquitto instance. - * host - the hostname or ip address of the broker to connect to. - * port - the network port to connect to. Usually 1883. - * keepalive - the number of seconds after which the broker should send a PING + * mosq - a valid mosquitto instance. + * host - the hostname or ip address of the broker to connect to. + * port - the network port to connect to. Usually 1883. + * keepalive - the number of seconds after which the broker should send a PING * message to the client if no other messages have been exchanged * in that time. * bind_address - the hostname or ip address of the local network interface to * bind to. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , + * , , */ -libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address); +libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int port, + int keepalive, const char *bind_address); /* * Function: mosquitto_connect_srv @@ -464,31 +473,32 @@ libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const ch * * This extends the functionality of by adding the * bind_address parameter. Use this function if you need to restrict network - * communication over a particular interface. + * communication over a particular interface. * * May be called before or after . * * Parameters: - * mosq - a valid mosquitto instance. - * host - the hostname or ip address of the broker to connect to. - * keepalive - the number of seconds after which the broker should send a PING + * mosq - a valid mosquitto instance. + * host - the hostname or ip address of the broker to connect to. + * keepalive - the number of seconds after which the broker should send a PING * message to the client if no other messages have been exchanged * in that time. * bind_address - the hostname or ip address of the local network interface to * bind to. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , + * , , */ -libmosq_EXPORT int mosquitto_connect_srv(struct mosquitto *mosq, const char *host, int keepalive, const char *bind_address); +libmosq_EXPORT int mosquitto_connect_srv(struct mosquitto *mosq, const char *host, int keepalive, + const char *bind_address); /* * Function: mosquitto_reconnect @@ -499,25 +509,25 @@ libmosq_EXPORT int mosquitto_connect_srv(struct mosquitto *mosq, const char *hos * connection has been lost. It uses the values that were provided in the * call. It must not be called before * . - * + * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , + * , , */ libmosq_EXPORT int mosquitto_reconnect(struct mosquitto *mosq); @@ -530,25 +540,25 @@ libmosq_EXPORT int mosquitto_reconnect(struct mosquitto *mosq); * connection has been lost. It uses the values that were provided in the * or calls. It must not be * called before . - * + * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , + * , */ libmosq_EXPORT int mosquitto_reconnect_async(struct mosquitto *mosq); @@ -558,50 +568,51 @@ libmosq_EXPORT int mosquitto_reconnect_async(struct mosquitto *mosq); * Disconnect from the broker. * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. */ libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq); -/* +/* * Function: mosquitto_publish * * Publish a message on a given topic. - * + * * Parameters: - * mosq - a valid mosquitto instance. - * mid - pointer to an int. If not NULL, the function will set this + * mosq - a valid mosquitto instance. + * mid - pointer to an int. If not NULL, the function will set this * to the message id of this particular message. This can be then * used with the publish callback to determine when the message * has been sent. * Note that although the MQTT protocol doesn't use message ids * for messages with QoS=0, libmosquitto assigns them message ids * so they can be tracked with this parameter. - * payloadlen - the size of the payload (bytes). Valid values are between 0 and + * payloadlen - the size of the payload (bytes). Valid values are between 0 and * 268,435,455. - * payload - pointer to the data to send. If payloadlen > 0 this must be a + * payload - pointer to the data to send. If payloadlen > 0 this must be a * valid memory location. - * qos - integer value 0, 1 or 2 indicating the Quality of Service to be + * qos - integer value 0, 1 or 2 indicating the Quality of Service to be * used for the message. - * retain - set to true to make the message retained. + * retain - set to true to make the message retained. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. - * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the * broker. - * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large. + * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large. * - * See Also: - * + * See Also: + * */ -libmosq_EXPORT int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int payloadlen, const void *payload, int qos, bool retain); +libmosq_EXPORT int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, + int payloadlen, const void *payload, int qos, bool retain); /* * Function: mosquitto_subscribe @@ -609,19 +620,19 @@ libmosq_EXPORT int mosquitto_publish(struct mosquitto *mosq, int *mid, const cha * Subscribe to a topic. * * Parameters: - * mosq - a valid mosquitto instance. - * mid - a pointer to an int. If not NULL, the function will set this to - * the message id of this particular message. This can be then used - * with the subscribe callback to determine when the message has been - * sent. - * sub - the subscription pattern. - * qos - the requested Quality of Service for this subscription. + * mosq - a valid mosquitto instance. + * mid - a pointer to an int. If not NULL, the function will set this to + * the message id of this particular message. This can be then used + * with the subscribe callback to determine when the message has been + * sent. + * sub - the subscription pattern. + * qos - the requested Quality of Service for this subscription. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. */ libmosq_EXPORT int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const char *sub, int qos); @@ -631,18 +642,18 @@ libmosq_EXPORT int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const c * Unsubscribe from a topic. * * Parameters: - * mosq - a valid mosquitto instance. - * mid - a pointer to an int. If not NULL, the function will set this to - * the message id of this particular message. This can be then used - * with the unsubscribe callback to determine when the message has been - * sent. - * sub - the unsubscription pattern. + * mosq - a valid mosquitto instance. + * mid - a pointer to an int. If not NULL, the function will set this to + * the message id of this particular message. This can be then used + * with the unsubscribe callback to determine when the message has been + * sent. + * sub - the unsubscription pattern. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. */ libmosq_EXPORT int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub); @@ -653,29 +664,30 @@ libmosq_EXPORT int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const * Useful for preserving a message received in the on_message() callback. * * Parameters: - * dst - a pointer to a valid mosquitto_message struct to copy to. - * src - a pointer to a valid mosquitto_message struct to copy from. + * dst - a pointer to a valid mosquitto_message struct to copy to. + * src - a pointer to a valid mosquitto_message struct to copy from. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * See Also: - * + * */ -libmosq_EXPORT int mosquitto_message_copy(struct mosquitto_message *dst, const struct mosquitto_message *src); +libmosq_EXPORT int mosquitto_message_copy(struct mosquitto_message *dst, + const struct mosquitto_message *src); /* * Function: mosquitto_message_free - * + * * Completely free a mosquitto_message struct. * * Parameters: - * message - pointer to a mosquitto_message pointer to free. + * message - pointer to a mosquitto_message pointer to free. * * See Also: - * + * */ libmosq_EXPORT void mosquitto_message_free(struct mosquitto_message **message); @@ -699,29 +711,29 @@ libmosq_EXPORT void mosquitto_message_free(struct mosquitto_message **message); * . * * Threads: - * + * * Parameters: - * mosq - a valid mosquitto instance. - * timeout - Maximum number of milliseconds to wait for network activity - * in the select() call before timing out. Set to 0 for instant - * return. Set negative to use the default of 1000ms. - * max_packets - this parameter is currently unused and should be set to 1 for - * future compatibility. - * + * mosq - a valid mosquitto instance. + * timeout - Maximum number of milliseconds to wait for network activity + * in the select() call before timing out. Set to 0 for instant + * return. Set negative to use the default of 1000ms. + * max_packets - this parameter is currently unused and should be set to 1 for + * future compatibility. + * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost. - * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the + * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the * broker. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * See Also: - * , , + * , , */ libmosq_EXPORT int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets); @@ -737,27 +749,27 @@ libmosq_EXPORT int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_p * * Parameters: * mosq - a valid mosquitto instance. - * timeout - Maximum number of milliseconds to wait for network activity - * in the select() call before timing out. Set to 0 for instant - * return. Set negative to use the default of 1000ms. - * max_packets - this parameter is currently unused and should be set to 1 for - * future compatibility. + * timeout - Maximum number of milliseconds to wait for network activity + * in the select() call before timing out. Set to 0 for instant + * return. Set negative to use the default of 1000ms. + * max_packets - this parameter is currently unused and should be set to 1 for + * future compatibility. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost. - * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the + * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the * broker. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , + * , */ libmosq_EXPORT int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets); @@ -772,12 +784,12 @@ libmosq_EXPORT int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, i * mosq - a valid mosquitto instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOT_SUPPORTED - if thread support is not available. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOT_SUPPORTED - if thread support is not available. * * See Also: - * , , , + * , , , */ libmosq_EXPORT int mosquitto_loop_start(struct mosquitto *mosq); @@ -792,16 +804,16 @@ libmosq_EXPORT int mosquitto_loop_start(struct mosquitto *mosq); * * Parameters: * mosq - a valid mosquitto instance. - * force - set to true to force thread cancellation. If false, - * must have already been called. + * force - set to true to force thread cancellation. If false, + * must have already been called. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOT_SUPPORTED - if thread support is not available. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOT_SUPPORTED - if thread support is not available. * * See Also: - * , + * , */ libmosq_EXPORT int mosquitto_loop_stop(struct mosquitto *mosq, bool force); @@ -812,10 +824,10 @@ libmosq_EXPORT int mosquitto_loop_stop(struct mosquitto *mosq, bool force); * include a mosquitto client in your own select() calls. * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * Returns: - * The socket for the mosquitto client or -1 on failure. + * The socket for the mosquitto client or -1 on failure. */ libmosq_EXPORT int mosquitto_socket(struct mosquitto *mosq); @@ -827,25 +839,25 @@ libmosq_EXPORT int mosquitto_socket(struct mosquitto *mosq); * monitoring the client network socket for activity yourself. * * Parameters: - * mosq - a valid mosquitto instance. - * max_packets - this parameter is currently unused and should be set to 1 for - * future compatibility. + * mosq - a valid mosquitto instance. + * max_packets - this parameter is currently unused and should be set to 1 for + * future compatibility. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost. - * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the + * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the * broker. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , + * , , */ libmosq_EXPORT int mosquitto_loop_read(struct mosquitto *mosq, int max_packets); @@ -857,25 +869,25 @@ libmosq_EXPORT int mosquitto_loop_read(struct mosquitto *mosq, int max_packets); * monitoring the client network socket for activity yourself. * * Parameters: - * mosq - a valid mosquitto instance. - * max_packets - this parameter is currently unused and should be set to 1 for - * future compatibility. + * mosq - a valid mosquitto instance. + * max_packets - this parameter is currently unused and should be set to 1 for + * future compatibility. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost. - * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the + * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the * broker. - * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno + * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno * contains the error code, even on Windows. * Use strerror_r() where available or FormatMessage() on * Windows. * * See Also: - * , , , + * , , , */ libmosq_EXPORT int mosquitto_loop_write(struct mosquitto *mosq, int max_packets); @@ -890,15 +902,15 @@ libmosq_EXPORT int mosquitto_loop_write(struct mosquitto *mosq, int max_packets) * to be retried, so should be called fairly frequently. * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. * * See Also: - * , , + * , , */ libmosq_EXPORT int mosquitto_loop_misc(struct mosquitto *mosq); @@ -908,10 +920,10 @@ libmosq_EXPORT int mosquitto_loop_misc(struct mosquitto *mosq); * Returns true if there is data ready to be written on the socket. * * Parameters: - * mosq - a valid mosquitto instance. + * mosq - a valid mosquitto instance. * * See Also: - * , , + * , , */ libmosq_EXPORT bool mosquitto_want_write(struct mosquitto *mosq); @@ -954,17 +966,17 @@ libmosq_EXPORT bool mosquitto_want_write(struct mosquitto *mosq); * instance. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * See Also: - * , , + * , , */ libmosq_EXPORT int mosquitto_tls_set(struct mosquitto *mosq, - const char *cafile, const char *capath, - const char *certfile, const char *keyfile, - int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)); + const char *cafile, const char *capath, + const char *certfile, const char *keyfile, + int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)); /* * Function: mosquitto_tls_insecure_set @@ -985,11 +997,11 @@ libmosq_EXPORT int mosquitto_tls_set(struct mosquitto *mosq, * the connection is insecure. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. * * See Also: - * + * */ libmosq_EXPORT int mosquitto_tls_insecure_set(struct mosquitto *mosq, bool value); @@ -1000,32 +1012,33 @@ libmosq_EXPORT int mosquitto_tls_insecure_set(struct mosquitto *mosq, bool value * * Parameters: * mosq - a valid mosquitto instance. - * cert_reqs - an integer defining the verification requirements the client - * will impose on the server. This can be one of: - * * SSL_VERIFY_NONE (0): the server will not be verified in any way. - * * SSL_VERIFY_PEER (1): the server certificate will be verified - * and the connection aborted if the verification fails. - * The default and recommended value is SSL_VERIFY_PEER. Using - * SSL_VERIFY_NONE provides no security. - * tls_version - the version of the SSL/TLS protocol to use as a string. If NULL, - * the default value is used. The default value and the - * available values depend on the version of openssl that the - * library was compiled against. For openssl >= 1.0.1, the - * available options are tlsv1.2, tlsv1.1 and tlsv1, with tlv1.2 - * as the default. For openssl < 1.0.1, only tlsv1 is available. - * ciphers - a string describing the ciphers available for use. See the - * "openssl ciphers" tool for more information. If NULL, the - * default ciphers will be used. + * cert_reqs - an integer defining the verification requirements the client + * will impose on the server. This can be one of: + * * SSL_VERIFY_NONE (0): the server will not be verified in any way. + * * SSL_VERIFY_PEER (1): the server certificate will be verified + * and the connection aborted if the verification fails. + * The default and recommended value is SSL_VERIFY_PEER. Using + * SSL_VERIFY_NONE provides no security. + * tls_version - the version of the SSL/TLS protocol to use as a string. If NULL, + * the default value is used. The default value and the + * available values depend on the version of openssl that the + * library was compiled against. For openssl >= 1.0.1, the + * available options are tlsv1.2, tlsv1.1 and tlsv1, with tlv1.2 + * as the default. For openssl < 1.0.1, only tlsv1 is available. + * ciphers - a string describing the ciphers available for use. See the + * "openssl ciphers" tool for more information. If NULL, the + * default ciphers will be used. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * See Also: - * + * */ -libmosq_EXPORT int mosquitto_tls_opts_set(struct mosquitto *mosq, int cert_reqs, const char *tls_version, const char *ciphers); +libmosq_EXPORT int mosquitto_tls_opts_set(struct mosquitto *mosq, int cert_reqs, + const char *tls_version, const char *ciphers); /* * Function: mosquitto_tls_psk_set @@ -1040,21 +1053,22 @@ libmosq_EXPORT int mosquitto_tls_opts_set(struct mosquitto *mosq, int cert_reqs, * psk - the pre-shared-key in hex format with no leading "0x". * identity - the identity of this client. May be used as the username * depending on the server settings. - * ciphers - a string describing the PSK ciphers available for use. See the - * "openssl ciphers" tool for more information. If NULL, the - * default ciphers will be used. + * ciphers - a string describing the PSK ciphers available for use. See the + * "openssl ciphers" tool for more information. If NULL, the + * default ciphers will be used. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * See Also: - * + * */ -libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk, const char *identity, const char *ciphers); +libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk, + const char *identity, const char *ciphers); -/* +/* * Function: mosquitto_connect_callback_set * * Set the connect callback. This is called when the broker sends a CONNACK @@ -1076,14 +1090,15 @@ libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk * * 3 - connection refused (broker unavailable) * * 4-255 - reserved for future use */ -libmosq_EXPORT void mosquitto_connect_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int)); - +libmosq_EXPORT void mosquitto_connect_callback_set(struct mosquitto *mosq, + void (*on_connect)(struct mosquitto *, void *, int)); + /* * Function: mosquitto_disconnect_callback_set * * Set the disconnect callback. This is called when the broker has received the * DISCONNECT command and has disconnected the client. - * + * * Parameters: * mosq - a valid mosquitto instance. * on_disconnect - a callback function in the following form: @@ -1096,14 +1111,15 @@ libmosq_EXPORT void mosquitto_connect_callback_set(struct mosquitto *mosq, void * means the client has called . Any other value * indicates that the disconnect is unexpected. */ -libmosq_EXPORT void mosquitto_disconnect_callback_set(struct mosquitto *mosq, void (*on_disconnect)(struct mosquitto *, void *, int)); - +libmosq_EXPORT void mosquitto_disconnect_callback_set(struct mosquitto *mosq, + void (*on_disconnect)(struct mosquitto *, void *, int)); + /* * Function: mosquitto_publish_callback_set * * Set the publish callback. This is called when a message initiated with * has been sent to the broker successfully. - * + * * Parameters: * mosq - a valid mosquitto instance. * on_publish - a callback function in the following form: @@ -1114,14 +1130,15 @@ libmosq_EXPORT void mosquitto_disconnect_callback_set(struct mosquitto *mosq, vo * obj - the user data provided in * mid - the message id of the sent message. */ -libmosq_EXPORT void mosquitto_publish_callback_set(struct mosquitto *mosq, void (*on_publish)(struct mosquitto *, void *, int)); +libmosq_EXPORT void mosquitto_publish_callback_set(struct mosquitto *mosq, + void (*on_publish)(struct mosquitto *, void *, int)); /* * Function: mosquitto_message_callback_set * * Set the message callback. This is called when a message is received from the * broker. - * + * * Parameters: * mosq - a valid mosquitto instance. * on_message - a callback function in the following form: @@ -1135,16 +1152,17 @@ libmosq_EXPORT void mosquitto_publish_callback_set(struct mosquitto *mosq, void * should make copies of any of the data it requires. * * See Also: - * + * */ -libmosq_EXPORT void mosquitto_message_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *)); +libmosq_EXPORT void mosquitto_message_callback_set(struct mosquitto *mosq, + void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *)); /* * Function: mosquitto_subscribe_callback_set * * Set the subscribe callback. This is called when the broker responds to a * subscription request. - * + * * Parameters: * mosq - a valid mosquitto instance. * on_subscribe - a callback function in the following form: @@ -1158,14 +1176,15 @@ libmosq_EXPORT void mosquitto_message_callback_set(struct mosquitto *mosq, void * granted_qos - an array of integers indicating the granted QoS for each of * the subscriptions. */ -libmosq_EXPORT void mosquitto_subscribe_callback_set(struct mosquitto *mosq, void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *)); +libmosq_EXPORT void mosquitto_subscribe_callback_set(struct mosquitto *mosq, + void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *)); /* * Function: mosquitto_unsubscribe_callback_set * * Set the unsubscribe callback. This is called when the broker responds to a * unsubscription request. - * + * * Parameters: * mosq - a valid mosquitto instance. * on_unsubscribe - a callback function in the following form: @@ -1176,7 +1195,8 @@ libmosq_EXPORT void mosquitto_subscribe_callback_set(struct mosquitto *mosq, voi * obj - the user data provided in * mid - the message id of the unsubscribe message. */ -libmosq_EXPORT void mosquitto_unsubscribe_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int)); +libmosq_EXPORT void mosquitto_unsubscribe_callback_set(struct mosquitto *mosq, + void (*on_unsubscribe)(struct mosquitto *, void *, int)); /* * Function: mosquitto_log_callback_set @@ -1192,14 +1212,15 @@ libmosq_EXPORT void mosquitto_unsubscribe_callback_set(struct mosquitto *mosq, v * mosq - the mosquitto instance making the callback. * obj - the user data provided in * level - the log message level from the values: - * MOSQ_LOG_INFO - * MOSQ_LOG_NOTICE - * MOSQ_LOG_WARNING - * MOSQ_LOG_ERR - * MOSQ_LOG_DEBUG - * str - the message string. + * MOSQ_LOG_INFO + * MOSQ_LOG_NOTICE + * MOSQ_LOG_WARNING + * MOSQ_LOG_ERR + * MOSQ_LOG_DEBUG + * str - the message string. */ -libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on_log)(struct mosquitto *, void *, int, const char *)); +libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, + void (*on_log)(struct mosquitto *, void *, int, const char *)); /* * Function: mosquitto_reconnect_delay_set @@ -1215,12 +1236,12 @@ libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on * set an upper bound on the delay with reconnect_delay_max. * * Example 1: - * delay=2, delay_max=10, exponential_backoff=False - * Delays would be: 2, 4, 6, 8, 10, 10, ... + * delay=2, delay_max=10, exponential_backoff=False + * Delays would be: 2, 4, 6, 8, 10, 10, ... * * Example 2: - * delay=3, delay_max=30, exponential_backoff=True - * Delays would be: 3, 6, 12, 24, 30, 30, ... + * delay=3, delay_max=30, exponential_backoff=True + * Delays would be: 3, 6, 12, 24, 30, 30, ... * * Parameters: * mosq - a valid mosquitto instance. @@ -1233,10 +1254,11 @@ libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on * exponential backoff. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. */ -libmosq_EXPORT int mosquitto_reconnect_delay_set(struct mosquitto *mosq, unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff); +libmosq_EXPORT int mosquitto_reconnect_delay_set(struct mosquitto *mosq, + unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff); /* * Function: mosquitto_max_inflight_messages_set @@ -1258,17 +1280,18 @@ libmosq_EXPORT int mosquitto_reconnect_delay_set(struct mosquitto *mosq, unsigne * to 20. * * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. */ -libmosq_EXPORT int mosquitto_max_inflight_messages_set(struct mosquitto *mosq, unsigned int max_inflight_messages); +libmosq_EXPORT int mosquitto_max_inflight_messages_set(struct mosquitto *mosq, + unsigned int max_inflight_messages); /* * Function: mosquitto_message_retry_set * * Set the number of seconds to wait before retrying messages. This applies to * publish messages with QoS>0. May be called at any time. - * + * * Parameters: * mosq - a valid mosquitto instance. * message_retry - the number of seconds to wait for a response before @@ -1287,8 +1310,8 @@ libmosq_EXPORT void mosquitto_message_retry_set(struct mosquitto *mosq, unsigned * * Parameters: * mosq - a valid mosquitto instance. - * obj - A user pointer that will be passed as an argument to any callbacks - * that are specified. + * obj - A user pointer that will be passed as an argument to any callbacks + * that are specified. */ libmosq_EXPORT void mosquitto_user_data_set(struct mosquitto *mosq, void *obj); @@ -1306,10 +1329,10 @@ libmosq_EXPORT void mosquitto_user_data_set(struct mosquitto *mosq, void *obj); * Call to obtain a const string description of a mosquitto error number. * * Parameters: - * mosq_errno - a mosquitto error number. + * mosq_errno - a mosquitto error number. * * Returns: - * A constant string describing the error. + * A constant string describing the error. */ libmosq_EXPORT const char *mosquitto_strerror(int mosq_errno); @@ -1319,10 +1342,10 @@ libmosq_EXPORT const char *mosquitto_strerror(int mosq_errno); * Call to obtain a const string description of an MQTT connection result. * * Parameters: - * connack_code - an MQTT connection result. + * connack_code - an MQTT connection result. * * Returns: - * A constant string describing the result. + * A constant string describing the result. */ libmosq_EXPORT const char *mosquitto_connack_string(int connack_code); @@ -1356,20 +1379,20 @@ libmosq_EXPORT const char *mosquitto_connack_string(int connack_code); * topics[4] = "hierarchy" * * Parameters: - * subtopic - the subscription/topic to tokenise - * topics - a pointer to store the array of strings - * count - an int pointer to store the number of items in the topics array. + * subtopic - the subscription/topic to tokenise + * topics - a pointer to store the array of strings + * count - an int pointer to store the number of items in the topics array. * * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. * * Example: * * > char **topics; * > int topic_count; * > int i; - * > + * > * > mosquitto_sub_topic_tokenise("$SYS/broker/uptime", &topics, &topic_count); * > * > for(i=0; i } * * See Also: - * + * */ libmosq_EXPORT int mosquitto_sub_topic_tokenise(const char *subtopic, char ***topics, int *count); @@ -1387,15 +1410,15 @@ libmosq_EXPORT int mosquitto_sub_topic_tokenise(const char *subtopic, char ***to * Free memory that was allocated in . * * Parameters: - * topics - pointer to string array. - * count - count of items in string array. + * topics - pointer to string array. + * count - count of items in string array. * * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if the input parameters were invalid. * * See Also: - * + * */ libmosq_EXPORT int mosquitto_sub_topic_tokens_free(char ***topics, int count); @@ -1410,15 +1433,15 @@ libmosq_EXPORT int mosquitto_sub_topic_tokens_free(char ***topics, int count); * non/matching would not match the subscription non/+/+ * * Parameters: - * sub - subscription string to check topic against. - * topic - topic to check. - * result - bool pointer to hold result. Will be set to true if the topic - * matches the subscription. + * sub - subscription string to check topic against. + * topic - topic to check. + * result - bool pointer to hold result. Will be set to true if the topic + * matches the subscription. * * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if the input parameters were invalid. - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if the input parameters were invalid. + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. */ libmosq_EXPORT int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result); diff --git a/service/protocol-plugin/plugins/mqtt-light/lib/mosquitto_internal.h b/service/protocol-plugin/plugins/mqtt-light/lib/mosquitto_internal.h index f3d5fde..523b1d9 100644 --- a/service/protocol-plugin/plugins/mqtt-light/lib/mosquitto_internal.h +++ b/service/protocol-plugin/plugins/mqtt-light/lib/mosquitto_internal.h @@ -52,16 +52,16 @@ POSSIBILITY OF SUCH DAMAGE. #endif #ifdef WIN32 -# 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 -# endif +# 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 +# endif #else -# include +# include #endif #include "mosquitto.h" @@ -70,172 +70,181 @@ POSSIBILITY OF SUCH DAMAGE. struct mosquitto_client_msg; #endif -enum mosquitto_msg_direction { - mosq_md_in = 0, - mosq_md_out = 1 +enum mosquitto_msg_direction +{ + mosq_md_in = 0, + mosq_md_out = 1 }; -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, - mosq_ms_queued = 11 +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, + mosq_ms_queued = 11 }; -enum mosquitto_client_state { - mosq_cs_new = 0, - mosq_cs_connected = 1, - mosq_cs_disconnecting = 2, - mosq_cs_connect_async = 3, - mosq_cs_connect_pending = 4, - mosq_cs_connect_srv = 5 +enum mosquitto_client_state +{ + mosq_cs_new = 0, + mosq_cs_connected = 1, + mosq_cs_disconnecting = 2, + mosq_cs_connect_async = 3, + mosq_cs_connect_pending = 4, + mosq_cs_connect_srv = 5 }; -enum _mosquitto_protocol { - mosq_p_invalid = 0, - mosq_p_mqtt31 = 1, - mosq_p_mqtt311 = 2, - mosq_p_mqtts = 3 +enum _mosquitto_protocol +{ + mosq_p_invalid = 0, + mosq_p_mqtt31 = 1, + mosq_p_mqtt311 = 2, + mosq_p_mqtts = 3 }; -enum _mosquitto_transport { - mosq_t_invalid = 0, - mosq_t_tcp = 1, - mosq_t_ws = 2, - mosq_t_sctp = 3 +enum _mosquitto_transport +{ + mosq_t_invalid = 0, + mosq_t_tcp = 1, + mosq_t_ws = 2, + mosq_t_sctp = 3 }; -struct _mosquitto_packet{ - uint8_t command; - uint8_t have_remaining; - uint8_t remaining_count; - uint16_t mid; - uint32_t remaining_mult; - uint32_t remaining_length; - uint32_t packet_length; - uint32_t to_process; - uint32_t pos; - uint8_t *payload; - struct _mosquitto_packet *next; +struct _mosquitto_packet +{ + uint8_t command; + uint8_t have_remaining; + uint8_t remaining_count; + uint16_t mid; + uint32_t remaining_mult; + uint32_t remaining_length; + uint32_t packet_length; + uint32_t to_process; + uint32_t pos; + uint8_t *payload; + struct _mosquitto_packet *next; }; -struct mosquitto_message_all{ - struct mosquitto_message_all *next; - time_t timestamp; - //enum mosquitto_msg_direction direction; - enum mosquitto_msg_state state; - bool dup; - struct mosquitto_message msg; +struct mosquitto_message_all +{ + struct mosquitto_message_all *next; + time_t timestamp; + //enum mosquitto_msg_direction direction; + enum mosquitto_msg_state state; + bool dup; + struct mosquitto_message msg; }; -struct mosquitto { +struct mosquitto +{ #ifndef WIN32 - int sock; + int sock; # ifndef WITH_BROKER - int sockpairR, sockpairW; + int sockpairR, sockpairW; # endif #else - SOCKET sock; + SOCKET sock; # ifndef WITH_BROKER - SOCKET sockpairR, sockpairW; + SOCKET sockpairR, sockpairW; # endif #endif - enum _mosquitto_protocol protocol; - char *address; - char *id; - char *username; - char *password; - uint16_t keepalive; - bool clean_session; - enum mosquitto_client_state state; - time_t last_msg_in; - time_t last_msg_out; - time_t ping_t; - uint16_t last_mid; - struct _mosquitto_packet in_packet; - struct _mosquitto_packet *current_out_packet; - struct _mosquitto_packet *out_packet; - struct mosquitto_message *will; + enum _mosquitto_protocol protocol; + char *address; + char *id; + char *username; + char *password; + uint16_t keepalive; + bool clean_session; + enum mosquitto_client_state state; + time_t last_msg_in; + time_t last_msg_out; + time_t ping_t; + uint16_t last_mid; + struct _mosquitto_packet in_packet; + struct _mosquitto_packet *current_out_packet; + struct _mosquitto_packet *out_packet; + struct mosquitto_message *will; #ifdef WITH_TLS - SSL *ssl; - SSL_CTX *ssl_ctx; - char *tls_cafile; - char *tls_capath; - char *tls_certfile; - char *tls_keyfile; - int (*tls_pw_callback)(char *buf, int size, int rwflag, void *userdata); - int tls_cert_reqs; - char *tls_version; - char *tls_ciphers; - char *tls_psk; - char *tls_psk_identity; - bool tls_insecure; + SSL *ssl; + SSL_CTX *ssl_ctx; + char *tls_cafile; + char *tls_capath; + char *tls_certfile; + char *tls_keyfile; + int (*tls_pw_callback)(char *buf, int size, int rwflag, void *userdata); + int tls_cert_reqs; + char *tls_version; + char *tls_ciphers; + char *tls_psk; + char *tls_psk_identity; + bool tls_insecure; #endif - bool want_write; + bool want_write; #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 current_out_packet_mutex; - pthread_mutex_t state_mutex; - pthread_mutex_t in_message_mutex; - pthread_mutex_t out_message_mutex; - pthread_t thread_id; + 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 current_out_packet_mutex; + pthread_mutex_t state_mutex; + pthread_mutex_t in_message_mutex; + pthread_mutex_t out_message_mutex; + pthread_t thread_id; #endif #ifdef WITH_BROKER - bool is_bridge; - struct _mqtt3_bridge *bridge; - struct mosquitto_client_msg *msgs; - struct mosquitto_client_msg *last_msg; - int msg_count; - int msg_count12; - struct _mosquitto_acl_user *acl_list; - struct _mqtt3_listener *listener; - time_t disconnect_t; - int pollfd_index; - int db_index; - struct _mosquitto_packet *out_packet_last; - bool is_dropping; + bool is_bridge; + struct _mqtt3_bridge *bridge; + struct mosquitto_client_msg *msgs; + struct mosquitto_client_msg *last_msg; + int msg_count; + int msg_count12; + struct _mosquitto_acl_user *acl_list; + struct _mqtt3_listener *listener; + time_t disconnect_t; + int pollfd_index; + int db_index; + struct _mosquitto_packet *out_packet_last; + bool is_dropping; #else - void *userdata; - bool in_callback; - unsigned int message_retry; - time_t last_retry_check; - struct mosquitto_message_all *in_messages; - struct mosquitto_message_all *in_messages_last; - struct mosquitto_message_all *out_messages; - struct mosquitto_message_all *out_messages_last; - void (*on_connect)(struct mosquitto *, void *userdata, int rc); - void (*on_disconnect)(struct mosquitto *, void *userdata, int rc); - void (*on_publish)(struct mosquitto *, void *userdata, int mid); - void (*on_message)(struct mosquitto *, void *userdata, const struct mosquitto_message *message); - void (*on_subscribe)(struct mosquitto *, void *userdata, int mid, int qos_count, const int *granted_qos); - void (*on_unsubscribe)(struct mosquitto *, void *userdata, int mid); - void (*on_log)(struct mosquitto *, void *userdata, int level, const char *str); - //void (*on_error)(); - char *host; - int port; - int in_queue_len; - int out_queue_len; - char *bind_address; - unsigned int reconnect_delay; - unsigned int reconnect_delay_max; - bool reconnect_exponential_backoff; - bool threaded; - struct _mosquitto_packet *out_packet_last; - int inflight_messages; - int max_inflight_messages; + void *userdata; + bool in_callback; + unsigned int message_retry; + time_t last_retry_check; + struct mosquitto_message_all *in_messages; + struct mosquitto_message_all *in_messages_last; + struct mosquitto_message_all *out_messages; + struct mosquitto_message_all *out_messages_last; + void (*on_connect)(struct mosquitto *, void *userdata, int rc); + void (*on_disconnect)(struct mosquitto *, void *userdata, int rc); + void (*on_publish)(struct mosquitto *, void *userdata, int mid); + void (*on_message)(struct mosquitto *, void *userdata, const struct mosquitto_message *message); + void (*on_subscribe)(struct mosquitto *, void *userdata, int mid, int qos_count, + const int *granted_qos); + void (*on_unsubscribe)(struct mosquitto *, void *userdata, int mid); + void (*on_log)(struct mosquitto *, void *userdata, int level, const char *str); + //void (*on_error)(); + char *host; + int port; + int in_queue_len; + int out_queue_len; + char *bind_address; + unsigned int reconnect_delay; + unsigned int reconnect_delay_max; + bool reconnect_exponential_backoff; + bool threaded; + struct _mosquitto_packet *out_packet_last; + int inflight_messages; + int max_inflight_messages; # ifdef WITH_SRV - ares_channel achan; + ares_channel achan; # endif #endif }; diff --git a/service/protocol-plugin/plugins/mqtt-light/lib/net_mosq.h b/service/protocol-plugin/plugins/mqtt-light/lib/net_mosq.h index 96f89a1..f8bd07f 100644 --- a/service/protocol-plugin/plugins/mqtt-light/lib/net_mosq.h +++ b/service/protocol-plugin/plugins/mqtt-light/lib/net_mosq.h @@ -71,9 +71,11 @@ void _mosquitto_net_cleanup(void); void _mosquitto_packet_cleanup(struct _mosquitto_packet *packet); int _mosquitto_packet_queue(struct mosquitto *mosq, struct _mosquitto_packet *packet); -int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking); +int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, + const char *bind_address, bool blocking); int _mosquitto_socket_close(struct mosquitto *mosq); -int _mosquitto_try_connect(const char *host, uint16_t port, int *sock, const char *bind_address, bool blocking); +int _mosquitto_try_connect(const char *host, uint16_t port, int *sock, const char *bind_address, + bool blocking); int _mosquitto_socket_nonblock(int sock); int _mosquitto_socketpair(int *sp1, int *sp2); diff --git a/service/protocol-plugin/plugins/mqtt-light/lib/send_mosq.h b/service/protocol-plugin/plugins/mqtt-light/lib/send_mosq.h index 35e8544..c49a5c7 100644 --- a/service/protocol-plugin/plugins/mqtt-light/lib/send_mosq.h +++ b/service/protocol-plugin/plugins/mqtt-light/lib/send_mosq.h @@ -32,8 +32,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "mosquitto.h" int _mosquitto_send_simple_command(struct mosquitto *mosq, uint8_t command); -int _mosquitto_send_command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, bool dup); -int _mosquitto_send_real_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); +int _mosquitto_send_command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, + bool dup); +int _mosquitto_send_real_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, + uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); int _mosquitto_send_connect(struct mosquitto *mosq, uint16_t keepalive, bool clean_session); int _mosquitto_send_disconnect(struct mosquitto *mosq); @@ -41,10 +43,12 @@ int _mosquitto_send_pingreq(struct mosquitto *mosq); int _mosquitto_send_pingresp(struct mosquitto *mosq); int _mosquitto_send_puback(struct mosquitto *mosq, uint16_t mid); int _mosquitto_send_pubcomp(struct mosquitto *mosq, uint16_t mid); -int _mosquitto_send_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); +int _mosquitto_send_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, + uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); int _mosquitto_send_pubrec(struct mosquitto *mosq, uint16_t mid); int _mosquitto_send_pubrel(struct mosquitto *mosq, uint16_t mid, bool dup); -int _mosquitto_send_subscribe(struct mosquitto *mosq, int *mid, bool dup, const char *topic, uint8_t topic_qos); +int _mosquitto_send_subscribe(struct mosquitto *mosq, int *mid, bool dup, const char *topic, + uint8_t topic_qos); int _mosquitto_send_unsubscribe(struct mosquitto *mosq, int *mid, bool dup, const char *topic); #endif diff --git a/service/protocol-plugin/plugins/mqtt-light/lib/will_mosq.h b/service/protocol-plugin/plugins/mqtt-light/lib/will_mosq.h index 61d0a79..8891c2e 100644 --- a/service/protocol-plugin/plugins/mqtt-light/lib/will_mosq.h +++ b/service/protocol-plugin/plugins/mqtt-light/lib/will_mosq.h @@ -33,7 +33,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "mosquitto.h" #include "mosquitto_internal.h" -int _mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain); +int _mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, + const void *payload, int qos, bool retain); int _mosquitto_will_clear(struct mosquitto *mosq); #endif -- 2.7.4