diff options
Diffstat (limited to 'src/engine/EngineForExtension.cpp')
| -rw-r--r-- | src/engine/EngineForExtension.cpp | 191 |
1 files changed, 12 insertions, 179 deletions
diff --git a/src/engine/EngineForExtension.cpp b/src/engine/EngineForExtension.cpp index 29b6a6b3..2e1c98fd 100644 --- a/src/engine/EngineForExtension.cpp +++ b/src/engine/EngineForExtension.cpp | |||
| @@ -3,12 +3,6 @@ | |||
| 3 | #include "precomp.h" | 3 | #include "precomp.h" |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | static HRESULT CopyStringToBE( | ||
| 7 | __in LPWSTR wzValue, | ||
| 8 | __in LPWSTR wzBuffer, | ||
| 9 | __inout DWORD* pcchBuffer | ||
| 10 | ); | ||
| 11 | |||
| 12 | static HRESULT BEEngineEscapeString( | 6 | static HRESULT BEEngineEscapeString( |
| 13 | __in BURN_EXTENSION_ENGINE_CONTEXT* /*pContext*/, | 7 | __in BURN_EXTENSION_ENGINE_CONTEXT* /*pContext*/, |
| 14 | __in const LPVOID pvArgs, | 8 | __in const LPVOID pvArgs, |
| @@ -16,28 +10,12 @@ static HRESULT BEEngineEscapeString( | |||
| 16 | ) | 10 | ) |
| 17 | { | 11 | { |
| 18 | HRESULT hr = S_OK; | 12 | HRESULT hr = S_OK; |
| 19 | LPWSTR sczValue = NULL; | ||
| 20 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_ARGS, pArgs); | 13 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_ARGS, pArgs); |
| 21 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_RESULTS, pResults); | 14 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_RESULTS, pResults); |
| 22 | LPCWSTR wzIn = pArgs->wzIn; | ||
| 23 | LPWSTR wzOut = pResults->wzOut; | ||
| 24 | DWORD* pcchOut = &pResults->cchOut; | ||
| 25 | 15 | ||
| 26 | if (wzIn && *wzIn) | 16 | hr = ExternalEngineEscapeString(pArgs->wzIn, pResults->wzOut, &pResults->cchOut); |
| 27 | { | ||
| 28 | hr = VariableEscapeString(wzIn, &sczValue); | ||
| 29 | if (SUCCEEDED(hr)) | ||
| 30 | { | ||
| 31 | hr = CopyStringToBE(sczValue, wzOut, pcchOut); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | else | ||
| 35 | { | ||
| 36 | hr = E_INVALIDARG; | ||
| 37 | } | ||
| 38 | 17 | ||
| 39 | LExit: | 18 | LExit: |
| 40 | StrSecureZeroFreeString(sczValue); | ||
| 41 | return hr; | 19 | return hr; |
| 42 | } | 20 | } |
| 43 | 21 | ||
| @@ -50,17 +28,8 @@ static HRESULT BEEngineEvaluateCondition( | |||
| 50 | HRESULT hr = S_OK; | 28 | HRESULT hr = S_OK; |
| 51 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_EVALUATECONDITION_ARGS, pArgs); | 29 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_EVALUATECONDITION_ARGS, pArgs); |
| 52 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_EVALUATECONDITION_RESULTS, pResults); | 30 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_EVALUATECONDITION_RESULTS, pResults); |
| 53 | LPCWSTR wzCondition = pArgs->wzCondition; | ||
| 54 | BOOL* pf = &pResults->f; | ||
| 55 | 31 | ||
| 56 | if (wzCondition && *wzCondition) | 32 | hr = ExternalEngineEvaluateCondition(pContext->pEngineState, pArgs->wzCondition, &pResults->f); |
| 57 | { | ||
| 58 | hr = ConditionEvaluate(&pContext->pEngineState->variables, wzCondition, pf); | ||
| 59 | } | ||
| 60 | else | ||
| 61 | { | ||
| 62 | hr = E_INVALIDARG; | ||
| 63 | } | ||
| 64 | 33 | ||
| 65 | LExit: | 34 | LExit: |
| 66 | return hr; | 35 | return hr; |
| @@ -73,28 +42,12 @@ static HRESULT BEEngineFormatString( | |||
| 73 | ) | 42 | ) |
| 74 | { | 43 | { |
| 75 | HRESULT hr = S_OK; | 44 | HRESULT hr = S_OK; |
| 76 | LPWSTR sczValue = NULL; | ||
| 77 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_FORMATSTRING_ARGS, pArgs); | 45 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_FORMATSTRING_ARGS, pArgs); |
| 78 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_FORMATSTRING_RESULTS, pResults); | 46 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_FORMATSTRING_RESULTS, pResults); |
| 79 | LPCWSTR wzIn = pArgs->wzIn; | ||
| 80 | LPWSTR wzOut = pResults->wzOut; | ||
| 81 | DWORD* pcchOut = &pResults->cchOut; | ||
| 82 | 47 | ||
| 83 | if (wzIn && *wzIn) | 48 | hr = ExternalEngineFormatString(pContext->pEngineState, pArgs->wzIn, pResults->wzOut, &pResults->cchOut); |
| 84 | { | ||
| 85 | hr = VariableFormatString(&pContext->pEngineState->variables, wzIn, &sczValue, NULL); | ||
| 86 | if (SUCCEEDED(hr)) | ||
| 87 | { | ||
| 88 | hr = CopyStringToBE(sczValue, wzOut, pcchOut); | ||
| 89 | } | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | hr = E_INVALIDARG; | ||
| 94 | } | ||
| 95 | 49 | ||
| 96 | LExit: | 50 | LExit: |
| 97 | StrSecureZeroFreeString(sczValue); | ||
| 98 | return hr; | 51 | return hr; |
| 99 | } | 52 | } |
| 100 | 53 | ||
| @@ -107,17 +60,8 @@ static HRESULT BEEngineGetVariableNumeric( | |||
| 107 | HRESULT hr = S_OK; | 60 | HRESULT hr = S_OK; |
| 108 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_ARGS, pArgs); | 61 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_ARGS, pArgs); |
| 109 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_RESULTS, pResults); | 62 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_RESULTS, pResults); |
| 110 | LPCWSTR wzVariable = pArgs->wzVariable; | ||
| 111 | LONGLONG* pllValue = &pResults->llValue; | ||
| 112 | 63 | ||
| 113 | if (wzVariable && *wzVariable) | 64 | hr = ExternalEngineGetVariableNumeric(pContext->pEngineState, pArgs->wzVariable, &pResults->llValue); |
| 114 | { | ||
| 115 | hr = VariableGetNumeric(&pContext->pEngineState->variables, wzVariable, pllValue); | ||
| 116 | } | ||
| 117 | else | ||
| 118 | { | ||
| 119 | hr = E_INVALIDARG; | ||
| 120 | } | ||
| 121 | 65 | ||
| 122 | LExit: | 66 | LExit: |
| 123 | return hr; | 67 | return hr; |
| @@ -130,28 +74,12 @@ static HRESULT BEEngineGetVariableString( | |||
| 130 | ) | 74 | ) |
| 131 | { | 75 | { |
| 132 | HRESULT hr = S_OK; | 76 | HRESULT hr = S_OK; |
| 133 | LPWSTR sczValue = NULL; | ||
| 134 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_ARGS, pArgs); | 77 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_ARGS, pArgs); |
| 135 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_RESULTS, pResults); | 78 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_RESULTS, pResults); |
| 136 | LPCWSTR wzVariable = pArgs->wzVariable; | ||
| 137 | LPWSTR wzValue = pResults->wzValue; | ||
| 138 | DWORD* pcchValue = &pResults->cchValue; | ||
| 139 | 79 | ||
| 140 | if (wzVariable && *wzVariable) | 80 | hr = ExternalEngineGetVariableString(pContext->pEngineState, pArgs->wzVariable, pResults->wzValue, &pResults->cchValue); |
| 141 | { | ||
| 142 | hr = VariableGetString(&pContext->pEngineState->variables, wzVariable, &sczValue); | ||
| 143 | if (SUCCEEDED(hr)) | ||
| 144 | { | ||
| 145 | hr = CopyStringToBE(sczValue, wzValue, pcchValue); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | else | ||
| 149 | { | ||
| 150 | hr = E_INVALIDARG; | ||
| 151 | } | ||
| 152 | 81 | ||
| 153 | LExit: | 82 | LExit: |
| 154 | StrSecureZeroFreeString(sczValue); | ||
| 155 | return hr; | 83 | return hr; |
| 156 | } | 84 | } |
| 157 | 85 | ||
| @@ -162,29 +90,12 @@ static HRESULT BEEngineGetVariableVersion( | |||
| 162 | ) | 90 | ) |
| 163 | { | 91 | { |
| 164 | HRESULT hr = S_OK; | 92 | HRESULT hr = S_OK; |
| 165 | VERUTIL_VERSION* pVersion = NULL; | ||
| 166 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_ARGS, pArgs); | 93 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_ARGS, pArgs); |
| 167 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_RESULTS, pResults); | 94 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_RESULTS, pResults); |
| 168 | LPCWSTR wzVariable = pArgs->wzVariable; | ||
| 169 | LPWSTR wzValue = pResults->wzValue; | ||
| 170 | DWORD* pcchValue = &pResults->cchValue; | ||
| 171 | 95 | ||
| 172 | if (wzVariable && *wzVariable) | 96 | hr = ExternalEngineGetVariableVersion(pContext->pEngineState, pArgs->wzVariable, pResults->wzValue, &pResults->cchValue); |
| 173 | { | ||
| 174 | hr = VariableGetVersion(&pContext->pEngineState->variables, wzVariable, &pVersion); | ||
| 175 | if (SUCCEEDED(hr)) | ||
| 176 | { | ||
| 177 | hr = CopyStringToBE(pVersion->sczVersion, wzValue, pcchValue); | ||
| 178 | } | ||
| 179 | } | ||
| 180 | else | ||
| 181 | { | ||
| 182 | hr = E_INVALIDARG; | ||
| 183 | } | ||
| 184 | 97 | ||
| 185 | LExit: | 98 | LExit: |
| 186 | ReleaseVerutilVersion(pVersion); | ||
| 187 | |||
| 188 | return hr; | 99 | return hr; |
| 189 | } | 100 | } |
| 190 | 101 | ||
| @@ -198,10 +109,8 @@ static HRESULT BEEngineLog( | |||
| 198 | REPORT_LEVEL rl = REPORT_NONE; | 109 | REPORT_LEVEL rl = REPORT_NONE; |
| 199 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_LOG_ARGS, pArgs); | 110 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_LOG_ARGS, pArgs); |
| 200 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_LOG_RESULTS, pResults); | 111 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_LOG_RESULTS, pResults); |
| 201 | BUNDLE_EXTENSION_LOG_LEVEL level = pArgs->level; | ||
| 202 | LPCWSTR wzMessage = pArgs->wzMessage; | ||
| 203 | 112 | ||
| 204 | switch (level) | 113 | switch (pArgs->level) |
| 205 | { | 114 | { |
| 206 | case BUNDLE_EXTENSION_LOG_LEVEL_STANDARD: | 115 | case BUNDLE_EXTENSION_LOG_LEVEL_STANDARD: |
| 207 | rl = REPORT_STANDARD; | 116 | rl = REPORT_STANDARD; |
| @@ -223,7 +132,7 @@ static HRESULT BEEngineLog( | |||
| 223 | ExitFunction1(hr = E_INVALIDARG); | 132 | ExitFunction1(hr = E_INVALIDARG); |
| 224 | } | 133 | } |
| 225 | 134 | ||
| 226 | hr = LogStringLine(rl, "%ls", wzMessage); | 135 | hr = ExternalEngineLog(rl, pArgs->wzMessage); |
| 227 | ExitOnFailure(hr, "Failed to log Bundle Extension message."); | 136 | ExitOnFailure(hr, "Failed to log Bundle Extension message."); |
| 228 | 137 | ||
| 229 | LExit: | 138 | LExit: |
| @@ -239,19 +148,8 @@ static HRESULT BEEngineSetVariableNumeric( | |||
| 239 | HRESULT hr = S_OK; | 148 | HRESULT hr = S_OK; |
| 240 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_SETVARIABLENUMERIC_ARGS, pArgs); | 149 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_SETVARIABLENUMERIC_ARGS, pArgs); |
| 241 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_SETVARIABLENUMERIC_RESULTS, pResults); | 150 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_SETVARIABLENUMERIC_RESULTS, pResults); |
| 242 | LPCWSTR wzVariable = pArgs->wzVariable; | ||
| 243 | LONGLONG llValue = pArgs->llValue; | ||
| 244 | 151 | ||
| 245 | if (wzVariable && *wzVariable) | 152 | hr = ExternalEngineSetVariableNumeric(pContext->pEngineState, pArgs->wzVariable, pArgs->llValue); |
| 246 | { | ||
| 247 | hr = VariableSetNumeric(&pContext->pEngineState->variables, wzVariable, llValue, FALSE); | ||
| 248 | ExitOnFailure(hr, "Failed to set numeric variable."); | ||
| 249 | } | ||
| 250 | else | ||
| 251 | { | ||
| 252 | hr = E_INVALIDARG; | ||
| 253 | ExitOnFailure(hr, "Bundle Extension did not provide variable name."); | ||
| 254 | } | ||
| 255 | 153 | ||
| 256 | LExit: | 154 | LExit: |
| 257 | return hr; | 155 | return hr; |
| @@ -266,19 +164,8 @@ static HRESULT BEEngineSetVariableString( | |||
| 266 | HRESULT hr = S_OK; | 164 | HRESULT hr = S_OK; |
| 267 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_ARGS, pArgs); | 165 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_ARGS, pArgs); |
| 268 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_RESULTS, pResults); | 166 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_RESULTS, pResults); |
| 269 | LPCWSTR wzVariable = pArgs->wzVariable; | ||
| 270 | LPCWSTR wzValue = pArgs->wzValue; | ||
| 271 | 167 | ||
| 272 | if (wzVariable && *wzVariable) | 168 | hr = ExternalEngineSetVariableString(pContext->pEngineState, pArgs->wzVariable, pArgs->wzValue, pArgs->fFormatted); |
| 273 | { | ||
| 274 | hr = VariableSetString(&pContext->pEngineState->variables, wzVariable, wzValue, FALSE, pArgs->fFormatted); | ||
| 275 | ExitOnFailure(hr, "Failed to set string variable."); | ||
| 276 | } | ||
| 277 | else | ||
| 278 | { | ||
| 279 | hr = E_INVALIDARG; | ||
| 280 | ExitOnFailure(hr, "Bundle Extension did not provide variable name."); | ||
| 281 | } | ||
| 282 | 169 | ||
| 283 | LExit: | 170 | LExit: |
| 284 | return hr; | 171 | return hr; |
| @@ -291,32 +178,12 @@ static HRESULT BEEngineSetVariableVersion( | |||
| 291 | ) | 178 | ) |
| 292 | { | 179 | { |
| 293 | HRESULT hr = S_OK; | 180 | HRESULT hr = S_OK; |
| 294 | VERUTIL_VERSION* pVersion = NULL; | ||
| 295 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_ARGS, pArgs); | 181 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_ARGS, pArgs); |
| 296 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_RESULTS, pResults); | 182 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_RESULTS, pResults); |
| 297 | LPCWSTR wzVariable = pArgs->wzVariable; | ||
| 298 | LPCWSTR wzValue = pArgs->wzValue; | ||
| 299 | 183 | ||
| 300 | if (wzVariable && *wzVariable) | 184 | hr = ExternalEngineSetVariableVersion(pContext->pEngineState, pArgs->wzVariable, pArgs->wzValue); |
| 301 | { | ||
| 302 | if (wzValue) | ||
| 303 | { | ||
| 304 | hr = VerParseVersion(wzValue, 0, FALSE, &pVersion); | ||
| 305 | ExitOnFailure(hr, "Failed to parse new version value."); | ||
| 306 | } | ||
| 307 | |||
| 308 | hr = VariableSetVersion(&pContext->pEngineState->variables, wzVariable, pVersion, FALSE); | ||
| 309 | ExitOnFailure(hr, "Failed to set version variable."); | ||
| 310 | } | ||
| 311 | else | ||
| 312 | { | ||
| 313 | hr = E_INVALIDARG; | ||
| 314 | ExitOnFailure(hr, "Bundle Extension did not provide variable name."); | ||
| 315 | } | ||
| 316 | 185 | ||
| 317 | LExit: | 186 | LExit: |
| 318 | ReleaseVerutilVersion(pVersion); | ||
| 319 | |||
| 320 | return hr; | 187 | return hr; |
| 321 | } | 188 | } |
| 322 | 189 | ||
| @@ -329,11 +196,8 @@ static HRESULT BEEngineCompareVersions( | |||
| 329 | HRESULT hr = S_OK; | 196 | HRESULT hr = S_OK; |
| 330 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_COMPAREVERSIONS_ARGS, pArgs); | 197 | ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_COMPAREVERSIONS_ARGS, pArgs); |
| 331 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_COMPAREVERSIONS_RESULTS, pResults); | 198 | ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_COMPAREVERSIONS_RESULTS, pResults); |
| 332 | LPCWSTR wzVersion1 = pArgs->wzVersion1; | ||
| 333 | LPCWSTR wzVersion2 = pArgs->wzVersion2; | ||
| 334 | int* pnResult = &pResults->nResult; | ||
| 335 | 199 | ||
| 336 | hr = VerCompareStringVersions(wzVersion1, wzVersion2, FALSE, pnResult); | 200 | hr = ExternalEngineCompareVersions(pArgs->wzVersion1, pArgs->wzVersion2, &pResults->nResult); |
| 337 | 201 | ||
| 338 | LExit: | 202 | LExit: |
| 339 | return hr; | 203 | return hr; |
| @@ -397,34 +261,3 @@ HRESULT WINAPI EngineForExtensionProc( | |||
| 397 | LExit: | 261 | LExit: |
| 398 | return hr; | 262 | return hr; |
| 399 | } | 263 | } |
| 400 | |||
| 401 | static HRESULT CopyStringToBE( | ||
| 402 | __in LPWSTR wzValue, | ||
| 403 | __in LPWSTR wzBuffer, | ||
| 404 | __inout DWORD* pcchBuffer | ||
| 405 | ) | ||
| 406 | { | ||
| 407 | HRESULT hr = S_OK; | ||
| 408 | BOOL fTooSmall = !wzBuffer; | ||
| 409 | |||
| 410 | if (!fTooSmall) | ||
| 411 | { | ||
| 412 | hr = ::StringCchCopyExW(wzBuffer, *pcchBuffer, wzValue, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); | ||
| 413 | if (STRSAFE_E_INSUFFICIENT_BUFFER == hr) | ||
| 414 | { | ||
| 415 | fTooSmall = TRUE; | ||
| 416 | } | ||
| 417 | } | ||
| 418 | |||
| 419 | if (fTooSmall) | ||
| 420 | { | ||
| 421 | hr = ::StringCchLengthW(wzValue, STRSAFE_MAX_CCH, reinterpret_cast<size_t*>(pcchBuffer)); | ||
| 422 | if (SUCCEEDED(hr)) | ||
| 423 | { | ||
| 424 | hr = E_MOREDATA; | ||
| 425 | *pcchBuffer += 1; // null terminator. | ||
| 426 | } | ||
| 427 | } | ||
| 428 | |||
| 429 | return hr; | ||
| 430 | } | ||
