diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2022-05-26 17:34:07 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-05-31 13:20:44 -0500 |
commit | a070d8c7b57d6c9a54106abeb359a6c868b6d7ae (patch) | |
tree | 5236359530757a11395580cf8775ffea90c912d0 /src | |
parent | dea25f58e6119ef1acc5c5cc2a7c98e52cdff519 (diff) | |
download | wix-a070d8c7b57d6c9a54106abeb359a6c868b6d7ae.tar.gz wix-a070d8c7b57d6c9a54106abeb359a6c868b6d7ae.tar.bz2 wix-a070d8c7b57d6c9a54106abeb359a6c868b6d7ae.zip |
Update payload.cpp and container.cpp to use more concise Exit* macros.
Diffstat (limited to 'src')
-rw-r--r-- | src/burn/engine/container.cpp | 32 | ||||
-rw-r--r-- | src/burn/engine/payload.cpp | 65 |
2 files changed, 43 insertions, 54 deletions
diff --git a/src/burn/engine/container.cpp b/src/burn/engine/container.cpp index aa123927..2f21baa8 100644 --- a/src/burn/engine/container.cpp +++ b/src/burn/engine/container.cpp | |||
@@ -15,6 +15,7 @@ extern "C" HRESULT ContainersParseFromXml( | |||
15 | IXMLDOMNode* pixnNode = NULL; | 15 | IXMLDOMNode* pixnNode = NULL; |
16 | DWORD cNodes = 0; | 16 | DWORD cNodes = 0; |
17 | LPWSTR scz = NULL; | 17 | LPWSTR scz = NULL; |
18 | BOOL fXmlFound = FALSE; | ||
18 | 19 | ||
19 | // select container nodes | 20 | // select container nodes |
20 | hr = XmlSelectNodes(pixnBundle, L"Container", &pixnNodes); | 21 | hr = XmlSelectNodes(pixnBundle, L"Container", &pixnNodes); |
@@ -48,26 +49,20 @@ extern "C" HRESULT ContainersParseFromXml( | |||
48 | 49 | ||
49 | // @Id | 50 | // @Id |
50 | hr = XmlGetAttributeEx(pixnNode, L"Id", &pContainer->sczId); | 51 | hr = XmlGetAttributeEx(pixnNode, L"Id", &pContainer->sczId); |
51 | ExitOnFailure(hr, "Failed to get @Id."); | 52 | ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Id."); |
52 | 53 | ||
53 | // @Attached | 54 | // @Attached |
54 | hr = XmlGetYesNoAttribute(pixnNode, L"Attached", &pContainer->fAttached); | 55 | hr = XmlGetYesNoAttribute(pixnNode, L"Attached", &pContainer->fAttached); |
55 | if (E_NOTFOUND != hr) | 56 | ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @Attached."); |
56 | { | ||
57 | ExitOnFailure(hr, "Failed to get @Attached."); | ||
58 | } | ||
59 | |||
60 | // @AttachedIndex | ||
61 | hr = XmlGetAttributeNumber(pixnNode, L"AttachedIndex", &pContainer->dwAttachedIndex); | ||
62 | if (E_NOTFOUND != hr || pContainer->fAttached) // if it is an attached container it must have an index | ||
63 | { | ||
64 | ExitOnFailure(hr, "Failed to get @AttachedIndex."); | ||
65 | } | ||
66 | 57 | ||
67 | // Attached containers are always found attached to the current process, so use the current proccess's | 58 | // Attached containers are always found attached to the current process, so use the current proccess's |
68 | // name instead of what may be in the manifest. | 59 | // name instead of what may be in the manifest. |
69 | if (pContainer->fAttached) | 60 | if (pContainer->fAttached) |
70 | { | 61 | { |
62 | // @AttachedIndex | ||
63 | hr = XmlGetAttributeNumber(pixnNode, L"AttachedIndex", &pContainer->dwAttachedIndex); | ||
64 | ExitOnRequiredXmlQueryFailure(hr, "Failed to get @AttachedIndex."); | ||
65 | |||
71 | hr = PathForCurrentProcess(&scz, NULL); | 66 | hr = PathForCurrentProcess(&scz, NULL); |
72 | ExitOnFailure(hr, "Failed to get path to current process for attached container."); | 67 | ExitOnFailure(hr, "Failed to get path to current process for attached container."); |
73 | 68 | ||
@@ -80,7 +75,7 @@ extern "C" HRESULT ContainersParseFromXml( | |||
80 | { | 75 | { |
81 | // @FilePath | 76 | // @FilePath |
82 | hr = XmlGetAttributeEx(pixnNode, L"FilePath", &pContainer->sczFilePath); | 77 | hr = XmlGetAttributeEx(pixnNode, L"FilePath", &pContainer->sczFilePath); |
83 | ExitOnFailure(hr, "Failed to get @FilePath."); | 78 | ExitOnRequiredXmlQueryFailure(hr, "Failed to get @FilePath."); |
84 | } | 79 | } |
85 | 80 | ||
86 | // The source path starts as the file path. | 81 | // The source path starts as the file path. |
@@ -89,28 +84,25 @@ extern "C" HRESULT ContainersParseFromXml( | |||
89 | 84 | ||
90 | // @DownloadUrl | 85 | // @DownloadUrl |
91 | hr = XmlGetAttributeEx(pixnNode, L"DownloadUrl", &pContainer->downloadSource.sczUrl); | 86 | hr = XmlGetAttributeEx(pixnNode, L"DownloadUrl", &pContainer->downloadSource.sczUrl); |
92 | if (E_NOTFOUND != hr) | 87 | ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @DownloadUrl."); |
93 | { | ||
94 | ExitOnFailure(hr, "Failed to get @DownloadUrl."); | ||
95 | } | ||
96 | 88 | ||
97 | // @Hash | 89 | // @Hash |
98 | hr = XmlGetAttributeEx(pixnNode, L"Hash", &pContainer->sczHash); | 90 | hr = XmlGetAttributeEx(pixnNode, L"Hash", &pContainer->sczHash); |
99 | ExitOnFailure(hr, "Failed to get @Hash."); | 91 | ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Hash."); |
100 | 92 | ||
101 | hr = StrAllocHexDecode(pContainer->sczHash, &pContainer->pbHash, &pContainer->cbHash); | 93 | hr = StrAllocHexDecode(pContainer->sczHash, &pContainer->pbHash, &pContainer->cbHash); |
102 | ExitOnFailure(hr, "Failed to hex decode the Container/@Hash."); | 94 | ExitOnFailure(hr, "Failed to hex decode the Container/@Hash."); |
103 | 95 | ||
104 | // @FileSize | 96 | // @FileSize |
105 | hr = XmlGetAttributeEx(pixnNode, L"FileSize", &scz); | 97 | hr = XmlGetAttributeEx(pixnNode, L"FileSize", &scz); |
106 | ExitOnFailure(hr, "Failed to get @FileSize."); | 98 | ExitOnRequiredXmlQueryFailure(hr, "Failed to get @FileSize."); |
107 | 99 | ||
108 | hr = StrStringToUInt64(scz, 0, &pContainer->qwFileSize); | 100 | hr = StrStringToUInt64(scz, 0, &pContainer->qwFileSize); |
109 | ExitOnFailure(hr, "Failed to parse @FileSize."); | 101 | ExitOnFailure(hr, "Failed to parse @FileSize."); |
110 | 102 | ||
111 | if (!pContainer->qwFileSize) | 103 | if (!pContainer->qwFileSize) |
112 | { | 104 | { |
113 | ExitOnRootFailure(hr = E_INVALIDDATA, "File size is required when verifying by hash for container: %ls", pContainer->sczId); | 105 | ExitWithRootFailure(hr, E_INVALIDDATA, "File size is required when verifying by hash for container: %ls", pContainer->sczId); |
114 | } | 106 | } |
115 | 107 | ||
116 | pContainer->verification = BURN_CONTAINER_VERIFICATION_HASH; | 108 | pContainer->verification = BURN_CONTAINER_VERIFICATION_HASH; |
diff --git a/src/burn/engine/payload.cpp b/src/burn/engine/payload.cpp index e0362a76..6acfcd73 100644 --- a/src/burn/engine/payload.cpp +++ b/src/burn/engine/payload.cpp | |||
@@ -23,6 +23,7 @@ extern "C" HRESULT PayloadsParseFromXml( | |||
23 | BOOL fChainPayload = pContainers && pLayoutPayloads; // These are required when parsing chain payloads. | 23 | BOOL fChainPayload = pContainers && pLayoutPayloads; // These are required when parsing chain payloads. |
24 | BOOL fValidFileSize = FALSE; | 24 | BOOL fValidFileSize = FALSE; |
25 | size_t cByteOffset = fChainPayload ? offsetof(BURN_PAYLOAD, sczKey) : offsetof(BURN_PAYLOAD, sczSourcePath); | 25 | size_t cByteOffset = fChainPayload ? offsetof(BURN_PAYLOAD, sczKey) : offsetof(BURN_PAYLOAD, sczSourcePath); |
26 | BOOL fXmlFound = FALSE; | ||
26 | 27 | ||
27 | // select payload nodes | 28 | // select payload nodes |
28 | hr = XmlSelectNodes(pixnBundle, L"Payload", &pixnNodes); | 29 | hr = XmlSelectNodes(pixnBundle, L"Payload", &pixnNodes); |
@@ -58,15 +59,15 @@ extern "C" HRESULT PayloadsParseFromXml( | |||
58 | 59 | ||
59 | // @Id | 60 | // @Id |
60 | hr = XmlGetAttributeEx(pixnNode, L"Id", &pPayload->sczKey); | 61 | hr = XmlGetAttributeEx(pixnNode, L"Id", &pPayload->sczKey); |
61 | ExitOnFailure(hr, "Failed to get @Id."); | 62 | ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Id."); |
62 | 63 | ||
63 | // @FilePath | 64 | // @FilePath |
64 | hr = XmlGetAttributeEx(pixnNode, L"FilePath", &pPayload->sczFilePath); | 65 | hr = XmlGetAttributeEx(pixnNode, L"FilePath", &pPayload->sczFilePath); |
65 | ExitOnFailure(hr, "Failed to get @FilePath."); | 66 | ExitOnRequiredXmlQueryFailure(hr, "Failed to get @FilePath."); |
66 | 67 | ||
67 | // @SourcePath | 68 | // @SourcePath |
68 | hr = XmlGetAttributeEx(pixnNode, L"SourcePath", &pPayload->sczSourcePath); | 69 | hr = XmlGetAttributeEx(pixnNode, L"SourcePath", &pPayload->sczSourcePath); |
69 | ExitOnFailure(hr, "Failed to get @SourcePath."); | 70 | ExitOnRequiredXmlQueryFailure(hr, "Failed to get @SourcePath."); |
70 | 71 | ||
71 | if (!fChainPayload) | 72 | if (!fChainPayload) |
72 | { | 73 | { |
@@ -77,7 +78,7 @@ extern "C" HRESULT PayloadsParseFromXml( | |||
77 | { | 78 | { |
78 | // @Packaging | 79 | // @Packaging |
79 | hr = XmlGetAttributeEx(pixnNode, L"Packaging", &scz); | 80 | hr = XmlGetAttributeEx(pixnNode, L"Packaging", &scz); |
80 | ExitOnFailure(hr, "Failed to get @Packaging."); | 81 | ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Packaging."); |
81 | 82 | ||
82 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"embedded", -1)) | 83 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"embedded", -1)) |
83 | { | 84 | { |
@@ -89,43 +90,40 @@ extern "C" HRESULT PayloadsParseFromXml( | |||
89 | } | 90 | } |
90 | else | 91 | else |
91 | { | 92 | { |
92 | hr = E_INVALIDARG; | 93 | ExitWithRootFailure(hr, E_INVALIDARG, "Invalid value for @Packaging: %ls", scz); |
93 | ExitOnFailure(hr, "Invalid value for @Packaging: %ls", scz); | ||
94 | } | 94 | } |
95 | 95 | ||
96 | // @Container | 96 | // @Container |
97 | hr = XmlGetAttributeEx(pixnNode, L"Container", &scz); | 97 | hr = XmlGetAttributeEx(pixnNode, L"Container", &scz); |
98 | if (E_NOTFOUND != hr || BURN_PAYLOAD_PACKAGING_EMBEDDED == pPayload->packaging) | 98 | ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @Container."); |
99 | { | ||
100 | ExitOnFailure(hr, "Failed to get @Container."); | ||
101 | 99 | ||
100 | if (fXmlFound) | ||
101 | { | ||
102 | // find container | 102 | // find container |
103 | hr = ContainerFindById(pContainers, scz, &pPayload->pContainer); | 103 | hr = ContainerFindById(pContainers, scz, &pPayload->pContainer); |
104 | ExitOnFailure(hr, "Failed to to find container: %ls", scz); | 104 | ExitOnFailure(hr, "Failed to find container: %ls", scz); |
105 | 105 | ||
106 | pPayload->pContainer->cParsedPayloads += 1; | 106 | pPayload->pContainer->cParsedPayloads += 1; |
107 | } | 107 | } |
108 | else if (BURN_PAYLOAD_PACKAGING_EMBEDDED == pPayload->packaging) | ||
109 | { | ||
110 | ExitWithRootFailure(hr, E_NOTFOUND, "@Container is required for embedded payload."); | ||
111 | } | ||
108 | 112 | ||
109 | // @LayoutOnly | 113 | // @LayoutOnly |
110 | hr = XmlGetYesNoAttribute(pixnNode, L"LayoutOnly", &pPayload->fLayoutOnly); | 114 | hr = XmlGetYesNoAttribute(pixnNode, L"LayoutOnly", &pPayload->fLayoutOnly); |
111 | if (E_NOTFOUND != hr) | 115 | ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @LayoutOnly."); |
112 | { | ||
113 | ExitOnFailure(hr, "Failed to get @LayoutOnly."); | ||
114 | } | ||
115 | 116 | ||
116 | // @DownloadUrl | 117 | // @DownloadUrl |
117 | hr = XmlGetAttributeEx(pixnNode, L"DownloadUrl", &pPayload->downloadSource.sczUrl); | 118 | hr = XmlGetAttributeEx(pixnNode, L"DownloadUrl", &pPayload->downloadSource.sczUrl); |
118 | if (E_NOTFOUND != hr) | 119 | ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @DownloadUrl."); |
119 | { | ||
120 | ExitOnFailure(hr, "Failed to get @DownloadUrl."); | ||
121 | } | ||
122 | 120 | ||
123 | // @FileSize | 121 | // @FileSize |
124 | hr = XmlGetAttributeEx(pixnNode, L"FileSize", &scz); | 122 | hr = XmlGetAttributeEx(pixnNode, L"FileSize", &scz); |
125 | if (E_NOTFOUND != hr) | 123 | ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @FileSize."); |
126 | { | ||
127 | ExitOnFailure(hr, "Failed to get @FileSize."); | ||
128 | 124 | ||
125 | if (fXmlFound) | ||
126 | { | ||
129 | hr = StrStringToUInt64(scz, 0, &pPayload->qwFileSize); | 127 | hr = StrStringToUInt64(scz, 0, &pPayload->qwFileSize); |
130 | ExitOnFailure(hr, "Failed to parse @FileSize."); | 128 | ExitOnFailure(hr, "Failed to parse @FileSize."); |
131 | 129 | ||
@@ -134,10 +132,10 @@ extern "C" HRESULT PayloadsParseFromXml( | |||
134 | 132 | ||
135 | // @CertificateAuthorityKeyIdentifier | 133 | // @CertificateAuthorityKeyIdentifier |
136 | hr = XmlGetAttributeEx(pixnNode, L"CertificateRootPublicKeyIdentifier", &scz); | 134 | hr = XmlGetAttributeEx(pixnNode, L"CertificateRootPublicKeyIdentifier", &scz); |
137 | if (E_NOTFOUND != hr) | 135 | ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @CertificateRootPublicKeyIdentifier."); |
138 | { | ||
139 | ExitOnFailure(hr, "Failed to get @CertificateRootPublicKeyIdentifier."); | ||
140 | 136 | ||
137 | if (fXmlFound) | ||
138 | { | ||
141 | hr = StrAllocHexDecode(scz, &pPayload->pbCertificateRootPublicKeyIdentifier, &pPayload->cbCertificateRootPublicKeyIdentifier); | 139 | hr = StrAllocHexDecode(scz, &pPayload->pbCertificateRootPublicKeyIdentifier, &pPayload->cbCertificateRootPublicKeyIdentifier); |
142 | ExitOnFailure(hr, "Failed to hex decode @CertificateRootPublicKeyIdentifier."); | 140 | ExitOnFailure(hr, "Failed to hex decode @CertificateRootPublicKeyIdentifier."); |
143 | 141 | ||
@@ -146,20 +144,20 @@ extern "C" HRESULT PayloadsParseFromXml( | |||
146 | 144 | ||
147 | // @CertificateThumbprint | 145 | // @CertificateThumbprint |
148 | hr = XmlGetAttributeEx(pixnNode, L"CertificateRootThumbprint", &scz); | 146 | hr = XmlGetAttributeEx(pixnNode, L"CertificateRootThumbprint", &scz); |
149 | if (E_NOTFOUND != hr) | 147 | ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @CertificateRootThumbprint."); |
150 | { | ||
151 | ExitOnFailure(hr, "Failed to get @CertificateRootThumbprint."); | ||
152 | 148 | ||
149 | if (fXmlFound) | ||
150 | { | ||
153 | hr = StrAllocHexDecode(scz, &pPayload->pbCertificateRootThumbprint, &pPayload->cbCertificateRootThumbprint); | 151 | hr = StrAllocHexDecode(scz, &pPayload->pbCertificateRootThumbprint, &pPayload->cbCertificateRootThumbprint); |
154 | ExitOnFailure(hr, "Failed to hex decode @CertificateRootThumbprint."); | 152 | ExitOnFailure(hr, "Failed to hex decode @CertificateRootThumbprint."); |
155 | } | 153 | } |
156 | 154 | ||
157 | // @Hash | 155 | // @Hash |
158 | hr = XmlGetAttributeEx(pixnNode, L"Hash", &scz); | 156 | hr = XmlGetAttributeEx(pixnNode, L"Hash", &scz); |
159 | if (E_NOTFOUND != hr) | 157 | ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @Hash."); |
160 | { | ||
161 | ExitOnFailure(hr, "Failed to get @Hash."); | ||
162 | 158 | ||
159 | if (fXmlFound) | ||
160 | { | ||
163 | hr = StrAllocHexDecode(scz, &pPayload->pbHash, &pPayload->cbHash); | 161 | hr = StrAllocHexDecode(scz, &pPayload->pbHash, &pPayload->cbHash); |
164 | ExitOnFailure(hr, "Failed to hex decode the Payload/@Hash."); | 162 | ExitOnFailure(hr, "Failed to hex decode the Payload/@Hash."); |
165 | 163 | ||
@@ -171,11 +169,11 @@ extern "C" HRESULT PayloadsParseFromXml( | |||
171 | 169 | ||
172 | if (BURN_PAYLOAD_VERIFICATION_NONE == pPayload->verification) | 170 | if (BURN_PAYLOAD_VERIFICATION_NONE == pPayload->verification) |
173 | { | 171 | { |
174 | ExitOnRootFailure(hr = E_INVALIDDATA, "There was no verification information for payload: %ls", pPayload->sczKey); | 172 | ExitWithRootFailure(hr, E_INVALIDDATA, "There was no verification information for payload: %ls", pPayload->sczKey); |
175 | } | 173 | } |
176 | else if (BURN_PAYLOAD_VERIFICATION_HASH == pPayload->verification && !fValidFileSize) | 174 | else if (BURN_PAYLOAD_VERIFICATION_HASH == pPayload->verification && !fValidFileSize) |
177 | { | 175 | { |
178 | ExitOnRootFailure(hr = E_INVALIDDATA, "File size is required when verifying by hash for payload: %ls", pPayload->sczKey); | 176 | ExitWithRootFailure(hr, E_INVALIDDATA, "File size is required when verifying by hash for payload: %ls", pPayload->sczKey); |
179 | } | 177 | } |
180 | 178 | ||
181 | if (pPayload->fLayoutOnly) | 179 | if (pPayload->fLayoutOnly) |
@@ -321,8 +319,7 @@ extern "C" HRESULT PayloadExtractUXContainer( | |||
321 | // if the payload has not been acquired | 319 | // if the payload has not been acquired |
322 | if (BURN_PAYLOAD_STATE_ACQUIRED > pPayload->state) | 320 | if (BURN_PAYLOAD_STATE_ACQUIRED > pPayload->state) |
323 | { | 321 | { |
324 | hr = E_INVALIDDATA; | 322 | ExitWithRootFailure(hr, E_INVALIDDATA, "Payload was not found in container: %ls", pPayload->sczKey); |
325 | ExitOnRootFailure(hr, "Payload was not found in container: %ls", pPayload->sczKey); | ||
326 | } | 323 | } |
327 | } | 324 | } |
328 | 325 | ||