diff --git a/README.md b/README.md index 25ff6ceea..0097313f2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MQTT client/server for C++14 based on Boost.Asio -Version 9.0.0 [![Actions Status](https://github.com/redboltz/mqtt_cpp/workflows/CI/badge.svg)](https://github.com/redboltz/mqtt_cpp/actions)[![Build Status](https://dev.azure.com/redboltz/redboltz/_apis/build/status/redboltz.mqtt_cpp?branchName=master)](https://dev.azure.com/redboltz/redboltz/_build/latest?definitionId=6&branchName=master)[![codecov](https://codecov.io/gh/redboltz/mqtt_cpp/branch/master/graph/badge.svg)](https://codecov.io/gh/redboltz/mqtt_cpp) +Version 10.0.0 [![Actions Status](https://github.com/redboltz/mqtt_cpp/workflows/CI/badge.svg)](https://github.com/redboltz/mqtt_cpp/actions)[![Build Status](https://dev.azure.com/redboltz/redboltz/_apis/build/status/redboltz.mqtt_cpp?branchName=master)](https://dev.azure.com/redboltz/redboltz/_build/latest?definitionId=6&branchName=master)[![codecov](https://codecov.io/gh/redboltz/mqtt_cpp/branch/master/graph/badge.svg)](https://codecov.io/gh/redboltz/mqtt_cpp) Important note https://github.com/redboltz/mqtt_cpp/wiki/News. diff --git a/include/mqtt/broker/broker.hpp b/include/mqtt/broker/broker.hpp index 46bf8daab..aeaeeada1 100644 --- a/include/mqtt/broker/broker.hpp +++ b/include/mqtt/broker/broker.hpp @@ -23,7 +23,6 @@ #include #include -#include #include MQTT_BROKER_NS_BEGIN @@ -556,7 +555,7 @@ class broker_t { ep.set_subscribe_handler( [this, wp] (packet_id_t packet_id, - std::vector> entries) { + std::vector entries) { con_sp_t sp = wp.lock(); BOOST_ASSERT(sp); return subscribe_handler( @@ -570,7 +569,7 @@ class broker_t { ep.set_v5_subscribe_handler( [this, wp] (packet_id_t packet_id, - std::vector> entries, + std::vector entries, v5::properties props ) { con_sp_t sp = wp.lock(); @@ -586,13 +585,13 @@ class broker_t { ep.set_unsubscribe_handler( [this, wp] (packet_id_t packet_id, - std::vector topics) { + std::vector entries) { con_sp_t sp = wp.lock(); BOOST_ASSERT(sp); return unsubscribe_handler( force_move(sp), packet_id, - force_move(topics), + force_move(entries), v5::properties{} ); } @@ -600,7 +599,7 @@ class broker_t { ep.set_v5_unsubscribe_handler( [this, wp] (packet_id_t packet_id, - std::vector topics, + std::vector entries, v5::properties props ) { con_sp_t sp = wp.lock(); @@ -608,7 +607,7 @@ class broker_t { return unsubscribe_handler( force_move(sp), packet_id, - force_move(topics), + force_move(entries), force_move(props) ); } @@ -1270,7 +1269,7 @@ class broker_t { bool subscribe_handler( con_sp_t spep, packet_id_t packet_id, - std::vector> entries, + std::vector entries, v5::properties props) { auto& ep = *spep; @@ -1336,20 +1335,18 @@ class broker_t { case protocol_version::v3_1_1: { std::vector res; res.reserve(entries.size()); - for (auto const& e : entries) { - auto sn_tf = parse_shared_subscription(std::get<0>(e)); - subscribe_options subopts = std::get<1>(e); - res.emplace_back(qos_to_suback_return_code(subopts.get_qos())); // converts to granted_qos_x + for (auto& e : entries) { + res.emplace_back(qos_to_suback_return_code(e.subopts.get_qos())); // converts to granted_qos_x ssr.get().subscribe( - force_move(sn_tf.share_name), - sn_tf.topic_filter, - subopts, + force_move(e.share_name), + e.topic_filter, + e.subopts, [&] { retains_.find( - sn_tf.topic_filter, + e.topic_filter, [&](retain_t const& r) { retain_deliver.emplace_back( - [&publish_proc, &r, qos_value = subopts.get_qos(), sid] { + [&publish_proc, &r, qos_value = e.subopts.get_qos(), sid] { publish_proc(r, qos_value, sid); } ); @@ -1370,20 +1367,18 @@ class broker_t { std::vector res; res.reserve(entries.size()); - for (auto const& e : entries) { - auto sn_tf = parse_shared_subscription(std::get<0>(e)); - subscribe_options subopts = std::get<1>(e); - res.emplace_back(v5::qos_to_suback_reason_code(subopts.get_qos())); // converts to granted_qos_x + for (auto& e : entries) { + res.emplace_back(v5::qos_to_suback_reason_code(e.subopts.get_qos())); // converts to granted_qos_x ssr.get().subscribe( - force_move(sn_tf.share_name), - sn_tf.topic_filter, - subopts, + force_move(e.share_name), + e.topic_filter, + e.subopts, [&] { retains_.find( - sn_tf.topic_filter, + e.topic_filter, [&](retain_t const& r) { retain_deliver.emplace_back( - [&publish_proc, &r, qos_value = subopts.get_qos(), sid] { + [&publish_proc, &r, qos_value = e.subopts.get_qos(), sid] { publish_proc(r, qos_value, sid); } ); @@ -1411,7 +1406,7 @@ class broker_t { bool unsubscribe_handler( con_sp_t spep, packet_id_t packet_id, - std::vector topic_filters, + std::vector entries, v5::properties props) { auto& ep = *spep; @@ -1439,9 +1434,8 @@ class broker_t { // For each subscription that this connection has // Compare against the list of topic filters, and remove // the subscription if the topic filter is in the list. - for (auto const& whole_topic_filter : topic_filters) { - auto sn_tf = parse_shared_subscription(whole_topic_filter); - ssr.get().unsubscribe(sn_tf.share_name, sn_tf.topic_filter); + for (auto const& e : entries) { + ssr.get().unsubscribe(e.share_name, e.topic_filter); } switch (ep.get_protocol_version()) { @@ -1453,7 +1447,7 @@ class broker_t { ep.unsuback( packet_id, std::vector( - topic_filters.size(), + entries.size(), v5::unsuback_reason_code::success ), unsuback_props_ @@ -1516,7 +1510,8 @@ class broker_t { } }; - std::set sent; + // share_name topic_filter + std::set> sent; subs_map_.modify( topic, diff --git a/include/mqtt/broker/session_state.hpp b/include/mqtt/broker/session_state.hpp index 548c92c4c..d19d157ce 100644 --- a/include/mqtt/broker/session_state.hpp +++ b/include/mqtt/broker/session_state.hpp @@ -25,7 +25,6 @@ #include #include #include -#include MQTT_BROKER_NS_BEGIN diff --git a/include/mqtt/callable_overlay.hpp b/include/mqtt/callable_overlay.hpp index ae8671e44..aea34fe0b 100644 --- a/include/mqtt/callable_overlay.hpp +++ b/include/mqtt/callable_overlay.hpp @@ -210,13 +210,12 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349801
* 3.8.2 Variable header * @param entries - * Collection of a pair of Topic Filter and QoS.
+ * Collection of Share Name, Topic Filter, and QoS.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349802
* @return if the handler returns true, then continue receiving, otherwise quit. */ MQTT_ALWAYS_INLINE bool on_subscribe(packet_id_t packet_id, - std::vector> entries) noexcept override final { + std::vector entries) noexcept override final { return ! h_subscribe_ || h_subscribe_(packet_id, force_move(entries)); } @@ -244,14 +243,14 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349810
* 3.10.2 Variable header * @param topics - * Collection of Topic Filters
+ * Collection of Share Name and Topic Filter
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800448
* @return if the handler returns true, then continue receiving, otherwise quit. */ MQTT_ALWAYS_INLINE bool on_unsubscribe(packet_id_t packet_id, - std::vector topics) noexcept override final { + std::vector entries) noexcept override final { return ! h_unsubscribe_ - || h_unsubscribe_(packet_id, force_move(topics)); + || h_unsubscribe_(packet_id, force_move(entries)); } /** @@ -497,7 +496,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901163
* 3.8.2 Variable header * @param entries - * Collection of a pair of Topic Filter and QoS.
+ * Collection of Share Name, Topic Filter, and QoS.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901168
* @param props * Properties
@@ -506,7 +505,7 @@ struct callable_overlay final : public Impl * @return if the handler returns true, then continue receiving, otherwise quit. */ MQTT_ALWAYS_INLINE bool on_v5_subscribe(packet_id_t packet_id, - std::vector> entries, + std::vector entries, v5::properties props) noexcept override final { return ! h_v5_subscribe_ || h_v5_subscribe_(packet_id, force_move(entries), force_move(props)); @@ -539,8 +538,8 @@ struct callable_overlay final : public Impl * @param packet_id packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901181
* 3.10.2 Variable header - * @param topics - * Collection of Topic Filters
+ * @param entries + * Collection of Share Name and Topic Filter
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901185
* 3.10.3 UNSUBSCRIBE Payload * @param props @@ -550,10 +549,10 @@ struct callable_overlay final : public Impl * @return if the handler returns true, then continue receiving, otherwise quit. */ MQTT_ALWAYS_INLINE bool on_v5_unsubscribe(packet_id_t packet_id, - std::vector topics, + std::vector entries, v5::properties props) noexcept override final { return ! h_v5_unsubscribe_ - || h_v5_unsubscribe_(packet_id, force_move(topics), force_move(props)); + || h_v5_unsubscribe_(packet_id, force_move(entries), force_move(props)); } /** @@ -900,12 +899,12 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349801
* 3.8.2 Variable header * @param entries - * Collection of a pair of Topic Filter and QoS.
+ * Collection of Share Name, Topic Filter, and QoS.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349802
* @return if the handler returns true, then continue receiving, otherwise quit. */ using subscribe_handler = std::function> entries)>; + std::vector entries)>; /** * @brief Suback handler @@ -926,13 +925,13 @@ struct callable_overlay final : public Impl * @param packet_id packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349810
* 3.10.2 Variable header - * @param topics - * Collection of Topic Filters
+ * @param entries + * Collection of Share Name and Topic Filter
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800448
* @return if the handler returns true, then continue receiving, otherwise quit. */ using unsubscribe_handler = std::function topics)>; + std::vector entries)>; /** * @brief Unsuback handler @@ -1154,7 +1153,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901163
* 3.8.2 Variable header * @param entries - * Collection of a pair of Topic Filter and QoS.
+ * Collection of Share Name, Topic Filter, and Subscribe Options.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901168
* @param props * Properties
@@ -1164,7 +1163,7 @@ struct callable_overlay final : public Impl */ using v5_subscribe_handler = std::function< bool(packet_id_t packet_id, - std::vector> entries, + std::vector entries, v5::properties props) >; @@ -1194,8 +1193,8 @@ struct callable_overlay final : public Impl * @param packet_id packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901181
* 3.10.2 Variable header - * @param topics - * Collection of Topic Filters
+ * @param entries + * Collection of Share Name and Topic Filter
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901185
* 3.10.3 UNSUBSCRIBE Payload * @param props @@ -1206,7 +1205,7 @@ struct callable_overlay final : public Impl */ using v5_unsubscribe_handler = std::function< bool(packet_id_t packet_id, - std::vector topics, + std::vector entries, v5::properties props) >; diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index 4898c17bd..cecfa72d5 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -7,7 +7,7 @@ #if !defined(MQTT_ENDPOINT_HPP) #define MQTT_ENDPOINT_HPP -#include // should be top to configure variant limit +#include // should be top to configure variant limit #include #include @@ -67,6 +67,8 @@ #include #include #include +#include +#include #if defined(MQTT_USE_WS) #include @@ -347,12 +349,12 @@ class endpoint : public std::enable_shared_from_this * 3.8.2 Variable header * @param entries - * Collection of a pair of Topic Filter and QoS.
+ * Collection of Share Name, Topic Filter, and QoS.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349802
* @return if the handler returns true, then continue receiving, otherwise quit. */ virtual bool on_subscribe(packet_id_t packet_id, - std::vector> entries) noexcept = 0; + std::vector entries) noexcept = 0; /** * @brief Suback handler @@ -372,12 +374,12 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349810
* 3.10.2 Variable header - * @param topics - * Collection of Topic Filters
+ * @param entries + * Collection of Share Name and Topic Filter
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800448
* @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_unsubscribe(packet_id_t packet_id, std::vector topics) noexcept = 0; + virtual bool on_unsubscribe(packet_id_t packet_id, std::vector entries) noexcept = 0; /** * @brief Unsuback handler @@ -585,7 +587,7 @@ class endpoint : public std::enable_shared_from_this * 3.8.2 Variable header * @param entries - * Collection of a pair of Topic Filter and QoS.
+ * Collection of Share Name, Topic Filter, and Subscribe Options.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901168
* @param props * Properties
@@ -594,7 +596,7 @@ class endpoint : public std::enable_shared_from_this> entries, + std::vector entries, v5::properties props) noexcept = 0; /** @@ -621,8 +623,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901181
* 3.10.2 Variable header - * @param topics - * Collection of Topic Filters
+ * @param entries + * Collection of Share Name and Topic Filter
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901185
* 3.10.3 UNSUBSCRIBE Payload * @param props @@ -632,7 +634,7 @@ class endpoint : public std::enable_shared_from_this topics, + std::vector entries, v5::properties props) noexcept = 0; /** @@ -8083,7 +8085,7 @@ class endpoint : public std::enable_shared_from_this> entries; + std::vector entries; }; void process_subscribe( @@ -8175,15 +8177,17 @@ class endpoint : public std::enable_shared_from_this(body[0])); @@ -8194,7 +8198,7 @@ class endpoint : public std::enable_shared_from_this( force_move(session_life_keeper), @@ -8423,7 +8427,7 @@ class endpoint : public std::enable_shared_from_this entries; + std::vector entries; }; void process_unsubscribe( @@ -8515,8 +8519,9 @@ class endpoint : public std::enable_shared_from_this( force_move(session_life_keeper), diff --git a/include/mqtt/broker/shared_subscriptions.hpp b/include/mqtt/shared_subscriptions.hpp similarity index 92% rename from include/mqtt/broker/shared_subscriptions.hpp rename to include/mqtt/shared_subscriptions.hpp index 4c14d86f3..6965138df 100644 --- a/include/mqtt/broker/shared_subscriptions.hpp +++ b/include/mqtt/shared_subscriptions.hpp @@ -5,13 +5,12 @@ // http://www.boost.org/LICENSE_1_0.txt) -#if !defined(MQTT_BROKER_SHARED_SUBSCRIPTIONS_HPP) -#define MQTT_BROKER_SHARED_SUBSCRIPTIONS_HPP +#if !defined(MQTT_SHARED_SUBSCRIPTIONS_HPP) +#define MQTT_SHARED_SUBSCRIPTIONS_HPP #include -#include - +#include #include #include @@ -62,4 +61,4 @@ inline share_name_topic_filter parse_shared_subscription(buffer whole_topic_filt } // namespace MQTT_NS -#endif // MQTT_BROKER_SHARED_SUBSCRIPTIONS_HPP +#endif // MQTT_SHARED_SUBSCRIPTIONS_HPP