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
This commit is contained in:
Billy O'Neal 2019-07-12 18:05:14 -07:00 коммит произвёл GitHub
Родитель a718c5bcf4
Коммит bed8fa538c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
58 изменённых файлов: 326 добавлений и 281 удалений

2
.gitignore поставляемый
Просмотреть файл

@ -73,3 +73,5 @@ Build_android/build/
Generated Files/
# Ignore iOS temp build directories
Build_iOS/Apple-Boost-BuildScript
/out/

16
.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"
]
}

Просмотреть файл

@ -24,8 +24,6 @@
#define CPPREST_CONSTEXPR const
#endif // _MSC_VER >= 1900
#define CASABLANCA_UNREFERENCED_PARAMETER(x) (x)
#include <sal.h>
#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

Просмотреть файл

@ -10,6 +10,10 @@
****/
#pragma once
#ifdef _WIN32
#include <Windows.h>
#endif // _WIN32
#include "cpprest/asyncrt_utils.h"
#include "cpprest/uri.h"
@ -24,23 +28,24 @@ public:
};
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<Windows::Storage::Streams::IBuffer ^> 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 @@ private:
std::vector<char> m_buffer;
size_t m_numCharacters;
};
#endif
#endif
#endif // __cplusplus_winrt
#endif // _WIN32_WINNT >= _WIN32_WINNT_VISTA
#endif // _WIN32
} // namespace details
/// <summary>
@ -89,7 +95,7 @@ public:
"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 @@ public:
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 @@ public:
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 @@ public:
/// <summary>
/// Constructs a proxy with the default settings.
/// </summary>
web_proxy() : m_address(_XPLATSTR("")), m_mode(use_default_) {}
web_proxy() : m_address(), m_mode(use_default_) {}
/// <summary>
/// Creates a proxy with specified mode.
/// </summary>
/// <param name="mode">Mode to use.</param>
web_proxy(web_proxy_mode mode) : m_address(_XPLATSTR("")), m_mode(static_cast<web_proxy_mode_internal>(mode)) {}
web_proxy(web_proxy_mode mode) : m_address(), m_mode(static_cast<web_proxy_mode_internal>(mode)) {}
/// <summary>
/// Creates a proxy explicitly with provided address.

Просмотреть файл

@ -54,7 +54,7 @@ typedef void* native_handle;
#include <limits>
#include <memory>
#if !defined(CPPREST_TARGET_XP)
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
#include "cpprest/oauth1.h"
#endif
@ -110,7 +110,7 @@ public:
{
}
#if !defined(CPPREST_TARGET_XP)
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
/// <summary>
/// Get OAuth 1.0 configuration.
/// </summary>
@ -363,7 +363,7 @@ public:
#endif
private:
#if !defined(CPPREST_TARGET_XP)
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
std::shared_ptr<oauth1::experimental::oauth1_config> m_oauth1;
#endif

Просмотреть файл

@ -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<ReturnType> _type_parser_base<CharType>::_parse_input(concurrency::st
auto update = [=](pplx::task<int_type> op) -> pplx::task<bool> {
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<CharType> buf = buffer;
return buf.bumpc().then([](int_type) { return true; });
@ -1308,9 +1308,18 @@ struct _double_state
template<typename FloatingPoint, typename int_type>
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<char>(ch);
return result;
}
template<typename FloatingPoint, typename int_type>

Просмотреть файл

@ -330,8 +330,7 @@ public:
virtual pplx::task<void> close() = 0;
virtual pplx::task<void> close(websocket_close_status close_status,
const utility::string_t& close_reason = _XPLATSTR("")) = 0;
virtual pplx::task<void> close(websocket_close_status close_status, const utility::string_t& close_reason = {}) = 0;
virtual void set_close_handler(
const std::function<void(websocket_close_status, const utility::string_t&, const std::error_code&)>&
@ -478,7 +477,7 @@ public:
/// frame.</param> <param name="close_reason">While closing an established connection, an endpoint may indicate the
/// reason for closure.</param> <returns>An asynchronous operation that is completed the connection has been
/// successfully closed.</returns>
pplx::task<void> close(websocket_close_status close_status, const utility::string_t& close_reason = _XPLATSTR(""))
pplx::task<void> 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 @@ public:
/// frame.</param> <param name="close_reason">While closing an established connection, an endpoint may indicate the
/// reason for closure.</param> <returns>An asynchronous operation that is completed the connection has been
/// successfully closed.</returns>
pplx::task<void> close(websocket_close_status close_status, const utility::string_t& close_reason = _XPLATSTR(""))
pplx::task<void> close(websocket_close_status close_status, const utility::string_t& close_reason = {})
{
return m_client->close(close_status, close_reason);
}

Просмотреть файл

@ -74,7 +74,7 @@ public:
/// </summary>
/// <param name="data">UTF-8 String containing the optional pong message.</param>
void set_pong_message(const std::string& data = {})
{
{
this->set_message_pong(concurrency::streams::container_buffer<std::string>(data));
}
#endif

Просмотреть файл

@ -3799,7 +3799,7 @@ private:
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 @@ private:
-> 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));
}

Просмотреть файл

@ -17,7 +17,6 @@
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#define NOMINMAX
#include <objbase.h>
#include <winsock2.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())

Просмотреть файл

@ -26,9 +26,6 @@
#include <vector>
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
#else
#include <sys/time.h>

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -25,10 +25,10 @@ public:
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();
}

Просмотреть файл

@ -116,7 +116,7 @@ void BlackjackClient::PlayingTable::Refresh()
request.then(
[this](pplx::task<http_response> 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<http_response> 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<http_response> 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<http_response> 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<http_response> 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<http_response> 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<http_response> 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<http_response> 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)
{

Просмотреть файл

@ -93,7 +93,7 @@ private:
{
ClearDealerCards();
ClearPlayerCards();
resultLabel->Text = "";
resultLabel->Text.clear();
}
void EnableBetting()

Просмотреть файл

@ -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");

Просмотреть файл

@ -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());

Просмотреть файл

@ -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.

Просмотреть файл

@ -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 @@ public:
: 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();

Просмотреть файл

@ -338,7 +338,7 @@ public:
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 @@ public:
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(); })

Просмотреть файл

@ -386,7 +386,7 @@ http_client::http_client(const uri& base_uri, const http_client_config& client_c
m_pipeline = std::make_shared<http_pipeline>(std::move(final_pipeline_stage));
#if !defined(CPPREST_TARGET_XP)
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
add_handler(std::static_pointer_cast<http::http_pipeline_stage>(
std::make_shared<oauth1::details::oauth1_handler>(client_config.oauth1())));
#endif

Просмотреть файл

@ -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 @@ public:
}
};
// 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 @@ private:
}
const auto this_request = shared_from_this();
const auto readSize = static_cast<size_t>(
std::min(static_cast<uint64_t>(m_http_client->client_config().chunksize()), m_content_length - m_uploaded));
const auto readSize = static_cast<size_t>((std::min)(
static_cast<uint64_t>(m_http_client->client_config().chunksize()), m_content_length - m_uploaded));
auto readbuf = _get_readbuffer();
readbuf.getn(boost::asio::buffer_cast<uint8_t*>(m_body_buf.prepare(readSize)), readSize)
.then([this_request AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op) {
@ -1487,8 +1487,8 @@ private:
if (!needChunked)
{
async_read_until_buffersize(
static_cast<size_t>(
std::min(m_content_length, static_cast<uint64_t>(m_http_client->client_config().chunksize()))),
static_cast<size_t>((std::min)(m_content_length,
static_cast<uint64_t>(m_http_client->client_config().chunksize()))),
boost::bind(
&asio_context::handle_read_content, shared_from_this(), boost::asio::placeholders::error));
}
@ -1572,7 +1572,7 @@ private:
{
if (inbytes)
{
output.resize(output.size() + std::max(input_size, static_cast<size_t>(1024)));
output.resize(output.size() + (std::max)(input_size, static_cast<size_t>(1024)));
}
got = m_decompressor->decompress(input + inbytes,
input_size - inbytes,
@ -1710,7 +1710,7 @@ private:
if (ec)
{
if (ec == boost::asio::error::eof && m_content_length == std::numeric_limits<size_t>::max())
if (ec == boost::asio::error::eof && m_content_length == (std::numeric_limits<size_t>::max)())
{
m_content_length = m_downloaded + m_body_buf.size();
}
@ -1742,7 +1742,7 @@ private:
const auto this_request = shared_from_this();
auto read_size = static_cast<size_t>(
std::min(static_cast<uint64_t>(m_body_buf.size()), m_content_length - m_downloaded));
(std::min)(static_cast<uint64_t>(m_body_buf.size()), m_content_length - m_downloaded));
if (m_decompressor)
{
@ -1765,7 +1765,7 @@ private:
this_request->m_downloaded += static_cast<uint64_t>(read_size);
this_request->async_read_until_buffersize(
static_cast<size_t>(std::min(
static_cast<size_t>((std::min)(
static_cast<uint64_t>(this_request->m_http_client->client_config().chunksize()),
this_request->m_content_length - this_request->m_downloaded)),
boost::bind(
@ -1794,7 +1794,7 @@ private:
this_request->m_downloaded += static_cast<uint64_t>(read_size);
this_request->m_body_buf.consume(read_size);
this_request->async_read_until_buffersize(
static_cast<size_t>(std::min(
static_cast<size_t>((std::min)(
static_cast<uint64_t>(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 @@ private:
this_request->m_downloaded += static_cast<uint64_t>(writtenSize);
this_request->m_body_buf.consume(writtenSize);
this_request->async_read_until_buffersize(
static_cast<size_t>(std::min(
static_cast<size_t>((std::min)(
static_cast<uint64_t>(this_request->m_http_client->client_config().chunksize()),
this_request->m_content_length - this_request->m_downloaded)),
boost::bind(&asio_context::handle_read_content,

Просмотреть файл

@ -20,7 +20,7 @@
#include <Wincrypt.h>
#include <atomic>
#ifndef CPPREST_TARGET_XP
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
#include <VersionHelpers.h>
#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 @@ public:
HINTERNET m_request_handle;
std::weak_ptr<winhttp_request_context>*
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 @@ public:
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 @@ protected:
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 @@ protected:
m_proxy_auto_config = true;
}
}
#endif // CPPREST_TARGET_XP
#endif // _WIN32_WINNT < _WIN32_WINNT_VISTA
}
else
{
@ -908,7 +941,7 @@ protected:
}
// 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 @@ protected:
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 @@ protected:
}
// There is a request body that needs to be transferred.
if (content_length == std::numeric_limits<size_t>::max())
if (content_length == (std::numeric_limits<size_t>::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 @@ private:
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<size_t>::max())
else if (p_request_context->m_remaining_to_write != (std::numeric_limits<size_t>::max)())
{
// Choose a semi-intelligent size based on how much total data is left to compress
chunk_size = std::min(static_cast<size_t>(p_request_context->m_remaining_to_write) + 128,
p_request_context->m_http_client->client_config().chunksize());
chunk_size = (std::min)(static_cast<size_t>(p_request_context->m_remaining_to_write) + 128,
p_request_context->m_http_client->client_config().chunksize());
}
else
{
@ -1331,8 +1364,8 @@ private:
{
// 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<size_t>(p_request_context->m_remaining_to_write),
p_request_context->m_http_client->client_config().chunksize());
chunk_size = (std::min)(static_cast<size_t>(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 @@ private:
chunk_size + http::details::chunked_encoding::additional_encoding_space,
bytes_read);
if (!compressor && p_request_context->m_remaining_to_write != std::numeric_limits<size_t>::max())
if (!compressor && p_request_context->m_remaining_to_write != (std::numeric_limits<size_t>::max)())
{
if (bytes_read == 0 && p_request_context->m_remaining_to_write)
{
@ -1465,7 +1498,7 @@ private:
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<size_t>::max())
p_request_context->m_remaining_to_write != (std::numeric_limits<size_t>::max)())
{
// The stream ended earlier than we detected it should
return pplx::task_from_exception<size_t>(http_exception(
@ -1518,7 +1551,7 @@ private:
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<size_t>::max())
if (p_request_context->m_remaining_to_write != (std::numeric_limits<size_t>::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 @@ private:
return;
}
else if (p_request_context->m_remaining_to_write &&
p_request_context->m_remaining_to_write != std::numeric_limits<size_t>::max())
p_request_context->m_remaining_to_write != (std::numeric_limits<size_t>::max)())
{
// Unexpected end-of-stream.
p_request_context->report_error(GetLastError(),
@ -1586,8 +1619,8 @@ private:
}
else
{
length = std::min(static_cast<size_t>(p_request_context->m_remaining_to_write),
p_request_context->m_http_client->client_config().chunksize());
length = (std::min)(static_cast<size_t>(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 @@ private:
if (content_length > 0)
{
// There is a request body that needs to be transferred.
if (content_length == std::numeric_limits<size_t>::max())
if (content_length == (std::numeric_limits<size_t>::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 @@ private:
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<winhttp_request_context>* p_weak_request_context =
reinterpret_cast<std::weak_ptr<winhttp_request_context>*>(context);
@ -2208,8 +2241,8 @@ private:
if (p_request_context->m_decompressor)
{
size_t chunk_size = std::max(static_cast<size_t>(bytesRead),
p_request_context->m_http_client->client_config().chunksize());
size_t chunk_size = (std::max)(static_cast<size_t>(bytesRead),
p_request_context->m_http_client->client_config().chunksize());
p_request_context->m_compression_state.m_bytes_read = static_cast<size_t>(bytesRead);
p_request_context->m_compression_state.m_chunk_bytes = 0;
@ -2396,24 +2429,23 @@ private:
return keep_going(p_request_context.get());
});
});
})
.then([p_request_context](pplx::task<bool> op) {
try
}).then([p_request_context](pplx::task<bool> 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)
{
bool ignored = op.get();
p_request_context->_get_writebuffer().commit(0);
p_request_context->m_compression_state.m_acquired = nullptr;
}
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)
{
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->report_exception(std::current_exception());
}
});
}
else
{

Просмотреть файл

@ -188,7 +188,7 @@ class IRequestStream final
{
public:
IRequestStream(const std::weak_ptr<winrt_request_context>& context,
size_t read_length = std::numeric_limits<size_t>::max())
size_t read_length = (std::numeric_limits<size_t>::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 @@ public:
_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 @@ public:
_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 @@ protected:
}
const size_t content_length = msg._get_impl()->_get_content_length();
if (content_length == std::numeric_limits<size_t>::max())
if (content_length == (std::numeric_limits<size_t>::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 @@ protected:
// Set timeout.
ULONGLONG timeout = static_cast<ULONGLONG>(config.timeout<std::chrono::milliseconds>().count());
timeout = std::max<decltype(timeout)>(timeout, std::numeric_limits<decltype(timeout)>::min() + 1);
timeout = (std::max<decltype(timeout)>)(timeout, (std::numeric_limits<decltype(timeout)>::min)() + 1);
hr = winrt_context->m_hRequest->SetProperty(XHR_PROP_TIMEOUT, timeout);
if (FAILED(hr))
{

Просмотреть файл

@ -97,7 +97,7 @@ public:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-constant-compare"
#endif // __clang__
if (input_size > std::numeric_limits<uInt>::max() || output_size > std::numeric_limits<uInt>::max())
if (input_size > (std::numeric_limits<uInt>::max)() || output_size > (std::numeric_limits<uInt>::max)())
#if defined(__clang__)
#pragma clang diagnostic pop
#endif // __clang__
@ -198,7 +198,7 @@ public:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-constant-compare"
#endif // __clang__
if (input_size > std::numeric_limits<uInt>::max() || output_size > std::numeric_limits<uInt>::max())
if (input_size > (std::numeric_limits<uInt>::max)() || output_size > (std::numeric_limits<uInt>::max)())
#if defined(__clang__)
#pragma clang diagnostic pop
#endif // __clang__

Просмотреть файл

@ -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<size_t>(end - offset);
}
return std::numeric_limits<size_t>::max();
return (std::numeric_limits<size_t>::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<size_t>::max();
return (std::numeric_limits<size_t>::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<size_t>::max();
return (std::numeric_limits<size_t>::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<size_t>::max())
if (content_length != (std::numeric_limits<size_t>::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<size_t>::max();
return (std::numeric_limits<size_t>::max)();
}
// There is no content

Просмотреть файл

@ -175,7 +175,7 @@ public:
auto path_segments = uri::split_path(uri::decode(u.path()));
for (auto i = static_cast<long>(path_segments.size()); i >= 0; --i)
{
std::string path = "";
std::string path;
for (size_t j = 0; j < static_cast<size_t>(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<const uint8_t*>(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<size_t> 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<uint8_t*>(m_response_buf.prepare(readBytes)), readBytes)
.then([=](pplx::task<size_t> actualSizeTask) -> will_deref_and_erase_t {
size_t actualSize = 0;

Просмотреть файл

@ -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<size_t>::max());
m_transfer_encoding = (content_length == std::numeric_limits<size_t>::max());
m_sending_in_chunks = (content_length != (std::numeric_limits<size_t>::max)());
m_transfer_encoding = (content_length == (std::numeric_limits<size_t>::max)());
m_remaining_to_write = content_length;
if (content_length == std::numeric_limits<size_t>::max())
if (content_length == (std::numeric_limits<size_t>::max)())
{
// Attempt to figure out the remaining length of the input stream
m_remaining_to_write = m_response._get_impl()->_get_stream_length();

Просмотреть файл

@ -58,9 +58,9 @@ public:
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);

Просмотреть файл

@ -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

Просмотреть файл

@ -286,8 +286,9 @@ bool web::json::number::is_int32() const
switch (m_type)
{
case signed_type:
return m_intval >= std::numeric_limits<int32_t>::min() && m_intval <= std::numeric_limits<int32_t>::max();
case unsigned_type: return m_uintval <= std::numeric_limits<int32_t>::max();
return m_intval >= (std::numeric_limits<int32_t>::min)() &&
m_intval <= (std::numeric_limits<int32_t>::max)();
case unsigned_type: return m_uintval <= (std::numeric_limits<int32_t>::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<uint32_t>::max();
case unsigned_type: return m_uintval <= std::numeric_limits<uint32_t>::max();
case signed_type: return m_intval >= 0 && m_intval <= (std::numeric_limits<uint32_t>::max)();
case unsigned_type: return m_uintval <= (std::numeric_limits<uint32_t>::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<uint64_t>(std::numeric_limits<int64_t>::max());
case unsigned_type: return m_uintval <= static_cast<uint64_t>((std::numeric_limits<int64_t>::max)());
case double_type:
default: return false;
}

Просмотреть файл

@ -20,32 +20,29 @@
#endif
#ifdef _WIN32
#define NOMINMAX
#ifdef CPPREST_TARGET_XP
#include <winsdkver.h>
#ifndef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_WS03 // Windows XP with SP2
#endif
#endif
#include <SDKDDKVer.h>
// use the debug version of the CRT if _DEBUG is defined
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include <stdlib.h>
#endif
#endif // _DEBUG
#include <SDKDDKVer.h>
#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 <objbase.h>
#include <windows.h>
// Windows Header Files:
#if !defined(__cplusplus_winrt)
#ifndef __cplusplus_winrt
#include <winhttp.h>
#endif !__cplusplus_winrt
#endif // #if !defined(__cplusplus_winrt)
#else // LINUX or APPLE
#else // LINUX or APPLE
#define __STDC_LIMIT_MACROS
#include "pthread.h"
#include <atomic>
@ -84,6 +81,7 @@
#include <exception>
#include <memory>
#include <mutex>
#include <stdlib.h>
#include <vector>
// json

Просмотреть файл

@ -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<size_t>(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<int>(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;

Просмотреть файл

@ -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<EXTENDED_OVERLAPPED*>(pOverlapped);
pExtOverlapped->func(result, static_cast<DWORD>(numberOfBytesTransferred), static_cast<LPOVERLAPPED>(pOverlapped));

Просмотреть файл

@ -734,7 +734,7 @@ std::map<utility::string_t, utility::string_t> 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
{

Просмотреть файл

@ -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

Просмотреть файл

@ -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));
});
}

Просмотреть файл

@ -404,7 +404,7 @@ public:
return close(websocket_close_status::normal, _XPLATSTR("Normal"));
}
pplx::task<void> close(websocket_close_status status, const utility::string_t& strreason = _XPLATSTR(""))
pplx::task<void> close(websocket_close_status status, const utility::string_t& strreason = {})
{
// Send a close frame to the server
m_msg_websocket->Close(static_cast<unsigned short>(status), Platform::StringReference(strreason.c_str()));

Просмотреть файл

@ -325,34 +325,32 @@ public:
}
});
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<std::string>(msg);
incoming_msg.m_msg_type = websocket_message_type::ping;
incoming_msg.m_body = concurrency::streams::container_buffer<std::string>(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<std::string>(msg);
incoming_msg.m_msg_type = websocket_message_type::pong;
incoming_msg.m_body = concurrency::streams::container_buffer<std::string>(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 @@ public:
}
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<void>(websocket_exception("Cannot send empty message."));
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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{};
}
};

Просмотреть файл

@ -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)
{
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -49,6 +49,5 @@
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <Windows.h>
#endif

Просмотреть файл

@ -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 <SDKDDKVer.h>

Просмотреть файл

@ -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<size_t>(128), bufsz / 1000); };
auto extra_size = [](size_t bufsz) -> size_t { return (std::max)(static_cast<size_t>(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

Просмотреть файл

@ -352,7 +352,7 @@ SUITE(outside_tests)
throw;
}
#else
CASABLANCA_UNREFERENCED_PARAMETER(e);
(void)e;
throw;
#endif
os_utilities::sleep(1000);

Просмотреть файл

@ -13,7 +13,6 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <winsock2.h>
#include <Windows.h>

Просмотреть файл

@ -258,8 +258,8 @@ SUITE(json_numbers_tests)
// unsigned int64 max
oracleStream.precision(std::numeric_limits<uint64_t>::digits10 + 2);
oracleStream << std::numeric_limits<uint64_t>::max();
json::value iMax(std::numeric_limits<uint64_t>::max());
oracleStream << (std::numeric_limits<uint64_t>::max)();
json::value iMax((std::numeric_limits<uint64_t>::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<int64_t>::min();
json::value iMin(std::numeric_limits<int64_t>::min());
oracleStream << (std::numeric_limits<int64_t>::min)();
json::value iMin((std::numeric_limits<int64_t>::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<double>::digits10 + 2);
oracleStream << std::numeric_limits<double>::max();
json::value dMax(std::numeric_limits<double>::max());
oracleStream << (std::numeric_limits<double>::max)();
json::value dMax((std::numeric_limits<double>::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<double>::min();
json::value dMin(std::numeric_limits<double>::min());
oracleStream << (std::numeric_limits<double>::min)();
json::value dMin((std::numeric_limits<double>::min)());
VERIFY_ARE_EQUAL(oracleStream.str(), dMin.serialize());
dMin.serialize(stream);
VERIFY_ARE_EQUAL(oracleStream.str(), stream.str());

Просмотреть файл

@ -16,5 +16,4 @@
#include "unittestpp.h"
#include <random>
#define NOMINMAX
#include "json_tests.h"

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -12,7 +12,6 @@
#pragma once
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
#endif

Просмотреть файл

@ -1333,7 +1333,7 @@ SUITE(istream_tests)
const auto actual = istream_double.extract<double>().get();
compare_double(expected, actual);
if (actual <= std::numeric_limits<float>::max())
if (actual <= (std::numeric_limits<float>::max)())
compare_float(float(expected), istream_float.extract<float>().get());
else
VERIFY_THROWS(istream_float.extract<float>().get(), std::exception);

Просмотреть файл

@ -13,7 +13,6 @@
#include <wrl.h>
#endif
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
#endif

Просмотреть файл

@ -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

Просмотреть файл

@ -13,7 +13,6 @@
#if defined(_WIN32)
// Include first to avoid any issues with Windows.h.
#define NOMINMAX
#include <winsock2.h>
#endif