aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/apuputil.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dutil/apuputil.cpp116
1 files changed, 65 insertions, 51 deletions
diff --git a/src/dutil/apuputil.cpp b/src/dutil/apuputil.cpp
index bf655ecc..07d591a7 100644
--- a/src/dutil/apuputil.cpp
+++ b/src/dutil/apuputil.cpp
@@ -2,6 +2,20 @@
2 2
3#include "precomp.h" 3#include "precomp.h"
4 4
5// Exit macros
6#define ApupExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_APUPUTIL, x, s, __VA_ARGS__)
7#define ApupExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_APUPUTIL, x, s, __VA_ARGS__)
8#define ApupExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_APUPUTIL, x, s, __VA_ARGS__)
9#define ApupExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_APUPUTIL, x, s, __VA_ARGS__)
10#define ApupExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_APUPUTIL, x, s, __VA_ARGS__)
11#define ApupExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_APUPUTIL, x, s, __VA_ARGS__)
12#define ApupExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_APUPUTIL, p, x, e, s, __VA_ARGS__)
13#define ApupExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_APUPUTIL, p, x, s, __VA_ARGS__)
14#define ApupExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_APUPUTIL, p, x, e, s, __VA_ARGS__)
15#define ApupExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_APUPUTIL, p, x, s, __VA_ARGS__)
16#define ApupExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_APUPUTIL, e, x, s, __VA_ARGS__)
17#define ApupExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_APUPUTIL, g, x, s, __VA_ARGS__)
18
5// prototypes 19// prototypes
6static HRESULT ProcessEntry( 20static HRESULT ProcessEntry(
7 __in ATOM_ENTRY* pAtomEntry, 21 __in ATOM_ENTRY* pAtomEntry,
@@ -61,14 +75,14 @@ extern "C" HRESULT DAPI ApupAllocChainFromAtom(
61 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"application", -1)) 75 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"application", -1))
62 { 76 {
63 hr = StrAllocString(&pChain->wzDefaultApplicationId, pElement->wzValue, 0); 77 hr = StrAllocString(&pChain->wzDefaultApplicationId, pElement->wzValue, 0);
64 ExitOnFailure(hr, "Failed to allocate default application id."); 78 ApupExitOnFailure(hr, "Failed to allocate default application id.");
65 79
66 for (ATOM_UNKNOWN_ATTRIBUTE* pAttribute = pElement->pAttributes; pAttribute; pAttribute = pAttribute->pNext) 80 for (ATOM_UNKNOWN_ATTRIBUTE* pAttribute = pElement->pAttributes; pAttribute; pAttribute = pAttribute->pNext)
67 { 81 {
68 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"type", -1)) 82 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"type", -1))
69 { 83 {
70 hr = StrAllocString(&pChain->wzDefaultApplicationType, pAttribute->wzValue, 0); 84 hr = StrAllocString(&pChain->wzDefaultApplicationType, pAttribute->wzValue, 0);
71 ExitOnFailure(hr, "Failed to allocate default application type."); 85 ApupExitOnFailure(hr, "Failed to allocate default application type.");
72 } 86 }
73 } 87 }
74 } 88 }
@@ -79,13 +93,13 @@ extern "C" HRESULT DAPI ApupAllocChainFromAtom(
79 if (pFeed->cEntries) 93 if (pFeed->cEntries)
80 { 94 {
81 pChain->rgEntries = static_cast<APPLICATION_UPDATE_ENTRY*>(MemAlloc(sizeof(APPLICATION_UPDATE_ENTRY) * pFeed->cEntries, TRUE)); 95 pChain->rgEntries = static_cast<APPLICATION_UPDATE_ENTRY*>(MemAlloc(sizeof(APPLICATION_UPDATE_ENTRY) * pFeed->cEntries, TRUE));
82 ExitOnNull(pChain->rgEntries, hr, E_OUTOFMEMORY, "Failed to allocate memory for update entries."); 96 ApupExitOnNull(pChain->rgEntries, hr, E_OUTOFMEMORY, "Failed to allocate memory for update entries.");
83 97
84 // Process each entry, building up the chain. 98 // Process each entry, building up the chain.
85 for (DWORD i = 0; i < pFeed->cEntries; ++i) 99 for (DWORD i = 0; i < pFeed->cEntries; ++i)
86 { 100 {
87 hr = ProcessEntry(pFeed->rgEntries + i, pChain->wzDefaultApplicationId, pChain->rgEntries + pChain->cEntries); 101 hr = ProcessEntry(pFeed->rgEntries + i, pChain->wzDefaultApplicationId, pChain->rgEntries + pChain->cEntries);
88 ExitOnFailure(hr, "Failed to process ATOM entry."); 102 ApupExitOnFailure(hr, "Failed to process ATOM entry.");
89 103
90 if (S_FALSE != hr) 104 if (S_FALSE != hr)
91 { 105 {
@@ -103,7 +117,7 @@ extern "C" HRESULT DAPI ApupAllocChainFromAtom(
103 if (pChain->cEntries > 0) 117 if (pChain->cEntries > 0)
104 { 118 {
105 pChain->rgEntries = static_cast<APPLICATION_UPDATE_ENTRY*>(MemReAlloc(pChain->rgEntries, sizeof(APPLICATION_UPDATE_ENTRY) * pChain->cEntries, FALSE)); 119 pChain->rgEntries = static_cast<APPLICATION_UPDATE_ENTRY*>(MemReAlloc(pChain->rgEntries, sizeof(APPLICATION_UPDATE_ENTRY) * pChain->cEntries, FALSE));
106 ExitOnNull(pChain->rgEntries, hr, E_OUTOFMEMORY, "Failed to reallocate memory for update entries."); 120 ApupExitOnNull(pChain->rgEntries, hr, E_OUTOFMEMORY, "Failed to reallocate memory for update entries.");
107 } 121 }
108 else 122 else
109 { 123 {
@@ -136,21 +150,21 @@ HRESULT DAPI ApupFilterChain(
136 DWORD cEntries = NULL; 150 DWORD cEntries = NULL;
137 151
138 pNewChain = static_cast<APPLICATION_UPDATE_CHAIN*>(MemAlloc(sizeof(APPLICATION_UPDATE_CHAIN), TRUE)); 152 pNewChain = static_cast<APPLICATION_UPDATE_CHAIN*>(MemAlloc(sizeof(APPLICATION_UPDATE_CHAIN), TRUE));
139 ExitOnNull(pNewChain, hr, E_OUTOFMEMORY, "Failed to allocate filtered chain."); 153 ApupExitOnNull(pNewChain, hr, E_OUTOFMEMORY, "Failed to allocate filtered chain.");
140 154
141 hr = FilterEntries(pChain->rgEntries, pChain->cEntries, pVersion, &prgEntries, &cEntries); 155 hr = FilterEntries(pChain->rgEntries, pChain->cEntries, pVersion, &prgEntries, &cEntries);
142 ExitOnFailure(hr, "Failed to filter entries by version."); 156 ApupExitOnFailure(hr, "Failed to filter entries by version.");
143 157
144 if (pChain->wzDefaultApplicationId) 158 if (pChain->wzDefaultApplicationId)
145 { 159 {
146 hr = StrAllocString(&pNewChain->wzDefaultApplicationId, pChain->wzDefaultApplicationId, 0); 160 hr = StrAllocString(&pNewChain->wzDefaultApplicationId, pChain->wzDefaultApplicationId, 0);
147 ExitOnFailure(hr, "Failed to copy default application id."); 161 ApupExitOnFailure(hr, "Failed to copy default application id.");
148 } 162 }
149 163
150 if (pChain->wzDefaultApplicationType) 164 if (pChain->wzDefaultApplicationType)
151 { 165 {
152 hr = StrAllocString(&pNewChain->wzDefaultApplicationType, pChain->wzDefaultApplicationType, 0); 166 hr = StrAllocString(&pNewChain->wzDefaultApplicationType, pChain->wzDefaultApplicationType, 0);
153 ExitOnFailure(hr, "Failed to copy default application type."); 167 ApupExitOnFailure(hr, "Failed to copy default application type.");
154 } 168 }
155 169
156 pNewChain->rgEntries = prgEntries; 170 pNewChain->rgEntries = prgEntries;
@@ -205,28 +219,28 @@ static HRESULT ProcessEntry(
205 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"application", -1)) 219 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"application", -1))
206 { 220 {
207 hr = StrAllocString(&pApupEntry->wzApplicationId, pElement->wzValue, 0); 221 hr = StrAllocString(&pApupEntry->wzApplicationId, pElement->wzValue, 0);
208 ExitOnFailure(hr, "Failed to allocate application identity."); 222 ApupExitOnFailure(hr, "Failed to allocate application identity.");
209 223
210 for (ATOM_UNKNOWN_ATTRIBUTE* pAttribute = pElement->pAttributes; pAttribute; pAttribute = pAttribute->pNext) 224 for (ATOM_UNKNOWN_ATTRIBUTE* pAttribute = pElement->pAttributes; pAttribute; pAttribute = pAttribute->pNext)
211 { 225 {
212 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"type", -1)) 226 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"type", -1))
213 { 227 {
214 hr = StrAllocString(&pApupEntry->wzApplicationType, pAttribute->wzValue, 0); 228 hr = StrAllocString(&pApupEntry->wzApplicationType, pAttribute->wzValue, 0);
215 ExitOnFailure(hr, "Failed to allocate application type."); 229 ApupExitOnFailure(hr, "Failed to allocate application type.");
216 } 230 }
217 } 231 }
218 } 232 }
219 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"upgrade", -1)) 233 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"upgrade", -1))
220 { 234 {
221 hr = StrAllocString(&pApupEntry->wzUpgradeId, pElement->wzValue, 0); 235 hr = StrAllocString(&pApupEntry->wzUpgradeId, pElement->wzValue, 0);
222 ExitOnFailure(hr, "Failed to allocate upgrade id."); 236 ApupExitOnFailure(hr, "Failed to allocate upgrade id.");
223 237
224 for (ATOM_UNKNOWN_ATTRIBUTE* pAttribute = pElement->pAttributes; pAttribute; pAttribute = pAttribute->pNext) 238 for (ATOM_UNKNOWN_ATTRIBUTE* pAttribute = pElement->pAttributes; pAttribute; pAttribute = pAttribute->pNext)
225 { 239 {
226 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"version", -1)) 240 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"version", -1))
227 { 241 {
228 hr = VerParseVersion(pAttribute->wzValue, 0, FALSE, &pApupEntry->pUpgradeVersion); 242 hr = VerParseVersion(pAttribute->wzValue, 0, FALSE, &pApupEntry->pUpgradeVersion);
229 ExitOnFailure(hr, "Failed to parse upgrade version string '%ls' from ATOM entry.", pAttribute->wzValue); 243 ApupExitOnFailure(hr, "Failed to parse upgrade version string '%ls' from ATOM entry.", pAttribute->wzValue);
230 } 244 }
231 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"exclusive", -1)) 245 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"exclusive", -1))
232 { 246 {
@@ -240,7 +254,7 @@ static HRESULT ProcessEntry(
240 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"version", -1)) 254 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"version", -1))
241 { 255 {
242 hr = VerParseVersion(pElement->wzValue, 0, FALSE, &pApupEntry->pVersion); 256 hr = VerParseVersion(pElement->wzValue, 0, FALSE, &pApupEntry->pVersion);
243 ExitOnFailure(hr, "Failed to parse version string '%ls' from ATOM entry.", pElement->wzValue); 257 ApupExitOnFailure(hr, "Failed to parse version string '%ls' from ATOM entry.", pElement->wzValue);
244 258
245 fVersionFound = TRUE; 259 fVersionFound = TRUE;
246 } 260 }
@@ -254,24 +268,24 @@ static HRESULT ProcessEntry(
254 } 268 }
255 269
256 hr = VerCompareParsedVersions(pApupEntry->pUpgradeVersion, pApupEntry->pVersion, &nCompareResult); 270 hr = VerCompareParsedVersions(pApupEntry->pUpgradeVersion, pApupEntry->pVersion, &nCompareResult);
257 ExitOnFailure(hr, "Failed to compare version to upgrade version."); 271 ApupExitOnFailure(hr, "Failed to compare version to upgrade version.");
258 272
259 if (nCompareResult >= 0) 273 if (nCompareResult >= 0)
260 { 274 {
261 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 275 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
262 ExitOnRootFailure(hr, "Upgrade version is greater than or equal to application version."); 276 ApupExitOnRootFailure(hr, "Upgrade version is greater than or equal to application version.");
263 } 277 }
264 278
265 if (pAtomEntry->wzTitle) 279 if (pAtomEntry->wzTitle)
266 { 280 {
267 hr = StrAllocString(&pApupEntry->wzTitle, pAtomEntry->wzTitle, 0); 281 hr = StrAllocString(&pApupEntry->wzTitle, pAtomEntry->wzTitle, 0);
268 ExitOnFailure(hr, "Failed to allocate application title."); 282 ApupExitOnFailure(hr, "Failed to allocate application title.");
269 } 283 }
270 284
271 if (pAtomEntry->wzSummary) 285 if (pAtomEntry->wzSummary)
272 { 286 {
273 hr = StrAllocString(&pApupEntry->wzSummary, pAtomEntry->wzSummary, 0); 287 hr = StrAllocString(&pApupEntry->wzSummary, pAtomEntry->wzSummary, 0);
274 ExitOnFailure(hr, "Failed to allocate application summary."); 288 ApupExitOnFailure(hr, "Failed to allocate application summary.");
275 } 289 }
276 290
277 if (pAtomEntry->pContent) 291 if (pAtomEntry->pContent)
@@ -279,18 +293,18 @@ static HRESULT ProcessEntry(
279 if (pAtomEntry->pContent->wzType) 293 if (pAtomEntry->pContent->wzType)
280 { 294 {
281 hr = StrAllocString(&pApupEntry->wzContentType, pAtomEntry->pContent->wzType, 0); 295 hr = StrAllocString(&pApupEntry->wzContentType, pAtomEntry->pContent->wzType, 0);
282 ExitOnFailure(hr, "Failed to allocate content type."); 296 ApupExitOnFailure(hr, "Failed to allocate content type.");
283 } 297 }
284 298
285 if (pAtomEntry->pContent->wzValue) 299 if (pAtomEntry->pContent->wzValue)
286 { 300 {
287 hr = StrAllocString(&pApupEntry->wzContent, pAtomEntry->pContent->wzValue, 0); 301 hr = StrAllocString(&pApupEntry->wzContent, pAtomEntry->pContent->wzValue, 0);
288 ExitOnFailure(hr, "Failed to allocate content."); 302 ApupExitOnFailure(hr, "Failed to allocate content.");
289 } 303 }
290 } 304 }
291 // Now process the enclosures. Assume every link in the ATOM entry is an enclosure. 305 // Now process the enclosures. Assume every link in the ATOM entry is an enclosure.
292 pApupEntry->rgEnclosures = static_cast<APPLICATION_UPDATE_ENCLOSURE*>(MemAlloc(sizeof(APPLICATION_UPDATE_ENCLOSURE) * pAtomEntry->cLinks, TRUE)); 306 pApupEntry->rgEnclosures = static_cast<APPLICATION_UPDATE_ENCLOSURE*>(MemAlloc(sizeof(APPLICATION_UPDATE_ENCLOSURE) * pAtomEntry->cLinks, TRUE));
293 ExitOnNull(pApupEntry->rgEnclosures, hr, E_OUTOFMEMORY, "Failed to allocate enclosures for application update entry."); 307 ApupExitOnNull(pApupEntry->rgEnclosures, hr, E_OUTOFMEMORY, "Failed to allocate enclosures for application update entry.");
294 308
295 for (DWORD i = 0; i < pAtomEntry->cLinks; ++i) 309 for (DWORD i = 0; i < pAtomEntry->cLinks; ++i)
296 { 310 {
@@ -298,7 +312,7 @@ static HRESULT ProcessEntry(
298 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pLink->wzRel, -1, L"enclosure", -1)) 312 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pLink->wzRel, -1, L"enclosure", -1))
299 { 313 {
300 hr = ParseEnclosure(pLink, pApupEntry->rgEnclosures + pApupEntry->cEnclosures); 314 hr = ParseEnclosure(pLink, pApupEntry->rgEnclosures + pApupEntry->cEnclosures);
301 ExitOnFailure(hr, "Failed to parse enclosure."); 315 ApupExitOnFailure(hr, "Failed to parse enclosure.");
302 316
303 pApupEntry->dw64TotalSize += pApupEntry->rgEnclosures[pApupEntry->cEnclosures].dw64Size; // total up the size of the enclosures 317 pApupEntry->dw64TotalSize += pApupEntry->rgEnclosures[pApupEntry->cEnclosures].dw64Size; // total up the size of the enclosures
304 318
@@ -369,25 +383,25 @@ static HRESULT ParseEnclosure(
369 dwDigestStringLength = 2 * dwDigestLength; 383 dwDigestStringLength = 2 * dwDigestLength;
370 384
371 hr = ::StringCchLengthW(pElement->wzValue, STRSAFE_MAX_CCH, &cchDigestString); 385 hr = ::StringCchLengthW(pElement->wzValue, STRSAFE_MAX_CCH, &cchDigestString);
372 ExitOnFailure(hr, "Failed to get string length of digest value."); 386 ApupExitOnFailure(hr, "Failed to get string length of digest value.");
373 387
374 if (dwDigestStringLength != cchDigestString) 388 if (dwDigestStringLength != cchDigestString)
375 { 389 {
376 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 390 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
377 ExitOnRootFailure(hr, "Invalid digest length (%zu) for digest algorithm (%u).", cchDigestString, dwDigestStringLength); 391 ApupExitOnRootFailure(hr, "Invalid digest length (%zu) for digest algorithm (%u).", cchDigestString, dwDigestStringLength);
378 } 392 }
379 393
380 pEnclosure->cbDigest = sizeof(BYTE) * dwDigestLength; 394 pEnclosure->cbDigest = sizeof(BYTE) * dwDigestLength;
381 pEnclosure->rgbDigest = static_cast<BYTE*>(MemAlloc(pEnclosure->cbDigest, TRUE)); 395 pEnclosure->rgbDigest = static_cast<BYTE*>(MemAlloc(pEnclosure->cbDigest, TRUE));
382 ExitOnNull(pEnclosure->rgbDigest, hr, E_OUTOFMEMORY, "Failed to allocate memory for digest."); 396 ApupExitOnNull(pEnclosure->rgbDigest, hr, E_OUTOFMEMORY, "Failed to allocate memory for digest.");
383 397
384 hr = StrHexDecode(pElement->wzValue, pEnclosure->rgbDigest, pEnclosure->cbDigest); 398 hr = StrHexDecode(pElement->wzValue, pEnclosure->rgbDigest, pEnclosure->cbDigest);
385 ExitOnFailure(hr, "Failed to decode digest value."); 399 ApupExitOnFailure(hr, "Failed to decode digest value.");
386 } 400 }
387 else 401 else
388 { 402 {
389 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 403 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
390 ExitOnRootFailure(hr, "Unknown algorithm type for digest."); 404 ApupExitOnRootFailure(hr, "Unknown algorithm type for digest.");
391 } 405 }
392 406
393 break; 407 break;
@@ -395,7 +409,7 @@ static HRESULT ParseEnclosure(
395 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, L"name", -1, pElement->wzElement, -1)) 409 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, L"name", -1, pElement->wzElement, -1))
396 { 410 {
397 hr = StrAllocString(&pEnclosure->wzLocalName, pElement->wzValue, 0); 411 hr = StrAllocString(&pEnclosure->wzLocalName, pElement->wzValue, 0);
398 ExitOnFailure(hr, "Failed to copy local name."); 412 ApupExitOnFailure(hr, "Failed to copy local name.");
399 } 413 }
400 } 414 }
401 } 415 }
@@ -403,7 +417,7 @@ static HRESULT ParseEnclosure(
403 pEnclosure->dw64Size = pLink->dw64Length; 417 pEnclosure->dw64Size = pLink->dw64Length;
404 418
405 hr = StrAllocString(&pEnclosure->wzUrl, pLink->wzUrl, 0); 419 hr = StrAllocString(&pEnclosure->wzUrl, pLink->wzUrl, 0);
406 ExitOnFailure(hr, "Failed to allocate enclosure URL."); 420 ApupExitOnFailure(hr, "Failed to allocate enclosure URL.");
407 421
408 pEnclosure->fInstaller = FALSE; 422 pEnclosure->fInstaller = FALSE;
409 pEnclosure->wzLocalName = NULL; 423 pEnclosure->wzLocalName = NULL;
@@ -459,7 +473,7 @@ static HRESULT FilterEntries(
459 const APPLICATION_UPDATE_ENTRY* pEntry = rgEntries + i; 473 const APPLICATION_UPDATE_ENTRY* pEntry = rgEntries + i;
460 474
461 hr = VerCompareParsedVersions(pCurrentVersion, pEntry->pVersion, &nCompareResult); 475 hr = VerCompareParsedVersions(pCurrentVersion, pEntry->pVersion, &nCompareResult);
462 ExitOnFailure(hr, "Failed to compare versions."); 476 ApupExitOnFailure(hr, "Failed to compare versions.");
463 477
464 if (nCompareResult >= 0) 478 if (nCompareResult >= 0)
465 { 479 {
@@ -467,7 +481,7 @@ static HRESULT FilterEntries(
467 } 481 }
468 482
469 hr = VerCompareParsedVersions(pCurrentVersion, pEntry->pUpgradeVersion, &nCompareResult); 483 hr = VerCompareParsedVersions(pCurrentVersion, pEntry->pUpgradeVersion, &nCompareResult);
470 ExitOnFailure(hr, "Failed to compare upgrade versions."); 484 ApupExitOnFailure(hr, "Failed to compare upgrade versions.");
471 485
472 if (nCompareResult > 0 || (!pEntry->fUpgradeExclusive && nCompareResult == 0)) 486 if (nCompareResult > 0 || (!pEntry->fUpgradeExclusive && nCompareResult == 0))
473 { 487 {
@@ -481,17 +495,17 @@ static HRESULT FilterEntries(
481 DWORD cNewFilteredEntries = *pcFilteredEntries + 1; 495 DWORD cNewFilteredEntries = *pcFilteredEntries + 1;
482 496
483 hr = ::SizeTMult(sizeof(APPLICATION_UPDATE_ENTRY), cNewFilteredEntries, &cbAllocSize); 497 hr = ::SizeTMult(sizeof(APPLICATION_UPDATE_ENTRY), cNewFilteredEntries, &cbAllocSize);
484 ExitOnFailure(hr, "Overflow while calculating alloc size for more entries - number of entries: %u", cNewFilteredEntries); 498 ApupExitOnFailure(hr, "Overflow while calculating alloc size for more entries - number of entries: %u", cNewFilteredEntries);
485 499
486 if (*prgFilteredEntries) 500 if (*prgFilteredEntries)
487 { 501 {
488 pv = MemReAlloc(*prgFilteredEntries, cbAllocSize, FALSE); 502 pv = MemReAlloc(*prgFilteredEntries, cbAllocSize, FALSE);
489 ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate memory for more entries."); 503 ApupExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate memory for more entries.");
490 } 504 }
491 else 505 else
492 { 506 {
493 pv = MemAlloc(cbAllocSize, TRUE); 507 pv = MemAlloc(cbAllocSize, TRUE);
494 ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for entries."); 508 ApupExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for entries.");
495 } 509 }
496 510
497 *pcFilteredEntries = cNewFilteredEntries; 511 *pcFilteredEntries = cNewFilteredEntries;
@@ -499,10 +513,10 @@ static HRESULT FilterEntries(
499 pv = NULL; 513 pv = NULL;
500 514
501 hr = CopyEntry(pRequired, *prgFilteredEntries + *pcFilteredEntries - 1); 515 hr = CopyEntry(pRequired, *prgFilteredEntries + *pcFilteredEntries - 1);
502 ExitOnFailure(hr, "Failed to deep copy entry."); 516 ApupExitOnFailure(hr, "Failed to deep copy entry.");
503 517
504 hr = VerCompareParsedVersions(pRequired->pVersion, rgEntries[0].pVersion, &nCompareResult); 518 hr = VerCompareParsedVersions(pRequired->pVersion, rgEntries[0].pVersion, &nCompareResult);
505 ExitOnFailure(hr, "Failed to compare required version."); 519 ApupExitOnFailure(hr, "Failed to compare required version.");
506 520
507 if (nCompareResult < 0) 521 if (nCompareResult < 0)
508 { 522 {
@@ -530,67 +544,67 @@ static HRESULT CopyEntry(
530 if (pSrc->wzApplicationId) 544 if (pSrc->wzApplicationId)
531 { 545 {
532 hr = StrAllocString(&pDest->wzApplicationId, pSrc->wzApplicationId, 0); 546 hr = StrAllocString(&pDest->wzApplicationId, pSrc->wzApplicationId, 0);
533 ExitOnFailure(hr, "Failed to copy application id."); 547 ApupExitOnFailure(hr, "Failed to copy application id.");
534 } 548 }
535 549
536 if (pSrc->wzApplicationType) 550 if (pSrc->wzApplicationType)
537 { 551 {
538 hr = StrAllocString(&pDest->wzApplicationType, pSrc->wzApplicationType, 0); 552 hr = StrAllocString(&pDest->wzApplicationType, pSrc->wzApplicationType, 0);
539 ExitOnFailure(hr, "Failed to copy application type."); 553 ApupExitOnFailure(hr, "Failed to copy application type.");
540 } 554 }
541 555
542 if (pSrc->wzUpgradeId) 556 if (pSrc->wzUpgradeId)
543 { 557 {
544 hr = StrAllocString(&pDest->wzUpgradeId, pSrc->wzUpgradeId, 0); 558 hr = StrAllocString(&pDest->wzUpgradeId, pSrc->wzUpgradeId, 0);
545 ExitOnFailure(hr, "Failed to copy upgrade id."); 559 ApupExitOnFailure(hr, "Failed to copy upgrade id.");
546 } 560 }
547 561
548 if (pSrc->wzTitle) 562 if (pSrc->wzTitle)
549 { 563 {
550 hr = StrAllocString(&pDest->wzTitle, pSrc->wzTitle, 0); 564 hr = StrAllocString(&pDest->wzTitle, pSrc->wzTitle, 0);
551 ExitOnFailure(hr, "Failed to copy title."); 565 ApupExitOnFailure(hr, "Failed to copy title.");
552 } 566 }
553 567
554 if (pSrc->wzSummary) 568 if (pSrc->wzSummary)
555 { 569 {
556 hr = StrAllocString(&pDest->wzSummary, pSrc->wzSummary, 0); 570 hr = StrAllocString(&pDest->wzSummary, pSrc->wzSummary, 0);
557 ExitOnFailure(hr, "Failed to copy summary."); 571 ApupExitOnFailure(hr, "Failed to copy summary.");
558 } 572 }
559 573
560 if (pSrc->wzContentType) 574 if (pSrc->wzContentType)
561 { 575 {
562 hr = StrAllocString(&pDest->wzContentType, pSrc->wzContentType, 0); 576 hr = StrAllocString(&pDest->wzContentType, pSrc->wzContentType, 0);
563 ExitOnFailure(hr, "Failed to copy content type."); 577 ApupExitOnFailure(hr, "Failed to copy content type.");
564 } 578 }
565 579
566 if (pSrc->wzContent) 580 if (pSrc->wzContent)
567 { 581 {
568 hr = StrAllocString(&pDest->wzContent, pSrc->wzContent, 0); 582 hr = StrAllocString(&pDest->wzContent, pSrc->wzContent, 0);
569 ExitOnFailure(hr, "Failed to copy content."); 583 ApupExitOnFailure(hr, "Failed to copy content.");
570 } 584 }
571 585
572 pDest->dw64TotalSize = pSrc->dw64TotalSize; 586 pDest->dw64TotalSize = pSrc->dw64TotalSize;
573 587
574 hr = VerCopyVersion(pSrc->pUpgradeVersion, &pDest->pUpgradeVersion); 588 hr = VerCopyVersion(pSrc->pUpgradeVersion, &pDest->pUpgradeVersion);
575 ExitOnFailure(hr, "Failed to copy upgrade version."); 589 ApupExitOnFailure(hr, "Failed to copy upgrade version.");
576 590
577 hr = VerCopyVersion(pSrc->pVersion, &pDest->pVersion); 591 hr = VerCopyVersion(pSrc->pVersion, &pDest->pVersion);
578 ExitOnFailure(hr, "Failed to copy version."); 592 ApupExitOnFailure(hr, "Failed to copy version.");
579 593
580 pDest->fUpgradeExclusive = pSrc->fUpgradeExclusive; 594 pDest->fUpgradeExclusive = pSrc->fUpgradeExclusive;
581 595
582 hr = ::SizeTMult(sizeof(APPLICATION_UPDATE_ENCLOSURE), pSrc->cEnclosures, &cbAllocSize); 596 hr = ::SizeTMult(sizeof(APPLICATION_UPDATE_ENCLOSURE), pSrc->cEnclosures, &cbAllocSize);
583 ExitOnRootFailure(hr, "Overflow while calculating memory allocation size"); 597 ApupExitOnRootFailure(hr, "Overflow while calculating memory allocation size");
584 598
585 pDest->rgEnclosures = static_cast<APPLICATION_UPDATE_ENCLOSURE*>(MemAlloc(cbAllocSize, TRUE)); 599 pDest->rgEnclosures = static_cast<APPLICATION_UPDATE_ENCLOSURE*>(MemAlloc(cbAllocSize, TRUE));
586 ExitOnNull(pDest->rgEnclosures, hr, E_OUTOFMEMORY, "Failed to allocate copy of enclosures."); 600 ApupExitOnNull(pDest->rgEnclosures, hr, E_OUTOFMEMORY, "Failed to allocate copy of enclosures.");
587 601
588 pDest->cEnclosures = pSrc->cEnclosures; 602 pDest->cEnclosures = pSrc->cEnclosures;
589 603
590 for (DWORD i = 0; i < pDest->cEnclosures; ++i) 604 for (DWORD i = 0; i < pDest->cEnclosures; ++i)
591 { 605 {
592 hr = CopyEnclosure(pSrc->rgEnclosures + i, pDest->rgEnclosures + i); 606 hr = CopyEnclosure(pSrc->rgEnclosures + i, pDest->rgEnclosures + i);
593 ExitOnFailure(hr, "Failed to copy enclosure."); 607 ApupExitOnFailure(hr, "Failed to copy enclosure.");
594 } 608 }
595 609
596LExit: 610LExit:
@@ -615,17 +629,17 @@ static HRESULT CopyEnclosure(
615 if (pSrc->wzUrl) 629 if (pSrc->wzUrl)
616 { 630 {
617 hr = StrAllocString(&pDest->wzUrl, pSrc->wzUrl, 0); 631 hr = StrAllocString(&pDest->wzUrl, pSrc->wzUrl, 0);
618 ExitOnFailure(hr, "Failed copy url."); 632 ApupExitOnFailure(hr, "Failed copy url.");
619 } 633 }
620 634
621 if (pSrc->wzLocalName) 635 if (pSrc->wzLocalName)
622 { 636 {
623 hr = StrAllocString(&pDest->wzLocalName, pSrc->wzLocalName, 0); 637 hr = StrAllocString(&pDest->wzLocalName, pSrc->wzLocalName, 0);
624 ExitOnFailure(hr, "Failed copy url."); 638 ApupExitOnFailure(hr, "Failed copy url.");
625 } 639 }
626 640
627 pDest->rgbDigest = static_cast<BYTE*>(MemAlloc(sizeof(BYTE) * pSrc->cbDigest, FALSE)); 641 pDest->rgbDigest = static_cast<BYTE*>(MemAlloc(sizeof(BYTE) * pSrc->cbDigest, FALSE));
628 ExitOnNull(pDest->rgbDigest, hr, E_OUTOFMEMORY, "Failed to allocate memory for copy of digest."); 642 ApupExitOnNull(pDest->rgbDigest, hr, E_OUTOFMEMORY, "Failed to allocate memory for copy of digest.");
629 643
630 pDest->cbDigest = pSrc->cbDigest; 644 pDest->cbDigest = pSrc->cbDigest;
631 645