diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 33e6873c7..f0355ad2f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,15 +9,12 @@ on: jobs: clang-format: - runs-on: ubuntu-22.04 # latest + runs-on: ubuntu-24.04 # latest steps: - name: Checkout Sources uses: actions/checkout@v4 - name: clang-format lint - uses: DoozyX/clang-format-lint-action@v0.13 - with: - source: './include ./source ./tests' - exclude: './include/aws/crt/external ./source/external' - clangFormatVersion: 11.1.0 + run: | + ./format-check.py diff --git a/format-check.py b/format-check.py new file mode 100755 index 000000000..e3c69fcd5 --- /dev/null +++ b/format-check.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +import argparse +import os +from pathlib import Path +import re +from subprocess import list2cmdline, run +from tempfile import NamedTemporaryFile + +CLANG_FORMAT_VERSION = '18.1.6' + +INCLUDE_REGEX = re.compile(r'^(include|source|tests)/.*\.(cpp|h)$') +EXCLUDE_REGEX = re.compile(r'^$') + +arg_parser = argparse.ArgumentParser(description="Check with clang-format") +arg_parser.add_argument('-i', '--inplace-edit', action='store_true', + help="Edit files inplace") +args = arg_parser.parse_args() + +os.chdir(Path(__file__).parent) + +# create file containing list of all files to format +filepaths_file = NamedTemporaryFile(delete=False) +for dirpath, dirnames, filenames in os.walk('.'): + for filename in filenames: + # our regexes expect filepath to use forward slash + filepath = Path(dirpath, filename).as_posix() + if not INCLUDE_REGEX.match(filepath): + continue + if EXCLUDE_REGEX.match(filepath): + continue + + filepaths_file.write(f"{filepath}\n".encode()) +filepaths_file.close() + +# use pipx to run clang-format from PyPI +# this is a simple way to run the same clang-format version regardless of OS +cmd = ['pipx', 'run', f'clang-format=={CLANG_FORMAT_VERSION}', + f'--files={filepaths_file.name}'] +if args.inplace_edit: + cmd += ['-i'] +else: + cmd += ['--Werror', '--dry-run'] + +print(f"{Path.cwd()}$ {list2cmdline(cmd)}") +if run(cmd).returncode: + exit(1) diff --git a/format-check.sh b/format-check.sh deleted file mode 100755 index fa5f00e27..000000000 --- a/format-check.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -if [[ -z $CLANG_FORMAT ]] ; then - CLANG_FORMAT=clang-format -fi - -if NOT type $CLANG_FORMAT 2> /dev/null ; then - echo "No appropriate clang-format found." - exit 1 -fi - -FAIL=0 -SOURCE_FILES=`find source include tests -type f \( -name '*.h' -o -name '*.cpp' \) -not -name "cJSON.h" -not -name "cJSON.cpp"` -for i in $SOURCE_FILES -do - $CLANG_FORMAT -output-replacements-xml $i | grep -c " /dev/null - if [ $? -ne 1 ] - then - echo "$i failed clang-format check." - FAIL=1 - fi -done - -exit $FAIL diff --git a/include/aws/crt/ImdsClient.h b/include/aws/crt/ImdsClient.h index c73e2bf27..4f2bdca97 100644 --- a/include/aws/crt/ImdsClient.h +++ b/include/aws/crt/ImdsClient.h @@ -382,5 +382,5 @@ namespace Aws }; } // namespace Imds - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/StringView.h b/include/aws/crt/StringView.h index b8c6c6688..27c162ffe 100644 --- a/include/aws/crt/StringView.h +++ b/include/aws/crt/StringView.h @@ -824,7 +824,7 @@ namespace Aws return basic_string_view(s, length); } - inline basic_string_view operator"" _sv(const wchar_t *s, size_t length) noexcept + inline basic_string_view operator"" _sv(const wchar_t * s, size_t length) noexcept { return basic_string_view(s, length); } diff --git a/include/aws/crt/Variant.h b/include/aws/crt/Variant.h index ad4ae3f88..2858ae951 100644 --- a/include/aws/crt/Variant.h +++ b/include/aws/crt/Variant.h @@ -17,7 +17,10 @@ namespace Aws { namespace VariantDetail { - template constexpr const T &ConstExprMax(const T &a, const T &b) { return (a < b) ? b : a; } + template constexpr const T &ConstExprMax(const T &a, const T &b) + { + return (a < b) ? b : a; + } namespace ParameterPackSize { @@ -77,7 +80,10 @@ namespace Aws } // a case when the template parameter pack is empty (i.e. Variant<>) - template constexpr bool ContainsType() { return false; } + template constexpr bool ContainsType() + { + return false; + } template struct HasType { @@ -109,8 +115,8 @@ namespace Aws } }; } // namespace VariantDebug -#endif /* defined(AWS_CRT_ENABLE_VARIANT_DEBUG) */ - } // namespace VariantDetail +#endif /* defined(AWS_CRT_ENABLE_VARIANT_DEBUG) */ + } // namespace VariantDetail template class VariantAlternative; diff --git a/include/aws/crt/auth/Credentials.h b/include/aws/crt/auth/Credentials.h index 48181d1ce..bfa02c526 100644 --- a/include/aws/crt/auth/Credentials.h +++ b/include/aws/crt/auth/Credentials.h @@ -581,5 +581,5 @@ namespace Aws aws_credentials_provider *m_provider; }; } // namespace Auth - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/auth/Signing.h b/include/aws/crt/auth/Signing.h index ad314b12d..0c24f3a31 100644 --- a/include/aws/crt/auth/Signing.h +++ b/include/aws/crt/auth/Signing.h @@ -95,5 +95,5 @@ namespace Aws }; } // namespace Auth - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/auth/Sigv4Signing.h b/include/aws/crt/auth/Sigv4Signing.h index e902b1363..db0a70d90 100644 --- a/include/aws/crt/auth/Sigv4Signing.h +++ b/include/aws/crt/auth/Sigv4Signing.h @@ -348,5 +348,5 @@ namespace Aws Allocator *m_allocator; }; } // namespace Auth - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/crypto/HMAC.h b/include/aws/crt/crypto/HMAC.h index 26894d5bb..b5c4f3776 100644 --- a/include/aws/crt/crypto/HMAC.h +++ b/include/aws/crt/crypto/HMAC.h @@ -164,5 +164,5 @@ namespace Aws std::function(size_t digestSize, const ByteCursor &secret, Allocator *)>; } // namespace Crypto - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/crypto/Hash.h b/include/aws/crt/crypto/Hash.h index cc2209b7b..98e3e3c93 100644 --- a/include/aws/crt/crypto/Hash.h +++ b/include/aws/crt/crypto/Hash.h @@ -208,5 +208,5 @@ namespace Aws using CreateHashCallback = std::function(size_t digestSize, Allocator *)>; } // namespace Crypto - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/crypto/SymmetricCipher.h b/include/aws/crt/crypto/SymmetricCipher.h index 3d99b8ab2..ba454f5bb 100644 --- a/include/aws/crt/crypto/SymmetricCipher.h +++ b/include/aws/crt/crypto/SymmetricCipher.h @@ -159,5 +159,5 @@ namespace Aws int m_lastError; }; } // namespace Crypto - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/endpoints/RuleEngine.h b/include/aws/crt/endpoints/RuleEngine.h index 84baff71d..1472492c0 100644 --- a/include/aws/crt/endpoints/RuleEngine.h +++ b/include/aws/crt/endpoints/RuleEngine.h @@ -151,5 +151,5 @@ namespace Aws aws_endpoints_rule_engine *m_ruleEngine; }; } // namespace Endpoints - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/http/HttpConnection.h b/include/aws/crt/http/HttpConnection.h index e046a61dc..1b5c72053 100644 --- a/include/aws/crt/http/HttpConnection.h +++ b/include/aws/crt/http/HttpConnection.h @@ -510,5 +510,5 @@ namespace Aws }; } // namespace Http - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/http/HttpConnectionManager.h b/include/aws/crt/http/HttpConnectionManager.h index 0ecd9b48d..ceb0c5eb7 100644 --- a/include/aws/crt/http/HttpConnectionManager.h +++ b/include/aws/crt/http/HttpConnectionManager.h @@ -123,5 +123,5 @@ namespace Aws friend class ManagedConnection; }; } // namespace Http - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/http/HttpProxyStrategy.h b/include/aws/crt/http/HttpProxyStrategy.h index bf7249069..d351d92e6 100644 --- a/include/aws/crt/http/HttpProxyStrategy.h +++ b/include/aws/crt/http/HttpProxyStrategy.h @@ -112,5 +112,5 @@ namespace Aws struct aws_http_proxy_strategy *m_strategy; }; } // namespace Http - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/http/HttpRequestResponse.h b/include/aws/crt/http/HttpRequestResponse.h index f89130e57..7114c2ba2 100644 --- a/include/aws/crt/http/HttpRequestResponse.h +++ b/include/aws/crt/http/HttpRequestResponse.h @@ -157,5 +157,5 @@ namespace Aws bool SetResponseCode(int response) noexcept; }; } // namespace Http - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/io/Bootstrap.h b/include/aws/crt/io/Bootstrap.h index e1175f83a..19e5b9536 100644 --- a/include/aws/crt/io/Bootstrap.h +++ b/include/aws/crt/io/Bootstrap.h @@ -100,5 +100,5 @@ namespace Aws bool m_enableBlockingShutdown; }; } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/io/ChannelHandler.h b/include/aws/crt/io/ChannelHandler.h index 7f5c8ecd9..1dc80aba8 100644 --- a/include/aws/crt/io/ChannelHandler.h +++ b/include/aws/crt/io/ChannelHandler.h @@ -119,7 +119,7 @@ namespace Aws /** * Directs the channel handler to reset all of the internal statistics it tracks about itself. */ - virtual void ResetStatistics(){}; + virtual void ResetStatistics() {}; /** * Adds a pointer to the handler's internal statistics (if they exist) to a list of statistics @@ -234,5 +234,5 @@ namespace Aws static void s_GatherStatistics(struct aws_channel_handler *, struct aws_array_list *statsList); }; } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/io/HostResolver.h b/include/aws/crt/io/HostResolver.h index dac0e6023..cbd1c6dbb 100644 --- a/include/aws/crt/io/HostResolver.h +++ b/include/aws/crt/io/HostResolver.h @@ -119,5 +119,5 @@ namespace Aws void *user_data); }; } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/io/Pkcs11.h b/include/aws/crt/io/Pkcs11.h index 7f10baad8..ffc2362aa 100644 --- a/include/aws/crt/io/Pkcs11.h +++ b/include/aws/crt/io/Pkcs11.h @@ -112,5 +112,5 @@ namespace Aws aws_pkcs11_lib *impl = nullptr; }; } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/io/SocketOptions.h b/include/aws/crt/io/SocketOptions.h index 9f31250dd..1292c86dd 100644 --- a/include/aws/crt/io/SocketOptions.h +++ b/include/aws/crt/io/SocketOptions.h @@ -153,5 +153,5 @@ namespace Aws aws_socket_options options; }; } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/io/Stream.h b/include/aws/crt/io/Stream.h index cf6c49fa3..91c8c36f2 100644 --- a/include/aws/crt/io/Stream.h +++ b/include/aws/crt/io/Stream.h @@ -169,5 +169,5 @@ namespace Aws std::shared_ptr m_stream; }; } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/io/TlsOptions.h b/include/aws/crt/io/TlsOptions.h index afb543a92..db3cd1fdc 100644 --- a/include/aws/crt/io/TlsOptions.h +++ b/include/aws/crt/io/TlsOptions.h @@ -449,5 +449,5 @@ namespace Aws Allocator *allocator)>; } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/io/Uri.h b/include/aws/crt/io/Uri.h index a32f2db19..3a8472f4e 100644 --- a/include/aws/crt/io/Uri.h +++ b/include/aws/crt/io/Uri.h @@ -101,5 +101,5 @@ namespace Aws AWS_CRT_CPP_API Aws::Crt::String EncodeQueryParameterValue(ByteCursor paramValue); } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/mqtt/Mqtt5Client.h b/include/aws/crt/mqtt/Mqtt5Client.h index 850efae19..02bf48d2e 100644 --- a/include/aws/crt/mqtt/Mqtt5Client.h +++ b/include/aws/crt/mqtt/Mqtt5Client.h @@ -838,5 +838,5 @@ namespace Aws }; } // namespace Mqtt5 - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/mqtt/Mqtt5Packets.h b/include/aws/crt/mqtt/Mqtt5Packets.h index b68f9a0a8..99448f00f 100644 --- a/include/aws/crt/mqtt/Mqtt5Packets.h +++ b/include/aws/crt/mqtt/Mqtt5Packets.h @@ -577,7 +577,7 @@ namespace Aws */ const Crt::String &getClientId() const noexcept; - virtual ~NegotiatedSettings(){}; + virtual ~NegotiatedSettings() {}; NegotiatedSettings(const NegotiatedSettings &) = delete; NegotiatedSettings(NegotiatedSettings &&) noexcept = delete; NegotiatedSettings &operator=(const NegotiatedSettings &) = delete; @@ -1388,7 +1388,7 @@ namespace Aws */ const Crt::Optional &getServerReference() const noexcept; - virtual ~ConnAckPacket(){}; + virtual ~ConnAckPacket() {}; ConnAckPacket(const ConnAckPacket &) = delete; ConnAckPacket(ConnAckPacket &&) noexcept = delete; ConnAckPacket &operator=(const ConnAckPacket &) = delete; @@ -1802,7 +1802,7 @@ namespace Aws */ const Crt::Vector &getUserProperties() const noexcept; - virtual ~PubAckPacket(){}; + virtual ~PubAckPacket() {}; PubAckPacket(const PubAckPacket &toCopy) noexcept = delete; PubAckPacket(PubAckPacket &&toMove) noexcept = delete; PubAckPacket &operator=(const PubAckPacket &toCopy) noexcept = delete; @@ -1968,7 +1968,7 @@ namespace Aws bool initializeRawOptions(aws_mqtt5_subscription_view &raw_options) const noexcept; - virtual ~Subscription(){}; + virtual ~Subscription() {}; Subscription(const Subscription &) noexcept; Subscription(Subscription &&) noexcept; Subscription &operator=(const Subscription &) noexcept; @@ -2404,5 +2404,5 @@ namespace Aws }; } // namespace Mqtt5 - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/mqtt/MqttClient.h b/include/aws/crt/mqtt/MqttClient.h index 6599f059a..19b2236a3 100644 --- a/include/aws/crt/mqtt/MqttClient.h +++ b/include/aws/crt/mqtt/MqttClient.h @@ -117,5 +117,5 @@ namespace Aws aws_mqtt_client *m_client; }; } // namespace Mqtt - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/mqtt/MqttConnection.h b/include/aws/crt/mqtt/MqttConnection.h index f599e669a..670dad35d 100644 --- a/include/aws/crt/mqtt/MqttConnection.h +++ b/include/aws/crt/mqtt/MqttConnection.h @@ -458,5 +458,5 @@ namespace Aws std::shared_ptr m_connectionCore; }; } // namespace Mqtt - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/mqtt/MqttTypes.h b/include/aws/crt/mqtt/MqttTypes.h index 14606b85e..5f057a33d 100644 --- a/include/aws/crt/mqtt/MqttTypes.h +++ b/include/aws/crt/mqtt/MqttTypes.h @@ -126,5 +126,5 @@ namespace Aws uint64_t unackedOperationSize; }; } // namespace Mqtt - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/include/aws/crt/mqtt/private/Mqtt5ClientCore.h b/include/aws/crt/mqtt/private/Mqtt5ClientCore.h index 397d6c400..69dac4d77 100644 --- a/include/aws/crt/mqtt/private/Mqtt5ClientCore.h +++ b/include/aws/crt/mqtt/private/Mqtt5ClientCore.h @@ -255,6 +255,6 @@ namespace Aws }; } // namespace Mqtt5 - } // namespace Crt + } // namespace Crt } // namespace Aws /*! \endcond */ diff --git a/include/aws/crt/mqtt/private/MqttConnectionCore.h b/include/aws/crt/mqtt/private/MqttConnectionCore.h index b967e57e0..8b0d503f8 100644 --- a/include/aws/crt/mqtt/private/MqttConnectionCore.h +++ b/include/aws/crt/mqtt/private/MqttConnectionCore.h @@ -390,6 +390,6 @@ namespace Aws std::shared_ptr m_self; }; } // namespace Mqtt - } // namespace Crt + } // namespace Crt } // namespace Aws /*! \endcond */ diff --git a/source/Allocator.cpp b/source/Allocator.cpp index a27071ef5..2fb57031b 100644 --- a/source/Allocator.cpp +++ b/source/Allocator.cpp @@ -9,13 +9,22 @@ namespace Aws namespace Crt { - Allocator *DefaultAllocatorImplementation() noexcept { return aws_default_allocator(); } + Allocator *DefaultAllocatorImplementation() noexcept + { + return aws_default_allocator(); + } - Allocator *DefaultAllocator() noexcept { return DefaultAllocatorImplementation(); } + Allocator *DefaultAllocator() noexcept + { + return DefaultAllocatorImplementation(); + } Allocator *g_allocator = Aws::Crt::DefaultAllocatorImplementation(); - Allocator *ApiAllocator() noexcept { return g_allocator; } + Allocator *ApiAllocator() noexcept + { + return g_allocator; + } } // namespace Crt } // namespace Aws diff --git a/source/Api.cpp b/source/Api.cpp index 0bfe5f4a8..7d6247512 100644 --- a/source/Api.cpp +++ b/source/Api.cpp @@ -131,7 +131,10 @@ namespace Aws aws_logger_set(&m_logger); } - void ApiHandle::SetShutdownBehavior(ApiHandleShutdownBehavior behavior) { m_shutdownBehavior = behavior; } + void ApiHandle::SetShutdownBehavior(ApiHandleShutdownBehavior behavior) + { + m_shutdownBehavior = behavior; + } #if BYO_CRYPTO static struct aws_hash *s_MD5New(struct aws_allocator *allocator) @@ -406,11 +409,20 @@ namespace Aws return s_BYOCryptoIsTlsAlpnSupportedCallback; } - ApiHandle::Version ApiHandle::GetCrtVersion() const { return m_version; } + ApiHandle::Version ApiHandle::GetCrtVersion() const + { + return m_version; + } - const char *ErrorDebugString(int error) noexcept { return aws_error_debug_str(error); } + const char *ErrorDebugString(int error) noexcept + { + return aws_error_debug_str(error); + } - int LastError() noexcept { return aws_last_error(); } + int LastError() noexcept + { + return aws_last_error(); + } int LastErrorOrUnknown() noexcept { diff --git a/source/DateTime.cpp b/source/DateTime.cpp index 8e550cc91..761d8ae88 100644 --- a/source/DateTime.cpp +++ b/source/DateTime.cpp @@ -62,7 +62,10 @@ namespace Aws return aws_date_time_diff(&m_date_time, &other.m_date_time) > 0; } - bool DateTime::operator!=(const DateTime &other) const noexcept { return !(*this == other); } + bool DateTime::operator!=(const DateTime &other) const noexcept + { + return !(*this == other); + } bool DateTime::operator<=(const DateTime &other) const noexcept { @@ -123,9 +126,15 @@ namespace Aws return *this; } - DateTime::operator bool() const noexcept { return m_good; } + DateTime::operator bool() const noexcept + { + return m_good; + } - int DateTime::GetLastError() const noexcept { return aws_last_error(); } + int DateTime::GetLastError() const noexcept + { + return aws_last_error(); + } bool DateTime::ToLocalTimeString(DateFormat format, ByteBuf &outputBuf) const noexcept { @@ -141,9 +150,15 @@ namespace Aws AWS_ERROR_SUCCESS); } - double DateTime::SecondsWithMSPrecision() const noexcept { return aws_date_time_as_epoch_secs(&m_date_time); } + double DateTime::SecondsWithMSPrecision() const noexcept + { + return aws_date_time_as_epoch_secs(&m_date_time); + } - uint64_t DateTime::Millis() const noexcept { return aws_date_time_as_millis(&m_date_time); } + uint64_t DateTime::Millis() const noexcept + { + return aws_date_time_as_millis(&m_date_time); + } std::chrono::system_clock::time_point DateTime::UnderlyingTimestamp() const noexcept { @@ -170,7 +185,10 @@ namespace Aws return static_cast(aws_date_time_day_of_week(&m_date_time, localTime)); } - uint8_t DateTime::GetHour(bool localTime) const noexcept { return aws_date_time_hour(&m_date_time, localTime); } + uint8_t DateTime::GetHour(bool localTime) const noexcept + { + return aws_date_time_hour(&m_date_time, localTime); + } uint8_t DateTime::GetMinute(bool localTime) const noexcept { @@ -182,7 +200,10 @@ namespace Aws return aws_date_time_second(&m_date_time, localTime); } - bool DateTime::IsDST(bool localTime) const noexcept { return aws_date_time_dst(&m_date_time, localTime); } + bool DateTime::IsDST(bool localTime) const noexcept + { + return aws_date_time_dst(&m_date_time, localTime); + } DateTime DateTime::Now() noexcept { diff --git a/source/ImdsClient.cpp b/source/ImdsClient.cpp index cb9b1f943..4a669c9ce 100644 --- a/source/ImdsClient.cpp +++ b/source/ImdsClient.cpp @@ -452,6 +452,6 @@ namespace Aws return aws_imds_client_get_instance_info(m_client, s_onInstanceInfoAcquired, wrappedCallbackArgs); } } // namespace Imds - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/JsonObject.cpp b/source/JsonObject.cpp index ca71c505d..a47c1f196 100644 --- a/source/JsonObject.cpp +++ b/source/JsonObject.cpp @@ -34,7 +34,10 @@ namespace Aws other.m_value = nullptr; } - JsonObject::~JsonObject() { aws_json_value_destroy(m_value); } + JsonObject::~JsonObject() + { + aws_json_value_destroy(m_value); + } JsonObject &JsonObject::operator=(const JsonObject &other) { @@ -103,7 +106,10 @@ namespace Aws return WithNewKeyValue(key, aws_json_value_new_boolean(ApiAllocator(), value)); } - JsonObject &JsonObject::WithBool(const String &key, bool value) { return WithBool(key.c_str(), value); } + JsonObject &JsonObject::WithBool(const String &key, bool value) + { + return WithBool(key.c_str(), value); + } JsonObject &JsonObject::AsBool(bool value) { @@ -135,14 +141,20 @@ namespace Aws return WithDouble(key.c_str(), static_cast(value)); } - JsonObject &JsonObject::AsInt64(int64_t value) { return AsDouble(static_cast(value)); } + JsonObject &JsonObject::AsInt64(int64_t value) + { + return AsDouble(static_cast(value)); + } JsonObject &JsonObject::WithDouble(const char *key, double value) { return WithNewKeyValue(key, aws_json_value_new_number(ApiAllocator(), value)); } - JsonObject &JsonObject::WithDouble(const String &key, double value) { return WithDouble(key.c_str(), value); } + JsonObject &JsonObject::WithDouble(const String &key, double value) + { + return WithDouble(key.c_str(), value); + } JsonObject &JsonObject::AsDouble(double value) { @@ -205,11 +217,20 @@ namespace Aws return WithNewKeyValue(key.c_str(), NewArray(std::move(array))); } - JsonObject &JsonObject::AsArray(const Vector &array) { return AsNewValue(NewArray(array)); } + JsonObject &JsonObject::AsArray(const Vector &array) + { + return AsNewValue(NewArray(array)); + } - JsonObject &JsonObject::AsArray(Vector &&array) { return AsNewValue(NewArray(std::move(array))); } + JsonObject &JsonObject::AsArray(Vector &&array) + { + return AsNewValue(NewArray(std::move(array))); + } - JsonObject &JsonObject::AsNull() { return AsNewValue(aws_json_value_new_null(ApiAllocator())); } + JsonObject &JsonObject::AsNull() + { + return AsNewValue(aws_json_value_new_null(ApiAllocator())); + } JsonObject &JsonObject::WithObject(const char *key, const JsonObject &value) { @@ -256,7 +277,10 @@ namespace Aws return false; } - bool JsonObject::operator!=(const JsonObject &other) const { return !(*this == other); } + bool JsonObject::operator!=(const JsonObject &other) const + { + return !(*this == other); + } std::unique_ptr JsonObject::s_errorMessage; std::unique_ptr JsonObject::s_okMessage; @@ -278,7 +302,10 @@ namespace Aws return m_value == nullptr ? *s_errorMessage : *s_okMessage; } - JsonView JsonObject::View() const { return JsonView(*this); } + JsonView JsonObject::View() const + { + return JsonView(*this); + } JsonView::JsonView() : m_value(nullptr) {} @@ -292,7 +319,10 @@ namespace Aws return *this; } - String JsonView::GetString(const String &key) const { return GetString(key.c_str()); } + String JsonView::GetString(const String &key) const + { + return GetString(key.c_str()); + } String JsonView::GetString(const char *key) const { @@ -326,7 +356,10 @@ namespace Aws return ""; } - bool JsonView::GetBool(const String &key) const { return GetBool(key.c_str()); } + bool JsonView::GetBool(const String &key) const + { + return GetBool(key.c_str()); + } bool JsonView::GetBool(const char *key) const { @@ -360,19 +393,40 @@ namespace Aws return false; } - int JsonView::GetInteger(const String &key) const { return static_cast(GetDouble(key)); } + int JsonView::GetInteger(const String &key) const + { + return static_cast(GetDouble(key)); + } - int JsonView::GetInteger(const char *key) const { return static_cast(GetDouble(key)); } + int JsonView::GetInteger(const char *key) const + { + return static_cast(GetDouble(key)); + } - int JsonView::AsInteger() const { return static_cast(AsDouble()); } + int JsonView::AsInteger() const + { + return static_cast(AsDouble()); + } - int64_t JsonView::GetInt64(const String &key) const { return static_cast(GetDouble(key)); } + int64_t JsonView::GetInt64(const String &key) const + { + return static_cast(GetDouble(key)); + } - int64_t JsonView::GetInt64(const char *key) const { return static_cast(GetDouble(key)); } + int64_t JsonView::GetInt64(const char *key) const + { + return static_cast(GetDouble(key)); + } - int64_t JsonView::AsInt64() const { return static_cast(AsDouble()); } + int64_t JsonView::AsInt64() const + { + return static_cast(AsDouble()); + } - double JsonView::GetDouble(const String &key) const { return GetDouble(key.c_str()); } + double JsonView::GetDouble(const String &key) const + { + return GetDouble(key.c_str()); + } double JsonView::GetDouble(const char *key) const { @@ -406,7 +460,10 @@ namespace Aws return 0.0; } - JsonView JsonView::GetJsonObject(const String &key) const { return GetJsonObject(key.c_str()); } + JsonView JsonView::GetJsonObject(const String &key) const + { + return GetJsonObject(key.c_str()); + } JsonView JsonView::GetJsonObject(const char *key) const { @@ -424,7 +481,10 @@ namespace Aws return JsonView(); } - JsonObject JsonView::GetJsonObjectCopy(const String &key) const { return GetJsonObjectCopy(key.c_str()); } + JsonObject JsonView::GetJsonObjectCopy(const String &key) const + { + return GetJsonObjectCopy(key.c_str()); + } JsonObject JsonView::GetJsonObjectCopy(const char *key) const { @@ -456,7 +516,10 @@ namespace Aws return JsonView(); } - Vector JsonView::GetArray(const String &key) const { return GetArray(key.c_str()); } + Vector JsonView::GetArray(const String &key) const + { + return GetArray(key.c_str()); + } Vector JsonView::GetArray(const char *key) const { @@ -480,7 +543,8 @@ namespace Aws { aws_json_const_iterate_array( m_value, - [](size_t index, const aws_json_value *value, bool *out_should_continue, void *user_data) { + [](size_t index, const aws_json_value *value, bool *out_should_continue, void *user_data) + { (void)index; (void)out_should_continue; auto returnArray = static_cast *>(user_data); @@ -503,7 +567,8 @@ namespace Aws [](const aws_byte_cursor *key, const aws_json_value *value, bool *out_should_continue, - void *user_data) { + void *user_data) + { (void)out_should_continue; auto valueMap = static_cast *>(user_data); valueMap->emplace( @@ -516,7 +581,10 @@ namespace Aws return valueMap; } - bool JsonView::ValueExists(const String &key) const { return ValueExists(key.c_str()); } + bool JsonView::ValueExists(const String &key) const + { + return ValueExists(key.c_str()); + } bool JsonView::ValueExists(const char *key) const { @@ -532,7 +600,10 @@ namespace Aws return false; } - bool JsonView::KeyExists(const String &key) const { return KeyExists(key.c_str()); } + bool JsonView::KeyExists(const String &key) const + { + return KeyExists(key.c_str()); + } bool JsonView::KeyExists(const char *key) const { @@ -544,13 +615,25 @@ namespace Aws return false; } - bool JsonView::IsObject() const { return m_value != nullptr && aws_json_value_is_object(m_value); } + bool JsonView::IsObject() const + { + return m_value != nullptr && aws_json_value_is_object(m_value); + } - bool JsonView::IsBool() const { return m_value != nullptr && aws_json_value_is_boolean(m_value); } + bool JsonView::IsBool() const + { + return m_value != nullptr && aws_json_value_is_boolean(m_value); + } - bool JsonView::IsString() const { return m_value != nullptr && aws_json_value_is_string(m_value); } + bool JsonView::IsString() const + { + return m_value != nullptr && aws_json_value_is_string(m_value); + } - bool JsonView::IsNumber() const { return m_value != nullptr && aws_json_value_is_number(m_value); } + bool JsonView::IsNumber() const + { + return m_value != nullptr && aws_json_value_is_number(m_value); + } bool JsonView::IsIntegerType() const { @@ -580,9 +663,15 @@ namespace Aws return false; } - bool JsonView::IsListType() const { return m_value != nullptr && aws_json_value_is_array(m_value); } + bool JsonView::IsListType() const + { + return m_value != nullptr && aws_json_value_is_array(m_value); + } - bool JsonView::IsNull() const { return m_value != nullptr && aws_json_value_is_null(m_value); } + bool JsonView::IsNull() const + { + return m_value != nullptr && aws_json_value_is_null(m_value); + } String JsonView::Write(bool treatAsObject, bool readable) const { @@ -610,10 +699,19 @@ namespace Aws return resultString; } - String JsonView::WriteCompact(bool treatAsObject) const { return Write(treatAsObject, false /*readable*/); } + String JsonView::WriteCompact(bool treatAsObject) const + { + return Write(treatAsObject, false /*readable*/); + } - String JsonView::WriteReadable(bool treatAsObject) const { return Write(treatAsObject, true /*readable*/); } + String JsonView::WriteReadable(bool treatAsObject) const + { + return Write(treatAsObject, true /*readable*/); + } - JsonObject JsonView::Materialize() const { return m_value; } + JsonObject JsonView::Materialize() const + { + return m_value; + } } // namespace Crt } // namespace Aws diff --git a/source/StringUtils.cpp b/source/StringUtils.cpp index 5c6984f62..a0e995602 100644 --- a/source/StringUtils.cpp +++ b/source/StringUtils.cpp @@ -10,6 +10,9 @@ namespace Aws { namespace Crt { - size_t HashString(const char *str) noexcept { return (size_t)aws_hash_c_string(str); } + size_t HashString(const char *str) noexcept + { + return (size_t)aws_hash_c_string(str); + } } // namespace Crt } // namespace Aws diff --git a/source/Types.cpp b/source/Types.cpp index 253048118..de2ebf256 100644 --- a/source/Types.cpp +++ b/source/Types.cpp @@ -10,7 +10,10 @@ namespace Aws { namespace Crt { - ByteBuf ByteBufFromCString(const char *str) noexcept { return aws_byte_buf_from_c_str(str); } + ByteBuf ByteBufFromCString(const char *str) noexcept + { + return aws_byte_buf_from_c_str(str); + } ByteBuf ByteBufFromEmptyArray(const uint8_t *array, size_t len) noexcept { @@ -37,9 +40,15 @@ namespace Aws return buff; } - void ByteBufDelete(ByteBuf &buf) { aws_byte_buf_clean_up(&buf); } + void ByteBufDelete(ByteBuf &buf) + { + aws_byte_buf_clean_up(&buf); + } - ByteCursor ByteCursorFromCString(const char *str) noexcept { return aws_byte_cursor_from_c_str(str); } + ByteCursor ByteCursorFromCString(const char *str) noexcept + { + return aws_byte_cursor_from_c_str(str); + } ByteCursor ByteCursorFromString(const Crt::String &str) noexcept { @@ -51,7 +60,10 @@ namespace Aws return aws_byte_cursor_from_array((const void *)str.data(), str.length()); } - ByteCursor ByteCursorFromByteBuf(const ByteBuf &buf) noexcept { return aws_byte_cursor_from_buf(&buf); } + ByteCursor ByteCursorFromByteBuf(const ByteBuf &buf) noexcept + { + return aws_byte_cursor_from_buf(&buf); + } ByteCursor ByteCursorFromArray(const uint8_t *array, size_t len) noexcept { diff --git a/source/UUID.cpp b/source/UUID.cpp index c985ea277..101b7a3df 100644 --- a/source/UUID.cpp +++ b/source/UUID.cpp @@ -31,9 +31,15 @@ namespace Aws return *this; } - bool UUID::operator==(const UUID &other) noexcept { return aws_uuid_equals(&m_uuid, &other.m_uuid); } + bool UUID::operator==(const UUID &other) noexcept + { + return aws_uuid_equals(&m_uuid, &other.m_uuid); + } - bool UUID::operator!=(const UUID &other) noexcept { return !aws_uuid_equals(&m_uuid, &other.m_uuid); } + bool UUID::operator!=(const UUID &other) noexcept + { + return !aws_uuid_equals(&m_uuid, &other.m_uuid); + } String UUID::ToString() const { @@ -45,10 +51,19 @@ namespace Aws return uuidStr; } - UUID::operator String() const { return ToString(); } + UUID::operator String() const + { + return ToString(); + } - UUID::operator ByteBuf() const noexcept { return ByteBufFromArray(m_uuid.uuid_data, sizeof(m_uuid.uuid_data)); } + UUID::operator ByteBuf() const noexcept + { + return ByteBufFromArray(m_uuid.uuid_data, sizeof(m_uuid.uuid_data)); + } - int UUID::GetLastError() const noexcept { return aws_last_error(); } + int UUID::GetLastError() const noexcept + { + return aws_last_error(); + } } // namespace Crt } // namespace Aws \ No newline at end of file diff --git a/source/auth/Credentials.cpp b/source/auth/Credentials.cpp index 77e40c61a..86ec09951 100644 --- a/source/auth/Credentials.cpp +++ b/source/auth/Credentials.cpp @@ -104,7 +104,10 @@ namespace Aws } } - Credentials::operator bool() const noexcept { return m_credentials != nullptr; } + Credentials::operator bool() const noexcept + { + return m_credentials != nullptr; + } CredentialsProvider::CredentialsProvider(aws_credentials_provider *provider, Allocator *allocator) noexcept : m_allocator(allocator), m_provider(provider) @@ -256,9 +259,8 @@ namespace Aws std::for_each( config.Providers.begin(), config.Providers.end(), - [&](const std::shared_ptr &provider) { - providers.push_back(provider->GetUnderlyingHandle()); - }); + [&](const std::shared_ptr &provider) + { providers.push_back(provider->GetUnderlyingHandle()); }); struct aws_credentials_provider_chain_options raw_config; AWS_ZERO_STRUCT(raw_config); @@ -474,5 +476,5 @@ namespace Aws return s_CreateWrappedProvider(aws_credentials_provider_new_sts(allocator, &raw_config), allocator); } } // namespace Auth - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/auth/Sigv4Signing.cpp b/source/auth/Sigv4Signing.cpp index 9586b85fa..573b3c8d2 100644 --- a/source/auth/Sigv4Signing.cpp +++ b/source/auth/Sigv4Signing.cpp @@ -21,16 +21,28 @@ namespace Aws namespace SignedBodyValue { const char *EmptySha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; - const char *EmptySha256Str() { return EmptySha256; } + const char *EmptySha256Str() + { + return EmptySha256; + } const char *UnsignedPayload = "UNSIGNED-PAYLOAD"; - const char *UnsignedPayloadStr() { return UnsignedPayload; } + const char *UnsignedPayloadStr() + { + return UnsignedPayload; + } const char *StreamingAws4HmacSha256Payload = "STREAMING-AWS4-HMAC-SHA256-PAYLOAD"; - const char *StreamingAws4HmacSha256PayloadStr() { return StreamingAws4HmacSha256Payload; } + const char *StreamingAws4HmacSha256PayloadStr() + { + return StreamingAws4HmacSha256Payload; + } const char *StreamingAws4HmacSha256Events = "STREAMING-AWS4-HMAC-SHA256-EVENTS"; - const char *StreamingAws4HmacSha256EventsStr() { return StreamingAws4HmacSha256Events; } + const char *StreamingAws4HmacSha256EventsStr() + { + return StreamingAws4HmacSha256Events; + } } // namespace SignedBodyValue AwsSigningConfig::AwsSigningConfig(Allocator *allocator) @@ -49,7 +61,10 @@ namespace Aws m_config.config_type = AWS_SIGNING_CONFIG_AWS; } - AwsSigningConfig::~AwsSigningConfig() { m_allocator = nullptr; } + AwsSigningConfig::~AwsSigningConfig() + { + m_allocator = nullptr; + } SigningAlgorithm AwsSigningConfig::GetSigningAlgorithm() const noexcept { @@ -71,7 +86,10 @@ namespace Aws m_config.signature_type = static_cast(signatureType); } - const Crt::String &AwsSigningConfig::GetRegion() const noexcept { return m_signingRegion; } + const Crt::String &AwsSigningConfig::GetRegion() const noexcept + { + return m_signingRegion; + } void AwsSigningConfig::SetRegion(const Crt::String ®ion) noexcept { @@ -79,7 +97,10 @@ namespace Aws m_config.region = ByteCursorFromCString(m_signingRegion.c_str()); } - const Crt::String &AwsSigningConfig::GetService() const noexcept { return m_serviceName; } + const Crt::String &AwsSigningConfig::GetService() const noexcept + { + return m_serviceName; + } void AwsSigningConfig::SetService(const Crt::String &service) noexcept { @@ -117,7 +138,10 @@ namespace Aws m_config.flags.should_normalize_uri_path = shouldNormalizeUriPath; } - bool AwsSigningConfig::GetOmitSessionToken() const noexcept { return m_config.flags.omit_session_token; } + bool AwsSigningConfig::GetOmitSessionToken() const noexcept + { + return m_config.flags.omit_session_token; + } void AwsSigningConfig::SetOmitSessionToken(bool omitSessionToken) noexcept { @@ -144,7 +168,10 @@ namespace Aws m_config.should_sign_header_ud = userData; } - const Crt::String &AwsSigningConfig::GetSignedBodyValue() const noexcept { return m_signedBodyValue; } + const Crt::String &AwsSigningConfig::GetSignedBodyValue() const noexcept + { + return m_signedBodyValue; + } void AwsSigningConfig::SetSignedBodyValue(const Crt::String &signedBodyValue) noexcept { @@ -270,5 +297,5 @@ namespace Aws signerCallbackData) == AWS_OP_SUCCESS; } } // namespace Auth - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/crypto/HMAC.cpp b/source/crypto/HMAC.cpp index 5b9da115e..0eb723b6d 100644 --- a/source/crypto/HMAC.cpp +++ b/source/crypto/HMAC.cpp @@ -195,5 +195,5 @@ namespace Aws return success ? AWS_OP_SUCCESS : AWS_OP_ERR; } } // namespace Crypto - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/crypto/Hash.cpp b/source/crypto/Hash.cpp index 9cae83094..ad15e0972 100644 --- a/source/crypto/Hash.cpp +++ b/source/crypto/Hash.cpp @@ -72,7 +72,10 @@ namespace Aws toMove.m_hash = nullptr; } - Hash::operator bool() const noexcept { return m_hash != nullptr && m_hash->good; } + Hash::operator bool() const noexcept + { + return m_hash != nullptr && m_hash->good; + } Hash &Hash::operator=(Hash &&toMove) { @@ -84,11 +87,20 @@ namespace Aws return *this; } - Hash Hash::CreateSHA256(Allocator *allocator) noexcept { return Hash(aws_sha256_new(allocator)); } + Hash Hash::CreateSHA256(Allocator *allocator) noexcept + { + return Hash(aws_sha256_new(allocator)); + } - Hash Hash::CreateMD5(Allocator *allocator) noexcept { return Hash(aws_md5_new(allocator)); } + Hash Hash::CreateMD5(Allocator *allocator) noexcept + { + return Hash(aws_md5_new(allocator)); + } - Hash Hash::CreateSHA1(Allocator *allocator) noexcept { return Hash(aws_sha1_new(allocator)); } + Hash Hash::CreateSHA1(Allocator *allocator) noexcept + { + return Hash(aws_sha1_new(allocator)); + } bool Hash::Update(const ByteCursor &toHash) noexcept { @@ -201,5 +213,5 @@ namespace Aws return success ? AWS_OP_SUCCESS : AWS_OP_ERR; } } // namespace Crypto - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/crypto/SecureRandom.cpp b/source/crypto/SecureRandom.cpp index 554b4fddc..081aad6b8 100644 --- a/source/crypto/SecureRandom.cpp +++ b/source/crypto/SecureRandom.cpp @@ -17,5 +17,5 @@ namespace Aws return aws_device_random_buffer_append(&output, lengthToGenerate) == AWS_OP_SUCCESS; } } // namespace Crypto - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/crypto/SymmetricCipher.cpp b/source/crypto/SymmetricCipher.cpp index 926271e88..9214566a9 100644 --- a/source/crypto/SymmetricCipher.cpp +++ b/source/crypto/SymmetricCipher.cpp @@ -121,14 +121,20 @@ namespace Aws return true; } - ByteCursor SymmetricCipher::GetKey() const noexcept { return aws_symmetric_cipher_get_key(m_cipher.get()); } + ByteCursor SymmetricCipher::GetKey() const noexcept + { + return aws_symmetric_cipher_get_key(m_cipher.get()); + } ByteCursor SymmetricCipher::GetIV() const noexcept { return aws_symmetric_cipher_get_initialization_vector(m_cipher.get()); } - ByteCursor SymmetricCipher::GetTag() const noexcept { return aws_symmetric_cipher_get_tag(m_cipher.get()); } + ByteCursor SymmetricCipher::GetTag() const noexcept + { + return aws_symmetric_cipher_get_tag(m_cipher.get()); + } SymmetricCipher SymmetricCipher::CreateAES_256_CBC_Cipher( const Optional &key, @@ -170,5 +176,5 @@ namespace Aws return {aws_aes_keywrap_256_new(allocator, key.has_value() ? &key.value() : nullptr)}; } } // namespace Crypto - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/endpoints/RuleEngine.cpp b/source/endpoints/RuleEngine.cpp index b319508c9..681eb5267 100644 --- a/source/endpoints/RuleEngine.cpp +++ b/source/endpoints/RuleEngine.cpp @@ -55,7 +55,10 @@ namespace Aws return *this; } - ResolutionOutcome::~ResolutionOutcome() { aws_endpoints_resolved_endpoint_release(m_resolvedEndpoint); } + ResolutionOutcome::~ResolutionOutcome() + { + aws_endpoints_resolved_endpoint_release(m_resolvedEndpoint); + } bool ResolutionOutcome::IsEndpoint() const noexcept { @@ -153,7 +156,10 @@ namespace Aws } } - RuleEngine::~RuleEngine() { m_ruleEngine = aws_endpoints_rule_engine_release(m_ruleEngine); } + RuleEngine::~RuleEngine() + { + m_ruleEngine = aws_endpoints_rule_engine_release(m_ruleEngine); + } Optional RuleEngine::Resolve(const RequestContext &context) const { @@ -165,5 +171,5 @@ namespace Aws return Optional(ResolutionOutcome(resolved)); } } // namespace Endpoints - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/http/HttpConnection.cpp b/source/http/HttpConnection.cpp index f8ed94cef..cbdace01a 100644 --- a/source/http/HttpConnection.cpp +++ b/source/http/HttpConnection.cpp @@ -243,9 +243,15 @@ namespace Aws return nullptr; } - bool HttpClientConnection::IsOpen() const noexcept { return aws_http_connection_is_open(m_connection); } + bool HttpClientConnection::IsOpen() const noexcept + { + return aws_http_connection_is_open(m_connection); + } - void HttpClientConnection::Close() noexcept { aws_http_connection_close(m_connection); } + void HttpClientConnection::Close() noexcept + { + aws_http_connection_close(m_connection); + } HttpVersion HttpClientConnection::GetVersion() noexcept { @@ -320,7 +326,10 @@ namespace Aws } } - HttpClientConnection &HttpStream::GetConnection() const noexcept { return *m_connection; } + HttpClientConnection &HttpStream::GetConnection() const noexcept + { + return *m_connection; + } HttpClientStream::HttpClientStream(const std::shared_ptr &connection) noexcept : HttpStream(connection) @@ -396,5 +405,5 @@ namespace Aws { } } // namespace Http - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/http/HttpConnectionManager.cpp b/source/http/HttpConnectionManager.cpp index 7a13a2bdb..4ec879ec8 100644 --- a/source/http/HttpConnectionManager.cpp +++ b/source/http/HttpConnectionManager.cpp @@ -232,5 +232,5 @@ namespace Aws } } // namespace Http - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/http/HttpProxyStrategy.cpp b/source/http/HttpProxyStrategy.cpp index 7b9ef2c3f..e5ee5a4a1 100644 --- a/source/http/HttpProxyStrategy.cpp +++ b/source/http/HttpProxyStrategy.cpp @@ -16,7 +16,10 @@ namespace Aws { HttpProxyStrategy::HttpProxyStrategy(struct aws_http_proxy_strategy *strategy) : m_strategy(strategy) {} - HttpProxyStrategy::~HttpProxyStrategy() { aws_http_proxy_strategy_release(m_strategy); } + HttpProxyStrategy::~HttpProxyStrategy() + { + aws_http_proxy_strategy_release(m_strategy); + } HttpProxyStrategyBasicAuthConfig::HttpProxyStrategyBasicAuthConfig() : ConnectionType(AwsHttpProxyConnectionType::Legacy), Username(), Password() @@ -192,5 +195,5 @@ namespace Aws return adaptiveStrategy; } } // namespace Http - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/http/HttpRequestResponse.cpp b/source/http/HttpRequestResponse.cpp index a80a582ac..9be9aed87 100644 --- a/source/http/HttpRequestResponse.cpp +++ b/source/http/HttpRequestResponse.cpp @@ -26,9 +26,15 @@ namespace Aws } } - HttpMessage::~HttpMessage() { m_message = aws_http_message_release(m_message); } + HttpMessage::~HttpMessage() + { + m_message = aws_http_message_release(m_message); + } - std::shared_ptr HttpMessage::GetBody() const noexcept { return m_bodyStream; } + std::shared_ptr HttpMessage::GetBody() const noexcept + { + return m_bodyStream; + } bool HttpMessage::SetBody(const std::shared_ptr &body) noexcept { @@ -57,7 +63,10 @@ namespace Aws return true; } - size_t HttpMessage::GetHeaderCount() const noexcept { return aws_http_message_get_header_count(m_message); } + size_t HttpMessage::GetHeaderCount() const noexcept + { + return aws_http_message_get_header_count(m_message); + } Optional HttpMessage::GetHeader(size_t index) const noexcept { @@ -147,5 +156,5 @@ namespace Aws return aws_http_message_set_response_status(m_message, response) == AWS_OP_SUCCESS; } } // namespace Http - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/io/Bootstrap.cpp b/source/io/Bootstrap.cpp index 84005a41d..be1291afa 100644 --- a/source/io/Bootstrap.cpp +++ b/source/io/Bootstrap.cpp @@ -97,16 +97,25 @@ namespace Aws } } - ClientBootstrap::operator bool() const noexcept { return m_lastError == AWS_ERROR_SUCCESS; } + ClientBootstrap::operator bool() const noexcept + { + return m_lastError == AWS_ERROR_SUCCESS; + } - int ClientBootstrap::LastError() const noexcept { return m_lastError; } + int ClientBootstrap::LastError() const noexcept + { + return m_lastError; + } void ClientBootstrap::SetShutdownCompleteCallback(OnClientBootstrapShutdownComplete callback) { m_callbackData->ShutdownCallback = std::move(callback); } - void ClientBootstrap::EnableBlockingShutdown() noexcept { m_enableBlockingShutdown = true; } + void ClientBootstrap::EnableBlockingShutdown() noexcept + { + m_enableBlockingShutdown = true; + } aws_client_bootstrap *ClientBootstrap::GetUnderlyingHandle() const noexcept { @@ -118,5 +127,5 @@ namespace Aws return nullptr; } } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/io/ChannelHandler.cpp b/source/io/ChannelHandler.cpp index fcbc44317..484125452 100644 --- a/source/io/ChannelHandler.cpp +++ b/source/io/ChannelHandler.cpp @@ -126,7 +126,10 @@ namespace Aws return aws_channel_slot_acquire_max_message_for_write(GetSlot()); } - void ChannelHandler::ShutDownChannel(int errorCode) { aws_channel_shutdown(GetSlot()->channel, errorCode); } + void ChannelHandler::ShutDownChannel(int errorCode) + { + aws_channel_shutdown(GetSlot()->channel, errorCode); + } bool ChannelHandler::ChannelsThreadIsCallersThread() const { @@ -170,7 +173,10 @@ namespace Aws return aws_channel_slot_upstream_message_overhead(GetSlot()); } - struct aws_channel_slot *ChannelHandler::GetSlot() const { return m_handler.slot; } + struct aws_channel_slot *ChannelHandler::GetSlot() const + { + return m_handler.slot; + } struct TaskWrapper { @@ -213,5 +219,5 @@ namespace Aws } } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/io/EventLoopGroup.cpp b/source/io/EventLoopGroup.cpp index 000c08513..c490abb85 100644 --- a/source/io/EventLoopGroup.cpp +++ b/source/io/EventLoopGroup.cpp @@ -32,7 +32,10 @@ namespace Aws } } - EventLoopGroup::~EventLoopGroup() { aws_event_loop_group_release(m_eventLoopGroup); } + EventLoopGroup::~EventLoopGroup() + { + aws_event_loop_group_release(m_eventLoopGroup); + } EventLoopGroup::EventLoopGroup(EventLoopGroup &&toMove) noexcept : m_eventLoopGroup(toMove.m_eventLoopGroup), m_lastError(toMove.m_lastError) @@ -51,9 +54,15 @@ namespace Aws return *this; } - int EventLoopGroup::LastError() const { return m_lastError; } + int EventLoopGroup::LastError() const + { + return m_lastError; + } - EventLoopGroup::operator bool() const { return m_lastError == AWS_ERROR_SUCCESS; } + EventLoopGroup::operator bool() const + { + return m_lastError == AWS_ERROR_SUCCESS; + } aws_event_loop_group *EventLoopGroup::GetUnderlyingHandle() noexcept { diff --git a/source/io/HostResolver.cpp b/source/io/HostResolver.cpp index b395ad424..06d4d5722 100644 --- a/source/io/HostResolver.cpp +++ b/source/io/HostResolver.cpp @@ -117,5 +117,5 @@ namespace Aws return true; } } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/io/Pkcs11.cpp b/source/io/Pkcs11.cpp index 6e7128738..2206abd2f 100644 --- a/source/io/Pkcs11.cpp +++ b/source/io/Pkcs11.cpp @@ -62,8 +62,11 @@ namespace Aws Pkcs11Lib::Pkcs11Lib(aws_pkcs11_lib &impl) : impl(&impl) {} - Pkcs11Lib::~Pkcs11Lib() { aws_pkcs11_lib_release(impl); } + Pkcs11Lib::~Pkcs11Lib() + { + aws_pkcs11_lib_release(impl); + } } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/io/SocketOptions.cpp b/source/io/SocketOptions.cpp index 339b81c08..c6fac9060 100644 --- a/source/io/SocketOptions.cpp +++ b/source/io/SocketOptions.cpp @@ -24,5 +24,5 @@ namespace Aws options.keepalive = false; } } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/io/Stream.cpp b/source/io/Stream.cpp index cf3d6d1cf..975d1c516 100644 --- a/source/io/Stream.cpp +++ b/source/io/Stream.cpp @@ -207,5 +207,5 @@ namespace Aws return true; } } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/io/TlsOptions.cpp b/source/io/TlsOptions.cpp index 6077912c9..69717bdca 100644 --- a/source/io/TlsOptions.cpp +++ b/source/io/TlsOptions.cpp @@ -24,7 +24,10 @@ namespace Aws } } - TlsContextOptions::TlsContextOptions() noexcept : m_isInit(false) { AWS_ZERO_STRUCT(m_options); } + TlsContextOptions::TlsContextOptions() noexcept : m_isInit(false) + { + AWS_ZERO_STRUCT(m_options); + } TlsContextOptions::TlsContextOptions(TlsContextOptions &&other) noexcept { @@ -139,9 +142,15 @@ namespace Aws return ctxOptions; } - int TlsContextOptions::LastError() const noexcept { return LastErrorOrUnknown(); } + int TlsContextOptions::LastError() const noexcept + { + return LastErrorOrUnknown(); + } - bool TlsContextOptions::IsAlpnSupported() noexcept { return aws_tls_is_alpn_available(); } + bool TlsContextOptions::IsAlpnSupported() noexcept + { + return aws_tls_is_alpn_available(); + } bool TlsContextOptions::SetAlpnList(const char *alpn_list) noexcept { @@ -186,11 +195,20 @@ namespace Aws { } - void TlsContextPkcs11Options::SetUserPin(const String &pin) noexcept { m_userPin = pin; } + void TlsContextPkcs11Options::SetUserPin(const String &pin) noexcept + { + m_userPin = pin; + } - void TlsContextPkcs11Options::SetSlotId(const uint64_t id) noexcept { m_slotId = id; } + void TlsContextPkcs11Options::SetSlotId(const uint64_t id) noexcept + { + m_slotId = id; + } - void TlsContextPkcs11Options::SetTokenLabel(const String &label) noexcept { m_tokenLabel = label; } + void TlsContextPkcs11Options::SetTokenLabel(const String &label) noexcept + { + m_tokenLabel = label; + } void TlsContextPkcs11Options::SetPrivateKeyObjectLabel(const String &label) noexcept { @@ -416,11 +434,15 @@ namespace Aws underlying_tls_ctx->alloc = allocator; underlying_tls_ctx->impl = impl; - aws_ref_count_init(&underlying_tls_ctx->ref_count, underlying_tls_ctx, [](void *userdata) { - auto dying_ctx = static_cast(userdata); - ApiHandle::GetBYOCryptoDeleteTlsContextImplCallback()(dying_ctx->impl); - aws_mem_release(dying_ctx->alloc, dying_ctx); - }); + aws_ref_count_init( + &underlying_tls_ctx->ref_count, + underlying_tls_ctx, + [](void *userdata) + { + auto dying_ctx = static_cast(userdata); + ApiHandle::GetBYOCryptoDeleteTlsContextImplCallback()(dying_ctx->impl); + aws_mem_release(dying_ctx->alloc, dying_ctx); + }); m_ctx.reset(underlying_tls_ctx, aws_tls_ctx_release); #else @@ -470,7 +492,10 @@ namespace Aws aws_byte_buf_init(&m_protocolByteBuf, allocator, 16); } - TlsChannelHandler::~TlsChannelHandler() { aws_byte_buf_clean_up(&m_protocolByteBuf); } + TlsChannelHandler::~TlsChannelHandler() + { + aws_byte_buf_clean_up(&m_protocolByteBuf); + } void TlsChannelHandler::CompleteTlsNegotiation(int errorCode) { @@ -486,7 +511,7 @@ namespace Aws } } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws #if BYO_CRYPTO diff --git a/source/io/Uri.cpp b/source/io/Uri.cpp index f882892c1..caebdf333 100644 --- a/source/io/Uri.cpp +++ b/source/io/Uri.cpp @@ -10,7 +10,10 @@ namespace Aws { namespace Io { - Uri::Uri() noexcept : m_lastError(AWS_ERROR_SUCCESS), m_isInit(false) { AWS_ZERO_STRUCT(m_uri); } + Uri::Uri() noexcept : m_lastError(AWS_ERROR_SUCCESS), m_isInit(false) + { + AWS_ZERO_STRUCT(m_uri); + } Uri::~Uri() { @@ -125,21 +128,45 @@ namespace Aws return *this; } - ByteCursor Uri::GetScheme() const noexcept { return m_uri.scheme; } + ByteCursor Uri::GetScheme() const noexcept + { + return m_uri.scheme; + } - ByteCursor Uri::GetAuthority() const noexcept { return m_uri.authority; } + ByteCursor Uri::GetAuthority() const noexcept + { + return m_uri.authority; + } - ByteCursor Uri::GetPath() const noexcept { return m_uri.path; } + ByteCursor Uri::GetPath() const noexcept + { + return m_uri.path; + } - ByteCursor Uri::GetQueryString() const noexcept { return m_uri.query_string; } + ByteCursor Uri::GetQueryString() const noexcept + { + return m_uri.query_string; + } - ByteCursor Uri::GetHostName() const noexcept { return m_uri.host_name; } + ByteCursor Uri::GetHostName() const noexcept + { + return m_uri.host_name; + } - uint32_t Uri::GetPort() const noexcept { return m_uri.port; } + uint32_t Uri::GetPort() const noexcept + { + return m_uri.port; + } - ByteCursor Uri::GetPathAndQuery() const noexcept { return m_uri.path_and_query; } + ByteCursor Uri::GetPathAndQuery() const noexcept + { + return m_uri.path_and_query; + } - ByteCursor Uri::GetFullUri() const noexcept { return ByteCursorFromByteBuf(m_uri.uri_str); } + ByteCursor Uri::GetFullUri() const noexcept + { + return ByteCursorFromByteBuf(m_uri.uri_str); + } Aws::Crt::String EncodeQueryParameterValue(ByteCursor paramValue) { @@ -155,5 +182,5 @@ namespace Aws return encoded_value; } } // namespace Io - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/iot/Mqtt5Client.cpp b/source/iot/Mqtt5Client.cpp index 6915527d3..46aaa8e29 100644 --- a/source/iot/Mqtt5Client.cpp +++ b/source/iot/Mqtt5Client.cpp @@ -576,13 +576,13 @@ namespace Aws auto websocketConfig = m_websocketConfig.value(); auto signerTransform = [websocketConfig]( std::shared_ptr req, - const Crt::Mqtt::OnWebSocketHandshakeInterceptComplete &onComplete) { + const Crt::Mqtt::OnWebSocketHandshakeInterceptComplete &onComplete) + { // it is only a very happy coincidence that these function signatures match. This is the callback // for signing to be complete. It invokes the callback for websocket handshake to be complete. auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; auto signerConfig = websocketConfig.CreateSigningConfigCb(); @@ -611,7 +611,10 @@ namespace Aws AWS_ZERO_STRUCT(m_passwordStorage); } - Aws::Iot::Mqtt5CustomAuthConfig::~Mqtt5CustomAuthConfig() { aws_byte_buf_clean_up(&m_passwordStorage); } + Aws::Iot::Mqtt5CustomAuthConfig::~Mqtt5CustomAuthConfig() + { + aws_byte_buf_clean_up(&m_passwordStorage); + } Aws::Iot::Mqtt5CustomAuthConfig::Mqtt5CustomAuthConfig(const Mqtt5CustomAuthConfig &rhs) { @@ -683,17 +686,35 @@ namespace Aws return *this; } - const Crt::Optional &Mqtt5CustomAuthConfig::GetAuthorizerName() { return m_authorizerName; } + const Crt::Optional &Mqtt5CustomAuthConfig::GetAuthorizerName() + { + return m_authorizerName; + } - const Crt::Optional &Mqtt5CustomAuthConfig::GetUsername() { return m_username; } + const Crt::Optional &Mqtt5CustomAuthConfig::GetUsername() + { + return m_username; + } - const Crt::Optional &Mqtt5CustomAuthConfig::GetPassword() { return m_password; } + const Crt::Optional &Mqtt5CustomAuthConfig::GetPassword() + { + return m_password; + } - const Crt::Optional &Mqtt5CustomAuthConfig::GetTokenKeyName() { return m_tokenKeyName; } + const Crt::Optional &Mqtt5CustomAuthConfig::GetTokenKeyName() + { + return m_tokenKeyName; + } - const Crt::Optional &Mqtt5CustomAuthConfig::GetTokenValue() { return m_tokenValue; } + const Crt::Optional &Mqtt5CustomAuthConfig::GetTokenValue() + { + return m_tokenValue; + } - const Crt::Optional &Mqtt5CustomAuthConfig::GetTokenSignature() { return m_tokenSignature; } + const Crt::Optional &Mqtt5CustomAuthConfig::GetTokenSignature() + { + return m_tokenSignature; + } Mqtt5CustomAuthConfig &Aws::Iot::Mqtt5CustomAuthConfig::WithAuthorizerName(Crt::String authName) { diff --git a/source/iot/MqttClient.cpp b/source/iot/MqttClient.cpp index 7e8b1772e..7ff917f5c 100644 --- a/source/iot/MqttClient.cpp +++ b/source/iot/MqttClient.cpp @@ -528,13 +528,13 @@ namespace Aws auto websocketConfig = m_websocketConfig.value(); auto signerTransform = [websocketConfig]( std::shared_ptr req, - const Crt::Mqtt::OnWebSocketHandshakeInterceptComplete &onComplete) { + const Crt::Mqtt::OnWebSocketHandshakeInterceptComplete &onComplete) + { // it is only a very happy coincidence that these function signatures match. This is the callback // for signing to be complete. It invokes the callback for websocket handshake to be complete. auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; auto signerConfig = websocketConfig.CreateSigningConfigCb(); diff --git a/source/iot/MqttCommon.cpp b/source/iot/MqttCommon.cpp index e96c7b5e7..4bb6530f5 100644 --- a/source/iot/MqttCommon.cpp +++ b/source/iot/MqttCommon.cpp @@ -32,7 +32,8 @@ namespace Aws auto credsProviderRef = CredentialsProvider; auto signingRegionCopy = SigningRegion; auto serviceNameCopy = ServiceName; - CreateSigningConfigCb = [allocator, credsProviderRef, signingRegionCopy, serviceNameCopy]() { + CreateSigningConfigCb = [allocator, credsProviderRef, signingRegionCopy, serviceNameCopy]() + { auto signerConfig = Aws::Crt::MakeShared(allocator); signerConfig->SetRegion(signingRegionCopy); signerConfig->SetService(serviceNameCopy); @@ -61,7 +62,8 @@ namespace Aws auto credsProviderRef = CredentialsProvider; auto signingRegionCopy = SigningRegion; auto serviceNameCopy = ServiceName; - CreateSigningConfigCb = [allocator, credsProviderRef, signingRegionCopy, serviceNameCopy]() { + CreateSigningConfigCb = [allocator, credsProviderRef, signingRegionCopy, serviceNameCopy]() + { auto signerConfig = Aws::Crt::MakeShared(allocator); signerConfig->SetRegion(signingRegionCopy); signerConfig->SetService(serviceNameCopy); diff --git a/source/mqtt/Mqtt5Client.cpp b/source/mqtt/Mqtt5Client.cpp index 44bf64da5..fbc75c098 100644 --- a/source/mqtt/Mqtt5Client.cpp +++ b/source/mqtt/Mqtt5Client.cpp @@ -61,9 +61,15 @@ namespace Aws toSeat, [allocator](Mqtt5Client *client) { Crt::Delete(client, allocator); }); } - Mqtt5Client::operator bool() const noexcept { return m_client_core != nullptr; } + Mqtt5Client::operator bool() const noexcept + { + return m_client_core != nullptr; + } - int Mqtt5Client::LastError() const noexcept { return aws_last_error(); } + int Mqtt5Client::LastError() const noexcept + { + return aws_last_error(); + } bool Mqtt5Client::Start() const noexcept { @@ -407,5 +413,5 @@ namespace Aws } } // namespace Mqtt5 - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/mqtt/Mqtt5ClientCore.cpp b/source/mqtt/Mqtt5ClientCore.cpp index ac24fde8f..f558dedd4 100644 --- a/source/mqtt/Mqtt5ClientCore.cpp +++ b/source/mqtt/Mqtt5ClientCore.cpp @@ -299,9 +299,8 @@ namespace Aws auto onInterceptComplete = [complete_fn, - complete_ctx](const std::shared_ptr &transformedRequest, int errorCode) { - complete_fn(transformedRequest->GetUnderlyingMessage(), errorCode, complete_ctx); - }; + complete_ctx](const std::shared_ptr &transformedRequest, int errorCode) + { complete_fn(transformedRequest->GetUnderlyingMessage(), errorCode, complete_ctx); }; client_core->websocketInterceptor(request, onInterceptComplete); } @@ -499,9 +498,15 @@ namespace Aws return shared_client; } - Mqtt5ClientCore::operator bool() const noexcept { return m_client != nullptr; } + Mqtt5ClientCore::operator bool() const noexcept + { + return m_client != nullptr; + } - int Mqtt5ClientCore::LastError() const noexcept { return aws_last_error(); } + int Mqtt5ClientCore::LastError() const noexcept + { + return aws_last_error(); + } bool Mqtt5ClientCore::Publish( std::shared_ptr publishOptions, @@ -641,9 +646,8 @@ namespace Aws auto signerTransform = [&adapterOptions]( std::shared_ptr req, - const Crt::Mqtt::OnWebSocketHandshakeInterceptComplete &onComplete) { - adapterOptions->m_websocketHandshakeTransform(std::move(req), onComplete); - }; + const Crt::Mqtt::OnWebSocketHandshakeInterceptComplete &onComplete) + { adapterOptions->m_websocketHandshakeTransform(std::move(req), onComplete); }; adapterOptions->m_webSocketInterceptor = std::move(signerTransform); } else @@ -653,6 +657,6 @@ namespace Aws return adapterOptions; } } // namespace Mqtt5 - } // namespace Crt + } // namespace Crt } // namespace Aws /*! \endcond */ diff --git a/source/mqtt/Mqtt5Packets.cpp b/source/mqtt/Mqtt5Packets.cpp index c578af921..8d8695cf3 100644 --- a/source/mqtt/Mqtt5Packets.cpp +++ b/source/mqtt/Mqtt5Packets.cpp @@ -361,13 +361,25 @@ namespace Aws aws_byte_buf_clean_up(&m_passowrdStorage); } - uint16_t ConnectPacket::getKeepAliveIntervalSec() const noexcept { return m_keepAliveIntervalSec; } + uint16_t ConnectPacket::getKeepAliveIntervalSec() const noexcept + { + return m_keepAliveIntervalSec; + } - const Crt::String &ConnectPacket::getClientId() const noexcept { return m_clientId; } + const Crt::String &ConnectPacket::getClientId() const noexcept + { + return m_clientId; + } - const Crt::Optional &ConnectPacket::getUsername() const noexcept { return m_username; } + const Crt::Optional &ConnectPacket::getUsername() const noexcept + { + return m_username; + } - const Crt::Optional &ConnectPacket::getPassword() const noexcept { return m_password; } + const Crt::Optional &ConnectPacket::getPassword() const noexcept + { + return m_password; + } const Crt::Optional &ConnectPacket::getSessionExpiryIntervalSec() const noexcept { @@ -615,13 +627,25 @@ namespace Aws return true; } - const ByteCursor &PublishPacket::getPayload() const noexcept { return m_payload; } + const ByteCursor &PublishPacket::getPayload() const noexcept + { + return m_payload; + } - Mqtt5::QOS PublishPacket::getQOS() const noexcept { return m_qos; } + Mqtt5::QOS PublishPacket::getQOS() const noexcept + { + return m_qos; + } - bool PublishPacket::getRetain() const noexcept { return m_retain; } + bool PublishPacket::getRetain() const noexcept + { + return m_retain; + } - const Crt::String &PublishPacket::getTopic() const noexcept { return m_topicName; } + const Crt::String &PublishPacket::getTopic() const noexcept + { + return m_topicName; + } const Crt::Optional &PublishPacket::getPayloadFormatIndicator() const noexcept { @@ -633,7 +657,10 @@ namespace Aws return m_messageExpiryIntervalSec; } - const Crt::Optional &PublishPacket::getTopicAlias() const noexcept { return m_topicAlias; } + const Crt::Optional &PublishPacket::getTopicAlias() const noexcept + { + return m_topicAlias; + } const Crt::Optional &PublishPacket::getResponseTopic() const noexcept { @@ -650,7 +677,10 @@ namespace Aws return m_subscriptionIdentifiers; } - const Crt::Optional &PublishPacket::getContentType() const noexcept { return m_contentType; } + const Crt::Optional &PublishPacket::getContentType() const noexcept + { + return m_contentType; + } const Crt::Vector &PublishPacket::getUserProperties() const noexcept { @@ -748,7 +778,10 @@ namespace Aws return *this; } - DisconnectReasonCode DisconnectPacket::getReasonCode() const noexcept { return m_reasonCode; } + DisconnectReasonCode DisconnectPacket::getReasonCode() const noexcept + { + return m_reasonCode; + } const Crt::Optional &DisconnectPacket::getSessionExpiryIntervalSec() const noexcept { @@ -798,9 +831,15 @@ namespace Aws setUserProperties(m_userProperties, packet.user_properties, packet.user_property_count); } - PubAckReasonCode PubAckPacket::getReasonCode() const noexcept { return m_reasonCode; } + PubAckReasonCode PubAckPacket::getReasonCode() const noexcept + { + return m_reasonCode; + } - const Crt::Optional &PubAckPacket::getReasonString() const noexcept { return m_reasonString; } + const Crt::Optional &PubAckPacket::getReasonString() const noexcept + { + return m_reasonString; + } const Crt::Vector &PubAckPacket::getUserProperties() const noexcept { @@ -830,9 +869,15 @@ namespace Aws setPacketStringOptional(m_serverReference, packet.server_reference); } - bool ConnAckPacket::getSessionPresent() const noexcept { return m_sessionPresent; } + bool ConnAckPacket::getSessionPresent() const noexcept + { + return m_sessionPresent; + } - ConnectReasonCode ConnAckPacket::getReasonCode() const noexcept { return m_reasonCode; } + ConnectReasonCode ConnAckPacket::getReasonCode() const noexcept + { + return m_reasonCode; + } const Crt::Optional &ConnAckPacket::getSessionExpiryIntervalSec() const noexcept { @@ -849,9 +894,15 @@ namespace Aws return m_receiveMaximum; } - const Crt::Optional &ConnAckPacket::getMaximumQOS() const noexcept { return m_maximumQOS; } + const Crt::Optional &ConnAckPacket::getMaximumQOS() const noexcept + { + return m_maximumQOS; + } - const Crt::Optional &ConnAckPacket::getRetainAvailable() const noexcept { return m_retainAvailable; } + const Crt::Optional &ConnAckPacket::getRetainAvailable() const noexcept + { + return m_retainAvailable; + } const Crt::Optional &ConnAckPacket::getMaximumPacketSize() const noexcept { @@ -868,9 +919,15 @@ namespace Aws return m_topicAliasMaximum; } - const Crt::Optional &ConnAckPacket::getReasonString() const noexcept { return m_reasonString; } + const Crt::Optional &ConnAckPacket::getReasonString() const noexcept + { + return m_reasonString; + } - const Vector &ConnAckPacket::getUserProperty() const noexcept { return m_userProperties; } + const Vector &ConnAckPacket::getUserProperty() const noexcept + { + return m_userProperties; + } const Crt::Optional &ConnAckPacket::getWildcardSubscriptionsAvailable() const noexcept { @@ -936,7 +993,10 @@ namespace Aws m_noLocal = noLocal; return *this; } - Subscription &Subscription::WithRetain(bool retain) noexcept { return WithRetainAsPublished(retain); } + Subscription &Subscription::WithRetain(bool retain) noexcept + { + return WithRetainAsPublished(retain); + } Subscription &Subscription::WithRetainAsPublished(bool retain) noexcept { m_retainAsPublished = retain; @@ -1089,14 +1149,20 @@ namespace Aws } } - const Crt::Optional &SubAckPacket::getReasonString() const noexcept { return m_reasonString; } + const Crt::Optional &SubAckPacket::getReasonString() const noexcept + { + return m_reasonString; + } const Crt::Vector &SubAckPacket::getUserProperties() const noexcept { return m_userProperties; } - const Crt::Vector &SubAckPacket::getReasonCodes() const noexcept { return m_reasonCodes; } + const Crt::Vector &SubAckPacket::getReasonCodes() const noexcept + { + return m_reasonCodes; + } UnsubscribePacket::UnsubscribePacket(Allocator *allocator) noexcept : m_allocator(allocator), m_userPropertiesStorage(nullptr) @@ -1217,7 +1283,10 @@ namespace Aws negotiated_settings.client_id_storage.len); } - Mqtt5::QOS NegotiatedSettings::getMaximumQOS() const noexcept { return m_maximumQOS; } + Mqtt5::QOS NegotiatedSettings::getMaximumQOS() const noexcept + { + return m_maximumQOS; + } uint32_t NegotiatedSettings::getSessionExpiryIntervalSec() const noexcept { @@ -1249,11 +1318,20 @@ namespace Aws return m_topicAliasMaximumToClient; } - uint16_t NegotiatedSettings::getServerKeepAliveSec() const noexcept { return m_serverKeepAliveSec; } + uint16_t NegotiatedSettings::getServerKeepAliveSec() const noexcept + { + return m_serverKeepAliveSec; + } - uint16_t NegotiatedSettings::getServerKeepAlive() const noexcept { return getServerKeepAliveSec(); } + uint16_t NegotiatedSettings::getServerKeepAlive() const noexcept + { + return getServerKeepAliveSec(); + } - bool NegotiatedSettings::getRetainAvailable() const noexcept { return m_retainAvailable; } + bool NegotiatedSettings::getRetainAvailable() const noexcept + { + return m_retainAvailable; + } bool NegotiatedSettings::getWildcardSubscriptionsAvailable() const noexcept { @@ -1270,18 +1348,30 @@ namespace Aws return m_sharedSubscriptionsAvailable; } - bool NegotiatedSettings::getRejoinedSession() const noexcept { return m_rejoinedSession; } + bool NegotiatedSettings::getRejoinedSession() const noexcept + { + return m_rejoinedSession; + } - const Crt::String &NegotiatedSettings::getClientId() const noexcept { return m_clientId; } + const Crt::String &NegotiatedSettings::getClientId() const noexcept + { + return m_clientId; + } PublishResult::PublishResult() : m_ack(nullptr), m_errorCode(0) {} - PublishResult::PublishResult(std::shared_ptr puback) : m_errorCode(0) { m_ack = puback; } + PublishResult::PublishResult(std::shared_ptr puback) : m_errorCode(0) + { + m_ack = puback; + } PublishResult::PublishResult(int error) : m_ack(nullptr), m_errorCode(error) {} - PublishResult::~PublishResult() noexcept { m_ack.reset(); } + PublishResult::~PublishResult() noexcept + { + m_ack.reset(); + } } // namespace Mqtt5 - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/mqtt/MqttClient.cpp b/source/mqtt/MqttClient.cpp index ae768338c..63798bfc4 100644 --- a/source/mqtt/MqttClient.cpp +++ b/source/mqtt/MqttClient.cpp @@ -55,9 +55,15 @@ namespace Aws return *this; } - MqttClient::operator bool() const noexcept { return m_client != nullptr; } + MqttClient::operator bool() const noexcept + { + return m_client != nullptr; + } - int MqttClient::LastError() const noexcept { return aws_last_error(); } + int MqttClient::LastError() const noexcept + { + return aws_last_error(); + } std::shared_ptr MqttClient::NewConnection( const char *hostName, @@ -107,5 +113,5 @@ namespace Aws return MqttConnection::s_CreateMqttConnection(m_client, std::move(connectionOptions)); } } // namespace Mqtt - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/mqtt/MqttConnection.cpp b/source/mqtt/MqttConnection.cpp index 23815488a..c65729289 100644 --- a/source/mqtt/MqttConnection.cpp +++ b/source/mqtt/MqttConnection.cpp @@ -205,9 +205,8 @@ namespace Aws AWS_ASSERT(m_connectionCore != nullptr); return m_connectionCore->SetOnMessageHandler( [onPublish]( - MqttConnection &connection, const String &topic, const ByteBuf &payload, bool, QOS, bool) { - onPublish(connection, topic, payload); - }); + MqttConnection &connection, const String &topic, const ByteBuf &payload, bool, QOS, bool) + { onPublish(connection, topic, payload); }); } bool MqttConnection::SetOnMessageHandler(OnMessageReceivedHandler &&onMessage) noexcept @@ -227,9 +226,8 @@ namespace Aws topicFilter, qos, [onPublish]( - MqttConnection &connection, const String &topic, const ByteBuf &payload, bool, QOS, bool) { - onPublish(connection, topic, payload); - }, + MqttConnection &connection, const String &topic, const ByteBuf &payload, bool, QOS, bool) + { onPublish(connection, topic, payload); }, std::move(onSubAck)); } @@ -258,9 +256,8 @@ namespace Aws newTopicFilters.emplace_back( pair.first, [pubHandler]( - MqttConnection &connection, const String &topic, const ByteBuf &payload, bool, QOS, bool) { - pubHandler(connection, topic, payload); - }); + MqttConnection &connection, const String &topic, const ByteBuf &payload, bool, QOS, bool) + { pubHandler(connection, topic, payload); }); } return m_connectionCore->Subscribe(newTopicFilters, qos, std::move(onOpComplete)); } @@ -299,5 +296,5 @@ namespace Aws return m_connectionCore->GetOperationStatistics(); } } // namespace Mqtt - } // namespace Crt + } // namespace Crt } // namespace Aws diff --git a/source/mqtt/MqttConnectionCore.cpp b/source/mqtt/MqttConnectionCore.cpp index 0f37ae979..96b0f46dd 100644 --- a/source/mqtt/MqttConnectionCore.cpp +++ b/source/mqtt/MqttConnectionCore.cpp @@ -528,9 +528,8 @@ namespace Aws auto onInterceptComplete = [completeFn, - completeCtx](const std::shared_ptr &transformedRequest, int errorCode) { - completeFn(transformedRequest->GetUnderlyingMessage(), errorCode, completeCtx); - }; + completeCtx](const std::shared_ptr &transformedRequest, int errorCode) + { completeFn(transformedRequest->GetUnderlyingMessage(), errorCode, completeCtx); }; if (connection->WebsocketInterceptor) { @@ -538,7 +537,10 @@ namespace Aws } } - MqttConnectionCore::operator bool() const noexcept { return m_underlyingConnection != nullptr; } + MqttConnectionCore::operator bool() const noexcept + { + return m_underlyingConnection != nullptr; + } void MqttConnectionCore::Destroy() { @@ -555,7 +557,10 @@ namespace Aws } } - int MqttConnectionCore::LastError() const noexcept { return aws_last_error(); } + int MqttConnectionCore::LastError() const noexcept + { + return aws_last_error(); + } bool MqttConnectionCore::SetWill(const char *topic, QOS qos, bool retain, const ByteBuf &payload) noexcept { @@ -919,6 +924,6 @@ namespace Aws return m_operationStatistics; } } // namespace Mqtt - } // namespace Crt + } // namespace Crt } // namespace Aws /*! \endcond */ diff --git a/tests/CredentialsTest.cpp b/tests/CredentialsTest.cpp index cd0eb0914..3f246639c 100644 --- a/tests/CredentialsTest.cpp +++ b/tests/CredentialsTest.cpp @@ -46,8 +46,8 @@ class GetCredentialsWaiter m_credentials = nullptr; } - m_provider->GetCredentials( - [this](std::shared_ptr credentials, int error_code) { OnCreds(credentials, error_code); }); + m_provider->GetCredentials([this](std::shared_ptr credentials, int error_code) + { OnCreds(credentials, error_code); }); { std::unique_lock lock(m_lock); @@ -300,7 +300,8 @@ static int s_TestProviderDelegateGet(struct aws_allocator *allocator, void *ctx) { ApiHandle apiHandle(allocator); - auto delegateGetCredentials = [&allocator]() -> std::shared_ptr { + auto delegateGetCredentials = [&allocator]() -> std::shared_ptr + { Credentials credentials( aws_byte_cursor_from_c_str(s_access_key_id), aws_byte_cursor_from_c_str(s_secret_access_key), @@ -336,7 +337,8 @@ static int s_TestProviderDelegateGetAnonymous(struct aws_allocator *allocator, v { ApiHandle apiHandle(allocator); - auto delegateGetCredentials = [&allocator]() -> std::shared_ptr { + auto delegateGetCredentials = [&allocator]() -> std::shared_ptr + { Credentials credentials(allocator); return Aws::Crt::MakeShared(allocator, credentials.GetUnderlyingHandle()); }; diff --git a/tests/HashTest.cpp b/tests/HashTest.cpp index f55f7361e..4d784faf5 100644 --- a/tests/HashTest.cpp +++ b/tests/HashTest.cpp @@ -156,9 +156,9 @@ static int s_TestSHA256ResourceSafety(struct aws_allocator *allocator, void *) }; Aws::Crt::String expectedStr = Aws::Crt::String(reinterpret_cast(expected), sizeof(expected)); - apiHandle.SetBYOCryptoNewSHA256Callback([&](size_t digestSize, Aws::Crt::Allocator *allocator) { - return Aws::Crt::MakeShared(allocator, digestSize, allocator, expectedStr); - }); + apiHandle.SetBYOCryptoNewSHA256Callback( + [&](size_t digestSize, Aws::Crt::Allocator *allocator) + { return Aws::Crt::MakeShared(allocator, digestSize, allocator, expectedStr); }); Aws::Crt::Crypto::Hash sha256 = Aws::Crt::Crypto::Hash::CreateSHA256(allocator); ASSERT_TRUE(sha256); @@ -190,9 +190,9 @@ static int s_TestSHA1ResourceSafety(struct aws_allocator *allocator, void *) }; Aws::Crt::String expectedStr = Aws::Crt::String(reinterpret_cast(expected), sizeof(expected)); - apiHandle.SetBYOCryptoNewSHA1Callback([&](size_t digestSize, Aws::Crt::Allocator *allocator) { - return Aws::Crt::MakeShared(allocator, digestSize, allocator, expectedStr); - }); + apiHandle.SetBYOCryptoNewSHA1Callback( + [&](size_t digestSize, Aws::Crt::Allocator *allocator) + { return Aws::Crt::MakeShared(allocator, digestSize, allocator, expectedStr); }); Aws::Crt::Crypto::Hash sha1 = Aws::Crt::Crypto::Hash::CreateSHA1(allocator); ASSERT_TRUE(sha1); @@ -238,9 +238,9 @@ static int s_TestMD5ResourceSafety(struct aws_allocator *allocator, void *) }; Aws::Crt::String expectedStr = Aws::Crt::String(reinterpret_cast(expected), sizeof(expected)); - apiHandle.SetBYOCryptoNewMD5Callback([&](size_t digestSize, struct aws_allocator *allocator) { - return Aws::Crt::MakeShared(allocator, digestSize, allocator, expectedStr); - }); + apiHandle.SetBYOCryptoNewMD5Callback( + [&](size_t digestSize, struct aws_allocator *allocator) + { return Aws::Crt::MakeShared(allocator, digestSize, allocator, expectedStr); }); Aws::Crt::Crypto::Hash md5 = Aws::Crt::Crypto::Hash::CreateMD5(allocator); ASSERT_TRUE(md5); diff --git a/tests/HostResolverTest.cpp b/tests/HostResolverTest.cpp index 3697c9c63..366e25adb 100644 --- a/tests/HostResolverTest.cpp +++ b/tests/HostResolverTest.cpp @@ -30,7 +30,8 @@ static int s_TestDefaultResolution(struct aws_allocator *allocator, void *) auto onHostResolved = [&](Aws::Crt::Io::HostResolver &, const Aws::Crt::Vector &addresses, - int errorCode) { + int errorCode) + { { std::lock_guard lock(semaphoreLock); addressCount = addresses.size(); diff --git a/tests/HttpClientConnectionManagerTest.cpp b/tests/HttpClientConnectionManagerTest.cpp index 95d3c1d0a..3be4704d0 100644 --- a/tests/HttpClientConnectionManagerTest.cpp +++ b/tests/HttpClientConnectionManagerTest.cpp @@ -91,7 +91,8 @@ static int s_TestHttpClientConnectionManagerResourceSafety(struct aws_allocator { Vector> connections; - auto onConnectionAvailable = [&](std::shared_ptr newConnection, int errorCode) { + auto onConnectionAvailable = [&](std::shared_ptr newConnection, int errorCode) + { { std::lock_guard lockGuard(semaphoreLock); @@ -249,7 +250,8 @@ static int s_TestHttpClientConnectionWithPendingAcquisitions(struct aws_allocato { Vector> connections; - auto onConnectionAvailable = [&](std::shared_ptr newConnection, int errorCode) { + auto onConnectionAvailable = [&](std::shared_ptr newConnection, int errorCode) + { { std::lock_guard lockGuard(semaphoreLock); @@ -272,9 +274,10 @@ static int s_TestHttpClientConnectionWithPendingAcquisitions(struct aws_allocato ASSERT_TRUE(connectionManager->AcquireConnection(onConnectionAvailable)); } std::unique_lock uniqueLock(semaphoreLock); - semaphore.wait(uniqueLock, [&]() { - return connections.size() + connectionsFailed == connectionManagerOptions.MaxConnections; - }); + semaphore.wait( + uniqueLock, + [&]() + { return connections.size() + connectionsFailed == connectionManagerOptions.MaxConnections; }); } /* make sure the test was actually meaningful. */ @@ -368,7 +371,8 @@ static int s_TestHttpClientConnectionWithPendingAcquisitionsAndClosedConnections { Vector> connections; - auto onConnectionAvailable = [&](std::shared_ptr newConnection, int errorCode) { + auto onConnectionAvailable = [&](std::shared_ptr newConnection, int errorCode) + { { std::lock_guard lockGuard(semaphoreLock); @@ -391,9 +395,9 @@ static int s_TestHttpClientConnectionWithPendingAcquisitionsAndClosedConnections ASSERT_TRUE(connectionManager->AcquireConnection(onConnectionAvailable)); } std::unique_lock uniqueLock(semaphoreLock); - semaphore.wait(uniqueLock, [&]() { - return connectionCount + connectionsFailed == connectionManagerOptions.MaxConnections; - }); + semaphore.wait( + uniqueLock, + [&]() { return connectionCount + connectionsFailed == connectionManagerOptions.MaxConnections; }); } /* make sure the test was actually meaningful. */ diff --git a/tests/HttpClientTest.cpp b/tests/HttpClientTest.cpp index 8b36e4f89..05d73f69e 100644 --- a/tests/HttpClientTest.cpp +++ b/tests/HttpClientTest.cpp @@ -103,7 +103,8 @@ static int s_TestHttpDownloadNoBackPressure(struct aws_allocator *allocator, Byt std::condition_variable semaphore; std::mutex semaphoreLock; - auto onConnectionSetup = [&](const std::shared_ptr &newConnection, int errorCode) { + auto onConnectionSetup = [&](const std::shared_ptr &newConnection, int errorCode) + { std::lock_guard lockGuard(semaphoreLock); if (!errorCode) @@ -119,7 +120,8 @@ static int s_TestHttpDownloadNoBackPressure(struct aws_allocator *allocator, Byt semaphore.notify_one(); }; - auto onConnectionShutdown = [&](Http::HttpClientConnection &, int errorCode) { + auto onConnectionShutdown = [&](Http::HttpClientConnection &, int errorCode) + { std::lock_guard lockGuard(semaphoreLock); connectionShutdown = true; @@ -160,7 +162,8 @@ static int s_TestHttpDownloadNoBackPressure(struct aws_allocator *allocator, Byt requestOptions.request = &request; bool streamCompleted = false; - requestOptions.onStreamComplete = [&](Http::HttpStream &, int errorCode) { + requestOptions.onStreamComplete = [&](Http::HttpStream &, int errorCode) + { std::lock_guard lockGuard(semaphoreLock); streamCompleted = true; @@ -173,12 +176,10 @@ static int s_TestHttpDownloadNoBackPressure(struct aws_allocator *allocator, Byt }; requestOptions.onIncomingHeadersBlockDone = nullptr; requestOptions.onIncomingHeaders = - [&](Http::HttpStream &stream, enum aws_http_header_block, const Http::HttpHeader *, std::size_t) { - responseCode = stream.GetResponseStatusCode(); - }; - requestOptions.onIncomingBody = [&](Http::HttpStream &, const ByteCursor &data) { - downloadedFile.write((const char *)data.ptr, data.len); - }; + [&](Http::HttpStream &stream, enum aws_http_header_block, const Http::HttpHeader *, std::size_t) + { responseCode = stream.GetResponseStatusCode(); }; + requestOptions.onIncomingBody = [&](Http::HttpStream &, const ByteCursor &data) + { downloadedFile.write((const char *)data.ptr, data.len); }; request.SetMethod(ByteCursorFromCString("GET")); request.SetPath(uri.GetPathAndQuery()); @@ -260,7 +261,8 @@ static int s_TestHttpStreamUnActivated(struct aws_allocator *allocator, void *ct std::condition_variable semaphore; std::mutex semaphoreLock; - auto onConnectionSetup = [&](const std::shared_ptr &newConnection, int errorCode) { + auto onConnectionSetup = [&](const std::shared_ptr &newConnection, int errorCode) + { std::lock_guard lockGuard(semaphoreLock); if (!errorCode) @@ -276,7 +278,8 @@ static int s_TestHttpStreamUnActivated(struct aws_allocator *allocator, void *ct semaphore.notify_one(); }; - auto onConnectionShutdown = [&](Http::HttpClientConnection &, int errorCode) { + auto onConnectionShutdown = [&](Http::HttpClientConnection &, int errorCode) + { std::lock_guard lockGuard(semaphoreLock); connectionShutdown = true; @@ -309,15 +312,18 @@ static int s_TestHttpStreamUnActivated(struct aws_allocator *allocator, void *ct Http::HttpRequestOptions requestOptions; requestOptions.request = &request; - requestOptions.onStreamComplete = [&](Http::HttpStream &, int) { + requestOptions.onStreamComplete = [&](Http::HttpStream &, int) + { // do nothing. }; requestOptions.onIncomingHeadersBlockDone = nullptr; requestOptions.onIncomingHeaders = - [&](Http::HttpStream &, enum aws_http_header_block, const Http::HttpHeader *, std::size_t) { - // do nothing - }; - requestOptions.onIncomingBody = [&](Http::HttpStream &, const ByteCursor &) { + [&](Http::HttpStream &, enum aws_http_header_block, const Http::HttpHeader *, std::size_t) + { + // do nothing + }; + requestOptions.onIncomingBody = [&](Http::HttpStream &, const ByteCursor &) + { // do nothing }; diff --git a/tests/ImdsClientTest.cpp b/tests/ImdsClientTest.cpp index 6b2a185b8..ce8fefe6e 100644 --- a/tests/ImdsClientTest.cpp +++ b/tests/ImdsClientTest.cpp @@ -63,7 +63,8 @@ static int s_TestImdsClientGetInstanceInfo(struct aws_allocator *allocator, void int error = 0; InstanceInfo info; - auto callback = [&](const InstanceInfo &instanceInfo, int errorCode, void *) { + auto callback = [&](const InstanceInfo &instanceInfo, int errorCode, void *) + { std::unique_lock ulock(lock); info = instanceInfo; error = errorCode; @@ -114,7 +115,8 @@ static int s_TestImdsClientGetCredentials(struct aws_allocator *allocator, void InstanceInfo info; std::string role; - auto roleCallback = [&](const StringView &resource, int errorCode, void *) { + auto roleCallback = [&](const StringView &resource, int errorCode, void *) + { std::unique_lock ulock(lock); role = std::string(resource.data(), resource.size()); error = errorCode; @@ -129,7 +131,8 @@ static int s_TestImdsClientGetCredentials(struct aws_allocator *allocator, void } std::shared_ptr creds(nullptr); - auto callback = [&](const Auth::Credentials &credentials, int errorCode, void *) { + auto callback = [&](const Auth::Credentials &credentials, int errorCode, void *) + { std::unique_lock ulock(lock); creds = Aws::Crt::MakeShared(allocator, credentials.GetUnderlyingHandle()); error = errorCode; diff --git a/tests/IotServiceTest.cpp b/tests/IotServiceTest.cpp index 797da1a7b..1945d7dfc 100644 --- a/tests/IotServiceTest.cpp +++ b/tests/IotServiceTest.cpp @@ -161,7 +161,8 @@ static int s_TestIotPublishSubscribe(Aws::Crt::Allocator *allocator, void *ctx) bool published = false; bool received = false; bool closed = false; - auto onConnectionCompleted = [&](MqttConnection &, int errorCode, ReturnCode returnCode, bool sessionPresent) { + auto onConnectionCompleted = [&](MqttConnection &, int errorCode, ReturnCode returnCode, bool sessionPresent) + { printf( "%s errorCode=%d returnCode=%d sessionPresent=%d\n", (errorCode == 0) ? "CONNECTED" : "COMPLETED", @@ -174,7 +175,8 @@ static int s_TestIotPublishSubscribe(Aws::Crt::Allocator *allocator, void *ctx) } cv.notify_one(); }; - auto onDisconnect = [&](MqttConnection &) { + auto onDisconnect = [&](MqttConnection &) + { printf("DISCONNECTED\n"); { std::lock_guard lock(mutex); @@ -182,7 +184,8 @@ static int s_TestIotPublishSubscribe(Aws::Crt::Allocator *allocator, void *ctx) } cv.notify_one(); }; - auto onTest = [&](MqttConnection &, const Aws::Crt::String &topic, const Aws::Crt::ByteBuf &payload) { + auto onTest = [&](MqttConnection &, const Aws::Crt::String &topic, const Aws::Crt::ByteBuf &payload) + { printf("GOT MESSAGE topic=%s payload=" PRInSTR "\n", topic.c_str(), AWS_BYTE_BUF_PRI(payload)); { std::lock_guard lock(mutex); @@ -190,7 +193,8 @@ static int s_TestIotPublishSubscribe(Aws::Crt::Allocator *allocator, void *ctx) } cv.notify_one(); }; - auto onSubAck = [&](MqttConnection &, uint16_t packetId, const Aws::Crt::String &topic, QOS qos, int) { + auto onSubAck = [&](MqttConnection &, uint16_t packetId, const Aws::Crt::String &topic, QOS qos, int) + { printf("SUBACK id=%d topic=%s qos=%d\n", packetId, topic.c_str(), qos); { std::lock_guard lock(mutex); @@ -198,7 +202,8 @@ static int s_TestIotPublishSubscribe(Aws::Crt::Allocator *allocator, void *ctx) } cv.notify_one(); }; - auto onPubAck = [&](MqttConnection &, uint16_t packetId, int) { + auto onPubAck = [&](MqttConnection &, uint16_t packetId, int) + { printf("PUBLISHED id=%d\n", packetId); { std::lock_guard lock(mutex); @@ -206,7 +211,8 @@ static int s_TestIotPublishSubscribe(Aws::Crt::Allocator *allocator, void *ctx) } cv.notify_one(); }; - auto onConnectionClosed = [&](MqttConnection &, OnConnectionClosedData *data) { + auto onConnectionClosed = [&](MqttConnection &, OnConnectionClosedData *data) + { (void)data; printf("CLOSED\n"); { @@ -322,7 +328,8 @@ static int s_TestIotConnectionSuccessTest(Aws::Crt::Allocator *allocator, void * bool connection_success = false; bool closed = false; - auto onConnectionSuccess = [&](MqttConnection &, OnConnectionSuccessData *data) { + auto onConnectionSuccess = [&](MqttConnection &, OnConnectionSuccessData *data) + { { std::lock_guard lock(mutex); connection_success = true; @@ -331,7 +338,8 @@ static int s_TestIotConnectionSuccessTest(Aws::Crt::Allocator *allocator, void * cv.notify_one(); }; - auto onConnectionClosed = [&](MqttConnection &, OnConnectionClosedData *data) { + auto onConnectionClosed = [&](MqttConnection &, OnConnectionClosedData *data) + { (void)data; printf("CLOSED"); { @@ -417,7 +425,8 @@ static int s_TestIotConnectionFailureTest(Aws::Crt::Allocator *allocator, void * std::mutex mutex; std::condition_variable cv; bool connection_failure = false; - auto onConnectionFailure = [&](MqttConnection &, OnConnectionFailureData *data) { + auto onConnectionFailure = [&](MqttConnection &, OnConnectionFailureData *data) + { printf("CONNECTION FAILURE: error=%i\n", data->error); { std::lock_guard lock(mutex); @@ -500,17 +509,19 @@ static int s_TestIotWillTest(Aws::Crt::Allocator *allocator, void *ctx) std::condition_variable willCv; bool willConnected = false; auto willOnConnectionCompleted = - [&](MqttConnection &, int errorCode, ReturnCode returnCode, bool sessionPresent) { - (void)errorCode; - (void)returnCode; - (void)sessionPresent; - { - std::lock_guard lock(willMutex); - willConnected = true; - } - willCv.notify_one(); - }; - auto willOnDisconnect = [&](MqttConnection &) { + [&](MqttConnection &, int errorCode, ReturnCode returnCode, bool sessionPresent) + { + (void)errorCode; + (void)returnCode; + (void)sessionPresent; + { + std::lock_guard lock(willMutex); + willConnected = true; + } + willCv.notify_one(); + }; + auto willOnDisconnect = [&](MqttConnection &) + { { std::lock_guard lock(willMutex); willConnected = false; @@ -533,17 +544,19 @@ static int s_TestIotWillTest(Aws::Crt::Allocator *allocator, void *ctx) bool subscriberSubscribed = false; bool subscriberReceived = false; auto subscriberOnConnectionCompleted = - [&](MqttConnection &, int errorCode, ReturnCode returnCode, bool sessionPresent) { - (void)errorCode; - (void)returnCode; - (void)sessionPresent; - { - std::lock_guard lock(subscriberMutex); - subscriberConnected = true; - } - subscriberCv.notify_one(); - }; - auto subscriberOnDisconnect = [&](MqttConnection &) { + [&](MqttConnection &, int errorCode, ReturnCode returnCode, bool sessionPresent) + { + (void)errorCode; + (void)returnCode; + (void)sessionPresent; + { + std::lock_guard lock(subscriberMutex); + subscriberConnected = true; + } + subscriberCv.notify_one(); + }; + auto subscriberOnDisconnect = [&](MqttConnection &) + { { std::lock_guard lock(subscriberMutex); subscriberConnected = false; @@ -551,18 +564,19 @@ static int s_TestIotWillTest(Aws::Crt::Allocator *allocator, void *ctx) subscriberCv.notify_one(); } }; - auto subscriberOnSubAck = - [&](MqttConnection &, uint16_t packetId, const Aws::Crt::String &topic, QOS qos, int) { - (void)packetId; - (void)topic; - (void)qos; - { - std::lock_guard lock(subscriberMutex); - subscriberSubscribed = true; - } - subscriberCv.notify_one(); - }; - auto subscriberOnTest = [&](MqttConnection &, const Aws::Crt::String &topic, const Aws::Crt::ByteBuf &payload) { + auto subscriberOnSubAck = [&](MqttConnection &, uint16_t packetId, const Aws::Crt::String &topic, QOS qos, int) + { + (void)packetId; + (void)topic; + (void)qos; + { + std::lock_guard lock(subscriberMutex); + subscriberSubscribed = true; + } + subscriberCv.notify_one(); + }; + auto subscriberOnTest = [&](MqttConnection &, const Aws::Crt::String &topic, const Aws::Crt::ByteBuf &payload) + { (void)topic; (void)payload; { @@ -593,17 +607,19 @@ static int s_TestIotWillTest(Aws::Crt::Allocator *allocator, void *ctx) std::condition_variable interruptCv; bool interruptConnected = false; auto interruptOnConnectionCompleted = - [&](MqttConnection &, int errorCode, ReturnCode returnCode, bool sessionPresent) { - (void)errorCode; - (void)returnCode; - (void)sessionPresent; - { - std::lock_guard lock(interruptMutex); - interruptConnected = true; - } - interruptCv.notify_one(); - }; - auto interruptOnDisconnect = [&](MqttConnection &) { + [&](MqttConnection &, int errorCode, ReturnCode returnCode, bool sessionPresent) + { + (void)errorCode; + (void)returnCode; + (void)sessionPresent; + { + std::lock_guard lock(interruptMutex); + interruptConnected = true; + } + interruptCv.notify_one(); + }; + auto interruptOnDisconnect = [&](MqttConnection &) + { { std::lock_guard lock(interruptMutex); interruptConnected = false; @@ -696,7 +712,8 @@ static int s_TestIotStatisticsPublishWaitStatisticsDisconnect(Aws::Crt::Allocato std::condition_variable cv; bool connected = false; bool published = false; - auto onConnectionCompleted = [&](MqttConnection &, int errorCode, ReturnCode returnCode, bool sessionPresent) { + auto onConnectionCompleted = [&](MqttConnection &, int errorCode, ReturnCode returnCode, bool sessionPresent) + { printf( "%s errorCode=%d returnCode=%d sessionPresent=%d\n", (errorCode == 0) ? "CONNECTED" : "COMPLETED", @@ -709,7 +726,8 @@ static int s_TestIotStatisticsPublishWaitStatisticsDisconnect(Aws::Crt::Allocato } cv.notify_one(); }; - auto onDisconnect = [&](MqttConnection &) { + auto onDisconnect = [&](MqttConnection &) + { printf("DISCONNECTED\n"); { std::lock_guard lock(mutex); @@ -718,7 +736,8 @@ static int s_TestIotStatisticsPublishWaitStatisticsDisconnect(Aws::Crt::Allocato cv.notify_one(); } }; - auto onPubAck = [&](MqttConnection &, uint16_t packetId, int) { + auto onPubAck = [&](MqttConnection &, uint16_t packetId, int) + { printf("PUBLISHED id=%d\n", packetId); { std::lock_guard lock(mutex); @@ -826,7 +845,8 @@ static int s_TestIotStatisticsPublishStatisticsWaitDisconnect(Aws::Crt::Allocato std::condition_variable cv; bool connected = false; bool published = false; - auto onConnectionCompleted = [&](MqttConnection &, int errorCode, ReturnCode returnCode, bool sessionPresent) { + auto onConnectionCompleted = [&](MqttConnection &, int errorCode, ReturnCode returnCode, bool sessionPresent) + { printf( "%s errorCode=%d returnCode=%d sessionPresent=%d\n", (errorCode == 0) ? "CONNECTED" : "COMPLETED", @@ -839,7 +859,8 @@ static int s_TestIotStatisticsPublishStatisticsWaitDisconnect(Aws::Crt::Allocato } cv.notify_one(); }; - auto onDisconnect = [&](MqttConnection &) { + auto onDisconnect = [&](MqttConnection &) + { printf("DISCONNECTED\n"); { std::lock_guard lock(mutex); @@ -848,7 +869,8 @@ static int s_TestIotStatisticsPublishStatisticsWaitDisconnect(Aws::Crt::Allocato cv.notify_one(); } }; - auto onPubAck = [&](MqttConnection &, uint16_t packetId, int) { + auto onPubAck = [&](MqttConnection &, uint16_t packetId, int) + { printf("PUBLISHED id=%d\n", packetId); { std::lock_guard lock(mutex); @@ -961,7 +983,8 @@ static int s_TestIotConnectionDestruction(Aws::Crt::Allocator *allocator, void * std::condition_variable cv; bool connection_success = false; - auto onConnectionSuccess = [&](MqttConnection &, OnConnectionSuccessData *data) { + auto onConnectionSuccess = [&](MqttConnection &, OnConnectionSuccessData *data) + { { std::lock_guard lock(mutex); connection_success = true; @@ -1043,7 +1066,8 @@ static int s_TestIotConnectionDestructionWithExecutingCallback(Aws::Crt::Allocat bool connectionSuccess = false; bool disconnectingStarted = false; - auto onConnectionSuccess = [&](MqttConnection &, OnConnectionSuccessData *data) { + auto onConnectionSuccess = [&](MqttConnection &, OnConnectionSuccessData *data) + { { std::lock_guard lock(mutex); connectionSuccess = true; @@ -1054,7 +1078,8 @@ static int s_TestIotConnectionDestructionWithExecutingCallback(Aws::Crt::Allocat mqttConnection->OnConnectionSuccess = onConnectionSuccess; - mqttConnection->OnDisconnect = [&](MqttConnection &) { + mqttConnection->OnDisconnect = [&](MqttConnection &) + { { std::lock_guard lock(mutex); disconnectingStarted = true; @@ -1143,7 +1168,8 @@ static int s_TestIotConnectionDestructionWithinConnectionCallback(Aws::Crt::Allo std::condition_variable cv; bool connection_success = false; - auto onConnectionSuccess = [&](MqttConnection &, OnConnectionSuccessData *data) { + auto onConnectionSuccess = [&](MqttConnection &, OnConnectionSuccessData *data) + { // Destroy mqtt connection object. mqttConnection.reset(); @@ -1225,7 +1251,8 @@ static int s_TestIotConnectionDestructionWithinDisconnectCallback(Aws::Crt::Allo bool connectionSuccess = false; bool disconnected = false; - auto onConnectionSuccess = [&](MqttConnection &, OnConnectionSuccessData *data) { + auto onConnectionSuccess = [&](MqttConnection &, OnConnectionSuccessData *data) + { { std::lock_guard lock(mutex); connectionSuccess = true; @@ -1236,7 +1263,8 @@ static int s_TestIotConnectionDestructionWithinDisconnectCallback(Aws::Crt::Allo mqttConnection->OnConnectionSuccess = onConnectionSuccess; - mqttConnection->OnDisconnect = [&](MqttConnection &) { + mqttConnection->OnDisconnect = [&](MqttConnection &) + { // Destroy mqtt connection object. mqttConnection.reset(); { @@ -1321,7 +1349,8 @@ static int s_TestIotConnectionDestructionWithPublish(Aws::Crt::Allocator *alloca std::condition_variable cv; bool connected = false; bool published = false; - auto onConnectionSuccess = [&](MqttConnection &, OnConnectionSuccessData * /*data*/) { + auto onConnectionSuccess = [&](MqttConnection &, OnConnectionSuccessData * /*data*/) + { { std::lock_guard lock(mutex); connected = true; @@ -1341,7 +1370,8 @@ static int s_TestIotConnectionDestructionWithPublish(Aws::Crt::Allocator *alloca // Publish data. Aws::Crt::ByteBuf payload = Aws::Crt::ByteBufFromCString("notice me pls"); - auto onPubAck = [&](MqttConnection &connection, uint16_t packetId, int) { + auto onPubAck = [&](MqttConnection &connection, uint16_t packetId, int) + { { std::lock_guard lock(mutex); published = true; diff --git a/tests/Mqtt5ClientCredentialsTest.cpp b/tests/Mqtt5ClientCredentialsTest.cpp index ca15e3c23..01dacbad3 100644 --- a/tests/Mqtt5ClientCredentialsTest.cpp +++ b/tests/Mqtt5ClientCredentialsTest.cpp @@ -124,21 +124,25 @@ static void s_setupConnectionLifeCycle( const char *clientName = "Client") { mqtt5Builder->WithClientConnectionSuccessCallback( - [&connectionPromise, clientName](const OnConnectionSuccessEventData &) { + [&connectionPromise, clientName](const OnConnectionSuccessEventData &) + { printf("[MQTT5]%s Connection Success.", clientName); connectionPromise.set_value(true); }); mqtt5Builder->WithClientConnectionFailureCallback( - [&connectionPromise, clientName](const OnConnectionFailureEventData &eventData) { + [&connectionPromise, clientName](const OnConnectionFailureEventData &eventData) + { printf("[MQTT5]%s Connection failed with error : %s", clientName, aws_error_debug_str(eventData.errorCode)); connectionPromise.set_value(false); }); - mqtt5Builder->WithClientStoppedCallback([&stoppedPromise, clientName](const OnStoppedEventData &) { - printf("[MQTT5]%s Stopped", clientName); - stoppedPromise.set_value(); - }); + mqtt5Builder->WithClientStoppedCallback( + [&stoppedPromise, clientName](const OnStoppedEventData &) + { + printf("[MQTT5]%s Stopped", clientName); + stoppedPromise.set_value(); + }); } static int s_CheckClientAndStop( diff --git a/tests/Mqtt5ClientTest.cpp b/tests/Mqtt5ClientTest.cpp index e2a390c0f..ad14dfcc0 100644 --- a/tests/Mqtt5ClientTest.cpp +++ b/tests/Mqtt5ClientTest.cpp @@ -29,21 +29,26 @@ static void s_setupConnectionLifeCycle( const char *clientName = "Client") { mqtt5Options.WithClientConnectionSuccessCallback( - [&connectionPromise, clientName](const OnConnectionSuccessEventData &) { + [&connectionPromise, clientName](const OnConnectionSuccessEventData &) + { printf("[MQTT5]%s Connection Success.\n", clientName); connectionPromise.set_value(true); }); - mqtt5Options.WithClientConnectionFailureCallback([&connectionPromise, - clientName](const OnConnectionFailureEventData &eventData) { - printf("[MQTT5]%s Connection failed with error : %s\n", clientName, aws_error_debug_str(eventData.errorCode)); - connectionPromise.set_value(false); - }); + mqtt5Options.WithClientConnectionFailureCallback( + [&connectionPromise, clientName](const OnConnectionFailureEventData &eventData) + { + printf( + "[MQTT5]%s Connection failed with error : %s\n", clientName, aws_error_debug_str(eventData.errorCode)); + connectionPromise.set_value(false); + }); - mqtt5Options.WithClientStoppedCallback([&stoppedPromise, clientName](const OnStoppedEventData &) { - printf("[MQTT5]%s Stopped\n", clientName); - stoppedPromise.set_value(); - }); + mqtt5Options.WithClientStoppedCallback( + [&stoppedPromise, clientName](const OnStoppedEventData &) + { + printf("[MQTT5]%s Stopped\n", clientName); + stoppedPromise.set_value(); + }); } /* @@ -449,21 +454,25 @@ static void s_setupConnectionLifeCycle( const char *clientName = "Client") { mqtt5Builder->WithClientConnectionSuccessCallback( - [&connectionPromise, clientName](const OnConnectionSuccessEventData &) { + [&connectionPromise, clientName](const OnConnectionSuccessEventData &) + { printf("[MQTT5]%s Connection Success.", clientName); connectionPromise.set_value(true); }); mqtt5Builder->WithClientConnectionFailureCallback( - [&connectionPromise, clientName](const OnConnectionFailureEventData &eventData) { + [&connectionPromise, clientName](const OnConnectionFailureEventData &eventData) + { printf("[MQTT5]%s Connection failed with error : %s", clientName, aws_error_debug_str(eventData.errorCode)); connectionPromise.set_value(false); }); - mqtt5Builder->WithClientStoppedCallback([&stoppedPromise, clientName](const OnStoppedEventData &) { - printf("[MQTT5]%s Stopped", clientName); - stoppedPromise.set_value(); - }); + mqtt5Builder->WithClientStoppedCallback( + [&stoppedPromise, clientName](const OnStoppedEventData &) + { + printf("[MQTT5]%s Stopped", clientName); + stoppedPromise.set_value(); + }); } ////////////////////////////////////////////////////////// @@ -803,11 +812,10 @@ static int s_TestMqtt5WSConnectionMinimal(Aws::Crt::Allocator *allocator, void * mqtt5Options.WithWebsocketHandshakeTransformCallback( [config]( std::shared_ptr req, - const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) { - auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) + { + auto signingComplete = [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; auto signerConfig = config.CreateSigningConfigCb(); @@ -863,11 +871,10 @@ static int s_TestMqtt5WSConnectionWithBasicAuth(Aws::Crt::Allocator *allocator, mqtt5Options.WithWebsocketHandshakeTransformCallback( [config]( std::shared_ptr req, - const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) { - auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) + { + auto signingComplete = [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; auto signerConfig = config.CreateSigningConfigCb(); @@ -929,11 +936,10 @@ static int s_TestMqtt5WSConnectionWithTLS(Aws::Crt::Allocator *allocator, void * mqtt5Options.WithWebsocketHandshakeTransformCallback( [config]( std::shared_ptr req, - const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) { - auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) + { + auto signingComplete = [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; auto signerConfig = config.CreateSigningConfigCb(); @@ -995,11 +1001,10 @@ static int s_TestMqtt5WSConnectionWithMutualTLS(Aws::Crt::Allocator *allocator, mqtt5Options.WithWebsocketHandshakeTransformCallback( [config]( std::shared_ptr req, - const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) { - auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) + { + auto signingComplete = [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; auto signerConfig = config.CreateSigningConfigCb(); @@ -1069,11 +1074,10 @@ static int s_TestMqtt5WSConnectionWithHttpProxy(Aws::Crt::Allocator *allocator, mqtt5Options.WithWebsocketHandshakeTransformCallback( [config]( std::shared_ptr req, - const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) { - auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) + { + auto signingComplete = [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; auto signerConfig = config.CreateSigningConfigCb(); @@ -1180,11 +1184,10 @@ static int s_TestMqtt5WSConnectionFull(Aws::Crt::Allocator *allocator, void *) mqtt5Options.WithWebsocketHandshakeTransformCallback( [config]( std::shared_ptr req, - const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) { - auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) + { + auto signingComplete = [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; auto signerConfig = config.CreateSigningConfigCb(); @@ -1305,11 +1308,10 @@ static int s_TestMqtt5WSInvalidPort(Aws::Crt::Allocator *allocator, void *) mqtt5Options.WithWebsocketHandshakeTransformCallback( [config]( std::shared_ptr req, - const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) { - auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) + { + auto signingComplete = [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; auto signerConfig = config.CreateSigningConfigCb(); @@ -1355,7 +1357,8 @@ static int s_TestMqtt5SocketTimeout(Aws::Crt::Allocator *allocator, void *) // Override connection failed callback mqtt5Options.WithClientConnectionFailureCallback( - [&connectionPromise](const OnConnectionFailureEventData &eventData) { + [&connectionPromise](const OnConnectionFailureEventData &eventData) + { printf("[MQTT5]Client Connection failed with error : %s", aws_error_debug_str(eventData.errorCode)); ASSERT_TRUE(eventData.errorCode == AWS_IO_SOCKET_TIMEOUT); connectionPromise.set_value(false); @@ -1444,9 +1447,8 @@ static int s_TestMqtt5IncorrectWSConnect(Aws::Crt::Allocator *allocator, void *) mqtt5Options.WithWebsocketHandshakeTransformCallback( [config]( std::shared_ptr req, - const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) { - onComplete(req, AWS_ERROR_UNSUPPORTED_OPERATION); - }); + const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) + { onComplete(req, AWS_ERROR_UNSUPPORTED_OPERATION); }); std::shared_ptr mqtt5Client = Mqtt5::Mqtt5Client::NewMqtt5Client(mqtt5Options, allocator); ASSERT_TRUE(mqtt5Client); @@ -1488,14 +1490,16 @@ static int s_TestMqtt5DoubleClientIDFailure(Aws::Crt::Allocator *allocator, void // SETUP CLIENT 1 CALLBACKS s_setupConnectionLifeCycle(mqtt5Options, connection1Promise, stopped1Promise, "Client1"); - mqtt5Options.WithClientDisconnectionCallback([&disconnectionPromise](const OnDisconnectionEventData &eventData) { - if (eventData.errorCode != 0) + mqtt5Options.WithClientDisconnectionCallback( + [&disconnectionPromise](const OnDisconnectionEventData &eventData) { - printf("[MQTT5]Client1 disconnected with error : %s", aws_error_debug_str(eventData.errorCode)); - disconnectionPromise.set_value(); - } - return 0; - }); + if (eventData.errorCode != 0) + { + printf("[MQTT5]Client1 disconnected with error : %s", aws_error_debug_str(eventData.errorCode)); + disconnectionPromise.set_value(); + } + return 0; + }); std::shared_ptr mqtt5Client1 = Mqtt5::Mqtt5Client::NewMqtt5Client(mqtt5Options, allocator); ASSERT_TRUE(mqtt5Client1); @@ -1564,12 +1568,14 @@ static int s_TestMqtt5NegotiatedSettingsHappy(Aws::Crt::Allocator *allocator, vo s_setupConnectionLifeCycle(mqtt5Options, connectionPromise, stoppedPromise); // Override the ConnectionSuccessCallback to validate the negotiatedSettings - mqtt5Options.WithClientConnectionSuccessCallback([&](const OnConnectionSuccessEventData &eventData) { - printf("[MQTT5]Client Connection Success."); - ASSERT_TRUE(eventData.negotiatedSettings->getSessionExpiryIntervalSec() == SESSION_EXPIRY_INTERVAL_SEC); - connectionPromise.set_value(true); - return 0; - }); + mqtt5Options.WithClientConnectionSuccessCallback( + [&](const OnConnectionSuccessEventData &eventData) + { + printf("[MQTT5]Client Connection Success."); + ASSERT_TRUE(eventData.negotiatedSettings->getSessionExpiryIntervalSec() == SESSION_EXPIRY_INTERVAL_SEC); + connectionPromise.set_value(true); + return 0; + }); std::shared_ptr mqtt5Client = Mqtt5::Mqtt5Client::NewMqtt5Client(mqtt5Options, allocator); ASSERT_TRUE(mqtt5Client); @@ -1620,15 +1626,17 @@ static int s_TestMqtt5NegotiatedSettingsFull(Aws::Crt::Allocator *allocator, voi s_setupConnectionLifeCycle(mqtt5Options, connectionPromise, stoppedPromise); // Override the ConnectionSuccessCallback to validate the negotiatedSettings - mqtt5Options.WithClientConnectionSuccessCallback([&](const OnConnectionSuccessEventData &eventData) { - printf("[MQTT5]Client Connection Success."); - std::shared_ptr settings = eventData.negotiatedSettings; - ASSERT_TRUE(settings->getSessionExpiryIntervalSec() == SESSION_EXPIRY_INTERVAL_SEC); - ASSERT_TRUE(settings->getClientId() == CLIENT_ID); - ASSERT_TRUE(settings->getServerKeepAliveSec() == KEEP_ALIVE_INTERVAL); - connectionPromise.set_value(true); - return 0; - }); + mqtt5Options.WithClientConnectionSuccessCallback( + [&](const OnConnectionSuccessEventData &eventData) + { + printf("[MQTT5]Client Connection Success."); + std::shared_ptr settings = eventData.negotiatedSettings; + ASSERT_TRUE(settings->getSessionExpiryIntervalSec() == SESSION_EXPIRY_INTERVAL_SEC); + ASSERT_TRUE(settings->getClientId() == CLIENT_ID); + ASSERT_TRUE(settings->getServerKeepAliveSec() == KEEP_ALIVE_INTERVAL); + connectionPromise.set_value(true); + return 0; + }); std::shared_ptr mqtt5Client = Mqtt5::Mqtt5Client::NewMqtt5Client(mqtt5Options, allocator); ASSERT_TRUE(mqtt5Client); @@ -1676,17 +1684,19 @@ static int s_TestMqtt5NegotiatedSettingsLimit(Aws::Crt::Allocator *allocator, vo s_setupConnectionLifeCycle(mqtt5Options, connectionPromise, stoppedPromise); - mqtt5Options.WithClientConnectionSuccessCallback([&](const OnConnectionSuccessEventData &eventData) { - std::shared_ptr settings = eventData.negotiatedSettings; - uint16_t receivedmax = settings->getReceiveMaximumFromServer(); - uint32_t max_package = settings->getMaximumPacketSizeToServer(); - ASSERT_FALSE(receivedmax == RECEIVE_MAX); - ASSERT_FALSE(max_package == PACKET_MAX); - ASSERT_FALSE(settings->getRejoinedSession()); + mqtt5Options.WithClientConnectionSuccessCallback( + [&](const OnConnectionSuccessEventData &eventData) + { + std::shared_ptr settings = eventData.negotiatedSettings; + uint16_t receivedmax = settings->getReceiveMaximumFromServer(); + uint32_t max_package = settings->getMaximumPacketSizeToServer(); + ASSERT_FALSE(receivedmax == RECEIVE_MAX); + ASSERT_FALSE(max_package == PACKET_MAX); + ASSERT_FALSE(settings->getRejoinedSession()); - connectionPromise.set_value(true); - return 0; - }); + connectionPromise.set_value(true); + return 0; + }); std::shared_ptr mqtt5Client = Mqtt5::Mqtt5Client::NewMqtt5Client(mqtt5Options, allocator); ASSERT_TRUE(mqtt5Client); @@ -1731,7 +1741,8 @@ static int s_TestMqtt5NegotiatedSettingsRejoinAlways(Aws::Crt::Allocator *alloca s_setupConnectionLifeCycle(mqtt5Options, connectionPromise, stoppedPromise); mqtt5Options.WithClientConnectionSuccessCallback( - [&connectionPromise](const OnConnectionSuccessEventData &eventData) { + [&connectionPromise](const OnConnectionSuccessEventData &eventData) + { std::shared_ptr settings = eventData.negotiatedSettings; ASSERT_FALSE(settings->getRejoinedSession()); connectionPromise.set_value(true); @@ -1753,7 +1764,8 @@ static int s_TestMqtt5NegotiatedSettingsRejoinAlways(Aws::Crt::Allocator *alloca s_setupConnectionLifeCycle(mqtt5Options, sessionConnectedPromise, sessionStoppedPromise); mqtt5Options.WithClientConnectionSuccessCallback( - [&sessionConnectedPromise](const OnConnectionSuccessEventData &eventData) { + [&sessionConnectedPromise](const OnConnectionSuccessEventData &eventData) + { std::shared_ptr settings = eventData.negotiatedSettings; ASSERT_TRUE(settings->getRejoinedSession()); sessionConnectedPromise.set_value(true); @@ -1803,13 +1815,15 @@ static int s_TestMqtt5SubUnsub(Aws::Crt::Allocator *allocator, void *) s_setupConnectionLifeCycle(mqtt5Options, connectionPromise, stoppedPromise); - mqtt5Options.WithPublishReceivedCallback([&receivedCount, TEST_TOPIC](const PublishReceivedEventData &eventData) { - String topic = eventData.publishPacket->getTopic(); - if (topic == TEST_TOPIC) + mqtt5Options.WithPublishReceivedCallback( + [&receivedCount, TEST_TOPIC](const PublishReceivedEventData &eventData) { - receivedCount++; - } - }); + String topic = eventData.publishPacket->getTopic(); + if (topic == TEST_TOPIC) + { + receivedCount++; + } + }); std::shared_ptr mqtt5Client = Mqtt5::Mqtt5Client::NewMqtt5Client(mqtt5Options, allocator); ASSERT_TRUE(mqtt5Client); @@ -1882,13 +1896,15 @@ static int s_TestMqtt5WillTest(Aws::Crt::Allocator *allocator, void *) s_setupConnectionLifeCycle(mqtt5Options, subscriberConnectionPromise, subscriberStoppedPromise, "Suberscriber"); - mqtt5Options.WithPublishReceivedCallback([&receivedWill, TEST_TOPIC](const PublishReceivedEventData &eventData) { - String topic = eventData.publishPacket->getTopic(); - if (topic == TEST_TOPIC) + mqtt5Options.WithPublishReceivedCallback( + [&receivedWill, TEST_TOPIC](const PublishReceivedEventData &eventData) { - receivedWill = true; - } - }); + String topic = eventData.publishPacket->getTopic(); + if (topic == TEST_TOPIC) + { + receivedWill = true; + } + }); std::shared_ptr subscriber = Mqtt5::Mqtt5Client::NewMqtt5Client(mqtt5Options, allocator); ASSERT_TRUE(subscriber); @@ -1979,8 +1995,10 @@ static int s_TestMqtt5SharedSubscriptionTest(Aws::Crt::Allocator *allocator, voi std::promise client_received; - auto get_on_message_callback = [&](bool &received) { - return [&](const PublishReceivedEventData &eventData) -> int { + auto get_on_message_callback = [&](bool &received) + { + return [&](const PublishReceivedEventData &eventData) -> int + { String topic = eventData.publishPacket->getTopic(); if (topic == TEST_TOPIC) { @@ -2350,18 +2368,20 @@ static int s_TestMqtt5QoS1SubPub(Aws::Crt::Allocator *allocator, void *) s_setupConnectionLifeCycle(mqtt5Options, subscriberConnectionPromise, subscriberStoppedPromise, "Subscriber"); - mqtt5Options.WithPublishReceivedCallback([&](const PublishReceivedEventData &eventData) { - String topic = eventData.publishPacket->getTopic(); - if (topic == TEST_TOPIC) + mqtt5Options.WithPublishReceivedCallback( + [&](const PublishReceivedEventData &eventData) { - ByteCursor payload = eventData.publishPacket->getPayload(); - String message_string = String((const char *)payload.ptr, payload.len); - int message_int = atoi(message_string.c_str()); - ASSERT_TRUE(message_int < MESSAGE_NUMBER); - ++receivedMessages[message_int]; - } - return 0; - }); + String topic = eventData.publishPacket->getTopic(); + if (topic == TEST_TOPIC) + { + ByteCursor payload = eventData.publishPacket->getPayload(); + String message_string = String((const char *)payload.ptr, payload.len); + int message_int = atoi(message_string.c_str()); + ASSERT_TRUE(message_int < MESSAGE_NUMBER); + ++receivedMessages[message_int]; + } + return 0; + }); std::shared_ptr subscriber = Mqtt5::Mqtt5Client::NewMqtt5Client(mqtt5Options, allocator); ASSERT_TRUE(subscriber); @@ -2458,7 +2478,8 @@ static int s_TestMqtt5RetainSetAndClear(Aws::Crt::Allocator *allocator, void *) s_setupConnectionLifeCycle(mqtt5Options, connection2Promise, stopped2Promise, "Client2"); mqtt5Options.WithPublishReceivedCallback( - [&client2RetianMessageReceived, TEST_TOPIC](const PublishReceivedEventData &eventData) { + [&client2RetianMessageReceived, TEST_TOPIC](const PublishReceivedEventData &eventData) + { String topic = eventData.publishPacket->getTopic(); if (topic == TEST_TOPIC) { @@ -2471,15 +2492,17 @@ static int s_TestMqtt5RetainSetAndClear(Aws::Crt::Allocator *allocator, void *) s_setupConnectionLifeCycle(mqtt5Options, connection3Promise, stopped3Promise, "Client3"); - mqtt5Options.WithPublishReceivedCallback([TEST_TOPIC](const PublishReceivedEventData &eventData) { - String topic = eventData.publishPacket->getTopic(); - if (topic == TEST_TOPIC) + mqtt5Options.WithPublishReceivedCallback( + [TEST_TOPIC](const PublishReceivedEventData &eventData) { - // Client3 should not receive any retian message - ASSERT_FALSE(false); - } - return 0; - }); + String topic = eventData.publishPacket->getTopic(); + if (topic == TEST_TOPIC) + { + // Client3 should not receive any retian message + ASSERT_FALSE(false); + } + return 0; + }); std::shared_ptr mqtt5Client3 = Mqtt5::Mqtt5Client::NewMqtt5Client(mqtt5Options, allocator); ASSERT_TRUE(mqtt5Client3); @@ -2749,17 +2772,18 @@ static int s_ConnectAndDisconnectThroughMqtt3(std::shared_ptr connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -2975,11 +2999,10 @@ static int s_TestMqtt5to3AdapterWSConnectionMinimalThroughMqtt3(Aws::Crt::Alloca mqtt5Options.WithWebsocketHandshakeTransformCallback( [config, &Mqtt5WebSocket]( std::shared_ptr req, - const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) { - auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) + { + auto signingComplete = [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; auto signerConfig = config.CreateSigningConfigCb(); @@ -2994,20 +3017,18 @@ static int s_TestMqtt5to3AdapterWSConnectionMinimalThroughMqtt3(Aws::Crt::Alloca Mqtt::MqttConnection::NewConnectionFromMqtt5Client(mqtt5Client); ASSERT_TRUE(mqttConnection); - mqttConnection->WebsocketInterceptor = - [config, &Mqtt3WebSocket]( - std::shared_ptr req, - const Aws::Crt::Mqtt::OnWebSocketHandshakeInterceptComplete &onComplete) { - auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + mqttConnection->WebsocketInterceptor = [config, &Mqtt3WebSocket]( + std::shared_ptr req, + const Aws::Crt::Mqtt::OnWebSocketHandshakeInterceptComplete &onComplete) + { + auto signingComplete = [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; - auto signerConfig = config.CreateSigningConfigCb(); + auto signerConfig = config.CreateSigningConfigCb(); - config.Signer->SignRequest(req, *signerConfig, signingComplete); - Mqtt3WebSocket = 1; - }; + config.Signer->SignRequest(req, *signerConfig, signingComplete); + Mqtt3WebSocket = 1; + }; int connectResult = s_ConnectAndDisconnectThroughMqtt3(mqttConnection); ASSERT_SUCCESS(connectResult); @@ -3157,11 +3178,10 @@ static int s_TestMqtt5to3AdapterWSConnectionMinimalThroughMqtt5(Aws::Crt::Alloca mqtt5Options.WithWebsocketHandshakeTransformCallback( [config, &Mqtt5WebSocket]( std::shared_ptr req, - const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) { - auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + const Aws::Crt::Mqtt5::OnWebSocketHandshakeInterceptComplete &onComplete) + { + auto signingComplete = [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; auto signerConfig = config.CreateSigningConfigCb(); @@ -3180,20 +3200,18 @@ static int s_TestMqtt5to3AdapterWSConnectionMinimalThroughMqtt5(Aws::Crt::Alloca Mqtt::MqttConnection::NewConnectionFromMqtt5Client(mqtt5Client); ASSERT_TRUE(mqttConnection); - mqttConnection->WebsocketInterceptor = - [config, &Mqtt3WebSocket]( - std::shared_ptr req, - const Aws::Crt::Mqtt::OnWebSocketHandshakeInterceptComplete &onComplete) { - auto signingComplete = - [onComplete](const std::shared_ptr &req1, int errorCode) { - onComplete(req1, errorCode); - }; + mqttConnection->WebsocketInterceptor = [config, &Mqtt3WebSocket]( + std::shared_ptr req, + const Aws::Crt::Mqtt::OnWebSocketHandshakeInterceptComplete &onComplete) + { + auto signingComplete = [onComplete](const std::shared_ptr &req1, int errorCode) + { onComplete(req1, errorCode); }; - auto signerConfig = config.CreateSigningConfigCb(); + auto signerConfig = config.CreateSigningConfigCb(); - config.Signer->SignRequest(req, *signerConfig, signingComplete); - Mqtt3WebSocket = 1; - }; + config.Signer->SignRequest(req, *signerConfig, signingComplete); + Mqtt3WebSocket = 1; + }; ASSERT_TRUE(mqtt5Client->Start()); ASSERT_TRUE(connectionPromise.get_future().get()); @@ -3331,7 +3349,8 @@ static int s_TestMqtt5to3AdapterOperations(Aws::Crt::Allocator *allocator, void ASSERT_TRUE(mqtt5Client->Start()); ASSERT_TRUE(connectionPromise.get_future().get()); - auto onMessage = [&](Mqtt::MqttConnection &, const String &topic, const ByteBuf &payload, bool, Mqtt::QOS, bool) { + auto onMessage = [&](Mqtt::MqttConnection &, const String &topic, const ByteBuf &payload, bool, Mqtt::QOS, bool) + { printf("GOT MESSAGE topic=%s payload=" PRInSTR "\n", topic.c_str(), AWS_BYTE_BUF_PRI(payload)); { std::lock_guard lock(mutex); @@ -3339,7 +3358,8 @@ static int s_TestMqtt5to3AdapterOperations(Aws::Crt::Allocator *allocator, void } cv.notify_one(); }; - auto onSubAck = [&](Mqtt::MqttConnection &, uint16_t packetId, const Aws::Crt::String &topic, Mqtt::QOS qos, int) { + auto onSubAck = [&](Mqtt::MqttConnection &, uint16_t packetId, const Aws::Crt::String &topic, Mqtt::QOS qos, int) + { printf("SUBACK id=%d topic=%s qos=%d\n", packetId, topic.c_str(), qos); { std::lock_guard lock(mutex); @@ -3347,7 +3367,8 @@ static int s_TestMqtt5to3AdapterOperations(Aws::Crt::Allocator *allocator, void } cv.notify_one(); }; - auto onPubAck = [&](Mqtt::MqttConnection &, uint16_t packetId, int) { + auto onPubAck = [&](Mqtt::MqttConnection &, uint16_t packetId, int) + { printf("PUBLISHED id=%d\n", packetId); { std::lock_guard lock(mutex); @@ -3355,7 +3376,8 @@ static int s_TestMqtt5to3AdapterOperations(Aws::Crt::Allocator *allocator, void } cv.notify_one(); }; - auto onUnsubAck = [&](Mqtt::MqttConnection &, uint16_t packetId, int) { + auto onUnsubAck = [&](Mqtt::MqttConnection &, uint16_t packetId, int) + { printf("UNSUBACK id=%d\n", packetId); { std::lock_guard lock(mutex); @@ -3509,7 +3531,8 @@ static int s_TestMqtt5to3AdapterMultipleAdapters(Aws::Crt::Allocator *allocator, bool published = false; ByteBuf testPayload = Aws::Crt::ByteBufFromCString("PUBLISH ME!"); - auto onMessage1 = [&](Mqtt::MqttConnection &, const String &topic, const ByteBuf &payload, bool, Mqtt::QOS, bool) { + auto onMessage1 = [&](Mqtt::MqttConnection &, const String &topic, const ByteBuf &payload, bool, Mqtt::QOS, bool) + { printf("GOT MESSAGE topic=%s payload=" PRInSTR "\n", topic.c_str(), AWS_BYTE_BUF_PRI(payload)); { std::lock_guard lock(mutex); @@ -3517,7 +3540,8 @@ static int s_TestMqtt5to3AdapterMultipleAdapters(Aws::Crt::Allocator *allocator, } cv.notify_one(); }; - auto onSubAck1 = [&](Mqtt::MqttConnection &, uint16_t packetId, const Aws::Crt::String &topic, Mqtt::QOS qos, int) { + auto onSubAck1 = [&](Mqtt::MqttConnection &, uint16_t packetId, const Aws::Crt::String &topic, Mqtt::QOS qos, int) + { printf("SUBACK id=%d topic=%s qos=%d\n", packetId, topic.c_str(), qos); { std::lock_guard lock(mutex); @@ -3526,7 +3550,8 @@ static int s_TestMqtt5to3AdapterMultipleAdapters(Aws::Crt::Allocator *allocator, cv.notify_one(); }; - auto onMessage2 = [&](Mqtt::MqttConnection &, const String &topic, const ByteBuf &payload, bool, Mqtt::QOS, bool) { + auto onMessage2 = [&](Mqtt::MqttConnection &, const String &topic, const ByteBuf &payload, bool, Mqtt::QOS, bool) + { printf("GOT MESSAGE topic=%s payload=" PRInSTR "\n", topic.c_str(), AWS_BYTE_BUF_PRI(payload)); { std::lock_guard lock(mutex); @@ -3534,7 +3559,8 @@ static int s_TestMqtt5to3AdapterMultipleAdapters(Aws::Crt::Allocator *allocator, } cv.notify_one(); }; - auto onSubAck2 = [&](Mqtt::MqttConnection &, uint16_t packetId, const Aws::Crt::String &topic, Mqtt::QOS qos, int) { + auto onSubAck2 = [&](Mqtt::MqttConnection &, uint16_t packetId, const Aws::Crt::String &topic, Mqtt::QOS qos, int) + { printf("SUBACK id=%d topic=%s qos=%d\n", packetId, topic.c_str(), qos); { std::lock_guard lock(mutex); @@ -3558,7 +3584,8 @@ static int s_TestMqtt5to3AdapterMultipleAdapters(Aws::Crt::Allocator *allocator, cv.wait(lock, [&]() { return subscribed2; }); } - auto onPubAck = [&](Mqtt::MqttConnection &, uint16_t packetId, int) { + auto onPubAck = [&](Mqtt::MqttConnection &, uint16_t packetId, int) + { printf("PUBLISHED id=%d\n", packetId); { std::lock_guard lock(mutex); diff --git a/tests/MqttClientCredentialsTest.cpp b/tests/MqttClientCredentialsTest.cpp index a8df9d2e8..9f48dae5d 100644 --- a/tests/MqttClientCredentialsTest.cpp +++ b/tests/MqttClientCredentialsTest.cpp @@ -151,17 +151,18 @@ static int s_TestIoTMqtt311ConnectWithNoSigningCustomAuth(Aws::Crt::Allocator *a std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -238,17 +239,18 @@ static int s_TestIoTMqtt311ConnectWithSigningCustomAuth(Aws::Crt::Allocator *all std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -328,17 +330,18 @@ static int s_TestIoTMqtt311ConnectWithSigningCustomAuthUnencoded(Aws::Crt::Alloc std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -425,17 +428,18 @@ static int s_TestIoTMqtt311ConnectWithSigningCustomAuthWebsockets(Aws::Crt::Allo std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -524,17 +528,18 @@ static int s_TestIoTMqtt311ConnectWithSigningCustomAuthWebsocketsUnencoded(Aws:: std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -624,17 +629,18 @@ static int s_TestIoTMqtt311ConnectWithPKCS11(Aws::Crt::Allocator *allocator, voi std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -710,17 +716,18 @@ static int s_TestIoTMqtt311ConnectWithPKCS12(Aws::Crt::Allocator *allocator, voi std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -785,17 +792,18 @@ static int s_TestIoTMqtt311ConnectWithWindowsCert(Aws::Crt::Allocator *allocator std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -854,17 +862,18 @@ static int s_TestIoTMqtt311ConnectWSDefault(Aws::Crt::Allocator *allocator, void std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -934,17 +943,18 @@ static int s_TestIoTMqtt311ConnectWSStatic(Aws::Crt::Allocator *allocator, void std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -1016,17 +1026,18 @@ static int s_TestIoTMqtt311ConnectWSCognito(Aws::Crt::Allocator *allocator, void std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -1094,17 +1105,18 @@ static int s_TestIoTMqtt311ConnectWSProfile(Aws::Crt::Allocator *allocator, void std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); @@ -1173,17 +1185,18 @@ static int s_TestIoTMqtt311ConnectWSEnvironment(Aws::Crt::Allocator *allocator, std::promise connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); diff --git a/tests/MqttClientTest.cpp b/tests/MqttClientTest.cpp index 922595b03..edadcbb3b 100644 --- a/tests/MqttClientTest.cpp +++ b/tests/MqttClientTest.cpp @@ -147,17 +147,18 @@ static int s_ConnectAndDisconnect(std::shared_ptr connectionCompletedPromise; std::promise connectionClosedPromise; auto onConnectionCompleted = - [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) { - (void)returnCode; - if (errorCode) - { - connectionCompletedPromise.set_value(false); - } - else - { - connectionCompletedPromise.set_value(true); - } - }; + [&](Aws::Crt::Mqtt::MqttConnection &, int errorCode, Aws::Crt::Mqtt::ReturnCode returnCode, bool) + { + (void)returnCode; + if (errorCode) + { + connectionCompletedPromise.set_value(false); + } + else + { + connectionCompletedPromise.set_value(true); + } + }; auto onDisconnect = [&](Aws::Crt::Mqtt::MqttConnection &) { connectionClosedPromise.set_value(); }; connection->OnConnectionCompleted = std::move(onConnectionCompleted); connection->OnDisconnect = std::move(onDisconnect); diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp index d407daf03..bccb4ad6c 100644 --- a/tests/ProxyTest.cpp +++ b/tests/ProxyTest.cpp @@ -154,18 +154,19 @@ static void s_InitializeProxiedRawConnection(ProxyIntegrationTestState &testStat std::shared_ptr connection; testState.m_connectionOptions.OnConnectionSetupCallback = - [&](std::shared_ptr newConnection, int errorCode) { - { - std::lock_guard lockGuard(testState.m_lock); + [&](std::shared_ptr newConnection, int errorCode) + { + { + std::lock_guard lockGuard(testState.m_lock); - acquisitionErrorCode = errorCode; - if (!errorCode) - { - connection = newConnection; - } + acquisitionErrorCode = errorCode; + if (!errorCode) + { + connection = newConnection; } - testState.m_signal.notify_one(); - }; + } + testState.m_signal.notify_one(); + }; testState.m_connectionOptions.OnConnectionShutdownCallback = [&](HttpClientConnection & /*newConnection*/, int /*errorCode*/) {}; @@ -184,7 +185,8 @@ static void s_AcquireProxyTestHttpConnection(ProxyIntegrationTestState &testStat int acquisitionErrorCode = 0; std::shared_ptr connection; - auto onConnectionAvailable = [&](std::shared_ptr newConnection, int errorCode) { + auto onConnectionAvailable = [&](std::shared_ptr newConnection, int errorCode) + { { std::lock_guard lockGuard(testState.m_lock); @@ -391,7 +393,8 @@ static void s_MakeForwardingTestRequest(ProxyIntegrationTestState &testState) HttpRequestOptions requestOptions; requestOptions.request = testState.m_request.get(); - requestOptions.onIncomingBody = [&testState](Http::HttpStream &, const ByteCursor &data) { + requestOptions.onIncomingBody = [&testState](Http::HttpStream &, const ByteCursor &data) + { std::lock_guard lock(testState.m_lock); Aws::Crt::String dataString((const char *)data.ptr, data.len); @@ -399,15 +402,17 @@ static void s_MakeForwardingTestRequest(ProxyIntegrationTestState &testState) }; requestOptions.onIncomingHeaders = - [&testState](Http::HttpStream &, enum aws_http_header_block, const Http::HttpHeader *, std::size_t) { - std::lock_guard lock(testState.m_lock); - if (testState.m_streamStatusCode == 0) - { - testState.m_streamStatusCode = testState.m_stream->GetResponseStatusCode(); - } - }; + [&testState](Http::HttpStream &, enum aws_http_header_block, const Http::HttpHeader *, std::size_t) + { + std::lock_guard lock(testState.m_lock); + if (testState.m_streamStatusCode == 0) + { + testState.m_streamStatusCode = testState.m_stream->GetResponseStatusCode(); + } + }; - requestOptions.onStreamComplete = [&testState](Http::HttpStream & /*stream*/, int /*errorCode*/) { + requestOptions.onStreamComplete = [&testState](Http::HttpStream & /*stream*/, int /*errorCode*/) + { { std::lock_guard lock(testState.m_lock); testState.m_streamComplete = true; @@ -760,7 +765,8 @@ static int s_InitializeX509Provider(ProxyIntegrationTestState &testState) static int s_X509GetCredentials(ProxyIntegrationTestState &testState) { - auto credentialsResolved = [&testState](std::shared_ptr credentials, int /*errorCode*/) { + auto credentialsResolved = [&testState](std::shared_ptr credentials, int /*errorCode*/) + { { std::lock_guard lock(testState.m_lock); testState.m_credentials = credentials; @@ -918,15 +924,17 @@ static int s_ConnectToIotCore(ProxyIntegrationTestState &testState) { testState.m_mqttConnection->OnConnectionCompleted = - [&testState](Mqtt::MqttConnection &, int errorCode, Mqtt::ReturnCode, bool) { - std::lock_guard lock(testState.m_lock); + [&testState](Mqtt::MqttConnection &, int errorCode, Mqtt::ReturnCode, bool) + { + std::lock_guard lock(testState.m_lock); - testState.m_mqttConnectComplete = true; - testState.m_mqttErrorCode = errorCode; - testState.m_signal.notify_one(); - }; + testState.m_mqttConnectComplete = true; + testState.m_mqttErrorCode = errorCode; + testState.m_signal.notify_one(); + }; - testState.m_mqttConnection->OnDisconnect = [&testState](Mqtt::MqttConnection &) { + testState.m_mqttConnection->OnDisconnect = [&testState](Mqtt::MqttConnection &) + { std::lock_guard lock(testState.m_lock); testState.m_mqttDisconnectComplete = true; diff --git a/tests/Sigv4SigningTest.cpp b/tests/Sigv4SigningTest.cpp index 6065df482..fdd34c813 100644 --- a/tests/Sigv4SigningTest.cpp +++ b/tests/Sigv4SigningTest.cpp @@ -187,9 +187,10 @@ static int s_Sigv4SigningTestSimple(struct aws_allocator *allocator, void *ctx) SignWaiter waiter; ASSERT_TRUE(signer->SignRequest( - request, signingConfig, [&](const std::shared_ptr &request, int errorCode) { - waiter.OnSigningComplete(request, errorCode); - })); + request, + signingConfig, + [&](const std::shared_ptr &request, int errorCode) + { waiter.OnSigningComplete(request, errorCode); })); waiter.Wait(); } @@ -234,9 +235,10 @@ static int s_Sigv4SigningTestCredentials(struct aws_allocator *allocator, void * SignWaiter waiter; ASSERT_TRUE(signer->SignRequest( - request, signingConfig, [&](const std::shared_ptr &request, int errorCode) { - waiter.OnSigningComplete(request, errorCode); - })); + request, + signingConfig, + [&](const std::shared_ptr &request, int errorCode) + { waiter.OnSigningComplete(request, errorCode); })); waiter.Wait(); } @@ -283,9 +285,10 @@ static int s_Sigv4SigningTestUnsignedPayload(struct aws_allocator *allocator, vo SignWaiter waiter; ASSERT_TRUE(signer->SignRequest( - request, signingConfig, [&](const std::shared_ptr &request, int errorCode) { - waiter.OnSigningComplete(request, errorCode); - })); + request, + signingConfig, + [&](const std::shared_ptr &request, int errorCode) + { waiter.OnSigningComplete(request, errorCode); })); waiter.Wait(); } @@ -406,9 +409,10 @@ static int s_Sigv4aSigningTestCredentials(struct aws_allocator *allocator, void SignWaiter waiter; ASSERT_TRUE(signer->SignRequest( - request, signingConfig, [&](const std::shared_ptr &request, int errorCode) { - waiter.OnSigningComplete(request, errorCode); - })); + request, + signingConfig, + [&](const std::shared_ptr &request, int errorCode) + { waiter.OnSigningComplete(request, errorCode); })); waiter.Wait();