diff options
author | unril <unril@yandex-team.ru> | 2022-02-10 16:46:05 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:05 +0300 |
commit | 3b241dd57cf58f20bbbd63fa6a0a758dbec09b68 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source | |
parent | 11ae9eca250d0188b7962459cbc6706719e7dca9 (diff) | |
download | ydb-3b241dd57cf58f20bbbd63fa6a0a758dbec09b68.tar.gz |
Restoring authorship annotation for <unril@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source')
32 files changed, 1526 insertions, 1526 deletions
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/Aws.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/Aws.cpp index 54a55e1118..1eaa477fca 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/Aws.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/Aws.cpp @@ -5,7 +5,7 @@ #include <aws/core/Version.h> #include <aws/core/utils/logging/LogMacros.h> #include <aws/core/Aws.h> -#include <aws/core/client/CoreErrors.h> +#include <aws/core/client/CoreErrors.h> #include <aws/core/utils/logging/AWSLogging.h> #include <aws/core/utils/logging/DefaultLogSystem.h> #include <aws/core/Globals.h> @@ -27,7 +27,7 @@ namespace Aws Aws::Utils::Memory::InitializeAWSMemorySystem(*options.memoryManagementOptions.memoryManager); } #endif // USE_AWS_MEMORY_MANAGEMENT - Aws::Client::CoreErrorsMapper::InitCoreErrorsMapper(); + Aws::Client::CoreErrorsMapper::InitCoreErrorsMapper(); if(options.loggingOptions.logLevel != Aws::Utils::Logging::LogLevel::Off) { if(options.loggingOptions.logger_create_fn) @@ -122,7 +122,7 @@ namespace Aws Aws::Utils::Logging::ShutdownAWSLogging(); } - Aws::Client::CoreErrorsMapper::CleanupCoreErrorsMapper(); + Aws::Client::CoreErrorsMapper::CleanupCoreErrorsMapper(); #ifdef USE_AWS_MEMORY_MANAGEMENT if(options.memoryManagementOptions.memoryManager) diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/auth/AWSAuthSigner.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/auth/AWSAuthSigner.cpp index f6a0d5da71..de4826fa5b 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/auth/AWSAuthSigner.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/auth/AWSAuthSigner.cpp @@ -17,14 +17,14 @@ #include <aws/core/utils/memory/AWSMemory.h> #include <aws/core/utils/crypto/Sha256.h> #include <aws/core/utils/crypto/Sha256HMAC.h> -#include <aws/core/utils/stream/PreallocatedStreamBuf.h> -#include <aws/core/utils/event/EventMessage.h> -#include <aws/core/utils/event/EventHeader.h> +#include <aws/core/utils/stream/PreallocatedStreamBuf.h> +#include <aws/core/utils/event/EventMessage.h> +#include <aws/core/utils/event/EventHeader.h> #include <cstdio> #include <iomanip> #include <math.h> -#include <cstring> +#include <cstring> using namespace Aws; using namespace Aws::Client; @@ -35,8 +35,8 @@ using namespace Aws::Utils::Logging; static const char* EQ = "="; static const char* AWS_HMAC_SHA256 = "AWS4-HMAC-SHA256"; -static const char* EVENT_STREAM_CONTENT_SHA256 = "STREAMING-AWS4-HMAC-SHA256-EVENTS"; -static const char* EVENT_STREAM_PAYLOAD = "AWS4-HMAC-SHA256-PAYLOAD"; +static const char* EVENT_STREAM_CONTENT_SHA256 = "STREAMING-AWS4-HMAC-SHA256-EVENTS"; +static const char* EVENT_STREAM_PAYLOAD = "AWS4-HMAC-SHA256-PAYLOAD"; static const char* AWS4_REQUEST = "aws4_request"; static const char* SIGNED_HEADERS = "SignedHeaders"; static const char* CREDENTIAL = "Credential"; @@ -46,25 +46,25 @@ static const char* X_AMZ_ALGORITHM = "X-Amz-Algorithm"; static const char* X_AMZ_CREDENTIAL = "X-Amz-Credential"; static const char* UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD"; static const char* X_AMZ_SIGNATURE = "X-Amz-Signature"; -static const char* X_AMZN_TRACE_ID = "x-amzn-trace-id"; -static const char* X_AMZ_CONTENT_SHA256 = "x-amz-content-sha256"; -static const char* USER_AGENT = "user-agent"; +static const char* X_AMZN_TRACE_ID = "x-amzn-trace-id"; +static const char* X_AMZ_CONTENT_SHA256 = "x-amz-content-sha256"; +static const char* USER_AGENT = "user-agent"; static const char* SIGNING_KEY = "AWS4"; static const char* SIMPLE_DATE_FORMAT_STR = "%Y%m%d"; static const char* EMPTY_STRING_SHA256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; -static const char v4LogTag[] = "AWSAuthV4Signer"; -static const char v4StreamingLogTag[] = "AWSAuthEventStreamV4Signer"; +static const char v4LogTag[] = "AWSAuthV4Signer"; +static const char v4StreamingLogTag[] = "AWSAuthEventStreamV4Signer"; namespace Aws { namespace Auth { - const char SIGNATURE[] = "Signature"; + const char SIGNATURE[] = "Signature"; const char SIGV4_SIGNER[] = "SignatureV4"; - const char EVENTSTREAM_SIGV4_SIGNER[] = "EventStreamSignatureV4"; - const char EVENTSTREAM_SIGNATURE_HEADER[] = ":chunk-signature"; - const char EVENTSTREAM_DATE_HEADER[] = ":date"; + const char EVENTSTREAM_SIGV4_SIGNER[] = "EventStreamSignatureV4"; + const char EVENTSTREAM_SIGNATURE_HEADER[] = ":chunk-signature"; + const char EVENTSTREAM_DATE_HEADER[] = ":date"; const char NULL_SIGNER[] = "NullSigner"; } } @@ -152,7 +152,7 @@ AWSAuthV4Signer::AWSAuthV4Signer(const std::shared_ptr<Auth::AWSCredentialsProvi m_region(region), m_hash(Aws::MakeUnique<Aws::Utils::Crypto::Sha256>(v4LogTag)), m_HMAC(Aws::MakeUnique<Aws::Utils::Crypto::Sha256HMAC>(v4LogTag)), - m_unsignedHeaders({USER_AGENT, X_AMZN_TRACE_ID}), + m_unsignedHeaders({USER_AGENT, X_AMZN_TRACE_ID}), m_payloadSigningPolicy(signingPolicy), m_urlEscapePath(urlEscapePath) { @@ -203,7 +203,7 @@ bool AWSAuthV4Signer::SignRequest(Aws::Http::HttpRequest& request, const char* r if(signBody || request.GetUri().GetScheme() != Http::Scheme::HTTPS) { - payloadHash = ComputePayloadHash(request); + payloadHash = ComputePayloadHash(request); if (payloadHash.empty()) { return false; @@ -217,7 +217,7 @@ bool AWSAuthV4Signer::SignRequest(Aws::Http::HttpRequest& request, const char* r if(m_includeSha256HashHeader) { - request.SetHeaderValue(X_AMZ_CONTENT_SHA256, payloadHash); + request.SetHeaderValue(X_AMZ_CONTENT_SHA256, payloadHash); } //calculate date header to use in internal signature (this also goes into date header). @@ -245,7 +245,7 @@ bool AWSAuthV4Signer::SignRequest(Aws::Http::HttpRequest& request, const char* r //remove that last semi-colon if (!signedHeadersValue.empty()) { - signedHeadersValue.pop_back(); + signedHeadersValue.pop_back(); } AWS_LOGSTREAM_DEBUG(v4LogTag, "Signed Headers value:" << signedHeadersValue); @@ -375,11 +375,11 @@ bool AWSAuthV4Signer::PresignRequest(Aws::Http::HttpRequest& request, const char canonicalRequestString.append(signedHeadersValue); canonicalRequestString.append(NEWLINE); if (ServiceRequireUnsignedPayload(signingServiceName)) - { + { canonicalRequestString.append(UNSIGNED_PAYLOAD); - } - else - { + } + else + { canonicalRequestString.append(EMPTY_STRING_SHA256); } AWS_LOGSTREAM_DEBUG(v4LogTag, "Canonical Request String: " << canonicalRequestString); @@ -438,7 +438,7 @@ Aws::String AWSAuthV4Signer::GenerateSignature(const Aws::String& stringToSign, { AWS_LOGSTREAM_ERROR(v4LogTag, "Unable to hmac (sha256) final string"); AWS_LOGSTREAM_DEBUG(v4LogTag, "The final string is: \"" << stringToSign << "\""); - return {}; + return {}; } //now we finally sign our request string with our hex encoded derived hash. @@ -470,7 +470,7 @@ Aws::String AWSAuthV4Signer::ComputePayloadHash(Aws::Http::HttpRequest& request) if (!hashResult.IsSuccess()) { AWS_LOGSTREAM_ERROR(v4LogTag, "Unable to hash (sha256) request body"); - return {}; + return {}; } auto sha256Digest = hashResult.GetResult(); @@ -532,275 +532,275 @@ Aws::Utils::ByteBuffer AWSAuthV4Signer::ComputeHash(const Aws::String& secretKey } return hashResult.GetResult(); } - -AWSAuthEventStreamV4Signer::AWSAuthEventStreamV4Signer(const std::shared_ptr<Auth::AWSCredentialsProvider>& - credentialsProvider, const char* serviceName, const Aws::String& region) : - m_serviceName(serviceName), - m_region(region), - m_credentialsProvider(credentialsProvider) -{ - - m_unsignedHeaders.emplace_back(X_AMZN_TRACE_ID); - m_unsignedHeaders.emplace_back(USER_AGENT_HEADER); -} - + +AWSAuthEventStreamV4Signer::AWSAuthEventStreamV4Signer(const std::shared_ptr<Auth::AWSCredentialsProvider>& + credentialsProvider, const char* serviceName, const Aws::String& region) : + m_serviceName(serviceName), + m_region(region), + m_credentialsProvider(credentialsProvider) +{ + + m_unsignedHeaders.emplace_back(X_AMZN_TRACE_ID); + m_unsignedHeaders.emplace_back(USER_AGENT_HEADER); +} + bool AWSAuthEventStreamV4Signer::SignRequest(Aws::Http::HttpRequest& request, const char* region, const char* serviceName, bool /* signBody */) const -{ - AWSCredentials credentials = m_credentialsProvider->GetAWSCredentials(); - - //don't sign anonymous requests - if (credentials.GetAWSAccessKeyId().empty() || credentials.GetAWSSecretKey().empty()) - { - return true; - } - - if (!credentials.GetSessionToken().empty()) - { - request.SetAwsSessionToken(credentials.GetSessionToken()); - } - - request.SetHeaderValue(X_AMZ_CONTENT_SHA256, EVENT_STREAM_CONTENT_SHA256); - - //calculate date header to use in internal signature (this also goes into date header). - DateTime now = GetSigningTimestamp(); +{ + AWSCredentials credentials = m_credentialsProvider->GetAWSCredentials(); + + //don't sign anonymous requests + if (credentials.GetAWSAccessKeyId().empty() || credentials.GetAWSSecretKey().empty()) + { + return true; + } + + if (!credentials.GetSessionToken().empty()) + { + request.SetAwsSessionToken(credentials.GetSessionToken()); + } + + request.SetHeaderValue(X_AMZ_CONTENT_SHA256, EVENT_STREAM_CONTENT_SHA256); + + //calculate date header to use in internal signature (this also goes into date header). + DateTime now = GetSigningTimestamp(); Aws::String dateHeaderValue = now.ToGmtString(DateFormat::ISO_8601_BASIC); - request.SetHeaderValue(AWS_DATE_HEADER, dateHeaderValue); - - Aws::StringStream headersStream; - Aws::StringStream signedHeadersStream; - - for (const auto& header : CanonicalizeHeaders(request.GetHeaders())) - { - if(ShouldSignHeader(header.first)) - { - headersStream << header.first.c_str() << ":" << header.second.c_str() << NEWLINE; - signedHeadersStream << header.first.c_str() << ";"; - } - } - - Aws::String canonicalHeadersString = headersStream.str(); - AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Canonical Header String: " << canonicalHeadersString); - - //calculate signed headers parameter - Aws::String signedHeadersValue = signedHeadersStream.str(); - //remove that last semi-colon - if (!signedHeadersValue.empty()) - { - signedHeadersValue.pop_back(); - } - - AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Signed Headers value:" << signedHeadersValue); - - //generate generalized canonicalized request string. - Aws::String canonicalRequestString = CanonicalizeRequestSigningString(request, true/* m_urlEscapePath */); - - //append v4 stuff to the canonical request string. - canonicalRequestString.append(canonicalHeadersString); - canonicalRequestString.append(NEWLINE); - canonicalRequestString.append(signedHeadersValue); - canonicalRequestString.append(NEWLINE); - canonicalRequestString.append(EVENT_STREAM_CONTENT_SHA256); - - AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Canonical Request String: " << canonicalRequestString); - - //now compute sha256 on that request string - auto hashResult = m_hash.Calculate(canonicalRequestString); - if (!hashResult.IsSuccess()) - { - AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Failed to hash (sha256) request string"); - AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "The request string is: \"" << canonicalRequestString << "\""); - return false; - } - - auto sha256Digest = hashResult.GetResult(); + request.SetHeaderValue(AWS_DATE_HEADER, dateHeaderValue); + + Aws::StringStream headersStream; + Aws::StringStream signedHeadersStream; + + for (const auto& header : CanonicalizeHeaders(request.GetHeaders())) + { + if(ShouldSignHeader(header.first)) + { + headersStream << header.first.c_str() << ":" << header.second.c_str() << NEWLINE; + signedHeadersStream << header.first.c_str() << ";"; + } + } + + Aws::String canonicalHeadersString = headersStream.str(); + AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Canonical Header String: " << canonicalHeadersString); + + //calculate signed headers parameter + Aws::String signedHeadersValue = signedHeadersStream.str(); + //remove that last semi-colon + if (!signedHeadersValue.empty()) + { + signedHeadersValue.pop_back(); + } + + AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Signed Headers value:" << signedHeadersValue); + + //generate generalized canonicalized request string. + Aws::String canonicalRequestString = CanonicalizeRequestSigningString(request, true/* m_urlEscapePath */); + + //append v4 stuff to the canonical request string. + canonicalRequestString.append(canonicalHeadersString); + canonicalRequestString.append(NEWLINE); + canonicalRequestString.append(signedHeadersValue); + canonicalRequestString.append(NEWLINE); + canonicalRequestString.append(EVENT_STREAM_CONTENT_SHA256); + + AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Canonical Request String: " << canonicalRequestString); + + //now compute sha256 on that request string + auto hashResult = m_hash.Calculate(canonicalRequestString); + if (!hashResult.IsSuccess()) + { + AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Failed to hash (sha256) request string"); + AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "The request string is: \"" << canonicalRequestString << "\""); + return false; + } + + auto sha256Digest = hashResult.GetResult(); Aws::String canonicalRequestHash = HashingUtils::HexEncode(sha256Digest); - Aws::String simpleDate = now.ToGmtString(SIMPLE_DATE_FORMAT_STR); - + Aws::String simpleDate = now.ToGmtString(SIMPLE_DATE_FORMAT_STR); + Aws::String signingRegion = region ? region : m_region; Aws::String signingServiceName = serviceName ? serviceName : m_serviceName; Aws::String stringToSign = GenerateStringToSign(dateHeaderValue, simpleDate, canonicalRequestHash, signingRegion, signingServiceName); auto finalSignature = GenerateSignature(credentials, stringToSign, simpleDate, signingRegion, signingServiceName); - - Aws::StringStream ss; - ss << AWS_HMAC_SHA256 << " " << CREDENTIAL << EQ << credentials.GetAWSAccessKeyId() << "/" << simpleDate + + Aws::StringStream ss; + ss << AWS_HMAC_SHA256 << " " << CREDENTIAL << EQ << credentials.GetAWSAccessKeyId() << "/" << simpleDate << "/" << signingRegion << "/" << signingServiceName << "/" << AWS4_REQUEST << ", " << SIGNED_HEADERS << EQ - << signedHeadersValue << ", " << SIGNATURE << EQ << HashingUtils::HexEncode(finalSignature); - - auto awsAuthString = ss.str(); - AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Signing request with: " << awsAuthString); - request.SetAwsAuthorization(awsAuthString); - request.SetSigningAccessKey(credentials.GetAWSAccessKeyId()); + << signedHeadersValue << ", " << SIGNATURE << EQ << HashingUtils::HexEncode(finalSignature); + + auto awsAuthString = ss.str(); + AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Signing request with: " << awsAuthString); + request.SetAwsAuthorization(awsAuthString); + request.SetSigningAccessKey(credentials.GetAWSAccessKeyId()); request.SetSigningRegion(signingRegion); - return true; -} - -// this works regardless if the current machine is Big/Little Endian -static void WriteBigEndian(Aws::String& str, uint64_t n) -{ - int shift = 56; - while(shift >= 0) - { - str.push_back((n >> shift) & 0xFF); - shift -= 8; - } -} - -bool AWSAuthEventStreamV4Signer::SignEventMessage(Event::Message& message, Aws::String& priorSignature) const -{ - using Event::EventHeaderValue; - - Aws::StringStream stringToSign; - stringToSign << EVENT_STREAM_PAYLOAD << NEWLINE; - const DateTime now = GetSigningTimestamp(); - const auto simpleDate = now.ToGmtString(SIMPLE_DATE_FORMAT_STR); + return true; +} + +// this works regardless if the current machine is Big/Little Endian +static void WriteBigEndian(Aws::String& str, uint64_t n) +{ + int shift = 56; + while(shift >= 0) + { + str.push_back((n >> shift) & 0xFF); + shift -= 8; + } +} + +bool AWSAuthEventStreamV4Signer::SignEventMessage(Event::Message& message, Aws::String& priorSignature) const +{ + using Event::EventHeaderValue; + + Aws::StringStream stringToSign; + stringToSign << EVENT_STREAM_PAYLOAD << NEWLINE; + const DateTime now = GetSigningTimestamp(); + const auto simpleDate = now.ToGmtString(SIMPLE_DATE_FORMAT_STR); stringToSign << now.ToGmtString(DateFormat::ISO_8601_BASIC) << NEWLINE - << simpleDate << "/" << m_region << "/" - << m_serviceName << "/aws4_request" << NEWLINE << priorSignature << NEWLINE; - - - Aws::String nonSignatureHeaders; - nonSignatureHeaders.push_back(char(sizeof(EVENTSTREAM_DATE_HEADER) - 1)); // length of the string - nonSignatureHeaders += EVENTSTREAM_DATE_HEADER; - nonSignatureHeaders.push_back(static_cast<char>(EventHeaderValue::EventHeaderType::TIMESTAMP)); // type of the value - WriteBigEndian(nonSignatureHeaders, static_cast<uint64_t>(now.Millis())); // the value of the timestamp in big-endian - - auto hashOutcome = m_hash.Calculate(nonSignatureHeaders); - if (!hashOutcome.IsSuccess()) - { - AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Failed to hash (sha256) non-signature headers."); - return false; - } - - const auto nonSignatureHeadersHash = hashOutcome.GetResult(); - stringToSign << HashingUtils::HexEncode(nonSignatureHeadersHash) << NEWLINE; - - if (message.GetEventPayload().empty()) - { - AWS_LOGSTREAM_WARN(v4StreamingLogTag, "Attempting to sign an empty message (no payload and no headers). " - "It is unlikely that this is the intended behavior."); - } - else - { - // use a preallocatedStreamBuf to avoid making a copy. - // The Hashing API requires either Aws::String or IStream as input. - // TODO: the hashing API should be accept 'unsigned char*' as input. - Utils::Stream::PreallocatedStreamBuf streamBuf(message.GetEventPayload().data(), message.GetEventPayload().size()); - Aws::IOStream payload(&streamBuf); - hashOutcome = m_hash.Calculate(payload); - - if (!hashOutcome.IsSuccess()) - { - AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Failed to hash (sha256) non-signature headers."); - return false; - } - const auto payloadHash = hashOutcome.GetResult(); - stringToSign << HashingUtils::HexEncode(payloadHash); - AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Payload hash - " << HashingUtils::HexEncode(payloadHash)); - } - + << simpleDate << "/" << m_region << "/" + << m_serviceName << "/aws4_request" << NEWLINE << priorSignature << NEWLINE; + + + Aws::String nonSignatureHeaders; + nonSignatureHeaders.push_back(char(sizeof(EVENTSTREAM_DATE_HEADER) - 1)); // length of the string + nonSignatureHeaders += EVENTSTREAM_DATE_HEADER; + nonSignatureHeaders.push_back(static_cast<char>(EventHeaderValue::EventHeaderType::TIMESTAMP)); // type of the value + WriteBigEndian(nonSignatureHeaders, static_cast<uint64_t>(now.Millis())); // the value of the timestamp in big-endian + + auto hashOutcome = m_hash.Calculate(nonSignatureHeaders); + if (!hashOutcome.IsSuccess()) + { + AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Failed to hash (sha256) non-signature headers."); + return false; + } + + const auto nonSignatureHeadersHash = hashOutcome.GetResult(); + stringToSign << HashingUtils::HexEncode(nonSignatureHeadersHash) << NEWLINE; + + if (message.GetEventPayload().empty()) + { + AWS_LOGSTREAM_WARN(v4StreamingLogTag, "Attempting to sign an empty message (no payload and no headers). " + "It is unlikely that this is the intended behavior."); + } + else + { + // use a preallocatedStreamBuf to avoid making a copy. + // The Hashing API requires either Aws::String or IStream as input. + // TODO: the hashing API should be accept 'unsigned char*' as input. + Utils::Stream::PreallocatedStreamBuf streamBuf(message.GetEventPayload().data(), message.GetEventPayload().size()); + Aws::IOStream payload(&streamBuf); + hashOutcome = m_hash.Calculate(payload); + + if (!hashOutcome.IsSuccess()) + { + AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Failed to hash (sha256) non-signature headers."); + return false; + } + const auto payloadHash = hashOutcome.GetResult(); + stringToSign << HashingUtils::HexEncode(payloadHash); + AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Payload hash - " << HashingUtils::HexEncode(payloadHash)); + } + Utils::ByteBuffer finalSignatureDigest = GenerateSignature(m_credentialsProvider->GetAWSCredentials(), stringToSign.str(), simpleDate, m_region, m_serviceName); - const auto finalSignature = HashingUtils::HexEncode(finalSignatureDigest); - AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Final computed signing hash: " << finalSignature); - priorSignature = finalSignature; - - message.InsertEventHeader(EVENTSTREAM_DATE_HEADER, EventHeaderValue(now.Millis(), EventHeaderValue::EventHeaderType::TIMESTAMP)); - message.InsertEventHeader(EVENTSTREAM_SIGNATURE_HEADER, std::move(finalSignatureDigest)); - - AWS_LOGSTREAM_INFO(v4StreamingLogTag, "Event chunk final signature - " << finalSignature); - return true; -} - -bool AWSAuthEventStreamV4Signer::ShouldSignHeader(const Aws::String& header) const -{ - return std::find(m_unsignedHeaders.cbegin(), m_unsignedHeaders.cend(), Aws::Utils::StringUtils::ToLower(header.c_str())) == m_unsignedHeaders.cend(); -} - -Utils::ByteBuffer AWSAuthEventStreamV4Signer::GenerateSignature(const AWSCredentials& credentials, const Aws::String& stringToSign, + const auto finalSignature = HashingUtils::HexEncode(finalSignatureDigest); + AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Final computed signing hash: " << finalSignature); + priorSignature = finalSignature; + + message.InsertEventHeader(EVENTSTREAM_DATE_HEADER, EventHeaderValue(now.Millis(), EventHeaderValue::EventHeaderType::TIMESTAMP)); + message.InsertEventHeader(EVENTSTREAM_SIGNATURE_HEADER, std::move(finalSignatureDigest)); + + AWS_LOGSTREAM_INFO(v4StreamingLogTag, "Event chunk final signature - " << finalSignature); + return true; +} + +bool AWSAuthEventStreamV4Signer::ShouldSignHeader(const Aws::String& header) const +{ + return std::find(m_unsignedHeaders.cbegin(), m_unsignedHeaders.cend(), Aws::Utils::StringUtils::ToLower(header.c_str())) == m_unsignedHeaders.cend(); +} + +Utils::ByteBuffer AWSAuthEventStreamV4Signer::GenerateSignature(const AWSCredentials& credentials, const Aws::String& stringToSign, const Aws::String& simpleDate, const Aws::String& region, const Aws::String& serviceName) const -{ - Utils::Threading::ReaderLockGuard guard(m_derivedKeyLock); - const auto& secretKey = credentials.GetAWSSecretKey(); - if (secretKey != m_currentSecretKey || simpleDate != m_currentDateStr) - { - guard.UpgradeToWriterLock(); - // double-checked lock to prevent updating twice - if (m_currentDateStr != simpleDate || m_currentSecretKey != secretKey) - { - m_currentSecretKey = secretKey; - m_currentDateStr = simpleDate; +{ + Utils::Threading::ReaderLockGuard guard(m_derivedKeyLock); + const auto& secretKey = credentials.GetAWSSecretKey(); + if (secretKey != m_currentSecretKey || simpleDate != m_currentDateStr) + { + guard.UpgradeToWriterLock(); + // double-checked lock to prevent updating twice + if (m_currentDateStr != simpleDate || m_currentSecretKey != secretKey) + { + m_currentSecretKey = secretKey; + m_currentDateStr = simpleDate; m_derivedKey = ComputeHash(m_currentSecretKey, m_currentDateStr, region, serviceName); - } - - } - return GenerateSignature(stringToSign, m_derivedKey); -} - -Utils::ByteBuffer AWSAuthEventStreamV4Signer::GenerateSignature(const Aws::String& stringToSign, const ByteBuffer& key) const -{ - AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Final String to sign: " << stringToSign); - - Aws::StringStream ss; - - auto hashResult = m_HMAC.Calculate(ByteBuffer((unsigned char*)stringToSign.c_str(), stringToSign.length()), key); - if (!hashResult.IsSuccess()) - { - AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Unable to hmac (sha256) final string"); - AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "The final string is: \"" << stringToSign << "\""); - return {}; - } - - return hashResult.GetResult(); -} - -Aws::String AWSAuthEventStreamV4Signer::GenerateStringToSign(const Aws::String& dateValue, const Aws::String& simpleDate, - const Aws::String& canonicalRequestHash, const Aws::String& region, const Aws::String& serviceName) const -{ - //generate the actual string we will use in signing the final request. - Aws::StringStream ss; - - ss << AWS_HMAC_SHA256 << NEWLINE << dateValue << NEWLINE << simpleDate << "/" << region << "/" - << serviceName << "/" << AWS4_REQUEST << NEWLINE << canonicalRequestHash; - - return ss.str(); -} - -Aws::Utils::ByteBuffer AWSAuthEventStreamV4Signer::ComputeHash(const Aws::String& secretKey, - const Aws::String& simpleDate, const Aws::String& region, const Aws::String& serviceName) const -{ - Aws::String signingKey(SIGNING_KEY); - signingKey.append(secretKey); - auto hashResult = m_HMAC.Calculate(ByteBuffer((unsigned char*)simpleDate.c_str(), simpleDate.length()), - ByteBuffer((unsigned char*)signingKey.c_str(), signingKey.length())); - - if (!hashResult.IsSuccess()) - { - AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Failed to HMAC (SHA256) date string \"" << simpleDate << "\""); - return {}; - } - - auto kDate = hashResult.GetResult(); - hashResult = m_HMAC.Calculate(ByteBuffer((unsigned char*)region.c_str(), region.length()), kDate); - if (!hashResult.IsSuccess()) - { - AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Failed to HMAC (SHA256) region string \"" << region << "\""); - return {}; - } - - auto kRegion = hashResult.GetResult(); - hashResult = m_HMAC.Calculate(ByteBuffer((unsigned char*)serviceName.c_str(), serviceName.length()), kRegion); - if (!hashResult.IsSuccess()) - { - AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Failed to HMAC (SHA256) service string \"" << m_serviceName << "\""); - return {}; - } - - auto kService = hashResult.GetResult(); - hashResult = m_HMAC.Calculate(ByteBuffer((unsigned char*)AWS4_REQUEST, strlen(AWS4_REQUEST)), kService); - if (!hashResult.IsSuccess()) - { - AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Unable to HMAC (SHA256) request string"); - AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "The request string is: \"" << AWS4_REQUEST << "\""); - return {}; - } - return hashResult.GetResult(); -} + } + + } + return GenerateSignature(stringToSign, m_derivedKey); +} + +Utils::ByteBuffer AWSAuthEventStreamV4Signer::GenerateSignature(const Aws::String& stringToSign, const ByteBuffer& key) const +{ + AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "Final String to sign: " << stringToSign); + + Aws::StringStream ss; + + auto hashResult = m_HMAC.Calculate(ByteBuffer((unsigned char*)stringToSign.c_str(), stringToSign.length()), key); + if (!hashResult.IsSuccess()) + { + AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Unable to hmac (sha256) final string"); + AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "The final string is: \"" << stringToSign << "\""); + return {}; + } + + return hashResult.GetResult(); +} + +Aws::String AWSAuthEventStreamV4Signer::GenerateStringToSign(const Aws::String& dateValue, const Aws::String& simpleDate, + const Aws::String& canonicalRequestHash, const Aws::String& region, const Aws::String& serviceName) const +{ + //generate the actual string we will use in signing the final request. + Aws::StringStream ss; + + ss << AWS_HMAC_SHA256 << NEWLINE << dateValue << NEWLINE << simpleDate << "/" << region << "/" + << serviceName << "/" << AWS4_REQUEST << NEWLINE << canonicalRequestHash; + + return ss.str(); +} + +Aws::Utils::ByteBuffer AWSAuthEventStreamV4Signer::ComputeHash(const Aws::String& secretKey, + const Aws::String& simpleDate, const Aws::String& region, const Aws::String& serviceName) const +{ + Aws::String signingKey(SIGNING_KEY); + signingKey.append(secretKey); + auto hashResult = m_HMAC.Calculate(ByteBuffer((unsigned char*)simpleDate.c_str(), simpleDate.length()), + ByteBuffer((unsigned char*)signingKey.c_str(), signingKey.length())); + + if (!hashResult.IsSuccess()) + { + AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Failed to HMAC (SHA256) date string \"" << simpleDate << "\""); + return {}; + } + + auto kDate = hashResult.GetResult(); + hashResult = m_HMAC.Calculate(ByteBuffer((unsigned char*)region.c_str(), region.length()), kDate); + if (!hashResult.IsSuccess()) + { + AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Failed to HMAC (SHA256) region string \"" << region << "\""); + return {}; + } + + auto kRegion = hashResult.GetResult(); + hashResult = m_HMAC.Calculate(ByteBuffer((unsigned char*)serviceName.c_str(), serviceName.length()), kRegion); + if (!hashResult.IsSuccess()) + { + AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Failed to HMAC (SHA256) service string \"" << m_serviceName << "\""); + return {}; + } + + auto kService = hashResult.GetResult(); + hashResult = m_HMAC.Calculate(ByteBuffer((unsigned char*)AWS4_REQUEST, strlen(AWS4_REQUEST)), kService); + if (!hashResult.IsSuccess()) + { + AWS_LOGSTREAM_ERROR(v4StreamingLogTag, "Unable to HMAC (SHA256) request string"); + AWS_LOGSTREAM_DEBUG(v4StreamingLogTag, "The request string is: \"" << AWS4_REQUEST << "\""); + return {}; + } + return hashResult.GetResult(); +} diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/auth/AWSCredentialsProvider.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/auth/AWSCredentialsProvider.cpp index d26d7ab006..31e28b996f 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/auth/AWSCredentialsProvider.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/auth/AWSCredentialsProvider.cpp @@ -9,7 +9,7 @@ #include <aws/core/config/AWSProfileConfigLoader.h> #include <aws/core/platform/Environment.h> #include <aws/core/platform/FileSystem.h> -#include <aws/core/platform/OSVersionInfo.h> +#include <aws/core/platform/OSVersionInfo.h> #include <aws/core/utils/logging/LogMacros.h> #include <aws/core/utils/StringUtils.h> #include <aws/core/utils/json/JsonSerializer.h> @@ -27,7 +27,7 @@ using namespace Aws::Utils; using namespace Aws::Utils::Logging; using namespace Aws::Auth; using namespace Aws::Internal; -using namespace Aws::FileSystem; +using namespace Aws::FileSystem; using namespace Aws::Utils::Xml; using namespace Aws::Client; using Aws::Utils::Threading::ReaderLockGuard; @@ -40,11 +40,11 @@ static const char DEFAULT_PROFILE[] = "default"; static const char AWS_PROFILE_ENV_VAR[] = "AWS_PROFILE"; static const char AWS_PROFILE_DEFAULT_ENV_VAR[] = "AWS_DEFAULT_PROFILE"; -static const char AWS_CREDENTIALS_FILE[] = "AWS_SHARED_CREDENTIALS_FILE"; +static const char AWS_CREDENTIALS_FILE[] = "AWS_SHARED_CREDENTIALS_FILE"; extern const char AWS_CONFIG_FILE[] = "AWS_CONFIG_FILE"; extern const char PROFILE_DIRECTORY[] = ".aws"; -static const char DEFAULT_CREDENTIALS_FILE[] = "credentials"; +static const char DEFAULT_CREDENTIALS_FILE[] = "credentials"; extern const char DEFAULT_CONFIG_FILE[] = "config"; @@ -98,17 +98,17 @@ AWSCredentials EnvironmentAWSCredentialsProvider::GetAWSCredentials() return credentials; } -Aws::String Aws::Auth::GetConfigProfileFilename() +Aws::String Aws::Auth::GetConfigProfileFilename() { - auto configFileNameFromVar = Aws::Environment::GetEnv(AWS_CONFIG_FILE); - if (!configFileNameFromVar.empty()) - { - return configFileNameFromVar; - } - else - { + auto configFileNameFromVar = Aws::Environment::GetEnv(AWS_CONFIG_FILE); + if (!configFileNameFromVar.empty()) + { + return configFileNameFromVar; + } + else + { return Aws::FileSystem::GetHomeDirectory() + PROFILE_DIRECTORY + PATH_DELIM + DEFAULT_CONFIG_FILE; - } + } } Aws::String Aws::Auth::GetConfigProfileName() @@ -129,11 +129,11 @@ Aws::String Aws::Auth::GetConfigProfileName() } } -static const char* PROFILE_LOG_TAG = "ProfileConfigFileAWSCredentialsProvider"; +static const char* PROFILE_LOG_TAG = "ProfileConfigFileAWSCredentialsProvider"; Aws::String ProfileConfigFileAWSCredentialsProvider::GetCredentialsProfileFilename() { - auto credentialsFileNameFromVar = Aws::Environment::GetEnv(AWS_CREDENTIALS_FILE); + auto credentialsFileNameFromVar = Aws::Environment::GetEnv(AWS_CREDENTIALS_FILE); if (credentialsFileNameFromVar.empty()) { @@ -147,15 +147,15 @@ Aws::String ProfileConfigFileAWSCredentialsProvider::GetCredentialsProfileFilena Aws::String ProfileConfigFileAWSCredentialsProvider::GetProfileDirectory() { - Aws::String credentialsFileName = GetCredentialsProfileFilename(); - auto lastSeparator = credentialsFileName.find_last_of(PATH_DELIM); + Aws::String credentialsFileName = GetCredentialsProfileFilename(); + auto lastSeparator = credentialsFileName.find_last_of(PATH_DELIM); if (lastSeparator != std::string::npos) { - return credentialsFileName.substr(0, lastSeparator); + return credentialsFileName.substr(0, lastSeparator); } else { - return {}; + return {}; } } @@ -183,9 +183,9 @@ AWSCredentials ProfileConfigFileAWSCredentialsProvider::GetAWSCredentials() { RefreshIfExpired(); ReaderLockGuard guard(m_reloadLock); - auto credsFileProfileIter = m_credentialsFileLoader.GetProfiles().find(m_profileToUse); + auto credsFileProfileIter = m_credentialsFileLoader.GetProfiles().find(m_profileToUse); - if(credsFileProfileIter != m_credentialsFileLoader.GetProfiles().end()) + if(credsFileProfileIter != m_credentialsFileLoader.GetProfiles().end()) { return credsFileProfileIter->second.GetCredentials(); } @@ -355,37 +355,37 @@ void TaskRoleCredentialsProvider::RefreshIfExpired() Reload(); } - -static const char PROCESS_LOG_TAG[] = "ProcessCredentialsProvider"; -ProcessCredentialsProvider::ProcessCredentialsProvider() : + +static const char PROCESS_LOG_TAG[] = "ProcessCredentialsProvider"; +ProcessCredentialsProvider::ProcessCredentialsProvider() : m_profileToUse(Aws::Auth::GetConfigProfileName()) -{ - AWS_LOGSTREAM_INFO(PROCESS_LOG_TAG, "Setting process credentials provider to read config from " << m_profileToUse); -} - -ProcessCredentialsProvider::ProcessCredentialsProvider(const Aws::String& profile) : +{ + AWS_LOGSTREAM_INFO(PROCESS_LOG_TAG, "Setting process credentials provider to read config from " << m_profileToUse); +} + +ProcessCredentialsProvider::ProcessCredentialsProvider(const Aws::String& profile) : m_profileToUse(profile) -{ - AWS_LOGSTREAM_INFO(PROCESS_LOG_TAG, "Setting process credentials provider to read config from " << m_profileToUse); -} - -AWSCredentials ProcessCredentialsProvider::GetAWSCredentials() -{ - RefreshIfExpired(); - ReaderLockGuard guard(m_reloadLock); - return m_credentials; -} - - -void ProcessCredentialsProvider::Reload() -{ +{ + AWS_LOGSTREAM_INFO(PROCESS_LOG_TAG, "Setting process credentials provider to read config from " << m_profileToUse); +} + +AWSCredentials ProcessCredentialsProvider::GetAWSCredentials() +{ + RefreshIfExpired(); + ReaderLockGuard guard(m_reloadLock); + return m_credentials; +} + + +void ProcessCredentialsProvider::Reload() +{ auto profile = Aws::Config::GetCachedConfigProfile(m_profileToUse); const Aws::String &command = profile.GetCredentialProcess(); if (command.empty()) - { - AWS_LOGSTREAM_ERROR(PROCESS_LOG_TAG, "Failed to find credential process's profile: " << m_profileToUse); - return; - } + { + AWS_LOGSTREAM_ERROR(PROCESS_LOG_TAG, "Failed to find credential process's profile: " << m_profileToUse); + return; + } m_credentials = GetCredentialsFromProcess(command); } @@ -409,41 +409,41 @@ void ProcessCredentialsProvider::RefreshIfExpired() AWSCredentials Aws::Auth::GetCredentialsFromProcess(const Aws::String& process) { Aws::String command = process; - command.append(" 2>&1"); // redirect stderr to stdout - Aws::String result = Aws::Utils::StringUtils::Trim(Aws::OSVersionInfo::GetSysCommandOutput(command.c_str()).c_str()); - Json::JsonValue credentialsDoc(result); + command.append(" 2>&1"); // redirect stderr to stdout + Aws::String result = Aws::Utils::StringUtils::Trim(Aws::OSVersionInfo::GetSysCommandOutput(command.c_str()).c_str()); + Json::JsonValue credentialsDoc(result); if (!credentialsDoc.WasParseSuccessful()) - { + { AWS_LOGSTREAM_ERROR(PROFILE_LOG_TAG, "Failed to load credential from running: " << command << " Error: " << result); return {}; - } - - Aws::Utils::Json::JsonView credentialsView(credentialsDoc); - if (!credentialsView.KeyExists("Version") || credentialsView.GetInteger("Version") != 1) - { + } + + Aws::Utils::Json::JsonView credentialsView(credentialsDoc); + if (!credentialsView.KeyExists("Version") || credentialsView.GetInteger("Version") != 1) + { AWS_LOGSTREAM_ERROR(PROFILE_LOG_TAG, "Encountered an unsupported process credentials payload version:" << credentialsView.GetInteger("Version")); return {}; - } - + } + AWSCredentials credentials; - Aws::String accessKey, secretKey, token, expire; + Aws::String accessKey, secretKey, token, expire; if (credentialsView.KeyExists("AccessKeyId")) { credentials.SetAWSAccessKeyId(credentialsView.GetString("AccessKeyId")); } - + if (credentialsView.KeyExists("SecretAccessKey")) { credentials.SetAWSSecretKey(credentialsView.GetString("SecretAccessKey")); } - + if (credentialsView.KeyExists("SessionToken")) - { + { credentials.SetSessionToken(credentialsView.GetString("SessionToken")); - } - + } + if (credentialsView.KeyExists("Expiration")) - { + { const auto expiration = Aws::Utils::DateTime(credentialsView.GetString("Expiration"), DateFormat::ISO_8601); if (expiration.WasParseSuccessful()) { @@ -454,13 +454,13 @@ AWSCredentials Aws::Auth::GetCredentialsFromProcess(const Aws::String& process) AWS_LOGSTREAM_ERROR(PROFILE_LOG_TAG, "Failed to parse credential's expiration value as an ISO 8601 Date. Credentials will be marked expired."); credentials.SetExpiration(Aws::Utils::DateTime::Now()); } - } + } else { credentials.SetExpiration((std::chrono::time_point<std::chrono::system_clock>::max)()); } - + AWS_LOGSTREAM_DEBUG(PROFILE_LOG_TAG, "Successfully pulled credentials from process credential with AccessKey: " << accessKey << ", Expiration:" << credentialsView.GetString("Expiration")); return credentials; -} +} diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSClient.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSClient.cpp index 4fc3af3287..e1ff064840 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSClient.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSClient.cpp @@ -37,9 +37,9 @@ #include <aws/core/Version.h> #include <aws/core/platform/OSVersionInfo.h> -#include <cstring> -#include <cassert> - +#include <cstring> +#include <cassert> + using namespace Aws; using namespace Aws::Client; using namespace Aws::Http; @@ -560,38 +560,38 @@ StreamOutcome AWSClient::MakeRequestWithUnparsedResponse(const Aws::Http::URI& u return StreamOutcome(std::move(httpResponseOutcome)); } -XmlOutcome AWSXMLClient::MakeRequestWithEventStream(const Aws::Http::URI& uri, - const Aws::AmazonWebServiceRequest& request, - Http::HttpMethod method, +XmlOutcome AWSXMLClient::MakeRequestWithEventStream(const Aws::Http::URI& uri, + const Aws::AmazonWebServiceRequest& request, + Http::HttpMethod method, const char* signerName, const char* signerRegionOverride, const char* signerServiceNameOverride) const -{ +{ HttpResponseOutcome httpOutcome = AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride); - if (httpOutcome.IsSuccess()) - { - return XmlOutcome(AmazonWebServiceResult<XmlDocument>(XmlDocument(), httpOutcome.GetResult()->GetHeaders())); - } - + if (httpOutcome.IsSuccess()) + { + return XmlOutcome(AmazonWebServiceResult<XmlDocument>(XmlDocument(), httpOutcome.GetResult()->GetHeaders())); + } + return XmlOutcome(std::move(httpOutcome)); -} - +} + XmlOutcome AWSXMLClient::MakeRequestWithEventStream(const Aws::Http::URI& uri, Http::HttpMethod method, const char* signerName, const char* requestName, const char* signerRegionOverride, const char* signerServiceNameOverride) const -{ +{ HttpResponseOutcome httpOutcome = AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride); - if (httpOutcome.IsSuccess()) - { - return XmlOutcome(AmazonWebServiceResult<XmlDocument>(XmlDocument(), httpOutcome.GetResult()->GetHeaders())); - } - + if (httpOutcome.IsSuccess()) + { + return XmlOutcome(AmazonWebServiceResult<XmlDocument>(XmlDocument(), httpOutcome.GetResult()->GetHeaders())); + } + return XmlOutcome(std::move(httpOutcome)); -} - +} + void AWSClient::AddHeadersToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest, const Http::HeaderValueCollection& headerValues) const { @@ -666,37 +666,37 @@ void AWSClient::AddContentBodyToRequest(const std::shared_ptr<Aws::Http::HttpReq } } -Aws::String Aws::Client::GetAuthorizationHeader(const Aws::Http::HttpRequest& httpRequest) -{ - // Extract the hex-encoded signature from the authorization header rather than recalculating it. - assert(httpRequest.HasAwsAuthorization()); - const auto& authHeader = httpRequest.GetAwsAuthorization(); - auto signaturePosition = authHeader.rfind(Aws::Auth::SIGNATURE); - // The auth header should end with 'Signature=<64 chars>' - // Make sure we found the word 'Signature' in the header and make sure it's the last item followed by its 64 hex chars - if (signaturePosition == Aws::String::npos || (signaturePosition + strlen(Aws::Auth::SIGNATURE) + 1/*'=' character*/ + 64/*hex chars*/) != authHeader.length()) - { - AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, "Failed to extract signature from authorization header."); - return {}; - } - return authHeader.substr(signaturePosition + strlen(Aws::Auth::SIGNATURE) + 1); -} - +Aws::String Aws::Client::GetAuthorizationHeader(const Aws::Http::HttpRequest& httpRequest) +{ + // Extract the hex-encoded signature from the authorization header rather than recalculating it. + assert(httpRequest.HasAwsAuthorization()); + const auto& authHeader = httpRequest.GetAwsAuthorization(); + auto signaturePosition = authHeader.rfind(Aws::Auth::SIGNATURE); + // The auth header should end with 'Signature=<64 chars>' + // Make sure we found the word 'Signature' in the header and make sure it's the last item followed by its 64 hex chars + if (signaturePosition == Aws::String::npos || (signaturePosition + strlen(Aws::Auth::SIGNATURE) + 1/*'=' character*/ + 64/*hex chars*/) != authHeader.length()) + { + AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, "Failed to extract signature from authorization header."); + return {}; + } + return authHeader.substr(signaturePosition + strlen(Aws::Auth::SIGNATURE) + 1); +} + void AWSClient::BuildHttpRequest(const Aws::AmazonWebServiceRequest& request, const std::shared_ptr<HttpRequest>& httpRequest) const -{ +{ //do headers first since the request likely will set content-length as it's own header. - AddHeadersToRequest(httpRequest, request.GetHeaders()); - + AddHeadersToRequest(httpRequest, request.GetHeaders()); + if (request.IsEventStreamRequest()) - { + { httpRequest->AddContentBody(request.GetBody()); - } + } else { AddContentBodyToRequest(httpRequest, request.GetBody(), request.ShouldComputeContentMd5(), request.IsStreaming() && request.IsChunked() && m_httpClient->SupportsChunkedTransferEncoding()); } - + // Pass along handlers for processing data sent/received in bytes httpRequest->SetDataReceivedEventHandler(request.GetDataReceivedEventHandler()); httpRequest->SetDataSentEventHandler(request.GetDataSentEventHandler()); @@ -719,7 +719,7 @@ Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, long lo return request->GetURIString(); } - return {}; + return {}; } Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds) @@ -735,7 +735,7 @@ Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, const A return request->GetURIString(); } - return {}; + return {}; } Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, const char* region, long long expirationInSeconds) const @@ -775,7 +775,7 @@ Aws::String AWSClient::GeneratePresignedUrl(Aws::Http::URI& uri, Aws::Http::Http return request->GetURIString(); } - return {}; + return {}; } Aws::String AWSClient::GeneratePresignedUrl(Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds) @@ -791,7 +791,7 @@ Aws::String AWSClient::GeneratePresignedUrl(Aws::Http::URI& uri, Aws::Http::Http return request->GetURIString(); } - return {}; + return {}; } Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request, Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, @@ -805,7 +805,7 @@ Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& return httpRequest->GetURIString(); } - return {}; + return {}; } Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request, Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, @@ -819,7 +819,7 @@ const Aws::Http::QueryStringParameterCollection& extraParams, long long expirati return httpRequest->GetURIString(); } - return {}; + return {}; } Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request, Aws::Http::URI& uri, Aws::Http::HttpMethod method, @@ -833,7 +833,7 @@ Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& return httpRequest->GetURIString(); } - return {}; + return {}; } std::shared_ptr<Aws::Http::HttpRequest> AWSClient::ConvertToRequestForPresigning(const Aws::AmazonWebServiceRequest& request, Aws::Http::URI& uri, @@ -850,12 +850,12 @@ std::shared_ptr<Aws::Http::HttpRequest> AWSClient::ConvertToRequestForPresigning return httpRequest; } -std::shared_ptr<Aws::Http::HttpResponse> AWSClient::MakeHttpRequest(std::shared_ptr<Aws::Http::HttpRequest>& request) const -{ - return m_httpClient->MakeRequest(request, m_readRateLimiter.get(), m_writeRateLimiter.get()); -} +std::shared_ptr<Aws::Http::HttpResponse> AWSClient::MakeHttpRequest(std::shared_ptr<Aws::Http::HttpRequest>& request) const +{ + return m_httpClient->MakeRequest(request, m_readRateLimiter.get(), m_writeRateLimiter.get()); +} + - //////////////////////////////////////////////////////////////////////////// AWSJsonClient::AWSJsonClient(const Aws::Client::ClientConfiguration& configuration, const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer, @@ -925,39 +925,39 @@ JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri, return JsonOutcome(AmazonWebServiceResult<JsonValue>(JsonValue(), httpOutcome.GetResult()->GetHeaders())); } -JsonOutcome AWSJsonClient::MakeEventStreamRequest(std::shared_ptr<Aws::Http::HttpRequest>& request) const -{ - // request is assumed to be signed - std::shared_ptr<HttpResponse> httpResponse = MakeHttpRequest(request); - - if (DoesResponseGenerateError(httpResponse)) - { - AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned error. Attempting to generate appropriate error codes from response"); +JsonOutcome AWSJsonClient::MakeEventStreamRequest(std::shared_ptr<Aws::Http::HttpRequest>& request) const +{ + // request is assumed to be signed + std::shared_ptr<HttpResponse> httpResponse = MakeHttpRequest(request); + + if (DoesResponseGenerateError(httpResponse)) + { + AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned error. Attempting to generate appropriate error codes from response"); auto error = BuildAWSError(httpResponse); return JsonOutcome(std::move(error)); - } - - AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned successful response."); - + } + + AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned successful response."); + HttpResponseOutcome httpOutcome(std::move(httpResponse)); - - if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) - { - JsonValue jsonValue(httpOutcome.GetResult()->GetResponseBody()); - if (!jsonValue.WasParseSuccessful()) - { - return JsonOutcome(AWSError<CoreErrors>(CoreErrors::UNKNOWN, "Json Parser Error", jsonValue.GetErrorMessage(), false)); - } - - //this is stupid, but gcc doesn't pick up the covariant on the dereference so we have to give it a little hint. - return JsonOutcome(AmazonWebServiceResult<JsonValue>(std::move(jsonValue), - httpOutcome.GetResult()->GetHeaders(), - httpOutcome.GetResult()->GetResponseCode())); - } - - return JsonOutcome(AmazonWebServiceResult<JsonValue>(JsonValue(), httpOutcome.GetResult()->GetHeaders())); -} - + + if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) + { + JsonValue jsonValue(httpOutcome.GetResult()->GetResponseBody()); + if (!jsonValue.WasParseSuccessful()) + { + return JsonOutcome(AWSError<CoreErrors>(CoreErrors::UNKNOWN, "Json Parser Error", jsonValue.GetErrorMessage(), false)); + } + + //this is stupid, but gcc doesn't pick up the covariant on the dereference so we have to give it a little hint. + return JsonOutcome(AmazonWebServiceResult<JsonValue>(std::move(jsonValue), + httpOutcome.GetResult()->GetHeaders(), + httpOutcome.GetResult()->GetResponseCode())); + } + + return JsonOutcome(AmazonWebServiceResult<JsonValue>(JsonValue(), httpOutcome.GetResult()->GetHeaders())); +} + AWSError<CoreErrors> AWSJsonClient::BuildAWSError( const std::shared_ptr<Aws::Http::HttpResponse>& httpResponse) const { diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp index fc5e6c5dd9..f5fa676f98 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp @@ -72,7 +72,7 @@ AWSError<CoreErrors> XmlErrorMarshaller::Marshall(const Aws::Http::HttpResponse& AWS_LOGSTREAM_TRACE(AWS_ERROR_MARSHALLER_LOG_TAG, "Error response is " << doc.ConvertToString()); bool errorParsed = false; AWSError<CoreErrors> error; - if (doc.WasParseSuccessful() && !doc.GetRootElement().IsNull()) + if (doc.WasParseSuccessful() && !doc.GetRootElement().IsNull()) { XmlNode errorNode = doc.GetRootElement(); diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp index 6fcb1fd497..e517379a77 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp @@ -27,7 +27,7 @@ namespace Client static const char* CLIENT_CONFIG_TAG = "ClientConfiguration"; -AWS_CORE_API Aws::String ComputeUserAgentString() +AWS_CORE_API Aws::String ComputeUserAgentString() { Aws::StringStream ss; ss << "aws-sdk-cpp/" << Version::GetVersionString() << " " << Aws::OSVersionInfo::ComputeOSVersionString() @@ -54,8 +54,8 @@ ClientConfiguration::ClientConfiguration() : httpLibOverride(Aws::Http::TransferLibType::DEFAULT_CLIENT), followRedirects(FollowRedirectsPolicy::DEFAULT), disableExpectHeader(false), - enableClockSkewAdjustment(true), - enableHostPrefixInjection(true), + enableClockSkewAdjustment(true), + enableHostPrefixInjection(true), enableEndpointDiscovery(false), profileName(Aws::Auth::GetConfigProfileName()) { diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/CoreErrors.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/CoreErrors.cpp index 1d445cc2c9..8c2c288dcd 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/CoreErrors.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/CoreErrors.cpp @@ -5,107 +5,107 @@ #include <aws/core/client/AWSError.h> #include <aws/core/client/CoreErrors.h> -#include <aws/core/utils/memory/stl/AWSMap.h> +#include <aws/core/utils/memory/stl/AWSMap.h> #include <aws/core/utils/HashingUtils.h> using namespace Aws::Client; using namespace Aws::Utils; using namespace Aws::Http; -#ifdef _MSC_VER -#pragma warning(push) -// VS2015 compiler's bug, warning s_CoreErrorsMapper: symbol will be dynamically initialized (implementation limitation) -#pragma warning(disable : 4592) -#endif +#ifdef _MSC_VER +#pragma warning(push) +// VS2015 compiler's bug, warning s_CoreErrorsMapper: symbol will be dynamically initialized (implementation limitation) +#pragma warning(disable : 4592) +#endif -static Aws::UniquePtr<Aws::Map<Aws::String, AWSError<CoreErrors> > > s_CoreErrorsMapper(nullptr); - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -void CoreErrorsMapper::InitCoreErrorsMapper() +static Aws::UniquePtr<Aws::Map<Aws::String, AWSError<CoreErrors> > > s_CoreErrorsMapper(nullptr); + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +void CoreErrorsMapper::InitCoreErrorsMapper() { - if (s_CoreErrorsMapper) - { - return; - } - s_CoreErrorsMapper = Aws::MakeUnique<Aws::Map<Aws::String, AWSError<CoreErrors> > >("InitCoreErrorsMapper"); + if (s_CoreErrorsMapper) + { + return; + } + s_CoreErrorsMapper = Aws::MakeUnique<Aws::Map<Aws::String, AWSError<CoreErrors> > >("InitCoreErrorsMapper"); - s_CoreErrorsMapper->emplace("IncompleteSignature", AWSError<CoreErrors>(CoreErrors::INCOMPLETE_SIGNATURE, false)); - s_CoreErrorsMapper->emplace("IncompleteSignatureException", AWSError<CoreErrors>(CoreErrors::INCOMPLETE_SIGNATURE, false)); - s_CoreErrorsMapper->emplace("InvalidSignatureException", AWSError<CoreErrors>(CoreErrors::INVALID_SIGNATURE, false)); - s_CoreErrorsMapper->emplace("InvalidSignature", AWSError<CoreErrors>(CoreErrors::INVALID_SIGNATURE, false)); - s_CoreErrorsMapper->emplace("InternalFailureException", AWSError<CoreErrors>(CoreErrors::INTERNAL_FAILURE, true)); - s_CoreErrorsMapper->emplace("InternalFailure", AWSError<CoreErrors>(CoreErrors::INTERNAL_FAILURE, true)); - s_CoreErrorsMapper->emplace("InternalServerError", AWSError<CoreErrors>(CoreErrors::INTERNAL_FAILURE, true)); - s_CoreErrorsMapper->emplace("InternalError", AWSError<CoreErrors>(CoreErrors::INTERNAL_FAILURE, true)); - s_CoreErrorsMapper->emplace("InvalidActionException", AWSError<CoreErrors>(CoreErrors::INVALID_ACTION, false)); - s_CoreErrorsMapper->emplace("InvalidAction", AWSError<CoreErrors>(CoreErrors::INVALID_ACTION, false)); - s_CoreErrorsMapper->emplace("InvalidClientTokenIdException", AWSError<CoreErrors>(CoreErrors::INVALID_CLIENT_TOKEN_ID, false)); - s_CoreErrorsMapper->emplace("InvalidClientTokenId", AWSError<CoreErrors>(CoreErrors::INVALID_CLIENT_TOKEN_ID, false)); - s_CoreErrorsMapper->emplace("InvalidParameterCombinationException", AWSError<CoreErrors>(CoreErrors::INVALID_PARAMETER_COMBINATION, false)); - s_CoreErrorsMapper->emplace("InvalidParameterCombination", AWSError<CoreErrors>(CoreErrors::INVALID_PARAMETER_COMBINATION, false)); - s_CoreErrorsMapper->emplace("InvalidParameterValueException", AWSError<CoreErrors>(CoreErrors::INVALID_PARAMETER_VALUE, false)); - s_CoreErrorsMapper->emplace("InvalidParameterValue", AWSError<CoreErrors>(CoreErrors::INVALID_PARAMETER_VALUE, false)); - s_CoreErrorsMapper->emplace("InvalidQueryParameterException", AWSError<CoreErrors>(CoreErrors::INVALID_QUERY_PARAMETER, false)); - s_CoreErrorsMapper->emplace("InvalidQueryParameter", AWSError<CoreErrors>(CoreErrors::INVALID_QUERY_PARAMETER, false)); - s_CoreErrorsMapper->emplace("MalformedQueryStringException", AWSError<CoreErrors>(CoreErrors::MALFORMED_QUERY_STRING, false)); - s_CoreErrorsMapper->emplace("MalformedQueryString", AWSError<CoreErrors>(CoreErrors::MALFORMED_QUERY_STRING, false)); - s_CoreErrorsMapper->emplace("MissingActionException", AWSError<CoreErrors>(CoreErrors::MISSING_ACTION, false)); - s_CoreErrorsMapper->emplace("MissingAction", AWSError<CoreErrors>(CoreErrors::MISSING_ACTION, false)); - s_CoreErrorsMapper->emplace("MissingAuthenticationTokenException", AWSError<CoreErrors>(CoreErrors::MISSING_AUTHENTICATION_TOKEN, false)); - s_CoreErrorsMapper->emplace("MissingAuthenticationToken", AWSError<CoreErrors>(CoreErrors::MISSING_AUTHENTICATION_TOKEN, false)); - s_CoreErrorsMapper->emplace("MissingParameterException", AWSError<CoreErrors>(CoreErrors::MISSING_PARAMETER, false)); - s_CoreErrorsMapper->emplace("MissingParameter", AWSError<CoreErrors>(CoreErrors::MISSING_PARAMETER, false)); - s_CoreErrorsMapper->emplace("OptInRequired", AWSError<CoreErrors>(CoreErrors::OPT_IN_REQUIRED, false)); - s_CoreErrorsMapper->emplace("RequestExpiredException", AWSError<CoreErrors>(CoreErrors::REQUEST_EXPIRED, true)); - s_CoreErrorsMapper->emplace("RequestExpired", AWSError<CoreErrors>(CoreErrors::REQUEST_EXPIRED, true)); - s_CoreErrorsMapper->emplace("ServiceUnavailableException", AWSError<CoreErrors>(CoreErrors::SERVICE_UNAVAILABLE, true)); - s_CoreErrorsMapper->emplace("ServiceUnavailableError", AWSError<CoreErrors>(CoreErrors::SERVICE_UNAVAILABLE, true)); - s_CoreErrorsMapper->emplace("ServiceUnavailable", AWSError<CoreErrors>(CoreErrors::SERVICE_UNAVAILABLE, true)); - s_CoreErrorsMapper->emplace("RequestThrottledException", AWSError<CoreErrors>(CoreErrors::THROTTLING, true)); - s_CoreErrorsMapper->emplace("RequestThrottled", AWSError<CoreErrors>(CoreErrors::THROTTLING, true)); - s_CoreErrorsMapper->emplace("ThrottlingException", AWSError<CoreErrors>(CoreErrors::THROTTLING, true)); - s_CoreErrorsMapper->emplace("ThrottledException", AWSError<CoreErrors>(CoreErrors::THROTTLING, true)); - s_CoreErrorsMapper->emplace("Throttling", AWSError<CoreErrors>(CoreErrors::THROTTLING, true)); - s_CoreErrorsMapper->emplace("ValidationErrorException", AWSError<CoreErrors>(CoreErrors::VALIDATION, false)); - s_CoreErrorsMapper->emplace("ValidationException", AWSError<CoreErrors>(CoreErrors::VALIDATION, false)); - s_CoreErrorsMapper->emplace("ValidationError", AWSError<CoreErrors>(CoreErrors::VALIDATION, false)); - s_CoreErrorsMapper->emplace("AccessDeniedException", AWSError<CoreErrors>(CoreErrors::ACCESS_DENIED, false)); - s_CoreErrorsMapper->emplace("AccessDenied", AWSError<CoreErrors>(CoreErrors::ACCESS_DENIED, false)); - s_CoreErrorsMapper->emplace("ResourceNotFoundException", AWSError<CoreErrors>(CoreErrors::RESOURCE_NOT_FOUND, false)); - s_CoreErrorsMapper->emplace("ResourceNotFound", AWSError<CoreErrors>(CoreErrors::RESOURCE_NOT_FOUND, false)); - s_CoreErrorsMapper->emplace("UnrecognizedClientException", AWSError<CoreErrors>(CoreErrors::UNRECOGNIZED_CLIENT, false)); - s_CoreErrorsMapper->emplace("UnrecognizedClient", AWSError<CoreErrors>(CoreErrors::UNRECOGNIZED_CLIENT, false)); - s_CoreErrorsMapper->emplace("SlowDownException", AWSError<CoreErrors>(CoreErrors::SLOW_DOWN, true)); - s_CoreErrorsMapper->emplace("SlowDown", AWSError<CoreErrors>(CoreErrors::SLOW_DOWN, true)); - s_CoreErrorsMapper->emplace("SignatureDoesNotMatchException", AWSError<CoreErrors>(CoreErrors::SIGNATURE_DOES_NOT_MATCH, false)); - s_CoreErrorsMapper->emplace("SignatureDoesNotMatch", AWSError<CoreErrors>(CoreErrors::SIGNATURE_DOES_NOT_MATCH, false)); - s_CoreErrorsMapper->emplace("InvalidAccessKeyIdException", AWSError<CoreErrors>(CoreErrors::INVALID_ACCESS_KEY_ID, false)); - s_CoreErrorsMapper->emplace("InvalidAccessKeyId", AWSError<CoreErrors>(CoreErrors::INVALID_ACCESS_KEY_ID, false)); - s_CoreErrorsMapper->emplace("RequestTimeTooSkewedException", AWSError<CoreErrors>(CoreErrors::REQUEST_TIME_TOO_SKEWED, true)); - s_CoreErrorsMapper->emplace("RequestTimeTooSkewed", AWSError<CoreErrors>(CoreErrors::REQUEST_TIME_TOO_SKEWED, true)); - s_CoreErrorsMapper->emplace("RequestTimeoutException", AWSError<CoreErrors>(CoreErrors::REQUEST_TIMEOUT, true)); - s_CoreErrorsMapper->emplace("RequestTimeout", AWSError<CoreErrors>(CoreErrors::REQUEST_TIMEOUT, true)); -} + s_CoreErrorsMapper->emplace("IncompleteSignature", AWSError<CoreErrors>(CoreErrors::INCOMPLETE_SIGNATURE, false)); + s_CoreErrorsMapper->emplace("IncompleteSignatureException", AWSError<CoreErrors>(CoreErrors::INCOMPLETE_SIGNATURE, false)); + s_CoreErrorsMapper->emplace("InvalidSignatureException", AWSError<CoreErrors>(CoreErrors::INVALID_SIGNATURE, false)); + s_CoreErrorsMapper->emplace("InvalidSignature", AWSError<CoreErrors>(CoreErrors::INVALID_SIGNATURE, false)); + s_CoreErrorsMapper->emplace("InternalFailureException", AWSError<CoreErrors>(CoreErrors::INTERNAL_FAILURE, true)); + s_CoreErrorsMapper->emplace("InternalFailure", AWSError<CoreErrors>(CoreErrors::INTERNAL_FAILURE, true)); + s_CoreErrorsMapper->emplace("InternalServerError", AWSError<CoreErrors>(CoreErrors::INTERNAL_FAILURE, true)); + s_CoreErrorsMapper->emplace("InternalError", AWSError<CoreErrors>(CoreErrors::INTERNAL_FAILURE, true)); + s_CoreErrorsMapper->emplace("InvalidActionException", AWSError<CoreErrors>(CoreErrors::INVALID_ACTION, false)); + s_CoreErrorsMapper->emplace("InvalidAction", AWSError<CoreErrors>(CoreErrors::INVALID_ACTION, false)); + s_CoreErrorsMapper->emplace("InvalidClientTokenIdException", AWSError<CoreErrors>(CoreErrors::INVALID_CLIENT_TOKEN_ID, false)); + s_CoreErrorsMapper->emplace("InvalidClientTokenId", AWSError<CoreErrors>(CoreErrors::INVALID_CLIENT_TOKEN_ID, false)); + s_CoreErrorsMapper->emplace("InvalidParameterCombinationException", AWSError<CoreErrors>(CoreErrors::INVALID_PARAMETER_COMBINATION, false)); + s_CoreErrorsMapper->emplace("InvalidParameterCombination", AWSError<CoreErrors>(CoreErrors::INVALID_PARAMETER_COMBINATION, false)); + s_CoreErrorsMapper->emplace("InvalidParameterValueException", AWSError<CoreErrors>(CoreErrors::INVALID_PARAMETER_VALUE, false)); + s_CoreErrorsMapper->emplace("InvalidParameterValue", AWSError<CoreErrors>(CoreErrors::INVALID_PARAMETER_VALUE, false)); + s_CoreErrorsMapper->emplace("InvalidQueryParameterException", AWSError<CoreErrors>(CoreErrors::INVALID_QUERY_PARAMETER, false)); + s_CoreErrorsMapper->emplace("InvalidQueryParameter", AWSError<CoreErrors>(CoreErrors::INVALID_QUERY_PARAMETER, false)); + s_CoreErrorsMapper->emplace("MalformedQueryStringException", AWSError<CoreErrors>(CoreErrors::MALFORMED_QUERY_STRING, false)); + s_CoreErrorsMapper->emplace("MalformedQueryString", AWSError<CoreErrors>(CoreErrors::MALFORMED_QUERY_STRING, false)); + s_CoreErrorsMapper->emplace("MissingActionException", AWSError<CoreErrors>(CoreErrors::MISSING_ACTION, false)); + s_CoreErrorsMapper->emplace("MissingAction", AWSError<CoreErrors>(CoreErrors::MISSING_ACTION, false)); + s_CoreErrorsMapper->emplace("MissingAuthenticationTokenException", AWSError<CoreErrors>(CoreErrors::MISSING_AUTHENTICATION_TOKEN, false)); + s_CoreErrorsMapper->emplace("MissingAuthenticationToken", AWSError<CoreErrors>(CoreErrors::MISSING_AUTHENTICATION_TOKEN, false)); + s_CoreErrorsMapper->emplace("MissingParameterException", AWSError<CoreErrors>(CoreErrors::MISSING_PARAMETER, false)); + s_CoreErrorsMapper->emplace("MissingParameter", AWSError<CoreErrors>(CoreErrors::MISSING_PARAMETER, false)); + s_CoreErrorsMapper->emplace("OptInRequired", AWSError<CoreErrors>(CoreErrors::OPT_IN_REQUIRED, false)); + s_CoreErrorsMapper->emplace("RequestExpiredException", AWSError<CoreErrors>(CoreErrors::REQUEST_EXPIRED, true)); + s_CoreErrorsMapper->emplace("RequestExpired", AWSError<CoreErrors>(CoreErrors::REQUEST_EXPIRED, true)); + s_CoreErrorsMapper->emplace("ServiceUnavailableException", AWSError<CoreErrors>(CoreErrors::SERVICE_UNAVAILABLE, true)); + s_CoreErrorsMapper->emplace("ServiceUnavailableError", AWSError<CoreErrors>(CoreErrors::SERVICE_UNAVAILABLE, true)); + s_CoreErrorsMapper->emplace("ServiceUnavailable", AWSError<CoreErrors>(CoreErrors::SERVICE_UNAVAILABLE, true)); + s_CoreErrorsMapper->emplace("RequestThrottledException", AWSError<CoreErrors>(CoreErrors::THROTTLING, true)); + s_CoreErrorsMapper->emplace("RequestThrottled", AWSError<CoreErrors>(CoreErrors::THROTTLING, true)); + s_CoreErrorsMapper->emplace("ThrottlingException", AWSError<CoreErrors>(CoreErrors::THROTTLING, true)); + s_CoreErrorsMapper->emplace("ThrottledException", AWSError<CoreErrors>(CoreErrors::THROTTLING, true)); + s_CoreErrorsMapper->emplace("Throttling", AWSError<CoreErrors>(CoreErrors::THROTTLING, true)); + s_CoreErrorsMapper->emplace("ValidationErrorException", AWSError<CoreErrors>(CoreErrors::VALIDATION, false)); + s_CoreErrorsMapper->emplace("ValidationException", AWSError<CoreErrors>(CoreErrors::VALIDATION, false)); + s_CoreErrorsMapper->emplace("ValidationError", AWSError<CoreErrors>(CoreErrors::VALIDATION, false)); + s_CoreErrorsMapper->emplace("AccessDeniedException", AWSError<CoreErrors>(CoreErrors::ACCESS_DENIED, false)); + s_CoreErrorsMapper->emplace("AccessDenied", AWSError<CoreErrors>(CoreErrors::ACCESS_DENIED, false)); + s_CoreErrorsMapper->emplace("ResourceNotFoundException", AWSError<CoreErrors>(CoreErrors::RESOURCE_NOT_FOUND, false)); + s_CoreErrorsMapper->emplace("ResourceNotFound", AWSError<CoreErrors>(CoreErrors::RESOURCE_NOT_FOUND, false)); + s_CoreErrorsMapper->emplace("UnrecognizedClientException", AWSError<CoreErrors>(CoreErrors::UNRECOGNIZED_CLIENT, false)); + s_CoreErrorsMapper->emplace("UnrecognizedClient", AWSError<CoreErrors>(CoreErrors::UNRECOGNIZED_CLIENT, false)); + s_CoreErrorsMapper->emplace("SlowDownException", AWSError<CoreErrors>(CoreErrors::SLOW_DOWN, true)); + s_CoreErrorsMapper->emplace("SlowDown", AWSError<CoreErrors>(CoreErrors::SLOW_DOWN, true)); + s_CoreErrorsMapper->emplace("SignatureDoesNotMatchException", AWSError<CoreErrors>(CoreErrors::SIGNATURE_DOES_NOT_MATCH, false)); + s_CoreErrorsMapper->emplace("SignatureDoesNotMatch", AWSError<CoreErrors>(CoreErrors::SIGNATURE_DOES_NOT_MATCH, false)); + s_CoreErrorsMapper->emplace("InvalidAccessKeyIdException", AWSError<CoreErrors>(CoreErrors::INVALID_ACCESS_KEY_ID, false)); + s_CoreErrorsMapper->emplace("InvalidAccessKeyId", AWSError<CoreErrors>(CoreErrors::INVALID_ACCESS_KEY_ID, false)); + s_CoreErrorsMapper->emplace("RequestTimeTooSkewedException", AWSError<CoreErrors>(CoreErrors::REQUEST_TIME_TOO_SKEWED, true)); + s_CoreErrorsMapper->emplace("RequestTimeTooSkewed", AWSError<CoreErrors>(CoreErrors::REQUEST_TIME_TOO_SKEWED, true)); + s_CoreErrorsMapper->emplace("RequestTimeoutException", AWSError<CoreErrors>(CoreErrors::REQUEST_TIMEOUT, true)); + s_CoreErrorsMapper->emplace("RequestTimeout", AWSError<CoreErrors>(CoreErrors::REQUEST_TIMEOUT, true)); +} -void CoreErrorsMapper::CleanupCoreErrorsMapper() -{ - if (s_CoreErrorsMapper) - { - s_CoreErrorsMapper = nullptr; - } -} +void CoreErrorsMapper::CleanupCoreErrorsMapper() +{ + if (s_CoreErrorsMapper) + { + s_CoreErrorsMapper = nullptr; + } +} -AWSError<CoreErrors> CoreErrorsMapper::GetErrorForName(const char* errorName) -{ - auto iter = s_CoreErrorsMapper->find(errorName); - if (iter != s_CoreErrorsMapper->end()) - { - return iter->second; - } - return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false); +AWSError<CoreErrors> CoreErrorsMapper::GetErrorForName(const char* errorName) +{ + auto iter = s_CoreErrorsMapper->find(errorName); + if (iter != s_CoreErrorsMapper->end()) + { + return iter->second; + } + return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false); } AWS_CORE_API AWSError<CoreErrors> CoreErrorsMapper::GetErrorForHttpResponseCode(HttpResponseCode code) diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/config/AWSProfileConfigLoader.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/config/AWSProfileConfigLoader.cpp index 3cb761129a..9ec2e54f55 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/config/AWSProfileConfigLoader.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/config/AWSProfileConfigLoader.cpp @@ -139,7 +139,7 @@ namespace Aws } } - FlushProfileAndReset(line, std::string::npos, std::string::npos); + FlushProfileAndReset(line, std::string::npos, std::string::npos); } private: @@ -204,13 +204,13 @@ namespace Aws AWS_LOGSTREAM_DEBUG(PARSER_TAG, "found source profile " << sourceProfileIter->second); profile.SetSourceProfile(sourceProfileIter->second); } - - auto credentialProcessIter = m_profileKeyValuePairs.find(CREDENTIAL_PROCESS_COMMAND); - if (credentialProcessIter != m_profileKeyValuePairs.end()) - { - AWS_LOGSTREAM_DEBUG(PARSER_TAG, "found credential process " << credentialProcessIter->second); - profile.SetCredentialProcess(credentialProcessIter->second); - } + + auto credentialProcessIter = m_profileKeyValuePairs.find(CREDENTIAL_PROCESS_COMMAND); + if (credentialProcessIter != m_profileKeyValuePairs.end()) + { + AWS_LOGSTREAM_DEBUG(PARSER_TAG, "found credential process " << credentialProcessIter->second); + profile.SetCredentialProcess(credentialProcessIter->second); + } profile.SetAllKeyValPairs(m_profileKeyValuePairs); m_foundProfiles[profile.GetName()] = std::move(profile); diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/HttpClientFactory.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/HttpClientFactory.cpp index 41902693b8..a556e39a5d 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/HttpClientFactory.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/HttpClientFactory.cpp @@ -100,7 +100,7 @@ namespace Aws // to error by -Werror) about the unused clientConfiguration parameter. We // prevent that warning with AWS_UNREFERENCED_PARAM. AWS_UNREFERENCED_PARAM(clientConfiguration); - AWS_LOGSTREAM_WARN(HTTP_CLIENT_FACTORY_ALLOCATION_TAG, "SDK was built without an Http implementation, default http client factory can't create an Http client instance."); + AWS_LOGSTREAM_WARN(HTTP_CLIENT_FACTORY_ALLOCATION_TAG, "SDK was built without an Http implementation, default http client factory can't create an Http client instance."); return nullptr; #endif } diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/URI.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/URI.cpp index 399665ae0c..a2239df54b 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/URI.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/URI.cpp @@ -117,8 +117,8 @@ Aws::String URI::URLEncodePathRFC3986(const Aws::String& path) ss << '/'; for(unsigned char c : segment) // alnum results in UB if the value of c is not unsigned char & is not EOF { - // §2.3 unreserved characters - if (StringUtils::IsAlnum(c)) + // §2.3 unreserved characters + if (StringUtils::IsAlnum(c)) { ss << c; continue; @@ -136,7 +136,7 @@ Aws::String URI::URLEncodePathRFC3986(const Aws::String& path) ss << c; break; default: - ss << '%' << std::setfill('0') << std::setw(2) << (int)((unsigned char)c) << std::setw(0); + ss << '%' << std::setfill('0') << std::setw(2) << (int)((unsigned char)c) << std::setw(0); } } } diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/curl/CurlHandleContainer.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/curl/CurlHandleContainer.cpp index ac7d39e7e9..1a965cd795 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/curl/CurlHandleContainer.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/curl/CurlHandleContainer.cpp @@ -147,7 +147,7 @@ void CurlHandleContainer::SetDefaultOptionsOnHandle(CURL* handle) curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, m_enableTcpKeepAlive ? 1L : 0L); curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, m_tcpKeepAliveIntervalMs / 1000); curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, m_tcpKeepAliveIntervalMs / 1000); -#ifdef CURL_HAS_H2 - curl_easy_setopt(handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); -#endif +#ifdef CURL_HAS_H2 + curl_easy_setopt(handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); +#endif } diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp index 1523cbd5f9..2fb9cc9643 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp @@ -572,10 +572,10 @@ std::shared_ptr<HttpResponse> CurlHttpClient::MakeRequest(const std::shared_ptr< curl_easy_setopt(connectionHandle, CURLOPT_FOLLOWLOCATION, 0L); } -#ifdef ENABLE_CURL_LOGGING - curl_easy_setopt(connectionHandle, CURLOPT_VERBOSE, 1); - curl_easy_setopt(connectionHandle, CURLOPT_DEBUGFUNCTION, CurlDebugCallback); -#endif +#ifdef ENABLE_CURL_LOGGING + curl_easy_setopt(connectionHandle, CURLOPT_VERBOSE, 1); + curl_easy_setopt(connectionHandle, CURLOPT_DEBUGFUNCTION, CurlDebugCallback); +#endif if (m_isUsingProxy) { Aws::StringStream ss; @@ -590,11 +590,11 @@ std::shared_ptr<HttpResponse> CurlHttpClient::MakeRequest(const std::shared_ptr< { curl_easy_setopt(connectionHandle, CURLOPT_PROXY_CAINFO, m_proxyCaFile.c_str()); } - if (!m_proxyUserName.empty() || !m_proxyPassword.empty()) - { - curl_easy_setopt(connectionHandle, CURLOPT_PROXYUSERNAME, m_proxyUserName.c_str()); - curl_easy_setopt(connectionHandle, CURLOPT_PROXYPASSWORD, m_proxyPassword.c_str()); - } + if (!m_proxyUserName.empty() || !m_proxyPassword.empty()) + { + curl_easy_setopt(connectionHandle, CURLOPT_PROXYUSERNAME, m_proxyUserName.c_str()); + curl_easy_setopt(connectionHandle, CURLOPT_PROXYPASSWORD, m_proxyPassword.c_str()); + } #ifdef CURL_HAS_TLS_PROXY if (!m_proxySSLCertPath.empty()) { @@ -702,12 +702,12 @@ std::shared_ptr<HttpResponse> CurlHttpClient::MakeRequest(const std::shared_ptr< request->AddRequestMetric(GetHttpClientMetricNameByType(HttpClientMetricsType::SslLatency), static_cast<int64_t>(timep * 1000)); } - const char* ip = nullptr; - auto curlGetInfoResult = curl_easy_getinfo(connectionHandle, CURLINFO_PRIMARY_IP, &ip); // Get the IP address of the remote endpoint - if (curlGetInfoResult == CURLE_OK && ip) - { + const char* ip = nullptr; + auto curlGetInfoResult = curl_easy_getinfo(connectionHandle, CURLINFO_PRIMARY_IP, &ip); // Get the IP address of the remote endpoint + if (curlGetInfoResult == CURLE_OK && ip) + { request->SetResolvedRemoteHost(ip); - } + } if (curlResponseCode != CURLE_OK) { m_curlHandleContainer.DestroyCurlHandle(connectionHandle); diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp index 3f713161a6..24145e4d92 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp @@ -36,13 +36,13 @@ static const char RESOURCE_CLIENT_CONFIGURATION_ALLOCATION_TAG[] = "AWSHttpResou static const char EC2_METADATA_CLIENT_LOG_TAG[] = "EC2MetadataClient"; static const char ECS_CREDENTIALS_CLIENT_LOG_TAG[] = "ECSCredentialsClient"; -namespace Aws -{ - namespace Client - { - Aws::String ComputeUserAgentString(); - } - +namespace Aws +{ + namespace Client + { + Aws::String ComputeUserAgentString(); + } + namespace Internal { static ClientConfiguration MakeDefaultHttpResourceClientConfiguration(const char *logtag) @@ -115,7 +115,7 @@ namespace Aws Aws::Utils::Stream::DefaultResponseStreamFactoryMethod)); request->SetUserAgent(ComputeUserAgentString()); - + if (authToken) { request->SetHeaderValue(Aws::Http::AWS_AUTHORIZATION_HEADER, authToken); diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/monitoring/DefaultMonitoring.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/monitoring/DefaultMonitoring.cpp index 757ca38aad..9953004bc3 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/monitoring/DefaultMonitoring.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/monitoring/DefaultMonitoring.cpp @@ -47,7 +47,7 @@ namespace Aws int retryCount = 0; bool lastAttemptSucceeded = false; bool lastErrorRetryable = false; //doesn't apply if last attempt succeeded. - const Aws::Client::HttpResponseOutcome* outcome = nullptr; + const Aws::Client::HttpResponseOutcome* outcome = nullptr; }; static inline void FillRequiredFieldsToJson(Json::JsonValue& json, @@ -56,15 +56,15 @@ namespace Aws const Aws::String& api, const Aws::String& clientId, const DateTime& timestamp, - int version, - const Aws::String& userAgent) + int version, + const Aws::String& userAgent) { json.WithString("Type", type) .WithString("Service", service) .WithString("Api", api) .WithString("ClientId", clientId.substr(0, CLIENT_ID_LENGTH_LIMIT)) .WithInt64("Timestamp", timestamp.Millis()) - .WithInteger("Version", version) + .WithInteger("Version", version) .WithString("UserAgent", userAgent.substr(0, USER_AGENT_LENGTH_LIMIT)); } @@ -106,30 +106,30 @@ namespace Aws } static inline void FillOptionalApiCallFieldsToJson(Json::JsonValue& json, - const Aws::Http::HttpRequest* request, - const Aws::Client::HttpResponseOutcome& outcome) + const Aws::Http::HttpRequest* request, + const Aws::Client::HttpResponseOutcome& outcome) { if (!request->GetSigningRegion().empty()) { json.WithString("Region", request->GetSigningRegion()); } - if (!outcome.IsSuccess()) - { + if (!outcome.IsSuccess()) + { if (outcome.GetError().GetExceptionName().empty()) // Not Aws Exception - { - json.WithString("FinalSdkExceptionMessage", outcome.GetError().GetMessage().substr(0, ERROR_MESSAGE_LENGTH_LIMIT)); - } - else // Aws Exception - { - json.WithString("FinalAwsException", outcome.GetError().GetExceptionName()) - .WithString("FinalAwsExceptionMessage", outcome.GetError().GetMessage().substr(0, ERROR_MESSAGE_LENGTH_LIMIT)); - } - json.WithInteger("FinalHttpStatusCode", static_cast<int>(outcome.GetError().GetResponseCode())); - } + { + json.WithString("FinalSdkExceptionMessage", outcome.GetError().GetMessage().substr(0, ERROR_MESSAGE_LENGTH_LIMIT)); + } + else // Aws Exception + { + json.WithString("FinalAwsException", outcome.GetError().GetExceptionName()) + .WithString("FinalAwsExceptionMessage", outcome.GetError().GetMessage().substr(0, ERROR_MESSAGE_LENGTH_LIMIT)); + } + json.WithInteger("FinalHttpStatusCode", static_cast<int>(outcome.GetError().GetResponseCode())); + } else - { - json.WithInteger("FinalHttpStatusCode", static_cast<int>(outcome.GetResult()->GetResponseCode())); - } + { + json.WithInteger("FinalHttpStatusCode", static_cast<int>(outcome.GetResult()->GetResponseCode())); + } } static inline void FillOptionalApiAttemptFieldsToJson(Json::JsonValue& json, @@ -164,19 +164,19 @@ namespace Aws { if (outcome.GetError().GetExceptionName().empty()) // Not Aws Exception { - json.WithString("SdkExceptionMessage", outcome.GetError().GetMessage().substr(0, ERROR_MESSAGE_LENGTH_LIMIT)); + json.WithString("SdkExceptionMessage", outcome.GetError().GetMessage().substr(0, ERROR_MESSAGE_LENGTH_LIMIT)); } else // Aws Exception { - json.WithString("AwsException", outcome.GetError().GetExceptionName()) - .WithString("AwsExceptionMessage", outcome.GetError().GetMessage().substr(0, ERROR_MESSAGE_LENGTH_LIMIT)); + json.WithString("AwsException", outcome.GetError().GetExceptionName()) + .WithString("AwsExceptionMessage", outcome.GetError().GetMessage().substr(0, ERROR_MESSAGE_LENGTH_LIMIT)); } - json.WithInteger("HttpStatusCode", static_cast<int>(outcome.GetError().GetResponseCode())); + json.WithInteger("HttpStatusCode", static_cast<int>(outcome.GetError().GetResponseCode())); } else - { - json.WithInteger("HttpStatusCode", static_cast<int>(outcome.GetResult()->GetResponseCode())); - } + { + json.WithInteger("HttpStatusCode", static_cast<int>(outcome.GetResult()->GetResponseCode())); + } // Optional MetricsCollectedFromCore ExportHttpMetricsToJson(json, metricsFromCore.httpClientMetrics, HttpClientMetricsType::AcquireConnectionLatency); @@ -238,11 +238,11 @@ namespace Aws AWS_UNREFERENCED_PARAM(request); AWS_LOGSTREAM_DEBUG(DEFAULT_MONITORING_ALLOC_TAG, "OnRequestFinish Service: " << serviceName << "Request: " << requestName); - DefaultContext* defaultContext = static_cast<DefaultContext*>(context); + DefaultContext* defaultContext = static_cast<DefaultContext*>(context); Aws::Utils::Json::JsonValue json; - FillRequiredFieldsToJson(json, "ApiCall", serviceName, requestName, m_clientId, defaultContext->apiCallStartTime, DEFAULT_MONITORING_VERSION, request->GetUserAgent()); + FillRequiredFieldsToJson(json, "ApiCall", serviceName, requestName, m_clientId, defaultContext->apiCallStartTime, DEFAULT_MONITORING_VERSION, request->GetUserAgent()); FillRequiredApiCallFieldsToJson(json, defaultContext->retryCount + 1, (DateTime::Now() - defaultContext->apiCallStartTime).count(), (!defaultContext->lastAttemptSucceeded && defaultContext->lastErrorRetryable)); - FillOptionalApiCallFieldsToJson(json, request.get(), *(defaultContext->outcome)); + FillOptionalApiCallFieldsToJson(json, request.get(), *(defaultContext->outcome)); Aws::String compactData = json.View().WriteCompact(); m_udp.SendData(reinterpret_cast<const uint8_t*>(compactData.c_str()), static_cast<int>(compactData.size())); AWS_LOGSTREAM_DEBUG(DEFAULT_MONITORING_ALLOC_TAG, "Send API Metrics: \n" << json.View().WriteReadable()); @@ -253,13 +253,13 @@ namespace Aws const std::shared_ptr<const Aws::Http::HttpRequest>& request, const Aws::Client::HttpResponseOutcome& outcome, const CoreMetricsCollection& metricsFromCore, void* context) const { - DefaultContext* defaultContext = static_cast<DefaultContext*>(context); - defaultContext->outcome = &outcome; + DefaultContext* defaultContext = static_cast<DefaultContext*>(context); + defaultContext->outcome = &outcome; defaultContext->lastAttemptSucceeded = outcome.IsSuccess() ? true : false; defaultContext->lastErrorRetryable = (!outcome.IsSuccess() && outcome.GetError().ShouldRetry()) ? true : false; Aws::Utils::Json::JsonValue json; - FillRequiredFieldsToJson(json, "ApiCallAttempt", serviceName, requestName, m_clientId, defaultContext->attemptStartTime, DEFAULT_MONITORING_VERSION, request->GetUserAgent()); - FillRequiredApiAttemptFieldsToJson(json, request->GetUri().GetAuthority(), (DateTime::Now() - defaultContext->attemptStartTime).count()); + FillRequiredFieldsToJson(json, "ApiCallAttempt", serviceName, requestName, m_clientId, defaultContext->attemptStartTime, DEFAULT_MONITORING_VERSION, request->GetUserAgent()); + FillRequiredApiAttemptFieldsToJson(json, request->GetUri().GetAuthority(), (DateTime::Now() - defaultContext->attemptStartTime).count()); FillOptionalApiAttemptFieldsToJson(json, request.get(), outcome, metricsFromCore); Aws::String compactData = json.View().WriteCompact(); AWS_LOGSTREAM_DEBUG(DEFAULT_MONITORING_ALLOC_TAG, "Send Attempt Metrics: \n" << json.View().WriteReadable()); diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/OSVersionInfo.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/OSVersionInfo.cpp index 21597d5629..040173a2e5 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/OSVersionInfo.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/OSVersionInfo.cpp @@ -37,7 +37,7 @@ Aws::String GetSysCommandOutput(const char* command) return Aws::Utils::StringUtils::Trim(outputStr.c_str()); } - return {}; + return {}; } diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/DNS.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/DNS.cpp index f0f01c0357..ce588150e2 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/DNS.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/DNS.cpp @@ -4,7 +4,7 @@ */ #include <aws/core/utils/DNS.h> -#include <aws/core/utils/StringUtils.h> +#include <aws/core/utils/StringUtils.h> namespace Aws { @@ -24,32 +24,32 @@ namespace Aws if (label.size() > 63) return false; - if (!StringUtils::IsAlnum(label.front())) + if (!StringUtils::IsAlnum(label.front())) return false; // '-' is not acceptable as the first character - if (!StringUtils::IsAlnum(label.back())) + if (!StringUtils::IsAlnum(label.back())) return false; // '-' is not acceptable as the last character for (size_t i = 1, e = label.size() - 1; i < e; ++i) { auto c = label[i]; - if (c != '-' && !StringUtils::IsAlnum(c)) + if (c != '-' && !StringUtils::IsAlnum(c)) return false; } return true; } - - bool IsValidHost(const Aws::String& host) - { - // Valid DNS hostnames are composed of valid DNS labels separated by a period. - auto labels = StringUtils::Split(host, '.'); - if (labels.empty()) - { - return false; - } - - return !std::any_of(labels.begin(), labels.end(), [](const Aws::String& label){ return !IsValidDnsLabel(label); }); - } + + bool IsValidHost(const Aws::String& host) + { + // Valid DNS hostnames are composed of valid DNS labels separated by a period. + auto labels = StringUtils::Split(host, '.'); + if (labels.empty()) + { + return false; + } + + return !std::any_of(labels.begin(), labels.end(), [](const Aws::String& label){ return !IsValidDnsLabel(label); }); + } } } diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/FileSystemUtils.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/FileSystemUtils.cpp index e99dae04ce..c47f750960 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/FileSystemUtils.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/FileSystemUtils.cpp @@ -17,7 +17,7 @@ Aws::String PathUtils::GetFileNameFromPathWithoutExt(const Aws::String& path) } if (endPos == 0) // fileName is "." { - return {}; + return {}; } return fileName.substr(0, endPos); @@ -33,7 +33,7 @@ Aws::String PathUtils::GetFileNameFromPathWithExt(const Aws::String& path) size_t startPos = path.find_last_of(Aws::FileSystem::PATH_DELIM); if (startPos == path.size() - 1) { - return {}; + return {}; } if (startPos == std::string::npos) @@ -48,4 +48,4 @@ Aws::String PathUtils::GetFileNameFromPathWithExt(const Aws::String& path) size_t endPos = path.size() - 1; return path.substr(startPos, endPos - startPos + 1); -} +} diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/HashingUtils.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/HashingUtils.cpp index ed4f3bf765..147bddf33e 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/HashingUtils.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/HashingUtils.cpp @@ -5,7 +5,7 @@ #include <aws/core/utils/logging/LogMacros.h> #include <aws/core/utils/HashingUtils.h> -#include <aws/core/utils/StringUtils.h> +#include <aws/core/utils/StringUtils.h> #include <aws/core/utils/base64/Base64.h> #include <aws/core/utils/crypto/Sha256.h> #include <aws/core/utils/crypto/Sha256HMAC.h> @@ -139,16 +139,16 @@ ByteBuffer HashingUtils::CalculateSHA256TreeHash(Aws::IOStream& stream) Aws::String HashingUtils::HexEncode(const ByteBuffer& message) { - Aws::String encoded; - encoded.reserve(2 * message.GetLength()); + Aws::String encoded; + encoded.reserve(2 * message.GetLength()); for (unsigned i = 0; i < message.GetLength(); ++i) { - encoded.push_back("0123456789abcdef"[message[i] >> 4]); - encoded.push_back("0123456789abcdef"[message[i] & 0x0f]); + encoded.push_back("0123456789abcdef"[message[i] >> 4]); + encoded.push_back("0123456789abcdef"[message[i] & 0x0f]); } - return encoded; + return encoded; } ByteBuffer HashingUtils::HexDecode(const Aws::String& str) @@ -176,7 +176,7 @@ ByteBuffer HashingUtils::HexDecode(const Aws::String& str) for (size_t i = readIndex; i < str.length(); i += 2) { - if(!StringUtils::IsAlnum(str[i]) || !StringUtils::IsAlnum(str[i + 1])) + if(!StringUtils::IsAlnum(str[i]) || !StringUtils::IsAlnum(str[i + 1])) { //contains non-hex characters assert(0); @@ -226,7 +226,7 @@ int HashingUtils::HashString(const char* strToHash) if (!strToHash) return 0; - unsigned hash = 0; + unsigned hash = 0; while (char charValue = *strToHash++) { hash = charValue + 31 * hash; diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/StringUtils.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/StringUtils.cpp index 22e3c8e973..e1deb3f046 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/StringUtils.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/StringUtils.cpp @@ -155,8 +155,8 @@ Aws::String StringUtils::URLEncode(const char* unsafe) size_t unsafeLength = strlen(unsafe); for (auto i = unsafe, n = unsafe + unsafeLength; i != n; ++i) { - char c = *i; - if (IsAlnum(c) || c == '-' || c == '_' || c == '.' || c == '~') + char c = *i; + if (IsAlnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { escaped << (char)c; } @@ -209,77 +209,77 @@ Aws::String StringUtils::URLEncode(double unsafe) Aws::String StringUtils::URLDecode(const char* safe) { - Aws::String unescaped; + Aws::String unescaped; - for (; *safe; safe++) + for (; *safe; safe++) { - switch(*safe) + switch(*safe) { - case '%': - { - int hex = 0; - auto ch = *++safe; - if (ch >= '0' && ch <= '9') - { - hex = (ch - '0') * 16; - } - else if (ch >= 'A' && ch <= 'F') - { - hex = (ch - 'A' + 10) * 16; - } - else if (ch >= 'a' && ch <= 'f') - { - hex = (ch - 'a' + 10) * 16; - } - else - { - unescaped.push_back('%'); - if (ch == 0) - { - return unescaped; - } - unescaped.push_back(ch); - break; - } - - ch = *++safe; - if (ch >= '0' && ch <= '9') - { - hex += (ch - '0'); - } - else if (ch >= 'A' && ch <= 'F') - { - hex += (ch - 'A' + 10); - } - else if (ch >= 'a' && ch <= 'f') - { - hex += (ch - 'a' + 10); - } - else - { - unescaped.push_back('%'); - unescaped.push_back(*(safe - 1)); - if (ch == 0) - { - return unescaped; - } - unescaped.push_back(ch); - break; - } - - unescaped.push_back(char(hex)); - break; - } - case '+': - unescaped.push_back(' '); - break; - default: - unescaped.push_back(*safe); - break; + case '%': + { + int hex = 0; + auto ch = *++safe; + if (ch >= '0' && ch <= '9') + { + hex = (ch - '0') * 16; + } + else if (ch >= 'A' && ch <= 'F') + { + hex = (ch - 'A' + 10) * 16; + } + else if (ch >= 'a' && ch <= 'f') + { + hex = (ch - 'a' + 10) * 16; + } + else + { + unescaped.push_back('%'); + if (ch == 0) + { + return unescaped; + } + unescaped.push_back(ch); + break; + } + + ch = *++safe; + if (ch >= '0' && ch <= '9') + { + hex += (ch - '0'); + } + else if (ch >= 'A' && ch <= 'F') + { + hex += (ch - 'A' + 10); + } + else if (ch >= 'a' && ch <= 'f') + { + hex += (ch - 'a' + 10); + } + else + { + unescaped.push_back('%'); + unescaped.push_back(*(safe - 1)); + if (ch == 0) + { + return unescaped; + } + unescaped.push_back(ch); + break; + } + + unescaped.push_back(char(hex)); + break; + } + case '+': + unescaped.push_back(' '); + break; + default: + unescaped.push_back(*safe); + break; } } - return unescaped; + return unescaped; } static bool IsSpace(int ch) diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/UUID.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/UUID.cpp index b1915ba144..862f3eacdd 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/UUID.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/UUID.cpp @@ -14,7 +14,7 @@ namespace Aws { namespace Utils { - static const size_t UUID_STR_SIZE = 0x24u; // 36 characters + static const size_t UUID_STR_SIZE = 0x24u; // 36 characters static const size_t VERSION_LOCATION = 0x06u; static const size_t VARIANT_LOCATION = 0x08u; static const unsigned char VERSION = 0x40u; @@ -22,12 +22,12 @@ namespace Aws static const unsigned char VARIANT = 0x80u; static const unsigned char VARIANT_MASK = 0x3Fu; - static void hexify(Aws::String& ss, const unsigned char* toWrite, size_t min, size_t max) + static void hexify(Aws::String& ss, const unsigned char* toWrite, size_t min, size_t max) { for (size_t i = min; i < max; ++i) { - ss.push_back("0123456789ABCDEF"[toWrite[i] >> 4]); - ss.push_back("0123456789ABCDEF"[toWrite[i] & 0x0F]); + ss.push_back("0123456789ABCDEF"[toWrite[i] >> 4]); + ss.push_back("0123456789ABCDEF"[toWrite[i] & 0x0F]); } } @@ -50,23 +50,23 @@ namespace Aws UUID::operator Aws::String() const { - Aws::String ss; - ss.reserve(UUID_STR_SIZE); - hexify(ss, m_uuid, 0, 4); - ss.push_back('-'); + Aws::String ss; + ss.reserve(UUID_STR_SIZE); + hexify(ss, m_uuid, 0, 4); + ss.push_back('-'); - hexify(ss, m_uuid, 4, 6); - ss.push_back('-'); + hexify(ss, m_uuid, 4, 6); + ss.push_back('-'); - hexify(ss, m_uuid, 6, 8); - ss.push_back('-'); + hexify(ss, m_uuid, 6, 8); + ss.push_back('-'); - hexify(ss, m_uuid, 8, 10); - ss.push_back('-'); + hexify(ss, m_uuid, 8, 10); + ss.push_back('-'); - hexify(ss, m_uuid, 10, 16); + hexify(ss, m_uuid, 10, 16); - return ss; + return ss; } UUID UUID::RandomUUID() diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/base64/Base64.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/base64/Base64.cpp index 9f92eae92a..2103d6d5a6 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/base64/Base64.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/base64/Base64.cpp @@ -122,8 +122,8 @@ Aws::Utils::ByteBuffer Base64::Decode(const Aws::String& str) const size_t Base64::CalculateBase64DecodedLength(const Aws::String& b64input) { - const size_t len = b64input.length(); - if(len < 2) + const size_t len = b64input.length(); + if(len < 2) { return 0; } diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventHeader.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventHeader.cpp index 6b5bf41441..c3c989bedb 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventHeader.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventHeader.cpp @@ -1,107 +1,107 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/core/utils/event/EventHeader.h> -#include <aws/core/utils/HashingUtils.h> - -namespace Aws -{ - namespace Utils - { - namespace Event - { - static const int HASH_BOOL_TRUE = HashingUtils::HashString("BOOL_TRUE"); - static const int HASH_BOOL_FALSE = HashingUtils::HashString("BOOL_FALSE"); - static const int HASH_BYTE = HashingUtils::HashString("BYTE"); - static const int HASH_INT16 = HashingUtils::HashString("INT16"); - static const int HASH_INT32 = HashingUtils::HashString("INT32"); - static const int HASH_INT64 = HashingUtils::HashString("INT64"); - static const int HASH_BYTE_BUF = HashingUtils::HashString("BYTE_BUFFER"); - static const int HASH_STRING = HashingUtils::HashString("STRING"); - static const int HASH_TIMESTAMP = HashingUtils::HashString("TIMESTAMP"); - static const int HASH_UUID = HashingUtils::HashString("UUID"); - - EventHeaderValue::EventHeaderType EventHeaderValue::GetEventHeaderTypeForName(const Aws::String& name) - { - int hashCode = Aws::Utils::HashingUtils::HashString(name.c_str()); - if (hashCode == HASH_BOOL_TRUE) - { - return EventHeaderType::BOOL_TRUE; - } - else if (hashCode == HASH_BOOL_FALSE) - { - return EventHeaderType::BOOL_FALSE; - } - else if (hashCode == HASH_BYTE) - { - return EventHeaderType::BYTE; - } - else if (hashCode == HASH_INT16) - { - return EventHeaderType::INT16; - } - else if (hashCode == HASH_INT32) - { - return EventHeaderType::INT32; - } - else if (hashCode == HASH_INT64) - { - return EventHeaderType::INT64; - } - else if (hashCode == HASH_BYTE_BUF) - { - return EventHeaderType::BYTE_BUF; - } - else if (hashCode == HASH_STRING) - { - return EventHeaderType::STRING; - } - else if (hashCode == HASH_TIMESTAMP) - { - return EventHeaderType::TIMESTAMP; - } - else if (hashCode == HASH_UUID) - { - return EventHeaderType::UUID; - } - else - { - return EventHeaderType::UNKNOWN; - } - } - - Aws::String EventHeaderValue::GetNameForEventHeaderType(EventHeaderType value) - { - switch (value) - { - case EventHeaderType::BOOL_TRUE: - return "BOOL_TRUE"; - case EventHeaderType::BOOL_FALSE: - return "BOOL_FALSE"; - case EventHeaderType::BYTE: - return "BYTE"; - case EventHeaderType::INT16: - return "INT16"; - case EventHeaderType::INT32: - return "INT32"; - case EventHeaderType::INT64: - return "INT64"; - case EventHeaderType::BYTE_BUF: - return "BYTE_BUF"; - case EventHeaderType::STRING: - return "STRING"; - case EventHeaderType::TIMESTAMP: - return "TIMESTAMP"; - case EventHeaderType::UUID: - return "UUID"; - default: - return "UNKNOWN"; - } - } - - } - } -} - + */ + +#include <aws/core/utils/event/EventHeader.h> +#include <aws/core/utils/HashingUtils.h> + +namespace Aws +{ + namespace Utils + { + namespace Event + { + static const int HASH_BOOL_TRUE = HashingUtils::HashString("BOOL_TRUE"); + static const int HASH_BOOL_FALSE = HashingUtils::HashString("BOOL_FALSE"); + static const int HASH_BYTE = HashingUtils::HashString("BYTE"); + static const int HASH_INT16 = HashingUtils::HashString("INT16"); + static const int HASH_INT32 = HashingUtils::HashString("INT32"); + static const int HASH_INT64 = HashingUtils::HashString("INT64"); + static const int HASH_BYTE_BUF = HashingUtils::HashString("BYTE_BUFFER"); + static const int HASH_STRING = HashingUtils::HashString("STRING"); + static const int HASH_TIMESTAMP = HashingUtils::HashString("TIMESTAMP"); + static const int HASH_UUID = HashingUtils::HashString("UUID"); + + EventHeaderValue::EventHeaderType EventHeaderValue::GetEventHeaderTypeForName(const Aws::String& name) + { + int hashCode = Aws::Utils::HashingUtils::HashString(name.c_str()); + if (hashCode == HASH_BOOL_TRUE) + { + return EventHeaderType::BOOL_TRUE; + } + else if (hashCode == HASH_BOOL_FALSE) + { + return EventHeaderType::BOOL_FALSE; + } + else if (hashCode == HASH_BYTE) + { + return EventHeaderType::BYTE; + } + else if (hashCode == HASH_INT16) + { + return EventHeaderType::INT16; + } + else if (hashCode == HASH_INT32) + { + return EventHeaderType::INT32; + } + else if (hashCode == HASH_INT64) + { + return EventHeaderType::INT64; + } + else if (hashCode == HASH_BYTE_BUF) + { + return EventHeaderType::BYTE_BUF; + } + else if (hashCode == HASH_STRING) + { + return EventHeaderType::STRING; + } + else if (hashCode == HASH_TIMESTAMP) + { + return EventHeaderType::TIMESTAMP; + } + else if (hashCode == HASH_UUID) + { + return EventHeaderType::UUID; + } + else + { + return EventHeaderType::UNKNOWN; + } + } + + Aws::String EventHeaderValue::GetNameForEventHeaderType(EventHeaderType value) + { + switch (value) + { + case EventHeaderType::BOOL_TRUE: + return "BOOL_TRUE"; + case EventHeaderType::BOOL_FALSE: + return "BOOL_FALSE"; + case EventHeaderType::BYTE: + return "BYTE"; + case EventHeaderType::INT16: + return "INT16"; + case EventHeaderType::INT32: + return "INT32"; + case EventHeaderType::INT64: + return "INT64"; + case EventHeaderType::BYTE_BUF: + return "BYTE_BUF"; + case EventHeaderType::STRING: + return "STRING"; + case EventHeaderType::TIMESTAMP: + return "TIMESTAMP"; + case EventHeaderType::UUID: + return "UUID"; + default: + return "UNKNOWN"; + } + } + + } + } +} + diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventMessage.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventMessage.cpp index 811d116223..de8b904775 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventMessage.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventMessage.cpp @@ -1,70 +1,70 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/core/utils/event/EventMessage.h> -#include <aws/core/utils/HashingUtils.h> -#include <algorithm> -#include <iterator> - -namespace Aws -{ - namespace Utils - { - namespace Event - { - const char EVENT_TYPE_HEADER[] = ":event-type"; - const char CONTENT_TYPE_HEADER[] = ":content-type"; - const char MESSAGE_TYPE_HEADER[] = ":message-type"; - const char ERROR_CODE_HEADER[] = ":error-code"; - const char ERROR_MESSAGE_HEADER[] = ":error-message"; + */ + +#include <aws/core/utils/event/EventMessage.h> +#include <aws/core/utils/HashingUtils.h> +#include <algorithm> +#include <iterator> + +namespace Aws +{ + namespace Utils + { + namespace Event + { + const char EVENT_TYPE_HEADER[] = ":event-type"; + const char CONTENT_TYPE_HEADER[] = ":content-type"; + const char MESSAGE_TYPE_HEADER[] = ":message-type"; + const char ERROR_CODE_HEADER[] = ":error-code"; + const char ERROR_MESSAGE_HEADER[] = ":error-message"; const char EXCEPTION_TYPE_HEADER[] = ":exception-type"; - - static const int EVENT_HASH = HashingUtils::HashString("event"); - static const int ERROR_HASH = HashingUtils::HashString("error"); + + static const int EVENT_HASH = HashingUtils::HashString("event"); + static const int ERROR_HASH = HashingUtils::HashString("error"); static const int EXCEPTION_HASH = HashingUtils::HashString("exception"); - + static const int CONTENT_TYPE_APPLICATION_OCTET_STREAM_HASH = HashingUtils::HashString("application/octet-stream"); static const int CONTENT_TYPE_APPLICATION_JSON_HASH = HashingUtils::HashString("application/json"); static const int CONTENT_TYPE_TEXT_PLAIN_HASH = HashingUtils::HashString("text/plain"); - Message::MessageType Message::GetMessageTypeForName(const Aws::String& name) - { - int hashCode = Aws::Utils::HashingUtils::HashString(name.c_str()); - if (hashCode == EVENT_HASH) - { - return MessageType::EVENT; - } - else if (hashCode == ERROR_HASH) - { - return MessageType::REQUEST_LEVEL_ERROR; - } + Message::MessageType Message::GetMessageTypeForName(const Aws::String& name) + { + int hashCode = Aws::Utils::HashingUtils::HashString(name.c_str()); + if (hashCode == EVENT_HASH) + { + return MessageType::EVENT; + } + else if (hashCode == ERROR_HASH) + { + return MessageType::REQUEST_LEVEL_ERROR; + } else if (hashCode == EXCEPTION_HASH) { return MessageType::REQUEST_LEVEL_EXCEPTION; } - else - { - return MessageType::UNKNOWN; - } - } - - Aws::String Message::GetNameForMessageType(MessageType value) - { - switch (value) - { - case MessageType::EVENT: - return "event"; - case MessageType::REQUEST_LEVEL_ERROR: - return "error"; + else + { + return MessageType::UNKNOWN; + } + } + + Aws::String Message::GetNameForMessageType(MessageType value) + { + switch (value) + { + case MessageType::EVENT: + return "event"; + case MessageType::REQUEST_LEVEL_ERROR: + return "error"; case MessageType::REQUEST_LEVEL_EXCEPTION: return "exception"; - default: - return "unknown"; - } - } - + default: + return "unknown"; + } + } + Message::ContentType Message::GetContentTypeForName(const Aws::String& name) { int hashCode = Aws::Utils::HashingUtils::HashString(name.c_str()); @@ -101,32 +101,32 @@ namespace Aws } } - void Message::Reset() - { - m_totalLength = 0; - m_headersLength = 0; - m_payloadLength = 0; - - m_eventHeaders.clear(); - m_eventPayload.clear(); - } - + void Message::Reset() + { + m_totalLength = 0; + m_headersLength = 0; + m_payloadLength = 0; + + m_eventHeaders.clear(); + m_eventPayload.clear(); + } + void Message::WriteEventPayload(const unsigned char* data, size_t length) { std::copy(data, data + length, std::back_inserter(m_eventPayload)); } - void Message::WriteEventPayload(const Aws::Vector<unsigned char>& bits) - { - std::copy(bits.cbegin(), bits.cend(), std::back_inserter(m_eventPayload)); - } - + void Message::WriteEventPayload(const Aws::Vector<unsigned char>& bits) + { + std::copy(bits.cbegin(), bits.cend(), std::back_inserter(m_eventPayload)); + } + void Message::WriteEventPayload(const Aws::String& bits) { std::copy(bits.cbegin(), bits.cend(), std::back_inserter(m_eventPayload)); } - } // namespace Event - } // namespace Utils -} // namespace Aws - + } // namespace Event + } // namespace Utils +} // namespace Aws + diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamBuf.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamBuf.cpp index eb740d9ac0..6a1766bb9f 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamBuf.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamBuf.cpp @@ -1,147 +1,147 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/core/utils/event/EventStreamBuf.h> -#include <cassert> - -namespace Aws -{ - namespace Utils - { - namespace Event - { + */ +#include <aws/core/utils/event/EventStreamBuf.h> +#include <cassert> + +namespace Aws +{ + namespace Utils + { + namespace Event + { const size_t DEFAULT_BUF_SIZE = 1024; - EventStreamBuf::EventStreamBuf(EventStreamDecoder& decoder, size_t bufferLength) : - m_byteBuffer(bufferLength), - m_bufferLength(bufferLength), - m_decoder(decoder) - { - assert(decoder); - char* begin = reinterpret_cast<char*>(m_byteBuffer.GetUnderlyingData()); - char* end = begin + bufferLength - 1; - - setp(begin, end); - setg(begin, begin, begin); - } - - EventStreamBuf::~EventStreamBuf() - { - if (m_decoder) - { - writeToDecoder(); - } - } - - void EventStreamBuf::writeToDecoder() - { - if (pptr() > pbase()) - { - size_t length = static_cast<size_t>(pptr() - pbase()); - m_decoder.Pump(m_byteBuffer, length); - - if (!m_decoder) - { - m_err.write(reinterpret_cast<char*>(m_byteBuffer.GetUnderlyingData()), length); - } - else - { - pbump(-static_cast<int>(length)); - } - } - } - - std::streampos EventStreamBuf::seekoff(std::streamoff off, std::ios_base::seekdir dir, std::ios_base::openmode which) - { - if (dir == std::ios_base::beg) - { - return seekpos(off, which); - } - else if (dir == std::ios_base::end) - { - return seekpos(m_bufferLength - 1 - off, which); - } - else if (dir == std::ios_base::cur) - { - if (which == std::ios_base::in) - { - return seekpos((gptr() - (char*)m_byteBuffer.GetUnderlyingData()) + off, which); - } - if (which == std::ios_base::out) - { - return seekpos((pptr() - (char*)m_byteBuffer.GetUnderlyingData()) + off, which); - } - } - - return std::streamoff(-1); - } - - std::streampos EventStreamBuf::seekpos(std::streampos pos, std::ios_base::openmode which) - { - assert(static_cast<size_t>(pos) <= m_bufferLength); - if (static_cast<size_t>(pos) > m_bufferLength) - { - return std::streampos(std::streamoff(-1)); - } - - if (which == std::ios_base::in) - { - m_err.seekg(pos); - return m_err.tellg(); - } - - if (which == std::ios_base::out) - { - return pos; - } - - return std::streampos(std::streamoff(-1)); - } - - int EventStreamBuf::underflow() - { - if (!m_err || m_err.eof() || m_decoder) - { - return std::char_traits<char>::eof(); - } - - m_err.flush(); - m_err.read(reinterpret_cast<char*>(m_byteBuffer.GetUnderlyingData()), m_byteBuffer.GetLength()); - - char* begin = reinterpret_cast<char*>(m_byteBuffer.GetUnderlyingData()); - setg(begin, begin, begin + m_err.gcount()); - return std::char_traits<char>::to_int_type(*gptr()); - } - - int EventStreamBuf::overflow(int ch) - { - auto eof = std::char_traits<char>::eof(); - - if (m_decoder) - { - if (ch != eof) - { - *pptr() = (char)ch; - pbump(1); - } - - writeToDecoder(); - return ch; - } - - return eof; - } - - int EventStreamBuf::sync() - { - if (m_decoder) - { - writeToDecoder(); - } - - return 0; - } - } - } -} + EventStreamBuf::EventStreamBuf(EventStreamDecoder& decoder, size_t bufferLength) : + m_byteBuffer(bufferLength), + m_bufferLength(bufferLength), + m_decoder(decoder) + { + assert(decoder); + char* begin = reinterpret_cast<char*>(m_byteBuffer.GetUnderlyingData()); + char* end = begin + bufferLength - 1; + + setp(begin, end); + setg(begin, begin, begin); + } + + EventStreamBuf::~EventStreamBuf() + { + if (m_decoder) + { + writeToDecoder(); + } + } + + void EventStreamBuf::writeToDecoder() + { + if (pptr() > pbase()) + { + size_t length = static_cast<size_t>(pptr() - pbase()); + m_decoder.Pump(m_byteBuffer, length); + + if (!m_decoder) + { + m_err.write(reinterpret_cast<char*>(m_byteBuffer.GetUnderlyingData()), length); + } + else + { + pbump(-static_cast<int>(length)); + } + } + } + + std::streampos EventStreamBuf::seekoff(std::streamoff off, std::ios_base::seekdir dir, std::ios_base::openmode which) + { + if (dir == std::ios_base::beg) + { + return seekpos(off, which); + } + else if (dir == std::ios_base::end) + { + return seekpos(m_bufferLength - 1 - off, which); + } + else if (dir == std::ios_base::cur) + { + if (which == std::ios_base::in) + { + return seekpos((gptr() - (char*)m_byteBuffer.GetUnderlyingData()) + off, which); + } + if (which == std::ios_base::out) + { + return seekpos((pptr() - (char*)m_byteBuffer.GetUnderlyingData()) + off, which); + } + } + + return std::streamoff(-1); + } + + std::streampos EventStreamBuf::seekpos(std::streampos pos, std::ios_base::openmode which) + { + assert(static_cast<size_t>(pos) <= m_bufferLength); + if (static_cast<size_t>(pos) > m_bufferLength) + { + return std::streampos(std::streamoff(-1)); + } + + if (which == std::ios_base::in) + { + m_err.seekg(pos); + return m_err.tellg(); + } + + if (which == std::ios_base::out) + { + return pos; + } + + return std::streampos(std::streamoff(-1)); + } + + int EventStreamBuf::underflow() + { + if (!m_err || m_err.eof() || m_decoder) + { + return std::char_traits<char>::eof(); + } + + m_err.flush(); + m_err.read(reinterpret_cast<char*>(m_byteBuffer.GetUnderlyingData()), m_byteBuffer.GetLength()); + + char* begin = reinterpret_cast<char*>(m_byteBuffer.GetUnderlyingData()); + setg(begin, begin, begin + m_err.gcount()); + return std::char_traits<char>::to_int_type(*gptr()); + } + + int EventStreamBuf::overflow(int ch) + { + auto eof = std::char_traits<char>::eof(); + + if (m_decoder) + { + if (ch != eof) + { + *pptr() = (char)ch; + pbump(1); + } + + writeToDecoder(); + return ch; + } + + return eof; + } + + int EventStreamBuf::sync() + { + if (m_decoder) + { + writeToDecoder(); + } + + return 0; + } + } + } +} diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamDecoder.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamDecoder.cpp index eeabf140b3..f70a6c88f6 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamDecoder.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamDecoder.cpp @@ -1,170 +1,170 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> -#include <aws/core/utils/event/EventHeader.h> -#include <aws/core/utils/event/EventMessage.h> -#include <aws/core/utils/event/EventStreamDecoder.h> -#include <aws/core/utils/logging/LogMacros.h> -#include <aws/core/utils/UnreferencedParam.h> + */ + +#include <aws/common/common.h> +#include <aws/core/utils/event/EventHeader.h> +#include <aws/core/utils/event/EventMessage.h> +#include <aws/core/utils/event/EventStreamDecoder.h> +#include <aws/core/utils/logging/LogMacros.h> +#include <aws/core/utils/UnreferencedParam.h> #include <aws/core/utils/memory/AWSMemory.h> - -namespace Aws -{ - namespace Utils - { - namespace Event - { - static const char EVENT_STREAM_DECODER_CLASS_TAG[] = "Aws::Utils::Event::EventStreamDecoder"; - - EventStreamDecoder::EventStreamDecoder(EventStreamHandler* handler) : m_eventStreamHandler(handler) - { + +namespace Aws +{ + namespace Utils + { + namespace Event + { + static const char EVENT_STREAM_DECODER_CLASS_TAG[] = "Aws::Utils::Event::EventStreamDecoder"; + + EventStreamDecoder::EventStreamDecoder(EventStreamHandler* handler) : m_eventStreamHandler(handler) + { aws_event_stream_streaming_decoder_init(&m_decoder, get_aws_allocator(), - onPayloadSegment, - onPreludeReceived, - onHeaderReceived, - onError, - (void*)handler); - } - - EventStreamDecoder::~EventStreamDecoder() - { - aws_event_stream_streaming_decoder_clean_up(&m_decoder); - } - - void EventStreamDecoder::Pump(const ByteBuffer& data) - { - Pump(data, data.GetLength()); - } - - void EventStreamDecoder::Pump(const ByteBuffer& data, size_t length) - { - aws_byte_buf dataBuf = aws_byte_buf_from_array(static_cast<uint8_t*>(data.GetUnderlyingData()), length); - aws_event_stream_streaming_decoder_pump(&m_decoder, &dataBuf); - } - - void EventStreamDecoder::Reset() - { - m_eventStreamHandler->Reset(); - } - - void EventStreamDecoder::ResetEventStreamHandler(EventStreamHandler* handler) - { + onPayloadSegment, + onPreludeReceived, + onHeaderReceived, + onError, + (void*)handler); + } + + EventStreamDecoder::~EventStreamDecoder() + { + aws_event_stream_streaming_decoder_clean_up(&m_decoder); + } + + void EventStreamDecoder::Pump(const ByteBuffer& data) + { + Pump(data, data.GetLength()); + } + + void EventStreamDecoder::Pump(const ByteBuffer& data, size_t length) + { + aws_byte_buf dataBuf = aws_byte_buf_from_array(static_cast<uint8_t*>(data.GetUnderlyingData()), length); + aws_event_stream_streaming_decoder_pump(&m_decoder, &dataBuf); + } + + void EventStreamDecoder::Reset() + { + m_eventStreamHandler->Reset(); + } + + void EventStreamDecoder::ResetEventStreamHandler(EventStreamHandler* handler) + { aws_event_stream_streaming_decoder_init(&m_decoder, get_aws_allocator(), - onPayloadSegment, - onPreludeReceived, - onHeaderReceived, - onError, - reinterpret_cast<void *>(handler)); - } - - void EventStreamDecoder::onPayloadSegment( - aws_event_stream_streaming_decoder* decoder, - aws_byte_buf* payload, - int8_t isFinalSegment, - void* context) - { - AWS_UNREFERENCED_PARAM(decoder); - auto handler = static_cast<EventStreamHandler*>(context); - assert(handler); - if (!handler) - { - AWS_LOGSTREAM_ERROR(EVENT_STREAM_DECODER_CLASS_TAG, "Payload received, but decoder encountered internal errors before." - "ErrorCode: " << EventStreamErrorsMapper::GetNameForError(handler->GetInternalError()) << ", " - "ErrorMessage: " << handler->GetEventPayloadAsString()); - return; - } - handler->WriteMessageEventPayload(static_cast<unsigned char*>(payload->buffer), payload->len); - - // Complete payload received - if (isFinalSegment == 1) - { - assert(handler->IsMessageCompleted()); - handler->OnEvent(); - handler->Reset(); - } - } - - void EventStreamDecoder::onPreludeReceived( - aws_event_stream_streaming_decoder* decoder, - aws_event_stream_message_prelude* prelude, - void* context) - { - AWS_UNREFERENCED_PARAM(decoder); - auto handler = static_cast<EventStreamHandler*>(context); - handler->Reset(); - - //Encounter internal error in prelude received. - //This error will be handled by OnError callback function later. - if (prelude->total_len < prelude->headers_len + 16) - { - return; - } - handler->SetMessageMetadata(prelude->total_len, prelude->headers_len, - prelude->total_len - prelude->headers_len - 4/*total byte-length*/ - 4/*headers byte-length*/ - 4/*prelude crc*/ - 4/*message crc*/); - AWS_LOGSTREAM_TRACE(EVENT_STREAM_DECODER_CLASS_TAG, "Message received, the expected length of the message is: " << prelude->total_len << - " bytes, and the expected length of the header is: " << prelude->headers_len << " bytes"); - - //Handle empty message - //if (handler->m_message.GetHeadersLength() == 0 && handler->m_message.GetPayloadLength() == 0) - if (handler->IsMessageCompleted()) - { - handler->OnEvent(); - handler->Reset(); - } - } - - void EventStreamDecoder::onHeaderReceived( - aws_event_stream_streaming_decoder* decoder, - aws_event_stream_message_prelude* prelude, - aws_event_stream_header_value_pair* header, - void* context) - { - AWS_UNREFERENCED_PARAM(decoder); - AWS_UNREFERENCED_PARAM(prelude); - auto handler = static_cast<EventStreamHandler*>(context); - assert(handler); - if (!handler) - { - AWS_LOGSTREAM_ERROR(EVENT_STREAM_DECODER_CLASS_TAG, "Payload received, but decoder encountered internal errors before." - "ErrorCode: " << EventStreamErrorsMapper::GetNameForError(handler->GetInternalError()) << ", " - "ErrorMessage: " << handler->GetEventPayloadAsString()); - return; - } - - // The length of a header = 1 byte (to represent the length of header name) + length of header name + 1 byte (to represent header type) - // + 2 bytes (to represent length of header value) + length of header value - handler->InsertMessageEventHeader(Aws::String(header->header_name, header->header_name_len), - 1 + header->header_name_len + 1 + 2 + header->header_value_len, EventHeaderValue(header)); - - // Handle messages only have headers, but without payload. - //if (handler->m_message.GetHeadersLength() == handler->m_headersBytesReceived() && handler->m_message.GetPayloadLength() == 0) - if (handler->IsMessageCompleted()) - { - handler->OnEvent(); - handler->Reset(); - } - } - - void EventStreamDecoder::onError( - aws_event_stream_streaming_decoder* decoder, - aws_event_stream_message_prelude* prelude, - int error_code, - const char* message, - void* context) - { - AWS_UNREFERENCED_PARAM(decoder); - AWS_UNREFERENCED_PARAM(prelude); - auto handler = static_cast<EventStreamHandler*>(context); - handler->SetFailure(); - handler->SetInternalError(error_code); - handler->WriteMessageEventPayload(reinterpret_cast<const unsigned char*>(message), strlen(message)); - handler->OnEvent(); - } - } // namespace Event - } // namespace Utils -} // namespace Aws - + onPayloadSegment, + onPreludeReceived, + onHeaderReceived, + onError, + reinterpret_cast<void *>(handler)); + } + + void EventStreamDecoder::onPayloadSegment( + aws_event_stream_streaming_decoder* decoder, + aws_byte_buf* payload, + int8_t isFinalSegment, + void* context) + { + AWS_UNREFERENCED_PARAM(decoder); + auto handler = static_cast<EventStreamHandler*>(context); + assert(handler); + if (!handler) + { + AWS_LOGSTREAM_ERROR(EVENT_STREAM_DECODER_CLASS_TAG, "Payload received, but decoder encountered internal errors before." + "ErrorCode: " << EventStreamErrorsMapper::GetNameForError(handler->GetInternalError()) << ", " + "ErrorMessage: " << handler->GetEventPayloadAsString()); + return; + } + handler->WriteMessageEventPayload(static_cast<unsigned char*>(payload->buffer), payload->len); + + // Complete payload received + if (isFinalSegment == 1) + { + assert(handler->IsMessageCompleted()); + handler->OnEvent(); + handler->Reset(); + } + } + + void EventStreamDecoder::onPreludeReceived( + aws_event_stream_streaming_decoder* decoder, + aws_event_stream_message_prelude* prelude, + void* context) + { + AWS_UNREFERENCED_PARAM(decoder); + auto handler = static_cast<EventStreamHandler*>(context); + handler->Reset(); + + //Encounter internal error in prelude received. + //This error will be handled by OnError callback function later. + if (prelude->total_len < prelude->headers_len + 16) + { + return; + } + handler->SetMessageMetadata(prelude->total_len, prelude->headers_len, + prelude->total_len - prelude->headers_len - 4/*total byte-length*/ - 4/*headers byte-length*/ - 4/*prelude crc*/ - 4/*message crc*/); + AWS_LOGSTREAM_TRACE(EVENT_STREAM_DECODER_CLASS_TAG, "Message received, the expected length of the message is: " << prelude->total_len << + " bytes, and the expected length of the header is: " << prelude->headers_len << " bytes"); + + //Handle empty message + //if (handler->m_message.GetHeadersLength() == 0 && handler->m_message.GetPayloadLength() == 0) + if (handler->IsMessageCompleted()) + { + handler->OnEvent(); + handler->Reset(); + } + } + + void EventStreamDecoder::onHeaderReceived( + aws_event_stream_streaming_decoder* decoder, + aws_event_stream_message_prelude* prelude, + aws_event_stream_header_value_pair* header, + void* context) + { + AWS_UNREFERENCED_PARAM(decoder); + AWS_UNREFERENCED_PARAM(prelude); + auto handler = static_cast<EventStreamHandler*>(context); + assert(handler); + if (!handler) + { + AWS_LOGSTREAM_ERROR(EVENT_STREAM_DECODER_CLASS_TAG, "Payload received, but decoder encountered internal errors before." + "ErrorCode: " << EventStreamErrorsMapper::GetNameForError(handler->GetInternalError()) << ", " + "ErrorMessage: " << handler->GetEventPayloadAsString()); + return; + } + + // The length of a header = 1 byte (to represent the length of header name) + length of header name + 1 byte (to represent header type) + // + 2 bytes (to represent length of header value) + length of header value + handler->InsertMessageEventHeader(Aws::String(header->header_name, header->header_name_len), + 1 + header->header_name_len + 1 + 2 + header->header_value_len, EventHeaderValue(header)); + + // Handle messages only have headers, but without payload. + //if (handler->m_message.GetHeadersLength() == handler->m_headersBytesReceived() && handler->m_message.GetPayloadLength() == 0) + if (handler->IsMessageCompleted()) + { + handler->OnEvent(); + handler->Reset(); + } + } + + void EventStreamDecoder::onError( + aws_event_stream_streaming_decoder* decoder, + aws_event_stream_message_prelude* prelude, + int error_code, + const char* message, + void* context) + { + AWS_UNREFERENCED_PARAM(decoder); + AWS_UNREFERENCED_PARAM(prelude); + auto handler = static_cast<EventStreamHandler*>(context); + handler->SetFailure(); + handler->SetInternalError(error_code); + handler->WriteMessageEventPayload(reinterpret_cast<const unsigned char*>(message), strlen(message)); + handler->OnEvent(); + } + } // namespace Event + } // namespace Utils +} // namespace Aws + diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamEncoder.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamEncoder.cpp index c7491a3e26..ef7104e839 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamEncoder.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamEncoder.cpp @@ -1,162 +1,162 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/core/utils/event/EventHeader.h> -#include <aws/core/utils/event/EventMessage.h> -#include <aws/core/utils/event/EventStreamEncoder.h> -#include <aws/core/utils/logging/LogMacros.h> -#include <aws/core/auth/AWSAuthSigner.h> -#include <aws/common/byte_order.h> + */ + +#include <aws/core/utils/event/EventHeader.h> +#include <aws/core/utils/event/EventMessage.h> +#include <aws/core/utils/event/EventStreamEncoder.h> +#include <aws/core/utils/logging/LogMacros.h> +#include <aws/core/auth/AWSAuthSigner.h> +#include <aws/common/byte_order.h> #include <aws/core/utils/memory/AWSMemory.h> - -#include <cassert> - -namespace Aws -{ - namespace Utils - { - namespace Event - { - static const char TAG[] = "EventStreamEncoder"; - - static void EncodeHeaders(const Aws::Utils::Event::Message& msg, aws_array_list* headers) - { + +#include <cassert> + +namespace Aws +{ + namespace Utils + { + namespace Event + { + static const char TAG[] = "EventStreamEncoder"; + + static void EncodeHeaders(const Aws::Utils::Event::Message& msg, aws_array_list* headers) + { aws_array_list_init_dynamic(headers, get_aws_allocator(), msg.GetEventHeaders().size(), sizeof(aws_event_stream_header_value_pair)); - for (auto&& header : msg.GetEventHeaders()) - { - const uint8_t headerKeyLen = static_cast<uint8_t>(header.first.length()); - switch(header.second.GetType()) - { - case EventHeaderValue::EventHeaderType::BOOL_TRUE: - case EventHeaderValue::EventHeaderType::BOOL_FALSE: - aws_event_stream_add_bool_header(headers, header.first.c_str(), headerKeyLen, header.second.GetEventHeaderValueAsBoolean()); - break; - case EventHeaderValue::EventHeaderType::BYTE: - aws_event_stream_add_bool_header(headers, header.first.c_str(), headerKeyLen, header.second.GetEventHeaderValueAsByte()); - break; - case EventHeaderValue::EventHeaderType::INT16: + for (auto&& header : msg.GetEventHeaders()) + { + const uint8_t headerKeyLen = static_cast<uint8_t>(header.first.length()); + switch(header.second.GetType()) + { + case EventHeaderValue::EventHeaderType::BOOL_TRUE: + case EventHeaderValue::EventHeaderType::BOOL_FALSE: + aws_event_stream_add_bool_header(headers, header.first.c_str(), headerKeyLen, header.second.GetEventHeaderValueAsBoolean()); + break; + case EventHeaderValue::EventHeaderType::BYTE: + aws_event_stream_add_bool_header(headers, header.first.c_str(), headerKeyLen, header.second.GetEventHeaderValueAsByte()); + break; + case EventHeaderValue::EventHeaderType::INT16: aws_event_stream_add_int16_header(headers, header.first.c_str(), headerKeyLen, header.second.GetEventHeaderValueAsInt16()); - break; - case EventHeaderValue::EventHeaderType::INT32: + break; + case EventHeaderValue::EventHeaderType::INT32: aws_event_stream_add_int32_header(headers, header.first.c_str(), headerKeyLen, header.second.GetEventHeaderValueAsInt32()); - break; - case EventHeaderValue::EventHeaderType::INT64: + break; + case EventHeaderValue::EventHeaderType::INT64: aws_event_stream_add_int64_header(headers, header.first.c_str(), headerKeyLen, header.second.GetEventHeaderValueAsInt64()); - break; - case EventHeaderValue::EventHeaderType::BYTE_BUF: - { - const auto& bytes = header.second.GetEventHeaderValueAsBytebuf(); + break; + case EventHeaderValue::EventHeaderType::BYTE_BUF: + { + const auto& bytes = header.second.GetEventHeaderValueAsBytebuf(); aws_event_stream_add_bytebuf_header(headers, header.first.c_str(), headerKeyLen, bytes.GetUnderlyingData(), static_cast<uint16_t>(bytes.GetLength()), 1 /*copy*/); - } - break; - case EventHeaderValue::EventHeaderType::STRING: - { - const auto& bytes = header.second.GetUnderlyingBuffer(); - aws_event_stream_add_string_header(headers, header.first.c_str(), headerKeyLen, reinterpret_cast<char*>(bytes.GetUnderlyingData()), static_cast<uint16_t>(bytes.GetLength()), 0 /*copy*/); - } - break; - case EventHeaderValue::EventHeaderType::TIMESTAMP: + } + break; + case EventHeaderValue::EventHeaderType::STRING: + { + const auto& bytes = header.second.GetUnderlyingBuffer(); + aws_event_stream_add_string_header(headers, header.first.c_str(), headerKeyLen, reinterpret_cast<char*>(bytes.GetUnderlyingData()), static_cast<uint16_t>(bytes.GetLength()), 0 /*copy*/); + } + break; + case EventHeaderValue::EventHeaderType::TIMESTAMP: aws_event_stream_add_timestamp_header(headers, header.first.c_str(), headerKeyLen, header.second.GetEventHeaderValueAsTimestamp()); - break; - case EventHeaderValue::EventHeaderType::UUID: - { - ByteBuffer uuidBytes = header.second.GetEventHeaderValueAsUuid(); - aws_event_stream_add_uuid_header(headers, header.first.c_str(), headerKeyLen, uuidBytes.GetUnderlyingData()); - } - break; - default: - AWS_LOG_ERROR(TAG, "Encountered unknown type of header."); - break; - } - } - } - - EventStreamEncoder::EventStreamEncoder(Client::AWSAuthSigner* signer) : m_signer(signer) - { - } - - - Aws::Vector<unsigned char> EventStreamEncoder::EncodeAndSign(const Aws::Utils::Event::Message& msg) - { - aws_event_stream_message encoded = Encode(msg); - aws_event_stream_message signedMessage = Sign(&encoded); - - const auto signedMessageLength = signedMessage.message_buffer ? aws_event_stream_message_total_length(&signedMessage) : 0; - - Aws::Vector<unsigned char> outputBits(signedMessage.message_buffer, signedMessage.message_buffer + signedMessageLength); - aws_event_stream_message_clean_up(&encoded); - aws_event_stream_message_clean_up(&signedMessage); - return outputBits; - } - - aws_event_stream_message EventStreamEncoder::Encode(const Aws::Utils::Event::Message& msg) - { - aws_array_list headers; - EncodeHeaders(msg, &headers); - - aws_byte_buf payload; - payload.len = msg.GetEventPayload().size(); - // this const_cast is OK because aws_byte_buf will only be "read from" by the following functions. - payload.buffer = const_cast<uint8_t*>(msg.GetEventPayload().data()); - payload.capacity = 0; - payload.allocator = nullptr; - - aws_event_stream_message encoded; + break; + case EventHeaderValue::EventHeaderType::UUID: + { + ByteBuffer uuidBytes = header.second.GetEventHeaderValueAsUuid(); + aws_event_stream_add_uuid_header(headers, header.first.c_str(), headerKeyLen, uuidBytes.GetUnderlyingData()); + } + break; + default: + AWS_LOG_ERROR(TAG, "Encountered unknown type of header."); + break; + } + } + } + + EventStreamEncoder::EventStreamEncoder(Client::AWSAuthSigner* signer) : m_signer(signer) + { + } + + + Aws::Vector<unsigned char> EventStreamEncoder::EncodeAndSign(const Aws::Utils::Event::Message& msg) + { + aws_event_stream_message encoded = Encode(msg); + aws_event_stream_message signedMessage = Sign(&encoded); + + const auto signedMessageLength = signedMessage.message_buffer ? aws_event_stream_message_total_length(&signedMessage) : 0; + + Aws::Vector<unsigned char> outputBits(signedMessage.message_buffer, signedMessage.message_buffer + signedMessageLength); + aws_event_stream_message_clean_up(&encoded); + aws_event_stream_message_clean_up(&signedMessage); + return outputBits; + } + + aws_event_stream_message EventStreamEncoder::Encode(const Aws::Utils::Event::Message& msg) + { + aws_array_list headers; + EncodeHeaders(msg, &headers); + + aws_byte_buf payload; + payload.len = msg.GetEventPayload().size(); + // this const_cast is OK because aws_byte_buf will only be "read from" by the following functions. + payload.buffer = const_cast<uint8_t*>(msg.GetEventPayload().data()); + payload.capacity = 0; + payload.allocator = nullptr; + + aws_event_stream_message encoded; if(aws_event_stream_message_init(&encoded, get_aws_allocator(), &headers, &payload) == AWS_OP_ERR) - { + { AWS_LOGSTREAM_ERROR(TAG, "Error creating event-stream message from payload."); aws_event_stream_headers_list_cleanup(&headers); - // GCC 4.9.4 issues a warning with -Wextra if we simply do - // return {}; - aws_event_stream_message empty{nullptr, nullptr, 0}; - return empty; - } + // GCC 4.9.4 issues a warning with -Wextra if we simply do + // return {}; + aws_event_stream_message empty{nullptr, nullptr, 0}; + return empty; + } aws_event_stream_headers_list_cleanup(&headers); - return encoded; - } - - aws_event_stream_message EventStreamEncoder::Sign(aws_event_stream_message* msg) - { - const auto msglen = msg->message_buffer ? aws_event_stream_message_total_length(msg) : 0; - Event::Message signedMessage; - signedMessage.WriteEventPayload(msg->message_buffer, msglen); - - assert(m_signer); - if (!m_signer->SignEventMessage(signedMessage, m_signatureSeed)) - { - AWS_LOGSTREAM_ERROR(TAG, "Failed to sign event message frame."); - // GCC 4.9.4 issues a warning with -Wextra if we simply do - // return {}; - aws_event_stream_message empty{nullptr, nullptr, 0}; - return empty; - } - - aws_array_list headers; - EncodeHeaders(signedMessage, &headers); - - aws_byte_buf payload; - payload.len = signedMessage.GetEventPayload().size(); - payload.buffer = signedMessage.GetEventPayload().data(); - payload.capacity = 0; - payload.allocator = nullptr; - - aws_event_stream_message signedmsg; + return encoded; + } + + aws_event_stream_message EventStreamEncoder::Sign(aws_event_stream_message* msg) + { + const auto msglen = msg->message_buffer ? aws_event_stream_message_total_length(msg) : 0; + Event::Message signedMessage; + signedMessage.WriteEventPayload(msg->message_buffer, msglen); + + assert(m_signer); + if (!m_signer->SignEventMessage(signedMessage, m_signatureSeed)) + { + AWS_LOGSTREAM_ERROR(TAG, "Failed to sign event message frame."); + // GCC 4.9.4 issues a warning with -Wextra if we simply do + // return {}; + aws_event_stream_message empty{nullptr, nullptr, 0}; + return empty; + } + + aws_array_list headers; + EncodeHeaders(signedMessage, &headers); + + aws_byte_buf payload; + payload.len = signedMessage.GetEventPayload().size(); + payload.buffer = signedMessage.GetEventPayload().data(); + payload.capacity = 0; + payload.allocator = nullptr; + + aws_event_stream_message signedmsg; if(aws_event_stream_message_init(&signedmsg, get_aws_allocator(), &headers, &payload)) - { + { AWS_LOGSTREAM_ERROR(TAG, "Error creating event-stream message from payload."); aws_event_stream_headers_list_cleanup(&headers); - // GCC 4.9.4 issues a warning with -Wextra if we simply do - // return {}; - aws_event_stream_message empty{nullptr, nullptr, 0}; - return empty; - } + // GCC 4.9.4 issues a warning with -Wextra if we simply do + // return {}; + aws_event_stream_message empty{nullptr, nullptr, 0}; + return empty; + } aws_event_stream_headers_list_cleanup(&headers); - return signedmsg; - } - - } // namespace Event - } // namespace Utils -} // namespace Aws - + return signedmsg; + } + + } // namespace Event + } // namespace Utils +} // namespace Aws + diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamErrors.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamErrors.cpp index df999b07b8..836d0b47c5 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamErrors.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/event/EventStreamErrors.cpp @@ -1,66 +1,66 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/core/client/AWSError.h> -#include <aws/core/utils/HashingUtils.h> -#include <aws/core/utils/event/EventStreamErrors.h> - - using namespace Aws::Client; -// using namespace Aws::S3; -// using namespace Aws::Utils; - -namespace Aws -{ - namespace Utils - { - namespace Event - { - namespace EventStreamErrorsMapper - { - /* - static const int EVENT_STREAM_NO_ERROR_HASH = HashingUtils::HashString("EventStreamNoError"); - static const int EVENT_STREAM_BUFFER_LENGTH_MISMATCH_HASH = HashingUtils::HashString("EventStreamBufferLengthMismatch"); - static const int EVENT_STREAM_INSUFFICIENT_BUFFER_LEN_HASH = HashingUtils::HashString("EventStreamInsufficientBufferLen"); - static const int EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED_HASH = HashingUtils::HashString("EventStreamMessageFieldSizeExceeded"); - static const int EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE_HASH = HashingUtils::HashString("EventStreamPreludeChecksumFailure"); - static const int EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE_HASH = HashingUtils::HashString("EventStreamMessageChecksumFailure"); - static const int EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN_HASH = HashingUtils::HashString("EventStreamMessageInvalidHeadersLen"); - static const int EVENT_STREAM_MESSAGE_UNKNOWN_HEADER_TYPE_HASH = HashingUtils::HashString("EventStreamMessageUnknownHeaderType"); - static const int EVENT_STREAM_MESSAGE_PARSER_ILLEGAL_STATE_HASH = HashingUtils::HashString("EventStreamMessageParserIllegalState"); - */ - const char* GetNameForError(EventStreamErrors error) - { - switch (error) - { - case EventStreamErrors::EVENT_STREAM_NO_ERROR: - return "EventStreamNoError"; - case EventStreamErrors::EVENT_STREAM_BUFFER_LENGTH_MISMATCH: - return "EventStreamBufferLengthMismatch"; - case EventStreamErrors::EVENT_STREAM_INSUFFICIENT_BUFFER_LEN: - return "EventStreamInsufficientBufferLen"; - case EventStreamErrors::EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED: - return "EventStreamMessageFieldSizeExceeded"; - case EventStreamErrors::EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE: - return "EventStreamPreludeChecksumFailure"; - case EventStreamErrors::EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE: - return "EventStreamMessageChecksumFailure"; - case EventStreamErrors::EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN: - return "EventStreamMessageInvalidHeadersLen"; - case EventStreamErrors::EVENT_STREAM_MESSAGE_UNKNOWN_HEADER_TYPE: - return "EventStreamMessageUnknownHeaderType"; - case EventStreamErrors::EVENT_STREAM_MESSAGE_PARSER_ILLEGAL_STATE: - return "EventStreamMessageParserIllegalState"; - default: - return "EventStreamUnknownError"; - } - } - - AWSError<CoreErrors> GetAwsErrorForEventStreamError(EventStreamErrors error) - { - return AWSError<CoreErrors>(CoreErrors::UNKNOWN, GetNameForError(error), "", false); - } - } // namespace EventStreamErrorsMapper - } // namespace Event - } // namespace Utils -} // namespace Aws + */ +#include <aws/core/client/AWSError.h> +#include <aws/core/utils/HashingUtils.h> +#include <aws/core/utils/event/EventStreamErrors.h> + + using namespace Aws::Client; +// using namespace Aws::S3; +// using namespace Aws::Utils; + +namespace Aws +{ + namespace Utils + { + namespace Event + { + namespace EventStreamErrorsMapper + { + /* + static const int EVENT_STREAM_NO_ERROR_HASH = HashingUtils::HashString("EventStreamNoError"); + static const int EVENT_STREAM_BUFFER_LENGTH_MISMATCH_HASH = HashingUtils::HashString("EventStreamBufferLengthMismatch"); + static const int EVENT_STREAM_INSUFFICIENT_BUFFER_LEN_HASH = HashingUtils::HashString("EventStreamInsufficientBufferLen"); + static const int EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED_HASH = HashingUtils::HashString("EventStreamMessageFieldSizeExceeded"); + static const int EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE_HASH = HashingUtils::HashString("EventStreamPreludeChecksumFailure"); + static const int EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE_HASH = HashingUtils::HashString("EventStreamMessageChecksumFailure"); + static const int EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN_HASH = HashingUtils::HashString("EventStreamMessageInvalidHeadersLen"); + static const int EVENT_STREAM_MESSAGE_UNKNOWN_HEADER_TYPE_HASH = HashingUtils::HashString("EventStreamMessageUnknownHeaderType"); + static const int EVENT_STREAM_MESSAGE_PARSER_ILLEGAL_STATE_HASH = HashingUtils::HashString("EventStreamMessageParserIllegalState"); + */ + const char* GetNameForError(EventStreamErrors error) + { + switch (error) + { + case EventStreamErrors::EVENT_STREAM_NO_ERROR: + return "EventStreamNoError"; + case EventStreamErrors::EVENT_STREAM_BUFFER_LENGTH_MISMATCH: + return "EventStreamBufferLengthMismatch"; + case EventStreamErrors::EVENT_STREAM_INSUFFICIENT_BUFFER_LEN: + return "EventStreamInsufficientBufferLen"; + case EventStreamErrors::EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED: + return "EventStreamMessageFieldSizeExceeded"; + case EventStreamErrors::EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE: + return "EventStreamPreludeChecksumFailure"; + case EventStreamErrors::EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE: + return "EventStreamMessageChecksumFailure"; + case EventStreamErrors::EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN: + return "EventStreamMessageInvalidHeadersLen"; + case EventStreamErrors::EVENT_STREAM_MESSAGE_UNKNOWN_HEADER_TYPE: + return "EventStreamMessageUnknownHeaderType"; + case EventStreamErrors::EVENT_STREAM_MESSAGE_PARSER_ILLEGAL_STATE: + return "EventStreamMessageParserIllegalState"; + default: + return "EventStreamUnknownError"; + } + } + + AWSError<CoreErrors> GetAwsErrorForEventStreamError(EventStreamErrors error) + { + return AWSError<CoreErrors>(CoreErrors::UNKNOWN, GetNameForError(error), "", false); + } + } // namespace EventStreamErrorsMapper + } // namespace Event + } // namespace Utils +} // namespace Aws diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/json/JsonSerializer.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/json/JsonSerializer.cpp index a0f5400612..9b785d1995 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/json/JsonSerializer.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/json/JsonSerializer.cpp @@ -633,7 +633,7 @@ Aws::String JsonView::WriteCompact(bool treatAsObject) const { return "{}"; } - return {}; + return {}; } auto temp = cJSON_PrintUnformatted(m_value); @@ -650,7 +650,7 @@ Aws::String JsonView::WriteReadable(bool treatAsObject) const { return "{\n}\n"; } - return {}; + return {}; } auto temp = cJSON_Print(m_value); diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/ConcurrentStreamBuf.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/ConcurrentStreamBuf.cpp index 0ba47bd92c..3f59dbe96d 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/ConcurrentStreamBuf.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/ConcurrentStreamBuf.cpp @@ -1,109 +1,109 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/core/utils/stream/ConcurrentStreamBuf.h> -#include <aws/core/utils/logging/LogMacros.h> -#include <cstdint> -#include <cassert> - -namespace Aws -{ - namespace Utils - { - namespace Stream - { - const char TAG[] = "ConcurrentStreamBuf"; - ConcurrentStreamBuf::ConcurrentStreamBuf(size_t bufferLength) : - m_putArea(bufferLength), // we access [0] of the put area below so we must initialize it. - m_eof(false) - { - m_getArea.reserve(bufferLength); - m_backbuf.reserve(bufferLength); - - char* pbegin = reinterpret_cast<char*>(&m_putArea[0]); - setp(pbegin, pbegin + bufferLength); - } - - void ConcurrentStreamBuf::SetEof() - { - { - std::unique_lock<std::mutex> lock(m_lock); - m_eof = true; - } - m_signal.notify_all(); - } - - void ConcurrentStreamBuf::FlushPutArea() - { - const size_t bitslen = pptr() - pbase(); - if (bitslen) - { - // scope the lock - { - std::unique_lock<std::mutex> lock(m_lock); + */ +#include <aws/core/utils/stream/ConcurrentStreamBuf.h> +#include <aws/core/utils/logging/LogMacros.h> +#include <cstdint> +#include <cassert> + +namespace Aws +{ + namespace Utils + { + namespace Stream + { + const char TAG[] = "ConcurrentStreamBuf"; + ConcurrentStreamBuf::ConcurrentStreamBuf(size_t bufferLength) : + m_putArea(bufferLength), // we access [0] of the put area below so we must initialize it. + m_eof(false) + { + m_getArea.reserve(bufferLength); + m_backbuf.reserve(bufferLength); + + char* pbegin = reinterpret_cast<char*>(&m_putArea[0]); + setp(pbegin, pbegin + bufferLength); + } + + void ConcurrentStreamBuf::SetEof() + { + { + std::unique_lock<std::mutex> lock(m_lock); + m_eof = true; + } + m_signal.notify_all(); + } + + void ConcurrentStreamBuf::FlushPutArea() + { + const size_t bitslen = pptr() - pbase(); + if (bitslen) + { + // scope the lock + { + std::unique_lock<std::mutex> lock(m_lock); m_signal.wait(lock, [this, bitslen]{ return m_eof || bitslen <= (m_backbuf.capacity() - m_backbuf.size()); }); if (m_eof) { return; } - std::copy(pbase(), pptr(), std::back_inserter(m_backbuf)); - } - m_signal.notify_one(); - char* pbegin = reinterpret_cast<char*>(&m_putArea[0]); - setp(pbegin, pbegin + m_putArea.size()); - } - } - - std::streampos ConcurrentStreamBuf::seekoff(std::streamoff, std::ios_base::seekdir, std::ios_base::openmode) - { - return std::streamoff(-1); // Seeking is not supported. - } - - std::streampos ConcurrentStreamBuf::seekpos(std::streampos, std::ios_base::openmode) - { - return std::streamoff(-1); // Seeking is not supported. - } - - int ConcurrentStreamBuf::underflow() - { - { - std::unique_lock<std::mutex> lock(m_lock); - m_signal.wait(lock, [this]{ return m_backbuf.empty() == false || m_eof; }); - - if (m_eof && m_backbuf.empty()) - { - return std::char_traits<char>::eof(); - } - - m_getArea.clear(); // keep the get-area from growing unbounded. - std::copy(m_backbuf.begin(), m_backbuf.end(), std::back_inserter(m_getArea)); - m_backbuf.clear(); - } - m_signal.notify_one(); - char* gbegin = reinterpret_cast<char*>(&m_getArea[0]); - setg(gbegin, gbegin, gbegin + m_getArea.size()); - return std::char_traits<char>::to_int_type(*gptr()); - } - - std::streamsize ConcurrentStreamBuf::showmanyc() - { - std::unique_lock<std::mutex> lock(m_lock); - AWS_LOGSTREAM_TRACE(TAG, "stream how many character? " << m_backbuf.size()); - return m_backbuf.size(); - } - - int ConcurrentStreamBuf::overflow(int ch) - { - const auto eof = std::char_traits<char>::eof(); - - if (ch == eof) - { - FlushPutArea(); - return eof; - } - - FlushPutArea(); + std::copy(pbase(), pptr(), std::back_inserter(m_backbuf)); + } + m_signal.notify_one(); + char* pbegin = reinterpret_cast<char*>(&m_putArea[0]); + setp(pbegin, pbegin + m_putArea.size()); + } + } + + std::streampos ConcurrentStreamBuf::seekoff(std::streamoff, std::ios_base::seekdir, std::ios_base::openmode) + { + return std::streamoff(-1); // Seeking is not supported. + } + + std::streampos ConcurrentStreamBuf::seekpos(std::streampos, std::ios_base::openmode) + { + return std::streamoff(-1); // Seeking is not supported. + } + + int ConcurrentStreamBuf::underflow() + { + { + std::unique_lock<std::mutex> lock(m_lock); + m_signal.wait(lock, [this]{ return m_backbuf.empty() == false || m_eof; }); + + if (m_eof && m_backbuf.empty()) + { + return std::char_traits<char>::eof(); + } + + m_getArea.clear(); // keep the get-area from growing unbounded. + std::copy(m_backbuf.begin(), m_backbuf.end(), std::back_inserter(m_getArea)); + m_backbuf.clear(); + } + m_signal.notify_one(); + char* gbegin = reinterpret_cast<char*>(&m_getArea[0]); + setg(gbegin, gbegin, gbegin + m_getArea.size()); + return std::char_traits<char>::to_int_type(*gptr()); + } + + std::streamsize ConcurrentStreamBuf::showmanyc() + { + std::unique_lock<std::mutex> lock(m_lock); + AWS_LOGSTREAM_TRACE(TAG, "stream how many character? " << m_backbuf.size()); + return m_backbuf.size(); + } + + int ConcurrentStreamBuf::overflow(int ch) + { + const auto eof = std::char_traits<char>::eof(); + + if (ch == eof) + { + FlushPutArea(); + return eof; + } + + FlushPutArea(); { std::unique_lock<std::mutex> lock(m_lock); if (m_eof) @@ -114,13 +114,13 @@ namespace Aws pbump(1); return ch; } - } - - int ConcurrentStreamBuf::sync() - { - FlushPutArea(); - return 0; - } - } - } -} + } + + int ConcurrentStreamBuf::sync() + { + FlushPutArea(); + return 0; + } + } + } +} diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/PreallocatedStreamBuf.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/PreallocatedStreamBuf.cpp index 7aaf9c82f3..f656fc8613 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/PreallocatedStreamBuf.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/PreallocatedStreamBuf.cpp @@ -16,8 +16,8 @@ namespace Aws PreallocatedStreamBuf::PreallocatedStreamBuf(unsigned char* buffer, uint64_t lengthToRead) : m_underlyingBuffer(buffer), m_lengthToRead(lengthToRead) { - char* end = reinterpret_cast<char*>(m_underlyingBuffer + m_lengthToRead); - char* begin = reinterpret_cast<char*>(m_underlyingBuffer); + char* end = reinterpret_cast<char*>(m_underlyingBuffer + m_lengthToRead); + char* begin = reinterpret_cast<char*>(m_underlyingBuffer); setp(begin, end); setg(begin, begin, end); } @@ -55,12 +55,12 @@ namespace Aws return pos_type(off_type(-1)); } - char* end = reinterpret_cast<char*>(m_underlyingBuffer + m_lengthToRead); - char* begin = reinterpret_cast<char*>(m_underlyingBuffer); + char* end = reinterpret_cast<char*>(m_underlyingBuffer + m_lengthToRead); + char* begin = reinterpret_cast<char*>(m_underlyingBuffer); if (which == std::ios_base::in) { - setg(begin, begin + static_cast<size_t>(pos), end); + setg(begin, begin + static_cast<size_t>(pos), end); } if (which == std::ios_base::out) @@ -72,4 +72,4 @@ namespace Aws } } } -} +} diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/SimpleStreamBuf.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/SimpleStreamBuf.cpp index 91064590a8..6e42994744 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/SimpleStreamBuf.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/SimpleStreamBuf.cpp @@ -201,7 +201,7 @@ std::streamsize SimpleStreamBuf::xsputn(const char* s, std::streamsize n) return writeCount; } -Aws::String SimpleStreamBuf::str() const +Aws::String SimpleStreamBuf::str() const { return Aws::String(m_buffer, pptr()); } @@ -236,4 +236,4 @@ void SimpleStreamBuf::str(const Aws::String& value) } } -} +} diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/xml/XmlSerializer.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/xml/XmlSerializer.cpp index 59d259a911..c06befaf9b 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/xml/XmlSerializer.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/xml/XmlSerializer.cpp @@ -125,7 +125,7 @@ Aws::String XmlNode::GetText() const return printer.CStr(); } - return {}; + return {}; } void XmlNode::SetText(const Aws::String& textValue) |