From d17a88d91637c9527e200e0e652eba59cd679fd6 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sat, 23 Dec 2023 12:59:58 +0000 Subject: [PATCH] Refactor headers for easier discovery. --- CMakeLists.txt | 55 + ChangeLog.txt | 1 + Makefile | 17 + apps/db_dump/print.c | 2 +- apps/mosquitto_ctrl/client.c | 2 +- apps/mosquitto_ctrl/options.c | 1 - client/client_props.c | 1 - client/client_shared.c | 1 - client/pub_client.c | 1 - client/pub_shared.c | 1 - client/rr_client.c | 1 - client/sub_client.c | 1 - client/sub_client_output.c | 1 - common/base64_mosq.c | 1 - include/mosquitto.h | 3635 +---------------- include/mosquitto/broker.h | 1265 ++++++ .../broker_control.h} | 10 +- include/mosquitto/broker_plugin.h | 441 ++ include/mosquitto/defs.h | 125 + include/mosquitto/libcommon.h | 39 + include/mosquitto/libcommon_properties.h | 752 ++++ include/mosquitto/libcommon_string.h | 97 + include/mosquitto/libcommon_topic.h | 348 ++ include/mosquitto/libcommon_utf8.h | 50 + include/mosquitto/libmosquitto.h | 248 ++ include/mosquitto/libmosquitto_auth.h | 63 + include/mosquitto/libmosquitto_callbacks.h | 440 ++ include/mosquitto/libmosquitto_connect.h | 372 ++ .../mosquitto/libmosquitto_create_delete.h | 114 + include/mosquitto/libmosquitto_helpers.h | 169 + include/mosquitto/libmosquitto_loop.h | 322 ++ include/mosquitto/libmosquitto_message.h | 86 + include/mosquitto/libmosquitto_options.h | 321 ++ include/mosquitto/libmosquitto_publish.h | 144 + include/mosquitto/libmosquitto_socks.h | 59 + include/mosquitto/libmosquitto_subscribe.h | 142 + include/mosquitto/libmosquitto_tls.h | 198 + include/mosquitto/libmosquitto_unsubscribe.h | 135 + include/mosquitto/libmosquitto_will.h | 127 + include/mosquitto/libmosquittopp.h | 162 + include/mosquitto/mqtt_protocol.h | 292 ++ include/mosquitto_broker.h | 1267 +----- include/mosquitto_plugin.h | 443 +- include/mosquittopp.h | 164 +- include/mqtt_protocol.h | 294 +- installer/mosquitto.nsi | 60 +- installer/mosquitto64.nsi | 61 +- lib/CMakeLists.txt | 5 +- lib/Makefile | 3 - lib/actions_publish.c | 2 +- lib/actions_subscribe.c | 2 +- lib/actions_unsubscribe.c | 2 +- lib/connect.c | 1 - lib/cpp/CMakeLists.txt | 4 +- lib/cpp/Makefile | 5 +- lib/cpp/mosquittopp.cpp | 3 +- lib/handle_auth.c | 2 +- lib/handle_connack.c | 3 +- lib/handle_disconnect.c | 2 +- lib/handle_ping.c | 2 +- lib/handle_pubackcomp.c | 2 +- lib/handle_publish.c | 2 +- lib/handle_pubrec.c | 2 +- lib/handle_pubrel.c | 2 +- lib/handle_suback.c | 2 +- lib/handle_unsuback.c | 2 +- lib/http_client.c | 2 +- lib/mosquitto.c | 2 +- lib/net_mosq.c | 2 +- lib/net_ws.c | 2 +- lib/options.c | 2 +- lib/packet_datatypes.c | 2 +- lib/packet_mosq.c | 2 +- lib/property_mosq.c | 2 +- lib/read_handle.c | 2 +- lib/send_connect.c | 2 +- lib/send_disconnect.c | 2 +- lib/send_mosq.c | 2 +- lib/send_publish.c | 2 +- lib/send_subscribe.c | 2 +- lib/send_unsubscribe.c | 2 +- lib/strings_mosq.c | 2 +- lib/will_mosq.c | 2 +- plugins/dynamic-security/acl.c | 5 +- plugins/dynamic-security/auth.c | 2 - plugins/dynamic-security/clientlist.c | 5 +- plugins/dynamic-security/clients.c | 5 +- plugins/dynamic-security/config.c | 7 +- plugins/dynamic-security/config_init.c | 9 +- plugins/dynamic-security/control.c | 7 +- plugins/dynamic-security/default_acl.c | 7 +- plugins/dynamic-security/dynamic_security.h | 4 +- plugins/dynamic-security/grouplist.c | 5 +- plugins/dynamic-security/groups.c | 5 +- plugins/dynamic-security/kicklist.c | 3 - plugins/dynamic-security/plugin.c | 7 +- plugins/dynamic-security/rolelist.c | 3 - plugins/dynamic-security/roles.c | 3 - plugins/dynamic-security/tick.c | 5 - .../add-properties/mosquitto_add_properties.c | 3 - .../auth-by-env/mosquitto_auth_by_env.c | 3 - .../auth-by-ip/mosquitto_auth_by_ip.c | 3 - .../mosquitto_client_lifetime_stats.c | 3 - .../mosquitto_client_properties.c | 3 - .../mosquitto_connection_state.c | 3 - .../delayed-auth/mosquitto_delayed_auth.c | 3 - .../mosquitto_deny_protocol_version.c | 3 - .../force-retain/mosquitto_force_retain.c | 3 - .../mosquitto_limit_subscription_qos.c | 3 - .../mosquitto_message_timestamp.c | 3 - .../payload-ban/mosquitto_payload_ban.c | 3 - .../mosquitto_payload_modification.c | 3 - .../mosquitto_payload_size_stats.c | 3 - .../mosquitto_plugin_event_stats.c | 3 +- .../mosquitto_print_ip_on_publish.c | 3 - .../topic-jail/mosquitto_topic_jail.c | 3 - .../mosquitto_topic_modification.c | 3 - .../wildcard-temp/mosquitto_wildcard_temp.c | 3 - plugins/persist-sqlite/base_msgs.c | 4 +- plugins/persist-sqlite/client_msgs.c | 2 +- plugins/persist-sqlite/clients.c | 2 +- plugins/persist-sqlite/init.c | 2 +- plugins/persist-sqlite/plugin.c | 6 +- plugins/persist-sqlite/restore.c | 4 +- plugins/persist-sqlite/retain_msgs.c | 2 +- plugins/persist-sqlite/subscriptions.c | 2 +- plugins/persist-sqlite/tick.c | 4 +- plugins/sparkplug-aware/on_message.c | 2 +- plugins/sparkplug-aware/plugin.c | 4 +- snap/snapcraft.yaml | 1 + src/CMakeLists.txt | 6 - src/Makefile | 3 - src/bridge.c | 2 +- src/broker_control.c | 8 +- src/conf.c | 2 +- src/conf_includedir.c | 2 +- src/control.c | 2 +- src/control_common.c | 6 +- src/handle_auth.c | 2 +- src/handle_connack.c | 2 +- src/handle_connect.c | 2 +- src/handle_disconnect.c | 2 +- src/handle_publish.c | 2 +- src/handle_subscribe.c | 2 +- src/handle_unsubscribe.c | 2 +- src/http_serv.c | 2 +- src/loop.c | 2 +- src/memory_public.c | 2 +- src/mosquitto_broker_internal.h | 4 +- src/net.c | 2 +- src/persist_read_v5.c | 2 +- src/persist_write_v5.c | 2 +- src/plugin_acl_check.c | 4 +- src/plugin_basic_auth.c | 4 +- src/plugin_cleanup.c | 4 +- src/plugin_extended_auth.c | 4 +- src/plugin_init.c | 4 +- src/plugin_persist.c | 4 +- src/plugin_psk_key.c | 4 +- src/plugin_public.c | 2 +- src/plugin_tick.c | 2 +- src/plugin_v2.c | 4 +- src/plugin_v3.c | 4 +- src/plugin_v4.c | 4 +- src/property_broker.c | 2 +- src/read_handle.c | 2 +- src/retain.c | 2 +- src/security_default.c | 2 +- src/send_auth.c | 2 +- src/send_connack.c | 2 +- src/send_suback.c | 2 +- src/send_unsuback.c | 2 +- src/subs.c | 2 +- src/topic_tok.c | 2 +- src/websockets.c | 2 +- test/broker/c/auth_plugin_acl.c | 4 +- test/broker/c/auth_plugin_acl_change.c | 4 +- test/broker/c/auth_plugin_acl_sub_denied.c | 4 +- test/broker/c/auth_plugin_context_params.c | 4 +- test/broker/c/auth_plugin_delayed.c | 4 +- test/broker/c/auth_plugin_extended_multiple.c | 4 +- test/broker/c/auth_plugin_extended_reauth.c | 4 +- test/broker/c/auth_plugin_extended_single.c | 4 +- test/broker/c/auth_plugin_extended_single2.c | 4 +- test/broker/c/auth_plugin_id_change.c | 4 +- test/broker/c/auth_plugin_msg_params.c | 4 +- test/broker/c/auth_plugin_publish.c | 6 +- test/broker/c/auth_plugin_pwd.c | 4 +- test/broker/c/auth_plugin_v3.c | 4 +- test/broker/c/auth_plugin_v4.c | 4 +- test/broker/c/auth_plugin_v5.c | 4 +- test/broker/c/auth_plugin_v5_control.c | 4 +- test/broker/c/bad_v1.c | 4 +- test/broker/c/bad_v3_1.c | 4 +- test/broker/c/bad_v3_2.c | 4 +- test/broker/c/bad_v3_3.c | 4 +- test/broker/c/bad_v3_4.c | 4 +- test/broker/c/bad_v3_5.c | 4 +- test/broker/c/bad_v3_6.c | 4 +- test/broker/c/bad_v3_7.c | 4 +- test/broker/c/bad_v4_1.c | 4 +- test/broker/c/bad_v4_2.c | 4 +- test/broker/c/bad_v4_3.c | 4 +- test/broker/c/bad_v4_4.c | 4 +- test/broker/c/bad_v5_1.c | 4 +- test/broker/c/bad_v6.c | 4 +- test/broker/c/plugin_control.c | 6 +- test/broker/c/plugin_evt_client_offline.c | 4 +- test/broker/c/plugin_evt_message_in.c | 4 +- test/broker/c/plugin_evt_message_out.c | 4 +- .../c/plugin_evt_persist_client_update.c | 4 +- test/broker/c/plugin_evt_psk_key.c | 6 +- test/broker/c/plugin_evt_subscribe.c | 4 +- test/broker/c/plugin_evt_tick.c | 4 +- test/broker/c/plugin_evt_unsubscribe.c | 4 +- test/lib/c/01-con-discon-success-v5.c | 2 +- test/lib/c/01-con-discon-will-v5.c | 2 +- test/lib/c/03-request-response-1.c | 2 +- test/lib/c/03-request-response-2.c | 2 +- .../lib/c/03-request-response-correlation-1.c | 2 +- test/lib/c/11-prop-recv.c | 2 +- test/lib/c/11-prop-send-content-type.c | 2 +- test/lib/c/11-prop-send-payload-format.c | 2 +- test/lib/cpp/01-con-discon-success-v5.cpp | 2 +- test/lib/cpp/01-con-discon-success.cpp | 2 +- test/lib/cpp/01-con-discon-will-clear.cpp | 2 +- test/lib/cpp/01-con-discon-will-v5.cpp | 2 +- test/lib/cpp/01-con-discon-will.cpp | 2 +- test/lib/cpp/01-keepalive-pingreq.cpp | 2 +- test/lib/cpp/01-no-clean-session.cpp | 2 +- test/lib/cpp/01-pre-connect-callback.cpp | 2 +- test/lib/cpp/01-server-keepalive-pingreq.cpp | 2 +- test/lib/cpp/01-unpwd-set.cpp | 2 +- test/lib/cpp/01-will-set.cpp | 2 +- test/lib/cpp/01-will-unpwd-set.cpp | 2 +- .../cpp/02-subscribe-helper-callback-qos2.cpp | 2 +- .../cpp/02-subscribe-helper-simple-qos2.cpp | 2 +- test/lib/cpp/02-subscribe-qos0.cpp | 2 +- test/lib/cpp/02-subscribe-qos1-async1.cpp | 2 +- test/lib/cpp/02-subscribe-qos1-async2.cpp | 2 +- test/lib/cpp/02-subscribe-qos1.cpp | 2 +- test/lib/cpp/02-subscribe-qos2.cpp | 2 +- test/lib/cpp/02-unsubscribe-v5.cpp | 2 +- test/lib/cpp/02-unsubscribe.cpp | 2 +- .../03-publish-b2c-qos1-unexpected-puback.cpp | 2 +- test/lib/cpp/03-publish-b2c-qos1.cpp | 2 +- test/lib/cpp/03-publish-b2c-qos2-len.cpp | 2 +- ...03-publish-b2c-qos2-unexpected-pubcomp.cpp | 2 +- .../03-publish-b2c-qos2-unexpected-pubrel.cpp | 2 +- test/lib/cpp/03-publish-b2c-qos2.cpp | 2 +- .../cpp/03-publish-c2b-qos1-disconnect.cpp | 2 +- test/lib/cpp/03-publish-c2b-qos1-len.cpp | 2 +- .../03-publish-c2b-qos1-receive-maximum.cpp | 2 +- .../cpp/03-publish-c2b-qos2-disconnect.cpp | 2 +- test/lib/cpp/03-publish-c2b-qos2-len.cpp | 2 +- .../cpp/03-publish-c2b-qos2-maximum-qos-0.cpp | 2 +- .../cpp/03-publish-c2b-qos2-maximum-qos-1.cpp | 2 +- .../cpp/03-publish-c2b-qos2-pubrec-error.cpp | 2 +- .../03-publish-c2b-qos2-receive-maximum.cpp | 2 +- test/lib/cpp/03-publish-c2b-qos2.cpp | 2 +- test/lib/cpp/03-publish-loop-forever.cpp | 2 +- test/lib/cpp/03-publish-loop-manual.cpp | 2 +- test/lib/cpp/03-publish-loop-start.cpp | 2 +- test/lib/cpp/03-publish-loop.cpp | 2 +- test/lib/cpp/03-publish-qos0-no-payload.cpp | 2 +- test/lib/cpp/03-publish-qos0.cpp | 2 +- test/lib/cpp/03-request-response-1.cpp | 2 +- test/lib/cpp/03-request-response-2.cpp | 2 +- .../cpp/03-request-response-correlation-1.cpp | 2 +- test/lib/cpp/04-retain-qos0.cpp | 2 +- test/lib/cpp/08-ssl-bad-cacert.cpp | 2 +- ...nnect-cert-auth-custom-ssl-ctx-default.cpp | 2 +- ...8-ssl-connect-cert-auth-custom-ssl-ctx.cpp | 2 +- test/lib/cpp/08-ssl-connect-cert-auth-enc.cpp | 2 +- test/lib/cpp/08-ssl-connect-cert-auth.cpp | 2 +- test/lib/cpp/08-ssl-connect-no-auth.cpp | 2 +- test/lib/cpp/08-ssl-connect-san.cpp | 2 +- test/lib/cpp/08-ssl-fake-cacert.cpp | 2 +- test/lib/cpp/09-util-topic-tokenise.cpp | 2 +- test/lib/cpp/11-prop-oversize-packet.cpp | 2 +- test/lib/cpp/11-prop-recv.cpp | 2 +- test/lib/cpp/11-prop-send-content-type.cpp | 2 +- test/lib/cpp/11-prop-send-payload-format.cpp | 2 +- test/unit/lib/property_add.c | 2 +- test/unit/lib/property_read.c | 2 +- test/unit/lib/property_user_read.c | 2 +- test/unit/lib/property_value.c | 2 +- test/unit/lib/property_write.c | 2 +- 288 files changed, 7001 insertions(+), 6225 deletions(-) create mode 100644 include/mosquitto/broker.h rename include/{mosquitto_control.h => mosquitto/broker_control.h} (90%) create mode 100644 include/mosquitto/broker_plugin.h create mode 100644 include/mosquitto/defs.h create mode 100644 include/mosquitto/libcommon.h create mode 100644 include/mosquitto/libcommon_properties.h create mode 100644 include/mosquitto/libcommon_string.h create mode 100644 include/mosquitto/libcommon_topic.h create mode 100644 include/mosquitto/libcommon_utf8.h create mode 100644 include/mosquitto/libmosquitto.h create mode 100644 include/mosquitto/libmosquitto_auth.h create mode 100644 include/mosquitto/libmosquitto_callbacks.h create mode 100644 include/mosquitto/libmosquitto_connect.h create mode 100644 include/mosquitto/libmosquitto_create_delete.h create mode 100644 include/mosquitto/libmosquitto_helpers.h create mode 100644 include/mosquitto/libmosquitto_loop.h create mode 100644 include/mosquitto/libmosquitto_message.h create mode 100644 include/mosquitto/libmosquitto_options.h create mode 100644 include/mosquitto/libmosquitto_publish.h create mode 100644 include/mosquitto/libmosquitto_socks.h create mode 100644 include/mosquitto/libmosquitto_subscribe.h create mode 100644 include/mosquitto/libmosquitto_tls.h create mode 100644 include/mosquitto/libmosquitto_unsubscribe.h create mode 100644 include/mosquitto/libmosquitto_will.h create mode 100644 include/mosquitto/libmosquittopp.h create mode 100644 include/mosquitto/mqtt_protocol.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5095af62..e8c6b36e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,28 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmosquitto.pc" DESTINATION "${CMAKE configure_file(libmosquittopp.pc.in libmosquittopp.pc @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmosquittopp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +# ======================================== +# Install headers +# ======================================== +install( + FILES + ${mosquitto_SOURCE_DIR}/include/mosquitto.h + ${mosquitto_SOURCE_DIR}/include/mosquitto_broker.h + ${mosquitto_SOURCE_DIR}/include/mosquitto_plugin.h + ${mosquitto_SOURCE_DIR}/include/mosquittopp.h + ${mosquitto_SOURCE_DIR}/include/mqtt_protocol.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) +install( + FILES + ${mosquitto_SOURCE_DIR}/include/mosquitto/broker.h + ${mosquitto_SOURCE_DIR}/include/mosquitto/broker_control.h + ${mosquitto_SOURCE_DIR}/include/mosquitto/broker_plugin.h + ${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquittopp.h + ${mosquitto_SOURCE_DIR}/include/mosquitto/mqtt_protocol.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/mosquitto" +) + # ======================================== # Testing # ======================================== @@ -180,3 +202,36 @@ if(WITH_TESTS) enable_testing() add_subdirectory(test) endif() +include +include/mosquitto_plugin.h +include/mosquitto.h +include/mosquittopp.h +include/mqtt_protocol.h +include/mosquitto_broker.h +include/mosquitto +include/mosquitto/libmosquitto_unsubscribe.h +include/mosquitto/libmosquitto.h +include/mosquitto/libmosquitto_loop.h +include/mosquitto/libmosquitto_subscribe.h +include/mosquitto/libcommon_topic.h +include/mosquitto/libmosquitto_socks.h +include/mosquitto/libmosquitto_helpers.h +include/mosquitto/libmosquittopp.h +include/mosquitto/broker.h +include/mosquitto/libmosquitto_options.h +include/mosquitto/broker_control.h +include/mosquitto/libcommon_string.h +include/mosquitto/libcommon_properties.h +include/mosquitto/libmosquitto_create_delete.h +include/mosquitto/mqtt_protocol.h +include/mosquitto/libmosquitto_will.h +include/mosquitto/broker_plugin.h +include/mosquitto/libmosquitto_message.h +include/mosquitto/libmosquitto_publish.h +include/mosquitto/libmosquitto_callbacks.h +include/mosquitto/libcommon_utf8.h +include/mosquitto/libmosquitto_auth.h +include/mosquitto/libmosquitto_connect.h +include/mosquitto/defs.h +include/mosquitto/libcommon.h +include/mosquitto/libmosquitto_tls.h diff --git a/ChangeLog.txt b/ChangeLog.txt index 8d7fbaa9..cc4907b8 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -188,6 +188,7 @@ Build: - Add an CMake option `WITH_LTO` to enable/disable link time optimization. - Set C99 as the explicit, rather than implicit, build standard. - cJSON is now a required dependency. +- Refactored headers for easier discovery. 2.0.17 - 2023-08-22 diff --git a/Makefile b/Makefile index 501bbd56..9255296a 100644 --- a/Makefile +++ b/Makefile @@ -109,6 +109,13 @@ endif $(INSTALL) -m 644 aclfile.example "${DESTDIR}/etc/mosquitto/aclfile.example" $(INSTALL) -m 644 pwfile.example "${DESTDIR}/etc/mosquitto/pwfile.example" $(INSTALL) -m 644 pskfile.example "${DESTDIR}/etc/mosquitto/pskfile.example" + $(INSTALL) -d "${DESTDIR}$(prefix)/include/mosquitto" + $(INSTALL) include/mosquitto/*.h "${DESTDIR}${prefix}/include/mosquitto/" + $(INSTALL) include/mosquitto.h "${DESTDIR}${prefix}/include/mosquitto.h" + $(INSTALL) include/mosquitto_broker.h "${DESTDIR}${prefix}/include/mosquitto_broker.h" + $(INSTALL) include/mosquitto_plugin.h "${DESTDIR}${prefix}/include/mosquitto_plugin.h" + $(INSTALL) include/mosquittopp.h "${DESTDIR}${prefix}/include/mosquittopp.h" + $(INSTALL) include/mqtt_protocol.h "${DESTDIR}${prefix}/include/mqtt_protocol.h" uninstall : set -e; for d in ${DIRS}; do $(MAKE) -C $${d} uninstall; done @@ -116,6 +123,16 @@ uninstall : rm -f "${DESTDIR}/etc/mosquitto/aclfile.example" rm -f "${DESTDIR}/etc/mosquitto/pwfile.example" rm -f "${DESTDIR}/etc/mosquitto/pskfile.example" + rm -f "${DESTDIR}${prefix}/include/mosquitto.h" + rm -f "${DESTDIR}${prefix}/include/mosquitto/broker.h" + rm -f "${DESTDIR}${prefix}/include/mosquitto/broker_control.h" + rm -f "${DESTDIR}${prefix}/include/mosquitto/broker_plugin.h" + rm -f "${DESTDIR}${prefix}/include/mosquitto/libmosquittopp.h" + rm -f "${DESTDIR}${prefix}/include/mosquitto/mqtt_protocol.h" + rm -f "${DESTDIR}${prefix}/include/mosquitto_broker.h" + rm -f "${DESTDIR}${prefix}/include/mosquitto_plugin.h" + rm -f "${DESTDIR}${prefix}/include/mosquittopp.h" + rm -f "${DESTDIR}${prefix}/include/mqtt_protocol.h" dist : reallyclean set -e; for d in ${DISTDIRS}; do $(MAKE) -C $${d} dist; done diff --git a/apps/db_dump/print.c b/apps/db_dump/print.c index f124b7ff..5aed249f 100644 --- a/apps/db_dump/print.c +++ b/apps/db_dump/print.c @@ -22,7 +22,7 @@ Contributors: #include "db_dump.h" #include #include -#include +#include #include #include diff --git a/apps/mosquitto_ctrl/client.c b/apps/mosquitto_ctrl/client.c index 86cdda14..e3a1f7a3 100644 --- a/apps/mosquitto_ctrl/client.c +++ b/apps/mosquitto_ctrl/client.c @@ -27,7 +27,7 @@ Contributors: #include #include -#include +#include #include "mosquitto_ctrl.h" static int run = 1; diff --git a/apps/mosquitto_ctrl/options.c b/apps/mosquitto_ctrl/options.c index 5f022962..346c09b0 100644 --- a/apps/mosquitto_ctrl/options.c +++ b/apps/mosquitto_ctrl/options.c @@ -35,7 +35,6 @@ Contributors: #endif #include -#include #include "mosquitto_ctrl.h" #include "get_password.h" diff --git a/client/client_props.c b/client/client_props.c index 5f93a404..7a540643 100644 --- a/client/client_props.c +++ b/client/client_props.c @@ -34,7 +34,6 @@ Contributors: #endif #include "mosquitto.h" -#include "mqtt_protocol.h" #include "client_shared.h" enum prop_type diff --git a/client/client_shared.c b/client/client_shared.c index 05312cb2..29a2e7d2 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -35,7 +35,6 @@ Contributors: #endif #include -#include #include "client_shared.h" #ifdef WITH_SOCKS diff --git a/client/pub_client.c b/client/pub_client.c index a0806046..5e785b8d 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -32,7 +32,6 @@ Contributors: #define snprintf sprintf_s #endif -#include #include #include "client_shared.h" #include "pub_shared.h" diff --git a/client/pub_shared.c b/client/pub_shared.c index 6b1aa389..57cb1033 100644 --- a/client/pub_shared.c +++ b/client/pub_shared.c @@ -32,7 +32,6 @@ Contributors: #endif #include -#include #include "client_shared.h" #include "pub_shared.h" diff --git a/client/rr_client.c b/client/rr_client.c index 480dff62..1ae30476 100644 --- a/client/rr_client.c +++ b/client/rr_client.c @@ -34,7 +34,6 @@ Contributors: #endif #include -#include #include "client_shared.h" #include "pub_shared.h" #include "sub_client_output.h" diff --git a/client/sub_client.c b/client/sub_client.c index cd4be9da..b69e1c8b 100644 --- a/client/sub_client.c +++ b/client/sub_client.c @@ -34,7 +34,6 @@ Contributors: #endif #include -#include #include "client_shared.h" #include "sub_client_output.h" diff --git a/client/sub_client_output.c b/client/sub_client_output.c index 8e684a82..91a14636 100644 --- a/client/sub_client_output.c +++ b/client/sub_client_output.c @@ -50,7 +50,6 @@ Contributors: #endif #include -#include #include "client_shared.h" #include "sub_client_output.h" diff --git a/common/base64_mosq.c b/common/base64_mosq.c index 461e9107..20b7da22 100644 --- a/common/base64_mosq.c +++ b/common/base64_mosq.c @@ -31,7 +31,6 @@ Contributors: #include #include "mosquitto.h" -#include "mosquitto_broker.h" #include "base64_mosq.h" #include "memory_mosq.h" diff --git a/include/mosquitto.h b/include/mosquitto.h index 5c1536ed..12eabdfe 100644 --- a/include/mosquitto.h +++ b/include/mosquitto.h @@ -15,3639 +15,16 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause Contributors: Roger Light - initial implementation and documentation. */ - #ifndef MOSQUITTO_H #define MOSQUITTO_H -/* - * File: mosquitto.h - * - * This header contains functions and definitions for use with libmosquitto, the Mosquitto client library. - * - * The definitions are also used in Mosquitto broker plugins, and some functions are available to plugins. - */ -#ifdef __cplusplus -extern "C" { -#endif +#include +#include +#include -#ifdef WIN32 -# ifdef mosquitto_EXPORTS -# define libmosq_EXPORT __declspec(dllexport) -# else -# ifndef LIBMOSQUITTO_STATIC -# ifdef libmosquitto_EXPORTS -# define libmosq_EXPORT __declspec(dllexport) -# else -# define libmosq_EXPORT __declspec(dllimport) -# endif -# else -# define libmosq_EXPORT -# endif -# endif -#else -# define libmosq_EXPORT -#endif - -#if defined(_MSC_VER) && _MSC_VER < 1900 && !defined(bool) -# ifndef __cplusplus -# define bool char -# define true 1 -# define false 0 -# endif -#else -# ifndef __cplusplus -# include -# endif -#endif - -#include -#include - -#include - -#define LIBMOSQUITTO_MAJOR 2 -#define LIBMOSQUITTO_MINOR 1 -#define LIBMOSQUITTO_REVISION 0 -/* LIBMOSQUITTO_VERSION_NUMBER looks like 1002001 for e.g. version 1.2.1. */ -#define LIBMOSQUITTO_VERSION_NUMBER (LIBMOSQUITTO_MAJOR*1000000+LIBMOSQUITTO_MINOR*1000+LIBMOSQUITTO_REVISION) - -/* Log types */ -#define MOSQ_LOG_NONE 0 -#define MOSQ_LOG_INFO (1<<0) -#define MOSQ_LOG_NOTICE (1<<1) -#define MOSQ_LOG_WARNING (1<<2) -#define MOSQ_LOG_ERR (1<<3) -#define MOSQ_LOG_DEBUG (1<<4) -#define MOSQ_LOG_SUBSCRIBE (1<<5) -#define MOSQ_LOG_UNSUBSCRIBE (1<<6) -#define MOSQ_LOG_WEBSOCKETS (1<<7) -#define MOSQ_LOG_INTERNAL 0x80000000U -#define MOSQ_LOG_ALL 0xFFFFFFFFU - -/* Enum: mosq_err_t - * Integer values returned from many libmosquitto functions. */ -enum mosq_err_t { - MOSQ_ERR_QUOTA_EXCEEDED = -6, - MOSQ_ERR_AUTH_DELAYED = -5, - MOSQ_ERR_AUTH_CONTINUE = -4, - MOSQ_ERR_NO_SUBSCRIBERS = -3, - MOSQ_ERR_SUB_EXISTS = -2, - 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, - MOSQ_ERR_PROXY = 16, - MOSQ_ERR_PLUGIN_DEFER = 17, - MOSQ_ERR_MALFORMED_UTF8 = 18, - MOSQ_ERR_KEEPALIVE = 19, - MOSQ_ERR_LOOKUP = 20, - MOSQ_ERR_MALFORMED_PACKET = 21, - MOSQ_ERR_DUPLICATE_PROPERTY = 22, - MOSQ_ERR_TLS_HANDSHAKE = 23, - MOSQ_ERR_QOS_NOT_SUPPORTED = 24, - MOSQ_ERR_OVERSIZE_PACKET = 25, - MOSQ_ERR_OCSP = 26, - MOSQ_ERR_TIMEOUT = 27, - /* 28, 29, 30 - was internal only, moved to MQTT v5 section. */ - MOSQ_ERR_ALREADY_EXISTS = 31, - MOSQ_ERR_PLUGIN_IGNORE = 32, - MOSQ_ERR_HTTP_BAD_ORIGIN = 33, - - /* MQTT v5 direct equivalents 128-255 */ - MOSQ_ERR_UNSPECIFIED = 128, - MOSQ_ERR_IMPLEMENTATION_SPECIFIC = 131, - MOSQ_ERR_CLIENT_IDENTIFIER_NOT_VALID = 133, - MOSQ_ERR_BAD_USERNAME_OR_PASSWORD = 134, - MOSQ_ERR_SERVER_UNAVAILABLE = 136, - MOSQ_ERR_SERVER_BUSY = 137, - MOSQ_ERR_BANNED = 138, - MOSQ_ERR_BAD_AUTHENTICATION_METHOD = 140, - MOSQ_ERR_SESSION_TAKEN_OVER = 142, - MOSQ_ERR_RECEIVE_MAXIMUM_EXCEEDED = 147, - MOSQ_ERR_TOPIC_ALIAS_INVALID = 148, - MOSQ_ERR_ADMINISTRATIVE_ACTION = 152, - MOSQ_ERR_RETAIN_NOT_SUPPORTED = 154, - MOSQ_ERR_CONNECTION_RATE_EXCEEDED = 159, -}; - -/* Enum: mosq_opt_t - * - * Client options. - * - * See , , and . - */ -enum mosq_opt_t { - MOSQ_OPT_PROTOCOL_VERSION = 1, - MOSQ_OPT_SSL_CTX = 2, - MOSQ_OPT_SSL_CTX_WITH_DEFAULTS = 3, - MOSQ_OPT_RECEIVE_MAXIMUM = 4, - MOSQ_OPT_SEND_MAXIMUM = 5, - MOSQ_OPT_TLS_KEYFORM = 6, - MOSQ_OPT_TLS_ENGINE = 7, - MOSQ_OPT_TLS_ENGINE_KPASS_SHA1 = 8, - MOSQ_OPT_TLS_OCSP_REQUIRED = 9, - MOSQ_OPT_TLS_ALPN = 10, - MOSQ_OPT_TCP_NODELAY = 11, - MOSQ_OPT_BIND_ADDRESS = 12, - MOSQ_OPT_TLS_USE_OS_CERTS = 13, - MOSQ_OPT_DISABLE_SOCKETPAIR = 14, - MOSQ_OPT_TRANSPORT = 15, - MOSQ_OPT_HTTP_PATH = 16, - MOSQ_OPT_HTTP_HEADER_SIZE = 17, -}; - -enum mosq_transport_t { - MOSQ_T_TCP = 1, - MOSQ_T_WEBSOCKETS = 2, -}; - -/* MQTT specification restricts client ids to a maximum of 23 characters */ -#define MOSQ_MQTT_ID_MAX_LENGTH 23 - -#define MQTT_PROTOCOL_V31 3 -#define MQTT_PROTOCOL_V311 4 -#define MQTT_PROTOCOL_V5 5 - -/* Struct: mosquitto_message - * - * Contains details of a PUBLISH message. - * - * int mid - the message/packet ID of the PUBLISH message, assuming this is a - * QoS 1 or 2 message. Will be set to 0 for QoS 0 messages. - * - * char *topic - the topic the message was delivered on. - * - * void *payload - the message payload. This will be payloadlen bytes long, and - * may be NULL if a zero length payload was sent. - * - * int payloadlen - the length of the payload, in bytes. - * - * int qos - the quality of service of the message, 0, 1, or 2. - * - * bool retain - set to true for stale retained messages. - */ -struct mosquitto_message{ - int mid; - char *topic; - void *payload; - int payloadlen; - int qos; - bool retain; -}; - -struct mosquitto; -typedef struct mqtt5__property mosquitto_property; - -struct mosquitto_message_v5{ - void *payload; - char *topic; - mosquitto_property *properties; - uint32_t payloadlen; - uint8_t qos; - bool retain; - uint8_t padding[2]; -}; - -/* - * Topic: Threads - * libmosquitto provides thread safe operation, with the exception of - * which is not thread safe. - * - * If the library has been compiled without thread support it is *not* - * guaranteed to be thread safe. - * - * If your application uses threads you must use to - * tell the library this is the case, otherwise it makes some optimisations - * for the single threaded case that may result in unexpected behaviour for - * the multi threaded case. - */ -/*************************************************** - * 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 - * socket is not available for writing at that time then the packet will not be - * sent. To ensure the packet is sent, call mosquitto_loop() (which must also - * be called to process incoming network data). - * This is especially important when disconnecting a client that has a will. If - * the broker does not receive the DISCONNECT command, it will assume that the - * client has disconnected unexpectedly and send the will. - * - * mosquitto_connect() - * mosquitto_disconnect() - * mosquitto_subscribe() - * mosquitto_unsubscribe() - * mosquitto_publish() - ***************************************************/ - - -/* ====================================================================== - * - * Section: Library version, init, and cleanup - * - * ====================================================================== */ -/* - * Function: mosquitto_lib_version - * - * Can be used to obtain version information for the mosquitto library. - * This allows the application to compare the library version against the - * version it was compiled against by using the LIBMOSQUITTO_MAJOR, - * LIBMOSQUITTO_MINOR and LIBMOSQUITTO_REVISION defines. - * - * Parameters: - * major - an integer pointer. If not NULL, the major version of the - * library will be returned in this variable. - * minor - an integer pointer. If not NULL, the minor version of the - * library will be returned in this variable. - * revision - an integer pointer. If not NULL, the revision of the library will - * be returned in this variable. - * - * Returns: - * 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); - -/* - * Function: mosquitto_lib_init - * - * Must be called before any other mosquitto functions. - * - * This function is *not* thread safe. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_UNKNOWN - on Windows, if sockets couldn't be initialized. - * - * See Also: - * , - */ -libmosq_EXPORT int mosquitto_lib_init(void); - -/* - * Function: mosquitto_lib_cleanup - * - * Call to free resources associated with the library. - * - * Returns: - * MOSQ_ERR_SUCCESS - always - * - * See Also: - * , - */ -libmosq_EXPORT int mosquitto_lib_cleanup(void); - - -/* ====================================================================== - * - * Section: Client creation, destruction, and reinitialisation - * - * ====================================================================== */ -/* - * Function: mosquitto_new - * - * 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 - * 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 - * messages on disconnect. Calling or - * will cause the messages to be resent. - * 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 - * callbacks that are specified. - * - * Returns: - * 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. - * - * See Also: - * , - */ -libmosq_EXPORT void mosquitto_destroy(struct mosquitto *mosq); - -/* - * Function: mosquitto_reinitialise - * - * This function allows an existing mosquitto client to be reused. Call on a - * mosquitto instance to close any open network connections, free memory - * and reinitialise the client with the new parameters. The end result is the - * 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 - * 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 - * 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_MALFORMED_UTF8 - if the client id is not valid UTF-8. - * - * See Also: - * , - */ -libmosq_EXPORT int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_session, void *obj); - - -/* ====================================================================== - * - * Section: Will - * - * ====================================================================== */ -/* - * 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 . - * - * It is valid to use this function for clients using all MQTT protocol versions. - * If you need to set MQTT v5 Will properties, use instead. - * - * 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 - * 268,435,455. - * 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 - * used for the will. - * 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_MALFORMED_UTF8 - if the topic is not valid UTF-8. - */ -libmosq_EXPORT int mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain); - -/* - * Function: mosquitto_will_set_v5 - * - * Configure will information for a mosquitto instance, with attached - * properties. By default, clients do not have a will. This must be called - * before calling . - * - * If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument - * will be applied to the Will. For MQTT v3.1.1 and below, the `properties` - * argument will be ignored. - * - * Set your client to use MQTT v5 immediately after it is created: - * - * mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); - * - * 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 - * 268,435,455. - * 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 - * used for the will. - * retain - set to true to make the will a retained message. - * properties - list of MQTT 5 properties. Can be NULL. On success only, the - * property list becomes the property of libmosquitto once this - * function is called and will be freed by the library. The - * property list must be freed by the application on error. - * - * 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_MALFORMED_UTF8 - if the topic is not valid UTF-8. - * MOSQ_ERR_NOT_SUPPORTED - if properties is not NULL and the client is not - * using MQTT v5 - * MOSQ_ERR_PROTOCOL - if a property is invalid for use with wills. - * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. - */ -libmosq_EXPORT int mosquitto_will_set_v5(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain, mosquitto_property *properties); - -/* - * Function: mosquitto_will_clear - * - * Remove a previously configured will. This must be called before calling - * . - * - * Parameters: - * mosq - a valid mosquitto instance. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid. - */ -libmosq_EXPORT int mosquitto_will_clear(struct mosquitto *mosq); - - -/* ====================================================================== - * - * Section: Username and password - * - * ====================================================================== */ -/* - * Function: mosquitto_username_pw_set - * - * Configure username and password for a mosquitto instance. By default, no - * username or password will be sent. For v3.1 and v3.1.1 clients, if username - * is NULL, the password argument is ignored. - * - * 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 - * authentication. - * 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. - */ -libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char *username, const char *password); - - -/* ====================================================================== - * - * Section: Connecting, reconnecting, disconnecting - * - * ====================================================================== */ -/* - * Function: mosquitto_connect - * - * Connect to an MQTT broker. - * - * It is valid to use this function for clients using all MQTT protocol versions. - * If you need to set MQTT v5 CONNECT properties, use - * instead. - * - * 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 client should send a PING - * message to the broker 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, which could be any of: - * * mosq == NULL - * * host == NULL - * * port < 0 - * * keepalive < 5 - * 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); - -/* - * 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. - * - * 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 client should send a PING - * message to the broker 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. If you do not want to bind to a specific interface, - * set this to NULL. - * - * 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 - * 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); - -/* - * Function: mosquitto_connect_bind_v5 - * - * Connect to an MQTT broker. This extends the functionality of - * by adding the bind_address parameter and MQTT v5 - * properties. Use this function if you need to restrict network communication - * over a particular interface. - * - * Use e.g. and similar to create a list of - * properties, then attach them to this publish. Properties need freeing with - * . - * - * If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument - * will be applied to the CONNECT message. For MQTT v3.1.1 and below, the - * `properties` argument will be ignored. - * - * Set your client to use MQTT v5 immediately after it is created: - * - * mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); - * - * 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 client should send a PING - * message to the broker 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. If you do not want to bind to a specific interface, - * set this to NULL. - * properties - the MQTT 5 properties for the connect (not for the Will). - * - * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid, which could be any of: - * * mosq == NULL - * * host == NULL - * * port < 0 - * * keepalive < 5 - * 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. - * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. - * MOSQ_ERR_PROTOCOL - if any property is invalid for use with CONNECT. - * - * See Also: - * , , - */ -libmosq_EXPORT int mosquitto_connect_bind_v5(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address, const mosquitto_property *properties); - -/* - * Function: mosquitto_connect_async - * - * Connect to an MQTT broker. This is a non-blocking call. If you use - * your client must use the threaded interface - * . If you need to use , you must use - * to connect the client. - * - * 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 client should send a PING - * message to the broker 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 - * 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); - -/* - * Function: mosquitto_connect_bind_async - * - * Connect to an MQTT broker. This is a non-blocking call. If you use - * your client must use the threaded interface - * . If you need to use , you must use - * to connect the client. - * - * 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. - * - * 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 client should send a PING - * message to the broker 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. If you do not want to bind to a specific interface, - * set this to NULL. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid, which could be any of: - * * mosq == NULL - * * host == NULL - * * port < 0 - * * keepalive < 5 - * 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); - -/* - * Function: mosquitto_connect_srv - * - * Connect to an MQTT broker. - * - * If you set `host` to `example.com`, then this call will attempt to retrieve - * the DNS SRV record for `_secure-mqtt._tcp.example.com` or - * `_mqtt._tcp.example.com` to discover which actual host to connect to. - * - * DNS SRV support is not usually compiled in to libmosquitto, use of this call - * is not recommended. - * - * Parameters: - * mosq - a valid mosquitto instance. - * host - the hostname to search for an SRV record. - * keepalive - the number of seconds after which the client should send a PING - * message to the broker 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. If you do not want to bind to a specific interface, - * set this to NULL. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success. - * MOSQ_ERR_INVAL - if the input parameters were invalid, which could be any of: - * * mosq == NULL - * * host == NULL - * * port < 0 - * * keepalive < 5 - * 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); - -/* - * Function: mosquitto_reconnect - * - * Reconnect to a broker. - * - * This function provides an easy way of reconnecting to a broker after a - * 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. - * - * 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_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); - -/* - * Function: mosquitto_reconnect_async - * - * Reconnect to a broker. Non blocking version of . - * - * This function provides an easy way of reconnecting to a broker after a - * 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. - * - * 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_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); - -/* - * Function: mosquitto_disconnect - * - * Disconnect from the broker. - * - * It is valid to use this function for clients using all MQTT protocol versions. - * If you need to set MQTT v5 DISCONNECT properties, use - * instead. - * - * Parameters: - * 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. - */ -libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq); - -/* - * Function: mosquitto_disconnect_v5 - * - * Disconnect from the broker, with attached MQTT properties. - * - * Use e.g. and similar to create a list of - * properties, then attach them to this publish. Properties need freeing with - * . - * - * If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument - * will be applied to the DISCONNECT message. For MQTT v3.1.1 and below, the - * `properties` argument will be ignored. - * - * Set your client to use MQTT v5 immediately after it is created: - * - * mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); - * - * Parameters: - * mosq - a valid mosquitto instance. - * reason_code - the disconnect reason code. - * properties - a valid mosquitto_property list, or NULL. - * - * 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_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. - * MOSQ_ERR_PROTOCOL - if any property is invalid for use with DISCONNECT. - */ -libmosq_EXPORT int mosquitto_disconnect_v5(struct mosquitto *mosq, int reason_code, const mosquitto_property *properties); - - -/* ====================================================================== - * - * Section: Publishing, subscribing, unsubscribing - * - * ====================================================================== */ -/* - * Function: mosquitto_publish - * - * Publish a message on a given topic. - * - * It is valid to use this function for clients using all MQTT protocol versions. - * If you need to set MQTT v5 PUBLISH properties, use - * instead. - * - * Parameters: - * 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. - * topic - null terminated string of the topic to publish to. - * 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 - * valid memory location. - * 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. - * - * 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 - * broker. - * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large. - * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8 - * MOSQ_ERR_QOS_NOT_SUPPORTED - if the QoS is greater than that supported by - * the broker. - * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than - * supported by the broker. - * - * See Also: - * - */ -libmosq_EXPORT int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int payloadlen, const void *payload, int qos, bool retain); - - -/* - * Function: mosquitto_publish_v5 - * - * Publish a message on a given topic, with attached MQTT properties. - * - * Use e.g. and similar to create a list of - * properties, then attach them to this publish. Properties need freeing with - * . - * - * If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument - * will be applied to the PUBLISH message. For MQTT v3.1.1 and below, the - * `properties` argument will be ignored. - * - * Set your client to use MQTT v5 immediately after it is created: - * - * mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); - * - * Parameters: - * 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. - * topic - null terminated string of the topic to publish to. - * 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 - * valid memory location. - * 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. - * properties - a valid mosquitto_property list, or NULL. - * - * 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 - * broker. - * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large. - * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8 - * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. - * MOSQ_ERR_PROTOCOL - if any property is invalid for use with PUBLISH. - * MOSQ_ERR_QOS_NOT_SUPPORTED - if the QoS is greater than that supported by - * the broker. - * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than - * supported by the broker. - */ -libmosq_EXPORT int mosquitto_publish_v5( - struct mosquitto *mosq, - int *mid, - const char *topic, - int payloadlen, - const void *payload, - int qos, - bool retain, - const mosquitto_property *properties); - - -/* - * Function: mosquitto_subscribe - * - * Subscribe to a topic. - * - * It is valid to use this function for clients using all MQTT protocol versions. - * If you need to set MQTT v5 SUBSCRIBE properties, use - * instead. - * - * 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 - must not be NULL or an empty string. - * 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_MALFORMED_UTF8 - if the topic is not valid UTF-8 - * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than - * supported by the broker. - */ -libmosq_EXPORT int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const char *sub, int qos); - -/* - * Function: mosquitto_subscribe_v5 - * - * Subscribe to a topic, with attached MQTT properties. - * - * Use e.g. and similar to create a list of - * properties, then attach them to this publish. Properties need freeing with - * . - * - * If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument - * will be applied to the PUBLISH message. For MQTT v3.1.1 and below, the - * `properties` argument will be ignored. - * - * Set your client to use MQTT v5 immediately after it is created: - * - * mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); - * - * 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 - must not be NULL or an empty string. - * qos - the requested Quality of Service for this subscription. - * options - options to apply to this subscription, OR'd together. Set to 0 to - * use the default options, otherwise choose from list of - * properties - a valid mosquitto_property list, or NULL. - * - * 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_MALFORMED_UTF8 - if the topic is not valid UTF-8 - * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. - * MOSQ_ERR_PROTOCOL - if any property is invalid for use with SUBSCRIBE. - * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than - * supported by the broker. - */ -libmosq_EXPORT int mosquitto_subscribe_v5(struct mosquitto *mosq, int *mid, const char *sub, int qos, int options, const mosquitto_property *properties); - -/* - * Function: mosquitto_subscribe_multiple - * - * Subscribe to multiple topics. - * - * 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_count - the count of subscriptions to be made - * sub - array of sub_count pointers, each pointing to a subscription string. - * The "char *const *const" datatype ensures that neither the array of - * pointers nor the strings that they point to are mutable. If you aren't - * familiar with this, just think of it as a safer "char **", - * equivalent to "const char *" for a simple string pointer. - * Each string must not be NULL or an empty string. - * qos - the requested Quality of Service for each subscription. - * options - options to apply to this subscription, OR'd together. This - * argument is not used for MQTT v3 susbcriptions. Set to 0 to use - * the default options, otherwise choose from list of - * properties - a valid mosquitto_property list, or NULL. Only used with MQTT - * v5 clients. - * - * 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_MALFORMED_UTF8 - if a topic is not valid UTF-8 - * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than - * supported by the broker. - */ -libmosq_EXPORT int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, int qos, int options, const mosquitto_property *properties); - -/* - * Function: mosquitto_unsubscribe - * - * 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 - must not by NULL or an empty string. - * - * 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_MALFORMED_UTF8 - if the topic is not valid UTF-8 - * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than - * supported by the broker. - */ -libmosq_EXPORT int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub); - -/* - * Function: mosquitto_unsubscribe_v5 - * - * Unsubscribe from a topic, with attached MQTT properties. - * - * It is valid to use this function for clients using all MQTT protocol versions. - * If you need to set MQTT v5 UNSUBSCRIBE properties, use - * instead. - * - * Use e.g. and similar to create a list of - * properties, then attach them to this publish. Properties need freeing with - * . - * - * If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument - * will be applied to the PUBLISH message. For MQTT v3.1.1 and below, the - * `properties` argument will be ignored. - * - * Set your client to use MQTT v5 immediately after it is created: - * - * mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); - * - * 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 - must not by NULL or an empty string. - * properties - a valid mosquitto_property list, or NULL. Only used with MQTT - * v5 clients. - * - * 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_MALFORMED_UTF8 - if the topic is not valid UTF-8 - * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. - * MOSQ_ERR_PROTOCOL - if any property is invalid for use with UNSUBSCRIBE. - * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than - * supported by the broker. - */ -libmosq_EXPORT int mosquitto_unsubscribe_v5(struct mosquitto *mosq, int *mid, const char *sub, const mosquitto_property *properties); - -/* - * Function: mosquitto_unsubscribe_multiple - * - * Unsubscribe from multiple topics. - * - * 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_count - the count of unsubscriptions to be made - * sub - array of sub_count pointers, each pointing to an unsubscription string. - * The "char *const *const" datatype ensures that neither the array of - * pointers nor the strings that they point to are mutable. If you aren't - * familiar with this, just think of it as a safer "char **", - * equivalent to "const char *" for a simple string pointer. - * Each sub must not be NULL or an empty string. - * properties - a valid mosquitto_property list, or NULL. Only used with MQTT - * v5 clients. - * - * 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_MALFORMED_UTF8 - if a topic is not valid UTF-8 - * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than - * supported by the broker. - */ -libmosq_EXPORT int mosquitto_unsubscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, const mosquitto_property *properties); - - -/* ====================================================================== - * - * Section: Struct mosquitto_message helper functions - * - * ====================================================================== */ -/* - * Function: mosquitto_message_copy - * - * Copy the contents of a mosquitto message to another message. - * 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. - * - * 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. - * - * See Also: - * - */ -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. - * - * See Also: - * , - */ -libmosq_EXPORT void mosquitto_message_free(struct mosquitto_message **message); - -/* - * Function: mosquitto_message_free_contents - * - * Free a mosquitto_message struct contents, leaving the struct unaffected. - * - * Parameters: - * message - pointer to a mosquitto_message struct to free its contents. - * - * See Also: - * , - */ -libmosq_EXPORT void mosquitto_message_free_contents(struct mosquitto_message *message); - - -/* ====================================================================== - * - * Section: Network loop (managed by libmosquitto) - * - * The internal network loop must be called at a regular interval. The two - * recommended approaches are to use either or - * . is a blocking call and is - * suitable for the situation where you only want to handle incoming messages - * in callbacks. is a non-blocking call, it creates a - * separate thread to run the loop for you. Use this function when you have - * other tasks you need to run at the same time as the MQTT client, e.g. - * reading data from a sensor. - * - * ====================================================================== */ - -/* - * Function: mosquitto_loop_forever - * - * This function call loop() for you in an infinite blocking loop. It is useful - * for the case where you only want to run the MQTT client loop in your - * program. - * - * It handles reconnecting in case server connection is lost. If you call - * mosquitto_disconnect() in a callback it will return. - * - * 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. - * - * 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_CONN_LOST - if the connection to the broker was lost. - * 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 - * 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); - -/* - * Function: mosquitto_loop_start - * - * This is part of the threaded client interface. Call this once to start a new - * thread to process network traffic. This provides an alternative to - * repeatedly calling yourself. - * - * Parameters: - * 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. - * - * See Also: - * , , , - */ -libmosq_EXPORT int mosquitto_loop_start(struct mosquitto *mosq); - -/* - * Function: mosquitto_loop_stop - * - * This is part of the threaded client interface. Call this once to stop the - * network thread previously created with . This call - * will block until the network thread finishes. For the network thread to end, - * you must have previously called or have set the force - * parameter to true. - * - * Parameters: - * mosq - a valid mosquitto instance. - * 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. - * - * See Also: - * , - */ -libmosq_EXPORT int mosquitto_loop_stop(struct mosquitto *mosq, bool force); - -/* - * Function: mosquitto_loop - * - * The main network loop for the client. This must be called frequently - * to keep communications between the client and broker working. This is - * carried out by and , which - * are the recommended ways of handling the network loop. You may also use this - * function if you wish. It must not be called inside a callback. - * - * If incoming data is present it will then be processed. Outgoing commands, - * from e.g. , are normally sent immediately that their - * function is called, but this is not always possible. will - * also attempt to send any remaining outgoing messages, which also includes - * commands that are part of the flow for messages with QoS>0. - * - * This calls select() to monitor the client network socket. If you want to - * integrate mosquitto client operation with your own select() call, use - * , , and - * . - * - * 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. - * - * 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_CONN_LOST - if the connection to the broker was lost. - * 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 - * 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); - -/* ====================================================================== - * - * Section: Network loop (for use in other event loops) - * - * ====================================================================== */ -/* - * Function: mosquitto_loop_read - * - * Carry out network read operations. - * This should only be used if you are not using mosquitto_loop() and are - * 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. - * - * 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_CONN_LOST - if the connection to the broker was lost. - * 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 - * 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); - -/* - * Function: mosquitto_loop_write - * - * Carry out network write operations. - * This should only be used if you are not using mosquitto_loop() and are - * 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. - * - * 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_CONN_LOST - if the connection to the broker was lost. - * 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 - * 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); - -/* - * Function: mosquitto_loop_misc - * - * Carry out miscellaneous operations required as part of the network loop. - * This should only be used if you are not using mosquitto_loop() and are - * monitoring the client network socket for activity yourself. - * - * This function deals with handling PINGs and checking whether messages need - * to be retried, so should be called fairly frequently, around once per second - * is sufficient. - * - * Parameters: - * 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. - * - * See Also: - * , , - */ -libmosq_EXPORT int mosquitto_loop_misc(struct mosquitto *mosq); - - -/* ====================================================================== - * - * Section: Network loop (helper functions) - * - * ====================================================================== */ -/* - * Function: mosquitto_socket - * - * Return the socket handle for a mosquitto instance. Useful if you want to - * include a mosquitto client in your own select() calls. - * - * Parameters: - * mosq - a valid mosquitto instance. - * - * Returns: - * The socket for the mosquitto client or -1 on failure. - */ -libmosq_EXPORT int mosquitto_socket(struct mosquitto *mosq); - -/* - * Function: mosquitto_want_write - * - * Returns true if there is data ready to be written on the socket. - * - * Parameters: - * mosq - a valid mosquitto instance. - * - * See Also: - * , , - */ -libmosq_EXPORT bool mosquitto_want_write(struct mosquitto *mosq); - -/* - * Function: mosquitto_threaded_set - * - * Used to tell the library that your application is using threads, but not - * using . The library operates slightly differently when - * not in threaded mode in order to simplify its operation. If you are managing - * your own threads and do not use this function you will experience crashes - * due to race conditions. - * - * When using , this is set automatically. - * - * Parameters: - * mosq - a valid mosquitto instance. - * threaded - true if your application is using threads, false otherwise. - */ -libmosq_EXPORT int mosquitto_threaded_set(struct mosquitto *mosq, bool threaded); - - -/* ====================================================================== - * - * Section: Client options - * - * ====================================================================== */ -/* - * Function: mosquitto_opts_set - * - * Used to set options for the client. - * - * This function is deprecated, the replacement , - * and functions should - * be used instead. - * - * Parameters: - * mosq - a valid mosquitto instance. - * option - the option to set. - * value - the option specific value. - * - * Options: - * MOSQ_OPT_PROTOCOL_VERSION - Value must be an int, set to either - * MQTT_PROTOCOL_V31 or MQTT_PROTOCOL_V311. Must be set - * before the client connects. - * Defaults to MQTT_PROTOCOL_V31. - * - * MOSQ_OPT_SSL_CTX - Pass an openssl SSL_CTX to be used when creating - * TLS connections rather than libmosquitto creating its own. - * This must be called before connecting to have any effect. - * If you use this option, the onus is on you to ensure that - * you are using secure settings. - * Setting to NULL means that libmosquitto will use its own SSL_CTX - * if TLS is to be used. - * This option is only available for openssl 1.1.0 and higher. - * - * MOSQ_OPT_SSL_CTX_WITH_DEFAULTS - Value must be an int set to 1 or 0. - * If set to 1, then the user specified SSL_CTX passed in using - * MOSQ_OPT_SSL_CTX will have the default options applied to it. - * This means that you only need to change the values that are - * relevant to you. If you use this option then you must configure - * the TLS options as normal, i.e. you should use - * to configure the cafile/capath as a minimum. - * This option is only available for openssl 1.1.0 and higher. - */ -libmosq_EXPORT int mosquitto_opts_set(struct mosquitto *mosq, enum mosq_opt_t option, void *value); - -/* - * Function: mosquitto_int_option - * - * Used to set integer options for the client. - * - * Parameters: - * mosq - a valid mosquitto instance. - * option - the option to set. - * value - the option specific value. - * - * Options: - * MOSQ_OPT_TCP_NODELAY - Set to 1 to disable Nagle's algorithm on client - * sockets. This has the effect of reducing latency of individual - * messages at the potential cost of increasing the number of - * packets being sent. - * Defaults to 0, which means Nagle remains enabled. - * - * MOSQ_OPT_PROTOCOL_VERSION - Value must be set to either MQTT_PROTOCOL_V31, - * MQTT_PROTOCOL_V311, or MQTT_PROTOCOL_V5. Must be set before the - * client connects. Defaults to MQTT_PROTOCOL_V311. - * - * MOSQ_OPT_RECEIVE_MAXIMUM - Value can be set between 1 and 65535 inclusive, - * and represents the maximum number of incoming QoS 1 and QoS 2 - * messages that this client wants to process at once. Defaults to - * 20. This option is not valid for MQTT v3.1 or v3.1.1 clients. - * Note that if the MQTT_PROP_RECEIVE_MAXIMUM property is in the - * proplist passed to mosquitto_connect_v5(), then that property - * will override this option. Using this option is the recommended - * method however. - * - * MOSQ_OPT_SEND_MAXIMUM - Value can be set between 1 and 65535 inclusive, - * and represents the maximum number of outgoing QoS 1 and QoS 2 - * messages that this client will attempt to have "in flight" at - * once. Defaults to 20. - * This option is not valid for MQTT v3.1 or v3.1.1 clients. - * Note that if the broker being connected to sends a - * MQTT_PROP_RECEIVE_MAXIMUM property that has a lower value than - * this option, then the broker provided value will be used. - * - * MOSQ_OPT_SSL_CTX_WITH_DEFAULTS - If value is set to a non zero value, - * then the user specified SSL_CTX passed in using MOSQ_OPT_SSL_CTX - * will have the default options applied to it. This means that - * you only need to change the values that are relevant to you. - * If you use this option then you must configure the TLS options - * as normal, i.e. you should use to - * configure the cafile/capath as a minimum. - * This option is only available for openssl 1.1.0 and higher. - * - * MOSQ_OPT_TLS_OCSP_REQUIRED - Set whether OCSP checking on TLS - * connections is required. Set to 1 to enable checking, - * or 0 (the default) for no checking. - * - * MOSQ_OPT_TLS_USE_OS_CERTS - Set to 1 to instruct the client to load and - * trust OS provided CA certificates for use with TLS connections. - * Set to 0 (the default) to only use manually specified CA certs. - * - * MOSQ_OPT_DISABLE_SOCKETPAIR - By default, each client connected will create - * an internal pair of connected sockets to allow the network thread - * to be notified and woken up if another thread calls - * or other similar command. If you are - * operating with an external loop, this is not necessary and - * consumes an extra two sockets per client. Set this option to 1 to - * disable the use of the socket pair. - * - * MOSQ_OPT_TRANSPORT - Have the client connect with either MQTT over TCP as - * normal, or MQTT over WebSockets. Set the value to MOSQ_T_TCP or - * MOSQ_T_WEBSOCKETS. - * - * MOSQ_OPT_HTTP_HEADER_SIZE - Size the size of buffer that will be allocated - * to store the incoming HTTP header when using Websocket transport. - * Defaults to 4096. Setting to below 100 will result in a return -* value of MOSQ_ERR_INVAL. This should be set before starting the -* connection. If you try to set this when the initial http request -* is underway then it will return MOSQ_ERR_INVAL. - */ -libmosq_EXPORT int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t option, int value); - - -/* - * Function: mosquitto_string_option - * - * Used to set const char* options for the client. - * - * Parameters: - * mosq - a valid mosquitto instance. - * option - the option to set. - * value - the option specific value. - * - * Options: - * MOSQ_OPT_TLS_ENGINE - Configure the client for TLS Engine support. - * Pass a TLS Engine ID to be used when creating TLS - * connections. Must be set before . - * Must be a valid engine, and note that the string will not be used - * until a connection attempt is made so this function will return - * success even if an invalid engine string is passed. - * - * MOSQ_OPT_TLS_KEYFORM - Configure the client to treat the keyfile - * differently depending on its type. Must be set - * before . - * Set as either "pem" or "engine", to determine from where the - * private key for a TLS connection will be obtained. Defaults to - * "pem", a normal private key file. - * - * MOSQ_OPT_TLS_KPASS_SHA1 - Where the TLS Engine requires the use of - * a password to be accessed, this option allows a hex encoded - * SHA1 hash of the private key password to be passed to the - * engine directly. Must be set before . - * - * MOSQ_OPT_TLS_ALPN - If the broker being connected to has multiple - * services available on a single TLS port, such as both MQTT - * and WebSockets, use this option to configure the ALPN - * option for the connection. - * - * MOSQ_OPT_BIND_ADDRESS - Set the hostname or ip address of the local network - * interface to bind to when connecting. - */ -libmosq_EXPORT int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, const char *value); - - -/* - * Function: mosquitto_void_option - * - * Used to set void* options for the client. - * - * Parameters: - * mosq - a valid mosquitto instance. - * option - the option to set. - * value - the option specific value. - * - * Options: - * MOSQ_OPT_SSL_CTX - Pass an openssl SSL_CTX to be used when creating TLS - * connections rather than libmosquitto creating its own. This must - * be called before connecting to have any effect. If you use this - * option, the onus is on you to ensure that you are using secure - * settings. - * Setting to NULL means that libmosquitto will use its own SSL_CTX - * if TLS is to be used. - * This option is only available for openssl 1.1.0 and higher. - */ -libmosq_EXPORT int mosquitto_void_option(struct mosquitto *mosq, enum mosq_opt_t option, void *value); - -/* - * Function: mosquitto_reconnect_delay_set - * - * Control the behaviour of the client when it has unexpectedly disconnected in - * or after . The default - * behaviour if this function is not used is to repeatedly attempt to reconnect - * with a delay of 1 second until the connection succeeds. - * - * Use reconnect_delay parameter to change the delay between successive - * reconnection attempts. You may also enable exponential backoff of the time - * between reconnections by setting reconnect_exponential_backoff to true and - * 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, ... - * - * Example 2: - * delay=3, delay_max=30, exponential_backoff=True - * Delays would be: 3, 6, 12, 24, 30, 30, ... - * - * Parameters: - * mosq - a valid mosquitto instance. - * reconnect_delay - the number of seconds to wait between - * reconnects. - * reconnect_delay_max - the maximum number of seconds to wait - * between reconnects. - * reconnect_exponential_backoff - use exponential backoff between - * reconnect attempts. Set to true to enable - * exponential backoff. - * - * Returns: - * 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); - -/* - * Function: mosquitto_max_inflight_messages_set - * - * This function is deprected. Use the function with the - * MOSQ_OPT_SEND_MAXIMUM option instead. - * - * Set the number of QoS 1 and 2 messages that can be "in flight" at one time. - * An in flight message is part way through its delivery flow. Attempts to send - * further messages with will result in the messages being - * queued until the number of in flight messages reduces. - * - * A higher number here results in greater message throughput, but if set - * higher than the maximum in flight messages on the broker may lead to - * delays in the messages being acknowledged. - * - * Set to 0 for no maximum. - * - * Parameters: - * mosq - a valid mosquitto instance. - * max_inflight_messages - the maximum number of inflight messages. Defaults - * to 20. - * - * Returns: - * 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); - -/* - * Function: mosquitto_message_retry_set - * - * This function now has no effect. - */ -libmosq_EXPORT void mosquitto_message_retry_set(struct mosquitto *mosq, unsigned int message_retry); - -/* - * Function: mosquitto_user_data_set - * - * When is called, the pointer given as the "obj" parameter - * will be passed to the callbacks as user data. The - * function allows this obj parameter to be updated at any time. This function - * will not modify the memory pointed to by the current user data pointer. If - * it is dynamically allocated memory you must free it yourself. - * - * Parameters: - * mosq - a valid mosquitto instance. - * 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); - -/* Function: mosquitto_userdata - * - * Retrieve the "userdata" variable for a mosquitto client. - * - * Parameters: - * mosq - a valid mosquitto instance. - * - * Returns: - * A pointer to the userdata member variable. - */ -libmosq_EXPORT void *mosquitto_userdata(struct mosquitto *mosq); - - -/* ====================================================================== - * - * Section: TLS support - * - * ====================================================================== */ -/* - * Function: mosquitto_tls_set - * - * Configure the client for certificate based SSL/TLS support. Must be called - * before . - * - * Cannot be used in conjunction with . - * - * Define the Certificate Authority certificates to be trusted (ie. the server - * certificate must be signed with one of these certificates) using cafile. - * - * If the server you are connecting to requires clients to provide a - * certificate, define certfile and keyfile with your client certificate and - * private key. If your private key is encrypted, provide a password callback - * function or you will have to enter the password at the command line. - * - * Parameters: - * mosq - a valid mosquitto instance. - * cafile - path to a file containing the PEM encoded trusted CA - * certificate files. Either cafile or capath must not be NULL. - * capath - path to a directory containing the PEM encoded trusted CA - * certificate files. See mosquitto.conf for more details on - * configuring this directory. Either cafile or capath must not - * be NULL. - * certfile - path to a file containing the PEM encoded certificate file - * for this client. If NULL, keyfile must also be NULL and no - * client certificate will be used. - * keyfile - path to a file containing the PEM encoded private key for - * this client. If NULL, certfile must also be NULL and no - * client certificate will be used. - * pw_callback - if keyfile is encrypted, set pw_callback to allow your client - * to pass the correct password for decryption. If set to NULL, - * the password must be entered on the command line. - * Your callback must write the password into "buf", which is - * "size" bytes long. The return value must be the length of the - * password. "userdata" will be set to the calling mosquitto - * instance. The mosquitto userdata member variable can be - * retrieved using . - * - * 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. - * - * 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)); - -/* - * Function: mosquitto_tls_insecure_set - * - * Configure verification of the server hostname in the server certificate. If - * value is set to true, it is impossible to guarantee that the host you are - * connecting to is not impersonating your server. This can be useful in - * initial server testing, but makes it possible for a malicious third party to - * impersonate your server through DNS spoofing, for example. - * Do not use this function in a real system. Setting value to true makes the - * connection encryption pointless. - * Must be called before . - * - * Parameters: - * mosq - a valid mosquitto instance. - * value - if set to false, the default, certificate hostname checking is - * performed. If set to true, no hostname checking is performed and - * the connection is insecure. - * - * Returns: - * 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); - -/* - * Function: mosquitto_tls_opts_set - * - * Set advanced SSL/TLS options. Must be called before . - * - * 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. - * - * 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. - * - * See Also: - * - */ -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 - * - * Configure the client for pre-shared-key based TLS support. Must be called - * before . - * - * Cannot be used in conjunction with . - * - * Parameters: - * mosq - a valid mosquitto instance. - * 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. - * - * 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. - * - * See Also: - * - */ -libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk, const char *identity, const char *ciphers); - - -/* - * Function: mosquitto_ssl_get - * - * Retrieve a pointer to the SSL structure used for TLS connections in this - * client. This can be used in e.g. the connect callback to carry out - * additional verification steps. - * - * Parameters: - * mosq - a valid mosquitto instance - * - * Returns: - * A valid pointer to an openssl SSL structure - if the client is using TLS. - * NULL - if the client is not using TLS, or TLS support is not compiled in. - */ -libmosq_EXPORT void *mosquitto_ssl_get(struct mosquitto *mosq); - - -/* ====================================================================== - * - * Section: Callbacks - * - * ====================================================================== */ -/* - * Function: mosquitto_connect_callback_set - * - * Set the connect callback. This is called when the library receives a CONNACK - * message in response to a connection. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_connect - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, int rc) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - * rc - the return code of the connection response. The values are defined by - * the MQTT protocol version in use. - * For MQTT v5.0, look at section 3.2.2.2 Connect Reason code: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html - * For MQTT v3.1.1, look at section 3.2.2.3 Connect Return code: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html - * - * See Also: - * - */ -libmosq_EXPORT void mosquitto_connect_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int)); - -/* - * Function: mosquitto_connect_with_flags_callback_set - * - * Set the connect callback. This is called when the library receives a CONNACK - * message in response to a connection. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_connect - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, int rc) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - * rc - the return code of the connection response. The values are defined by - * the MQTT protocol version in use. - * For MQTT v5.0, look at section 3.2.2.2 Connect Reason code: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html - * For MQTT v3.1.1, look at section 3.2.2.3 Connect Return code: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html - * flags - the connect flags. - * - * See Also: - * - */ -libmosq_EXPORT void mosquitto_connect_with_flags_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int, int)); - -/* - * Function: mosquitto_connect_v5_callback_set - * - * Set the connect callback. This is called when the library receives a CONNACK - * message in response to a connection. - * - * It is valid to set this callback for all MQTT protocol versions. If it is - * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` - * argument will always be NULL. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_connect - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, int rc) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - * rc - the return code of the connection response. The values are defined by - * the MQTT protocol version in use. - * For MQTT v5.0, look at section 3.2.2.2 Connect Reason code: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html - * For MQTT v3.1.1, look at section 3.2.2.3 Connect Return code: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html - * flags - the connect flags. - * props - list of MQTT 5 properties, or NULL - * - * See Also: - * - */ -libmosq_EXPORT void mosquitto_connect_v5_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int, int, const mosquitto_property *props)); - -/* - * Function: mosquitto_pre_connect_callback_set - * - * Set the pre-connect callback. The pre-connect callback is called just before an attempt is made to connect to the broker. This may be useful if you are using , or - * , because when your client disconnects the library - * will by default automatically reconnect. Using the pre-connect callback - * allows you to set usernames, passwords, and TLS related parameters. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_pre_connect - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - */ -libmosq_EXPORT void mosquitto_pre_connect_callback_set(struct mosquitto *mosq, void (*on_pre_connect)(struct mosquitto *, void *)); - -/* - * 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: - * void callback(struct mosquitto *mosq, void *obj) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - * rc - integer value indicating the reason for the disconnect. A value of 0 - * 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)); - -/* - * Function: mosquitto_disconnect_v5_callback_set - * - * Set the disconnect callback. This is called when the broker has received the - * DISCONNECT command and has disconnected the client. - * - * It is valid to set this callback for all MQTT protocol versions. If it is - * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` - * argument will always be NULL. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_disconnect - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - * rc - integer value indicating the reason for the disconnect. A value of 0 - * means the client has called . Any other value - * indicates that the disconnect is unexpected. - * props - list of MQTT 5 properties, or NULL - */ -libmosq_EXPORT void mosquitto_disconnect_v5_callback_set(struct mosquitto *mosq, void (*on_disconnect)(struct mosquitto *, void *, int, const mosquitto_property *props)); - -/* - * Function: mosquitto_publish_callback_set - * - * Set the publish callback. This is called when a message initiated with - * has been sent to the broker. "Sent" means different - * things depending on the QoS of the message: - * - * QoS 0: The PUBLISH was passed to the local operating system for delivery, - * there is no guarantee that it was delivered to the remote broker. - * QoS 1: The PUBLISH was sent to the remote broker and the corresponding - * PUBACK was received by the library. - * QoS 2: The PUBLISH was sent to the remote broker and the corresponding - * PUBCOMP was received by the library. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_publish - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, int mid) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * 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)); - -/* - * Function: mosquitto_publish_v5_callback_set - * - * Set the publish callback. This is called when a message initiated with - * has been sent to the broker. This callback will be - * called both if the message is sent successfully, or if the broker responded - * with an error, which will be reflected in the reason_code parameter. - * "Sent" means different things depending on the QoS of the message: - * - * QoS 0: The PUBLISH was passed to the local operating system for delivery, - * there is no guarantee that it was delivered to the remote broker. - * QoS 1: The PUBLISH was sent to the remote broker and the corresponding - * PUBACK was received by the library. - * QoS 2: The PUBLISH was sent to the remote broker and the corresponding - * PUBCOMP was received by the library. - * - * - * It is valid to set this callback for all MQTT protocol versions. If it is - * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` - * argument will always be NULL. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_publish - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, int mid) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - * mid - the message id of the sent message. - * reason_code - the MQTT 5 reason code - * props - list of MQTT 5 properties, or NULL - */ -libmosq_EXPORT void mosquitto_publish_v5_callback_set(struct mosquitto *mosq, void (*on_publish)(struct mosquitto *, void *, int, int, const mosquitto_property *props)); - -/* - * Function: mosquitto_message_callback_set - * - * Set the message callback. This is called when a message is received from the - * broker and the required QoS flow has completed. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_message - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - * message - the message data. This variable and associated memory will be - * freed by the library after the callback completes. The client - * 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 *)); - -/* - * Function: mosquitto_message_v5_callback_set - * - * Set the message callback. This is called when a message is received from the - * broker and the required QoS flow has completed. - * - * It is valid to set this callback for all MQTT protocol versions. If it is - * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` - * argument will always be NULL. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_message - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - * message - the message data. This variable and associated memory will be - * freed by the library after the callback completes. The client - * should make copies of any of the data it requires. - * props - list of MQTT 5 properties, or NULL - * - * See Also: - * - */ -libmosq_EXPORT void mosquitto_message_v5_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *, const mosquitto_property *props)); - -/* - * Function: mosquitto_subscribe_callback_set - * - * Set the subscribe callback. This is called when the library receives a - * SUBACK message in response to a SUBSCRIBE. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_subscribe - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - * mid - the message id of the subscribe message. - * qos_count - the number of granted subscriptions (size of granted_qos). - * 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 *)); - -/* - * Function: mosquitto_subscribe_v5_callback_set - * - * Set the subscribe callback. This is called when the library receives a - * SUBACK message in response to a SUBSCRIBE. - * - * It is valid to set this callback for all MQTT protocol versions. If it is - * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` - * argument will always be NULL. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_subscribe - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - * mid - the message id of the subscribe message. - * qos_count - the number of granted subscriptions (size of granted_qos). - * granted_qos - an array of integers indicating the granted QoS for each of - * the subscriptions. - * props - list of MQTT 5 properties, or NULL - */ -libmosq_EXPORT void mosquitto_subscribe_v5_callback_set(struct mosquitto *mosq, void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *, const mosquitto_property *props)); - -/* - * Function: mosquitto_unsubscribe_callback_set - * - * Set the unsubscribe callback. This is called when the library receives a - * UNSUBACK message in response to an UNSUBSCRIBE. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_unsubscribe - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, int mid) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * 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)); - -/* - * Function: mosquitto_unsubscribe_v5_callback_set - * - * Set the unsubscribe callback. This is called when the library receives a - * UNSUBACK message in response to an UNSUBSCRIBE. - * - * It is valid to set this callback for all MQTT protocol versions. If it is - * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` - * argument will always be NULL. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_unsubscribe - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, int mid, const mosquitto_property *props) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - * mid - the message id of the unsubscribe message. - * props - list of MQTT 5 properties, or NULL - */ -libmosq_EXPORT void mosquitto_unsubscribe_v5_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int, const mosquitto_property *props)); - -/* - * Function: mosquitto_unsubscribe2_v5_callback_set - * - * Set the unsubscribe callback. This is called when the library receives a - * UNSUBACK message in response to an UNSUBSCRIBE. - * - * It is valid to set this callback for all MQTT protocol versions. If it is - * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` - * argument will always be NULL. - * - * Parameters: - * mosq - a valid mosquitto instance. - * on_unsubscribe - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, int mid, - * int reason_code_count, const int *reason_codes, const mosquitto_property *props) - * - * Callback Parameters: - * mosq - the mosquitto instance making the callback. - * obj - the user data provided in - * mid - the message id of the unsubscribe message. - * reason_code_count - the count of reason code responses - * reason_codes - an array of integers indicating the reason codes for each of - * the unsubscription requests. - * mid - the message id of the unsubscribe message. - * props - list of MQTT 5 properties, or NULL - */ -libmosq_EXPORT void mosquitto_unsubscribe2_v5_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int, int, const int *, const mosquitto_property *props)); - -/* - * Function: mosquitto_log_callback_set - * - * Set the logging callback. This should be used if you want event logging - * information from the client library. - * - * mosq - a valid mosquitto instance. - * on_log - a callback function in the following form: - * void callback(struct mosquitto *mosq, void *obj, int level, const char *str) - * - * Callback Parameters: - * 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. - */ -libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on_log)(struct mosquitto *, void *, int, const char *)); - - -/* ============================================================================= - * - * Section: SOCKS5 proxy functions - * - * ============================================================================= - */ - -/* - * Function: mosquitto_socks5_set - * - * Configure the client to use a SOCKS5 proxy when connecting. Must be called - * before connecting. "None" and "username/password" authentication is - * supported. - * - * Parameters: - * mosq - a valid mosquitto instance. - * host - the SOCKS5 proxy host to connect to. - * port - the SOCKS5 proxy port to use. - * username - if not NULL, use this username when authenticating with the proxy. - * password - if not NULL and username is not NULL, use this password when - * authenticating with the proxy. - */ -libmosq_EXPORT int mosquitto_socks5_set(struct mosquitto *mosq, const char *host, int port, const char *username, const char *password); - - -/* ============================================================================= - * - * Section: Utility functions - * - * ============================================================================= - */ - -/* - * Function: mosquitto_strerror - * - * Call to obtain a const string description of a mosquitto error number. - * - * Parameters: - * mosq_errno - a mosquitto error number. - * - * Returns: - * A constant string describing the error. - */ -libmosq_EXPORT const char *mosquitto_strerror(int mosq_errno); - -/* - * Function: mosquitto_connack_string - * - * Call to obtain a const string description of an MQTT connection result. - * - * Parameters: - * connack_code - an MQTT connection result. - * - * Returns: - * A constant string describing the result. - */ -libmosq_EXPORT const char *mosquitto_connack_string(int connack_code); - -/* - * Function: mosquitto_reason_string - * - * Call to obtain a const string description of an MQTT reason code. - * - * Parameters: - * reason_code - an MQTT reason code. - * - * Returns: - * A constant string describing the reason. - */ -libmosq_EXPORT const char *mosquitto_reason_string(int reason_code); - -/* Function: mosquitto_string_to_command - * - * Take a string input representing an MQTT command and convert it to the - * libmosquitto integer representation. - * - * Parameters: - * str - the string to parse. - * cmd - pointer to an int, for the result. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - on an invalid input. - * - * Example: - * (start code) - * mosquitto_string_to_command("CONNECT", &cmd); - * // cmd == CMD_CONNECT - * (end) - */ -libmosq_EXPORT int mosquitto_string_to_command(const char *str, int *cmd); - -/* - * Function: mosquitto_sub_topic_tokenise - * - * Tokenise a topic or subscription string into an array of strings - * representing the topic hierarchy. - * - * For example: - * - * subtopic: "a/deep/topic/hierarchy" - * - * Would result in: - * - * topics[0] = "a" - * topics[1] = "deep" - * topics[2] = "topic" - * topics[3] = "hierarchy" - * - * and: - * - * subtopic: "/a/deep/topic/hierarchy/" - * - * Would result in: - * - * topics[0] = NULL - * topics[1] = "a" - * topics[2] = "deep" - * topics[3] = "topic" - * 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. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_NOMEM - if an out of memory condition occurred. - * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8 - * - * Example: - * - * > char **topics; - * > int topic_count; - * > int i; - * > - * > mosquitto_sub_topic_tokenise("$SYS/broker/uptime", &topics, &topic_count); - * > - * > for(i=0; i printf("%d: %s\n", i, topics[i]); - * > } - * - * See Also: - * - */ -libmosq_EXPORT int mosquitto_sub_topic_tokenise(const char *subtopic, char ***topics, int *count); - -/* - * Function: mosquitto_sub_topic_tokens_free - * - * Free memory that was allocated in . - * - * Parameters: - * 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. - * - * See Also: - * - */ -libmosq_EXPORT int mosquitto_sub_topic_tokens_free(char ***topics, int count); - -/* - * Function: mosquitto_topic_matches_sub - * - * Check whether a topic matches a subscription. - * - * For example: - * - * foo/bar would match the subscription foo/# or +/bar - * 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. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if the input parameters were invalid. - */ -libmosq_EXPORT int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result); - -/* - * Function: mosquitto_topic_matches_sub2 - * - * Identical to . The sublen and topiclen - * parameters are *IGNORED*. - */ -libmosq_EXPORT int mosquitto_topic_matches_sub2(const char *sub, size_t sublen, const char *topic, size_t topiclen, bool *result); - - -/* - * Function: mosquitto_topic_matches_sub_with_pattern - * - * Check whether a topic matches a subscription, with client id/username - * pattern substitution. - * - * Any instances of a subscriptions hierarchy that are exactly %c or %u will be - * replaced with the client id or username respectively. - * - * For example: - * - * mosquitto_topic_matches_sub_with_pattern("sensors/%c/temperature", "sensors/kitchen/temperature", "kitchen", NULL, &result) - * -> this will match - * - * mosquitto_topic_matches_sub_with_pattern("sensors/%c/temperature", "sensors/bathroom/temperature", "kitchen", NULL, &result) - * -> this will not match - * - * mosquitto_topic_matches_sub_with_pattern("sensors/%count/temperature", "sensors/kitchen/temperature", "kitchen", NULL, &result) - * -> this will not match - the `%count` is not treated as a pattern - * - * mosquitto_topic_matches_sub_with_pattern("%c/%c/%u/%u", "kitchen/kitchen/bathroom/bathroom", "kitchen", "bathroom", &result) - * -> this will match - * - * Parameters: - * sub - subscription string to check topic against. - * topic - topic to check. - * clientid - client id to substitute in patterns. If NULL, then any %c patterns will not match. - * username - username to substitute in patterns. If NULL, then any %u patterns will not match. - * 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. - */ -libmosq_EXPORT int mosquitto_topic_matches_sub_with_pattern(const char *sub, const char *topic, const char *clientid, const char *username, bool *result); - - -/* - * Function: mosquitto_sub_matches_acl - * - * Check whether a subscription matches an ACL topic filter - * - * For example: - * - * The subscription $SYS/broker/# would match against the ACL $SYS/# - * The subscription $SYS/broker/# would not match against the ACL $SYS/broker/uptime - * - * Parameters: - * acl - topic filter string to check sub against. - * sub - subscription topic to check. - * result - bool pointer to hold result. Will be set to true if the subscription - * matches the acl. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if the input parameters were invalid. - */ -libmosq_EXPORT int mosquitto_sub_matches_acl(const char *acl, const char *sub, bool *result); - - -/* - * Function: mosquitto_sub_matches_acl_with_pattern - * - * Check whether a subscription (a topic filter with wildcards) matches an ACL - * (a topic filter with wildcards) , with client id/username pattern - * substitution. - * - * Any instances of an ACL hierarchy that are exactly %c or %u will be - * replaced with the client id or username respectively. - * - * For example: - * - * mosquitto_sub_matches_acl_with_pattern("sensors/%c/+", "sensors/kitchen/temperature", "kitchen", NULL, &result) - * -> this will match - * - * mosquitto_sub_matches_acl_with_pattern("sensors/%c/+", "sensors/bathroom/temperature", "kitchen", NULL, &result) - * -> this will not match - * - * mosquitto_sub_matches_acl_with_pattern("sensors/%count/+", "sensors/kitchen/temperature", "kitchen", NULL, &result) - * -> this will not match - the `%count` is not treated as a pattern - * - * mosquitto_sub_matches_acl_with_pattern("%c/%c/%u/+", "kitchen/kitchen/bathroom/bathroom", "kitchen", "bathroom", &result) - * -> this will match - * - * Parameters: - * acl - ACL topic filter string to check sub against. - * sub - subscription to check. - * clientid - client id to substitute in patterns. If NULL, then any %c patterns will not match. - * username - username to substitute in patterns. If NULL, then any %u patterns will not match. - * result - bool pointer to hold result. Will be set to true if the subscription - * matches the ACL. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if the input parameters were invalid. - */ -libmosq_EXPORT int mosquitto_sub_matches_acl_with_pattern(const char *acl, const char *sub, const char *clientid, const char *username, bool *result); - - -/* - * Function: mosquitto_pub_topic_check - * - * Check whether a topic to be used for publishing is valid. - * - * This searches for + or # in a topic and checks its length. - * - * This check is already carried out in and - * , there is no need to call it directly before them. It - * may be useful if you wish to check the validity of a topic in advance of - * making a connection for example. - * - * Parameters: - * topic - the topic to check - * - * Returns: - * MOSQ_ERR_SUCCESS - for a valid topic - * MOSQ_ERR_INVAL - if the topic contains a + or a #, or if it is too long. - * MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8 - * - * See Also: - * - */ -libmosq_EXPORT int mosquitto_pub_topic_check(const char *topic); - -/* - * Function: mosquitto_pub_topic_check2 - * - * Check whether a topic to be used for publishing is valid. - * - * This searches for + or # in a topic and checks its length. - * - * This check is already carried out in and - * , there is no need to call it directly before them. It - * may be useful if you wish to check the validity of a topic in advance of - * making a connection for example. - * - * Parameters: - * topic - the topic to check - * topiclen - length of the topic in bytes - * - * Returns: - * MOSQ_ERR_SUCCESS - for a valid topic - * MOSQ_ERR_INVAL - if the topic contains a + or a #, or if it is too long. - * MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8 - * - * See Also: - * - */ -libmosq_EXPORT int mosquitto_pub_topic_check2(const char *topic, size_t topiclen); - -/* - * Function: mosquitto_sub_topic_check - * - * Check whether a topic to be used for subscribing is valid. - * - * This searches for + or # in a topic and checks that they aren't in invalid - * positions, such as with foo/#/bar, foo/+bar or foo/bar#, and checks its - * length. - * - * This check is already carried out in and - * , there is no need to call it directly before them. - * It may be useful if you wish to check the validity of a topic in advance of - * making a connection for example. - * - * Parameters: - * topic - the topic to check - * - * Returns: - * MOSQ_ERR_SUCCESS - for a valid topic - * MOSQ_ERR_INVAL - if the topic contains a + or a # that is in an - * invalid position, or if it is too long. - * MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8 - * - * See Also: - * - */ -libmosq_EXPORT int mosquitto_sub_topic_check(const char *topic); - -/* - * Function: mosquitto_sub_topic_check2 - * - * Check whether a topic to be used for subscribing is valid. - * - * This searches for + or # in a topic and checks that they aren't in invalid - * positions, such as with foo/#/bar, foo/+bar or foo/bar#, and checks its - * length. - * - * This check is already carried out in and - * , there is no need to call it directly before them. - * It may be useful if you wish to check the validity of a topic in advance of - * making a connection for example. - * - * Parameters: - * topic - the topic to check - * topiclen - the length in bytes of the topic - * - * Returns: - * MOSQ_ERR_SUCCESS - for a valid topic - * MOSQ_ERR_INVAL - if the topic contains a + or a # that is in an - * invalid position, or if it is too long. - * MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8 - * - * See Also: - * - */ -libmosq_EXPORT int mosquitto_sub_topic_check2(const char *topic, size_t topiclen); - - -/* - * Function: mosquitto_validate_utf8 - * - * Helper function to validate whether a UTF-8 string is valid, according to - * the UTF-8 spec and the MQTT additions. - * - * Parameters: - * str - a string to check - * len - the length of the string in bytes - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if str is NULL or len<0 or len>65536 - * MOSQ_ERR_MALFORMED_UTF8 - if str is not valid UTF-8 - */ -libmosq_EXPORT int mosquitto_validate_utf8(const char *str, int len); - - -/* ============================================================================= - * - * Section: One line client helper functions - * - * ============================================================================= - */ - -struct libmosquitto_will { - char *topic; - void *payload; - int payloadlen; - int qos; - bool retain; -}; - -struct libmosquitto_auth { - char *username; - char *password; -}; - -struct libmosquitto_tls { - char *cafile; - char *capath; - char *certfile; - char *keyfile; - char *ciphers; - char *tls_version; - int (*pw_callback)(char *buf, int size, int rwflag, void *userdata); - int cert_reqs; -}; - -/* - * Function: mosquitto_subscribe_simple - * - * Helper function to make subscribing to a topic and retrieving some messages - * very straightforward. - * - * This connects to a broker, subscribes to a topic, waits for msg_count - * messages to be received, then returns after disconnecting cleanly. - * - * Parameters: - * messages - pointer to a "struct mosquitto_message *". The received - * messages will be returned here. On error, this will be set to - * NULL. - * msg_count - the number of messages to retrieve. - * want_retained - if set to true, stale retained messages will be treated as - * normal messages with regards to msg_count. If set to - * false, they will be ignored. - * topic - the subscription topic to use (wildcards are allowed). - * qos - the qos to use for the subscription. - * host - the broker to connect to. - * port - the network port the broker is listening on. - * clientid - the client id to use, or NULL if a random client id should be - * generated. - * keepalive - the MQTT keepalive value. - * clean_session - the MQTT clean session flag. - * username - the username string, or NULL for no username authentication. - * password - the password string, or NULL for an empty password. - * will - a libmosquitto_will struct containing will information, or NULL for - * no will. - * tls - a libmosquitto_tls struct containing TLS related parameters, or NULL - * for no use of TLS. - * - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * Greater than 0 - on error. - */ -libmosq_EXPORT int mosquitto_subscribe_simple( - struct mosquitto_message **messages, - int msg_count, - bool want_retained, - const char *topic, - int qos, - const char *host, - int port, - const char *clientid, - int keepalive, - bool clean_session, - const char *username, - const char *password, - const struct libmosquitto_will *will, - const struct libmosquitto_tls *tls); - - -/* - * Function: mosquitto_subscribe_callback - * - * Helper function to make subscribing to a topic and processing some messages - * very straightforward. - * - * This connects to a broker, subscribes to a topic, then passes received - * messages to a user provided callback. If the callback returns a 1, it then - * disconnects cleanly and returns. - * - * Parameters: - * callback - a callback function in the following form: - * int callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) - * Note that this is the same as the normal on_message callback, - * except that it returns an int. - * userdata - user provided pointer that will be passed to the callback. - * topic - the subscription topic to use (wildcards are allowed). - * qos - the qos to use for the subscription. - * host - the broker to connect to. - * port - the network port the broker is listening on. - * clientid - the client id to use, or NULL if a random client id should be - * generated. - * keepalive - the MQTT keepalive value. - * clean_session - the MQTT clean session flag. - * username - the username string, or NULL for no username authentication. - * password - the password string, or NULL for an empty password. - * will - a libmosquitto_will struct containing will information, or NULL for - * no will. - * tls - a libmosquitto_tls struct containing TLS related parameters, or NULL - * for no use of TLS. - * - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * Greater than 0 - on error. - */ -libmosq_EXPORT int mosquitto_subscribe_callback( - int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *), - void *userdata, - const char *topic, - int qos, - const char *host, - int port, - const char *clientid, - int keepalive, - bool clean_session, - const char *username, - const char *password, - const struct libmosquitto_will *will, - const struct libmosquitto_tls *tls); - - -/* ============================================================================= - * - * Section: Properties - * - * ============================================================================= - */ - - -/* - * Function: mosquitto_property_add_byte - * - * Add a new byte property to a property list. - * - * If *proplist == NULL, a new list will be created, otherwise the new property - * will be appended to the list. - * - * Parameters: - * proplist - pointer to mosquitto_property pointer, the list of properties - * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) - * value - integer value for the new property - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL - * MOSQ_ERR_NOMEM - on out of memory - * - * Example: - * > mosquitto_property *proplist = NULL; - * > mosquitto_property_add_byte(&proplist, MQTT_PROP_PAYLOAD_FORMAT_IDENTIFIER, 1); - */ -libmosq_EXPORT int mosquitto_property_add_byte(mosquitto_property **proplist, int identifier, uint8_t value); - -/* - * Function: mosquitto_property_add_int16 - * - * Add a new int16 property to a property list. - * - * If *proplist == NULL, a new list will be created, otherwise the new property - * will be appended to the list. - * - * Parameters: - * proplist - pointer to mosquitto_property pointer, the list of properties - * identifier - property identifier (e.g. MQTT_PROP_RECEIVE_MAXIMUM) - * value - integer value for the new property - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL - * MOSQ_ERR_NOMEM - on out of memory - * - * Example: - * > mosquitto_property *proplist = NULL; - * > mosquitto_property_add_int16(&proplist, MQTT_PROP_RECEIVE_MAXIMUM, 1000); - */ -libmosq_EXPORT int mosquitto_property_add_int16(mosquitto_property **proplist, int identifier, uint16_t value); - -/* - * Function: mosquitto_property_add_int32 - * - * Add a new int32 property to a property list. - * - * If *proplist == NULL, a new list will be created, otherwise the new property - * will be appended to the list. - * - * Parameters: - * proplist - pointer to mosquitto_property pointer, the list of properties - * identifier - property identifier (e.g. MQTT_PROP_MESSAGE_EXPIRY_INTERVAL) - * value - integer value for the new property - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL - * MOSQ_ERR_NOMEM - on out of memory - * - * Example: - * > mosquitto_property *proplist = NULL; - * > mosquitto_property_add_int32(&proplist, MQTT_PROP_MESSAGE_EXPIRY_INTERVAL, 86400); - */ -libmosq_EXPORT int mosquitto_property_add_int32(mosquitto_property **proplist, int identifier, uint32_t value); - -/* - * Function: mosquitto_property_add_varint - * - * Add a new varint property to a property list. - * - * If *proplist == NULL, a new list will be created, otherwise the new property - * will be appended to the list. - * - * Parameters: - * proplist - pointer to mosquitto_property pointer, the list of properties - * identifier - property identifier (e.g. MQTT_PROP_SUBSCRIPTION_IDENTIFIER) - * value - integer value for the new property - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL - * MOSQ_ERR_NOMEM - on out of memory - * - * Example: - * > mosquitto_property *proplist = NULL; - * > mosquitto_property_add_varint(&proplist, MQTT_PROP_SUBSCRIPTION_IDENTIFIER, 1); - */ -libmosq_EXPORT int mosquitto_property_add_varint(mosquitto_property **proplist, int identifier, uint32_t value); - -/* - * Function: mosquitto_property_add_binary - * - * Add a new binary property to a property list. - * - * If *proplist == NULL, a new list will be created, otherwise the new property - * will be appended to the list. - * - * Parameters: - * proplist - pointer to mosquitto_property pointer, the list of properties - * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) - * value - pointer to the property data - * len - length of property data in bytes - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL - * MOSQ_ERR_NOMEM - on out of memory - * - * Example: - * > mosquitto_property *proplist = NULL; - * > mosquitto_property_add_binary(&proplist, MQTT_PROP_AUTHENTICATION_DATA, auth_data, auth_data_len); - */ -libmosq_EXPORT int mosquitto_property_add_binary(mosquitto_property **proplist, int identifier, const void *value, uint16_t len); - -/* - * Function: mosquitto_property_add_string - * - * Add a new string property to a property list. - * - * If *proplist == NULL, a new list will be created, otherwise the new property - * will be appended to the list. - * - * Parameters: - * proplist - pointer to mosquitto_property pointer, the list of properties - * identifier - property identifier (e.g. MQTT_PROP_CONTENT_TYPE) - * value - string value for the new property, must be UTF-8 and zero terminated - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if identifier is invalid, if value is NULL, or if proplist is NULL - * MOSQ_ERR_NOMEM - on out of memory - * MOSQ_ERR_MALFORMED_UTF8 - value is not valid UTF-8. - * - * Example: - * > mosquitto_property *proplist = NULL; - * > mosquitto_property_add_string(&proplist, MQTT_PROP_CONTENT_TYPE, "application/json"); - */ -libmosq_EXPORT int mosquitto_property_add_string(mosquitto_property **proplist, int identifier, const char *value); - -/* - * Function: mosquitto_property_add_string_pair - * - * Add a new string pair property to a property list. - * - * If *proplist == NULL, a new list will be created, otherwise the new property - * will be appended to the list. - * - * Parameters: - * proplist - pointer to mosquitto_property pointer, the list of properties - * identifier - property identifier (e.g. MQTT_PROP_USER_PROPERTY) - * name - string name for the new property, must be UTF-8 and zero terminated - * value - string value for the new property, must be UTF-8 and zero terminated - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if identifier is invalid, if name or value is NULL, or if proplist is NULL - * MOSQ_ERR_NOMEM - on out of memory - * MOSQ_ERR_MALFORMED_UTF8 - if name or value are not valid UTF-8. - * - * Example: - * > mosquitto_property *proplist = NULL; - * > mosquitto_property_add_string_pair(&proplist, MQTT_PROP_USER_PROPERTY, "client", "mosquitto_pub"); - */ -libmosq_EXPORT int mosquitto_property_add_string_pair(mosquitto_property **proplist, int identifier, const char *name, const char *value); - - -/* - * Function: mosquitto_property_remove - * - * Remove a property from a property list. The property will not be freed. - * - * Parameters: - * proplist - pointer to mosquitto_property pointer, the list of properties - * property - pointer to the property to remove - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if proplist is NULL or property is NULL - * MOSQ_ERR_NOT_FOUND - if the property was not found - */ -libmosq_EXPORT int mosquitto_property_remove(mosquitto_property **proplist, const mosquitto_property *property); - - -/* - * Function: mosquitto_property_identifier - * - * Return the property identifier for a single property. - * - * Parameters: - * property - pointer to a valid mosquitto_property pointer. - * - * Returns: - * A valid property identifier on success - * 0 - on error - */ -libmosq_EXPORT int mosquitto_property_identifier(const mosquitto_property *property); - - -/* - * Function: mosquitto_property_next - * - * Return the next property in a property list. Use to iterate over a property - * list, e.g.: - * - * (start code) - * for(prop = proplist; prop != NULL; prop = mosquitto_property_next(prop)){ - * if(mosquitto_property_identifier(prop) == MQTT_PROP_CONTENT_TYPE){ - * ... - * } - * } - * (end) - * - * Parameters: - * proplist - pointer to mosquitto_property pointer, the list of properties - * - * Returns: - * Pointer to the next item in the list - * NULL, if proplist is NULL, or if there are no more items in the list. - */ -libmosq_EXPORT mosquitto_property *mosquitto_property_next(const mosquitto_property *proplist); - - -/* - * Function: mosquitto_property_read_byte - * - * Attempt to read a byte property matching an identifier, from a property list - * or single property. This function can search for multiple entries of the - * same identifier by using the returned value and skip_first. Note however - * that it is forbidden for most properties to be duplicated. - * - * If the property is not found, *value will not be modified, so it is safe to - * pass a variable with a default value to be potentially overwritten: - * - * (start code) - * uint16_t keepalive = 60; // default value - * // Get value from property list, or keep default if not found. - * mosquitto_property_read_int16(proplist, MQTT_PROP_SERVER_KEEP_ALIVE, &keepalive, false); - * (end) - * - * Parameters: - * proplist - mosquitto_property pointer, the list of properties or single property - * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) - * value - pointer to store the value, or NULL if the value is not required. - * skip_first - boolean that indicates whether the first item in the list - * should be ignored or not. Should usually be set to false. - * - * Returns: - * A valid property pointer if the property is found - * NULL, if the property is not found, or proplist is NULL. - * - * Example: - * (start code) - * // proplist is obtained from a callback - * mosquitto_property *prop; - * prop = mosquitto_property_read_byte(proplist, identifier, &value, false); - * while(prop){ - * printf("value: %s\n", value); - * prop = mosquitto_property_read_byte(prop, identifier, &value); - * } - * (end) - */ -libmosq_EXPORT const mosquitto_property *mosquitto_property_read_byte( - const mosquitto_property *proplist, - int identifier, - uint8_t *value, - bool skip_first); - -/* - * Function: mosquitto_property_read_int16 - * - * Read an int16 property value from a property. - * - * Parameters: - * property - property to read - * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) - * value - pointer to store the value, or NULL if the value is not required. - * skip_first - boolean that indicates whether the first item in the list - * should be ignored or not. Should usually be set to false. - * - * Returns: - * A valid property pointer if the property is found - * NULL, if the property is not found, or proplist is NULL. - * - * Example: - * See - */ -libmosq_EXPORT const mosquitto_property *mosquitto_property_read_int16( - const mosquitto_property *proplist, - int identifier, - uint16_t *value, - bool skip_first); - -/* - * Function: mosquitto_property_read_int32 - * - * Read an int32 property value from a property. - * - * Parameters: - * property - pointer to mosquitto_property pointer, the list of properties - * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) - * value - pointer to store the value, or NULL if the value is not required. - * skip_first - boolean that indicates whether the first item in the list - * should be ignored or not. Should usually be set to false. - * - * Returns: - * A valid property pointer if the property is found - * NULL, if the property is not found, or proplist is NULL. - * - * Example: - * See - */ -libmosq_EXPORT const mosquitto_property *mosquitto_property_read_int32( - const mosquitto_property *proplist, - int identifier, - uint32_t *value, - bool skip_first); - -/* - * Function: mosquitto_property_read_varint - * - * Read a varint property value from a property. - * - * Parameters: - * property - property to read - * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) - * value - pointer to store the value, or NULL if the value is not required. - * skip_first - boolean that indicates whether the first item in the list - * should be ignored or not. Should usually be set to false. - * - * Returns: - * A valid property pointer if the property is found - * NULL, if the property is not found, or proplist is NULL. - * - * Example: - * See - */ -libmosq_EXPORT const mosquitto_property *mosquitto_property_read_varint( - const mosquitto_property *proplist, - int identifier, - uint32_t *value, - bool skip_first); - -/* - * Function: mosquitto_property_read_binary - * - * Read a binary property value from a property. - * - * On success, value must be free()'d by the application. - * - * Parameters: - * property - property to read - * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) - * value - pointer to store the value, or NULL if the value is not required. - * Will be set to NULL if the value has zero length. - * skip_first - boolean that indicates whether the first item in the list - * should be ignored or not. Should usually be set to false. - * - * Returns: - * A valid property pointer if the property is found - * NULL, if the property is not found, or proplist is NULL, or if an out of memory condition occurred. - * - * Example: - * See - */ -libmosq_EXPORT const mosquitto_property *mosquitto_property_read_binary( - const mosquitto_property *proplist, - int identifier, - void **value, - uint16_t *len, - bool skip_first); - -/* - * Function: mosquitto_property_read_string - * - * Read a string property value from a property. - * - * On success, value must be free()'d by the application. - * - * Parameters: - * property - property to read - * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) - * value - pointer to char*, for the property data to be stored in, or NULL if - * the value is not required. - * Will be set to NULL if the value has zero length. - * skip_first - boolean that indicates whether the first item in the list - * should be ignored or not. Should usually be set to false. - * - * Returns: - * A valid property pointer if the property is found - * NULL, if the property is not found, or proplist is NULL, or if an out of memory condition occurred. - * - * Example: - * See - */ -libmosq_EXPORT const mosquitto_property *mosquitto_property_read_string( - const mosquitto_property *proplist, - int identifier, - char **value, - bool skip_first); - -/* - * Function: mosquitto_property_read_string_pair - * - * Read a string pair property value pair from a property. - * - * On success, name and value must be free()'d by the application. - * - * Parameters: - * property - property to read - * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) - * name - pointer to char* for the name property data to be stored in, or NULL - * if the name is not required. - * Will be set to NULL if the name has zero length. - * value - pointer to char*, for the property data to be stored in, or NULL if - * the value is not required. - * Will be set to NULL if the value has zero length. - * skip_first - boolean that indicates whether the first item in the list - * should be ignored or not. Should usually be set to false. - * - * Returns: - * A valid property pointer if the property is found - * NULL, if the property is not found, or proplist is NULL, or if an out of memory condition occurred. - * - * Example: - * See - */ -libmosq_EXPORT const mosquitto_property *mosquitto_property_read_string_pair( - const mosquitto_property *proplist, - int identifier, - char **name, - char **value, - bool skip_first); - -/* - * Function: mosquitto_property_type - * - * Return the property type for a single property. - * - * Parameters: - * property - pointer to a valid mosquitto_property pointer. - * - * Returns: - * A valid property type on success - * 0 - on error - */ -libmosq_EXPORT int mosquitto_property_type(const mosquitto_property *property); - - -/* - * Function: mosquitto_property_byte_value - * - * Return the property value for a byte type property. - * - * Parameters: - * property - pointer to a valid mosquitto_property pointer. - * - * Returns: - * Byte value on success - * 0 - on error (property is NULL, or not a byte) - */ -libmosq_EXPORT uint8_t mosquitto_property_byte_value(const mosquitto_property *property); - - -/* - * Function: mosquitto_property_int16_value - * - * Return the property value for an int16 type property. - * - * Parameters: - * property - pointer to a valid mosquitto_property pointer. - * - * Returns: - * Int16 value on success - * 0 - on error (property is NULL, or not a int16) - */ -libmosq_EXPORT uint16_t mosquitto_property_int16_value(const mosquitto_property *property); - - -/* - * Function: mosquitto_property_int32_value - * - * Return the property value for an int32 type property. - * - * Parameters: - * property - pointer to a valid mosquitto_property pointer. - * - * Returns: - * Int32 value on success - * 0 - on error (property is NULL, or not a int32) - */ -libmosq_EXPORT uint32_t mosquitto_property_int32_value(const mosquitto_property *property); - - -/* - * Function: mosquitto_property_varint_value - * - * Return the property value for a varint type property. - * - * Parameters: - * property - pointer to a valid mosquitto_property pointer. - * - * Returns: - * Varint value on success - * 0 - on error (property is NULL, or not a varint) - */ -libmosq_EXPORT uint32_t mosquitto_property_varint_value(const mosquitto_property *property); - - -/* - * Function: mosquitto_property_binary_value - * - * Return the property value for a binary type property. - * - * Parameters: - * property - pointer to a valid mosquitto_property pointer. - * - * Returns: - * Binary value on success - * NULL - on error (property is NULL, or not a binary) - */ -libmosq_EXPORT const void *mosquitto_property_binary_value(const mosquitto_property *property); - - -/* - * Function: mosquitto_property_byte_value_length - * - * Return the property value for a byte type property. - * - * Parameters: - * property - pointer to a valid mosquitto_property pointer. - * - * Returns: - * Binary value length on success - * 0 - on error (property is NULL, or not a binary) - */ -libmosq_EXPORT uint16_t mosquitto_property_binary_value_length(const mosquitto_property *property); - - -/* - * Function: mosquitto_property_string_value - * - * Return the property value for a string or string pair type property. - * - * Parameters: - * property - pointer to a valid mosquitto_property pointer. - * - * Returns: - * String value on success - * NULL - on error (property is NULL, or not a string or string pair) - */ -libmosq_EXPORT const char *mosquitto_property_string_value(const mosquitto_property *property); - - -/* - * Function: mosquitto_property_string_value_length - * - * Return the length of the property value for a string or string pair type property. - * - * Parameters: - * property - pointer to a valid mosquitto_property pointer. - * - * Returns: - * Value length on success - * 0 - on error (property is NULL, or not a string or string pair) - */ -libmosq_EXPORT uint16_t mosquitto_property_string_value_length(const mosquitto_property *property); - - -/* - * Function: mosquitto_property_string_value - * - * Return the property name for a string pair type property. - * - * Parameters: - * property - pointer to a valid mosquitto_property pointer. - * - * Returns: - * String name on success - * NULL - on error (property is NULL, or not a string pair) - */ -libmosq_EXPORT const char *mosquitto_property_string_name(const mosquitto_property *property); - - -/* - * Function: mosquitto_property_string_name_length - * - * Return the property name length for a string pair type property. - * - * Parameters: - * property - pointer to a valid mosquitto_property pointer. - * - * Returns: - * Name length on success - * 0 - on error (property is NULL, or not a string pair) - */ -libmosq_EXPORT uint16_t mosquitto_property_string_name_length(const mosquitto_property *property); - - -/* - * Function: mosquitto_property_free_all - * - * Free all properties from a list of properties. Frees the list and sets *properties to NULL. - * - * Parameters: - * properties - list of properties to free - * - * Example: - * > mosquitto_properties *properties = NULL; - * > // Add properties - * > mosquitto_property_free_all(&properties); - */ -libmosq_EXPORT void mosquitto_property_free_all(mosquitto_property **properties); - -/* - * Function: mosquitto_property_copy_all - * - * Parameters: - * dest - pointer for new property list - * src - property list - * - * Returns: - * MOSQ_ERR_SUCCESS - on successful copy - * MOSQ_ERR_INVAL - if dest is NULL - * MOSQ_ERR_NOMEM - on out of memory (dest will be set to NULL) - */ -libmosq_EXPORT int mosquitto_property_copy_all(mosquitto_property **dest, const mosquitto_property *src); - -/* - * Function: mosquitto_property_check_command - * - * Check whether a property identifier is valid for the given command. - * - * Parameters: - * command - MQTT command (e.g. CMD_CONNECT) - * identifier - MQTT property (e.g. MQTT_PROP_USER_PROPERTY) - * - * Returns: - * MOSQ_ERR_SUCCESS - if the identifier is valid for command - * MOSQ_ERR_PROTOCOL - if the identifier is not valid for use with command. - */ -libmosq_EXPORT int mosquitto_property_check_command(int command, int identifier); - - -/* - * Function: mosquitto_property_check_all - * - * Check whether a list of properties are valid for a particular command, - * whether there are duplicates, and whether the values are valid where - * possible. - * - * Note that this function is used internally in the library whenever - * properties are passed to it, so in basic use this is not needed, but should - * be helpful to check property lists *before* the point of using them. - * - * Parameters: - * command - MQTT command (e.g. CMD_CONNECT) - * properties - list of MQTT properties to check. - * - * Returns: - * MOSQ_ERR_SUCCESS - if all properties are valid - * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. - * MOSQ_ERR_PROTOCOL - if any property is invalid - */ -libmosq_EXPORT int mosquitto_property_check_all(int command, const mosquitto_property *properties); - -/* - * Function: mosquitto_property_identifier_to_string - * - * Return the property name as a string for a property identifier. - * The property name is as defined in the MQTT specification, with - as a - * separator, for example: payload-format-indicator. - * - * Parameters: - * identifier - valid MQTT property identifier integer - * - * Returns: - * A const string to the property name on success - * NULL on failure - */ -libmosq_EXPORT const char *mosquitto_property_identifier_to_string(int identifier); - - -/* Function: mosquitto_string_to_property_info - * - * Parse a property name string and convert to a property identifier and data type. - * The property name is as defined in the MQTT specification, with - as a - * separator, for example: payload-format-indicator. - * - * Parameters: - * propname - the string to parse - * identifier - pointer to an int to receive the property identifier - * type - pointer to an int to receive the property type - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if the string does not match a property - * - * Example: - * (start code) - * mosquitto_string_to_property_info("response-topic", &id, &type); - * // id == MQTT_PROP_RESPONSE_TOPIC - * // type == MQTT_PROP_TYPE_STRING - * (end) - */ -libmosq_EXPORT int mosquitto_string_to_property_info(const char *propname, int *identifier, int *type); - - -#ifdef __cplusplus -} -#endif +#include +#include +#include #endif diff --git a/include/mosquitto/broker.h b/include/mosquitto/broker.h new file mode 100644 index 00000000..ec751da2 --- /dev/null +++ b/include/mosquitto/broker.h @@ -0,0 +1,1265 @@ +/* +Copyright (c) 2009-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +/* + * File: mosquitto_broker.h + * + * This header contains functions for use by plugins. + */ +#ifndef MOSQUITTO_BROKER_H +#define MOSQUITTO_BROKER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(WIN32) && defined(mosquitto_EXPORTS) +# define mosq_EXPORT __declspec(dllexport) +#else +# define mosq_EXPORT +#endif + +#include +#include +#include +#include + +#include +#include + +enum mosquitto_protocol { + mp_mqtt, + mp_mqttsn, + mp_websockets +}; + +enum mosquitto_broker_msg_direction { + mosq_bmd_in = 0, + mosq_bmd_out = 1, + mosq_bmd_all = 2 +}; + + +/* ========================================================================= + * + * Section: General structs + * + * ========================================================================= */ + +struct mosquitto_client { + char *clientid; + char *username; + char *auth_method; + struct mosquitto_message_v5 *will; + time_t will_delay_time; + time_t session_expiry_time; + uint32_t will_delay_interval; + uint32_t session_expiry_interval; + uint32_t max_packet_size; + uint16_t listener_port; + uint8_t max_qos; + bool retain_available; + void *future2[8]; +}; + +struct mosquitto_subscription { + char *clientid; + char *topic_filter; + mosquitto_property *properties; + uint32_t identifier; + uint8_t options; + uint8_t padding[3]; + void *future2[8]; +}; + +struct mosquitto_base_msg { + uint64_t store_id; + int64_t expiry_time; + char *topic; + void *payload; + char *source_id; + char *source_username; + mosquitto_property *properties; + uint32_t payloadlen; + uint16_t source_mid; + uint16_t source_port; + uint8_t qos; + bool retain; + uint8_t padding[6]; + void *future2[8]; +}; + +struct mosquitto_client_msg { + const char *clientid; + uint64_t cmsg_id; + uint64_t store_id; + uint32_t subscription_identifier; + uint16_t mid; + uint8_t qos; + bool retain; + uint8_t dup; + uint8_t direction; + uint8_t state; + uint8_t padding[5]; + void *future2[8]; +}; + +/* ========================================================================= + * + * Section: Register callbacks. + * + * ========================================================================= */ + +/* Callback events */ +enum mosquitto_plugin_event { + MOSQ_EVT_RELOAD = 1, + MOSQ_EVT_ACL_CHECK = 2, + MOSQ_EVT_BASIC_AUTH = 3, + MOSQ_EVT_EXT_AUTH_START = 4, + MOSQ_EVT_EXT_AUTH_CONTINUE = 5, + MOSQ_EVT_CONTROL = 6, + MOSQ_EVT_MESSAGE = 7, // deprecated name + MOSQ_EVT_MESSAGE_IN = 7, + MOSQ_EVT_PSK_KEY = 8, + MOSQ_EVT_TICK = 9, + MOSQ_EVT_DISCONNECT = 10, + MOSQ_EVT_CONNECT = 11, + MOSQ_EVT_SUBSCRIBE = 12, + MOSQ_EVT_UNSUBSCRIBE = 13, + MOSQ_EVT_PERSIST_RESTORE = 14, + MOSQ_EVT_PERSIST_BASE_MSG_ADD = 15, + MOSQ_EVT_PERSIST_BASE_MSG_DELETE = 16, + MOSQ_EVT_PERSIST_RETAIN_MSG_SET = 17, + MOSQ_EVT_PERSIST_RETAIN_MSG_DELETE = 18, + MOSQ_EVT_PERSIST_CLIENT_ADD = 19, + MOSQ_EVT_PERSIST_CLIENT_DELETE = 20, + MOSQ_EVT_PERSIST_CLIENT_UPDATE = 21, + MOSQ_EVT_PERSIST_SUBSCRIPTION_ADD = 22, + MOSQ_EVT_PERSIST_SUBSCRIPTION_DELETE = 23, + MOSQ_EVT_PERSIST_CLIENT_MSG_ADD = 24, + MOSQ_EVT_PERSIST_CLIENT_MSG_DELETE = 25, + MOSQ_EVT_PERSIST_CLIENT_MSG_UPDATE = 26, + MOSQ_EVT_MESSAGE_OUT = 27, + MOSQ_EVT_CLIENT_OFFLINE = 28, +}; + +/* Data for the MOSQ_EVT_RELOAD event */ +struct mosquitto_evt_reload { + void *future; + struct mosquitto_opt *options; + int option_count; + void *future2[4]; +}; + +/* Data for the MOSQ_EVT_ACL_CHECK event */ +struct mosquitto_evt_acl_check { + void *future; + struct mosquitto *client; + const char *topic; + const void *payload; + mosquitto_property *properties; + int access; + uint32_t payloadlen; + uint8_t qos; + bool retain; + void *future2[4]; +}; + +/* Data for the MOSQ_EVT_BASIC_AUTH event */ +struct mosquitto_evt_basic_auth { + void *future; + struct mosquitto *client; + char *username; + char *password; + void *future2[4]; +}; + +/* Data for the MOSQ_EVT_PSK_KEY event */ +struct mosquitto_evt_psk_key { + void *future; + struct mosquitto *client; + const char *hint; + const char *identity; + char *key; + int max_key_len; + void *future2[4]; +}; + +/* Data for the MOSQ_EVT_EXTENDED_AUTH event */ +struct mosquitto_evt_extended_auth { + void *future; + struct mosquitto *client; + const void *data_in; + void *data_out; + uint16_t data_in_len; + uint16_t data_out_len; + const char *auth_method; + void *future2[3]; +}; + +/* Data for the MOSQ_EVT_CONTROL event */ +struct mosquitto_evt_control { + void *future; + struct mosquitto *client; + const char *topic; + const void *payload; + const mosquitto_property *properties; + char *reason_string; + uint32_t payloadlen; + uint8_t qos; + uint8_t reason_code; + bool retain; + uint8_t padding; + void *future2[4]; +}; + +/* Data for the MOSQ_EVT_MESSAGE_IN and MOSQ_EVT_MESSAGE_OUT events */ +struct mosquitto_evt_message { + void *future; + struct mosquitto *client; + char *topic; + void *payload; + mosquitto_property *properties; + char *reason_string; + uint32_t payloadlen; + uint8_t qos; + uint8_t reason_code; + bool retain; + uint8_t padding; + void *future2[4]; +}; + + +/* Data for the MOSQ_EVT_TICK event */ +struct mosquitto_evt_tick { + void *future; + long now_ns; + long next_ms; + time_t now_s; + time_t next_s; + void *future2[4]; +}; + +/* Data for the MOSQ_EVT_CONNECT event */ +struct mosquitto_evt_connect { + void *future; + struct mosquitto *client; + void *future2[4]; +}; + +/* Data for the MOSQ_EVT_DISCONNECT event */ +struct mosquitto_evt_disconnect { + void *future; + struct mosquitto *client; + int reason; + void *future2[4]; +}; + +/* Data for the MOSQ_EVT_CLIENT_OFFLINE event */ +struct mosquitto_evt_client_offline { + void *future; + struct mosquitto *client; + int reason; + void *future2[4]; +}; + +/* Data for the MOSQ_EVT_SUBSCRIBE event */ +struct mosquitto_evt_subscribe { + void *future; + struct mosquitto *client; + struct mosquitto_subscription data; + void *future2[8]; +}; + + +/* Data for the MOSQ_EVT_UNSUBSCRIBE event */ +struct mosquitto_evt_unsubscribe { + void *future; + struct mosquitto *client; + struct mosquitto_subscription data; + void *future2[8]; +}; + + +/* Data for the MOSQ_EVT_PERSIST_RESTORE event */ +/* NOTE: The persistence interface is currently marked as unstable, which means + * it may change in a future minor release. */ +struct mosquitto_evt_persist_restore { + void *future[8]; +}; + + +/* Data for the MOSQ_EVT_PERSIST_CLIENT_ADD/_DELETE/_UPDATE event */ +/* NOTE: The persistence interface is currently marked as unstable, which means + * it may change in a future minor release. */ +struct mosquitto_evt_persist_client { + void *future; + struct mosquitto_client data; + void *future2[8]; +}; + + +/* Data for the MOSQ_EVT_PERSIST_SUBSCRIPTION_ADD/_DELETE event */ +/* NOTE: The persistence interface is currently marked as unstable, which means + * it may change in a future minor release. */ +struct mosquitto_evt_persist_subscription { + void *future; + struct mosquitto_subscription data; + void *future2[8]; +}; + + +/* Data for the MOSQ_EVT_PERSIST_CLIENT_MSG_ADD/_DELETE/_UPDATE event */ +/* NOTE: The persistence interface is currently marked as unstable, which means + * it may change in a future minor release. */ +struct mosquitto_evt_persist_client_msg { + void *future; + struct mosquitto_client_msg data; + void *future2[8]; +}; + + +/* Data for the MOSQ_EVT_PERSIST_BASE_MSG_ADD/_DELETE/_LOAD event */ +/* NOTE: The persistence interface is currently marked as unstable, which means + * it may change in a future minor release. */ +struct mosquitto_evt_persist_base_msg { + void *future; + struct mosquitto_base_msg data; + void *future2[8]; +}; + + +/* Data for the MOSQ_EVT_PERSIST_RETAIN_MSG_SET/_DELETE event */ +/* NOTE: The persistence interface is currently marked as unstable, which means + * it may change in a future minor release. */ +struct mosquitto_evt_persist_retain_msg { + void *future; + const char *topic; + uint64_t store_id; + void *future2[8]; +}; + + +/* Callback definition */ +typedef int (*MOSQ_FUNC_generic_callback)(int, void *, void *); + +typedef struct mosquitto_plugin_id_t mosquitto_plugin_id_t; + +/* + * Function: mosquitto_plugin_set_info + * + * Set plugin name and version information for the broker to report. It is + * recommended this is used in the mosquitto_plugin_init() call. + */ +mosq_EXPORT int mosquitto_plugin_set_info( + mosquitto_plugin_id_t *identifier, + const char *plugin_name, + const char *plugin_version); + + +/* + * Function: mosquitto_callback_register + * + * Register a callback for an event. + * + * Parameters: + * identifier - the plugin identifier, as provided by . + * event - the event to register a callback for. Can be one of: + * * MOSQ_EVT_RELOAD + * Called when the broker is sent a signal indicating it should + * reload its configuration. + * * MOSQ_EVT_ACL_CHECK + * Called when a publish/subscribe/unsubscribe command is received + * and the broker wants to check when the client is allowed to carry + * out this command. + * * MOSQ_EVT_BASIC_AUTH + * Called when a client connects to the broker, to allow the + * username/password/clientid to be authenticated. + * * MOSQ_EVT_EXT_AUTH_START + * Called when an MQTT v5 client connects, if it is using extended + * authentication. + * * MOSQ_EVT_EXT_AUTH_CONTINUE + * Called when an MQTT v5 client connects, if it is using extended + * authentication. + * * MOSQ_EVT_CONTROL + * Called on receipt of a $CONTROL message that the plugin has + * registered for. + * * MOSQ_EVT_MESSAGE_IN + * Called for each incoming PUBLISH message after it has been received + * and authorised. The contents of the message can be modified. + * * MOSQ_EVT_MESSAGE_OUT + * Called for each outgoing PUBLISH message after it has been authorised, + * but before it is sent to each subscribing client. The contents of the + * message can be modified. + * * MOSQ_EVT_PSK_KEY + * Called when a client connects with TLS-PSK and the broker needs + * the PSK information. + * * MOSQ_EVT_TICK + * Called periodically in the event loop. At the moment this + * occurs at a regular frequency, but this should not be relied + * upon. + * * MOSQ_EVT_DISCONNECT + * Called when a client disconnects from the broker. + * * MOSQ_EVT_CONNECT + * Called when a client has successfully connected to the broker, + * i.e. has been authenticated. + * * MOSQ_EVT_SUBSCRIBE + * Called when a client has made a successful subscription + * request, but before the subscription is applied. The + * subscription request can be modified, although this is not + * recommended. + * * MOSQ_EVT_UNSUBSCRIBE + * Called when a client has made a successful unsubscription + * request, but before the unsubscription is applied. The + * unsubscription request can be modified, although this is not + * recommended. + * * MOSQ_EVT_PERSIST_RESTORE + * Called on startup when a persistence plugin should restore + * persistence data. + * * MOSQ_EVT_PERSIST_BASE_MSG_ADD + * Called when a persistence plugin must add a base message to its + * store. + * * MOSQ_EVT_PERSIST_BASE_MSG_DELETE + * Called when a persistence plugin must delete a base message + * from its store. + * * MOSQ_EVT_PERSIST_RETAIN_MSG_SET + * Called when a persistence plugin must set or update a retained + * message in its store. + * * MOSQ_EVT_PERSIST_RETAIN_MSG_DELETE + * Called when a persistence plugin must delete a retained message + * from its store. + * * MOSQ_EVT_PERSIST_CLIENT_ADD + * Called when a persistence plugin must add a client session to + * its store. + * * MOSQ_EVT_PERSIST_CLIENT_DELETE + * Called when a persistence plugin must delete a client session + * from its store. + * * MOSQ_EVT_PERSIST_CLIENT_UPDATE + * Called when a persistence plugin must update a client session + * in its store. + * * MOSQ_EVT_PERSIST_SUBSCRIPTION_ADD + * Called when a persistence plugin must add a client subscription + * to its store. + * * MOSQ_EVT_PERSIST_SUBSCRIPTION_DELETE + * Called when a persistence plugin must delete a client + * subscription from its store. + * * MOSQ_EVT_PERSIST_CLIENT_MSG_ADD + * Called when a persistence plugin must add a client message to + * its store. + * * MOSQ_EVT_PERSIST_CLIENT_MSG_DELETE + * Called when a persistence plugin must delete a client message + * from its store. + * * MOSQ_EVT_PERSIST_CLIENT_MSG_UPDATE + * Called when a persistence plugin must update a client message + * in its store. + * + * cb_func - the callback function + * event_data - event specific data + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if cb_func is NULL + * MOSQ_ERR_NOMEM - on out of memory + * MOSQ_ERR_ALREADY_EXISTS - if cb_func has already been registered for this event + * MOSQ_ERR_NOT_SUPPORTED - if the event is not supported + */ +mosq_EXPORT int mosquitto_callback_register( + mosquitto_plugin_id_t *identifier, + int event, + MOSQ_FUNC_generic_callback cb_func, + const void *event_data, + void *userdata); + +/* + * Function: mosquitto_callback_unregister + * + * Unregister a previously registered callback function. + * + * Parameters: + * identifier - the plugin identifier, as provided by . + * event - the event to register a callback for. Can be one of: + * * MOSQ_EVT_RELOAD + * * MOSQ_EVT_ACL_CHECK + * * MOSQ_EVT_BASIC_AUTH + * * MOSQ_EVT_EXT_AUTH_START + * * MOSQ_EVT_EXT_AUTH_CONTINUE + * * MOSQ_EVT_CONTROL + * * MOSQ_EVT_MESSAGE_IN + * * MOSQ_EVT_MESSAGE_OUT + * * MOSQ_EVT_PSK_KEY + * * MOSQ_EVT_TICK + * * MOSQ_EVT_DISCONNECT + * * MOSQ_EVT_CONNECT + * * MOSQ_EVT_SUBSCRIBE + * * MOSQ_EVT_UNSUBSCRIBE + * * MOSQ_EVT_PERSIST_RESTORE + * * MOSQ_EVT_PERSIST_BASE_MSG_ADD + * * MOSQ_EVT_PERSIST_BASE_MSG_DELETE + * * MOSQ_EVT_PERSIST_RETAIN_MSG_SET + * * MOSQ_EVT_PERSIST_RETAIN_MSG_DELETE + * * MOSQ_EVT_PERSIST_CLIENT_ADD + * * MOSQ_EVT_PERSIST_CLIENT_DELETE + * * MOSQ_EVT_PERSIST_CLIENT_UPDATE + * * MOSQ_EVT_PERSIST_SUBSCRIPTION_ADD + * * MOSQ_EVT_PERSIST_SUBSCRIPTION_DELETE + * * MOSQ_EVT_PERSIST_CLIENT_MSG_ADD + * * MOSQ_EVT_PERSIST_CLIENT_MSG_DELETE + * * MOSQ_EVT_PERSIST_CLIENT_MSG_UPDATE + * cb_func - the callback function + * event_data - event specific data + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if cb_func is NULL + * MOSQ_ERR_NOT_FOUND - if cb_func was not registered for this event + * MOSQ_ERR_NOT_SUPPORTED - if the event is not supported + */ +mosq_EXPORT int mosquitto_callback_unregister( + mosquitto_plugin_id_t *identifier, + int event, + MOSQ_FUNC_generic_callback cb_func, + const void *event_data); + + +/* ========================================================================= + * + * Section: Memory allocation. + * + * Use these functions when allocating or freeing memory to have your memory + * included in the memory tracking on the broker. + * + * ========================================================================= */ + +/* + * Function: mosquitto_calloc + */ +mosq_EXPORT void *mosquitto_calloc(size_t nmemb, size_t size); + +/* + * Function: mosquitto_free + */ +mosq_EXPORT void mosquitto_free(void *mem); + +/* + * Function: mosquitto_malloc + */ +mosq_EXPORT void *mosquitto_malloc(size_t size); + +/* + * Function: mosquitto_realloc + */ +mosq_EXPORT void *mosquitto_realloc(void *ptr, size_t size); + +/* + * Function: mosquitto_strdup + */ +mosq_EXPORT char *mosquitto_strdup(const char *s); + +/* + * Function: mosquitto_strndup + */ +mosq_EXPORT char *mosquitto_strndup(const char *s, size_t n); + +/* ========================================================================= + * + * Section: Utility Functions + * + * Use these functions from within your plugin. + * + * ========================================================================= */ + + +/* + * Function: mosquitto_log_printf + * + * Write a log message using the broker configured logging. + * + * Parameters: + * level - Log message priority. Can currently be one of: + * + * * MOSQ_LOG_INFO + * * MOSQ_LOG_NOTICE + * * MOSQ_LOG_WARNING + * * MOSQ_LOG_ERR + * * MOSQ_LOG_DEBUG + * * MOSQ_LOG_SUBSCRIBE (not recommended for use by plugins) + * * MOSQ_LOG_UNSUBSCRIBE (not recommended for use by plugins) + * + * These values are defined in mosquitto.h. + * + * fmt, ... - printf style format and arguments. + */ +mosq_EXPORT void mosquitto_log_printf(int level, const char *fmt, ...); + + +/* ========================================================================= + * + * Client Functions + * + * Use these functions to access client information. + * + * ========================================================================= */ + +/* + * Function: mosquitto_client + * + * Retrieve the struct mosquitto for a client id, or NULL if the client is not connected. + */ +mosq_EXPORT struct mosquitto *mosquitto_client(const char *clientid); + + +/* + * Function: mosquitto_client_address + * + * Retrieve the IP address of the client as a string. + */ +mosq_EXPORT const char *mosquitto_client_address(const struct mosquitto *client); + + +/* + * Function: mosquitto_client_port + * + * Retrieve the network port number the client connected to, or 0 on error. + */ +mosq_EXPORT int mosquitto_client_port(const struct mosquitto *client); + + +/* + * Function: mosquitto_client_clean_session + * + * Retrieve the clean session flag value for a client. + */ +mosq_EXPORT bool mosquitto_client_clean_session(const struct mosquitto *client); + + +/* + * Function: mosquitto_client_id + * + * Retrieve the client id associated with a client. + */ +mosq_EXPORT const char *mosquitto_client_id(const struct mosquitto *client); + + +/* + * Function: mosquitto_client_keepalive + * + * Retrieve the keepalive value for a client. + */ +mosq_EXPORT int mosquitto_client_keepalive(const struct mosquitto *client); + + +/* + * Function: mosquitto_client_certificate + * + * If TLS support is enabled, return the certificate provided by a client as an + * X509 pointer from openssl. If the client did not provide a certificate, then + * NULL will be returned. This function will only ever return a non-NULL value + * if the `require_certificate` option is set to true. + * + * When you have finished with the x509 pointer, it must be freed using + * X509_free(). + * + * If TLS is not supported, this function will always return NULL. + */ +mosq_EXPORT void *mosquitto_client_certificate(const struct mosquitto *client); + + +/* + * Function: mosquitto_client_protocol + * + * Retrieve the protocol with which the client has connected. Can be one of: + * + * mp_mqtt (MQTT over TCP) + * mp_mqttsn (MQTT-SN) + * mp_websockets (MQTT over Websockets) + */ +mosq_EXPORT int mosquitto_client_protocol(const struct mosquitto *client); + + +/* + * Function: mosquitto_client_protocol_version + * + * Retrieve the MQTT protocol version with which the client has connected. Can be one of: + * + * Returns: + * 3 - for MQTT v3 / v3.1 + * 4 - for MQTT v3.1.1 + * 5 - for MQTT v5 + */ +mosq_EXPORT int mosquitto_client_protocol_version(const struct mosquitto *client); + + +/* + * Function: mosquitto_client_sub_count + * + * Retrieve the number of subscriptions that have been made by a client. + */ +mosq_EXPORT int mosquitto_client_sub_count(const struct mosquitto *client); + + +/* + * Function: mosquitto_client_username + * + * Retrieve the username associated with a client. + */ +mosq_EXPORT const char *mosquitto_client_username(const struct mosquitto *client); + + +/* Function: mosquitto_set_username + * + * Set the username for a client. + * + * This removes and replaces the current username for a client and hence + * updates its access. + * + * username can be NULL, in which case the client will become anonymous, but + * must not be zero length. + * + * In the case of error, the client will be left with its original username. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if client is NULL, or if username is zero length + * MOSQ_ERR_NOMEM - on out of memory + */ +mosq_EXPORT int mosquitto_set_username(struct mosquitto *client, const char *username); + +/* Function: mosquitto_set_clientid + * + * Set the client id for a client. + * + * This effectively forces the client onto another message queue. + * Can be used to scope client ids by prefixing the client id with some user-specific data. + * eg. "client1" could become "user1-client1". + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if client is NULL, or if clientid is not a valid utf-8 string + * MOSQ_ERR_NOMEM - on out of memory + */ +mosq_EXPORT int mosquitto_set_clientid(struct mosquitto *client, const char *clientid); + + +/* ========================================================================= + * + * Section: Client control + * + * ========================================================================= */ + +/* Function: mosquitto_kick_client_by_clientid + * + * Forcefully disconnect a client from the broker. + * + * If clientid != NULL, then the client with the matching client id is + * disconnected from the broker. + * If clientid == NULL, then all clients are disconnected from the broker. + * + * If with_will == true, then if the client has a Last Will and Testament + * defined then this will be sent. If false, the LWT will not be sent. + */ +mosq_EXPORT int mosquitto_kick_client_by_clientid(const char *clientid, bool with_will); + +/* Function: mosquitto_kick_client_by_username + * + * Forcefully disconnect a client from the broker. + * + * If username != NULL, then all clients with a matching username are kicked + * from the broker. + * If username == NULL, then all clients that do not have a username are + * kicked. + * + * If with_will == true, then if the client has a Last Will and Testament + * defined then this will be sent. If false, the LWT will not be sent. + */ +mosq_EXPORT int mosquitto_kick_client_by_username(const char *username, bool with_will); + +/* Function: mosquitto_apply_on_all_clients + * + * Apply a given functor to all clients + * + * The functor will be applied to all existing client structures. If the functor + * returns an error code the iteration over the clients will be stopped. The + * functor_context pointer maybe used to pass additional data structures into + * the functor as second argument. + * + * The result value will be the result of the last functor invoked. + */ +mosq_EXPORT int mosquitto_apply_on_all_clients(int (*FUNC_client_functor)(const struct mosquitto *, void *), void *functor_context); + +/* ========================================================================= + * + * Section: Publishing functions + * + * ========================================================================= */ + +/* Function: mosquitto_broker_publish + * + * Publish a message from within a plugin. + * + * This function allows a plugin to publish a message. Messages published in + * this way are treated as coming from the broker and so will not be passed to + * `mosquitto_auth_acl_check(, MOSQ_ACL_WRITE, , )` for checking. Read access + * will be enforced as normal for individual clients when they are due to + * receive the message. + * + * It can be used to send messages to all clients that have a matching + * subscription, or to a single client whether or not it has a matching + * subscription. + * + * Parameters: + * clientid - optional string. If set to NULL, the message is delivered to all + * clients. If non-NULL, the message is delivered only to the + * client with the corresponding client id. If the client id + * specified is not connected, the message will be dropped. + * topic - message topic + * payloadlen - payload length in bytes. Can be 0 for an empty payload. + * payload - payload bytes. If payloadlen > 0 this must not be NULL. Must + * be allocated on the heap. Will be freed by mosquitto after use if the + * function returns success. + * qos - message QoS to use. + * retain - should retain be set on the message. This does not apply if + * clientid is non-NULL. + * properties - MQTT v5 properties to attach to the message. If the function + * returns success, then properties is owned by the broker and + * will be freed at a later point. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if topic is NULL, if payloadlen < 0, if payloadlen > 0 + * and payload is NULL, if qos is not 0, 1, or 2. + * MOSQ_ERR_NOMEM - on out of memory + */ +mosq_EXPORT int mosquitto_broker_publish( + const char *clientid, + const char *topic, + int payloadlen, + void *payload, + int qos, + bool retain, + mosquitto_property *properties); + + +/* Function: mosquitto_broker_publish_copy + * + * Publish a message from within a plugin. + * + * This function is identical to mosquitto_broker_publish, except that a copy + * of `payload` is taken. + * + * Parameters: + * clientid - optional string. If set to NULL, the message is delivered to all + * clients. If non-NULL, the message is delivered only to the + * client with the corresponding client id. If the client id + * specified is not connected, the message will be dropped. + * topic - message topic + * payloadlen - payload length in bytes. Can be 0 for an empty payload. + * payload - payload bytes. If payloadlen > 0 this must not be NULL. + * Memory remains the property of the calling function. + * qos - message QoS to use. + * retain - should retain be set on the message. This does not apply if + * clientid is non-NULL. + * properties - MQTT v5 properties to attach to the message. If the function + * returns success, then properties is owned by the broker and + * will be freed at a later point. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if topic is NULL, if payloadlen < 0, if payloadlen > 0 + * and payload is NULL, if qos is not 0, 1, or 2. + * MOSQ_ERR_NOMEM - on out of memory + */ +mosq_EXPORT int mosquitto_broker_publish_copy( + const char *clientid, + const char *topic, + int payloadlen, + const void *payload, + int qos, + bool retain, + mosquitto_property *properties); + +/* Function: mosquitto_complete_basic_auth + * + * Complete a delayed authentication request. + * + * Useful for plugins that subscribe to the MOSQ_EVT_BASIC_AUTH event. If your + * plugin makes authentication requests that are not "instant", in particular + * if they communicate with an external service, then instead of blocking for a + * reply and returning MOSQ_ERR_SUCCESS or MOSQ_ERR_AUTH, the plugin can return + * MOSQ_ERR_AUTH_DELAYED. This means that the plugin is promising to tell the + * broker the authentication result in the future. Once the plugin has an + * answer, it should call `mosquitto_complete_basic_auth()` passing the client + * id and the result. + * + * Result: + * MOSQ_ERR_SUCCESS - the client successfully authenticated + * MOSQ_ERR_AUTH - the client authentication failed + * + * Other error codes can be used if more appropriate, and the client connection + * will still be rejected, e.g. MOSQ_ERR_NOMEM. + * + * The plugin may use extra threads to handle the authentication requests, but + * the call to `mosquitto_complete_basic_auth()` must happen in the main + * mosquitto thread. Using the MOSQ_EVT_TICK event for this is suggested. + */ +mosq_EXPORT void mosquitto_complete_basic_auth(const char* clientid, int result); + + +/* Function: mosquitto_broker_node_id_set + * + * Set a node ID for this broker between 0-1023 inclusive. This is used to help + * generate unique client message IDs and hence can be useful for persistence + * plugins where brokers are sharing a database. It is down to the plugin to ensure + * this ID is unique. + * + * Result: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - the value was > 1023. + */ +mosq_EXPORT int mosquitto_broker_node_id_set(uint16_t id); + + +/* ================================================================= + * + * Persistence interface + * + * ================================================================= */ + +/* NOTE: The persistence interface is currently marked as unstable, which means + * it may change in a future minor release. */ + + +/* Function: mosquitto_persist_client_add + * + * Use to add a new client session, in particular when restoring on starting + * the broker. + * + * Parameters: + * client->clientid - the client id of the client to add. + * This must be allocated on the heap and becomes the property of the + * broker immediately this call is made. Must not be NULL. + * client->username - the username for the client session, or NULL. Must + * be allocated on the heap and becomes the property of the broker + * immediately this call is made. + * client->auth_method - the MQTT v5 extended authentication method, + * or NULL. Must be allocated on the heap and becomes the property of + * the broker immediately this call is made. + * client->will_delay_time - the actual will delay time for this client + * client->session_expiry_time - the actual session expiry time for this + * client + * client->will_delay_interval - the MQTT v5 will delay interval for this + * client + * client->maximum_packet_size - the MQTT v5 maximum packet size parameter + * for this client + * client->listener_port - the listener port that this client last connected to + * client->max_qos - the MQTT v5 maximum QoS parameter for this client + * client->retain_available - the MQTT v5 retain available parameter for this + * client + * + * All other members of struct mosquitto_client are unused. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if client or client->plugin_clientid is NULL, or if a + * client with the same ID already exists. + * MOSQ_ERR_NOMEM - on out of memory + */ +mosq_EXPORT int mosquitto_persist_client_add(struct mosquitto_client *client); + + +/* Function: mosquitto_persist_client_update + * + * Use to update client session parameters + * + * Parameters: + * client->clientid - the client id of the client to update + * The broker will *not* modify this string and it remains the + * property of the plugin. + * client->username - the new username for the client session, or NULL. Must + * be allocated on the heap and becomes the property of the broker + * immediately this call is made. + * client->will_delay_time - the actual will delay time for this client + * client->session_expiry_time - the actual session expiry time for this + * client + * client->will_delay_interval - the MQTT v5 will delay interval for this + * client + * client->maximum_packet_size - the MQTT v5 maximum packet size parameter + * for this client + * client->listener_port - the listener port that this client last connected to + * client->max_qos - the MQTT v5 maximum QoS parameter for this client + * client->retain_available - the MQTT v5 retain available parameter for this + * client + * + * All other members of struct mosquitto_client are unused. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if client or client->clientid is NULL + * MOSQ_ERR_NOT_FOUND - the client is not found + */ +mosq_EXPORT int mosquitto_persist_client_update(struct mosquitto_client *client); + + +/* Function: mosquitto_persist_client_delete + * + * Use to delete client session for a client from the broker + * + * Parameters: + * clientid - the client id of the client to delete + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if clientid is NULL + * MOSQ_ERR_NOT_FOUND - the referenced client is not found + */ +mosq_EXPORT int mosquitto_persist_client_delete(const char *clientid); + + +/* Function: mosquitto_persist_client_msg_add + * + * Use to add a client message for a particular client. + * + * Parameters: + * client_msg->clientid - the client id of the client that the + * message belongs to. + * client_msg->cmsg_id - the ID of this client message. + * client_msg->store_id - the ID of the base message that this client + * message references. + * client_msg->subscription_identifier - the MQTT v5 subscription identifier, + * for outgoing messages only. + * client_msg->mid - the MQTT message ID of the new message + * client_msg->qos - the MQTT QoS of the new message + * client_msg->retain - the retain flag of the message + * client_msg->dup - the dup flag of the message + * client_msg->direction - the direction of the new message from the perspective + * of the broker (mosq_bmd_in / mosq_bmd_out) + * client_msg->state - the current message state + * + * All other members of struct mosquitto_client_msg are unused. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if client_msg or client_msg->plugin_clientid is NULL + * MOSQ_ERR_NOT_FOUND - the client or base message is not found + */ +mosq_EXPORT int mosquitto_persist_client_msg_add(struct mosquitto_client_msg *client_msg); + + +/* Function: mosquitto_persist_client_msg_delete + * + * Use to delete a client message for a particular client. + * + * Parameters: + * client_msg->clientid - the client id of the client that the + * message belongs to. + * client_msg->cmsg_id - the client message id of the affected message + * client_msg->mid - the MQTT message id of the affected message + * client_msg->qos - the MQTT QoS of the affected message + * client_msg->direction - the direction of the message from the perspective + * of the broker (mosq_bmd_in / mosq_bmd_out) + * + * All other members of struct mosquitto_client_msg are unused. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if client_msg or client_msg->clientid is NULL + * MOSQ_ERR_NOT_FOUND - the client is not found + */ +mosq_EXPORT int mosquitto_persist_client_msg_delete(struct mosquitto_client_msg *client_msg); + + +/* Function: mosquitto_persist_client_msg_update + * + * Use to update the state of a client message for a particular client. + * + * Parameters: + * client_msg->clientid - the client id of the client that the + * message belongs to. + * client_msg->cmsg_id - the client message id of the affected message + * client_msg->mid - the MQTT message id of the affected message + * client_msg->qos - the MQTT QoS of the affected message + * client_msg->direction - the direction of the message from the perspective + * of the broker (mosq_bmd_in / mosq_bmd_out) + * client_msg->state - the new state of the message + * + * All other members of struct mosquitto_client_msg are unused. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if client_msg or client_msg->clientid is NULL + * MOSQ_ERR_NOT_FOUND - the client is not found + */ +mosq_EXPORT int mosquitto_persist_client_msg_update(struct mosquitto_client_msg *client_msg); + + +/* Function: mosquitto_persist_client_msg_clear + * + * Clear all messages for the listed client and direction. + * + * Parameters: + * client_msg->clientid - the client id of the client that the + * message belongs to. + * client_msg->direction - the direction of the messages to be cleared, from + * the perspective of the broker (mosq_bmd_in / mosq_bmd_out / mosq_bmd_all) + * + * All other members of struct mosquitto_client_msg are unused. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if client_msg or client_msg->clientid is NULL + * MOSQ_ERR_NOT_FOUND - the client is not found + */ +mosq_EXPORT int mosquitto_persist_client_msg_clear(struct mosquitto_client_msg *client_msg); + +/* Function: mosquitto_persist_base_msg_add + * + * Use to add a new base message. Any client messages or retained messages + * refering to this base message must be added afterwards. + * + * Parameters: + * msg->store_id - the base message ID + * msg->expiry_time - the time at which the message expires, or 0. + * msg->topic - the message topic. + * Must be allocated on the heap and becomes the property of the + * broker immediately this call is made. + * msg->payload - the message payload. + * Must be allocated on the heap and becomes the property of the + * broker immediately this call is made. + * msg->source_id - the client id of the client that the + * message originated with, or NULL. + * The broker will *not* modify this string and it remains the + * property of the plugin. + * msg->source_username - the username of the client that the + * message originated with, or NULL. + * The broker will *not* modify this string and it remains the + * property of the plugin. + * msg->properties - list of MQTT v5 message properties for this message. + * Must be allocated on the heap and becomes the property of the + * broker immediately this call is made. + * msg->payloadlen - the length of the payload, in bytes + * msg->source_mid - the mid of the source message + * msg->source_port - the network port number that the originating client was + * connected to, or 0. + * msg->qos - the message QoS as delivered to the broker + * msg->retain - the message retain flag as delivered to the broker + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_NOMEM - on out of memory + */ +mosq_EXPORT int mosquitto_persist_base_msg_add(struct mosquitto_base_msg *msg); + + +/* Function: mosquitto_persist_base_msg_delete + * + * Use to delete a base message. + * + * Parameters: + * store_id - the base message ID + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + */ +mosq_EXPORT int mosquitto_persist_base_msg_delete(uint64_t store_id); + + +/* Function: mosquitto_persist_subscription_add + * + * Use to add a new subscription for a client + * + * Parameters: + * sub->clientid - the client id of the client the new subscription is for + * sub->topic_filter - the topic filter for the subscription + * sub->options - the QoS and other flags for this subscription + * sub->identifier - the MQTT v5 subscription id, or 0 + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if sub, clientid, or topic_filter are NULL, or are zero length + * MOSQ_ERR_NOT_FOUND - the referenced client was not found + * MOSQ_ERR_NOMEM - on out of memory + */ +mosq_EXPORT int mosquitto_subscription_add(const struct mosquitto_subscription *sub); + + +/* Function: mosquitto_persist_subscription_delete + * + * Use to delete a subscription for a client + * + * Parameters: + * clientid - the client id of the client the new subscription is for + * topic_filter - the topic filter for the subscription + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if clientid or topic are NULL, or are zero length + * MOSQ_ERR_NOT_FOUND - the referenced client was not found + * MOSQ_ERR_NOMEM - on out of memory + */ +mosq_EXPORT int mosquitto_subscription_delete(const char *clientid, const char *topic_filter); + + +/* Function: mosquitto_persist_retain_msg_set + * + * Use to set a retained message. It is not required to delete a retained + * message for an existing topic first. + * + * Parameters: + * topic - the topic that the message references + * store_id - the ID of the base message that is to be retained + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if topic is NULL + * MOSQ_ERR_NOT_FOUND - the referenced base message was not found + * MOSQ_ERR_NOMEM - on out of memory + */ +mosq_EXPORT int mosquitto_persist_retain_msg_set(const char *topic, uint64_t store_id); + + +/* Function: mosquitto_persist_retain_msg_delete + * + * Use to delete a retained message. + * + * Parameters: + * topic - the topic that the message references + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if topic is NULL + * MOSQ_ERR_NOMEM - on out of memory + */ +mosq_EXPORT int mosquitto_persist_retain_msg_delete(const char *topic); + +/* Function: mosquitto_persistence_location + * + * Returns the `persistence_location` config option, or the contents of the + * MOSQUITTO_PERSISTENCE_LOCATION environment variable, if set. + * + * This location should be used by plugins needing to store persistent data. + * Use of sub directories is recommended. + * + * Returns: + * A valid pointer to the persistence location string + * A NULL pointer if neither the option nor the variable are set + */ +mosq_EXPORT const char *mosquitto_persistence_location(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/mosquitto_control.h b/include/mosquitto/broker_control.h similarity index 90% rename from include/mosquitto_control.h rename to include/mosquitto/broker_control.h index 4b519361..bbc339f9 100644 --- a/include/mosquitto_control.h +++ b/include/mosquitto/broker_control.h @@ -17,12 +17,12 @@ Contributors: */ /* - * File: mosquitto_control.h + * File: mosquitto/control.h * * This header contains functions for use by plugins using the CONTROL event. */ -#ifndef MOSQUITTO_CONTROL_H -#define MOSQUITTO_CONTROL_H +#ifndef MOSQUITTO_BROKER_CONTROL_H +#define MOSQUITTO_BROKER_CONTROL_H #ifdef __cplusplus extern "C" { @@ -30,9 +30,9 @@ extern "C" { #include -#include +#include #include -#include +#include /* ========================================================================= diff --git a/include/mosquitto/broker_plugin.h b/include/mosquitto/broker_plugin.h new file mode 100644 index 00000000..2c07656b --- /dev/null +++ b/include/mosquitto/broker_plugin.h @@ -0,0 +1,441 @@ +/* +Copyright (c) 2012-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_BROKER_PLUGIN_H +#define MOSQUITTO_BROKER_PLUGIN_H + +/* + * File: mosquitto_plugin.h + * + * This header contains function declarations for use when writing a Mosquitto plugin. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* The generic plugin interface starts at version 5 */ +#define MOSQ_PLUGIN_VERSION 5 + +/* The old auth only interface stopped at version 4 */ +#define MOSQ_AUTH_PLUGIN_VERSION 4 + +#define MOSQ_ACL_NONE 0x00 +#define MOSQ_ACL_READ 0x01 +#define MOSQ_ACL_WRITE 0x02 +#define MOSQ_ACL_SUBSCRIBE 0x04 +#define MOSQ_ACL_UNSUBSCRIBE 0x08 + +#include +#include + +#include +#include + +struct mosquitto; + +struct mosquitto_opt { + char *key; + char *value; +}; + +struct mosquitto_auth_opt { + char *key; + char *value; +}; + +struct mosquitto_acl_msg { + const char *topic; + const void *payload; + long payloadlen; + int qos; + bool retain; +}; + +#ifdef WIN32 +# define mosq_plugin_EXPORT __declspec(dllexport) +#else +# define mosq_plugin_EXPORT +#endif + +/* + * To create an authentication plugin you must include this file then implement + * the functions listed in the "Plugin Functions" section below. The resulting + * code should then be compiled as a shared library. Using gcc this can be + * achieved as follows: + * + * gcc -I -fPIC -shared plugin.c -o plugin.so + * + * On Mac OS X: + * + * gcc -I -fPIC -shared plugin.c -undefined dynamic_lookup -o plugin.so + * + */ + +/* ========================================================================= + * + * Helper Functions + * + * ========================================================================= */ + +/* There are functions that are available for plugin developers to use in + * mosquitto_broker.h, including logging and accessor functions. + */ + + +/* ========================================================================= + * + * Section: Plugin Functions v5 + * + * This is the plugin version 5 interface, which covers authentication, access + * control, the $CONTROL topic space handling, and message inspection and + * modification. + * + * This interface is available from v2.0 onwards. + * + * There are just three functions to implement in your plugin. You should + * register callbacks to handle different events in your + * mosquitto_plugin_init() function. See mosquitto_broker.h for the events and + * callback registering functions. + * + * ========================================================================= */ + +/* + * Function: mosquitto_plugin_version + * + * The broker will attempt to call this function immediately after loading the + * plugin to check it is a supported plugin version. Your code must simply + * return the plugin interface version you support, i.e. 5. + * + * The supported_versions array tells you which plugin versions the broker supports. + * + * If the broker does not support the version that you require, return -1 to + * indicate failure. + * + * HELPER: If you only wish to declare support for a single version, you can + * use the helper macro: + * + * MOSQUITTO_PLUGIN_DECLARE_VERSION(5); + */ +mosq_plugin_EXPORT int mosquitto_plugin_version(int supported_version_count, const int *supported_versions); + +#define MOSQUITTO_PLUGIN_DECLARE_VERSION(A) \ + int mosquitto_plugin_version(int supported_version_count, const int *supported_versions) \ + { \ + int i; \ + for(i=0; i + * has been called. This will only ever be called once and can be used to + * initialise the plugin. + * + * Parameters: + * + * identifier - This is a pointer to an opaque structure which you must + * save and use when registering/unregistering callbacks. + * user_data - The pointer set here will be passed to the other plugin + * functions. Use to hold connection information for example. + * opts - Pointer to an array of struct mosquitto_opt, which + * provides the plugin options defined in the configuration file. + * opt_count - The number of elements in the opts array. + * + * Return value: + * Return 0 on success + * Return >0 on failure. + */ +mosq_plugin_EXPORT int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **userdata, struct mosquitto_opt *options, int option_count); + + +/* + * Function: mosquitto_plugin_cleanup + * + * Called when the broker is shutting down. This will only ever be called once + * per plugin. + * + * If you do not need to do any of your own cleanup, this function is not + * required. The broker will automatically unregister your callbacks. + * + * Parameters: + * + * user_data - The pointer provided in . + * opts - Pointer to an array of struct mosquitto_opt, which + * provides the plugin options defined in the configuration file. + * opt_count - The number of elements in the opts array. + * + * Return value: + * Return 0 on success + * Return >0 on failure. + */ +mosq_plugin_EXPORT int mosquitto_plugin_cleanup(void *userdata, struct mosquitto_opt *options, int option_count); + + + +/* ========================================================================= + * + * Section: Plugin Functions v4 + * + * This is the plugin version 4 interface, which is exclusively for + * authentication and access control, and which is still supported for existing + * plugins. If you are developing a new plugin, please use the v5 interface. + * + * You must implement these functions in your plugin. + * + * Authentication plugins can implement one or both of authentication and + * access control. If your plugin does not wish to handle either of + * authentication or access control it should return MOSQ_ERR_PLUGIN_DEFER. In + * this case, the next plugin will handle it. If all plugins return + * MOSQ_ERR_PLUGIN_DEFER, the request will be denied. + * + * For each check, the following flow happens: + * + * * The default password file and/or acl file checks are made. If either one + * of these is not defined, then they are considered to be deferred. If either + * one accepts the check, no further checks are made. If an error occurs, the + * check is denied + * * The first plugin does the check, if it returns anything other than + * MOSQ_ERR_PLUGIN_DEFER, then the check returns immediately. If the plugin + * returns MOSQ_ERR_PLUGIN_DEFER then the next plugin runs its check. + * * If the final plugin returns MOSQ_ERR_PLUGIN_DEFER, then access will be + * denied. + * ========================================================================= */ + +/* + * Function: mosquitto_auth_plugin_version + * + * The broker will call this function immediately after loading the plugin to + * check it is a supported plugin version. Your code must simply return + * the version of the plugin interface you support, i.e. 4. + */ +mosq_plugin_EXPORT int mosquitto_auth_plugin_version(void); + + +/* + * Function: mosquitto_auth_plugin_init + * + * Called after the plugin has been loaded and + * has been called. This will only ever be called once and can be used to + * initialise the plugin. + * + * Parameters: + * + * user_data - The pointer set here will be passed to the other plugin + * functions. Use to hold connection information for example. + * opts - Pointer to an array of struct mosquitto_opt, which + * provides the plugin options defined in the configuration file. + * opt_count - The number of elements in the opts array. + * + * Return value: + * Return 0 on success + * Return >0 on failure. + */ +mosq_plugin_EXPORT int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *opts, int opt_count); + + +/* + * Function: mosquitto_auth_plugin_cleanup + * + * Called when the broker is shutting down. This will only ever be called once + * per plugin. + * Note that will be called directly before + * this function. + * + * Parameters: + * + * user_data - The pointer provided in . + * opts - Pointer to an array of struct mosquitto_opt, which + * provides the plugin options defined in the configuration file. + * opt_count - The number of elements in the opts array. + * + * Return value: + * Return 0 on success + * Return >0 on failure. + */ +mosq_plugin_EXPORT int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count); + + +/* + * Function: mosquitto_auth_security_init + * + * This function is called in two scenarios: + * + * 1. When the broker starts up. + * 2. If the broker is requested to reload its configuration whilst running. In + * this case, will be called first, then + * this function will be called. In this situation, the reload parameter + * will be true. + * + * Parameters: + * + * user_data - The pointer provided in . + * opts - Pointer to an array of struct mosquitto_opt, which + * provides the plugin options defined in the configuration file. + * opt_count - The number of elements in the opts array. + * reload - If set to false, this is the first time the function has + * been called. If true, the broker has received a signal + * asking to reload its configuration. + * + * Return value: + * Return 0 on success + * Return >0 on failure. + */ +mosq_plugin_EXPORT int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *opts, int opt_count, bool reload); + + +/* + * Function: mosquitto_auth_security_cleanup + * + * This function is called in two scenarios: + * + * 1. When the broker is shutting down. + * 2. If the broker is requested to reload its configuration whilst running. In + * this case, this function will be called, followed by + * . In this situation, the reload parameter + * will be true. + * + * Parameters: + * + * user_data - The pointer provided in . + * opts - Pointer to an array of struct mosquitto_opt, which + * provides the plugin options defined in the configuration file. + * opt_count - The number of elements in the opts array. + * reload - If set to false, this is the first time the function has + * been called. If true, the broker has received a signal + * asking to reload its configuration. + * + * Return value: + * Return 0 on success + * Return >0 on failure. + */ +mosq_plugin_EXPORT int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count, bool reload); + + +/* + * Function: mosquitto_auth_acl_check + * + * Called by the broker when topic access must be checked. access will be one + * of: + * MOSQ_ACL_SUBSCRIBE when a client is asking to subscribe to a topic string. + * This differs from MOSQ_ACL_READ in that it allows you to + * deny access to topic strings rather than by pattern. For + * example, you may use MOSQ_ACL_SUBSCRIBE to deny + * subscriptions to '#', but allow all topics in + * MOSQ_ACL_READ. This allows clients to subscribe to any + * topic they want, but not discover what topics are in use + * on the server. + * MOSQ_ACL_READ when a message is about to be sent to a client (i.e. whether + * it can read that topic or not). + * MOSQ_ACL_WRITE when a message has been received from a client (i.e. whether + * it can write to that topic or not). + * + * Return: + * MOSQ_ERR_SUCCESS if access was granted. + * MOSQ_ERR_ACL_DENIED if access was not granted. + * MOSQ_ERR_UNKNOWN for an application specific error. + * MOSQ_ERR_PLUGIN_DEFER if your plugin does not wish to handle this check. + */ +mosq_plugin_EXPORT int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *client, const struct mosquitto_acl_msg *msg); + + +/* + * Function: mosquitto_auth_unpwd_check + * + * This function is OPTIONAL. Only include this function in your plugin if you + * are making basic username/password checks. + * + * Called by the broker when a username/password must be checked. + * + * Return: + * MOSQ_ERR_SUCCESS if the user is authenticated. + * MOSQ_ERR_AUTH if authentication failed. + * MOSQ_ERR_UNKNOWN for an application specific error. + * MOSQ_ERR_PLUGIN_DEFER if your plugin does not wish to handle this check. + */ +mosq_plugin_EXPORT int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const char *username, const char *password); + + +/* + * Function: mosquitto_psk_key_get + * + * This function is OPTIONAL. Only include this function in your plugin if you + * are making TLS-PSK checks. + * + * Called by the broker when a client connects to a listener using TLS/PSK. + * This is used to retrieve the pre-shared-key associated with a client + * identity. + * + * Examine hint and identity to determine the required PSK (which must be a + * hexadecimal string with no leading "0x") and copy this string into key. + * + * Parameters: + * user_data - the pointer provided in . + * hint - the psk_hint for the listener the client is connecting to. + * identity - the identity string provided by the client + * key - a string where the hex PSK should be copied + * max_key_len - the size of key + * + * Return value: + * Return 0 on success. + * Return >0 on failure. + * Return MOSQ_ERR_PLUGIN_DEFER if your plugin does not wish to handle this check. + */ +mosq_plugin_EXPORT int mosquitto_auth_psk_key_get(void *user_data, struct mosquitto *client, const char *hint, const char *identity, char *key, int max_key_len); + +/* + * Function: mosquitto_auth_start + * + * This function is OPTIONAL. Only include this function in your plugin if you + * are making extended authentication checks. + * + * Parameters: + * user_data - the pointer provided in . + * method - the authentication method + * reauth - this is set to false if this is the first authentication attempt + * on a connection, set to true if the client is attempting to + * reauthenticate. + * data_in - pointer to authentication data, or NULL + * data_in_len - length of data_in, in bytes + * data_out - if your plugin wishes to send authentication data back to the + * client, allocate some memory using malloc or friends and set + * data_out. The broker will free the memory after use. + * data_out_len - Set the length of data_out in bytes. + * + * Return value: + * Return MOSQ_ERR_SUCCESS if authentication was successful. + * Return MOSQ_ERR_AUTH_CONTINUE if the authentication is a multi step process and can continue. + * Return MOSQ_ERR_AUTH if authentication was valid but did not succeed. + * Return any other relevant positive integer MOSQ_ERR_* to produce an error. + */ +mosq_plugin_EXPORT int mosquitto_auth_start(void *user_data, struct mosquitto *client, const char *method, bool reauth, const void *data_in, uint16_t data_in_len, void **data_out, uint16_t *data_out_len); + +mosq_plugin_EXPORT int mosquitto_auth_continue(void *user_data, struct mosquitto *client, const char *method, const void *data_in, uint16_t data_in_len, void **data_out, uint16_t *data_out_len); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/defs.h b/include/mosquitto/defs.h new file mode 100644 index 00000000..9adfeeb5 --- /dev/null +++ b/include/mosquitto/defs.h @@ -0,0 +1,125 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_DEFS_H +#define MOSQUITTO_DEFS_H + +/* + * File: mosquitto/defs.h + * + * This header contains defines and enums used by the mosquitto broker and + * libmosquitto, the Mosquitto client library. + */ +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* Log types */ +#define MOSQ_LOG_NONE 0 +#define MOSQ_LOG_INFO (1<<0) +#define MOSQ_LOG_NOTICE (1<<1) +#define MOSQ_LOG_WARNING (1<<2) +#define MOSQ_LOG_ERR (1<<3) +#define MOSQ_LOG_DEBUG (1<<4) +#define MOSQ_LOG_SUBSCRIBE (1<<5) +#define MOSQ_LOG_UNSUBSCRIBE (1<<6) +#define MOSQ_LOG_WEBSOCKETS (1<<7) +#define MOSQ_LOG_INTERNAL 0x80000000U +#define MOSQ_LOG_ALL 0xFFFFFFFFU + +/* Enum: mosq_err_t + * Integer values returned from many libmosquitto functions. */ +enum mosq_err_t { + MOSQ_ERR_QUOTA_EXCEEDED = -6, + MOSQ_ERR_AUTH_DELAYED = -5, + MOSQ_ERR_AUTH_CONTINUE = -4, + MOSQ_ERR_NO_SUBSCRIBERS = -3, + MOSQ_ERR_SUB_EXISTS = -2, + 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, + MOSQ_ERR_PROXY = 16, + MOSQ_ERR_PLUGIN_DEFER = 17, + MOSQ_ERR_MALFORMED_UTF8 = 18, + MOSQ_ERR_KEEPALIVE = 19, + MOSQ_ERR_LOOKUP = 20, + MOSQ_ERR_MALFORMED_PACKET = 21, + MOSQ_ERR_DUPLICATE_PROPERTY = 22, + MOSQ_ERR_TLS_HANDSHAKE = 23, + MOSQ_ERR_QOS_NOT_SUPPORTED = 24, + MOSQ_ERR_OVERSIZE_PACKET = 25, + MOSQ_ERR_OCSP = 26, + MOSQ_ERR_TIMEOUT = 27, + /* 28, 29, 30 - was internal only, moved to MQTT v5 section. */ + MOSQ_ERR_ALREADY_EXISTS = 31, + MOSQ_ERR_PLUGIN_IGNORE = 32, + MOSQ_ERR_HTTP_BAD_ORIGIN = 33, + + /* MQTT v5 direct equivalents 128-255 */ + MOSQ_ERR_UNSPECIFIED = 128, + MOSQ_ERR_IMPLEMENTATION_SPECIFIC = 131, + MOSQ_ERR_CLIENT_IDENTIFIER_NOT_VALID = 133, + MOSQ_ERR_BAD_USERNAME_OR_PASSWORD = 134, + MOSQ_ERR_SERVER_UNAVAILABLE = 136, + MOSQ_ERR_SERVER_BUSY = 137, + MOSQ_ERR_BANNED = 138, + MOSQ_ERR_BAD_AUTHENTICATION_METHOD = 140, + MOSQ_ERR_SESSION_TAKEN_OVER = 142, + MOSQ_ERR_RECEIVE_MAXIMUM_EXCEEDED = 147, + MOSQ_ERR_TOPIC_ALIAS_INVALID = 148, + MOSQ_ERR_ADMINISTRATIVE_ACTION = 152, + MOSQ_ERR_RETAIN_NOT_SUPPORTED = 154, + MOSQ_ERR_CONNECTION_RATE_EXCEEDED = 159, +}; + +enum mosq_transport_t { + MOSQ_T_TCP = 1, + MOSQ_T_WEBSOCKETS = 2, +}; + +/* MQTT specification restricts client ids to a maximum of 23 characters */ +#define MOSQ_MQTT_ID_MAX_LENGTH 23 + +#define MQTT_PROTOCOL_V31 3 +#define MQTT_PROTOCOL_V311 4 +#define MQTT_PROTOCOL_V5 5 + +struct mosquitto; +typedef struct mqtt5__property mosquitto_property; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libcommon.h b/include/mosquitto/libcommon.h new file mode 100644 index 00000000..5f8d7701 --- /dev/null +++ b/include/mosquitto/libcommon.h @@ -0,0 +1,39 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBCOMMON_H +#define MOSQUITTO_LIBCOMMON_H + +/* + * File: mosquitto/libcommon.h + */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/mosquitto/libcommon_properties.h b/include/mosquitto/libcommon_properties.h new file mode 100644 index 00000000..7de718b0 --- /dev/null +++ b/include/mosquitto/libcommon_properties.h @@ -0,0 +1,752 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBCOMMON_PROPERTIES_H +#define MOSQUITTO_LIBCOMMON_PROPERTIES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= + * + * Section: Properties + * + * ============================================================================= + */ + + +/* + * Function: mosquitto_property_add_byte + * + * Add a new byte property to a property list. + * + * If *proplist == NULL, a new list will be created, otherwise the new property + * will be appended to the list. + * + * Parameters: + * proplist - pointer to mosquitto_property pointer, the list of properties + * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) + * value - integer value for the new property + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL + * MOSQ_ERR_NOMEM - on out of memory + * + * Example: + * > mosquitto_property *proplist = NULL; + * > mosquitto_property_add_byte(&proplist, MQTT_PROP_PAYLOAD_FORMAT_IDENTIFIER, 1); + */ +libmosq_EXPORT int mosquitto_property_add_byte(mosquitto_property **proplist, int identifier, uint8_t value); + +/* + * Function: mosquitto_property_add_int16 + * + * Add a new int16 property to a property list. + * + * If *proplist == NULL, a new list will be created, otherwise the new property + * will be appended to the list. + * + * Parameters: + * proplist - pointer to mosquitto_property pointer, the list of properties + * identifier - property identifier (e.g. MQTT_PROP_RECEIVE_MAXIMUM) + * value - integer value for the new property + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL + * MOSQ_ERR_NOMEM - on out of memory + * + * Example: + * > mosquitto_property *proplist = NULL; + * > mosquitto_property_add_int16(&proplist, MQTT_PROP_RECEIVE_MAXIMUM, 1000); + */ +libmosq_EXPORT int mosquitto_property_add_int16(mosquitto_property **proplist, int identifier, uint16_t value); + +/* + * Function: mosquitto_property_add_int32 + * + * Add a new int32 property to a property list. + * + * If *proplist == NULL, a new list will be created, otherwise the new property + * will be appended to the list. + * + * Parameters: + * proplist - pointer to mosquitto_property pointer, the list of properties + * identifier - property identifier (e.g. MQTT_PROP_MESSAGE_EXPIRY_INTERVAL) + * value - integer value for the new property + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL + * MOSQ_ERR_NOMEM - on out of memory + * + * Example: + * > mosquitto_property *proplist = NULL; + * > mosquitto_property_add_int32(&proplist, MQTT_PROP_MESSAGE_EXPIRY_INTERVAL, 86400); + */ +libmosq_EXPORT int mosquitto_property_add_int32(mosquitto_property **proplist, int identifier, uint32_t value); + +/* + * Function: mosquitto_property_add_varint + * + * Add a new varint property to a property list. + * + * If *proplist == NULL, a new list will be created, otherwise the new property + * will be appended to the list. + * + * Parameters: + * proplist - pointer to mosquitto_property pointer, the list of properties + * identifier - property identifier (e.g. MQTT_PROP_SUBSCRIPTION_IDENTIFIER) + * value - integer value for the new property + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL + * MOSQ_ERR_NOMEM - on out of memory + * + * Example: + * > mosquitto_property *proplist = NULL; + * > mosquitto_property_add_varint(&proplist, MQTT_PROP_SUBSCRIPTION_IDENTIFIER, 1); + */ +libmosq_EXPORT int mosquitto_property_add_varint(mosquitto_property **proplist, int identifier, uint32_t value); + +/* + * Function: mosquitto_property_add_binary + * + * Add a new binary property to a property list. + * + * If *proplist == NULL, a new list will be created, otherwise the new property + * will be appended to the list. + * + * Parameters: + * proplist - pointer to mosquitto_property pointer, the list of properties + * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) + * value - pointer to the property data + * len - length of property data in bytes + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL + * MOSQ_ERR_NOMEM - on out of memory + * + * Example: + * > mosquitto_property *proplist = NULL; + * > mosquitto_property_add_binary(&proplist, MQTT_PROP_AUTHENTICATION_DATA, auth_data, auth_data_len); + */ +libmosq_EXPORT int mosquitto_property_add_binary(mosquitto_property **proplist, int identifier, const void *value, uint16_t len); + +/* + * Function: mosquitto_property_add_string + * + * Add a new string property to a property list. + * + * If *proplist == NULL, a new list will be created, otherwise the new property + * will be appended to the list. + * + * Parameters: + * proplist - pointer to mosquitto_property pointer, the list of properties + * identifier - property identifier (e.g. MQTT_PROP_CONTENT_TYPE) + * value - string value for the new property, must be UTF-8 and zero terminated + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if identifier is invalid, if value is NULL, or if proplist is NULL + * MOSQ_ERR_NOMEM - on out of memory + * MOSQ_ERR_MALFORMED_UTF8 - value is not valid UTF-8. + * + * Example: + * > mosquitto_property *proplist = NULL; + * > mosquitto_property_add_string(&proplist, MQTT_PROP_CONTENT_TYPE, "application/json"); + */ +libmosq_EXPORT int mosquitto_property_add_string(mosquitto_property **proplist, int identifier, const char *value); + +/* + * Function: mosquitto_property_add_string_pair + * + * Add a new string pair property to a property list. + * + * If *proplist == NULL, a new list will be created, otherwise the new property + * will be appended to the list. + * + * Parameters: + * proplist - pointer to mosquitto_property pointer, the list of properties + * identifier - property identifier (e.g. MQTT_PROP_USER_PROPERTY) + * name - string name for the new property, must be UTF-8 and zero terminated + * value - string value for the new property, must be UTF-8 and zero terminated + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if identifier is invalid, if name or value is NULL, or if proplist is NULL + * MOSQ_ERR_NOMEM - on out of memory + * MOSQ_ERR_MALFORMED_UTF8 - if name or value are not valid UTF-8. + * + * Example: + * > mosquitto_property *proplist = NULL; + * > mosquitto_property_add_string_pair(&proplist, MQTT_PROP_USER_PROPERTY, "client", "mosquitto_pub"); + */ +libmosq_EXPORT int mosquitto_property_add_string_pair(mosquitto_property **proplist, int identifier, const char *name, const char *value); + + +/* + * Function: mosquitto_property_remove + * + * Remove a property from a property list. The property will not be freed. + * + * Parameters: + * proplist - pointer to mosquitto_property pointer, the list of properties + * property - pointer to the property to remove + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if proplist is NULL or property is NULL + * MOSQ_ERR_NOT_FOUND - if the property was not found + */ +libmosq_EXPORT int mosquitto_property_remove(mosquitto_property **proplist, const mosquitto_property *property); + + +/* + * Function: mosquitto_property_identifier + * + * Return the property identifier for a single property. + * + * Parameters: + * property - pointer to a valid mosquitto_property pointer. + * + * Returns: + * A valid property identifier on success + * 0 - on error + */ +libmosq_EXPORT int mosquitto_property_identifier(const mosquitto_property *property); + + +/* + * Function: mosquitto_property_next + * + * Return the next property in a property list. Use to iterate over a property + * list, e.g.: + * + * (start code) + * for(prop = proplist; prop != NULL; prop = mosquitto_property_next(prop)){ + * if(mosquitto_property_identifier(prop) == MQTT_PROP_CONTENT_TYPE){ + * ... + * } + * } + * (end) + * + * Parameters: + * proplist - pointer to mosquitto_property pointer, the list of properties + * + * Returns: + * Pointer to the next item in the list + * NULL, if proplist is NULL, or if there are no more items in the list. + */ +libmosq_EXPORT mosquitto_property *mosquitto_property_next(const mosquitto_property *proplist); + + +/* + * Function: mosquitto_property_read_byte + * + * Attempt to read a byte property matching an identifier, from a property list + * or single property. This function can search for multiple entries of the + * same identifier by using the returned value and skip_first. Note however + * that it is forbidden for most properties to be duplicated. + * + * If the property is not found, *value will not be modified, so it is safe to + * pass a variable with a default value to be potentially overwritten: + * + * (start code) + * uint16_t keepalive = 60; // default value + * // Get value from property list, or keep default if not found. + * mosquitto_property_read_int16(proplist, MQTT_PROP_SERVER_KEEP_ALIVE, &keepalive, false); + * (end) + * + * Parameters: + * proplist - mosquitto_property pointer, the list of properties or single property + * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) + * value - pointer to store the value, or NULL if the value is not required. + * skip_first - boolean that indicates whether the first item in the list + * should be ignored or not. Should usually be set to false. + * + * Returns: + * A valid property pointer if the property is found + * NULL, if the property is not found, or proplist is NULL. + * + * Example: + * (start code) + * // proplist is obtained from a callback + * mosquitto_property *prop; + * prop = mosquitto_property_read_byte(proplist, identifier, &value, false); + * while(prop){ + * printf("value: %s\n", value); + * prop = mosquitto_property_read_byte(prop, identifier, &value); + * } + * (end) + */ +libmosq_EXPORT const mosquitto_property *mosquitto_property_read_byte( + const mosquitto_property *proplist, + int identifier, + uint8_t *value, + bool skip_first); + +/* + * Function: mosquitto_property_read_int16 + * + * Read an int16 property value from a property. + * + * Parameters: + * property - property to read + * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) + * value - pointer to store the value, or NULL if the value is not required. + * skip_first - boolean that indicates whether the first item in the list + * should be ignored or not. Should usually be set to false. + * + * Returns: + * A valid property pointer if the property is found + * NULL, if the property is not found, or proplist is NULL. + * + * Example: + * See + */ +libmosq_EXPORT const mosquitto_property *mosquitto_property_read_int16( + const mosquitto_property *proplist, + int identifier, + uint16_t *value, + bool skip_first); + +/* + * Function: mosquitto_property_read_int32 + * + * Read an int32 property value from a property. + * + * Parameters: + * property - pointer to mosquitto_property pointer, the list of properties + * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) + * value - pointer to store the value, or NULL if the value is not required. + * skip_first - boolean that indicates whether the first item in the list + * should be ignored or not. Should usually be set to false. + * + * Returns: + * A valid property pointer if the property is found + * NULL, if the property is not found, or proplist is NULL. + * + * Example: + * See + */ +libmosq_EXPORT const mosquitto_property *mosquitto_property_read_int32( + const mosquitto_property *proplist, + int identifier, + uint32_t *value, + bool skip_first); + +/* + * Function: mosquitto_property_read_varint + * + * Read a varint property value from a property. + * + * Parameters: + * property - property to read + * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) + * value - pointer to store the value, or NULL if the value is not required. + * skip_first - boolean that indicates whether the first item in the list + * should be ignored or not. Should usually be set to false. + * + * Returns: + * A valid property pointer if the property is found + * NULL, if the property is not found, or proplist is NULL. + * + * Example: + * See + */ +libmosq_EXPORT const mosquitto_property *mosquitto_property_read_varint( + const mosquitto_property *proplist, + int identifier, + uint32_t *value, + bool skip_first); + +/* + * Function: mosquitto_property_read_binary + * + * Read a binary property value from a property. + * + * On success, value must be free()'d by the application. + * + * Parameters: + * property - property to read + * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) + * value - pointer to store the value, or NULL if the value is not required. + * Will be set to NULL if the value has zero length. + * skip_first - boolean that indicates whether the first item in the list + * should be ignored or not. Should usually be set to false. + * + * Returns: + * A valid property pointer if the property is found + * NULL, if the property is not found, or proplist is NULL, or if an out of memory condition occurred. + * + * Example: + * See + */ +libmosq_EXPORT const mosquitto_property *mosquitto_property_read_binary( + const mosquitto_property *proplist, + int identifier, + void **value, + uint16_t *len, + bool skip_first); + +/* + * Function: mosquitto_property_read_string + * + * Read a string property value from a property. + * + * On success, value must be free()'d by the application. + * + * Parameters: + * property - property to read + * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) + * value - pointer to char*, for the property data to be stored in, or NULL if + * the value is not required. + * Will be set to NULL if the value has zero length. + * skip_first - boolean that indicates whether the first item in the list + * should be ignored or not. Should usually be set to false. + * + * Returns: + * A valid property pointer if the property is found + * NULL, if the property is not found, or proplist is NULL, or if an out of memory condition occurred. + * + * Example: + * See + */ +libmosq_EXPORT const mosquitto_property *mosquitto_property_read_string( + const mosquitto_property *proplist, + int identifier, + char **value, + bool skip_first); + +/* + * Function: mosquitto_property_read_string_pair + * + * Read a string pair property value pair from a property. + * + * On success, name and value must be free()'d by the application. + * + * Parameters: + * property - property to read + * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) + * name - pointer to char* for the name property data to be stored in, or NULL + * if the name is not required. + * Will be set to NULL if the name has zero length. + * value - pointer to char*, for the property data to be stored in, or NULL if + * the value is not required. + * Will be set to NULL if the value has zero length. + * skip_first - boolean that indicates whether the first item in the list + * should be ignored or not. Should usually be set to false. + * + * Returns: + * A valid property pointer if the property is found + * NULL, if the property is not found, or proplist is NULL, or if an out of memory condition occurred. + * + * Example: + * See + */ +libmosq_EXPORT const mosquitto_property *mosquitto_property_read_string_pair( + const mosquitto_property *proplist, + int identifier, + char **name, + char **value, + bool skip_first); + +/* + * Function: mosquitto_property_type + * + * Return the property type for a single property. + * + * Parameters: + * property - pointer to a valid mosquitto_property pointer. + * + * Returns: + * A valid property type on success + * 0 - on error + */ +libmosq_EXPORT int mosquitto_property_type(const mosquitto_property *property); + + +/* + * Function: mosquitto_property_byte_value + * + * Return the property value for a byte type property. + * + * Parameters: + * property - pointer to a valid mosquitto_property pointer. + * + * Returns: + * Byte value on success + * 0 - on error (property is NULL, or not a byte) + */ +libmosq_EXPORT uint8_t mosquitto_property_byte_value(const mosquitto_property *property); + + +/* + * Function: mosquitto_property_int16_value + * + * Return the property value for an int16 type property. + * + * Parameters: + * property - pointer to a valid mosquitto_property pointer. + * + * Returns: + * Int16 value on success + * 0 - on error (property is NULL, or not a int16) + */ +libmosq_EXPORT uint16_t mosquitto_property_int16_value(const mosquitto_property *property); + + +/* + * Function: mosquitto_property_int32_value + * + * Return the property value for an int32 type property. + * + * Parameters: + * property - pointer to a valid mosquitto_property pointer. + * + * Returns: + * Int32 value on success + * 0 - on error (property is NULL, or not a int32) + */ +libmosq_EXPORT uint32_t mosquitto_property_int32_value(const mosquitto_property *property); + + +/* + * Function: mosquitto_property_varint_value + * + * Return the property value for a varint type property. + * + * Parameters: + * property - pointer to a valid mosquitto_property pointer. + * + * Returns: + * Varint value on success + * 0 - on error (property is NULL, or not a varint) + */ +libmosq_EXPORT uint32_t mosquitto_property_varint_value(const mosquitto_property *property); + + +/* + * Function: mosquitto_property_binary_value + * + * Return the property value for a binary type property. + * + * Parameters: + * property - pointer to a valid mosquitto_property pointer. + * + * Returns: + * Binary value on success + * NULL - on error (property is NULL, or not a binary) + */ +libmosq_EXPORT const void *mosquitto_property_binary_value(const mosquitto_property *property); + + +/* + * Function: mosquitto_property_byte_value_length + * + * Return the property value for a byte type property. + * + * Parameters: + * property - pointer to a valid mosquitto_property pointer. + * + * Returns: + * Binary value length on success + * 0 - on error (property is NULL, or not a binary) + */ +libmosq_EXPORT uint16_t mosquitto_property_binary_value_length(const mosquitto_property *property); + + +/* + * Function: mosquitto_property_string_value + * + * Return the property value for a string or string pair type property. + * + * Parameters: + * property - pointer to a valid mosquitto_property pointer. + * + * Returns: + * String value on success + * NULL - on error (property is NULL, or not a string or string pair) + */ +libmosq_EXPORT const char *mosquitto_property_string_value(const mosquitto_property *property); + + +/* + * Function: mosquitto_property_string_value_length + * + * Return the length of the property value for a string or string pair type property. + * + * Parameters: + * property - pointer to a valid mosquitto_property pointer. + * + * Returns: + * Value length on success + * 0 - on error (property is NULL, or not a string or string pair) + */ +libmosq_EXPORT uint16_t mosquitto_property_string_value_length(const mosquitto_property *property); + + +/* + * Function: mosquitto_property_string_value + * + * Return the property name for a string pair type property. + * + * Parameters: + * property - pointer to a valid mosquitto_property pointer. + * + * Returns: + * String name on success + * NULL - on error (property is NULL, or not a string pair) + */ +libmosq_EXPORT const char *mosquitto_property_string_name(const mosquitto_property *property); + + +/* + * Function: mosquitto_property_string_name_length + * + * Return the property name length for a string pair type property. + * + * Parameters: + * property - pointer to a valid mosquitto_property pointer. + * + * Returns: + * Name length on success + * 0 - on error (property is NULL, or not a string pair) + */ +libmosq_EXPORT uint16_t mosquitto_property_string_name_length(const mosquitto_property *property); + + +/* + * Function: mosquitto_property_free_all + * + * Free all properties from a list of properties. Frees the list and sets *properties to NULL. + * + * Parameters: + * properties - list of properties to free + * + * Example: + * > mosquitto_properties *properties = NULL; + * > // Add properties + * > mosquitto_property_free_all(&properties); + */ +libmosq_EXPORT void mosquitto_property_free_all(mosquitto_property **properties); + +/* + * Function: mosquitto_property_copy_all + * + * Parameters: + * dest - pointer for new property list + * src - property list + * + * Returns: + * MOSQ_ERR_SUCCESS - on successful copy + * MOSQ_ERR_INVAL - if dest is NULL + * MOSQ_ERR_NOMEM - on out of memory (dest will be set to NULL) + */ +libmosq_EXPORT int mosquitto_property_copy_all(mosquitto_property **dest, const mosquitto_property *src); + +/* + * Function: mosquitto_property_check_command + * + * Check whether a property identifier is valid for the given command. + * + * Parameters: + * command - MQTT command (e.g. CMD_CONNECT) + * identifier - MQTT property (e.g. MQTT_PROP_USER_PROPERTY) + * + * Returns: + * MOSQ_ERR_SUCCESS - if the identifier is valid for command + * MOSQ_ERR_PROTOCOL - if the identifier is not valid for use with command. + */ +libmosq_EXPORT int mosquitto_property_check_command(int command, int identifier); + + +/* + * Function: mosquitto_property_check_all + * + * Check whether a list of properties are valid for a particular command, + * whether there are duplicates, and whether the values are valid where + * possible. + * + * Note that this function is used internally in the library whenever + * properties are passed to it, so in basic use this is not needed, but should + * be helpful to check property lists *before* the point of using them. + * + * Parameters: + * command - MQTT command (e.g. CMD_CONNECT) + * properties - list of MQTT properties to check. + * + * Returns: + * MOSQ_ERR_SUCCESS - if all properties are valid + * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. + * MOSQ_ERR_PROTOCOL - if any property is invalid + */ +libmosq_EXPORT int mosquitto_property_check_all(int command, const mosquitto_property *properties); + +/* + * Function: mosquitto_property_identifier_to_string + * + * Return the property name as a string for a property identifier. + * The property name is as defined in the MQTT specification, with - as a + * separator, for example: payload-format-indicator. + * + * Parameters: + * identifier - valid MQTT property identifier integer + * + * Returns: + * A const string to the property name on success + * NULL on failure + */ +libmosq_EXPORT const char *mosquitto_property_identifier_to_string(int identifier); + + +/* Function: mosquitto_string_to_property_info + * + * Parse a property name string and convert to a property identifier and data type. + * The property name is as defined in the MQTT specification, with - as a + * separator, for example: payload-format-indicator. + * + * Parameters: + * propname - the string to parse + * identifier - pointer to an int to receive the property identifier + * type - pointer to an int to receive the property type + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if the string does not match a property + * + * Example: + * (start code) + * mosquitto_string_to_property_info("response-topic", &id, &type); + * // id == MQTT_PROP_RESPONSE_TOPIC + * // type == MQTT_PROP_TYPE_STRING + * (end) + */ +libmosq_EXPORT int mosquitto_string_to_property_info(const char *propname, int *identifier, int *type); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libcommon_string.h b/include/mosquitto/libcommon_string.h new file mode 100644 index 00000000..b5d4c189 --- /dev/null +++ b/include/mosquitto/libcommon_string.h @@ -0,0 +1,97 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBCOMMON_STRING_H +#define MOSQUITTO_LIBCOMMON_STRING_H + +/* + * File: mosquitto.h + * + * This header contains functions and definitions for use with libmosquitto, the Mosquitto client library. + * + * The definitions are also used in Mosquitto broker plugins, and some functions are available to plugins. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Function: mosquitto_strerror + * + * Call to obtain a const string description of a mosquitto error number. + * + * Parameters: + * mosq_errno - a mosquitto error number. + * + * Returns: + * A constant string describing the error. + */ +libmosq_EXPORT const char *mosquitto_strerror(int mosq_errno); + +/* + * Function: mosquitto_connack_string + * + * Call to obtain a const string description of an MQTT connection result. + * + * Parameters: + * connack_code - an MQTT connection result. + * + * Returns: + * A constant string describing the result. + */ +libmosq_EXPORT const char *mosquitto_connack_string(int connack_code); + +/* + * Function: mosquitto_reason_string + * + * Call to obtain a const string description of an MQTT reason code. + * + * Parameters: + * reason_code - an MQTT reason code. + * + * Returns: + * A constant string describing the reason. + */ +libmosq_EXPORT const char *mosquitto_reason_string(int reason_code); + +/* Function: mosquitto_string_to_command + * + * Take a string input representing an MQTT command and convert it to the + * libmosquitto integer representation. + * + * Parameters: + * str - the string to parse. + * cmd - pointer to an int, for the result. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - on an invalid input. + * + * Example: + * (start code) + * mosquitto_string_to_command("CONNECT", &cmd); + * // cmd == CMD_CONNECT + * (end) + */ +libmosq_EXPORT int mosquitto_string_to_command(const char *str, int *cmd); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libcommon_topic.h b/include/mosquitto/libcommon_topic.h new file mode 100644 index 00000000..ab383e42 --- /dev/null +++ b/include/mosquitto/libcommon_topic.h @@ -0,0 +1,348 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBCOMMON_TOPIC_H +#define MOSQUITTO_LIBCOMMON_TOPIC_H + +/* + * File: mosquitto/libcommon_topic.h + * + * This header contains functions and definitions for checking and manipulating topic strings. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Function: mosquitto_sub_topic_tokenise + * + * Tokenise a topic or subscription string into an array of strings + * representing the topic hierarchy. + * + * For example: + * + * subtopic: "a/deep/topic/hierarchy" + * + * Would result in: + * + * topics[0] = "a" + * topics[1] = "deep" + * topics[2] = "topic" + * topics[3] = "hierarchy" + * + * and: + * + * subtopic: "/a/deep/topic/hierarchy/" + * + * Would result in: + * + * topics[0] = NULL + * topics[1] = "a" + * topics[2] = "deep" + * topics[3] = "topic" + * 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. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_NOMEM - if an out of memory condition occurred. + * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8 + * + * Example: + * + * > char **topics; + * > int topic_count; + * > int i; + * > + * > mosquitto_sub_topic_tokenise("$SYS/broker/uptime", &topics, &topic_count); + * > + * > for(i=0; i printf("%d: %s\n", i, topics[i]); + * > } + * + * See Also: + * + */ +libmosq_EXPORT int mosquitto_sub_topic_tokenise(const char *subtopic, char ***topics, int *count); + +/* + * Function: mosquitto_sub_topic_tokens_free + * + * Free memory that was allocated in . + * + * Parameters: + * 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. + * + * See Also: + * + */ +libmosq_EXPORT int mosquitto_sub_topic_tokens_free(char ***topics, int count); + +/* + * Function: mosquitto_topic_matches_sub + * + * Check whether a topic matches a subscription. + * + * For example: + * + * foo/bar would match the subscription foo/# or +/bar + * 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. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if the input parameters were invalid. + */ +libmosq_EXPORT int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result); + +/* + * Function: mosquitto_topic_matches_sub2 + * + * Identical to . The sublen and topiclen + * parameters are *IGNORED*. + */ +libmosq_EXPORT int mosquitto_topic_matches_sub2(const char *sub, size_t sublen, const char *topic, size_t topiclen, bool *result); + + +/* + * Function: mosquitto_topic_matches_sub_with_pattern + * + * Check whether a topic matches a subscription, with client id/username + * pattern substitution. + * + * Any instances of a subscriptions hierarchy that are exactly %c or %u will be + * replaced with the client id or username respectively. + * + * For example: + * + * mosquitto_topic_matches_sub_with_pattern("sensors/%c/temperature", "sensors/kitchen/temperature", "kitchen", NULL, &result) + * -> this will match + * + * mosquitto_topic_matches_sub_with_pattern("sensors/%c/temperature", "sensors/bathroom/temperature", "kitchen", NULL, &result) + * -> this will not match + * + * mosquitto_topic_matches_sub_with_pattern("sensors/%count/temperature", "sensors/kitchen/temperature", "kitchen", NULL, &result) + * -> this will not match - the `%count` is not treated as a pattern + * + * mosquitto_topic_matches_sub_with_pattern("%c/%c/%u/%u", "kitchen/kitchen/bathroom/bathroom", "kitchen", "bathroom", &result) + * -> this will match + * + * Parameters: + * sub - subscription string to check topic against. + * topic - topic to check. + * clientid - client id to substitute in patterns. If NULL, then any %c patterns will not match. + * username - username to substitute in patterns. If NULL, then any %u patterns will not match. + * 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. + */ +libmosq_EXPORT int mosquitto_topic_matches_sub_with_pattern(const char *sub, const char *topic, const char *clientid, const char *username, bool *result); + + +/* + * Function: mosquitto_sub_matches_acl + * + * Check whether a subscription matches an ACL topic filter + * + * For example: + * + * The subscription $SYS/broker/# would match against the ACL $SYS/# + * The subscription $SYS/broker/# would not match against the ACL $SYS/broker/uptime + * + * Parameters: + * acl - topic filter string to check sub against. + * sub - subscription topic to check. + * result - bool pointer to hold result. Will be set to true if the subscription + * matches the acl. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if the input parameters were invalid. + */ +libmosq_EXPORT int mosquitto_sub_matches_acl(const char *acl, const char *sub, bool *result); + + +/* + * Function: mosquitto_sub_matches_acl_with_pattern + * + * Check whether a subscription (a topic filter with wildcards) matches an ACL + * (a topic filter with wildcards) , with client id/username pattern + * substitution. + * + * Any instances of an ACL hierarchy that are exactly %c or %u will be + * replaced with the client id or username respectively. + * + * For example: + * + * mosquitto_sub_matches_acl_with_pattern("sensors/%c/+", "sensors/kitchen/temperature", "kitchen", NULL, &result) + * -> this will match + * + * mosquitto_sub_matches_acl_with_pattern("sensors/%c/+", "sensors/bathroom/temperature", "kitchen", NULL, &result) + * -> this will not match + * + * mosquitto_sub_matches_acl_with_pattern("sensors/%count/+", "sensors/kitchen/temperature", "kitchen", NULL, &result) + * -> this will not match - the `%count` is not treated as a pattern + * + * mosquitto_sub_matches_acl_with_pattern("%c/%c/%u/+", "kitchen/kitchen/bathroom/bathroom", "kitchen", "bathroom", &result) + * -> this will match + * + * Parameters: + * acl - ACL topic filter string to check sub against. + * sub - subscription to check. + * clientid - client id to substitute in patterns. If NULL, then any %c patterns will not match. + * username - username to substitute in patterns. If NULL, then any %u patterns will not match. + * result - bool pointer to hold result. Will be set to true if the subscription + * matches the ACL. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if the input parameters were invalid. + */ +libmosq_EXPORT int mosquitto_sub_matches_acl_with_pattern(const char *acl, const char *sub, const char *clientid, const char *username, bool *result); + + +/* + * Function: mosquitto_pub_topic_check + * + * Check whether a topic to be used for publishing is valid. + * + * This searches for + or # in a topic and checks its length. + * + * This check is already carried out in and + * , there is no need to call it directly before them. It + * may be useful if you wish to check the validity of a topic in advance of + * making a connection for example. + * + * Parameters: + * topic - the topic to check + * + * Returns: + * MOSQ_ERR_SUCCESS - for a valid topic + * MOSQ_ERR_INVAL - if the topic contains a + or a #, or if it is too long. + * MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8 + * + * See Also: + * + */ +libmosq_EXPORT int mosquitto_pub_topic_check(const char *topic); + +/* + * Function: mosquitto_pub_topic_check2 + * + * Check whether a topic to be used for publishing is valid. + * + * This searches for + or # in a topic and checks its length. + * + * This check is already carried out in and + * , there is no need to call it directly before them. It + * may be useful if you wish to check the validity of a topic in advance of + * making a connection for example. + * + * Parameters: + * topic - the topic to check + * topiclen - length of the topic in bytes + * + * Returns: + * MOSQ_ERR_SUCCESS - for a valid topic + * MOSQ_ERR_INVAL - if the topic contains a + or a #, or if it is too long. + * MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8 + * + * See Also: + * + */ +libmosq_EXPORT int mosquitto_pub_topic_check2(const char *topic, size_t topiclen); + +/* + * Function: mosquitto_sub_topic_check + * + * Check whether a topic to be used for subscribing is valid. + * + * This searches for + or # in a topic and checks that they aren't in invalid + * positions, such as with foo/#/bar, foo/+bar or foo/bar#, and checks its + * length. + * + * This check is already carried out in and + * , there is no need to call it directly before them. + * It may be useful if you wish to check the validity of a topic in advance of + * making a connection for example. + * + * Parameters: + * topic - the topic to check + * + * Returns: + * MOSQ_ERR_SUCCESS - for a valid topic + * MOSQ_ERR_INVAL - if the topic contains a + or a # that is in an + * invalid position, or if it is too long. + * MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8 + * + * See Also: + * + */ +libmosq_EXPORT int mosquitto_sub_topic_check(const char *topic); + +/* + * Function: mosquitto_sub_topic_check2 + * + * Check whether a topic to be used for subscribing is valid. + * + * This searches for + or # in a topic and checks that they aren't in invalid + * positions, such as with foo/#/bar, foo/+bar or foo/bar#, and checks its + * length. + * + * This check is already carried out in and + * , there is no need to call it directly before them. + * It may be useful if you wish to check the validity of a topic in advance of + * making a connection for example. + * + * Parameters: + * topic - the topic to check + * topiclen - the length in bytes of the topic + * + * Returns: + * MOSQ_ERR_SUCCESS - for a valid topic + * MOSQ_ERR_INVAL - if the topic contains a + or a # that is in an + * invalid position, or if it is too long. + * MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8 + * + * See Also: + * + */ +libmosq_EXPORT int mosquitto_sub_topic_check2(const char *topic, size_t topiclen); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libcommon_utf8.h b/include/mosquitto/libcommon_utf8.h new file mode 100644 index 00000000..38673270 --- /dev/null +++ b/include/mosquitto/libcommon_utf8.h @@ -0,0 +1,50 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBCOMMON_UTF8_H +#define MOSQUITTO_LIBCOMMON_UTF8_H + +/* + * File: mosquitto/libcommon_utf8.h + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Function: mosquitto_validate_utf8 + * + * Helper function to validate whether a UTF-8 string is valid, according to + * the UTF-8 spec and the MQTT additions. + * + * Parameters: + * str - a string to check + * len - the length of the string in bytes + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * MOSQ_ERR_INVAL - if str is NULL or len<0 or len>65536 + * MOSQ_ERR_MALFORMED_UTF8 - if str is not valid UTF-8 + */ +libmosq_EXPORT int mosquitto_validate_utf8(const char *str, int len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto.h b/include/mosquitto/libmosquitto.h new file mode 100644 index 00000000..9bed48ec --- /dev/null +++ b/include/mosquitto/libmosquitto.h @@ -0,0 +1,248 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_H +#define MOSQUITTO_LIBMOSQUITTO_H + +/* + * File: mosquitto/libmosquitto.h + * + * This header contains functions and definitions for use with libmosquitto, the Mosquitto client library. + */ +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef WIN32 +# ifdef mosquitto_EXPORTS +# define libmosq_EXPORT __declspec(dllexport) +# else +# ifndef LIBMOSQUITTO_STATIC +# ifdef libmosquitto_EXPORTS +# define libmosq_EXPORT __declspec(dllexport) +# else +# define libmosq_EXPORT __declspec(dllimport) +# endif +# else +# define libmosq_EXPORT +# endif +# endif +#else +# define libmosq_EXPORT +#endif + +#if defined(_MSC_VER) && _MSC_VER < 1900 && !defined(bool) +# ifndef __cplusplus +# define bool char +# define true 1 +# define false 0 +# endif +#else +# ifndef __cplusplus +# include +# endif +#endif + +#include +#include + +#include +#include + +#define LIBMOSQUITTO_MAJOR 2 +#define LIBMOSQUITTO_MINOR 1 +#define LIBMOSQUITTO_REVISION 0 +/* LIBMOSQUITTO_VERSION_NUMBER looks like 1002001 for e.g. version 1.2.1. */ +#define LIBMOSQUITTO_VERSION_NUMBER (LIBMOSQUITTO_MAJOR*1000000+LIBMOSQUITTO_MINOR*1000+LIBMOSQUITTO_REVISION) + +/* Enum: mosq_opt_t + * + * Client options. + * + * See , , and . + */ +enum mosq_opt_t { + MOSQ_OPT_PROTOCOL_VERSION = 1, + MOSQ_OPT_SSL_CTX = 2, + MOSQ_OPT_SSL_CTX_WITH_DEFAULTS = 3, + MOSQ_OPT_RECEIVE_MAXIMUM = 4, + MOSQ_OPT_SEND_MAXIMUM = 5, + MOSQ_OPT_TLS_KEYFORM = 6, + MOSQ_OPT_TLS_ENGINE = 7, + MOSQ_OPT_TLS_ENGINE_KPASS_SHA1 = 8, + MOSQ_OPT_TLS_OCSP_REQUIRED = 9, + MOSQ_OPT_TLS_ALPN = 10, + MOSQ_OPT_TCP_NODELAY = 11, + MOSQ_OPT_BIND_ADDRESS = 12, + MOSQ_OPT_TLS_USE_OS_CERTS = 13, + MOSQ_OPT_DISABLE_SOCKETPAIR = 14, + MOSQ_OPT_TRANSPORT = 15, + MOSQ_OPT_HTTP_PATH = 16, + MOSQ_OPT_HTTP_HEADER_SIZE = 17, +}; + +/* Struct: mosquitto_message + * + * Contains details of a PUBLISH message. + * + * int mid - the message/packet ID of the PUBLISH message, assuming this is a + * QoS 1 or 2 message. Will be set to 0 for QoS 0 messages. + * + * char *topic - the topic the message was delivered on. + * + * void *payload - the message payload. This will be payloadlen bytes long, and + * may be NULL if a zero length payload was sent. + * + * int payloadlen - the length of the payload, in bytes. + * + * int qos - the quality of service of the message, 0, 1, or 2. + * + * bool retain - set to true for stale retained messages. + */ +struct mosquitto_message{ + int mid; + char *topic; + void *payload; + int payloadlen; + int qos; + bool retain; +}; + +struct mosquitto_message_v5{ + void *payload; + char *topic; + mosquitto_property *properties; + uint32_t payloadlen; + uint8_t qos; + bool retain; + uint8_t padding[2]; +}; + +/* + * Topic: Threads + * libmosquitto provides thread safe operation, with the exception of + * which is not thread safe. + * + * If the library has been compiled without thread support it is *not* + * guaranteed to be thread safe. + * + * If your application uses threads you must use to + * tell the library this is the case, otherwise it makes some optimisations + * for the single threaded case that may result in unexpected behaviour for + * the multi threaded case. + */ +/*************************************************** + * 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 + * socket is not available for writing at that time then the packet will not be + * sent. To ensure the packet is sent, call mosquitto_loop() (which must also + * be called to process incoming network data). + * This is especially important when disconnecting a client that has a will. If + * the broker does not receive the DISCONNECT command, it will assume that the + * client has disconnected unexpectedly and send the will. + * + * mosquitto_connect() + * mosquitto_disconnect() + * mosquitto_subscribe() + * mosquitto_unsubscribe() + * mosquitto_publish() + ***************************************************/ + + +/* ====================================================================== + * + * Section: Library version, init, and cleanup + * + * ====================================================================== */ +/* + * Function: mosquitto_lib_version + * + * Can be used to obtain version information for the mosquitto library. + * This allows the application to compare the library version against the + * version it was compiled against by using the LIBMOSQUITTO_MAJOR, + * LIBMOSQUITTO_MINOR and LIBMOSQUITTO_REVISION defines. + * + * Parameters: + * major - an integer pointer. If not NULL, the major version of the + * library will be returned in this variable. + * minor - an integer pointer. If not NULL, the minor version of the + * library will be returned in this variable. + * revision - an integer pointer. If not NULL, the revision of the library will + * be returned in this variable. + * + * Returns: + * 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); + +/* + * Function: mosquitto_lib_init + * + * Must be called before any other mosquitto functions. + * + * This function is *not* thread safe. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_UNKNOWN - on Windows, if sockets couldn't be initialized. + * + * See Also: + * , + */ +libmosq_EXPORT int mosquitto_lib_init(void); + +/* + * Function: mosquitto_lib_cleanup + * + * Call to free resources associated with the library. + * + * Returns: + * MOSQ_ERR_SUCCESS - always + * + * See Also: + * , + */ +libmosq_EXPORT int mosquitto_lib_cleanup(void); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_auth.h b/include/mosquitto/libmosquitto_auth.h new file mode 100644 index 00000000..30480596 --- /dev/null +++ b/include/mosquitto/libmosquitto_auth.h @@ -0,0 +1,63 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_AUTH_H +#define MOSQUITTO_LIBMOSQUITTO_AUTH_H + +/* + * File: mosquitto/libmosquitto_auth.h + * + * This header contains functions for setting client authentication parameters in libmosquitto. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* ====================================================================== + * + * Section: Username and password + * + * ====================================================================== */ +/* + * Function: mosquitto_username_pw_set + * + * Configure username and password for a mosquitto instance. By default, no + * username or password will be sent. For v3.1 and v3.1.1 clients, if username + * is NULL, the password argument is ignored. + * + * 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 + * authentication. + * 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. + */ +libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char *username, const char *password); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_callbacks.h b/include/mosquitto/libmosquitto_callbacks.h new file mode 100644 index 00000000..c522e00d --- /dev/null +++ b/include/mosquitto/libmosquitto_callbacks.h @@ -0,0 +1,440 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_CALLBACKS_H +#define MOSQUITTO_LIBMOSQUITTO_CALLBACKS_H + +/* + * File: mosquitto/libmosquitto_callbacks.h + * + * This header contains functions for handling libmosquitto client callbacks. + */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include +#include + +/* ====================================================================== + * + * Section: Callbacks + * + * ====================================================================== */ +/* + * Function: mosquitto_connect_callback_set + * + * Set the connect callback. This is called when the library receives a CONNACK + * message in response to a connection. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_connect - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, int rc) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + * rc - the return code of the connection response. The values are defined by + * the MQTT protocol version in use. + * For MQTT v5.0, look at section 3.2.2.2 Connect Reason code: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html + * For MQTT v3.1.1, look at section 3.2.2.3 Connect Return code: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html + * + * See Also: + * + */ +libmosq_EXPORT void mosquitto_connect_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int)); + +/* + * Function: mosquitto_connect_with_flags_callback_set + * + * Set the connect callback. This is called when the library receives a CONNACK + * message in response to a connection. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_connect - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, int rc) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + * rc - the return code of the connection response. The values are defined by + * the MQTT protocol version in use. + * For MQTT v5.0, look at section 3.2.2.2 Connect Reason code: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html + * For MQTT v3.1.1, look at section 3.2.2.3 Connect Return code: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html + * flags - the connect flags. + * + * See Also: + * + */ +libmosq_EXPORT void mosquitto_connect_with_flags_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int, int)); + +/* + * Function: mosquitto_connect_v5_callback_set + * + * Set the connect callback. This is called when the library receives a CONNACK + * message in response to a connection. + * + * It is valid to set this callback for all MQTT protocol versions. If it is + * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` + * argument will always be NULL. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_connect - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, int rc) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + * rc - the return code of the connection response. The values are defined by + * the MQTT protocol version in use. + * For MQTT v5.0, look at section 3.2.2.2 Connect Reason code: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html + * For MQTT v3.1.1, look at section 3.2.2.3 Connect Return code: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html + * flags - the connect flags. + * props - list of MQTT 5 properties, or NULL + * + * See Also: + * + */ +libmosq_EXPORT void mosquitto_connect_v5_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int, int, const mosquitto_property *props)); + +/* + * Function: mosquitto_pre_connect_callback_set + * + * Set the pre-connect callback. The pre-connect callback is called just before an attempt is made to connect to the broker. This may be useful if you are using , or + * , because when your client disconnects the library + * will by default automatically reconnect. Using the pre-connect callback + * allows you to set usernames, passwords, and TLS related parameters. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_pre_connect - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + */ +libmosq_EXPORT void mosquitto_pre_connect_callback_set(struct mosquitto *mosq, void (*on_pre_connect)(struct mosquitto *, void *)); + +/* + * 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: + * void callback(struct mosquitto *mosq, void *obj) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + * rc - integer value indicating the reason for the disconnect. A value of 0 + * 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)); + +/* + * Function: mosquitto_disconnect_v5_callback_set + * + * Set the disconnect callback. This is called when the broker has received the + * DISCONNECT command and has disconnected the client. + * + * It is valid to set this callback for all MQTT protocol versions. If it is + * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` + * argument will always be NULL. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_disconnect - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + * rc - integer value indicating the reason for the disconnect. A value of 0 + * means the client has called . Any other value + * indicates that the disconnect is unexpected. + * props - list of MQTT 5 properties, or NULL + */ +libmosq_EXPORT void mosquitto_disconnect_v5_callback_set(struct mosquitto *mosq, void (*on_disconnect)(struct mosquitto *, void *, int, const mosquitto_property *props)); + +/* + * Function: mosquitto_publish_callback_set + * + * Set the publish callback. This is called when a message initiated with + * has been sent to the broker. "Sent" means different + * things depending on the QoS of the message: + * + * QoS 0: The PUBLISH was passed to the local operating system for delivery, + * there is no guarantee that it was delivered to the remote broker. + * QoS 1: The PUBLISH was sent to the remote broker and the corresponding + * PUBACK was received by the library. + * QoS 2: The PUBLISH was sent to the remote broker and the corresponding + * PUBCOMP was received by the library. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_publish - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, int mid) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * 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)); + +/* + * Function: mosquitto_publish_v5_callback_set + * + * Set the publish callback. This is called when a message initiated with + * has been sent to the broker. This callback will be + * called both if the message is sent successfully, or if the broker responded + * with an error, which will be reflected in the reason_code parameter. + * "Sent" means different things depending on the QoS of the message: + * + * QoS 0: The PUBLISH was passed to the local operating system for delivery, + * there is no guarantee that it was delivered to the remote broker. + * QoS 1: The PUBLISH was sent to the remote broker and the corresponding + * PUBACK was received by the library. + * QoS 2: The PUBLISH was sent to the remote broker and the corresponding + * PUBCOMP was received by the library. + * + * + * It is valid to set this callback for all MQTT protocol versions. If it is + * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` + * argument will always be NULL. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_publish - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, int mid) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + * mid - the message id of the sent message. + * reason_code - the MQTT 5 reason code + * props - list of MQTT 5 properties, or NULL + */ +libmosq_EXPORT void mosquitto_publish_v5_callback_set(struct mosquitto *mosq, void (*on_publish)(struct mosquitto *, void *, int, int, const mosquitto_property *props)); + +/* + * Function: mosquitto_message_callback_set + * + * Set the message callback. This is called when a message is received from the + * broker and the required QoS flow has completed. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_message - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + * message - the message data. This variable and associated memory will be + * freed by the library after the callback completes. The client + * 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 *)); + +/* + * Function: mosquitto_message_v5_callback_set + * + * Set the message callback. This is called when a message is received from the + * broker and the required QoS flow has completed. + * + * It is valid to set this callback for all MQTT protocol versions. If it is + * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` + * argument will always be NULL. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_message - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + * message - the message data. This variable and associated memory will be + * freed by the library after the callback completes. The client + * should make copies of any of the data it requires. + * props - list of MQTT 5 properties, or NULL + * + * See Also: + * + */ +libmosq_EXPORT void mosquitto_message_v5_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *, const mosquitto_property *props)); + +/* + * Function: mosquitto_subscribe_callback_set + * + * Set the subscribe callback. This is called when the library receives a + * SUBACK message in response to a SUBSCRIBE. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_subscribe - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + * mid - the message id of the subscribe message. + * qos_count - the number of granted subscriptions (size of granted_qos). + * 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 *)); + +/* + * Function: mosquitto_subscribe_v5_callback_set + * + * Set the subscribe callback. This is called when the library receives a + * SUBACK message in response to a SUBSCRIBE. + * + * It is valid to set this callback for all MQTT protocol versions. If it is + * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` + * argument will always be NULL. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_subscribe - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + * mid - the message id of the subscribe message. + * qos_count - the number of granted subscriptions (size of granted_qos). + * granted_qos - an array of integers indicating the granted QoS for each of + * the subscriptions. + * props - list of MQTT 5 properties, or NULL + */ +libmosq_EXPORT void mosquitto_subscribe_v5_callback_set(struct mosquitto *mosq, void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *, const mosquitto_property *props)); + +/* + * Function: mosquitto_unsubscribe_callback_set + * + * Set the unsubscribe callback. This is called when the library receives a + * UNSUBACK message in response to an UNSUBSCRIBE. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_unsubscribe - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, int mid) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * 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)); + +/* + * Function: mosquitto_unsubscribe_v5_callback_set + * + * Set the unsubscribe callback. This is called when the library receives a + * UNSUBACK message in response to an UNSUBSCRIBE. + * + * It is valid to set this callback for all MQTT protocol versions. If it is + * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` + * argument will always be NULL. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_unsubscribe - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, int mid, const mosquitto_property *props) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + * mid - the message id of the unsubscribe message. + * props - list of MQTT 5 properties, or NULL + */ +libmosq_EXPORT void mosquitto_unsubscribe_v5_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int, const mosquitto_property *props)); + +/* + * Function: mosquitto_unsubscribe2_v5_callback_set + * + * Set the unsubscribe callback. This is called when the library receives a + * UNSUBACK message in response to an UNSUBSCRIBE. + * + * It is valid to set this callback for all MQTT protocol versions. If it is + * used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props` + * argument will always be NULL. + * + * Parameters: + * mosq - a valid mosquitto instance. + * on_unsubscribe - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, int mid, + * int reason_code_count, const int *reason_codes, const mosquitto_property *props) + * + * Callback Parameters: + * mosq - the mosquitto instance making the callback. + * obj - the user data provided in + * mid - the message id of the unsubscribe message. + * reason_code_count - the count of reason code responses + * reason_codes - an array of integers indicating the reason codes for each of + * the unsubscription requests. + * mid - the message id of the unsubscribe message. + * props - list of MQTT 5 properties, or NULL + */ +libmosq_EXPORT void mosquitto_unsubscribe2_v5_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int, int, const int *, const mosquitto_property *props)); + +/* + * Function: mosquitto_log_callback_set + * + * Set the logging callback. This should be used if you want event logging + * information from the client library. + * + * mosq - a valid mosquitto instance. + * on_log - a callback function in the following form: + * void callback(struct mosquitto *mosq, void *obj, int level, const char *str) + * + * Callback Parameters: + * 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. + */ +libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on_log)(struct mosquitto *, void *, int, const char *)); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_connect.h b/include/mosquitto/libmosquitto_connect.h new file mode 100644 index 00000000..497f6ca9 --- /dev/null +++ b/include/mosquitto/libmosquitto_connect.h @@ -0,0 +1,372 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_CONNECT_H +#define MOSQUITTO_LIBMOSQUITTO_CONNECT_H + +/* + * File: mosquitto/libmosquitto_connect.h + * + * This header contains functions for connect/disconnecting/reconnectng clients in libmosquitto. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* ====================================================================== + * + * Section: Connecting, reconnecting, disconnecting + * + * ====================================================================== */ +/* + * Function: mosquitto_connect + * + * Connect to an MQTT broker. + * + * It is valid to use this function for clients using all MQTT protocol versions. + * If you need to set MQTT v5 CONNECT properties, use + * instead. + * + * 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 client should send a PING + * message to the broker 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, which could be any of: + * * mosq == NULL + * * host == NULL + * * port < 0 + * * keepalive < 5 + * 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); + +/* + * 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. + * + * 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 client should send a PING + * message to the broker 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. If you do not want to bind to a specific interface, + * set this to NULL. + * + * 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 + * 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); + +/* + * Function: mosquitto_connect_bind_v5 + * + * Connect to an MQTT broker. This extends the functionality of + * by adding the bind_address parameter and MQTT v5 + * properties. Use this function if you need to restrict network communication + * over a particular interface. + * + * Use e.g. and similar to create a list of + * properties, then attach them to this publish. Properties need freeing with + * . + * + * If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument + * will be applied to the CONNECT message. For MQTT v3.1.1 and below, the + * `properties` argument will be ignored. + * + * Set your client to use MQTT v5 immediately after it is created: + * + * mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); + * + * 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 client should send a PING + * message to the broker 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. If you do not want to bind to a specific interface, + * set this to NULL. + * properties - the MQTT 5 properties for the connect (not for the Will). + * + * Returns: + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid, which could be any of: + * * mosq == NULL + * * host == NULL + * * port < 0 + * * keepalive < 5 + * 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. + * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. + * MOSQ_ERR_PROTOCOL - if any property is invalid for use with CONNECT. + * + * See Also: + * , , + */ +libmosq_EXPORT int mosquitto_connect_bind_v5(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address, const mosquitto_property *properties); + +/* + * Function: mosquitto_connect_async + * + * Connect to an MQTT broker. This is a non-blocking call. If you use + * your client must use the threaded interface + * . If you need to use , you must use + * to connect the client. + * + * 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 client should send a PING + * message to the broker 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 + * 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); + +/* + * Function: mosquitto_connect_bind_async + * + * Connect to an MQTT broker. This is a non-blocking call. If you use + * your client must use the threaded interface + * . If you need to use , you must use + * to connect the client. + * + * 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. + * + * 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 client should send a PING + * message to the broker 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. If you do not want to bind to a specific interface, + * set this to NULL. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid, which could be any of: + * * mosq == NULL + * * host == NULL + * * port < 0 + * * keepalive < 5 + * 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); + +/* + * Function: mosquitto_connect_srv + * + * Connect to an MQTT broker. + * + * If you set `host` to `example.com`, then this call will attempt to retrieve + * the DNS SRV record for `_secure-mqtt._tcp.example.com` or + * `_mqtt._tcp.example.com` to discover which actual host to connect to. + * + * DNS SRV support is not usually compiled in to libmosquitto, use of this call + * is not recommended. + * + * Parameters: + * mosq - a valid mosquitto instance. + * host - the hostname to search for an SRV record. + * keepalive - the number of seconds after which the client should send a PING + * message to the broker 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. If you do not want to bind to a specific interface, + * set this to NULL. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid, which could be any of: + * * mosq == NULL + * * host == NULL + * * port < 0 + * * keepalive < 5 + * 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); + +/* + * Function: mosquitto_reconnect + * + * Reconnect to a broker. + * + * This function provides an easy way of reconnecting to a broker after a + * 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. + * + * 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_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); + +/* + * Function: mosquitto_reconnect_async + * + * Reconnect to a broker. Non blocking version of . + * + * This function provides an easy way of reconnecting to a broker after a + * 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. + * + * 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_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); + +/* + * Function: mosquitto_disconnect + * + * Disconnect from the broker. + * + * It is valid to use this function for clients using all MQTT protocol versions. + * If you need to set MQTT v5 DISCONNECT properties, use + * instead. + * + * Parameters: + * 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. + */ +libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq); + +/* + * Function: mosquitto_disconnect_v5 + * + * Disconnect from the broker, with attached MQTT properties. + * + * Use e.g. and similar to create a list of + * properties, then attach them to this publish. Properties need freeing with + * . + * + * If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument + * will be applied to the DISCONNECT message. For MQTT v3.1.1 and below, the + * `properties` argument will be ignored. + * + * Set your client to use MQTT v5 immediately after it is created: + * + * mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); + * + * Parameters: + * mosq - a valid mosquitto instance. + * reason_code - the disconnect reason code. + * properties - a valid mosquitto_property list, or NULL. + * + * 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_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. + * MOSQ_ERR_PROTOCOL - if any property is invalid for use with DISCONNECT. + */ +libmosq_EXPORT int mosquitto_disconnect_v5(struct mosquitto *mosq, int reason_code, const mosquitto_property *properties); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_create_delete.h b/include/mosquitto/libmosquitto_create_delete.h new file mode 100644 index 00000000..2921718b --- /dev/null +++ b/include/mosquitto/libmosquitto_create_delete.h @@ -0,0 +1,114 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_CREATE_DELETE_H +#define MOSQUITTO_LIBMOSQUITTO_CREATE_DELETE_H + +/* + * File: mosquitto/libmosquitto_create_delete.h + * + * This header contains functions for creating/deleting/reinitialising mosquitto clients. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* ====================================================================== + * + * Section: Client creation, destruction, and reinitialisation + * + * ====================================================================== */ +/* + * Function: mosquitto_new + * + * 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 + * 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 + * messages on disconnect. Calling or + * will cause the messages to be resent. + * 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 + * callbacks that are specified. + * + * Returns: + * 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. + * + * See Also: + * , + */ +libmosq_EXPORT void mosquitto_destroy(struct mosquitto *mosq); + +/* + * Function: mosquitto_reinitialise + * + * This function allows an existing mosquitto client to be reused. Call on a + * mosquitto instance to close any open network connections, free memory + * and reinitialise the client with the new parameters. The end result is the + * 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 + * 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 + * 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_MALFORMED_UTF8 - if the client id is not valid UTF-8. + * + * See Also: + * , + */ +libmosq_EXPORT int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_session, void *obj); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_helpers.h b/include/mosquitto/libmosquitto_helpers.h new file mode 100644 index 00000000..c0ab0ce2 --- /dev/null +++ b/include/mosquitto/libmosquitto_helpers.h @@ -0,0 +1,169 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_HELPERS_H +#define MOSQUITTO_LIBMOSQUITTO_HELPERS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/* ============================================================================= + * + * Section: One line client helper functions + * + * ============================================================================= + */ + +struct libmosquitto_will { + char *topic; + void *payload; + int payloadlen; + int qos; + bool retain; +}; + +struct libmosquitto_auth { + char *username; + char *password; +}; + +struct libmosquitto_tls { + char *cafile; + char *capath; + char *certfile; + char *keyfile; + char *ciphers; + char *tls_version; + int (*pw_callback)(char *buf, int size, int rwflag, void *userdata); + int cert_reqs; +}; + +/* + * Function: mosquitto_subscribe_simple + * + * Helper function to make subscribing to a topic and retrieving some messages + * very straightforward. + * + * This connects to a broker, subscribes to a topic, waits for msg_count + * messages to be received, then returns after disconnecting cleanly. + * + * Parameters: + * messages - pointer to a "struct mosquitto_message *". The received + * messages will be returned here. On error, this will be set to + * NULL. + * msg_count - the number of messages to retrieve. + * want_retained - if set to true, stale retained messages will be treated as + * normal messages with regards to msg_count. If set to + * false, they will be ignored. + * topic - the subscription topic to use (wildcards are allowed). + * qos - the qos to use for the subscription. + * host - the broker to connect to. + * port - the network port the broker is listening on. + * clientid - the client id to use, or NULL if a random client id should be + * generated. + * keepalive - the MQTT keepalive value. + * clean_session - the MQTT clean session flag. + * username - the username string, or NULL for no username authentication. + * password - the password string, or NULL for an empty password. + * will - a libmosquitto_will struct containing will information, or NULL for + * no will. + * tls - a libmosquitto_tls struct containing TLS related parameters, or NULL + * for no use of TLS. + * + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * Greater than 0 - on error. + */ +libmosq_EXPORT int mosquitto_subscribe_simple( + struct mosquitto_message **messages, + int msg_count, + bool want_retained, + const char *topic, + int qos, + const char *host, + int port, + const char *clientid, + int keepalive, + bool clean_session, + const char *username, + const char *password, + const struct libmosquitto_will *will, + const struct libmosquitto_tls *tls); + + +/* + * Function: mosquitto_subscribe_callback + * + * Helper function to make subscribing to a topic and processing some messages + * very straightforward. + * + * This connects to a broker, subscribes to a topic, then passes received + * messages to a user provided callback. If the callback returns a 1, it then + * disconnects cleanly and returns. + * + * Parameters: + * callback - a callback function in the following form: + * int callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message) + * Note that this is the same as the normal on_message callback, + * except that it returns an int. + * userdata - user provided pointer that will be passed to the callback. + * topic - the subscription topic to use (wildcards are allowed). + * qos - the qos to use for the subscription. + * host - the broker to connect to. + * port - the network port the broker is listening on. + * clientid - the client id to use, or NULL if a random client id should be + * generated. + * keepalive - the MQTT keepalive value. + * clean_session - the MQTT clean session flag. + * username - the username string, or NULL for no username authentication. + * password - the password string, or NULL for an empty password. + * will - a libmosquitto_will struct containing will information, or NULL for + * no will. + * tls - a libmosquitto_tls struct containing TLS related parameters, or NULL + * for no use of TLS. + * + * + * Returns: + * MOSQ_ERR_SUCCESS - on success + * Greater than 0 - on error. + */ +libmosq_EXPORT int mosquitto_subscribe_callback( + int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *), + void *userdata, + const char *topic, + int qos, + const char *host, + int port, + const char *clientid, + int keepalive, + bool clean_session, + const char *username, + const char *password, + const struct libmosquitto_will *will, + const struct libmosquitto_tls *tls); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_loop.h b/include/mosquitto/libmosquitto_loop.h new file mode 100644 index 00000000..1f224939 --- /dev/null +++ b/include/mosquitto/libmosquitto_loop.h @@ -0,0 +1,322 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_LOOP_H +#define MOSQUITTO_LIBMOSQUITTO_LOOP_H + +/* + * File: mosquitto/libmosquitto_loop.h + * + * This header contains functions for handling the libmosquitto network loop. + */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include +#include + +/* ====================================================================== + * + * Section: Network loop (managed by libmosquitto) + * + * The internal network loop must be called at a regular interval. The two + * recommended approaches are to use either or + * . is a blocking call and is + * suitable for the situation where you only want to handle incoming messages + * in callbacks. is a non-blocking call, it creates a + * separate thread to run the loop for you. Use this function when you have + * other tasks you need to run at the same time as the MQTT client, e.g. + * reading data from a sensor. + * + * ====================================================================== */ + +/* + * Function: mosquitto_loop_forever + * + * This function call loop() for you in an infinite blocking loop. It is useful + * for the case where you only want to run the MQTT client loop in your + * program. + * + * It handles reconnecting in case server connection is lost. If you call + * mosquitto_disconnect() in a callback it will return. + * + * 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. + * + * 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_CONN_LOST - if the connection to the broker was lost. + * 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 + * 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); + +/* + * Function: mosquitto_loop_start + * + * This is part of the threaded client interface. Call this once to start a new + * thread to process network traffic. This provides an alternative to + * repeatedly calling yourself. + * + * Parameters: + * 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. + * + * See Also: + * , , , + */ +libmosq_EXPORT int mosquitto_loop_start(struct mosquitto *mosq); + +/* + * Function: mosquitto_loop_stop + * + * This is part of the threaded client interface. Call this once to stop the + * network thread previously created with . This call + * will block until the network thread finishes. For the network thread to end, + * you must have previously called or have set the force + * parameter to true. + * + * Parameters: + * mosq - a valid mosquitto instance. + * 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. + * + * See Also: + * , + */ +libmosq_EXPORT int mosquitto_loop_stop(struct mosquitto *mosq, bool force); + +/* + * Function: mosquitto_loop + * + * The main network loop for the client. This must be called frequently + * to keep communications between the client and broker working. This is + * carried out by and , which + * are the recommended ways of handling the network loop. You may also use this + * function if you wish. It must not be called inside a callback. + * + * If incoming data is present it will then be processed. Outgoing commands, + * from e.g. , are normally sent immediately that their + * function is called, but this is not always possible. will + * also attempt to send any remaining outgoing messages, which also includes + * commands that are part of the flow for messages with QoS>0. + * + * This calls select() to monitor the client network socket. If you want to + * integrate mosquitto client operation with your own select() call, use + * , , and + * . + * + * 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. + * + * 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_CONN_LOST - if the connection to the broker was lost. + * 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 + * 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); + +/* ====================================================================== + * + * Section: Network loop (for use in other event loops) + * + * ====================================================================== */ +/* + * Function: mosquitto_loop_read + * + * Carry out network read operations. + * This should only be used if you are not using mosquitto_loop() and are + * 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. + * + * 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_CONN_LOST - if the connection to the broker was lost. + * 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 + * 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); + +/* + * Function: mosquitto_loop_write + * + * Carry out network write operations. + * This should only be used if you are not using mosquitto_loop() and are + * 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. + * + * 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_CONN_LOST - if the connection to the broker was lost. + * 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 + * 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); + +/* + * Function: mosquitto_loop_misc + * + * Carry out miscellaneous operations required as part of the network loop. + * This should only be used if you are not using mosquitto_loop() and are + * monitoring the client network socket for activity yourself. + * + * This function deals with handling PINGs and checking whether messages need + * to be retried, so should be called fairly frequently, around once per second + * is sufficient. + * + * Parameters: + * 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. + * + * See Also: + * , , + */ +libmosq_EXPORT int mosquitto_loop_misc(struct mosquitto *mosq); + + +/* ====================================================================== + * + * Section: Network loop (helper functions) + * + * ====================================================================== */ +/* + * Function: mosquitto_socket + * + * Return the socket handle for a mosquitto instance. Useful if you want to + * include a mosquitto client in your own select() calls. + * + * Parameters: + * mosq - a valid mosquitto instance. + * + * Returns: + * The socket for the mosquitto client or -1 on failure. + */ +libmosq_EXPORT int mosquitto_socket(struct mosquitto *mosq); + +/* + * Function: mosquitto_want_write + * + * Returns true if there is data ready to be written on the socket. + * + * Parameters: + * mosq - a valid mosquitto instance. + * + * See Also: + * , , + */ +libmosq_EXPORT bool mosquitto_want_write(struct mosquitto *mosq); + +/* + * Function: mosquitto_threaded_set + * + * Used to tell the library that your application is using threads, but not + * using . The library operates slightly differently when + * not in threaded mode in order to simplify its operation. If you are managing + * your own threads and do not use this function you will experience crashes + * due to race conditions. + * + * When using , this is set automatically. + * + * Parameters: + * mosq - a valid mosquitto instance. + * threaded - true if your application is using threads, false otherwise. + */ +libmosq_EXPORT int mosquitto_threaded_set(struct mosquitto *mosq, bool threaded); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_message.h b/include/mosquitto/libmosquitto_message.h new file mode 100644 index 00000000..8054755e --- /dev/null +++ b/include/mosquitto/libmosquitto_message.h @@ -0,0 +1,86 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_MESSAGE_H +#define MOSQUITTO_LIBMOSQUITTO_MESSAGE_H + +/* + * File: mosquitto/libmosquitto_message.h + * + * This header contains functions for handling mosquitto_message structs. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* ====================================================================== + * + * Section: Struct mosquitto_message helper functions + * + * ====================================================================== */ +/* + * Function: mosquitto_message_copy + * + * Copy the contents of a mosquitto message to another message. + * 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. + * + * 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. + * + * See Also: + * + */ +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. + * + * See Also: + * , + */ +libmosq_EXPORT void mosquitto_message_free(struct mosquitto_message **message); + +/* + * Function: mosquitto_message_free_contents + * + * Free a mosquitto_message struct contents, leaving the struct unaffected. + * + * Parameters: + * message - pointer to a mosquitto_message struct to free its contents. + * + * See Also: + * , + */ +libmosq_EXPORT void mosquitto_message_free_contents(struct mosquitto_message *message); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_options.h b/include/mosquitto/libmosquitto_options.h new file mode 100644 index 00000000..090caedc --- /dev/null +++ b/include/mosquitto/libmosquitto_options.h @@ -0,0 +1,321 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_OPTIONS_H +#define MOSQUITTO_LIBMOSQUITTO_OPTIONS_H + +/* + * File: mosquitto/libmosquitto_options.h + * + * This header contains functions for setting client options in libmosquitto. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* ====================================================================== + * + * Section: Client options + * + * ====================================================================== */ +/* + * Function: mosquitto_opts_set + * + * Used to set options for the client. + * + * This function is deprecated, the replacement , + * and functions should + * be used instead. + * + * Parameters: + * mosq - a valid mosquitto instance. + * option - the option to set. + * value - the option specific value. + * + * Options: + * MOSQ_OPT_PROTOCOL_VERSION - Value must be an int, set to either + * MQTT_PROTOCOL_V31 or MQTT_PROTOCOL_V311. Must be set + * before the client connects. + * Defaults to MQTT_PROTOCOL_V31. + * + * MOSQ_OPT_SSL_CTX - Pass an openssl SSL_CTX to be used when creating + * TLS connections rather than libmosquitto creating its own. + * This must be called before connecting to have any effect. + * If you use this option, the onus is on you to ensure that + * you are using secure settings. + * Setting to NULL means that libmosquitto will use its own SSL_CTX + * if TLS is to be used. + * This option is only available for openssl 1.1.0 and higher. + * + * MOSQ_OPT_SSL_CTX_WITH_DEFAULTS - Value must be an int set to 1 or 0. + * If set to 1, then the user specified SSL_CTX passed in using + * MOSQ_OPT_SSL_CTX will have the default options applied to it. + * This means that you only need to change the values that are + * relevant to you. If you use this option then you must configure + * the TLS options as normal, i.e. you should use + * to configure the cafile/capath as a minimum. + * This option is only available for openssl 1.1.0 and higher. + */ +libmosq_EXPORT int mosquitto_opts_set(struct mosquitto *mosq, enum mosq_opt_t option, void *value); + +/* + * Function: mosquitto_int_option + * + * Used to set integer options for the client. + * + * Parameters: + * mosq - a valid mosquitto instance. + * option - the option to set. + * value - the option specific value. + * + * Options: + * MOSQ_OPT_TCP_NODELAY - Set to 1 to disable Nagle's algorithm on client + * sockets. This has the effect of reducing latency of individual + * messages at the potential cost of increasing the number of + * packets being sent. + * Defaults to 0, which means Nagle remains enabled. + * + * MOSQ_OPT_PROTOCOL_VERSION - Value must be set to either MQTT_PROTOCOL_V31, + * MQTT_PROTOCOL_V311, or MQTT_PROTOCOL_V5. Must be set before the + * client connects. Defaults to MQTT_PROTOCOL_V311. + * + * MOSQ_OPT_RECEIVE_MAXIMUM - Value can be set between 1 and 65535 inclusive, + * and represents the maximum number of incoming QoS 1 and QoS 2 + * messages that this client wants to process at once. Defaults to + * 20. This option is not valid for MQTT v3.1 or v3.1.1 clients. + * Note that if the MQTT_PROP_RECEIVE_MAXIMUM property is in the + * proplist passed to mosquitto_connect_v5(), then that property + * will override this option. Using this option is the recommended + * method however. + * + * MOSQ_OPT_SEND_MAXIMUM - Value can be set between 1 and 65535 inclusive, + * and represents the maximum number of outgoing QoS 1 and QoS 2 + * messages that this client will attempt to have "in flight" at + * once. Defaults to 20. + * This option is not valid for MQTT v3.1 or v3.1.1 clients. + * Note that if the broker being connected to sends a + * MQTT_PROP_RECEIVE_MAXIMUM property that has a lower value than + * this option, then the broker provided value will be used. + * + * MOSQ_OPT_SSL_CTX_WITH_DEFAULTS - If value is set to a non zero value, + * then the user specified SSL_CTX passed in using MOSQ_OPT_SSL_CTX + * will have the default options applied to it. This means that + * you only need to change the values that are relevant to you. + * If you use this option then you must configure the TLS options + * as normal, i.e. you should use to + * configure the cafile/capath as a minimum. + * This option is only available for openssl 1.1.0 and higher. + * + * MOSQ_OPT_TLS_OCSP_REQUIRED - Set whether OCSP checking on TLS + * connections is required. Set to 1 to enable checking, + * or 0 (the default) for no checking. + * + * MOSQ_OPT_TLS_USE_OS_CERTS - Set to 1 to instruct the client to load and + * trust OS provided CA certificates for use with TLS connections. + * Set to 0 (the default) to only use manually specified CA certs. + * + * MOSQ_OPT_DISABLE_SOCKETPAIR - By default, each client connected will create + * an internal pair of connected sockets to allow the network thread + * to be notified and woken up if another thread calls + * or other similar command. If you are + * operating with an external loop, this is not necessary and + * consumes an extra two sockets per client. Set this option to 1 to + * disable the use of the socket pair. + * + * MOSQ_OPT_TRANSPORT - Have the client connect with either MQTT over TCP as + * normal, or MQTT over WebSockets. Set the value to MOSQ_T_TCP or + * MOSQ_T_WEBSOCKETS. + * + * MOSQ_OPT_HTTP_HEADER_SIZE - Size the size of buffer that will be allocated + * to store the incoming HTTP header when using Websocket transport. + * Defaults to 4096. Setting to below 100 will result in a return +* value of MOSQ_ERR_INVAL. This should be set before starting the +* connection. If you try to set this when the initial http request +* is underway then it will return MOSQ_ERR_INVAL. + */ +libmosq_EXPORT int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t option, int value); + + +/* + * Function: mosquitto_string_option + * + * Used to set const char* options for the client. + * + * Parameters: + * mosq - a valid mosquitto instance. + * option - the option to set. + * value - the option specific value. + * + * Options: + * MOSQ_OPT_TLS_ENGINE - Configure the client for TLS Engine support. + * Pass a TLS Engine ID to be used when creating TLS + * connections. Must be set before . + * Must be a valid engine, and note that the string will not be used + * until a connection attempt is made so this function will return + * success even if an invalid engine string is passed. + * + * MOSQ_OPT_TLS_KEYFORM - Configure the client to treat the keyfile + * differently depending on its type. Must be set + * before . + * Set as either "pem" or "engine", to determine from where the + * private key for a TLS connection will be obtained. Defaults to + * "pem", a normal private key file. + * + * MOSQ_OPT_TLS_KPASS_SHA1 - Where the TLS Engine requires the use of + * a password to be accessed, this option allows a hex encoded + * SHA1 hash of the private key password to be passed to the + * engine directly. Must be set before . + * + * MOSQ_OPT_TLS_ALPN - If the broker being connected to has multiple + * services available on a single TLS port, such as both MQTT + * and WebSockets, use this option to configure the ALPN + * option for the connection. + * + * MOSQ_OPT_BIND_ADDRESS - Set the hostname or ip address of the local network + * interface to bind to when connecting. + */ +libmosq_EXPORT int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, const char *value); + + +/* + * Function: mosquitto_void_option + * + * Used to set void* options for the client. + * + * Parameters: + * mosq - a valid mosquitto instance. + * option - the option to set. + * value - the option specific value. + * + * Options: + * MOSQ_OPT_SSL_CTX - Pass an openssl SSL_CTX to be used when creating TLS + * connections rather than libmosquitto creating its own. This must + * be called before connecting to have any effect. If you use this + * option, the onus is on you to ensure that you are using secure + * settings. + * Setting to NULL means that libmosquitto will use its own SSL_CTX + * if TLS is to be used. + * This option is only available for openssl 1.1.0 and higher. + */ +libmosq_EXPORT int mosquitto_void_option(struct mosquitto *mosq, enum mosq_opt_t option, void *value); + +/* + * Function: mosquitto_reconnect_delay_set + * + * Control the behaviour of the client when it has unexpectedly disconnected in + * or after . The default + * behaviour if this function is not used is to repeatedly attempt to reconnect + * with a delay of 1 second until the connection succeeds. + * + * Use reconnect_delay parameter to change the delay between successive + * reconnection attempts. You may also enable exponential backoff of the time + * between reconnections by setting reconnect_exponential_backoff to true and + * 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, ... + * + * Example 2: + * delay=3, delay_max=30, exponential_backoff=True + * Delays would be: 3, 6, 12, 24, 30, 30, ... + * + * Parameters: + * mosq - a valid mosquitto instance. + * reconnect_delay - the number of seconds to wait between + * reconnects. + * reconnect_delay_max - the maximum number of seconds to wait + * between reconnects. + * reconnect_exponential_backoff - use exponential backoff between + * reconnect attempts. Set to true to enable + * exponential backoff. + * + * Returns: + * 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); + +/* + * Function: mosquitto_max_inflight_messages_set + * + * This function is deprected. Use the function with the + * MOSQ_OPT_SEND_MAXIMUM option instead. + * + * Set the number of QoS 1 and 2 messages that can be "in flight" at one time. + * An in flight message is part way through its delivery flow. Attempts to send + * further messages with will result in the messages being + * queued until the number of in flight messages reduces. + * + * A higher number here results in greater message throughput, but if set + * higher than the maximum in flight messages on the broker may lead to + * delays in the messages being acknowledged. + * + * Set to 0 for no maximum. + * + * Parameters: + * mosq - a valid mosquitto instance. + * max_inflight_messages - the maximum number of inflight messages. Defaults + * to 20. + * + * Returns: + * 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); + +/* + * Function: mosquitto_message_retry_set + * + * This function now has no effect. + */ +libmosq_EXPORT void mosquitto_message_retry_set(struct mosquitto *mosq, unsigned int message_retry); + +/* + * Function: mosquitto_user_data_set + * + * When is called, the pointer given as the "obj" parameter + * will be passed to the callbacks as user data. The + * function allows this obj parameter to be updated at any time. This function + * will not modify the memory pointed to by the current user data pointer. If + * it is dynamically allocated memory you must free it yourself. + * + * Parameters: + * mosq - a valid mosquitto instance. + * 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); + +/* Function: mosquitto_userdata + * + * Retrieve the "userdata" variable for a mosquitto client. + * + * Parameters: + * mosq - a valid mosquitto instance. + * + * Returns: + * A pointer to the userdata member variable. + */ +libmosq_EXPORT void *mosquitto_userdata(struct mosquitto *mosq); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_publish.h b/include/mosquitto/libmosquitto_publish.h new file mode 100644 index 00000000..112bd7aa --- /dev/null +++ b/include/mosquitto/libmosquitto_publish.h @@ -0,0 +1,144 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_PUBLISH_H +#define MOSQUITTO_LIBMOSQUITTO_PUBLISH_H + +/* + * File: mosquitto/libmosquitto_publish.h + * + * This header contains functions for publishing with libmosquitto. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Function: mosquitto_publish + * + * Publish a message on a given topic. + * + * It is valid to use this function for clients using all MQTT protocol versions. + * If you need to set MQTT v5 PUBLISH properties, use + * instead. + * + * Parameters: + * 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. + * topic - null terminated string of the topic to publish to. + * 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 + * valid memory location. + * 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. + * + * 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 + * broker. + * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large. + * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8 + * MOSQ_ERR_QOS_NOT_SUPPORTED - if the QoS is greater than that supported by + * the broker. + * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than + * supported by the broker. + * + * See Also: + * + */ +libmosq_EXPORT int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int payloadlen, const void *payload, int qos, bool retain); + + +/* + * Function: mosquitto_publish_v5 + * + * Publish a message on a given topic, with attached MQTT properties. + * + * Use e.g. and similar to create a list of + * properties, then attach them to this publish. Properties need freeing with + * . + * + * If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument + * will be applied to the PUBLISH message. For MQTT v3.1.1 and below, the + * `properties` argument will be ignored. + * + * Set your client to use MQTT v5 immediately after it is created: + * + * mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); + * + * Parameters: + * 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. + * topic - null terminated string of the topic to publish to. + * 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 + * valid memory location. + * 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. + * properties - a valid mosquitto_property list, or NULL. + * + * 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 + * broker. + * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large. + * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8 + * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. + * MOSQ_ERR_PROTOCOL - if any property is invalid for use with PUBLISH. + * MOSQ_ERR_QOS_NOT_SUPPORTED - if the QoS is greater than that supported by + * the broker. + * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than + * supported by the broker. + */ +libmosq_EXPORT int mosquitto_publish_v5( + struct mosquitto *mosq, + int *mid, + const char *topic, + int payloadlen, + const void *payload, + int qos, + bool retain, + const mosquitto_property *properties); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_socks.h b/include/mosquitto/libmosquitto_socks.h new file mode 100644 index 00000000..446a0971 --- /dev/null +++ b/include/mosquitto/libmosquitto_socks.h @@ -0,0 +1,59 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_SOCKS_H +#define MOSQUITTO_LIBMOSQUITTO_SOCKS_H + +/* + * File: mosquitto/libmosquitto_socks.h + * + * This header contains functions for controlling SOCKSv5 in libmosquitto. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* ============================================================================= + * + * Section: SOCKS5 proxy functions + * + * ============================================================================= + */ + +/* + * Function: mosquitto_socks5_set + * + * Configure the client to use a SOCKS5 proxy when connecting. Must be called + * before connecting. "None" and "username/password" authentication is + * supported. + * + * Parameters: + * mosq - a valid mosquitto instance. + * host - the SOCKS5 proxy host to connect to. + * port - the SOCKS5 proxy port to use. + * username - if not NULL, use this username when authenticating with the proxy. + * password - if not NULL and username is not NULL, use this password when + * authenticating with the proxy. + */ +libmosq_EXPORT int mosquitto_socks5_set(struct mosquitto *mosq, const char *host, int port, const char *username, const char *password); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_subscribe.h b/include/mosquitto/libmosquitto_subscribe.h new file mode 100644 index 00000000..66564a5e --- /dev/null +++ b/include/mosquitto/libmosquitto_subscribe.h @@ -0,0 +1,142 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_SUBSCRIBE_H +#define MOSQUITTO_LIBMOSQUITTO_SUBSCRIBE_H + +/* + * File: mosquitto/libmosquitto_subscribe.h + * + * This header contains functions for subscribing in libmosquitto. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Function: mosquitto_subscribe + * + * Subscribe to a topic. + * + * It is valid to use this function for clients using all MQTT protocol versions. + * If you need to set MQTT v5 SUBSCRIBE properties, use + * instead. + * + * 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 - must not be NULL or an empty string. + * 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_MALFORMED_UTF8 - if the topic is not valid UTF-8 + * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than + * supported by the broker. + */ +libmosq_EXPORT int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const char *sub, int qos); + +/* + * Function: mosquitto_subscribe_v5 + * + * Subscribe to a topic, with attached MQTT properties. + * + * Use e.g. and similar to create a list of + * properties, then attach them to this publish. Properties need freeing with + * . + * + * If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument + * will be applied to the PUBLISH message. For MQTT v3.1.1 and below, the + * `properties` argument will be ignored. + * + * Set your client to use MQTT v5 immediately after it is created: + * + * mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); + * + * 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 - must not be NULL or an empty string. + * qos - the requested Quality of Service for this subscription. + * options - options to apply to this subscription, OR'd together. Set to 0 to + * use the default options, otherwise choose from list of + * properties - a valid mosquitto_property list, or NULL. + * + * 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_MALFORMED_UTF8 - if the topic is not valid UTF-8 + * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. + * MOSQ_ERR_PROTOCOL - if any property is invalid for use with SUBSCRIBE. + * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than + * supported by the broker. + */ +libmosq_EXPORT int mosquitto_subscribe_v5(struct mosquitto *mosq, int *mid, const char *sub, int qos, int options, const mosquitto_property *properties); + +/* + * Function: mosquitto_subscribe_multiple + * + * Subscribe to multiple topics. + * + * 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_count - the count of subscriptions to be made + * sub - array of sub_count pointers, each pointing to a subscription string. + * The "char *const *const" datatype ensures that neither the array of + * pointers nor the strings that they point to are mutable. If you aren't + * familiar with this, just think of it as a safer "char **", + * equivalent to "const char *" for a simple string pointer. + * Each string must not be NULL or an empty string. + * qos - the requested Quality of Service for each subscription. + * options - options to apply to this subscription, OR'd together. This + * argument is not used for MQTT v3 susbcriptions. Set to 0 to use + * the default options, otherwise choose from list of + * properties - a valid mosquitto_property list, or NULL. Only used with MQTT + * v5 clients. + * + * 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_MALFORMED_UTF8 - if a topic is not valid UTF-8 + * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than + * supported by the broker. + */ +libmosq_EXPORT int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, int qos, int options, const mosquitto_property *properties); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_tls.h b/include/mosquitto/libmosquitto_tls.h new file mode 100644 index 00000000..a4d7b838 --- /dev/null +++ b/include/mosquitto/libmosquitto_tls.h @@ -0,0 +1,198 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_TLS_H +#define MOSQUITTO_LIBMOSQUITTO_TLS_H + +/* + * File: mosquitto/libmosquitto_tls.h + * + * This header contains functions for setting TLS options in libmosquitto. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* ====================================================================== + * + * Section: TLS support + * + * ====================================================================== */ +/* + * Function: mosquitto_tls_set + * + * Configure the client for certificate based SSL/TLS support. Must be called + * before . + * + * Cannot be used in conjunction with . + * + * Define the Certificate Authority certificates to be trusted (ie. the server + * certificate must be signed with one of these certificates) using cafile. + * + * If the server you are connecting to requires clients to provide a + * certificate, define certfile and keyfile with your client certificate and + * private key. If your private key is encrypted, provide a password callback + * function or you will have to enter the password at the command line. + * + * Parameters: + * mosq - a valid mosquitto instance. + * cafile - path to a file containing the PEM encoded trusted CA + * certificate files. Either cafile or capath must not be NULL. + * capath - path to a directory containing the PEM encoded trusted CA + * certificate files. See mosquitto.conf for more details on + * configuring this directory. Either cafile or capath must not + * be NULL. + * certfile - path to a file containing the PEM encoded certificate file + * for this client. If NULL, keyfile must also be NULL and no + * client certificate will be used. + * keyfile - path to a file containing the PEM encoded private key for + * this client. If NULL, certfile must also be NULL and no + * client certificate will be used. + * pw_callback - if keyfile is encrypted, set pw_callback to allow your client + * to pass the correct password for decryption. If set to NULL, + * the password must be entered on the command line. + * Your callback must write the password into "buf", which is + * "size" bytes long. The return value must be the length of the + * password. "userdata" will be set to the calling mosquitto + * instance. The mosquitto userdata member variable can be + * retrieved using . + * + * 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. + * + * 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)); + +/* + * Function: mosquitto_tls_insecure_set + * + * Configure verification of the server hostname in the server certificate. If + * value is set to true, it is impossible to guarantee that the host you are + * connecting to is not impersonating your server. This can be useful in + * initial server testing, but makes it possible for a malicious third party to + * impersonate your server through DNS spoofing, for example. + * Do not use this function in a real system. Setting value to true makes the + * connection encryption pointless. + * Must be called before . + * + * Parameters: + * mosq - a valid mosquitto instance. + * value - if set to false, the default, certificate hostname checking is + * performed. If set to true, no hostname checking is performed and + * the connection is insecure. + * + * Returns: + * 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); + +/* + * Function: mosquitto_tls_opts_set + * + * Set advanced SSL/TLS options. Must be called before . + * + * 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. + * + * 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. + * + * See Also: + * + */ +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 + * + * Configure the client for pre-shared-key based TLS support. Must be called + * before . + * + * Cannot be used in conjunction with . + * + * Parameters: + * mosq - a valid mosquitto instance. + * 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. + * + * 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. + * + * See Also: + * + */ +libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk, const char *identity, const char *ciphers); + + +/* + * Function: mosquitto_ssl_get + * + * Retrieve a pointer to the SSL structure used for TLS connections in this + * client. This can be used in e.g. the connect callback to carry out + * additional verification steps. + * + * Parameters: + * mosq - a valid mosquitto instance + * + * Returns: + * A valid pointer to an openssl SSL structure - if the client is using TLS. + * NULL - if the client is not using TLS, or TLS support is not compiled in. + */ +libmosq_EXPORT void *mosquitto_ssl_get(struct mosquitto *mosq); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_unsubscribe.h b/include/mosquitto/libmosquitto_unsubscribe.h new file mode 100644 index 00000000..9368586f --- /dev/null +++ b/include/mosquitto/libmosquitto_unsubscribe.h @@ -0,0 +1,135 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_UNSUBSCRIBE_H +#define MOSQUITTO_LIBMOSQUITTO_UNSUBSCRIBE_H + +/* + * File: mosquitto/libmosquitto_unsubscribe.h + * + * This header contains functions for client unsubscribing in libmosquitto. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Function: mosquitto_unsubscribe + * + * 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 - must not by NULL or an empty string. + * + * 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_MALFORMED_UTF8 - if the topic is not valid UTF-8 + * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than + * supported by the broker. + */ +libmosq_EXPORT int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub); + +/* + * Function: mosquitto_unsubscribe_v5 + * + * Unsubscribe from a topic, with attached MQTT properties. + * + * It is valid to use this function for clients using all MQTT protocol versions. + * If you need to set MQTT v5 UNSUBSCRIBE properties, use + * instead. + * + * Use e.g. and similar to create a list of + * properties, then attach them to this publish. Properties need freeing with + * . + * + * If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument + * will be applied to the PUBLISH message. For MQTT v3.1.1 and below, the + * `properties` argument will be ignored. + * + * Set your client to use MQTT v5 immediately after it is created: + * + * mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); + * + * 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 - must not by NULL or an empty string. + * properties - a valid mosquitto_property list, or NULL. Only used with MQTT + * v5 clients. + * + * 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_MALFORMED_UTF8 - if the topic is not valid UTF-8 + * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. + * MOSQ_ERR_PROTOCOL - if any property is invalid for use with UNSUBSCRIBE. + * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than + * supported by the broker. + */ +libmosq_EXPORT int mosquitto_unsubscribe_v5(struct mosquitto *mosq, int *mid, const char *sub, const mosquitto_property *properties); + +/* + * Function: mosquitto_unsubscribe_multiple + * + * Unsubscribe from multiple topics. + * + * 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_count - the count of unsubscriptions to be made + * sub - array of sub_count pointers, each pointing to an unsubscription string. + * The "char *const *const" datatype ensures that neither the array of + * pointers nor the strings that they point to are mutable. If you aren't + * familiar with this, just think of it as a safer "char **", + * equivalent to "const char *" for a simple string pointer. + * Each sub must not be NULL or an empty string. + * properties - a valid mosquitto_property list, or NULL. Only used with MQTT + * v5 clients. + * + * 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_MALFORMED_UTF8 - if a topic is not valid UTF-8 + * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than + * supported by the broker. + */ +libmosq_EXPORT int mosquitto_unsubscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, const mosquitto_property *properties); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquitto_will.h b/include/mosquitto/libmosquitto_will.h new file mode 100644 index 00000000..52b15a7f --- /dev/null +++ b/include/mosquitto/libmosquitto_will.h @@ -0,0 +1,127 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTO_WILL_H +#define MOSQUITTO_LIBMOSQUITTO_WILL_H + +/* + * File: mosquitto/libmosquitto_will.h + * + * This header contains functions for manipulating client Wills in libmosquitto. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/* ====================================================================== + * + * Section: Will + * + * ====================================================================== */ +/* + * 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 . + * + * It is valid to use this function for clients using all MQTT protocol versions. + * If you need to set MQTT v5 Will properties, use instead. + * + * 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 + * 268,435,455. + * 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 + * used for the will. + * 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_MALFORMED_UTF8 - if the topic is not valid UTF-8. + */ +libmosq_EXPORT int mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain); + +/* + * Function: mosquitto_will_set_v5 + * + * Configure will information for a mosquitto instance, with attached + * properties. By default, clients do not have a will. This must be called + * before calling . + * + * If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument + * will be applied to the Will. For MQTT v3.1.1 and below, the `properties` + * argument will be ignored. + * + * Set your client to use MQTT v5 immediately after it is created: + * + * mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); + * + * 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 + * 268,435,455. + * 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 + * used for the will. + * retain - set to true to make the will a retained message. + * properties - list of MQTT 5 properties. Can be NULL. On success only, the + * property list becomes the property of libmosquitto once this + * function is called and will be freed by the library. The + * property list must be freed by the application on error. + * + * 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_MALFORMED_UTF8 - if the topic is not valid UTF-8. + * MOSQ_ERR_NOT_SUPPORTED - if properties is not NULL and the client is not + * using MQTT v5 + * MOSQ_ERR_PROTOCOL - if a property is invalid for use with wills. + * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. + */ +libmosq_EXPORT int mosquitto_will_set_v5(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain, mosquitto_property *properties); + +/* + * Function: mosquitto_will_clear + * + * Remove a previously configured will. This must be called before calling + * . + * + * Parameters: + * mosq - a valid mosquitto instance. + * + * Returns: + * MOSQ_ERR_SUCCESS - on success. + * MOSQ_ERR_INVAL - if the input parameters were invalid. + */ +libmosq_EXPORT int mosquitto_will_clear(struct mosquitto *mosq); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mosquitto/libmosquittopp.h b/include/mosquitto/libmosquittopp.h new file mode 100644 index 00000000..4d99e240 --- /dev/null +++ b/include/mosquitto/libmosquittopp.h @@ -0,0 +1,162 @@ +/* +Copyright (c) 2010-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MOSQUITTO_LIBMOSQUITTOPP_H +#define MOSQUITTO_LIBMOSQUITTOPP_H + +#if defined(_WIN32) && !defined(LIBMOSQUITTO_STATIC) +# ifdef mosquittopp_EXPORTS +# define mosqpp_EXPORT __declspec(dllexport) +# else +# define mosqpp_EXPORT __declspec(dllimport) +# endif +#else +# define mosqpp_EXPORT +#endif + +#include +#include +#include + +namespace mosqpp { + + +mosqpp_EXPORT const char * strerror(int mosq_errno); +mosqpp_EXPORT const char * connack_string(int connack_code); +mosqpp_EXPORT const char * reason_string(int reason_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 int topic_matches_sub_with_pattern(const char *sub, const char *topic, const char *clientid, const char *username, bool *result); +mosqpp_EXPORT int sub_matches_acl(const char *acl, const char *sub, bool *result); +mosqpp_EXPORT int sub_matches_acl_with_pattern(const char *acl, const char *sub, const char *clientid, const char *username, bool *result); +mosqpp_EXPORT int validate_utf8(const char *str, int len); +mosqpp_EXPORT int subscribe_simple( + struct mosquitto_message **messages, + int msg_count, + bool retained, + const char *topic, + int qos=0, + const char *host="localhost", + int port=1883, + const char *clientid=NULL, + int keepalive=60, + bool clean_session=true, + const char *username=NULL, + const char *password=NULL, + const struct libmosquitto_will *will=NULL, + const struct libmosquitto_tls *tls=NULL); + +mosqpp_EXPORT int subscribe_callback( + int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *), + void *userdata, + const char *topic, + int qos=0, + const char *host="localhost", + int port=1883, + const char *clientid=NULL, + int keepalive=60, + bool clean_session=true, + const char *username=NULL, + const char *password=NULL, + const struct libmosquitto_will *will=NULL, + const struct libmosquitto_tls *tls=NULL); + +mosqpp_EXPORT int property_check_command(int command, int identifier); +mosqpp_EXPORT int property_check_all(int command, const mosquitto_property *properties); + +/* + * 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); + virtual ~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_set_v5(const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false, mosquitto_property *properties=NULL); + 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(const char *host, int port, int keepalive, const char *bind_address); + int connect_v5(const char *host, int port, int keepalive, const char *bind_address, const mosquitto_property *properties); + int connect_async(const char *host, int port=1883, int keepalive=60); + int connect_async(const char *host, int port, int keepalive, const char *bind_address); + int reconnect(); + int reconnect_async(); + int disconnect(); + int disconnect_v5(int reason_code, const mosquitto_property *properties); + int publish(int *mid, const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); + int publish_v5(int *mid, const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false, const mosquitto_property *properties=NULL); + int subscribe(int *mid, const char *sub, int qos=0); + int subscribe_v5(int *mid, const char *sub, int qos=0, int options=0, const mosquitto_property *properties=NULL); + int unsubscribe(int *mid, const char *sub); + int unsubscribe_v5(int *mid, const char *sub, const mosquitto_property *properties); + 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 opts_set(enum mosq_opt_t option, void *value); + int int_option(enum mosq_opt_t option, int value); + int string_option(enum mosq_opt_t option, const char *value); + int void_option(enum mosq_opt_t option, void *value); + + 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 threaded_set(bool threaded=true); + int socks5_set(const char *host, int port=1080, const char *username=NULL, const char *password=NULL); + + // names in the functions commented to prevent unused parameter warning + virtual void on_pre_connect() {return;} + virtual void on_connect(int /*rc*/) {return;} + virtual void on_connect_with_flags(int /*rc*/, int /*flags*/) {return;} + virtual void on_connect_v5(int /*rc*/, int /*flags*/, const mosquitto_property * /*props*/) {return;} + virtual void on_disconnect(int /*rc*/) {return;} + virtual void on_disconnect_v5(int /*rc*/, const mosquitto_property * /*props*/) {return;} + virtual void on_publish(int /*mid*/) {return;} + virtual void on_publish_v5(int /*mid*/, int /*reason_code*/, const mosquitto_property * /*props*/) {return;} + virtual void on_message(const struct mosquitto_message * /*message*/) {return;} + virtual void on_message_v5(const struct mosquitto_message * /*message*/, const mosquitto_property * /*props*/) {return;} + virtual void on_subscribe(int /*mid*/, int /*qos_count*/, const int * /*granted_qos*/) {return;} + virtual void on_subscribe_v5(int /*mid*/, int /*qos_count*/, const int * /*granted_qos*/, const mosquitto_property * /*props*/) {return;} + virtual void on_unsubscribe(int /*mid*/) {return;} + virtual void on_unsubscribe_v5(int /*mid*/, const mosquitto_property * /*props*/) {return;} + virtual void on_log(int /*level*/, const char * /*str*/) {return;} + virtual void on_error() {return;} +}; + +} +#endif diff --git a/include/mosquitto/mqtt_protocol.h b/include/mosquitto/mqtt_protocol.h new file mode 100644 index 00000000..ebcf2473 --- /dev/null +++ b/include/mosquitto/mqtt_protocol.h @@ -0,0 +1,292 @@ +/* +Copyright (c) 2009-2021 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License 2.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + https://www.eclipse.org/legal/epl-2.0/ +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#ifndef MQTT_PROTOCOL_H +#define MQTT_PROTOCOL_H + +/* + * File: mosquitto/mqtt_protocol.h + * + * This header contains definitions of MQTT values as defined in the specifications. + */ +#define PROTOCOL_NAME_v31 "MQIsdp" +#define PROTOCOL_VERSION_v31 3 + +#define PROTOCOL_NAME "MQTT" + +#define PROTOCOL_VERSION_v311 4 +#define PROTOCOL_VERSION_v5 5 + + +/* Message types */ +#define CMD_CONNECT 0x10U +#define CMD_CONNACK 0x20U +#define CMD_PUBLISH 0x30U +#define CMD_PUBACK 0x40U +#define CMD_PUBREC 0x50U +#define CMD_PUBREL 0x60U +#define CMD_PUBCOMP 0x70U +#define CMD_SUBSCRIBE 0x80U +#define CMD_SUBACK 0x90U +#define CMD_UNSUBSCRIBE 0xA0U +#define CMD_UNSUBACK 0xB0U +#define CMD_PINGREQ 0xC0U +#define CMD_PINGRESP 0xD0U +#define CMD_DISCONNECT 0xE0U +#define CMD_AUTH 0xF0U + +/* Mosquitto only: for distinguishing CONNECT and WILL properties */ +#define CMD_WILL 0x100 + +/* Enum: mqtt311_connack_codes + * + * The CONNACK results for MQTT v3.1.1, and v3.1. + * + * Values: + * CONNACK_ACCEPTED - 0 + * CONNACK_REFUSED_PROTOCOL_VERSION - 1 + * CONNACK_REFUSED_IDENTIFIER_REJECTED - 2 + * CONNACK_REFUSED_SERVER_UNAVAILABLE - 3 + * CONNACK_REFUSED_BAD_USERNAME_PASSWORD - 4 + * CONNACK_REFUSED_NOT_AUTHORIZED - 5 + */ +enum mqtt311_connack_codes { + CONNACK_ACCEPTED = 0, + CONNACK_REFUSED_PROTOCOL_VERSION = 1, + CONNACK_REFUSED_IDENTIFIER_REJECTED = 2, + CONNACK_REFUSED_SERVER_UNAVAILABLE = 3, + CONNACK_REFUSED_BAD_USERNAME_PASSWORD = 4, + CONNACK_REFUSED_NOT_AUTHORIZED = 5, +}; + +/* Enum: mqtt5_return_codes + * The reason codes returned in various MQTT commands. + * + * Values: + * MQTT_RC_SUCCESS - 0 + * MQTT_RC_NORMAL_DISCONNECTION - 0 + * MQTT_RC_GRANTED_QOS0 - 0 + * MQTT_RC_GRANTED_QOS1 - 1 + * MQTT_RC_GRANTED_QOS2 - 2 + * MQTT_RC_DISCONNECT_WITH_WILL_MSG - 4 + * MQTT_RC_NO_MATCHING_SUBSCRIBERS - 16 + * MQTT_RC_NO_SUBSCRIPTION_EXISTED - 17 + * MQTT_RC_CONTINUE_AUTHENTICATION - 24 + * MQTT_RC_REAUTHENTICATE - 25 + * MQTT_RC_UNSPECIFIED - 128 + * MQTT_RC_MALFORMED_PACKET - 129 + * MQTT_RC_PROTOCOL_ERROR - 130 + * MQTT_RC_IMPLEMENTATION_SPECIFIC - 131 + * MQTT_RC_UNSUPPORTED_PROTOCOL_VERSION - 132 + * MQTT_RC_CLIENTID_NOT_VALID - 133 + * MQTT_RC_BAD_USERNAME_OR_PASSWORD - 134 + * MQTT_RC_NOT_AUTHORIZED - 135 + * MQTT_RC_SERVER_UNAVAILABLE - 136 + * MQTT_RC_SERVER_BUSY - 137 + * MQTT_RC_BANNED - 138 + * MQTT_RC_SERVER_SHUTTING_DOWN - 139 + * MQTT_RC_BAD_AUTHENTICATION_METHOD - 140 + * MQTT_RC_KEEP_ALIVE_TIMEOUT - 141 + * MQTT_RC_SESSION_TAKEN_OVER - 142 + * MQTT_RC_TOPIC_FILTER_INVALID - 143 + * MQTT_RC_TOPIC_NAME_INVALID - 144 + * MQTT_RC_PACKET_ID_IN_USE - 145 + * MQTT_RC_PACKET_ID_NOT_FOUND - 146 + * MQTT_RC_RECEIVE_MAXIMUM_EXCEEDED - 147 + * MQTT_RC_TOPIC_ALIAS_INVALID - 148 + * MQTT_RC_PACKET_TOO_LARGE - 149 + * MQTT_RC_MESSAGE_RATE_TOO_HIGH - 150 + * MQTT_RC_QUOTA_EXCEEDED - 151 + * MQTT_RC_ADMINISTRATIVE_ACTION - 152 + * MQTT_RC_PAYLOAD_FORMAT_INVALID - 153 + * MQTT_RC_RETAIN_NOT_SUPPORTED - 154 + * MQTT_RC_QOS_NOT_SUPPORTED - 155 + * MQTT_RC_USE_ANOTHER_SERVER - 156 + * MQTT_RC_SERVER_MOVED - 157 + * MQTT_RC_SHARED_SUBS_NOT_SUPPORTED - 158 + * MQTT_RC_CONNECTION_RATE_EXCEEDED - 159 + * MQTT_RC_MAXIMUM_CONNECT_TIME - 160 + * MQTT_RC_SUBSCRIPTION_IDS_NOT_SUPPORTED - 161 + * MQTT_RC_WILDCARD_SUBS_NOT_SUPPORTED - 162 + */ +enum mqtt5_return_codes { + MQTT_RC_SUCCESS = 0, /* CONNACK, PUBACK, PUBREC, PUBREL, PUBCOMP, UNSUBACK, AUTH */ + MQTT_RC_NORMAL_DISCONNECTION = 0, /* DISCONNECT */ + MQTT_RC_GRANTED_QOS0 = 0, /* SUBACK */ + MQTT_RC_GRANTED_QOS1 = 1, /* SUBACK */ + MQTT_RC_GRANTED_QOS2 = 2, /* SUBACK */ + MQTT_RC_DISCONNECT_WITH_WILL_MSG = 4, /* DISCONNECT */ + MQTT_RC_NO_MATCHING_SUBSCRIBERS = 16, /* PUBACK, PUBREC */ + MQTT_RC_NO_SUBSCRIPTION_EXISTED = 17, /* UNSUBACK */ + MQTT_RC_CONTINUE_AUTHENTICATION = 24, /* AUTH */ + MQTT_RC_REAUTHENTICATE = 25, /* AUTH */ + + MQTT_RC_UNSPECIFIED = 128, /* CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, DISCONNECT */ + MQTT_RC_MALFORMED_PACKET = 129, /* CONNACK, DISCONNECT */ + MQTT_RC_PROTOCOL_ERROR = 130, /* DISCONNECT */ + MQTT_RC_IMPLEMENTATION_SPECIFIC = 131, /* CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, DISCONNECT */ + MQTT_RC_UNSUPPORTED_PROTOCOL_VERSION = 132, /* CONNACK */ + MQTT_RC_CLIENTID_NOT_VALID = 133, /* CONNACK */ + MQTT_RC_BAD_USERNAME_OR_PASSWORD = 134, /* CONNACK */ + MQTT_RC_NOT_AUTHORIZED = 135, /* CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, DISCONNECT */ + MQTT_RC_SERVER_UNAVAILABLE = 136, /* CONNACK */ + MQTT_RC_SERVER_BUSY = 137, /* CONNACK, DISCONNECT */ + MQTT_RC_BANNED = 138, /* CONNACK */ + MQTT_RC_SERVER_SHUTTING_DOWN = 139, /* DISCONNECT */ + MQTT_RC_BAD_AUTHENTICATION_METHOD = 140, /* CONNACK */ + MQTT_RC_KEEP_ALIVE_TIMEOUT = 141, /* DISCONNECT */ + MQTT_RC_SESSION_TAKEN_OVER = 142, /* DISCONNECT */ + MQTT_RC_TOPIC_FILTER_INVALID = 143, /* SUBACK, UNSUBACK, DISCONNECT */ + MQTT_RC_TOPIC_NAME_INVALID = 144, /* CONNACK, PUBACK, PUBREC, DISCONNECT */ + MQTT_RC_PACKET_ID_IN_USE = 145, /* PUBACK, SUBACK, UNSUBACK */ + MQTT_RC_PACKET_ID_NOT_FOUND = 146, /* PUBREL, PUBCOMP */ + MQTT_RC_RECEIVE_MAXIMUM_EXCEEDED = 147, /* DISCONNECT */ + MQTT_RC_TOPIC_ALIAS_INVALID = 148, /* DISCONNECT */ + MQTT_RC_PACKET_TOO_LARGE = 149, /* CONNACK, PUBACK, PUBREC, DISCONNECT */ + MQTT_RC_MESSAGE_RATE_TOO_HIGH = 150, /* DISCONNECT */ + MQTT_RC_QUOTA_EXCEEDED = 151, /* PUBACK, PUBREC, SUBACK, DISCONNECT */ + MQTT_RC_ADMINISTRATIVE_ACTION = 152, /* DISCONNECT */ + MQTT_RC_PAYLOAD_FORMAT_INVALID = 153, /* CONNACK, DISCONNECT */ + MQTT_RC_RETAIN_NOT_SUPPORTED = 154, /* CONNACK, DISCONNECT */ + MQTT_RC_QOS_NOT_SUPPORTED = 155, /* CONNACK, DISCONNECT */ + MQTT_RC_USE_ANOTHER_SERVER = 156, /* CONNACK, DISCONNECT */ + MQTT_RC_SERVER_MOVED = 157, /* CONNACK, DISCONNECT */ + MQTT_RC_SHARED_SUBS_NOT_SUPPORTED = 158, /* SUBACK, DISCONNECT */ + MQTT_RC_CONNECTION_RATE_EXCEEDED = 159, /* CONNACK, DISCONNECT */ + MQTT_RC_MAXIMUM_CONNECT_TIME = 160, /* DISCONNECT */ + MQTT_RC_SUBSCRIPTION_IDS_NOT_SUPPORTED = 161, /* SUBACK, DISCONNECT */ + MQTT_RC_WILDCARD_SUBS_NOT_SUPPORTED = 162, /* SUBACK, DISCONNECT */ +}; + +/* Enum: mqtt5_property + * Options for use with MQTTv5 properties. + * Options: + * + * MQTT_PROP_PAYLOAD_FORMAT_INDICATOR - property option. + * MQTT_PROP_MESSAGE_EXPIRY_INTERVAL - property option. + * MQTT_PROP_CONTENT_TYPE - property option. + * MQTT_PROP_RESPONSE_TOPIC - property option. + * MQTT_PROP_CORRELATION_DATA - property option. + * MQTT_PROP_SUBSCRIPTION_IDENTIFIER - property option. + * MQTT_PROP_SESSION_EXPIRY_INTERVAL - property option. + * MQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER - property option. + * MQTT_PROP_SERVER_KEEP_ALIVE - property option. + * MQTT_PROP_AUTHENTICATION_METHOD - property option. + * MQTT_PROP_AUTHENTICATION_DATA - property option. + * MQTT_PROP_REQUEST_PROBLEM_INFORMATION - property option. + * MQTT_PROP_WILL_DELAY_INTERVAL - property option. + * MQTT_PROP_REQUEST_RESPONSE_INFORMATION - property option. + * MQTT_PROP_RESPONSE_INFORMATION - property option. + * MQTT_PROP_SERVER_REFERENCE - property option. + * MQTT_PROP_REASON_STRING - property option. + * MQTT_PROP_RECEIVE_MAXIMUM - property option. + * MQTT_PROP_TOPIC_ALIAS_MAXIMUM - property option. + * MQTT_PROP_TOPIC_ALIAS - property option. + * MQTT_PROP_MAXIMUM_QOS - property option. + * MQTT_PROP_RETAIN_AVAILABLE - property option. + * MQTT_PROP_USER_PROPERTY - property option. + * MQTT_PROP_MAXIMUM_PACKET_SIZE - property option. + * MQTT_PROP_WILDCARD_SUB_AVAILABLE - property option. + * MQTT_PROP_SUBSCRIPTION_ID_AVAILABLE - property option. + * MQTT_PROP_SHARED_SUB_AVAILABLE - property option. + */ +enum mqtt5_property { + MQTT_PROP_PAYLOAD_FORMAT_INDICATOR = 1, /* Byte : PUBLISH, Will Properties */ + MQTT_PROP_MESSAGE_EXPIRY_INTERVAL = 2, /* 4 byte int : PUBLISH, Will Properties */ + MQTT_PROP_CONTENT_TYPE = 3, /* UTF-8 string : PUBLISH, Will Properties */ + MQTT_PROP_RESPONSE_TOPIC = 8, /* UTF-8 string : PUBLISH, Will Properties */ + MQTT_PROP_CORRELATION_DATA = 9, /* Binary Data : PUBLISH, Will Properties */ + MQTT_PROP_SUBSCRIPTION_IDENTIFIER = 11, /* Variable byte int : PUBLISH, SUBSCRIBE */ + MQTT_PROP_SESSION_EXPIRY_INTERVAL = 17, /* 4 byte int : CONNECT, CONNACK, DISCONNECT */ + MQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER = 18, /* UTF-8 string : CONNACK */ + MQTT_PROP_SERVER_KEEP_ALIVE = 19, /* 2 byte int : CONNACK */ + MQTT_PROP_AUTHENTICATION_METHOD = 21, /* UTF-8 string : CONNECT, CONNACK, AUTH */ + MQTT_PROP_AUTHENTICATION_DATA = 22, /* Binary Data : CONNECT, CONNACK, AUTH */ + MQTT_PROP_REQUEST_PROBLEM_INFORMATION = 23, /* Byte : CONNECT */ + MQTT_PROP_WILL_DELAY_INTERVAL = 24, /* 4 byte int : Will properties */ + MQTT_PROP_REQUEST_RESPONSE_INFORMATION = 25,/* Byte : CONNECT */ + MQTT_PROP_RESPONSE_INFORMATION = 26, /* UTF-8 string : CONNACK */ + MQTT_PROP_SERVER_REFERENCE = 28, /* UTF-8 string : CONNACK, DISCONNECT */ + MQTT_PROP_REASON_STRING = 31, /* UTF-8 string : CONNACK, PUBACK, PUBREC, PUBREL, PUBCOMP, SUBACK, UNSUBACK, DISCONNECT, AUTH */ + MQTT_PROP_RECEIVE_MAXIMUM = 33, /* 2 byte int : CONNECT, CONNACK */ + MQTT_PROP_TOPIC_ALIAS_MAXIMUM = 34, /* 2 byte int : CONNECT, CONNACK */ + MQTT_PROP_TOPIC_ALIAS = 35, /* 2 byte int : PUBLISH */ + MQTT_PROP_MAXIMUM_QOS = 36, /* Byte : CONNACK */ + MQTT_PROP_RETAIN_AVAILABLE = 37, /* Byte : CONNACK */ + MQTT_PROP_USER_PROPERTY = 38, /* UTF-8 string pair : All */ + MQTT_PROP_MAXIMUM_PACKET_SIZE = 39, /* 4 byte int : CONNECT, CONNACK */ + MQTT_PROP_WILDCARD_SUB_AVAILABLE = 40, /* Byte : CONNACK */ + MQTT_PROP_SUBSCRIPTION_ID_AVAILABLE = 41, /* Byte : CONNACK */ + MQTT_PROP_SHARED_SUB_AVAILABLE = 42, /* Byte : CONNACK */ +}; + +enum mqtt5_property_type { + MQTT_PROP_TYPE_BYTE = 1, + MQTT_PROP_TYPE_INT16 = 2, + MQTT_PROP_TYPE_INT32 = 3, + MQTT_PROP_TYPE_VARINT = 4, + MQTT_PROP_TYPE_BINARY = 5, + MQTT_PROP_TYPE_STRING = 6, + MQTT_PROP_TYPE_STRING_PAIR = 7 +}; + +/* Enum: mqtt5_sub_options + * Options for use with MQTTv5 subscriptions. + * + * MQTT_SUB_OPT_NO_LOCAL - with this option set, if this client publishes to + * a topic to which it is subscribed, the broker will not publish the + * message back to the client. + * + * MQTT_SUB_OPT_RETAIN_AS_PUBLISHED - with this option set, messages + * published for this subscription will keep the retain flag as was set by + * the publishing client. The default behaviour without this option set has + * the retain flag indicating whether a message is fresh/stale. + * + * MQTT_SUB_OPT_SEND_RETAIN_ALWAYS - with this option set, pre-existing + * retained messages are sent as soon as the subscription is made, even + * if the subscription already exists. This is the default behaviour, so + * it is not necessary to set this option. + * + * MQTT_SUB_OPT_SEND_RETAIN_NEW - with this option set, pre-existing retained + * messages for this subscription will be sent when the subscription is made, + * but only if the subscription does not already exist. + * + * MQTT_SUB_OPT_SEND_RETAIN_NEVER - with this option set, pre-existing + * retained messages will never be sent for this subscription. + */ +enum mqtt5_sub_options { + MQTT_SUB_OPT_NO_LOCAL = 0x04, + MQTT_SUB_OPT_RETAIN_AS_PUBLISHED = 0x08, + MQTT_SUB_OPT_SEND_RETAIN_ALWAYS = 0x00, + MQTT_SUB_OPT_SEND_RETAIN_NEW = 0x10, + MQTT_SUB_OPT_SEND_RETAIN_NEVER = 0x20, +}; + +#define MQTT_MAX_PAYLOAD 268435455U + +#define MQTT_SUB_OPT_GET_QOS(opt) ((opt) & 0x03) +#define MQTT_SUB_OPT_GET_NO_LOCAL(opt) ((opt) & MQTT_SUB_OPT_NO_LOCAL) +#define MQTT_SUB_OPT_GET_RETAIN_AS_PUBLISHED(opt) ((opt) & MQTT_SUB_OPT_RETAIN_AS_PUBLISHED) +#define MQTT_SUB_OPT_GET_SEND_RETAIN(opt) ((opt) & (MQTT_SUB_OPT_SEND_RETAIN_NEW | MQTT_SUB_OPT_SEND_RETAIN_NEVER)) + +#define MQTT_SUB_OPT_SET_QOS(opt, qos) ((opt) = ((opt) & 0xFC) | ((qos) & 0x03)) + +#define MQTT_SUB_OPT_SET(opt, val) ((opt) |= val) +#define MQTT_SUB_OPT_CLEAR(opt, val) ((opt) = (opt) & !val) + +#endif diff --git a/include/mosquitto_broker.h b/include/mosquitto_broker.h index 6f1d79fd..0ac1f4a8 100644 --- a/include/mosquitto_broker.h +++ b/include/mosquitto_broker.h @@ -1,1265 +1,2 @@ -/* -Copyright (c) 2009-2021 Roger Light - -All rights reserved. This program and the accompanying materials -are made available under the terms of the Eclipse Public License 2.0 -and Eclipse Distribution License v1.0 which accompany this distribution. - -The Eclipse Public License is available at - https://www.eclipse.org/legal/epl-2.0/ -and the Eclipse Distribution License is available at - http://www.eclipse.org/org/documents/edl-v10.php. - -SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause - -Contributors: - Roger Light - initial implementation and documentation. -*/ - -/* - * File: mosquitto_broker.h - * - * This header contains functions for use by plugins. - */ -#ifndef MOSQUITTO_BROKER_H -#define MOSQUITTO_BROKER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(WIN32) && defined(mosquitto_EXPORTS) -# define mosq_EXPORT __declspec(dllexport) -#else -# define mosq_EXPORT -#endif - -#include -#include -#include -#include - -#include -#include - -enum mosquitto_protocol { - mp_mqtt, - mp_mqttsn, - mp_websockets -}; - -enum mosquitto_broker_msg_direction { - mosq_bmd_in = 0, - mosq_bmd_out = 1, - mosq_bmd_all = 2 -}; - - -/* ========================================================================= - * - * Section: General structs - * - * ========================================================================= */ - -struct mosquitto_client { - char *clientid; - char *username; - char *auth_method; - struct mosquitto_message_v5 *will; - time_t will_delay_time; - time_t session_expiry_time; - uint32_t will_delay_interval; - uint32_t session_expiry_interval; - uint32_t max_packet_size; - uint16_t listener_port; - uint8_t max_qos; - bool retain_available; - void *future2[8]; -}; - -struct mosquitto_subscription { - char *clientid; - char *topic_filter; - mosquitto_property *properties; - uint32_t identifier; - uint8_t options; - uint8_t padding[3]; - void *future2[8]; -}; - -struct mosquitto_base_msg { - uint64_t store_id; - int64_t expiry_time; - char *topic; - void *payload; - char *source_id; - char *source_username; - mosquitto_property *properties; - uint32_t payloadlen; - uint16_t source_mid; - uint16_t source_port; - uint8_t qos; - bool retain; - uint8_t padding[6]; - void *future2[8]; -}; - -struct mosquitto_client_msg { - const char *clientid; - uint64_t cmsg_id; - uint64_t store_id; - uint32_t subscription_identifier; - uint16_t mid; - uint8_t qos; - bool retain; - uint8_t dup; - uint8_t direction; - uint8_t state; - uint8_t padding[5]; - void *future2[8]; -}; - -/* ========================================================================= - * - * Section: Register callbacks. - * - * ========================================================================= */ - -/* Callback events */ -enum mosquitto_plugin_event { - MOSQ_EVT_RELOAD = 1, - MOSQ_EVT_ACL_CHECK = 2, - MOSQ_EVT_BASIC_AUTH = 3, - MOSQ_EVT_EXT_AUTH_START = 4, - MOSQ_EVT_EXT_AUTH_CONTINUE = 5, - MOSQ_EVT_CONTROL = 6, - MOSQ_EVT_MESSAGE = 7, // deprecated name - MOSQ_EVT_MESSAGE_IN = 7, - MOSQ_EVT_PSK_KEY = 8, - MOSQ_EVT_TICK = 9, - MOSQ_EVT_DISCONNECT = 10, - MOSQ_EVT_CONNECT = 11, - MOSQ_EVT_SUBSCRIBE = 12, - MOSQ_EVT_UNSUBSCRIBE = 13, - MOSQ_EVT_PERSIST_RESTORE = 14, - MOSQ_EVT_PERSIST_BASE_MSG_ADD = 15, - MOSQ_EVT_PERSIST_BASE_MSG_DELETE = 16, - MOSQ_EVT_PERSIST_RETAIN_MSG_SET = 17, - MOSQ_EVT_PERSIST_RETAIN_MSG_DELETE = 18, - MOSQ_EVT_PERSIST_CLIENT_ADD = 19, - MOSQ_EVT_PERSIST_CLIENT_DELETE = 20, - MOSQ_EVT_PERSIST_CLIENT_UPDATE = 21, - MOSQ_EVT_PERSIST_SUBSCRIPTION_ADD = 22, - MOSQ_EVT_PERSIST_SUBSCRIPTION_DELETE = 23, - MOSQ_EVT_PERSIST_CLIENT_MSG_ADD = 24, - MOSQ_EVT_PERSIST_CLIENT_MSG_DELETE = 25, - MOSQ_EVT_PERSIST_CLIENT_MSG_UPDATE = 26, - MOSQ_EVT_MESSAGE_OUT = 27, - MOSQ_EVT_CLIENT_OFFLINE = 28, -}; - -/* Data for the MOSQ_EVT_RELOAD event */ -struct mosquitto_evt_reload { - void *future; - struct mosquitto_opt *options; - int option_count; - void *future2[4]; -}; - -/* Data for the MOSQ_EVT_ACL_CHECK event */ -struct mosquitto_evt_acl_check { - void *future; - struct mosquitto *client; - const char *topic; - const void *payload; - mosquitto_property *properties; - int access; - uint32_t payloadlen; - uint8_t qos; - bool retain; - void *future2[4]; -}; - -/* Data for the MOSQ_EVT_BASIC_AUTH event */ -struct mosquitto_evt_basic_auth { - void *future; - struct mosquitto *client; - char *username; - char *password; - void *future2[4]; -}; - -/* Data for the MOSQ_EVT_PSK_KEY event */ -struct mosquitto_evt_psk_key { - void *future; - struct mosquitto *client; - const char *hint; - const char *identity; - char *key; - int max_key_len; - void *future2[4]; -}; - -/* Data for the MOSQ_EVT_EXTENDED_AUTH event */ -struct mosquitto_evt_extended_auth { - void *future; - struct mosquitto *client; - const void *data_in; - void *data_out; - uint16_t data_in_len; - uint16_t data_out_len; - const char *auth_method; - void *future2[3]; -}; - -/* Data for the MOSQ_EVT_CONTROL event */ -struct mosquitto_evt_control { - void *future; - struct mosquitto *client; - const char *topic; - const void *payload; - const mosquitto_property *properties; - char *reason_string; - uint32_t payloadlen; - uint8_t qos; - uint8_t reason_code; - bool retain; - uint8_t padding; - void *future2[4]; -}; - -/* Data for the MOSQ_EVT_MESSAGE_IN and MOSQ_EVT_MESSAGE_OUT events */ -struct mosquitto_evt_message { - void *future; - struct mosquitto *client; - char *topic; - void *payload; - mosquitto_property *properties; - char *reason_string; - uint32_t payloadlen; - uint8_t qos; - uint8_t reason_code; - bool retain; - uint8_t padding; - void *future2[4]; -}; - - -/* Data for the MOSQ_EVT_TICK event */ -struct mosquitto_evt_tick { - void *future; - long now_ns; - long next_ms; - time_t now_s; - time_t next_s; - void *future2[4]; -}; - -/* Data for the MOSQ_EVT_CONNECT event */ -struct mosquitto_evt_connect { - void *future; - struct mosquitto *client; - void *future2[4]; -}; - -/* Data for the MOSQ_EVT_DISCONNECT event */ -struct mosquitto_evt_disconnect { - void *future; - struct mosquitto *client; - int reason; - void *future2[4]; -}; - -/* Data for the MOSQ_EVT_CLIENT_OFFLINE event */ -struct mosquitto_evt_client_offline { - void *future; - struct mosquitto *client; - int reason; - void *future2[4]; -}; - -/* Data for the MOSQ_EVT_SUBSCRIBE event */ -struct mosquitto_evt_subscribe { - void *future; - struct mosquitto *client; - struct mosquitto_subscription data; - void *future2[8]; -}; - - -/* Data for the MOSQ_EVT_UNSUBSCRIBE event */ -struct mosquitto_evt_unsubscribe { - void *future; - struct mosquitto *client; - struct mosquitto_subscription data; - void *future2[8]; -}; - - -/* Data for the MOSQ_EVT_PERSIST_RESTORE event */ -/* NOTE: The persistence interface is currently marked as unstable, which means - * it may change in a future minor release. */ -struct mosquitto_evt_persist_restore { - void *future[8]; -}; - - -/* Data for the MOSQ_EVT_PERSIST_CLIENT_ADD/_DELETE/_UPDATE event */ -/* NOTE: The persistence interface is currently marked as unstable, which means - * it may change in a future minor release. */ -struct mosquitto_evt_persist_client { - void *future; - struct mosquitto_client data; - void *future2[8]; -}; - - -/* Data for the MOSQ_EVT_PERSIST_SUBSCRIPTION_ADD/_DELETE event */ -/* NOTE: The persistence interface is currently marked as unstable, which means - * it may change in a future minor release. */ -struct mosquitto_evt_persist_subscription { - void *future; - struct mosquitto_subscription data; - void *future2[8]; -}; - - -/* Data for the MOSQ_EVT_PERSIST_CLIENT_MSG_ADD/_DELETE/_UPDATE event */ -/* NOTE: The persistence interface is currently marked as unstable, which means - * it may change in a future minor release. */ -struct mosquitto_evt_persist_client_msg { - void *future; - struct mosquitto_client_msg data; - void *future2[8]; -}; - - -/* Data for the MOSQ_EVT_PERSIST_BASE_MSG_ADD/_DELETE/_LOAD event */ -/* NOTE: The persistence interface is currently marked as unstable, which means - * it may change in a future minor release. */ -struct mosquitto_evt_persist_base_msg { - void *future; - struct mosquitto_base_msg data; - void *future2[8]; -}; - - -/* Data for the MOSQ_EVT_PERSIST_RETAIN_MSG_SET/_DELETE event */ -/* NOTE: The persistence interface is currently marked as unstable, which means - * it may change in a future minor release. */ -struct mosquitto_evt_persist_retain_msg { - void *future; - const char *topic; - uint64_t store_id; - void *future2[8]; -}; - - -/* Callback definition */ -typedef int (*MOSQ_FUNC_generic_callback)(int, void *, void *); - -typedef struct mosquitto_plugin_id_t mosquitto_plugin_id_t; - -/* - * Function: mosquitto_plugin_set_info - * - * Set plugin name and version information for the broker to report. It is - * recommended this is used in the mosquitto_plugin_init() call. - */ -mosq_EXPORT int mosquitto_plugin_set_info( - mosquitto_plugin_id_t *identifier, - const char *plugin_name, - const char *plugin_version); - - -/* - * Function: mosquitto_callback_register - * - * Register a callback for an event. - * - * Parameters: - * identifier - the plugin identifier, as provided by . - * event - the event to register a callback for. Can be one of: - * * MOSQ_EVT_RELOAD - * Called when the broker is sent a signal indicating it should - * reload its configuration. - * * MOSQ_EVT_ACL_CHECK - * Called when a publish/subscribe/unsubscribe command is received - * and the broker wants to check when the client is allowed to carry - * out this command. - * * MOSQ_EVT_BASIC_AUTH - * Called when a client connects to the broker, to allow the - * username/password/clientid to be authenticated. - * * MOSQ_EVT_EXT_AUTH_START - * Called when an MQTT v5 client connects, if it is using extended - * authentication. - * * MOSQ_EVT_EXT_AUTH_CONTINUE - * Called when an MQTT v5 client connects, if it is using extended - * authentication. - * * MOSQ_EVT_CONTROL - * Called on receipt of a $CONTROL message that the plugin has - * registered for. - * * MOSQ_EVT_MESSAGE_IN - * Called for each incoming PUBLISH message after it has been received - * and authorised. The contents of the message can be modified. - * * MOSQ_EVT_MESSAGE_OUT - * Called for each outgoing PUBLISH message after it has been authorised, - * but before it is sent to each subscribing client. The contents of the - * message can be modified. - * * MOSQ_EVT_PSK_KEY - * Called when a client connects with TLS-PSK and the broker needs - * the PSK information. - * * MOSQ_EVT_TICK - * Called periodically in the event loop. At the moment this - * occurs at a regular frequency, but this should not be relied - * upon. - * * MOSQ_EVT_DISCONNECT - * Called when a client disconnects from the broker. - * * MOSQ_EVT_CONNECT - * Called when a client has successfully connected to the broker, - * i.e. has been authenticated. - * * MOSQ_EVT_SUBSCRIBE - * Called when a client has made a successful subscription - * request, but before the subscription is applied. The - * subscription request can be modified, although this is not - * recommended. - * * MOSQ_EVT_UNSUBSCRIBE - * Called when a client has made a successful unsubscription - * request, but before the unsubscription is applied. The - * unsubscription request can be modified, although this is not - * recommended. - * * MOSQ_EVT_PERSIST_RESTORE - * Called on startup when a persistence plugin should restore - * persistence data. - * * MOSQ_EVT_PERSIST_BASE_MSG_ADD - * Called when a persistence plugin must add a base message to its - * store. - * * MOSQ_EVT_PERSIST_BASE_MSG_DELETE - * Called when a persistence plugin must delete a base message - * from its store. - * * MOSQ_EVT_PERSIST_RETAIN_MSG_SET - * Called when a persistence plugin must set or update a retained - * message in its store. - * * MOSQ_EVT_PERSIST_RETAIN_MSG_DELETE - * Called when a persistence plugin must delete a retained message - * from its store. - * * MOSQ_EVT_PERSIST_CLIENT_ADD - * Called when a persistence plugin must add a client session to - * its store. - * * MOSQ_EVT_PERSIST_CLIENT_DELETE - * Called when a persistence plugin must delete a client session - * from its store. - * * MOSQ_EVT_PERSIST_CLIENT_UPDATE - * Called when a persistence plugin must update a client session - * in its store. - * * MOSQ_EVT_PERSIST_SUBSCRIPTION_ADD - * Called when a persistence plugin must add a client subscription - * to its store. - * * MOSQ_EVT_PERSIST_SUBSCRIPTION_DELETE - * Called when a persistence plugin must delete a client - * subscription from its store. - * * MOSQ_EVT_PERSIST_CLIENT_MSG_ADD - * Called when a persistence plugin must add a client message to - * its store. - * * MOSQ_EVT_PERSIST_CLIENT_MSG_DELETE - * Called when a persistence plugin must delete a client message - * from its store. - * * MOSQ_EVT_PERSIST_CLIENT_MSG_UPDATE - * Called when a persistence plugin must update a client message - * in its store. - * - * cb_func - the callback function - * event_data - event specific data - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if cb_func is NULL - * MOSQ_ERR_NOMEM - on out of memory - * MOSQ_ERR_ALREADY_EXISTS - if cb_func has already been registered for this event - * MOSQ_ERR_NOT_SUPPORTED - if the event is not supported - */ -mosq_EXPORT int mosquitto_callback_register( - mosquitto_plugin_id_t *identifier, - int event, - MOSQ_FUNC_generic_callback cb_func, - const void *event_data, - void *userdata); - -/* - * Function: mosquitto_callback_unregister - * - * Unregister a previously registered callback function. - * - * Parameters: - * identifier - the plugin identifier, as provided by . - * event - the event to register a callback for. Can be one of: - * * MOSQ_EVT_RELOAD - * * MOSQ_EVT_ACL_CHECK - * * MOSQ_EVT_BASIC_AUTH - * * MOSQ_EVT_EXT_AUTH_START - * * MOSQ_EVT_EXT_AUTH_CONTINUE - * * MOSQ_EVT_CONTROL - * * MOSQ_EVT_MESSAGE_IN - * * MOSQ_EVT_MESSAGE_OUT - * * MOSQ_EVT_PSK_KEY - * * MOSQ_EVT_TICK - * * MOSQ_EVT_DISCONNECT - * * MOSQ_EVT_CONNECT - * * MOSQ_EVT_SUBSCRIBE - * * MOSQ_EVT_UNSUBSCRIBE - * * MOSQ_EVT_PERSIST_RESTORE - * * MOSQ_EVT_PERSIST_BASE_MSG_ADD - * * MOSQ_EVT_PERSIST_BASE_MSG_DELETE - * * MOSQ_EVT_PERSIST_RETAIN_MSG_SET - * * MOSQ_EVT_PERSIST_RETAIN_MSG_DELETE - * * MOSQ_EVT_PERSIST_CLIENT_ADD - * * MOSQ_EVT_PERSIST_CLIENT_DELETE - * * MOSQ_EVT_PERSIST_CLIENT_UPDATE - * * MOSQ_EVT_PERSIST_SUBSCRIPTION_ADD - * * MOSQ_EVT_PERSIST_SUBSCRIPTION_DELETE - * * MOSQ_EVT_PERSIST_CLIENT_MSG_ADD - * * MOSQ_EVT_PERSIST_CLIENT_MSG_DELETE - * * MOSQ_EVT_PERSIST_CLIENT_MSG_UPDATE - * cb_func - the callback function - * event_data - event specific data - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if cb_func is NULL - * MOSQ_ERR_NOT_FOUND - if cb_func was not registered for this event - * MOSQ_ERR_NOT_SUPPORTED - if the event is not supported - */ -mosq_EXPORT int mosquitto_callback_unregister( - mosquitto_plugin_id_t *identifier, - int event, - MOSQ_FUNC_generic_callback cb_func, - const void *event_data); - - -/* ========================================================================= - * - * Section: Memory allocation. - * - * Use these functions when allocating or freeing memory to have your memory - * included in the memory tracking on the broker. - * - * ========================================================================= */ - -/* - * Function: mosquitto_calloc - */ -mosq_EXPORT void *mosquitto_calloc(size_t nmemb, size_t size); - -/* - * Function: mosquitto_free - */ -mosq_EXPORT void mosquitto_free(void *mem); - -/* - * Function: mosquitto_malloc - */ -mosq_EXPORT void *mosquitto_malloc(size_t size); - -/* - * Function: mosquitto_realloc - */ -mosq_EXPORT void *mosquitto_realloc(void *ptr, size_t size); - -/* - * Function: mosquitto_strdup - */ -mosq_EXPORT char *mosquitto_strdup(const char *s); - -/* - * Function: mosquitto_strndup - */ -mosq_EXPORT char *mosquitto_strndup(const char *s, size_t n); - -/* ========================================================================= - * - * Section: Utility Functions - * - * Use these functions from within your plugin. - * - * ========================================================================= */ - - -/* - * Function: mosquitto_log_printf - * - * Write a log message using the broker configured logging. - * - * Parameters: - * level - Log message priority. Can currently be one of: - * - * * MOSQ_LOG_INFO - * * MOSQ_LOG_NOTICE - * * MOSQ_LOG_WARNING - * * MOSQ_LOG_ERR - * * MOSQ_LOG_DEBUG - * * MOSQ_LOG_SUBSCRIBE (not recommended for use by plugins) - * * MOSQ_LOG_UNSUBSCRIBE (not recommended for use by plugins) - * - * These values are defined in mosquitto.h. - * - * fmt, ... - printf style format and arguments. - */ -mosq_EXPORT void mosquitto_log_printf(int level, const char *fmt, ...); - - -/* ========================================================================= - * - * Client Functions - * - * Use these functions to access client information. - * - * ========================================================================= */ - -/* - * Function: mosquitto_client - * - * Retrieve the struct mosquitto for a client id, or NULL if the client is not connected. - */ -mosq_EXPORT struct mosquitto *mosquitto_client(const char *clientid); - - -/* - * Function: mosquitto_client_address - * - * Retrieve the IP address of the client as a string. - */ -mosq_EXPORT const char *mosquitto_client_address(const struct mosquitto *client); - - -/* - * Function: mosquitto_client_port - * - * Retrieve the network port number the client connected to, or 0 on error. - */ -mosq_EXPORT int mosquitto_client_port(const struct mosquitto *client); - - -/* - * Function: mosquitto_client_clean_session - * - * Retrieve the clean session flag value for a client. - */ -mosq_EXPORT bool mosquitto_client_clean_session(const struct mosquitto *client); - - -/* - * Function: mosquitto_client_id - * - * Retrieve the client id associated with a client. - */ -mosq_EXPORT const char *mosquitto_client_id(const struct mosquitto *client); - - -/* - * Function: mosquitto_client_keepalive - * - * Retrieve the keepalive value for a client. - */ -mosq_EXPORT int mosquitto_client_keepalive(const struct mosquitto *client); - - -/* - * Function: mosquitto_client_certificate - * - * If TLS support is enabled, return the certificate provided by a client as an - * X509 pointer from openssl. If the client did not provide a certificate, then - * NULL will be returned. This function will only ever return a non-NULL value - * if the `require_certificate` option is set to true. - * - * When you have finished with the x509 pointer, it must be freed using - * X509_free(). - * - * If TLS is not supported, this function will always return NULL. - */ -mosq_EXPORT void *mosquitto_client_certificate(const struct mosquitto *client); - - -/* - * Function: mosquitto_client_protocol - * - * Retrieve the protocol with which the client has connected. Can be one of: - * - * mp_mqtt (MQTT over TCP) - * mp_mqttsn (MQTT-SN) - * mp_websockets (MQTT over Websockets) - */ -mosq_EXPORT int mosquitto_client_protocol(const struct mosquitto *client); - - -/* - * Function: mosquitto_client_protocol_version - * - * Retrieve the MQTT protocol version with which the client has connected. Can be one of: - * - * Returns: - * 3 - for MQTT v3 / v3.1 - * 4 - for MQTT v3.1.1 - * 5 - for MQTT v5 - */ -mosq_EXPORT int mosquitto_client_protocol_version(const struct mosquitto *client); - - -/* - * Function: mosquitto_client_sub_count - * - * Retrieve the number of subscriptions that have been made by a client. - */ -mosq_EXPORT int mosquitto_client_sub_count(const struct mosquitto *client); - - -/* - * Function: mosquitto_client_username - * - * Retrieve the username associated with a client. - */ -mosq_EXPORT const char *mosquitto_client_username(const struct mosquitto *client); - - -/* Function: mosquitto_set_username - * - * Set the username for a client. - * - * This removes and replaces the current username for a client and hence - * updates its access. - * - * username can be NULL, in which case the client will become anonymous, but - * must not be zero length. - * - * In the case of error, the client will be left with its original username. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client is NULL, or if username is zero length - * MOSQ_ERR_NOMEM - on out of memory - */ -mosq_EXPORT int mosquitto_set_username(struct mosquitto *client, const char *username); - -/* Function: mosquitto_set_clientid - * - * Set the client id for a client. - * - * This effectively forces the client onto another message queue. - * Can be used to scope client ids by prefixing the client id with some user-specific data. - * eg. "client1" could become "user1-client1". - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client is NULL, or if clientid is not a valid utf-8 string - * MOSQ_ERR_NOMEM - on out of memory - */ -mosq_EXPORT int mosquitto_set_clientid(struct mosquitto *client, const char *clientid); - - -/* ========================================================================= - * - * Section: Client control - * - * ========================================================================= */ - -/* Function: mosquitto_kick_client_by_clientid - * - * Forcefully disconnect a client from the broker. - * - * If clientid != NULL, then the client with the matching client id is - * disconnected from the broker. - * If clientid == NULL, then all clients are disconnected from the broker. - * - * If with_will == true, then if the client has a Last Will and Testament - * defined then this will be sent. If false, the LWT will not be sent. - */ -mosq_EXPORT int mosquitto_kick_client_by_clientid(const char *clientid, bool with_will); - -/* Function: mosquitto_kick_client_by_username - * - * Forcefully disconnect a client from the broker. - * - * If username != NULL, then all clients with a matching username are kicked - * from the broker. - * If username == NULL, then all clients that do not have a username are - * kicked. - * - * If with_will == true, then if the client has a Last Will and Testament - * defined then this will be sent. If false, the LWT will not be sent. - */ -mosq_EXPORT int mosquitto_kick_client_by_username(const char *username, bool with_will); - -/* Function: mosquitto_apply_on_all_clients - * - * Apply a given functor to all clients - * - * The functor will be applied to all existing client structures. If the functor - * returns an error code the iteration over the clients will be stopped. The - * functor_context pointer maybe used to pass additional data structures into - * the functor as second argument. - * - * The result value will be the result of the last functor invoked. - */ -mosq_EXPORT int mosquitto_apply_on_all_clients(int (*FUNC_client_functor)(const struct mosquitto *, void *), void *functor_context); - -/* ========================================================================= - * - * Section: Publishing functions - * - * ========================================================================= */ - -/* Function: mosquitto_broker_publish - * - * Publish a message from within a plugin. - * - * This function allows a plugin to publish a message. Messages published in - * this way are treated as coming from the broker and so will not be passed to - * `mosquitto_auth_acl_check(, MOSQ_ACL_WRITE, , )` for checking. Read access - * will be enforced as normal for individual clients when they are due to - * receive the message. - * - * It can be used to send messages to all clients that have a matching - * subscription, or to a single client whether or not it has a matching - * subscription. - * - * Parameters: - * clientid - optional string. If set to NULL, the message is delivered to all - * clients. If non-NULL, the message is delivered only to the - * client with the corresponding client id. If the client id - * specified is not connected, the message will be dropped. - * topic - message topic - * payloadlen - payload length in bytes. Can be 0 for an empty payload. - * payload - payload bytes. If payloadlen > 0 this must not be NULL. Must - * be allocated on the heap. Will be freed by mosquitto after use if the - * function returns success. - * qos - message QoS to use. - * retain - should retain be set on the message. This does not apply if - * clientid is non-NULL. - * properties - MQTT v5 properties to attach to the message. If the function - * returns success, then properties is owned by the broker and - * will be freed at a later point. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if topic is NULL, if payloadlen < 0, if payloadlen > 0 - * and payload is NULL, if qos is not 0, 1, or 2. - * MOSQ_ERR_NOMEM - on out of memory - */ -mosq_EXPORT int mosquitto_broker_publish( - const char *clientid, - const char *topic, - int payloadlen, - void *payload, - int qos, - bool retain, - mosquitto_property *properties); - - -/* Function: mosquitto_broker_publish_copy - * - * Publish a message from within a plugin. - * - * This function is identical to mosquitto_broker_publish, except that a copy - * of `payload` is taken. - * - * Parameters: - * clientid - optional string. If set to NULL, the message is delivered to all - * clients. If non-NULL, the message is delivered only to the - * client with the corresponding client id. If the client id - * specified is not connected, the message will be dropped. - * topic - message topic - * payloadlen - payload length in bytes. Can be 0 for an empty payload. - * payload - payload bytes. If payloadlen > 0 this must not be NULL. - * Memory remains the property of the calling function. - * qos - message QoS to use. - * retain - should retain be set on the message. This does not apply if - * clientid is non-NULL. - * properties - MQTT v5 properties to attach to the message. If the function - * returns success, then properties is owned by the broker and - * will be freed at a later point. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if topic is NULL, if payloadlen < 0, if payloadlen > 0 - * and payload is NULL, if qos is not 0, 1, or 2. - * MOSQ_ERR_NOMEM - on out of memory - */ -mosq_EXPORT int mosquitto_broker_publish_copy( - const char *clientid, - const char *topic, - int payloadlen, - const void *payload, - int qos, - bool retain, - mosquitto_property *properties); - -/* Function: mosquitto_complete_basic_auth - * - * Complete a delayed authentication request. - * - * Useful for plugins that subscribe to the MOSQ_EVT_BASIC_AUTH event. If your - * plugin makes authentication requests that are not "instant", in particular - * if they communicate with an external service, then instead of blocking for a - * reply and returning MOSQ_ERR_SUCCESS or MOSQ_ERR_AUTH, the plugin can return - * MOSQ_ERR_AUTH_DELAYED. This means that the plugin is promising to tell the - * broker the authentication result in the future. Once the plugin has an - * answer, it should call `mosquitto_complete_basic_auth()` passing the client - * id and the result. - * - * Result: - * MOSQ_ERR_SUCCESS - the client successfully authenticated - * MOSQ_ERR_AUTH - the client authentication failed - * - * Other error codes can be used if more appropriate, and the client connection - * will still be rejected, e.g. MOSQ_ERR_NOMEM. - * - * The plugin may use extra threads to handle the authentication requests, but - * the call to `mosquitto_complete_basic_auth()` must happen in the main - * mosquitto thread. Using the MOSQ_EVT_TICK event for this is suggested. - */ -mosq_EXPORT void mosquitto_complete_basic_auth(const char* clientid, int result); - - -/* Function: mosquitto_broker_node_id_set - * - * Set a node ID for this broker between 0-1023 inclusive. This is used to help - * generate unique client message IDs and hence can be useful for persistence - * plugins where brokers are sharing a database. It is down to the plugin to ensure - * this ID is unique. - * - * Result: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - the value was > 1023. - */ -mosq_EXPORT int mosquitto_broker_node_id_set(uint16_t id); - - -/* ================================================================= - * - * Persistence interface - * - * ================================================================= */ - -/* NOTE: The persistence interface is currently marked as unstable, which means - * it may change in a future minor release. */ - - -/* Function: mosquitto_persist_client_add - * - * Use to add a new client session, in particular when restoring on starting - * the broker. - * - * Parameters: - * client->clientid - the client id of the client to add. - * This must be allocated on the heap and becomes the property of the - * broker immediately this call is made. Must not be NULL. - * client->username - the username for the client session, or NULL. Must - * be allocated on the heap and becomes the property of the broker - * immediately this call is made. - * client->auth_method - the MQTT v5 extended authentication method, - * or NULL. Must be allocated on the heap and becomes the property of - * the broker immediately this call is made. - * client->will_delay_time - the actual will delay time for this client - * client->session_expiry_time - the actual session expiry time for this - * client - * client->will_delay_interval - the MQTT v5 will delay interval for this - * client - * client->maximum_packet_size - the MQTT v5 maximum packet size parameter - * for this client - * client->listener_port - the listener port that this client last connected to - * client->max_qos - the MQTT v5 maximum QoS parameter for this client - * client->retain_available - the MQTT v5 retain available parameter for this - * client - * - * All other members of struct mosquitto_client are unused. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client or client->plugin_clientid is NULL, or if a - * client with the same ID already exists. - * MOSQ_ERR_NOMEM - on out of memory - */ -mosq_EXPORT int mosquitto_persist_client_add(struct mosquitto_client *client); - - -/* Function: mosquitto_persist_client_update - * - * Use to update client session parameters - * - * Parameters: - * client->clientid - the client id of the client to update - * The broker will *not* modify this string and it remains the - * property of the plugin. - * client->username - the new username for the client session, or NULL. Must - * be allocated on the heap and becomes the property of the broker - * immediately this call is made. - * client->will_delay_time - the actual will delay time for this client - * client->session_expiry_time - the actual session expiry time for this - * client - * client->will_delay_interval - the MQTT v5 will delay interval for this - * client - * client->maximum_packet_size - the MQTT v5 maximum packet size parameter - * for this client - * client->listener_port - the listener port that this client last connected to - * client->max_qos - the MQTT v5 maximum QoS parameter for this client - * client->retain_available - the MQTT v5 retain available parameter for this - * client - * - * All other members of struct mosquitto_client are unused. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client or client->clientid is NULL - * MOSQ_ERR_NOT_FOUND - the client is not found - */ -mosq_EXPORT int mosquitto_persist_client_update(struct mosquitto_client *client); - - -/* Function: mosquitto_persist_client_delete - * - * Use to delete client session for a client from the broker - * - * Parameters: - * clientid - the client id of the client to delete - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if clientid is NULL - * MOSQ_ERR_NOT_FOUND - the referenced client is not found - */ -mosq_EXPORT int mosquitto_persist_client_delete(const char *clientid); - - -/* Function: mosquitto_persist_client_msg_add - * - * Use to add a client message for a particular client. - * - * Parameters: - * client_msg->clientid - the client id of the client that the - * message belongs to. - * client_msg->cmsg_id - the ID of this client message. - * client_msg->store_id - the ID of the base message that this client - * message references. - * client_msg->subscription_identifier - the MQTT v5 subscription identifier, - * for outgoing messages only. - * client_msg->mid - the MQTT message ID of the new message - * client_msg->qos - the MQTT QoS of the new message - * client_msg->retain - the retain flag of the message - * client_msg->dup - the dup flag of the message - * client_msg->direction - the direction of the new message from the perspective - * of the broker (mosq_bmd_in / mosq_bmd_out) - * client_msg->state - the current message state - * - * All other members of struct mosquitto_client_msg are unused. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client_msg or client_msg->plugin_clientid is NULL - * MOSQ_ERR_NOT_FOUND - the client or base message is not found - */ -mosq_EXPORT int mosquitto_persist_client_msg_add(struct mosquitto_client_msg *client_msg); - - -/* Function: mosquitto_persist_client_msg_delete - * - * Use to delete a client message for a particular client. - * - * Parameters: - * client_msg->clientid - the client id of the client that the - * message belongs to. - * client_msg->cmsg_id - the client message id of the affected message - * client_msg->mid - the MQTT message id of the affected message - * client_msg->qos - the MQTT QoS of the affected message - * client_msg->direction - the direction of the message from the perspective - * of the broker (mosq_bmd_in / mosq_bmd_out) - * - * All other members of struct mosquitto_client_msg are unused. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client_msg or client_msg->clientid is NULL - * MOSQ_ERR_NOT_FOUND - the client is not found - */ -mosq_EXPORT int mosquitto_persist_client_msg_delete(struct mosquitto_client_msg *client_msg); - - -/* Function: mosquitto_persist_client_msg_update - * - * Use to update the state of a client message for a particular client. - * - * Parameters: - * client_msg->clientid - the client id of the client that the - * message belongs to. - * client_msg->cmsg_id - the client message id of the affected message - * client_msg->mid - the MQTT message id of the affected message - * client_msg->qos - the MQTT QoS of the affected message - * client_msg->direction - the direction of the message from the perspective - * of the broker (mosq_bmd_in / mosq_bmd_out) - * client_msg->state - the new state of the message - * - * All other members of struct mosquitto_client_msg are unused. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client_msg or client_msg->clientid is NULL - * MOSQ_ERR_NOT_FOUND - the client is not found - */ -mosq_EXPORT int mosquitto_persist_client_msg_update(struct mosquitto_client_msg *client_msg); - - -/* Function: mosquitto_persist_client_msg_clear - * - * Clear all messages for the listed client and direction. - * - * Parameters: - * client_msg->clientid - the client id of the client that the - * message belongs to. - * client_msg->direction - the direction of the messages to be cleared, from - * the perspective of the broker (mosq_bmd_in / mosq_bmd_out / mosq_bmd_all) - * - * All other members of struct mosquitto_client_msg are unused. - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client_msg or client_msg->clientid is NULL - * MOSQ_ERR_NOT_FOUND - the client is not found - */ -mosq_EXPORT int mosquitto_persist_client_msg_clear(struct mosquitto_client_msg *client_msg); - -/* Function: mosquitto_persist_base_msg_add - * - * Use to add a new base message. Any client messages or retained messages - * refering to this base message must be added afterwards. - * - * Parameters: - * msg->store_id - the base message ID - * msg->expiry_time - the time at which the message expires, or 0. - * msg->topic - the message topic. - * Must be allocated on the heap and becomes the property of the - * broker immediately this call is made. - * msg->payload - the message payload. - * Must be allocated on the heap and becomes the property of the - * broker immediately this call is made. - * msg->source_id - the client id of the client that the - * message originated with, or NULL. - * The broker will *not* modify this string and it remains the - * property of the plugin. - * msg->source_username - the username of the client that the - * message originated with, or NULL. - * The broker will *not* modify this string and it remains the - * property of the plugin. - * msg->properties - list of MQTT v5 message properties for this message. - * Must be allocated on the heap and becomes the property of the - * broker immediately this call is made. - * msg->payloadlen - the length of the payload, in bytes - * msg->source_mid - the mid of the source message - * msg->source_port - the network port number that the originating client was - * connected to, or 0. - * msg->qos - the message QoS as delivered to the broker - * msg->retain - the message retain flag as delivered to the broker - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_NOMEM - on out of memory - */ -mosq_EXPORT int mosquitto_persist_base_msg_add(struct mosquitto_base_msg *msg); - - -/* Function: mosquitto_persist_base_msg_delete - * - * Use to delete a base message. - * - * Parameters: - * store_id - the base message ID - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - */ -mosq_EXPORT int mosquitto_persist_base_msg_delete(uint64_t store_id); - - -/* Function: mosquitto_persist_subscription_add - * - * Use to add a new subscription for a client - * - * Parameters: - * sub->clientid - the client id of the client the new subscription is for - * sub->topic_filter - the topic filter for the subscription - * sub->options - the QoS and other flags for this subscription - * sub->identifier - the MQTT v5 subscription id, or 0 - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if sub, clientid, or topic_filter are NULL, or are zero length - * MOSQ_ERR_NOT_FOUND - the referenced client was not found - * MOSQ_ERR_NOMEM - on out of memory - */ -mosq_EXPORT int mosquitto_subscription_add(const struct mosquitto_subscription *sub); - - -/* Function: mosquitto_persist_subscription_delete - * - * Use to delete a subscription for a client - * - * Parameters: - * clientid - the client id of the client the new subscription is for - * topic_filter - the topic filter for the subscription - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if clientid or topic are NULL, or are zero length - * MOSQ_ERR_NOT_FOUND - the referenced client was not found - * MOSQ_ERR_NOMEM - on out of memory - */ -mosq_EXPORT int mosquitto_subscription_delete(const char *clientid, const char *topic_filter); - - -/* Function: mosquitto_persist_retain_msg_set - * - * Use to set a retained message. It is not required to delete a retained - * message for an existing topic first. - * - * Parameters: - * topic - the topic that the message references - * store_id - the ID of the base message that is to be retained - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if topic is NULL - * MOSQ_ERR_NOT_FOUND - the referenced base message was not found - * MOSQ_ERR_NOMEM - on out of memory - */ -mosq_EXPORT int mosquitto_persist_retain_msg_set(const char *topic, uint64_t store_id); - - -/* Function: mosquitto_persist_retain_msg_delete - * - * Use to delete a retained message. - * - * Parameters: - * topic - the topic that the message references - * - * Returns: - * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if topic is NULL - * MOSQ_ERR_NOMEM - on out of memory - */ -mosq_EXPORT int mosquitto_persist_retain_msg_delete(const char *topic); - -/* Function: mosquitto_persistence_location - * - * Returns the `persistence_location` config option, or the contents of the - * MOSQUITTO_PERSISTENCE_LOCATION environment variable, if set. - * - * This location should be used by plugins needing to store persistent data. - * Use of sub directories is recommended. - * - * Returns: - * A valid pointer to the persistence location string - * A NULL pointer if neither the option nor the variable are set - */ -mosq_EXPORT const char *mosquitto_persistence_location(void); - -#ifdef __cplusplus -} -#endif -#endif +#include +#warning "Please replace '#include with #include " diff --git a/include/mosquitto_plugin.h b/include/mosquitto_plugin.h index 38c59a3c..ae80b3e7 100644 --- a/include/mosquitto_plugin.h +++ b/include/mosquitto_plugin.h @@ -1,441 +1,2 @@ -/* -Copyright (c) 2012-2021 Roger Light - -All rights reserved. This program and the accompanying materials -are made available under the terms of the Eclipse Public License 2.0 -and Eclipse Distribution License v1.0 which accompany this distribution. - -The Eclipse Public License is available at - https://www.eclipse.org/legal/epl-2.0/ -and the Eclipse Distribution License is available at - http://www.eclipse.org/org/documents/edl-v10.php. - -SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause - -Contributors: - Roger Light - initial implementation and documentation. -*/ - -#ifndef MOSQUITTO_PLUGIN_H -#define MOSQUITTO_PLUGIN_H - -/* - * File: mosquitto_plugin.h - * - * This header contains function declarations for use when writing a Mosquitto plugin. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* The generic plugin interface starts at version 5 */ -#define MOSQ_PLUGIN_VERSION 5 - -/* The old auth only interface stopped at version 4 */ -#define MOSQ_AUTH_PLUGIN_VERSION 4 - -#define MOSQ_ACL_NONE 0x00 -#define MOSQ_ACL_READ 0x01 -#define MOSQ_ACL_WRITE 0x02 -#define MOSQ_ACL_SUBSCRIBE 0x04 -#define MOSQ_ACL_UNSUBSCRIBE 0x08 - -#include -#include - -#include -#include - -struct mosquitto; - -struct mosquitto_opt { - char *key; - char *value; -}; - -struct mosquitto_auth_opt { - char *key; - char *value; -}; - -struct mosquitto_acl_msg { - const char *topic; - const void *payload; - long payloadlen; - int qos; - bool retain; -}; - -#ifdef WIN32 -# define mosq_plugin_EXPORT __declspec(dllexport) -#else -# define mosq_plugin_EXPORT -#endif - -/* - * To create an authentication plugin you must include this file then implement - * the functions listed in the "Plugin Functions" section below. The resulting - * code should then be compiled as a shared library. Using gcc this can be - * achieved as follows: - * - * gcc -I -fPIC -shared plugin.c -o plugin.so - * - * On Mac OS X: - * - * gcc -I -fPIC -shared plugin.c -undefined dynamic_lookup -o plugin.so - * - */ - -/* ========================================================================= - * - * Helper Functions - * - * ========================================================================= */ - -/* There are functions that are available for plugin developers to use in - * mosquitto_broker.h, including logging and accessor functions. - */ - - -/* ========================================================================= - * - * Section: Plugin Functions v5 - * - * This is the plugin version 5 interface, which covers authentication, access - * control, the $CONTROL topic space handling, and message inspection and - * modification. - * - * This interface is available from v2.0 onwards. - * - * There are just three functions to implement in your plugin. You should - * register callbacks to handle different events in your - * mosquitto_plugin_init() function. See mosquitto_broker.h for the events and - * callback registering functions. - * - * ========================================================================= */ - -/* - * Function: mosquitto_plugin_version - * - * The broker will attempt to call this function immediately after loading the - * plugin to check it is a supported plugin version. Your code must simply - * return the plugin interface version you support, i.e. 5. - * - * The supported_versions array tells you which plugin versions the broker supports. - * - * If the broker does not support the version that you require, return -1 to - * indicate failure. - * - * HELPER: If you only wish to declare support for a single version, you can - * use the helper macro: - * - * MOSQUITTO_PLUGIN_DECLARE_VERSION(5); - */ -mosq_plugin_EXPORT int mosquitto_plugin_version(int supported_version_count, const int *supported_versions); - -#define MOSQUITTO_PLUGIN_DECLARE_VERSION(A) \ - int mosquitto_plugin_version(int supported_version_count, const int *supported_versions) \ - { \ - int i; \ - for(i=0; i - * has been called. This will only ever be called once and can be used to - * initialise the plugin. - * - * Parameters: - * - * identifier - This is a pointer to an opaque structure which you must - * save and use when registering/unregistering callbacks. - * user_data - The pointer set here will be passed to the other plugin - * functions. Use to hold connection information for example. - * opts - Pointer to an array of struct mosquitto_opt, which - * provides the plugin options defined in the configuration file. - * opt_count - The number of elements in the opts array. - * - * Return value: - * Return 0 on success - * Return >0 on failure. - */ -mosq_plugin_EXPORT int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **userdata, struct mosquitto_opt *options, int option_count); - - -/* - * Function: mosquitto_plugin_cleanup - * - * Called when the broker is shutting down. This will only ever be called once - * per plugin. - * - * If you do not need to do any of your own cleanup, this function is not - * required. The broker will automatically unregister your callbacks. - * - * Parameters: - * - * user_data - The pointer provided in . - * opts - Pointer to an array of struct mosquitto_opt, which - * provides the plugin options defined in the configuration file. - * opt_count - The number of elements in the opts array. - * - * Return value: - * Return 0 on success - * Return >0 on failure. - */ -mosq_plugin_EXPORT int mosquitto_plugin_cleanup(void *userdata, struct mosquitto_opt *options, int option_count); - - - -/* ========================================================================= - * - * Section: Plugin Functions v4 - * - * This is the plugin version 4 interface, which is exclusively for - * authentication and access control, and which is still supported for existing - * plugins. If you are developing a new plugin, please use the v5 interface. - * - * You must implement these functions in your plugin. - * - * Authentication plugins can implement one or both of authentication and - * access control. If your plugin does not wish to handle either of - * authentication or access control it should return MOSQ_ERR_PLUGIN_DEFER. In - * this case, the next plugin will handle it. If all plugins return - * MOSQ_ERR_PLUGIN_DEFER, the request will be denied. - * - * For each check, the following flow happens: - * - * * The default password file and/or acl file checks are made. If either one - * of these is not defined, then they are considered to be deferred. If either - * one accepts the check, no further checks are made. If an error occurs, the - * check is denied - * * The first plugin does the check, if it returns anything other than - * MOSQ_ERR_PLUGIN_DEFER, then the check returns immediately. If the plugin - * returns MOSQ_ERR_PLUGIN_DEFER then the next plugin runs its check. - * * If the final plugin returns MOSQ_ERR_PLUGIN_DEFER, then access will be - * denied. - * ========================================================================= */ - -/* - * Function: mosquitto_auth_plugin_version - * - * The broker will call this function immediately after loading the plugin to - * check it is a supported plugin version. Your code must simply return - * the version of the plugin interface you support, i.e. 4. - */ -mosq_plugin_EXPORT int mosquitto_auth_plugin_version(void); - - -/* - * Function: mosquitto_auth_plugin_init - * - * Called after the plugin has been loaded and - * has been called. This will only ever be called once and can be used to - * initialise the plugin. - * - * Parameters: - * - * user_data - The pointer set here will be passed to the other plugin - * functions. Use to hold connection information for example. - * opts - Pointer to an array of struct mosquitto_opt, which - * provides the plugin options defined in the configuration file. - * opt_count - The number of elements in the opts array. - * - * Return value: - * Return 0 on success - * Return >0 on failure. - */ -mosq_plugin_EXPORT int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *opts, int opt_count); - - -/* - * Function: mosquitto_auth_plugin_cleanup - * - * Called when the broker is shutting down. This will only ever be called once - * per plugin. - * Note that will be called directly before - * this function. - * - * Parameters: - * - * user_data - The pointer provided in . - * opts - Pointer to an array of struct mosquitto_opt, which - * provides the plugin options defined in the configuration file. - * opt_count - The number of elements in the opts array. - * - * Return value: - * Return 0 on success - * Return >0 on failure. - */ -mosq_plugin_EXPORT int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count); - - -/* - * Function: mosquitto_auth_security_init - * - * This function is called in two scenarios: - * - * 1. When the broker starts up. - * 2. If the broker is requested to reload its configuration whilst running. In - * this case, will be called first, then - * this function will be called. In this situation, the reload parameter - * will be true. - * - * Parameters: - * - * user_data - The pointer provided in . - * opts - Pointer to an array of struct mosquitto_opt, which - * provides the plugin options defined in the configuration file. - * opt_count - The number of elements in the opts array. - * reload - If set to false, this is the first time the function has - * been called. If true, the broker has received a signal - * asking to reload its configuration. - * - * Return value: - * Return 0 on success - * Return >0 on failure. - */ -mosq_plugin_EXPORT int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *opts, int opt_count, bool reload); - - -/* - * Function: mosquitto_auth_security_cleanup - * - * This function is called in two scenarios: - * - * 1. When the broker is shutting down. - * 2. If the broker is requested to reload its configuration whilst running. In - * this case, this function will be called, followed by - * . In this situation, the reload parameter - * will be true. - * - * Parameters: - * - * user_data - The pointer provided in . - * opts - Pointer to an array of struct mosquitto_opt, which - * provides the plugin options defined in the configuration file. - * opt_count - The number of elements in the opts array. - * reload - If set to false, this is the first time the function has - * been called. If true, the broker has received a signal - * asking to reload its configuration. - * - * Return value: - * Return 0 on success - * Return >0 on failure. - */ -mosq_plugin_EXPORT int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count, bool reload); - - -/* - * Function: mosquitto_auth_acl_check - * - * Called by the broker when topic access must be checked. access will be one - * of: - * MOSQ_ACL_SUBSCRIBE when a client is asking to subscribe to a topic string. - * This differs from MOSQ_ACL_READ in that it allows you to - * deny access to topic strings rather than by pattern. For - * example, you may use MOSQ_ACL_SUBSCRIBE to deny - * subscriptions to '#', but allow all topics in - * MOSQ_ACL_READ. This allows clients to subscribe to any - * topic they want, but not discover what topics are in use - * on the server. - * MOSQ_ACL_READ when a message is about to be sent to a client (i.e. whether - * it can read that topic or not). - * MOSQ_ACL_WRITE when a message has been received from a client (i.e. whether - * it can write to that topic or not). - * - * Return: - * MOSQ_ERR_SUCCESS if access was granted. - * MOSQ_ERR_ACL_DENIED if access was not granted. - * MOSQ_ERR_UNKNOWN for an application specific error. - * MOSQ_ERR_PLUGIN_DEFER if your plugin does not wish to handle this check. - */ -mosq_plugin_EXPORT int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *client, const struct mosquitto_acl_msg *msg); - - -/* - * Function: mosquitto_auth_unpwd_check - * - * This function is OPTIONAL. Only include this function in your plugin if you - * are making basic username/password checks. - * - * Called by the broker when a username/password must be checked. - * - * Return: - * MOSQ_ERR_SUCCESS if the user is authenticated. - * MOSQ_ERR_AUTH if authentication failed. - * MOSQ_ERR_UNKNOWN for an application specific error. - * MOSQ_ERR_PLUGIN_DEFER if your plugin does not wish to handle this check. - */ -mosq_plugin_EXPORT int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const char *username, const char *password); - - -/* - * Function: mosquitto_psk_key_get - * - * This function is OPTIONAL. Only include this function in your plugin if you - * are making TLS-PSK checks. - * - * Called by the broker when a client connects to a listener using TLS/PSK. - * This is used to retrieve the pre-shared-key associated with a client - * identity. - * - * Examine hint and identity to determine the required PSK (which must be a - * hexadecimal string with no leading "0x") and copy this string into key. - * - * Parameters: - * user_data - the pointer provided in . - * hint - the psk_hint for the listener the client is connecting to. - * identity - the identity string provided by the client - * key - a string where the hex PSK should be copied - * max_key_len - the size of key - * - * Return value: - * Return 0 on success. - * Return >0 on failure. - * Return MOSQ_ERR_PLUGIN_DEFER if your plugin does not wish to handle this check. - */ -mosq_plugin_EXPORT int mosquitto_auth_psk_key_get(void *user_data, struct mosquitto *client, const char *hint, const char *identity, char *key, int max_key_len); - -/* - * Function: mosquitto_auth_start - * - * This function is OPTIONAL. Only include this function in your plugin if you - * are making extended authentication checks. - * - * Parameters: - * user_data - the pointer provided in . - * method - the authentication method - * reauth - this is set to false if this is the first authentication attempt - * on a connection, set to true if the client is attempting to - * reauthenticate. - * data_in - pointer to authentication data, or NULL - * data_in_len - length of data_in, in bytes - * data_out - if your plugin wishes to send authentication data back to the - * client, allocate some memory using malloc or friends and set - * data_out. The broker will free the memory after use. - * data_out_len - Set the length of data_out in bytes. - * - * Return value: - * Return MOSQ_ERR_SUCCESS if authentication was successful. - * Return MOSQ_ERR_AUTH_CONTINUE if the authentication is a multi step process and can continue. - * Return MOSQ_ERR_AUTH if authentication was valid but did not succeed. - * Return any other relevant positive integer MOSQ_ERR_* to produce an error. - */ -mosq_plugin_EXPORT int mosquitto_auth_start(void *user_data, struct mosquitto *client, const char *method, bool reauth, const void *data_in, uint16_t data_in_len, void **data_out, uint16_t *data_out_len); - -mosq_plugin_EXPORT int mosquitto_auth_continue(void *user_data, struct mosquitto *client, const char *method, const void *data_in, uint16_t data_in_len, void **data_out, uint16_t *data_out_len); - - -#ifdef __cplusplus -} -#endif - -#endif +#include +#warning "Please replace '#include with #include " diff --git a/include/mosquittopp.h b/include/mosquittopp.h index a71db242..43e29c7c 100644 --- a/include/mosquittopp.h +++ b/include/mosquittopp.h @@ -1,162 +1,2 @@ -/* -Copyright (c) 2010-2021 Roger Light - -All rights reserved. This program and the accompanying materials -are made available under the terms of the Eclipse Public License 2.0 -and Eclipse Distribution License v1.0 which accompany this distribution. - -The Eclipse Public License is available at - https://www.eclipse.org/legal/epl-2.0/ -and the Eclipse Distribution License is available at - http://www.eclipse.org/org/documents/edl-v10.php. - -Contributors: - Roger Light - initial implementation and documentation. -*/ - -#ifndef MOSQUITTOPP_H -#define MOSQUITTOPP_H - -#if defined(_WIN32) && !defined(LIBMOSQUITTO_STATIC) -# ifdef mosquittopp_EXPORTS -# define mosqpp_EXPORT __declspec(dllexport) -# else -# define mosqpp_EXPORT __declspec(dllimport) -# endif -#else -# define mosqpp_EXPORT -#endif - -#include -#include -#include - -namespace mosqpp { - - -mosqpp_EXPORT const char * strerror(int mosq_errno); -mosqpp_EXPORT const char * connack_string(int connack_code); -mosqpp_EXPORT const char * reason_string(int reason_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 int topic_matches_sub_with_pattern(const char *sub, const char *topic, const char *clientid, const char *username, bool *result); -mosqpp_EXPORT int sub_matches_acl(const char *acl, const char *sub, bool *result); -mosqpp_EXPORT int sub_matches_acl_with_pattern(const char *acl, const char *sub, const char *clientid, const char *username, bool *result); -mosqpp_EXPORT int validate_utf8(const char *str, int len); -mosqpp_EXPORT int subscribe_simple( - struct mosquitto_message **messages, - int msg_count, - bool retained, - const char *topic, - int qos=0, - const char *host="localhost", - int port=1883, - const char *clientid=NULL, - int keepalive=60, - bool clean_session=true, - const char *username=NULL, - const char *password=NULL, - const struct libmosquitto_will *will=NULL, - const struct libmosquitto_tls *tls=NULL); - -mosqpp_EXPORT int subscribe_callback( - int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *), - void *userdata, - const char *topic, - int qos=0, - const char *host="localhost", - int port=1883, - const char *clientid=NULL, - int keepalive=60, - bool clean_session=true, - const char *username=NULL, - const char *password=NULL, - const struct libmosquitto_will *will=NULL, - const struct libmosquitto_tls *tls=NULL); - -mosqpp_EXPORT int property_check_command(int command, int identifier); -mosqpp_EXPORT int property_check_all(int command, const mosquitto_property *properties); - -/* - * 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); - virtual ~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_set_v5(const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false, mosquitto_property *properties=NULL); - 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(const char *host, int port, int keepalive, const char *bind_address); - int connect_v5(const char *host, int port, int keepalive, const char *bind_address, const mosquitto_property *properties); - int connect_async(const char *host, int port=1883, int keepalive=60); - int connect_async(const char *host, int port, int keepalive, const char *bind_address); - int reconnect(); - int reconnect_async(); - int disconnect(); - int disconnect_v5(int reason_code, const mosquitto_property *properties); - int publish(int *mid, const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false); - int publish_v5(int *mid, const char *topic, int payloadlen=0, const void *payload=NULL, int qos=0, bool retain=false, const mosquitto_property *properties=NULL); - int subscribe(int *mid, const char *sub, int qos=0); - int subscribe_v5(int *mid, const char *sub, int qos=0, int options=0, const mosquitto_property *properties=NULL); - int unsubscribe(int *mid, const char *sub); - int unsubscribe_v5(int *mid, const char *sub, const mosquitto_property *properties); - 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 opts_set(enum mosq_opt_t option, void *value); - int int_option(enum mosq_opt_t option, int value); - int string_option(enum mosq_opt_t option, const char *value); - int void_option(enum mosq_opt_t option, void *value); - - 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 threaded_set(bool threaded=true); - int socks5_set(const char *host, int port=1080, const char *username=NULL, const char *password=NULL); - - // names in the functions commented to prevent unused parameter warning - virtual void on_pre_connect() {return;} - virtual void on_connect(int /*rc*/) {return;} - virtual void on_connect_with_flags(int /*rc*/, int /*flags*/) {return;} - virtual void on_connect_v5(int /*rc*/, int /*flags*/, const mosquitto_property * /*props*/) {return;} - virtual void on_disconnect(int /*rc*/) {return;} - virtual void on_disconnect_v5(int /*rc*/, const mosquitto_property * /*props*/) {return;} - virtual void on_publish(int /*mid*/) {return;} - virtual void on_publish_v5(int /*mid*/, int /*reason_code*/, const mosquitto_property * /*props*/) {return;} - virtual void on_message(const struct mosquitto_message * /*message*/) {return;} - virtual void on_message_v5(const struct mosquitto_message * /*message*/, const mosquitto_property * /*props*/) {return;} - virtual void on_subscribe(int /*mid*/, int /*qos_count*/, const int * /*granted_qos*/) {return;} - virtual void on_subscribe_v5(int /*mid*/, int /*qos_count*/, const int * /*granted_qos*/, const mosquitto_property * /*props*/) {return;} - virtual void on_unsubscribe(int /*mid*/) {return;} - virtual void on_unsubscribe_v5(int /*mid*/, const mosquitto_property * /*props*/) {return;} - virtual void on_log(int /*level*/, const char * /*str*/) {return;} - virtual void on_error() {return;} -}; - -} -#endif +#include +#warning "Please replace '#include with #include " diff --git a/include/mqtt_protocol.h b/include/mqtt_protocol.h index 94c708aa..1925b865 100644 --- a/include/mqtt_protocol.h +++ b/include/mqtt_protocol.h @@ -1,292 +1,2 @@ -/* -Copyright (c) 2009-2021 Roger Light - -All rights reserved. This program and the accompanying materials -are made available under the terms of the Eclipse Public License 2.0 -and Eclipse Distribution License v1.0 which accompany this distribution. - -The Eclipse Public License is available at - https://www.eclipse.org/legal/epl-2.0/ -and the Eclipse Distribution License is available at - http://www.eclipse.org/org/documents/edl-v10.php. - -SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause - -Contributors: - Roger Light - initial implementation and documentation. -*/ - -#ifndef MQTT_PROTOCOL_H -#define MQTT_PROTOCOL_H - -/* - * File: mqtt_protocol.h - * - * This header contains definitions of MQTT values as defined in the specifications. - */ -#define PROTOCOL_NAME_v31 "MQIsdp" -#define PROTOCOL_VERSION_v31 3 - -#define PROTOCOL_NAME "MQTT" - -#define PROTOCOL_VERSION_v311 4 -#define PROTOCOL_VERSION_v5 5 - - -/* Message types */ -#define CMD_CONNECT 0x10U -#define CMD_CONNACK 0x20U -#define CMD_PUBLISH 0x30U -#define CMD_PUBACK 0x40U -#define CMD_PUBREC 0x50U -#define CMD_PUBREL 0x60U -#define CMD_PUBCOMP 0x70U -#define CMD_SUBSCRIBE 0x80U -#define CMD_SUBACK 0x90U -#define CMD_UNSUBSCRIBE 0xA0U -#define CMD_UNSUBACK 0xB0U -#define CMD_PINGREQ 0xC0U -#define CMD_PINGRESP 0xD0U -#define CMD_DISCONNECT 0xE0U -#define CMD_AUTH 0xF0U - -/* Mosquitto only: for distinguishing CONNECT and WILL properties */ -#define CMD_WILL 0x100 - -/* Enum: mqtt311_connack_codes - * - * The CONNACK results for MQTT v3.1.1, and v3.1. - * - * Values: - * CONNACK_ACCEPTED - 0 - * CONNACK_REFUSED_PROTOCOL_VERSION - 1 - * CONNACK_REFUSED_IDENTIFIER_REJECTED - 2 - * CONNACK_REFUSED_SERVER_UNAVAILABLE - 3 - * CONNACK_REFUSED_BAD_USERNAME_PASSWORD - 4 - * CONNACK_REFUSED_NOT_AUTHORIZED - 5 - */ -enum mqtt311_connack_codes { - CONNACK_ACCEPTED = 0, - CONNACK_REFUSED_PROTOCOL_VERSION = 1, - CONNACK_REFUSED_IDENTIFIER_REJECTED = 2, - CONNACK_REFUSED_SERVER_UNAVAILABLE = 3, - CONNACK_REFUSED_BAD_USERNAME_PASSWORD = 4, - CONNACK_REFUSED_NOT_AUTHORIZED = 5, -}; - -/* Enum: mqtt5_return_codes - * The reason codes returned in various MQTT commands. - * - * Values: - * MQTT_RC_SUCCESS - 0 - * MQTT_RC_NORMAL_DISCONNECTION - 0 - * MQTT_RC_GRANTED_QOS0 - 0 - * MQTT_RC_GRANTED_QOS1 - 1 - * MQTT_RC_GRANTED_QOS2 - 2 - * MQTT_RC_DISCONNECT_WITH_WILL_MSG - 4 - * MQTT_RC_NO_MATCHING_SUBSCRIBERS - 16 - * MQTT_RC_NO_SUBSCRIPTION_EXISTED - 17 - * MQTT_RC_CONTINUE_AUTHENTICATION - 24 - * MQTT_RC_REAUTHENTICATE - 25 - * MQTT_RC_UNSPECIFIED - 128 - * MQTT_RC_MALFORMED_PACKET - 129 - * MQTT_RC_PROTOCOL_ERROR - 130 - * MQTT_RC_IMPLEMENTATION_SPECIFIC - 131 - * MQTT_RC_UNSUPPORTED_PROTOCOL_VERSION - 132 - * MQTT_RC_CLIENTID_NOT_VALID - 133 - * MQTT_RC_BAD_USERNAME_OR_PASSWORD - 134 - * MQTT_RC_NOT_AUTHORIZED - 135 - * MQTT_RC_SERVER_UNAVAILABLE - 136 - * MQTT_RC_SERVER_BUSY - 137 - * MQTT_RC_BANNED - 138 - * MQTT_RC_SERVER_SHUTTING_DOWN - 139 - * MQTT_RC_BAD_AUTHENTICATION_METHOD - 140 - * MQTT_RC_KEEP_ALIVE_TIMEOUT - 141 - * MQTT_RC_SESSION_TAKEN_OVER - 142 - * MQTT_RC_TOPIC_FILTER_INVALID - 143 - * MQTT_RC_TOPIC_NAME_INVALID - 144 - * MQTT_RC_PACKET_ID_IN_USE - 145 - * MQTT_RC_PACKET_ID_NOT_FOUND - 146 - * MQTT_RC_RECEIVE_MAXIMUM_EXCEEDED - 147 - * MQTT_RC_TOPIC_ALIAS_INVALID - 148 - * MQTT_RC_PACKET_TOO_LARGE - 149 - * MQTT_RC_MESSAGE_RATE_TOO_HIGH - 150 - * MQTT_RC_QUOTA_EXCEEDED - 151 - * MQTT_RC_ADMINISTRATIVE_ACTION - 152 - * MQTT_RC_PAYLOAD_FORMAT_INVALID - 153 - * MQTT_RC_RETAIN_NOT_SUPPORTED - 154 - * MQTT_RC_QOS_NOT_SUPPORTED - 155 - * MQTT_RC_USE_ANOTHER_SERVER - 156 - * MQTT_RC_SERVER_MOVED - 157 - * MQTT_RC_SHARED_SUBS_NOT_SUPPORTED - 158 - * MQTT_RC_CONNECTION_RATE_EXCEEDED - 159 - * MQTT_RC_MAXIMUM_CONNECT_TIME - 160 - * MQTT_RC_SUBSCRIPTION_IDS_NOT_SUPPORTED - 161 - * MQTT_RC_WILDCARD_SUBS_NOT_SUPPORTED - 162 - */ -enum mqtt5_return_codes { - MQTT_RC_SUCCESS = 0, /* CONNACK, PUBACK, PUBREC, PUBREL, PUBCOMP, UNSUBACK, AUTH */ - MQTT_RC_NORMAL_DISCONNECTION = 0, /* DISCONNECT */ - MQTT_RC_GRANTED_QOS0 = 0, /* SUBACK */ - MQTT_RC_GRANTED_QOS1 = 1, /* SUBACK */ - MQTT_RC_GRANTED_QOS2 = 2, /* SUBACK */ - MQTT_RC_DISCONNECT_WITH_WILL_MSG = 4, /* DISCONNECT */ - MQTT_RC_NO_MATCHING_SUBSCRIBERS = 16, /* PUBACK, PUBREC */ - MQTT_RC_NO_SUBSCRIPTION_EXISTED = 17, /* UNSUBACK */ - MQTT_RC_CONTINUE_AUTHENTICATION = 24, /* AUTH */ - MQTT_RC_REAUTHENTICATE = 25, /* AUTH */ - - MQTT_RC_UNSPECIFIED = 128, /* CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, DISCONNECT */ - MQTT_RC_MALFORMED_PACKET = 129, /* CONNACK, DISCONNECT */ - MQTT_RC_PROTOCOL_ERROR = 130, /* DISCONNECT */ - MQTT_RC_IMPLEMENTATION_SPECIFIC = 131, /* CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, DISCONNECT */ - MQTT_RC_UNSUPPORTED_PROTOCOL_VERSION = 132, /* CONNACK */ - MQTT_RC_CLIENTID_NOT_VALID = 133, /* CONNACK */ - MQTT_RC_BAD_USERNAME_OR_PASSWORD = 134, /* CONNACK */ - MQTT_RC_NOT_AUTHORIZED = 135, /* CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, DISCONNECT */ - MQTT_RC_SERVER_UNAVAILABLE = 136, /* CONNACK */ - MQTT_RC_SERVER_BUSY = 137, /* CONNACK, DISCONNECT */ - MQTT_RC_BANNED = 138, /* CONNACK */ - MQTT_RC_SERVER_SHUTTING_DOWN = 139, /* DISCONNECT */ - MQTT_RC_BAD_AUTHENTICATION_METHOD = 140, /* CONNACK */ - MQTT_RC_KEEP_ALIVE_TIMEOUT = 141, /* DISCONNECT */ - MQTT_RC_SESSION_TAKEN_OVER = 142, /* DISCONNECT */ - MQTT_RC_TOPIC_FILTER_INVALID = 143, /* SUBACK, UNSUBACK, DISCONNECT */ - MQTT_RC_TOPIC_NAME_INVALID = 144, /* CONNACK, PUBACK, PUBREC, DISCONNECT */ - MQTT_RC_PACKET_ID_IN_USE = 145, /* PUBACK, SUBACK, UNSUBACK */ - MQTT_RC_PACKET_ID_NOT_FOUND = 146, /* PUBREL, PUBCOMP */ - MQTT_RC_RECEIVE_MAXIMUM_EXCEEDED = 147, /* DISCONNECT */ - MQTT_RC_TOPIC_ALIAS_INVALID = 148, /* DISCONNECT */ - MQTT_RC_PACKET_TOO_LARGE = 149, /* CONNACK, PUBACK, PUBREC, DISCONNECT */ - MQTT_RC_MESSAGE_RATE_TOO_HIGH = 150, /* DISCONNECT */ - MQTT_RC_QUOTA_EXCEEDED = 151, /* PUBACK, PUBREC, SUBACK, DISCONNECT */ - MQTT_RC_ADMINISTRATIVE_ACTION = 152, /* DISCONNECT */ - MQTT_RC_PAYLOAD_FORMAT_INVALID = 153, /* CONNACK, DISCONNECT */ - MQTT_RC_RETAIN_NOT_SUPPORTED = 154, /* CONNACK, DISCONNECT */ - MQTT_RC_QOS_NOT_SUPPORTED = 155, /* CONNACK, DISCONNECT */ - MQTT_RC_USE_ANOTHER_SERVER = 156, /* CONNACK, DISCONNECT */ - MQTT_RC_SERVER_MOVED = 157, /* CONNACK, DISCONNECT */ - MQTT_RC_SHARED_SUBS_NOT_SUPPORTED = 158, /* SUBACK, DISCONNECT */ - MQTT_RC_CONNECTION_RATE_EXCEEDED = 159, /* CONNACK, DISCONNECT */ - MQTT_RC_MAXIMUM_CONNECT_TIME = 160, /* DISCONNECT */ - MQTT_RC_SUBSCRIPTION_IDS_NOT_SUPPORTED = 161, /* SUBACK, DISCONNECT */ - MQTT_RC_WILDCARD_SUBS_NOT_SUPPORTED = 162, /* SUBACK, DISCONNECT */ -}; - -/* Enum: mqtt5_property - * Options for use with MQTTv5 properties. - * Options: - * - * MQTT_PROP_PAYLOAD_FORMAT_INDICATOR - property option. - * MQTT_PROP_MESSAGE_EXPIRY_INTERVAL - property option. - * MQTT_PROP_CONTENT_TYPE - property option. - * MQTT_PROP_RESPONSE_TOPIC - property option. - * MQTT_PROP_CORRELATION_DATA - property option. - * MQTT_PROP_SUBSCRIPTION_IDENTIFIER - property option. - * MQTT_PROP_SESSION_EXPIRY_INTERVAL - property option. - * MQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER - property option. - * MQTT_PROP_SERVER_KEEP_ALIVE - property option. - * MQTT_PROP_AUTHENTICATION_METHOD - property option. - * MQTT_PROP_AUTHENTICATION_DATA - property option. - * MQTT_PROP_REQUEST_PROBLEM_INFORMATION - property option. - * MQTT_PROP_WILL_DELAY_INTERVAL - property option. - * MQTT_PROP_REQUEST_RESPONSE_INFORMATION - property option. - * MQTT_PROP_RESPONSE_INFORMATION - property option. - * MQTT_PROP_SERVER_REFERENCE - property option. - * MQTT_PROP_REASON_STRING - property option. - * MQTT_PROP_RECEIVE_MAXIMUM - property option. - * MQTT_PROP_TOPIC_ALIAS_MAXIMUM - property option. - * MQTT_PROP_TOPIC_ALIAS - property option. - * MQTT_PROP_MAXIMUM_QOS - property option. - * MQTT_PROP_RETAIN_AVAILABLE - property option. - * MQTT_PROP_USER_PROPERTY - property option. - * MQTT_PROP_MAXIMUM_PACKET_SIZE - property option. - * MQTT_PROP_WILDCARD_SUB_AVAILABLE - property option. - * MQTT_PROP_SUBSCRIPTION_ID_AVAILABLE - property option. - * MQTT_PROP_SHARED_SUB_AVAILABLE - property option. - */ -enum mqtt5_property { - MQTT_PROP_PAYLOAD_FORMAT_INDICATOR = 1, /* Byte : PUBLISH, Will Properties */ - MQTT_PROP_MESSAGE_EXPIRY_INTERVAL = 2, /* 4 byte int : PUBLISH, Will Properties */ - MQTT_PROP_CONTENT_TYPE = 3, /* UTF-8 string : PUBLISH, Will Properties */ - MQTT_PROP_RESPONSE_TOPIC = 8, /* UTF-8 string : PUBLISH, Will Properties */ - MQTT_PROP_CORRELATION_DATA = 9, /* Binary Data : PUBLISH, Will Properties */ - MQTT_PROP_SUBSCRIPTION_IDENTIFIER = 11, /* Variable byte int : PUBLISH, SUBSCRIBE */ - MQTT_PROP_SESSION_EXPIRY_INTERVAL = 17, /* 4 byte int : CONNECT, CONNACK, DISCONNECT */ - MQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER = 18, /* UTF-8 string : CONNACK */ - MQTT_PROP_SERVER_KEEP_ALIVE = 19, /* 2 byte int : CONNACK */ - MQTT_PROP_AUTHENTICATION_METHOD = 21, /* UTF-8 string : CONNECT, CONNACK, AUTH */ - MQTT_PROP_AUTHENTICATION_DATA = 22, /* Binary Data : CONNECT, CONNACK, AUTH */ - MQTT_PROP_REQUEST_PROBLEM_INFORMATION = 23, /* Byte : CONNECT */ - MQTT_PROP_WILL_DELAY_INTERVAL = 24, /* 4 byte int : Will properties */ - MQTT_PROP_REQUEST_RESPONSE_INFORMATION = 25,/* Byte : CONNECT */ - MQTT_PROP_RESPONSE_INFORMATION = 26, /* UTF-8 string : CONNACK */ - MQTT_PROP_SERVER_REFERENCE = 28, /* UTF-8 string : CONNACK, DISCONNECT */ - MQTT_PROP_REASON_STRING = 31, /* UTF-8 string : CONNACK, PUBACK, PUBREC, PUBREL, PUBCOMP, SUBACK, UNSUBACK, DISCONNECT, AUTH */ - MQTT_PROP_RECEIVE_MAXIMUM = 33, /* 2 byte int : CONNECT, CONNACK */ - MQTT_PROP_TOPIC_ALIAS_MAXIMUM = 34, /* 2 byte int : CONNECT, CONNACK */ - MQTT_PROP_TOPIC_ALIAS = 35, /* 2 byte int : PUBLISH */ - MQTT_PROP_MAXIMUM_QOS = 36, /* Byte : CONNACK */ - MQTT_PROP_RETAIN_AVAILABLE = 37, /* Byte : CONNACK */ - MQTT_PROP_USER_PROPERTY = 38, /* UTF-8 string pair : All */ - MQTT_PROP_MAXIMUM_PACKET_SIZE = 39, /* 4 byte int : CONNECT, CONNACK */ - MQTT_PROP_WILDCARD_SUB_AVAILABLE = 40, /* Byte : CONNACK */ - MQTT_PROP_SUBSCRIPTION_ID_AVAILABLE = 41, /* Byte : CONNACK */ - MQTT_PROP_SHARED_SUB_AVAILABLE = 42, /* Byte : CONNACK */ -}; - -enum mqtt5_property_type { - MQTT_PROP_TYPE_BYTE = 1, - MQTT_PROP_TYPE_INT16 = 2, - MQTT_PROP_TYPE_INT32 = 3, - MQTT_PROP_TYPE_VARINT = 4, - MQTT_PROP_TYPE_BINARY = 5, - MQTT_PROP_TYPE_STRING = 6, - MQTT_PROP_TYPE_STRING_PAIR = 7 -}; - -/* Enum: mqtt5_sub_options - * Options for use with MQTTv5 subscriptions. - * - * MQTT_SUB_OPT_NO_LOCAL - with this option set, if this client publishes to - * a topic to which it is subscribed, the broker will not publish the - * message back to the client. - * - * MQTT_SUB_OPT_RETAIN_AS_PUBLISHED - with this option set, messages - * published for this subscription will keep the retain flag as was set by - * the publishing client. The default behaviour without this option set has - * the retain flag indicating whether a message is fresh/stale. - * - * MQTT_SUB_OPT_SEND_RETAIN_ALWAYS - with this option set, pre-existing - * retained messages are sent as soon as the subscription is made, even - * if the subscription already exists. This is the default behaviour, so - * it is not necessary to set this option. - * - * MQTT_SUB_OPT_SEND_RETAIN_NEW - with this option set, pre-existing retained - * messages for this subscription will be sent when the subscription is made, - * but only if the subscription does not already exist. - * - * MQTT_SUB_OPT_SEND_RETAIN_NEVER - with this option set, pre-existing - * retained messages will never be sent for this subscription. - */ -enum mqtt5_sub_options { - MQTT_SUB_OPT_NO_LOCAL = 0x04, - MQTT_SUB_OPT_RETAIN_AS_PUBLISHED = 0x08, - MQTT_SUB_OPT_SEND_RETAIN_ALWAYS = 0x00, - MQTT_SUB_OPT_SEND_RETAIN_NEW = 0x10, - MQTT_SUB_OPT_SEND_RETAIN_NEVER = 0x20, -}; - -#define MQTT_MAX_PAYLOAD 268435455U - -#define MQTT_SUB_OPT_GET_QOS(opt) ((opt) & 0x03) -#define MQTT_SUB_OPT_GET_NO_LOCAL(opt) ((opt) & MQTT_SUB_OPT_NO_LOCAL) -#define MQTT_SUB_OPT_GET_RETAIN_AS_PUBLISHED(opt) ((opt) & MQTT_SUB_OPT_RETAIN_AS_PUBLISHED) -#define MQTT_SUB_OPT_GET_SEND_RETAIN(opt) ((opt) & (MQTT_SUB_OPT_SEND_RETAIN_NEW | MQTT_SUB_OPT_SEND_RETAIN_NEVER)) - -#define MQTT_SUB_OPT_SET_QOS(opt, qos) ((opt) = ((opt) & 0xFC) | ((qos) & 0x03)) - -#define MQTT_SUB_OPT_SET(opt, val) ((opt) |= val) -#define MQTT_SUB_OPT_CLEAR(opt, val) ((opt) = (opt) & !val) - -#endif +#include +#warning "Please replace '#include with #include " diff --git a/installer/mosquitto.nsi b/installer/mosquitto.nsi index a22750d5..7b616cf1 100644 --- a/installer/mosquitto.nsi +++ b/installer/mosquitto.nsi @@ -74,7 +74,35 @@ Section "Files" SecInstall File "..\include\mosquitto_broker.h" File "..\include\mosquitto_plugin.h" File "..\include\mosquittopp.h" - File "..\include\mqtt_protocol.h" + file "..\include\mqtt_protocol.h" + + SetOutPath "$INSTDIR\devel\mosquitto" + File "..\include\mosquitto\broker.h" + File "..\include\mosquitto\broker_control.h" + File "..\include\mosquitto\broker_plugin.h" + File "..\include\mosquitto\defs.h" + File "..\include\mosquitto\libcommon.h" + File "..\include\mosquitto\libcommon_properties.h" + File "..\include\mosquitto\libcommon_string.h" + File "..\include\mosquitto\libcommon_topic.h" + File "..\include\mosquitto\libcommon_utf8.h" + File "..\include\mosquitto\libmosquitto.h" + File "..\include\mosquitto\libmosquitto_auth.h" + File "..\include\mosquitto\libmosquitto_callbacks.h" + File "..\include\mosquitto\libmosquitto_connect.h" + File "..\include\mosquitto\libmosquitto_create_delete.h" + File "..\include\mosquitto\libmosquitto_helpers.h" + File "..\include\mosquitto\libmosquitto_loop.h" + File "..\include\mosquitto\libmosquitto_message.h" + File "..\include\mosquitto\libmosquitto_options.h" + File "..\include\mosquitto\libmosquitto_publish.h" + File "..\include\mosquitto\libmosquitto_socks.h" + File "..\include\mosquitto\libmosquitto_subscribe.h" + File "..\include\mosquitto\libmosquitto_tls.h" + File "..\include\mosquitto\libmosquitto_unsubscribe.h" + File "..\include\mosquitto\libmosquitto_will.h" + File "..\include\mosquitto\libmosquittopp.h" + File "..\include\mosquitto\mqtt_protocol.h" WriteUninstaller "$INSTDIR\Uninstall.exe" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Mosquitto" "DisplayName" "Eclipse Mosquitto MQTT broker" @@ -128,13 +156,37 @@ Section "Uninstall" Delete "$INSTDIR\epl-v20" Delete "$INSTDIR\devel\mosquitto.h" - Delete "$INSTDIR\devel\mosquitto.lib" + Delete "$INSTDIR\devel\mosquitto/broker.h" + Delete "$INSTDIR\devel\mosquitto/broker_control.h" + Delete "$INSTDIR\devel\mosquitto/broker_plugin.h" + Delete "$INSTDIR\devel\mosquitto/defs.h" + Delete "$INSTDIR\devel\mosquitto/libcommon.h" + Delete "$INSTDIR\devel\mosquitto/libcommon_properties.h" + Delete "$INSTDIR\devel\mosquitto/libcommon_string.h" + Delete "$INSTDIR\devel\mosquitto/libcommon_topic.h" + Delete "$INSTDIR\devel\mosquitto/libcommon_utf8.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_auth.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_callbacks.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_connect.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_create_delete.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_helpers.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_loop.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_message.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_options.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_publish.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_socks.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_subscribe.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_tls.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_unsubscribe.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_will.h" + Delete "$INSTDIR\devel\mosquitto/libmosquittopp.h" + Delete "$INSTDIR\devel\mosquitto/mqtt_protocol.h" Delete "$INSTDIR\devel\mosquitto_broker.h" Delete "$INSTDIR\devel\mosquitto_plugin.h" - Delete "$INSTDIR\devel\mosquitto_plugin.h" Delete "$INSTDIR\devel\mosquittopp.h" - Delete "$INSTDIR\devel\mosquittopp.lib" Delete "$INSTDIR\devel\mqtt_protocol.h" + RMDir "$INSTDIR\devel\mosquitto" RMDir "$INSTDIR\devel" Delete "$INSTDIR\Uninstall.exe" diff --git a/installer/mosquitto64.nsi b/installer/mosquitto64.nsi index 7b456b53..b6773ff9 100644 --- a/installer/mosquitto64.nsi +++ b/installer/mosquitto64.nsi @@ -75,7 +75,36 @@ Section "Files" SecInstall File "..\include\mosquitto_broker.h" File "..\include\mosquitto_plugin.h" File "..\include\mosquittopp.h" - File "..\include\mqtt_protocol.h" + file "..\include\mqtt_protocol.h" + + SetOutPath "$INSTDIR\devel\mosquitto" + File "..\include\mosquitto\broker.h" + File "..\include\mosquitto\broker_control.h" + File "..\include\mosquitto\broker_plugin.h" + File "..\include\mosquitto\defs.h" + File "..\include\mosquitto\libcommon.h" + File "..\include\mosquitto\libcommon_properties.h" + File "..\include\mosquitto\libcommon_string.h" + File "..\include\mosquitto\libcommon_topic.h" + File "..\include\mosquitto\libcommon_utf8.h" + File "..\include\mosquitto\libmosquitto.h" + File "..\include\mosquitto\libmosquitto_auth.h" + File "..\include\mosquitto\libmosquitto_callbacks.h" + File "..\include\mosquitto\libmosquitto_connect.h" + File "..\include\mosquitto\libmosquitto_create_delete.h" + File "..\include\mosquitto\libmosquitto_helpers.h" + File "..\include\mosquitto\libmosquitto_loop.h" + File "..\include\mosquitto\libmosquitto_message.h" + File "..\include\mosquitto\libmosquitto_options.h" + File "..\include\mosquitto\libmosquitto_publish.h" + File "..\include\mosquitto\libmosquitto_socks.h" + File "..\include\mosquitto\libmosquitto_subscribe.h" + File "..\include\mosquitto\libmosquitto_tls.h" + File "..\include\mosquitto\libmosquitto_unsubscribe.h" + File "..\include\mosquitto\libmosquitto_will.h" + File "..\include\mosquitto\libmosquittopp.h" + File "..\include\mosquitto\mqtt_protocol.h" + WriteUninstaller "$INSTDIR\Uninstall.exe" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Mosquitto64" "DisplayName" "Eclipse Mosquitto MQTT broker (64 bit)" @@ -129,13 +158,37 @@ Section "Uninstall" Delete "$INSTDIR\epl-v20" Delete "$INSTDIR\devel\mosquitto.h" - Delete "$INSTDIR\devel\mosquitto.lib" + Delete "$INSTDIR\devel\mosquitto/broker.h" + Delete "$INSTDIR\devel\mosquitto/broker_control.h" + Delete "$INSTDIR\devel\mosquitto/broker_plugin.h" + Delete "$INSTDIR\devel\mosquitto/defs.h" + Delete "$INSTDIR\devel\mosquitto/libcommon.h" + Delete "$INSTDIR\devel\mosquitto/libcommon_properties.h" + Delete "$INSTDIR\devel\mosquitto/libcommon_string.h" + Delete "$INSTDIR\devel\mosquitto/libcommon_topic.h" + Delete "$INSTDIR\devel\mosquitto/libcommon_utf8.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_auth.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_callbacks.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_connect.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_create_delete.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_helpers.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_loop.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_message.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_options.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_publish.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_socks.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_subscribe.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_tls.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_unsubscribe.h" + Delete "$INSTDIR\devel\mosquitto/libmosquitto_will.h" + Delete "$INSTDIR\devel\mosquitto/libmosquittopp.h" + Delete "$INSTDIR\devel\mosquitto/mqtt_protocol.h" Delete "$INSTDIR\devel\mosquitto_broker.h" Delete "$INSTDIR\devel\mosquitto_plugin.h" - Delete "$INSTDIR\devel\mosquitto_plugin.h" Delete "$INSTDIR\devel\mosquittopp.h" - Delete "$INSTDIR\devel\mosquittopp.lib" Delete "$INSTDIR\devel\mqtt_protocol.h" + RMDir "$INSTDIR\devel\mosquitto" RMDir "$INSTDIR\devel" Delete "$INSTDIR\Uninstall.exe" diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 5f81d2ea..e542f2f2 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -29,7 +29,7 @@ set(C_SRC ../common/misc_mosq.c ../common/misc_mosq.h mosquitto.c ../include/mosquitto.h mosquitto_internal.h - ../include/mqtt_protocol.h + ../include/mosquitto/mqtt_protocol.h net_mosq_ocsp.c net_mosq.c net_mosq.h net_ws.c options.c @@ -168,6 +168,3 @@ if(WITH_STATIC_LIBRARIES) ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) endif() - -install(FILES ${mosquitto_SOURCE_DIR}/include/mosquitto.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") -install(FILES ${mosquitto_SOURCE_DIR}/include/mqtt_protocol.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") diff --git a/lib/Makefile b/lib/Makefile index 40979b0a..0d40b00c 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -120,9 +120,6 @@ endif ifeq ($(WITH_STATIC_LIBRARIES),yes) $(INSTALL) ${STRIP_OPTS} libmosquitto.a "${DESTDIR}${libdir}/libmosquitto.a" endif - $(INSTALL) -d "${DESTDIR}${incdir}/" - $(INSTALL) ${R}/include/mosquitto.h "${DESTDIR}${incdir}/mosquitto.h" - $(INSTALL) ${R}/include/mqtt_protocol.h "${DESTDIR}${incdir}/mqtt_protocol.h" $(INSTALL) -d "${DESTDIR}${libdir}/pkgconfig" $(INSTALL) -m644 ${R}/libmosquitto.pc.in "${DESTDIR}${libdir}/pkgconfig/libmosquitto.pc" sed ${SEDINPLACE} -e "s#@CMAKE_INSTALL_PREFIX@#${prefix}#" -e "s#@VERSION@#${VERSION}#" "${DESTDIR}${libdir}/pkgconfig/libmosquitto.pc" diff --git a/lib/actions_publish.c b/lib/actions_publish.c index 6251f818..1bae132f 100644 --- a/lib/actions_publish.c +++ b/lib/actions_publish.c @@ -24,7 +24,7 @@ Contributors: #include "memory_mosq.h" #include "messages_mosq.h" #include "mosquitto_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "property_mosq.h" #include "send_mosq.h" diff --git a/lib/actions_subscribe.c b/lib/actions_subscribe.c index 06c0c20f..9067bcc5 100644 --- a/lib/actions_subscribe.c +++ b/lib/actions_subscribe.c @@ -20,7 +20,7 @@ Contributors: #include -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "send_mosq.h" diff --git a/lib/actions_unsubscribe.c b/lib/actions_unsubscribe.c index 1c99d269..4f803773 100644 --- a/lib/actions_unsubscribe.c +++ b/lib/actions_unsubscribe.c @@ -21,7 +21,7 @@ Contributors: #include #include -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/lib/connect.c b/lib/connect.c index ba011006..77166dca 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -28,7 +28,6 @@ Contributors: #include "messages_mosq.h" #include "memory_mosq.h" #include "packet_mosq.h" -#include "mqtt_protocol.h" #include "net_mosq.h" #include "send_mosq.h" #include "socks_mosq.h" diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt index f6dfc8c3..2007f7a6 100644 --- a/lib/cpp/CMakeLists.txt +++ b/lib/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -set(CPP_SRC mosquittopp.cpp ../../include/mosquittopp.h) +set(CPP_SRC mosquittopp.cpp ../../include/mosquitto/libmosquittopp.h) add_library(mosquittopp SHARED ${CPP_SRC} @@ -64,5 +64,3 @@ if(WITH_STATIC_LIBRARIES) ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) endif() - -install(FILES ${mosquitto_SOURCE_DIR}/include/mosquittopp.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") diff --git a/lib/cpp/Makefile b/lib/cpp/Makefile index 3b1cf27b..c22584e0 100644 --- a/lib/cpp/Makefile +++ b/lib/cpp/Makefile @@ -24,8 +24,6 @@ ifeq ($(WITH_STATIC_LIBRARIES),yes) $(INSTALL) libmosquittopp.a "${DESTDIR}${libdir}/libmosquittopp.a" ${CROSS_COMPILE}${STRIP} -g --strip-unneeded "${DESTDIR}${libdir}/libmosquittopp.a" endif - $(INSTALL) -d "${DESTDIR}${incdir}/" - $(INSTALL) ${R}/include/mosquittopp.h "${DESTDIR}${incdir}/mosquittopp.h" $(INSTALL) -d "${DESTDIR}${libdir}/pkgconfig/" $(INSTALL) -m644 ${R}/libmosquittopp.pc.in "${DESTDIR}${libdir}/pkgconfig/libmosquittopp.pc" sed ${SEDINPLACE} -e "s#@CMAKE_INSTALL_PREFIX@#${prefix}#" -e "s#@VERSION@#${VERSION}#" "${DESTDIR}${libdir}/pkgconfig/libmosquittopp.pc" @@ -34,7 +32,6 @@ uninstall : -rm -f "${DESTDIR}${libdir}/libmosquittopp.so.${SOVERSION}" -rm -f "${DESTDIR}${libdir}/libmosquittopp.so" -rm -f "${DESTDIR}${libdir}/libmosquittopp.a" - -rm -f "${DESTDIR}${incdir}/mosquittopp.h" clean : -rm -f *.o libmosquittopp.so.${SOVERSION} libmosquittopp.a @@ -45,5 +42,5 @@ libmosquittopp.so.${SOVERSION} : mosquittopp.o libmosquittopp.a : mosquittopp.o ${CROSS_COMPILE}$(AR) cr $@ $^ -mosquittopp.o : mosquittopp.cpp ${R}/include/mosquittopp.h +mosquittopp.o : mosquittopp.cpp ${R}/include/mosquitto/libmosquittopp.h ${CROSS_COMPILE}$(CXX) $(LOCAL_CPPFLAGS) $(LOCAL_CXXFLAGS) -c $< -o $@ diff --git a/lib/cpp/mosquittopp.cpp b/lib/cpp/mosquittopp.cpp index cd4d0428..8adc9c5a 100644 --- a/lib/cpp/mosquittopp.cpp +++ b/lib/cpp/mosquittopp.cpp @@ -15,8 +15,7 @@ Contributors: */ #include -#include -#include +#include #define UNUSED(A) (void)(A) diff --git a/lib/handle_auth.c b/lib/handle_auth.c index 041c7c42..5907e483 100644 --- a/lib/handle_auth.c +++ b/lib/handle_auth.c @@ -23,7 +23,7 @@ Contributors: #include "logging_mosq.h" #include "mosquitto_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "property_mosq.h" #include "read_handle.h" diff --git a/lib/handle_connack.c b/lib/handle_connack.c index 724108a9..58847f47 100644 --- a/lib/handle_connack.c +++ b/lib/handle_connack.c @@ -21,11 +21,10 @@ Contributors: #include #include "callbacks.h" -#include "mosquitto.h" #include "logging_mosq.h" #include "memory_mosq.h" #include "messages_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/lib/handle_disconnect.c b/lib/handle_disconnect.c index 7f9ce225..fc09b36c 100644 --- a/lib/handle_disconnect.c +++ b/lib/handle_disconnect.c @@ -22,7 +22,7 @@ Contributors: #include #include "logging_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "net_mosq.h" #include "packet_mosq.h" diff --git a/lib/handle_ping.c b/lib/handle_ping.c index df197fa5..27b7892d 100644 --- a/lib/handle_ping.c +++ b/lib/handle_ping.c @@ -30,7 +30,7 @@ Contributors: #include "logging_mosq.h" #include "memory_mosq.h" #include "messages_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "read_handle.h" diff --git a/lib/handle_pubackcomp.c b/lib/handle_pubackcomp.c index 58af3047..315a3b5d 100644 --- a/lib/handle_pubackcomp.c +++ b/lib/handle_pubackcomp.c @@ -31,7 +31,7 @@ Contributors: #include "logging_mosq.h" #include "memory_mosq.h" #include "messages_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "read_handle.h" diff --git a/lib/handle_publish.c b/lib/handle_publish.c index 011046c5..b1cc0814 100644 --- a/lib/handle_publish.c +++ b/lib/handle_publish.c @@ -27,7 +27,7 @@ Contributors: #include "mosquitto_internal.h" #include "logging_mosq.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "messages_mosq.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/lib/handle_pubrec.c b/lib/handle_pubrec.c index d9f93ae3..9c8b496a 100644 --- a/lib/handle_pubrec.c +++ b/lib/handle_pubrec.c @@ -31,7 +31,7 @@ Contributors: #include "logging_mosq.h" #include "memory_mosq.h" #include "messages_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "read_handle.h" diff --git a/lib/handle_pubrel.c b/lib/handle_pubrel.c index ee1eef1c..0eb61a1c 100644 --- a/lib/handle_pubrel.c +++ b/lib/handle_pubrel.c @@ -31,7 +31,7 @@ Contributors: #include "logging_mosq.h" #include "memory_mosq.h" #include "messages_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "read_handle.h" diff --git a/lib/handle_suback.c b/lib/handle_suback.c index 8367303f..f61247cf 100644 --- a/lib/handle_suback.c +++ b/lib/handle_suback.c @@ -29,7 +29,7 @@ Contributors: #include "mosquitto_internal.h" #include "logging_mosq.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "property_mosq.h" #include "read_handle.h" diff --git a/lib/handle_unsuback.c b/lib/handle_unsuback.c index 3db5ca65..7f0b0482 100644 --- a/lib/handle_unsuback.c +++ b/lib/handle_unsuback.c @@ -31,7 +31,7 @@ Contributors: #include "logging_mosq.h" #include "memory_mosq.h" #include "messages_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/lib/http_client.c b/lib/http_client.c index c4a32a58..bcd6cc3c 100644 --- a/lib/http_client.c +++ b/lib/http_client.c @@ -28,7 +28,7 @@ Contributors: #include "base64_mosq.h" #include "http_client.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "read_handle.h" diff --git a/lib/mosquitto.c b/lib/mosquitto.c index af18b9bf..22bd6325 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -35,7 +35,7 @@ Contributors: #include "mosquitto_internal.h" #include "memory_mosq.h" #include "messages_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "will_mosq.h" diff --git a/lib/net_mosq.c b/lib/net_mosq.c index 1a25ab6d..5811c1d9 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -72,7 +72,7 @@ Contributors: #include "logging_mosq.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "time_mosq.h" diff --git a/lib/net_ws.c b/lib/net_ws.c index 2d06bdfa..fae80c98 100644 --- a/lib/net_ws.c +++ b/lib/net_ws.c @@ -30,7 +30,7 @@ Contributors: #include "base64_mosq.h" #include "mosquitto_internal.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "util_mosq.h" diff --git a/lib/options.c b/lib/options.c index 4bbe4ebc..a2d5ab4a 100644 --- a/lib/options.c +++ b/lib/options.c @@ -35,7 +35,7 @@ Contributors: #include "mosquitto_internal.h" #include "memory_mosq.h" #include "misc_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "util_mosq.h" #include "will_mosq.h" diff --git a/lib/packet_datatypes.c b/lib/packet_datatypes.c index 340bb918..4f21c74b 100644 --- a/lib/packet_datatypes.c +++ b/lib/packet_datatypes.c @@ -35,7 +35,7 @@ Contributors: #endif #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "read_handle.h" diff --git a/lib/packet_mosq.c b/lib/packet_mosq.c index da1f30e3..a9f07561 100644 --- a/lib/packet_mosq.c +++ b/lib/packet_mosq.c @@ -33,7 +33,7 @@ Contributors: #include "callbacks.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "read_handle.h" diff --git a/lib/property_mosq.c b/lib/property_mosq.c index 30113b35..45668868 100644 --- a/lib/property_mosq.c +++ b/lib/property_mosq.c @@ -28,7 +28,7 @@ Contributors: #include "logging_mosq.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/lib/read_handle.c b/lib/read_handle.c index a19905b6..0d2235c9 100644 --- a/lib/read_handle.c +++ b/lib/read_handle.c @@ -26,7 +26,7 @@ Contributors: #include "logging_mosq.h" #include "memory_mosq.h" #include "messages_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "read_handle.h" diff --git a/lib/send_connect.c b/lib/send_connect.c index 29349fec..28a89d69 100644 --- a/lib/send_connect.c +++ b/lib/send_connect.c @@ -30,7 +30,7 @@ Contributors: #include "memory_mosq.h" #include "mosquitto.h" #include "mosquitto_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "property_mosq.h" #include "send_mosq.h" diff --git a/lib/send_disconnect.c b/lib/send_disconnect.c index 4c0d1283..79b088f1 100644 --- a/lib/send_disconnect.c +++ b/lib/send_disconnect.c @@ -29,7 +29,7 @@ Contributors: #include "mosquitto_internal.h" #include "logging_mosq.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "property_mosq.h" #include "send_mosq.h" diff --git a/lib/send_mosq.c b/lib/send_mosq.c index c4c6ff7d..b701448f 100644 --- a/lib/send_mosq.c +++ b/lib/send_mosq.c @@ -30,7 +30,7 @@ Contributors: #include "mosquitto.h" #include "mosquitto_internal.h" #include "logging_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "net_mosq.h" #include "packet_mosq.h" diff --git a/lib/send_publish.c b/lib/send_publish.c index 27b0fda0..703ba352 100644 --- a/lib/send_publish.c +++ b/lib/send_publish.c @@ -32,7 +32,7 @@ Contributors: #include "mosquitto.h" #include "mosquitto_internal.h" #include "logging_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "net_mosq.h" #include "packet_mosq.h" diff --git a/lib/send_subscribe.c b/lib/send_subscribe.c index 98a69663..68b8a2e8 100644 --- a/lib/send_subscribe.c +++ b/lib/send_subscribe.c @@ -30,7 +30,7 @@ Contributors: #include "mosquitto_internal.h" #include "logging_mosq.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "property_mosq.h" #include "send_mosq.h" diff --git a/lib/send_unsubscribe.c b/lib/send_unsubscribe.c index 0bc3a843..d80b89d3 100644 --- a/lib/send_unsubscribe.c +++ b/lib/send_unsubscribe.c @@ -29,7 +29,7 @@ Contributors: #include "mosquitto.h" #include "logging_mosq.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "property_mosq.h" #include "send_mosq.h" diff --git a/lib/strings_mosq.c b/lib/strings_mosq.c index ec74ccf8..805e052f 100644 --- a/lib/strings_mosq.c +++ b/lib/strings_mosq.c @@ -26,7 +26,7 @@ Contributors: #endif #include "mosquitto.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" const char *mosquitto_strerror(int mosq_errno) { diff --git a/lib/will_mosq.c b/lib/will_mosq.c index ec3a6de3..71f2c0ba 100644 --- a/lib/will_mosq.c +++ b/lib/will_mosq.c @@ -30,7 +30,7 @@ Contributors: #include "logging_mosq.h" #include "messages_mosq.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "read_handle.h" #include "send_mosq.h" diff --git a/plugins/dynamic-security/acl.c b/plugins/dynamic-security/acl.c index 1c7510e9..291f10bf 100644 --- a/plugins/dynamic-security/acl.c +++ b/plugins/dynamic-security/acl.c @@ -18,10 +18,9 @@ Contributors: #include "config.h" +#include "mosquitto/broker_plugin.h" + #include "dynamic_security.h" -#include "mosquitto.h" -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" typedef int (*MOSQ_FUNC_acl_check)(struct dynsec__data *data, struct mosquitto_evt_acl_check *, struct dynsec__rolelist *); diff --git a/plugins/dynamic-security/auth.c b/plugins/dynamic-security/auth.c index cf2d20be..5820155d 100644 --- a/plugins/dynamic-security/auth.c +++ b/plugins/dynamic-security/auth.c @@ -24,8 +24,6 @@ Contributors: #include #include "dynamic_security.h" -#include "mosquitto.h" -#include "mosquitto_broker.h" /* ################################################################ diff --git a/plugins/dynamic-security/clientlist.c b/plugins/dynamic-security/clientlist.c index e8fcef2d..71a6f527 100644 --- a/plugins/dynamic-security/clientlist.c +++ b/plugins/dynamic-security/clientlist.c @@ -22,11 +22,8 @@ Contributors: #include #include -#include "mosquitto.h" -#include "mosquitto_broker.h" -#include "json_help.h" - #include "dynamic_security.h" +#include "json_help.h" /* ################################################################ * # diff --git a/plugins/dynamic-security/clients.c b/plugins/dynamic-security/clients.c index 0a455bc1..f44d85c4 100644 --- a/plugins/dynamic-security/clients.c +++ b/plugins/dynamic-security/clients.c @@ -22,11 +22,8 @@ Contributors: #include #include -#include "mosquitto.h" -#include "mosquitto_broker.h" -#include "json_help.h" - #include "dynamic_security.h" +#include "json_help.h" struct connection_array_context{ const char *username; diff --git a/plugins/dynamic-security/config.c b/plugins/dynamic-security/config.c index 0192b9b6..dabeeb2a 100644 --- a/plugins/dynamic-security/config.c +++ b/plugins/dynamic-security/config.c @@ -25,14 +25,9 @@ Contributors: #include #include +#include "dynamic_security.h" #include "json_help.h" #include "misc_mosq.h" -#include "mosquitto.h" -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" -#include "mqtt_protocol.h" - -#include "dynamic_security.h" static int dynsec__general_config_load(struct dynsec__data *data, cJSON *tree) { diff --git a/plugins/dynamic-security/config_init.c b/plugins/dynamic-security/config_init.c index d1f79174..7438a92e 100644 --- a/plugins/dynamic-security/config_init.c +++ b/plugins/dynamic-security/config_init.c @@ -27,14 +27,9 @@ Contributors: #include #include -#include "json_help.h" -#include "mosquitto.h" -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" -#include "mqtt_protocol.h" -#include "misc_mosq.h" - #include "dynamic_security.h" +#include "json_help.h" +#include "misc_mosq.h" const char pw_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=_+[]{}@#~,./<>?"; diff --git a/plugins/dynamic-security/control.c b/plugins/dynamic-security/control.c index 7d5aa8db..8159c222 100644 --- a/plugins/dynamic-security/control.c +++ b/plugins/dynamic-security/control.c @@ -25,13 +25,8 @@ Contributors: #include #include -#include "json_help.h" -#include "mosquitto.h" -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" -#include "mqtt_protocol.h" - #include "dynamic_security.h" +#include "json_help.h" #define RESPONSE_TOPIC "$CONTROL/dynamic-security/v1/response" diff --git a/plugins/dynamic-security/default_acl.c b/plugins/dynamic-security/default_acl.c index 41a3f4f4..877a89ae 100644 --- a/plugins/dynamic-security/default_acl.c +++ b/plugins/dynamic-security/default_acl.c @@ -25,13 +25,8 @@ Contributors: #include #include -#include "json_help.h" -#include "mosquitto.h" -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" -#include "mqtt_protocol.h" - #include "dynamic_security.h" +#include "json_help.h" int dynsec__process_set_default_acl_access(struct dynsec__data *data, struct mosquitto_control_cmd *cmd) { diff --git a/plugins/dynamic-security/dynamic_security.h b/plugins/dynamic-security/dynamic_security.h index 580051e4..eedd0e1a 100644 --- a/plugins/dynamic-security/dynamic_security.h +++ b/plugins/dynamic-security/dynamic_security.h @@ -21,8 +21,8 @@ Contributors: #include #include #include "mosquitto.h" -#include "mosquitto_broker.h" -#include "mosquitto_control.h" +#include "mosquitto/broker.h" +#include "mosquitto/broker_control.h" #include "password_mosq.h" #include "base64_mosq.h" diff --git a/plugins/dynamic-security/grouplist.c b/plugins/dynamic-security/grouplist.c index 3d575dc9..5fea3b15 100644 --- a/plugins/dynamic-security/grouplist.c +++ b/plugins/dynamic-security/grouplist.c @@ -22,11 +22,8 @@ Contributors: #include #include -#include "mosquitto.h" -#include "mosquitto_broker.h" -#include "json_help.h" - #include "dynamic_security.h" +#include "json_help.h" /* ################################################################ * # diff --git a/plugins/dynamic-security/groups.c b/plugins/dynamic-security/groups.c index bbae4e02..21f0ae8d 100644 --- a/plugins/dynamic-security/groups.c +++ b/plugins/dynamic-security/groups.c @@ -22,11 +22,8 @@ Contributors: #include #include -#include "mosquitto.h" -#include "mosquitto_broker.h" -#include "json_help.h" - #include "dynamic_security.h" +#include "json_help.h" /* ################################################################ * # diff --git a/plugins/dynamic-security/kicklist.c b/plugins/dynamic-security/kicklist.c index 2d8ab329..21f8bc4f 100644 --- a/plugins/dynamic-security/kicklist.c +++ b/plugins/dynamic-security/kicklist.c @@ -21,9 +21,6 @@ Contributors: #include #include -#include "mosquitto.h" -#include "mosquitto_broker.h" - #include "dynamic_security.h" int dynsec_kicklist__add(struct dynsec__data *data, const char *username) diff --git a/plugins/dynamic-security/plugin.c b/plugins/dynamic-security/plugin.c index 767f8582..c1ce33cb 100644 --- a/plugins/dynamic-security/plugin.c +++ b/plugins/dynamic-security/plugin.c @@ -28,13 +28,10 @@ Contributors: # include #endif -#include "json_help.h" -#include "mosquitto.h" -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" -#include "mqtt_protocol.h" +#include "mosquitto/broker_plugin.h" #include "dynamic_security.h" +#include "json_help.h" MOSQUITTO_PLUGIN_DECLARE_VERSION(5); diff --git a/plugins/dynamic-security/rolelist.c b/plugins/dynamic-security/rolelist.c index 71cc0389..8a391ca8 100644 --- a/plugins/dynamic-security/rolelist.c +++ b/plugins/dynamic-security/rolelist.c @@ -26,9 +26,6 @@ Contributors: #include "dynamic_security.h" #include "json_help.h" -#include "mosquitto.h" -#include "mosquitto_broker.h" - /* ################################################################ * # diff --git a/plugins/dynamic-security/roles.c b/plugins/dynamic-security/roles.c index 1fbff3a2..4d02545c 100644 --- a/plugins/dynamic-security/roles.c +++ b/plugins/dynamic-security/roles.c @@ -30,9 +30,6 @@ Contributors: #include "dynamic_security.h" #include "json_help.h" -#include "mosquitto.h" -#include "mosquitto_broker.h" - static cJSON *add_role_to_json(struct dynsec__role *role, bool verbose); static void role__remove_all_clients(struct dynsec__data *data, struct dynsec__role *role); diff --git a/plugins/dynamic-security/tick.c b/plugins/dynamic-security/tick.c index 211465d3..eeb2731f 100644 --- a/plugins/dynamic-security/tick.c +++ b/plugins/dynamic-security/tick.c @@ -18,11 +18,6 @@ Contributors: #include "config.h" -#include "mosquitto.h" -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" -#include "mqtt_protocol.h" - #include "dynamic_security.h" int dynsec__tick_callback(int event, void *event_data, void *userdata) diff --git a/plugins/examples/add-properties/mosquitto_add_properties.c b/plugins/examples/add-properties/mosquitto_add_properties.c index 6a1032ed..ec51d2a4 100644 --- a/plugins/examples/add-properties/mosquitto_add_properties.c +++ b/plugins/examples/add-properties/mosquitto_add_properties.c @@ -37,10 +37,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define TS_BUF_LEN (14+1) // 14 characters in unix epoch (ms) is ≈16 Nov 5138 #define PLUGIN_NAME "add-properties" diff --git a/plugins/examples/auth-by-env/mosquitto_auth_by_env.c b/plugins/examples/auth-by-env/mosquitto_auth_by_env.c index ce94eede..538241f0 100644 --- a/plugins/examples/auth-by-env/mosquitto_auth_by_env.c +++ b/plugins/examples/auth-by-env/mosquitto_auth_by_env.c @@ -29,10 +29,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define ENV_MOSQUITTO_PASSWORD "MOSQUITTO_PASSWORD" diff --git a/plugins/examples/auth-by-ip/mosquitto_auth_by_ip.c b/plugins/examples/auth-by-ip/mosquitto_auth_by_ip.c index c1edff87..f8a12929 100644 --- a/plugins/examples/auth-by-ip/mosquitto_auth_by_ip.c +++ b/plugins/examples/auth-by-ip/mosquitto_auth_by_ip.c @@ -37,10 +37,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "auth-by-ip" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/client-lifetime-stats/mosquitto_client_lifetime_stats.c b/plugins/examples/client-lifetime-stats/mosquitto_client_lifetime_stats.c index bf6f5d78..83e4c6be 100644 --- a/plugins/examples/client-lifetime-stats/mosquitto_client_lifetime_stats.c +++ b/plugins/examples/client-lifetime-stats/mosquitto_client_lifetime_stats.c @@ -36,10 +36,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" MOSQUITTO_PLUGIN_DECLARE_VERSION(5); diff --git a/plugins/examples/client-properties/mosquitto_client_properties.c b/plugins/examples/client-properties/mosquitto_client_properties.c index 9312632d..783cafde 100644 --- a/plugins/examples/client-properties/mosquitto_client_properties.c +++ b/plugins/examples/client-properties/mosquitto_client_properties.c @@ -14,10 +14,7 @@ #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "client-properties" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/connection-state/mosquitto_connection_state.c b/plugins/examples/connection-state/mosquitto_connection_state.c index 0a00943a..0a839855 100644 --- a/plugins/examples/connection-state/mosquitto_connection_state.c +++ b/plugins/examples/connection-state/mosquitto_connection_state.c @@ -35,10 +35,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "connection-state" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/delayed-auth/mosquitto_delayed_auth.c b/plugins/examples/delayed-auth/mosquitto_delayed_auth.c index c79993d5..61dd7572 100644 --- a/plugins/examples/delayed-auth/mosquitto_delayed_auth.c +++ b/plugins/examples/delayed-auth/mosquitto_delayed_auth.c @@ -39,10 +39,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "delayed-auth" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/deny-protocol-version/mosquitto_deny_protocol_version.c b/plugins/examples/deny-protocol-version/mosquitto_deny_protocol_version.c index d0fb3430..c81db1ba 100644 --- a/plugins/examples/deny-protocol-version/mosquitto_deny_protocol_version.c +++ b/plugins/examples/deny-protocol-version/mosquitto_deny_protocol_version.c @@ -49,10 +49,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" static mosquitto_plugin_id_t *mosq_pid = NULL; diff --git a/plugins/examples/force-retain/mosquitto_force_retain.c b/plugins/examples/force-retain/mosquitto_force_retain.c index 045e60d3..c708e33a 100644 --- a/plugins/examples/force-retain/mosquitto_force_retain.c +++ b/plugins/examples/force-retain/mosquitto_force_retain.c @@ -32,10 +32,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "force-retain" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/limit-subscription-qos/mosquitto_limit_subscription_qos.c b/plugins/examples/limit-subscription-qos/mosquitto_limit_subscription_qos.c index 74b606a2..89b81733 100644 --- a/plugins/examples/limit-subscription-qos/mosquitto_limit_subscription_qos.c +++ b/plugins/examples/limit-subscription-qos/mosquitto_limit_subscription_qos.c @@ -31,10 +31,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "limit-subscription-qos" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/message-timestamp/mosquitto_message_timestamp.c b/plugins/examples/message-timestamp/mosquitto_message_timestamp.c index 63bbae30..288cba08 100644 --- a/plugins/examples/message-timestamp/mosquitto_message_timestamp.c +++ b/plugins/examples/message-timestamp/mosquitto_message_timestamp.c @@ -33,10 +33,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "message-timestamp" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/payload-ban/mosquitto_payload_ban.c b/plugins/examples/payload-ban/mosquitto_payload_ban.c index 16a2bd0f..3f14c529 100644 --- a/plugins/examples/payload-ban/mosquitto_payload_ban.c +++ b/plugins/examples/payload-ban/mosquitto_payload_ban.c @@ -41,10 +41,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "payload-ban" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/payload-modification/mosquitto_payload_modification.c b/plugins/examples/payload-modification/mosquitto_payload_modification.c index 2db360ed..eb5837b3 100644 --- a/plugins/examples/payload-modification/mosquitto_payload_modification.c +++ b/plugins/examples/payload-modification/mosquitto_payload_modification.c @@ -35,10 +35,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "payload-modification" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/payload-size-stats/mosquitto_payload_size_stats.c b/plugins/examples/payload-size-stats/mosquitto_payload_size_stats.c index 77bbfd34..d1e13b0f 100644 --- a/plugins/examples/payload-size-stats/mosquitto_payload_size_stats.c +++ b/plugins/examples/payload-size-stats/mosquitto_payload_size_stats.c @@ -34,10 +34,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" MOSQUITTO_PLUGIN_DECLARE_VERSION(5); diff --git a/plugins/examples/plugin-event-stats/mosquitto_plugin_event_stats.c b/plugins/examples/plugin-event-stats/mosquitto_plugin_event_stats.c index e4465849..e483d72b 100644 --- a/plugins/examples/plugin-event-stats/mosquitto_plugin_event_stats.c +++ b/plugins/examples/plugin-event-stats/mosquitto_plugin_event_stats.c @@ -35,8 +35,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" +#include "mosquitto.h" #define PLUGIN_NAME "plugin-event-stats" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/print-ip-on-publish/mosquitto_print_ip_on_publish.c b/plugins/examples/print-ip-on-publish/mosquitto_print_ip_on_publish.c index 7fae2719..2efea362 100644 --- a/plugins/examples/print-ip-on-publish/mosquitto_print_ip_on_publish.c +++ b/plugins/examples/print-ip-on-publish/mosquitto_print_ip_on_publish.c @@ -5,10 +5,7 @@ #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "print-ip-on-publish" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/topic-jail/mosquitto_topic_jail.c b/plugins/examples/topic-jail/mosquitto_topic_jail.c index 0b2928c5..76e012a1 100644 --- a/plugins/examples/topic-jail/mosquitto_topic_jail.c +++ b/plugins/examples/topic-jail/mosquitto_topic_jail.c @@ -49,10 +49,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "topic-jail" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/topic-modification/mosquitto_topic_modification.c b/plugins/examples/topic-modification/mosquitto_topic_modification.c index 0704621a..9a396503 100644 --- a/plugins/examples/topic-modification/mosquitto_topic_modification.c +++ b/plugins/examples/topic-modification/mosquitto_topic_modification.c @@ -35,10 +35,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "topic-modification" #define PLUGIN_VERSION "1.0" diff --git a/plugins/examples/wildcard-temp/mosquitto_wildcard_temp.c b/plugins/examples/wildcard-temp/mosquitto_wildcard_temp.c index e7387bb9..129d54e8 100644 --- a/plugins/examples/wildcard-temp/mosquitto_wildcard_temp.c +++ b/plugins/examples/wildcard-temp/mosquitto_wildcard_temp.c @@ -50,10 +50,7 @@ Contributors: #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" #include "mosquitto.h" -#include "mqtt_protocol.h" #define PLUGIN_NAME "wildcard-temp" #define PLUGIN_VERSION "1.0" diff --git a/plugins/persist-sqlite/base_msgs.c b/plugins/persist-sqlite/base_msgs.c index 78051660..e1d40189 100644 --- a/plugins/persist-sqlite/base_msgs.c +++ b/plugins/persist-sqlite/base_msgs.c @@ -22,9 +22,9 @@ Contributors: #include #include -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "mosquitto.h" -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "persist_sqlite.h" static char *properties_to_json(const mosquitto_property *properties) diff --git a/plugins/persist-sqlite/client_msgs.c b/plugins/persist-sqlite/client_msgs.c index 26cbd394..c7c30a5b 100644 --- a/plugins/persist-sqlite/client_msgs.c +++ b/plugins/persist-sqlite/client_msgs.c @@ -20,7 +20,7 @@ Contributors: #include #include "mosquitto.h" -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "persist_sqlite.h" diff --git a/plugins/persist-sqlite/clients.c b/plugins/persist-sqlite/clients.c index 4cd11baf..a0d2d84a 100644 --- a/plugins/persist-sqlite/clients.c +++ b/plugins/persist-sqlite/clients.c @@ -20,7 +20,7 @@ Contributors: #include #include "mosquitto.h" -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "persist_sqlite.h" int persist_sqlite__client_add_cb(int event, void *event_data, void *userdata) diff --git a/plugins/persist-sqlite/init.c b/plugins/persist-sqlite/init.c index 49f43200..8f97a5da 100644 --- a/plugins/persist-sqlite/init.c +++ b/plugins/persist-sqlite/init.c @@ -21,7 +21,7 @@ Contributors: #include "persist_sqlite.h" #include "mosquitto.h" -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" static int create_tables(struct mosquitto_sqlite *ms) { diff --git a/plugins/persist-sqlite/plugin.c b/plugins/persist-sqlite/plugin.c index d35fb609..1e720c63 100644 --- a/plugins/persist-sqlite/plugin.c +++ b/plugins/persist-sqlite/plugin.c @@ -28,9 +28,9 @@ Contributors: #endif #include "mosquitto.h" -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" -#include "mqtt_protocol.h" +#include "mosquitto/broker.h" +#include "mosquitto/broker_plugin.h" +#include "mosquitto/mqtt_protocol.h" #include "persist_sqlite.h" diff --git a/plugins/persist-sqlite/restore.c b/plugins/persist-sqlite/restore.c index f4e88bf9..8e111aa3 100644 --- a/plugins/persist-sqlite/restore.c +++ b/plugins/persist-sqlite/restore.c @@ -23,8 +23,8 @@ Contributors: #include "json_help.h" #include "mosquitto.h" -#include "mosquitto_broker.h" -#include "mqtt_protocol.h" +#include "mosquitto/broker.h" +#include "mosquitto/mqtt_protocol.h" #include "persist_sqlite.h" static uint8_t hex2nibble(char c) diff --git a/plugins/persist-sqlite/retain_msgs.c b/plugins/persist-sqlite/retain_msgs.c index b1544e52..15b5b04a 100644 --- a/plugins/persist-sqlite/retain_msgs.c +++ b/plugins/persist-sqlite/retain_msgs.c @@ -20,7 +20,7 @@ Contributors: #include #include "mosquitto.h" -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "persist_sqlite.h" int persist_sqlite__retain_msg_set_cb(int event, void *event_data, void *userdata) diff --git a/plugins/persist-sqlite/subscriptions.c b/plugins/persist-sqlite/subscriptions.c index 200d0686..6646bae0 100644 --- a/plugins/persist-sqlite/subscriptions.c +++ b/plugins/persist-sqlite/subscriptions.c @@ -20,7 +20,7 @@ Contributors: #include #include "mosquitto.h" -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "persist_sqlite.h" int persist_sqlite__subscription_add_cb(int event, void *event_data, void *userdata) diff --git a/plugins/persist-sqlite/tick.c b/plugins/persist-sqlite/tick.c index d51802bc..17895a39 100644 --- a/plugins/persist-sqlite/tick.c +++ b/plugins/persist-sqlite/tick.c @@ -20,9 +20,9 @@ Contributors: #include #include -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "mosquitto.h" -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "persist_sqlite.h" int persist_sqlite__tick_cb(int event, void *event_data, void *userdata) diff --git a/plugins/sparkplug-aware/on_message.c b/plugins/sparkplug-aware/on_message.c index 5f54e701..4d186649 100644 --- a/plugins/sparkplug-aware/on_message.c +++ b/plugins/sparkplug-aware/on_message.c @@ -7,7 +7,7 @@ Copyright (c) 2023 Cedalo Gmbh #include #include -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "plugin_global.h" int plugin__message_in_callback(int event, void *event_data, void *user_data) diff --git a/plugins/sparkplug-aware/plugin.c b/plugins/sparkplug-aware/plugin.c index 96478d0c..cd7521e8 100644 --- a/plugins/sparkplug-aware/plugin.c +++ b/plugins/sparkplug-aware/plugin.c @@ -7,8 +7,8 @@ Copyright (c) 2023 Cedalo Gmbh #include #include -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" +#include "mosquitto/broker.h" +#include "mosquitto/broker_plugin.h" #include "plugin_global.h" MOSQUITTO_PLUGIN_DECLARE_VERSION(5); diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 4d70eab8..d6559801 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -90,6 +90,7 @@ parts: - usr/include/mosquitto_broker.h - usr/include/mosquitto_plugin.h - usr/include/mqtt_protocol.h + - usr/include/mosquitto/*.h lws: after: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eaeb23c4..4caaafb4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -279,9 +279,3 @@ endif() install(TARGETS mosquitto RUNTIME DESTINATION "${CMAKE_INSTALL_SBINDIR}" ) -install( - FILES - ${mosquitto_SOURCE_DIR}/include/mosquitto_broker.h - ${mosquitto_SOURCE_DIR}/include/mosquitto_plugin.h - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" -) diff --git a/src/Makefile b/src/Makefile index 750409c3..9a74977e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -256,9 +256,6 @@ will_mosq.o : ${R}/lib/will_mosq.c ${R}/lib/will_mosq.h install : all $(INSTALL) -d "${DESTDIR}$(prefix)/sbin" $(INSTALL) ${STRIP_OPTS} mosquitto "${DESTDIR}${prefix}/sbin/mosquitto" - $(INSTALL) -d "${DESTDIR}$(prefix)/include" - $(INSTALL) ${R}/include/mosquitto_broker.h "${DESTDIR}${prefix}/include/mosquitto_broker.h" - $(INSTALL) ${R}/include/mosquitto_plugin.h "${DESTDIR}${prefix}/include/mosquitto_plugin.h" uninstall : -rm -f "${DESTDIR}${prefix}/sbin/mosquitto" diff --git a/src/bridge.c b/src/bridge.c index f78d03f1..53855176 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -41,7 +41,7 @@ Contributors: #include #endif -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "mosquitto.h" #include "mosquitto_broker_internal.h" #include "mosquitto_internal.h" diff --git a/src/broker_control.c b/src/broker_control.c index c2c0e053..1b040c7f 100644 --- a/src/broker_control.c +++ b/src/broker_control.c @@ -29,11 +29,11 @@ Contributors: #include "json_help.h" #include "mosquitto.h" #include "mosquitto_broker_internal.h" -#include "mosquitto_broker.h" -#include "mosquitto_control.h" -#include "mosquitto_plugin.h" +#include "mosquitto/broker.h" +#include "mosquitto/broker_control.h" +#include "mosquitto/broker_plugin.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" static mosquitto_plugin_id_t plg_id; diff --git a/src/conf.c b/src/conf.c index 11d391ab..287f3625 100644 --- a/src/conf.c +++ b/src/conf.c @@ -47,7 +47,7 @@ Contributors: #include "misc_mosq.h" #include "tls_mosq.h" #include "util_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "utlist.h" diff --git a/src/conf_includedir.c b/src/conf_includedir.c index d8c20519..b5bef3e3 100644 --- a/src/conf_includedir.c +++ b/src/conf_includedir.c @@ -49,7 +49,7 @@ Contributors: #include "memory_mosq.h" #include "tls_mosq.h" #include "util_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" static int scmp_p(const void *p1, const void *p2) diff --git a/src/control.c b/src/control.c index 14e79dde..1db3de9e 100644 --- a/src/control.c +++ b/src/control.c @@ -21,7 +21,7 @@ Contributors: #include #include -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "mosquitto_broker_internal.h" #include "memory_mosq.h" #include "send_mosq.h" diff --git a/src/control_common.c b/src/control_common.c index 25e9e9e1..4f4b5ca5 100644 --- a/src/control_common.c +++ b/src/control_common.c @@ -1,8 +1,8 @@ #include "config.h" -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/handle_auth.c b/src/handle_auth.c index e4c354df..9661974c 100644 --- a/src/handle_auth.c +++ b/src/handle_auth.c @@ -22,7 +22,7 @@ Contributors: #include #include "mosquitto_broker_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/src/handle_connack.c b/src/handle_connack.c index 925084ac..56beebc2 100644 --- a/src/handle_connack.c +++ b/src/handle_connack.c @@ -23,7 +23,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "send_mosq.h" #include "util_mosq.h" diff --git a/src/handle_connect.c b/src/handle_connect.c index 0482e21c..75bec11a 100644 --- a/src/handle_connect.c +++ b/src/handle_connect.c @@ -23,7 +23,7 @@ Contributors: #include #include "mosquitto_broker_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/src/handle_disconnect.c b/src/handle_disconnect.c index c83e7876..fc58943a 100644 --- a/src/handle_disconnect.c +++ b/src/handle_disconnect.c @@ -19,7 +19,7 @@ Contributors: #include "config.h" #include "mosquitto_broker_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "property_mosq.h" #include "send_mosq.h" diff --git a/src/handle_publish.c b/src/handle_publish.c index 471dd997..63eafb2c 100644 --- a/src/handle_publish.c +++ b/src/handle_publish.c @@ -24,7 +24,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "alias_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/src/handle_subscribe.c b/src/handle_subscribe.c index 34c5c275..f7c86b33 100644 --- a/src/handle_subscribe.c +++ b/src/handle_subscribe.c @@ -23,7 +23,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/src/handle_unsubscribe.c b/src/handle_unsubscribe.c index 9b73c0ee..c7ae0524 100644 --- a/src/handle_unsubscribe.c +++ b/src/handle_unsubscribe.c @@ -23,7 +23,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "send_mosq.h" diff --git a/src/http_serv.c b/src/http_serv.c index dcd7c1a4..41e8dbfe 100644 --- a/src/http_serv.c +++ b/src/http_serv.c @@ -27,7 +27,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "base64_mosq.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "net_mosq.h" #include "packet_mosq.h" #include "read_handle.h" diff --git a/src/loop.c b/src/loop.c index 85996e1e..75777d9e 100644 --- a/src/loop.c +++ b/src/loop.c @@ -48,7 +48,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "packet_mosq.h" #include "send_mosq.h" #include "sys_tree.h" diff --git a/src/memory_public.c b/src/memory_public.c index 57533a55..76e6b41d 100644 --- a/src/memory_public.c +++ b/src/memory_public.c @@ -17,7 +17,7 @@ Contributors: */ #include "config.h" -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "memory_mosq.h" BROKER_EXPORT void *mosquitto_calloc(size_t nmemb, size_t size) diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 703dc5ce..a60bb97e 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -35,8 +35,8 @@ Contributors: #endif #include "mosquitto_internal.h" -#include "mosquitto_broker.h" -#include "mosquitto_plugin.h" +#include "mosquitto/broker.h" +#include "mosquitto/broker_plugin.h" #include "mosquitto.h" #include "logging_mosq.h" #include "password_mosq.h" diff --git a/src/net.c b/src/net.c index 12e35927..9f8d1700 100644 --- a/src/net.c +++ b/src/net.c @@ -54,7 +54,7 @@ Contributors: #endif #include "mosquitto_broker_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "misc_mosq.h" #include "net_mosq.h" diff --git a/src/persist_read_v5.c b/src/persist_read_v5.c index 53627bf7..891d99e6 100644 --- a/src/persist_read_v5.c +++ b/src/persist_read_v5.c @@ -33,7 +33,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "persist.h" #include "property_mosq.h" #include "time_mosq.h" diff --git a/src/persist_write_v5.c b/src/persist_write_v5.c index 643e0980..b37bca7f 100644 --- a/src/persist_write_v5.c +++ b/src/persist_write_v5.c @@ -31,7 +31,7 @@ Contributors: #include #include -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "mosquitto_broker_internal.h" #include "memory_mosq.h" #include "persist.h" diff --git a/src/plugin_acl_check.c b/src/plugin_acl_check.c index 219844e2..0d2ea849 100644 --- a/src/plugin_acl_check.c +++ b/src/plugin_acl_check.c @@ -21,9 +21,9 @@ Contributors: #include #include -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "mosquitto_broker_internal.h" -#include "mosquitto_plugin.h" +#include "mosquitto/broker_plugin.h" #include "memory_mosq.h" #include "lib_load.h" #include "utlist.h" diff --git a/src/plugin_basic_auth.c b/src/plugin_basic_auth.c index a7132541..76186732 100644 --- a/src/plugin_basic_auth.c +++ b/src/plugin_basic_auth.c @@ -21,9 +21,9 @@ Contributors: #include #include -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "mosquitto_broker_internal.h" -#include "mosquitto_plugin.h" +#include "mosquitto/broker_plugin.h" #include "memory_mosq.h" #include "lib_load.h" #include "utlist.h" diff --git a/src/plugin_cleanup.c b/src/plugin_cleanup.c index 2c558384..3f44430b 100644 --- a/src/plugin_cleanup.c +++ b/src/plugin_cleanup.c @@ -21,9 +21,9 @@ Contributors: #include #include -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "mosquitto_broker_internal.h" -#include "mosquitto_plugin.h" +#include "mosquitto/broker_plugin.h" #include "memory_mosq.h" #include "lib_load.h" #include "utlist.h" diff --git a/src/plugin_extended_auth.c b/src/plugin_extended_auth.c index 5e024702..bdca9a67 100644 --- a/src/plugin_extended_auth.c +++ b/src/plugin_extended_auth.c @@ -21,9 +21,9 @@ Contributors: #include #include -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "mosquitto_broker_internal.h" -#include "mosquitto_plugin.h" +#include "mosquitto/broker_plugin.h" #include "memory_mosq.h" #include "lib_load.h" #include "utlist.h" diff --git a/src/plugin_init.c b/src/plugin_init.c index bd71db79..5d6717d5 100644 --- a/src/plugin_init.c +++ b/src/plugin_init.c @@ -21,9 +21,9 @@ Contributors: #include #include -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "mosquitto_broker_internal.h" -#include "mosquitto_plugin.h" +#include "mosquitto/broker_plugin.h" #include "memory_mosq.h" #include "lib_load.h" #include "utlist.h" diff --git a/src/plugin_persist.c b/src/plugin_persist.c index 4849800a..fd21233e 100644 --- a/src/plugin_persist.c +++ b/src/plugin_persist.c @@ -20,9 +20,9 @@ Contributors: #include "mosquitto_broker_internal.h" #include "mosquitto_internal.h" -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "send_mosq.h" #include "util_mosq.h" #include "utlist.h" diff --git a/src/plugin_psk_key.c b/src/plugin_psk_key.c index 35d79fbd..306338d3 100644 --- a/src/plugin_psk_key.c +++ b/src/plugin_psk_key.c @@ -21,9 +21,9 @@ Contributors: #include #include -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "mosquitto_broker_internal.h" -#include "mosquitto_plugin.h" +#include "mosquitto/broker_plugin.h" #include "memory_mosq.h" #include "lib_load.h" #include "utlist.h" diff --git a/src/plugin_public.c b/src/plugin_public.c index 4af1271f..1039cc0a 100644 --- a/src/plugin_public.c +++ b/src/plugin_public.c @@ -20,7 +20,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "send_mosq.h" #include "util_mosq.h" #include "will_mosq.h" diff --git a/src/plugin_tick.c b/src/plugin_tick.c index 15e47ad7..c2120c16 100644 --- a/src/plugin_tick.c +++ b/src/plugin_tick.c @@ -21,7 +21,7 @@ Contributors: #include #include "mosquitto_broker_internal.h" -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "time_mosq.h" #include "utlist.h" diff --git a/src/plugin_v2.c b/src/plugin_v2.c index b3fe1da1..570775c0 100644 --- a/src/plugin_v2.c +++ b/src/plugin_v2.c @@ -23,9 +23,9 @@ Contributors: #include #include -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "mosquitto_broker_internal.h" -#include "mosquitto_plugin.h" +#include "mosquitto/broker_plugin.h" #include "memory_mosq.h" #include "lib_load.h" #include "utlist.h" diff --git a/src/plugin_v3.c b/src/plugin_v3.c index b95a07fc..da63deb6 100644 --- a/src/plugin_v3.c +++ b/src/plugin_v3.c @@ -23,9 +23,9 @@ Contributors: #include #include -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "mosquitto_broker_internal.h" -#include "mosquitto_plugin.h" +#include "mosquitto/broker_plugin.h" #include "memory_mosq.h" #include "lib_load.h" #include "utlist.h" diff --git a/src/plugin_v4.c b/src/plugin_v4.c index 63fb3636..96c69fc6 100644 --- a/src/plugin_v4.c +++ b/src/plugin_v4.c @@ -23,9 +23,9 @@ Contributors: #include #include -#include "mosquitto_broker.h" +#include "mosquitto/broker.h" #include "mosquitto_broker_internal.h" -#include "mosquitto_plugin.h" +#include "mosquitto/broker_plugin.h" #include "memory_mosq.h" #include "lib_load.h" #include "utlist.h" diff --git a/src/property_broker.c b/src/property_broker.c index 8ebe87f0..b484beca 100644 --- a/src/property_broker.c +++ b/src/property_broker.c @@ -23,7 +23,7 @@ Contributors: #include #include "mosquitto_broker_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "property_mosq.h" /* Process the incoming properties, we should be able to assume that only valid diff --git a/src/read_handle.c b/src/read_handle.c index 16143179..d57393fd 100644 --- a/src/read_handle.c +++ b/src/read_handle.c @@ -23,7 +23,7 @@ Contributors: #include #include "mosquitto_broker_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "packet_mosq.h" #include "read_handle.h" diff --git a/src/retain.c b/src/retain.c index 5d9401cc..c3d7cdd9 100644 --- a/src/retain.c +++ b/src/retain.c @@ -24,7 +24,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "util_mosq.h" #include "utlist.h" diff --git a/src/security_default.c b/src/security_default.c index 4f234026..e3812ae3 100644 --- a/src/security_default.c +++ b/src/security_default.c @@ -24,7 +24,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "send_mosq.h" #include "base64_mosq.h" #include "misc_mosq.h" diff --git a/src/send_auth.c b/src/send_auth.c index 87b462e4..6bfdc1b7 100644 --- a/src/send_auth.c +++ b/src/send_auth.c @@ -19,7 +19,7 @@ Contributors: #include "config.h" #include "mosquitto_broker_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/src/send_connack.c b/src/send_connack.c index e41a0743..c336e0c0 100644 --- a/src/send_connack.c +++ b/src/send_connack.c @@ -19,7 +19,7 @@ Contributors: #include "config.h" #include "mosquitto_broker_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/src/send_suback.c b/src/send_suback.c index dd3cf312..80430ebb 100644 --- a/src/send_suback.c +++ b/src/send_suback.c @@ -19,7 +19,7 @@ Contributors: #include "config.h" #include "mosquitto_broker_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/src/send_unsuback.c b/src/send_unsuback.c index 2cd67eaf..bd56f9b7 100644 --- a/src/send_unsuback.c +++ b/src/send_unsuback.c @@ -21,7 +21,7 @@ Contributors: #include #include "mosquitto_broker_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "packet_mosq.h" #include "property_mosq.h" diff --git a/src/subs.c b/src/subs.c index c4c8ac8b..261a9933 100644 --- a/src/subs.c +++ b/src/subs.c @@ -55,7 +55,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "util_mosq.h" #include "utlist.h" diff --git a/src/topic_tok.c b/src/topic_tok.c index a1944967..c8d8651c 100644 --- a/src/topic_tok.c +++ b/src/topic_tok.c @@ -24,7 +24,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "memory_mosq.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "util_mosq.h" #include "utlist.h" diff --git a/src/websockets.c b/src/websockets.c index d8110d72..27159517 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -25,7 +25,7 @@ Contributors: #endif #include "mosquitto_internal.h" #include "mosquitto_broker_internal.h" -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "packet_mosq.h" #include "sys_tree.h" diff --git a/test/broker/c/auth_plugin_acl.c b/test/broker/c/auth_plugin_acl.c index 95737579..c244f3b8 100644 --- a/test/broker/c/auth_plugin_acl.c +++ b/test/broker/c/auth_plugin_acl.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/auth_plugin_acl_change.c b/test/broker/c/auth_plugin_acl_change.c index 18e4d7b4..7889f62e 100644 --- a/test/broker/c/auth_plugin_acl_change.c +++ b/test/broker/c/auth_plugin_acl_change.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_acl_check_v5(int event, void *event_data, void *user_data); int mosquitto_auth_unpwd_check_v5(int event, void *event_data, void *user_data); diff --git a/test/broker/c/auth_plugin_acl_sub_denied.c b/test/broker/c/auth_plugin_acl_sub_denied.c index 89132934..00472adb 100644 --- a/test/broker/c/auth_plugin_acl_sub_denied.c +++ b/test/broker/c/auth_plugin_acl_sub_denied.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/auth_plugin_context_params.c b/test/broker/c/auth_plugin_context_params.c index 611e3f05..f6ec41f0 100644 --- a/test/broker/c/auth_plugin_context_params.c +++ b/test/broker/c/auth_plugin_context_params.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/auth_plugin_delayed.c b/test/broker/c/auth_plugin_delayed.c index 76f07580..673a90b1 100644 --- a/test/broker/c/auth_plugin_delayed.c +++ b/test/broker/c/auth_plugin_delayed.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include static int tick_callback(int event, void *event_data, void *user_data); static int unpwd_check_callback(int event, void *event_data, void *user_data); diff --git a/test/broker/c/auth_plugin_extended_multiple.c b/test/broker/c/auth_plugin_extended_multiple.c index a6120c25..02c94190 100644 --- a/test/broker/c/auth_plugin_extended_multiple.c +++ b/test/broker/c/auth_plugin_extended_multiple.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/auth_plugin_extended_reauth.c b/test/broker/c/auth_plugin_extended_reauth.c index e48ad80e..59ed4ae0 100644 --- a/test/broker/c/auth_plugin_extended_reauth.c +++ b/test/broker/c/auth_plugin_extended_reauth.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include #define UNUSED(A) (void)(A) diff --git a/test/broker/c/auth_plugin_extended_single.c b/test/broker/c/auth_plugin_extended_single.c index b0e684bb..5c518eac 100644 --- a/test/broker/c/auth_plugin_extended_single.c +++ b/test/broker/c/auth_plugin_extended_single.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/auth_plugin_extended_single2.c b/test/broker/c/auth_plugin_extended_single2.c index 89b371d9..552296a4 100644 --- a/test/broker/c/auth_plugin_extended_single2.c +++ b/test/broker/c/auth_plugin_extended_single2.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/auth_plugin_id_change.c b/test/broker/c/auth_plugin_id_change.c index 1709676a..1194dc2f 100644 --- a/test/broker/c/auth_plugin_id_change.c +++ b/test/broker/c/auth_plugin_id_change.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_acl_check_v5(int event, void *event_data, void *user_data); int mosquitto_auth_unpwd_check_v5(int event, void *event_data, void *user_data); diff --git a/test/broker/c/auth_plugin_msg_params.c b/test/broker/c/auth_plugin_msg_params.c index 840e6b3f..b4addc48 100644 --- a/test/broker/c/auth_plugin_msg_params.c +++ b/test/broker/c/auth_plugin_msg_params.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/auth_plugin_publish.c b/test/broker/c/auth_plugin_publish.c index 118f2e8e..517b5c2d 100644 --- a/test/broker/c/auth_plugin_publish.c +++ b/test/broker/c/auth_plugin_publish.c @@ -1,10 +1,10 @@ #include #include #include -#include +#include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/auth_plugin_pwd.c b/test/broker/c/auth_plugin_pwd.c index 2b26b6b3..d989e3cd 100644 --- a/test/broker/c/auth_plugin_pwd.c +++ b/test/broker/c/auth_plugin_pwd.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/auth_plugin_v3.c b/test/broker/c/auth_plugin_v3.c index e3b0661c..cb10139a 100644 --- a/test/broker/c/auth_plugin_v3.c +++ b/test/broker/c/auth_plugin_v3.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/auth_plugin_v4.c b/test/broker/c/auth_plugin_v4.c index 0167af90..c16ff676 100644 --- a/test/broker/c/auth_plugin_v4.c +++ b/test/broker/c/auth_plugin_v4.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/auth_plugin_v5.c b/test/broker/c/auth_plugin_v5.c index 8491c9d6..b861d0b7 100644 --- a/test/broker/c/auth_plugin_v5.c +++ b/test/broker/c/auth_plugin_v5.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_acl_check_v5(int event, void *event_data, void *user_data); int mosquitto_auth_unpwd_check_v5(int event, void *event_data, void *user_data); diff --git a/test/broker/c/auth_plugin_v5_control.c b/test/broker/c/auth_plugin_v5_control.c index 5c18c5bd..e349922e 100644 --- a/test/broker/c/auth_plugin_v5_control.c +++ b/test/broker/c/auth_plugin_v5_control.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_acl_check_v5(int event, void *event_data, void *user_data); int mosquitto_auth_unpwd_check_v5(int event, void *event_data, void *user_data); diff --git a/test/broker/c/bad_v1.c b/test/broker/c/bad_v1.c index 9469c2dd..fb5196d1 100644 --- a/test/broker/c/bad_v1.c +++ b/test/broker/c/bad_v1.c @@ -2,7 +2,7 @@ #include #include #include -#include -#include +#include +#include MOSQUITTO_PLUGIN_DECLARE_VERSION(1); diff --git a/test/broker/c/bad_v3_1.c b/test/broker/c/bad_v3_1.c index d67f8732..c7b20f2d 100644 --- a/test/broker/c/bad_v3_1.c +++ b/test/broker/c/bad_v3_1.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/bad_v3_2.c b/test/broker/c/bad_v3_2.c index 26aea6a5..a0b8d846 100644 --- a/test/broker/c/bad_v3_2.c +++ b/test/broker/c/bad_v3_2.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/bad_v3_3.c b/test/broker/c/bad_v3_3.c index 4a9bb481..94a48578 100644 --- a/test/broker/c/bad_v3_3.c +++ b/test/broker/c/bad_v3_3.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/bad_v3_4.c b/test/broker/c/bad_v3_4.c index 526bb75b..36a1007e 100644 --- a/test/broker/c/bad_v3_4.c +++ b/test/broker/c/bad_v3_4.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/bad_v3_5.c b/test/broker/c/bad_v3_5.c index be503814..4d082184 100644 --- a/test/broker/c/bad_v3_5.c +++ b/test/broker/c/bad_v3_5.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/bad_v3_6.c b/test/broker/c/bad_v3_6.c index c2e968e6..a5138a57 100644 --- a/test/broker/c/bad_v3_6.c +++ b/test/broker/c/bad_v3_6.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/bad_v3_7.c b/test/broker/c/bad_v3_7.c index 4ae0c058..cbf04901 100644 --- a/test/broker/c/bad_v3_7.c +++ b/test/broker/c/bad_v3_7.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/bad_v4_1.c b/test/broker/c/bad_v4_1.c index 55064a70..f7435347 100644 --- a/test/broker/c/bad_v4_1.c +++ b/test/broker/c/bad_v4_1.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/bad_v4_2.c b/test/broker/c/bad_v4_2.c index 02752caa..44d0a63b 100644 --- a/test/broker/c/bad_v4_2.c +++ b/test/broker/c/bad_v4_2.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/bad_v4_3.c b/test/broker/c/bad_v4_3.c index 274f4a92..da09da6a 100644 --- a/test/broker/c/bad_v4_3.c +++ b/test/broker/c/bad_v4_3.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/bad_v4_4.c b/test/broker/c/bad_v4_4.c index 8933a6b0..dccd9d98 100644 --- a/test/broker/c/bad_v4_4.c +++ b/test/broker/c/bad_v4_4.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include int mosquitto_auth_plugin_version(void) { diff --git a/test/broker/c/bad_v5_1.c b/test/broker/c/bad_v5_1.c index 8305f98d..c5e0d3c6 100644 --- a/test/broker/c/bad_v5_1.c +++ b/test/broker/c/bad_v5_1.c @@ -2,7 +2,7 @@ #include #include #include -#include -#include +#include +#include MOSQUITTO_PLUGIN_DECLARE_VERSION(5); diff --git a/test/broker/c/bad_v6.c b/test/broker/c/bad_v6.c index 613a26f0..9d1e7c54 100644 --- a/test/broker/c/bad_v6.c +++ b/test/broker/c/bad_v6.c @@ -2,7 +2,7 @@ #include #include #include -#include -#include +#include +#include MOSQUITTO_PLUGIN_DECLARE_VERSION(6); diff --git a/test/broker/c/plugin_control.c b/test/broker/c/plugin_control.c index 2936c3c5..3ebfb178 100644 --- a/test/broker/c/plugin_control.c +++ b/test/broker/c/plugin_control.c @@ -1,10 +1,10 @@ #include #include #include -#include +#include #include -#include -#include +#include +#include static mosquitto_plugin_id_t *plg_id = NULL; diff --git a/test/broker/c/plugin_evt_client_offline.c b/test/broker/c/plugin_evt_client_offline.c index b1cd2ed9..0550d52d 100644 --- a/test/broker/c/plugin_evt_client_offline.c +++ b/test/broker/c/plugin_evt_client_offline.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include MOSQUITTO_PLUGIN_DECLARE_VERSION(5); diff --git a/test/broker/c/plugin_evt_message_in.c b/test/broker/c/plugin_evt_message_in.c index 0228d5e2..74b3147d 100644 --- a/test/broker/c/plugin_evt_message_in.c +++ b/test/broker/c/plugin_evt_message_in.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include MOSQUITTO_PLUGIN_DECLARE_VERSION(5); diff --git a/test/broker/c/plugin_evt_message_out.c b/test/broker/c/plugin_evt_message_out.c index 0de684c2..bd2fefc4 100644 --- a/test/broker/c/plugin_evt_message_out.c +++ b/test/broker/c/plugin_evt_message_out.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include MOSQUITTO_PLUGIN_DECLARE_VERSION(5); diff --git a/test/broker/c/plugin_evt_persist_client_update.c b/test/broker/c/plugin_evt_persist_client_update.c index 474b60d4..1cadd4b6 100644 --- a/test/broker/c/plugin_evt_persist_client_update.c +++ b/test/broker/c/plugin_evt_persist_client_update.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include MOSQUITTO_PLUGIN_DECLARE_VERSION(5); diff --git a/test/broker/c/plugin_evt_psk_key.c b/test/broker/c/plugin_evt_psk_key.c index 65b8b835..67f1346a 100644 --- a/test/broker/c/plugin_evt_psk_key.c +++ b/test/broker/c/plugin_evt_psk_key.c @@ -1,10 +1,10 @@ #include #include #include -#include +#include #include -#include -#include +#include +#include #define UNUSED(A) (void)(A) diff --git a/test/broker/c/plugin_evt_subscribe.c b/test/broker/c/plugin_evt_subscribe.c index 6ea66fb5..db3443d6 100644 --- a/test/broker/c/plugin_evt_subscribe.c +++ b/test/broker/c/plugin_evt_subscribe.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include MOSQUITTO_PLUGIN_DECLARE_VERSION(5); diff --git a/test/broker/c/plugin_evt_tick.c b/test/broker/c/plugin_evt_tick.c index f1dc03d1..f00b6962 100644 --- a/test/broker/c/plugin_evt_tick.c +++ b/test/broker/c/plugin_evt_tick.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include #define UNUSED(A) (void)(A) diff --git a/test/broker/c/plugin_evt_unsubscribe.c b/test/broker/c/plugin_evt_unsubscribe.c index 8ddc7921..9f0fc0db 100644 --- a/test/broker/c/plugin_evt_unsubscribe.c +++ b/test/broker/c/plugin_evt_unsubscribe.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include MOSQUITTO_PLUGIN_DECLARE_VERSION(5); diff --git a/test/lib/c/01-con-discon-success-v5.c b/test/lib/c/01-con-discon-success-v5.c index b46bb8cb..5add4f1d 100644 --- a/test/lib/c/01-con-discon-success-v5.c +++ b/test/lib/c/01-con-discon-success-v5.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include static int run = -1; diff --git a/test/lib/c/01-con-discon-will-v5.c b/test/lib/c/01-con-discon-will-v5.c index b4199cf7..d3d382fb 100644 --- a/test/lib/c/01-con-discon-will-v5.c +++ b/test/lib/c/01-con-discon-will-v5.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include static int run = -1; diff --git a/test/lib/c/03-request-response-1.c b/test/lib/c/03-request-response-1.c index 4a381d5a..4314705c 100644 --- a/test/lib/c/03-request-response-1.c +++ b/test/lib/c/03-request-response-1.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #define QOS 0 diff --git a/test/lib/c/03-request-response-2.c b/test/lib/c/03-request-response-2.c index b8a51924..3f0ddf94 100644 --- a/test/lib/c/03-request-response-2.c +++ b/test/lib/c/03-request-response-2.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include static int run = -1; diff --git a/test/lib/c/03-request-response-correlation-1.c b/test/lib/c/03-request-response-correlation-1.c index 7dde9a93..20d0d68a 100644 --- a/test/lib/c/03-request-response-correlation-1.c +++ b/test/lib/c/03-request-response-correlation-1.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #define QOS 0 diff --git a/test/lib/c/11-prop-recv.c b/test/lib/c/11-prop-recv.c index 9232b4ec..7a1b9437 100644 --- a/test/lib/c/11-prop-recv.c +++ b/test/lib/c/11-prop-recv.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include static int run = -1; static int qos = -1; diff --git a/test/lib/c/11-prop-send-content-type.c b/test/lib/c/11-prop-send-content-type.c index 23274b38..466e06f0 100644 --- a/test/lib/c/11-prop-send-content-type.c +++ b/test/lib/c/11-prop-send-content-type.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include static int run = -1; static int sent_mid = -1; diff --git a/test/lib/c/11-prop-send-payload-format.c b/test/lib/c/11-prop-send-payload-format.c index 252a7db9..98739f85 100644 --- a/test/lib/c/11-prop-send-payload-format.c +++ b/test/lib/c/11-prop-send-payload-format.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include static int run = -1; static int sent_mid = -1; diff --git a/test/lib/cpp/01-con-discon-success-v5.cpp b/test/lib/cpp/01-con-discon-success-v5.cpp index 1b199a9c..7949e40e 100644 --- a/test/lib/cpp/01-con-discon-success-v5.cpp +++ b/test/lib/cpp/01-con-discon-success-v5.cpp @@ -1,5 +1,5 @@ #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/01-con-discon-success.cpp b/test/lib/cpp/01-con-discon-success.cpp index 6bbc05a1..59288d78 100644 --- a/test/lib/cpp/01-con-discon-success.cpp +++ b/test/lib/cpp/01-con-discon-success.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/01-con-discon-will-clear.cpp b/test/lib/cpp/01-con-discon-will-clear.cpp index 90b5a740..a12b9d0f 100644 --- a/test/lib/cpp/01-con-discon-will-clear.cpp +++ b/test/lib/cpp/01-con-discon-will-clear.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/01-con-discon-will-v5.cpp b/test/lib/cpp/01-con-discon-will-v5.cpp index 19bd70b4..42b31c2d 100644 --- a/test/lib/cpp/01-con-discon-will-v5.cpp +++ b/test/lib/cpp/01-con-discon-will-v5.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/01-con-discon-will.cpp b/test/lib/cpp/01-con-discon-will.cpp index 36ed4c58..ea807a03 100644 --- a/test/lib/cpp/01-con-discon-will.cpp +++ b/test/lib/cpp/01-con-discon-will.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/01-keepalive-pingreq.cpp b/test/lib/cpp/01-keepalive-pingreq.cpp index c2faddb7..867b8c81 100644 --- a/test/lib/cpp/01-keepalive-pingreq.cpp +++ b/test/lib/cpp/01-keepalive-pingreq.cpp @@ -1,5 +1,5 @@ #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/01-no-clean-session.cpp b/test/lib/cpp/01-no-clean-session.cpp index 8b24f5d9..799703ef 100644 --- a/test/lib/cpp/01-no-clean-session.cpp +++ b/test/lib/cpp/01-no-clean-session.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/01-pre-connect-callback.cpp b/test/lib/cpp/01-pre-connect-callback.cpp index 9624ba02..9519efbb 100644 --- a/test/lib/cpp/01-pre-connect-callback.cpp +++ b/test/lib/cpp/01-pre-connect-callback.cpp @@ -1,5 +1,5 @@ #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/01-server-keepalive-pingreq.cpp b/test/lib/cpp/01-server-keepalive-pingreq.cpp index 882a7d25..f66ca7a8 100644 --- a/test/lib/cpp/01-server-keepalive-pingreq.cpp +++ b/test/lib/cpp/01-server-keepalive-pingreq.cpp @@ -1,5 +1,5 @@ #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/01-unpwd-set.cpp b/test/lib/cpp/01-unpwd-set.cpp index f6b891fe..95af1ad7 100644 --- a/test/lib/cpp/01-unpwd-set.cpp +++ b/test/lib/cpp/01-unpwd-set.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/01-will-set.cpp b/test/lib/cpp/01-will-set.cpp index deae697f..df4f0c14 100644 --- a/test/lib/cpp/01-will-set.cpp +++ b/test/lib/cpp/01-will-set.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/01-will-unpwd-set.cpp b/test/lib/cpp/01-will-unpwd-set.cpp index eac4253f..3b58f615 100644 --- a/test/lib/cpp/01-will-unpwd-set.cpp +++ b/test/lib/cpp/01-will-unpwd-set.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/02-subscribe-helper-callback-qos2.cpp b/test/lib/cpp/02-subscribe-helper-callback-qos2.cpp index 57b58ba9..8d76156e 100644 --- a/test/lib/cpp/02-subscribe-helper-callback-qos2.cpp +++ b/test/lib/cpp/02-subscribe-helper-callback-qos2.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #define QOS 2 static int mydata = 1; diff --git a/test/lib/cpp/02-subscribe-helper-simple-qos2.cpp b/test/lib/cpp/02-subscribe-helper-simple-qos2.cpp index d880bb50..e7a0d162 100644 --- a/test/lib/cpp/02-subscribe-helper-simple-qos2.cpp +++ b/test/lib/cpp/02-subscribe-helper-simple-qos2.cpp @@ -1,5 +1,5 @@ #include -#include +#include #define QOS 2 diff --git a/test/lib/cpp/02-subscribe-qos0.cpp b/test/lib/cpp/02-subscribe-qos0.cpp index b60b4413..bbbc59ff 100644 --- a/test/lib/cpp/02-subscribe-qos0.cpp +++ b/test/lib/cpp/02-subscribe-qos0.cpp @@ -1,5 +1,5 @@ #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/02-subscribe-qos1-async1.cpp b/test/lib/cpp/02-subscribe-qos1-async1.cpp index 2a9cc75e..6fa4c57f 100644 --- a/test/lib/cpp/02-subscribe-qos1-async1.cpp +++ b/test/lib/cpp/02-subscribe-qos1-async1.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include /* mosquitto_connect_async() test, with mosquitto_loop_start() called before mosquitto_connect_async(). */ diff --git a/test/lib/cpp/02-subscribe-qos1-async2.cpp b/test/lib/cpp/02-subscribe-qos1-async2.cpp index 17da80be..f691e201 100644 --- a/test/lib/cpp/02-subscribe-qos1-async2.cpp +++ b/test/lib/cpp/02-subscribe-qos1-async2.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include /* mosquitto_connect_async() test, with mosquitto_loop_start() called after mosquitto_connect_async(). */ diff --git a/test/lib/cpp/02-subscribe-qos1.cpp b/test/lib/cpp/02-subscribe-qos1.cpp index 4b65dac3..94747e3e 100644 --- a/test/lib/cpp/02-subscribe-qos1.cpp +++ b/test/lib/cpp/02-subscribe-qos1.cpp @@ -1,5 +1,5 @@ #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/02-subscribe-qos2.cpp b/test/lib/cpp/02-subscribe-qos2.cpp index aae10abf..16295672 100644 --- a/test/lib/cpp/02-subscribe-qos2.cpp +++ b/test/lib/cpp/02-subscribe-qos2.cpp @@ -1,5 +1,5 @@ #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/02-unsubscribe-v5.cpp b/test/lib/cpp/02-unsubscribe-v5.cpp index 0defed87..7c52c0f3 100644 --- a/test/lib/cpp/02-unsubscribe-v5.cpp +++ b/test/lib/cpp/02-unsubscribe-v5.cpp @@ -1,5 +1,5 @@ #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/02-unsubscribe.cpp b/test/lib/cpp/02-unsubscribe.cpp index 26158aaa..9ce41a44 100644 --- a/test/lib/cpp/02-unsubscribe.cpp +++ b/test/lib/cpp/02-unsubscribe.cpp @@ -1,5 +1,5 @@ #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-b2c-qos1-unexpected-puback.cpp b/test/lib/cpp/03-publish-b2c-qos1-unexpected-puback.cpp index 307fa0d1..bff8fc50 100644 --- a/test/lib/cpp/03-publish-b2c-qos1-unexpected-puback.cpp +++ b/test/lib/cpp/03-publish-b2c-qos1-unexpected-puback.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include class mosquittopp_test : public mosqpp::mosquittopp { diff --git a/test/lib/cpp/03-publish-b2c-qos1.cpp b/test/lib/cpp/03-publish-b2c-qos1.cpp index beabc29a..1e4c8fb7 100644 --- a/test/lib/cpp/03-publish-b2c-qos1.cpp +++ b/test/lib/cpp/03-publish-b2c-qos1.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include class mosquittopp_test : public mosqpp::mosquittopp { diff --git a/test/lib/cpp/03-publish-b2c-qos2-len.cpp b/test/lib/cpp/03-publish-b2c-qos2-len.cpp index 2b06c8cb..226d5303 100644 --- a/test/lib/cpp/03-publish-b2c-qos2-len.cpp +++ b/test/lib/cpp/03-publish-b2c-qos2-len.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-b2c-qos2-unexpected-pubcomp.cpp b/test/lib/cpp/03-publish-b2c-qos2-unexpected-pubcomp.cpp index 2ef2f988..66fca997 100644 --- a/test/lib/cpp/03-publish-b2c-qos2-unexpected-pubcomp.cpp +++ b/test/lib/cpp/03-publish-b2c-qos2-unexpected-pubcomp.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-b2c-qos2-unexpected-pubrel.cpp b/test/lib/cpp/03-publish-b2c-qos2-unexpected-pubrel.cpp index c659d2cf..7f5a435d 100644 --- a/test/lib/cpp/03-publish-b2c-qos2-unexpected-pubrel.cpp +++ b/test/lib/cpp/03-publish-b2c-qos2-unexpected-pubrel.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-b2c-qos2.cpp b/test/lib/cpp/03-publish-b2c-qos2.cpp index b75ab7cf..c047a8df 100644 --- a/test/lib/cpp/03-publish-b2c-qos2.cpp +++ b/test/lib/cpp/03-publish-b2c-qos2.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-c2b-qos1-disconnect.cpp b/test/lib/cpp/03-publish-c2b-qos1-disconnect.cpp index ad9b9431..790ea901 100644 --- a/test/lib/cpp/03-publish-c2b-qos1-disconnect.cpp +++ b/test/lib/cpp/03-publish-c2b-qos1-disconnect.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include static int run = -1; static int first_connection = 1; diff --git a/test/lib/cpp/03-publish-c2b-qos1-len.cpp b/test/lib/cpp/03-publish-c2b-qos1-len.cpp index 484486a4..5878320d 100644 --- a/test/lib/cpp/03-publish-c2b-qos1-len.cpp +++ b/test/lib/cpp/03-publish-c2b-qos1-len.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-c2b-qos1-receive-maximum.cpp b/test/lib/cpp/03-publish-c2b-qos1-receive-maximum.cpp index 6feb0654..15404b65 100644 --- a/test/lib/cpp/03-publish-c2b-qos1-receive-maximum.cpp +++ b/test/lib/cpp/03-publish-c2b-qos1-receive-maximum.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-c2b-qos2-disconnect.cpp b/test/lib/cpp/03-publish-c2b-qos2-disconnect.cpp index fe85abfe..a0e85181 100644 --- a/test/lib/cpp/03-publish-c2b-qos2-disconnect.cpp +++ b/test/lib/cpp/03-publish-c2b-qos2-disconnect.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include static int run = -1; static int first_connection = 1; diff --git a/test/lib/cpp/03-publish-c2b-qos2-len.cpp b/test/lib/cpp/03-publish-c2b-qos2-len.cpp index d86cb77e..5ae6617b 100644 --- a/test/lib/cpp/03-publish-c2b-qos2-len.cpp +++ b/test/lib/cpp/03-publish-c2b-qos2-len.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include static int run = -1; static int sent_mid = -1; diff --git a/test/lib/cpp/03-publish-c2b-qos2-maximum-qos-0.cpp b/test/lib/cpp/03-publish-c2b-qos2-maximum-qos-0.cpp index 2f53829e..54d77cc9 100644 --- a/test/lib/cpp/03-publish-c2b-qos2-maximum-qos-0.cpp +++ b/test/lib/cpp/03-publish-c2b-qos2-maximum-qos-0.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-c2b-qos2-maximum-qos-1.cpp b/test/lib/cpp/03-publish-c2b-qos2-maximum-qos-1.cpp index 2613b449..941d617b 100644 --- a/test/lib/cpp/03-publish-c2b-qos2-maximum-qos-1.cpp +++ b/test/lib/cpp/03-publish-c2b-qos2-maximum-qos-1.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-c2b-qos2-pubrec-error.cpp b/test/lib/cpp/03-publish-c2b-qos2-pubrec-error.cpp index f66b2c84..550cede0 100644 --- a/test/lib/cpp/03-publish-c2b-qos2-pubrec-error.cpp +++ b/test/lib/cpp/03-publish-c2b-qos2-pubrec-error.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-c2b-qos2-receive-maximum.cpp b/test/lib/cpp/03-publish-c2b-qos2-receive-maximum.cpp index df9a44d2..87f56fae 100644 --- a/test/lib/cpp/03-publish-c2b-qos2-receive-maximum.cpp +++ b/test/lib/cpp/03-publish-c2b-qos2-receive-maximum.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-c2b-qos2.cpp b/test/lib/cpp/03-publish-c2b-qos2.cpp index 11f9dc6a..82078002 100644 --- a/test/lib/cpp/03-publish-c2b-qos2.cpp +++ b/test/lib/cpp/03-publish-c2b-qos2.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include static int run = -1; static int sent_mid = -1; diff --git a/test/lib/cpp/03-publish-loop-forever.cpp b/test/lib/cpp/03-publish-loop-forever.cpp index b59b8d82..0eb413c2 100644 --- a/test/lib/cpp/03-publish-loop-forever.cpp +++ b/test/lib/cpp/03-publish-loop-forever.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-loop-manual.cpp b/test/lib/cpp/03-publish-loop-manual.cpp index 1145a6cc..4ddfce64 100644 --- a/test/lib/cpp/03-publish-loop-manual.cpp +++ b/test/lib/cpp/03-publish-loop-manual.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-loop-start.cpp b/test/lib/cpp/03-publish-loop-start.cpp index 4b7734d4..dd698c88 100644 --- a/test/lib/cpp/03-publish-loop-start.cpp +++ b/test/lib/cpp/03-publish-loop-start.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-loop.cpp b/test/lib/cpp/03-publish-loop.cpp index 03b5772a..89bd3467 100644 --- a/test/lib/cpp/03-publish-loop.cpp +++ b/test/lib/cpp/03-publish-loop.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include static int run = -1; diff --git a/test/lib/cpp/03-publish-qos0-no-payload.cpp b/test/lib/cpp/03-publish-qos0-no-payload.cpp index d3cdc6a7..a65abc8f 100644 --- a/test/lib/cpp/03-publish-qos0-no-payload.cpp +++ b/test/lib/cpp/03-publish-qos0-no-payload.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include static int run = -1; static int sent_mid = -1; diff --git a/test/lib/cpp/03-publish-qos0.cpp b/test/lib/cpp/03-publish-qos0.cpp index f437a56a..b42b3bc4 100644 --- a/test/lib/cpp/03-publish-qos0.cpp +++ b/test/lib/cpp/03-publish-qos0.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include static int sent_mid = -1; diff --git a/test/lib/cpp/03-request-response-1.cpp b/test/lib/cpp/03-request-response-1.cpp index 5988e261..4b8574b6 100644 --- a/test/lib/cpp/03-request-response-1.cpp +++ b/test/lib/cpp/03-request-response-1.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #define QOS 0 diff --git a/test/lib/cpp/03-request-response-2.cpp b/test/lib/cpp/03-request-response-2.cpp index c6d860ac..3432c24d 100644 --- a/test/lib/cpp/03-request-response-2.cpp +++ b/test/lib/cpp/03-request-response-2.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #define QOS 0 diff --git a/test/lib/cpp/03-request-response-correlation-1.cpp b/test/lib/cpp/03-request-response-correlation-1.cpp index 7b3759b8..acd64309 100644 --- a/test/lib/cpp/03-request-response-correlation-1.cpp +++ b/test/lib/cpp/03-request-response-correlation-1.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #define QOS 0 diff --git a/test/lib/cpp/04-retain-qos0.cpp b/test/lib/cpp/04-retain-qos0.cpp index d3aa1954..14148e28 100644 --- a/test/lib/cpp/04-retain-qos0.cpp +++ b/test/lib/cpp/04-retain-qos0.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include static int run = -1; static int sent_mid = -1; diff --git a/test/lib/cpp/08-ssl-bad-cacert.cpp b/test/lib/cpp/08-ssl-bad-cacert.cpp index df3ff1ac..0522e75c 100644 --- a/test/lib/cpp/08-ssl-bad-cacert.cpp +++ b/test/lib/cpp/08-ssl-bad-cacert.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include "path_helper.h" class mosquittopp_test : public mosqpp::mosquittopp diff --git a/test/lib/cpp/08-ssl-connect-cert-auth-custom-ssl-ctx-default.cpp b/test/lib/cpp/08-ssl-connect-cert-auth-custom-ssl-ctx-default.cpp index 8bbda885..6c2a1790 100644 --- a/test/lib/cpp/08-ssl-connect-cert-auth-custom-ssl-ctx-default.cpp +++ b/test/lib/cpp/08-ssl-connect-cert-auth-custom-ssl-ctx-default.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include "path_helper.h" diff --git a/test/lib/cpp/08-ssl-connect-cert-auth-custom-ssl-ctx.cpp b/test/lib/cpp/08-ssl-connect-cert-auth-custom-ssl-ctx.cpp index 9497c586..b59d43cb 100644 --- a/test/lib/cpp/08-ssl-connect-cert-auth-custom-ssl-ctx.cpp +++ b/test/lib/cpp/08-ssl-connect-cert-auth-custom-ssl-ctx.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include "path_helper.h" diff --git a/test/lib/cpp/08-ssl-connect-cert-auth-enc.cpp b/test/lib/cpp/08-ssl-connect-cert-auth-enc.cpp index d8a93fa9..4ee68343 100644 --- a/test/lib/cpp/08-ssl-connect-cert-auth-enc.cpp +++ b/test/lib/cpp/08-ssl-connect-cert-auth-enc.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include "path_helper.h" static int run = -1; diff --git a/test/lib/cpp/08-ssl-connect-cert-auth.cpp b/test/lib/cpp/08-ssl-connect-cert-auth.cpp index c62e6f45..b635f6ed 100644 --- a/test/lib/cpp/08-ssl-connect-cert-auth.cpp +++ b/test/lib/cpp/08-ssl-connect-cert-auth.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include "path_helper.h" static int run = -1; diff --git a/test/lib/cpp/08-ssl-connect-no-auth.cpp b/test/lib/cpp/08-ssl-connect-no-auth.cpp index e58a85ec..c398a988 100644 --- a/test/lib/cpp/08-ssl-connect-no-auth.cpp +++ b/test/lib/cpp/08-ssl-connect-no-auth.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include "path_helper.h" static int run = -1; diff --git a/test/lib/cpp/08-ssl-connect-san.cpp b/test/lib/cpp/08-ssl-connect-san.cpp index 8f7e9f98..f466a4e7 100644 --- a/test/lib/cpp/08-ssl-connect-san.cpp +++ b/test/lib/cpp/08-ssl-connect-san.cpp @@ -1,6 +1,6 @@ #include #include "path_helper.h" -#include +#include #include "path_helper.h" static int run = -1; diff --git a/test/lib/cpp/08-ssl-fake-cacert.cpp b/test/lib/cpp/08-ssl-fake-cacert.cpp index e4db25e9..667f9639 100644 --- a/test/lib/cpp/08-ssl-fake-cacert.cpp +++ b/test/lib/cpp/08-ssl-fake-cacert.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include "path_helper.h" class mosquittopp_test : public mosqpp::mosquittopp diff --git a/test/lib/cpp/09-util-topic-tokenise.cpp b/test/lib/cpp/09-util-topic-tokenise.cpp index 571c0553..fc66c5f4 100644 --- a/test/lib/cpp/09-util-topic-tokenise.cpp +++ b/test/lib/cpp/09-util-topic-tokenise.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include void print_error(const char *topic, char **topics, int topic_count) { diff --git a/test/lib/cpp/11-prop-oversize-packet.cpp b/test/lib/cpp/11-prop-oversize-packet.cpp index b4372ed8..4c2e32d7 100644 --- a/test/lib/cpp/11-prop-oversize-packet.cpp +++ b/test/lib/cpp/11-prop-oversize-packet.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include static int run = -1; static int sent_mid = -1; diff --git a/test/lib/cpp/11-prop-recv.cpp b/test/lib/cpp/11-prop-recv.cpp index 5c482d69..27fac64b 100644 --- a/test/lib/cpp/11-prop-recv.cpp +++ b/test/lib/cpp/11-prop-recv.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include static int run = -1; static int qos = -1; diff --git a/test/lib/cpp/11-prop-send-content-type.cpp b/test/lib/cpp/11-prop-send-content-type.cpp index 70ebe6e6..03cdfe08 100644 --- a/test/lib/cpp/11-prop-send-content-type.cpp +++ b/test/lib/cpp/11-prop-send-content-type.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include static int run = -1; static int sent_mid = -1; diff --git a/test/lib/cpp/11-prop-send-payload-format.cpp b/test/lib/cpp/11-prop-send-payload-format.cpp index d67f0d41..598840e9 100644 --- a/test/lib/cpp/11-prop-send-payload-format.cpp +++ b/test/lib/cpp/11-prop-send-payload-format.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include static int run = -1; static int sent_mid = -1; diff --git a/test/unit/lib/property_add.c b/test/unit/lib/property_add.c index a7affc55..c0e705e1 100644 --- a/test/unit/lib/property_add.c +++ b/test/unit/lib/property_add.c @@ -1,7 +1,7 @@ #include #include -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "property_mosq.h" #include "packet_mosq.h" diff --git a/test/unit/lib/property_read.c b/test/unit/lib/property_read.c index 295ee45d..1505c646 100644 --- a/test/unit/lib/property_read.c +++ b/test/unit/lib/property_read.c @@ -1,7 +1,7 @@ #include #include -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "property_mosq.h" #include "packet_mosq.h" diff --git a/test/unit/lib/property_user_read.c b/test/unit/lib/property_user_read.c index 3b2f8439..d04c45b0 100644 --- a/test/unit/lib/property_user_read.c +++ b/test/unit/lib/property_user_read.c @@ -1,7 +1,7 @@ #include #include -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "memory_mosq.h" #include "property_mosq.h" #include "packet_mosq.h" diff --git a/test/unit/lib/property_value.c b/test/unit/lib/property_value.c index 51ba7309..f09202f7 100644 --- a/test/unit/lib/property_value.c +++ b/test/unit/lib/property_value.c @@ -1,7 +1,7 @@ #include #include -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "property_mosq.h" #include "packet_mosq.h" diff --git a/test/unit/lib/property_write.c b/test/unit/lib/property_write.c index 6a0bbc76..49c3967c 100644 --- a/test/unit/lib/property_write.c +++ b/test/unit/lib/property_write.c @@ -1,7 +1,7 @@ #include #include -#include "mqtt_protocol.h" +#include "mosquitto/mqtt_protocol.h" #include "property_mosq.h" #include "packet_mosq.h"