Skip to content

Replace CPPREST_TARGET_XP with version checks, remove ""s, and other cleanup #1187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 13, 2019
Merged
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ Build_android/build/
Generated Files/
# Ignore iOS temp build directories
Build_iOS/Apple-Boost-BuildScript

/out/
16 changes: 14 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
3 changes: 0 additions & 3 deletions Release/include/cpprest/details/cpprest_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
30 changes: 18 additions & 12 deletions Release/include/cpprest/details/web_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
****/
#pragma once

#ifdef _WIN32
#include <Windows.h>
#endif // _WIN32

#include "cpprest/asyncrt_utils.h"
#include "cpprest/uri.h"

Expand All @@ -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<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;
Expand All @@ -49,8 +54,9 @@ class win32_encryption
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>
Expand Down Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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
Expand Down Expand Up @@ -151,13 +157,13 @@ class web_proxy
/// <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.
Expand Down
6 changes: 3 additions & 3 deletions Release/include/cpprest/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -110,7 +110,7 @@ class http_client_config
{
}

#if !defined(CPPREST_TARGET_XP)
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
/// <summary>
/// Get OAuth 1.0 configuration.
/// </summary>
Expand Down Expand Up @@ -363,7 +363,7 @@ class http_client_config
#endif

private:
#if !defined(CPPREST_TARGET_XP)
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
std::shared_ptr<oauth1::experimental::oauth1_config> m_oauth1;
#endif

Expand Down
21 changes: 15 additions & 6 deletions Release/include/cpprest/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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; });
Expand Down Expand Up @@ -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>
Expand Down
7 changes: 3 additions & 4 deletions Release/include/cpprest/ws_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ class websocket_client_callback_impl

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&)>&
Expand Down Expand Up @@ -478,7 +477,7 @@ class websocket_client
/// 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);
}
Expand Down Expand Up @@ -566,7 +565,7 @@ class websocket_callback_client
/// 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);
}
Expand Down
2 changes: 1 addition & 1 deletion Release/include/cpprest/ws_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class websocket_outgoing_message
/// </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
Expand Down
4 changes: 2 additions & 2 deletions Release/include/pplx/pplxtasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#define NOMINMAX
#include <objbase.h>
#include <winsock2.h>

Expand Down
4 changes: 2 additions & 2 deletions Release/samples/BlackJack/BlackJack_Server/messagetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 0 additions & 3 deletions Release/samples/BlackJack/BlackJack_Server/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
#include <vector>

#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
#else
#include <sys/time.h>
Expand Down
16 changes: 11 additions & 5 deletions Release/samples/BlackJack/BlackJack_UIClient/Player.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions Release/samples/BlackJack/BlackJack_UIClient/Player.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading