diff --git a/Release/include/cpprest/asyncrt_utils.h b/Release/include/cpprest/asyncrt_utils.h index 21c92de294..23ec9aca02 100644 --- a/Release/include/cpprest/asyncrt_utils.h +++ b/Release/include/cpprest/asyncrt_utils.h @@ -68,35 +68,35 @@ namespace conversions /// /// A two byte character UTF-16 string. /// A single byte character UTF-8 string. - _ASYNCRTIMP std::string __cdecl utf16_to_utf8(const utf16string &w); + _ASYNCRTIMP utility::string __cdecl utf16_to_utf8(const utf16string &w); /// /// Converts a UTF-8 string to a UTF-16 /// /// A single byte character UTF-8 string. /// A two byte character UTF-16 string. - _ASYNCRTIMP utf16string __cdecl utf8_to_utf16(const std::string &s); + _ASYNCRTIMP utf16string __cdecl utf8_to_utf16(const utility::string &s); /// /// Converts a ASCII (us-ascii) string to a UTF-16 string. /// /// A single byte character us-ascii string. /// A two byte character UTF-16 string. - _ASYNCRTIMP utf16string __cdecl usascii_to_utf16(const std::string &s); + _ASYNCRTIMP utf16string __cdecl usascii_to_utf16(const utility::string &s); /// /// Converts a Latin1 (iso-8859-1) string to a UTF-16 string. /// /// A single byte character UTF-8 string. /// A two byte character UTF-16 string. - _ASYNCRTIMP utf16string __cdecl latin1_to_utf16(const std::string &s); + _ASYNCRTIMP utf16string __cdecl latin1_to_utf16(const utility::string &s); /// /// Converts a Latin1 (iso-8859-1) string to a UTF-8 string. /// /// A single byte character UTF-8 string. /// A single byte character UTF-8 string. - _ASYNCRTIMP utf8string __cdecl latin1_to_utf8(const std::string &s); + _ASYNCRTIMP utf8string __cdecl latin1_to_utf8(const utility::string &s); /// /// Converts to a platform dependent Unicode string type. @@ -104,9 +104,9 @@ namespace conversions /// A single byte character UTF-8 string. /// A platform dependent string type. #ifdef _UTF16_STRINGS - _ASYNCRTIMP utility::string_t __cdecl to_string_t(std::string &&s); + _ASYNCRTIMP utility::string_t __cdecl to_string_t(utility::string &&s); #else - inline utility::string_t&& to_string_t(std::string &&s) { return std::move(s); } + inline utility::string_t&& to_string_t(utility::string &&s) { return std::move(s); } #endif /// @@ -125,9 +125,9 @@ namespace conversions /// A single byte character UTF-8 string. /// A platform dependent string type. #ifdef _UTF16_STRINGS - _ASYNCRTIMP utility::string_t __cdecl to_string_t(const std::string &s); + _ASYNCRTIMP utility::string_t __cdecl to_string_t(const utility::string &s); #else - inline const utility::string_t& to_string_t(const std::string &s) { return s; } + inline const utility::string_t& to_string_t(const utility::string &s) { return s; } #endif /// @@ -146,7 +146,7 @@ namespace conversions /// /// A single byte character UTF-8 string. /// A two byte character UTF-16 string. - _ASYNCRTIMP utf16string __cdecl to_utf16string(const std::string &value); + _ASYNCRTIMP utf16string __cdecl to_utf16string(const utility::string &value); /// /// Converts to a UTF-16 from string. @@ -172,26 +172,26 @@ namespace conversions /// /// A single byte character UTF-8 string. /// A single byte character UTF-8 string. - inline std::string&& to_utf8string(std::string&& value) { return std::move(value); } + inline utility::string&& to_utf8string(utility::string&& value) { return std::move(value); } /// /// Converts to a UTF-8 string. /// /// A single byte character UTF-8 string. /// A single byte character UTF-8 string. - inline const std::string& to_utf8string(const std::string& value) { return value; } + inline const utility::string& to_utf8string(const utility::string& value) { return value; } /// /// Converts to a UTF-8 string. /// /// A two byte character UTF-16 string. /// A single byte character UTF-8 string. - _ASYNCRTIMP std::string __cdecl to_utf8string(const utf16string &value); + _ASYNCRTIMP utility::string __cdecl to_utf8string(const utf16string &value); /// /// Encode the given byte array into a base64 string /// - _ASYNCRTIMP utility::string_t __cdecl to_base64(const std::vector& data); + _ASYNCRTIMP utility::string_t __cdecl to_base64(const utility::vector& data); /// /// Encode the given 8-byte integer into a base64 string @@ -201,7 +201,7 @@ namespace conversions /// /// Decode the given base64 string to a byte array /// - _ASYNCRTIMP std::vector __cdecl from_base64(const utility::string_t& str); + _ASYNCRTIMP utility::vector __cdecl from_base64(const utility::string_t& str); template CASABLANCA_DEPRECATED("All locale-sensitive APIs will be removed in a future update. Use stringstreams directly if locale support is required.") @@ -226,28 +226,42 @@ namespace conversions namespace details { -#if defined(__ANDROID__) template - inline std::string to_string(const T t) + inline utility::string to_string(const T t) { - std::ostringstream os; +#if defined(__ANDROID__) + utility::ostringstream os; os.imbue(std::locale::classic()); os << t; return os.str(); +#else + using std::to_string; + return to_string(t).c_str(); +#endif + } + +#if defined(_WIN32) || defined(_UTF16_STRINGS) + template + inline utility::wstring to_wstring(const T t) { + using std::to_wstring; + return to_wstring(t).c_str(); } #endif template inline utility::string_t to_string_t(const T t) { -#ifdef _UTF16_STRINGS +#if defined(_WIN32) || defined(_UTF16_STRINGS) using std::to_wstring; - return to_wstring(t); + return to_wstring(t).c_str(); +#elif defined(__ANDROID__) + utility::ostringstream os; + os.imbue(std::locale::classic()); + os << t; + return os.str(); #else -#if !defined(__ANDROID__) using std::to_string; -#endif - return to_string(t); + return to_string(t).c_str(); #endif } @@ -343,7 +357,7 @@ namespace details #endif private: #ifdef _WIN32 - std::string m_prevLocale; + utility::string m_prevLocale; int m_prevThreadSetting; #elif !(defined(ANDROID) || defined(__ANDROID__)) locale_t m_prevLocale; @@ -397,42 +411,13 @@ namespace details return (uch <= static_cast('z') && is_alnum(static_cast(uch))); } - /// - /// Simplistic implementation of make_unique. A better implementation would be based on variadic templates - /// and therefore not be compatible with Dev10. - /// - template - std::unique_ptr<_Type> make_unique() { - return std::unique_ptr<_Type>(new _Type()); - } - - template - std::unique_ptr<_Type> make_unique(_Arg1&& arg1) { - return std::unique_ptr<_Type>(new _Type(std::forward<_Arg1>(arg1))); - } - - template - std::unique_ptr<_Type> make_unique(_Arg1&& arg1, _Arg2&& arg2) { - return std::unique_ptr<_Type>(new _Type(std::forward<_Arg1>(arg1), std::forward<_Arg2>(arg2))); - } - - template - std::unique_ptr<_Type> make_unique(_Arg1&& arg1, _Arg2&& arg2, _Arg3&& arg3) { - return std::unique_ptr<_Type>(new _Type(std::forward<_Arg1>(arg1), std::forward<_Arg2>(arg2), std::forward<_Arg3>(arg3))); - } - - template - std::unique_ptr<_Type> make_unique(_Arg1&& arg1, _Arg2&& arg2, _Arg3&& arg3, _Arg4&& arg4) { - return std::unique_ptr<_Type>(new _Type(std::forward<_Arg1>(arg1), std::forward<_Arg2>(arg2), std::forward<_Arg3>(arg3), std::forward<_Arg4>(arg4))); - } - /// /// Cross platform utility function for performing case insensitive string equality comparision. /// /// First string to compare. /// Second strong to compare. /// true if the strings are equivalent, false otherwise - _ASYNCRTIMP bool __cdecl str_iequal(const std::string &left, const std::string &right) CPPREST_NOEXCEPT; + _ASYNCRTIMP bool __cdecl str_iequal(const utility::string &left, const utility::string &right) CPPREST_NOEXCEPT; /// /// Cross platform utility function for performing case insensitive string equality comparision. @@ -440,7 +425,7 @@ namespace details /// First string to compare. /// Second strong to compare. /// true if the strings are equivalent, false otherwise - _ASYNCRTIMP bool __cdecl str_iequal(const std::wstring &left, const std::wstring &right) CPPREST_NOEXCEPT; + _ASYNCRTIMP bool __cdecl str_iequal(const utility::wstring &left, const utility::wstring &right) CPPREST_NOEXCEPT; /// /// Cross platform utility function for performing case insensitive string less-than comparision. @@ -448,7 +433,7 @@ namespace details /// First string to compare. /// Second strong to compare. /// true if a lowercase view of left is lexicographically less than a lowercase view of right; otherwise, false. - _ASYNCRTIMP bool __cdecl str_iless(const std::string &left, const std::string &right) CPPREST_NOEXCEPT; + _ASYNCRTIMP bool __cdecl str_iless(const utility::string &left, const utility::string &right) CPPREST_NOEXCEPT; /// /// Cross platform utility function for performing case insensitive string less-than comparision. @@ -456,19 +441,19 @@ namespace details /// First string to compare. /// Second strong to compare. /// true if a lowercase view of left is lexicographically less than a lowercase view of right; otherwise, false. - _ASYNCRTIMP bool __cdecl str_iless(const std::wstring &left, const std::wstring &right) CPPREST_NOEXCEPT; + _ASYNCRTIMP bool __cdecl str_iless(const utility::wstring &left, const utility::wstring &right) CPPREST_NOEXCEPT; /// /// Convert a string to lowercase in place. /// /// The string to convert to lowercase. - _ASYNCRTIMP void __cdecl inplace_tolower(std::string &target) CPPREST_NOEXCEPT; + _ASYNCRTIMP void __cdecl inplace_tolower(utility::string &target) CPPREST_NOEXCEPT; /// /// Convert a string to lowercase in place. /// /// The string to convert to lowercase. - _ASYNCRTIMP void __cdecl inplace_tolower(std::wstring &target) CPPREST_NOEXCEPT; + _ASYNCRTIMP void __cdecl inplace_tolower(utility::wstring &target) CPPREST_NOEXCEPT; #ifdef _WIN32 @@ -528,7 +513,7 @@ inline std::error_code __cdecl create_error_code(unsigned long errorCode) /// inline utility::string_t __cdecl create_error_message(unsigned long errorCode) { - return utility::conversions::to_string_t(create_error_code(errorCode).message()); + return utility::conversions::to_string_t(create_error_code(errorCode).message().c_str()); } } diff --git a/Release/include/cpprest/base_uri.h b/Release/include/cpprest/base_uri.h index b5fc8fcfd0..bcf3502ad9 100644 --- a/Release/include/cpprest/base_uri.h +++ b/Release/include/cpprest/base_uri.h @@ -78,7 +78,7 @@ namespace web { { public: - uri_exception(std::string msg) : m_msg(std::move(msg)) {} + uri_exception(utility::string msg) : m_msg(std::move(msg)) {} ~uri_exception() CPPREST_NOEXCEPT {} @@ -88,7 +88,7 @@ namespace web { } private: - std::string m_msg; + utility::string m_msg; }; /// @@ -167,15 +167,15 @@ namespace web { /// Splits a path into its hierarchical components. /// /// The path as a string - /// A std::vector<utility::string_t> containing the segments in the path. - _ASYNCRTIMP static std::vector __cdecl split_path(const utility::string_t &path); + /// A utility::vector<utility::string_t> containing the segments in the path. + _ASYNCRTIMP static utility::vector __cdecl split_path(const utility::string_t &path); /// /// Splits a query into its key-value components. /// /// The query string - /// A std::map<utility::string_t, utility::string_t> containing the key-value components of the query. - _ASYNCRTIMP static std::map __cdecl split_query(const utility::string_t &query); + /// A utility::map<utility::string_t, utility::string_t> containing the key-value components of the query. + _ASYNCRTIMP static utility::map __cdecl split_query(const utility::string_t &query); /// /// Validates a string as a URI. diff --git a/Release/include/cpprest/containerstream.h b/Release/include/cpprest/containerstream.h index 63ead19f9b..7050e74013 100644 --- a/Release/include/cpprest/containerstream.h +++ b/Release/include/cpprest/containerstream.h @@ -55,6 +55,25 @@ namespace Concurrency { namespace streams { return m_data; } + /// + /// Constructor + /// + basic_container_buffer(std::ios_base::openmode mode) + : streambuf_state_manager(mode), + m_current_position(0) { + validate_mode(mode); + } + + /// + /// Constructor + /// + basic_container_buffer(_CollectionType data, std::ios_base::openmode mode) + : streambuf_state_manager(mode), + m_data(std::move(data)), + m_current_position((mode & std::ios_base::in) ? 0 : m_data.size()) { + validate_mode(mode); + } + /// /// Destructor /// @@ -363,27 +382,6 @@ namespace Concurrency { namespace streams { private: template friend class streams::container_buffer; - /// - /// Constructor - /// - basic_container_buffer(std::ios_base::openmode mode) - : streambuf_state_manager(mode), - m_current_position(0) - { - validate_mode(mode); - } - - /// - /// Constructor - /// - basic_container_buffer(_CollectionType data, std::ios_base::openmode mode) - : streambuf_state_manager(mode), - m_data(std::move(data)), - m_current_position((mode & std::ios_base::in) ? 0 : m_data.size()) - { - validate_mode(mode); - } - static void validate_mode(std::ios_base::openmode mode) { // Disallow simultaneous use of the stream buffer for writing and reading. @@ -520,7 +518,7 @@ namespace Concurrency { namespace streams { /// The I/O mode that the buffer should use (in / out) container_buffer(_CollectionType data, std::ios_base::openmode mode = std::ios_base::in) : streambuf( - std::shared_ptr>(new streams::details::basic_container_buffer<_CollectionType>(std::move(data), mode))) + utility::make_shared>(std::move(data), mode)) { } @@ -530,7 +528,7 @@ namespace Concurrency { namespace streams { /// The I/O mode that the buffer should use (in / out) container_buffer(std::ios_base::openmode mode = std::ios_base::out) : streambuf( - std::shared_ptr>(new details::basic_container_buffer<_CollectionType>(mode))) + utility::make_shared>(mode)) { } @@ -579,7 +577,7 @@ namespace Concurrency { namespace streams { /// The stringstream allows an input stream to be constructed from std::string or std::wstring /// For output streams the underlying string container could be retrieved using buf->collection(). /// - typedef container_stream> stringstream; + typedef container_stream> stringstream; typedef stringstream::buffer_type stringstreambuf; typedef container_stream wstringstream; diff --git a/Release/include/cpprest/details/basic_types.h b/Release/include/cpprest/details/basic_types.h index eadba01684..5fc5063bd5 100644 --- a/Release/include/cpprest/details/basic_types.h +++ b/Release/include/cpprest/details/basic_types.h @@ -13,7 +13,12 @@ #pragma once +#include +#include +#include +#include #include +#include #include #include #include @@ -43,20 +48,358 @@ typedef uint64_t size64_t; typedef uint32_t HRESULT; // Needed for PPLX #endif +#if defined _WIN32 && !defined _DLL +// TEMPLATE CLASS allocator +template +class allocator : public std::allocator<_Ty> { +public: + typedef allocator<_Ty> _Alloc; + typedef std::allocator<_Ty> _Mybase; + + template + struct rebind { + // convert this type to allocator<_Other> + typedef allocator<_Other> other; + }; + + allocator() CPPREST_NOEXCEPT : _Mybase() { + // construct default allocator (do nothing) + } + + allocator(const _Alloc& _Right) CPPREST_NOEXCEPT : _Mybase(_Right) { + // construct by copying (do nothing) + } + + allocator(_Alloc&& _Right) CPPREST_NOEXCEPT : _Mybase(std::move(_Right)) { + // construct by moving (do nothing) + } + + template + allocator(const allocator<_Other>& _Right) CPPREST_NOEXCEPT : _Mybase(_Right) { + // construct from a related allocator (do nothing) + } + + template + allocator(allocator<_Other>&& _Right) CPPREST_NOEXCEPT : _Mybase(std::forward<_Other>(_Right)) { + // construct from a related allocator (do nothing) + } + + _Alloc& operator=(const _Alloc& _Right) { + // assign by copying + _Mybase::operator=(_Right); + return (*this); + } + + _Alloc& operator=(_Alloc&& _Right) { + // assign by moving + _Mybase::operator=(std::move(_Right)); + return (*this); + } + + template + _Alloc& operator=(const allocator<_Other>&) { + // assign from a related allocator + _Mybase::operator=(std::forward<_Other>(_Right)); + return (*this); + } + + _DECLSPEC_ALLOCATOR pointer allocate(size_type _Count) { + // allocate array of _Count elements + return static_cast(::HeapAlloc(::GetProcessHeap(), NULL, _Count * sizeof(_Ty))); + } + + _DECLSPEC_ALLOCATOR pointer allocate(size_type _Count, const void *) { + // allocate array of _Count elements, ignore hint + return allocate(_Count); + } + + void deallocate(pointer _Ptr, size_type _Count) { + // deallocate object at _Ptr + UNREFERENCED_PARAMETER(_Count); + ::HeapFree(::GetProcessHeap(), NULL, _Ptr); + } +}; + +template +inline bool operator == (const allocator<_Ty1>&, const allocator<_Ty2>&) { + return true; +} + +template +inline bool operator != (const allocator<_Ty1>& _Left, const allocator<_Ty2>& _Right) { + return !(_Left == _Right); +} + +// TEMPLATE CLASS secure_allocator +template +class secure_allocator : public utility::allocator<_Ty> { +public: + typedef secure_allocator<_Ty> _Alloc; + typedef utility::allocator<_Ty> _Mybase; + + template + struct rebind { + // convert this type to secure_allocator<_Other> + typedef secure_allocator<_Other> other; + }; + + secure_allocator() CPPREST_NOEXCEPT : _Mybase() { + // construct default secure_allocator (do nothing) + } + + secure_allocator(const _Alloc& _Right) CPPREST_NOEXCEPT : _Mybase(_Right) { + // construct by copying (do nothing) + } + + secure_allocator(_Alloc&& _Right) CPPREST_NOEXCEPT : _Mybase(std::move(_Right)) { + // construct by moving (do nothing) + } + + template + secure_allocator(const secure_allocator<_Other>& _Right) CPPREST_NOEXCEPT : _Mybase(_Right) { + // construct from a related secure_allocator (do nothing) + } + + template + secure_allocator(secure_allocator<_Other>&& _Right) CPPREST_NOEXCEPT : _Mybase(std::forward<_Other>(_Right)) { + // construct from a related secure_allocator (do nothing) + } + + _Alloc& operator=(const _Alloc& _Right) { + // assign by copying + _Mybase::operator=(_Right); + return (*this); + } + + _Alloc& operator=(_Alloc&& _Right) { + // assign by moving + _Mybase::operator=(std::move(_Right)); + return (*this); + } + + template + _Alloc& operator=(const secure_allocator<_Other>&) { + // assign from a related secure_allocator + _Mybase::operator=(std::forward<_Other>(_Right)); + return (*this); + } + + _DECLSPEC_ALLOCATOR pointer allocate(size_type _Count) { + // allocate array of _Count elements + return static_cast(::HeapAlloc(::GetProcessHeap(), NULL, _Count * sizeof(_Ty))); + } + + _DECLSPEC_ALLOCATOR pointer allocate(size_type _Count, const void *) { + // allocate array of _Count elements, ignore hint + return allocate(_Count); + } + + void deallocate(pointer _Ptr, size_type _Count) { + // deallocate object at _Ptr + ::SecureZeroMemory(_Ptr, _Count * sizeof(_Ty)); + ::HeapFree(::GetProcessHeap(), NULL, _Ptr); + } +}; + +template +inline bool operator == (const secure_allocator<_Ty1>&, const secure_allocator<_Ty2>&) { + return true; +} + +template +inline bool operator != (const secure_allocator<_Ty1>& _Left, const secure_allocator<_Ty2>& _Right) { + return !(_Left == _Right); +} +#else +template +using allocator = std::allocator<_Ty>; +#endif + +#if defined _WIN32 && !defined _DLL +// TEMPLATE CLASS unique_ptr_deleter +template +struct unique_ptr_deleter { + // deleter for unique_ptr + constexpr unique_ptr_deleter() CPPREST_NOEXCEPT = default; + + template::value, void>::type> + unique_ptr_deleter(const unique_ptr_deleter<_Ty2>&) CPPREST_NOEXCEPT { + // construct from another unique_ptr_deleter + } + + void operator()(_Ty *_Ptr) const CPPREST_NOEXCEPT { + // delete a pointer + static_assert(0 < sizeof(_Ty), "can't delete an incomplete type"); + // destroy object at _Ptr + _Ptr->~_Ty(); + ::HeapFree(::GetProcessHeap(), NULL, _Ptr); + } +}; + +template +struct unique_ptr_deleter<_Ty[]> { + // deleter for unique_ptr to array of unknown size + constexpr unique_ptr_deleter() CPPREST_NOEXCEPT = default; + + template::value, void>::type> + unique_ptr_deleter(const unique_ptr_deleter<_Uty[]>&) CPPREST_NOEXCEPT { + // construct from another unique_ptr_deleter + } + + template::value, void>::type> + void operator()(_Uty *_Array) const CPPREST_NOEXCEPT { + // delete a pointer + static_assert(0 < sizeof(_Uty), "can't delete an incomplete type"); + // destroy object at _Ptr + size_t *_Ptr = reinterpret_cast(_Array); + + if (!std::is_trivially_destructible<_Uty>::value) { + // Call destructor for non-trivially destructible types + size_t _Count = *(--_Ptr); + for (size_t _Idx = _Count; _Idx > 0; --_Idx) { + _Array[_Idx - 1].~_Uty(); + } + } + + ::HeapFree(::GetProcessHeap(), NULL, _Ptr); + } + +}; + +template +struct secure_unique_ptr_deleter : public unique_ptr_deleter<_Ty> { + // deleter for unique_ptr + constexpr secure_unique_ptr_deleter() CPPREST_NOEXCEPT = default; + + template::value, void>::type> + secure_unique_ptr_deleter(const secure_unique_ptr_deleter<_Ty2>&) CPPREST_NOEXCEPT { + // construct from another secure_unique_ptr_deleter + } + + void operator()(_Ty *_Ptr) const CPPREST_NOEXCEPT { + // delete a pointer + static_assert(0 < sizeof(_Ty), "can't delete an incomplete type"); + // destroy object at _Ptr + _Ptr->~_Ty(); + ::SecureZeroMemory(_Ptr, sizeof(_Ty)); + ::HeapFree(::GetProcessHeap(), NULL, _Ptr); + } +}; +#else +template +using unique_ptr_deleter = std::default_delete<_Ty> + +template +using secure_unique_ptr_deleter = std::default_delete<_Ty> +#endif + +template> +using unique_ptr = std::unique_ptr<_Ty, _Dx>; + +template> +using secure_unique_ptr = std::unique_ptr<_Ty, _Dx>; + +// TEMPLATE FUNCTION make_unique +template, class... _Types> inline + typename std::enable_if::value, + std::unique_ptr<_Ty, _Dx>>::type make_unique(_Types&&... _Args) { + // make a unique_ptr +#if defined _WIN32 && !defined _DLL + _Ty* _Ptr = static_cast<_Ty*>(::HeapAlloc(::GetProcessHeap(), NULL, sizeof(_Ty))); + return std::unique_ptr<_Ty, _Dx>(new(_Ptr) _Ty(std::forward<_Types>(_Args)...)); +#else + return std::unique_ptr<_Ty, _Dx>(new _Ty(std::forward<_Types>(_Args)...)); +#endif +} + +template> inline +typename std::enable_if::value && std::extent<_Ty>::value == 0, + std::unique_ptr<_Ty, _Dx>>::type make_unique(size_t _Count) { + // make a unique_ptr +#if defined _WIN32 && !defined _DLL + typedef typename std::remove_extent<_Ty>::type _Elem; + + size_t _Size = _Count * sizeof(_Elem); + if (!std::is_trivially_destructible<_Elem>::value) { + // Extra space for new[] overhead for non-trivially destructible types + _Size += sizeof(size_t); + } + + _Elem* _Ptr = static_cast<_Elem*>(::HeapAlloc(::GetProcessHeap(), NULL, _Size)); + _Elem* _Array = new(_Ptr) _Elem[_Count](); + + return std::unique_ptr<_Ty, _Dx>(_Array); +#else + return std::unique_ptr<_Ty, _Dx>(new _Elem[_Count]()); +#endif +} + +template, class... _Types> +typename std::enable_if::value != 0, + void>::type make_unique(_Types&&...) = delete; + + +// TEMPLATE FUNCTION make_shared +template, typename... _Types> +inline std::shared_ptr<_Ty> make_shared(_Types&&... _Args) { + // make a shared_ptr + return std::allocate_shared<_Ty, _Alloc>(_Alloc(), std::forward<_Types>(_Args)...); +} + + +template> +using vector = std::vector<_Ty, _Alloc>; + +template, class _Alloc = utility::allocator>> +using map = std::map<_Kty, _Ty, _Pr, _Alloc>; + +template, class _Keyeq = std::equal_to<_Kty>, class _Alloc = utility::allocator>> +using unordered_map = std::unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>; + +template> +using deque = std::deque<_Ty, _Alloc>; + +template> +using queue = std::queue<_Ty, _Container>; + +template, class _Alloc = utility::allocator<_Ty>> +using basic_string = std::basic_string<_Ty, _Traits, _Alloc>; +template, class _Alloc = utility::allocator<_Ty>> +using basic_ostringstream = std::basic_ostringstream<_Ty, _Traits, _Alloc>; +template, class _Alloc = utility::allocator<_Ty>> +using basic_istringstream = std::basic_istringstream<_Ty, _Traits, _Alloc>; +template, class _Alloc = utility::allocator<_Ty>> +using basic_stringstream = std::basic_stringstream<_Ty, _Traits, _Alloc>; + +typedef utility::basic_string string; +typedef std::basic_string, utility::secure_allocator> secure_string; +typedef std::unique_ptr> secure_unique_string; +typedef utility::basic_ostringstream ostringstream; +typedef utility::basic_istringstream istringstream; +typedef utility::basic_stringstream stringstream; + +typedef utility::basic_string wstring; +typedef std::basic_string, utility::secure_allocator> secure_wstring; +typedef std::unique_ptr> secure_unique_wstring; +typedef utility::basic_ostringstream wostringstream; +typedef utility::basic_istringstream wistringstream; +typedef utility::basic_stringstream wstringstream; + #ifdef _UTF16_STRINGS // // On Windows, all strings are wide // -typedef wchar_t char_t ; -typedef std::wstring string_t; +typedef wchar_t char_t; +typedef utility::wstring string_t; +typedef utility::secure_wstring secure_string_t; #define _XPLATSTR(x) L ## x -typedef std::wostringstream ostringstream_t; +typedef utility::wostringstream ostringstream_t; typedef std::wofstream ofstream_t; typedef std::wostream ostream_t; typedef std::wistream istream_t; typedef std::wifstream ifstream_t; -typedef std::wistringstream istringstream_t; -typedef std::wstringstream stringstream_t; +typedef utility::wistringstream istringstream_t; +typedef utility::wstringstream stringstream_t; #define ucout std::wcout #define ucin std::wcin #define ucerr std::wcerr @@ -65,15 +408,16 @@ typedef std::wstringstream stringstream_t; // On POSIX platforms, all strings are narrow // typedef char char_t; -typedef std::string string_t; +typedef utility::string string_t; +typedef utility::secure_string secure_string_t; #define _XPLATSTR(x) x -typedef std::ostringstream ostringstream_t; +typedef utility::ostringstream ostringstream_t; typedef std::ofstream ofstream_t; typedef std::ostream ostream_t; typedef std::istream istream_t; typedef std::ifstream ifstream_t; -typedef std::istringstream istringstream_t; -typedef std::stringstream stringstream_t; +typedef utility::istringstream istringstream_t; +typedef utility::stringstream stringstream_t; #define ucout std::cout #define ucin std::cin #define ucerr std::cerr @@ -89,29 +433,29 @@ typedef std::stringstream stringstream_t; }// namespace utility typedef char utf8char; -typedef std::string utf8string; -typedef std::stringstream utf8stringstream; -typedef std::ostringstream utf8ostringstream; +typedef utility::string utf8string; +typedef utility::stringstream utf8stringstream; +typedef utility::ostringstream utf8ostringstream; typedef std::ostream utf8ostream; typedef std::istream utf8istream; -typedef std::istringstream utf8istringstream; +typedef utility::istringstream utf8istringstream; #ifdef _UTF16_STRINGS typedef wchar_t utf16char; -typedef std::wstring utf16string; -typedef std::wstringstream utf16stringstream; -typedef std::wostringstream utf16ostringstream; +typedef utility::wstring utf16string; +typedef utility::wstringstream utf16stringstream; +typedef utility::wostringstream utf16ostringstream; typedef std::wostream utf16ostream; typedef std::wistream utf16istream; -typedef std::wistringstream utf16istringstream; +typedef utility::wistringstream utf16istringstream; #else typedef char16_t utf16char; typedef std::u16string utf16string; -typedef std::basic_stringstream utf16stringstream; -typedef std::basic_ostringstream utf16ostringstream; +typedef utility::basic_stringstream utf16stringstream; +typedef utility::basic_ostringstream utf16ostringstream; typedef std::basic_ostream utf16ostream; typedef std::basic_istream utf16istream; -typedef std::basic_istringstream utf16istringstream; +typedef utility::basic_istringstream utf16istringstream; #endif diff --git a/Release/include/cpprest/details/http_helpers.h b/Release/include/cpprest/details/http_helpers.h index 596ac9efaa..79346d9557 100644 --- a/Release/include/cpprest/details/http_helpers.h +++ b/Release/include/cpprest/details/http_helpers.h @@ -50,7 +50,7 @@ namespace details invalid = 9999 }; - using data_buffer = std::vector; + using data_buffer = utility::vector; class stream_decompressor { diff --git a/Release/include/cpprest/details/http_server_api.h b/Release/include/cpprest/details/http_server_api.h index e44e104f02..e71336bea4 100644 --- a/Release/include/cpprest/details/http_server_api.h +++ b/Release/include/cpprest/details/http_server_api.h @@ -46,7 +46,7 @@ class http_server_api /// /// Registers a HTTP server API. /// - static void __cdecl register_server_api(std::unique_ptr server_api); + static void __cdecl register_server_api(utility::unique_ptr server_api); /// /// Clears the http server API. @@ -74,10 +74,10 @@ class http_server_api static pplx::extensibility::critical_section_t s_lock; /// Registers a server API set -- this assumes the lock has already been taken - static void unsafe_register_server_api(std::unique_ptr server_api); + static void unsafe_register_server_api(utility::unique_ptr server_api); // Static instance of the HTTP server API. - static std::unique_ptr s_server_api; + static utility::unique_ptr s_server_api; /// Number of registered listeners; static pplx::details::atomic_long s_registrations; diff --git a/Release/include/cpprest/details/web_utilities.h b/Release/include/cpprest/details/web_utilities.h index c32a58e5e3..0d1da413f6 100644 --- a/Release/include/cpprest/details/web_utilities.h +++ b/Release/include/cpprest/details/web_utilities.h @@ -17,21 +17,14 @@ namespace web namespace details { -class zero_memory_deleter -{ -public: - _ASYNCRTIMP void operator()(::utility::string_t *data) const; -}; -typedef std::unique_ptr< ::utility::string_t, zero_memory_deleter> plaintext_string; - #if defined(_WIN32) && !defined(CPPREST_TARGET_XP) #if defined(__cplusplus_winrt) class winrt_encryption { public: winrt_encryption() {} - _ASYNCRTIMP winrt_encryption(const std::wstring &data); - _ASYNCRTIMP plaintext_string decrypt() const; + _ASYNCRTIMP winrt_encryption(const utility::wstring &data); + _ASYNCRTIMP secure_unique_wstring decrypt() const; private: ::pplx::task m_buffer; }; @@ -40,11 +33,11 @@ class win32_encryption { public: win32_encryption() {} - _ASYNCRTIMP win32_encryption(const std::wstring &data); + _ASYNCRTIMP win32_encryption(const utility::secure_wstring &data); _ASYNCRTIMP ~win32_encryption(); - _ASYNCRTIMP plaintext_string decrypt() const; + _ASYNCRTIMP utility::secure_unique_wstring decrypt() const; private: - std::vector m_buffer; + utility::vector> m_buffer; size_t m_numCharacters; }; #endif @@ -68,7 +61,7 @@ class credentials /// /// User name as a string. /// Password as a string. - credentials(utility::string_t username, const utility::string_t & password) : + credentials(utility::wstring username, const utility::secure_wstring &password) : m_username(std::move(username)), m_password(password) {} @@ -77,17 +70,17 @@ class credentials /// The user name associated with the credentials. /// /// A string containing the user name. - const utility::string_t &username() const { return m_username; } + const utility::wstring &username() const { return m_username; } /// /// The password for the user name associated with the credentials. /// /// A string containing the password. CASABLANCA_DEPRECATED("This API is deprecated for security reasons to avoid unnecessary password copies stored in plaintext.") - utility::string_t password() const + utility::secure_unique_wstring password() const { #if defined(_WIN32) && !defined(CPPREST_TARGET_XP) - return utility::string_t(*m_password.decrypt()); + return m_password.decrypt(); #else return m_password; #endif @@ -99,18 +92,25 @@ class credentials /// true if user name and password is set, false otherwise. bool is_set() const { return !m_username.empty(); } - details::plaintext_string _internal_decrypt() const + utility::secure_unique_wstring _internal_decrypt() const { // Encryption APIs not supported on XP #if defined(_WIN32) && !defined(CPPREST_TARGET_XP) return m_password.decrypt(); #else - return details::plaintext_string(new ::utility::string_t(m_password)); + return utility::make_unique>(m_password)); #endif } + utility::secure_unique_string to_base64() { + utility::wstring userpass = m_username + _XPLATSTR(":") + _internal_decrypt()->c_str(); + auto&& u8_userpass = utility::conversions::to_utf8string(userpass); + utility::vector> credentials_buffer(u8_userpass.begin(), u8_userpass.end()); + return utility::make_unique>(utility::conversions::to_utf8string(utility::conversions::to_base64(credentials_buffer)).c_str()); + } + private: - ::utility::string_t m_username; + utility::wstring m_username; #if defined(_WIN32) && !defined(CPPREST_TARGET_XP) #if defined(__cplusplus_winrt) @@ -119,7 +119,7 @@ class credentials details::win32_encryption m_password; #endif #else - ::utility::string_t m_password; + utility::secure_wstring m_password; #endif }; diff --git a/Release/include/cpprest/filestream.h b/Release/include/cpprest/filestream.h index b8b982556a..a5c65b7489 100644 --- a/Release/include/cpprest/filestream.h +++ b/Release/include/cpprest/filestream.h @@ -278,7 +278,7 @@ namespace details { std::shared_ptr<_CharType> sharedCh; try { - sharedCh = std::make_shared<_CharType>(ch); + sharedCh = utility::make_shared<_CharType>(ch); } catch (const std::bad_alloc &) { delete callback; @@ -374,7 +374,7 @@ namespace details { { if (copy) { - auto sharedData = std::make_shared>(ptr, ptr + count); + auto sharedData = utility::make_shared>(ptr, ptr + count); return _putn(ptr, count).then([sharedData](size_t size) { return size; @@ -715,7 +715,7 @@ namespace details { pplx::task flush_internal() { pplx::task_completion_event result_tce; - auto callback = utility::details::make_unique<_filestream_callback_write_b>(m_info, result_tce); + auto callback = utility::make_unique<_filestream_callback_write_b>(m_info, result_tce); if ( !_sync_fsb(m_info, callback.get()) ) { @@ -763,7 +763,7 @@ namespace details { virtual void on_opened(_In_ _file_info *info) { - m_op.set(std::shared_ptr>(new basic_file_buffer<_CharType>(info))); + m_op.set(utility::make_shared>(info)); delete this; } diff --git a/Release/include/cpprest/http_client.h b/Release/include/cpprest/http_client.h index f5ad8fac70..b545a887fa 100644 --- a/Release/include/cpprest/http_client.h +++ b/Release/include/cpprest/http_client.h @@ -112,7 +112,7 @@ class http_client_config /// OAuth 1.0 configuration to set. void set_oauth1(oauth1::experimental::oauth1_config config) { - m_oauth1 = std::make_shared(std::move(config)); + m_oauth1 = utility::make_shared(std::move(config)); } #endif @@ -131,7 +131,7 @@ class http_client_config /// OAuth 2.0 configuration to set. void set_oauth2(oauth2::experimental::oauth2_config config) { - m_oauth2 = std::make_shared(std::move(config)); + m_oauth2 = utility::make_shared(std::move(config)); } /// @@ -561,7 +561,7 @@ class http_client const pplx::cancellation_token &token = pplx::cancellation_token::none()) { http_request msg(mtd); - msg.set_request_uri(::utility::conversions::to_string_t(path_query_fragment)); + msg.set_request_uri(utility::conversions::to_string_t(path_query_fragment)); msg.set_body(body_data, content_type); return request(msg, token); } @@ -584,7 +584,7 @@ class http_client const pplx::cancellation_token &token = pplx::cancellation_token::none()) { http_request msg(mtd); - msg.set_request_uri(::utility::conversions::to_string_t(path_query_fragment)); + msg.set_request_uri(utility::conversions::to_string_t(path_query_fragment)); msg.set_body(std::move(body_data), content_type); return request(msg, token); } @@ -607,7 +607,7 @@ class http_client const pplx::cancellation_token &token = pplx::cancellation_token::none()) { http_request msg(mtd); - msg.set_request_uri(::utility::conversions::to_string_t(path_query_fragment)); + msg.set_request_uri(utility::conversions::to_string_t(path_query_fragment)); msg.set_body(body_data, content_type); return request(msg, token); } @@ -646,7 +646,7 @@ class http_client const pplx::cancellation_token &token) { http_request msg(mtd); - msg.set_request_uri(::utility::conversions::to_string_t(path_query_fragment)); + msg.set_request_uri(utility::conversions::to_string_t(path_query_fragment)); msg.set_body(std::move(body_data), "text/plain; charset=utf-8"); return request(msg, token); } @@ -666,7 +666,7 @@ class http_client const utf16string &body_data, const pplx::cancellation_token &token) { - return request(mtd, path_query_fragment, body_data, ::utility::conversions::to_utf16string("text/plain"), token); + return request(mtd, path_query_fragment, body_data, utility::conversions::to_utf16string("text/plain"), token); } #if !defined (__cplusplus_winrt) diff --git a/Release/include/cpprest/http_headers.h b/Release/include/cpprest/http_headers.h index c2e35f6079..10e25221ae 100644 --- a/Release/include/cpprest/http_headers.h +++ b/Release/include/cpprest/http_headers.h @@ -73,7 +73,7 @@ class http_headers }; private: - typedef std::map inner_container; + typedef utility::map inner_container; public: /// @@ -306,7 +306,7 @@ class http_headers return true; } - bool bind_impl(const key_type &text, std::string &ref) const + bool bind_impl(const key_type &text, utility::string &ref) const { ref = utility::conversions::to_utf8string(text); return true; diff --git a/Release/include/cpprest/http_listener.h b/Release/include/cpprest/http_listener.h index c8059e02ba..b75ca4dd38 100644 --- a/Release/include/cpprest/http_listener.h +++ b/Release/include/cpprest/http_listener.h @@ -208,7 +208,7 @@ class http_listener_impl // Handlers std::function m_all_requests; - std::map> m_supported_methods; + utility::map> m_supported_methods; private: @@ -242,7 +242,7 @@ class http_listener /// The listener will not have been opened when returned. /// URI at which the listener should accept requests. http_listener(http::uri address) - : m_impl(utility::details::make_unique(std::move(address))) + : m_impl(utility::make_unique(std::move(address))) { } @@ -252,7 +252,7 @@ class http_listener /// URI at which the listener should accept requests. /// Configuration to create listener with. http_listener(http::uri address, http_listener_config config) - : m_impl(utility::details::make_unique(std::move(address), std::move(config))) + : m_impl(utility::make_unique(std::move(address), std::move(config))) { } @@ -262,7 +262,7 @@ class http_listener /// The resulting listener cannot be used for anything, but is useful to initialize a variable /// that will later be overwritten with a real listener instance. http_listener() - : m_impl(utility::details::make_unique()) + : m_impl(utility::make_unique()) { } @@ -270,7 +270,16 @@ class http_listener /// Destructor frees any held resources. /// /// Call close() before allowing a listener to be destroyed. - _ASYNCRTIMP ~http_listener(); + ~http_listener() { + if (m_impl) { + // As a safe guard close the listener if not already done. + // Users are required to call close, but this is just a safeguard. + try { + m_impl->close().wait(); + } catch (...) { + } + } + } /// /// Asynchronously open the listener, i.e. start accepting requests. @@ -356,7 +365,7 @@ class http_listener http_listener(const http_listener &other); http_listener &operator=(const http_listener &other); - std::unique_ptr m_impl; + utility::unique_ptr m_impl; }; }}}} diff --git a/Release/include/cpprest/http_msg.h b/Release/include/cpprest/http_msg.h index b85e98ff42..af4153018c 100644 --- a/Release/include/cpprest/http_msg.h +++ b/Release/include/cpprest/http_msg.h @@ -63,12 +63,12 @@ struct http_version /// Creates http_version from an HTTP-Version string, "HTTP" "/" 1*DIGIT "." 1*DIGIT. /// /// Returns a http_version of {0, 0} if not successful. - static _ASYNCRTIMP http_version __cdecl from_string(const std::string& http_version_string); + static _ASYNCRTIMP http_version __cdecl from_string(const utility::string& http_version_string); /// /// Returns the string representation of the http_version. /// - _ASYNCRTIMP std::string to_utf8string() const; + _ASYNCRTIMP utility::string to_utf8string() const; }; /// @@ -200,7 +200,7 @@ class http_exception : public std::exception /// Creates an http_exception with just a string message and no error code. /// /// Error message string. - http_exception(std::string whatArg) : m_msg(std::move(whatArg)) {} + http_exception(utility::string whatArg) : m_msg(std::move(whatArg)) {} #endif /// @@ -211,7 +211,7 @@ class http_exception : public std::exception http_exception(int errorCode) : m_errorCode(utility::details::create_error_code(errorCode)) { - m_msg = m_errorCode.message(); + m_msg = m_errorCode.message().c_str(); } /// @@ -230,7 +230,7 @@ class http_exception : public std::exception /// /// Error code value. /// Message to use in what() string. - http_exception(int errorCode, std::string whatArg) : + http_exception(int errorCode, utility::string whatArg) : m_errorCode(utility::details::create_error_code(errorCode)), m_msg(std::move(whatArg)) {} @@ -244,7 +244,7 @@ class http_exception : public std::exception /// Error category for the code. http_exception(int errorCode, const std::error_category &cat) : m_errorCode(std::error_code(errorCode, cat)) { - m_msg = m_errorCode.message(); + m_msg = m_errorCode.message().c_str(); } /// @@ -267,7 +267,7 @@ class http_exception : public std::exception private: std::error_code m_errorCode; - std::string m_msg; + utility::string m_msg; }; namespace details @@ -309,7 +309,7 @@ class http_msg_base _ASYNCRTIMP utility::string_t extract_string(bool ignore_content_type = false); _ASYNCRTIMP json::value _extract_json(bool ignore_content_type = false); - _ASYNCRTIMP std::vector _extract_vector(); + _ASYNCRTIMP utility::vector _extract_vector(); virtual _ASYNCRTIMP utility::string_t to_string() const; @@ -422,10 +422,10 @@ class _http_response final : public http::details::http_msg_base _http_server_context * _get_server_context() const { return m_server_context.get(); } - void _set_server_context(std::unique_ptr server_context) { m_server_context = std::move(server_context); } + void _set_server_context(utility::unique_ptr server_context) { m_server_context = std::move(server_context); } private: - std::unique_ptr<_http_server_context> m_server_context; + utility::unique_ptr<_http_server_context> m_server_context; http::status_code m_status_code; http::reason_phrase m_reason_phrase; @@ -445,7 +445,7 @@ class http_response /// Constructs a response with an empty status code, no headers, and no body. /// /// A new HTTP response. - http_response() : _m_impl(std::make_shared()) { } + http_response() : _m_impl(utility::make_shared()) { } /// /// Constructs a response with given status code, no headers, and no body. @@ -453,7 +453,7 @@ class http_response /// HTTP status code to use in response. /// A new HTTP response. http_response(http::status_code code) - : _m_impl(std::make_shared(code)) { } + : _m_impl(utility::make_shared(code)) { } /// /// Gets the status code of the response message. @@ -563,7 +563,7 @@ class http_response /// Extracts the body of the response message into a vector of bytes. /// /// The body of the message as a vector of bytes. - pplx::task> extract_vector() const + pplx::task> extract_vector() const { auto impl = _m_impl; return pplx::create_task(_m_impl->_get_data_available()).then([impl](utility::size64_t) { return impl->_extract_vector(); }); @@ -581,7 +581,7 @@ class http_response void set_body(utf8string &&body_text, const utf8string &content_type = utf8string("text/plain; charset=utf-8")) { const auto length = body_text.size(); - _m_impl->set_body(concurrency::streams::bytestream::open_istream(std::move(body_text)), length, content_type); + _m_impl->set_body(concurrency::streams::bytestream::open_istream(std::move(body_text)), length, content_type); } /// @@ -595,7 +595,7 @@ class http_response /// void set_body(const utf8string &body_text, const utf8string &content_type = utf8string("text/plain; charset=utf-8")) { - _m_impl->set_body(concurrency::streams::bytestream::open_istream(body_text), body_text.size(), content_type); + _m_impl->set_body(concurrency::streams::bytestream::open_istream(body_text), body_text.size(), content_type); } /// @@ -609,17 +609,17 @@ class http_response /// void set_body(const utf16string &body_text, utf16string content_type = utility::conversions::to_utf16string("text/plain")) { - if (content_type.find(::utility::conversions::to_utf16string("charset=")) != content_type.npos) + if (content_type.find(utility::conversions::to_utf16string("charset=")) != content_type.npos) { throw std::invalid_argument("content_type can't contain a 'charset'."); } auto utf8body = utility::conversions::utf16_to_utf8(body_text); auto length = utf8body.size(); - _m_impl->set_body(concurrency::streams::bytestream::open_istream( + _m_impl->set_body(concurrency::streams::bytestream::open_istream( std::move(utf8body)), length, - std::move(content_type.append(::utility::conversions::to_utf16string("; charset=utf-8")))); + std::move(content_type.append(utility::conversions::to_utf16string("; charset=utf-8")))); } /// @@ -645,7 +645,7 @@ class http_response /// /// This will overwrite any previously set body data. /// - void set_body(std::vector &&body_data) + void set_body(utility::vector &&body_data) { auto length = body_data.size(); set_body(concurrency::streams::bytestream::open_istream(std::move(body_data)), length); @@ -659,7 +659,7 @@ class http_response /// /// This will overwrite any previously set body data. /// - void set_body(const std::vector &body_data) + void set_body(const utility::vector &body_data) { set_body(concurrency::streams::bytestream::open_istream(body_data), body_data.size()); } @@ -723,7 +723,7 @@ class http_response std::shared_ptr _get_impl() const { return _m_impl; } http::details::_http_server_context * _get_server_context() const { return _m_impl->_get_server_context(); } - void _set_server_context(std::unique_ptr server_context) { _m_impl->_set_server_context(std::move(server_context)); } + void _set_server_context(utility::unique_ptr server_context) { _m_impl->_set_server_context(std::move(server_context)); } private: @@ -740,7 +740,7 @@ class _http_request final : public http::details::http_msg_base, public std::ena _ASYNCRTIMP _http_request(http::method mtd); - _ASYNCRTIMP _http_request(std::unique_ptr server_context); + _ASYNCRTIMP _http_request(utility::unique_ptr server_context); virtual ~_http_request() {} @@ -783,7 +783,7 @@ class _http_request final : public http::details::http_msg_base, public std::ena void set_progress_handler(const progress_handler &handler) { - m_progress_handler = std::make_shared(handler); + m_progress_handler = utility::make_shared(handler); } const concurrency::streams::ostream & _response_stream() const { return m_response_stream; } @@ -792,7 +792,7 @@ class _http_request final : public http::details::http_msg_base, public std::ena http::details::_http_server_context * _get_server_context() const { return m_server_context.get(); } - void _set_server_context(std::unique_ptr server_context) { m_server_context = std::move(server_context); } + void _set_server_context(utility::unique_ptr server_context) { m_server_context = std::move(server_context); } void _set_listener_path(const utility::string_t &path) { m_listener_path = path; } @@ -812,7 +812,7 @@ class _http_request final : public http::details::http_msg_base, public std::ena // Tracks whether or not a response has already been started for this message. pplx::details::atomic_long m_initiated_response; - std::unique_ptr m_server_context; + utility::unique_ptr m_server_context; pplx::cancellation_token m_cancellationToken; @@ -844,14 +844,14 @@ class http_request /// Constructs a new HTTP request with the 'GET' method. /// http_request() - : _m_impl(std::make_shared(methods::GET)) {} + : _m_impl(utility::make_shared(methods::GET)) {} /// /// Constructs a new HTTP request with the given request method. /// /// Request method. http_request(http::method mtd) - : _m_impl(std::make_shared(std::move(mtd))) {} + : _m_impl(utility::make_shared(std::move(mtd))) {} /// /// Destructor frees any held resources. @@ -987,7 +987,7 @@ class http_request /// Extract the body of the response message into a vector of bytes. Extracting a vector can be done on /// /// The body of the message as a vector of bytes. - pplx::task> extract_vector() const + pplx::task> extract_vector() const { auto impl = _m_impl; return pplx::create_task(_m_impl->_get_data_available()).then([impl](utility::size64_t) { return impl->_extract_vector(); }); @@ -1005,7 +1005,7 @@ class http_request void set_body(utf8string &&body_text, const utf8string &content_type = utf8string("text/plain; charset=utf-8")) { const auto length = body_text.size(); - _m_impl->set_body(concurrency::streams::bytestream::open_istream(std::move(body_text)), length, content_type); + _m_impl->set_body(concurrency::streams::bytestream::open_istream(std::move(body_text)), length, content_type); } /// @@ -1019,7 +1019,7 @@ class http_request /// void set_body(const utf8string &body_text, const utf8string &content_type = utf8string("text/plain; charset=utf-8")) { - _m_impl->set_body(concurrency::streams::bytestream::open_istream(body_text), body_text.size(), content_type); + _m_impl->set_body(concurrency::streams::bytestream::open_istream(body_text), body_text.size(), content_type); } /// @@ -1034,7 +1034,7 @@ class http_request /// void set_body(const utf16string &body_text, utf16string content_type = utility::conversions::to_utf16string("text/plain")) { - if(content_type.find(::utility::conversions::to_utf16string("charset=")) != content_type.npos) + if(content_type.find(utility::conversions::to_utf16string("charset=")) != content_type.npos) { throw std::invalid_argument("content_type can't contain a 'charset'."); } @@ -1044,7 +1044,7 @@ class http_request _m_impl->set_body(concurrency::streams::bytestream::open_istream( std::move(utf8body)), length, - std::move(content_type.append(::utility::conversions::to_utf16string("; charset=utf-8")))); + std::move(content_type.append(utility::conversions::to_utf16string("; charset=utf-8")))); } /// @@ -1070,7 +1070,7 @@ class http_request /// /// This will overwrite any previously set body data. /// - void set_body(std::vector &&body_data) + void set_body(utility::vector &&body_data) { auto length = body_data.size(); _m_impl->set_body(concurrency::streams::bytestream::open_istream(std::move(body_data)), length, _XPLATSTR("application/octet-stream")); @@ -1084,7 +1084,7 @@ class http_request /// /// This will overwrite any previously set body data. /// - void set_body(const std::vector &body_data) + void set_body(const utility::vector &body_data) { set_body(concurrency::streams::bytestream::open_istream(body_data), body_data.size()); } @@ -1341,8 +1341,8 @@ class http_request /// /// These are used for the initial creation of the HTTP request. /// - static http_request _create_request(std::unique_ptr server_context) { return http_request(std::move(server_context)); } - void _set_server_context(std::unique_ptr server_context) { _m_impl->_set_server_context(std::move(server_context)); } + static http_request _create_request(utility::unique_ptr server_context) { return http_request(std::move(server_context)); } + void _set_server_context(utility::unique_ptr server_context) { _m_impl->_set_server_context(std::move(server_context)); } void _set_listener_path(const utility::string_t &path) { _m_impl->_set_listener_path(path); } @@ -1367,7 +1367,7 @@ class http_request friend class http::details::_http_request; friend class http::client::http_client; - http_request(std::unique_ptr server_context) : _m_impl(std::make_shared(std::move(server_context))) {} + http_request(utility::unique_ptr server_context) : _m_impl(utility::make_shared(std::move(server_context))) {} std::shared_ptr _m_impl; }; diff --git a/Release/include/cpprest/interopstream.h b/Release/include/cpprest/interopstream.h index 5cf575aa0e..1d381227fa 100644 --- a/Release/include/cpprest/interopstream.h +++ b/Release/include/cpprest/interopstream.h @@ -134,7 +134,7 @@ namespace Concurrency { namespace streams { /// The synchronous stream that this is using for its I/O template stdio_ostream(std::basic_ostream& stream) - : basic_ostream(streams::streambuf(std::shared_ptr>(new details::basic_stdio_buffer(stream.rdbuf(), std::ios_base::out)))) + : basic_ostream(utility::make_shared>(stream.rdbuf(), std::ios_base::out)) { } @@ -178,7 +178,7 @@ namespace Concurrency { namespace streams { /// The synchronous stream that this is using for its I/O template stdio_istream(std::basic_istream& stream) - : basic_istream(streams::streambuf(std::shared_ptr>(new details::basic_stdio_buffer(stream.rdbuf(), std::ios_base::in)))) + : basic_istream(utility::make_shared>(stream.rdbuf(), std::ios_base::in)) { } diff --git a/Release/include/cpprest/json.h b/Release/include/cpprest/json.h index dfdeead4f3..42340c1881 100644 --- a/Release/include/cpprest/json.h +++ b/Release/include/cpprest/json.h @@ -284,7 +284,7 @@ namespace json #ifdef _WIN32 private: // Only used internally by JSON parser. - static _ASYNCRTIMP value __cdecl string(const std::string &value); + static _ASYNCRTIMP value __cdecl string(const utility::string &value); public: #endif @@ -301,7 +301,7 @@ namespace json /// Field names associated with JSON values /// Whether to preserve the original order of the fields /// A non-empty JSON object value - static _ASYNCRTIMP json::value __cdecl object(std::vector> fields, bool keep_order = false); + static _ASYNCRTIMP json::value __cdecl object(utility::vector> fields, bool keep_order = false); /// /// Creates an empty JSON array @@ -321,7 +321,7 @@ namespace json /// /// A vector of JSON values /// A JSON array value - static _ASYNCRTIMP json::value __cdecl array(std::vector elements); + static _ASYNCRTIMP json::value __cdecl array(utility::vector elements); /// /// Accesses the type of JSON value the current value instance is @@ -651,7 +651,7 @@ namespace json #ifdef _WIN32 private: // Only used internally by JSON parser - _ASYNCRTIMP value & operator [] (const std::string &key) + _ASYNCRTIMP value & operator [] (const utility::string &key) { // JSON object stores its field map as a unordered_map of string_t, so this conversion is hard to avoid return operator[](utility::conversions::to_string_t(key)); @@ -684,22 +684,22 @@ namespace json /// Writes the current JSON value as a double-byte string to a string instance. /// /// The string that the JSON representation should be written to. - _ASYNCRTIMP void format(std::basic_string &string) const; + _ASYNCRTIMP void format(utility::basic_string &string) const; #endif /// /// Serializes the content of the value into a string instance in UTF8 format /// /// The string that the JSON representation should be written to - _ASYNCRTIMP void format(std::basic_string& string) const; + _ASYNCRTIMP void format(utility::string& string) const; #ifdef ENABLE_JSON_VALUE_VISUALIZER - explicit value(std::unique_ptr v, value_type kind) : m_value(std::move(v)), m_kind(kind) + explicit value(utility::unique_ptr v, value_type kind) : m_value(std::move(v)), m_kind(kind) #else - explicit value(std::unique_ptr v) : m_value(std::move(v)) + explicit value(utility::unique_ptr v) : m_value(std::move(v)) #endif {} - std::unique_ptr m_value; + utility::unique_ptr m_value; #ifdef ENABLE_JSON_VALUE_VISUALIZER value_type m_kind; #endif @@ -712,7 +712,7 @@ namespace json class json_exception : public std::exception { private: - std::string _message; + utility::string _message; public: json_exception(const utility::char_t * const &message) : _message(utility::conversions::to_utf8string(message)) { } @@ -788,7 +788,7 @@ namespace json /// class array { - typedef std::vector storage_type; + typedef utility::vector storage_type; public: typedef storage_type::iterator iterator; @@ -998,7 +998,7 @@ namespace json /// class object { - typedef std::vector> storage_type; + typedef utility::vector> storage_type; public: typedef storage_type::iterator iterator; @@ -1461,7 +1461,7 @@ namespace json class _Value { public: - virtual std::unique_ptr<_Value> _copy_value() = 0; + virtual utility::unique_ptr<_Value> _copy_value() = 0; virtual bool has_field(const utility::string_t &) const { return false; } virtual value get_field(const utility::string_t &) const { throw json_exception(_XPLATSTR("not an object")); } @@ -1474,12 +1474,12 @@ namespace json virtual const value &cnst_index(array::size_type) const { throw json_exception(_XPLATSTR("not an array")); } // Common function used for serialization to strings and streams. - virtual void serialize_impl(std::string& str) const + virtual void serialize_impl(utility::string& str) const { format(str); } #ifdef _WIN32 - virtual void serialize_impl(std::wstring& str) const + virtual void serialize_impl(utility::wstring& str) const { format(str); } @@ -1514,12 +1514,12 @@ namespace json protected: _Value() {} - virtual void format(std::basic_string& stream) const + virtual void format(utility::string& stream) const { stream.append("null"); } #ifdef _WIN32 - virtual void format(std::basic_string& stream) const + virtual void format(utility::wstring& stream) const { stream.append(L"null"); } @@ -1532,9 +1532,9 @@ namespace json class _Null : public _Value { public: - virtual std::unique_ptr<_Value> _copy_value() + virtual utility::unique_ptr<_Value> _copy_value() { - return utility::details::make_unique<_Null>(); + return utility::make_unique<_Null>(); } virtual json::value::value_type type() const { return json::value::Null; } }; @@ -1548,9 +1548,9 @@ namespace json _Number(int64_t value) : m_number(value) { } _Number(uint64_t value) : m_number(value) { } - virtual std::unique_ptr<_Value> _copy_value() + virtual utility::unique_ptr<_Value> _copy_value() { - return utility::details::make_unique<_Number>(*this); + return utility::make_unique<_Number>(*this); } virtual json::value::value_type type() const { return json::value::Number; } @@ -1571,9 +1571,9 @@ namespace json virtual const number& as_number() { return m_number; } protected: - virtual void format(std::basic_string& stream) const ; + virtual void format(utility::string& stream) const ; #ifdef _WIN32 - virtual void format(std::basic_string& stream) const; + virtual void format(utility::wstring& stream) const; #endif private: template friend class json::details::JSON_Parser; @@ -1586,9 +1586,9 @@ namespace json public: _Boolean(bool value) : m_value(value) { } - virtual std::unique_ptr<_Value> _copy_value() + virtual utility::unique_ptr<_Value> _copy_value() { - return utility::details::make_unique<_Boolean>(*this); + return utility::make_unique<_Boolean>(*this); } virtual json::value::value_type type() const { return json::value::Boolean; } @@ -1596,13 +1596,13 @@ namespace json virtual bool as_bool() const { return m_value; } protected: - virtual void format(std::basic_string& stream) const + virtual void format(utility::string& stream) const { stream.append(m_value ? "true" : "false"); } #ifdef _WIN32 - virtual void format(std::basic_string& stream) const + virtual void format(utility::wstring& stream) const { stream.append(m_value ? L"true" : L"false"); } @@ -1626,40 +1626,40 @@ namespace json { } #ifdef _WIN32 - _String(std::string &&value) : m_string(utility::conversions::to_utf16string(std::move(value))) + _String(utility::string &&value) : m_string(utility::conversions::to_utf16string(std::move(value))) { m_has_escape_char = has_escape_chars(*this); } - _String(std::string &&value, bool escape_chars) + _String(utility::string &&value, bool escape_chars) : m_string(utility::conversions::to_utf16string(std::move(value))), m_has_escape_char(escape_chars) { } #endif - virtual std::unique_ptr<_Value> _copy_value() + virtual utility::unique_ptr<_Value> _copy_value() { - return utility::details::make_unique<_String>(*this); + return utility::make_unique<_String>(*this); } virtual json::value::value_type type() const { return json::value::String; } virtual const utility::string_t & as_string() const; - virtual void serialize_impl(std::string& str) const + virtual void serialize_impl(utility::string& str) const { serialize_impl_char_type(str); } #ifdef _WIN32 - virtual void serialize_impl(std::wstring& str) const + virtual void serialize_impl(utility::wstring& str) const { serialize_impl_char_type(str); } #endif protected: - virtual void format(std::basic_string& str) const; + virtual void format(utility::string& str) const; #ifdef _WIN32 - virtual void format(std::basic_string& str) const; + virtual void format(utility::wstring& str) const; #endif private: @@ -1672,7 +1672,7 @@ namespace json } template - void serialize_impl_char_type(std::basic_string& str) const + void serialize_impl_char_type(utility::basic_string& str) const { // To avoid repeated allocations reserve some space all up front. // size of string + 2 for quotes @@ -1680,7 +1680,7 @@ namespace json format(str); } - std::string as_utf8_string() const; + utility::string as_utf8_string() const; utf16string as_utf16_string() const; utility::string_t m_string; @@ -1692,12 +1692,12 @@ namespace json }; template - _ASYNCRTIMP void append_escape_string(std::basic_string& str, const std::basic_string& escaped); + _ASYNCRTIMP void append_escape_string(utility::basic_string& str, const utility::basic_string& escaped); void format_string(const utility::string_t& key, utility::string_t& str); #ifdef _WIN32 - void format_string(const utility::string_t& key, std::string& str); + void format_string(const utility::string_t& key, utility::string& str); #endif class _Object : public _Value @@ -1707,9 +1707,9 @@ namespace json _Object(bool keep_order) : m_object(keep_order) { } _Object(object::storage_type fields, bool keep_order) : m_object(std::move(fields), keep_order) { } - virtual std::unique_ptr<_Value> _copy_value() + virtual utility::unique_ptr<_Value> _copy_value() { - return utility::details::make_unique<_Object>(*this); + return utility::make_unique<_Object>(*this); } virtual json::object& as_object() { return m_object; } @@ -1730,14 +1730,14 @@ namespace json return std::equal(std::begin(m_object), std::end(m_object), std::begin(other->m_object)); } - virtual void serialize_impl(std::string& str) const + virtual void serialize_impl(utility::string& str) const { // To avoid repeated allocations reserve some space all up front. str.reserve(get_reserve_size()); format(str); } #ifdef _WIN32 - virtual void serialize_impl(std::wstring& str) const + virtual void serialize_impl(utility::wstring& str) const { // To avoid repeated allocations reserve some space all up front. str.reserve(get_reserve_size()); @@ -1747,12 +1747,12 @@ namespace json size_t size() const { return m_object.size(); } protected: - virtual void format(std::basic_string& str) const + virtual void format(utility::string& str) const { format_impl(str); } #ifdef _WIN32 - virtual void format(std::basic_string& str) const + virtual void format(utility::wstring& str) const { format_impl(str); } @@ -1764,7 +1764,7 @@ namespace json template friend class json::details::JSON_Parser; template - void format_impl(std::basic_string& str) const + void format_impl(utility::basic_string& str) const { str.push_back('{'); if(!m_object.empty()) @@ -1818,9 +1818,9 @@ namespace json _Array(array::size_type size) : m_array(size) {} _Array(array::storage_type elements) : m_array(std::move(elements)) { } - virtual std::unique_ptr<_Value> _copy_value() + virtual utility::unique_ptr<_Value> _copy_value() { - return utility::details::make_unique<_Array>(*this); + return utility::make_unique<_Array>(*this); } virtual json::value::value_type type() const { return json::value::Array; } @@ -1852,14 +1852,14 @@ namespace json return true; } - virtual void serialize_impl(std::string& str) const + virtual void serialize_impl(utility::string& str) const { // To avoid repeated allocations reserve some space all up front. str.reserve(get_reserve_size()); format(str); } #ifdef _WIN32 - virtual void serialize_impl(std::wstring& str) const + virtual void serialize_impl(utility::wstring& str) const { // To avoid repeated allocations reserve some space all up front. str.reserve(get_reserve_size()); @@ -1869,12 +1869,12 @@ namespace json size_t size() const { return m_array.size(); } protected: - virtual void format(std::basic_string& str) const + virtual void format(utility::string& str) const { format_impl(str); } #ifdef _WIN32 - virtual void format(std::basic_string& str) const + virtual void format(utility::wstring& str) const { format_impl(str); } @@ -1885,7 +1885,7 @@ namespace json template friend class json::details::JSON_Parser; template - void format_impl(std::basic_string& str) const + void format_impl(utility::basic_string& str) const { str.push_back('['); if(!m_array.m_elements.empty()) diff --git a/Release/include/cpprest/oauth1.h b/Release/include/cpprest/oauth1.h index 24a10c7d79..6a9c87d4b1 100644 --- a/Release/include/cpprest/oauth1.h +++ b/Release/include/cpprest/oauth1.h @@ -114,7 +114,7 @@ class oauth1_exception : public std::exception const char* what() const CPPREST_NOEXCEPT { return m_msg.c_str(); } private: - std::string m_msg; + utility::string m_msg; }; /// @@ -186,7 +186,7 @@ class oauth1_token /// Retrieves any additional parameters. /// /// A map containing the additional parameters. - const std::map &additional_parameters() const { return m_additional_parameters; } + const utility::map &additional_parameters() const { return m_additional_parameters; } /// /// Sets a specific parameter additional parameter. @@ -218,7 +218,7 @@ class oauth1_token utility::string_t m_token; utility::string_t m_secret; - std::map m_additional_parameters; + utility::map m_additional_parameters; }; /// @@ -437,7 +437,7 @@ class oauth1_config /// Gets map of parameters to sign. /// /// Map of parameters. - const std::map& parameters() const { return m_parameters_to_sign; } + const utility::map& parameters() const { return m_parameters_to_sign; } /// /// Adds a key value parameter. @@ -457,7 +457,7 @@ class oauth1_config /// Sets entire map or parameters replacing all previously values. /// /// Map of values. - void set_parameters(const std::map ¶meters) + void set_parameters(const utility::map ¶meters) { m_parameters_to_sign.clear(); m_parameters_to_sign = parameters; @@ -504,7 +504,7 @@ class oauth1_config return utility::conversions::details::to_string_t(utility::datetime::utc_timestamp()); } - _ASYNCRTIMP static std::vector __cdecl _hmac_sha1(const utility::string_t& key, const utility::string_t& data); + _ASYNCRTIMP static utility::vector __cdecl _hmac_sha1(const utility::string_t& key, const utility::string_t& data); static utility::string_t _build_base_string_uri(const uri& u); @@ -537,7 +537,7 @@ class oauth1_config utility::string_t m_realm; oauth1_method m_method; - std::map m_parameters_to_sign; + utility::map m_parameters_to_sign; web::web_proxy m_proxy; diff --git a/Release/include/cpprest/oauth2.h b/Release/include/cpprest/oauth2.h index 7afccdc3e1..e990977b6d 100644 --- a/Release/include/cpprest/oauth2.h +++ b/Release/include/cpprest/oauth2.h @@ -65,7 +65,7 @@ class oauth2_exception : public std::exception const char* what() const CPPREST_NOEXCEPT { return m_msg.c_str(); } private: - std::string m_msg; + utility::string m_msg; }; /// diff --git a/Release/include/cpprest/producerconsumerstream.h b/Release/include/cpprest/producerconsumerstream.h index 4e10872f45..03d7c9390e 100644 --- a/Release/include/cpprest/producerconsumerstream.h +++ b/Release/include/cpprest/producerconsumerstream.h @@ -150,7 +150,7 @@ namespace Concurrency { namespace streams { // easier book keeping _ASSERTE(!m_allocBlock); - m_allocBlock = std::make_shared<_block>(count); + m_allocBlock = utility::make_shared<_block>(count); return m_allocBlock->wbegin(); } @@ -379,7 +379,7 @@ namespace Concurrency { namespace streams { if ( m_blocks.empty() || m_blocks.back()->wr_chars_left() < count ) { msl::safeint3::SafeInt alloc = m_alloc_size.Max(count); - m_blocks.push_back(std::make_shared<_block>(alloc)); + m_blocks.push_back(utility::make_shared<_block>(alloc)); } // The block at the back is always the write head @@ -659,10 +659,10 @@ namespace Concurrency { namespace streams { pplx::extensibility::critical_section_t m_lock; // Memory blocks - std::deque> m_blocks; + utility::deque> m_blocks; // Queue of requests - std::queue<_request> m_requests; + utility::queue<_request> m_requests; }; } // namespace details @@ -687,7 +687,7 @@ namespace Concurrency { namespace streams { /// /// The internal default block size. producer_consumer_buffer(size_t alloc_size = 512) - : streambuf<_CharType>(std::make_shared>(alloc_size)) + : streambuf<_CharType>(utility::make_shared>(alloc_size)) { } }; diff --git a/Release/include/cpprest/rawptrstream.h b/Release/include/cpprest/rawptrstream.h index 3fdbb99cb3..bcf8a97910 100644 --- a/Release/include/cpprest/rawptrstream.h +++ b/Release/include/cpprest/rawptrstream.h @@ -58,6 +58,33 @@ namespace Concurrency { namespace streams { { } + /// + /// Constructor + /// + /// The address (pointer to) the memory block. + /// The memory block size, measured in number of characters. + basic_rawptr_buffer(const _CharType* data, size_t size) + : streambuf_state_manager<_CharType>(std::ios_base::in), + m_data(const_cast<_CharType*>(data)), + m_size(size), + m_current_position(0) { + validate_mode(std::ios_base::in); + } + + /// + /// Constructor + /// + /// The address (pointer to) the memory block. + /// The memory block size, measured in number of characters. + /// The stream mode (in, out, etc.). + basic_rawptr_buffer(_CharType* data, size_t size, std::ios_base::openmode mode) + : streambuf_state_manager<_CharType>(mode), + m_data(data), + m_size(size), + m_current_position(0) { + validate_mode(mode); + } + /// /// Destructor /// @@ -397,35 +424,6 @@ namespace Concurrency { namespace streams { private: template friend class ::concurrency::streams::rawptr_buffer; - /// - /// Constructor - /// - /// The address (pointer to) the memory block. - /// The memory block size, measured in number of characters. - basic_rawptr_buffer(const _CharType* data, size_t size) - : streambuf_state_manager<_CharType>(std::ios_base::in), - m_data(const_cast<_CharType*>(data)), - m_size(size), - m_current_position(0) - { - validate_mode(std::ios_base::in); - } - - /// - /// Constructor - /// - /// The address (pointer to) the memory block. - /// The memory block size, measured in number of characters. - /// The stream mode (in, out, etc.). - basic_rawptr_buffer(_CharType* data, size_t size, std::ios_base::openmode mode) - : streambuf_state_manager<_CharType>(mode), - m_data(data), - m_size(size), - m_current_position(0) - { - validate_mode(mode); - } - static void validate_mode(std::ios_base::openmode mode) { // Disallow simultaneous use of the stream buffer for writing and reading. @@ -555,7 +553,7 @@ namespace Concurrency { namespace streams { /// The address (pointer to) the memory block. /// The memory block size, measured in number of characters. rawptr_buffer(const char_type* data, size_t size) - : streambuf(std::shared_ptr>(new details::basic_rawptr_buffer(data, size))) + : streambuf(utility::make_shared>(data, size)) { } @@ -565,7 +563,7 @@ namespace Concurrency { namespace streams { /// The address (pointer to) the memory block. /// The memory block size, measured in number of characters. rawptr_buffer(char_type* data, size_t size, std::ios_base::openmode mode = std::ios::out) - : streambuf(std::shared_ptr>(new details::basic_rawptr_buffer(data, size, mode))) + : streambuf(utility::make_shared>(data, size, mode)) { } diff --git a/Release/include/cpprest/streams.h b/Release/include/cpprest/streams.h index d2923d3774..0b03d9dff7 100644 --- a/Release/include/cpprest/streams.h +++ b/Release/include/cpprest/streams.h @@ -56,9 +56,9 @@ namespace Concurrency { namespace streams struct Value2StringFormatter { template - static std::basic_string format(const T &val) + static utility::basic_string format(const T &val) { - std::basic_ostringstream ss; + utility::basic_ostringstream ss; ss << val; return ss.str(); } @@ -68,14 +68,14 @@ namespace Concurrency { namespace streams struct Value2StringFormatter { template - static std::basic_string format(const T &val) + static utility::basic_string format(const T &val) { - std::basic_ostringstream ss; + utility::basic_ostringstream ss; ss << val; return reinterpret_cast(ss.str().c_str()); } - static std::basic_string format(const utf16string &val) + static utility::basic_string format(const utf16string &val) { return format(utility::conversions::utf16_to_utf8(val)); } @@ -123,7 +123,7 @@ namespace Concurrency { namespace streams /// /// A stream buffer. basic_ostream(streams::streambuf buffer) : - m_helper(std::make_shared>(buffer)) + m_helper(utility::make_shared>(buffer)) { _verify_and_throw(details::_out_streambuf_msg); } @@ -182,7 +182,7 @@ namespace Concurrency { namespace streams pplx::task result; if ( !_verify_and_return_task(details::_out_stream_msg, result) ) return result; - auto copy = std::make_shared(std::move(value)); + auto copy = utility::make_shared(std::move(value)); return helper()->m_buffer.putn_nocopy((CharType*)copy.get(), sizeof(T)).then([copy](pplx::task op) -> size_t { return op.get(); }); } @@ -262,7 +262,7 @@ namespace Concurrency { namespace streams /// Write the specified string to the output stream. /// /// Input string. - pplx::task print(const std::basic_string& str) const + pplx::task print(const utility::basic_string& str) const { pplx::task result; if ( !_verify_and_return_task(details::_out_stream_msg, result) ) return result; @@ -273,7 +273,7 @@ namespace Concurrency { namespace streams } else { - auto sharedStr = std::make_shared>(str); + auto sharedStr = utility::make_shared>(str); return helper()->m_buffer.putn_nocopy(sharedStr->c_str(), sharedStr->size()).then([sharedStr](size_t size) { return size; }); } } @@ -578,7 +578,7 @@ namespace Concurrency { namespace streams /// /// A stream buffer. template - basic_istream(streams::streambuf buffer) : m_helper(std::make_shared>(std::move(buffer))) + basic_istream(streams::streambuf buffer) : m_helper(utility::make_shared>(std::move(buffer))) { _verify_and_throw(details::_in_streambuf_msg); } @@ -663,7 +663,7 @@ namespace Concurrency { namespace streams pplx::task result; if ( !_verify_and_return_task(details::_in_stream_msg, result) ) return result; - auto copy = std::make_shared(); + auto copy = utility::make_shared(); return helper()->m_buffer.getn((CharType*)copy.get(), sizeof(T)).then([copy](pplx::task) -> T { return std::move(*copy); @@ -772,7 +772,7 @@ namespace Concurrency { namespace streams int_type req_async = traits::requires_async(); - std::shared_ptr<_read_helper> _locals = std::make_shared<_read_helper>(); + std::shared_ptr<_read_helper> _locals = utility::make_shared<_read_helper>(); auto flush = [=]() mutable { @@ -844,7 +844,7 @@ namespace Concurrency { namespace streams int_type req_async = traits::requires_async(); - std::shared_ptr<_read_helper> _locals = std::make_shared<_read_helper>(); + std::shared_ptr<_read_helper> _locals = utility::make_shared<_read_helper>(); auto flush = [=]() mutable { @@ -941,7 +941,7 @@ namespace Concurrency { namespace streams auto l_buffer = helper()->m_buffer; auto l_buf_size = this->buf_size; - std::shared_ptr<_read_helper> l_locals = std::make_shared<_read_helper>(); + std::shared_ptr<_read_helper> l_locals = utility::make_shared<_read_helper>(); auto copy_to_target = [l_locals, target, l_buffer, l_buf_size]() mutable -> pplx::task { @@ -1173,7 +1173,7 @@ pplx::task _type_parser_base::_parse_input( AcceptFunctor accept_character, ExtractFunctor extract) { - std::shared_ptr state = std::make_shared(); + std::shared_ptr state = utility::make_shared(); auto update = [=] (pplx::task op) -> pplx::task { @@ -1223,26 +1223,26 @@ pplx::task _type_parser_base::_parse_input( } template -class type_parser> : public _type_parser_base +class type_parser> : public _type_parser_base { typedef _type_parser_base base; public: typedef typename base::traits traits; typedef typename base::int_type int_type; - static pplx::task parse(streams::streambuf buffer) + static pplx::task parse(streams::streambuf buffer) { - return base::template _parse_input, std::string>(buffer, _accept_char, _extract_result); + return base::template _parse_input, utility::string>(buffer, _accept_char, _extract_result); } private: - static bool _accept_char(std::shared_ptr> state, int_type ch) + static bool _accept_char(std::shared_ptr> state, int_type ch) { if ( ch == traits::eof() || isspace(ch)) return false; state->push_back(CharType(ch)); return true; } - static pplx::task> _extract_result(std::shared_ptr> state) + static pplx::task> _extract_result(std::shared_ptr> state) { return pplx::task_from_result(*state); } @@ -1739,26 +1739,26 @@ class type_parser : public _type_parser_base #ifdef _WIN32 template -class type_parser>> : public _type_parser_base +class type_parser>> : public _type_parser_base { typedef _type_parser_base base; public: typedef typename base::traits traits; typedef typename base::int_type int_type; - static pplx::task parse(streams::streambuf buffer) + static pplx::task parse(streams::streambuf buffer) { - return base::template _parse_input,std::basic_string>(buffer, _accept_char, _extract_result); + return base::template _parse_input,utility::basic_string>(buffer, _accept_char, _extract_result); } private: - static bool _accept_char(const std::shared_ptr> &state, int_type ch) + static bool _accept_char(const std::shared_ptr> &state, int_type ch) { if ( ch == concurrency::streams::char_traits::eof() || isspace(ch)) return false; state->push_back(char(ch)); return true; } - static pplx::task> _extract_result(std::shared_ptr> state) + static pplx::task> _extract_result(std::shared_ptr> state) { return pplx::task_from_result(utility::conversions::utf8_to_utf16(*state)); } diff --git a/Release/include/cpprest/ws_client.h b/Release/include/cpprest/ws_client.h index 98f933e149..24087d2c6f 100644 --- a/Release/include/cpprest/ws_client.h +++ b/Release/include/cpprest/ws_client.h @@ -176,7 +176,7 @@ class websocket_client_config /// /// The name of the subprotocol. /// If additional subprotocols have already been specified, the new one will just be added. - _ASYNCRTIMP void add_subprotocol(const ::utility::string_t &name); + _ASYNCRTIMP void add_subprotocol(const utility::string_t &name); /// /// Gets list of the specified subprotocols. @@ -184,7 +184,7 @@ class websocket_client_config /// Vector of all the subprotocols /// If you want all the subprotocols in a comma separated string /// they can be directly looked up in the headers using 'Sec-WebSocket-Protocol'. - _ASYNCRTIMP std::vector< ::utility::string_t> subprotocols() const; + _ASYNCRTIMP utility::vector subprotocols() const; /// /// Gets the server certificate validation property. @@ -233,7 +233,7 @@ class websocket_exception : public std::exception /// Creates an websocket_exception with just a string message and no error code. /// /// Error message string. - websocket_exception(std::string whatArg) : m_msg(std::move(whatArg)) {} + websocket_exception(utility::string whatArg) : m_msg(std::move(whatArg)) {} #endif /// @@ -244,7 +244,7 @@ class websocket_exception : public std::exception websocket_exception(int errorCode) : m_errorCode(utility::details::create_error_code(errorCode)) { - m_msg = m_errorCode.message(); + m_msg = m_errorCode.message().c_str(); } /// @@ -263,7 +263,7 @@ class websocket_exception : public std::exception /// /// Error code value. /// Message to use in what() string. - websocket_exception(int errorCode, std::string whatArg) + websocket_exception(int errorCode, utility::string whatArg) : m_errorCode(utility::details::create_error_code(errorCode)), m_msg(std::move(whatArg)) {} @@ -273,7 +273,7 @@ class websocket_exception : public std::exception /// Error code. /// Message to use in what() string. /// - websocket_exception(std::error_code code, std::string whatArg) : + websocket_exception(std::error_code code, utility::string whatArg) : m_errorCode(std::move(code)), m_msg(std::move(whatArg)) {} @@ -287,7 +287,7 @@ class websocket_exception : public std::exception /// Error category for the code. websocket_exception(int errorCode, const std::error_category &cat) : m_errorCode(std::error_code(errorCode, cat)) { - m_msg = m_errorCode.message(); + m_msg = m_errorCode.message().c_str(); } /// @@ -320,7 +320,7 @@ class websocket_exception : public std::exception private: std::error_code m_errorCode; - std::string m_msg; + utility::string m_msg; }; namespace details @@ -413,9 +413,9 @@ class websocket_client_task_impl // m_receive_queue_lock : to guard access to the queue & m_client_closed std::mutex m_receive_queue_lock; // Queue to store incoming messages when there are no tasks waiting for a message - std::queue m_receive_msg_queue; + utility::queue m_receive_msg_queue; // Queue to maintain the receive tasks when there are no messages(yet). - std::queue> m_receive_task_queue; + utility::queue> m_receive_task_queue; // Initially set to false, becomes true if a close frame is received from the server or // if the underlying connection is aborted or terminated. @@ -435,7 +435,7 @@ class websocket_client /// Creates a new websocket_client. /// websocket_client() : - m_client(std::make_shared(websocket_client_config())) + m_client(utility::make_shared(websocket_client_config())) {} /// @@ -443,7 +443,7 @@ class websocket_client /// /// The client configuration object containing the possible configuration options to initialize the websocket_client. websocket_client(websocket_client_config config) : - m_client(std::make_shared(std::move(config))) + m_client(utility::make_shared(std::move(config))) {} /// diff --git a/Release/include/cpprest/ws_msg.h b/Release/include/cpprest/ws_msg.h index 326541c7a1..8e10b09223 100644 --- a/Release/include/cpprest/ws_msg.h +++ b/Release/include/cpprest/ws_msg.h @@ -76,18 +76,18 @@ class websocket_outgoing_message /// Sets a UTF-8 message as the message body. /// /// UTF-8 String containing body of the message. - void set_utf8_message(std::string &&data) + void set_utf8_message(utility::string &&data) { - this->set_message(concurrency::streams::container_buffer(std::move(data))); + this->set_message(concurrency::streams::container_buffer(std::move(data))); } /// /// Sets a UTF-8 message as the message body. /// /// UTF-8 String containing body of the message. - void set_utf8_message(const std::string &data) + void set_utf8_message(const utility::string &data) { - this->set_message(concurrency::streams::container_buffer(data)); + this->set_message(concurrency::streams::container_buffer(data)); } /// @@ -154,14 +154,14 @@ class websocket_outgoing_message #if !defined(__cplusplus_winrt) void set_message_pong() { - concurrency::streams::container_buffer buffer(""); + concurrency::streams::container_buffer buffer(""); m_msg_type = websocket_message_type::pong; m_length = static_cast(buffer.size()); m_body = buffer; } #endif - void set_message(const concurrency::streams::container_buffer &buffer) + void set_message(const concurrency::streams::container_buffer &buffer) { m_msg_type = websocket_message_type::text_message; m_length = static_cast(buffer.size()); @@ -188,7 +188,7 @@ class websocket_incoming_message /// A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out. /// /// String containing body of the message. - _ASYNCRTIMP pplx::task extract_string() const; + _ASYNCRTIMP pplx::task extract_string() const; /// /// Produces a stream which the caller may use to retrieve body from an incoming message. @@ -242,7 +242,7 @@ class websocket_incoming_message // Store message body in a container buffer backed by a string. // Allows for optimization in the string message cases. - concurrency::streams::container_buffer m_body; + concurrency::streams::container_buffer m_body; websocket_message_type m_msg_type; }; diff --git a/Release/include/pplx/pplxtasks.h b/Release/include/pplx/pplxtasks.h index e784306d40..923b328c46 100644 --- a/Release/include/pplx/pplxtasks.h +++ b/Release/include/pplx/pplxtasks.h @@ -117,13 +117,17 @@ namespace std } } #endif /* _MSC_VER < 1700 */ -#ifndef _PPLTASK_ASYNC_LOGGING - #if _MSC_VER >= 1800 && defined(__cplusplus_winrt) - #define _PPLTASK_ASYNC_LOGGING 1 // Only enable async logging under dev12 winrt - #else - #define _PPLTASK_ASYNC_LOGGING 0 - #endif -#endif /* !_PPLTASK_ASYNC_LOGGING */ + +#ifndef _PPLTASK_ASYNC_LOGGING +#define _PPLTASK_ASYNC_LOGGING 1 +#endif // #ifndef _PPLTASK_ASYNC_LOGGING + +#if _PPLTASK_ASYNC_LOGGING +#pragma detect_mismatch("_PPLTASK_ASYNC_LOGGING", "1") +#else +#pragma detect_mismatch("_PPLTASK_ASYNC_LOGGING", "0") +#endif // #if _PPLTASK_ASYNC_LOGGING + #endif /* _MSC_VER */ #pragma pack(push,_CRT_PACKING) @@ -249,7 +253,7 @@ namespace details // If _M_SingleFrame != nullptr, there will be only one frame of callstacks, which is stored in _M_SingleFrame; // otherwise, _M_Frame will store all the callstack frames. void* _M_SingleFrame; - std::vector _M_frames; + utility::vector _M_frames; public: _TaskCreationCallstack() { @@ -857,9 +861,9 @@ namespace details // The below are for composability with tasks auto-created from when_any / when_all / && / || constructs. // template - struct _ResultHolder> + struct _ResultHolder> { - void Set(const std::vector<_Type^>& _type) + void Set(const utility::vector<_Type^>& _type) { _Result.reserve(_type.size()); @@ -869,10 +873,10 @@ namespace details } } - std::vector<_Type^> Get() + utility::vector<_Type^> Get() { // Return vectory with the objects that are marshaled in the proper appartment - std::vector<_Type^> _Return; + utility::vector<_Type^> _Return; _Return.reserve(_Result.size()); for (auto _PTask = _Result.begin(); _PTask != _Result.end(); ++_PTask) @@ -883,7 +887,7 @@ namespace details return _Return; } - std::vector< ::Platform::Agile<_Type^> > _Result; + utility::vector< ::Platform::Agile<_Type^> > _Result; }; template @@ -1415,7 +1419,7 @@ namespace details struct _Task_ptr { typedef std::shared_ptr<_Task_impl<_ReturnType>> _Type; - static _Type _Make(_CancellationTokenState * _Ct, scheduler_ptr _Scheduler_arg) { return std::make_shared<_Task_impl<_ReturnType>>(_Ct, _Scheduler_arg); } + static _Type _Make(_CancellationTokenState * _Ct, scheduler_ptr _Scheduler_arg) { return utility::make_shared<_Task_impl<_ReturnType>>(_Ct, _Scheduler_arg); } }; typedef _TaskCollection_t::_TaskProcHandle_t _UnrealizedChore_t; @@ -1441,7 +1445,7 @@ namespace details virtual ~_ContinuationTaskHandleBase() {} }; -#if _PPLTASK_ASYNC_LOGGING +#if _PPLTASK_ASYNC_LOGGING && _MSC_VER >= 1800 && defined(__cplusplus_winrt) // GUID used for identifying causality logs from PPLTask const ::Platform::Guid _PPLTaskCausalityPlatformID(0x7A76B220, 0xA758, 0x4E6E, 0xB0, 0xE0, 0xD7, 0xC6, 0xD7, 0x4A, 0x88, 0xFE); @@ -1863,7 +1867,7 @@ namespace details { // This task was canceled because the task body encountered an exception. _ASSERTE(!_HasUserException()); - return _CancelAndRunContinuations(true, true, false, std::make_shared<_ExceptionHolder>(_Exception, _GetTaskCreationCallstack())); + return _CancelAndRunContinuations(true, true, false, utility::make_shared<_ExceptionHolder>(_Exception, _GetTaskCreationCallstack())); } #endif /* defined (__cplusplus_winrt) */ @@ -1871,7 +1875,7 @@ namespace details { // This task was canceled because the task body encountered an exception. _ASSERTE(!_HasUserException()); - return _CancelAndRunContinuations(true, true, false, std::make_shared<_ExceptionHolder>(_Exception, _GetTaskCreationCallstack())); + return _CancelAndRunContinuations(true, true, false, utility::make_shared<_ExceptionHolder>(_Exception, _GetTaskCreationCallstack())); } void _RegisterCancellation(std::weak_ptr<_Task_impl_base> _WeakPtr) @@ -2360,7 +2364,7 @@ namespace details _Task_impl_base const & operator=(_Task_impl_base const&); }; -#if _PPLTASK_ASYNC_LOGGING +#if _PPLTASK_ASYNC_LOGGING && _MSC_VER >= 1800 && defined(__cplusplus_winrt) inline void _TaskEventLogger::_LogTaskCompleted() { if (_M_scheduled) @@ -2587,7 +2591,7 @@ namespace details public: - typedef std::vector::_Type> _TaskList; + typedef utility::vector::_Type> _TaskList; _Task_completion_event_impl() : _M_fHasValue(false), _M_fIsCanceled(false) @@ -2668,7 +2672,7 @@ class task_completion_event /// /**/ task_completion_event() - : _M_Impl(std::make_shared>()) + : _M_Impl(utility::make_shared>()) { } @@ -2824,7 +2828,7 @@ class task_completion_event static std::shared_ptr _ToExceptionHolder(std::exception_ptr _ExceptionPtr, const details::_TaskCreationCallstack &_SetExceptionAddressHint) { - return std::make_shared(_ExceptionPtr, _SetExceptionAddressHint); + return utility::make_shared(_ExceptionPtr, _SetExceptionAddressHint); } @@ -3093,7 +3097,7 @@ namespace details typename std::enable_if, typename std::decay<_Tx>::type>::value>::type> explicit _NonCopyableFunctorWrapper(_Tx&& f) - : _M_functor{std::make_shared<_Ty>(std::forward<_Tx>(f))} + : _M_functor{utility::make_shared<_Ty>(std::forward<_Tx>(f))} {} template @@ -6280,14 +6284,14 @@ namespace details } task_completion_event<_Unit_type> _M_completed; - _ResultHolder > _M_vector; + _ResultHolder > _M_vector; _ResultHolder<_Type> _M_mergeVal; atomic_size_t _M_completeCount; size_t _M_numTasks; }; template - struct _RunAllParam > + struct _RunAllParam > { _RunAllParam() : _M_completeCount(0), _M_numTasks(0) { @@ -6304,7 +6308,7 @@ namespace details } task_completion_event<_Unit_type> _M_completed; - std::vector<_ResultHolder > > _M_vector; + utility::vector<_ResultHolder > > _M_vector; atomic_size_t _M_completeCount; size_t _M_numTasks; }; @@ -6375,7 +6379,7 @@ namespace details template struct _WhenAllImpl { - static task> _Perform(const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End) + static task> _Perform(const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End) { _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() : nullptr; @@ -6387,7 +6391,7 @@ namespace details _Options.set_cancellation_token(_MergedSource.get_token()); task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _Options); // The return task must be created before step 3 to enforce inline execution. - auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> std::vector<_ElementType> { + auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> utility::vector<_ElementType> { return _PParam->_M_vector.Get(); }, nullptr); @@ -6444,13 +6448,13 @@ namespace details }; template - struct _WhenAllImpl, _Iterator> + struct _WhenAllImpl, _Iterator> { - static task> _Perform(const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End) + static task> _Perform(const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End) { _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() : nullptr; - auto _PParam = new _RunAllParam>(); + auto _PParam = new _RunAllParam>(); cancellation_token_source _MergedSource; // Step1: Create task completion event. @@ -6458,12 +6462,12 @@ namespace details _Options.set_cancellation_token(_MergedSource.get_token()); task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _Options); // The return task must be created before step 3 to enforce inline execution. - auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> std::vector<_ElementType> { + auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> utility::vector<_ElementType> { _ASSERTE(_PParam->_M_completeCount == _PParam->_M_numTasks); - std::vector<_ElementType> _Result; + utility::vector<_ElementType> _Result; for(size_t _I = 0; _I < _PParam->_M_numTasks; _I++) { - const std::vector<_ElementType>& _Vec = _PParam->_M_vector[_I].Get(); + const utility::vector<_ElementType>& _Vec = _PParam->_M_vector[_I].Get(); _Result.insert(_Result.end(), _Vec.begin(), _Vec.end()); } return _Result; @@ -6502,7 +6506,7 @@ namespace details _ReturnTask._SetAsync(); } - _PTask->_Then([_PParam, _Index](task> _ResultTask) { + _PTask->_Then([_PParam, _Index](task> _ResultTask) { auto _PParamCopy = _PParam; auto _IndexCopy = _Index; @@ -6583,7 +6587,7 @@ namespace details }; template - task> _WhenAllVectorAndValue(const task>& _VectorTask, const task<_ReturnType>& _ValueTask, + task> _WhenAllVectorAndValue(const task>& _VectorTask, const task<_ReturnType>& _ValueTask, bool _OutputVectorFirst) { auto _PParam = new _RunAllParam<_ReturnType>(); @@ -6592,7 +6596,7 @@ namespace details // Step1: Create task completion event. task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _MergedSource.get_token()); // The return task must be created before step 3 to enforce inline execution. - auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> std::vector<_ReturnType> { + auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> utility::vector<_ReturnType> { _ASSERTE(_PParam->_M_completeCount == 2); auto _Result = _PParam->_M_vector.Get(); // copy by value auto _mergeVal = _PParam->_M_mergeVal.Get(); @@ -6619,7 +6623,7 @@ namespace details { _ReturnTask._SetAsync(); } - _VectorTask._Then([_PParam](task> _ResultTask) { + _VectorTask._Then([_PParam](task> _ResultTask) { auto _PParamCopy = _PParam; auto _Func = [_PParamCopy, &_ResultTask]() { auto _ResultLocal = _ResultTask._GetImpl()->_GetResult(); @@ -6656,7 +6660,7 @@ namespace details /// /// /// A task that completes sucessfully when all of the input tasks have completed successfully. If the input tasks are of type T, -/// the output of this function will be a task<std::vector<T>>. If the input tasks are of type void the output +/// the output of this function will be a task<utility::vector<T>>. If the input tasks are of type void the output /// task will also be a task<void>. /// /// @@ -6687,10 +6691,10 @@ auto when_all(_Iterator _Begin, _Iterator _End, const task_options& _TaskOptions /// /// /// A task that completes successfully when both of the input tasks have completed successfully. If the input tasks are of type T, -/// the output of this function will be a task<std::vector<T>>. If the input tasks are of type void the output +/// the output of this function will be a task<utility::vector<T>>. If the input tasks are of type void the output /// task will also be a task<void>. /// To allow for a construct of the sort taskA && taskB && taskC, which are combined in pairs, the && operator -/// produces a task<std::vector<T>> if either one or both of the tasks are of type task<std::vector<T>>. +/// produces a task<utility::vector<T>> if either one or both of the tasks are of type task<utility::vector<T>>. /// /// /// If one of the tasks is canceled or throws an exception, the returned task will complete early, in the canceled state, and the exception, @@ -6719,10 +6723,10 @@ auto operator&&(const task<_ReturnType> & _Lhs, const task<_ReturnType> & _Rhs) /// /// /// A task that completes successfully when both of the input tasks have completed successfully. If the input tasks are of type T, -/// the output of this function will be a task<std::vector<T>>. If the input tasks are of type void the output +/// the output of this function will be a task<utility::vector<T>>. If the input tasks are of type void the output /// task will also be a task<void>. /// To allow for a construct of the sort taskA && taskB && taskC, which are combined in pairs, the && operator -/// produces a task<std::vector<T>> if either one or both of the tasks are of type task<std::vector<T>>. +/// produces a task<utility::vector<T>> if either one or both of the tasks are of type task<utility::vector<T>>. /// /// /// If one of the tasks is canceled or throws an exception, the returned task will complete early, in the canceled state, and the exception, @@ -6731,7 +6735,7 @@ auto operator&&(const task<_ReturnType> & _Lhs, const task<_ReturnType> & _Rhs) /// /**/ template -auto operator&&(const task> & _Lhs, const task<_ReturnType> & _Rhs) -> decltype(details::_WhenAllVectorAndValue(_Lhs, _Rhs, true)) +auto operator&&(const task> & _Lhs, const task<_ReturnType> & _Rhs) -> decltype(details::_WhenAllVectorAndValue(_Lhs, _Rhs, true)) { return details::_WhenAllVectorAndValue(_Lhs, _Rhs, true); } @@ -6750,10 +6754,10 @@ auto operator&&(const task> & _Lhs, const task<_ReturnT /// /// /// A task that completes successfully when both of the input tasks have completed successfully. If the input tasks are of type T, -/// the output of this function will be a task<std::vector<T>>. If the input tasks are of type void the output +/// the output of this function will be a task<utility::vector<T>>. If the input tasks are of type void the output /// task will also be a task<void>. /// To allow for a construct of the sort taskA && taskB && taskC, which are combined in pairs, the && operator -/// produces a task<std::vector<T>> if either one or both of the tasks are of type task<std::vector<T>>. +/// produces a task<utility::vector<T>> if either one or both of the tasks are of type task<utility::vector<T>>. /// /// /// If one of the tasks is canceled or throws an exception, the returned task will complete early, in the canceled state, and the exception, @@ -6762,7 +6766,7 @@ auto operator&&(const task> & _Lhs, const task<_ReturnT /// /**/ template -auto operator&&(const task<_ReturnType> & _Lhs, const task> & _Rhs) -> decltype(details::_WhenAllVectorAndValue(_Rhs, _Lhs, false)) +auto operator&&(const task<_ReturnType> & _Lhs, const task> & _Rhs) -> decltype(details::_WhenAllVectorAndValue(_Rhs, _Lhs, false)) { return details::_WhenAllVectorAndValue(_Rhs, _Lhs, false); } @@ -6781,10 +6785,10 @@ auto operator&&(const task<_ReturnType> & _Lhs, const task /// /// A task that completes successfully when both of the input tasks have completed successfully. If the input tasks are of type T, -/// the output of this function will be a task<std::vector<T>>. If the input tasks are of type void the output +/// the output of this function will be a task<utility::vector<T>>. If the input tasks are of type void the output /// task will also be a task<void>. /// To allow for a construct of the sort taskA && taskB && taskC, which are combined in pairs, the && operator -/// produces a task<std::vector<T>> if either one or both of the tasks are of type task<std::vector<T>>. +/// produces a task<utility::vector<T>> if either one or both of the tasks are of type task<utility::vector<T>>. /// /// /// If one of the tasks is canceled or throws an exception, the returned task will complete early, in the canceled state, and the exception, @@ -6793,9 +6797,9 @@ auto operator&&(const task<_ReturnType> & _Lhs, const task /**/ template -auto operator&&(const task> & _Lhs, const task> & _Rhs) -> decltype(when_all(&_Lhs, &_Lhs)) +auto operator&&(const task> & _Lhs, const task> & _Rhs) -> decltype(when_all(&_Lhs, &_Lhs)) { - task> _PTasks[2] = {_Lhs, _Rhs}; + task> _PTasks[2] = {_Lhs, _Rhs}; return when_all(_PTasks, _PTasks+2); } @@ -7071,10 +7075,10 @@ auto when_any(_Iterator _Begin, _Iterator _End, cancellation_token _Cancellation /// /// /// A task that completes sucessfully when either of the input tasks has completed successfully. If the input tasks are of type T, -/// the output of this function will be a task<std::vector<T>. If the input tasks are of type void the output task +/// the output of this function will be a task<utility::vector<T>. If the input tasks are of type void the output task /// will also be a task<void>. /// To allow for a construct of the sort taskA || taskB && taskC, which are combined in pairs, with && taking precedence -/// over ||, the operator|| produces a task<std::vector<T>> if one of the tasks is of type task<std::vector<T>> +/// over ||, the operator|| produces a task<utility::vector<T>> if one of the tasks is of type task<utility::vector<T>> /// and the other one is of type task<T>. /// /// @@ -7132,10 +7136,10 @@ task<_ReturnType> operator||(const task<_ReturnType> & _Lhs, const task<_ReturnT /// /// /// A task that completes sucessfully when either of the input tasks has completed successfully. If the input tasks are of type T, -/// the output of this function will be a task<std::vector<T>. If the input tasks are of type void the output task +/// the output of this function will be a task<utility::vector<T>. If the input tasks are of type void the output task /// will also be a task<void>. /// To allow for a construct of the sort taskA || taskB && taskC, which are combined in pairs, with && taking precedence -/// over ||, the operator|| produces a task<std::vector<T>> if one of the tasks is of type task<std::vector<T>> +/// over ||, the operator|| produces a task<utility::vector<T>> if one of the tasks is of type task<utility::vector<T>> /// and the other one is of type task<T>. /// /// @@ -7145,15 +7149,15 @@ task<_ReturnType> operator||(const task<_ReturnType> & _Lhs, const task<_ReturnT /// /**/ template -task> operator||(const task> & _Lhs, const task<_ReturnType> & _Rhs) +task> operator||(const task> & _Lhs, const task<_ReturnType> & _Rhs) { - auto _PParam = new details::_RunAnyParam, details::_CancellationTokenState *>>(); + auto _PParam = new details::_RunAnyParam, details::_CancellationTokenState *>>(); - task, details::_CancellationTokenState *>> _Any_tasks_completed(_PParam->_M_Completed, _PParam->_M_cancellationSource.get_token()); + task, details::_CancellationTokenState *>> _Any_tasks_completed(_PParam->_M_Completed, _PParam->_M_cancellationSource.get_token()); // Chain the return continuation task here to ensure it will get inline execution when _M_Completed.set is called, // So that _PParam can be used before it getting deleted. - auto _ReturnTask = _Any_tasks_completed._Then([=](std::pair, details::_CancellationTokenState *> _Ret) -> std::vector<_ReturnType> { + auto _ReturnTask = _Any_tasks_completed._Then([=](std::pair, details::_CancellationTokenState *> _Ret) -> utility::vector<_ReturnType> { _ASSERTE(_Ret.second); _JoinAllTokens_Add(_PParam->_M_cancellationSource, _Ret.second); return _Ret.first; @@ -7165,7 +7169,7 @@ task> operator||(const task> & } _PParam->_M_numTasks = 2; - _Lhs._Then([_PParam](task> _ResultTask) { + _Lhs._Then([_PParam](task> _ResultTask) { // Dev10 compiler bug auto _PParamCopy = _PParam; auto _Func = [&_ResultTask, _PParamCopy]() { @@ -7182,7 +7186,7 @@ task> operator||(const task> & auto _Func = [&_ResultTask, _PParamCopy]() { auto _Result = _ResultTask._GetImpl()->_GetResult(); - std::vector<_ReturnType> _Vec; + utility::vector<_ReturnType> _Vec; _Vec.push_back(_Result); _PParamCopy->_M_Completed.set(std::make_pair(_Vec, _ResultTask._GetImpl()->_M_pTokenState)); }; @@ -7206,10 +7210,10 @@ task> operator||(const task> & /// /// /// A task that completes sucessfully when either of the input tasks has completed successfully. If the input tasks are of type T, -/// the output of this function will be a task<std::vector<T>. If the input tasks are of type void the output task +/// the output of this function will be a task<utility::vector<T>. If the input tasks are of type void the output task /// will also be a task<void>. /// To allow for a construct of the sort taskA || taskB && taskC, which are combined in pairs, with && taking precedence -/// over ||, the operator|| produces a task<std::vector<T>> if one of the tasks is of type task<std::vector<T>> +/// over ||, the operator|| produces a task<utility::vector<T>> if one of the tasks is of type task<utility::vector<T>> /// and the other one is of type task<T>. /// /// @@ -7219,7 +7223,7 @@ task> operator||(const task> & /// /**/ template -auto operator||(const task<_ReturnType> & _Lhs, const task> & _Rhs) -> decltype(_Rhs || _Lhs) +auto operator||(const task<_ReturnType> & _Lhs, const task> & _Rhs) -> decltype(_Rhs || _Lhs) { return _Rhs || _Lhs; } @@ -7238,10 +7242,10 @@ auto operator||(const task<_ReturnType> & _Lhs, const task /// /// A task that completes sucessfully when either of the input tasks has completed successfully. If the input tasks are of type T, -/// the output of this function will be a task<std::vector<T>. If the input tasks are of type void the output task +/// the output of this function will be a task<utility::vector<T>. If the input tasks are of type void the output task /// will also be a task<void>. /// To allow for a construct of the sort taskA || taskB && taskC, which are combined in pairs, with && taking precedence -/// over ||, the operator|| produces a task<std::vector<T>> if one of the tasks is of type task<std::vector<T>> +/// over ||, the operator|| produces a task<utility::vector<T>> if one of the tasks is of type task<utility::vector<T>> /// and the other one is of type task<T>. /// /// diff --git a/Release/src/http/client/http_client.cpp b/Release/src/http/client/http_client.cpp index 2963fae3c2..35b7515ad8 100644 --- a/Release/src/http/client/http_client.cpp +++ b/Release/src/http/client/http_client.cpp @@ -58,13 +58,13 @@ void request_context::complete_request(utility::size64_t body_size) finish(); } -void request_context::report_error(unsigned long error_code, const std::string &errorMessage) +void request_context::report_error(unsigned long error_code, const utility::string &errorMessage) { report_exception(http_exception(static_cast(error_code), errorMessage)); } #if defined(_WIN32) -void request_context::report_error(unsigned long error_code, const std::wstring &errorMessage) +void request_context::report_error(unsigned long error_code, const utility::wstring &errorMessage) { report_exception(http_exception(static_cast(error_code), errorMessage)); } @@ -109,7 +109,7 @@ bool request_context::handle_content_encoding_compression() if (alg != web::http::details::compression::compression_algorithm::invalid) { - m_decompressor = utility::details::make_unique(alg); + m_decompressor = utility::make_unique(alg); } else { @@ -315,7 +315,7 @@ class http_pipeline private: // The vector of pipeline stages. - std::vector> m_stages; + utility::vector> m_stages; pplx::extensibility::recursive_lock_t m_lock; }; @@ -338,7 +338,7 @@ void http_client::add_handler(const std::function __cd std::function(http_request, std::shared_ptr)> m_handler; }; - m_pipeline->append(std::make_shared(handler)); + m_pipeline->append(utility::make_shared(handler)); } void http_client::add_handler(const std::shared_ptr &stage) @@ -367,15 +367,15 @@ http_client::http_client(const uri &base_uri, const http_client_config &client_c final_pipeline_stage = details::create_platform_final_pipeline_stage(uri(base_uri), http_client_config(client_config)); } - m_pipeline = std::make_shared(std::move(final_pipeline_stage)); + m_pipeline = utility::make_shared(std::move(final_pipeline_stage)); #if !defined(CPPREST_TARGET_XP) add_handler(std::static_pointer_cast( - std::make_shared(client_config.oauth1()))); + utility::make_shared(client_config.oauth1()))); #endif add_handler(std::static_pointer_cast( - std::make_shared(client_config.oauth2()))); + utility::make_shared(client_config.oauth2()))); } http_client::~http_client() CPPREST_NOEXCEPT {} diff --git a/Release/src/http/client/http_client_asio.cpp b/Release/src/http/client/http_client_asio.cpp index e3ea15c9ff..eb3a5bb87d 100644 --- a/Release/src/http/client/http_client_asio.cpp +++ b/Release/src/http/client/http_client_asio.cpp @@ -131,14 +131,6 @@ enum class httpclient_errorcode_context close }; -static std::string generate_base64_userpass(const ::web::credentials& creds) -{ - auto userpass = creds.username() + U(":") + *creds._internal_decrypt(); - auto&& u8_userpass = utility::conversions::to_utf8string(userpass); - std::vector credentials_buffer(u8_userpass.begin(), u8_userpass.end()); - return utility::conversions::to_utf8string(utility::conversions::to_base64(credentials_buffer)); -} - class asio_connection_pool; class asio_connection @@ -172,7 +164,7 @@ class asio_connection { ssl_context_callback(ssl_context); } - m_ssl_stream = utility::details::make_unique>( + m_ssl_stream = utility::make_unique>( m_socket, ssl_context); m_cn_hostname = std::move(cn_hostname); } @@ -336,7 +328,7 @@ class asio_connection // as normal message processing. std::mutex m_socket_lock; tcp::socket m_socket; - std::unique_ptr> m_ssl_stream; + utility::unique_ptr> m_ssl_stream; std::string m_cn_hostname; bool m_is_reused; @@ -383,7 +375,7 @@ class connection_pool_stack private: size_t m_highWater = 0; - std::vector> m_connections; + utility::vector> m_connections; }; /// Implements a connection pool with adaptive connection removal @@ -511,7 +503,7 @@ class asio_client final : public _http_client_communicator asio_client(http::uri&& address, http_client_config&& client_config) : _http_client_communicator(std::move(address), std::move(client_config)) , m_resolver(crossplat::threadpool::shared_instance().service()) - , m_pool(std::make_shared()) + , m_pool(utility::make_shared()) , m_start_with_ssl(base_uri().scheme() == U("https") && !this->client_config().proxy().is_specified()) { } @@ -527,7 +519,7 @@ class asio_client final : public _http_client_communicator if (conn == nullptr) { // Pool was empty. Create a new connection - conn = std::make_shared(crossplat::threadpool::shared_instance().service()); + conn = utility::make_shared(crossplat::threadpool::shared_instance().service()); if (m_start_with_ssl) { conn->upgrade_to_ssl(std::move(cn_host), this->client_config().get_ssl_context_callback()); @@ -579,7 +571,7 @@ class asio_context final : public request_context, public std::enable_shared_fro { auto client_cast(std::static_pointer_cast(client)); auto connection(client_cast->obtain_connection(request)); - auto ctx = std::make_shared(client, request, connection); + auto ctx = utility::make_shared(client, request, connection); ctx->m_timer.set_ctx(std::weak_ptr(ctx)); return ctx; } @@ -939,7 +931,7 @@ class asio_context final : public request_context, public std::enable_shared_fro // The ssl_tunnel_proxy keeps the context alive and then calls back once the ssl tunnel is established via // 'start_http_request_flow' std::shared_ptr ssl_tunnel = - std::make_shared(shared_from_this(), start_http_request_flow); + utility::make_shared(shared_from_this(), start_http_request_flow); ssl_tunnel->start_proxy_connect(); } else @@ -973,7 +965,7 @@ class asio_context final : public request_context, public std::enable_shared_fro { std::string header; header.append("Authorization: Basic "); - header.append(generate_base64_userpass(m_http_client->client_config().credentials())); + header.append(m_http_client->client_config().credentials().to_base64()); header.append(CRLF); return header; } @@ -982,7 +974,7 @@ class asio_context final : public request_context, public std::enable_shared_fro { std::string header; header.append("Proxy-Authorization: Basic "); - header.append(generate_base64_userpass(m_http_client->client_config().proxy().credentials())); + header.append(m_http_client->client_config().proxy().credentials().to_base64()); header.append(CRLF); return header; } @@ -1575,7 +1567,7 @@ class asio_context final : public request_context, public std::enable_shared_fro // Move the decompressed buffer into a shared_ptr to keep it alive until putn_nocopy completes. // When VS 2013 support is dropped, this should be changed to a unique_ptr plus a move capture. using web::http::details::compression::data_buffer; - auto shared_decompressed = std::make_shared(std::move(decompressed)); + auto shared_decompressed = utility::make_shared(std::move(decompressed)); writeBuffer.putn_nocopy(shared_decompressed->data(), shared_decompressed->size()) .then([this_request, to_read, shared_decompressed AND_CAPTURE_MEMBER_FUNCTION_POINTERS]( @@ -1705,7 +1697,7 @@ class asio_context final : public request_context, public std::enable_shared_fro // Move the decompressed buffer into a shared_ptr to keep it alive until putn_nocopy completes. // When VS 2013 support is dropped, this should be changed to a unique_ptr plus a move capture. using web::http::details::compression::data_buffer; - auto shared_decompressed = std::make_shared(std::move(decompressed)); + auto shared_decompressed = utility::make_shared(std::move(decompressed)); writeBuffer.putn_nocopy(shared_decompressed->data(), shared_decompressed->size()) .then([this_request, read_size, shared_decompressed AND_CAPTURE_MEMBER_FUNCTION_POINTERS]( @@ -1862,7 +1854,7 @@ class asio_context final : public request_context, public std::enable_shared_fro std::shared_ptr<_http_client_communicator> create_platform_final_pipeline_stage(uri&& base_uri, http_client_config&& client_config) { - return std::make_shared(std::move(base_uri), std::move(client_config)); + return utility::make_shared(std::move(base_uri), std::move(client_config)); } void asio_client::send_request(const std::shared_ptr& request_ctx) diff --git a/Release/src/http/client/http_client_impl.h b/Release/src/http/client/http_client_impl.h index 7b6c974a0d..fed7b2040c 100644 --- a/Release/src/http/client/http_client_impl.h +++ b/Release/src/http/client/http_client_impl.h @@ -58,10 +58,10 @@ class request_context /// void complete_request(utility::size64_t body_size); - void report_error(unsigned long error_code, const std::string &errorMessage); + void report_error(unsigned long error_code, const utility::string &errorMessage); #ifdef _WIN32 - void report_error(unsigned long error_code, const std::wstring &errorMessage); + void report_error(unsigned long error_code, const utility::wstring &errorMessage); #endif template @@ -95,7 +95,7 @@ class request_context // Registration for cancellation notification if enabled. pplx::cancellation_token_registration m_cancellationRegistration; - std::unique_ptr m_decompressor; + utility::unique_ptr m_decompressor; protected: @@ -141,7 +141,7 @@ class _http_client_communicator : public http_pipeline_stage void async_send_request_impl(const std::shared_ptr &request); // Queue used to guarantee ordering of requests, when applicable. - std::queue> m_requests_queue; + utility::queue> m_requests_queue; bool m_outstanding; }; diff --git a/Release/src/http/client/http_client_winhttp.cpp b/Release/src/http/client/http_client_winhttp.cpp index a1f69ab215..17daad8368 100644 --- a/Release/src/http/client/http_client_winhttp.cpp +++ b/Release/src/http/client/http_client_winhttp.cpp @@ -50,9 +50,9 @@ CPPREST_CONSTEXPR security_failure_message g_security_failure_messages[] = { "WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR internal error."}, }; -std::string generate_security_failure_message(std::uint32_t flags) +utility::string generate_security_failure_message(std::uint32_t flags) { - std::string result("SSL Error:"); + utility::string result("SSL Error:"); for (const auto& message : g_security_failure_messages) { if (flags & message.flag) { result.push_back(' '); @@ -148,18 +148,18 @@ static void parse_winhttp_headers(HINTERNET request_handle, _In_z_ utf16char *he } // Helper function to build error messages. -static std::string build_error_msg(unsigned long code, const std::string &location) +static utility::string build_error_msg(unsigned long code, const utility::string &location) { - std::string msg(location); + utility::string msg(location); msg.append(": "); - msg.append(std::to_string(code)); + msg.append(utility::conversions::details::to_string(code)); msg.append(": "); - msg.append(utility::details::windows_category().message(code)); + msg.append(utility::details::windows_category().message(code).c_str()); return msg; } // Helper function to build an error message from a WinHTTP async result. -static std::string build_error_msg(_In_ WINHTTP_ASYNC_RESULT *error_result) +static utility::string build_error_msg(_In_ WINHTTP_ASYNC_RESULT *error_result) { switch(error_result->dwResult) { @@ -181,7 +181,7 @@ static std::string build_error_msg(_In_ WINHTTP_ASYNC_RESULT *error_result) class memory_holder { uint8_t* m_externalData; - std::vector m_internalData; + utility::vector m_internalData; public: memory_holder() : m_externalData(nullptr) @@ -225,12 +225,19 @@ enum msg_body_type // Additional information necessary to track a WinHTTP request. class winhttp_request_context final : public request_context { +private: + + struct private_constructor_cookie { }; + public: + explicit winhttp_request_context(private_constructor_cookie, const std::shared_ptr<_http_client_communicator> &client, const http_request &request) + : winhttp_request_context(client, request) { }; + // Factory function to create requests on the heap. static std::shared_ptr create_request_context(const std::shared_ptr<_http_client_communicator> &client, const http_request &request) { - std::shared_ptr ret(new winhttp_request_context(client, request)); + std::shared_ptr ret = utility::make_shared(private_constructor_cookie(), client, request); ret->m_self_reference = ret; return std::move(ret); } @@ -276,7 +283,7 @@ class winhttp_request_context final : public request_context // If the user specified that to guarantee data buffering of request data, in case of challenged authentication requests, etc... // Then if the request stream buffer doesn't support seeking we need to copy the body chunks as it is sent. concurrency::streams::istream m_readStream; - std::unique_ptr>> m_readBufferCopy; + utility::unique_ptr>> m_readBufferCopy; virtual concurrency::streams::streambuf _get_readbuffer() { return m_readStream.streambuf(); @@ -427,7 +434,7 @@ class winhttp_request_context final : public request_context private: utility::string_t m_customCnCheck; - std::vector m_cachedEncodedCert; + utility::vector m_cachedEncodedCert; // Can only create on the heap using factory function. winhttp_request_context(const std::shared_ptr<_http_client_communicator> &client, const http_request &request) @@ -657,7 +664,7 @@ class winhttp_client final : public _http_client_communicator if (uri.port() > 0) { proxy_str.push_back(_XPLATSTR(':')); - proxy_str.append(::utility::conversions::details::to_string_t(uri.port())); + proxy_str.append(utility::conversions::details::to_string_t(uri.port())); } proxy_name = proxy_str.c_str(); @@ -968,7 +975,7 @@ class winhttp_client final : public _http_client_communicator // Only need to cache the request body if user specified and the request stream doesn't support seeking. if (winhttp_context->m_bodyType != no_body && client_config().buffer_request() && !winhttp_context->_get_readbuffer().can_seek()) { - winhttp_context->m_readBufferCopy = ::utility::details::make_unique<::concurrency::streams::container_buffer>>(); + winhttp_context->m_readBufferCopy = utility::make_unique<::concurrency::streams::container_buffer>>(); } _start_request_send(winhttp_context, content_length); @@ -981,10 +988,10 @@ class winhttp_client final : public _http_client_communicator void _start_request_send(const std::shared_ptr& winhttp_context, size_t content_length) { // WinHttp takes a context object as a void*. We therefore heap allocate a std::weak_ptr to the request context which will be destroyed during the final callback. - std::unique_ptr> weak_context_holder; + utility::unique_ptr> weak_context_holder; if (winhttp_context->m_request_context == nullptr) { - weak_context_holder = std::make_unique>(winhttp_context); + weak_context_holder = utility::make_unique>(winhttp_context); winhttp_context->m_request_context = weak_context_holder.get(); } @@ -1122,7 +1129,7 @@ class winhttp_client final : public _http_client_communicator if (p_request_context->m_readBufferCopy) { // Move the saved buffer into the read buffer, which now supports seeking. - p_request_context->m_readStream = concurrency::streams::container_stream>::open_istream(std::move(p_request_context->m_readBufferCopy->collection())); + p_request_context->m_readStream = concurrency::streams::container_stream>::open_istream(std::move(p_request_context->m_readBufferCopy->collection())); p_request_context->m_readBufferCopy.reset(); } } @@ -1331,13 +1338,12 @@ class winhttp_client final : public _http_client_communicator // New scope to ensure plaintext password is cleared as soon as possible. { - auto password = cred._internal_decrypt(); if (!WinHttpSetCredentials( hRequestHandle, dwAuthTarget, dwSelectedScheme, cred.username().c_str(), - password->c_str(), + cred._internal_decrypt()->c_str(), nullptr)) { return false; @@ -1397,11 +1403,16 @@ class winhttp_client final : public _http_client_communicator { // This callback is responsible for freeing the type-erased context. // This particular status code indicates that this is the final callback call, suitable for context destruction. - delete p_weak_request_context; + auto lock = p_weak_request_context->lock(); + if (lock) { + lock->cleanup(); + } else { + utility::unique_ptr> weak_context_holder(p_weak_request_context); + } return; } - auto p_request_context = p_weak_request_context->lock(); + std::shared_ptr p_request_context = p_weak_request_context->lock(); if (!p_request_context) { // The request context was already released, probably due to cancellation @@ -1470,7 +1481,7 @@ class winhttp_client final : public _http_client_communicator return; case WINHTTP_CALLBACK_STATUS_SECURE_FAILURE: p_request_context->report_exception(web::http::http_exception( - generate_security_failure_message(*reinterpret_cast(statusInfo)))); + generate_security_failure_message(*reinterpret_cast(statusInfo)).c_str())); return; case WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE : { @@ -1521,7 +1532,7 @@ class winhttp_client final : public _http_client_communicator query_header_length(hRequestHandle, WINHTTP_QUERY_RAW_HEADERS_CRLF, headerBufferLength); // Now allocate buffer for headers and query for them. - std::vector header_raw_buffer; + utility::vector header_raw_buffer; header_raw_buffer.resize(headerBufferLength); utf16char * header_buffer = reinterpret_cast(&header_raw_buffer[0]); if(!WinHttpQueryHeaders( @@ -1730,7 +1741,7 @@ class winhttp_client final : public _http_client_communicator std::shared_ptr<_http_client_communicator> create_platform_final_pipeline_stage(uri&& base_uri, http_client_config&& client_config) { - return std::make_shared(std::move(base_uri), std::move(client_config)); + return utility::make_shared(std::move(base_uri), std::move(client_config)); } }}}} diff --git a/Release/src/http/client/http_client_winrt.cpp b/Release/src/http/client/http_client_winrt.cpp index 5a0697b489..2adbb2a282 100644 --- a/Release/src/http/client/http_client_winrt.cpp +++ b/Release/src/http/client/http_client_winrt.cpp @@ -45,7 +45,7 @@ class winrt_request_context final : public request_context // Factory function to create requests on the heap. static std::shared_ptr create_request_context(const std::shared_ptr<_http_client_communicator> &client, http_request &request) { - return std::make_shared(client, request); + return utility::make_shared(client, request); } Microsoft::WRL::ComPtr m_hRequest; @@ -157,7 +157,7 @@ class HttpRequestCallback final : { if (m_request->m_exceptionPtr == nullptr) { - std::wstring msg(L"IXMLHttpRequest2Callback::OnError: "); + utility::wstring msg(L"IXMLHttpRequest2Callback::OnError: "); msg.append(std::to_wstring(hrError)); msg.append(L": "); msg.append(utility::conversions::to_string_t(utility::details::windows_category().message(hrError))); @@ -553,7 +553,7 @@ class winrt_client final : public _http_client_communicator std::shared_ptr<_http_client_communicator> create_platform_final_pipeline_stage(uri&& base_uri, http_client_config&& client_config) { - return std::make_shared(std::move(base_uri), std::move(client_config)); + return utility::make_shared(std::move(base_uri), std::move(client_config)); } }}}} diff --git a/Release/src/http/client/x509_cert_utilities.cpp b/Release/src/http/client/x509_cert_utilities.cpp index 0a7a762d50..8aa1861ef8 100644 --- a/Release/src/http/client/x509_cert_utilities.cpp +++ b/Release/src/http/client/x509_cert_utilities.cpp @@ -40,9 +40,9 @@ namespace client { namespace details { -static bool verify_X509_cert_chain(const std::vector& certChain, const std::string& hostName); +static bool verify_X509_cert_chain(const utility::vector& certChain, const utility::string& hostName); -bool verify_cert_chain_platform_specific(boost::asio::ssl::verify_context& verifyCtx, const std::string& hostName) +bool verify_cert_chain_platform_specific(boost::asio::ssl::verify_context& verifyCtx, const utility::string& hostName) { X509_STORE_CTX* storeContext = verifyCtx.native_handle(); int currentDepth = X509_STORE_CTX_get_error_depth(storeContext); @@ -58,7 +58,7 @@ bool verify_cert_chain_platform_specific(boost::asio::ssl::verify_context& verif return false; } - std::vector certChain; + utility::vector certChain; certChain.reserve(numCerts); for (int i = 0; i < numCerts; ++i) { @@ -71,7 +71,7 @@ bool verify_cert_chain_platform_specific(boost::asio::ssl::verify_context& verif return false; } - std::string certData; + utility::string certData; certData.resize(len); unsigned char* buffer = reinterpret_cast(&certData[0]); len = i2d_X509(cert, &buffer); @@ -89,7 +89,7 @@ bool verify_cert_chain_platform_specific(boost::asio::ssl::verify_context& verif #if defined(_WIN32) if (verify_result) { - boost::asio::ssl::rfc2818_verification rfc2818(hostName); + boost::asio::ssl::rfc2818_verification rfc2818(hostName.c_str()); verify_result = rfc2818(verify_result, verifyCtx); } #endif @@ -140,7 +140,7 @@ static bool jni_failed(JNIEnv* env, const jmethodID& result) #define CHECK_JNI(env) \ if (jni_failed(env)) return false; -bool verify_X509_cert_chain(const std::vector& certChain, const std::string& hostName) +bool verify_X509_cert_chain(const utility::vector& certChain, const utility::string& hostName) { JNIEnv* env = get_jvm_env(); @@ -310,12 +310,12 @@ class cf_ref }; } -bool verify_X509_cert_chain(const std::vector& certChain, const std::string& hostName) +bool verify_X509_cert_chain(const utility::vector& certChain, const utility::string& hostName) { // Build up CFArrayRef with all the certificates. // All this code is basically just to get into the correct structures for the Apple APIs. // Copies are avoided whenever possible. - std::vector> certs; + utility::vector> certs; for (const auto& certBuf : certChain) { cf_ref certDataRef = @@ -370,7 +370,7 @@ bool verify_X509_cert_chain(const std::vector& certChain, const std #endif #if defined(_WIN32) -bool verify_X509_cert_chain(const std::vector& certChain, const std::string& hostname) +bool verify_X509_cert_chain(const utility::vector& certChain, const utility::string& hostname) { // Create certificate context from server certificate. winhttp_cert_context cert; diff --git a/Release/src/http/common/http_helpers.cpp b/Release/src/http/common/http_helpers.cpp index 2c45e5961d..11e0995e04 100644 --- a/Release/src/http/common/http_helpers.cpp +++ b/Release/src/http/common/http_helpers.cpp @@ -386,7 +386,7 @@ namespace compression } stream_decompressor::stream_decompressor(compression_algorithm alg) - : m_pimpl(std::make_shared(alg)) + : m_pimpl(utility::make_shared(alg)) { } @@ -420,7 +420,7 @@ namespace compression } stream_compressor::stream_compressor(compression_algorithm alg) - : m_pimpl(std::make_shared(alg)) + : m_pimpl(utility::make_shared(alg)) { } diff --git a/Release/src/http/common/http_msg.cpp b/Release/src/http/common/http_msg.cpp index 8f218cb913..b9a1b6e1d4 100644 --- a/Release/src/http/common/http_msg.cpp +++ b/Release/src/http/common/http_msg.cpp @@ -65,7 +65,7 @@ namespace { return unknown; } - std::string convert_utf16le_to_utf8(utf16string src, bool erase_bom) + utility::string convert_utf16le_to_utf8(utf16string src, bool erase_bom) { if (erase_bom && !src.empty()) { @@ -110,7 +110,7 @@ namespace { return src; } - std::string convert_utf16be_to_utf8(utf16string src, bool erase_bom) + utility::string convert_utf16be_to_utf8(utf16string src, bool erase_bom) { return utf16_to_utf8(big_endian_to_little_endian(std::move(src), erase_bom)); } @@ -129,7 +129,7 @@ namespace { #endif } - std::string convert_utf16_to_utf8(utf16string src) + utility::string convert_utf16_to_utf8(utf16string src) { const endianness endian = check_byte_order_mark(src); switch (endian) @@ -251,12 +251,12 @@ void parse_headers_string(_Inout_z_ utf16char *headersStr, http_headers &headers } -http_version __cdecl http_version::from_string(const std::string& http_version_string) +http_version __cdecl http_version::from_string(const utility::string& http_version_string) { - std::stringstream str(http_version_string); + utility::stringstream str(http_version_string); str.imbue(std::locale::classic()); - std::string http; std::getline(str, http, '/'); + utility::string http; std::getline(str, http, '/'); unsigned int major = 0; str >> major; char dot = '\0'; str >> dot; unsigned int minor = 0; str >> minor; @@ -269,14 +269,14 @@ http_version __cdecl http_version::from_string(const std::string& http_version_s return{ 0, 0 }; } -std::string http_version::to_utf8string() const +utility::string http_version::to_utf8string() const { - std::string ret; + utility::string ret; ret.reserve(8); ret.append("HTTP/"); - ret.append(std::to_string(static_cast(major))); + ret.append(utility::conversions::details::to_string(static_cast(major))); ret.append("."); - ret.append(std::to_string(static_cast(minor))); + ret.append(utility::conversions::details::to_string(static_cast(minor))); return ret; } @@ -610,8 +610,8 @@ utf8string details::http_msg_base::extract_utf8string(bool ignore_content_type) || utility::details::str_iequal(charset, charset_types::usascii) || utility::details::str_iequal(charset, charset_types::ascii)) { - std::string body; - body.resize((std::string::size_type)buf_r.in_avail()); + utility::string body; + body.resize((utility::string::size_type)buf_r.in_avail()); buf_r.getn(const_cast(reinterpret_cast(body.data())), body.size()).get(); // There is no risk of blocking. return body; } @@ -619,8 +619,8 @@ utf8string details::http_msg_base::extract_utf8string(bool ignore_content_type) // Latin1 else if (utility::details::str_iequal(charset, charset_types::latin1)) { - std::string body; - body.resize((std::string::size_type)buf_r.in_avail()); + utility::string body; + body.resize((utility::string::size_type)buf_r.in_avail()); buf_r.getn(const_cast(reinterpret_cast(body.data())), body.size()).get(); // There is no risk of blocking. return latin1_to_utf8(std::move(body)); } @@ -681,8 +681,8 @@ utf16string details::http_msg_base::extract_utf16string(bool ignore_content_type || utility::details::str_iequal(charset, charset_types::usascii) || utility::details::str_iequal(charset, charset_types::ascii)) { - std::string body; - body.resize((std::string::size_type)buf_r.in_avail()); + utility::string body; + body.resize((utility::string::size_type)buf_r.in_avail()); buf_r.getn(const_cast(reinterpret_cast(body.data())), body.size()).get(); // There is no risk of blocking. return utility::conversions::utf8_to_utf16(std::move(body)); } @@ -690,8 +690,8 @@ utf16string details::http_msg_base::extract_utf16string(bool ignore_content_type // Latin1 else if (utility::details::str_iequal(charset, charset_types::latin1)) { - std::string body; - body.resize((std::string::size_type)buf_r.in_avail()); + utility::string body; + body.resize((utility::string::size_type)buf_r.in_avail()); buf_r.getn(const_cast(reinterpret_cast(body.data())), body.size()).get(); // There is no risk of blocking. return latin1_to_utf16(std::move(body)); } @@ -733,8 +733,8 @@ utility::string_t details::http_msg_base::extract_string(bool ignore_content_typ if (utility::details::str_iequal(charset, charset_types::usascii) || utility::details::str_iequal(charset, charset_types::ascii)) { - std::string body; - body.resize((std::string::size_type)buf_r.in_avail()); + utility::string body; + body.resize((utility::string::size_type)buf_r.in_avail()); buf_r.getn(const_cast(reinterpret_cast(body.data())), body.size()).get(); // There is no risk of blocking. return to_string_t(std::move(body)); } @@ -742,8 +742,8 @@ utility::string_t details::http_msg_base::extract_string(bool ignore_content_typ // Latin1 if(utility::details::str_iequal(charset, charset_types::latin1)) { - std::string body; - body.resize((std::string::size_type)buf_r.in_avail()); + utility::string body; + body.resize((utility::string::size_type)buf_r.in_avail()); buf_r.getn(const_cast(reinterpret_cast(body.data())), body.size()).get(); // There is no risk of blocking. // Could optimize for linux in the future if a latin1_to_utf8 function was written. return to_string_t(latin1_to_utf16(std::move(body))); @@ -752,8 +752,8 @@ utility::string_t details::http_msg_base::extract_string(bool ignore_content_typ // utf-8. else if(utility::details::str_iequal(charset, charset_types::utf8)) { - std::string body; - body.resize((std::string::size_type)buf_r.in_avail()); + utility::string body; + body.resize((utility::string::size_type)buf_r.in_avail()); buf_r.getn(const_cast(reinterpret_cast(body.data())), body.size()).get(); // There is no risk of blocking. return to_string_t(std::move(body)); } @@ -803,7 +803,7 @@ json::value details::http_msg_base::_extract_json(bool ignore_content_type) // Latin1 if(utility::details::str_iequal(charset, charset_types::latin1)) { - std::string body; + utility::string body; body.resize(buf_r.in_avail()); buf_r.getn(const_cast(reinterpret_cast(body.data())), body.size()).get(); // There is no risk of blocking. // On Linux could optimize in the future if a latin1_to_utf8 function is written. @@ -815,7 +815,7 @@ json::value details::http_msg_base::_extract_json(bool ignore_content_type) || utility::details::str_iequal(charset, charset_types::usascii) || utility::details::str_iequal(charset, charset_types::ascii)) { - std::string body; + utility::string body; body.resize(buf_r.in_avail()); buf_r.getn(const_cast(reinterpret_cast(body.data())), body.size()).get(); // There is no risk of blocking. return json::value::parse(to_string_t(std::move(body))); @@ -854,14 +854,14 @@ json::value details::http_msg_base::_extract_json(bool ignore_content_type) } } -std::vector details::http_msg_base::_extract_vector() +utility::vector details::http_msg_base::_extract_vector() { if (!instream()) { throw http_exception(stream_was_set_explicitly); } - std::vector body; + utility::vector body; auto buf_r = instream().streambuf(); const size_t size = buf_r.in_avail(); body.resize(size); @@ -897,7 +897,7 @@ static utility::string_t convert_body_to_string_t(const utility::string_t &conte // Latin1 if(utility::details::str_iequal(charset, charset_types::latin1)) { - std::string body; + utility::string body; body.resize(streambuf.in_avail()); if(streambuf.scopy((unsigned char *)&body[0], body.size()) == 0) return string_t(); return to_string_t(latin1_to_utf16(std::move(body))); @@ -906,7 +906,7 @@ static utility::string_t convert_body_to_string_t(const utility::string_t &conte // utf-8. else if(utility::details::str_iequal(charset, charset_types::utf8)) { - std::string body; + utility::string body; body.resize(streambuf.in_avail()); if(streambuf.scopy((unsigned char *)&body[0], body.size()) == 0) return string_t(); return to_string_t(std::move(body)); @@ -1033,7 +1033,7 @@ details::_http_request::_http_request(http::method mtd) } } -details::_http_request::_http_request(std::unique_ptr server_context) +details::_http_request::_http_request(utility::unique_ptr server_context) : m_initiated_response(0), m_server_context(std::move(server_context)), m_cancellationToken(pplx::cancellation_token::none()), diff --git a/Release/src/http/common/internal_http_helpers.h b/Release/src/http/common/internal_http_helpers.h index 024ac84ac4..232f7cf68c 100644 --- a/Release/src/http/common/internal_http_helpers.h +++ b/Release/src/http/common/internal_http_helpers.h @@ -17,7 +17,7 @@ utility::string_t get_default_reason_phrase(status_code code); // simple helper functions to trim whitespace. template -void trim_whitespace(std::basic_string &str) +void trim_whitespace(utility::basic_string &str) { size_t index; // trim left whitespace diff --git a/Release/src/http/common/x509_cert_utilities.h b/Release/src/http/common/x509_cert_utilities.h index 9884b05993..3b3a85587b 100644 --- a/Release/src/http/common/x509_cert_utilities.h +++ b/Release/src/http/common/x509_cert_utilities.h @@ -101,7 +101,7 @@ namespace details /// Boost.ASIO context to get certificate chain from. /// Host name from the URI. /// True if verification passed and server can be trusted, false otherwise. -bool verify_cert_chain_platform_specific(boost::asio::ssl::verify_context& verifyCtx, const std::string& hostName); +bool verify_cert_chain_platform_specific(boost::asio::ssl::verify_context& verifyCtx, const utility::string& hostName); } } } diff --git a/Release/src/http/listener/http_listener.cpp b/Release/src/http/listener/http_listener.cpp index baa204b56d..423adfe00b 100644 --- a/Release/src/http/listener/http_listener.cpp +++ b/Release/src/http/listener/http_listener.cpp @@ -63,21 +63,6 @@ details::http_listener_impl::http_listener_impl(http::uri address, http_listener check_listener_uri(m_uri); } -http_listener::~http_listener() -{ - if(m_impl) - { - // As a safe guard close the listener if not already done. - // Users are required to call close, but this is just a safeguard. - try - { - close().wait(); - } catch(...) - { - } - } -} - pplx::task details::http_listener_impl::open() { // Do nothing if the open operation was already attempted diff --git a/Release/src/http/listener/http_server_api.cpp b/Release/src/http/listener/http_server_api.cpp index 9a8289b7fa..29e5913925 100644 --- a/Release/src/http/listener/http_server_api.cpp +++ b/Release/src/http/listener/http_server_api.cpp @@ -26,7 +26,7 @@ namespace details pplx::extensibility::critical_section_t http_server_api::s_lock; -std::unique_ptr http_server_api::s_server_api((http_server*)nullptr); +utility::unique_ptr http_server_api::s_server_api((http_server*)nullptr); pplx::details::atomic_long http_server_api::s_registrations(0L); @@ -35,7 +35,7 @@ bool http_server_api::has_listener() return s_registrations > 0L; } -void http_server_api::register_server_api(std::unique_ptr server_api) +void http_server_api::register_server_api(utility::unique_ptr server_api) { pplx::extensibility::scoped_critical_section_t lock(s_lock); http_server_api::unsafe_register_server_api(std::move(server_api)); @@ -53,7 +53,7 @@ void http_server_api::unregister_server_api() s_server_api.release(); } -void http_server_api::unsafe_register_server_api(std::unique_ptr server_api) +void http_server_api::unsafe_register_server_api(utility::unique_ptr server_api) { // we assume that the lock has been taken here. if (http_server_api::has_listener()) diff --git a/Release/src/http/listener/http_server_asio.cpp b/Release/src/http/listener/http_server_asio.cpp index 13b813b858..f4dc156085 100644 --- a/Release/src/http/listener/http_server_asio.cpp +++ b/Release/src/http/listener/http_server_asio.cpp @@ -59,7 +59,7 @@ using web::http::http_exception; using web::http::experimental::listener::details::http_listener_impl; using web::http::experimental::listener::http_listener_config; -using utility::details::make_unique; +using utility::make_unique; namespace { @@ -84,8 +84,8 @@ namespace friend class asio_server_connection; pplx::extensibility::reader_writer_lock_t m_listeners_lock; - std::map, iequal_to> m_listeners; - std::unordered_map> m_registered_listeners; + std::map, iequal_to> m_listeners; + utility::unordered_map> m_registered_listeners; bool m_started; public: @@ -124,7 +124,7 @@ namespace { private: int m_backlog; - std::unique_ptr m_acceptor; + utility::unique_ptr m_acceptor; std::map m_listeners; pplx::extensibility::reader_writer_lock_t m_listeners_lock; @@ -197,7 +197,7 @@ namespace } private: - void on_accept(std::unique_ptr socket, const boost::system::error_code& ec); + void on_accept(utility::unique_ptr socket, const boost::system::error_code& ec); }; @@ -313,7 +313,7 @@ class asio_server_connection typedef void (asio_server_connection::*ResponseFuncPtr) (const http_response &response, const boost::system::error_code& ec); - std::unique_ptr m_socket; + utility::unique_ptr m_socket; boost::asio::streambuf m_request_buf; boost::asio::streambuf m_response_buf; http_linux_server* m_p_server; @@ -327,10 +327,10 @@ class asio_server_connection using ssl_stream = boost::asio::ssl::stream; - std::unique_ptr m_ssl_context; - std::unique_ptr m_ssl_stream; + utility::unique_ptr m_ssl_context; + utility::unique_ptr m_ssl_stream; - asio_server_connection(std::unique_ptr socket, http_linux_server* server, hostport_listener* parent) + asio_server_connection(utility::unique_ptr socket, http_linux_server* server, hostport_listener* parent) : m_socket(std::move(socket)) , m_request_buf() , m_response_buf() @@ -348,11 +348,11 @@ class asio_server_connection }; public: - using refcount_ptr = std::unique_ptr; + using refcount_ptr = utility::unique_ptr; - static refcount_ptr create(std::unique_ptr socket, http_linux_server* server, hostport_listener* parent) + static refcount_ptr create(utility::unique_ptr socket, http_linux_server* server, hostport_listener* parent) { - return refcount_ptr(new asio_server_connection(std::move(socket), server, parent)); + return refcount_ptr(utility::make_unique(std::move(socket), server, parent)); } refcount_ptr get_reference() @@ -511,17 +511,17 @@ void hostport_listener::start() tcp::endpoint endpoint = *resolver.resolve(query); - m_acceptor.reset(new tcp::acceptor(service)); + m_acceptor = utility::make_unique(service); m_acceptor->open(endpoint.protocol()); m_acceptor->set_option(socket_base::reuse_address(true)); m_acceptor->bind(endpoint); m_acceptor->listen(0 != m_backlog ? m_backlog : socket_base::max_connections); - auto socket = new ip::tcp::socket(service); - std::unique_ptr usocket(socket); + utility::unique_ptr usocket = utility::make_unique(socket); + ip::tcp::socket *socket = usocket.get(); m_acceptor->async_accept(*socket, [this, socket](const boost::system::error_code& ec) { - std::unique_ptr usocket(socket); + utility::unique_ptr usocket(socket); this->on_accept(std::move(usocket), ec); }); usocket.release(); @@ -564,7 +564,7 @@ will_deref_and_erase_t asio_server_connection::start_request_response() return will_deref_and_erase_t{}; } -void hostport_listener::on_accept(std::unique_ptr socket, const boost::system::error_code& ec) +void hostport_listener::on_accept(utility::unique_ptr socket, const boost::system::error_code& ec) { // Listener closed if (ec == boost::asio::error::operation_aborted) @@ -602,11 +602,11 @@ void hostport_listener::on_accept(std::unique_ptr socket, const if (m_acceptor) { // spin off another async accept - auto newSocket = new ip::tcp::socket(crossplat::threadpool::shared_instance().service()); - std::unique_ptr usocket(newSocket); + utility::unique_ptr usocket = utility::make_unique(socket); + ip::tcp::socket *newSocket = usocket.get(); m_acceptor->async_accept(*newSocket, [this, newSocket](const boost::system::error_code& ec) { - std::unique_ptr usocket(newSocket); + utility::unique_ptr usocket(newSocket); this->on_accept(std::move(usocket), ec); }); usocket.release(); @@ -615,7 +615,7 @@ void hostport_listener::on_accept(std::unique_ptr socket, const will_deref_and_erase_t asio_server_connection::handle_http_line(const boost::system::error_code& ec) { - m_request = http_request::_create_request(make_unique()); + m_request = http_request::_create_request(utility::make_unique()); if (ec) { // client closed connection @@ -1307,13 +1307,13 @@ pplx::task http_linux_server::register_listener(http_listener_impl* listen try { - m_registered_listeners[listener] = make_unique(); + m_registered_listeners[listener] = utility::make_unique(); auto found_hostport_listener = m_listeners.find(hostport); if (found_hostport_listener == m_listeners.end()) { found_hostport_listener = m_listeners.insert( - std::make_pair(hostport, make_unique(this, hostport, is_https, listener->configuration()))).first; + std::make_pair(hostport, utility::make_unique(this, hostport, is_https, listener->configuration()))).first; if (m_started) { @@ -1355,7 +1355,7 @@ pplx::task http_linux_server::unregister_listener(http_listener_impl* list } // Second remove the listener form listener collection - std::unique_ptr pListenerLock = nullptr; + utility::unique_ptr pListenerLock; { pplx::extensibility::scoped_rw_lock_t lock(m_listeners_lock); pListenerLock = std::move(m_registered_listeners[listener]); @@ -1390,9 +1390,9 @@ namespace experimental namespace details { -std::unique_ptr make_http_asio_server() +utility::unique_ptr make_http_asio_server() { - return make_unique(); + return utility::make_unique(); } }}}} diff --git a/Release/src/http/listener/http_server_httpsys.cpp b/Release/src/http/listener/http_server_httpsys.cpp index 8da74d0083..f3bd54285b 100644 --- a/Release/src/http/listener/http_server_httpsys.cpp +++ b/Release/src/http/listener/http_server_httpsys.cpp @@ -104,7 +104,7 @@ static utility::string_t HttpServerAPIKnownHeaders[] = static void char_to_wstring(utf16string &dest, const char * src) { - dest = utility::conversions::to_utf16string(std::string(src)); + dest = utility::conversions::to_utf16string(src); } http::method parse_request_method(const HTTP_REQUEST *p_request) @@ -300,7 +300,7 @@ pplx::task http_windows_server::register_listener(_In_ web::http::experime HttpCloseUrlGroup(urlGroupId); throw std::invalid_argument("Error: http_listener is already registered"); } - _M_registeredListeners[pListener] = std::unique_ptr(new listener_registration(urlGroupId)); + _M_registeredListeners[pListener] = utility::make_unique(urlGroupId); } // Associate Url group with request queue. @@ -326,7 +326,7 @@ pplx::task http_windows_server::unregister_listener(_In_ web::http::experi return pplx::create_task([=]() { // First remove listener registration. - std::unique_ptr registration; + utility::unique_ptr registration; { pplx::extensibility::scoped_rw_lock_t lock(_M_listenersLock); registration = std::move(_M_registeredListeners[pListener]); @@ -445,8 +445,8 @@ void http_windows_server::receive_requests() } // Start processing the request - auto pContext = new windows_request_context(); - auto pRequestContext = std::unique_ptr<_http_server_context>(pContext); + utility::unique_ptr pRequestContext = utility::make_unique(); + windows_request_context* pContext = pRequestContext.get(); http_request msg = http_request::_create_request(std::move(pRequestContext)); pContext->async_process_request(p_request.RequestId, msg, bytes_received); } @@ -502,7 +502,7 @@ void windows_request_context::async_process_request(HTTP_REQUEST_ID request_id, // Save the http_request as the member of windows_request_context for the callback use. m_msg = msg; - m_request_buffer = std::unique_ptr(new unsigned char[msl::safeint3::SafeInt(headers_size)]); + m_request_buffer = utility::make_unique(msl::safeint3::SafeInt(headers_size)); m_request = (HTTP_REQUEST *) m_request_buffer.get(); // The read_headers_io_completion callback function. @@ -539,7 +539,7 @@ void windows_request_context::read_headers_io_completion(DWORD error_code, DWORD } else { - std::string badRequestMsg; + utility::string badRequestMsg; try { // HTTP_REQUEST::pRawUrl contains the raw URI that came across the wire. @@ -560,7 +560,7 @@ void windows_request_context::read_headers_io_completion(DWORD error_code, DWORD m_msg._get_impl()->_set_http_version({ (uint8_t)m_request->Version.MajorVersion, (uint8_t)m_request->Version.MinorVersion }); // Retrieve the remote IP address - std::vector remoteAddressBuffer(50); + utility::vector remoteAddressBuffer(50); if (m_request->Address.pRemoteAddress->sa_family == AF_INET6) { @@ -797,13 +797,13 @@ void windows_request_context::async_process_response() HTTP_RESPONSE win_api_response; ZeroMemory(&win_api_response, sizeof(win_api_response)); win_api_response.StatusCode = m_response.status_code(); - const std::string reason = utf16_to_utf8(m_response.reason_phrase()); + const utility::string reason = utf16_to_utf8(m_response.reason_phrase()); win_api_response.pReason = reason.c_str(); win_api_response.ReasonLength = (USHORT)reason.size(); size_t content_length = m_response._get_impl()->_get_content_length(); - m_headers = std::unique_ptr(new HTTP_UNKNOWN_HEADER[msl::safeint3::SafeInt(m_response.headers().size())]); + m_headers = utility::make_unique(msl::safeint3::SafeInt(m_response.headers().size())); m_headers_buffer.resize(msl::safeint3::SafeInt(m_response.headers().size()) * 2); win_api_response.Headers.UnknownHeaderCount = (USHORT)m_response.headers().size(); @@ -1049,9 +1049,9 @@ void windows_request_context::cancel_request(std::exception_ptr except_ptr) } } -std::unique_ptr make_http_httpsys_server() +utility::unique_ptr make_http_httpsys_server() { - return std::make_unique(); + return utility::make_unique(); } }}}} diff --git a/Release/src/http/listener/http_server_httpsys.h b/Release/src/http/listener/http_server_httpsys.h index 2523d62e4e..6ec42821c7 100644 --- a/Release/src/http/listener/http_server_httpsys.h +++ b/Release/src/http/listener/http_server_httpsys.h @@ -132,10 +132,10 @@ struct windows_request_context : http::details::_http_server_context size_t m_remaining_to_write; HTTP_REQUEST *m_request; - std::unique_ptr m_request_buffer; + utility::unique_ptr m_request_buffer; - std::unique_ptr m_headers; - std::vector m_headers_buffer; + utility::unique_ptr m_headers; + utility::vector m_headers_buffer; http_overlapped m_overlapped; @@ -153,7 +153,7 @@ struct windows_request_context : http::details::_http_server_context // Cancels this request. void cancel_request(std::exception_ptr except_ptr); - std::vector m_body_data; + utility::vector m_body_data; }; /// @@ -221,7 +221,7 @@ class http_windows_server : public http_server // Registered listeners pplx::extensibility::reader_writer_lock_t _M_listenersLock; - std::unordered_map> _M_registeredListeners; + utility::unordered_map> _M_registeredListeners; // HTTP Server API server session id. HTTP_SERVER_SESSION_ID m_serverSessionId; diff --git a/Release/src/http/listener/http_server_impl.h b/Release/src/http/listener/http_server_impl.h index 6a4380b708..5856f33846 100644 --- a/Release/src/http/listener/http_server_impl.h +++ b/Release/src/http/listener/http_server_impl.h @@ -12,7 +12,7 @@ namespace experimental namespace details { -std::unique_ptr make_http_httpsys_server(); -std::unique_ptr make_http_asio_server(); +utility::unique_ptr make_http_httpsys_server(); +utility::unique_ptr make_http_asio_server(); }}}} diff --git a/Release/src/http/oauth/oauth1.cpp b/Release/src/http/oauth/oauth1.cpp index 37c71deb22..762a7f6876 100644 --- a/Release/src/http/oauth/oauth1.cpp +++ b/Release/src/http/oauth/oauth1.cpp @@ -49,13 +49,13 @@ namespace experimental // Code analysis complains even though there is no bug. #pragma warning(push) #pragma warning(disable : 6102) -std::vector oauth1_config::_hmac_sha1(const utility::string_t& key, const utility::string_t& data) +utility::vector oauth1_config::_hmac_sha1(const utility::string_t& key, const utility::string_t& data) { NTSTATUS status; BCRYPT_ALG_HANDLE alg_handle = nullptr; BCRYPT_HASH_HANDLE hash_handle = nullptr; - std::vector hash; + utility::vector hash; DWORD hash_len = 0; ULONG result_len = 0; @@ -110,7 +110,7 @@ using namespace Windows::Security::Cryptography; using namespace Windows::Security::Cryptography::Core; using namespace Windows::Storage::Streams; -std::vector oauth1_config::_hmac_sha1(const utility::string_t& key, const utility::string_t& data) +utility::vector oauth1_config::_hmac_sha1(const utility::string_t& key, const utility::string_t& data) { Platform::String^ data_str = ref new Platform::String(data.c_str()); Platform::String^ key_str = ref new Platform::String(key.c_str()); @@ -124,14 +124,14 @@ std::vector oauth1_config::_hmac_sha1(const utility::string_t& ke Platform::Array^ arr; CryptographicBuffer::CopyToByteArray(signed_buffer, &arr); - return std::vector(arr->Data, arr->Data + arr->Length); + return utility::vector(arr->Data, arr->Data + arr->Length); } #else // Linux, Mac OS X #include -std::vector oauth1_config::_hmac_sha1(const utility::string_t& key, const utility::string_t& data) +utility::vector oauth1_config::_hmac_sha1(const utility::string_t& key, const utility::string_t& data) { unsigned char digest[HMAC_MAX_MD_CBLOCK]; unsigned int digest_len = 0; @@ -140,7 +140,7 @@ std::vector oauth1_config::_hmac_sha1(const utility::string_t& ke (const unsigned char*) data.c_str(), data.length(), digest, &digest_len); - return std::vector(digest, digest + digest_len); + return utility::vector(digest, digest + digest_len); } #endif @@ -168,8 +168,8 @@ utility::string_t oauth1_config::_build_normalized_parameters(web::http::uri u, { // While map sorts items by keys it doesn't take value into account. // We need to sort the query parameters separately. - std::map queries_map = http::uri::split_query(std::move(u).query()); - std::vector queries; + utility::map queries_map = http::uri::split_query(std::move(u).query()); + utility::vector queries; for (const auto& query : queries_map) { utility::ostringstream_t os; diff --git a/Release/src/http/oauth/oauth2.cpp b/Release/src/http/oauth/oauth2.cpp index 247241933f..c642433890 100644 --- a/Release/src/http/oauth/oauth2.cpp +++ b/Release/src/http/oauth/oauth2.cpp @@ -115,7 +115,7 @@ pplx::task oauth2_config::_request_token(uri_builder& request_body_ub) if (http_basic_auth()) { // Build HTTP Basic authorization header. - const std::string creds_utf8(to_utf8string( + const utility::string creds_utf8(to_utf8string( uri::encode_data_string(client_key()) + U(":") + uri::encode_data_string(client_secret()))); request.headers().add(header_names::authorization, U("Basic ") + _to_base64(reinterpret_cast(creds_utf8.data()), creds_utf8.size())); diff --git a/Release/src/json/json.cpp b/Release/src/json/json.cpp index e5a6089aea..f575974c0e 100644 --- a/Release/src/json/json.cpp +++ b/Release/src/json/json.cpp @@ -34,77 +34,77 @@ utility::istream_t& web::json::operator >> (utility::istream_t &is, json::value } web::json::value::value() : - m_value(utility::details::make_unique()) + m_value(utility::make_unique()) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,m_kind(value::Null) #endif { } web::json::value::value(int32_t value) : - m_value(utility::details::make_unique(value)) + m_value(utility::make_unique(value)) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,m_kind(value::Number) #endif { } web::json::value::value(uint32_t value) : - m_value(utility::details::make_unique(value)) + m_value(utility::make_unique(value)) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,m_kind(value::Number) #endif { } web::json::value::value(int64_t value) : - m_value(utility::details::make_unique(value)) + m_value(utility::make_unique(value)) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,m_kind(value::Number) #endif { } web::json::value::value(uint64_t value) : - m_value(utility::details::make_unique(value)) + m_value(utility::make_unique(value)) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,m_kind(value::Number) #endif { } web::json::value::value(double value) : - m_value(utility::details::make_unique(value)) + m_value(utility::make_unique(value)) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,m_kind(value::Number) #endif { } web::json::value::value(bool value) : - m_value(utility::details::make_unique(value)) + m_value(utility::make_unique(value)) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,m_kind(value::Boolean) #endif { } web::json::value::value(utility::string_t value) : - m_value(utility::details::make_unique(std::move(value))) + m_value(utility::make_unique(std::move(value))) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,m_kind(value::String) #endif { } web::json::value::value(utility::string_t value, bool has_escape_chars) : -m_value(utility::details::make_unique(std::move(value), has_escape_chars)) +m_value(utility::make_unique(std::move(value), has_escape_chars)) #ifdef ENABLE_JSON_VALUE_VISUALIZER , m_kind(value::String) #endif { } web::json::value::value(const utility::char_t* value) : - m_value(utility::details::make_unique(value)) + m_value(utility::make_unique(value)) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,m_kind(value::String) #endif { } web::json::value::value(const utility::char_t* value, bool has_escape_chars) : -m_value(utility::details::make_unique(utility::string_t(value), has_escape_chars)) +m_value(utility::make_unique(utility::string_t(value), has_escape_chars)) #ifdef ENABLE_JSON_VALUE_VISUALIZER , m_kind(value::String) #endif @@ -121,7 +121,7 @@ web::json::value &web::json::value::operator=(const value &other) { if(this != &other) { - m_value = std::unique_ptr(other.m_value->_copy_value()); + m_value = utility::unique_ptr(other.m_value->_copy_value()); #ifdef ENABLE_JSON_VALUE_VISUALIZER m_kind = other.m_kind; #endif @@ -185,7 +185,7 @@ web::json::value web::json::value::boolean(bool value) web::json::value web::json::value::string(utility::string_t value) { - std::unique_ptr ptr = utility::details::make_unique(std::move(value)); + utility::unique_ptr ptr = utility::make_unique(std::move(value)); return web::json::value(std::move(ptr) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,value::String @@ -195,7 +195,7 @@ web::json::value web::json::value::string(utility::string_t value) web::json::value web::json::value::string(utility::string_t value, bool has_escape_chars) { - std::unique_ptr ptr = utility::details::make_unique(std::move(value), has_escape_chars); + utility::unique_ptr ptr = utility::make_unique(std::move(value), has_escape_chars); return web::json::value(std::move(ptr) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,value::String @@ -204,9 +204,9 @@ web::json::value web::json::value::string(utility::string_t value, bool has_esca } #ifdef _WIN32 -web::json::value web::json::value::string(const std::string &value) +web::json::value web::json::value::string(const utility::string &value) { - std::unique_ptr ptr = utility::details::make_unique(utility::conversions::to_utf16string(value)); + utility::unique_ptr ptr = utility::make_unique(utility::conversions::to_utf16string(value)); return web::json::value(std::move(ptr) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,value::String @@ -217,7 +217,7 @@ web::json::value web::json::value::string(const std::string &value) web::json::value web::json::value::object(bool keep_order) { - std::unique_ptr ptr = utility::details::make_unique(keep_order); + utility::unique_ptr ptr = utility::make_unique(keep_order); return web::json::value(std::move(ptr) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,value::Object @@ -225,9 +225,9 @@ web::json::value web::json::value::object(bool keep_order) ); } -web::json::value web::json::value::object(std::vector> fields, bool keep_order) +web::json::value web::json::value::object(utility::vector> fields, bool keep_order) { - std::unique_ptr ptr = utility::details::make_unique(std::move(fields), keep_order); + utility::unique_ptr ptr = utility::make_unique(std::move(fields), keep_order); return web::json::value(std::move(ptr) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,value::Object @@ -237,7 +237,7 @@ web::json::value web::json::value::object(std::vector ptr = utility::details::make_unique(); + utility::unique_ptr ptr = utility::make_unique(); return web::json::value(std::move(ptr) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,value::Array @@ -247,7 +247,7 @@ web::json::value web::json::value::array() web::json::value web::json::value::array(size_t size) { - std::unique_ptr ptr = utility::details::make_unique(size); + utility::unique_ptr ptr = utility::make_unique(size); return web::json::value(std::move(ptr) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,value::Array @@ -255,9 +255,9 @@ web::json::value web::json::value::array(size_t size) ); } -web::json::value web::json::value::array(std::vector elements) +web::json::value web::json::value::array(utility::vector elements) { - std::unique_ptr ptr = utility::details::make_unique(std::move(elements)); + utility::unique_ptr ptr = utility::make_unique(std::move(elements)); return web::json::value(std::move(ptr) #ifdef ENABLE_JSON_VALUE_VISUALIZER ,value::Array @@ -485,7 +485,7 @@ web::json::value& web::json::value::operator [] (const utility::string_t &key) { if ( this->is_null() ) { - m_value.reset(new web::json::details::_Object(details::g_keep_json_object_unsorted)); + m_value = utility::make_unique(details::g_keep_json_object_unsorted); #ifdef ENABLE_JSON_VALUE_VISUALIZER m_kind = value::Object; #endif @@ -497,7 +497,7 @@ web::json::value& web::json::value::operator[](size_t index) { if ( this->is_null() ) { - m_value.reset(new web::json::details::_Array()); + m_value = utility::make_unique(); #ifdef ENABLE_JSON_VALUE_VISUALIZER m_kind = value::Array; #endif diff --git a/Release/src/json/json_parsing.cpp b/Release/src/json/json_parsing.cpp index 13ecb5437c..e52852a2c0 100644 --- a/Release/src/json/json_parsing.cpp +++ b/Release/src/json/json_parsing.cpp @@ -100,7 +100,7 @@ class JSON_Parser Token() : kind(TKN_EOF) {} Kind kind; - std::basic_string string_val; + utility::basic_string string_val; typename JSON_Parser::Location start; @@ -151,9 +151,9 @@ class JSON_Parser bool CompleteKeywordTrue(Token &token); bool CompleteKeywordFalse(Token &token); bool CompleteKeywordNull(Token &token); - std::unique_ptr _ParseValue(typename JSON_Parser::Token &first); - std::unique_ptr _ParseObject(typename JSON_Parser::Token &tkn); - std::unique_ptr _ParseArray(typename JSON_Parser::Token &tkn); + utility::unique_ptr _ParseValue(typename JSON_Parser::Token &first); + utility::unique_ptr _ParseObject(typename JSON_Parser::Token &tkn); + utility::unique_ptr _ParseArray(typename JSON_Parser::Token &tkn); JSON_Parser& operator=(const JSON_Parser&); @@ -219,7 +219,7 @@ template class JSON_StringParser : public JSON_Parser { public: - JSON_StringParser(const std::basic_string& string) + JSON_StringParser(const utility::basic_string& string) : m_position(&string[0]) { m_startpos = m_position; @@ -476,7 +476,7 @@ bool JSON_Parser::CompleteNumberLiteral(CharType first, Token &token) } // Magic number 5 leaves room for decimal point, null terminator, etc (in most cases) - ::std::vector buf(::std::numeric_limits::digits10 + 5); + utility::vector buf(std::numeric_limits::digits10 + 5); int count = print_llu(buf.data(), buf.size(), val64); _ASSERTE(count >= 0); _ASSERTE((size_t)count < buf.size()); @@ -699,7 +699,7 @@ void convert_append_unicode_code_unit(JSON_Parser::Token &token, utf16c void convert_append_unicode_code_unit(JSON_Parser::Token &token, utf16char value) { utf16string utf16(reinterpret_cast(&value), 1); - token.string_val.append(::utility::conversions::utf16_to_utf8(utf16)); + token.string_val.append(utility::conversions::utf16_to_utf8(utf16)); } template @@ -961,9 +961,9 @@ void JSON_Parser::GetNextToken(typename JSON_Parser::Token& } template -std::unique_ptr JSON_Parser::_ParseObject(typename JSON_Parser::Token &tkn) +utility::unique_ptr JSON_Parser::_ParseObject(typename JSON_Parser::Token &tkn) { - auto obj = utility::details::make_unique(g_keep_json_object_unsorted); + auto obj = utility::make_unique(g_keep_json_object_unsorted); auto& elems = obj->m_object.m_elements; GetNextToken(tkn); @@ -974,7 +974,7 @@ std::unique_ptr JSON_Parser::_ParseObject( while (true) { // State 1: New field or end of object, looking for field name or closing brace - std::basic_string fieldName; + utility::basic_string fieldName; switch (tkn.kind) { case JSON_Parser::Token::TKN_StringLiteral: @@ -1020,7 +1020,7 @@ std::unique_ptr JSON_Parser::_ParseObject( done: GetNextToken(tkn); - if (tkn.m_error) return utility::details::make_unique(); + if (tkn.m_error) return utility::make_unique(); if (!g_keep_json_object_unsorted) { ::std::sort(elems.begin(), elems.end(), json::object::compare_pairs); @@ -1033,16 +1033,16 @@ std::unique_ptr JSON_Parser::_ParseObject( { SetErrorCode(tkn, json_error::malformed_object_literal); } - return utility::details::make_unique(); + return utility::make_unique(); } template -std::unique_ptr JSON_Parser::_ParseArray(typename JSON_Parser::Token &tkn) +utility::unique_ptr JSON_Parser::_ParseArray(typename JSON_Parser::Token &tkn) { GetNextToken(tkn); - if (tkn.m_error) return utility::details::make_unique(); + if (tkn.m_error) return utility::make_unique(); - auto result = utility::details::make_unique(); + auto result = utility::make_unique(); if (tkn.kind != JSON_Parser::Token::TKN_CloseBracket) { @@ -1050,34 +1050,34 @@ std::unique_ptr JSON_Parser::_ParseArray(t { // State 1: Looking for an expression. result->m_array.m_elements.emplace_back(ParseValue(tkn)); - if (tkn.m_error) return utility::details::make_unique(); + if (tkn.m_error) return utility::make_unique(); // State 4: Looking for a comma or a closing bracket switch (tkn.kind) { case JSON_Parser::Token::TKN_Comma: GetNextToken(tkn); - if (tkn.m_error) return utility::details::make_unique(); + if (tkn.m_error) return utility::make_unique(); break; case JSON_Parser::Token::TKN_CloseBracket: GetNextToken(tkn); - if (tkn.m_error) return utility::details::make_unique(); + if (tkn.m_error) return utility::make_unique(); return std::move(result); default: SetErrorCode(tkn, json_error::malformed_array_literal); - return utility::details::make_unique(); + return utility::make_unique(); } } } GetNextToken(tkn); - if (tkn.m_error) return utility::details::make_unique(); + if (tkn.m_error) return utility::make_unique(); return std::move(result); } template -std::unique_ptr JSON_Parser::_ParseValue(typename JSON_Parser::Token &tkn) +utility::unique_ptr JSON_Parser::_ParseValue(typename JSON_Parser::Token &tkn) { switch (tkn.kind) { @@ -1091,47 +1091,47 @@ std::unique_ptr JSON_Parser::_ParseValue(t } case JSON_Parser::Token::TKN_StringLiteral: { - auto value = utility::details::make_unique(std::move(tkn.string_val), tkn.has_unescape_symbol); + auto value = utility::make_unique(std::move(tkn.string_val), tkn.has_unescape_symbol); GetNextToken(tkn); - if (tkn.m_error) return utility::details::make_unique(); + if (tkn.m_error) return utility::make_unique(); return std::move(value); } case JSON_Parser::Token::TKN_IntegerLiteral: { - std::unique_ptr value; + utility::unique_ptr value; if (tkn.signed_number) - value = utility::details::make_unique(tkn.int64_val); + value = utility::make_unique(tkn.int64_val); else - value = utility::details::make_unique(tkn.uint64_val); + value = utility::make_unique(tkn.uint64_val); GetNextToken(tkn); - if (tkn.m_error) return utility::details::make_unique(); + if (tkn.m_error) return utility::make_unique(); return std::move(value); } case JSON_Parser::Token::TKN_NumberLiteral: { - auto value = utility::details::make_unique(tkn.double_val); + auto value = utility::make_unique(tkn.double_val); GetNextToken(tkn); - if (tkn.m_error) return utility::details::make_unique(); + if (tkn.m_error) return utility::make_unique(); return std::move(value); } case JSON_Parser::Token::TKN_BooleanLiteral: { - auto value = utility::details::make_unique(tkn.boolean_val); + auto value = utility::make_unique(tkn.boolean_val); GetNextToken(tkn); - if (tkn.m_error) return utility::details::make_unique(); + if (tkn.m_error) return utility::make_unique(); return std::move(value); } case JSON_Parser::Token::TKN_NullLiteral: { GetNextToken(tkn); // Returning a null value whether or not an error occurred. - return utility::details::make_unique(); + return utility::make_unique(); } default: { SetErrorCode(tkn, json_error::malformed_token); - return utility::details::make_unique(); + return utility::make_unique(); } } } @@ -1146,13 +1146,13 @@ static web::json::value _parse_stream(utility::istream_t &stream) parser.GetNextToken(tkn); if (tkn.m_error) { - web::json::details::CreateException(tkn, utility::conversions::to_string_t(tkn.m_error.message())); + web::json::details::CreateException(tkn, utility::conversions::to_string_t(tkn.m_error.message().c_str())); } auto value = parser.ParseValue(tkn); if (tkn.m_error) { - web::json::details::CreateException(tkn, utility::conversions::to_string_t(tkn.m_error.message())); + web::json::details::CreateException(tkn, utility::conversions::to_string_t(tkn.m_error.message().c_str())); } else if (tkn.kind != web::json::details::JSON_Parser::Token::TKN_EOF) { @@ -1192,13 +1192,13 @@ static web::json::value _parse_narrow_stream(std::istream &stream) parser.GetNextToken(tkn); if (tkn.m_error) { - web::json::details::CreateException(tkn, utility::conversions::to_string_t(tkn.m_error.message())); + web::json::details::CreateException(tkn, utility::conversions::to_string_t(tkn.m_error.message().c_str())); } auto value = parser.ParseValue(tkn); if (tkn.m_error) { - web::json::details::CreateException(tkn, utility::conversions::to_string_t(tkn.m_error.message())); + web::json::details::CreateException(tkn, utility::conversions::to_string_t(tkn.m_error.message().c_str())); } else if (tkn.kind != web::json::details::JSON_Parser::Token::TKN_EOF) { @@ -1239,13 +1239,13 @@ web::json::value web::json::value::parse(const utility::string_t& str) parser.GetNextToken(tkn); if (tkn.m_error) { - web::json::details::CreateException(tkn, utility::conversions::to_string_t(tkn.m_error.message())); + web::json::details::CreateException(tkn, utility::conversions::to_string_t(tkn.m_error.message().c_str())); } auto value = parser.ParseValue(tkn); if (tkn.m_error) { - web::json::details::CreateException(tkn, utility::conversions::to_string_t(tkn.m_error.message())); + web::json::details::CreateException(tkn, utility::conversions::to_string_t(tkn.m_error.message().c_str())); } else if (tkn.kind != web::json::details::JSON_Parser::Token::TKN_EOF) { diff --git a/Release/src/json/json_serialization.cpp b/Release/src/json/json_serialization.cpp index e5ddbf0776..e0f94882d9 100644 --- a/Release/src/json/json_serialization.cpp +++ b/Release/src/json/json_serialization.cpp @@ -32,11 +32,11 @@ using namespace utility::conversions; void web::json::value::serialize(std::ostream& stream) const { // This has better performance than writing directly to stream. - std::string str; + utility::string str; m_value->serialize_impl(str); stream << str; } -void web::json::value::format(std::basic_string &string) const +void web::json::value::format(utility::wstring &string) const { m_value->format(string); } @@ -54,13 +54,13 @@ void web::json::value::serialize(utility::ostream_t &stream) const stream << str; } -void web::json::value::format(std::basic_string& string) const +void web::json::value::format(utility::string& string) const { m_value->format(string); } template -void web::json::details::append_escape_string(std::basic_string& str, const std::basic_string& escaped) +void web::json::details::append_escape_string(utility::basic_string& str, const utility::basic_string& escaped) { for (const auto &ch : escaped) { @@ -123,7 +123,7 @@ void web::json::details::format_string(const utility::string_t& key, utility::st } #ifdef _WIN32 -void web::json::details::format_string(const utility::string_t& key, std::string& str) +void web::json::details::format_string(const utility::string_t& key, utility::string& str) { str.push_back('"'); append_escape_string(str, utility::conversions::to_utf8string(key)); @@ -131,7 +131,7 @@ void web::json::details::format_string(const utility::string_t& key, std::string } #endif -void web::json::details::_String::format(std::basic_string& str) const +void web::json::details::_String::format(utility::string& str) const { str.push_back('"'); @@ -147,7 +147,7 @@ void web::json::details::_String::format(std::basic_string& str) const str.push_back('"'); } -void web::json::details::_Number::format(std::basic_string& stream) const +void web::json::details::_Number::format(utility::string& stream) const { if(m_number.m_type != number::type::double_type) { @@ -194,7 +194,7 @@ void web::json::details::_Number::format(std::basic_string& stream) const #ifdef _WIN32 -void web::json::details::_String::format(std::basic_string& str) const +void web::json::details::_String::format(utility::wstring& str) const { str.push_back(L'"'); @@ -210,7 +210,7 @@ void web::json::details::_String::format(std::basic_string& str) const str.push_back(L'"'); } -void web::json::details::_Number::format(std::basic_string& stream) const +void web::json::details::_Number::format(utility::wstring& stream) const { if(m_number.m_type != number::type::double_type) { diff --git a/Release/src/pplx/pplx.cpp b/Release/src/pplx/pplx.cpp index 99d00e9ea5..a6748dd82e 100644 --- a/Release/src/pplx/pplx.cpp +++ b/Release/src/pplx/pplx.cpp @@ -91,7 +91,7 @@ static struct _pplx_g_sched_t ::pplx::details::_Scoped_spin_lock lock(m_spinlock); if (!m_scheduler) { - m_scheduler = std::make_shared< ::pplx::default_scheduler_t>(); + m_scheduler = utility::make_shared< ::pplx::default_scheduler_t>(); } } @@ -99,7 +99,7 @@ static struct _pplx_g_sched_t default: // This case means the global m_scheduler is not available. // We spin off an individual scheduler instead. - return std::make_shared< ::pplx::default_scheduler_t>(); + return utility::make_shared< ::pplx::default_scheduler_t>(); } } diff --git a/Release/src/pplx/threadpool.cpp b/Release/src/pplx/threadpool.cpp index d2dc6161a2..d5d9639963 100644 --- a/Release/src/pplx/threadpool.cpp +++ b/Release/src/pplx/threadpool.cpp @@ -42,7 +42,7 @@ struct threadpool_impl final : crossplat::threadpool private: void add_thread() { - m_threads.push_back(std::unique_ptr(new boost::asio::detail::thread([&]{ thread_start(this); }))); + m_threads.push_back(utility::make_unique([&]{ thread_start(this); })); } #if defined(__ANDROID__) @@ -67,7 +67,7 @@ struct threadpool_impl final : crossplat::threadpool return arg; } - std::vector> m_threads; + utility::vector> m_threads; boost::asio::io_service::work m_work; }; } diff --git a/Release/src/streams/fileio_posix.cpp b/Release/src/streams/fileio_posix.cpp index ce166957ce..90a73dce8f 100644 --- a/Release/src/streams/fileio_posix.cpp +++ b/Release/src/streams/fileio_posix.cpp @@ -56,7 +56,7 @@ struct _file_info_impl : _file_info /// /// A list of callback waiting to be signalled that there are no outstanding writes. /// - std::vector<_filestream_callback *> m_sync_waiters; + utility::vector<_filestream_callback *> m_sync_waiters; std::atomic m_outstanding_writes; }; @@ -150,7 +150,7 @@ bool _open_fsb_str(_filestream_callback *callback, const char *filename, std::io { if ( callback == nullptr || filename == nullptr) return false; - std::string name(filename); + utility::string name(filename); pplx::create_task([=]() -> void { diff --git a/Release/src/streams/fileio_win32.cpp b/Release/src/streams/fileio_win32.cpp index a27c74e11f..8860e2c14a 100644 --- a/Release/src/streams/fileio_win32.cpp +++ b/Release/src/streams/fileio_win32.cpp @@ -230,7 +230,7 @@ bool __cdecl _open_fsb_str(_In_ _filestream_callback *callback, const utility::c _ASSERTE(callback != nullptr); _ASSERTE(filename != nullptr); - std::wstring name(filename); + utility::wstring name(filename); pplx::create_task([=]() { @@ -360,7 +360,7 @@ VOID CALLBACK _ReadFileCompletionRoutine(DWORD dwErrorCode, DWORD dwNumberOfByte /// 0 if the write request is still outstanding, -1 if the request failed, otherwise the size of the data written size_t _write_file_async(_In_ streams::details::_file_info_impl *fInfo, _In_ streams::details::_filestream_callback *callback, const void *ptr, size_t count, size_t position) { - auto pOverlapped = std::unique_ptr(new EXTENDED_OVERLAPPED(_WriteFileCompletionRoutine, callback)); + auto pOverlapped = utility::make_unique(_WriteFileCompletionRoutine, callback); if (position == static_cast(-1)) { @@ -454,7 +454,7 @@ size_t _write_file_async(_In_ streams::details::_file_info_impl *fInfo, _In_ str /// 0 if the read request is still outstanding, -1 if the request failed, otherwise the size of the data read into the buffer size_t _read_file_async(_In_ streams::details::_file_info_impl *fInfo, _In_ streams::details::_filestream_callback *callback, _Out_writes_ (count) void *ptr, _In_ size_t count, size_t offset) { - auto pOverlapped = std::unique_ptr(new EXTENDED_OVERLAPPED(_ReadFileCompletionRoutine, callback)); + auto pOverlapped = utility::make_unique(_ReadFileCompletionRoutine, callback); pOverlapped->Offset = static_cast(offset); #ifdef _WIN64 pOverlapped->OffsetHigh = static_cast(offset >> 32); diff --git a/Release/src/uri/uri.cpp b/Release/src/uri/uri.cpp index 737ed12e1b..d6510395fa 100644 --- a/Release/src/uri/uri.cpp +++ b/Release/src/uri/uri.cpp @@ -31,7 +31,7 @@ namespace /// inline bool is_unreserved(int c) { - return ::utility::details::is_alnum((char)c) || c == '-' || c == '.' || c == '_' || c == '~'; + return utility::details::is_alnum((char)c) || c == '-' || c == '.' || c == '_' || c == '~'; } /// @@ -91,7 +91,7 @@ namespace /// inline bool is_scheme_character(int c) { - return ::utility::details::is_alnum((char)c) || c == '+' || c == '-' || c == '.'; + return utility::details::is_alnum((char)c) || c == '+' || c == '-' || c == '.'; } /// @@ -627,9 +627,9 @@ static int hex_char_digit_to_decimal_char(int hex) } template -static std::string decode_template(const String& encoded) +static utility::string decode_template(const String& encoded) { - std::string raw; + utility::string raw; for (auto iter = encoded.begin(); iter != encoded.end(); ++iter) { if (*iter == '%') @@ -665,9 +665,9 @@ utility::string_t uri::decode(const utility::string_t &encoded) return to_string_t(decode_template(encoded)); } -std::vector uri::split_path(const utility::string_t &path) +utility::vector uri::split_path(const utility::string_t &path) { - std::vector results; + utility::vector results; utility::istringstream_t iss(path); iss.imbue(std::locale::classic()); utility::string_t s; @@ -683,9 +683,9 @@ std::vector uri::split_path(const utility::string_t &path) return results; } -std::map uri::split_query(const utility::string_t &query) +utility::map uri::split_query(const utility::string_t &query) { - std::map results; + utility::map results; // Split into key value pairs separated by '&'. size_t prev_amp_index = 0; diff --git a/Release/src/utilities/Resource.rc b/Release/src/utilities/Resource.rc index bb48f87937..001dea393e 100644 Binary files a/Release/src/utilities/Resource.rc and b/Release/src/utilities/Resource.rc differ diff --git a/Release/src/utilities/asyncrt_utils.cpp b/Release/src/utilities/asyncrt_utils.cpp index 3faffd1e40..c8ebadd543 100644 --- a/Release/src/utilities/asyncrt_utils.cpp +++ b/Release/src/utilities/asyncrt_utils.cpp @@ -82,29 +82,29 @@ namespace utility namespace details { -_ASYNCRTIMP bool __cdecl str_iequal(const std::string &left, const std::string &right) CPPREST_NOEXCEPT +_ASYNCRTIMP bool __cdecl str_iequal(const utility::string &left, const utility::string &right) CPPREST_NOEXCEPT { return left.size() == right.size() && std::equal(left.cbegin(), left.cend(), right.cbegin(), eq_lower_ch); } -_ASYNCRTIMP bool __cdecl str_iequal(const std::wstring &left, const std::wstring &right) CPPREST_NOEXCEPT +_ASYNCRTIMP bool __cdecl str_iequal(const utility::wstring &left, const utility::wstring &right) CPPREST_NOEXCEPT { return left.size() == right.size() && std::equal(left.cbegin(), left.cend(), right.cbegin(), eq_lower_ch); } -_ASYNCRTIMP bool __cdecl str_iless(const std::string &left, const std::string &right) CPPREST_NOEXCEPT +_ASYNCRTIMP bool __cdecl str_iless(const utility::string &left, const utility::string &right) CPPREST_NOEXCEPT { return std::lexicographical_compare(left.cbegin(), left.cend(), right.cbegin(), right.cend(), lt_lower_ch); } -_ASYNCRTIMP bool __cdecl str_iless(const std::wstring &left, const std::wstring &right) CPPREST_NOEXCEPT +_ASYNCRTIMP bool __cdecl str_iless(const utility::wstring &left, const utility::wstring &right) CPPREST_NOEXCEPT { return std::lexicographical_compare(left.cbegin(), left.cend(), right.cbegin(), right.cend(), lt_lower_ch); } -_ASYNCRTIMP void __cdecl inplace_tolower(std::string &target) CPPREST_NOEXCEPT +_ASYNCRTIMP void __cdecl inplace_tolower(utility::string &target) CPPREST_NOEXCEPT { for (auto& ch : target) { @@ -112,7 +112,7 @@ _ASYNCRTIMP void __cdecl inplace_tolower(std::string &target) CPPREST_NOEXCEPT } } -_ASYNCRTIMP void __cdecl inplace_tolower(std::wstring &target) CPPREST_NOEXCEPT +_ASYNCRTIMP void __cdecl inplace_tolower(utility::wstring &target) CPPREST_NOEXCEPT { for (auto& ch : target) { @@ -122,7 +122,7 @@ _ASYNCRTIMP void __cdecl inplace_tolower(std::wstring &target) CPPREST_NOEXCEPT #if !defined(ANDROID) && !defined(__ANDROID__) std::once_flag g_c_localeFlag; -std::unique_ptr g_c_locale(nullptr, [](scoped_c_thread_locale::xplat_locale *){}); +utility::unique_ptr g_c_locale(nullptr, [](scoped_c_thread_locale::xplat_locale *){}); scoped_c_thread_locale::xplat_locale scoped_c_thread_locale::c_locale() { std::call_once(g_c_localeFlag, [&]() @@ -151,7 +151,7 @@ scoped_c_thread_locale::xplat_locale scoped_c_thread_locale::c_locale() delete clocale; }; #endif - g_c_locale = std::unique_ptr(clocale, deleter); + g_c_locale = utility::unique_ptr(clocale, deleter); }); return *g_c_locale; } @@ -264,7 +264,7 @@ std::string windows_category_impl::message(int errorCode) const CPPREST_NOEXCEPT } #endif - std::wstring buffer; + utility::wstring buffer; buffer.resize(buffer_size); const auto result = ::FormatMessageW( @@ -282,14 +282,14 @@ std::string windows_category_impl::message(int errorCode) const CPPREST_NOEXCEPT return os.str(); } - return utility::conversions::to_utf8string(buffer); + return std::string(utility::conversions::to_utf8string(buffer).c_str()); } std::error_condition windows_category_impl::default_error_condition(int errorCode) const CPPREST_NOEXCEPT { // First see if the STL implementation can handle the mapping for common cases. const std::error_condition errCondition = std::system_category().default_error_condition(errorCode); - const std::string errConditionMsg = errCondition.message(); + const utility::string errConditionMsg = errCondition.message().c_str(); if(!utility::details::str_iequal(errConditionMsg, "unknown error")) { return errCondition; @@ -347,7 +347,7 @@ const std::error_category & __cdecl linux_category() #define H_SURROGATE_END 0xDBFF #define SURROGATE_PAIR_START 0x10000 -inline size_t count_utf8_to_utf16(const std::string& s) +inline size_t count_utf8_to_utf16(const utility::string& s) { const size_t sSize = s.size(); const char* const sData = s.data(); @@ -423,18 +423,18 @@ inline size_t count_utf8_to_utf16(const std::string& s) return result; } -utf16string __cdecl conversions::utf8_to_utf16(const std::string &s) +utf16string __cdecl conversions::utf8_to_utf16(const utility::string &s) { // Save repeated heap allocations, use the length of resulting sequence. const size_t srcSize = s.size(); - const std::string::value_type* const srcData = &s[0]; + const utility::string::value_type* const srcData = &s[0]; utf16string dest(count_utf8_to_utf16(s), L'\0'); utf16string::value_type* const destData = &dest[0]; size_t destIndex = 0; for (size_t index = 0; index < srcSize; ++index) { - std::string::value_type src = srcData[index]; + utility::string::value_type src = srcData[index]; switch (src & 0xF0) { case 0xF0: // 4 byte character, 0x10000 to 0x10FFFF @@ -525,12 +525,12 @@ inline size_t count_utf16_to_utf8(const utf16string &w) return destSize; } -std::string __cdecl conversions::utf16_to_utf8(const utf16string &w) +utility::string __cdecl conversions::utf16_to_utf8(const utf16string &w) { const size_t srcSize = w.size(); const utf16string::value_type* const srcData = &w[0]; - std::string dest(count_utf16_to_utf8(w), '\0'); - std::string::value_type* const destData = &dest[0]; + utility::string dest(count_utf16_to_utf8(w), '\0'); + utility::string::value_type* const destData = &dest[0]; size_t destIndex(0); for (size_t index = 0; index < srcSize; ++index) @@ -581,13 +581,13 @@ std::string __cdecl conversions::utf16_to_utf8(const utf16string &w) return dest; } -utf16string __cdecl conversions::usascii_to_utf16(const std::string &s) +utf16string __cdecl conversions::usascii_to_utf16(const utility::string &s) { // Ascii is a subset of UTF-8 so just convert to UTF-16 return utf8_to_utf16(s); } -utf16string __cdecl conversions::latin1_to_utf16(const std::string &s) +utf16string __cdecl conversions::latin1_to_utf16(const utility::string &s) { // Latin1 is the first 256 code points in Unicode. // In UTF-16 encoding each of these is represented as exactly the numeric code point. @@ -600,7 +600,7 @@ utf16string __cdecl conversions::latin1_to_utf16(const std::string &s) return dest; } -utf8string __cdecl conversions::latin1_to_utf8(const std::string &s) +utf8string __cdecl conversions::latin1_to_utf8(const utility::string &s) { return utf16_to_utf8(latin1_to_utf16(s)); } @@ -613,7 +613,7 @@ utility::string_t __cdecl conversions::to_string_t(utf16string &&s) #endif #ifdef _UTF16_STRINGS -utility::string_t __cdecl conversions::to_string_t(std::string &&s) +utility::string_t __cdecl conversions::to_string_t(utility::string &&s) { return utf8_to_utf16(std::move(s)); } @@ -627,15 +627,15 @@ utility::string_t __cdecl conversions::to_string_t(const utf16string &s) #endif #ifdef _UTF16_STRINGS -utility::string_t __cdecl conversions::to_string_t(const std::string &s) +utility::string_t __cdecl conversions::to_string_t(const utility::string &s) { return utf8_to_utf16(s); } #endif -std::string __cdecl conversions::to_utf8string(const utf16string &value) { return utf16_to_utf8(value); } +utility::string __cdecl conversions::to_utf8string(const utf16string &value) { return utf16_to_utf8(value); } -utf16string __cdecl conversions::to_utf16string(const std::string &value) { return utf8_to_utf16(value); } +utf16string __cdecl conversions::to_utf16string(const utility::string &value) { return utf8_to_utf16(value); } #ifndef WIN32 datetime datetime::timeval_to_datetime(const timeval &time) @@ -686,7 +686,7 @@ utility::string_t datetime::to_string(date_format format) const throw utility::details::create_system_error(GetLastError()); } - std::wostringstream outStream; + utility::wostringstream outStream; outStream.imbue(std::locale::classic()); if (format == RFC_1123) @@ -794,7 +794,7 @@ utility::string_t datetime::to_string(date_format format) const &datetime); } - return std::string(output); + return utility::string(output); #endif } @@ -873,8 +873,8 @@ datetime __cdecl datetime::from_string(const utility::string_t& dateString, date { SYSTEMTIME sysTime = {0}; - std::wstring month(3, L'\0'); - std::wstring unused(3, L'\0'); + utility::wstring month(3, L'\0'); + utility::wstring unused(3, L'\0'); const wchar_t * formatString = L"%3c, %2d %3c %4d %2d:%2d:%2d %3c"; auto n = swscanf_s(dateString.c_str(), formatString, @@ -889,8 +889,8 @@ datetime __cdecl datetime::from_string(const utility::string_t& dateString, date if (n == 8) { - std::wstring monthnames[12] = {L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"}; - auto loc = std::find_if(monthnames, monthnames+12, [&month](const std::wstring& m) { return m == month;}); + utility::wstring monthnames[12] = {L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"}; + auto loc = std::find_if(monthnames, monthnames+12, [&month](const utility::wstring& m) { return m == month;}); if (loc != monthnames+12) { @@ -978,7 +978,7 @@ datetime __cdecl datetime::from_string(const utility::string_t& dateString, date return datetime(); #else - std::string input(dateString); + utility::string input(dateString); struct tm output = tm(); @@ -1037,7 +1037,7 @@ datetime __cdecl datetime::from_string(const utility::string_t& dateString, date static boost::mutex env_var_lock; { boost::lock_guard lock(env_var_lock); - std::string prev_env; + utility::string prev_env; auto prev_env_cstr = getenv("TZ"); if (prev_env_cstr != nullptr) { diff --git a/Release/src/utilities/base64.cpp b/Release/src/utilities/base64.cpp index 8e29289deb..44e4fe6102 100644 --- a/Release/src/utilities/base64.cpp +++ b/Release/src/utilities/base64.cpp @@ -13,15 +13,15 @@ using namespace web; using namespace utility; -std::vector _from_base64(const utility::string_t& str); +utility::vector _from_base64(const utility::string_t& str); utility::string_t _to_base64(const unsigned char *ptr, size_t size); -std::vector __cdecl conversions::from_base64(const utility::string_t& str) +utility::vector __cdecl conversions::from_base64(const utility::string_t& str) { return _from_base64(str); } -utility::string_t __cdecl conversions::to_base64(const std::vector& input) +utility::string_t __cdecl conversions::to_base64(const utility::vector& input) { if (input.size() == 0) { @@ -84,9 +84,9 @@ struct _single_byte // gcc is concerned about the bitfield uses in the code, something we simply need to ignore. #pragma GCC diagnostic ignored "-Wconversion" #endif -std::vector _from_base64(const utility::string_t& input) +utility::vector _from_base64(const utility::string_t& input) { - std::vector result; + utility::vector result; if ( input.empty() ) return result; diff --git a/Release/src/utilities/web_utilities.cpp b/Release/src/utilities/web_utilities.cpp index f17b5ab099..26fc2c7c2c 100644 --- a/Release/src/utilities/web_utilities.cpp +++ b/Release/src/utilities/web_utilities.cpp @@ -44,14 +44,14 @@ void winrt_secure_zero_buffer(Windows::Storage::Streams::IBuffer ^buffer) } } -winrt_encryption::winrt_encryption(const std::wstring &data) +winrt_encryption::winrt_encryption(const utility::wstring &data) { auto provider = ref new Windows::Security::Cryptography::DataProtection::DataProtectionProvider(ref new Platform::String(L"Local=user")); // Create buffer containing plain text password. Platform::ArrayReference arrayref( - reinterpret_cast(const_cast(data.c_str())), - static_cast(data.size()) * sizeof(std::wstring::value_type)); + reinterpret_cast(const_cast(data.c_str())), + static_cast(data.size()) * sizeof(utility::wstring::value_type)); Windows::Storage::Streams::IBuffer ^plaintext = Windows::Security::Cryptography::CryptographicBuffer::CreateFromByteArray(arrayref); m_buffer = pplx::create_task(provider->ProtectAsync(plaintext)); m_buffer.then([plaintext](pplx::task) @@ -60,7 +60,7 @@ winrt_encryption::winrt_encryption(const std::wstring &data) }); } -plaintext_string winrt_encryption::decrypt() const +utility::secure_unique_wstring winrt_encryption::decrypt() const { // To fully guarantee asynchrony would require significant impact on existing code. This code path // is never run on a user's thread and is only done once when setting up a connection. @@ -76,12 +76,12 @@ plaintext_string winrt_encryption::decrypt() const const auto &result = bufferByteAccess->Buffer(&rawPlaintext); if (result != S_OK) { - throw ::utility::details::create_system_error(result); + throw utility::details::create_system_error(result); } // Construct string and zero out memory from plain text buffer. - auto data = plaintext_string(new std::wstring( - reinterpret_cast(rawPlaintext), + auto data = utility::make_unique>( + reinterpret_cast(rawPlaintext), plaintext->Length / 2)); SecureZeroMemory(rawPlaintext, plaintext->Length); return std::move(data); @@ -89,28 +89,22 @@ plaintext_string winrt_encryption::decrypt() const #else -win32_encryption::win32_encryption(const std::wstring &data) : +win32_encryption::win32_encryption(const utility::secure_wstring &data) : m_numCharacters(data.size()) { - // Early return because CryptProtectMemory crashs with empty string + // Early return because CryptProtectMemory crashes with empty string if (m_numCharacters == 0) { return; } - const auto dataNumBytes = data.size() * sizeof(std::wstring::value_type); - m_buffer.resize(dataNumBytes); - memcpy_s(m_buffer.data(), m_buffer.size(), data.c_str(), dataNumBytes); - // Buffer must be a multiple of CRYPTPROTECTMEMORY_BLOCK_SIZE - const auto mod = m_buffer.size() % CRYPTPROTECTMEMORY_BLOCK_SIZE; - if (mod != 0) - { - m_buffer.resize(m_buffer.size() + CRYPTPROTECTMEMORY_BLOCK_SIZE - mod); - } - if (!CryptProtectMemory(m_buffer.data(), static_cast(m_buffer.size()), CRYPTPROTECTMEMORY_SAME_PROCESS)) + m_buffer.resize(m_numCharacters + CRYPTPROTECTMEMORY_BLOCK_SIZE - (m_numCharacters % CRYPTPROTECTMEMORY_BLOCK_SIZE)); + memcpy_s(m_buffer.data(), m_buffer.size(), data.c_str(), m_numCharacters); + + if (!CryptProtectMemory(m_buffer.data(), static_cast(m_buffer.size() * sizeof(utility::vector>::value_type)), CRYPTPROTECTMEMORY_SAME_PROCESS)) { - throw ::utility::details::create_system_error(GetLastError()); + throw utility::details::create_system_error(GetLastError()); } } @@ -119,36 +113,25 @@ win32_encryption::~win32_encryption() SecureZeroMemory(m_buffer.data(), m_buffer.size()); } -plaintext_string win32_encryption::decrypt() const +utility::secure_unique_wstring win32_encryption::decrypt() const { if (m_buffer.empty()) - return plaintext_string(new std::wstring()); + return utility::make_unique>(); // Copy the buffer and decrypt to avoid having to re-encrypt. - auto data = plaintext_string(new std::wstring(reinterpret_cast(m_buffer.data()), m_buffer.size() / 2)); + auto data = utility::make_unique>(reinterpret_cast(m_buffer.data()), m_buffer.size()); if (!CryptUnprotectMemory( - const_cast(data->c_str()), - static_cast(m_buffer.size()), + const_cast(data->c_str()), + static_cast(m_buffer.size() * sizeof(utility::secure_wstring::value_type)), CRYPTPROTECTMEMORY_SAME_PROCESS)) { - throw ::utility::details::create_system_error(GetLastError()); + throw utility::details::create_system_error(GetLastError()); } data->resize(m_numCharacters); return std::move(data); } #endif #endif - -void zero_memory_deleter::operator()(::utility::string_t *data) const -{ - CASABLANCA_UNREFERENCED_PARAMETER(data); -#if defined(_WIN32) - SecureZeroMemory( - const_cast<::utility::string_t::value_type *>(data->data()), - data->size() * sizeof(::utility::string_t::value_type)); - delete data; -#endif -} } } \ No newline at end of file diff --git a/Release/src/websockets/client/ws_client_impl.h b/Release/src/websockets/client/ws_client_impl.h index 2cd824d24a..338433d815 100644 --- a/Release/src/websockets/client/ws_client_impl.h +++ b/Release/src/websockets/client/ws_client_impl.h @@ -51,7 +51,7 @@ struct outgoing_msg_queue private: std::mutex m_lock; - std::queue m_queue; + utility::queue m_queue; }; diff --git a/Release/src/websockets/client/ws_client_winrt.cpp b/Release/src/websockets/client/ws_client_winrt.cpp index 38b4f7989d..312648a4be 100644 --- a/Release/src/websockets/client/ws_client_winrt.cpp +++ b/Release/src/websockets/client/ws_client_winrt.cpp @@ -95,7 +95,7 @@ class winrt_callback_client : public websocket_client_callback_impl, public std: // Add any specified subprotocols. if (headers.has(protocolHeader)) { - const std::vector protocols = m_config.subprotocols(); + const utility::vector protocols = m_config.subprotocols(); for (const auto & value : protocols) { m_msg_websocket->Control->SupportedProtocols->Append(Platform::StringReference(value.c_str())); @@ -269,7 +269,7 @@ class winrt_callback_client : public websocket_client_callback_impl, public std: { // The stream needs to be buffered. auto is_buf_istream = is_buf.create_istream(); - msg.m_body = concurrency::streams::container_buffer>(); + msg.m_body = concurrency::streams::container_buffer>(); is_buf_istream.read_to_end(msg.m_body).then([this_client, msg](pplx::task t) mutable { try @@ -465,7 +465,7 @@ void ReceiveContext::OnClosed(IWebSocket^ sender, WebSocketClosedEventArgs^ args } websocket_client_task_impl::websocket_client_task_impl(websocket_client_config config) : - m_callback_client(std::make_shared(std::move(config))), + m_callback_client(utility::make_shared(std::move(config))), m_client_closed(false) { set_handler(); @@ -473,11 +473,11 @@ websocket_client_task_impl::websocket_client_task_impl(websocket_client_config c } websocket_callback_client::websocket_callback_client() : - m_client(std::make_shared(websocket_client_config())) + m_client(utility::make_shared(websocket_client_config())) {} websocket_callback_client::websocket_callback_client(websocket_client_config config) : - m_client(std::make_shared(std::move(config))) + m_client(utility::make_shared(std::move(config))) {} }}} diff --git a/Release/src/websockets/client/ws_client_wspp.cpp b/Release/src/websockets/client/ws_client_wspp.cpp index 39b7121d57..2b3e0fbc2e 100644 --- a/Release/src/websockets/client/ws_client_wspp.cpp +++ b/Release/src/websockets/client/ws_client_wspp.cpp @@ -95,9 +95,9 @@ namespace details { // Utility function to build up error string based on error code and location. -static std::string build_error_msg(const std::error_code &ec, const std::string &location) +static utility::string build_error_msg(const std::error_code &ec, const utility::string &location) { - std::stringstream ss; + utility::stringstream ss; ss.imbue(std::locale::classic()); ss << location << ": " << ec.value() @@ -170,13 +170,13 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: { if (m_uri.scheme() == U("wss")) { - m_client = std::unique_ptr(new websocketpp_tls_client()); + m_client = utility::make_unique(); // Options specific to TLS client. auto &client = m_client->client(); client.set_tls_init_handler([this](websocketpp::connection_hdl) { - auto sslContext = websocketpp::lib::shared_ptr(new boost::asio::ssl::context(boost::asio::ssl::context::sslv23)); + auto sslContext = utility::make_shared(boost::asio::ssl::context::sslv23); sslContext->set_default_verify_paths(); sslContext->set_options(boost::asio::ssl::context::default_workarounds); if (m_config.validate_certificates()) @@ -207,7 +207,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: return http::client::details::verify_cert_chain_platform_specific(verifyCtx, utility::conversions::to_utf8string(m_uri.host())); } #endif - boost::asio::ssl::rfc2818_verification rfc2818(utility::conversions::to_utf8string(m_uri.host())); + boost::asio::ssl::rfc2818_verification rfc2818(utility::conversions::to_utf8string(m_uri.host()).c_str()); return rfc2818(preverified, verifyCtx); }); @@ -249,7 +249,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: } else { - m_client = std::unique_ptr(new websocketpp_client()); + m_client = utility::make_unique(); return connect_impl(); } } @@ -300,8 +300,8 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: } // 'move' the payload into a container buffer to avoid any copies. - auto &payload = msg->get_raw_payload(); - incoming_msg.m_body = concurrency::streams::container_buffer(std::move(payload)); + auto payload = utility::string(msg->get_raw_payload().c_str()); + incoming_msg.m_body = concurrency::streams::container_buffer(std::move(payload)); m_external_message_handler(incoming_msg); } @@ -319,13 +319,13 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: auto user_agent_it = headers.find(web::http::header_names::user_agent); if (user_agent_it != headers.end()) { - client.set_user_agent(utility::conversions::to_utf8string(user_agent_it->second)); + client.set_user_agent(utility::conversions::to_utf8string(user_agent_it->second).c_str()); } // Get the connection handle to save for later, have to create temporary // because type erasure occurs with connection_hdl. websocketpp::lib::error_code ec; - auto con = client.get_connection(utility::conversions::to_utf8string(m_uri.to_string()), ec); + auto con = client.get_connection(utility::conversions::to_utf8string(m_uri.to_string()).c_str(), ec); m_con = con; if (ec.value() != 0) { @@ -337,17 +337,17 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: { if (!utility::details::str_iequal(header.first, g_subProtocolHeader)) { - con->append_header(utility::conversions::to_utf8string(header.first), utility::conversions::to_utf8string(header.second)); + con->append_header(utility::conversions::to_utf8string(header.first).c_str(), utility::conversions::to_utf8string(header.second).c_str()); } } // Add any specified subprotocols. if (headers.has(g_subProtocolHeader)) { - const std::vector protocols = m_config.subprotocols(); + const utility::vector protocols = m_config.subprotocols(); for (const auto & value : protocols) { - con->add_subprotocol(utility::conversions::to_utf8string(value), ec); + con->add_subprotocol(utility::conversions::to_utf8string(value).c_str(), ec); if (ec.value()) { return pplx::task_from_exception(websocket_exception(ec, build_error_msg(ec, "add_subprotocol"))); @@ -359,7 +359,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: const auto &proxy = m_config.proxy(); if (proxy.is_specified()) { - con->set_proxy(utility::conversions::to_utf8string(proxy.address().to_string()), ec); + con->set_proxy(utility::conversions::to_utf8string(proxy.address().to_string()).c_str(), ec); if (ec) { return pplx::task_from_exception(websocket_exception(ec, build_error_msg(ec, "set_proxy"))); @@ -369,8 +369,8 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: if (cred.is_set()) { con->set_proxy_basic_auth( - utility::conversions::to_utf8string(cred.username()), - utility::conversions::to_utf8string(*cred._internal_decrypt()), + utility::conversions::to_utf8string(cred.username()).c_str(), + utility::conversions::to_utf8string(cred._internal_decrypt()->c_str()).c_str(), ec); if (ec) { @@ -467,7 +467,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: { // The stream needs to be buffered. auto is_buf_istream = is_buf.create_istream(); - msg.m_body = concurrency::streams::container_buffer>(); + msg.m_body = concurrency::streams::container_buffer>(); is_buf_istream.read_to_end(msg.m_body).then([this_client, msg](pplx::task t) mutable { try @@ -644,7 +644,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: } if (m_external_close_handler) { - m_external_close_handler(static_cast(closeCode), utility::conversions::to_string_t(reason), ec); + m_external_close_handler(static_cast(closeCode), utility::conversions::to_string_t(reason.c_str()).c_str(), ec); } // Making a local copy of the TCE prevents it from being destroyed along with "this" auto tceref = m_close_tce; @@ -695,7 +695,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: void close_impl(websocket_close_status status, const utility::string_t& reason, websocketpp::lib::error_code &ec) { auto &client = m_client->client(); - client.close(m_con, static_cast(status), utility::conversions::to_utf8string(reason), ec); + client.close(m_con, static_cast(status), utility::conversions::to_utf8string(reason).c_str(), ec); } void set_message_handler(const std::function& handler) @@ -766,7 +766,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: // Used to safe guard the wspp client. std::mutex m_wspp_client_lock; State m_state; - std::unique_ptr m_client; + utility::unique_ptr m_client; // Queue to track pending sends outgoing_msg_queue m_out_queue; @@ -786,18 +786,18 @@ class wspp_callback_client : public websocket_client_callback_impl, public std:: websocket_client_task_impl::websocket_client_task_impl(websocket_client_config config) : m_client_closed(false), - m_callback_client(std::make_shared(std::move(config))) + m_callback_client(utility::make_shared(std::move(config))) { set_handler(); } } websocket_callback_client::websocket_callback_client() : - m_client(std::make_shared(websocket_client_config())) + m_client(utility::make_shared(websocket_client_config())) {} websocket_callback_client::websocket_callback_client(websocket_client_config config) : - m_client(std::make_shared(std::move(config))) + m_client(utility::make_shared(std::move(config))) {} }}} diff --git a/Release/src/websockets/client/ws_msg.cpp b/Release/src/websockets/client/ws_msg.cpp index 1d24409c67..da8e1d8149 100644 --- a/Release/src/websockets/client/ws_msg.cpp +++ b/Release/src/websockets/client/ws_msg.cpp @@ -27,21 +27,21 @@ namespace websockets namespace client { -static ::utility::string_t g_subProtocolHeader = _XPLATSTR("Sec-WebSocket-Protocol"); +static utility::string_t g_subProtocolHeader = _XPLATSTR("Sec-WebSocket-Protocol"); void websocket_client_config::set_user_agent(const utf8string &user_agent) { headers().add(web::http::header_names::user_agent, utility::conversions::to_string_t(user_agent)); } -void websocket_client_config::add_subprotocol(const ::utility::string_t &name) +void websocket_client_config::add_subprotocol(const utility::string_t &name) { m_headers.add(g_subProtocolHeader, name); } -std::vector<::utility::string_t> websocket_client_config::subprotocols() const +utility::vector websocket_client_config::subprotocols() const { - std::vector<::utility::string_t> values; + utility::vector values; auto subprotocolHeader = m_headers.find(g_subProtocolHeader); if (subprotocolHeader != m_headers.end()) { @@ -59,11 +59,11 @@ std::vector<::utility::string_t> websocket_client_config::subprotocols() const return values; } -pplx::task websocket_incoming_message::extract_string() const +pplx::task websocket_incoming_message::extract_string() const { if (m_msg_type == websocket_message_type::binary_message) { - return pplx::task_from_exception(websocket_exception("Invalid message type")); + return pplx::task_from_exception(websocket_exception("Invalid message type")); } return pplx::task_from_result(std::move(m_body.collection())); }