| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | #include "precomp.h" |
| 4 | |
| 5 | |
| 6 | class CBextBootstrapperExtensionEngine : public IBootstrapperExtensionEngine |
| 7 | { |
| 8 | public: // IUnknown |
| 9 | virtual STDMETHODIMP QueryInterface( |
| 10 | __in REFIID riid, |
| 11 | __out LPVOID *ppvObject |
| 12 | ) |
| 13 | { |
| 14 | if (!ppvObject) |
| 15 | { |
| 16 | return E_INVALIDARG; |
| 17 | } |
| 18 | |
| 19 | *ppvObject = NULL; |
| 20 | |
| 21 | if (::IsEqualIID(__uuidof(IBootstrapperExtensionEngine), riid)) |
| 22 | { |
| 23 | *ppvObject = static_cast<IBootstrapperExtensionEngine*>(this); |
| 24 | } |
| 25 | else if (::IsEqualIID(IID_IUnknown, riid)) |
| 26 | { |
| 27 | *ppvObject = reinterpret_cast<IUnknown*>(this); |
| 28 | } |
| 29 | else // no interface for requested iid |
| 30 | { |
| 31 | return E_NOINTERFACE; |
| 32 | } |
| 33 | |
| 34 | AddRef(); |
| 35 | return S_OK; |
| 36 | } |
| 37 | |
| 38 | virtual STDMETHODIMP_(ULONG) AddRef() |
| 39 | { |
| 40 | return ::InterlockedIncrement(&this->m_cReferences); |
| 41 | } |
| 42 | |
| 43 | virtual STDMETHODIMP_(ULONG) Release() |
| 44 | { |
| 45 | long l = ::InterlockedDecrement(&this->m_cReferences); |
| 46 | if (0 < l) |
| 47 | { |
| 48 | return l; |
| 49 | } |
| 50 | |
| 51 | delete this; |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | public: // IBootstrapperExtensionEngine |
| 56 | virtual STDMETHODIMP EscapeString( |
| 57 | __in_z LPCWSTR wzIn, |
| 58 | __out_ecount_opt(*pcchOut) LPWSTR wzOut, |
| 59 | __inout SIZE_T* pcchOut |
| 60 | ) |
| 61 | { |
| 62 | HRESULT hr = S_OK; |
| 63 | BOOTSTRAPPER_EXTENSION_ENGINE_ESCAPESTRING_ARGS args = { }; |
| 64 | BOOTSTRAPPER_EXTENSION_ENGINE_ESCAPESTRING_RESULTS results = { }; |
| 65 | |
| 66 | ExitOnNull(pcchOut, hr, E_INVALIDARG, "pcchOut is required"); |
| 67 | |
| 68 | args.cbSize = sizeof(args); |
| 69 | args.wzIn = wzIn; |
| 70 | |
| 71 | results.cbSize = sizeof(results); |
| 72 | results.wzOut = wzOut; |
| 73 | results.cchOut = *pcchOut; |
| 74 | |
| 75 | hr = m_pfnBootstrapperExtensionEngineProc(BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_ESCAPESTRING, &args, &results, m_pvBootstrapperExtensionEngineProcContext); |
| 76 | |
| 77 | *pcchOut = results.cchOut; |
| 78 | |
| 79 | LExit: |
| 80 | return hr; |
| 81 | } |
| 82 | |
| 83 | virtual STDMETHODIMP EvaluateCondition( |
| 84 | __in_z LPCWSTR wzCondition, |
| 85 | __out BOOL* pf |
| 86 | ) |
| 87 | { |
| 88 | HRESULT hr = S_OK; |
| 89 | BOOTSTRAPPER_EXTENSION_ENGINE_EVALUATECONDITION_ARGS args = { }; |
| 90 | BOOTSTRAPPER_EXTENSION_ENGINE_EVALUATECONDITION_RESULTS results = { }; |
| 91 | |
| 92 | ExitOnNull(pf, hr, E_INVALIDARG, "pf is required"); |
| 93 | |
| 94 | args.cbSize = sizeof(args); |
| 95 | args.wzCondition = wzCondition; |
| 96 | |
| 97 | results.cbSize = sizeof(results); |
| 98 | |
| 99 | hr = m_pfnBootstrapperExtensionEngineProc(BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_EVALUATECONDITION, &args, &results, m_pvBootstrapperExtensionEngineProcContext); |
| 100 | |
| 101 | *pf = results.f; |
| 102 | |
| 103 | LExit: |
| 104 | return hr; |
| 105 | } |
| 106 | |
| 107 | virtual STDMETHODIMP FormatString( |
| 108 | __in_z LPCWSTR wzIn, |
| 109 | __out_ecount_opt(*pcchOut) LPWSTR wzOut, |
| 110 | __inout SIZE_T* pcchOut |
| 111 | ) |
| 112 | { |
| 113 | HRESULT hr = S_OK; |
| 114 | BOOTSTRAPPER_EXTENSION_ENGINE_FORMATSTRING_ARGS args = { }; |
| 115 | BOOTSTRAPPER_EXTENSION_ENGINE_FORMATSTRING_RESULTS results = { }; |
| 116 | |
| 117 | ExitOnNull(pcchOut, hr, E_INVALIDARG, "pcchOut is required"); |
| 118 | |
| 119 | args.cbSize = sizeof(args); |
| 120 | args.wzIn = wzIn; |
| 121 | |
| 122 | results.cbSize = sizeof(results); |
| 123 | results.wzOut = wzOut; |
| 124 | results.cchOut = *pcchOut; |
| 125 | |
| 126 | hr = m_pfnBootstrapperExtensionEngineProc(BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_FORMATSTRING, &args, &results, m_pvBootstrapperExtensionEngineProcContext); |
| 127 | |
| 128 | *pcchOut = results.cchOut; |
| 129 | |
| 130 | LExit: |
| 131 | return hr; |
| 132 | } |
| 133 | |
| 134 | virtual STDMETHODIMP GetVariableNumeric( |
| 135 | __in_z LPCWSTR wzVariable, |
| 136 | __out LONGLONG* pllValue |
| 137 | ) |
| 138 | { |
| 139 | HRESULT hr = S_OK; |
| 140 | BOOTSTRAPPER_EXTENSION_ENGINE_GETVARIABLENUMERIC_ARGS args = { }; |
| 141 | BOOTSTRAPPER_EXTENSION_ENGINE_GETVARIABLENUMERIC_RESULTS results = { }; |
| 142 | |
| 143 | ExitOnNull(pllValue, hr, E_INVALIDARG, "pllValue is required"); |
| 144 | |
| 145 | args.cbSize = sizeof(args); |
| 146 | args.wzVariable = wzVariable; |
| 147 | |
| 148 | results.cbSize = sizeof(results); |
| 149 | |
| 150 | hr = m_pfnBootstrapperExtensionEngineProc(BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_GETVARIABLENUMERIC, &args, &results, m_pvBootstrapperExtensionEngineProcContext); |
| 151 | |
| 152 | *pllValue = results.llValue; |
| 153 | |
| 154 | LExit: |
| 155 | SecureZeroMemory(&results, sizeof(results)); |
| 156 | return hr; |
| 157 | } |
| 158 | |
| 159 | virtual STDMETHODIMP GetVariableString( |
| 160 | __in_z LPCWSTR wzVariable, |
| 161 | __out_ecount_opt(*pcchValue) LPWSTR wzValue, |
| 162 | __inout SIZE_T* pcchValue |
| 163 | ) |
| 164 | { |
| 165 | HRESULT hr = S_OK; |
| 166 | BOOTSTRAPPER_EXTENSION_ENGINE_GETVARIABLESTRING_ARGS args = { }; |
| 167 | BOOTSTRAPPER_EXTENSION_ENGINE_GETVARIABLESTRING_RESULTS results = { }; |
| 168 | |
| 169 | ExitOnNull(pcchValue, hr, E_INVALIDARG, "pcchValue is required"); |
| 170 | |
| 171 | args.cbSize = sizeof(args); |
| 172 | args.wzVariable = wzVariable; |
| 173 | |
| 174 | results.cbSize = sizeof(results); |
| 175 | results.wzValue = wzValue; |
| 176 | results.cchValue = *pcchValue; |
| 177 | |
| 178 | hr = m_pfnBootstrapperExtensionEngineProc(BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_GETVARIABLESTRING, &args, &results, m_pvBootstrapperExtensionEngineProcContext); |
| 179 | |
| 180 | *pcchValue = results.cchValue; |
| 181 | |
| 182 | LExit: |
| 183 | return hr; |
| 184 | } |
| 185 | |
| 186 | virtual STDMETHODIMP GetVariableVersion( |
| 187 | __in_z LPCWSTR wzVariable, |
| 188 | __out_ecount_opt(*pcchValue) LPWSTR wzValue, |
| 189 | __inout SIZE_T* pcchValue |
| 190 | ) |
| 191 | { |
| 192 | HRESULT hr = S_OK; |
| 193 | BOOTSTRAPPER_EXTENSION_ENGINE_GETVARIABLEVERSION_ARGS args = { }; |
| 194 | BOOTSTRAPPER_EXTENSION_ENGINE_GETVARIABLEVERSION_RESULTS results = { }; |
| 195 | |
| 196 | ExitOnNull(pcchValue, hr, E_INVALIDARG, "pcchValue is required"); |
| 197 | |
| 198 | args.cbSize = sizeof(args); |
| 199 | args.wzVariable = wzVariable; |
| 200 | |
| 201 | results.cbSize = sizeof(results); |
| 202 | results.wzValue = wzValue; |
| 203 | results.cchValue = *pcchValue; |
| 204 | |
| 205 | hr = m_pfnBootstrapperExtensionEngineProc(BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_GETVARIABLEVERSION, &args, &results, m_pvBootstrapperExtensionEngineProcContext); |
| 206 | |
| 207 | *pcchValue = results.cchValue; |
| 208 | |
| 209 | LExit: |
| 210 | return hr; |
| 211 | } |
| 212 | |
| 213 | virtual STDMETHODIMP Log( |
| 214 | __in BOOTSTRAPPER_EXTENSION_LOG_LEVEL level, |
| 215 | __in_z LPCWSTR wzMessage |
| 216 | ) |
| 217 | { |
| 218 | BOOTSTRAPPER_EXTENSION_ENGINE_LOG_ARGS args = { }; |
| 219 | BOOTSTRAPPER_EXTENSION_ENGINE_LOG_RESULTS results = { }; |
| 220 | |
| 221 | args.cbSize = sizeof(args); |
| 222 | args.level = level; |
| 223 | args.wzMessage = wzMessage; |
| 224 | |
| 225 | results.cbSize = sizeof(results); |
| 226 | |
| 227 | return m_pfnBootstrapperExtensionEngineProc(BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_LOG, &args, &results, m_pvBootstrapperExtensionEngineProcContext); |
| 228 | } |
| 229 | |
| 230 | virtual STDMETHODIMP SetVariableNumeric( |
| 231 | __in_z LPCWSTR wzVariable, |
| 232 | __in LONGLONG llValue |
| 233 | ) |
| 234 | { |
| 235 | BOOTSTRAPPER_EXTENSION_ENGINE_SETVARIABLENUMERIC_ARGS args = { }; |
| 236 | BOOTSTRAPPER_EXTENSION_ENGINE_SETVARIABLENUMERIC_RESULTS results = { }; |
| 237 | |
| 238 | args.cbSize = sizeof(args); |
| 239 | args.wzVariable = wzVariable; |
| 240 | args.llValue = llValue; |
| 241 | |
| 242 | results.cbSize = sizeof(results); |
| 243 | |
| 244 | return m_pfnBootstrapperExtensionEngineProc(BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_SETVARIABLENUMERIC, &args, &results, m_pvBootstrapperExtensionEngineProcContext); |
| 245 | } |
| 246 | |
| 247 | virtual STDMETHODIMP SetVariableString( |
| 248 | __in_z LPCWSTR wzVariable, |
| 249 | __in_z_opt LPCWSTR wzValue, |
| 250 | __in BOOL fFormatted |
| 251 | ) |
| 252 | { |
| 253 | BOOTSTRAPPER_EXTENSION_ENGINE_SETVARIABLESTRING_ARGS args = { }; |
| 254 | BOOTSTRAPPER_EXTENSION_ENGINE_SETVARIABLESTRING_RESULTS results = { }; |
| 255 | |
| 256 | args.cbSize = sizeof(args); |
| 257 | args.wzVariable = wzVariable; |
| 258 | args.wzValue = wzValue; |
| 259 | args.fFormatted = fFormatted; |
| 260 | |
| 261 | results.cbSize = sizeof(results); |
| 262 | |
| 263 | return m_pfnBootstrapperExtensionEngineProc(BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_SETVARIABLESTRING, &args, &results, m_pvBootstrapperExtensionEngineProcContext); |
| 264 | } |
| 265 | |
| 266 | virtual STDMETHODIMP SetVariableVersion( |
| 267 | __in_z LPCWSTR wzVariable, |
| 268 | __in_z_opt LPCWSTR wzValue |
| 269 | ) |
| 270 | { |
| 271 | BOOTSTRAPPER_EXTENSION_ENGINE_SETVARIABLEVERSION_ARGS args = { }; |
| 272 | BOOTSTRAPPER_EXTENSION_ENGINE_SETVARIABLEVERSION_RESULTS results = { }; |
| 273 | |
| 274 | args.cbSize = sizeof(args); |
| 275 | args.wzVariable = wzVariable; |
| 276 | args.wzValue = wzValue; |
| 277 | |
| 278 | results.cbSize = sizeof(results); |
| 279 | |
| 280 | return m_pfnBootstrapperExtensionEngineProc(BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_SETVARIABLEVERSION, &args, &results, m_pvBootstrapperExtensionEngineProcContext); |
| 281 | } |
| 282 | |
| 283 | virtual STDMETHODIMP CompareVersions( |
| 284 | __in_z LPCWSTR wzVersion1, |
| 285 | __in_z LPCWSTR wzVersion2, |
| 286 | __out int* pnResult |
| 287 | ) |
| 288 | { |
| 289 | HRESULT hr = S_OK; |
| 290 | BOOTSTRAPPER_EXTENSION_ENGINE_COMPAREVERSIONS_ARGS args = { }; |
| 291 | BOOTSTRAPPER_EXTENSION_ENGINE_COMPAREVERSIONS_RESULTS results = { }; |
| 292 | |
| 293 | ExitOnNull(pnResult, hr, E_INVALIDARG, "pnResult is required"); |
| 294 | |
| 295 | args.cbSize = sizeof(args); |
| 296 | args.wzVersion1 = wzVersion1; |
| 297 | args.wzVersion2 = wzVersion2; |
| 298 | |
| 299 | results.cbSize = sizeof(results); |
| 300 | |
| 301 | hr = m_pfnBootstrapperExtensionEngineProc(BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_COMPAREVERSIONS, &args, &results, m_pvBootstrapperExtensionEngineProcContext); |
| 302 | |
| 303 | *pnResult = results.nResult; |
| 304 | |
| 305 | LExit: |
| 306 | return hr; |
| 307 | } |
| 308 | |
| 309 | virtual STDMETHODIMP GetRelatedBundleVariable( |
| 310 | __in_z LPCWSTR wzBundleId, |
| 311 | __in_z LPCWSTR wzVariable, |
| 312 | __out_ecount_opt(*pcchValue) LPWSTR wzValue, |
| 313 | __inout SIZE_T* pcchValue |
| 314 | ) |
| 315 | { |
| 316 | HRESULT hr = S_OK; |
| 317 | BOOTSTRAPPER_EXTENSION_ENGINE_GETRELATEDBUNDLEVARIABLE_ARGS args = { }; |
| 318 | BOOTSTRAPPER_EXTENSION_ENGINE_GETRELATEDBUNDLEVARIABLE_RESULTS results = { }; |
| 319 | |
| 320 | ExitOnNull(pcchValue, hr, E_INVALIDARG, "pcchValue is required"); |
| 321 | |
| 322 | args.cbSize = sizeof(args); |
| 323 | args.wzBundleId = wzBundleId; |
| 324 | args.wzVariable = wzVariable; |
| 325 | |
| 326 | results.cbSize = sizeof(results); |
| 327 | results.wzValue = wzValue; |
| 328 | results.cchValue = *pcchValue; |
| 329 | |
| 330 | hr = m_pfnBootstrapperExtensionEngineProc(BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_GETRELATEDBUNDLEVARIABLE, &args, &results, m_pvBootstrapperExtensionEngineProcContext); |
| 331 | |
| 332 | *pcchValue = results.cchValue; |
| 333 | |
| 334 | LExit: |
| 335 | return hr; |
| 336 | } |
| 337 | |
| 338 | public: |
| 339 | CBextBootstrapperExtensionEngine( |
| 340 | __in PFN_BOOTSTRAPPER_EXTENSION_ENGINE_PROC pfnBootstrapperExtensionEngineProc, |
| 341 | __in_opt LPVOID pvBootstrapperExtensionEngineProcContext |
| 342 | ) |
| 343 | { |
| 344 | m_cReferences = 1; |
| 345 | m_pfnBootstrapperExtensionEngineProc = pfnBootstrapperExtensionEngineProc; |
| 346 | m_pvBootstrapperExtensionEngineProcContext = pvBootstrapperExtensionEngineProcContext; |
| 347 | } |
| 348 | |
| 349 | private: |
| 350 | long m_cReferences; |
| 351 | PFN_BOOTSTRAPPER_EXTENSION_ENGINE_PROC m_pfnBootstrapperExtensionEngineProc; |
| 352 | LPVOID m_pvBootstrapperExtensionEngineProcContext; |
| 353 | }; |
| 354 | |
| 355 | HRESULT BextBootstrapperExtensionEngineCreate( |
| 356 | __in PFN_BOOTSTRAPPER_EXTENSION_ENGINE_PROC pfnBootstrapperExtensionEngineProc, |
| 357 | __in_opt LPVOID pvBootstrapperExtensionEngineProcContext, |
| 358 | __out IBootstrapperExtensionEngine** ppEngineForExtension |
| 359 | ) |
| 360 | { |
| 361 | HRESULT hr = S_OK; |
| 362 | CBextBootstrapperExtensionEngine* pBootstrapperExtensionEngine = NULL; |
| 363 | |
| 364 | pBootstrapperExtensionEngine = new CBextBootstrapperExtensionEngine(pfnBootstrapperExtensionEngineProc, pvBootstrapperExtensionEngineProcContext); |
| 365 | ExitOnNull(pBootstrapperExtensionEngine, hr, E_OUTOFMEMORY, "Failed to allocate new BextBootstrapperExtensionEngine object."); |
| 366 | |
| 367 | hr = pBootstrapperExtensionEngine->QueryInterface(IID_PPV_ARGS(ppEngineForExtension)); |
| 368 | ExitOnFailure(hr, "Failed to QI for IBootstrapperExtensionEngine from BextBootstrapperExtensionEngine object."); |
| 369 | |
| 370 | LExit: |
| 371 | ReleaseObject(pBootstrapperExtensionEngine); |
| 372 | return hr; |
| 373 | } |