From e1ad0774d3b3328ad6e1dedeb4c04646902c746c Mon Sep 17 00:00:00 2001 From: Jeffrey Saathoff Date: Tue, 31 Jan 2023 17:00:00 -0800 Subject: [PATCH 1/5] Add get_property support, remove callbacks and vectors from properties --- build/build.py | 2 +- sdk-cpp/include/do_download.h | 46 +- sdk-cpp/include/do_download_property.h | 82 +-- sdk-cpp/include/do_download_status.h | 4 + sdk-cpp/src/do_download.cpp | 20 +- sdk-cpp/src/do_download_property.cpp | 29 +- .../deliveryoptimization.h | 576 ++++++++++++++++++ .../internal/com/deliveryoptimization/do.hpp | 132 ---- .../com/do_download_property_internal.cpp | 190 +++--- sdk-cpp/src/internal/com/download_impl.cpp | 281 +++------ .../internal/do_download_property_internal.h | 31 +- sdk-cpp/src/internal/do_error_helpers.h | 10 + sdk-cpp/src/internal/download_impl.h | 9 +- sdk-cpp/src/internal/download_interface.h | 3 +- .../rest/do_download_property_internal.cpp | 24 - sdk-cpp/src/internal/rest/download_impl.cpp | 2 +- sdk-cpp/tests/download_properties_tests.cpp | 159 ++--- sdk-cpp/tests/test_helpers.h | 20 +- 18 files changed, 995 insertions(+), 625 deletions(-) create mode 100644 sdk-cpp/src/internal/com/deliveryoptimization/deliveryoptimization.h delete mode 100644 sdk-cpp/src/internal/com/deliveryoptimization/do.hpp diff --git a/build/build.py b/build/build.py index 996f7b9e..9f64a245 100644 --- a/build/build.py +++ b/build/build.py @@ -495,7 +495,7 @@ def compiler(self): def generator(self): # No need to specify architecture here as the default target platform name (architecture) is that of the host and is provided in the CMAKE_VS_PLATFORM_NAME_DEFAULT variable # https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2016%202019.html - return super().generator or 'Visual Studio 16 2019' + return super().generator or 'Visual Studio 17 2022' @property def generate_options(self): diff --git a/sdk-cpp/include/do_download.h b/sdk-cpp/include/do_download.h index 694e0fe8..1704c8ea 100644 --- a/sdk-cpp/include/do_download.h +++ b/sdk-cpp/include/do_download.h @@ -34,6 +34,7 @@ class download std::error_code finalize() noexcept; std::error_code abort() noexcept; std::error_code get_status(download_status& status) noexcept; + std::error_code set_status_callback(status_callback_t callback) noexcept; std::error_code start_and_wait_until_completion(std::chrono::seconds timeoutSecs = std::chrono::hours(24)) noexcept; std::error_code start_and_wait_until_completion(const std::atomic_bool& isCancelled, std::chrono::seconds timeoutSecs = std::chrono::hours(24)) noexcept; @@ -41,13 +42,46 @@ class download static std::error_code download_url_to_path(const std::string& uri, const std::string& downloadFilePath, const std::atomic_bool& isCancelled, std::chrono::seconds timeoutSecs = std::chrono::hours(24)) noexcept; /* - For devices running windows before 20H1, dosvc exposed a now-deprecated com interface for setting certain download properties. - After 20H1, these properties were added to newer com interface, which this SDK is using. - Attempting to set a download property on a version of windows earlier than 20H1 will not set the property and throw an exception with - error code msdo::errc::do_e_unknown_property_id. + Certain properties are not supported on older versions of Windows, resulting in + msdo::errc::do_e_unknown_property_id from the following methods. See do_download_property.h. */ - std::error_code set_property(download_property key, const download_property_value& value) noexcept; - std::error_code get_property(download_property key, download_property_value& value) noexcept; + std::error_code set_property(download_property prop, const download_property_value& value) noexcept; + std::error_code get_property(download_property prop, download_property_value& value) noexcept; + + template + std::error_code set_property(download_property prop, const T& value) noexcept + { + download_property_value propVal; + std::error_code ec = download_property_value::make(value, propVal); + if (!ec) + { + ec = set_property(prop, propVal); + } + return ec; + } + + template + std::error_code get_property(download_property prop, T& value) noexcept + { + value = {}; + download_property_value propVal; + std::error_code ec = get_property(prop, propVal); + if (!ec) + { + ec = propVal.as(value); + } + return ec; + } + + std::error_code set_cost_policy(download_cost_policy value) noexcept + { + return set_property(download_property::cost_policy, static_cast(value)); + } + + std::error_code set_security_flags(download_security_flags value) noexcept + { + return set_property(download_property::security_flags, static_cast(value)); + } private: download(); diff --git a/sdk-cpp/include/do_download_property.h b/sdk-cpp/include/do_download_property.h index 355f7673..ab794e52 100644 --- a/sdk-cpp/include/do_download_property.h +++ b/sdk-cpp/include/do_download_property.h @@ -4,7 +4,6 @@ #ifndef _DELIVERY_OPTIMIZATION_DO_DOWNLOAD_PROPERTY_H #define _DELIVERY_OPTIMIZATION_DO_DOWNLOAD_PROPERTY_H -#include #include #include #include @@ -23,69 +22,84 @@ class CDownloadPropertyValueInternal; class download; class download_status; -/* -For REST interface, these download properties are not yet supported -SDK will throw/return msdo::errc::e_notimpl if attempting to set/get a property -*/ enum class download_property { - id, // std::string - uri, // std::string - catalog_id, // std::string - caller_name, // std::string - download_file_path, // std::string - http_custom_headers, // std::string - cost_policy, // uint32 - security_flags, // uint32 + id = 0, // string (readonly) + uri, // string + catalog_id, // string + caller_name, // string + download_file_path, // string + http_custom_headers, // string + cost_policy, // uint32 (see download_cost_policy enum) + security_flags, // uint32 (see download_security_flags enum) callback_freq_percent, // uint32 callback_freq_seconds, // uint32 no_progress_timeout_seconds, // uint32 use_foreground_priority, // bool blocking_mode, // bool - callback_interface, // void*, but used for storing lambda expressions - stream_interface, // void* - security_context, // byte array network_token, // bool - correlation_vector, // std::string - decryption_info, // std::string - integrity_check_info, // std::string - integrity_check_mandatory, // boolean + + // Available beginning in Windows 20H1 (build 19041) + correlation_vector, // string + decryption_info, // string + integrity_check_info, // string + integrity_check_mandatory, // bool total_size_bytes, // uint64 - // For the COM interface, the following properties are available only in Windows 21H2 (Build Number 22000) and beyond + // Available beginning in Windows 21H2 (build 22000) disallow_on_cellular, // bool - http_custom_auth_headers, // std::string + http_custom_auth_headers, // string + + // Available beginning in Windows 22H2 (build 22621) + allow_http_to_https_redirect, // bool + non_volatile, // bool }; -class download_property_value +// Values for download_property::cost_policy +enum class download_cost_policy : uint32_t { + always = 0, // download regardless of cost (foreground default) + unrestricted_network, // pause download on any metered network + standard, // pause download if over or near data limit (background default) + no_roaming, // pause download if roaming + no_surcharge, // pause download if over data limit +}; -/* -CDownloadImpl is declared as a friend class because it needs to access the platform-specific native value for download_property_value -The type of the native value is defined in CDownloadPropertyValueInternal, because DO header files are platform agnostic -This is so any user of the SDK does not have to worry about supplying platform specific compile definitions to use the SDK -*/ +// Values for download_property::security_flags +enum class download_security_flags : uint32_t +{ + enable_ssl_revocation = 0x0001, // WINHTTP_ENABLE_SSL_REVOCATION + ignore_unknown_ca = 0x0100, // SECURITY_FLAG_IGNORE_UNKNOWN_CA + ignore_cert_wrong_usage = 0x0200, // SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE + ignore_cert_cn_invalid = 0x1000, // SECURITY_FLAG_IGNORE_CERT_CN_INVALID + ignore_cert_date_invalid = 0x2000, // SECURITY_FLAG_IGNORE_CERT_DATE_INVALID + ignore_all_cert_errors = 0x3300, // SECURITY_FLAG_IGNORE_ALL_CERT_ERRORS +}; + +class download_property_value +{ friend class details::CDownloadImpl; public: - using status_callback_t = std::function; - download_property_value(); ~download_property_value() = default; static std::error_code make(const std::string& val, download_property_value& out); + static std::error_code make(const char* val, download_property_value& out) { return make(std::string(val), out); } static std::error_code make(uint32_t val, download_property_value& out); static std::error_code make(uint64_t val, download_property_value& out); static std::error_code make(bool val, download_property_value& out); - static std::error_code make(std::vector& val, download_property_value& out); - static std::error_code make(const status_callback_t& val, download_property_value& out); std::error_code as(bool& val) const noexcept; std::error_code as(uint32_t& val) const noexcept; std::error_code as(uint64_t& val) const noexcept; std::error_code as(std::string& val) const noexcept; - std::error_code as(std::vector& val) const noexcept; - std::error_code as(status_callback_t& val) const noexcept; + +#if defined(DO_INTERFACE_COM) + static std::error_code make(const std::wstring& val, download_property_value& out); + static std::error_code make(const wchar_t* val, download_property_value& out) { return make(std::wstring(val), out); } + std::error_code as(std::wstring& val) const noexcept; +#endif private: std::shared_ptr _val; diff --git a/sdk-cpp/include/do_download_status.h b/sdk-cpp/include/do_download_status.h index 5813fb2b..f2d83f65 100644 --- a/sdk-cpp/include/do_download_status.h +++ b/sdk-cpp/include/do_download_status.h @@ -5,6 +5,7 @@ #define _DELIVERY_OPTIMIZATION_DO_DOWNLOAD_STATUS_H #include +#include #include #include "do_errors.h" @@ -71,6 +72,9 @@ class download_status }; +class download; +using status_callback_t = std::function; + } // namespace deliveryoptimization } // namespace microsoft diff --git a/sdk-cpp/src/do_download.cpp b/sdk-cpp/src/do_download.cpp index 966d9ebe..94934a76 100644 --- a/sdk-cpp/src/do_download.cpp +++ b/sdk-cpp/src/do_download.cpp @@ -30,7 +30,6 @@ download::~download() = default; std::error_code download::make(const std::string& uri, const std::string& downloadFilePath, std::unique_ptr& out) noexcept { out.reset(); - // using 'new' to access non-public constructor std::unique_ptr tmp(new download()); tmp->_download = std::make_shared(); std::error_code code = tmp->_download->Init(uri, downloadFilePath); @@ -69,6 +68,11 @@ std::error_code download::get_status(download_status& status) noexcept return _download->GetStatus(status); } +std::error_code download::set_status_callback(status_callback_t callback) noexcept +{ + return _download->SetStatusCallback(callback, *this); +} + std::error_code download::start_and_wait_until_completion(std::chrono::seconds timeOut) noexcept { std::atomic_bool isCancelled{ false }; @@ -157,18 +161,8 @@ static std::error_code g_TryOverrideDownlevelOsSetPropertyError(download_propert std::error_code download::set_property(download_property prop, const download_property_value& val) noexcept { - if (prop == download_property::callback_interface) - { - download_property_value::status_callback_t userCallback; - DO_RETURN_IF_FAILED(val.as(userCallback)); - - return _download->SetCallback(userCallback, *this); - } - else - { - auto ec = _download->SetProperty(prop, val); - return g_TryOverrideDownlevelOsSetPropertyError(prop, ec); - } + auto ec = _download->SetProperty(prop, val); + return g_TryOverrideDownlevelOsSetPropertyError(prop, ec); } std::error_code download::get_property(download_property prop, download_property_value& val) noexcept diff --git a/sdk-cpp/src/do_download_property.cpp b/sdk-cpp/src/do_download_property.cpp index bd1043aa..907789f6 100644 --- a/sdk-cpp/src/do_download_property.cpp +++ b/sdk-cpp/src/do_download_property.cpp @@ -28,7 +28,8 @@ std::error_code download_property_value::make(const std::string& val, download_p return DO_OK; } -std::error_code download_property_value::make(uint32_t val, download_property_value& out) +#if defined(DO_INTERFACE_COM) +std::error_code download_property_value::make(const std::wstring& val, download_property_value& out) { download_property_value temp; std::error_code code = temp._val->Init(val); @@ -37,18 +38,9 @@ std::error_code download_property_value::make(uint32_t val, download_property_va out = temp; return DO_OK; } +#endif -std::error_code download_property_value::make(uint64_t val, download_property_value& out) -{ - download_property_value temp; - std::error_code code = temp._val->Init(val); - DO_RETURN_IF_FAILED(code); - - out = temp; - return DO_OK; -} - -std::error_code download_property_value::make(bool val, download_property_value& out) +std::error_code download_property_value::make(uint32_t val, download_property_value& out) { download_property_value temp; std::error_code code = temp._val->Init(val); @@ -58,7 +50,7 @@ std::error_code download_property_value::make(bool val, download_property_value& return DO_OK; } -std::error_code download_property_value::make(std::vector& val, download_property_value& out) +std::error_code download_property_value::make(uint64_t val, download_property_value& out) { download_property_value temp; std::error_code code = temp._val->Init(val); @@ -68,7 +60,7 @@ std::error_code download_property_value::make(std::vector& val, d return DO_OK; } -std::error_code download_property_value::make(const status_callback_t& val, download_property_value& out) +std::error_code download_property_value::make(bool val, download_property_value& out) { download_property_value temp; std::error_code code = temp._val->Init(val); @@ -98,15 +90,12 @@ std::error_code download_property_value::as(std::string& val) const noexcept return _val->As(val); } -std::error_code download_property_value::as(std::vector& val) const noexcept -{ - return _val->As(val); -} - -std::error_code download_property_value::as(status_callback_t& val) const noexcept +#if defined(DO_INTERFACE_COM) +std::error_code download_property_value::as(std::wstring& val) const noexcept { return _val->As(val); } +#endif } // deliveryoptimization } // microsoft diff --git a/sdk-cpp/src/internal/com/deliveryoptimization/deliveryoptimization.h b/sdk-cpp/src/internal/com/deliveryoptimization/deliveryoptimization.h new file mode 100644 index 00000000..6e63dd25 --- /dev/null +++ b/sdk-cpp/src/internal/com/deliveryoptimization/deliveryoptimization.h @@ -0,0 +1,576 @@ + + +/* this ALWAYS GENERATED file contains the definitions for the interfaces */ + + + /* File created by MIDL compiler version 8.01.0628 */ +/* @@MIDL_FILE_HEADING( ) */ + + + +/* verify that the version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCNDR_H_VERSION__ +#define __REQUIRED_RPCNDR_H_VERSION__ 501 +#endif + +/* verify that the version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCSAL_H_VERSION__ +#define __REQUIRED_RPCSAL_H_VERSION__ 100 +#endif + +#include "rpc.h" +#include "rpcndr.h" + +#ifndef __RPCNDR_H_VERSION__ +#error this stub requires an updated version of +#endif /* __RPCNDR_H_VERSION__ */ + +#ifndef COM_NO_WINDOWS_H +#include "windows.h" +#include "ole2.h" +#endif /*COM_NO_WINDOWS_H*/ + +#ifndef __deliveryoptimization_h__ +#define __deliveryoptimization_h__ + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +#pragma once +#endif + +#ifndef DECLSPEC_XFGVIRT +#if defined(_CONTROL_FLOW_GUARD_XFG) +#define DECLSPEC_XFGVIRT(base, func) __declspec(xfg_virtual(base, func)) +#else +#define DECLSPEC_XFGVIRT(base, func) +#endif +#endif + +/* Forward Declarations */ + +#ifndef __IDODownload_FWD_DEFINED__ +#define __IDODownload_FWD_DEFINED__ +typedef interface IDODownload IDODownload; + +#endif /* __IDODownload_FWD_DEFINED__ */ + + +#ifndef __IDODownloadStatusCallback_FWD_DEFINED__ +#define __IDODownloadStatusCallback_FWD_DEFINED__ +typedef interface IDODownloadStatusCallback IDODownloadStatusCallback; + +#endif /* __IDODownloadStatusCallback_FWD_DEFINED__ */ + + +#ifndef __IDOManager_FWD_DEFINED__ +#define __IDOManager_FWD_DEFINED__ +typedef interface IDOManager IDOManager; + +#endif /* __IDOManager_FWD_DEFINED__ */ + + +#ifndef __DeliveryOptimization_FWD_DEFINED__ +#define __DeliveryOptimization_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class DeliveryOptimization DeliveryOptimization; +#else +typedef struct DeliveryOptimization DeliveryOptimization; +#endif /* __cplusplus */ + +#endif /* __DeliveryOptimization_FWD_DEFINED__ */ + + +/* header files for imported files */ +#include "oaidl.h" + +#ifdef __cplusplus +extern "C"{ +#endif + + +/* interface __MIDL_itf_deliveryoptimization_0000_0000 */ +/* [local] */ + +#include + +#pragma region Desktop Family +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + +typedef struct _DO_DOWNLOAD_RANGE + { + UINT64 Offset; + UINT64 Length; + } DO_DOWNLOAD_RANGE; + +typedef struct _DO_DOWNLOAD_RANGES_INFO + { + UINT RangeCount; + /* [size_is] */ DO_DOWNLOAD_RANGE Ranges[ 1 ]; + } DO_DOWNLOAD_RANGES_INFO; + +typedef +enum _DODownloadState + { + DODownloadState_Created = 0, + DODownloadState_Transferring = ( DODownloadState_Created + 1 ) , + DODownloadState_Transferred = ( DODownloadState_Transferring + 1 ) , + DODownloadState_Finalized = ( DODownloadState_Transferred + 1 ) , + DODownloadState_Aborted = ( DODownloadState_Finalized + 1 ) , + DODownloadState_Paused = ( DODownloadState_Aborted + 1 ) + } DODownloadState; + +typedef struct _DO_DOWNLOAD_STATUS + { + UINT64 BytesTotal; + UINT64 BytesTransferred; + DODownloadState State; + HRESULT Error; + HRESULT ExtendedError; + } DO_DOWNLOAD_STATUS; + +typedef +enum _DODownloadCostPolicy + { + DODownloadCostPolicy_Always = 0, + DODownloadCostPolicy_Unrestricted = ( DODownloadCostPolicy_Always + 1 ) , + DODownloadCostPolicy_Standard = ( DODownloadCostPolicy_Unrestricted + 1 ) , + DODownloadCostPolicy_NoRoaming = ( DODownloadCostPolicy_Standard + 1 ) , + DODownloadCostPolicy_NoSurcharge = ( DODownloadCostPolicy_NoRoaming + 1 ) , + DODownloadCostPolicy_NoCellular = ( DODownloadCostPolicy_NoSurcharge + 1 ) + } DODownloadCostPolicy; + +typedef +enum _DODownloadProperty + { + DODownloadProperty_Id = 0, + DODownloadProperty_Uri = ( DODownloadProperty_Id + 1 ) , + DODownloadProperty_ContentId = ( DODownloadProperty_Uri + 1 ) , + DODownloadProperty_DisplayName = ( DODownloadProperty_ContentId + 1 ) , + DODownloadProperty_LocalPath = ( DODownloadProperty_DisplayName + 1 ) , + DODownloadProperty_HttpCustomHeaders = ( DODownloadProperty_LocalPath + 1 ) , + DODownloadProperty_CostPolicy = ( DODownloadProperty_HttpCustomHeaders + 1 ) , + DODownloadProperty_SecurityFlags = ( DODownloadProperty_CostPolicy + 1 ) , + DODownloadProperty_CallbackFreqPercent = ( DODownloadProperty_SecurityFlags + 1 ) , + DODownloadProperty_CallbackFreqSeconds = ( DODownloadProperty_CallbackFreqPercent + 1 ) , + DODownloadProperty_NoProgressTimeoutSeconds = ( DODownloadProperty_CallbackFreqSeconds + 1 ) , + DODownloadProperty_ForegroundPriority = ( DODownloadProperty_NoProgressTimeoutSeconds + 1 ) , + DODownloadProperty_BlockingMode = ( DODownloadProperty_ForegroundPriority + 1 ) , + DODownloadProperty_CallbackInterface = ( DODownloadProperty_BlockingMode + 1 ) , + DODownloadProperty_StreamInterface = ( DODownloadProperty_CallbackInterface + 1 ) , + DODownloadProperty_SecurityContext = ( DODownloadProperty_StreamInterface + 1 ) , + DODownloadProperty_NetworkToken = ( DODownloadProperty_SecurityContext + 1 ) , + DODownloadProperty_CorrelationVector = ( DODownloadProperty_NetworkToken + 1 ) , + DODownloadProperty_DecryptionInfo = ( DODownloadProperty_CorrelationVector + 1 ) , + DODownloadProperty_IntegrityCheckInfo = ( DODownloadProperty_DecryptionInfo + 1 ) , + DODownloadProperty_IntegrityCheckMandatory = ( DODownloadProperty_IntegrityCheckInfo + 1 ) , + DODownloadProperty_TotalSizeBytes = ( DODownloadProperty_IntegrityCheckMandatory + 1 ) , + DODownloadProperty_DisallowOnCellular = ( DODownloadProperty_TotalSizeBytes + 1 ) , + DODownloadProperty_HttpCustomAuthHeaders = ( DODownloadProperty_DisallowOnCellular + 1 ) , + DODownloadProperty_HttpAllowSecureToNonSecureRedirect = ( DODownloadProperty_HttpCustomAuthHeaders + 1 ) , + DODownloadProperty_NonVolatile = ( DODownloadProperty_HttpAllowSecureToNonSecureRedirect + 1 ) + } DODownloadProperty; + +typedef struct _DO_DOWNLOAD_ENUM_CATEGORY + { + DODownloadProperty Property; + LPCWSTR Value; + } DO_DOWNLOAD_ENUM_CATEGORY; + + + +extern RPC_IF_HANDLE __MIDL_itf_deliveryoptimization_0000_0000_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_deliveryoptimization_0000_0000_v0_0_s_ifspec; + +#ifndef __IDODownload_INTERFACE_DEFINED__ +#define __IDODownload_INTERFACE_DEFINED__ + +/* interface IDODownload */ +/* [uuid][object] */ + + +EXTERN_C const IID IID_IDODownload; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("FBBD7FC0-C147-4727-A38D-827EF071EE77") + IDODownload : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Start( + /* [unique][in] */ __RPC__in_opt const DO_DOWNLOAD_RANGES_INFO *ranges) = 0; + + virtual HRESULT STDMETHODCALLTYPE Pause( void) = 0; + + virtual HRESULT STDMETHODCALLTYPE Abort( void) = 0; + + virtual HRESULT STDMETHODCALLTYPE Finalize( void) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetStatus( + /* [out] */ __RPC__out DO_DOWNLOAD_STATUS *status) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetProperty( + /* [in] */ DODownloadProperty propId, + /* [out] */ __RPC__out VARIANT *propVal) = 0; + + virtual HRESULT STDMETHODCALLTYPE SetProperty( + /* [in] */ DODownloadProperty propId, + /* [in] */ __RPC__in const VARIANT *propVal) = 0; + + }; + + +#else /* C style interface */ + + typedef struct IDODownloadVtbl + { + BEGIN_INTERFACE + + DECLSPEC_XFGVIRT(IUnknown, QueryInterface) + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + __RPC__in IDODownload * This, + /* [in] */ __RPC__in REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + DECLSPEC_XFGVIRT(IUnknown, AddRef) + ULONG ( STDMETHODCALLTYPE *AddRef )( + __RPC__in IDODownload * This); + + DECLSPEC_XFGVIRT(IUnknown, Release) + ULONG ( STDMETHODCALLTYPE *Release )( + __RPC__in IDODownload * This); + + DECLSPEC_XFGVIRT(IDODownload, Start) + HRESULT ( STDMETHODCALLTYPE *Start )( + __RPC__in IDODownload * This, + /* [unique][in] */ __RPC__in_opt const DO_DOWNLOAD_RANGES_INFO *ranges); + + DECLSPEC_XFGVIRT(IDODownload, Pause) + HRESULT ( STDMETHODCALLTYPE *Pause )( + __RPC__in IDODownload * This); + + DECLSPEC_XFGVIRT(IDODownload, Abort) + HRESULT ( STDMETHODCALLTYPE *Abort )( + __RPC__in IDODownload * This); + + DECLSPEC_XFGVIRT(IDODownload, Finalize) + HRESULT ( STDMETHODCALLTYPE *Finalize )( + __RPC__in IDODownload * This); + + DECLSPEC_XFGVIRT(IDODownload, GetStatus) + HRESULT ( STDMETHODCALLTYPE *GetStatus )( + __RPC__in IDODownload * This, + /* [out] */ __RPC__out DO_DOWNLOAD_STATUS *status); + + DECLSPEC_XFGVIRT(IDODownload, GetProperty) + HRESULT ( STDMETHODCALLTYPE *GetProperty )( + __RPC__in IDODownload * This, + /* [in] */ DODownloadProperty propId, + /* [out] */ __RPC__out VARIANT *propVal); + + DECLSPEC_XFGVIRT(IDODownload, SetProperty) + HRESULT ( STDMETHODCALLTYPE *SetProperty )( + __RPC__in IDODownload * This, + /* [in] */ DODownloadProperty propId, + /* [in] */ __RPC__in const VARIANT *propVal); + + END_INTERFACE + } IDODownloadVtbl; + + interface IDODownload + { + CONST_VTBL struct IDODownloadVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IDODownload_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define IDODownload_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define IDODownload_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define IDODownload_Start(This,ranges) \ + ( (This)->lpVtbl -> Start(This,ranges) ) + +#define IDODownload_Pause(This) \ + ( (This)->lpVtbl -> Pause(This) ) + +#define IDODownload_Abort(This) \ + ( (This)->lpVtbl -> Abort(This) ) + +#define IDODownload_Finalize(This) \ + ( (This)->lpVtbl -> Finalize(This) ) + +#define IDODownload_GetStatus(This,status) \ + ( (This)->lpVtbl -> GetStatus(This,status) ) + +#define IDODownload_GetProperty(This,propId,propVal) \ + ( (This)->lpVtbl -> GetProperty(This,propId,propVal) ) + +#define IDODownload_SetProperty(This,propId,propVal) \ + ( (This)->lpVtbl -> SetProperty(This,propId,propVal) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __IDODownload_INTERFACE_DEFINED__ */ + + +#ifndef __IDODownloadStatusCallback_INTERFACE_DEFINED__ +#define __IDODownloadStatusCallback_INTERFACE_DEFINED__ + +/* interface IDODownloadStatusCallback */ +/* [uuid][object] */ + + +EXTERN_C const IID IID_IDODownloadStatusCallback; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("D166E8E3-A90E-4392-8E87-05E996D3747D") + IDODownloadStatusCallback : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE OnStatusChange( + /* [in] */ __RPC__in_opt IDODownload *download, + /* [in] */ __RPC__in const DO_DOWNLOAD_STATUS *status) = 0; + + }; + + +#else /* C style interface */ + + typedef struct IDODownloadStatusCallbackVtbl + { + BEGIN_INTERFACE + + DECLSPEC_XFGVIRT(IUnknown, QueryInterface) + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + __RPC__in IDODownloadStatusCallback * This, + /* [in] */ __RPC__in REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + DECLSPEC_XFGVIRT(IUnknown, AddRef) + ULONG ( STDMETHODCALLTYPE *AddRef )( + __RPC__in IDODownloadStatusCallback * This); + + DECLSPEC_XFGVIRT(IUnknown, Release) + ULONG ( STDMETHODCALLTYPE *Release )( + __RPC__in IDODownloadStatusCallback * This); + + DECLSPEC_XFGVIRT(IDODownloadStatusCallback, OnStatusChange) + HRESULT ( STDMETHODCALLTYPE *OnStatusChange )( + __RPC__in IDODownloadStatusCallback * This, + /* [in] */ __RPC__in_opt IDODownload *download, + /* [in] */ __RPC__in const DO_DOWNLOAD_STATUS *status); + + END_INTERFACE + } IDODownloadStatusCallbackVtbl; + + interface IDODownloadStatusCallback + { + CONST_VTBL struct IDODownloadStatusCallbackVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IDODownloadStatusCallback_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define IDODownloadStatusCallback_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define IDODownloadStatusCallback_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define IDODownloadStatusCallback_OnStatusChange(This,download,status) \ + ( (This)->lpVtbl -> OnStatusChange(This,download,status) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __IDODownloadStatusCallback_INTERFACE_DEFINED__ */ + + +#ifndef __IDOManager_INTERFACE_DEFINED__ +#define __IDOManager_INTERFACE_DEFINED__ + +/* interface IDOManager */ +/* [uuid][object] */ + + +EXTERN_C const IID IID_IDOManager; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("400E2D4A-1431-4C1A-A748-39CA472CFDB1") + IDOManager : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE CreateDownload( + /* [out] */ __RPC__deref_out_opt IDODownload **download) = 0; + + virtual HRESULT STDMETHODCALLTYPE EnumDownloads( + /* [unique][in] */ __RPC__in_opt const DO_DOWNLOAD_ENUM_CATEGORY *category, + /* [out] */ __RPC__deref_out_opt IEnumUnknown **ppEnum) = 0; + + }; + + +#else /* C style interface */ + + typedef struct IDOManagerVtbl + { + BEGIN_INTERFACE + + DECLSPEC_XFGVIRT(IUnknown, QueryInterface) + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + __RPC__in IDOManager * This, + /* [in] */ __RPC__in REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + DECLSPEC_XFGVIRT(IUnknown, AddRef) + ULONG ( STDMETHODCALLTYPE *AddRef )( + __RPC__in IDOManager * This); + + DECLSPEC_XFGVIRT(IUnknown, Release) + ULONG ( STDMETHODCALLTYPE *Release )( + __RPC__in IDOManager * This); + + DECLSPEC_XFGVIRT(IDOManager, CreateDownload) + HRESULT ( STDMETHODCALLTYPE *CreateDownload )( + __RPC__in IDOManager * This, + /* [out] */ __RPC__deref_out_opt IDODownload **download); + + DECLSPEC_XFGVIRT(IDOManager, EnumDownloads) + HRESULT ( STDMETHODCALLTYPE *EnumDownloads )( + __RPC__in IDOManager * This, + /* [unique][in] */ __RPC__in_opt const DO_DOWNLOAD_ENUM_CATEGORY *category, + /* [out] */ __RPC__deref_out_opt IEnumUnknown **ppEnum); + + END_INTERFACE + } IDOManagerVtbl; + + interface IDOManager + { + CONST_VTBL struct IDOManagerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IDOManager_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define IDOManager_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define IDOManager_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define IDOManager_CreateDownload(This,download) \ + ( (This)->lpVtbl -> CreateDownload(This,download) ) + +#define IDOManager_EnumDownloads(This,category,ppEnum) \ + ( (This)->lpVtbl -> EnumDownloads(This,category,ppEnum) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __IDOManager_INTERFACE_DEFINED__ */ + + + +#ifndef __DeliveryOptimization_LIBRARY_DEFINED__ +#define __DeliveryOptimization_LIBRARY_DEFINED__ + +/* library DeliveryOptimization */ +/* [uuid] */ + + +EXTERN_C const IID LIBID_DeliveryOptimization; + +EXTERN_C const CLSID CLSID_DeliveryOptimization; + +#ifdef __cplusplus + +class DECLSPEC_UUID("5b99fa76-721c-423c-adac-56d03c8a8007") +DeliveryOptimization; +#endif +#endif /* __DeliveryOptimization_LIBRARY_DEFINED__ */ + +/* interface __MIDL_itf_deliveryoptimization_0000_0004 */ +/* [local] */ + +#define DO_LENGTH_TO_EOF (UINT64)(-1) + +#define DecryptionInfo_KeyData L"KeyData" +#define DecryptionInfo_EncryptionBufferSize L"EncryptionBufferSize" +#define DecryptionInfo_AlgorithmName L"AlgorithmName" +#define DecryptionInfo_ChainingMode L"ChainingMode" + +#define IntegrityCheckInfo_PiecesHashFileUrl L"PiecesHashFileUrl" +#define IntegrityCheckInfo_PiecesHashFileDigest L"PiecesHashFileDigest" +#define IntegrityCheckInfo_PiecesHashFileDigestAlgorithm L"PiecesHashFileDigestAlgorithm" +#define IntegrityCheckInfo_HashOfHashes L"HashOfHashes" + +#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */ +#pragma endregion + + +extern RPC_IF_HANDLE __MIDL_itf_deliveryoptimization_0000_0004_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_deliveryoptimization_0000_0004_v0_0_s_ifspec; + +/* Additional Prototypes for ALL interfaces */ + +unsigned long __RPC_USER VARIANT_UserSize( __RPC__in unsigned long *, unsigned long , __RPC__in VARIANT * ); +unsigned char * __RPC_USER VARIANT_UserMarshal( __RPC__in unsigned long *, __RPC__inout_xcount(0) unsigned char *, __RPC__in VARIANT * ); +unsigned char * __RPC_USER VARIANT_UserUnmarshal(__RPC__in unsigned long *, __RPC__in_xcount(0) unsigned char *, __RPC__out VARIANT * ); +void __RPC_USER VARIANT_UserFree( __RPC__in unsigned long *, __RPC__in VARIANT * ); + +unsigned long __RPC_USER VARIANT_UserSize64( __RPC__in unsigned long *, unsigned long , __RPC__in VARIANT * ); +unsigned char * __RPC_USER VARIANT_UserMarshal64( __RPC__in unsigned long *, __RPC__inout_xcount(0) unsigned char *, __RPC__in VARIANT * ); +unsigned char * __RPC_USER VARIANT_UserUnmarshal64(__RPC__in unsigned long *, __RPC__in_xcount(0) unsigned char *, __RPC__out VARIANT * ); +void __RPC_USER VARIANT_UserFree64( __RPC__in unsigned long *, __RPC__in VARIANT * ); + +/* end of Additional Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/sdk-cpp/src/internal/com/deliveryoptimization/do.hpp b/sdk-cpp/src/internal/com/deliveryoptimization/do.hpp deleted file mode 100644 index 0beed91c..00000000 --- a/sdk-cpp/src/internal/com/deliveryoptimization/do.hpp +++ /dev/null @@ -1,132 +0,0 @@ -#ifndef _do_hpp_ -#define _do_hpp_ -extern "C" { - -// Prerequisites. These may already be included via a precompiled header, possibly via other headers such as windows.h or ole.h. -//#include "rpc.h" -//#include "rpcndr.h" -//#include "oaidl.h" - -// DO reference: https://docs.microsoft.com/en-us/windows/win32/delivery_optimization/do-reference - -// https://docs.microsoft.com/en-us/windows/win32/delivery_optimization/deliveryoptimizationdownloadtypes/ns-deliveryoptimizationdownloadtypes-do_download_range -typedef struct _DO_DOWNLOAD_RANGE -{ - UINT64 Offset; - UINT64 Length; -} DO_DOWNLOAD_RANGE; - -// https://docs.microsoft.com/en-us/windows/win32/delivery_optimization/do/ns-do-do_download_range_info -typedef struct _DO_DOWNLOAD_RANGES_INFO -{ - UINT RangeCount; - DO_DOWNLOAD_RANGE Ranges[1]; -} DO_DOWNLOAD_RANGES_INFO; - -// https://docs.microsoft.com/en-us/windows/win32/delivery_optimization/deliveryoptimizationdownloadtypes/ne-deliveryoptimizationdownloadtypes-dodownloadstate -typedef enum _DODownloadState -{ - DODownloadState_Created = 0, - DODownloadState_Transferring, - DODownloadState_Transferred, - DODownloadState_Finalized, - DODownloadState_Aborted, - DODownloadState_Paused -} DODownloadState; - -// https://docs.microsoft.com/en-us/windows/win32/delivery_optimization/do/ns-do-do_download_status -typedef struct _DO_DOWNLOAD_STATUS -{ - UINT64 BytesTotal; - UINT64 BytesTransferred; - DODownloadState State; - HRESULT Error; - HRESULT ExtendedError; -} DO_DOWNLOAD_STATUS; - -// https://docs.microsoft.com/en-us/windows/win32/delivery_optimization/deliveryoptimizationdownloadtypes/ne-deliveryoptimizationdownloadtypes-dodownloadcostpolicy -typedef enum _DODownloadCostPolicy -{ - DODownloadCostPolicy_Always = 0, - DODownloadCostPolicy_Unrestricted, - DODownloadCostPolicy_Standard, - DODownloadCostPolicy_NoRoaming, - DODownloadCostPolicy_NoSurcharge, - DODownloadCostPolicy_NoCellular -} DODownloadCostPolicy; - -// https://docs.microsoft.com/en-us/windows/win32/delivery_optimization/deliveryoptimizationdownloadtypes/ne-deliveryoptimizationdownloadtypes-dodownloadproperty -typedef enum _DODownloadProperty -{ - DODownloadProperty_Id = 0, - DODownloadProperty_Uri, - DODownloadProperty_ContentId, - DODownloadProperty_DisplayName, - DODownloadProperty_LocalPath, - DODownloadProperty_HttpCustomHeaders, - DODownloadProperty_CostPolicy, - DODownloadProperty_SecurityFlags, - DODownloadProperty_CallbackFreqPercent, - DODownloadProperty_CallbackFreqSeconds, - DODownloadProperty_NoProgressTimeoutSeconds, - DODownloadProperty_ForegroundPriority, - DODownloadProperty_BlockingMode, - DODownloadProperty_CallbackInterface, - DODownloadProperty_StreamInterface, - DODownloadProperty_SecurityContext, - DODownloadProperty_NetworkToken, - DODownloadProperty_CorrelationVector, - DODownloadProperty_DecryptionInfo, - DODownloadProperty_IntegrityCheckInfo, - DODownloadProperty_IntegrityCheckMandatory, - DODownloadProperty_TotalSizeBytes, - DODownloadProperty_DisallowOnCellular, // Windows 21H2 (Build Number 22000) - DODownloadProperty_HttpCustomAuthHeaders, // Windows 21H2 (Build Number 22000) -} DODownloadProperty; - -// https://docs.microsoft.com/en-us/windows/win32/delivery_optimization/do/ns-do-do_download_enum_category -typedef struct _DO_DOWNLOAD_ENUM_CATEGORY -{ - DODownloadProperty Property; - LPCWSTR Value; -} DO_DOWNLOAD_ENUM_CATEGORY; - -// https://docs.microsoft.com/en-us/windows/win32/delivery_optimization/do/nn-do-idodownload -interface DECLSPEC_UUID("FBBD7FC0-C147-4727-A38D-827EF071EE77") DECLSPEC_NOVTABLE -IDODownload : public IUnknown -{ -public: - IFACEMETHOD(Start)(const DO_DOWNLOAD_RANGES_INFO *ranges) = 0; - IFACEMETHOD(Pause)() = 0; - IFACEMETHOD(Abort)() = 0; - IFACEMETHOD(Finalize)() = 0; - IFACEMETHOD(GetStatus)(DO_DOWNLOAD_STATUS* status) = 0; - IFACEMETHOD(GetProperty)(DODownloadProperty propId, VARIANT* propVal) = 0; - IFACEMETHOD(SetProperty)(DODownloadProperty propId, const VARIANT* propVal) = 0; -}; -DEFINE_GUID(IID_IDODownload, 0xFBBD7FC0, 0xC147, 0x4727, 0xA3, 0x8D, 0x82, 0x7E, 0xF0, 0x71, 0xEE, 0x77); - -// https://docs.microsoft.com/en-us/windows/win32/delivery_optimization/do/nn-do-idodownloadstatuscallback -interface DECLSPEC_UUID("D166E8E3-A90E-4392-8E87-05E996D3747D") DECLSPEC_NOVTABLE -IDODownloadStatusCallback : public IUnknown -{ -public: - IFACEMETHOD(OnStatusChange)(IDODownload* download, const DO_DOWNLOAD_STATUS* status) = 0; -}; -DEFINE_GUID(IID_IDODownloadStatusCallback, 0xD166E8E3, 0xA90E, 0x4392, 0x8E, 0x87, 0x05, 0xE9, 0x96, 0xD3, 0x74, 0x7D); - -// https://docs.microsoft.com/en-us/windows/win32/delivery_optimization/do/nn-do-idomanager -interface DECLSPEC_UUID("400E2D4A-1431-4C1A-A748-39CA472CFDB1") DECLSPEC_NOVTABLE -IDOManager : public IUnknown -{ -public: - IFACEMETHOD(CreateDownload)(IDODownload** download) = 0; - IFACEMETHOD(EnumDownloads)(const DO_DOWNLOAD_ENUM_CATEGORY* category, IEnumUnknown** ppEnum) = 0; -}; -DEFINE_GUID(IID_IDOManager, 0x400E2D4A, 0x1431, 0x4C1A, 0xA7, 0x48, 0x39, 0xCA, 0x47, 0x2C, 0xFD, 0xB1); - -DEFINE_GUID(CLSID_DeliveryOptimization, 0x5b99fa76, 0x721c, 0x423c, 0xad, 0xac, 0x56, 0xd0, 0x3c, 0x8a, 0x80, 0x07); -class DECLSPEC_UUID("5b99fa76-721c-423c-adac-56d03c8a8007") DeliveryOptimization; - -} // extern "C" -#endif // _do_hpp_ diff --git a/sdk-cpp/src/internal/com/do_download_property_internal.cpp b/sdk-cpp/src/internal/com/do_download_property_internal.cpp index 233c5a89..bf8e515f 100644 --- a/sdk-cpp/src/internal/com/do_download_property_internal.cpp +++ b/sdk-cpp/src/internal/com/do_download_property_internal.cpp @@ -19,150 +19,200 @@ namespace deliveryoptimization namespace details { -static std::error_code UTF8toWstr(const char* str, std::wstring& wstr) +static std::error_code UTF8toWstr(const std::string& str, std::wstring& wstr) { - size_t cch = strlen(str); - if (cch == 0) + wstr.clear(); + size_t cch = str.size(); + if (cch != 0) { - wstr = std::wstring(); + std::vector dest(cch * 4); + const int result = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), static_cast(cch), dest.data(), static_cast(dest.size())); + if (result == 0) + { + return make_error_code(HRESULT_FROM_WIN32(::GetLastError())); + } + wstr = std::wstring(dest.data(), static_cast(result)); } + return DO_OK; +} - std::vector dest(cch * 4); - const int result = MultiByteToWideChar(CP_UTF8, 0, str, static_cast(cch), dest.data(), static_cast(dest.size())); - if (result == 0) +static std::error_code WstrToUTF8(const std::wstring& wstr, std::string& str) +{ + str.clear(); + size_t cch = wstr.size(); + if (cch != 0) { - return make_error_code(HRESULT_FROM_WIN32(::GetLastError())); + std::vector dest(cch * 4); + const int result = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), static_cast(cch), dest.data(), static_cast(dest.size()), 0, 0); + if (result == 0) + { + return make_error_code(HRESULT_FROM_WIN32(::GetLastError())); + } + str = std::string(dest.data(), static_cast(result)); } - wstr = std::wstring(dest.data(), static_cast(result)); return DO_OK; } +unique_variant::unique_variant() +{ + VariantInit(this); +} + +unique_variant::unique_variant(const VARIANT& other) noexcept : + VARIANT(other) +{ +} + +unique_variant::unique_variant(const unique_variant& other) +{ + HRESULT res = VariantCopy(this, &other); + assert(SUCCEEDED(res)); + if (FAILED(res)) + { + std::terminate(); + } +} + +unique_variant::unique_variant(unique_variant&& other) noexcept : + VARIANT(other) +{ + VariantInit(&other); +} + +unique_variant& unique_variant::operator=(unique_variant&& other) +{ + VariantClear(this); + VARIANT::operator=(other); + VariantInit(&other); + return *this; +} + +unique_variant::~unique_variant() +{ + VariantClear(this); +} + CDownloadPropertyValueInternal::CDownloadPropertyValueInternal() { - VariantInit(&_var); } std::error_code CDownloadPropertyValueInternal::Init(const std::string& val) noexcept { - V_VT(&_var) = VT_BSTR; - std::wstring wval; - auto hr = UTF8toWstr(val.c_str(), wval); - DO_RETURN_IF_FAILED(hr); + DO_RETURN_IF_FAILED(UTF8toWstr(val, wval)); + return Init(wval); +} - BSTR bstr = SysAllocString(wval.c_str()); +std::error_code CDownloadPropertyValueInternal::Init(const std::wstring& val) noexcept +{ + BSTR bstr = SysAllocString(val.c_str()); if (bstr == nullptr) { return msdo::details::make_error_code(std::errc::not_enough_memory); } - V_BSTR(&_var) = bstr; + V_VT(&_var) = VT_BSTR; + V_BSTR(&_var) = bstr; return DO_OK; -}; +} std::error_code CDownloadPropertyValueInternal::Init(uint32_t val) noexcept { V_VT(&_var) = VT_UI4; V_UI4(&_var) = val; return DO_OK; -}; +} std::error_code CDownloadPropertyValueInternal::Init(uint64_t val) noexcept { V_VT(&_var) = VT_UI8; V_UI8(&_var) = val; return DO_OK; -}; +} std::error_code CDownloadPropertyValueInternal::Init(bool val) noexcept { V_VT(&_var) = VT_BOOL; V_BOOL(&_var) = val ? VARIANT_TRUE : VARIANT_FALSE; return DO_OK; -}; - -std::error_code CDownloadPropertyValueInternal::Init(std::vector& val) noexcept -{ - return make_error_code(errc::e_not_impl); -}; - -std::error_code CDownloadPropertyValueInternal::Init(const download_property_value::status_callback_t& val) noexcept -{ - _callback = val; - return DO_OK; } CDownloadPropertyValueInternal::~CDownloadPropertyValueInternal() { -#ifdef DEBUG - assert(SUCCEEDED(VariantClear(&_var))); -#else - (void)VariantClear(&_var); -#endif -}; +} -CDownloadPropertyValueInternal::CDownloadPropertyValueInternal(const CDownloadPropertyValueInternal& rhs) +CDownloadPropertyValueInternal::CDownloadPropertyValueInternal(const CDownloadPropertyValueInternal& rhs) : + _var(rhs._var) { - HRESULT res = VariantCopy(&_var, &rhs._var); -#if DEBUG - assert(SUCCEEDED(res)); -#endif - if (FAILED(res)) - { - std::terminate(); - } - _callback = rhs._callback; -}; +} CDownloadPropertyValueInternal& CDownloadPropertyValueInternal::operator=(CDownloadPropertyValueInternal copy) { swap(*this, copy); return *this; -}; +} -CDownloadPropertyValueInternal::CDownloadPropertyValueInternal(CDownloadPropertyValueInternal&& rhs) noexcept +CDownloadPropertyValueInternal::CDownloadPropertyValueInternal(CDownloadPropertyValueInternal&& rhs) noexcept : + _var(std::move(rhs._var)) { - _var = rhs._var; - rhs._var = {}; - V_VT(&rhs._var) = VT_EMPTY; - _callback = std::move(rhs._callback); -}; +} const CDownloadPropertyValueInternal::native_type& CDownloadPropertyValueInternal::native_value() const noexcept { return _var; -}; +} std::error_code CDownloadPropertyValueInternal::As(bool& val) const noexcept { - return make_error_code(errc::e_not_impl); -}; + val = false; + unique_variant v2; + RETURN_IF_FAILED(VariantChangeType(&v2, &_var, 0, VT_BOOL)); + val = (V_BOOL(&v2) != VARIANT_FALSE); + return DO_OK; +} std::error_code CDownloadPropertyValueInternal::As(uint32_t& val) const noexcept { - return make_error_code(errc::e_not_impl); -}; + val = 0; + unique_variant v2; + RETURN_IF_FAILED(VariantChangeType(&v2, &_var, 0, VT_UI4)); + val = V_UI4(&v2); + return DO_OK; +} std::error_code CDownloadPropertyValueInternal::As(uint64_t& val) const noexcept { - return make_error_code(errc::e_not_impl); -}; + val = 0; + unique_variant v2; + RETURN_IF_FAILED(VariantChangeType(&v2, &_var, 0, VT_UI8)); + val = V_UI8(&v2); + return DO_OK; +} std::error_code CDownloadPropertyValueInternal::As(std::string& val) const noexcept { - return make_error_code(errc::e_not_impl); -}; - -std::error_code CDownloadPropertyValueInternal::As(std::vector& val) const noexcept -{ - return make_error_code(errc::e_not_impl); + val.clear(); + std::wstring wstr; + DO_RETURN_IF_FAILED(As(wstr)); + DO_RETURN_IF_FAILED(WstrToUTF8(wstr, val)); + return DO_OK; } -std::error_code CDownloadPropertyValueInternal::As(download_property_value::status_callback_t& val) const noexcept +std::error_code CDownloadPropertyValueInternal::As(std::wstring& val) const noexcept { - val = _callback; + val.clear(); + if (V_VT(&_var) == VT_BSTR) + { + val = V_BSTR(&_var); // avoid the extra string copy from VariantChangeType + } + else + { + unique_variant v2; + RETURN_IF_FAILED(VariantChangeType(&v2, &_var, 0, VT_BSTR)); + val = V_BSTR(&v2); + } return DO_OK; -}; +} } // namespace details } // namespace deliveryoptimization diff --git a/sdk-cpp/src/internal/com/download_impl.cpp b/sdk-cpp/src/internal/com/download_impl.cpp index b06e8f35..216bb85c 100644 --- a/sdk-cpp/src/internal/com/download_impl.cpp +++ b/sdk-cpp/src/internal/com/download_impl.cpp @@ -3,7 +3,8 @@ #include "download_impl.h" -#include +#include + #include #include #include @@ -16,16 +17,6 @@ namespace msdo = microsoft::deliveryoptimization; using namespace Microsoft::WRL; -#ifndef FAILED -#define FAILED(hr) (((int32_t)(hr)) < 0) -#endif - -#ifndef RETURN_IF_FAILED -#define RETURN_IF_FAILED(hr) { \ - int32_t __hr = (hr); \ - if (FAILED(__hr)) return std::error_code(__hr, msdo::details::do_category()); } -#endif - namespace microsoft { namespace deliveryoptimization @@ -35,41 +26,17 @@ namespace details static msdo::download_state ConvertFromComState(DODownloadState platformState) { - msdo::download_state state; - switch (platformState) - { - case DODownloadState_Created: - { - state = msdo::download_state::created; - break; - } - case DODownloadState_Transferring: - { - state = msdo::download_state::transferring; - break; - } - case DODownloadState_Transferred: - { - state = msdo::download_state::transferred; - break; - } - case DODownloadState_Finalized: - { - state = msdo::download_state::finalized; - break; - } - case DODownloadState_Aborted: - { - state = msdo::download_state::aborted; - break; - } - case DODownloadState_Paused: - { - state = msdo::download_state::paused; - break; - } - } - return state; + static const msdo::download_state c_stateMap[] = + { + msdo::download_state::created, // DODownloadState_Created + msdo::download_state::transferring, // DODownloadState_Transferring + msdo::download_state::transferred, // DODownloadState_Transferred + msdo::download_state::finalized, // DODownloadState_Finalized + msdo::download_state::aborted, // DODownloadState_Aborted + msdo::download_state::paused, // DODownloadState_Paused + }; + auto index = static_cast(platformState); + return (index < ARRAYSIZE(c_stateMap)) ? c_stateMap[index] : msdo::download_state::paused; } static msdo::download_status ConvertFromComStatus(const DO_DOWNLOAD_STATUS& platformStatus) @@ -78,127 +45,48 @@ static msdo::download_status ConvertFromComStatus(const DO_DOWNLOAD_STATUS& plat platformStatus.ExtendedError, ConvertFromComState(platformStatus.State)); } -static std::error_code ConvertToComProperty(msdo::download_property key, DODownloadProperty& comProperty) -{ - switch (key) - { - case msdo::download_property::blocking_mode: - { - comProperty = DODownloadProperty_BlockingMode; - return DO_OK; - } - case msdo::download_property::callback_interface: - { - comProperty = DODownloadProperty_CallbackInterface; - return DO_OK; - } - case msdo::download_property::disallow_on_cellular: - { - comProperty = DODownloadProperty_DisallowOnCellular; - return DO_OK; - } - case msdo::download_property::caller_name: - { - comProperty = DODownloadProperty_DisplayName; - return DO_OK; - } - case msdo::download_property::catalog_id: - { - comProperty = DODownloadProperty_ContentId; - return DO_OK; - } - case msdo::download_property::correlation_vector: - { - comProperty = DODownloadProperty_CorrelationVector; - return DO_OK; - } - case msdo::download_property::cost_policy: - { - comProperty = DODownloadProperty_CostPolicy; - return DO_OK; - } - case msdo::download_property::decryption_info: - { - comProperty = DODownloadProperty_DecryptionInfo; - return DO_OK; - } - case msdo::download_property::download_file_path: - { - comProperty = DODownloadProperty_LocalPath; - return DO_OK; - } - case msdo::download_property::http_custom_auth_headers: - { - comProperty = DODownloadProperty::DODownloadProperty_HttpCustomAuthHeaders; - return DO_OK; - } - case msdo::download_property::http_custom_headers: - { - comProperty = DODownloadProperty_HttpCustomHeaders; - return DO_OK; - } - case msdo::download_property::id: - { - comProperty = DODownloadProperty_Id; - return DO_OK; - } - case msdo::download_property::integrity_check_info: - { - comProperty = DODownloadProperty_IntegrityCheckInfo; - return DO_OK; - } - case msdo::download_property::integrity_check_mandatory: - { - comProperty = DODownloadProperty_IntegrityCheckMandatory; - return DO_OK; - } - case msdo::download_property::network_token: - { - comProperty = DODownloadProperty_NetworkToken; - return DO_OK; - } - case msdo::download_property::no_progress_timeout_seconds: - { - comProperty = DODownloadProperty_NoProgressTimeoutSeconds; - return DO_OK; - } - case msdo::download_property::stream_interface: - { - comProperty = DODownloadProperty_StreamInterface; - return DO_OK; - } - case msdo::download_property::security_context: - { - comProperty = DODownloadProperty_SecurityContext; - return DO_OK; - } - case msdo::download_property::total_size_bytes: - { - comProperty = DODownloadProperty_TotalSizeBytes; - return DO_OK; - } - case msdo::download_property::uri: - { - comProperty = DODownloadProperty_Uri; - return DO_OK; - } - case msdo::download_property::use_foreground_priority: - { - comProperty = DODownloadProperty_ForegroundPriority; - return DO_OK; - } - default: - { - return make_error_code(E_INVALIDARG); - } - } +static std::error_code ConvertToComProperty(msdo::download_property prop, DODownloadProperty& comProperty) +{ + static const DODownloadProperty c_propMap[] = + { + DODownloadProperty_Id, // id + DODownloadProperty_Uri, // uri + DODownloadProperty_ContentId, // catalog_id + DODownloadProperty_DisplayName, // caller_name + DODownloadProperty_LocalPath, // download_file_path + DODownloadProperty_HttpCustomHeaders, // http_custom_headers + DODownloadProperty_CostPolicy, // cost_policy + DODownloadProperty_SecurityFlags, // security_flags + DODownloadProperty_CallbackFreqPercent, // callback_freq_percent + DODownloadProperty_CallbackFreqSeconds, // callback_freq_seconds + DODownloadProperty_NoProgressTimeoutSeconds, // no_progress_timeout_seconds + DODownloadProperty_ForegroundPriority, // use_foreground_priority + DODownloadProperty_BlockingMode, // blocking_mode + DODownloadProperty_NetworkToken, // network_token + DODownloadProperty_CorrelationVector, // correlation_vector + DODownloadProperty_DecryptionInfo, // decryption_info + DODownloadProperty_IntegrityCheckInfo, // integrity_check_info + DODownloadProperty_IntegrityCheckMandatory, // integrity_check_mandatory + DODownloadProperty_TotalSizeBytes, // total_size_bytes + DODownloadProperty_DisallowOnCellular, // disallow_on_cellular + DODownloadProperty_HttpCustomAuthHeaders, // http_custom_auth_headers + DODownloadProperty_HttpAllowSecureToNonSecureRedirect, // allow_http_to_https_redirect + DODownloadProperty_NonVolatile, // non_volatile + }; + auto index = static_cast(prop); + if (index >= ARRAYSIZE(c_propMap)) + { + return make_error_code(errc::invalid_arg); + } + comProperty = c_propMap[index]; + return DO_OK; } class DOStatusCallback : public RuntimeClass, IDODownloadStatusCallback> { public: - HRESULT RuntimeClassInitialize(const msdo::download_property_value::status_callback_t& callback, msdo::download& download) + HRESULT RuntimeClassInitialize(const msdo::status_callback_t& callback, msdo::download& download) { _download = &download; _callback = callback; @@ -213,7 +101,7 @@ class DOStatusCallback : } private: - msdo::download_property_value::status_callback_t _callback; + msdo::status_callback_t _callback; msdo::download* _download; }; @@ -233,11 +121,11 @@ std::error_code CDownloadImpl::Init(const std::string& uri, const std::string& d DO_RETURN_IF_FAILED(download_property_value::make(uri, propUri)); DO_RETURN_IF_FAILED(download_property_value::make(downloadFilePath, propDownloadFilePath)); - DO_RETURN_IF_FAILED(_SetPropertyHelper(*spDownload.Get(), download_property::uri, propUri)); - DO_RETURN_IF_FAILED(_SetPropertyHelper(*spDownload.Get(), download_property::download_file_path, propDownloadFilePath)); + DO_RETURN_IF_FAILED(SetProperty(download_property::uri, propUri)); + DO_RETURN_IF_FAILED(SetProperty(download_property::download_file_path, propDownloadFilePath)); _spDownload = std::move(spDownload); - return DO_OK;; + return DO_OK; } // Support only full file downloads for now @@ -276,45 +164,56 @@ std::error_code CDownloadImpl::GetStatus(msdo::download_status& status) noexcept return DO_OK; } -std::error_code CDownloadImpl::GetProperty(msdo::download_property key, msdo::download_property_value& value) noexcept -{ - return _GetPropertyHelper(key, value); -} - -std::error_code CDownloadImpl::SetProperty(msdo::download_property key, const msdo::download_property_value& val) noexcept -{ - assert(key != msdo::download_property::callback_interface); - return _SetPropertyHelper(*_spDownload.Get(), key, val); -} - -std::error_code CDownloadImpl::SetCallback(const download_property_value::status_callback_t& callback, download& download) noexcept +std::error_code CDownloadImpl::SetStatusCallback(const msdo::status_callback_t& callback, msdo::download& download) noexcept { Microsoft::WRL::ComPtr spCallback; RETURN_IF_FAILED(MakeAndInitialize(&spCallback, callback, download)); - VARIANT vtCallback; - VariantInit(&vtCallback); + unique_variant vtCallback; V_VT(&vtCallback) = VT_UNKNOWN; - V_UNKNOWN(&vtCallback) = spCallback.Get(); - spCallback.Get()->AddRef(); - DODownloadProperty prop; - ConvertToComProperty(msdo::download_property::callback_interface, prop); - const auto hr = _spDownload->SetProperty(prop, &vtCallback); - VariantClear(&vtCallback); - return make_error_code(hr); + V_UNKNOWN(&vtCallback) = spCallback.Detach(); + RETURN_IF_FAILED(_spDownload->SetProperty(DODownloadProperty_CallbackInterface, &vtCallback)); + return DO_OK; } -std::error_code CDownloadImpl::_SetPropertyHelper(IDODownload& download, msdo::download_property key, const msdo::download_property_value& val) noexcept +std::error_code CDownloadImpl::SetProperty(msdo::download_property key, const msdo::download_property_value& val) noexcept { DODownloadProperty prop; DO_RETURN_IF_FAILED(ConvertToComProperty(key, prop)); - - return make_error_code(download.SetProperty(prop, &val._val->native_value())); + RETURN_IF_FAILED(_spDownload->SetProperty(prop, &val._val->native_value())); + return DO_OK; } -std::error_code CDownloadImpl::_GetPropertyHelper(msdo::download_property key, msdo::download_property_value& value) noexcept +std::error_code CDownloadImpl::GetProperty(msdo::download_property key, msdo::download_property_value& value) noexcept { - return make_error_code(errc::e_not_impl); + DODownloadProperty prop; + DO_RETURN_IF_FAILED(ConvertToComProperty(key, prop)); + + unique_variant var; + RETURN_IF_FAILED(_spDownload->GetProperty(prop, &var)); + + switch (V_VT(&var)) + { + case VT_BOOL: + DO_RETURN_IF_FAILED(download_property_value::make(var.boolVal != VARIANT_FALSE, value)); + break; + + case VT_UI4: + DO_RETURN_IF_FAILED(download_property_value::make(var.uintVal, value)); + break; + + case VT_UI8: + DO_RETURN_IF_FAILED(download_property_value::make(var.ullVal, value)); + break; + + case VT_BSTR: + DO_RETURN_IF_FAILED(download_property_value::make(var.bstrVal, value)); + break; + + default: + return make_error_code(E_UNEXPECTED); + } + return DO_OK; } } // namespace details diff --git a/sdk-cpp/src/internal/do_download_property_internal.h b/sdk-cpp/src/internal/do_download_property_internal.h index e7959451..00ce1cd8 100644 --- a/sdk-cpp/src/internal/do_download_property_internal.h +++ b/sdk-cpp/src/internal/do_download_property_internal.h @@ -10,7 +10,6 @@ #include #endif -#include #include #include @@ -24,13 +23,28 @@ namespace deliveryoptimization namespace details { +#if defined(DO_INTERFACE_COM) +struct unique_variant : VARIANT +{ + unique_variant(); + explicit unique_variant(const VARIANT& other) noexcept; // takes ownership via shallow copy + unique_variant(const unique_variant& other); // true copy + unique_variant(unique_variant&& other) noexcept; + unique_variant& operator=(unique_variant&& other); + ~unique_variant(); + + unique_variant& operator=(const unique_variant&) = delete; + unique_variant& operator=(const VARIANT&) = delete; +}; +#endif + class CDownloadPropertyValueInternal { public: #if defined(DO_INTERFACE_COM) - using native_type = VARIANT; + using native_type = unique_variant; #else - using native_type = boost::variant>; + using native_type = boost::variant; #endif CDownloadPropertyValueInternal(); @@ -38,8 +52,6 @@ class CDownloadPropertyValueInternal std::error_code Init(uint32_t val) noexcept; std::error_code Init(uint64_t val) noexcept; std::error_code Init(bool val) noexcept; - std::error_code Init(std::vector& val) noexcept; - std::error_code Init(const download_property_value::status_callback_t& val) noexcept; ~CDownloadPropertyValueInternal(); @@ -50,21 +62,22 @@ class CDownloadPropertyValueInternal friend void swap(CDownloadPropertyValueInternal& first, CDownloadPropertyValueInternal& second) noexcept { std::swap(first._var, second._var); - std::swap(first._callback, second._callback); } std::error_code As(bool& val) const noexcept; std::error_code As(uint32_t& val) const noexcept; std::error_code As(uint64_t& val) const noexcept; std::error_code As(std::string& val) const noexcept; - std::error_code As(download_property_value::status_callback_t& val) const noexcept; - std::error_code As(std::vector& val) const noexcept; + +#if defined(DO_INTERFACE_COM) + std::error_code Init(const std::wstring& val) noexcept; + std::error_code As(std::wstring& val) const noexcept; +#endif const native_type& native_value() const noexcept; private: native_type _var; - download_property_value::status_callback_t _callback; }; } // namespace details diff --git a/sdk-cpp/src/internal/do_error_helpers.h b/sdk-cpp/src/internal/do_error_helpers.h index db5055fb..bf4307d9 100644 --- a/sdk-cpp/src/internal/do_error_helpers.h +++ b/sdk-cpp/src/internal/do_error_helpers.h @@ -53,6 +53,16 @@ inline std::error_code make_error_code(errc e) return std::error_code(static_cast(e), do_category()); } +#ifndef FAILED +#define FAILED(hr) (((int32_t)(hr)) < 0) +#endif + +#ifndef RETURN_IF_FAILED +#define RETURN_IF_FAILED(hr) { \ + int32_t __hr = (hr); \ + if (FAILED(__hr)) return std::error_code(__hr, do_category()); } +#endif + #ifdef DO_ENABLE_EXCEPTIONS class exception : public std::exception diff --git a/sdk-cpp/src/internal/download_impl.h b/sdk-cpp/src/internal/download_impl.h index c1858ffb..ab058d1c 100644 --- a/sdk-cpp/src/internal/download_impl.h +++ b/sdk-cpp/src/internal/download_impl.h @@ -14,7 +14,8 @@ #if defined(DO_INTERFACE_COM) #include -#include "do.hpp" // Fwd declaration of IDODownload doesn't work well w/ all build systems +// Future: delete the local copy of deliveryoptimization.h and require Windows SDK 22621+ +#include // IDODownload, etc. #endif namespace microsoft @@ -37,16 +38,12 @@ class CDownloadImpl : public IDownload std::error_code Abort() noexcept override; std::error_code GetStatus(download_status& status) noexcept override; + std::error_code SetStatusCallback(const status_callback_t& callback, download& download) noexcept override; std::error_code GetProperty(download_property key, download_property_value& value) noexcept override; std::error_code SetProperty(download_property key, const download_property_value& val) noexcept override; - std::error_code SetCallback(const download_property_value::status_callback_t& callback, download& download) noexcept override; private: - #if defined(DO_INTERFACE_COM) - static std::error_code _SetPropertyHelper(IDODownload& download, download_property key, const download_property_value& val) noexcept; - std::error_code _GetPropertyHelper(download_property key, download_property_value& value) noexcept; - Microsoft::WRL::ComPtr _spDownload; #elif defined(DO_INTERFACE_REST) std::error_code _DownloadOperationCall(const std::string& type) noexcept; diff --git a/sdk-cpp/src/internal/download_interface.h b/sdk-cpp/src/internal/download_interface.h index d00a4eeb..4f661fec 100644 --- a/sdk-cpp/src/internal/download_interface.h +++ b/sdk-cpp/src/internal/download_interface.h @@ -5,7 +5,6 @@ #define _DELIVERY_OPTIMIZATION_DOWNLOAD_INTERFACE_H #include "do_download_status.h" - #include "do_download_property.h" class download; @@ -31,10 +30,10 @@ class IDownload virtual std::error_code Abort() noexcept = 0; virtual std::error_code GetStatus(download_status& status) noexcept = 0; + virtual std::error_code SetStatusCallback(const status_callback_t& callback, download& download) noexcept = 0; virtual std::error_code GetProperty(download_property key, download_property_value& value) noexcept = 0; virtual std::error_code SetProperty(download_property key, const download_property_value& val) noexcept = 0; - virtual std::error_code SetCallback(const download_property_value::status_callback_t& callback, download& download) noexcept = 0; }; } // namespace details } // namespace deliveryoptimization diff --git a/sdk-cpp/src/internal/rest/do_download_property_internal.cpp b/sdk-cpp/src/internal/rest/do_download_property_internal.cpp index b53d2716..977cf76d 100644 --- a/sdk-cpp/src/internal/rest/do_download_property_internal.cpp +++ b/sdk-cpp/src/internal/rest/do_download_property_internal.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include "do_errors.h" @@ -40,16 +39,6 @@ std::error_code CDownloadPropertyValueInternal::Init(bool val) noexcept return make_error_code(errc::e_not_impl); } -std::error_code CDownloadPropertyValueInternal::Init(std::vector& val) noexcept -{ - return make_error_code(errc::e_not_impl); -} - -std::error_code CDownloadPropertyValueInternal::Init(const download_property_value::status_callback_t& val) noexcept -{ - return make_error_code(errc::e_not_impl); -} - CDownloadPropertyValueInternal::~CDownloadPropertyValueInternal() { } @@ -57,7 +46,6 @@ CDownloadPropertyValueInternal::~CDownloadPropertyValueInternal() CDownloadPropertyValueInternal::CDownloadPropertyValueInternal(const CDownloadPropertyValueInternal& rhs) { _var = rhs._var; - _callback = rhs._callback; } CDownloadPropertyValueInternal& CDownloadPropertyValueInternal::operator=(CDownloadPropertyValueInternal copy) @@ -70,7 +58,6 @@ CDownloadPropertyValueInternal::CDownloadPropertyValueInternal(CDownloadProperty { _var = rhs._var; rhs._var = {}; - _callback = std::move(rhs._callback); } const CDownloadPropertyValueInternal::native_type& CDownloadPropertyValueInternal::native_value() const noexcept @@ -98,17 +85,6 @@ std::error_code CDownloadPropertyValueInternal::As(std::string& val) const noexc return make_error_code(errc::e_not_impl); } -std::error_code CDownloadPropertyValueInternal::As(std::vector& val) const noexcept -{ - return make_error_code(errc::e_not_impl); -} - -std::error_code CDownloadPropertyValueInternal::As(download_property_value::status_callback_t& val) const noexcept -{ - val = _callback; - return DO_OK; -} - } // namespace details } // namespace deliveryoptimization } // namespace microsoft diff --git a/sdk-cpp/src/internal/rest/download_impl.cpp b/sdk-cpp/src/internal/rest/download_impl.cpp index 41b726b0..786815ed 100644 --- a/sdk-cpp/src/internal/rest/download_impl.cpp +++ b/sdk-cpp/src/internal/rest/download_impl.cpp @@ -142,7 +142,7 @@ std::error_code CDownloadImpl::SetProperty(msdo::download_property key, const ms return make_error_code(msdo::errc::e_not_impl); } -std::error_code CDownloadImpl::SetCallback(const download_property_value::status_callback_t& callback, download& download) noexcept +std::error_code CDownloadImpl::SetStatusCallback(const status_callback_t& callback, download& download) noexcept { return make_error_code(msdo::errc::e_not_impl); } diff --git a/sdk-cpp/tests/download_properties_tests.cpp b/sdk-cpp/tests/download_properties_tests.cpp index 3afe3df2..37788af1 100644 --- a/sdk-cpp/tests/download_properties_tests.cpp +++ b/sdk-cpp/tests/download_properties_tests.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include "do_download.h" @@ -14,6 +13,7 @@ #include "test_helpers.h" namespace msdo = microsoft::deliveryoptimization; +namespace msdot = microsoft::deliveryoptimization::test; using namespace std::chrono_literals; class DownloadPropertyTests : public ::testing::Test @@ -36,12 +36,6 @@ class DownloadPropertyTests : public ::testing::Test { ASSERT_TRUE(std::find(expectedErrors.begin(), expectedErrors.end(), code) != expectedErrors.end()); } - - static void VerifyCallWithExpectedErrors(const std::function& op, const std::vector& expectedErrors) - { - auto ec = op(); - VerifyError(ec.value(), expectedErrors); - } #endif }; @@ -56,68 +50,35 @@ static uint32_t TimeOperation(const std::function& op) return static_cast(std::chrono::duration_cast(end - start).count()); } -static std::unique_ptr g_MakeDownload(const std::string& url, const std::string& destPath) -{ - std::unique_ptr downloadObj; - auto ec = msdo::download::make(url, destPath, downloadObj); - if (ec) throw std::exception(); - - // msdo::download_property_value propUri; - // auto ec = msdo::download_property_value::make(url, propUri); - // if (ec) throw std::exception(); - // ec = obj.set_property(msdo::download_property::uri, propUri); - // if (ec) throw std::exception(); - - // msdo::download_property_value propFilePath; - // ec = msdo::download_property_value::make(destPath, propFilePath); - // ec = obj.set_property(msdo::download_property::uri, propFilePath); - // if (ec) throw std::exception(); - - return downloadObj; -} - -template -static msdo::download_property_value g_MakePropertyValue(T value) -{ - msdo::download_property_value propValue; - auto ec = msdo::download_property_value::make(value, propValue); - if (ec) - { - throw std::exception(); - } - return propValue; -} - -//TODO: Not sure how much value these tests are, functional tests utilize parsing log lines to verify these properties were set, could be useful here -//At the moment, these tests are essentially just verifying that these properties can be set and download succeeds TEST_F(DownloadPropertyTests, SmallDownloadSetCallerNameTest) { - auto simpleDownload = g_MakeDownload(g_smallFileUrl, g_tmpFileName); + auto simpleDownload = msdot::download::make(g_smallFileUrl, g_tmpFileName); std::string strCallerName("dosdkcpp_tests"); - msdo::download_property_value callerName = g_MakePropertyValue(strCallerName); - ASSERT_EQ(simpleDownload->set_property(msdo::download_property::caller_name, callerName).value(), 0); - ASSERT_EQ(simpleDownload->start_and_wait_until_completion().value(), 0); + simpleDownload->set_property(msdo::download_property::caller_name, strCallerName); + + std::string outCallerName; + simpleDownload->get_property(msdo::download_property::caller_name, outCallerName); + ASSERT_EQ(strCallerName, outCallerName); + + simpleDownload->start_and_wait_until_completion(); ASSERT_TRUE(boost::filesystem::exists(g_tmpFileName)); } TEST_F(DownloadPropertyTests, SmallDownloadWithPhfDigestandCvTest) { - auto simpleDownload = g_MakeDownload(g_smallFileUrl, g_tmpFileName); + std::unique_ptr simpleDownload; + ASSERT_EQ(msdo::download::make(g_smallFileUrl, g_tmpFileName, simpleDownload).value(), 0); std::vector expectedErrors = { 0, static_cast(msdo::errc::do_e_unknown_property_id) }; - msdo::download_property_value integrityCheckMandatory = g_MakePropertyValue(false); - int32_t code = simpleDownload->set_property(msdo::download_property::integrity_check_mandatory, integrityCheckMandatory).value(); + int32_t code = simpleDownload->set_property(msdo::download_property::integrity_check_mandatory, false).value(); VerifyError(code, expectedErrors); - msdo::download_property_value integrityCheckInfo = g_MakePropertyValue(g_smallFilePhfInfoJson); - code = simpleDownload->set_property(msdo::download_property::integrity_check_info, integrityCheckInfo).value(); + code = simpleDownload->set_property(msdo::download_property::integrity_check_info, g_smallFilePhfInfoJson).value(); VerifyError(code, expectedErrors); - std::string strCorrelationVector("g+Vo71JZwkmJdYfF.0"); - msdo::download_property_value correlationVector = g_MakePropertyValue(strCorrelationVector); - code = simpleDownload->set_property(msdo::download_property::correlation_vector, correlationVector).value(); + code = simpleDownload->set_property(msdo::download_property::correlation_vector, "g+Vo71JZwkmJdYfF.0").value(); VerifyError(code, expectedErrors); ASSERT_EQ(simpleDownload->start_and_wait_until_completion().value(), 0); @@ -127,36 +88,29 @@ TEST_F(DownloadPropertyTests, SmallDownloadWithPhfDigestandCvTest) TEST_F(DownloadPropertyTests, InvalidPhfDigestTest) { - auto simpleDownload = g_MakeDownload(g_smallFileUrl, g_tmpFileName); + std::unique_ptr simpleDownload; + ASSERT_EQ(msdo::download::make(g_smallFileUrl, g_tmpFileName, simpleDownload).value(), 0); - msdo::download_property_value integrityCheckInfo = g_MakePropertyValue("blah"); std::vector expectedErrors = { 0, static_cast(msdo::errc::invalid_arg) }; - VerifyCallWithExpectedErrors([&]() - { - return simpleDownload->set_property(msdo::download_property::integrity_check_info, integrityCheckInfo); - }, expectedErrors); + + int32_t code = simpleDownload->set_property(msdo::download_property::integrity_check_info, "blah").value(); + VerifyError(code, expectedErrors); } -// For some reason, custom headers are getting rejected and returning E_INVALIDARG now, disabling test for now -TEST_F(DownloadPropertyTests, DISABLED_SmallDownloadWithCustomHeaders) +TEST_F(DownloadPropertyTests, SmallDownloadWithCustomHeaders) { - auto simpleDownload = g_MakeDownload(g_smallFileUrl, g_tmpFileName); - - std::string strHttpCustomHeaders("XCustom1=someData\nXCustom2=moreData"); - msdo::download_property_value httpCustomHeaders = g_MakePropertyValue(strHttpCustomHeaders); - simpleDownload->set_property(msdo::download_property::http_custom_headers, httpCustomHeaders); - + auto simpleDownload = msdot::download::make(g_smallFileUrl, g_tmpFileName); + simpleDownload->set_property(msdo::download_property::http_custom_headers, "XCustom1=someData\nXCustom2=moreData\n"); simpleDownload->start_and_wait_until_completion(); - ASSERT_TRUE(boost::filesystem::exists(g_tmpFileName)); } TEST_F(DownloadPropertyTests, CallbackTestUseDownload) { - auto simpleDownload = g_MakeDownload(g_largeFileUrl, g_tmpFileName); - bool fPauseDownload = false; + auto simpleDownload = msdot::download::make(g_largeFileUrl, g_tmpFileName); - msdo::download_property_value callback = g_MakePropertyValue([&fPauseDownload](msdo::download& download, msdo::download_status& status) + bool fPauseDownload = false; + auto callback = [&fPauseDownload](msdo::download& download, msdo::download_status& status) { char msgBuf[1024]; snprintf(msgBuf, sizeof(msgBuf), "Received status callback: %" PRIu64 "/%" PRIu64 ", 0x%x, 0x%x, %u", @@ -170,23 +124,22 @@ TEST_F(DownloadPropertyTests, CallbackTestUseDownload) { ASSERT_EQ(download.pause().value(), 0); } - }); + }; - ASSERT_EQ(simpleDownload->set_property(msdo::download_property::callback_interface, callback).value(), 0); - ASSERT_EQ(simpleDownload->start().value(), 0); + simpleDownload->set_status_callback(callback); + simpleDownload->start(); std::this_thread::sleep_for(5s); fPauseDownload = true; - microsoft::deliveryoptimization::test::download testDownload{std::move(simpleDownload)}; - TestHelpers::WaitForState(testDownload, msdo::download_state::paused); + TestHelpers::WaitForState(*simpleDownload, msdo::download_state::paused); } TEST_F(DownloadPropertyTests, SetCallbackTest) { - auto simpleDownload = g_MakeDownload(g_smallFileUrl, g_tmpFileName); + auto simpleDownload = msdot::download::make(g_smallFileUrl, g_tmpFileName); int i= 0; - msdo::download_property_value callback = g_MakePropertyValue([&i](msdo::download&, msdo::download_status& status) + auto callback = [&i](msdo::download&, msdo::download_status& status) { char msgBuf[1024]; snprintf(msgBuf, sizeof(msgBuf), "Received status callback: %" PRIu64 "/%" PRIu64 ", 0x%x, 0x%x, %u", @@ -194,32 +147,21 @@ TEST_F(DownloadPropertyTests, SetCallbackTest) static_cast(status.state())); std::cout << msgBuf << std::endl; i += 1; - }); - ASSERT_EQ(simpleDownload->set_property(msdo::download_property::callback_interface, callback).value(), 0); + }; + simpleDownload->set_status_callback(callback); - ASSERT_EQ(simpleDownload->start_and_wait_until_completion().value(), 0); + simpleDownload->start_and_wait_until_completion(); ASSERT_GE(i, 0); } TEST_F(DownloadPropertyTests, OverrideCallbackTest) { - auto simpleDownload = g_MakeDownload(g_smallFileUrl, g_tmpFileName); - + auto simpleDownload = msdot::download::make(g_smallFileUrl, g_tmpFileName); int i = 0; - msdo::download_property_value callback = g_MakePropertyValue([&i](msdo::download&, msdo::download_status&) - { - i += 1; - }); - ASSERT_EQ(simpleDownload->set_property(msdo::download_property::callback_interface, callback).value(), 0); - - msdo::download_property_value::status_callback_t cb2 = [](msdo::download&, msdo::download_status&) {}; - - callback = g_MakePropertyValue(cb2); - ASSERT_EQ(simpleDownload->set_property(msdo::download_property::callback_interface, callback).value(), 0); - - ASSERT_EQ(simpleDownload->start_and_wait_until_completion().value(), 0); - + simpleDownload->set_status_callback([&i](msdo::download&, msdo::download_status&){ i += 1; }); + simpleDownload->set_status_callback([](msdo::download&, msdo::download_status&){}); + simpleDownload->start_and_wait_until_completion(); ASSERT_EQ(i, 0); } @@ -227,23 +169,29 @@ TEST_F(DownloadPropertyTests, ForegroundBackgroundRace) { uint32_t backgroundDuration = TimeOperation([&]() { - auto simpleDownload = g_MakeDownload(g_largeFileUrl, g_tmpFileName); + auto simpleDownload = msdot::download::make(g_largeFileUrl, g_tmpFileName); + + simpleDownload->set_property(msdo::download_property::use_foreground_priority, false); - msdo::download_property_value foregroundPriority = g_MakePropertyValue(false); - ASSERT_EQ(simpleDownload->set_property(msdo::download_property::use_foreground_priority, foregroundPriority).value(), 0); + bool outVal = true; + simpleDownload->get_property(msdo::download_property::use_foreground_priority, outVal); + ASSERT_FALSE(outVal); - ASSERT_EQ(simpleDownload->start_and_wait_until_completion().value(), 0); + simpleDownload->start_and_wait_until_completion(); }); printf("Time for background download: %u ms\n", backgroundDuration); uint32_t foregroundDuration = TimeOperation([&]() { - auto simpleDownload = g_MakeDownload(g_largeFileUrl, g_tmpFileName2); + auto simpleDownload = msdot::download::make(g_largeFileUrl, g_tmpFileName2); - msdo::download_property_value foregroundPriority = g_MakePropertyValue(true); - ASSERT_EQ(simpleDownload->set_property(msdo::download_property::use_foreground_priority, foregroundPriority).value(), 0); + simpleDownload->set_property(msdo::download_property::use_foreground_priority, true); - ASSERT_EQ(simpleDownload->start_and_wait_until_completion().value(), 0); + bool outVal = false; + simpleDownload->get_property(msdo::download_property::use_foreground_priority, outVal); + ASSERT_TRUE(outVal); + + simpleDownload->start_and_wait_until_completion(); }); printf("Time for foreground download: %u ms\n", foregroundDuration); @@ -254,9 +202,8 @@ TEST_F(DownloadPropertyTests, ForegroundBackgroundRace) TEST_F(DownloadPropertyTests, SmallDownloadSetCallerNameFailureTest) { - std::string strCallerName("dosdkcpp_tests"); msdo::download_property_value callerName; - auto ec = msdo::download_property_value::make(strCallerName, callerName); + auto ec = msdo::download_property_value::make("dosdkcpp_tests", callerName); ASSERT_EQ(ec.value(), static_cast(msdo::errc::e_not_impl)); } diff --git a/sdk-cpp/tests/test_helpers.h b/sdk-cpp/tests/test_helpers.h index 3736d115..ef1a6187 100644 --- a/sdk-cpp/tests/test_helpers.h +++ b/sdk-cpp/tests/test_helpers.h @@ -75,6 +75,11 @@ class download msdod::throw_if_fail(ec); return status; } + void set_status_callback(status_callback_t callback) + { + std::error_code ec = _downloadImpl->set_status_callback(callback); + msdod::throw_if_fail(ec); + } void start_and_wait_until_completion(std::chrono::seconds timeoutSecs = std::chrono::hours(24)) { @@ -100,22 +105,17 @@ class download msdod::throw_if_fail(ec); } - /* - For devices running windows before 20H1, dosvc exposed a now-deprecated com interface for setting certain download properties. - After 20H1, these properties were added to newer com interface, which this SDK is using. - Attempting to set a download property on a version of windows earlier than 20H1 will not set the property and throw an exception with error code msdo::errc::do_e_unknown_property_id - */ - void set_property(msdo::download_property key, const msdo::download_property_value& value) + template + void set_property(msdo::download_property key, const T& value) { std::error_code ec = _downloadImpl->set_property(key, value); msdod::throw_if_fail(ec); } - msdo::download_property_value get_property(msdo::download_property key) + template + void get_property(msdo::download_property key, T& value) { - msdo::download_property_value propValue; - std::error_code ec = _downloadImpl->get_property(key, propValue); + std::error_code ec = _downloadImpl->get_property(key, value); msdod::throw_if_fail(ec); - return propValue; } private: From 302eb8fde9a58fe0be206c3da5066ebd769af55d Mon Sep 17 00:00:00 2001 From: Jeffrey Saathoff Date: Thu, 2 Feb 2023 17:26:51 -0800 Subject: [PATCH 2/5] Fix SetProperty calls in CDownloadImpl::Init --- sdk-cpp/src/do_download_property.cpp | 22 ++++++++++------------ sdk-cpp/src/internal/com/download_impl.cpp | 5 ++--- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/sdk-cpp/src/do_download_property.cpp b/sdk-cpp/src/do_download_property.cpp index 907789f6..ddb4a43a 100644 --- a/sdk-cpp/src/do_download_property.cpp +++ b/sdk-cpp/src/do_download_property.cpp @@ -28,18 +28,6 @@ std::error_code download_property_value::make(const std::string& val, download_p return DO_OK; } -#if defined(DO_INTERFACE_COM) -std::error_code download_property_value::make(const std::wstring& val, download_property_value& out) -{ - download_property_value temp; - std::error_code code = temp._val->Init(val); - DO_RETURN_IF_FAILED(code); - - out = temp; - return DO_OK; -} -#endif - std::error_code download_property_value::make(uint32_t val, download_property_value& out) { download_property_value temp; @@ -91,6 +79,16 @@ std::error_code download_property_value::as(std::string& val) const noexcept } #if defined(DO_INTERFACE_COM) +std::error_code download_property_value::make(const std::wstring& val, download_property_value& out) +{ + download_property_value temp; + std::error_code code = temp._val->Init(val); + DO_RETURN_IF_FAILED(code); + + out = temp; + return DO_OK; +} + std::error_code download_property_value::as(std::wstring& val) const noexcept { return _val->As(val); diff --git a/sdk-cpp/src/internal/com/download_impl.cpp b/sdk-cpp/src/internal/com/download_impl.cpp index 216bb85c..fb4421d8 100644 --- a/sdk-cpp/src/internal/com/download_impl.cpp +++ b/sdk-cpp/src/internal/com/download_impl.cpp @@ -3,8 +3,6 @@ #include "download_impl.h" -#include - #include #include #include @@ -116,6 +114,8 @@ std::error_code CDownloadImpl::Init(const std::string& uri, const std::string& d RPC_C_AUTHZ_NONE, COLE_DEFAULT_PRINCIPAL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, EOAC_STATIC_CLOAKING)); + _spDownload = std::move(spDownload); + download_property_value propUri; download_property_value propDownloadFilePath; DO_RETURN_IF_FAILED(download_property_value::make(uri, propUri)); @@ -124,7 +124,6 @@ std::error_code CDownloadImpl::Init(const std::string& uri, const std::string& d DO_RETURN_IF_FAILED(SetProperty(download_property::uri, propUri)); DO_RETURN_IF_FAILED(SetProperty(download_property::download_file_path, propDownloadFilePath)); - _spDownload = std::move(spDownload); return DO_OK; } From e67195400e921221212e7e9db988f5ab89870564 Mon Sep 17 00:00:00 2001 From: Jeffrey Saathoff Date: Fri, 3 Feb 2023 17:47:09 -0800 Subject: [PATCH 3/5] Remove unnecessary constructors and declare A/W throughout --- sdk-cpp/include/do_download_property.h | 7 +--- sdk-cpp/src/do_download_property.cpp | 22 +++++----- .../com/do_download_property_internal.cpp | 41 +------------------ .../internal/do_download_property_internal.h | 26 ++++-------- .../rest/do_download_property_internal.cpp | 38 +++++------------ 5 files changed, 30 insertions(+), 104 deletions(-) diff --git a/sdk-cpp/include/do_download_property.h b/sdk-cpp/include/do_download_property.h index ab794e52..2b21ffcc 100644 --- a/sdk-cpp/include/do_download_property.h +++ b/sdk-cpp/include/do_download_property.h @@ -85,7 +85,9 @@ friend class details::CDownloadImpl; ~download_property_value() = default; static std::error_code make(const std::string& val, download_property_value& out); + static std::error_code make(const std::wstring& val, download_property_value& out); static std::error_code make(const char* val, download_property_value& out) { return make(std::string(val), out); } + static std::error_code make(const wchar_t* val, download_property_value& out) { return make(std::wstring(val), out); } static std::error_code make(uint32_t val, download_property_value& out); static std::error_code make(uint64_t val, download_property_value& out); static std::error_code make(bool val, download_property_value& out); @@ -94,12 +96,7 @@ friend class details::CDownloadImpl; std::error_code as(uint32_t& val) const noexcept; std::error_code as(uint64_t& val) const noexcept; std::error_code as(std::string& val) const noexcept; - -#if defined(DO_INTERFACE_COM) - static std::error_code make(const std::wstring& val, download_property_value& out); - static std::error_code make(const wchar_t* val, download_property_value& out) { return make(std::wstring(val), out); } std::error_code as(std::wstring& val) const noexcept; -#endif private: std::shared_ptr _val; diff --git a/sdk-cpp/src/do_download_property.cpp b/sdk-cpp/src/do_download_property.cpp index ddb4a43a..ba20ed31 100644 --- a/sdk-cpp/src/do_download_property.cpp +++ b/sdk-cpp/src/do_download_property.cpp @@ -28,6 +28,16 @@ std::error_code download_property_value::make(const std::string& val, download_p return DO_OK; } +std::error_code download_property_value::make(const std::wstring& val, download_property_value& out) +{ + download_property_value temp; + std::error_code code = temp._val->Init(val); + DO_RETURN_IF_FAILED(code); + + out = temp; + return DO_OK; +} + std::error_code download_property_value::make(uint32_t val, download_property_value& out) { download_property_value temp; @@ -78,22 +88,10 @@ std::error_code download_property_value::as(std::string& val) const noexcept return _val->As(val); } -#if defined(DO_INTERFACE_COM) -std::error_code download_property_value::make(const std::wstring& val, download_property_value& out) -{ - download_property_value temp; - std::error_code code = temp._val->Init(val); - DO_RETURN_IF_FAILED(code); - - out = temp; - return DO_OK; -} - std::error_code download_property_value::as(std::wstring& val) const noexcept { return _val->As(val); } -#endif } // deliveryoptimization } // microsoft diff --git a/sdk-cpp/src/internal/com/do_download_property_internal.cpp b/sdk-cpp/src/internal/com/do_download_property_internal.cpp index bf8e515f..c5cb639e 100644 --- a/sdk-cpp/src/internal/com/do_download_property_internal.cpp +++ b/sdk-cpp/src/internal/com/do_download_property_internal.cpp @@ -63,23 +63,13 @@ unique_variant::unique_variant(const VARIANT& other) noexcept : { } -unique_variant::unique_variant(const unique_variant& other) -{ - HRESULT res = VariantCopy(this, &other); - assert(SUCCEEDED(res)); - if (FAILED(res)) - { - std::terminate(); - } -} - unique_variant::unique_variant(unique_variant&& other) noexcept : VARIANT(other) { VariantInit(&other); } -unique_variant& unique_variant::operator=(unique_variant&& other) +unique_variant& unique_variant::operator=(unique_variant&& other) noexcept { VariantClear(this); VARIANT::operator=(other); @@ -92,10 +82,6 @@ unique_variant::~unique_variant() VariantClear(this); } -CDownloadPropertyValueInternal::CDownloadPropertyValueInternal() -{ -} - std::error_code CDownloadPropertyValueInternal::Init(const std::string& val) noexcept { std::wstring wval; @@ -137,31 +123,6 @@ std::error_code CDownloadPropertyValueInternal::Init(bool val) noexcept return DO_OK; } -CDownloadPropertyValueInternal::~CDownloadPropertyValueInternal() -{ -} - -CDownloadPropertyValueInternal::CDownloadPropertyValueInternal(const CDownloadPropertyValueInternal& rhs) : - _var(rhs._var) -{ -} - -CDownloadPropertyValueInternal& CDownloadPropertyValueInternal::operator=(CDownloadPropertyValueInternal copy) -{ - swap(*this, copy); - return *this; -} - -CDownloadPropertyValueInternal::CDownloadPropertyValueInternal(CDownloadPropertyValueInternal&& rhs) noexcept : - _var(std::move(rhs._var)) -{ -} - -const CDownloadPropertyValueInternal::native_type& CDownloadPropertyValueInternal::native_value() const noexcept -{ - return _var; -} - std::error_code CDownloadPropertyValueInternal::As(bool& val) const noexcept { val = false; diff --git a/sdk-cpp/src/internal/do_download_property_internal.h b/sdk-cpp/src/internal/do_download_property_internal.h index 00ce1cd8..20fd1b92 100644 --- a/sdk-cpp/src/internal/do_download_property_internal.h +++ b/sdk-cpp/src/internal/do_download_property_internal.h @@ -28,11 +28,11 @@ struct unique_variant : VARIANT { unique_variant(); explicit unique_variant(const VARIANT& other) noexcept; // takes ownership via shallow copy - unique_variant(const unique_variant& other); // true copy unique_variant(unique_variant&& other) noexcept; - unique_variant& operator=(unique_variant&& other); + unique_variant& operator=(unique_variant&& other) noexcept; ~unique_variant(); + unique_variant(const unique_variant& other) = delete; unique_variant& operator=(const unique_variant&) = delete; unique_variant& operator=(const VARIANT&) = delete; }; @@ -46,35 +46,23 @@ class CDownloadPropertyValueInternal #else using native_type = boost::variant; #endif - CDownloadPropertyValueInternal(); + + CDownloadPropertyValueInternal() = default; + ~CDownloadPropertyValueInternal() = default; std::error_code Init(const std::string& val) noexcept; + std::error_code Init(const std::wstring& val) noexcept; std::error_code Init(uint32_t val) noexcept; std::error_code Init(uint64_t val) noexcept; std::error_code Init(bool val) noexcept; - ~CDownloadPropertyValueInternal(); - - CDownloadPropertyValueInternal(const CDownloadPropertyValueInternal& rhs); - CDownloadPropertyValueInternal& operator=(CDownloadPropertyValueInternal copy); - CDownloadPropertyValueInternal(CDownloadPropertyValueInternal&& rhs) noexcept; - - friend void swap(CDownloadPropertyValueInternal& first, CDownloadPropertyValueInternal& second) noexcept - { - std::swap(first._var, second._var); - } - std::error_code As(bool& val) const noexcept; std::error_code As(uint32_t& val) const noexcept; std::error_code As(uint64_t& val) const noexcept; std::error_code As(std::string& val) const noexcept; - -#if defined(DO_INTERFACE_COM) - std::error_code Init(const std::wstring& val) noexcept; std::error_code As(std::wstring& val) const noexcept; -#endif - const native_type& native_value() const noexcept; + const native_type& native_value() const noexcept { return _var; } private: native_type _var; diff --git a/sdk-cpp/src/internal/rest/do_download_property_internal.cpp b/sdk-cpp/src/internal/rest/do_download_property_internal.cpp index 977cf76d..2df79aca 100644 --- a/sdk-cpp/src/internal/rest/do_download_property_internal.cpp +++ b/sdk-cpp/src/internal/rest/do_download_property_internal.cpp @@ -17,52 +17,29 @@ namespace deliveryoptimization namespace details { -CDownloadPropertyValueInternal::CDownloadPropertyValueInternal() = default; - std::error_code CDownloadPropertyValueInternal::Init(const std::string& val) noexcept { return make_error_code(errc::e_not_impl); } -std::error_code CDownloadPropertyValueInternal::Init(uint32_t val) noexcept +std::error_code CDownloadPropertyValueInternal::Init(const std::wstring& val) noexcept { return make_error_code(errc::e_not_impl); } -std::error_code CDownloadPropertyValueInternal::Init(uint64_t val) noexcept +std::error_code CDownloadPropertyValueInternal::Init(uint32_t val) noexcept { return make_error_code(errc::e_not_impl); } -std::error_code CDownloadPropertyValueInternal::Init(bool val) noexcept +std::error_code CDownloadPropertyValueInternal::Init(uint64_t val) noexcept { return make_error_code(errc::e_not_impl); } -CDownloadPropertyValueInternal::~CDownloadPropertyValueInternal() -{ -} - -CDownloadPropertyValueInternal::CDownloadPropertyValueInternal(const CDownloadPropertyValueInternal& rhs) -{ - _var = rhs._var; -} - -CDownloadPropertyValueInternal& CDownloadPropertyValueInternal::operator=(CDownloadPropertyValueInternal copy) -{ - swap(*this, copy); - return *this; -} - -CDownloadPropertyValueInternal::CDownloadPropertyValueInternal(CDownloadPropertyValueInternal&& rhs) noexcept -{ - _var = rhs._var; - rhs._var = {}; -} - -const CDownloadPropertyValueInternal::native_type& CDownloadPropertyValueInternal::native_value() const noexcept +std::error_code CDownloadPropertyValueInternal::Init(bool val) noexcept { - return _var; + return make_error_code(errc::e_not_impl); } std::error_code CDownloadPropertyValueInternal::As(bool& val) const noexcept @@ -85,6 +62,11 @@ std::error_code CDownloadPropertyValueInternal::As(std::string& val) const noexc return make_error_code(errc::e_not_impl); } +std::error_code CDownloadPropertyValueInternal::As(std::wstring& val) const noexcept +{ + return make_error_code(errc::e_not_impl); +} + } // namespace details } // namespace deliveryoptimization } // namespace microsoft From 626e381159ffc248bde4dbccb82b1f4c2b7b90d5 Mon Sep 17 00:00:00 2001 From: Jeffrey Saathoff Date: Fri, 3 Feb 2023 18:05:00 -0800 Subject: [PATCH 4/5] move pipeline to Windows 2022 --- azure-pipelines/build/windows/dosdkcpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines/build/windows/dosdkcpp.yml b/azure-pipelines/build/windows/dosdkcpp.yml index 92492a72..24ace13a 100644 --- a/azure-pipelines/build/windows/dosdkcpp.yml +++ b/azure-pipelines/build/windows/dosdkcpp.yml @@ -32,7 +32,7 @@ pr: - sdk-cpp/build/cleanup-install.sh pool: - vmImage: "windows-2019" + vmImage: "windows-2022" jobs: - job: Debug From 72e38277b299914dd6621d1f682a8917a165106b Mon Sep 17 00:00:00 2001 From: Jeffrey Saathoff Date: Wed, 8 Feb 2023 12:17:57 -0800 Subject: [PATCH 5/5] Remove flags enum --- sdk-cpp/include/do_download.h | 5 ----- sdk-cpp/include/do_download_property.h | 13 +------------ 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/sdk-cpp/include/do_download.h b/sdk-cpp/include/do_download.h index 1704c8ea..bddd7eda 100644 --- a/sdk-cpp/include/do_download.h +++ b/sdk-cpp/include/do_download.h @@ -78,11 +78,6 @@ class download return set_property(download_property::cost_policy, static_cast(value)); } - std::error_code set_security_flags(download_security_flags value) noexcept - { - return set_property(download_property::security_flags, static_cast(value)); - } - private: download(); diff --git a/sdk-cpp/include/do_download_property.h b/sdk-cpp/include/do_download_property.h index 2b21ffcc..e34f1195 100644 --- a/sdk-cpp/include/do_download_property.h +++ b/sdk-cpp/include/do_download_property.h @@ -31,7 +31,7 @@ enum class download_property download_file_path, // string http_custom_headers, // string cost_policy, // uint32 (see download_cost_policy enum) - security_flags, // uint32 (see download_security_flags enum) + security_flags, // uint32 callback_freq_percent, // uint32 callback_freq_seconds, // uint32 no_progress_timeout_seconds, // uint32 @@ -65,17 +65,6 @@ enum class download_cost_policy : uint32_t no_surcharge, // pause download if over data limit }; -// Values for download_property::security_flags -enum class download_security_flags : uint32_t -{ - enable_ssl_revocation = 0x0001, // WINHTTP_ENABLE_SSL_REVOCATION - ignore_unknown_ca = 0x0100, // SECURITY_FLAG_IGNORE_UNKNOWN_CA - ignore_cert_wrong_usage = 0x0200, // SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE - ignore_cert_cn_invalid = 0x1000, // SECURITY_FLAG_IGNORE_CERT_CN_INVALID - ignore_cert_date_invalid = 0x2000, // SECURITY_FLAG_IGNORE_CERT_DATE_INVALID - ignore_all_cert_errors = 0x3300, // SECURITY_FLAG_IGNORE_ALL_CERT_ERRORS -}; - class download_property_value { friend class details::CDownloadImpl;