| 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 | static HRESULT BEEngineEscapeString( |
| 7 | __in BURN_EXTENSION_ENGINE_CONTEXT* /*pContext*/, |
| 8 | __in const LPVOID pvArgs, |
| 9 | __inout LPVOID pvResults |
| 10 | ) |
| 11 | { |
| 12 | HRESULT hr = S_OK; |
| 13 | ValidateMessageArgs(hr, pvArgs, BOOTSTRAPPER_EXTENSION_ENGINE_ESCAPESTRING_ARGS, pArgs); |
| 14 | ValidateMessageResults(hr, pvResults, BOOTSTRAPPER_EXTENSION_ENGINE_ESCAPESTRING_RESULTS, pResults); |
| 15 | |
| 16 | hr = ExternalEngineEscapeString(pArgs->wzIn, pResults->wzOut, &pResults->cchOut); |
| 17 | |
| 18 | LExit: |
| 19 | return hr; |
| 20 | } |
| 21 | |
| 22 | static HRESULT BEEngineEvaluateCondition( |
| 23 | __in BURN_EXTENSION_ENGINE_CONTEXT* pContext, |
| 24 | __in const LPVOID pvArgs, |
| 25 | __inout LPVOID pvResults |
| 26 | ) |
| 27 | { |
| 28 | HRESULT hr = S_OK; |
| 29 | ValidateMessageArgs(hr, pvArgs, BOOTSTRAPPER_EXTENSION_ENGINE_EVALUATECONDITION_ARGS, pArgs); |
| 30 | ValidateMessageResults(hr, pvResults, BOOTSTRAPPER_EXTENSION_ENGINE_EVALUATECONDITION_RESULTS, pResults); |
| 31 | |
| 32 | hr = ExternalEngineEvaluateCondition(pContext->pEngineState, pArgs->wzCondition, &pResults->f); |
| 33 | |
| 34 | LExit: |
| 35 | return hr; |
| 36 | } |
| 37 | |
| 38 | static HRESULT BEEngineFormatString( |
| 39 | __in BURN_EXTENSION_ENGINE_CONTEXT* pContext, |
| 40 | __in const LPVOID pvArgs, |
| 41 | __inout LPVOID pvResults |
| 42 | ) |
| 43 | { |
| 44 | HRESULT hr = S_OK; |
| 45 | ValidateMessageArgs(hr, pvArgs, BOOTSTRAPPER_EXTENSION_ENGINE_FORMATSTRING_ARGS, pArgs); |
| 46 | ValidateMessageResults(hr, pvResults, BOOTSTRAPPER_EXTENSION_ENGINE_FORMATSTRING_RESULTS, pResults); |
| 47 | |
| 48 | hr = ExternalEngineFormatString(pContext->pEngineState, pArgs->wzIn, pResults->wzOut, &pResults->cchOut); |
| 49 | |
| 50 | LExit: |
| 51 | return hr; |
| 52 | } |
| 53 | |
| 54 | static HRESULT BEEngineGetVariableNumeric( |
| 55 | __in BURN_EXTENSION_ENGINE_CONTEXT* pContext, |
| 56 | __in const LPVOID pvArgs, |
| 57 | __inout LPVOID pvResults |
| 58 | ) |
| 59 | { |
| 60 | HRESULT hr = S_OK; |
| 61 | ValidateMessageArgs(hr, pvArgs, BOOTSTRAPPER_EXTENSION_ENGINE_GETVARIABLENUMERIC_ARGS, pArgs); |
| 62 | ValidateMessageResults(hr, pvResults, BOOTSTRAPPER_EXTENSION_ENGINE_GETVARIABLENUMERIC_RESULTS, pResults); |
| 63 | |
| 64 | hr = ExternalEngineGetVariableNumeric(pContext->pEngineState, pArgs->wzVariable, &pResults->llValue); |
| 65 | |
| 66 | LExit: |
| 67 | return hr; |
| 68 | } |
| 69 | |
| 70 | static HRESULT BEEngineGetVariableString( |
| 71 | __in BURN_EXTENSION_ENGINE_CONTEXT* pContext, |
| 72 | __in const LPVOID pvArgs, |
| 73 | __inout LPVOID pvResults |
| 74 | ) |
| 75 | { |
| 76 | HRESULT hr = S_OK; |
| 77 | ValidateMessageArgs(hr, pvArgs, BOOTSTRAPPER_EXTENSION_ENGINE_GETVARIABLESTRING_ARGS, pArgs); |
| 78 | ValidateMessageResults(hr, pvResults, BOOTSTRAPPER_EXTENSION_ENGINE_GETVARIABLESTRING_RESULTS, pResults); |
| 79 | |
| 80 | hr = ExternalEngineGetVariableString(pContext->pEngineState, pArgs->wzVariable, pResults->wzValue, &pResults->cchValue); |
| 81 | |
| 82 | LExit: |
| 83 | return hr; |
| 84 | } |
| 85 | |
| 86 | static HRESULT BEEngineGetVariableVersion( |
| 87 | __in BURN_EXTENSION_ENGINE_CONTEXT* pContext, |
| 88 | __in const LPVOID pvArgs, |
| 89 | __inout LPVOID pvResults |
| 90 | ) |
| 91 | { |
| 92 | HRESULT hr = S_OK; |
| 93 | ValidateMessageArgs(hr, pvArgs, BOOTSTRAPPER_EXTENSION_ENGINE_GETVARIABLEVERSION_ARGS, pArgs); |
| 94 | ValidateMessageResults(hr, pvResults, BOOTSTRAPPER_EXTENSION_ENGINE_GETVARIABLEVERSION_RESULTS, pResults); |
| 95 | |
| 96 | hr = ExternalEngineGetVariableVersion(pContext->pEngineState, pArgs->wzVariable, pResults->wzValue, &pResults->cchValue); |
| 97 | |
| 98 | LExit: |
| 99 | return hr; |
| 100 | } |
| 101 | |
| 102 | static HRESULT BEEngineLog( |
| 103 | __in BURN_EXTENSION_ENGINE_CONTEXT* /*pContext*/, |
| 104 | __in const LPVOID pvArgs, |
| 105 | __inout LPVOID pvResults |
| 106 | ) |
| 107 | { |
| 108 | HRESULT hr = S_OK; |
| 109 | REPORT_LEVEL rl = REPORT_NONE; |
| 110 | ValidateMessageArgs(hr, pvArgs, BOOTSTRAPPER_EXTENSION_ENGINE_LOG_ARGS, pArgs); |
| 111 | ValidateMessageResults(hr, pvResults, BOOTSTRAPPER_EXTENSION_ENGINE_LOG_RESULTS, pResults); |
| 112 | |
| 113 | switch (pArgs->level) |
| 114 | { |
| 115 | case BOOTSTRAPPER_EXTENSION_LOG_LEVEL_STANDARD: |
| 116 | rl = REPORT_STANDARD; |
| 117 | break; |
| 118 | |
| 119 | case BOOTSTRAPPER_EXTENSION_LOG_LEVEL_VERBOSE: |
| 120 | rl = REPORT_VERBOSE; |
| 121 | break; |
| 122 | |
| 123 | case BOOTSTRAPPER_EXTENSION_LOG_LEVEL_DEBUG: |
| 124 | rl = REPORT_DEBUG; |
| 125 | break; |
| 126 | |
| 127 | case BOOTSTRAPPER_EXTENSION_LOG_LEVEL_ERROR: |
| 128 | rl = REPORT_ERROR; |
| 129 | break; |
| 130 | |
| 131 | default: |
| 132 | ExitFunction1(hr = E_INVALIDARG); |
| 133 | } |
| 134 | |
| 135 | hr = ExternalEngineLog(rl, pArgs->wzMessage); |
| 136 | ExitOnFailure(hr, "Failed to log Bundle Extension message."); |
| 137 | |
| 138 | LExit: |
| 139 | return hr; |
| 140 | } |
| 141 | |
| 142 | static HRESULT BEEngineSetVariableNumeric( |
| 143 | __in BURN_EXTENSION_ENGINE_CONTEXT* pContext, |
| 144 | __in const LPVOID pvArgs, |
| 145 | __inout LPVOID pvResults |
| 146 | ) |
| 147 | { |
| 148 | HRESULT hr = S_OK; |
| 149 | ValidateMessageArgs(hr, pvArgs, BOOTSTRAPPER_EXTENSION_ENGINE_SETVARIABLENUMERIC_ARGS, pArgs); |
| 150 | ValidateMessageResults(hr, pvResults, BOOTSTRAPPER_EXTENSION_ENGINE_SETVARIABLENUMERIC_RESULTS, pResults); |
| 151 | |
| 152 | hr = ExternalEngineSetVariableNumeric(pContext->pEngineState, pArgs->wzVariable, pArgs->llValue); |
| 153 | |
| 154 | LExit: |
| 155 | return hr; |
| 156 | } |
| 157 | |
| 158 | static HRESULT BEEngineSetVariableString( |
| 159 | __in BURN_EXTENSION_ENGINE_CONTEXT* pContext, |
| 160 | __in const LPVOID pvArgs, |
| 161 | __inout LPVOID pvResults |
| 162 | ) |
| 163 | { |
| 164 | HRESULT hr = S_OK; |
| 165 | ValidateMessageArgs(hr, pvArgs, BOOTSTRAPPER_EXTENSION_ENGINE_SETVARIABLESTRING_ARGS, pArgs); |
| 166 | ValidateMessageResults(hr, pvResults, BOOTSTRAPPER_EXTENSION_ENGINE_SETVARIABLESTRING_RESULTS, pResults); |
| 167 | |
| 168 | hr = ExternalEngineSetVariableString(pContext->pEngineState, pArgs->wzVariable, pArgs->wzValue, pArgs->fFormatted); |
| 169 | |
| 170 | LExit: |
| 171 | return hr; |
| 172 | } |
| 173 | |
| 174 | static HRESULT BEEngineSetVariableVersion( |
| 175 | __in BURN_EXTENSION_ENGINE_CONTEXT* pContext, |
| 176 | __in const LPVOID pvArgs, |
| 177 | __inout LPVOID pvResults |
| 178 | ) |
| 179 | { |
| 180 | HRESULT hr = S_OK; |
| 181 | ValidateMessageArgs(hr, pvArgs, BOOTSTRAPPER_EXTENSION_ENGINE_SETVARIABLEVERSION_ARGS, pArgs); |
| 182 | ValidateMessageResults(hr, pvResults, BOOTSTRAPPER_EXTENSION_ENGINE_SETVARIABLEVERSION_RESULTS, pResults); |
| 183 | |
| 184 | hr = ExternalEngineSetVariableVersion(pContext->pEngineState, pArgs->wzVariable, pArgs->wzValue); |
| 185 | |
| 186 | LExit: |
| 187 | return hr; |
| 188 | } |
| 189 | |
| 190 | static HRESULT BEEngineCompareVersions( |
| 191 | __in BURN_EXTENSION_ENGINE_CONTEXT* /*pContext*/, |
| 192 | __in const LPVOID pvArgs, |
| 193 | __inout LPVOID pvResults |
| 194 | ) |
| 195 | { |
| 196 | HRESULT hr = S_OK; |
| 197 | ValidateMessageArgs(hr, pvArgs, BOOTSTRAPPER_EXTENSION_ENGINE_COMPAREVERSIONS_ARGS, pArgs); |
| 198 | ValidateMessageResults(hr, pvResults, BOOTSTRAPPER_EXTENSION_ENGINE_COMPAREVERSIONS_RESULTS, pResults); |
| 199 | |
| 200 | hr = ExternalEngineCompareVersions(pArgs->wzVersion1, pArgs->wzVersion2, &pResults->nResult); |
| 201 | |
| 202 | LExit: |
| 203 | return hr; |
| 204 | } |
| 205 | |
| 206 | static HRESULT BEEngineGetRelatedBundleVariable( |
| 207 | __in BURN_EXTENSION_ENGINE_CONTEXT* pContext, |
| 208 | __in const LPVOID pvArgs, |
| 209 | __inout LPVOID pvResults |
| 210 | ) |
| 211 | { |
| 212 | HRESULT hr = S_OK; |
| 213 | ValidateMessageArgs(hr, pvArgs, BOOTSTRAPPER_EXTENSION_ENGINE_GETRELATEDBUNDLEVARIABLE_ARGS, pArgs); |
| 214 | ValidateMessageResults(hr, pvResults, BOOTSTRAPPER_EXTENSION_ENGINE_GETRELATEDBUNDLEVARIABLE_RESULTS, pResults); |
| 215 | |
| 216 | hr = ExternalEngineGetRelatedBundleVariable(pContext->pEngineState, pArgs->wzBundleId, pArgs->wzVariable, pResults->wzValue, &pResults->cchValue); |
| 217 | |
| 218 | LExit: |
| 219 | return hr; |
| 220 | } |
| 221 | |
| 222 | HRESULT WINAPI EngineForExtensionProc( |
| 223 | __in BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE message, |
| 224 | __in const LPVOID pvArgs, |
| 225 | __inout LPVOID pvResults, |
| 226 | __in_opt LPVOID pvContext |
| 227 | ) |
| 228 | { |
| 229 | HRESULT hr = S_OK; |
| 230 | BURN_EXTENSION_ENGINE_CONTEXT* pContext = reinterpret_cast<BURN_EXTENSION_ENGINE_CONTEXT*>(pvContext); |
| 231 | |
| 232 | if (!pContext || !pvArgs || !pvResults) |
| 233 | { |
| 234 | ExitFunction1(hr = E_INVALIDARG); |
| 235 | } |
| 236 | |
| 237 | switch (message) |
| 238 | { |
| 239 | case BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_ESCAPESTRING: |
| 240 | hr = BEEngineEscapeString(pContext, pvArgs, pvResults); |
| 241 | break; |
| 242 | case BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_EVALUATECONDITION: |
| 243 | hr = BEEngineEvaluateCondition(pContext, pvArgs, pvResults); |
| 244 | break; |
| 245 | case BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_FORMATSTRING: |
| 246 | hr = BEEngineFormatString(pContext, pvArgs, pvResults); |
| 247 | break; |
| 248 | case BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_GETVARIABLENUMERIC: |
| 249 | hr = BEEngineGetVariableNumeric(pContext, pvArgs, pvResults); |
| 250 | break; |
| 251 | case BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_GETVARIABLESTRING: |
| 252 | hr = BEEngineGetVariableString(pContext, pvArgs, pvResults); |
| 253 | break; |
| 254 | case BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_GETVARIABLEVERSION: |
| 255 | hr = BEEngineGetVariableVersion(pContext, pvArgs, pvResults); |
| 256 | break; |
| 257 | case BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_LOG: |
| 258 | hr = BEEngineLog(pContext, pvArgs, pvResults); |
| 259 | break; |
| 260 | case BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_SETVARIABLENUMERIC: |
| 261 | hr = BEEngineSetVariableNumeric(pContext, pvArgs, pvResults); |
| 262 | break; |
| 263 | case BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_SETVARIABLESTRING: |
| 264 | hr = BEEngineSetVariableString(pContext, pvArgs, pvResults); |
| 265 | break; |
| 266 | case BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_SETVARIABLEVERSION: |
| 267 | hr = BEEngineSetVariableVersion(pContext, pvArgs, pvResults); |
| 268 | break; |
| 269 | case BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_COMPAREVERSIONS: |
| 270 | hr = BEEngineCompareVersions(pContext, pvArgs, pvResults); |
| 271 | break; |
| 272 | case BOOTSTRAPPER_EXTENSION_ENGINE_MESSAGE_GETRELATEDBUNDLEVARIABLE: |
| 273 | hr = BEEngineGetRelatedBundleVariable(pContext, pvArgs, pvResults); |
| 274 | break; |
| 275 | default: |
| 276 | hr = E_NOTIMPL; |
| 277 | break; |
| 278 | } |
| 279 | |
| 280 | LExit: |
| 281 | return hr; |
| 282 | } |