From c9a7184459d94410e241f894f48b80e5fbcbdcd2 Mon Sep 17 00:00:00 2001 From: Bruno Iljazovic Date: Fri, 16 Feb 2024 11:07:34 +0100 Subject: [PATCH] Use properties by reference when validating them. Reviewers: ivica Reviewed By: ivica Subscribers: korina Differential Revision: https://repo.mireo.local/D27963 --- include/async_mqtt5/impl/disconnect_op.hpp | 4 ++-- include/async_mqtt5/impl/publish_send_op.hpp | 8 ++++---- include/async_mqtt5/impl/re_auth_op.hpp | 6 +++--- include/async_mqtt5/impl/subscribe_op.hpp | 4 ++-- include/async_mqtt5/impl/unsubscribe_op.hpp | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/async_mqtt5/impl/disconnect_op.hpp b/include/async_mqtt5/impl/disconnect_op.hpp index 311eee0..7247279 100644 --- a/include/async_mqtt5/impl/disconnect_op.hpp +++ b/include/async_mqtt5/impl/disconnect_op.hpp @@ -123,14 +123,14 @@ public: private: static error_code validate_disconnect(const disconnect_props& props) { - auto reason_string = props[prop::reason_string]; + const auto& reason_string = props[prop::reason_string]; if ( reason_string && validate_mqtt_utf8(*reason_string) != validation_result::valid ) return client::error::malformed_packet; - auto user_properties = props[prop::user_property]; + const auto& user_properties = props[prop::user_property]; for (const auto& user_property: user_properties) if (!is_valid_string_pair(user_property)) return client::error::malformed_packet; diff --git a/include/async_mqtt5/impl/publish_send_op.hpp b/include/async_mqtt5/impl/publish_send_op.hpp index fdfdbcc..3e6291a 100644 --- a/include/async_mqtt5/impl/publish_send_op.hpp +++ b/include/async_mqtt5/impl/publish_send_op.hpp @@ -360,7 +360,7 @@ private: error_code validate_props(const publish_props& props) const { constexpr uint16_t default_topic_alias_max = 0; - auto topic_alias = props[prop::topic_alias]; + const auto& topic_alias = props[prop::topic_alias]; if (topic_alias) { auto topic_alias_max = _svc_ptr->connack_property(prop::topic_alias_maximum) .value_or(default_topic_alias_max); @@ -371,14 +371,14 @@ private: return client::error::malformed_packet; } - auto response_topic = props[prop::response_topic]; + const auto& response_topic = props[prop::response_topic]; if ( response_topic && validate_topic_name(*response_topic) != validation_result::valid ) return client::error::malformed_packet; - auto user_properties = props[prop::user_property]; + const auto& user_properties = props[prop::user_property]; for (const auto& user_property: user_properties) if (!is_valid_string_pair(user_property)) return client::error::malformed_packet; @@ -386,7 +386,7 @@ private: if (!props[prop::subscription_identifier].empty()) return client::error::malformed_packet; - auto content_type = props[prop::content_type]; + const auto& content_type = props[prop::content_type]; if ( content_type && validate_mqtt_utf8(*content_type) != validation_result::valid diff --git a/include/async_mqtt5/impl/re_auth_op.hpp b/include/async_mqtt5/impl/re_auth_op.hpp index 1528591..bfbbdc4 100644 --- a/include/async_mqtt5/impl/re_auth_op.hpp +++ b/include/async_mqtt5/impl/re_auth_op.hpp @@ -62,7 +62,7 @@ public: disconnect_rc_e::protocol_error ); - const auto& [rc, auth_props] = auth_message; + const auto& [rc, props] = auth_message; auto auth_rc = to_reason_code(rc); if (!auth_rc.has_value()) return on_auth_fail( @@ -70,7 +70,7 @@ public: disconnect_rc_e::malformed_packet ); - auto server_auth_method = auth_props[prop::authentication_method]; + const auto& server_auth_method = props[prop::authentication_method]; if (!server_auth_method || *server_auth_method != _auth.method()) return on_auth_fail( "Malformed AUTH received: wrong authentication method", @@ -79,7 +79,7 @@ public: auto auth_step = auth_rc == reason_codes::success ? auth_step_e::server_final : auth_step_e::server_challenge; - auto data = auth_props[prop::authentication_data].value_or(""); + auto data = props[prop::authentication_data].value_or(""); return _auth.async_auth( auth_step, std::move(data), diff --git a/include/async_mqtt5/impl/subscribe_op.hpp b/include/async_mqtt5/impl/subscribe_op.hpp index 9db3308..0396033 100644 --- a/include/async_mqtt5/impl/subscribe_op.hpp +++ b/include/async_mqtt5/impl/subscribe_op.hpp @@ -219,12 +219,12 @@ private: } error_code validate_props(const subscribe_props& props) const { - auto user_properties = props[prop::user_property]; + const auto& user_properties = props[prop::user_property]; for (const auto& user_property: user_properties) if (!is_valid_string_pair(user_property)) return client::error::malformed_packet; - auto sub_id = props[prop::subscription_identifier]; + const auto& sub_id = props[prop::subscription_identifier]; if (!sub_id.has_value()) return error_code {}; diff --git a/include/async_mqtt5/impl/unsubscribe_op.hpp b/include/async_mqtt5/impl/unsubscribe_op.hpp index 0e62ed8..eef8014 100644 --- a/include/async_mqtt5/impl/unsubscribe_op.hpp +++ b/include/async_mqtt5/impl/unsubscribe_op.hpp @@ -177,7 +177,7 @@ private: if (validate_topic_filter(topic) != validation_result::valid) return client::error::invalid_topic; - auto user_properties = props[prop::user_property]; + const auto& user_properties = props[prop::user_property]; for (const auto& user_property: user_properties) if (!is_valid_string_pair(user_property)) return client::error::malformed_packet;