From bed8fa538c862a8297cb02c99d8b3dcc29247d5b Mon Sep 17 00:00:00 2001 From: Billy O'Neal Date: Fri, 12 Jul 2019 18:05:14 -0700 Subject: [PATCH] Replace CPPREST_TARGET_XP with version checks, remove ""s, and other cleanup (#1187) * Audit for "" and use std::string default ctor instead. * Fix Linux ambiguity. * Exclude common build directories. * Replace CPPREST_TARGET_XP with checks against _WIN32_WINNT to allow more fine grained controls going forward (e.g. assume Win10). Also fix a few typos. * Delete CASABLANCA_UNREFERENCED_PARAMETER and attempt Linux compile fix. * Defend NOMINMAX. * Another _WIN32 guard. * With && this time. * Fix more spelling errors. * Optimize trim_nulls slightly. * And actually make the optimization correct this time. * Fix unit test failure. * clang-format --- .gitignore | 2 + .vscode/settings.json | 16 ++- .../include/cpprest/details/cpprest_compat.h | 3 - .../include/cpprest/details/web_utilities.h | 30 ++-- Release/include/cpprest/http_client.h | 6 +- Release/include/cpprest/streams.h | 21 ++- Release/include/cpprest/ws_client.h | 7 +- Release/include/cpprest/ws_msg.h | 2 +- Release/include/pplx/pplxtasks.h | 4 +- .../BlackJack_Client/BlackJackClient.cpp | 1 - .../BlackJack/BlackJack_Server/messagetypes.h | 4 +- .../BlackJack/BlackJack_Server/stdafx.h | 3 - .../BlackJack_UIClient/Player.xaml.cpp | 16 ++- .../BlackJack_UIClient/Player.xaml.h | 8 +- .../BlackJack_UIClient/PlayingTable.xaml.cpp | 22 +-- .../BlackJack_UIClient/PlayingTable.xaml.h | 2 +- Release/samples/CasaLens/casalens.cpp | 8 +- Release/samples/OAuth2Live/MainPage.xaml.cpp | 6 +- Release/samples/Oauth1Client/Oauth1Client.cpp | 8 +- Release/samples/Oauth2Client/Oauth2Client.cpp | 14 +- .../samples/WindowsLiveAuth/live_connect.h | 4 +- Release/src/http/client/http_client.cpp | 2 +- Release/src/http/client/http_client_asio.cpp | 26 ++-- .../src/http/client/http_client_winhttp.cpp | 130 +++++++++++------- Release/src/http/client/http_client_winrt.cpp | 18 +-- Release/src/http/common/http_compression.cpp | 4 +- Release/src/http/common/http_msg.cpp | 16 +-- .../src/http/listener/http_server_asio.cpp | 16 +-- .../src/http/listener/http_server_httpsys.cpp | 8 +- .../src/http/listener/http_server_httpsys.h | 6 +- Release/src/http/oauth/oauth1.cpp | 4 +- Release/src/json/json.cpp | 11 +- Release/src/pch/stdafx.h | 24 ++-- Release/src/streams/fileio_posix.cpp | 8 +- Release/src/streams/fileio_win32.cpp | 6 +- Release/src/uri/uri.cpp | 2 +- Release/src/utilities/web_utilities.cpp | 16 ++- Release/src/websockets/client/ws_client.cpp | 3 +- .../src/websockets/client/ws_client_winrt.cpp | 2 +- .../src/websockets/client/ws_client_wspp.cpp | 47 ++++--- .../tests/common/TestRunner/test_runner.cpp | 6 +- Release/tests/common/UnitTestpp/src/Checks.h | 2 +- .../UnitTestpp/src/DeferredTestResult.cpp | 6 +- .../common/UnitTestpp/src/MemoryOutStream.cpp | 2 +- Release/tests/common/UnitTestpp/src/stdafx.h | 1 - .../tests/common/utilities/os_utilities.cpp | 1 - .../http/client/compression_tests.cpp | 22 +-- .../functional/http/client/outside_tests.cpp | 2 +- .../tests/functional/http/utilities/stdafx.h | 1 - .../functional/json/json_numbers_tests.cpp | 16 +-- Release/tests/functional/json/stdafx.h | 1 - .../misc/atl_headers/header_test1.cpp | 1 - .../misc/atl_headers/header_test2.cpp | 1 - .../tests/functional/pplx/pplx_test/stdafx.h | 1 - .../functional/streams/istream_tests.cpp | 2 +- .../functional/streams/memstream_tests.cpp | 1 - .../utils/win32_encryption_tests.cpp | 4 +- .../functional/websockets/utilities/stdafx.h | 1 - 58 files changed, 326 insertions(+), 281 deletions(-) diff --git a/.gitignore b/.gitignore index 8fc8285e16..3a3fea4411 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,5 @@ Build_android/build/ Generated Files/ # Ignore iOS temp build directories Build_iOS/Apple-Boost-BuildScript + +/out/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 2fc5e0c5fe..9bad9cb7c7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,18 @@ "**/.git/objects/**": true, "**/.git/subtree-cache/**": true, "**/node_modules/*/**": true, - "**/vcpkg/**": true - } + "**/vcpkg/**": true, + "build.x86.debug": true, + "build.x86.release": true, + "build.x64.debug": true, + "build.x64.release": true, + "out": true, + }, + "cSpell.words": [ + "XPLATSTR", + "blittable", + "pplx", + "rdpos", + "rgpsz" + ] } diff --git a/Release/include/cpprest/details/cpprest_compat.h b/Release/include/cpprest/details/cpprest_compat.h index c671ce2fe5..6dae41d8d9 100644 --- a/Release/include/cpprest/details/cpprest_compat.h +++ b/Release/include/cpprest/details/cpprest_compat.h @@ -24,8 +24,6 @@ #define CPPREST_CONSTEXPR const #endif // _MSC_VER >= 1900 -#define CASABLANCA_UNREFERENCED_PARAMETER(x) (x) - #include #else // ^^^ _WIN32 ^^^ // vvv !_WIN32 vvv @@ -38,7 +36,6 @@ { \ if (!(x)) __builtin_unreachable(); \ } while (false) -#define CASABLANCA_UNREFERENCED_PARAMETER(x) (void)x #define CPPREST_NOEXCEPT noexcept #define CPPREST_CONSTEXPR constexpr diff --git a/Release/include/cpprest/details/web_utilities.h b/Release/include/cpprest/details/web_utilities.h index 8b99d94aa2..aed7419c85 100644 --- a/Release/include/cpprest/details/web_utilities.h +++ b/Release/include/cpprest/details/web_utilities.h @@ -10,6 +10,10 @@ ****/ #pragma once +#ifdef _WIN32 +#include +#endif // _WIN32 + #include "cpprest/asyncrt_utils.h" #include "cpprest/uri.h" @@ -24,23 +28,24 @@ class zero_memory_deleter }; typedef std::unique_ptr<::utility::string_t, zero_memory_deleter> plaintext_string; -#if defined(_WIN32) && !defined(CPPREST_TARGET_XP) -#if defined(__cplusplus_winrt) +#ifdef _WIN32 +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA +#ifdef __cplusplus_winrt class winrt_encryption { public: - winrt_encryption() {} + winrt_encryption() = default; _ASYNCRTIMP winrt_encryption(const std::wstring& data); _ASYNCRTIMP plaintext_string decrypt() const; private: ::pplx::task m_buffer; }; -#else +#else // ^^^ __cplusplus_winrt ^^^ // vvv !__cplusplus_winrt vvv class win32_encryption { public: - win32_encryption() {} + win32_encryption() = default; _ASYNCRTIMP win32_encryption(const std::wstring& data); _ASYNCRTIMP ~win32_encryption(); _ASYNCRTIMP plaintext_string decrypt() const; @@ -49,8 +54,9 @@ class win32_encryption std::vector m_buffer; size_t m_numCharacters; }; -#endif -#endif +#endif // __cplusplus_winrt +#endif // _WIN32_WINNT >= _WIN32_WINNT_VISTA +#endif // _WIN32 } // namespace details /// @@ -89,7 +95,7 @@ class credentials "This API is deprecated for security reasons to avoid unnecessary password copies stored in plaintext.") utility::string_t password() const { -#if defined(_WIN32) && !defined(CPPREST_TARGET_XP) +#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA return utility::string_t(*m_password.decrypt()); #else return m_password; @@ -105,7 +111,7 @@ class credentials details::plaintext_string _internal_decrypt() const { // Encryption APIs not supported on XP -#if defined(_WIN32) && !defined(CPPREST_TARGET_XP) +#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA return m_password.decrypt(); #else return details::plaintext_string(new ::utility::string_t(m_password)); @@ -115,7 +121,7 @@ class credentials private: ::utility::string_t m_username; -#if defined(_WIN32) && !defined(CPPREST_TARGET_XP) +#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA #if defined(__cplusplus_winrt) details::winrt_encryption m_password; #else @@ -151,13 +157,13 @@ class web_proxy /// /// Constructs a proxy with the default settings. /// - web_proxy() : m_address(_XPLATSTR("")), m_mode(use_default_) {} + web_proxy() : m_address(), m_mode(use_default_) {} /// /// Creates a proxy with specified mode. /// /// Mode to use. - web_proxy(web_proxy_mode mode) : m_address(_XPLATSTR("")), m_mode(static_cast(mode)) {} + web_proxy(web_proxy_mode mode) : m_address(), m_mode(static_cast(mode)) {} /// /// Creates a proxy explicitly with provided address. diff --git a/Release/include/cpprest/http_client.h b/Release/include/cpprest/http_client.h index 743e2b5635..0bedfbd42a 100644 --- a/Release/include/cpprest/http_client.h +++ b/Release/include/cpprest/http_client.h @@ -54,7 +54,7 @@ typedef void* native_handle; #include #include -#if !defined(CPPREST_TARGET_XP) +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA #include "cpprest/oauth1.h" #endif @@ -110,7 +110,7 @@ class http_client_config { } -#if !defined(CPPREST_TARGET_XP) +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA /// /// Get OAuth 1.0 configuration. /// @@ -363,7 +363,7 @@ class http_client_config #endif private: -#if !defined(CPPREST_TARGET_XP) +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA std::shared_ptr m_oauth1; #endif diff --git a/Release/include/cpprest/streams.h b/Release/include/cpprest/streams.h index 08713226b7..c2968b9d49 100644 --- a/Release/include/cpprest/streams.h +++ b/Release/include/cpprest/streams.h @@ -470,7 +470,7 @@ _UINT_TRAIT(unsigned long long, ULLONG_MIN, ULLONG_MAX) { \ typedef std::true_type _is_integral; \ typedef std::false_type _is_unsigned; \ - static const int64_t _min = std::numeric_limits<_t>::min(); \ + static const int64_t _min = (std::numeric_limits<_t>::min)(); \ static const int64_t _max = (std::numeric_limits<_t>::max)(); \ }; #define _UINT_TRAIT(_t) \ @@ -1139,8 +1139,8 @@ pplx::task _type_parser_base::_parse_input(concurrency::st auto update = [=](pplx::task op) -> pplx::task { int_type ch = op.get(); if (ch == traits::eof()) return pplx::task_from_result(false); - bool accptd = accept_character(state, ch); - if (!accptd) return pplx::task_from_result(false); + bool accepted = accept_character(state, ch); + if (!accepted) return pplx::task_from_result(false); // We peeked earlier, so now we must advance the position. concurrency::streams::streambuf buf = buffer; return buf.bumpc().then([](int_type) { return true; }); @@ -1308,9 +1308,18 @@ struct _double_state template static std::string create_exception_message(int_type ch, bool exponent) { - std::ostringstream os; - os << "Invalid character '" << char(ch) << "'" << (exponent ? " in exponent" : ""); - return os.str(); + std::string result; + if (exponent) + { + result.assign("Invalid character 'X' in exponent"); + } + else + { + result.assign("Invalid character 'X'"); + } + + result[19] = static_cast(ch); + return result; } template diff --git a/Release/include/cpprest/ws_client.h b/Release/include/cpprest/ws_client.h index 9c202d7f73..af17bd6060 100644 --- a/Release/include/cpprest/ws_client.h +++ b/Release/include/cpprest/ws_client.h @@ -330,8 +330,7 @@ class websocket_client_callback_impl virtual pplx::task close() = 0; - virtual pplx::task close(websocket_close_status close_status, - const utility::string_t& close_reason = _XPLATSTR("")) = 0; + virtual pplx::task close(websocket_close_status close_status, const utility::string_t& close_reason = {}) = 0; virtual void set_close_handler( const std::function& @@ -478,7 +477,7 @@ class websocket_client /// frame. While closing an established connection, an endpoint may indicate the /// reason for closure. An asynchronous operation that is completed the connection has been /// successfully closed. - pplx::task close(websocket_close_status close_status, const utility::string_t& close_reason = _XPLATSTR("")) + pplx::task close(websocket_close_status close_status, const utility::string_t& close_reason = {}) { return m_client->callback_client()->close(close_status, close_reason); } @@ -566,7 +565,7 @@ class websocket_callback_client /// frame. While closing an established connection, an endpoint may indicate the /// reason for closure. An asynchronous operation that is completed the connection has been /// successfully closed. - pplx::task close(websocket_close_status close_status, const utility::string_t& close_reason = _XPLATSTR("")) + pplx::task close(websocket_close_status close_status, const utility::string_t& close_reason = {}) { return m_client->close(close_status, close_reason); } diff --git a/Release/include/cpprest/ws_msg.h b/Release/include/cpprest/ws_msg.h index 73e968a001..9b13a80849 100644 --- a/Release/include/cpprest/ws_msg.h +++ b/Release/include/cpprest/ws_msg.h @@ -74,7 +74,7 @@ class websocket_outgoing_message /// /// UTF-8 String containing the optional pong message. void set_pong_message(const std::string& data = {}) - { + { this->set_message_pong(concurrency::streams::container_buffer(data)); } #endif diff --git a/Release/include/pplx/pplxtasks.h b/Release/include/pplx/pplxtasks.h index 63cedc4f28..6868fc1619 100644 --- a/Release/include/pplx/pplxtasks.h +++ b/Release/include/pplx/pplxtasks.h @@ -3799,7 +3799,7 @@ class task auto _LogWorkItemAndInvokeUserLambda(_Func&& _func) const -> decltype(_func()) { details::_TaskWorkItemRAIILogger _LogWorkItem(this->_M_pTask->_M_taskEventLogger); - CASABLANCA_UNREFERENCED_PARAMETER(_LogWorkItem); + (void)_LogWorkItem; return _func(); } @@ -3931,7 +3931,7 @@ class task -> decltype(_func(std::forward<_Arg>(_value))) { details::_TaskWorkItemRAIILogger _LogWorkItem(this->_M_pTask->_M_taskEventLogger); - CASABLANCA_UNREFERENCED_PARAMETER(_LogWorkItem); + (void)_LogWorkItem; return _func(std::forward<_Arg>(_value)); } diff --git a/Release/samples/BlackJack/BlackJack_Client/BlackJackClient.cpp b/Release/samples/BlackJack/BlackJack_Client/BlackJackClient.cpp index 5c9b1fc4b1..184ab42937 100644 --- a/Release/samples/BlackJack/BlackJack_Client/BlackJackClient.cpp +++ b/Release/samples/BlackJack/BlackJack_Client/BlackJackClient.cpp @@ -17,7 +17,6 @@ #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#define NOMINMAX #include #include diff --git a/Release/samples/BlackJack/BlackJack_Server/messagetypes.h b/Release/samples/BlackJack/BlackJack_Server/messagetypes.h index 91c633984e..f38556dde3 100644 --- a/Release/samples/BlackJack/BlackJack_Server/messagetypes.h +++ b/Release/samples/BlackJack/BlackJack_Server/messagetypes.h @@ -179,7 +179,7 @@ struct BJHand { if (iter->value == CV_Ace) hasAces = true; - res.low += std::min((int)iter->value, 10); + res.low += (std::min)((int)iter->value, 10); } res.high = hasAces ? res.low + 10 : res.low; return res; @@ -271,7 +271,7 @@ struct Player static Player FromJSON(const web::json::object& object) { - Player result(U("")); + Player result(utility::string_t{}); auto iName = object.find(NAME); if (iName == object.end()) diff --git a/Release/samples/BlackJack/BlackJack_Server/stdafx.h b/Release/samples/BlackJack/BlackJack_Server/stdafx.h index ae59ac7dbd..d9bef583ff 100644 --- a/Release/samples/BlackJack/BlackJack_Server/stdafx.h +++ b/Release/samples/BlackJack/BlackJack_Server/stdafx.h @@ -26,9 +26,6 @@ #include #ifdef _WIN32 -#ifndef NOMINMAX -#define NOMINMAX -#endif #include #else #include diff --git a/Release/samples/BlackJack/BlackJack_UIClient/Player.xaml.cpp b/Release/samples/BlackJack/BlackJack_UIClient/Player.xaml.cpp index e32a766883..394165a53c 100644 --- a/Release/samples/BlackJack/BlackJack_UIClient/Player.xaml.cpp +++ b/Release/samples/BlackJack/BlackJack_UIClient/Player.xaml.cpp @@ -54,7 +54,13 @@ void PlayerSpace::Update(Player player) playerName->Text = ref new Platform::String(web::uri::decode(player.Name).c_str()); playerBalance->Text = "$" + player.Balance.ToString(); playerBet->Text = "Bet: $" + player.Hand.bet.ToString(); - playerInsurance->Text = (player.Hand.insurance > 0) ? "Ins: $" + player.Hand.insurance.ToString() : ""; + if (player.Hand.insurance > 0) { + auto& text = playerInsurance->Text; + text.assign("Ins: $"); + text.append(std::to_string(player.Hand.insurance)); + } else { + text.clear(); + } } void PlayerSpace::AddCard(Card card) @@ -87,19 +93,19 @@ void PlayerSpace::ShowResult(BJHandResult result) { case BJHandResult::HR_ComputerWin: playerInsurance->Text = L"Dealer Wins"; - playerBet->Text = L""; + playerBet->Text.clear(); break; case BJHandResult::HR_PlayerWin: playerInsurance->Text = L"Player Wins"; - playerBet->Text = L""; + playerBet->Text.clear(); break; case BJHandResult::HR_Push: playerInsurance->Text = L"Push"; - playerBet->Text = L""; + playerBet->Text.clear(); break; case BJHandResult::HR_PlayerBlackJack: playerInsurance->Text = L"Blackjack!"; - playerBet->Text = L""; + playerBet->Text.clear(); break; default: break; } diff --git a/Release/samples/BlackJack/BlackJack_UIClient/Player.xaml.h b/Release/samples/BlackJack/BlackJack_UIClient/Player.xaml.h index 429d5e38c3..5b7ee7462b 100644 --- a/Release/samples/BlackJack/BlackJack_UIClient/Player.xaml.h +++ b/Release/samples/BlackJack/BlackJack_UIClient/Player.xaml.h @@ -25,10 +25,10 @@ ref class PlayerSpace sealed void Clear() { - playerBalance->Text = L""; - playerBet->Text = L""; - playerName->Text = L""; - playerInsurance->Text = L""; + playerBalance->Text.clear(); + playerBet->Text.clear(); + playerName->Text.clear(); + playerInsurance->Text.clear(); m_cards.clear(); playerCardGrid->Children->Clear(); } diff --git a/Release/samples/BlackJack/BlackJack_UIClient/PlayingTable.xaml.cpp b/Release/samples/BlackJack/BlackJack_UIClient/PlayingTable.xaml.cpp index 64fd0adae6..5f835e1b3f 100644 --- a/Release/samples/BlackJack/BlackJack_UIClient/PlayingTable.xaml.cpp +++ b/Release/samples/BlackJack/BlackJack_UIClient/PlayingTable.xaml.cpp @@ -116,7 +116,7 @@ void BlackjackClient::PlayingTable::Refresh() request.then( [this](pplx::task tsk) { - this->resultLabel->Text = L""; + this->resultLabel->Text.clear(); try { @@ -137,7 +137,7 @@ void BlackjackClient::PlayingTable::InterpretResponse(http_response& response) { if (response.headers().content_type() != L"application/json") return; - this->resultLabel->Text = L""; + this->resultLabel->Text.clear(); response.extract_json().then( [this, response](json::value jsonResponse) { @@ -265,7 +265,7 @@ void BlackjackClient::PlayingTable::BetButton_Click(Platform::Object ^ sender, request.then( [this](pplx::task tsk) { - this->resultLabel->Text = L""; + this->resultLabel->Text.clear(); try { @@ -307,7 +307,7 @@ void BlackjackClient::PlayingTable::InsuranceButton_Click(Platform::Object ^ sen request.then( [this](pplx::task tsk) { - this->resultLabel->Text = L""; + this->resultLabel->Text.clear(); try { @@ -343,7 +343,7 @@ void BlackjackClient::PlayingTable::DoubleButton_Click(Platform::Object ^ sender request.then( [this](pplx::task tsk) { - this->resultLabel->Text = L""; + this->resultLabel->Text.clear(); try { @@ -378,7 +378,7 @@ void BlackjackClient::PlayingTable::StayButton_Click(Platform::Object ^ sender, request.then( [this](pplx::task tsk) { - this->resultLabel->Text = L""; + this->resultLabel->Text.clear(); try { @@ -412,7 +412,7 @@ void BlackjackClient::PlayingTable::HitButton_Click(Platform::Object ^ sender, request.then( [this](pplx::task tsk) { - this->resultLabel->Text = L""; + this->resultLabel->Text.clear(); try { @@ -449,7 +449,7 @@ void BlackjackClient::PlayingTable::ExitButton_Click(Platform::Object ^ sender, [this](pplx::task tsk) { EnableExit(); - this->resultLabel->Text = L""; + this->resultLabel->Text.clear(); try { @@ -499,7 +499,7 @@ void BlackjackClient::PlayingTable::JoinButton_Click(Platform::Object ^ sender, [this](pplx::task tsk) { EnableExit(); - this->resultLabel->Text = L""; + this->resultLabel->Text.clear(); try { @@ -516,7 +516,7 @@ void BlackjackClient::PlayingTable::JoinButton_Click(Platform::Object ^ sender, { InterpretError(exc.error_code().value()); EnableConnecting(); - _tableId = L""; + _tableId.clear(); } }, ctx); @@ -551,7 +551,7 @@ void BlackjackClient::PlayingTable::LeaveButton_Click(Platform::Object ^ sender, this->resultLabel->Text = L"Thanks for playing!"; - _tableId = L""; + _tableId.clear(); } catch (const http_exception& exc) { diff --git a/Release/samples/BlackJack/BlackJack_UIClient/PlayingTable.xaml.h b/Release/samples/BlackJack/BlackJack_UIClient/PlayingTable.xaml.h index 589c1f9e6c..9f2fbe689a 100644 --- a/Release/samples/BlackJack/BlackJack_UIClient/PlayingTable.xaml.h +++ b/Release/samples/BlackJack/BlackJack_UIClient/PlayingTable.xaml.h @@ -93,7 +93,7 @@ ref class PlayingTable sealed { ClearDealerCards(); ClearPlayerCards(); - resultLabel->Text = ""; + resultLabel->Text.clear(); } void EnableBetting() diff --git a/Release/samples/CasaLens/casalens.cpp b/Release/samples/CasaLens/casalens.cpp index c98e926abf..5990ef240f 100644 --- a/Release/samples/CasaLens/casalens.cpp +++ b/Release/samples/CasaLens/casalens.cpp @@ -30,13 +30,13 @@ const utility::string_t casalens_creds::weather_url = U("http://api.openweatherm // FILL IN THE API KEYS FOR THE DIFFERENT SERVICES HERE. // Refer Readme.txt for details on how to obtain the key for the services. const utility::string_t casalens_creds::events_keyname = U("app_key"); -const utility::string_t casalens_creds::events_key = U(""); +const utility::string_t casalens_creds::events_key; const utility::string_t casalens_creds::movies_keyname = U("api_key"); -const utility::string_t casalens_creds::movies_key = U(""); +const utility::string_t casalens_creds::movies_key; const utility::string_t casalens_creds::images_keyname = U("username"); -const utility::string_t casalens_creds::images_key = U(""); +const utility::string_t casalens_creds::images_key; const utility::string_t casalens_creds::bmaps_keyname = U("key"); -const utility::string_t casalens_creds::bmaps_key = U(""); +const utility::string_t casalens_creds::bmaps_key; const utility::string_t CasaLens::events_json_key = U("events"); const utility::string_t CasaLens::movies_json_key = U("movies"); diff --git a/Release/samples/OAuth2Live/MainPage.xaml.cpp b/Release/samples/OAuth2Live/MainPage.xaml.cpp index acdc7ba4e3..fef5d2d365 100644 --- a/Release/samples/OAuth2Live/MainPage.xaml.cpp +++ b/Release/samples/OAuth2Live/MainPage.xaml.cpp @@ -29,8 +29,8 @@ using namespace web::http::oauth2::experimental; // // NOTE: You must set this Live key and secret for app to work. // -static const utility::string_t s_live_key(U("")); -static const utility::string_t s_live_secret(U("")); +static const utility::string_t s_live_key; +static const utility::string_t s_live_secret; MainPage::MainPage() : m_live_oauth2_config(s_live_key, @@ -69,7 +69,7 @@ void OAuth2Live::MainPage::_GetToken() // Start over, clear tokens and button state. m_live_oauth2_config.set_token(oauth2_token()); - AccessToken->Text = ""; + AccessToken->Text.clear(); _UpdateButtonState(); String ^ authURI = ref new String(m_live_oauth2_config.build_authorization_uri(true).c_str()); diff --git a/Release/samples/Oauth1Client/Oauth1Client.cpp b/Release/samples/Oauth1Client/Oauth1Client.cpp index da09fda29f..dec9b342b5 100644 --- a/Release/samples/Oauth1Client/Oauth1Client.cpp +++ b/Release/samples/Oauth1Client/Oauth1Client.cpp @@ -49,11 +49,11 @@ using namespace web::http::experimental::listener; // // Set key & secret pair to enable session for that service. // -static const utility::string_t s_linkedin_key(U("")); -static const utility::string_t s_linkedin_secret(U("")); +static const utility::string_t s_linkedin_key; +static const utility::string_t s_linkedin_secret; -static const utility::string_t s_twitter_key(U("")); -static const utility::string_t s_twitter_secret(U("")); +static const utility::string_t s_twitter_key; +static const utility::string_t s_twitter_secret; // // Utility method to open browser on Windows, OS X and Linux systems. diff --git a/Release/samples/Oauth2Client/Oauth2Client.cpp b/Release/samples/Oauth2Client/Oauth2Client.cpp index 2d82a70f18..19072cf6c6 100644 --- a/Release/samples/Oauth2Client/Oauth2Client.cpp +++ b/Release/samples/Oauth2Client/Oauth2Client.cpp @@ -49,14 +49,14 @@ using namespace web::http::experimental::listener; // // Set key & secret pair to enable session for that service. // -static const utility::string_t s_dropbox_key(U("")); -static const utility::string_t s_dropbox_secret(U("")); +static const utility::string_t s_dropbox_key; +static const utility::string_t s_dropbox_secret; -static const utility::string_t s_linkedin_key(U("")); -static const utility::string_t s_linkedin_secret(U("")); +static const utility::string_t s_linkedin_key; +static const utility::string_t s_linkedin_secret; -static const utility::string_t s_live_key(U("")); -static const utility::string_t s_live_secret(U("")); +static const utility::string_t s_live_key; +static const utility::string_t s_live_secret; // // Utility method to open browser on Windows, OS X and Linux systems. @@ -89,7 +89,7 @@ class oauth2_code_listener : m_listener(new http_listener(listen_uri)), m_config(config) { m_listener->support([this](http::http_request request) -> void { - if (request.request_uri().path() == U("/") && request.request_uri().query() != U("")) + if (request.request_uri().path() == U("/") && !request.request_uri().query().empty()) { m_resplock.lock(); diff --git a/Release/samples/WindowsLiveAuth/live_connect.h b/Release/samples/WindowsLiveAuth/live_connect.h index c8381df046..325538c84f 100644 --- a/Release/samples/WindowsLiveAuth/live_connect.h +++ b/Release/samples/WindowsLiveAuth/live_connect.h @@ -338,7 +338,7 @@ class live_client web::http::http_request req(web::http::methods::PUT); req.set_request_uri(bldr.to_string()); - req.set_body(stream, content_length, U("")); + req.set_body(stream, content_length, utility::string_t{}); return _make_request(req).then([](web::http::http_response response) { return _json_extract(response); }); } @@ -368,7 +368,7 @@ class live_client web::http::http_request req(web::http::methods::PUT); req.set_request_uri(bldr.to_string()); - req.set_body(stream, size, U("")); + req.set_body(stream, size, utility::string_t{}); return _make_request(req) .then([](web::http::http_response response) { return response.content_ready(); }) diff --git a/Release/src/http/client/http_client.cpp b/Release/src/http/client/http_client.cpp index 41230ea517..f3174272bb 100644 --- a/Release/src/http/client/http_client.cpp +++ b/Release/src/http/client/http_client.cpp @@ -386,7 +386,7 @@ http_client::http_client(const uri& base_uri, const http_client_config& client_c m_pipeline = std::make_shared(std::move(final_pipeline_stage)); -#if !defined(CPPREST_TARGET_XP) +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA add_handler(std::static_pointer_cast( std::make_shared(client_config.oauth1()))); #endif diff --git a/Release/src/http/client/http_client_asio.cpp b/Release/src/http/client/http_client_asio.cpp index c5c815eec7..f8401d6e99 100644 --- a/Release/src/http/client/http_client_asio.cpp +++ b/Release/src/http/client/http_client_asio.cpp @@ -87,8 +87,7 @@ namespace { const std::string CRLF("\r\n"); -std::string calc_cn_host(const web::http::uri& baseUri, - const web::http::http_headers& requestHeaders) +std::string calc_cn_host(const web::http::uri& baseUri, const web::http::http_headers& requestHeaders) { std::string result; if (baseUri.scheme() == U("https")) @@ -905,7 +904,8 @@ class asio_context final : public request_context, public std::enable_shared_fro } }; - // Note that we must not try to CONNECT using an already established connection via proxy -- this would send CONNECT to the end server which is definitely not what we want. + // Note that we must not try to CONNECT using an already established connection via proxy -- this would send + // CONNECT to the end server which is definitely not what we want. if (proxy_type == http_proxy_type::ssl_tunnel && !m_connection->is_reused()) { // The ssl_tunnel_proxy keeps the context alive and then calls back once the ssl tunnel is established via @@ -1234,8 +1234,8 @@ class asio_context final : public request_context, public std::enable_shared_fro } const auto this_request = shared_from_this(); - const auto readSize = static_cast( - std::min(static_cast(m_http_client->client_config().chunksize()), m_content_length - m_uploaded)); + const auto readSize = static_cast((std::min)( + static_cast(m_http_client->client_config().chunksize()), m_content_length - m_uploaded)); auto readbuf = _get_readbuffer(); readbuf.getn(boost::asio::buffer_cast(m_body_buf.prepare(readSize)), readSize) .then([this_request AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task op) { @@ -1487,8 +1487,8 @@ class asio_context final : public request_context, public std::enable_shared_fro if (!needChunked) { async_read_until_buffersize( - static_cast( - std::min(m_content_length, static_cast(m_http_client->client_config().chunksize()))), + static_cast((std::min)(m_content_length, + static_cast(m_http_client->client_config().chunksize()))), boost::bind( &asio_context::handle_read_content, shared_from_this(), boost::asio::placeholders::error)); } @@ -1572,7 +1572,7 @@ class asio_context final : public request_context, public std::enable_shared_fro { if (inbytes) { - output.resize(output.size() + std::max(input_size, static_cast(1024))); + output.resize(output.size() + (std::max)(input_size, static_cast(1024))); } got = m_decompressor->decompress(input + inbytes, input_size - inbytes, @@ -1710,7 +1710,7 @@ class asio_context final : public request_context, public std::enable_shared_fro if (ec) { - if (ec == boost::asio::error::eof && m_content_length == std::numeric_limits::max()) + if (ec == boost::asio::error::eof && m_content_length == (std::numeric_limits::max)()) { m_content_length = m_downloaded + m_body_buf.size(); } @@ -1742,7 +1742,7 @@ class asio_context final : public request_context, public std::enable_shared_fro const auto this_request = shared_from_this(); auto read_size = static_cast( - std::min(static_cast(m_body_buf.size()), m_content_length - m_downloaded)); + (std::min)(static_cast(m_body_buf.size()), m_content_length - m_downloaded)); if (m_decompressor) { @@ -1765,7 +1765,7 @@ class asio_context final : public request_context, public std::enable_shared_fro this_request->m_downloaded += static_cast(read_size); this_request->async_read_until_buffersize( - static_cast(std::min( + static_cast((std::min)( static_cast(this_request->m_http_client->client_config().chunksize()), this_request->m_content_length - this_request->m_downloaded)), boost::bind( @@ -1794,7 +1794,7 @@ class asio_context final : public request_context, public std::enable_shared_fro this_request->m_downloaded += static_cast(read_size); this_request->m_body_buf.consume(read_size); this_request->async_read_until_buffersize( - static_cast(std::min( + static_cast((std::min)( static_cast(this_request->m_http_client->client_config().chunksize()), this_request->m_content_length - this_request->m_downloaded)), boost::bind(&asio_context::handle_read_content, @@ -1820,7 +1820,7 @@ class asio_context final : public request_context, public std::enable_shared_fro this_request->m_downloaded += static_cast(writtenSize); this_request->m_body_buf.consume(writtenSize); this_request->async_read_until_buffersize( - static_cast(std::min( + static_cast((std::min)( static_cast(this_request->m_http_client->client_config().chunksize()), this_request->m_content_length - this_request->m_downloaded)), boost::bind(&asio_context::handle_read_content, diff --git a/Release/src/http/client/http_client_winhttp.cpp b/Release/src/http/client/http_client_winhttp.cpp index 61a13abfb5..a6e5a226b1 100644 --- a/Release/src/http/client/http_client_winhttp.cpp +++ b/Release/src/http/client/http_client_winhttp.cpp @@ -20,7 +20,7 @@ #include #include -#ifndef CPPREST_TARGET_XP +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA #include #endif @@ -102,13 +102,46 @@ static http::status_code parse_status_code(HINTERNET request_handle) // Helper function to trim leading and trailing null characters from a string. static void trim_nulls(utility::string_t& str) { - size_t index; - for (index = 0; index < str.size() && str[index] == 0; ++index) - ; - str.erase(0, index); - for (index = str.size(); index > 0 && str[index - 1] == 0; --index) - ; - str.erase(index); + if (str.empty()) + { + return; + } + + auto first = str.begin(); + auto last = str.end(); + + if (*first) + { + --last; + if (*last) + { + // no nulls to remove + return; + } + + // nulls at the back to remove + do + { + --last; + } while (*last == utility::char_t {}); + ++last; + str.erase(last, str.end()); + return; + } + + // nulls at the front, and maybe the back, to remove + first = std::find_if(str.begin(), last, [](const utility::char_t c) { return c != utility::char_t {}; }); + + if (first != last) + { + do + { + --last; + } while (*last == utility::char_t {}); + ++last; + } + + str.assign(first, last); } // Helper function to get the reason phrase from a WinHTTP response. @@ -245,7 +278,7 @@ class winhttp_request_context final : public request_context HINTERNET m_request_handle; std::weak_ptr* - m_request_handle_context; // owned by m_request_handle to be delete'd by WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING + m_request_handle_context; // owned by m_request_handle to be deleted by WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING bool m_proxy_authentication_tried; bool m_server_authentication_tried; @@ -464,7 +497,7 @@ class winhttp_request_context final : public request_context if (m_bytes_remaining) { // We're at the offset of a chunk of consumable data; let the caller process it - l = std::min(m_bytes_remaining, buffer_size - n); + l = (std::min)(m_bytes_remaining, buffer_size - n); m_bytes_remaining -= l; if (!m_bytes_remaining) { @@ -803,12 +836,12 @@ class winhttp_client final : public _http_client_communicator access_type = WINHTTP_ACCESS_TYPE_DEFAULT_PROXY; proxy_name = WINHTTP_NO_PROXY_NAME; -#ifdef CPPREST_TARGET_XP +#if _WIN32_WINNT < _WIN32_WINNT_VISTA if (config.proxy().is_auto_discovery()) { m_proxy_auto_config = true; } -#else // ^^^ CPPREST_TARGET_XP ^^^ // vvv !CPPREST_TARGET_XP vvv +#else // ^^^ _WIN32_WINNT < _WIN32_WINNT_VISTA ^^^ // vvv _WIN32_WINNT >= _WIN32_WINNT_VISTA vvv if (IsWindows8Point1OrGreater()) { // Windows 8.1 and newer supports automatic proxy discovery and auto-fallback to IE proxy settings @@ -854,7 +887,7 @@ class winhttp_client final : public _http_client_communicator m_proxy_auto_config = true; } } -#endif // CPPREST_TARGET_XP +#endif // _WIN32_WINNT < _WIN32_WINNT_VISTA } else { @@ -908,7 +941,7 @@ class winhttp_client final : public _http_client_communicator } // Enable TLS 1.1 and 1.2 -#if !defined(CPPREST_TARGET_XP) +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA BOOL win32_result(FALSE); DWORD secure_protocols(WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 | @@ -1074,11 +1107,11 @@ class winhttp_client final : public _http_client_communicator if (client_config().validate_certificates()) { // if we are validating certificates, also turn on revocation checking - DWORD dwEnableSSLRevocOpt = WINHTTP_ENABLE_SSL_REVOCATION; + DWORD dwEnableSSLRevocationOpt = WINHTTP_ENABLE_SSL_REVOCATION; if (!WinHttpSetOption(winhttp_context->m_request_handle, WINHTTP_OPTION_ENABLE_FEATURE, - &dwEnableSSLRevocOpt, - sizeof(dwEnableSSLRevocOpt))) + &dwEnableSSLRevocationOpt, + sizeof(dwEnableSSLRevocationOpt))) { auto errorCode = GetLastError(); request->report_error(errorCode, build_error_msg(errorCode, "Error enabling SSL revocation check")); @@ -1134,7 +1167,7 @@ class winhttp_client final : public _http_client_communicator } // There is a request body that needs to be transferred. - if (content_length == std::numeric_limits::max()) + if (content_length == (std::numeric_limits::max)()) { // The content length is not set and the application set a stream. This is an // indication that we will use transfer encoding chunked. We still want to @@ -1315,11 +1348,11 @@ class winhttp_client final : public _http_client_communicator chunk_size = p_request_context->m_body_data.size() - http::details::chunked_encoding::additional_encoding_space; } - else if (p_request_context->m_remaining_to_write != std::numeric_limits::max()) + else if (p_request_context->m_remaining_to_write != (std::numeric_limits::max)()) { // Choose a semi-intelligent size based on how much total data is left to compress - chunk_size = std::min(static_cast(p_request_context->m_remaining_to_write) + 128, - p_request_context->m_http_client->client_config().chunksize()); + chunk_size = (std::min)(static_cast(p_request_context->m_remaining_to_write) + 128, + p_request_context->m_http_client->client_config().chunksize()); } else { @@ -1331,8 +1364,8 @@ class winhttp_client final : public _http_client_communicator { // We're not compressing; use the smaller of the remaining data (if known) and the configured (or default) // chunk size - chunk_size = std::min(static_cast(p_request_context->m_remaining_to_write), - p_request_context->m_http_client->client_config().chunksize()); + chunk_size = (std::min)(static_cast(p_request_context->m_remaining_to_write), + p_request_context->m_http_client->client_config().chunksize()); } p_request_context->allocate_request_space( nullptr, chunk_size + http::details::chunked_encoding::additional_encoding_space); @@ -1370,7 +1403,7 @@ class winhttp_client final : public _http_client_communicator chunk_size + http::details::chunked_encoding::additional_encoding_space, bytes_read); - if (!compressor && p_request_context->m_remaining_to_write != std::numeric_limits::max()) + if (!compressor && p_request_context->m_remaining_to_write != (std::numeric_limits::max)()) { if (bytes_read == 0 && p_request_context->m_remaining_to_write) { @@ -1465,7 +1498,7 @@ class winhttp_client final : public _http_client_communicator p_request_context->m_compression_state.m_bytes_read) { if (p_request_context->m_remaining_to_write && - p_request_context->m_remaining_to_write != std::numeric_limits::max()) + p_request_context->m_remaining_to_write != (std::numeric_limits::max)()) { // The stream ended earlier than we detected it should return pplx::task_from_exception(http_exception( @@ -1518,7 +1551,7 @@ class winhttp_client final : public _http_client_communicator p_request_context->m_compression_state.m_bytes_processed += r.input_bytes_processed; _ASSERTE(p_request_context->m_compression_state.m_bytes_processed <= p_request_context->m_compression_state.m_bytes_read); - if (p_request_context->m_remaining_to_write != std::numeric_limits::max()) + if (p_request_context->m_remaining_to_write != (std::numeric_limits::max)()) { _ASSERTE(p_request_context->m_remaining_to_write >= r.input_bytes_processed); p_request_context->m_remaining_to_write -= r.input_bytes_processed; @@ -1568,7 +1601,7 @@ class winhttp_client final : public _http_client_communicator return; } else if (p_request_context->m_remaining_to_write && - p_request_context->m_remaining_to_write != std::numeric_limits::max()) + p_request_context->m_remaining_to_write != (std::numeric_limits::max)()) { // Unexpected end-of-stream. p_request_context->report_error(GetLastError(), @@ -1586,8 +1619,8 @@ class winhttp_client final : public _http_client_communicator } else { - length = std::min(static_cast(p_request_context->m_remaining_to_write), - p_request_context->m_http_client->client_config().chunksize()); + length = (std::min)(static_cast(p_request_context->m_remaining_to_write), + p_request_context->m_http_client->client_config().chunksize()); if (p_request_context->m_compression_state.m_buffer.capacity() < length) { p_request_context->m_compression_state.m_buffer.reserve(length); @@ -1842,7 +1875,7 @@ class winhttp_client final : public _http_client_communicator if (content_length > 0) { // There is a request body that needs to be transferred. - if (content_length == std::numeric_limits::max()) + if (content_length == (std::numeric_limits::max)()) { // The content length is unknown and the application set a stream. This is an // indication that we will need to chunk the data. @@ -1873,7 +1906,7 @@ class winhttp_client final : public _http_client_communicator static void CALLBACK completion_callback( HINTERNET hRequestHandle, DWORD_PTR context, DWORD statusCode, _In_ void* statusInfo, DWORD statusInfoLength) { - CASABLANCA_UNREFERENCED_PARAMETER(statusInfoLength); + (void)statusInfoLength; std::weak_ptr* p_weak_request_context = reinterpret_cast*>(context); @@ -2208,8 +2241,8 @@ class winhttp_client final : public _http_client_communicator if (p_request_context->m_decompressor) { - size_t chunk_size = std::max(static_cast(bytesRead), - p_request_context->m_http_client->client_config().chunksize()); + size_t chunk_size = (std::max)(static_cast(bytesRead), + p_request_context->m_http_client->client_config().chunksize()); p_request_context->m_compression_state.m_bytes_read = static_cast(bytesRead); p_request_context->m_compression_state.m_chunk_bytes = 0; @@ -2396,24 +2429,23 @@ class winhttp_client final : public _http_client_communicator return keep_going(p_request_context.get()); }); }); - }) - .then([p_request_context](pplx::task op) { - try - { - bool ignored = op.get(); - } - catch (...) + }).then([p_request_context](pplx::task op) { + try + { + bool ignored = op.get(); + } + catch (...) + { + // We're only here to pick up any exception that may have been thrown, and to clean up + // if needed + if (p_request_context->m_compression_state.m_acquired) { - // We're only here to pick up any exception that may have been thrown, and to clean up - // if needed - if (p_request_context->m_compression_state.m_acquired) - { - p_request_context->_get_writebuffer().commit(0); - p_request_context->m_compression_state.m_acquired = nullptr; - } - p_request_context->report_exception(std::current_exception()); + p_request_context->_get_writebuffer().commit(0); + p_request_context->m_compression_state.m_acquired = nullptr; } - }); + p_request_context->report_exception(std::current_exception()); + } + }); } else { diff --git a/Release/src/http/client/http_client_winrt.cpp b/Release/src/http/client/http_client_winrt.cpp index 294227512d..a95d9b3431 100644 --- a/Release/src/http/client/http_client_winrt.cpp +++ b/Release/src/http/client/http_client_winrt.cpp @@ -188,7 +188,7 @@ class IRequestStream final { public: IRequestStream(const std::weak_ptr& context, - size_t read_length = std::numeric_limits::max()) + size_t read_length = (std::numeric_limits::max)()) : m_context(context), m_read_length(read_length) { // read_length is the initial length of the ISequentialStream that is available for read @@ -253,9 +253,9 @@ class IRequestStream final _In_ ULONG cb, _Out_opt_ ULONG* pcbWritten) { - CASABLANCA_UNREFERENCED_PARAMETER(pv); - CASABLANCA_UNREFERENCED_PARAMETER(cb); - CASABLANCA_UNREFERENCED_PARAMETER(pcbWritten); + (void)pv; + (void)cb; + (void)pcbWritten; return E_NOTIMPL; } @@ -345,9 +345,9 @@ class IResponseStream final _In_ ULONG cb, _Out_ ULONG* pcbRead) { - CASABLANCA_UNREFERENCED_PARAMETER(pv); - CASABLANCA_UNREFERENCED_PARAMETER(cb); - CASABLANCA_UNREFERENCED_PARAMETER(pcbRead); + (void)pv; + (void)cb; + (void)pcbRead; return E_NOTIMPL; } @@ -403,7 +403,7 @@ class winrt_client final : public _http_client_communicator } const size_t content_length = msg._get_impl()->_get_content_length(); - if (content_length == std::numeric_limits::max()) + if (content_length == (std::numeric_limits::max)()) { // IXHR2 does not allow transfer encoding chunked. So the user is expected to set the content length request->report_exception(http_exception(L"Content length is not specified in the http headers")); @@ -478,7 +478,7 @@ class winrt_client final : public _http_client_communicator // Set timeout. ULONGLONG timeout = static_cast(config.timeout().count()); - timeout = std::max(timeout, std::numeric_limits::min() + 1); + timeout = (std::max)(timeout, (std::numeric_limits::min)() + 1); hr = winrt_context->m_hRequest->SetProperty(XHR_PROP_TIMEOUT, timeout); if (FAILED(hr)) { diff --git a/Release/src/http/common/http_compression.cpp b/Release/src/http/common/http_compression.cpp index 691914488a..a65adc2468 100644 --- a/Release/src/http/common/http_compression.cpp +++ b/Release/src/http/common/http_compression.cpp @@ -97,7 +97,7 @@ class zlib_compressor_base : public compress_provider #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wtautological-constant-compare" #endif // __clang__ - if (input_size > std::numeric_limits::max() || output_size > std::numeric_limits::max()) + if (input_size > (std::numeric_limits::max)() || output_size > (std::numeric_limits::max)()) #if defined(__clang__) #pragma clang diagnostic pop #endif // __clang__ @@ -198,7 +198,7 @@ class zlib_decompressor_base : public decompress_provider #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wtautological-constant-compare" #endif // __clang__ - if (input_size > std::numeric_limits::max() || output_size > std::numeric_limits::max()) + if (input_size > (std::numeric_limits::max)() || output_size > (std::numeric_limits::max)()) #if defined(__clang__) #pragma clang diagnostic pop #endif // __clang__ diff --git a/Release/src/http/common/http_msg.cpp b/Release/src/http/common/http_msg.cpp index 50332fd1e9..c32dfcfaaa 100644 --- a/Release/src/http/common/http_msg.cpp +++ b/Release/src/http/common/http_msg.cpp @@ -287,11 +287,7 @@ static const utility::char_t* stream_was_set_explicitly = static const utility::char_t* unsupported_charset = _XPLATSTR("Charset must be iso-8859-1, utf-8, utf-16, utf-16le, or utf-16be to be extracted."); -http_msg_base::http_msg_base() - : m_http_version(http::http_version{ 0, 0 }) - , m_headers() - , m_default_outstream(false) -{} +http_msg_base::http_msg_base() : m_http_version(http::http_version {0, 0}), m_headers(), m_default_outstream(false) {} void http_msg_base::_prepare_to_receive_data() { @@ -326,7 +322,7 @@ size_t http_msg_base::_get_stream_length() return static_cast(end - offset); } - return std::numeric_limits::max(); + return (std::numeric_limits::max)(); } size_t http_msg_base::_get_content_length(bool honor_compression) @@ -356,7 +352,7 @@ size_t http_msg_base::_get_content_length(bool honor_compression) } } - return std::numeric_limits::max(); + return (std::numeric_limits::max)(); } if (honor_compression && m_compressor) @@ -365,7 +361,7 @@ size_t http_msg_base::_get_content_length(bool honor_compression) // up front for content encoding. We return the uncompressed length if we can figure it out. headers().add(header_names::transfer_encoding, m_compressor->algorithm()); headers().add(header_names::transfer_encoding, _XPLATSTR("chunked")); - return std::numeric_limits::max(); + return (std::numeric_limits::max)(); } if (headers().match(header_names::content_length, content_length)) @@ -376,7 +372,7 @@ size_t http_msg_base::_get_content_length(bool honor_compression) } content_length = _get_stream_length(); - if (content_length != std::numeric_limits::max()) + if (content_length != (std::numeric_limits::max)()) { // The content length wasn't explicitly set, but we figured it out; // use it, since sending this way is more efficient than chunking @@ -386,7 +382,7 @@ size_t http_msg_base::_get_content_length(bool honor_compression) // We don't know the content length; we'll chunk the stream headers().add(header_names::transfer_encoding, _XPLATSTR("chunked")); - return std::numeric_limits::max(); + return (std::numeric_limits::max)(); } // There is no content diff --git a/Release/src/http/listener/http_server_asio.cpp b/Release/src/http/listener/http_server_asio.cpp index 96a24f6be6..f1d8c819c5 100644 --- a/Release/src/http/listener/http_server_asio.cpp +++ b/Release/src/http/listener/http_server_asio.cpp @@ -175,7 +175,7 @@ class hostport_listener auto path_segments = uri::split_path(uri::decode(u.path())); for (auto i = static_cast(path_segments.size()); i >= 0; --i) { - std::string path = ""; + std::string path; for (size_t j = 0; j < static_cast(i); ++j) { path += "/" + utility::conversions::to_utf8string(path_segments[j]); @@ -520,9 +520,9 @@ void hostport_listener::start() auto& service = crossplat::threadpool::shared_instance().service(); tcp::resolver resolver(service); // #446: boost resolver does not recognize "+" as a host wildchar - tcp::resolver::query query = ("+" == m_host) ? - tcp::resolver::query(m_port, boost::asio::ip::resolver_query_base::flags()) : - tcp::resolver::query(m_host, m_port, boost::asio::ip::resolver_query_base::flags()); + tcp::resolver::query query = + ("+" == m_host) ? tcp::resolver::query(m_port, boost::asio::ip::resolver_query_base::flags()) + : tcp::resolver::query(m_host, m_port, boost::asio::ip::resolver_query_base::flags()); tcp::endpoint endpoint = *resolver.resolve(query); @@ -828,7 +828,7 @@ will_deref_and_erase_t asio_server_connection::handle_headers() m_read = 0; ++m_refs; async_read_until_buffersize( - std::min(ChunkSize, m_read_size), + (std::min)(ChunkSize, m_read_size), [this](const boost::system::error_code& ec, size_t) { (will_deref_t) this->handle_body(ec); }); } @@ -910,7 +910,7 @@ will_deref_t asio_server_connection::handle_body(const boost::system::error_code auto writebuf = requestImpl->outstream().streambuf(); writebuf .putn_nocopy(boost::asio::buffer_cast(m_request_buf.data()), - std::min(m_request_buf.size(), m_read_size - m_read)) + (std::min)(m_request_buf.size(), m_read_size - m_read)) .then([this](pplx::task writtenSizeTask) -> will_deref_t { size_t writtenSize = 0; try @@ -926,7 +926,7 @@ will_deref_t asio_server_connection::handle_body(const boost::system::error_code m_request_buf.consume(writtenSize); async_read_until_buffersize( - std::min(ChunkSize, m_read_size - m_read), + (std::min)(ChunkSize, m_read_size - m_read), [this](const boost::system::error_code& ec, size_t) { (will_deref_t) this->handle_body(ec); }); return will_deref_t {}; }); @@ -1162,7 +1162,7 @@ will_deref_and_erase_t asio_server_connection::handle_write_large_response(const if (readbuf.is_eof()) return cancel_sending_response_with_error( response, std::make_exception_ptr(http_exception("Response stream close early!"))); - size_t readBytes = std::min(ChunkSize, m_write_size - m_write); + size_t readBytes = (std::min)(ChunkSize, m_write_size - m_write); readbuf.getn(buffer_cast(m_response_buf.prepare(readBytes)), readBytes) .then([=](pplx::task actualSizeTask) -> will_deref_and_erase_t { size_t actualSize = 0; diff --git a/Release/src/http/listener/http_server_httpsys.cpp b/Release/src/http/listener/http_server_httpsys.cpp index 49d83fe874..d4c080a76b 100644 --- a/Release/src/http/listener/http_server_httpsys.cpp +++ b/Release/src/http/listener/http_server_httpsys.cpp @@ -155,7 +155,7 @@ void parse_http_headers(const HTTP_REQUEST_HEADERS& headers, http::http_headers& } else { - msgHeaders[unknown_header_name] = U(""); + msgHeaders[unknown_header_name].clear(); } } for (int i = 0; i < HttpHeaderMaximum; ++i) @@ -976,10 +976,10 @@ void windows_request_context::async_process_response() // OK, so we need to chunk it up. _ASSERTE(content_length > 0); - m_sending_in_chunks = (content_length != std::numeric_limits::max()); - m_transfer_encoding = (content_length == std::numeric_limits::max()); + m_sending_in_chunks = (content_length != (std::numeric_limits::max)()); + m_transfer_encoding = (content_length == (std::numeric_limits::max)()); m_remaining_to_write = content_length; - if (content_length == std::numeric_limits::max()) + if (content_length == (std::numeric_limits::max)()) { // Attempt to figure out the remaining length of the input stream m_remaining_to_write = m_response._get_impl()->_get_stream_length(); diff --git a/Release/src/http/listener/http_server_httpsys.h b/Release/src/http/listener/http_server_httpsys.h index d998619bbe..40c2a5e9ab 100644 --- a/Release/src/http/listener/http_server_httpsys.h +++ b/Release/src/http/listener/http_server_httpsys.h @@ -58,9 +58,9 @@ class http_overlapped : public OVERLAPPED ULONG_PTR numberOfBytesTransferred, PTP_IO io) { - CASABLANCA_UNREFERENCED_PARAMETER(io); - CASABLANCA_UNREFERENCED_PARAMETER(context); - CASABLANCA_UNREFERENCED_PARAMETER(instance); + (void)io; + (void)context; + (void)instance; http_overlapped* p_http_overlapped = (http_overlapped*)pOverlapped; p_http_overlapped->m_http_io_completion(result, (DWORD)numberOfBytesTransferred); diff --git a/Release/src/http/oauth/oauth1.cpp b/Release/src/http/oauth/oauth1.cpp index 0e973aa401..b313cfcdb3 100644 --- a/Release/src/http/oauth/oauth1.cpp +++ b/Release/src/http/oauth/oauth1.cpp @@ -15,7 +15,7 @@ #include "cpprest/asyncrt_utils.h" -#if !defined(CPPREST_TARGET_XP) +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA using namespace utility; using web::http::client::http_client; @@ -455,4 +455,4 @@ const oauth1_token& oauth1_config::token() const } // namespace http } // namespace web -#endif +#endif // _WIN32_WINNT >= _WIN32_WINNT_VISTA diff --git a/Release/src/json/json.cpp b/Release/src/json/json.cpp index 7b61a179cc..7614866acc 100644 --- a/Release/src/json/json.cpp +++ b/Release/src/json/json.cpp @@ -286,8 +286,9 @@ bool web::json::number::is_int32() const switch (m_type) { case signed_type: - return m_intval >= std::numeric_limits::min() && m_intval <= std::numeric_limits::max(); - case unsigned_type: return m_uintval <= std::numeric_limits::max(); + return m_intval >= (std::numeric_limits::min)() && + m_intval <= (std::numeric_limits::max)(); + case unsigned_type: return m_uintval <= (std::numeric_limits::max)(); case double_type: default: return false; } @@ -297,8 +298,8 @@ bool web::json::number::is_uint32() const { switch (m_type) { - case signed_type: return m_intval >= 0 && m_intval <= std::numeric_limits::max(); - case unsigned_type: return m_uintval <= std::numeric_limits::max(); + case signed_type: return m_intval >= 0 && m_intval <= (std::numeric_limits::max)(); + case unsigned_type: return m_uintval <= (std::numeric_limits::max)(); case double_type: default: return false; } @@ -309,7 +310,7 @@ bool web::json::number::is_int64() const switch (m_type) { case signed_type: return true; - case unsigned_type: return m_uintval <= static_cast(std::numeric_limits::max()); + case unsigned_type: return m_uintval <= static_cast((std::numeric_limits::max)()); case double_type: default: return false; } diff --git a/Release/src/pch/stdafx.h b/Release/src/pch/stdafx.h index d999befe5b..2061bea7f6 100644 --- a/Release/src/pch/stdafx.h +++ b/Release/src/pch/stdafx.h @@ -20,32 +20,29 @@ #endif #ifdef _WIN32 -#define NOMINMAX -#ifdef CPPREST_TARGET_XP -#include -#ifndef _WIN32_WINNT -#define _WIN32_WINNT _WIN32_WINNT_WS03 // Windows XP with SP2 -#endif -#endif -#include // use the debug version of the CRT if _DEBUG is defined #ifdef _DEBUG #define _CRTDBG_MAP_ALLOC #include -#include -#endif +#endif // _DEBUG +#include #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers + +#if CPPREST_TARGET_XP && _WIN32_WINNT != 0x0501 +#error CPPREST_TARGET_XP implies _WIN32_WINNT == 0x0501 +#endif // CPPREST_TARGET_XP && _WIN32_WINNT != 0x0501 + #include #include // Windows Header Files: -#if !defined(__cplusplus_winrt) +#ifndef __cplusplus_winrt #include +#endif !__cplusplus_winrt -#endif // #if !defined(__cplusplus_winrt) -#else // LINUX or APPLE +#else // LINUX or APPLE #define __STDC_LIMIT_MACROS #include "pthread.h" #include @@ -84,6 +81,7 @@ #include #include #include +#include #include // json diff --git a/Release/src/streams/fileio_posix.cpp b/Release/src/streams/fileio_posix.cpp index 013d910d44..2404196423 100644 --- a/Release/src/streams/fileio_posix.cpp +++ b/Release/src/streams/fileio_posix.cpp @@ -375,7 +375,7 @@ size_t _fill_buffer_fsb(_file_info_impl* fInfo, _filestream_callback* callback, size_t byteCount = count * charSize; if (fInfo->m_buffer == nullptr) { - fInfo->m_bufsize = std::max(PageSize, byteCount); + fInfo->m_bufsize = (std::max)(PageSize, byteCount); fInfo->m_buffer = new char[static_cast(fInfo->m_bufsize)]; fInfo->m_bufoff = fInfo->m_rdpos; @@ -396,7 +396,7 @@ size_t _fill_buffer_fsb(_file_info_impl* fInfo, _filestream_callback* callback, if (bufrem < count) { - fInfo->m_bufsize = std::max(PageSize, byteCount); + fInfo->m_bufsize = (std::max)(PageSize, byteCount); // Then, we allocate a new buffer. @@ -456,7 +456,7 @@ size_t _getn_fsb(Concurrency::streams::details::_file_info* info, if (fInfo->m_buffer_reads) { auto cb = create_callback(fInfo, callback, [=](size_t read) { - auto copy = std::min(read, byteCount); + auto copy = (std::min)(read, byteCount); auto bufoff = fInfo->m_rdpos - fInfo->m_bufoff; memcpy(ptr, fInfo->m_buffer + bufoff * charSize, copy); fInfo->m_atend = copy < byteCount; @@ -467,7 +467,7 @@ size_t _getn_fsb(Concurrency::streams::details::_file_info* info, if (static_cast(read) > 0) { - auto copy = std::min(read, byteCount); + auto copy = (std::min)(read, byteCount); auto bufoff = fInfo->m_rdpos - fInfo->m_bufoff; memcpy(ptr, fInfo->m_buffer + bufoff * charSize, copy); fInfo->m_atend = copy < byteCount; diff --git a/Release/src/streams/fileio_win32.cpp b/Release/src/streams/fileio_win32.cpp index 86b5bd1ddc..97cd6e5e6d 100644 --- a/Release/src/streams/fileio_win32.cpp +++ b/Release/src/streams/fileio_win32.cpp @@ -105,9 +105,9 @@ void CALLBACK IoCompletionCallback(PTP_CALLBACK_INSTANCE instance, ULONG_PTR numberOfBytesTransferred, PTP_IO io) { - CASABLANCA_UNREFERENCED_PARAMETER(io); - CASABLANCA_UNREFERENCED_PARAMETER(ctxt); - CASABLANCA_UNREFERENCED_PARAMETER(instance); + (void)io; + (void)ctxt; + (void)instance; EXTENDED_OVERLAPPED* pExtOverlapped = static_cast(pOverlapped); pExtOverlapped->func(result, static_cast(numberOfBytesTransferred), static_cast(pOverlapped)); diff --git a/Release/src/uri/uri.cpp b/Release/src/uri/uri.cpp index 92781f67a8..3f2414af2c 100644 --- a/Release/src/uri/uri.cpp +++ b/Release/src/uri/uri.cpp @@ -734,7 +734,7 @@ std::map uri::split_query(const utility::s else if (equals_index == 0) { utility::string_t value(key_value_pair.begin() + equals_index + 1, key_value_pair.end()); - results[_XPLATSTR("")] = value; + results[utility::string_t {}] = value; } else { diff --git a/Release/src/utilities/web_utilities.cpp b/Release/src/utilities/web_utilities.cpp index 9316f41f4f..ce00078b79 100644 --- a/Release/src/utilities/web_utilities.cpp +++ b/Release/src/utilities/web_utilities.cpp @@ -27,8 +27,9 @@ namespace web { namespace details { -#if defined(_WIN32) && !defined(CPPREST_TARGET_XP) -#if defined(__cplusplus_winrt) +#ifdef _WIN32 +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA +#ifdef __cplusplus_winrt // Helper function to zero out memory of an IBuffer. void winrt_secure_zero_buffer(Windows::Storage::Streams::IBuffer ^ buffer) @@ -88,7 +89,7 @@ plaintext_string winrt_encryption::decrypt() const return std::move(data); } -#else +#else // ^^^ __cplusplus_winrt ^^^ // vvv !__cplusplus_winrt vvv win32_encryption::win32_encryption(const std::wstring& data) : m_numCharacters(data.size()) { @@ -141,13 +142,14 @@ plaintext_string win32_encryption::decrypt() const return result; } -#endif -#endif +#endif // __cplusplus_winrt +#endif // _WIN32_WINNT >= _WIN32_WINNT_VISTA +#endif // _WIN32 void zero_memory_deleter::operator()(::utility::string_t* data) const { - CASABLANCA_UNREFERENCED_PARAMETER(data); -#if defined(_WIN32) + (void)data; +#ifdef _WIN32 SecureZeroMemory(&(*data)[0], data->size() * sizeof(::utility::string_t::value_type)); delete data; #endif diff --git a/Release/src/websockets/client/ws_client.cpp b/Release/src/websockets/client/ws_client.cpp index f768e968fb..48a40797e6 100644 --- a/Release/src/websockets/client/ws_client.cpp +++ b/Release/src/websockets/client/ws_client.cpp @@ -51,8 +51,7 @@ void websocket_client_task_impl::set_handler() }); m_callback_client->set_close_handler( - [=](websocket_close_status status, const utility::string_t& reason, const std::error_code& error_code) { - CASABLANCA_UNREFERENCED_PARAMETER(status); + [=](websocket_close_status, const utility::string_t& reason, const std::error_code& error_code) { close_pending_tasks_with_error(websocket_exception(error_code, reason)); }); } diff --git a/Release/src/websockets/client/ws_client_winrt.cpp b/Release/src/websockets/client/ws_client_winrt.cpp index 291ba8ce8a..6bb4351cee 100644 --- a/Release/src/websockets/client/ws_client_winrt.cpp +++ b/Release/src/websockets/client/ws_client_winrt.cpp @@ -404,7 +404,7 @@ class winrt_callback_client : public websocket_client_callback_impl, return close(websocket_close_status::normal, _XPLATSTR("Normal")); } - pplx::task close(websocket_close_status status, const utility::string_t& strreason = _XPLATSTR("")) + pplx::task close(websocket_close_status status, const utility::string_t& strreason = {}) { // Send a close frame to the server m_msg_websocket->Close(static_cast(status), Platform::StringReference(strreason.c_str())); diff --git a/Release/src/websockets/client/ws_client_wspp.cpp b/Release/src/websockets/client/ws_client_wspp.cpp index 26fa547d5d..ef9c1d0bd3 100644 --- a/Release/src/websockets/client/ws_client_wspp.cpp +++ b/Release/src/websockets/client/ws_client_wspp.cpp @@ -325,34 +325,32 @@ class wspp_callback_client : public websocket_client_callback_impl, } }); - client.set_ping_handler( - [this](websocketpp::connection_hdl, const std::string& msg) { - if (m_external_message_handler) - { - _ASSERTE(m_state >= CONNECTED && m_state < CLOSED); - websocket_incoming_message incoming_msg; + client.set_ping_handler([this](websocketpp::connection_hdl, const std::string& msg) { + if (m_external_message_handler) + { + _ASSERTE(m_state >= CONNECTED && m_state < CLOSED); + websocket_incoming_message incoming_msg; - incoming_msg.m_msg_type = websocket_message_type::ping; - incoming_msg.m_body = concurrency::streams::container_buffer(msg); + incoming_msg.m_msg_type = websocket_message_type::ping; + incoming_msg.m_body = concurrency::streams::container_buffer(msg); - m_external_message_handler(incoming_msg); - } - return true; - }); + m_external_message_handler(incoming_msg); + } + return true; + }); - client.set_pong_handler( - [this](websocketpp::connection_hdl, const std::string& msg) { - if (m_external_message_handler) - { - _ASSERTE(m_state >= CONNECTED && m_state < CLOSED); - websocket_incoming_message incoming_msg; + client.set_pong_handler([this](websocketpp::connection_hdl, const std::string& msg) { + if (m_external_message_handler) + { + _ASSERTE(m_state >= CONNECTED && m_state < CLOSED); + websocket_incoming_message incoming_msg; - incoming_msg.m_msg_type = websocket_message_type::pong; - incoming_msg.m_body = concurrency::streams::container_buffer(msg); + incoming_msg.m_msg_type = websocket_message_type::pong; + incoming_msg.m_body = concurrency::streams::container_buffer(msg); - m_external_message_handler(incoming_msg); - } - }); + m_external_message_handler(incoming_msg); + } + }); client.set_close_handler([this](websocketpp::connection_hdl con_hdl) { _ASSERTE(m_state != CLOSED); @@ -469,7 +467,8 @@ class wspp_callback_client : public websocket_client_callback_impl, } const auto length = msg.m_length; - if (length == 0 && msg.m_msg_type != websocket_message_type::ping && msg.m_msg_type != websocket_message_type::pong) + if (length == 0 && msg.m_msg_type != websocket_message_type::ping && + msg.m_msg_type != websocket_message_type::pong) { return pplx::task_from_exception(websocket_exception("Cannot send empty message.")); } diff --git a/Release/tests/common/TestRunner/test_runner.cpp b/Release/tests/common/TestRunner/test_runner.cpp index 4d1a8d39f9..9a356a9b0f 100644 --- a/Release/tests/common/TestRunner/test_runner.cpp +++ b/Release/tests/common/TestRunner/test_runner.cpp @@ -238,7 +238,7 @@ static int parse_command_line(int argc, char** argv) } else { - UnitTest::GlobalSettings::Add(arg.substr(1), ""); + UnitTest::GlobalSettings::Add(arg.substr(1), std::string{}); } } else if (arg.find("/debug") == 0) @@ -262,9 +262,9 @@ static bool matched_properties(const UnitTest::TestProperties& test_props) // This starts with visual studio versions after VS 2012. #if defined(_MSC_VER) && (_MSC_VER >= 1800) #ifdef WINRT_TEST_RUNNER - UnitTest::GlobalSettings::Add("winrt", ""); + UnitTest::GlobalSettings::Add("winrt", std::string{}); #elif defined DESKTOP_TEST_RUNNER - UnitTest::GlobalSettings::Add("desktop", ""); + UnitTest::GlobalSettings::Add("desktop", std::string{}); #endif #endif diff --git a/Release/tests/common/UnitTestpp/src/Checks.h b/Release/tests/common/UnitTestpp/src/Checks.h index 4425fed100..f4494069b3 100644 --- a/Release/tests/common/UnitTestpp/src/Checks.h +++ b/Release/tests/common/UnitTestpp/src/Checks.h @@ -103,7 +103,7 @@ struct BuildFailureStringImpl std::string BuildString(const char*, const char*, const T1&, const T2&) { // Don't do anything since operator<< isn't supported. - return ""; + return std::string{}; } }; diff --git a/Release/tests/common/UnitTestpp/src/DeferredTestResult.cpp b/Release/tests/common/UnitTestpp/src/DeferredTestResult.cpp index 5800eeb6f1..703031f9fc 100644 --- a/Release/tests/common/UnitTestpp/src/DeferredTestResult.cpp +++ b/Release/tests/common/UnitTestpp/src/DeferredTestResult.cpp @@ -54,12 +54,12 @@ DeferredTestFailure::DeferredTestFailure(int lineNumber_, const char* failureStr } DeferredTestResult::DeferredTestResult() - : suiteName(""), testName(""), failureFile(""), timeElapsed(0.0f), failed(false) + : suiteName(), testName(), failureFile(), timeElapsed(0.0f), failed(false) { } -DeferredTestResult::DeferredTestResult(char const* suite, char const* test) - : suiteName(suite), testName(test), failureFile(""), timeElapsed(0.0f), failed(false) +DeferredTestResult::DeferredTestResult(char const* const suite, char const* const test) + : suiteName(suite), testName(test), failureFile(), timeElapsed(0.0f), failed(false) { } diff --git a/Release/tests/common/UnitTestpp/src/MemoryOutStream.cpp b/Release/tests/common/UnitTestpp/src/MemoryOutStream.cpp index c16845efb8..a0da2e4868 100644 --- a/Release/tests/common/UnitTestpp/src/MemoryOutStream.cpp +++ b/Release/tests/common/UnitTestpp/src/MemoryOutStream.cpp @@ -174,7 +174,7 @@ void MemoryOutStream::GrowBuffer(int const desiredCapacity) if (m_buffer) strcpy(buffer, m_buffer); else - strcpy(buffer, ""); + *buffer = '\0'; delete[] m_buffer; m_buffer = buffer; diff --git a/Release/tests/common/UnitTestpp/src/stdafx.h b/Release/tests/common/UnitTestpp/src/stdafx.h index 14b38623cb..99e91a15ee 100644 --- a/Release/tests/common/UnitTestpp/src/stdafx.h +++ b/Release/tests/common/UnitTestpp/src/stdafx.h @@ -49,6 +49,5 @@ #ifdef WIN32 #define WIN32_LEAN_AND_MEAN -#define NOMINMAX #include #endif \ No newline at end of file diff --git a/Release/tests/common/utilities/os_utilities.cpp b/Release/tests/common/utilities/os_utilities.cpp index de2a06d9fb..12aa4be6ef 100644 --- a/Release/tests/common/utilities/os_utilities.cpp +++ b/Release/tests/common/utilities/os_utilities.cpp @@ -12,7 +12,6 @@ #include "os_utilities.h" #ifdef WIN32 -#define NOMINMAX #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include diff --git a/Release/tests/functional/http/client/compression_tests.cpp b/Release/tests/functional/http/client/compression_tests.cpp index 128006431b..1ccb740fab 100644 --- a/Release/tests/functional/http/client/compression_tests.cpp +++ b/Release/tests/functional/http/client/compression_tests.cpp @@ -73,7 +73,7 @@ SUITE(compression_tests) << " / " << _size; throw std::runtime_error(std::move(ss.str())); } - bytes = std::min(input_size, output_size); + bytes = (std::min)(input_size, output_size); if (bytes) { memcpy(output, input, bytes); @@ -128,7 +128,7 @@ SUITE(compression_tests) << " / " << _size; throw std::runtime_error(std::move(ss.str())); } - bytes = std::min(input_size, output_size); + bytes = (std::min)(input_size, output_size); if (bytes) { memcpy(output, input, bytes); @@ -218,18 +218,18 @@ SUITE(compression_tests) if (csize == cmpsize) { // extend the output buffer if there may be more compressed bytes to retrieve - cmpsize += std::min(chunk_size, (size_t)200); + cmpsize += (std::min)(chunk_size, (size_t)200); cmp_buffer.resize(cmpsize); } r = compressor ->compress(input_buffer.data() + i, - std::min(chunk_size, buffer_size - i), + (std::min)(chunk_size, buffer_size - i), cmp_buffer.data() + csize, - std::min(chunk_size, cmpsize - csize), + (std::min)(chunk_size, cmpsize - csize), hint) .get(); - VERIFY_IS_TRUE(r.input_bytes_processed == std::min(chunk_size, buffer_size - i) || - r.output_bytes_produced == std::min(chunk_size, cmpsize - csize)); + VERIFY_IS_TRUE(r.input_bytes_processed == (std::min)(chunk_size, buffer_size - i) || + r.output_bytes_produced == (std::min)(chunk_size, cmpsize - csize)); VERIFY_IS_TRUE(hint == operation_hint::is_last || !r.done); chunk_sizes.push_back(r.output_bytes_produced); csize += r.output_bytes_produced; @@ -262,7 +262,7 @@ SUITE(compression_tests) ->decompress(cmp_buffer.data() + nn, *it, dcmp_buffer.data() + dsize, - std::min(chunk_size, buffer_size - dsize), + (std::min)(chunk_size, buffer_size - dsize), hint) .get(); nn += *it; @@ -281,14 +281,14 @@ SUITE(compression_tests) memset(dcmp_buffer.data(), 0, dcmp_buffer.size()); do { - size_t n = std::min(chunk_size, csize - nn); + size_t n = (std::min)(chunk_size, csize - nn); do { r = decompressor ->decompress(cmp_buffer.data() + nn, n, dcmp_buffer.data() + dsize, - std::min(chunk_size, buffer_size - dsize), + (std::min)(chunk_size, buffer_size - dsize), operation_hint::has_more) .get(); dsize += r.output_bytes_produced; @@ -770,7 +770,7 @@ SUITE(compression_tests) } #endif // _WIN32 - auto extra_size = [](size_t bufsz) -> size_t { return std::max(static_cast(128), bufsz / 1000); }; + auto extra_size = [](size_t bufsz) -> size_t { return (std::max)(static_cast(128), bufsz / 1000); }; // Test decompression both explicitly through the test server and implicitly through the listener; // this is the top-level loop in order to avoid thrashing the listeners more than necessary diff --git a/Release/tests/functional/http/client/outside_tests.cpp b/Release/tests/functional/http/client/outside_tests.cpp index 41709bc3a1..3ff1a809ec 100644 --- a/Release/tests/functional/http/client/outside_tests.cpp +++ b/Release/tests/functional/http/client/outside_tests.cpp @@ -352,7 +352,7 @@ SUITE(outside_tests) throw; } #else - CASABLANCA_UNREFERENCED_PARAMETER(e); + (void)e; throw; #endif os_utilities::sleep(1000); diff --git a/Release/tests/functional/http/utilities/stdafx.h b/Release/tests/functional/http/utilities/stdafx.h index 9ce41e4b72..23e69e4535 100644 --- a/Release/tests/functional/http/utilities/stdafx.h +++ b/Release/tests/functional/http/utilities/stdafx.h @@ -13,7 +13,6 @@ #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN -#define NOMINMAX #include #include diff --git a/Release/tests/functional/json/json_numbers_tests.cpp b/Release/tests/functional/json/json_numbers_tests.cpp index 4935a6af27..538d44d367 100644 --- a/Release/tests/functional/json/json_numbers_tests.cpp +++ b/Release/tests/functional/json/json_numbers_tests.cpp @@ -258,8 +258,8 @@ SUITE(json_numbers_tests) // unsigned int64 max oracleStream.precision(std::numeric_limits::digits10 + 2); - oracleStream << std::numeric_limits::max(); - json::value iMax(std::numeric_limits::max()); + oracleStream << (std::numeric_limits::max)(); + json::value iMax((std::numeric_limits::max)()); VERIFY_ARE_EQUAL(oracleStream.str(), iMax.serialize()); iMax.serialize(stream); VERIFY_ARE_EQUAL(oracleStream.str(), stream.str()); @@ -268,8 +268,8 @@ SUITE(json_numbers_tests) stream.str(U("")); oracleStream.str(U("")); oracleStream.clear(); - oracleStream << std::numeric_limits::min(); - json::value iMin(std::numeric_limits::min()); + oracleStream << (std::numeric_limits::min)(); + json::value iMin((std::numeric_limits::min)()); VERIFY_ARE_EQUAL(oracleStream.str(), iMin.serialize()); iMin.serialize(stream); VERIFY_ARE_EQUAL(oracleStream.str(), stream.str()); @@ -278,8 +278,8 @@ SUITE(json_numbers_tests) stream.str(U("")); oracleStream.str(U("")); oracleStream.precision(std::numeric_limits::digits10 + 2); - oracleStream << std::numeric_limits::max(); - json::value dMax(std::numeric_limits::max()); + oracleStream << (std::numeric_limits::max)(); + json::value dMax((std::numeric_limits::max)()); VERIFY_ARE_EQUAL(oracleStream.str(), dMax.serialize()); dMax.serialize(stream); VERIFY_ARE_EQUAL(oracleStream.str(), stream.str()); @@ -287,8 +287,8 @@ SUITE(json_numbers_tests) // double min stream.str(U("")); oracleStream.str(U("")); - oracleStream << std::numeric_limits::min(); - json::value dMin(std::numeric_limits::min()); + oracleStream << (std::numeric_limits::min)(); + json::value dMin((std::numeric_limits::min)()); VERIFY_ARE_EQUAL(oracleStream.str(), dMin.serialize()); dMin.serialize(stream); VERIFY_ARE_EQUAL(oracleStream.str(), stream.str()); diff --git a/Release/tests/functional/json/stdafx.h b/Release/tests/functional/json/stdafx.h index bb65303dca..bb43264b61 100644 --- a/Release/tests/functional/json/stdafx.h +++ b/Release/tests/functional/json/stdafx.h @@ -16,5 +16,4 @@ #include "unittestpp.h" #include -#define NOMINMAX #include "json_tests.h" diff --git a/Release/tests/functional/misc/atl_headers/header_test1.cpp b/Release/tests/functional/misc/atl_headers/header_test1.cpp index 46d54ff2e3..95dd22359d 100644 --- a/Release/tests/functional/misc/atl_headers/header_test1.cpp +++ b/Release/tests/functional/misc/atl_headers/header_test1.cpp @@ -11,7 +11,6 @@ // Include ATL headers before casablanca headers #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#define NOMINMAX #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit #ifndef VC_EXTRALEAN diff --git a/Release/tests/functional/misc/atl_headers/header_test2.cpp b/Release/tests/functional/misc/atl_headers/header_test2.cpp index 91cf63fbc6..73e35711de 100644 --- a/Release/tests/functional/misc/atl_headers/header_test2.cpp +++ b/Release/tests/functional/misc/atl_headers/header_test2.cpp @@ -9,7 +9,6 @@ * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ****/ #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#define NOMINMAX #include "cpprest/http_client.h" // Include ATL headers after casablanca headers diff --git a/Release/tests/functional/pplx/pplx_test/stdafx.h b/Release/tests/functional/pplx/pplx_test/stdafx.h index 7c2d53ab4f..790829ef64 100644 --- a/Release/tests/functional/pplx/pplx_test/stdafx.h +++ b/Release/tests/functional/pplx/pplx_test/stdafx.h @@ -12,7 +12,6 @@ #pragma once #ifdef _WIN32 -#define NOMINMAX #include #endif diff --git a/Release/tests/functional/streams/istream_tests.cpp b/Release/tests/functional/streams/istream_tests.cpp index d1018e3116..32cb545aa2 100644 --- a/Release/tests/functional/streams/istream_tests.cpp +++ b/Release/tests/functional/streams/istream_tests.cpp @@ -1333,7 +1333,7 @@ SUITE(istream_tests) const auto actual = istream_double.extract().get(); compare_double(expected, actual); - if (actual <= std::numeric_limits::max()) + if (actual <= (std::numeric_limits::max)()) compare_float(float(expected), istream_float.extract().get()); else VERIFY_THROWS(istream_float.extract().get(), std::exception); diff --git a/Release/tests/functional/streams/memstream_tests.cpp b/Release/tests/functional/streams/memstream_tests.cpp index 6442883327..3bdbd6812a 100644 --- a/Release/tests/functional/streams/memstream_tests.cpp +++ b/Release/tests/functional/streams/memstream_tests.cpp @@ -13,7 +13,6 @@ #include #endif #ifdef _WIN32 -#define NOMINMAX #include #endif diff --git a/Release/tests/functional/utils/win32_encryption_tests.cpp b/Release/tests/functional/utils/win32_encryption_tests.cpp index 32e6ab2ecb..a2be7cde5a 100644 --- a/Release/tests/functional/utils/win32_encryption_tests.cpp +++ b/Release/tests/functional/utils/win32_encryption_tests.cpp @@ -21,7 +21,7 @@ namespace functional { namespace utils_tests { -#if defined(_WIN32) && !defined(CPPREST_TARGET_XP) && !defined(__cplusplus_winrt) +#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA && !defined(__cplusplus_winrt) SUITE(win32_encryption) { TEST(win32_encryption_random_string) @@ -42,7 +42,7 @@ SUITE(win32_encryption) } // SUITE(win32_encryption) -#endif +#endif // defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA && !defined(__cplusplus_winrt) } // namespace utils_tests } // namespace functional diff --git a/Release/tests/functional/websockets/utilities/stdafx.h b/Release/tests/functional/websockets/utilities/stdafx.h index e8adb749c9..0c6e35125a 100644 --- a/Release/tests/functional/websockets/utilities/stdafx.h +++ b/Release/tests/functional/websockets/utilities/stdafx.h @@ -13,7 +13,6 @@ #if defined(_WIN32) // Include first to avoid any issues with Windows.h. -#define NOMINMAX #include #endif