From fdd47bab30235f62a8bcc7a5a88c6d69267046aa Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Tue, 17 Nov 2020 18:53:13 -0600 Subject: Consolidate the code for the BA and bext engines. --- src/engine/EngineForExtension.cpp | 191 +++----------------------------------- 1 file changed, 12 insertions(+), 179 deletions(-) (limited to 'src/engine/EngineForExtension.cpp') 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 @@ #include "precomp.h" -static HRESULT CopyStringToBE( - __in LPWSTR wzValue, - __in LPWSTR wzBuffer, - __inout DWORD* pcchBuffer - ); - static HRESULT BEEngineEscapeString( __in BURN_EXTENSION_ENGINE_CONTEXT* /*pContext*/, __in const LPVOID pvArgs, @@ -16,28 +10,12 @@ static HRESULT BEEngineEscapeString( ) { HRESULT hr = S_OK; - LPWSTR sczValue = NULL; ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_ARGS, pArgs); ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_RESULTS, pResults); - LPCWSTR wzIn = pArgs->wzIn; - LPWSTR wzOut = pResults->wzOut; - DWORD* pcchOut = &pResults->cchOut; - if (wzIn && *wzIn) - { - hr = VariableEscapeString(wzIn, &sczValue); - if (SUCCEEDED(hr)) - { - hr = CopyStringToBE(sczValue, wzOut, pcchOut); - } - } - else - { - hr = E_INVALIDARG; - } + hr = ExternalEngineEscapeString(pArgs->wzIn, pResults->wzOut, &pResults->cchOut); LExit: - StrSecureZeroFreeString(sczValue); return hr; } @@ -50,17 +28,8 @@ static HRESULT BEEngineEvaluateCondition( HRESULT hr = S_OK; ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_EVALUATECONDITION_ARGS, pArgs); ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_EVALUATECONDITION_RESULTS, pResults); - LPCWSTR wzCondition = pArgs->wzCondition; - BOOL* pf = &pResults->f; - if (wzCondition && *wzCondition) - { - hr = ConditionEvaluate(&pContext->pEngineState->variables, wzCondition, pf); - } - else - { - hr = E_INVALIDARG; - } + hr = ExternalEngineEvaluateCondition(pContext->pEngineState, pArgs->wzCondition, &pResults->f); LExit: return hr; @@ -73,28 +42,12 @@ static HRESULT BEEngineFormatString( ) { HRESULT hr = S_OK; - LPWSTR sczValue = NULL; ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_FORMATSTRING_ARGS, pArgs); ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_FORMATSTRING_RESULTS, pResults); - LPCWSTR wzIn = pArgs->wzIn; - LPWSTR wzOut = pResults->wzOut; - DWORD* pcchOut = &pResults->cchOut; - if (wzIn && *wzIn) - { - hr = VariableFormatString(&pContext->pEngineState->variables, wzIn, &sczValue, NULL); - if (SUCCEEDED(hr)) - { - hr = CopyStringToBE(sczValue, wzOut, pcchOut); - } - } - else - { - hr = E_INVALIDARG; - } + hr = ExternalEngineFormatString(pContext->pEngineState, pArgs->wzIn, pResults->wzOut, &pResults->cchOut); LExit: - StrSecureZeroFreeString(sczValue); return hr; } @@ -107,17 +60,8 @@ static HRESULT BEEngineGetVariableNumeric( HRESULT hr = S_OK; ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_ARGS, pArgs); ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_RESULTS, pResults); - LPCWSTR wzVariable = pArgs->wzVariable; - LONGLONG* pllValue = &pResults->llValue; - if (wzVariable && *wzVariable) - { - hr = VariableGetNumeric(&pContext->pEngineState->variables, wzVariable, pllValue); - } - else - { - hr = E_INVALIDARG; - } + hr = ExternalEngineGetVariableNumeric(pContext->pEngineState, pArgs->wzVariable, &pResults->llValue); LExit: return hr; @@ -130,28 +74,12 @@ static HRESULT BEEngineGetVariableString( ) { HRESULT hr = S_OK; - LPWSTR sczValue = NULL; ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_ARGS, pArgs); ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_RESULTS, pResults); - LPCWSTR wzVariable = pArgs->wzVariable; - LPWSTR wzValue = pResults->wzValue; - DWORD* pcchValue = &pResults->cchValue; - if (wzVariable && *wzVariable) - { - hr = VariableGetString(&pContext->pEngineState->variables, wzVariable, &sczValue); - if (SUCCEEDED(hr)) - { - hr = CopyStringToBE(sczValue, wzValue, pcchValue); - } - } - else - { - hr = E_INVALIDARG; - } + hr = ExternalEngineGetVariableString(pContext->pEngineState, pArgs->wzVariable, pResults->wzValue, &pResults->cchValue); LExit: - StrSecureZeroFreeString(sczValue); return hr; } @@ -162,29 +90,12 @@ static HRESULT BEEngineGetVariableVersion( ) { HRESULT hr = S_OK; - VERUTIL_VERSION* pVersion = NULL; ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_ARGS, pArgs); ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_RESULTS, pResults); - LPCWSTR wzVariable = pArgs->wzVariable; - LPWSTR wzValue = pResults->wzValue; - DWORD* pcchValue = &pResults->cchValue; - if (wzVariable && *wzVariable) - { - hr = VariableGetVersion(&pContext->pEngineState->variables, wzVariable, &pVersion); - if (SUCCEEDED(hr)) - { - hr = CopyStringToBE(pVersion->sczVersion, wzValue, pcchValue); - } - } - else - { - hr = E_INVALIDARG; - } + hr = ExternalEngineGetVariableVersion(pContext->pEngineState, pArgs->wzVariable, pResults->wzValue, &pResults->cchValue); LExit: - ReleaseVerutilVersion(pVersion); - return hr; } @@ -198,10 +109,8 @@ static HRESULT BEEngineLog( REPORT_LEVEL rl = REPORT_NONE; ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_LOG_ARGS, pArgs); ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_LOG_RESULTS, pResults); - BUNDLE_EXTENSION_LOG_LEVEL level = pArgs->level; - LPCWSTR wzMessage = pArgs->wzMessage; - switch (level) + switch (pArgs->level) { case BUNDLE_EXTENSION_LOG_LEVEL_STANDARD: rl = REPORT_STANDARD; @@ -223,7 +132,7 @@ static HRESULT BEEngineLog( ExitFunction1(hr = E_INVALIDARG); } - hr = LogStringLine(rl, "%ls", wzMessage); + hr = ExternalEngineLog(rl, pArgs->wzMessage); ExitOnFailure(hr, "Failed to log Bundle Extension message."); LExit: @@ -239,19 +148,8 @@ static HRESULT BEEngineSetVariableNumeric( HRESULT hr = S_OK; ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_SETVARIABLENUMERIC_ARGS, pArgs); ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_SETVARIABLENUMERIC_RESULTS, pResults); - LPCWSTR wzVariable = pArgs->wzVariable; - LONGLONG llValue = pArgs->llValue; - if (wzVariable && *wzVariable) - { - hr = VariableSetNumeric(&pContext->pEngineState->variables, wzVariable, llValue, FALSE); - ExitOnFailure(hr, "Failed to set numeric variable."); - } - else - { - hr = E_INVALIDARG; - ExitOnFailure(hr, "Bundle Extension did not provide variable name."); - } + hr = ExternalEngineSetVariableNumeric(pContext->pEngineState, pArgs->wzVariable, pArgs->llValue); LExit: return hr; @@ -266,19 +164,8 @@ static HRESULT BEEngineSetVariableString( HRESULT hr = S_OK; ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_ARGS, pArgs); ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_RESULTS, pResults); - LPCWSTR wzVariable = pArgs->wzVariable; - LPCWSTR wzValue = pArgs->wzValue; - if (wzVariable && *wzVariable) - { - hr = VariableSetString(&pContext->pEngineState->variables, wzVariable, wzValue, FALSE, pArgs->fFormatted); - ExitOnFailure(hr, "Failed to set string variable."); - } - else - { - hr = E_INVALIDARG; - ExitOnFailure(hr, "Bundle Extension did not provide variable name."); - } + hr = ExternalEngineSetVariableString(pContext->pEngineState, pArgs->wzVariable, pArgs->wzValue, pArgs->fFormatted); LExit: return hr; @@ -291,32 +178,12 @@ static HRESULT BEEngineSetVariableVersion( ) { HRESULT hr = S_OK; - VERUTIL_VERSION* pVersion = NULL; ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_ARGS, pArgs); ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_RESULTS, pResults); - LPCWSTR wzVariable = pArgs->wzVariable; - LPCWSTR wzValue = pArgs->wzValue; - if (wzVariable && *wzVariable) - { - if (wzValue) - { - hr = VerParseVersion(wzValue, 0, FALSE, &pVersion); - ExitOnFailure(hr, "Failed to parse new version value."); - } - - hr = VariableSetVersion(&pContext->pEngineState->variables, wzVariable, pVersion, FALSE); - ExitOnFailure(hr, "Failed to set version variable."); - } - else - { - hr = E_INVALIDARG; - ExitOnFailure(hr, "Bundle Extension did not provide variable name."); - } + hr = ExternalEngineSetVariableVersion(pContext->pEngineState, pArgs->wzVariable, pArgs->wzValue); LExit: - ReleaseVerutilVersion(pVersion); - return hr; } @@ -329,11 +196,8 @@ static HRESULT BEEngineCompareVersions( HRESULT hr = S_OK; ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_COMPAREVERSIONS_ARGS, pArgs); ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_COMPAREVERSIONS_RESULTS, pResults); - LPCWSTR wzVersion1 = pArgs->wzVersion1; - LPCWSTR wzVersion2 = pArgs->wzVersion2; - int* pnResult = &pResults->nResult; - hr = VerCompareStringVersions(wzVersion1, wzVersion2, FALSE, pnResult); + hr = ExternalEngineCompareVersions(pArgs->wzVersion1, pArgs->wzVersion2, &pResults->nResult); LExit: return hr; @@ -397,34 +261,3 @@ HRESULT WINAPI EngineForExtensionProc( LExit: return hr; } - -static HRESULT CopyStringToBE( - __in LPWSTR wzValue, - __in LPWSTR wzBuffer, - __inout DWORD* pcchBuffer - ) -{ - HRESULT hr = S_OK; - BOOL fTooSmall = !wzBuffer; - - if (!fTooSmall) - { - hr = ::StringCchCopyExW(wzBuffer, *pcchBuffer, wzValue, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); - if (STRSAFE_E_INSUFFICIENT_BUFFER == hr) - { - fTooSmall = TRUE; - } - } - - if (fTooSmall) - { - hr = ::StringCchLengthW(wzValue, STRSAFE_MAX_CCH, reinterpret_cast(pcchBuffer)); - if (SUCCEEDED(hr)) - { - hr = E_MOREDATA; - *pcchBuffer += 1; // null terminator. - } - } - - return hr; -} -- cgit v1.2.3-55-g6feb