From b2dd543ae48943d08dcd43aa591e884ac5eb9d33 Mon Sep 17 00:00:00 2001 From: Artur Laksberg Date: Thu, 10 Oct 2013 10:48:22 -0700 Subject: [PATCH 1/3] Tweak BJ client --- .../Samples/BlackJack/BlackJack_Client/BlackJackClient.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Release/collateral/Samples/BlackJack/BlackJack_Client/BlackJackClient.cpp b/Release/collateral/Samples/BlackJack/BlackJack_Client/BlackJackClient.cpp index 706ae94516..0975cb1c54 100644 --- a/Release/collateral/Samples/BlackJack/BlackJack_Client/BlackJackClient.cpp +++ b/Release/collateral/Samples/BlackJack/BlackJack_Client/BlackJackClient.cpp @@ -127,7 +127,8 @@ void PrintTable(const http_response &response, bool &refresh) if ( suppressMoney ) ucout << "'" << name.as_string() << "'" ; else - fprintf(stdout, "'%s' Balance = $%02g ", name.as_string().c_str(), bet.as_double()); + ucout << "'" << name.as_string() << "' Balance = $" << bet.as_double() << " "; + PrintHand(suppressMoney, BJHand::FromJSON(player[HAND])); ucout << std::endl; } From 86f8be6f24a4a153861d0f31b8abc818b7566979 Mon Sep 17 00:00:00 2001 From: Artur Laksberg Date: Thu, 10 Oct 2013 10:48:56 -0700 Subject: [PATCH 2/3] Expose native_handle in http_client --- Release/include/cpprest/http_client.h | 50 ++++++++++++ Release/src/http/client/http_win7.cpp | 11 +++ Release/src/http/client/http_win8.cpp | 24 ++++-- .../client/VS11/HttpClient110_test.vcxproj | 6 ++ .../client/VS12/HttpClient120_test.vcxproj | 6 ++ .../http/client/authentication_tests.cpp | 81 +++++++++++++++++++ 6 files changed, 172 insertions(+), 6 deletions(-) diff --git a/Release/include/cpprest/http_client.h b/Release/include/cpprest/http_client.h index e312b974b8..20f4dd0ac0 100644 --- a/Release/include/cpprest/http_client.h +++ b/Release/include/cpprest/http_client.h @@ -29,6 +29,16 @@ #ifndef _CASA_HTTP_CLIENT_H #define _CASA_HTTP_CLIENT_H +#if defined (__cplusplus_winrt) +#define __WRL_NO_DEFAULT_LIB__ +#include +#include +namespace web { namespace http{namespace client{ +typedef IXMLHTTPRequest2* native_handle;}}} +#else +namespace web { namespace http{namespace client{ +typedef void* native_handle;}}} +#endif // __cplusplus_winrt #include #include @@ -53,6 +63,16 @@ namespace web { namespace http namespace client { +#ifdef _MS_WINDOWS +namespace details { +#ifdef __cplusplus_winrt + class winrt_client ; +#else + class winhttp_client; +#endif // __cplusplus_winrt +} +#endif // _MS_WINDOWS + /// /// credentials represents a set of user credentials (username and password) to be used /// for the client and proxy authentication @@ -130,6 +150,7 @@ class http_client_config #if !defined(__cplusplus_winrt) , m_validate_certificates(true) #endif + ,m_set_user_nativehandle_options([](native_handle)->void{}) { } @@ -245,6 +266,15 @@ class http_client_config } #endif + /// + /// Sets a callback to enable custom setting of winhttp options + /// + /// A user callback allowing for customization of the request + void set_nativehandle_options(std::function callback) + { + m_set_user_nativehandle_options = callback; + } + private: web_proxy m_proxy; http::client::credentials m_credentials; @@ -255,9 +285,29 @@ class http_client_config #if !defined(__cplusplus_winrt) bool m_validate_certificates; #endif + std::function m_set_user_nativehandle_options; utility::seconds m_timeout; size_t m_chunksize; + +#ifdef _MS_WINDOWS +#ifdef __cplusplus_winrt + friend class details::winrt_client; +#else + friend class details::winhttp_client; +#endif // __cplusplus_winrt +#endif // _MS_WINDOWS + + + /// + /// Invokes a user callback to allow for customization of the requst + /// + /// The internal http_request handle + /// True if users set WinHttp/IXAMLHttpRequest2 options correctly, false otherwise. + void call_user_nativehandle_options(native_handle handle) const + { + m_set_user_nativehandle_options(handle); + } }; /// diff --git a/Release/src/http/client/http_win7.cpp b/Release/src/http/client/http_win7.cpp index 6d19fb8b23..2855bee4e7 100644 --- a/Release/src/http/client/http_win7.cpp +++ b/Release/src/http/client/http_win7.cpp @@ -644,6 +644,17 @@ namespace web { namespace http winhttp_context->m_request_data = &m_request_data; + //call the callback function of user customized options + try + { + client_config().call_user_nativehandle_options(winhttp_context->m_request_handle); + } + catch (...) + { + request->report_exception(std::current_exception()); + return; + } + _start_request_send(winhttp_context, content_length); return; diff --git a/Release/src/http/client/http_win8.cpp b/Release/src/http/client/http_win8.cpp index 269c437976..7fc8db21b9 100644 --- a/Release/src/http/client/http_win8.cpp +++ b/Release/src/http/client/http_win8.cpp @@ -77,15 +77,15 @@ namespace web { namespace http // Do not read more than the specified read_length msl::utilities::SafeInt safe_count = static_cast(cb); size_t size_to_read = safe_count.Min(m_read_length); - + size_t count = m_buffer.getn((uint8_t *)pv, size_to_read).get(); - + if (count == 0 && size_to_read != 0) { *pcbRead = (ULONG)count; return (HRESULT)STG_E_READFAULT; } - + _ASSERTE(count != static_cast(-1)); if (pcbRead != nullptr) @@ -162,7 +162,7 @@ namespace web { namespace http private: concurrency::streams::streambuf m_buffer; - + request_context *m_request; // Total count of bytes read @@ -303,7 +303,7 @@ namespace web { namespace http { IXMLHTTPRequest2 * req = m_request->m_hRequest; if ( req != nullptr ) req->AddRef(); - + if (m_request->m_exceptionPtr != nullptr) m_request->report_exception(m_request->m_exceptionPtr); else @@ -363,7 +363,7 @@ namespace web { namespace http request->report_error(L"The method string is invalid."); return; } - + if ( msg.method() == http::methods::TRCE ) { // Not supported by WinInet. Generate a more specific exception than what WinInet does. @@ -490,6 +490,18 @@ namespace web { namespace http return; } + //call the callback function of user customized options + try + { + config.call_user_nativehandle_options(xhr); + } + catch (...) + { + request->report_exception(std::current_exception()); + xhr->Release(); + return; + } + if (content_length == 0) { hr = xhr->Send(nullptr, 0); diff --git a/Release/tests/Functional/http/client/VS11/HttpClient110_test.vcxproj b/Release/tests/Functional/http/client/VS11/HttpClient110_test.vcxproj index 8d5fee8798..14fe0371b4 100644 --- a/Release/tests/Functional/http/client/VS11/HttpClient110_test.vcxproj +++ b/Release/tests/Functional/http/client/VS11/HttpClient110_test.vcxproj @@ -89,6 +89,7 @@ Windows true $(OutDir);%(AdditionalLibraryDirectories) + Winhttp.lib;httpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -103,6 +104,7 @@ Windows true $(OutDir);%(AdditionalLibraryDirectories) + Winhttp.lib;httpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -117,6 +119,7 @@ Windows true $(OutDir);%(AdditionalLibraryDirectories) + Winhttp.lib;httpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -135,6 +138,7 @@ true true $(OutDir);%(AdditionalLibraryDirectories) + Winhttp.lib;httpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -153,6 +157,7 @@ true true $(OutDir);%(AdditionalLibraryDirectories) + Winhttp.lib;httpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -171,6 +176,7 @@ true true $(OutDir);%(AdditionalLibraryDirectories) + Winhttp.lib;httpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) diff --git a/Release/tests/Functional/http/client/VS12/HttpClient120_test.vcxproj b/Release/tests/Functional/http/client/VS12/HttpClient120_test.vcxproj index b291c0a505..4f136d4695 100644 --- a/Release/tests/Functional/http/client/VS12/HttpClient120_test.vcxproj +++ b/Release/tests/Functional/http/client/VS12/HttpClient120_test.vcxproj @@ -103,6 +103,7 @@ Windows true $(OutDir);%(AdditionalLibraryDirectories) + Winhttp.lib;httpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -116,6 +117,7 @@ Windows true $(OutDir);%(AdditionalLibraryDirectories) + Winhttp.lib;httpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -129,6 +131,7 @@ Windows true $(OutDir);%(AdditionalLibraryDirectories) + Winhttp.lib;httpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -146,6 +149,7 @@ true true $(OutDir);%(AdditionalLibraryDirectories) + Winhttp.lib;httpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -163,6 +167,7 @@ true true $(OutDir);%(AdditionalLibraryDirectories) + Winhttp.lib;httpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -180,6 +185,7 @@ true true $(OutDir);%(AdditionalLibraryDirectories) + Winhttp.lib;httpapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) diff --git a/Release/tests/Functional/http/client/authentication_tests.cpp b/Release/tests/Functional/http/client/authentication_tests.cpp index 1b57187154..91893c0d2d 100644 --- a/Release/tests/Functional/http/client/authentication_tests.cpp +++ b/Release/tests/Functional/http/client/authentication_tests.cpp @@ -24,6 +24,18 @@ ****/ #include "stdafx.h" +#include + +#ifdef _MS_WINDOWS +#ifdef __cplusplus_winrt +#define __WRL_NO_DEFAULT_LIB__ +#include +#include +#else +#include +#include +#endif +#endif using namespace web; using namespace utility; @@ -409,6 +421,75 @@ TEST_FIXTURE(server_properties, failed_authentication_resend_request_error, "Req VERIFY_ARE_EQUAL(200, response.status_code()); } +#ifdef __cplusplus_winrt +TEST_FIXTURE(uri_address, set_user_options_winrt) +{ + test_http_server::scoped_server scoped(m_uri); + scoped.server()->next_request().then([](test_request *p_request) + { + p_request->reply(status_codes::OK); + }); + + http_client_config config; + config.set_nativehandle_options([](native_handle handle)->void{ + auto hr = handle->SetProperty(XHR_PROP_TIMEOUT, 1000); + if(!SUCCEEDED(hr)) + throw std::runtime_error("The Test Exception"); + }); + http_client client(m_uri, config); + auto response = client.request(methods::GET).get(); + VERIFY_ARE_EQUAL(200, response.status_code()); +} +#endif // __cplusplus_winrt + +#ifdef _MS_WINDOWS +#if !defined(__cplusplus_winrt) +TEST_FIXTURE(server_properties, set_user_options, "Requires", "Server;UserName;Password") +{ + load_parameters(); + + http_client_config config; + config.set_credentials(credentials(m_username, m_password)); + + config.set_nativehandle_options([&](native_handle handle)->void{ + DWORD policy = WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW; + if (!WinHttpSetOption(handle, + WINHTTP_OPTION_AUTOLOGON_POLICY, + &policy, + sizeof(policy))) + { + throw std::runtime_error("The Test Error"); + } + }); + + http_client client(m_uri, config); + + const size_t rawDataSize = 8; + + std::vector data(rawDataSize); + memcpy(&data[0], "raw data", rawDataSize); + + http_request request; + request.set_method(methods::POST); + request.set_body(data); + + VERIFY_ARE_EQUAL(200, client.request(request).get().status_code()); +} +#endif + +TEST_FIXTURE(uri_address, set_user_options_exceptions) +{ + test_http_server::scoped_server scoped(m_uri); + http_client_config config; + class TestException; + config.set_nativehandle_options([](native_handle handle)->void{ + (handle); + throw std::runtime_error("The Test exception"); + }); + http_client client(m_uri, config); + VERIFY_THROWS(client.request(methods::GET).get(), std::runtime_error); +} +#endif // _MS_WINDOWS #pragma endregion // Fix for 522831 AV after failed authentication attempt From 76156f05aab1d84d23487daa9695a93deb3b3943 Mon Sep 17 00:00:00 2001 From: Artur Laksberg Date: Thu, 10 Oct 2013 10:49:26 -0700 Subject: [PATCH 3/3] Fix setup - ensure proper target dir for Extension SDK on WinBlue --- Release/setup/CasablancaSetup.wxs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Release/setup/CasablancaSetup.wxs b/Release/setup/CasablancaSetup.wxs index 09548f5837..1ced3e3e80 100644 --- a/Release/setup/CasablancaSetup.wxs +++ b/Release/setup/CasablancaSetup.wxs @@ -10,11 +10,13 @@ + +