diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2021-03-02 14:19:14 -0600 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2021-03-02 15:40:02 -0600 |
commit | 10ebf674da5df9224e4eddd3545518434c5b455b (patch) | |
tree | ea1f4063edd46e9942eab94dd7adb2f75c6c589e | |
parent | 3bbf1347b900ec115a12faf8f46965c9b7649696 (diff) | |
download | wix-10ebf674da5df9224e4eddd3545518434c5b455b.tar.gz wix-10ebf674da5df9224e4eddd3545518434c5b455b.tar.bz2 wix-10ebf674da5df9224e4eddd3545518434c5b455b.zip |
Update rest of dutil to use their own source with the Exit* macros.
Fix some CA warnings.
73 files changed, 2779 insertions, 1953 deletions
diff --git a/src/dutil/acl2util.cpp b/src/dutil/acl2util.cpp index 2261abe3..5aba60f0 100644 --- a/src/dutil/acl2util.cpp +++ b/src/dutil/acl2util.cpp | |||
@@ -2,6 +2,20 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | // Exit macros | ||
6 | #define AclExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
7 | #define AclExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
8 | #define AclExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
9 | #define AclExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
10 | #define AclExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
11 | #define AclExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
12 | #define AclExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_ACLUTIL, p, x, e, s, __VA_ARGS__) | ||
13 | #define AclExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, p, x, s, __VA_ARGS__) | ||
14 | #define AclExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_ACLUTIL, p, x, e, s, __VA_ARGS__) | ||
15 | #define AclExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, p, x, s, __VA_ARGS__) | ||
16 | #define AclExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_ACLUTIL, e, x, s, __VA_ARGS__) | ||
17 | #define AclExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_ACLUTIL, g, x, s, __VA_ARGS__) | ||
18 | |||
5 | /******************************************************************** | 19 | /******************************************************************** |
6 | AclCalculateServiceSidString - gets the SID string for the given service name | 20 | AclCalculateServiceSidString - gets the SID string for the given service name |
7 | 21 | ||
@@ -26,17 +40,17 @@ extern "C" HRESULT DAPI AclCalculateServiceSidString( | |||
26 | if (0 == cchServiceName) | 40 | if (0 == cchServiceName) |
27 | { | 41 | { |
28 | hr = ::StringCchLengthW(wzServiceName, INT_MAX, reinterpret_cast<size_t*>(&cchServiceName)); | 42 | hr = ::StringCchLengthW(wzServiceName, INT_MAX, reinterpret_cast<size_t*>(&cchServiceName)); |
29 | ExitOnFailure(hr, "Failed to get the length of the service name."); | 43 | AclExitOnFailure(hr, "Failed to get the length of the service name."); |
30 | } | 44 | } |
31 | 45 | ||
32 | hr = StrAllocStringToUpperInvariant(&sczUpperServiceName, wzServiceName, cchServiceName); | 46 | hr = StrAllocStringToUpperInvariant(&sczUpperServiceName, wzServiceName, cchServiceName); |
33 | ExitOnFailure(hr, "Failed to upper case the service name."); | 47 | AclExitOnFailure(hr, "Failed to upper case the service name."); |
34 | 48 | ||
35 | pbHash = reinterpret_cast<BYTE*>(MemAlloc(cbHash, TRUE)); | 49 | pbHash = reinterpret_cast<BYTE*>(MemAlloc(cbHash, TRUE)); |
36 | ExitOnNull(pbHash, hr, E_OUTOFMEMORY, "Failed to allocate hash byte array."); | 50 | AclExitOnNull(pbHash, hr, E_OUTOFMEMORY, "Failed to allocate hash byte array."); |
37 | 51 | ||
38 | hr = CrypHashBuffer(reinterpret_cast<BYTE*>(sczUpperServiceName), cchServiceName * 2, PROV_RSA_FULL, CALG_SHA1, pbHash, cbHash); | 52 | hr = CrypHashBuffer(reinterpret_cast<BYTE*>(sczUpperServiceName), cchServiceName * 2, PROV_RSA_FULL, CALG_SHA1, pbHash, cbHash); |
39 | ExitOnNull(pbHash, hr, E_OUTOFMEMORY, "Failed to hash the service name."); | 53 | AclExitOnNull(pbHash, hr, E_OUTOFMEMORY, "Failed to hash the service name."); |
40 | 54 | ||
41 | hr = StrAllocFormatted(psczSid, L"S-1-5-80-%u-%u-%u-%u-%u", | 55 | hr = StrAllocFormatted(psczSid, L"S-1-5-80-%u-%u-%u-%u-%u", |
42 | MAKEDWORD(MAKEWORD(pbHash[0], pbHash[1]), MAKEWORD(pbHash[2], pbHash[3])), | 56 | MAKEDWORD(MAKEWORD(pbHash[0], pbHash[1]), MAKEWORD(pbHash[2], pbHash[3])), |
@@ -80,7 +94,7 @@ extern "C" HRESULT DAPI AclGetAccountSidStringEx( | |||
80 | 94 | ||
81 | if (!::ConvertSidToStringSidW(psid, &pwz)) | 95 | if (!::ConvertSidToStringSidW(psid, &pwz)) |
82 | { | 96 | { |
83 | ExitWithLastError(hr, "Failed to convert SID to string for Account: %ls", wzAccount); | 97 | AclExitWithLastError(hr, "Failed to convert SID to string for Account: %ls", wzAccount); |
84 | } | 98 | } |
85 | 99 | ||
86 | hr = StrAllocString(psczSid, pwz, 0); | 100 | hr = StrAllocString(psczSid, pwz, 0); |
@@ -90,20 +104,20 @@ extern "C" HRESULT DAPI AclGetAccountSidStringEx( | |||
90 | if (HRESULT_FROM_WIN32(ERROR_NONE_MAPPED) == hr) | 104 | if (HRESULT_FROM_WIN32(ERROR_NONE_MAPPED) == hr) |
91 | { | 105 | { |
92 | HRESULT hrLength = ::StringCchLengthW(wzAccount, INT_MAX, reinterpret_cast<size_t*>(&cchAccount)); | 106 | HRESULT hrLength = ::StringCchLengthW(wzAccount, INT_MAX, reinterpret_cast<size_t*>(&cchAccount)); |
93 | ExitOnFailure(hrLength, "Failed to get the length of the account name."); | 107 | AclExitOnFailure(hrLength, "Failed to get the length of the account name."); |
94 | 108 | ||
95 | if (11 < cchAccount && CSTR_EQUAL == CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, L"NT SERVICE\\", 11, wzAccount, 11)) | 109 | if (11 < cchAccount && CSTR_EQUAL == CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, L"NT SERVICE\\", 11, wzAccount, 11)) |
96 | { | 110 | { |
97 | // If the service is not installed then LookupAccountName doesn't resolve the SID, but we can calculate it. | 111 | // If the service is not installed then LookupAccountName doesn't resolve the SID, but we can calculate it. |
98 | LPCWSTR wzServiceName = &wzAccount[11]; | 112 | LPCWSTR wzServiceName = &wzAccount[11]; |
99 | hr = AclCalculateServiceSidString(wzServiceName, cchAccount - 11, &sczSid); | 113 | hr = AclCalculateServiceSidString(wzServiceName, cchAccount - 11, &sczSid); |
100 | ExitOnFailure(hr, "Failed to calculate the service SID for %ls", wzServiceName); | 114 | AclExitOnFailure(hr, "Failed to calculate the service SID for %ls", wzServiceName); |
101 | 115 | ||
102 | *psczSid = sczSid; | 116 | *psczSid = sczSid; |
103 | sczSid = NULL; | 117 | sczSid = NULL; |
104 | } | 118 | } |
105 | } | 119 | } |
106 | ExitOnFailure(hr, "Failed to get SID for account: %ls", wzAccount); | 120 | AclExitOnFailure(hr, "Failed to get SID for account: %ls", wzAccount); |
107 | } | 121 | } |
108 | 122 | ||
109 | LExit: | 123 | LExit: |
diff --git a/src/dutil/aclutil.cpp b/src/dutil/aclutil.cpp index fc01ecc8..c9733033 100644 --- a/src/dutil/aclutil.cpp +++ b/src/dutil/aclutil.cpp | |||
@@ -2,6 +2,20 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | // Exit macros | ||
6 | #define AclExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
7 | #define AclExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
8 | #define AclExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
9 | #define AclExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
10 | #define AclExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
11 | #define AclExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
12 | #define AclExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_ACLUTIL, p, x, e, s, __VA_ARGS__) | ||
13 | #define AclExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, p, x, s, __VA_ARGS__) | ||
14 | #define AclExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_ACLUTIL, p, x, e, s, __VA_ARGS__) | ||
15 | #define AclExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, p, x, s, __VA_ARGS__) | ||
16 | #define AclExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_ACLUTIL, e, x, s, __VA_ARGS__) | ||
17 | #define AclExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_ACLUTIL, g, x, s, __VA_ARGS__) | ||
18 | |||
5 | /******************************************************************** | 19 | /******************************************************************** |
6 | AclCheckAccess - determines if token has appropriate privileges | 20 | AclCheckAccess - determines if token has appropriate privileges |
7 | 21 | ||
@@ -18,25 +32,25 @@ extern "C" HRESULT DAPI AclCheckAccess( | |||
18 | PSID psid = NULL; | 32 | PSID psid = NULL; |
19 | BOOL fIsMember = FALSE; | 33 | BOOL fIsMember = FALSE; |
20 | 34 | ||
21 | ExitOnNull(paa, hr, E_INVALIDARG, "Failed to check ACL access, because no acl access provided to check"); | 35 | AclExitOnNull(paa, hr, E_INVALIDARG, "Failed to check ACL access, because no acl access provided to check"); |
22 | Assert(0 == paa->fDenyAccess && 0 == paa->dwAccessMask); | 36 | Assert(0 == paa->fDenyAccess && 0 == paa->dwAccessMask); |
23 | 37 | ||
24 | if (paa->pwzAccountName) | 38 | if (paa->pwzAccountName) |
25 | { | 39 | { |
26 | hr = AclGetAccountSid(NULL, paa->pwzAccountName, &psid); | 40 | hr = AclGetAccountSid(NULL, paa->pwzAccountName, &psid); |
27 | ExitOnFailure(hr, "failed to get SID for account: %ls", paa->pwzAccountName); | 41 | AclExitOnFailure(hr, "failed to get SID for account: %ls", paa->pwzAccountName); |
28 | } | 42 | } |
29 | else | 43 | else |
30 | { | 44 | { |
31 | if (!::AllocateAndInitializeSid(&paa->sia, paa->nSubAuthorityCount, paa->nSubAuthority[0], paa->nSubAuthority[1], paa->nSubAuthority[2], paa->nSubAuthority[3], paa->nSubAuthority[4], paa->nSubAuthority[5], paa->nSubAuthority[6], paa->nSubAuthority[7], &psid)) | 45 | if (!::AllocateAndInitializeSid(&paa->sia, paa->nSubAuthorityCount, paa->nSubAuthority[0], paa->nSubAuthority[1], paa->nSubAuthority[2], paa->nSubAuthority[3], paa->nSubAuthority[4], paa->nSubAuthority[5], paa->nSubAuthority[6], paa->nSubAuthority[7], &psid)) |
32 | { | 46 | { |
33 | ExitWithLastError(hr, "failed to initialize SID"); | 47 | AclExitWithLastError(hr, "failed to initialize SID"); |
34 | } | 48 | } |
35 | } | 49 | } |
36 | 50 | ||
37 | if (!::CheckTokenMembership(hToken, psid, &fIsMember)) | 51 | if (!::CheckTokenMembership(hToken, psid, &fIsMember)) |
38 | { | 52 | { |
39 | ExitWithLastError(hr, "failed to check membership"); | 53 | AclExitWithLastError(hr, "failed to check membership"); |
40 | } | 54 | } |
41 | 55 | ||
42 | fIsMember ? hr = S_OK : hr = S_FALSE; | 56 | fIsMember ? hr = S_OK : hr = S_FALSE; |
@@ -123,7 +137,7 @@ extern "C" HRESULT DAPI AclGetWellKnownSid( | |||
123 | // allocate memory for the SID and get it | 137 | // allocate memory for the SID and get it |
124 | // | 138 | // |
125 | psid = static_cast<PSID>(MemAlloc(cbSid, TRUE)); | 139 | psid = static_cast<PSID>(MemAlloc(cbSid, TRUE)); |
126 | ExitOnNull(psid, hr, E_OUTOFMEMORY, "failed allocate memory for well known SID"); | 140 | AclExitOnNull(psid, hr, E_OUTOFMEMORY, "failed allocate memory for well known SID"); |
127 | 141 | ||
128 | #if(_WIN32_WINNT < 0x0501) | 142 | #if(_WIN32_WINNT < 0x0501) |
129 | switch (wkst) | 143 | switch (wkst) |
@@ -160,19 +174,19 @@ extern "C" HRESULT DAPI AclGetWellKnownSid( | |||
160 | break; | 174 | break; |
161 | default: | 175 | default: |
162 | hr = E_INVALIDARG; | 176 | hr = E_INVALIDARG; |
163 | ExitOnFailure(hr, "unknown well known SID: %d", wkst); | 177 | AclExitOnFailure(hr, "unknown well known SID: %d", wkst); |
164 | } | 178 | } |
165 | 179 | ||
166 | if (!fSuccess) | 180 | if (!fSuccess) |
167 | ExitOnLastError(hr, "failed to allocate well known SID: %d", wkst); | 181 | AclExitOnLastError(hr, "failed to allocate well known SID: %d", wkst); |
168 | 182 | ||
169 | if (!::CopySid(cbSid, psid, psidTemp)) | 183 | if (!::CopySid(cbSid, psid, psidTemp)) |
170 | ExitOnLastError(hr, "failed to create well known SID: %d", wkst); | 184 | AclExitOnLastError(hr, "failed to create well known SID: %d", wkst); |
171 | #else | 185 | #else |
172 | Assert(NULL == psidTemp); | 186 | Assert(NULL == psidTemp); |
173 | if (!::CreateWellKnownSid(wkst, NULL, psid, &cbSid)) | 187 | if (!::CreateWellKnownSid(wkst, NULL, psid, &cbSid)) |
174 | { | 188 | { |
175 | ExitWithLastError(hr, "failed to create well known SID: %d", wkst); | 189 | AclExitWithLastError(hr, "failed to create well known SID: %d", wkst); |
176 | } | 190 | } |
177 | #endif | 191 | #endif |
178 | 192 | ||
@@ -216,9 +230,9 @@ extern "C" HRESULT DAPI AclGetAccountSid( | |||
216 | // allocate memory for the SID and domain name | 230 | // allocate memory for the SID and domain name |
217 | // | 231 | // |
218 | psid = static_cast<PSID>(MemAlloc(cbSid, TRUE)); | 232 | psid = static_cast<PSID>(MemAlloc(cbSid, TRUE)); |
219 | ExitOnNull(psid, hr, E_OUTOFMEMORY, "failed to allocate memory for SID"); | 233 | AclExitOnNull(psid, hr, E_OUTOFMEMORY, "failed to allocate memory for SID"); |
220 | hr = StrAlloc(&pwzDomainName, cbDomainName); | 234 | hr = StrAlloc(&pwzDomainName, cbDomainName); |
221 | ExitOnFailure(hr, "failed to allocate string for domain name"); | 235 | AclExitOnFailure(hr, "failed to allocate string for domain name"); |
222 | 236 | ||
223 | // | 237 | // |
224 | // try to lookup the account now | 238 | // try to lookup the account now |
@@ -232,24 +246,24 @@ extern "C" HRESULT DAPI AclGetAccountSid( | |||
232 | if (SECURITY_MAX_SID_SIZE < cbSid) | 246 | if (SECURITY_MAX_SID_SIZE < cbSid) |
233 | { | 247 | { |
234 | PSID psidNew = static_cast<PSID>(MemReAlloc(psid, cbSid, TRUE)); | 248 | PSID psidNew = static_cast<PSID>(MemReAlloc(psid, cbSid, TRUE)); |
235 | ExitOnNullWithLastError(psidNew, hr, "failed to allocate memory for account: %ls", wzAccount); | 249 | AclExitOnNullWithLastError(psidNew, hr, "failed to allocate memory for account: %ls", wzAccount); |
236 | 250 | ||
237 | psid = psidNew; | 251 | psid = psidNew; |
238 | } | 252 | } |
239 | if (255 < cbDomainName) | 253 | if (255 < cbDomainName) |
240 | { | 254 | { |
241 | hr = StrAlloc(&pwzDomainName, cbDomainName); | 255 | hr = StrAlloc(&pwzDomainName, cbDomainName); |
242 | ExitOnFailure(hr, "failed to allocate string for domain name"); | 256 | AclExitOnFailure(hr, "failed to allocate string for domain name"); |
243 | } | 257 | } |
244 | 258 | ||
245 | if (!::LookupAccountNameW(wzSystem, wzAccount, psid, &cbSid, pwzDomainName, &cbDomainName, &peUse)) | 259 | if (!::LookupAccountNameW(wzSystem, wzAccount, psid, &cbSid, pwzDomainName, &cbDomainName, &peUse)) |
246 | { | 260 | { |
247 | ExitWithLastError(hr, "failed to lookup account: %ls", wzAccount); | 261 | AclExitWithLastError(hr, "failed to lookup account: %ls", wzAccount); |
248 | } | 262 | } |
249 | } | 263 | } |
250 | else | 264 | else |
251 | { | 265 | { |
252 | ExitOnWin32Error(er, hr, "failed to lookup account: %ls", wzAccount); | 266 | AclExitOnWin32Error(er, hr, "failed to lookup account: %ls", wzAccount); |
253 | } | 267 | } |
254 | } | 268 | } |
255 | 269 | ||
@@ -284,12 +298,12 @@ extern "C" HRESULT DAPI AclGetAccountSidString( | |||
284 | *ppwzSid = NULL; | 298 | *ppwzSid = NULL; |
285 | 299 | ||
286 | hr = AclGetAccountSid(wzSystem, wzAccount, &psid); | 300 | hr = AclGetAccountSid(wzSystem, wzAccount, &psid); |
287 | ExitOnFailure(hr, "failed to get SID for account: %ls", wzAccount); | 301 | AclExitOnFailure(hr, "failed to get SID for account: %ls", wzAccount); |
288 | Assert(::IsValidSid(psid)); | 302 | Assert(::IsValidSid(psid)); |
289 | 303 | ||
290 | if (!::ConvertSidToStringSidW(psid, &pwz)) | 304 | if (!::ConvertSidToStringSidW(psid, &pwz)) |
291 | { | 305 | { |
292 | ExitWithLastError(hr, "failed to convert SID to string for Account: %ls", wzAccount); | 306 | AclExitWithLastError(hr, "failed to convert SID to string for Account: %ls", wzAccount); |
293 | } | 307 | } |
294 | 308 | ||
295 | hr = StrAllocString(ppwzSid, pwz, 0); | 309 | hr = StrAllocString(ppwzSid, pwz, 0); |
@@ -347,14 +361,14 @@ extern "C" HRESULT DAPI AclCreateDacl( | |||
347 | } | 361 | } |
348 | 362 | ||
349 | pAcl = static_cast<ACL*>(MemAlloc(cbAcl, TRUE)); | 363 | pAcl = static_cast<ACL*>(MemAlloc(cbAcl, TRUE)); |
350 | ExitOnNull(pAcl, hr, E_OUTOFMEMORY, "failed to allocate ACL"); | 364 | AclExitOnNull(pAcl, hr, E_OUTOFMEMORY, "failed to allocate ACL"); |
351 | 365 | ||
352 | #pragma prefast(push) | 366 | #pragma prefast(push) |
353 | #pragma prefast(disable:25029) | 367 | #pragma prefast(disable:25029) |
354 | if (!::InitializeAcl(pAcl, cbAcl, ACL_REVISION)) | 368 | if (!::InitializeAcl(pAcl, cbAcl, ACL_REVISION)) |
355 | #pragma prefast(pop) | 369 | #pragma prefast(pop) |
356 | { | 370 | { |
357 | ExitWithLastError(hr, "failed to initialize ACL"); | 371 | AclExitWithLastError(hr, "failed to initialize ACL"); |
358 | } | 372 | } |
359 | 373 | ||
360 | // add in the ACEs (denied first) | 374 | // add in the ACEs (denied first) |
@@ -365,7 +379,7 @@ extern "C" HRESULT DAPI AclCreateDacl( | |||
365 | if (!::AddAccessDeniedAceEx(pAcl, ACL_REVISION, rgaaDeny[i].dwFlags, rgaaDeny[i].dwMask, rgaaDeny[i].psid)) | 379 | if (!::AddAccessDeniedAceEx(pAcl, ACL_REVISION, rgaaDeny[i].dwFlags, rgaaDeny[i].dwMask, rgaaDeny[i].psid)) |
366 | #pragma prefast(pop) | 380 | #pragma prefast(pop) |
367 | { | 381 | { |
368 | ExitWithLastError(hr, "failed to add access denied ACE #%d to ACL", i); | 382 | AclExitWithLastError(hr, "failed to add access denied ACE #%d to ACL", i); |
369 | } | 383 | } |
370 | } | 384 | } |
371 | for (i = 0; i < cAllow; ++i) | 385 | for (i = 0; i < cAllow; ++i) |
@@ -375,7 +389,7 @@ extern "C" HRESULT DAPI AclCreateDacl( | |||
375 | if (!::AddAccessAllowedAceEx(pAcl, ACL_REVISION, rgaaAllow[i].dwFlags, rgaaAllow[i].dwMask, rgaaAllow[i].psid)) | 389 | if (!::AddAccessAllowedAceEx(pAcl, ACL_REVISION, rgaaAllow[i].dwFlags, rgaaAllow[i].dwMask, rgaaAllow[i].psid)) |
376 | #pragma prefast(pop) | 390 | #pragma prefast(pop) |
377 | { | 391 | { |
378 | ExitWithLastError(hr, "failed to add access allowed ACE #$d to ACL", i); | 392 | AclExitWithLastError(hr, "failed to add access allowed ACE #%d to ACL", i); |
379 | } | 393 | } |
380 | } | 394 | } |
381 | 395 | ||
@@ -422,7 +436,7 @@ extern "C" HRESULT DAPI AclAddToDacl( | |||
422 | // allocate memory for all the new ACEs (NOTE: this over calculates the memory necessary, but that's okay) | 436 | // allocate memory for all the new ACEs (NOTE: this over calculates the memory necessary, but that's okay) |
423 | if (!::GetAclInformation(pAcl, &asi, sizeof(asi), AclSizeInformation)) | 437 | if (!::GetAclInformation(pAcl, &asi, sizeof(asi), AclSizeInformation)) |
424 | { | 438 | { |
425 | ExitWithLastError(hr, "failed to get information about original ACL"); | 439 | AclExitWithLastError(hr, "failed to get information about original ACL"); |
426 | } | 440 | } |
427 | 441 | ||
428 | if ((asi.AceCount + cDeny) < asi.AceCount || // check for overflow | 442 | if ((asi.AceCount + cDeny) < asi.AceCount || // check for overflow |
@@ -430,29 +444,29 @@ extern "C" HRESULT DAPI AclAddToDacl( | |||
430 | (asi.AceCount + cDeny) >= MAXSIZE_T / sizeof(ACL_ACE)) | 444 | (asi.AceCount + cDeny) >= MAXSIZE_T / sizeof(ACL_ACE)) |
431 | { | 445 | { |
432 | hr = E_OUTOFMEMORY; | 446 | hr = E_OUTOFMEMORY; |
433 | ExitOnFailure(hr, "Not enough memory to allocate %d ACEs", (asi.AceCount + cDeny)); | 447 | AclExitOnFailure(hr, "Not enough memory to allocate %d ACEs", (asi.AceCount + cDeny)); |
434 | } | 448 | } |
435 | 449 | ||
436 | paaNewDeny = static_cast<ACL_ACE*>(MemAlloc(sizeof(ACL_ACE) * (asi.AceCount + cDeny), TRUE)); | 450 | paaNewDeny = static_cast<ACL_ACE*>(MemAlloc(sizeof(ACL_ACE) * (asi.AceCount + cDeny), TRUE)); |
437 | ExitOnNull(paaNewDeny, hr, E_OUTOFMEMORY, "failed to allocate memory for new deny ACEs"); | 451 | AclExitOnNull(paaNewDeny, hr, E_OUTOFMEMORY, "failed to allocate memory for new deny ACEs"); |
438 | 452 | ||
439 | if ((asi.AceCount + cAllow) < asi.AceCount || // check for overflow | 453 | if ((asi.AceCount + cAllow) < asi.AceCount || // check for overflow |
440 | (asi.AceCount + cAllow) < cAllow || // check for overflow | 454 | (asi.AceCount + cAllow) < cAllow || // check for overflow |
441 | (asi.AceCount + cAllow) >= MAXSIZE_T / sizeof(ACL_ACE)) | 455 | (asi.AceCount + cAllow) >= MAXSIZE_T / sizeof(ACL_ACE)) |
442 | { | 456 | { |
443 | hr = E_OUTOFMEMORY; | 457 | hr = E_OUTOFMEMORY; |
444 | ExitOnFailure(hr, "Not enough memory to allocate %d ACEs", (asi.AceCount + cAllow)); | 458 | AclExitOnFailure(hr, "Not enough memory to allocate %d ACEs", (asi.AceCount + cAllow)); |
445 | } | 459 | } |
446 | 460 | ||
447 | paaNewAllow = static_cast<ACL_ACE*>(MemAlloc(sizeof(ACL_ACE) * (asi.AceCount + cAllow), TRUE)); | 461 | paaNewAllow = static_cast<ACL_ACE*>(MemAlloc(sizeof(ACL_ACE) * (asi.AceCount + cAllow), TRUE)); |
448 | ExitOnNull(paaNewAllow, hr, E_OUTOFMEMORY, "failed to allocate memory for new allow ACEs"); | 462 | AclExitOnNull(paaNewAllow, hr, E_OUTOFMEMORY, "failed to allocate memory for new allow ACEs"); |
449 | 463 | ||
450 | // fill in the new structures with old data then new data (denied first) | 464 | // fill in the new structures with old data then new data (denied first) |
451 | for (i = 0; i < asi.AceCount; ++i) | 465 | for (i = 0; i < asi.AceCount; ++i) |
452 | { | 466 | { |
453 | if (!::GetAce(pAcl, i, reinterpret_cast<LPVOID*>(&pada))) | 467 | if (!::GetAce(pAcl, i, reinterpret_cast<LPVOID*>(&pada))) |
454 | { | 468 | { |
455 | ExitWithLastError(hr, "failed to get ACE #%d from ACL", i); | 469 | AclExitWithLastError(hr, "failed to get ACE #%d from ACL", i); |
456 | } | 470 | } |
457 | 471 | ||
458 | if (ACCESS_DENIED_ACE_TYPE != pada->Header.AceType) | 472 | if (ACCESS_DENIED_ACE_TYPE != pada->Header.AceType) |
@@ -474,7 +488,7 @@ extern "C" HRESULT DAPI AclAddToDacl( | |||
474 | { | 488 | { |
475 | if (!::GetAce(pAcl, i, reinterpret_cast<LPVOID*>(&paaa))) | 489 | if (!::GetAce(pAcl, i, reinterpret_cast<LPVOID*>(&paaa))) |
476 | { | 490 | { |
477 | ExitWithLastError(hr, "failed to get ACE #%d from ACL", i); | 491 | AclExitWithLastError(hr, "failed to get ACE #%d from ACL", i); |
478 | } | 492 | } |
479 | 493 | ||
480 | if (ACCESS_ALLOWED_ACE_TYPE != paaa->Header.AceType) | 494 | if (ACCESS_ALLOWED_ACE_TYPE != paaa->Header.AceType) |
@@ -493,7 +507,7 @@ extern "C" HRESULT DAPI AclAddToDacl( | |||
493 | 507 | ||
494 | // create the dacl with the new | 508 | // create the dacl with the new |
495 | hr = AclCreateDacl(paaNewDeny, cNewDeny, paaNewAllow, cNewAllow, ppAclNew); | 509 | hr = AclCreateDacl(paaNewDeny, cNewDeny, paaNewAllow, cNewAllow, ppAclNew); |
496 | ExitOnFailure(hr, "failed to create new ACL from existing ACL"); | 510 | AclExitOnFailure(hr, "failed to create new ACL from existing ACL"); |
497 | 511 | ||
498 | AssertSz(::IsValidAcl(*ppAclNew), "AclAddToDacl() - created invalid ACL"); | 512 | AssertSz(::IsValidAcl(*ppAclNew), "AclAddToDacl() - created invalid ACL"); |
499 | Assert(S_OK == hr); | 513 | Assert(S_OK == hr); |
@@ -551,9 +565,9 @@ extern "C" HRESULT DAPI AclCreateDaclOld( | |||
551 | // create the SIDs and calculate the space for the ACL | 565 | // create the SIDs and calculate the space for the ACL |
552 | // | 566 | // |
553 | pdwAccessMask = static_cast<DWORD*>(MemAlloc(sizeof(DWORD) * cAclAccesses, TRUE)); | 567 | pdwAccessMask = static_cast<DWORD*>(MemAlloc(sizeof(DWORD) * cAclAccesses, TRUE)); |
554 | ExitOnNull(pdwAccessMask, hr, E_OUTOFMEMORY, "failed allocate memory for access mask"); | 568 | AclExitOnNull(pdwAccessMask, hr, E_OUTOFMEMORY, "failed allocate memory for access mask"); |
555 | ppsid = static_cast<PSID*>(MemAlloc(sizeof(PSID) * cAclAccesses, TRUE)); | 569 | ppsid = static_cast<PSID*>(MemAlloc(sizeof(PSID) * cAclAccesses, TRUE)); |
556 | ExitOnNull(ppsid, hr, E_OUTOFMEMORY, "failed allocate memory for sid"); | 570 | AclExitOnNull(ppsid, hr, E_OUTOFMEMORY, "failed allocate memory for sid"); |
557 | 571 | ||
558 | cbAcl = sizeof (ACL); // start with the size of the header | 572 | cbAcl = sizeof (ACL); // start with the size of the header |
559 | for (i = 0; i < cAclAccesses; ++i) | 573 | for (i = 0; i < cAclAccesses; ++i) |
@@ -561,7 +575,7 @@ extern "C" HRESULT DAPI AclCreateDaclOld( | |||
561 | if (paa[i].pwzAccountName) | 575 | if (paa[i].pwzAccountName) |
562 | { | 576 | { |
563 | hr = AclGetAccountSid(NULL, paa[i].pwzAccountName, ppsid + i); | 577 | hr = AclGetAccountSid(NULL, paa[i].pwzAccountName, ppsid + i); |
564 | ExitOnFailure(hr, "failed to get SID for account: %ls", paa[i].pwzAccountName); | 578 | AclExitOnFailure(hr, "failed to get SID for account: %ls", paa[i].pwzAccountName); |
565 | } | 579 | } |
566 | else | 580 | else |
567 | { | 581 | { |
@@ -572,7 +586,7 @@ extern "C" HRESULT DAPI AclCreateDaclOld( | |||
572 | paa[i].nSubAuthority[6], paa[i].nSubAuthority[7], | 586 | paa[i].nSubAuthority[6], paa[i].nSubAuthority[7], |
573 | (void**)(ppsid + i)))) | 587 | (void**)(ppsid + i)))) |
574 | { | 588 | { |
575 | ExitWithLastError(hr, "failed to initialize SIDs #%u", i); | 589 | AclExitWithLastError(hr, "failed to initialize SIDs #%u", i); |
576 | } | 590 | } |
577 | } | 591 | } |
578 | 592 | ||
@@ -594,14 +608,14 @@ extern "C" HRESULT DAPI AclCreateDaclOld( | |||
594 | // allocate the ACL and set the appropriate ACEs | 608 | // allocate the ACL and set the appropriate ACEs |
595 | // | 609 | // |
596 | *ppACL = static_cast<ACL*>(MemAlloc(cbAcl, FALSE)); | 610 | *ppACL = static_cast<ACL*>(MemAlloc(cbAcl, FALSE)); |
597 | ExitOnNull(*ppACL, hr, E_OUTOFMEMORY, "failed allocate memory for ACL"); | 611 | AclExitOnNull(*ppACL, hr, E_OUTOFMEMORY, "failed allocate memory for ACL"); |
598 | 612 | ||
599 | #pragma prefast(push) | 613 | #pragma prefast(push) |
600 | #pragma prefast(disable:25029) | 614 | #pragma prefast(disable:25029) |
601 | if (!::InitializeAcl(*ppACL, cbAcl, ACL_REVISION)) | 615 | if (!::InitializeAcl(*ppACL, cbAcl, ACL_REVISION)) |
602 | #pragma prefast(pop) | 616 | #pragma prefast(pop) |
603 | { | 617 | { |
604 | ExitWithLastError(hr, "failed to initialize ACLs"); | 618 | AclExitWithLastError(hr, "failed to initialize ACLs"); |
605 | } | 619 | } |
606 | 620 | ||
607 | // add an access-allowed ACE for each of the SIDs | 621 | // add an access-allowed ACE for each of the SIDs |
@@ -614,7 +628,7 @@ extern "C" HRESULT DAPI AclCreateDaclOld( | |||
614 | if (!::AddAccessDeniedAceEx(*ppACL, ACL_REVISION, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, pdwAccessMask[i], *(ppsid + i))) | 628 | if (!::AddAccessDeniedAceEx(*ppACL, ACL_REVISION, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, pdwAccessMask[i], *(ppsid + i))) |
615 | #pragma prefast(pop) | 629 | #pragma prefast(pop) |
616 | { | 630 | { |
617 | ExitWithLastError(hr, "failed to add access denied for ACE"); | 631 | AclExitWithLastError(hr, "failed to add access denied for ACE"); |
618 | } | 632 | } |
619 | } | 633 | } |
620 | else | 634 | else |
@@ -624,7 +638,7 @@ extern "C" HRESULT DAPI AclCreateDaclOld( | |||
624 | if (!::AddAccessAllowedAceEx(*ppACL, ACL_REVISION, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, pdwAccessMask[i], *(ppsid + i))) | 638 | if (!::AddAccessAllowedAceEx(*ppACL, ACL_REVISION, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, pdwAccessMask[i], *(ppsid + i))) |
625 | #pragma prefast(pop) | 639 | #pragma prefast(pop) |
626 | { | 640 | { |
627 | ExitWithLastError(hr, "failed to add access allowed for ACE"); | 641 | AclExitWithLastError(hr, "failed to add access allowed for ACE"); |
628 | } | 642 | } |
629 | } | 643 | } |
630 | } | 644 | } |
@@ -669,8 +683,8 @@ extern "C" HRESULT DAPI AclCreateSecurityDescriptorFromDacl( | |||
669 | SECURITY_DESCRIPTOR sd; | 683 | SECURITY_DESCRIPTOR sd; |
670 | DWORD cbSD; | 684 | DWORD cbSD; |
671 | 685 | ||
672 | ExitOnNull(pACL, hr, E_INVALIDARG, "Failed to create security descriptor from DACL, because no DACL was provided"); | 686 | AclExitOnNull(pACL, hr, E_INVALIDARG, "Failed to create security descriptor from DACL, because no DACL was provided"); |
673 | ExitOnNull(ppsd, hr, E_INVALIDARG, "Failed to create security descriptor from DACL, because no output object was provided"); | 687 | AclExitOnNull(ppsd, hr, E_INVALIDARG, "Failed to create security descriptor from DACL, because no output object was provided"); |
674 | 688 | ||
675 | *ppsd = NULL; | 689 | *ppsd = NULL; |
676 | 690 | ||
@@ -687,7 +701,7 @@ extern "C" HRESULT DAPI AclCreateSecurityDescriptorFromDacl( | |||
687 | (!::SetSecurityDescriptorOwner(&sd, NULL, FALSE))) | 701 | (!::SetSecurityDescriptorOwner(&sd, NULL, FALSE))) |
688 | #pragma prefast(pop) | 702 | #pragma prefast(pop) |
689 | { | 703 | { |
690 | ExitWithLastError(hr, "failed to initialize security descriptor"); | 704 | AclExitWithLastError(hr, "failed to initialize security descriptor"); |
691 | } | 705 | } |
692 | 706 | ||
693 | // | 707 | // |
@@ -695,7 +709,7 @@ extern "C" HRESULT DAPI AclCreateSecurityDescriptorFromDacl( | |||
695 | // | 709 | // |
696 | cbSD = ::GetSecurityDescriptorLength(&sd); | 710 | cbSD = ::GetSecurityDescriptorLength(&sd); |
697 | *ppsd = static_cast<SECURITY_DESCRIPTOR*>(MemAlloc(cbSD, FALSE)); | 711 | *ppsd = static_cast<SECURITY_DESCRIPTOR*>(MemAlloc(cbSD, FALSE)); |
698 | ExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed allocate memory for security descriptor"); | 712 | AclExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed allocate memory for security descriptor"); |
699 | 713 | ||
700 | ::MakeSelfRelativeSD(&sd, (BYTE*)*ppsd, &cbSD); | 714 | ::MakeSelfRelativeSD(&sd, (BYTE*)*ppsd, &cbSD); |
701 | Assert(::IsValidSecurityDescriptor(*ppsd)); | 715 | Assert(::IsValidSecurityDescriptor(*ppsd)); |
@@ -734,7 +748,7 @@ extern "C" HRESULT DAPI AclCreateSecurityDescriptor( | |||
734 | // create the DACL | 748 | // create the DACL |
735 | // | 749 | // |
736 | hr = AclCreateDaclOld(paa, cAclAccesses, &pACL); | 750 | hr = AclCreateDaclOld(paa, cAclAccesses, &pACL); |
737 | ExitOnFailure(hr, "failed to create DACL for security descriptor"); | 751 | AclExitOnFailure(hr, "failed to create DACL for security descriptor"); |
738 | 752 | ||
739 | // | 753 | // |
740 | // create self-relative security descriptor | 754 | // create self-relative security descriptor |
@@ -770,15 +784,15 @@ extern "C" HRESULT DAPI AclCreateSecurityDescriptorFromString( | |||
770 | va_start(args, wzSddlFormat); | 784 | va_start(args, wzSddlFormat); |
771 | hr = StrAllocFormattedArgs(&pwzSddl, wzSddlFormat, args); | 785 | hr = StrAllocFormattedArgs(&pwzSddl, wzSddlFormat, args); |
772 | va_end(args); | 786 | va_end(args); |
773 | ExitOnFailure(hr, "failed to create SDDL string for format: %ls", wzSddlFormat); | 787 | AclExitOnFailure(hr, "failed to create SDDL string for format: %ls", wzSddlFormat); |
774 | 788 | ||
775 | if (!::ConvertStringSecurityDescriptorToSecurityDescriptorW(pwzSddl, SDDL_REVISION_1, &psd, &cbSD)) | 789 | if (!::ConvertStringSecurityDescriptorToSecurityDescriptorW(pwzSddl, SDDL_REVISION_1, &psd, &cbSD)) |
776 | { | 790 | { |
777 | ExitWithLastError(hr, "failed to create security descriptor from SDDL: %ls", pwzSddl); | 791 | AclExitWithLastError(hr, "failed to create security descriptor from SDDL: %ls", pwzSddl); |
778 | } | 792 | } |
779 | 793 | ||
780 | *ppsd = static_cast<SECURITY_DESCRIPTOR*>(MemAlloc(cbSD, FALSE)); | 794 | *ppsd = static_cast<SECURITY_DESCRIPTOR*>(MemAlloc(cbSD, FALSE)); |
781 | ExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed to allocate memory for security descriptor"); | 795 | AclExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed to allocate memory for security descriptor"); |
782 | 796 | ||
783 | memcpy(*ppsd, psd, cbSD); | 797 | memcpy(*ppsd, psd, cbSD); |
784 | Assert(::IsValidSecurityDescriptor(*ppsd)); | 798 | Assert(::IsValidSecurityDescriptor(*ppsd)); |
@@ -815,7 +829,7 @@ extern "C" HRESULT DAPI AclDuplicateSecurityDescriptor( | |||
815 | HRESULT hr = S_OK; | 829 | HRESULT hr = S_OK; |
816 | DWORD cbSD; | 830 | DWORD cbSD; |
817 | 831 | ||
818 | ExitOnNull(ppsd, hr, E_INVALIDARG, "Failed to get duplicate ACL security descriptor because no place to output was provided"); | 832 | AclExitOnNull(ppsd, hr, E_INVALIDARG, "Failed to get duplicate ACL security descriptor because no place to output was provided"); |
819 | *ppsd = NULL; | 833 | *ppsd = NULL; |
820 | 834 | ||
821 | // | 835 | // |
@@ -823,7 +837,7 @@ extern "C" HRESULT DAPI AclDuplicateSecurityDescriptor( | |||
823 | // | 837 | // |
824 | cbSD = ::GetSecurityDescriptorLength(psd); | 838 | cbSD = ::GetSecurityDescriptorLength(psd); |
825 | *ppsd = static_cast<SECURITY_DESCRIPTOR*>(MemAlloc(cbSD, 0)); | 839 | *ppsd = static_cast<SECURITY_DESCRIPTOR*>(MemAlloc(cbSD, 0)); |
826 | ExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed allocate memory for security descriptor"); | 840 | AclExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed allocate memory for security descriptor"); |
827 | 841 | ||
828 | memcpy(*ppsd, psd, cbSD); | 842 | memcpy(*ppsd, psd, cbSD); |
829 | Assert(::IsValidSecurityDescriptor(*ppsd)); | 843 | Assert(::IsValidSecurityDescriptor(*ppsd)); |
@@ -856,18 +870,18 @@ extern "C" HRESULT DAPI AclGetSecurityDescriptor( | |||
856 | PSECURITY_DESCRIPTOR psd = NULL; | 870 | PSECURITY_DESCRIPTOR psd = NULL; |
857 | DWORD cbSD; | 871 | DWORD cbSD; |
858 | 872 | ||
859 | ExitOnNull(ppsd, hr, E_INVALIDARG, "Failed to get ACL Security Descriptor because no place to output was provided"); | 873 | AclExitOnNull(ppsd, hr, E_INVALIDARG, "Failed to get ACL Security Descriptor because no place to output was provided"); |
860 | *ppsd = NULL; | 874 | *ppsd = NULL; |
861 | 875 | ||
862 | // get the security descriptor for the object | 876 | // get the security descriptor for the object |
863 | er = ::GetNamedSecurityInfoW(const_cast<LPWSTR>(wzObject), sot, securityInformation, NULL, NULL, NULL, NULL, &psd); | 877 | er = ::GetNamedSecurityInfoW(const_cast<LPWSTR>(wzObject), sot, securityInformation, NULL, NULL, NULL, NULL, &psd); |
864 | ExitOnWin32Error(er, hr, "failed to get security info from object: %ls", wzObject); | 878 | AclExitOnWin32Error(er, hr, "failed to get security info from object: %ls", wzObject); |
865 | Assert(::IsValidSecurityDescriptor(psd)); | 879 | Assert(::IsValidSecurityDescriptor(psd)); |
866 | 880 | ||
867 | // copy the self-relative security descriptor | 881 | // copy the self-relative security descriptor |
868 | cbSD = ::GetSecurityDescriptorLength(psd); | 882 | cbSD = ::GetSecurityDescriptorLength(psd); |
869 | *ppsd = static_cast<SECURITY_DESCRIPTOR*>(MemAlloc(cbSD, 0)); | 883 | *ppsd = static_cast<SECURITY_DESCRIPTOR*>(MemAlloc(cbSD, 0)); |
870 | ExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed allocate memory for security descriptor"); | 884 | AclExitOnNull(*ppsd, hr, E_OUTOFMEMORY, "failed allocate memory for security descriptor"); |
871 | 885 | ||
872 | memcpy(*ppsd, psd, cbSD); | 886 | memcpy(*ppsd, psd, cbSD); |
873 | Assert(::IsValidSecurityDescriptor(*ppsd)); | 887 | Assert(::IsValidSecurityDescriptor(*ppsd)); |
@@ -905,7 +919,7 @@ extern "C" HRESULT DAPI AclSetSecurityWithRetry( | |||
905 | DWORD i = 0; | 919 | DWORD i = 0; |
906 | 920 | ||
907 | hr = StrAllocString(&sczObject, wzObject, 0); | 921 | hr = StrAllocString(&sczObject, wzObject, 0); |
908 | ExitOnFailure(hr, "Failed to copy object to secure."); | 922 | AclExitOnFailure(hr, "Failed to copy object to secure."); |
909 | 923 | ||
910 | hr = E_FAIL; | 924 | hr = E_FAIL; |
911 | for (i = 0; FAILED(hr) && i <= cRetry; ++i) | 925 | for (i = 0; FAILED(hr) && i <= cRetry; ++i) |
@@ -918,7 +932,7 @@ extern "C" HRESULT DAPI AclSetSecurityWithRetry( | |||
918 | DWORD er = ::SetNamedSecurityInfoW(sczObject, sot, securityInformation, psidOwner, psidGroup, pDacl, pSacl); | 932 | DWORD er = ::SetNamedSecurityInfoW(sczObject, sot, securityInformation, psidOwner, psidGroup, pDacl, pSacl); |
919 | hr = HRESULT_FROM_WIN32(er); | 933 | hr = HRESULT_FROM_WIN32(er); |
920 | } | 934 | } |
921 | ExitOnRootFailure(hr, "Failed to set security on object '%ls' after %u retries.", wzObject, i); | 935 | AclExitOnRootFailure(hr, "Failed to set security on object '%ls' after %u retries.", wzObject, i); |
922 | 936 | ||
923 | LExit: | 937 | LExit: |
924 | ReleaseStr(sczObject); | 938 | ReleaseStr(sczObject); |
@@ -996,20 +1010,20 @@ extern "C" HRESULT DAPI AclAddAdminToSecurityDescriptor( | |||
996 | 1010 | ||
997 | if (!::GetSecurityDescriptorDacl(pSecurity, &fValid, &pAcl, &fDaclDefaulted) || !fValid) | 1011 | if (!::GetSecurityDescriptorDacl(pSecurity, &fValid, &pAcl, &fDaclDefaulted) || !fValid) |
998 | { | 1012 | { |
999 | ExitOnLastError(hr, "Failed to get acl from security descriptor"); | 1013 | AclExitOnLastError(hr, "Failed to get acl from security descriptor"); |
1000 | } | 1014 | } |
1001 | 1015 | ||
1002 | hr = AclGetWellKnownSid(WinBuiltinAdministratorsSid, &ace[0].psid); | 1016 | hr = AclGetWellKnownSid(WinBuiltinAdministratorsSid, &ace[0].psid); |
1003 | ExitOnFailure(hr, "failed to get sid for Administrators group"); | 1017 | AclExitOnFailure(hr, "failed to get sid for Administrators group"); |
1004 | 1018 | ||
1005 | ace[0].dwFlags = NO_PROPAGATE_INHERIT_ACE; | 1019 | ace[0].dwFlags = NO_PROPAGATE_INHERIT_ACE; |
1006 | ace[0].dwMask = GENERIC_ALL; | 1020 | ace[0].dwMask = GENERIC_ALL; |
1007 | 1021 | ||
1008 | hr = AclAddToDacl(pAcl, NULL, 0, ace, 1, &pAclNew); | 1022 | hr = AclAddToDacl(pAcl, NULL, 0, ace, 1, &pAclNew); |
1009 | ExitOnFailure(hr, "failed to add Administrators ACE to ACL"); | 1023 | AclExitOnFailure(hr, "failed to add Administrators ACE to ACL"); |
1010 | 1024 | ||
1011 | hr = AclCreateSecurityDescriptorFromDacl(pAclNew, &pSecurityNew); | 1025 | hr = AclCreateSecurityDescriptorFromDacl(pAclNew, &pSecurityNew); |
1012 | ExitOnLastError(hr, "Failed to create new security descriptor"); | 1026 | AclExitOnLastError(hr, "Failed to create new security descriptor"); |
1013 | 1027 | ||
1014 | // The DACL is referenced by, not copied into, the security descriptor. Make sure not to free it. | 1028 | // The DACL is referenced by, not copied into, the security descriptor. Make sure not to free it. |
1015 | pAclNew = NULL; | 1029 | pAclNew = NULL; |
diff --git a/src/dutil/apputil.cpp b/src/dutil/apputil.cpp index 8562a47a..589a09dd 100644 --- a/src/dutil/apputil.cpp +++ b/src/dutil/apputil.cpp | |||
@@ -2,6 +2,20 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | // Exit macros | ||
6 | #define AppExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__) | ||
7 | #define AppExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__) | ||
8 | #define AppExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__) | ||
9 | #define AppExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__) | ||
10 | #define AppExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__) | ||
11 | #define AppExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__) | ||
12 | #define AppExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_APPUTIL, p, x, e, s, __VA_ARGS__) | ||
13 | #define AppExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_APPUTIL, p, x, s, __VA_ARGS__) | ||
14 | #define AppExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_APPUTIL, p, x, e, s, __VA_ARGS__) | ||
15 | #define AppExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_APPUTIL, p, x, s, __VA_ARGS__) | ||
16 | #define AppExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_APPUTIL, e, x, s, __VA_ARGS__) | ||
17 | #define AppExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_APPUTIL, g, x, s, __VA_ARGS__) | ||
18 | |||
5 | const DWORD PRIVATE_LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800; | 19 | const DWORD PRIVATE_LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800; |
6 | typedef BOOL(WINAPI *LPFN_SETDEFAULTDLLDIRECTORIES)(DWORD); | 20 | typedef BOOL(WINAPI *LPFN_SETDEFAULTDLLDIRECTORIES)(DWORD); |
7 | typedef BOOL(WINAPI *LPFN_SETDLLDIRECTORYW)(LPCWSTR); | 21 | typedef BOOL(WINAPI *LPFN_SETDLLDIRECTORYW)(LPCWSTR); |
@@ -33,6 +47,7 @@ extern "C" void DAPI AppInitialize( | |||
33 | 47 | ||
34 | // Best effort call to initialize default DLL directories to system only. | 48 | // Best effort call to initialize default DLL directories to system only. |
35 | HMODULE hKernel32 = ::GetModuleHandleW(L"kernel32"); | 49 | HMODULE hKernel32 = ::GetModuleHandleW(L"kernel32"); |
50 | Assert(hKernel32); | ||
36 | LPFN_SETDEFAULTDLLDIRECTORIES pfnSetDefaultDllDirectories = (LPFN_SETDEFAULTDLLDIRECTORIES)::GetProcAddress(hKernel32, "SetDefaultDllDirectories"); | 51 | LPFN_SETDEFAULTDLLDIRECTORIES pfnSetDefaultDllDirectories = (LPFN_SETDEFAULTDLLDIRECTORIES)::GetProcAddress(hKernel32, "SetDefaultDllDirectories"); |
37 | if (pfnSetDefaultDllDirectories) | 52 | if (pfnSetDefaultDllDirectories) |
38 | { | 53 | { |
@@ -90,13 +105,13 @@ extern "C" DAPI_(HRESULT) AppParseCommandLine( | |||
90 | // which fails pretty miserably if your first argument is something like | 105 | // which fails pretty miserably if your first argument is something like |
91 | // FOO="C:\Program Files\My Company". So give it something harmless to play with. | 106 | // FOO="C:\Program Files\My Company". So give it something harmless to play with. |
92 | hr = StrAllocConcat(&sczCommandLine, L"ignored ", 0); | 107 | hr = StrAllocConcat(&sczCommandLine, L"ignored ", 0); |
93 | ExitOnFailure(hr, "Failed to initialize command line."); | 108 | AppExitOnFailure(hr, "Failed to initialize command line."); |
94 | 109 | ||
95 | hr = StrAllocConcat(&sczCommandLine, wzCommandLine, 0); | 110 | hr = StrAllocConcat(&sczCommandLine, wzCommandLine, 0); |
96 | ExitOnFailure(hr, "Failed to copy command line."); | 111 | AppExitOnFailure(hr, "Failed to copy command line."); |
97 | 112 | ||
98 | argv = ::CommandLineToArgvW(sczCommandLine, &argc); | 113 | argv = ::CommandLineToArgvW(sczCommandLine, &argc); |
99 | ExitOnNullWithLastError(argv, hr, "Failed to parse command line."); | 114 | AppExitOnNullWithLastError(argv, hr, "Failed to parse command line."); |
100 | 115 | ||
101 | // Skip "ignored" argument/hack. | 116 | // Skip "ignored" argument/hack. |
102 | *pArgv = argv + 1; | 117 | *pArgv = argv + 1; |
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 |
6 | static HRESULT ProcessEntry( | 20 | static 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 | ||
596 | LExit: | 610 | LExit: |
@@ -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 | ||
diff --git a/src/dutil/atomutil.cpp b/src/dutil/atomutil.cpp index 4a12fb80..c7c7975a 100644 --- a/src/dutil/atomutil.cpp +++ b/src/dutil/atomutil.cpp | |||
@@ -2,6 +2,19 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | // Exit macros | ||
6 | #define AtomExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_ATOMUTIL, x, s, __VA_ARGS__) | ||
7 | #define AtomExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_ATOMUTIL, x, s, __VA_ARGS__) | ||
8 | #define AtomExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_ATOMUTIL, x, s, __VA_ARGS__) | ||
9 | #define AtomExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_ATOMUTIL, x, s, __VA_ARGS__) | ||
10 | #define AtomExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_ATOMUTIL, x, s, __VA_ARGS__) | ||
11 | #define AtomExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_ATOMUTIL, x, s, __VA_ARGS__) | ||
12 | #define AtomExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_ATOMUTIL, p, x, e, s, __VA_ARGS__) | ||
13 | #define AtomExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_ATOMUTIL, p, x, s, __VA_ARGS__) | ||
14 | #define AtomExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_ATOMUTIL, p, x, e, s, __VA_ARGS__) | ||
15 | #define AtomExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_ATOMUTIL, p, x, s, __VA_ARGS__) | ||
16 | #define AtomExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_ATOMUTIL, e, x, s, __VA_ARGS__) | ||
17 | #define AtomExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_ATOMUTIL, g, x, s, __VA_ARGS__) | ||
5 | 18 | ||
6 | static HRESULT ParseAtomDocument( | 19 | static HRESULT ParseAtomDocument( |
7 | __in IXMLDOMDocument *pixd, | 20 | __in IXMLDOMDocument *pixd, |
@@ -98,7 +111,7 @@ extern "C" void DAPI AtomUninitialize() | |||
98 | 111 | ||
99 | *********************************************************************/ | 112 | *********************************************************************/ |
100 | extern "C" HRESULT DAPI AtomParseFromString( | 113 | extern "C" HRESULT DAPI AtomParseFromString( |
101 | __in LPCWSTR wzAtomString, | 114 | __in_z LPCWSTR wzAtomString, |
102 | __out ATOM_FEED **ppFeed | 115 | __out ATOM_FEED **ppFeed |
103 | ) | 116 | ) |
104 | { | 117 | { |
@@ -110,10 +123,10 @@ extern "C" HRESULT DAPI AtomParseFromString( | |||
110 | IXMLDOMDocument *pixdAtom = NULL; | 123 | IXMLDOMDocument *pixdAtom = NULL; |
111 | 124 | ||
112 | hr = XmlLoadDocument(wzAtomString, &pixdAtom); | 125 | hr = XmlLoadDocument(wzAtomString, &pixdAtom); |
113 | ExitOnFailure(hr, "Failed to load ATOM string as XML document."); | 126 | AtomExitOnFailure(hr, "Failed to load ATOM string as XML document."); |
114 | 127 | ||
115 | hr = ParseAtomDocument(pixdAtom, &pNewFeed); | 128 | hr = ParseAtomDocument(pixdAtom, &pNewFeed); |
116 | ExitOnFailure(hr, "Failed to parse ATOM document."); | 129 | AtomExitOnFailure(hr, "Failed to parse ATOM document."); |
117 | 130 | ||
118 | *ppFeed = pNewFeed; | 131 | *ppFeed = pNewFeed; |
119 | pNewFeed = NULL; | 132 | pNewFeed = NULL; |
@@ -131,7 +144,7 @@ LExit: | |||
131 | 144 | ||
132 | *********************************************************************/ | 145 | *********************************************************************/ |
133 | extern "C" HRESULT DAPI AtomParseFromFile( | 146 | extern "C" HRESULT DAPI AtomParseFromFile( |
134 | __in LPCWSTR wzAtomFile, | 147 | __in_z LPCWSTR wzAtomFile, |
135 | __out ATOM_FEED **ppFeed | 148 | __out ATOM_FEED **ppFeed |
136 | ) | 149 | ) |
137 | { | 150 | { |
@@ -143,10 +156,10 @@ extern "C" HRESULT DAPI AtomParseFromFile( | |||
143 | IXMLDOMDocument *pixdAtom = NULL; | 156 | IXMLDOMDocument *pixdAtom = NULL; |
144 | 157 | ||
145 | hr = XmlLoadDocumentFromFile(wzAtomFile, &pixdAtom); | 158 | hr = XmlLoadDocumentFromFile(wzAtomFile, &pixdAtom); |
146 | ExitOnFailure(hr, "Failed to load ATOM string as XML document."); | 159 | AtomExitOnFailure(hr, "Failed to load ATOM string as XML document."); |
147 | 160 | ||
148 | hr = ParseAtomDocument(pixdAtom, &pNewFeed); | 161 | hr = ParseAtomDocument(pixdAtom, &pNewFeed); |
149 | ExitOnFailure(hr, "Failed to parse ATOM document."); | 162 | AtomExitOnFailure(hr, "Failed to parse ATOM document."); |
150 | 163 | ||
151 | *ppFeed = pNewFeed; | 164 | *ppFeed = pNewFeed; |
152 | pNewFeed = NULL; | 165 | pNewFeed = NULL; |
@@ -175,7 +188,7 @@ extern "C" HRESULT DAPI AtomParseFromDocument( | |||
175 | ATOM_FEED *pNewFeed = NULL; | 188 | ATOM_FEED *pNewFeed = NULL; |
176 | 189 | ||
177 | hr = ParseAtomDocument(pixdDocument, &pNewFeed); | 190 | hr = ParseAtomDocument(pixdDocument, &pNewFeed); |
178 | ExitOnFailure(hr, "Failed to parse ATOM document."); | 191 | AtomExitOnFailure(hr, "Failed to parse ATOM document."); |
179 | 192 | ||
180 | *ppFeed = pNewFeed; | 193 | *ppFeed = pNewFeed; |
181 | pNewFeed = NULL; | 194 | pNewFeed = NULL; |
@@ -192,7 +205,7 @@ LExit: | |||
192 | 205 | ||
193 | *********************************************************************/ | 206 | *********************************************************************/ |
194 | extern "C" void DAPI AtomFreeFeed( | 207 | extern "C" void DAPI AtomFreeFeed( |
195 | __in_xcount(pFeed->cItems) ATOM_FEED *pFeed | 208 | __in_xcount(pFeed->cItems) ATOM_FEED* pFeed |
196 | ) | 209 | ) |
197 | { | 210 | { |
198 | if (pFeed) | 211 | if (pFeed) |
@@ -257,10 +270,10 @@ static HRESULT ParseAtomDocument( | |||
257 | // Get the document element and start processing feeds. | 270 | // Get the document element and start processing feeds. |
258 | // | 271 | // |
259 | hr = pixd->get_documentElement(&pFeedElement); | 272 | hr = pixd->get_documentElement(&pFeedElement); |
260 | ExitOnFailure(hr, "failed get_documentElement in ParseAtomDocument"); | 273 | AtomExitOnFailure(hr, "failed get_documentElement in ParseAtomDocument"); |
261 | 274 | ||
262 | hr = ParseAtomFeed(pFeedElement, &pNewFeed); | 275 | hr = ParseAtomFeed(pFeedElement, &pNewFeed); |
263 | ExitOnFailure(hr, "Failed to parse ATOM feed."); | 276 | AtomExitOnFailure(hr, "Failed to parse ATOM feed."); |
264 | 277 | ||
265 | if (S_FALSE == hr) | 278 | if (S_FALSE == hr) |
266 | { | 279 | { |
@@ -305,96 +318,96 @@ static HRESULT ParseAtomFeed( | |||
305 | 318 | ||
306 | // First, allocate the new feed and all the possible sub elements. | 319 | // First, allocate the new feed and all the possible sub elements. |
307 | pNewFeed = (ATOM_FEED*)MemAlloc(sizeof(ATOM_FEED), TRUE); | 320 | pNewFeed = (ATOM_FEED*)MemAlloc(sizeof(ATOM_FEED), TRUE); |
308 | ExitOnNull(pNewFeed, hr, E_OUTOFMEMORY, "Failed to allocate ATOM feed structure."); | 321 | AtomExitOnNull(pNewFeed, hr, E_OUTOFMEMORY, "Failed to allocate ATOM feed structure."); |
309 | 322 | ||
310 | pNewFeed->pixn = pixnFeed; | 323 | pNewFeed->pixn = pixnFeed; |
311 | pNewFeed->pixn->AddRef(); | 324 | pNewFeed->pixn->AddRef(); |
312 | 325 | ||
313 | hr = AllocateAtomType<ATOM_AUTHOR>(pixnFeed, L"author", &pNewFeed->rgAuthors, &pNewFeed->cAuthors); | 326 | hr = AllocateAtomType<ATOM_AUTHOR>(pixnFeed, L"author", &pNewFeed->rgAuthors, &pNewFeed->cAuthors); |
314 | ExitOnFailure(hr, "Failed to allocate ATOM feed authors."); | 327 | AtomExitOnFailure(hr, "Failed to allocate ATOM feed authors."); |
315 | 328 | ||
316 | hr = AllocateAtomType<ATOM_CATEGORY>(pixnFeed, L"category", &pNewFeed->rgCategories, &pNewFeed->cCategories); | 329 | hr = AllocateAtomType<ATOM_CATEGORY>(pixnFeed, L"category", &pNewFeed->rgCategories, &pNewFeed->cCategories); |
317 | ExitOnFailure(hr, "Failed to allocate ATOM feed categories."); | 330 | AtomExitOnFailure(hr, "Failed to allocate ATOM feed categories."); |
318 | 331 | ||
319 | hr = AllocateAtomType<ATOM_ENTRY>(pixnFeed, L"entry", &pNewFeed->rgEntries, &pNewFeed->cEntries); | 332 | hr = AllocateAtomType<ATOM_ENTRY>(pixnFeed, L"entry", &pNewFeed->rgEntries, &pNewFeed->cEntries); |
320 | ExitOnFailure(hr, "Failed to allocate ATOM feed entries."); | 333 | AtomExitOnFailure(hr, "Failed to allocate ATOM feed entries."); |
321 | 334 | ||
322 | hr = AllocateAtomType<ATOM_LINK>(pixnFeed, L"link", &pNewFeed->rgLinks, &pNewFeed->cLinks); | 335 | hr = AllocateAtomType<ATOM_LINK>(pixnFeed, L"link", &pNewFeed->rgLinks, &pNewFeed->cLinks); |
323 | ExitOnFailure(hr, "Failed to allocate ATOM feed links."); | 336 | AtomExitOnFailure(hr, "Failed to allocate ATOM feed links."); |
324 | 337 | ||
325 | // Second, process the elements under a feed. | 338 | // Second, process the elements under a feed. |
326 | hr = pixnFeed->get_childNodes(&pNodeList); | 339 | hr = pixnFeed->get_childNodes(&pNodeList); |
327 | ExitOnFailure(hr, "Failed to get child nodes of ATOM feed element."); | 340 | AtomExitOnFailure(hr, "Failed to get child nodes of ATOM feed element."); |
328 | 341 | ||
329 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) | 342 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) |
330 | { | 343 | { |
331 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"generator", -1)) | 344 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"generator", -1)) |
332 | { | 345 | { |
333 | hr = AssignString(&pNewFeed->wzGenerator, pNode); | 346 | hr = AssignString(&pNewFeed->wzGenerator, pNode); |
334 | ExitOnFailure(hr, "Failed to allocate ATOM feed generator."); | 347 | AtomExitOnFailure(hr, "Failed to allocate ATOM feed generator."); |
335 | } | 348 | } |
336 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"icon", -1)) | 349 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"icon", -1)) |
337 | { | 350 | { |
338 | hr = AssignString(&pNewFeed->wzIcon, pNode); | 351 | hr = AssignString(&pNewFeed->wzIcon, pNode); |
339 | ExitOnFailure(hr, "Failed to allocate ATOM feed icon."); | 352 | AtomExitOnFailure(hr, "Failed to allocate ATOM feed icon."); |
340 | } | 353 | } |
341 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"id", -1)) | 354 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"id", -1)) |
342 | { | 355 | { |
343 | hr = AssignString(&pNewFeed->wzId, pNode); | 356 | hr = AssignString(&pNewFeed->wzId, pNode); |
344 | ExitOnFailure(hr, "Failed to allocate ATOM feed id."); | 357 | AtomExitOnFailure(hr, "Failed to allocate ATOM feed id."); |
345 | } | 358 | } |
346 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"logo", -1)) | 359 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"logo", -1)) |
347 | { | 360 | { |
348 | hr = AssignString(&pNewFeed->wzLogo, pNode); | 361 | hr = AssignString(&pNewFeed->wzLogo, pNode); |
349 | ExitOnFailure(hr, "Failed to allocate ATOM feed logo."); | 362 | AtomExitOnFailure(hr, "Failed to allocate ATOM feed logo."); |
350 | } | 363 | } |
351 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"subtitle", -1)) | 364 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"subtitle", -1)) |
352 | { | 365 | { |
353 | hr = AssignString(&pNewFeed->wzSubtitle, pNode); | 366 | hr = AssignString(&pNewFeed->wzSubtitle, pNode); |
354 | ExitOnFailure(hr, "Failed to allocate ATOM feed subtitle."); | 367 | AtomExitOnFailure(hr, "Failed to allocate ATOM feed subtitle."); |
355 | } | 368 | } |
356 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"title", -1)) | 369 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"title", -1)) |
357 | { | 370 | { |
358 | hr = AssignString(&pNewFeed->wzTitle, pNode); | 371 | hr = AssignString(&pNewFeed->wzTitle, pNode); |
359 | ExitOnFailure(hr, "Failed to allocate ATOM feed title."); | 372 | AtomExitOnFailure(hr, "Failed to allocate ATOM feed title."); |
360 | } | 373 | } |
361 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"updated", -1)) | 374 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"updated", -1)) |
362 | { | 375 | { |
363 | hr = AssignDateTime(&pNewFeed->ftUpdated, pNode); | 376 | hr = AssignDateTime(&pNewFeed->ftUpdated, pNode); |
364 | ExitOnFailure(hr, "Failed to allocate ATOM feed updated."); | 377 | AtomExitOnFailure(hr, "Failed to allocate ATOM feed updated."); |
365 | } | 378 | } |
366 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"author", -1)) | 379 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"author", -1)) |
367 | { | 380 | { |
368 | hr = ParseAtomAuthor(pNode, &pNewFeed->rgAuthors[cAuthors]); | 381 | hr = ParseAtomAuthor(pNode, &pNewFeed->rgAuthors[cAuthors]); |
369 | ExitOnFailure(hr, "Failed to parse ATOM author."); | 382 | AtomExitOnFailure(hr, "Failed to parse ATOM author."); |
370 | 383 | ||
371 | ++cAuthors; | 384 | ++cAuthors; |
372 | } | 385 | } |
373 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"category", -1)) | 386 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"category", -1)) |
374 | { | 387 | { |
375 | hr = ParseAtomCategory(pNode, &pNewFeed->rgCategories[cCategories]); | 388 | hr = ParseAtomCategory(pNode, &pNewFeed->rgCategories[cCategories]); |
376 | ExitOnFailure(hr, "Failed to parse ATOM category."); | 389 | AtomExitOnFailure(hr, "Failed to parse ATOM category."); |
377 | 390 | ||
378 | ++cCategories; | 391 | ++cCategories; |
379 | } | 392 | } |
380 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"entry", -1)) | 393 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"entry", -1)) |
381 | { | 394 | { |
382 | hr = ParseAtomEntry(pNode, &pNewFeed->rgEntries[cEntries]); | 395 | hr = ParseAtomEntry(pNode, &pNewFeed->rgEntries[cEntries]); |
383 | ExitOnFailure(hr, "Failed to parse ATOM entry."); | 396 | AtomExitOnFailure(hr, "Failed to parse ATOM entry."); |
384 | 397 | ||
385 | ++cEntries; | 398 | ++cEntries; |
386 | } | 399 | } |
387 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"link", -1)) | 400 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"link", -1)) |
388 | { | 401 | { |
389 | hr = ParseAtomLink(pNode, &pNewFeed->rgLinks[cLinks]); | 402 | hr = ParseAtomLink(pNode, &pNewFeed->rgLinks[cLinks]); |
390 | ExitOnFailure(hr, "Failed to parse ATOM link."); | 403 | AtomExitOnFailure(hr, "Failed to parse ATOM link."); |
391 | 404 | ||
392 | ++cLinks; | 405 | ++cLinks; |
393 | } | 406 | } |
394 | else | 407 | else |
395 | { | 408 | { |
396 | hr = ParseAtomUnknownElement(pNode, &pNewFeed->pUnknownElements); | 409 | hr = ParseAtomUnknownElement(pNode, &pNewFeed->pUnknownElements); |
397 | ExitOnFailure(hr, "Failed to parse unknown ATOM feed element: %ls", bstrNodeName); | 410 | AtomExitOnFailure(hr, "Failed to parse unknown ATOM feed element: %ls", bstrNodeName); |
398 | } | 411 | } |
399 | 412 | ||
400 | ReleaseNullBSTR(bstrNodeName); | 413 | ReleaseNullBSTR(bstrNodeName); |
@@ -404,17 +417,17 @@ static HRESULT ParseAtomFeed( | |||
404 | if (!pNewFeed->wzId || !*pNewFeed->wzId) | 417 | if (!pNewFeed->wzId || !*pNewFeed->wzId) |
405 | { | 418 | { |
406 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 419 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); |
407 | ExitOnRootFailure(hr, "Failed to find required feed/id element."); | 420 | AtomExitOnRootFailure(hr, "Failed to find required feed/id element."); |
408 | } | 421 | } |
409 | else if (!pNewFeed->wzTitle || !*pNewFeed->wzTitle) | 422 | else if (!pNewFeed->wzTitle || !*pNewFeed->wzTitle) |
410 | { | 423 | { |
411 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 424 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); |
412 | ExitOnRootFailure(hr, "Failed to find required feed/title element."); | 425 | AtomExitOnRootFailure(hr, "Failed to find required feed/title element."); |
413 | } | 426 | } |
414 | else if (0 == pNewFeed->ftUpdated.dwHighDateTime && 0 == pNewFeed->ftUpdated.dwLowDateTime) | 427 | else if (0 == pNewFeed->ftUpdated.dwHighDateTime && 0 == pNewFeed->ftUpdated.dwLowDateTime) |
415 | { | 428 | { |
416 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 429 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); |
417 | ExitOnRootFailure(hr, "Failed to find required feed/updated element."); | 430 | AtomExitOnRootFailure(hr, "Failed to find required feed/updated element."); |
418 | } | 431 | } |
419 | 432 | ||
420 | *ppFeed = pNewFeed; | 433 | *ppFeed = pNewFeed; |
@@ -450,12 +463,12 @@ template<class T> static HRESULT AllocateAtomType( | |||
450 | T* prgT = NULL; | 463 | T* prgT = NULL; |
451 | 464 | ||
452 | hr = XmlSelectNodes(pixnParent, wzT, &pNodeList); | 465 | hr = XmlSelectNodes(pixnParent, wzT, &pNodeList); |
453 | ExitOnFailure(hr, "Failed to select all ATOM %ls.", wzT); | 466 | AtomExitOnFailure(hr, "Failed to select all ATOM %ls.", wzT); |
454 | 467 | ||
455 | if (S_OK == hr) | 468 | if (S_OK == hr) |
456 | { | 469 | { |
457 | hr = pNodeList->get_length(&cT); | 470 | hr = pNodeList->get_length(&cT); |
458 | ExitOnFailure(hr, "Failed to count the number of ATOM %ls.", wzT); | 471 | AtomExitOnFailure(hr, "Failed to count the number of ATOM %ls.", wzT); |
459 | 472 | ||
460 | if (cT == 0) | 473 | if (cT == 0) |
461 | { | 474 | { |
@@ -463,7 +476,7 @@ template<class T> static HRESULT AllocateAtomType( | |||
463 | } | 476 | } |
464 | 477 | ||
465 | prgT = static_cast<T*>(MemAlloc(sizeof(T) * cT, TRUE)); | 478 | prgT = static_cast<T*>(MemAlloc(sizeof(T) * cT, TRUE)); |
466 | ExitOnNull(prgT, hr, E_OUTOFMEMORY, "Failed to allocate ATOM."); | 479 | AtomExitOnNull(prgT, hr, E_OUTOFMEMORY, "Failed to allocate ATOM."); |
467 | 480 | ||
468 | *pcT = cT; | 481 | *pcT = cT; |
469 | *pprgT = prgT; | 482 | *pprgT = prgT; |
@@ -499,30 +512,30 @@ static HRESULT ParseAtomAuthor( | |||
499 | BSTR bstrNodeName = NULL; | 512 | BSTR bstrNodeName = NULL; |
500 | 513 | ||
501 | hr = pixnAuthor->get_childNodes(&pNodeList); | 514 | hr = pixnAuthor->get_childNodes(&pNodeList); |
502 | ExitOnFailure(hr, "Failed to get child nodes of ATOM author element."); | 515 | AtomExitOnFailure(hr, "Failed to get child nodes of ATOM author element."); |
503 | 516 | ||
504 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) | 517 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) |
505 | { | 518 | { |
506 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"name", -1)) | 519 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"name", -1)) |
507 | { | 520 | { |
508 | hr = AssignString(&pAuthor->wzName, pNode); | 521 | hr = AssignString(&pAuthor->wzName, pNode); |
509 | ExitOnFailure(hr, "Failed to allocate ATOM author name."); | 522 | AtomExitOnFailure(hr, "Failed to allocate ATOM author name."); |
510 | } | 523 | } |
511 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"email", -1)) | 524 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"email", -1)) |
512 | { | 525 | { |
513 | hr = AssignString(&pAuthor->wzEmail, pNode); | 526 | hr = AssignString(&pAuthor->wzEmail, pNode); |
514 | ExitOnFailure(hr, "Failed to allocate ATOM author email."); | 527 | AtomExitOnFailure(hr, "Failed to allocate ATOM author email."); |
515 | } | 528 | } |
516 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"uri", -1)) | 529 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"uri", -1)) |
517 | { | 530 | { |
518 | hr = AssignString(&pAuthor->wzUrl, pNode); | 531 | hr = AssignString(&pAuthor->wzUrl, pNode); |
519 | ExitOnFailure(hr, "Failed to allocate ATOM author uri."); | 532 | AtomExitOnFailure(hr, "Failed to allocate ATOM author uri."); |
520 | } | 533 | } |
521 | 534 | ||
522 | ReleaseNullBSTR(bstrNodeName); | 535 | ReleaseNullBSTR(bstrNodeName); |
523 | ReleaseNullObject(pNode); | 536 | ReleaseNullObject(pNode); |
524 | } | 537 | } |
525 | ExitOnFailure(hr, "Failed to process all ATOM author elements."); | 538 | AtomExitOnFailure(hr, "Failed to process all ATOM author elements."); |
526 | 539 | ||
527 | hr = S_OK; | 540 | hr = S_OK; |
528 | 541 | ||
@@ -553,44 +566,44 @@ static HRESULT ParseAtomCategory( | |||
553 | 566 | ||
554 | // Process attributes first. | 567 | // Process attributes first. |
555 | hr = pixnCategory->get_attributes(&pixnnmAttributes); | 568 | hr = pixnCategory->get_attributes(&pixnnmAttributes); |
556 | ExitOnFailure(hr, "Failed get attributes on ATOM unknown element."); | 569 | AtomExitOnFailure(hr, "Failed get attributes on ATOM unknown element."); |
557 | 570 | ||
558 | while (S_OK == (hr = XmlNextAttribute(pixnnmAttributes, &pNode, &bstrNodeName))) | 571 | while (S_OK == (hr = XmlNextAttribute(pixnnmAttributes, &pNode, &bstrNodeName))) |
559 | { | 572 | { |
560 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"label", -1)) | 573 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"label", -1)) |
561 | { | 574 | { |
562 | hr = AssignString(&pCategory->wzLabel, pNode); | 575 | hr = AssignString(&pCategory->wzLabel, pNode); |
563 | ExitOnFailure(hr, "Failed to allocate ATOM category label."); | 576 | AtomExitOnFailure(hr, "Failed to allocate ATOM category label."); |
564 | } | 577 | } |
565 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"scheme", -1)) | 578 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"scheme", -1)) |
566 | { | 579 | { |
567 | hr = AssignString(&pCategory->wzScheme, pNode); | 580 | hr = AssignString(&pCategory->wzScheme, pNode); |
568 | ExitOnFailure(hr, "Failed to allocate ATOM category scheme."); | 581 | AtomExitOnFailure(hr, "Failed to allocate ATOM category scheme."); |
569 | } | 582 | } |
570 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"term", -1)) | 583 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"term", -1)) |
571 | { | 584 | { |
572 | hr = AssignString(&pCategory->wzTerm, pNode); | 585 | hr = AssignString(&pCategory->wzTerm, pNode); |
573 | ExitOnFailure(hr, "Failed to allocate ATOM category term."); | 586 | AtomExitOnFailure(hr, "Failed to allocate ATOM category term."); |
574 | } | 587 | } |
575 | 588 | ||
576 | ReleaseNullBSTR(bstrNodeName); | 589 | ReleaseNullBSTR(bstrNodeName); |
577 | ReleaseNullObject(pNode); | 590 | ReleaseNullObject(pNode); |
578 | } | 591 | } |
579 | ExitOnFailure(hr, "Failed to process all ATOM category attributes."); | 592 | AtomExitOnFailure(hr, "Failed to process all ATOM category attributes."); |
580 | 593 | ||
581 | // Process elements second. | 594 | // Process elements second. |
582 | hr = pixnCategory->get_childNodes(&pNodeList); | 595 | hr = pixnCategory->get_childNodes(&pNodeList); |
583 | ExitOnFailure(hr, "Failed to get child nodes of ATOM category element."); | 596 | AtomExitOnFailure(hr, "Failed to get child nodes of ATOM category element."); |
584 | 597 | ||
585 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) | 598 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) |
586 | { | 599 | { |
587 | hr = ParseAtomUnknownElement(pNode, &pCategory->pUnknownElements); | 600 | hr = ParseAtomUnknownElement(pNode, &pCategory->pUnknownElements); |
588 | ExitOnFailure(hr, "Failed to parse unknown ATOM category element: %ls", bstrNodeName); | 601 | AtomExitOnFailure(hr, "Failed to parse unknown ATOM category element: %ls", bstrNodeName); |
589 | 602 | ||
590 | ReleaseNullBSTR(bstrNodeName); | 603 | ReleaseNullBSTR(bstrNodeName); |
591 | ReleaseNullObject(pNode); | 604 | ReleaseNullObject(pNode); |
592 | } | 605 | } |
593 | ExitOnFailure(hr, "Failed to process all ATOM category elements."); | 606 | AtomExitOnFailure(hr, "Failed to process all ATOM category elements."); |
594 | 607 | ||
595 | hr = S_OK; | 608 | hr = S_OK; |
596 | 609 | ||
@@ -622,42 +635,42 @@ static HRESULT ParseAtomContent( | |||
622 | 635 | ||
623 | // Process attributes first. | 636 | // Process attributes first. |
624 | hr = pixnContent->get_attributes(&pixnnmAttributes); | 637 | hr = pixnContent->get_attributes(&pixnnmAttributes); |
625 | ExitOnFailure(hr, "Failed get attributes on ATOM unknown element."); | 638 | AtomExitOnFailure(hr, "Failed get attributes on ATOM unknown element."); |
626 | 639 | ||
627 | while (S_OK == (hr = XmlNextAttribute(pixnnmAttributes, &pNode, &bstrNodeName))) | 640 | while (S_OK == (hr = XmlNextAttribute(pixnnmAttributes, &pNode, &bstrNodeName))) |
628 | { | 641 | { |
629 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"type", -1)) | 642 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"type", -1)) |
630 | { | 643 | { |
631 | hr = AssignString(&pContent->wzType, pNode); | 644 | hr = AssignString(&pContent->wzType, pNode); |
632 | ExitOnFailure(hr, "Failed to allocate ATOM content type."); | 645 | AtomExitOnFailure(hr, "Failed to allocate ATOM content type."); |
633 | } | 646 | } |
634 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"url", -1)) | 647 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"url", -1)) |
635 | { | 648 | { |
636 | hr = AssignString(&pContent->wzUrl, pNode); | 649 | hr = AssignString(&pContent->wzUrl, pNode); |
637 | ExitOnFailure(hr, "Failed to allocate ATOM content scheme."); | 650 | AtomExitOnFailure(hr, "Failed to allocate ATOM content scheme."); |
638 | } | 651 | } |
639 | 652 | ||
640 | ReleaseNullBSTR(bstrNodeName); | 653 | ReleaseNullBSTR(bstrNodeName); |
641 | ReleaseNullObject(pNode); | 654 | ReleaseNullObject(pNode); |
642 | } | 655 | } |
643 | ExitOnFailure(hr, "Failed to process all ATOM content attributes."); | 656 | AtomExitOnFailure(hr, "Failed to process all ATOM content attributes."); |
644 | 657 | ||
645 | // Process elements second. | 658 | // Process elements second. |
646 | hr = pixnContent->get_childNodes(&pNodeList); | 659 | hr = pixnContent->get_childNodes(&pNodeList); |
647 | ExitOnFailure(hr, "Failed to get child nodes of ATOM content element."); | 660 | AtomExitOnFailure(hr, "Failed to get child nodes of ATOM content element."); |
648 | 661 | ||
649 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) | 662 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) |
650 | { | 663 | { |
651 | hr = ParseAtomUnknownElement(pNode, &pContent->pUnknownElements); | 664 | hr = ParseAtomUnknownElement(pNode, &pContent->pUnknownElements); |
652 | ExitOnFailure(hr, "Failed to parse unknown ATOM content element: %ls", bstrNodeName); | 665 | AtomExitOnFailure(hr, "Failed to parse unknown ATOM content element: %ls", bstrNodeName); |
653 | 666 | ||
654 | ReleaseNullBSTR(bstrNodeName); | 667 | ReleaseNullBSTR(bstrNodeName); |
655 | ReleaseNullObject(pNode); | 668 | ReleaseNullObject(pNode); |
656 | } | 669 | } |
657 | ExitOnFailure(hr, "Failed to process all ATOM content elements."); | 670 | AtomExitOnFailure(hr, "Failed to process all ATOM content elements."); |
658 | 671 | ||
659 | hr = AssignString(&pContent->wzValue, pixnContent); | 672 | hr = AssignString(&pContent->wzValue, pixnContent); |
660 | ExitOnFailure(hr, "Failed to allocate ATOM content value."); | 673 | AtomExitOnFailure(hr, "Failed to allocate ATOM content value."); |
661 | 674 | ||
662 | LExit: | 675 | LExit: |
663 | ReleaseBSTR(bstrNodeName); | 676 | ReleaseBSTR(bstrNodeName); |
@@ -694,56 +707,56 @@ static HRESULT ParseAtomEntry( | |||
694 | 707 | ||
695 | // First, allocate all the possible sub elements. | 708 | // First, allocate all the possible sub elements. |
696 | hr = AllocateAtomType<ATOM_AUTHOR>(pixnEntry, L"author", &pEntry->rgAuthors, &pEntry->cAuthors); | 709 | hr = AllocateAtomType<ATOM_AUTHOR>(pixnEntry, L"author", &pEntry->rgAuthors, &pEntry->cAuthors); |
697 | ExitOnFailure(hr, "Failed to allocate ATOM entry authors."); | 710 | AtomExitOnFailure(hr, "Failed to allocate ATOM entry authors."); |
698 | 711 | ||
699 | hr = AllocateAtomType<ATOM_CATEGORY>(pixnEntry, L"category", &pEntry->rgCategories, &pEntry->cCategories); | 712 | hr = AllocateAtomType<ATOM_CATEGORY>(pixnEntry, L"category", &pEntry->rgCategories, &pEntry->cCategories); |
700 | ExitOnFailure(hr, "Failed to allocate ATOM entry categories."); | 713 | AtomExitOnFailure(hr, "Failed to allocate ATOM entry categories."); |
701 | 714 | ||
702 | hr = AllocateAtomType<ATOM_LINK>(pixnEntry, L"link", &pEntry->rgLinks, &pEntry->cLinks); | 715 | hr = AllocateAtomType<ATOM_LINK>(pixnEntry, L"link", &pEntry->rgLinks, &pEntry->cLinks); |
703 | ExitOnFailure(hr, "Failed to allocate ATOM entry links."); | 716 | AtomExitOnFailure(hr, "Failed to allocate ATOM entry links."); |
704 | 717 | ||
705 | // Second, process elements. | 718 | // Second, process elements. |
706 | hr = pixnEntry->get_childNodes(&pNodeList); | 719 | hr = pixnEntry->get_childNodes(&pNodeList); |
707 | ExitOnFailure(hr, "Failed to get child nodes of ATOM entry element."); | 720 | AtomExitOnFailure(hr, "Failed to get child nodes of ATOM entry element."); |
708 | 721 | ||
709 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) | 722 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) |
710 | { | 723 | { |
711 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"id", -1)) | 724 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"id", -1)) |
712 | { | 725 | { |
713 | hr = AssignString(&pEntry->wzId, pNode); | 726 | hr = AssignString(&pEntry->wzId, pNode); |
714 | ExitOnFailure(hr, "Failed to allocate ATOM entry id."); | 727 | AtomExitOnFailure(hr, "Failed to allocate ATOM entry id."); |
715 | } | 728 | } |
716 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"summary", -1)) | 729 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"summary", -1)) |
717 | { | 730 | { |
718 | hr = AssignString(&pEntry->wzSummary, pNode); | 731 | hr = AssignString(&pEntry->wzSummary, pNode); |
719 | ExitOnFailure(hr, "Failed to allocate ATOM entry summary."); | 732 | AtomExitOnFailure(hr, "Failed to allocate ATOM entry summary."); |
720 | } | 733 | } |
721 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"title", -1)) | 734 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"title", -1)) |
722 | { | 735 | { |
723 | hr = AssignString(&pEntry->wzTitle, pNode); | 736 | hr = AssignString(&pEntry->wzTitle, pNode); |
724 | ExitOnFailure(hr, "Failed to allocate ATOM entry title."); | 737 | AtomExitOnFailure(hr, "Failed to allocate ATOM entry title."); |
725 | } | 738 | } |
726 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"published", -1)) | 739 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"published", -1)) |
727 | { | 740 | { |
728 | hr = AssignDateTime(&pEntry->ftPublished, pNode); | 741 | hr = AssignDateTime(&pEntry->ftPublished, pNode); |
729 | ExitOnFailure(hr, "Failed to allocate ATOM entry published."); | 742 | AtomExitOnFailure(hr, "Failed to allocate ATOM entry published."); |
730 | } | 743 | } |
731 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"updated", -1)) | 744 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"updated", -1)) |
732 | { | 745 | { |
733 | hr = AssignDateTime(&pEntry->ftUpdated, pNode); | 746 | hr = AssignDateTime(&pEntry->ftUpdated, pNode); |
734 | ExitOnFailure(hr, "Failed to allocate ATOM entry updated."); | 747 | AtomExitOnFailure(hr, "Failed to allocate ATOM entry updated."); |
735 | } | 748 | } |
736 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"author", -1)) | 749 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"author", -1)) |
737 | { | 750 | { |
738 | hr = ParseAtomAuthor(pNode, &pEntry->rgAuthors[cAuthors]); | 751 | hr = ParseAtomAuthor(pNode, &pEntry->rgAuthors[cAuthors]); |
739 | ExitOnFailure(hr, "Failed to parse ATOM entry author."); | 752 | AtomExitOnFailure(hr, "Failed to parse ATOM entry author."); |
740 | 753 | ||
741 | ++cAuthors; | 754 | ++cAuthors; |
742 | } | 755 | } |
743 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"category", -1)) | 756 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"category", -1)) |
744 | { | 757 | { |
745 | hr = ParseAtomCategory(pNode, &pEntry->rgCategories[cCategories]); | 758 | hr = ParseAtomCategory(pNode, &pEntry->rgCategories[cCategories]); |
746 | ExitOnFailure(hr, "Failed to parse ATOM entry category."); | 759 | AtomExitOnFailure(hr, "Failed to parse ATOM entry category."); |
747 | 760 | ||
748 | ++cCategories; | 761 | ++cCategories; |
749 | } | 762 | } |
@@ -752,47 +765,47 @@ static HRESULT ParseAtomEntry( | |||
752 | if (NULL != pEntry->pContent) | 765 | if (NULL != pEntry->pContent) |
753 | { | 766 | { |
754 | hr = E_UNEXPECTED; | 767 | hr = E_UNEXPECTED; |
755 | ExitOnFailure(hr, "Cannot have two content elements in ATOM entry."); | 768 | AtomExitOnFailure(hr, "Cannot have two content elements in ATOM entry."); |
756 | } | 769 | } |
757 | 770 | ||
758 | pEntry->pContent = static_cast<ATOM_CONTENT*>(MemAlloc(sizeof(ATOM_CONTENT), TRUE)); | 771 | pEntry->pContent = static_cast<ATOM_CONTENT*>(MemAlloc(sizeof(ATOM_CONTENT), TRUE)); |
759 | ExitOnNull(pEntry->pContent, hr, E_OUTOFMEMORY, "Failed to allocate ATOM entry content."); | 772 | AtomExitOnNull(pEntry->pContent, hr, E_OUTOFMEMORY, "Failed to allocate ATOM entry content."); |
760 | 773 | ||
761 | hr = ParseAtomContent(pNode, pEntry->pContent); | 774 | hr = ParseAtomContent(pNode, pEntry->pContent); |
762 | ExitOnFailure(hr, "Failed to parse ATOM entry content."); | 775 | AtomExitOnFailure(hr, "Failed to parse ATOM entry content."); |
763 | } | 776 | } |
764 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"link", -1)) | 777 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"link", -1)) |
765 | { | 778 | { |
766 | hr = ParseAtomLink(pNode, &pEntry->rgLinks[cLinks]); | 779 | hr = ParseAtomLink(pNode, &pEntry->rgLinks[cLinks]); |
767 | ExitOnFailure(hr, "Failed to parse ATOM entry link."); | 780 | AtomExitOnFailure(hr, "Failed to parse ATOM entry link."); |
768 | 781 | ||
769 | ++cLinks; | 782 | ++cLinks; |
770 | } | 783 | } |
771 | else | 784 | else |
772 | { | 785 | { |
773 | hr = ParseAtomUnknownElement(pNode, &pEntry->pUnknownElements); | 786 | hr = ParseAtomUnknownElement(pNode, &pEntry->pUnknownElements); |
774 | ExitOnFailure(hr, "Failed to parse unknown ATOM entry element: %ls", bstrNodeName); | 787 | AtomExitOnFailure(hr, "Failed to parse unknown ATOM entry element: %ls", bstrNodeName); |
775 | } | 788 | } |
776 | 789 | ||
777 | ReleaseNullBSTR(bstrNodeName); | 790 | ReleaseNullBSTR(bstrNodeName); |
778 | ReleaseNullObject(pNode); | 791 | ReleaseNullObject(pNode); |
779 | } | 792 | } |
780 | ExitOnFailure(hr, "Failed to process all ATOM entry elements."); | 793 | AtomExitOnFailure(hr, "Failed to process all ATOM entry elements."); |
781 | 794 | ||
782 | if (!pEntry->wzId || !*pEntry->wzId) | 795 | if (!pEntry->wzId || !*pEntry->wzId) |
783 | { | 796 | { |
784 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 797 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); |
785 | ExitOnRootFailure(hr, "Failed to find required feed/entry/id element."); | 798 | AtomExitOnRootFailure(hr, "Failed to find required feed/entry/id element."); |
786 | } | 799 | } |
787 | else if (!pEntry->wzTitle || !*pEntry->wzTitle) | 800 | else if (!pEntry->wzTitle || !*pEntry->wzTitle) |
788 | { | 801 | { |
789 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 802 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); |
790 | ExitOnRootFailure(hr, "Failed to find required feed/entry/title element."); | 803 | AtomExitOnRootFailure(hr, "Failed to find required feed/entry/title element."); |
791 | } | 804 | } |
792 | else if (0 == pEntry->ftUpdated.dwHighDateTime && 0 == pEntry->ftUpdated.dwLowDateTime) | 805 | else if (0 == pEntry->ftUpdated.dwHighDateTime && 0 == pEntry->ftUpdated.dwLowDateTime) |
793 | { | 806 | { |
794 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 807 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); |
795 | ExitOnRootFailure(hr, "Failed to find required feed/entry/updated element."); | 808 | AtomExitOnRootFailure(hr, "Failed to find required feed/entry/updated element."); |
796 | } | 809 | } |
797 | 810 | ||
798 | hr = S_OK; | 811 | hr = S_OK; |
@@ -825,19 +838,19 @@ static HRESULT ParseAtomLink( | |||
825 | 838 | ||
826 | // Process attributes first. | 839 | // Process attributes first. |
827 | hr = pixnLink->get_attributes(&pixnnmAttributes); | 840 | hr = pixnLink->get_attributes(&pixnnmAttributes); |
828 | ExitOnFailure(hr, "Failed get attributes for ATOM link."); | 841 | AtomExitOnFailure(hr, "Failed get attributes for ATOM link."); |
829 | 842 | ||
830 | while (S_OK == (hr = XmlNextAttribute(pixnnmAttributes, &pNode, &bstrNodeName))) | 843 | while (S_OK == (hr = XmlNextAttribute(pixnnmAttributes, &pNode, &bstrNodeName))) |
831 | { | 844 | { |
832 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"rel", -1)) | 845 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"rel", -1)) |
833 | { | 846 | { |
834 | hr = AssignString(&pLink->wzRel, pNode); | 847 | hr = AssignString(&pLink->wzRel, pNode); |
835 | ExitOnFailure(hr, "Failed to allocate ATOM link rel."); | 848 | AtomExitOnFailure(hr, "Failed to allocate ATOM link rel."); |
836 | } | 849 | } |
837 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"href", -1)) | 850 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"href", -1)) |
838 | { | 851 | { |
839 | hr = AssignString(&pLink->wzUrl, pNode); | 852 | hr = AssignString(&pLink->wzUrl, pNode); |
840 | ExitOnFailure(hr, "Failed to allocate ATOM link href."); | 853 | AtomExitOnFailure(hr, "Failed to allocate ATOM link href."); |
841 | } | 854 | } |
842 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"length", -1)) | 855 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"length", -1)) |
843 | { | 856 | { |
@@ -846,45 +859,45 @@ static HRESULT ParseAtomLink( | |||
846 | { | 859 | { |
847 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 860 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); |
848 | } | 861 | } |
849 | ExitOnFailure(hr, "Failed to parse ATOM link length."); | 862 | AtomExitOnFailure(hr, "Failed to parse ATOM link length."); |
850 | } | 863 | } |
851 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"title", -1)) | 864 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"title", -1)) |
852 | { | 865 | { |
853 | hr = AssignString(&pLink->wzTitle, pNode); | 866 | hr = AssignString(&pLink->wzTitle, pNode); |
854 | ExitOnFailure(hr, "Failed to allocate ATOM link title."); | 867 | AtomExitOnFailure(hr, "Failed to allocate ATOM link title."); |
855 | } | 868 | } |
856 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"type", -1)) | 869 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"type", -1)) |
857 | { | 870 | { |
858 | hr = AssignString(&pLink->wzType, pNode); | 871 | hr = AssignString(&pLink->wzType, pNode); |
859 | ExitOnFailure(hr, "Failed to allocate ATOM link type."); | 872 | AtomExitOnFailure(hr, "Failed to allocate ATOM link type."); |
860 | } | 873 | } |
861 | else | 874 | else |
862 | { | 875 | { |
863 | hr = ParseAtomUnknownAttribute(pNode, &pLink->pUnknownAttributes); | 876 | hr = ParseAtomUnknownAttribute(pNode, &pLink->pUnknownAttributes); |
864 | ExitOnFailure(hr, "Failed to parse unknown ATOM link attribute: %ls", bstrNodeName); | 877 | AtomExitOnFailure(hr, "Failed to parse unknown ATOM link attribute: %ls", bstrNodeName); |
865 | } | 878 | } |
866 | 879 | ||
867 | ReleaseNullBSTR(bstrNodeName); | 880 | ReleaseNullBSTR(bstrNodeName); |
868 | ReleaseNullObject(pNode); | 881 | ReleaseNullObject(pNode); |
869 | } | 882 | } |
870 | ExitOnFailure(hr, "Failed to process all ATOM link attributes."); | 883 | AtomExitOnFailure(hr, "Failed to process all ATOM link attributes."); |
871 | 884 | ||
872 | // Process elements second. | 885 | // Process elements second. |
873 | hr = pixnLink->get_childNodes(&pNodeList); | 886 | hr = pixnLink->get_childNodes(&pNodeList); |
874 | ExitOnFailure(hr, "Failed to get child nodes of ATOM link element."); | 887 | AtomExitOnFailure(hr, "Failed to get child nodes of ATOM link element."); |
875 | 888 | ||
876 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) | 889 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) |
877 | { | 890 | { |
878 | hr = ParseAtomUnknownElement(pNode, &pLink->pUnknownElements); | 891 | hr = ParseAtomUnknownElement(pNode, &pLink->pUnknownElements); |
879 | ExitOnFailure(hr, "Failed to parse unknown ATOM link element: %ls", bstrNodeName); | 892 | AtomExitOnFailure(hr, "Failed to parse unknown ATOM link element: %ls", bstrNodeName); |
880 | 893 | ||
881 | ReleaseNullBSTR(bstrNodeName); | 894 | ReleaseNullBSTR(bstrNodeName); |
882 | ReleaseNullObject(pNode); | 895 | ReleaseNullObject(pNode); |
883 | } | 896 | } |
884 | ExitOnFailure(hr, "Failed to process all ATOM link elements."); | 897 | AtomExitOnFailure(hr, "Failed to process all ATOM link elements."); |
885 | 898 | ||
886 | hr = AssignString(&pLink->wzValue, pixnLink); | 899 | hr = AssignString(&pLink->wzValue, pixnLink); |
887 | ExitOnFailure(hr, "Failed to allocate ATOM link value."); | 900 | AtomExitOnFailure(hr, "Failed to allocate ATOM link value."); |
888 | 901 | ||
889 | LExit: | 902 | LExit: |
890 | ReleaseBSTR(bstrNodeName); | 903 | ReleaseBSTR(bstrNodeName); |
@@ -916,39 +929,39 @@ static HRESULT ParseAtomUnknownElement( | |||
916 | ATOM_UNKNOWN_ELEMENT* pNewUnknownElement; | 929 | ATOM_UNKNOWN_ELEMENT* pNewUnknownElement; |
917 | 930 | ||
918 | pNewUnknownElement = (ATOM_UNKNOWN_ELEMENT*)MemAlloc(sizeof(ATOM_UNKNOWN_ELEMENT), TRUE); | 931 | pNewUnknownElement = (ATOM_UNKNOWN_ELEMENT*)MemAlloc(sizeof(ATOM_UNKNOWN_ELEMENT), TRUE); |
919 | ExitOnNull(pNewUnknownElement, hr, E_OUTOFMEMORY, "Failed to allocate unknown element."); | 932 | AtomExitOnNull(pNewUnknownElement, hr, E_OUTOFMEMORY, "Failed to allocate unknown element."); |
920 | 933 | ||
921 | hr = pNode->get_namespaceURI(&bstrNodeNamespace); | 934 | hr = pNode->get_namespaceURI(&bstrNodeNamespace); |
922 | if (S_OK == hr) | 935 | if (S_OK == hr) |
923 | { | 936 | { |
924 | hr = StrAllocString(&pNewUnknownElement->wzNamespace, bstrNodeNamespace, 0); | 937 | hr = StrAllocString(&pNewUnknownElement->wzNamespace, bstrNodeNamespace, 0); |
925 | ExitOnFailure(hr, "Failed to allocate ATOM unknown element namespace."); | 938 | AtomExitOnFailure(hr, "Failed to allocate ATOM unknown element namespace."); |
926 | } | 939 | } |
927 | else if (S_FALSE == hr) | 940 | else if (S_FALSE == hr) |
928 | { | 941 | { |
929 | hr = S_OK; | 942 | hr = S_OK; |
930 | } | 943 | } |
931 | ExitOnFailure(hr, "Failed to get unknown element namespace."); | 944 | AtomExitOnFailure(hr, "Failed to get unknown element namespace."); |
932 | 945 | ||
933 | hr = pNode->get_baseName(&bstrNodeName); | 946 | hr = pNode->get_baseName(&bstrNodeName); |
934 | ExitOnFailure(hr, "Failed to get unknown element name."); | 947 | AtomExitOnFailure(hr, "Failed to get unknown element name."); |
935 | 948 | ||
936 | hr = StrAllocString(&pNewUnknownElement->wzElement, bstrNodeName, 0); | 949 | hr = StrAllocString(&pNewUnknownElement->wzElement, bstrNodeName, 0); |
937 | ExitOnFailure(hr, "Failed to allocate ATOM unknown element name."); | 950 | AtomExitOnFailure(hr, "Failed to allocate ATOM unknown element name."); |
938 | 951 | ||
939 | hr = XmlGetText(pNode, &bstrNodeValue); | 952 | hr = XmlGetText(pNode, &bstrNodeValue); |
940 | ExitOnFailure(hr, "Failed to get unknown element value."); | 953 | AtomExitOnFailure(hr, "Failed to get unknown element value."); |
941 | 954 | ||
942 | hr = StrAllocString(&pNewUnknownElement->wzValue, bstrNodeValue, 0); | 955 | hr = StrAllocString(&pNewUnknownElement->wzValue, bstrNodeValue, 0); |
943 | ExitOnFailure(hr, "Failed to allocate ATOM unknown element value."); | 956 | AtomExitOnFailure(hr, "Failed to allocate ATOM unknown element value."); |
944 | 957 | ||
945 | hr = pNode->get_attributes(&pixnnmAttributes); | 958 | hr = pNode->get_attributes(&pixnnmAttributes); |
946 | ExitOnFailure(hr, "Failed get attributes on ATOM unknown element."); | 959 | AtomExitOnFailure(hr, "Failed get attributes on ATOM unknown element."); |
947 | 960 | ||
948 | while (S_OK == (hr = pixnnmAttributes->nextNode(&pixnAttribute))) | 961 | while (S_OK == (hr = pixnnmAttributes->nextNode(&pixnAttribute))) |
949 | { | 962 | { |
950 | hr = ParseAtomUnknownAttribute(pixnAttribute, &pNewUnknownElement->pAttributes); | 963 | hr = ParseAtomUnknownAttribute(pixnAttribute, &pNewUnknownElement->pAttributes); |
951 | ExitOnFailure(hr, "Failed to parse attribute on ATOM unknown element."); | 964 | AtomExitOnFailure(hr, "Failed to parse attribute on ATOM unknown element."); |
952 | 965 | ||
953 | ReleaseNullObject(pixnAttribute); | 966 | ReleaseNullObject(pixnAttribute); |
954 | } | 967 | } |
@@ -957,7 +970,7 @@ static HRESULT ParseAtomUnknownElement( | |||
957 | { | 970 | { |
958 | hr = S_OK; | 971 | hr = S_OK; |
959 | } | 972 | } |
960 | ExitOnFailure(hr, "Failed to enumerate all attributes on ATOM unknown element."); | 973 | AtomExitOnFailure(hr, "Failed to enumerate all attributes on ATOM unknown element."); |
961 | 974 | ||
962 | ATOM_UNKNOWN_ELEMENT** ppTail = ppUnknownElement; | 975 | ATOM_UNKNOWN_ELEMENT** ppTail = ppUnknownElement; |
963 | while (*ppTail) | 976 | while (*ppTail) |
@@ -999,31 +1012,31 @@ static HRESULT ParseAtomUnknownAttribute( | |||
999 | ATOM_UNKNOWN_ATTRIBUTE* pNewUnknownAttribute; | 1012 | ATOM_UNKNOWN_ATTRIBUTE* pNewUnknownAttribute; |
1000 | 1013 | ||
1001 | pNewUnknownAttribute = (ATOM_UNKNOWN_ATTRIBUTE*)MemAlloc(sizeof(ATOM_UNKNOWN_ATTRIBUTE), TRUE); | 1014 | pNewUnknownAttribute = (ATOM_UNKNOWN_ATTRIBUTE*)MemAlloc(sizeof(ATOM_UNKNOWN_ATTRIBUTE), TRUE); |
1002 | ExitOnNull(pNewUnknownAttribute, hr, E_OUTOFMEMORY, "Failed to allocate unknown attribute."); | 1015 | AtomExitOnNull(pNewUnknownAttribute, hr, E_OUTOFMEMORY, "Failed to allocate unknown attribute."); |
1003 | 1016 | ||
1004 | hr = pNode->get_namespaceURI(&bstrNodeNamespace); | 1017 | hr = pNode->get_namespaceURI(&bstrNodeNamespace); |
1005 | if (S_OK == hr) | 1018 | if (S_OK == hr) |
1006 | { | 1019 | { |
1007 | hr = StrAllocString(&pNewUnknownAttribute->wzNamespace, bstrNodeNamespace, 0); | 1020 | hr = StrAllocString(&pNewUnknownAttribute->wzNamespace, bstrNodeNamespace, 0); |
1008 | ExitOnFailure(hr, "Failed to allocate ATOM unknown attribute namespace."); | 1021 | AtomExitOnFailure(hr, "Failed to allocate ATOM unknown attribute namespace."); |
1009 | } | 1022 | } |
1010 | else if (S_FALSE == hr) | 1023 | else if (S_FALSE == hr) |
1011 | { | 1024 | { |
1012 | hr = S_OK; | 1025 | hr = S_OK; |
1013 | } | 1026 | } |
1014 | ExitOnFailure(hr, "Failed to get unknown attribute namespace."); | 1027 | AtomExitOnFailure(hr, "Failed to get unknown attribute namespace."); |
1015 | 1028 | ||
1016 | hr = pNode->get_baseName(&bstrNodeName); | 1029 | hr = pNode->get_baseName(&bstrNodeName); |
1017 | ExitOnFailure(hr, "Failed to get unknown attribute name."); | 1030 | AtomExitOnFailure(hr, "Failed to get unknown attribute name."); |
1018 | 1031 | ||
1019 | hr = StrAllocString(&pNewUnknownAttribute->wzAttribute, bstrNodeName, 0); | 1032 | hr = StrAllocString(&pNewUnknownAttribute->wzAttribute, bstrNodeName, 0); |
1020 | ExitOnFailure(hr, "Failed to allocate ATOM unknown attribute name."); | 1033 | AtomExitOnFailure(hr, "Failed to allocate ATOM unknown attribute name."); |
1021 | 1034 | ||
1022 | hr = XmlGetText(pNode, &bstrNodeValue); | 1035 | hr = XmlGetText(pNode, &bstrNodeValue); |
1023 | ExitOnFailure(hr, "Failed to get unknown attribute value."); | 1036 | AtomExitOnFailure(hr, "Failed to get unknown attribute value."); |
1024 | 1037 | ||
1025 | hr = StrAllocString(&pNewUnknownAttribute->wzValue, bstrNodeValue, 0); | 1038 | hr = StrAllocString(&pNewUnknownAttribute->wzValue, bstrNodeValue, 0); |
1026 | ExitOnFailure(hr, "Failed to allocate ATOM unknown attribute value."); | 1039 | AtomExitOnFailure(hr, "Failed to allocate ATOM unknown attribute value."); |
1027 | 1040 | ||
1028 | ATOM_UNKNOWN_ATTRIBUTE** ppTail = ppUnknownAttribute; | 1041 | ATOM_UNKNOWN_ATTRIBUTE** ppTail = ppUnknownAttribute; |
1029 | while (*ppTail) | 1042 | while (*ppTail) |
@@ -1060,16 +1073,16 @@ static HRESULT AssignDateTime( | |||
1060 | if (0 != pft->dwHighDateTime || 0 != pft->dwLowDateTime) | 1073 | if (0 != pft->dwHighDateTime || 0 != pft->dwLowDateTime) |
1061 | { | 1074 | { |
1062 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 1075 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); |
1063 | ExitOnRootFailure(hr, "Already process this datetime value."); | 1076 | AtomExitOnRootFailure(hr, "Already process this datetime value."); |
1064 | } | 1077 | } |
1065 | 1078 | ||
1066 | hr = XmlGetText(pNode, &bstrValue); | 1079 | hr = XmlGetText(pNode, &bstrValue); |
1067 | ExitOnFailure(hr, "Failed to get value."); | 1080 | AtomExitOnFailure(hr, "Failed to get value."); |
1068 | 1081 | ||
1069 | if (S_OK == hr) | 1082 | if (S_OK == hr) |
1070 | { | 1083 | { |
1071 | hr = TimeFromString3339(bstrValue, pft); | 1084 | hr = TimeFromString3339(bstrValue, pft); |
1072 | ExitOnFailure(hr, "Failed to convert value to time."); | 1085 | AtomExitOnFailure(hr, "Failed to convert value to time."); |
1073 | } | 1086 | } |
1074 | else | 1087 | else |
1075 | { | 1088 | { |
@@ -1099,16 +1112,16 @@ static HRESULT AssignString( | |||
1099 | if (pwzValue && *pwzValue) | 1112 | if (pwzValue && *pwzValue) |
1100 | { | 1113 | { |
1101 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 1114 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); |
1102 | ExitOnRootFailure(hr, "Already processed this value."); | 1115 | AtomExitOnRootFailure(hr, "Already processed this value."); |
1103 | } | 1116 | } |
1104 | 1117 | ||
1105 | hr = XmlGetText(pNode, &bstrValue); | 1118 | hr = XmlGetText(pNode, &bstrValue); |
1106 | ExitOnFailure(hr, "Failed to get value."); | 1119 | AtomExitOnFailure(hr, "Failed to get value."); |
1107 | 1120 | ||
1108 | if (S_OK == hr) | 1121 | if (S_OK == hr) |
1109 | { | 1122 | { |
1110 | hr = StrAllocString(pwzValue, bstrValue, 0); | 1123 | hr = StrAllocString(pwzValue, bstrValue, 0); |
1111 | ExitOnFailure(hr, "Failed to allocate value."); | 1124 | AtomExitOnFailure(hr, "Failed to allocate value."); |
1112 | } | 1125 | } |
1113 | else | 1126 | else |
1114 | { | 1127 | { |
diff --git a/src/dutil/buffutil.cpp b/src/dutil/buffutil.cpp index a70aaa81..a6d3ac90 100644 --- a/src/dutil/buffutil.cpp +++ b/src/dutil/buffutil.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | 5 | ||
6 | // Exit macros | ||
7 | #define BuffExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_BUFFUTIL, x, s, __VA_ARGS__) | ||
8 | #define BuffExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_BUFFUTIL, x, s, __VA_ARGS__) | ||
9 | #define BuffExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_BUFFUTIL, x, s, __VA_ARGS__) | ||
10 | #define BuffExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_BUFFUTIL, x, s, __VA_ARGS__) | ||
11 | #define BuffExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_BUFFUTIL, x, s, __VA_ARGS__) | ||
12 | #define BuffExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_BUFFUTIL, x, s, __VA_ARGS__) | ||
13 | #define BuffExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_BUFFUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define BuffExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_BUFFUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define BuffExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_BUFFUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define BuffExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_BUFFUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define BuffExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_BUFFUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define BuffExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_BUFFUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
6 | // constants | 21 | // constants |
7 | 22 | ||
8 | #define BUFFER_INCREMENT 128 | 23 | #define BUFFER_INCREMENT 128 |
@@ -11,7 +26,7 @@ | |||
11 | // helper function declarations | 26 | // helper function declarations |
12 | 27 | ||
13 | static HRESULT EnsureBufferSize( | 28 | static HRESULT EnsureBufferSize( |
14 | __deref_out_bcount(cbSize) BYTE** ppbBuffer, | 29 | __deref_inout_bcount(cbSize) BYTE** ppbBuffer, |
15 | __in SIZE_T cbSize | 30 | __in SIZE_T cbSize |
16 | ); | 31 | ); |
17 | 32 | ||
@@ -34,13 +49,13 @@ extern "C" HRESULT BuffReadNumber( | |||
34 | 49 | ||
35 | // get availiable data size | 50 | // get availiable data size |
36 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); | 51 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); |
37 | ExitOnRootFailure(hr, "Failed to calculate available data size."); | 52 | BuffExitOnRootFailure(hr, "Failed to calculate available data size."); |
38 | 53 | ||
39 | // verify buffer size | 54 | // verify buffer size |
40 | if (sizeof(DWORD) > cbAvailable) | 55 | if (sizeof(DWORD) > cbAvailable) |
41 | { | 56 | { |
42 | hr = E_INVALIDARG; | 57 | hr = E_INVALIDARG; |
43 | ExitOnRootFailure(hr, "Buffer too small."); | 58 | BuffExitOnRootFailure(hr, "Buffer too small."); |
44 | } | 59 | } |
45 | 60 | ||
46 | *pdw = *(const DWORD*)(pbBuffer + *piBuffer); | 61 | *pdw = *(const DWORD*)(pbBuffer + *piBuffer); |
@@ -66,13 +81,13 @@ extern "C" HRESULT BuffReadNumber64( | |||
66 | 81 | ||
67 | // get availiable data size | 82 | // get availiable data size |
68 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); | 83 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); |
69 | ExitOnRootFailure(hr, "Failed to calculate available data size."); | 84 | BuffExitOnRootFailure(hr, "Failed to calculate available data size."); |
70 | 85 | ||
71 | // verify buffer size | 86 | // verify buffer size |
72 | if (sizeof(DWORD64) > cbAvailable) | 87 | if (sizeof(DWORD64) > cbAvailable) |
73 | { | 88 | { |
74 | hr = E_INVALIDARG; | 89 | hr = E_INVALIDARG; |
75 | ExitOnRootFailure(hr, "Buffer too small."); | 90 | BuffExitOnRootFailure(hr, "Buffer too small."); |
76 | } | 91 | } |
77 | 92 | ||
78 | *pdw64 = *(const DWORD64*)(pbBuffer + *piBuffer); | 93 | *pdw64 = *(const DWORD64*)(pbBuffer + *piBuffer); |
@@ -98,13 +113,13 @@ extern "C" HRESULT BuffReadPointer( | |||
98 | 113 | ||
99 | // get availiable data size | 114 | // get availiable data size |
100 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); | 115 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); |
101 | ExitOnRootFailure(hr, "Failed to calculate available data size."); | 116 | BuffExitOnRootFailure(hr, "Failed to calculate available data size."); |
102 | 117 | ||
103 | // verify buffer size | 118 | // verify buffer size |
104 | if (sizeof(DWORD_PTR) > cbAvailable) | 119 | if (sizeof(DWORD_PTR) > cbAvailable) |
105 | { | 120 | { |
106 | hr = E_INVALIDARG; | 121 | hr = E_INVALIDARG; |
107 | ExitOnRootFailure(hr, "Buffer too small."); | 122 | BuffExitOnRootFailure(hr, "Buffer too small."); |
108 | } | 123 | } |
109 | 124 | ||
110 | *pdw64 = *(const DWORD_PTR*)(pbBuffer + *piBuffer); | 125 | *pdw64 = *(const DWORD_PTR*)(pbBuffer + *piBuffer); |
@@ -132,38 +147,38 @@ extern "C" HRESULT BuffReadString( | |||
132 | 147 | ||
133 | // get availiable data size | 148 | // get availiable data size |
134 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); | 149 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); |
135 | ExitOnRootFailure(hr, "Failed to calculate available data size for character count."); | 150 | BuffExitOnRootFailure(hr, "Failed to calculate available data size for character count."); |
136 | 151 | ||
137 | // verify buffer size | 152 | // verify buffer size |
138 | if (sizeof(DWORD) > cbAvailable) | 153 | if (sizeof(DWORD) > cbAvailable) |
139 | { | 154 | { |
140 | hr = E_INVALIDARG; | 155 | hr = E_INVALIDARG; |
141 | ExitOnRootFailure(hr, "Buffer too small."); | 156 | BuffExitOnRootFailure(hr, "Buffer too small."); |
142 | } | 157 | } |
143 | 158 | ||
144 | // read character count | 159 | // read character count |
145 | cch = *(const DWORD*)(pbBuffer + *piBuffer); | 160 | cch = *(const DWORD*)(pbBuffer + *piBuffer); |
146 | 161 | ||
147 | hr = ::DWordMult(cch, static_cast<DWORD>(sizeof(WCHAR)), &cb); | 162 | hr = ::DWordMult(cch, static_cast<DWORD>(sizeof(WCHAR)), &cb); |
148 | ExitOnRootFailure(hr, "Overflow while multiplying to calculate buffer size"); | 163 | BuffExitOnRootFailure(hr, "Overflow while multiplying to calculate buffer size"); |
149 | 164 | ||
150 | hr = ::SIZETAdd(*piBuffer, sizeof(DWORD), piBuffer); | 165 | hr = ::SIZETAdd(*piBuffer, sizeof(DWORD), piBuffer); |
151 | ExitOnRootFailure(hr, "Overflow while adding to calculate buffer size"); | 166 | BuffExitOnRootFailure(hr, "Overflow while adding to calculate buffer size"); |
152 | 167 | ||
153 | // get availiable data size | 168 | // get availiable data size |
154 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); | 169 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); |
155 | ExitOnRootFailure(hr, "Failed to calculate available data size for character buffer."); | 170 | BuffExitOnRootFailure(hr, "Failed to calculate available data size for character buffer."); |
156 | 171 | ||
157 | // verify buffer size | 172 | // verify buffer size |
158 | if (cb > cbAvailable) | 173 | if (cb > cbAvailable) |
159 | { | 174 | { |
160 | hr = E_INVALIDARG; | 175 | hr = E_INVALIDARG; |
161 | ExitOnRootFailure(hr, "Buffer too small to hold character data."); | 176 | BuffExitOnRootFailure(hr, "Buffer too small to hold character data."); |
162 | } | 177 | } |
163 | 178 | ||
164 | // copy character data | 179 | // copy character data |
165 | hr = StrAllocString(pscz, cch ? (LPCWSTR)(pbBuffer + *piBuffer) : L"", cch); | 180 | hr = StrAllocString(pscz, cch ? (LPCWSTR)(pbBuffer + *piBuffer) : L"", cch); |
166 | ExitOnFailure(hr, "Failed to copy character data."); | 181 | BuffExitOnFailure(hr, "Failed to copy character data."); |
167 | 182 | ||
168 | *piBuffer += cb; | 183 | *piBuffer += cb; |
169 | 184 | ||
@@ -189,38 +204,38 @@ extern "C" HRESULT BuffReadStringAnsi( | |||
189 | 204 | ||
190 | // get availiable data size | 205 | // get availiable data size |
191 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); | 206 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); |
192 | ExitOnRootFailure(hr, "Failed to calculate available data size for character count."); | 207 | BuffExitOnRootFailure(hr, "Failed to calculate available data size for character count."); |
193 | 208 | ||
194 | // verify buffer size | 209 | // verify buffer size |
195 | if (sizeof(DWORD) > cbAvailable) | 210 | if (sizeof(DWORD) > cbAvailable) |
196 | { | 211 | { |
197 | hr = E_INVALIDARG; | 212 | hr = E_INVALIDARG; |
198 | ExitOnRootFailure(hr, "Buffer too small."); | 213 | BuffExitOnRootFailure(hr, "Buffer too small."); |
199 | } | 214 | } |
200 | 215 | ||
201 | // read character count | 216 | // read character count |
202 | cch = *(const DWORD*)(pbBuffer + *piBuffer); | 217 | cch = *(const DWORD*)(pbBuffer + *piBuffer); |
203 | 218 | ||
204 | hr = ::DWordMult(cch, static_cast<DWORD>(sizeof(CHAR)), &cb); | 219 | hr = ::DWordMult(cch, static_cast<DWORD>(sizeof(CHAR)), &cb); |
205 | ExitOnRootFailure(hr, "Overflow while multiplying to calculate buffer size"); | 220 | BuffExitOnRootFailure(hr, "Overflow while multiplying to calculate buffer size"); |
206 | 221 | ||
207 | hr = ::SIZETAdd(*piBuffer, sizeof(DWORD), piBuffer); | 222 | hr = ::SIZETAdd(*piBuffer, sizeof(DWORD), piBuffer); |
208 | ExitOnRootFailure(hr, "Overflow while adding to calculate buffer size"); | 223 | BuffExitOnRootFailure(hr, "Overflow while adding to calculate buffer size"); |
209 | 224 | ||
210 | // get availiable data size | 225 | // get availiable data size |
211 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); | 226 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); |
212 | ExitOnRootFailure(hr, "Failed to calculate available data size for character buffer."); | 227 | BuffExitOnRootFailure(hr, "Failed to calculate available data size for character buffer."); |
213 | 228 | ||
214 | // verify buffer size | 229 | // verify buffer size |
215 | if (cb > cbAvailable) | 230 | if (cb > cbAvailable) |
216 | { | 231 | { |
217 | hr = E_INVALIDARG; | 232 | hr = E_INVALIDARG; |
218 | ExitOnRootFailure(hr, "Buffer too small to hold character count."); | 233 | BuffExitOnRootFailure(hr, "Buffer too small to hold character count."); |
219 | } | 234 | } |
220 | 235 | ||
221 | // copy character data | 236 | // copy character data |
222 | hr = StrAnsiAllocStringAnsi(pscz, cch ? (LPCSTR)(pbBuffer + *piBuffer) : "", cch); | 237 | hr = StrAnsiAllocStringAnsi(pscz, cch ? (LPCSTR)(pbBuffer + *piBuffer) : "", cch); |
223 | ExitOnFailure(hr, "Failed to copy character data."); | 238 | BuffExitOnFailure(hr, "Failed to copy character data."); |
224 | 239 | ||
225 | *piBuffer += cb; | 240 | *piBuffer += cb; |
226 | 241 | ||
@@ -232,7 +247,7 @@ extern "C" HRESULT BuffReadStream( | |||
232 | __in_bcount(cbBuffer) const BYTE* pbBuffer, | 247 | __in_bcount(cbBuffer) const BYTE* pbBuffer, |
233 | __in SIZE_T cbBuffer, | 248 | __in SIZE_T cbBuffer, |
234 | __inout SIZE_T* piBuffer, | 249 | __inout SIZE_T* piBuffer, |
235 | __deref_out_bcount(*pcbStream) BYTE** ppbStream, | 250 | __deref_inout_bcount(*pcbStream) BYTE** ppbStream, |
236 | __out SIZE_T* pcbStream | 251 | __out SIZE_T* pcbStream |
237 | ) | 252 | ) |
238 | { | 253 | { |
@@ -247,13 +262,13 @@ extern "C" HRESULT BuffReadStream( | |||
247 | 262 | ||
248 | // get availiable data size | 263 | // get availiable data size |
249 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); | 264 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); |
250 | ExitOnRootFailure(hr, "Failed to calculate available data size for stream size."); | 265 | BuffExitOnRootFailure(hr, "Failed to calculate available data size for stream size."); |
251 | 266 | ||
252 | // verify buffer size | 267 | // verify buffer size |
253 | if (sizeof(DWORD64) > cbAvailable) | 268 | if (sizeof(DWORD64) > cbAvailable) |
254 | { | 269 | { |
255 | hr = E_INVALIDARG; | 270 | hr = E_INVALIDARG; |
256 | ExitOnRootFailure(hr, "Buffer too small."); | 271 | BuffExitOnRootFailure(hr, "Buffer too small."); |
257 | } | 272 | } |
258 | 273 | ||
259 | // read stream size | 274 | // read stream size |
@@ -262,18 +277,18 @@ extern "C" HRESULT BuffReadStream( | |||
262 | 277 | ||
263 | // get availiable data size | 278 | // get availiable data size |
264 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); | 279 | hr = ::SIZETSub(cbBuffer, *piBuffer, &cbAvailable); |
265 | ExitOnRootFailure(hr, "Failed to calculate available data size for stream buffer."); | 280 | BuffExitOnRootFailure(hr, "Failed to calculate available data size for stream buffer."); |
266 | 281 | ||
267 | // verify buffer size | 282 | // verify buffer size |
268 | if (cb > cbAvailable) | 283 | if (cb > cbAvailable) |
269 | { | 284 | { |
270 | hr = E_INVALIDARG; | 285 | hr = E_INVALIDARG; |
271 | ExitOnRootFailure(hr, "Buffer too small to hold byte count."); | 286 | BuffExitOnRootFailure(hr, "Buffer too small to hold byte count."); |
272 | } | 287 | } |
273 | 288 | ||
274 | // allocate buffer | 289 | // allocate buffer |
275 | *ppbStream = (BYTE*)MemAlloc((SIZE_T)cb, TRUE); | 290 | *ppbStream = (BYTE*)MemAlloc((SIZE_T)cb, TRUE); |
276 | ExitOnNull(*ppbStream, hr, E_OUTOFMEMORY, "Failed to allocate stream."); | 291 | BuffExitOnNull(*ppbStream, hr, E_OUTOFMEMORY, "Failed to allocate stream."); |
277 | 292 | ||
278 | // read stream data | 293 | // read stream data |
279 | memcpy_s(*ppbStream, cbBuffer - *piBuffer, pbBuffer + *piBuffer, (SIZE_T)cb); | 294 | memcpy_s(*ppbStream, cbBuffer - *piBuffer, pbBuffer + *piBuffer, (SIZE_T)cb); |
@@ -287,7 +302,7 @@ LExit: | |||
287 | } | 302 | } |
288 | 303 | ||
289 | extern "C" HRESULT BuffWriteNumber( | 304 | extern "C" HRESULT BuffWriteNumber( |
290 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 305 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
291 | __inout SIZE_T* piBuffer, | 306 | __inout SIZE_T* piBuffer, |
292 | __in DWORD_PTR dw | 307 | __in DWORD_PTR dw |
293 | ) | 308 | ) |
@@ -299,7 +314,7 @@ extern "C" HRESULT BuffWriteNumber( | |||
299 | 314 | ||
300 | // make sure we have a buffer with sufficient space | 315 | // make sure we have a buffer with sufficient space |
301 | hr = EnsureBufferSize(ppbBuffer, *piBuffer + sizeof(DWORD)); | 316 | hr = EnsureBufferSize(ppbBuffer, *piBuffer + sizeof(DWORD)); |
302 | ExitOnFailure(hr, "Failed to ensure buffer size."); | 317 | BuffExitOnFailure(hr, "Failed to ensure buffer size."); |
303 | 318 | ||
304 | // copy data to buffer | 319 | // copy data to buffer |
305 | *(DWORD_PTR*)(*ppbBuffer + *piBuffer) = dw; | 320 | *(DWORD_PTR*)(*ppbBuffer + *piBuffer) = dw; |
@@ -310,7 +325,7 @@ LExit: | |||
310 | } | 325 | } |
311 | 326 | ||
312 | extern "C" HRESULT BuffWriteNumber64( | 327 | extern "C" HRESULT BuffWriteNumber64( |
313 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 328 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
314 | __inout SIZE_T* piBuffer, | 329 | __inout SIZE_T* piBuffer, |
315 | __in DWORD64 dw64 | 330 | __in DWORD64 dw64 |
316 | ) | 331 | ) |
@@ -322,7 +337,7 @@ extern "C" HRESULT BuffWriteNumber64( | |||
322 | 337 | ||
323 | // make sure we have a buffer with sufficient space | 338 | // make sure we have a buffer with sufficient space |
324 | hr = EnsureBufferSize(ppbBuffer, *piBuffer + sizeof(DWORD64)); | 339 | hr = EnsureBufferSize(ppbBuffer, *piBuffer + sizeof(DWORD64)); |
325 | ExitOnFailure(hr, "Failed to ensure buffer size."); | 340 | BuffExitOnFailure(hr, "Failed to ensure buffer size."); |
326 | 341 | ||
327 | // copy data to buffer | 342 | // copy data to buffer |
328 | *(DWORD64*)(*ppbBuffer + *piBuffer) = dw64; | 343 | *(DWORD64*)(*ppbBuffer + *piBuffer) = dw64; |
@@ -333,7 +348,7 @@ LExit: | |||
333 | } | 348 | } |
334 | 349 | ||
335 | extern "C" HRESULT BuffWritePointer( | 350 | extern "C" HRESULT BuffWritePointer( |
336 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 351 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
337 | __inout SIZE_T* piBuffer, | 352 | __inout SIZE_T* piBuffer, |
338 | __in DWORD_PTR dw | 353 | __in DWORD_PTR dw |
339 | ) | 354 | ) |
@@ -345,7 +360,7 @@ extern "C" HRESULT BuffWritePointer( | |||
345 | 360 | ||
346 | // make sure we have a buffer with sufficient space | 361 | // make sure we have a buffer with sufficient space |
347 | hr = EnsureBufferSize(ppbBuffer, *piBuffer + sizeof(DWORD_PTR)); | 362 | hr = EnsureBufferSize(ppbBuffer, *piBuffer + sizeof(DWORD_PTR)); |
348 | ExitOnFailure(hr, "Failed to ensure buffer size."); | 363 | BuffExitOnFailure(hr, "Failed to ensure buffer size."); |
349 | 364 | ||
350 | // copy data to buffer | 365 | // copy data to buffer |
351 | *(DWORD_PTR*)(*ppbBuffer + *piBuffer) = dw; | 366 | *(DWORD_PTR*)(*ppbBuffer + *piBuffer) = dw; |
@@ -356,7 +371,7 @@ LExit: | |||
356 | } | 371 | } |
357 | 372 | ||
358 | extern "C" HRESULT BuffWriteString( | 373 | extern "C" HRESULT BuffWriteString( |
359 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 374 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
360 | __inout SIZE_T* piBuffer, | 375 | __inout SIZE_T* piBuffer, |
361 | __in_z_opt LPCWSTR scz | 376 | __in_z_opt LPCWSTR scz |
362 | ) | 377 | ) |
@@ -370,7 +385,7 @@ extern "C" HRESULT BuffWriteString( | |||
370 | 385 | ||
371 | // make sure we have a buffer with sufficient space | 386 | // make sure we have a buffer with sufficient space |
372 | hr = EnsureBufferSize(ppbBuffer, *piBuffer + (sizeof(DWORD) + cb)); | 387 | hr = EnsureBufferSize(ppbBuffer, *piBuffer + (sizeof(DWORD) + cb)); |
373 | ExitOnFailure(hr, "Failed to ensure buffer size."); | 388 | BuffExitOnFailure(hr, "Failed to ensure buffer size."); |
374 | 389 | ||
375 | // copy character count to buffer | 390 | // copy character count to buffer |
376 | *(DWORD*)(*ppbBuffer + *piBuffer) = cch; | 391 | *(DWORD*)(*ppbBuffer + *piBuffer) = cch; |
@@ -385,7 +400,7 @@ LExit: | |||
385 | } | 400 | } |
386 | 401 | ||
387 | extern "C" HRESULT BuffWriteStringAnsi( | 402 | extern "C" HRESULT BuffWriteStringAnsi( |
388 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 403 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
389 | __inout SIZE_T* piBuffer, | 404 | __inout SIZE_T* piBuffer, |
390 | __in_z_opt LPCSTR scz | 405 | __in_z_opt LPCSTR scz |
391 | ) | 406 | ) |
@@ -399,7 +414,7 @@ extern "C" HRESULT BuffWriteStringAnsi( | |||
399 | 414 | ||
400 | // make sure we have a buffer with sufficient space | 415 | // make sure we have a buffer with sufficient space |
401 | hr = EnsureBufferSize(ppbBuffer, *piBuffer + (sizeof(DWORD) + cb)); | 416 | hr = EnsureBufferSize(ppbBuffer, *piBuffer + (sizeof(DWORD) + cb)); |
402 | ExitOnFailure(hr, "Failed to ensure buffer size."); | 417 | BuffExitOnFailure(hr, "Failed to ensure buffer size."); |
403 | 418 | ||
404 | // copy character count to buffer | 419 | // copy character count to buffer |
405 | *(DWORD*)(*ppbBuffer + *piBuffer) = cch; | 420 | *(DWORD*)(*ppbBuffer + *piBuffer) = cch; |
@@ -414,7 +429,7 @@ LExit: | |||
414 | } | 429 | } |
415 | 430 | ||
416 | extern "C" HRESULT BuffWriteStream( | 431 | extern "C" HRESULT BuffWriteStream( |
417 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 432 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
418 | __inout SIZE_T* piBuffer, | 433 | __inout SIZE_T* piBuffer, |
419 | __in_bcount(cbStream) const BYTE* pbStream, | 434 | __in_bcount(cbStream) const BYTE* pbStream, |
420 | __in SIZE_T cbStream | 435 | __in SIZE_T cbStream |
@@ -429,7 +444,7 @@ extern "C" HRESULT BuffWriteStream( | |||
429 | 444 | ||
430 | // make sure we have a buffer with sufficient space | 445 | // make sure we have a buffer with sufficient space |
431 | hr = EnsureBufferSize(ppbBuffer, *piBuffer + cbStream + sizeof(DWORD64)); | 446 | hr = EnsureBufferSize(ppbBuffer, *piBuffer + cbStream + sizeof(DWORD64)); |
432 | ExitOnFailure(hr, "Failed to ensure buffer size."); | 447 | BuffExitOnFailure(hr, "Failed to ensure buffer size."); |
433 | 448 | ||
434 | // copy byte count to buffer | 449 | // copy byte count to buffer |
435 | *(DWORD64*)(*ppbBuffer + *piBuffer) = cb; | 450 | *(DWORD64*)(*ppbBuffer + *piBuffer) = cb; |
@@ -447,7 +462,7 @@ LExit: | |||
447 | // helper functions | 462 | // helper functions |
448 | 463 | ||
449 | static HRESULT EnsureBufferSize( | 464 | static HRESULT EnsureBufferSize( |
450 | __deref_out_bcount(cbSize) BYTE** ppbBuffer, | 465 | __deref_inout_bcount(cbSize) BYTE** ppbBuffer, |
451 | __in SIZE_T cbSize | 466 | __in SIZE_T cbSize |
452 | ) | 467 | ) |
453 | { | 468 | { |
@@ -459,14 +474,14 @@ static HRESULT EnsureBufferSize( | |||
459 | if (MemSize(*ppbBuffer) < cbTarget) | 474 | if (MemSize(*ppbBuffer) < cbTarget) |
460 | { | 475 | { |
461 | LPVOID pv = MemReAlloc(*ppbBuffer, cbTarget, TRUE); | 476 | LPVOID pv = MemReAlloc(*ppbBuffer, cbTarget, TRUE); |
462 | ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate buffer."); | 477 | BuffExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate buffer."); |
463 | *ppbBuffer = (BYTE*)pv; | 478 | *ppbBuffer = (BYTE*)pv; |
464 | } | 479 | } |
465 | } | 480 | } |
466 | else | 481 | else |
467 | { | 482 | { |
468 | *ppbBuffer = (BYTE*)MemAlloc(cbTarget, TRUE); | 483 | *ppbBuffer = (BYTE*)MemAlloc(cbTarget, TRUE); |
469 | ExitOnNull(*ppbBuffer, hr, E_OUTOFMEMORY, "Failed to allocate buffer."); | 484 | BuffExitOnNull(*ppbBuffer, hr, E_OUTOFMEMORY, "Failed to allocate buffer."); |
470 | } | 485 | } |
471 | 486 | ||
472 | LExit: | 487 | LExit: |
diff --git a/src/dutil/cabcutil.cpp b/src/dutil/cabcutil.cpp index 8619822d..93a9b7e1 100644 --- a/src/dutil/cabcutil.cpp +++ b/src/dutil/cabcutil.cpp | |||
@@ -2,6 +2,22 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define CabcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_CABCUTIL, x, s, __VA_ARGS__) | ||
8 | #define CabcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_CABCUTIL, x, s, __VA_ARGS__) | ||
9 | #define CabcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_CABCUTIL, x, s, __VA_ARGS__) | ||
10 | #define CabcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_CABCUTIL, x, s, __VA_ARGS__) | ||
11 | #define CabcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_CABCUTIL, x, s, __VA_ARGS__) | ||
12 | #define CabcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_CABCUTIL, x, s, __VA_ARGS__) | ||
13 | #define CabcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_CABCUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define CabcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_CABCUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define CabcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_CABCUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define CabcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_CABCUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define CabcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_CABCUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define CabcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_CABCUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
5 | static const WCHAR CABC_MAGIC_UNICODE_STRING_MARKER = '?'; | 21 | static const WCHAR CABC_MAGIC_UNICODE_STRING_MARKER = '?'; |
6 | static const DWORD MAX_CABINET_HEADER_SIZE = 16 * 1024 * 1024; | 22 | static const DWORD MAX_CABINET_HEADER_SIZE = 16 * 1024 * 1024; |
7 | 23 | ||
@@ -144,19 +160,19 @@ static HRESULT UtcFileTimeToLocalDosDateTime( | |||
144 | __out USHORT* pTime | 160 | __out USHORT* pTime |
145 | ); | 161 | ); |
146 | 162 | ||
147 | static __callback int DIAMONDAPI CabCFilePlaced(__in PCCAB pccab, __in_z PSTR szFile, __in long cbFile, __in BOOL fContinuation, __out_bcount(CABC_HANDLE_BYTES) void *pv); | 163 | static __callback int DIAMONDAPI CabCFilePlaced(__in PCCAB pccab, __in_z PSTR szFile, __in long cbFile, __in BOOL fContinuation, __inout_bcount(CABC_HANDLE_BYTES) void *pv); |
148 | static __callback void * DIAMONDAPI CabCAlloc(__in ULONG cb); | 164 | static __callback void * DIAMONDAPI CabCAlloc(__in ULONG cb); |
149 | static __callback void DIAMONDAPI CabCFree(__out_bcount(CABC_HANDLE_BYTES) void *pv); | 165 | static __callback void DIAMONDAPI CabCFree(__out_bcount(CABC_HANDLE_BYTES) void *pv); |
150 | static __callback INT_PTR DIAMONDAPI CabCOpen(__in_z PSTR pszFile, __in int oflag, __in int pmode, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv); | 166 | static __callback INT_PTR DIAMONDAPI CabCOpen(__in_z PSTR pszFile, __in int oflag, __in int pmode, __out int *err, __inout_bcount(CABC_HANDLE_BYTES) void *pv); |
151 | static __callback UINT FAR DIAMONDAPI CabCRead(__in INT_PTR hf, __out_bcount(cb) void FAR *memory, __in UINT cb, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv); | 167 | static __callback UINT FAR DIAMONDAPI CabCRead(__in INT_PTR hf, __out_bcount(cb) void FAR *memory, __in UINT cb, __out int *err, __inout_bcount(CABC_HANDLE_BYTES) void *pv); |
152 | static __callback UINT FAR DIAMONDAPI CabCWrite(__in INT_PTR hf, __in_bcount(cb) void FAR *memory, __in UINT cb, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv); | 168 | static __callback UINT FAR DIAMONDAPI CabCWrite(__in INT_PTR hf, __in_bcount(cb) void FAR *memory, __in UINT cb, __out int *err, __inout_bcount(CABC_HANDLE_BYTES) void *pv); |
153 | static __callback long FAR DIAMONDAPI CabCSeek(__in INT_PTR hf, __in long dist, __in int seektype, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv); | 169 | static __callback long FAR DIAMONDAPI CabCSeek(__in INT_PTR hf, __in long dist, __in int seektype, __out int *err, __inout_bcount(CABC_HANDLE_BYTES) void *pv); |
154 | static __callback int FAR DIAMONDAPI CabCClose(__in INT_PTR hf, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv); | 170 | static __callback int FAR DIAMONDAPI CabCClose(__in INT_PTR hf, __out int *err, __inout_bcount(CABC_HANDLE_BYTES) void *pv); |
155 | static __callback int DIAMONDAPI CabCDelete(__in_z PSTR szFile, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv); | 171 | static __callback int DIAMONDAPI CabCDelete(__in_z PSTR szFile, __out int *err, __inout_bcount(CABC_HANDLE_BYTES) void *pv); |
156 | __success(return != FALSE) static __callback BOOL DIAMONDAPI CabCGetTempFile(__out_bcount_z(cbFile) char *szFile, __in int cbFile, __out_bcount(CABC_HANDLE_BYTES) void *pv); | 172 | __success(return != FALSE) static __callback BOOL DIAMONDAPI CabCGetTempFile(__out_bcount_z(cbFile) char *szFile, __in int cbFile, __inout_bcount(CABC_HANDLE_BYTES) void *pv); |
157 | __success(return != FALSE) static __callback BOOL DIAMONDAPI CabCGetNextCabinet(__in PCCAB pccab, __in ULONG ul, __out_bcount(CABC_HANDLE_BYTES) void *pv); | 173 | __success(return != FALSE) static __callback BOOL DIAMONDAPI CabCGetNextCabinet(__in PCCAB pccab, __in ULONG ul, __out_bcount(CABC_HANDLE_BYTES) void *pv); |
158 | static __callback INT_PTR DIAMONDAPI CabCGetOpenInfo(__in_z PSTR pszName, __out USHORT *pdate, __out USHORT *ptime, __out USHORT *pattribs, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv); | 174 | static __callback INT_PTR DIAMONDAPI CabCGetOpenInfo(__in_z PSTR pszName, __out USHORT *pdate, __out USHORT *ptime, __out USHORT *pattribs, __out int *err, __out_bcount(CABC_HANDLE_BYTES) void *pv); |
159 | static __callback long DIAMONDAPI CabCStatus(__in UINT uiTypeStatus, __in ULONG cb1, __in ULONG cb2, __out_bcount(CABC_HANDLE_BYTES) void *pv); | 175 | static __callback long DIAMONDAPI CabCStatus(__in UINT uiTypeStatus, __in ULONG cb1, __in ULONG cb2, __inout_bcount(CABC_HANDLE_BYTES) void *pv); |
160 | 176 | ||
161 | 177 | ||
162 | /******************************************************************** | 178 | /******************************************************************** |
@@ -174,7 +190,7 @@ extern "C" HRESULT DAPI CabCBegin( | |||
174 | __in DWORD dwMaxSize, | 190 | __in DWORD dwMaxSize, |
175 | __in DWORD dwMaxThresh, | 191 | __in DWORD dwMaxThresh, |
176 | __in COMPRESSION_TYPE ct, | 192 | __in COMPRESSION_TYPE ct, |
177 | __out HANDLE *phContext | 193 | __out_bcount(CABC_HANDLE_BYTES) HANDLE *phContext |
178 | ) | 194 | ) |
179 | { | 195 | { |
180 | Assert(wzCab && *wzCab && phContext); | 196 | Assert(wzCab && *wzCab && phContext); |
@@ -190,28 +206,28 @@ extern "C" HRESULT DAPI CabCBegin( | |||
190 | if (wzCabDir) | 206 | if (wzCabDir) |
191 | { | 207 | { |
192 | hr = ::StringCchLengthW(wzCabDir, MAX_PATH, &cchPathBuffer); | 208 | hr = ::StringCchLengthW(wzCabDir, MAX_PATH, &cchPathBuffer); |
193 | ExitOnFailure(hr, "Failed to get length of cab directory"); | 209 | CabcExitOnFailure(hr, "Failed to get length of cab directory"); |
194 | 210 | ||
195 | // Need room to terminate with L'\\' and L'\0' | 211 | // Need room to terminate with L'\\' and L'\0' |
196 | if((MAX_PATH - 1) <= cchPathBuffer || 0 == cchPathBuffer) | 212 | if((MAX_PATH - 1) <= cchPathBuffer || 0 == cchPathBuffer) |
197 | { | 213 | { |
198 | hr = E_INVALIDARG; | 214 | hr = E_INVALIDARG; |
199 | ExitOnFailure(hr, "Cab directory had invalid length: %u", cchPathBuffer); | 215 | CabcExitOnFailure(hr, "Cab directory had invalid length: %u", cchPathBuffer); |
200 | } | 216 | } |
201 | 217 | ||
202 | hr = ::StringCchCopyW(wzPathBuffer, countof(wzPathBuffer), wzCabDir); | 218 | hr = ::StringCchCopyW(wzPathBuffer, countof(wzPathBuffer), wzCabDir); |
203 | ExitOnFailure(hr, "Failed to copy cab directory to buffer"); | 219 | CabcExitOnFailure(hr, "Failed to copy cab directory to buffer"); |
204 | 220 | ||
205 | if (L'\\' != wzPathBuffer[cchPathBuffer - 1]) | 221 | if (L'\\' != wzPathBuffer[cchPathBuffer - 1]) |
206 | { | 222 | { |
207 | hr = ::StringCchCatW(wzPathBuffer, countof(wzPathBuffer), L"\\"); | 223 | hr = ::StringCchCatW(wzPathBuffer, countof(wzPathBuffer), L"\\"); |
208 | ExitOnFailure(hr, "Failed to cat \\ to end of buffer"); | 224 | CabcExitOnFailure(hr, "Failed to cat \\ to end of buffer"); |
209 | ++cchPathBuffer; | 225 | ++cchPathBuffer; |
210 | } | 226 | } |
211 | } | 227 | } |
212 | 228 | ||
213 | pcd = static_cast<CABC_DATA*>(MemAlloc(sizeof(CABC_DATA), TRUE)); | 229 | pcd = static_cast<CABC_DATA*>(MemAlloc(sizeof(CABC_DATA), TRUE)); |
214 | ExitOnNull(pcd, hr, E_OUTOFMEMORY, "failed to allocate cab creation data structure"); | 230 | CabcExitOnNull(pcd, hr, E_OUTOFMEMORY, "failed to allocate cab creation data structure"); |
215 | 231 | ||
216 | pcd->hrLastError = S_OK; | 232 | pcd->hrLastError = S_OK; |
217 | pcd->fGoodCab = TRUE; | 233 | pcd->fGoodCab = TRUE; |
@@ -266,35 +282,35 @@ extern "C" HRESULT DAPI CabCBegin( | |||
266 | else | 282 | else |
267 | { | 283 | { |
268 | hr = E_INVALIDARG; | 284 | hr = E_INVALIDARG; |
269 | ExitOnFailure(hr, "Invalid compression type specified."); | 285 | CabcExitOnFailure(hr, "Invalid compression type specified."); |
270 | } | 286 | } |
271 | 287 | ||
272 | if (0 == ::WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wzCab, -1, pcd->ccab.szCab, sizeof(pcd->ccab.szCab), NULL, NULL)) | 288 | if (0 == ::WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wzCab, -1, pcd->ccab.szCab, sizeof(pcd->ccab.szCab), NULL, NULL)) |
273 | { | 289 | { |
274 | ExitWithLastError(hr, "failed to convert cab name to multi-byte"); | 290 | CabcExitWithLastError(hr, "failed to convert cab name to multi-byte"); |
275 | } | 291 | } |
276 | 292 | ||
277 | if (0 == ::WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wzPathBuffer, -1, pcd->ccab.szCabPath, sizeof(pcd->ccab.szCab), NULL, NULL)) | 293 | if (0 == ::WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wzPathBuffer, -1, pcd->ccab.szCabPath, sizeof(pcd->ccab.szCab), NULL, NULL)) |
278 | { | 294 | { |
279 | ExitWithLastError(hr, "failed to convert cab dir to multi-byte"); | 295 | CabcExitWithLastError(hr, "failed to convert cab dir to multi-byte"); |
280 | } | 296 | } |
281 | 297 | ||
282 | // Remember the path to the cabinet. | 298 | // Remember the path to the cabinet. |
283 | hr= ::StringCchCopyW(pcd->wzCabinetPath, countof(pcd->wzCabinetPath), wzPathBuffer); | 299 | hr= ::StringCchCopyW(pcd->wzCabinetPath, countof(pcd->wzCabinetPath), wzPathBuffer); |
284 | ExitOnFailure(hr, "Failed to copy cabinet path from path: %ls", wzPathBuffer); | 300 | CabcExitOnFailure(hr, "Failed to copy cabinet path from path: %ls", wzPathBuffer); |
285 | 301 | ||
286 | hr = ::StringCchCatW(pcd->wzCabinetPath, countof(pcd->wzCabinetPath), wzCab); | 302 | hr = ::StringCchCatW(pcd->wzCabinetPath, countof(pcd->wzCabinetPath), wzCab); |
287 | ExitOnFailure(hr, "Failed to concat to cabinet path cabinet name: %ls", wzCab); | 303 | CabcExitOnFailure(hr, "Failed to concat to cabinet path cabinet name: %ls", wzCab); |
288 | 304 | ||
289 | // Get the empty file to use as the blank marker for duplicates. | 305 | // Get the empty file to use as the blank marker for duplicates. |
290 | if (!::GetTempPathW(countof(wzTempPath), wzTempPath)) | 306 | if (!::GetTempPathW(countof(wzTempPath), wzTempPath)) |
291 | { | 307 | { |
292 | ExitWithLastError(hr, "Failed to get temp path."); | 308 | CabcExitWithLastError(hr, "Failed to get temp path."); |
293 | } | 309 | } |
294 | 310 | ||
295 | if (!::GetTempFileNameW(wzTempPath, L"WSC", 0, pcd->wzEmptyFile)) | 311 | if (!::GetTempFileNameW(wzTempPath, L"WSC", 0, pcd->wzEmptyFile)) |
296 | { | 312 | { |
297 | ExitWithLastError(hr, "Failed to create a temp file name."); | 313 | CabcExitWithLastError(hr, "Failed to create a temp file name."); |
298 | } | 314 | } |
299 | 315 | ||
300 | // Try to open the newly created empty file (remember, GetTempFileName() is kind enough to create a file for us) | 316 | // Try to open the newly created empty file (remember, GetTempFileName() is kind enough to create a file for us) |
@@ -303,7 +319,7 @@ extern "C" HRESULT DAPI CabCBegin( | |||
303 | pcd->hEmptyFile = ::CreateFileW(pcd->wzEmptyFile, 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL); | 319 | pcd->hEmptyFile = ::CreateFileW(pcd->wzEmptyFile, 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL); |
304 | 320 | ||
305 | hr = DictCreateWithEmbeddedKey(&pcd->shDictHandle, dwMaxFiles, reinterpret_cast<void **>(&pcd->prgFiles), offsetof(CABC_FILE, pwzSourcePath), DICT_FLAG_CASEINSENSITIVE); | 321 | hr = DictCreateWithEmbeddedKey(&pcd->shDictHandle, dwMaxFiles, reinterpret_cast<void **>(&pcd->prgFiles), offsetof(CABC_FILE, pwzSourcePath), DICT_FLAG_CASEINSENSITIVE); |
306 | ExitOnFailure(hr, "Failed to create dictionary to keep track of duplicate files"); | 322 | CabcExitOnFailure(hr, "Failed to create dictionary to keep track of duplicate files"); |
307 | 323 | ||
308 | // Make sure to allocate at least some space, or we won't be able to realloc later if they "lied" about having zero files | 324 | // Make sure to allocate at least some space, or we won't be able to realloc later if they "lied" about having zero files |
309 | if (1 > dwMaxFiles) | 325 | if (1 > dwMaxFiles) |
@@ -315,10 +331,10 @@ extern "C" HRESULT DAPI CabCBegin( | |||
315 | size_t cbFileAllocSize = 0; | 331 | size_t cbFileAllocSize = 0; |
316 | 332 | ||
317 | hr = ::SizeTMult(pcd->cMaxFilePaths, sizeof(CABC_FILE), &(cbFileAllocSize)); | 333 | hr = ::SizeTMult(pcd->cMaxFilePaths, sizeof(CABC_FILE), &(cbFileAllocSize)); |
318 | ExitOnFailure(hr, "Maximum allocation exceeded on initialization."); | 334 | CabcExitOnFailure(hr, "Maximum allocation exceeded on initialization."); |
319 | 335 | ||
320 | pcd->prgFiles = static_cast<CABC_FILE*>(MemAlloc(cbFileAllocSize, TRUE)); | 336 | pcd->prgFiles = static_cast<CABC_FILE*>(MemAlloc(cbFileAllocSize, TRUE)); |
321 | ExitOnNull(pcd->prgFiles, hr, E_OUTOFMEMORY, "Failed to allocate memory for files."); | 337 | CabcExitOnNull(pcd->prgFiles, hr, E_OUTOFMEMORY, "Failed to allocate memory for files."); |
322 | 338 | ||
323 | // Tell cabinet API about our configuration. | 339 | // Tell cabinet API about our configuration. |
324 | pcd->hfci = ::FCICreate(&(pcd->erf), CabCFilePlaced, CabCAlloc, CabCFree, CabCOpen, CabCRead, CabCWrite, CabCClose, CabCSeek, CabCDelete, CabCGetTempFile, &(pcd->ccab), pcd); | 340 | pcd->hfci = ::FCICreate(&(pcd->erf), CabCFilePlaced, CabCAlloc, CabCFree, CabCOpen, CabCRead, CabCWrite, CabCClose, CabCSeek, CabCDelete, CabCGetTempFile, &(pcd->ccab), pcd); |
@@ -331,12 +347,12 @@ extern "C" HRESULT DAPI CabCBegin( | |||
331 | } | 347 | } |
332 | else | 348 | else |
333 | { | 349 | { |
334 | ExitWithLastError(hr, "failed to create FCI object Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); | 350 | CabcExitWithLastError(hr, "failed to create FCI object Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); |
335 | } | 351 | } |
336 | 352 | ||
337 | pcd->fGoodCab = FALSE; | 353 | pcd->fGoodCab = FALSE; |
338 | 354 | ||
339 | ExitOnFailure(hr, "failed to create FCI object Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); // TODO: can these be converted to HRESULTS? | 355 | CabcExitOnFailure(hr, "failed to create FCI object Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); // TODO: can these be converted to HRESULTS? |
340 | } | 356 | } |
341 | 357 | ||
342 | *phContext = pcd; | 358 | *phContext = pcd; |
@@ -392,25 +408,25 @@ extern "C" HRESULT DAPI CabCAddFile( | |||
392 | { | 408 | { |
393 | // Store file size, primarily used to determine which files to hash for duplicates | 409 | // Store file size, primarily used to determine which files to hash for duplicates |
394 | hr = FileSize(wzFile, &llFileSize); | 410 | hr = FileSize(wzFile, &llFileSize); |
395 | ExitOnFailure(hr, "Failed to check size of file %ls", wzFile); | 411 | CabcExitOnFailure(hr, "Failed to check size of file %ls", wzFile); |
396 | 412 | ||
397 | hr = CheckForDuplicateFile(pcd, &pcfDuplicate, wzFile, &pmfLocalHash, llFileSize); | 413 | hr = CheckForDuplicateFile(pcd, &pcfDuplicate, wzFile, &pmfLocalHash, llFileSize); |
398 | ExitOnFailure(hr, "Failed while checking for duplicate of file: %ls", wzFile); | 414 | CabcExitOnFailure(hr, "Failed while checking for duplicate of file: %ls", wzFile); |
399 | } | 415 | } |
400 | 416 | ||
401 | if (pcfDuplicate) // This will be null for smart cabbing case | 417 | if (pcfDuplicate) // This will be null for smart cabbing case |
402 | { | 418 | { |
403 | DWORD index; | 419 | DWORD index; |
404 | hr = ::PtrdiffTToDWord(pcfDuplicate - pcd->prgFiles, &index); | 420 | hr = ::PtrdiffTToDWord(pcfDuplicate - pcd->prgFiles, &index); |
405 | ExitOnFailure(hr, "Failed to calculate index of file name: %ls", pcfDuplicate->pwzSourcePath); | 421 | CabcExitOnFailure(hr, "Failed to calculate index of file name: %ls", pcfDuplicate->pwzSourcePath); |
406 | 422 | ||
407 | hr = AddDuplicateFile(pcd, index, wzFile, wzToken, pcd->dwLastFileIndex); | 423 | hr = AddDuplicateFile(pcd, index, wzFile, wzToken, pcd->dwLastFileIndex); |
408 | ExitOnFailure(hr, "Failed to add duplicate of file name: %ls", pcfDuplicate->pwzSourcePath); | 424 | CabcExitOnFailure(hr, "Failed to add duplicate of file name: %ls", pcfDuplicate->pwzSourcePath); |
409 | } | 425 | } |
410 | else | 426 | else |
411 | { | 427 | { |
412 | hr = AddNonDuplicateFile(pcd, wzFile, wzToken, pmfLocalHash, llFileSize, pcd->dwLastFileIndex); | 428 | hr = AddNonDuplicateFile(pcd, wzFile, wzToken, pmfLocalHash, llFileSize, pcd->dwLastFileIndex); |
413 | ExitOnFailure(hr, "Failed to add non-duplicated file: %ls", wzFile); | 429 | CabcExitOnFailure(hr, "Failed to add non-duplicated file: %ls", wzFile); |
414 | } | 430 | } |
415 | 431 | ||
416 | ++pcd->dwLastFileIndex; | 432 | ++pcd->dwLastFileIndex; |
@@ -483,13 +499,13 @@ extern "C" HRESULT DAPI CabCFinish( | |||
483 | { | 499 | { |
484 | LPCWSTR pwzTemp = pcd->prgFiles[dwArrayFileIndex].pwzToken; | 500 | LPCWSTR pwzTemp = pcd->prgFiles[dwArrayFileIndex].pwzToken; |
485 | hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP); | 501 | hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP); |
486 | ExitOnFailure(hr, "failed to convert file token to ANSI: %ls", pwzTemp); | 502 | CabcExitOnFailure(hr, "failed to convert file token to ANSI: %ls", pwzTemp); |
487 | } | 503 | } |
488 | else | 504 | else |
489 | { | 505 | { |
490 | LPCWSTR pwzTemp = FileFromPath(fileInfo.wzSourcePath); | 506 | LPCWSTR pwzTemp = FileFromPath(fileInfo.wzSourcePath); |
491 | hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP); | 507 | hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP); |
492 | ExitOnFailure(hr, "failed to convert file name to ANSI: %ls", pwzTemp); | 508 | CabcExitOnFailure(hr, "failed to convert file name to ANSI: %ls", pwzTemp); |
493 | } | 509 | } |
494 | 510 | ||
495 | if (pcd->prgFiles[dwArrayFileIndex].fHasDuplicates) | 511 | if (pcd->prgFiles[dwArrayFileIndex].fHasDuplicates) |
@@ -518,13 +534,13 @@ extern "C" HRESULT DAPI CabCFinish( | |||
518 | { | 534 | { |
519 | LPCWSTR pwzTemp = pcd->prgDuplicates[dwDupeArrayFileIndex].pwzToken; | 535 | LPCWSTR pwzTemp = pcd->prgDuplicates[dwDupeArrayFileIndex].pwzToken; |
520 | hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP); | 536 | hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP); |
521 | ExitOnFailure(hr, "failed to convert duplicate file token to ANSI: %ls", pwzTemp); | 537 | CabcExitOnFailure(hr, "failed to convert duplicate file token to ANSI: %ls", pwzTemp); |
522 | } | 538 | } |
523 | else | 539 | else |
524 | { | 540 | { |
525 | LPCWSTR pwzTemp = FileFromPath(fileInfo.wzSourcePath); | 541 | LPCWSTR pwzTemp = FileFromPath(fileInfo.wzSourcePath); |
526 | hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP); | 542 | hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP); |
527 | ExitOnFailure(hr, "failed to convert duplicate file name to ANSI: %ls", pwzTemp); | 543 | CabcExitOnFailure(hr, "failed to convert duplicate file name to ANSI: %ls", pwzTemp); |
528 | } | 544 | } |
529 | 545 | ||
530 | // Flush afterward only if this isn't a duplicate of the previous file, and at least one non-duplicate file remains to be added to the cab | 546 | // Flush afterward only if this isn't a duplicate of the previous file, and at least one non-duplicate file remains to be added to the cab |
@@ -543,14 +559,14 @@ extern "C" HRESULT DAPI CabCFinish( | |||
543 | else // If it's neither duplicate nor non-duplicate, throw an error | 559 | else // If it's neither duplicate nor non-duplicate, throw an error |
544 | { | 560 | { |
545 | hr = HRESULT_FROM_WIN32(ERROR_EA_LIST_INCONSISTENT); | 561 | hr = HRESULT_FROM_WIN32(ERROR_EA_LIST_INCONSISTENT); |
546 | ExitOnRootFailure(hr, "Internal inconsistency in data structures while creating CAB file - a non-standard, non-duplicate file was encountered"); | 562 | CabcExitOnRootFailure(hr, "Internal inconsistency in data structures while creating CAB file - a non-standard, non-duplicate file was encountered"); |
547 | } | 563 | } |
548 | 564 | ||
549 | if (fFlushBefore && pcd->llBytesSinceLastFlush > pcd->llFlushThreshhold) | 565 | if (fFlushBefore && pcd->llBytesSinceLastFlush > pcd->llFlushThreshhold) |
550 | { | 566 | { |
551 | if (!::FCIFlushFolder(pcd->hfci, CabCGetNextCabinet, CabCStatus)) | 567 | if (!::FCIFlushFolder(pcd->hfci, CabCGetNextCabinet, CabCStatus)) |
552 | { | 568 | { |
553 | ExitWithLastError(hr, "failed to flush FCI folder before adding file, Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); | 569 | CabcExitWithLastError(hr, "failed to flush FCI folder before adding file, Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); |
554 | } | 570 | } |
555 | pcd->llBytesSinceLastFlush = 0; | 571 | pcd->llBytesSinceLastFlush = 0; |
556 | } | 572 | } |
@@ -574,10 +590,10 @@ extern "C" HRESULT DAPI CabCFinish( | |||
574 | } | 590 | } |
575 | else | 591 | else |
576 | { | 592 | { |
577 | ExitWithLastError(hr, "failed to add file to FCI object Oper: 0x%x Type: 0x%x File: %ls", pcd->erf.erfOper, pcd->erf.erfType, fileInfo.wzSourcePath); | 593 | CabcExitWithLastError(hr, "failed to add file to FCI object Oper: 0x%x Type: 0x%x File: %ls", pcd->erf.erfOper, pcd->erf.erfType, fileInfo.wzSourcePath); |
578 | } | 594 | } |
579 | 595 | ||
580 | ExitOnFailure(hr, "failed to add file to FCI object Oper: 0x%x Type: 0x%x File: %ls", pcd->erf.erfOper, pcd->erf.erfType, fileInfo.wzSourcePath); // TODO: can these be converted to HRESULTS? | 596 | CabcExitOnFailure(hr, "failed to add file to FCI object Oper: 0x%x Type: 0x%x File: %ls", pcd->erf.erfOper, pcd->erf.erfType, fileInfo.wzSourcePath); // TODO: can these be converted to HRESULTS? |
581 | } | 597 | } |
582 | 598 | ||
583 | // For Cabinet Splitting case, check for pcd->hrLastError that may be set as result of Error in CabCGetNextCabinet | 599 | // For Cabinet Splitting case, check for pcd->hrLastError that may be set as result of Error in CabCGetNextCabinet |
@@ -585,14 +601,14 @@ extern "C" HRESULT DAPI CabCFinish( | |||
585 | if (pcd->fCabinetSplittingEnabled && FAILED(pcd->hrLastError)) | 601 | if (pcd->fCabinetSplittingEnabled && FAILED(pcd->hrLastError)) |
586 | { | 602 | { |
587 | hr = pcd->hrLastError; | 603 | hr = pcd->hrLastError; |
588 | ExitOnFailure(hr, "Failed to create next cabinet name while splitting cabinet."); | 604 | CabcExitOnFailure(hr, "Failed to create next cabinet name while splitting cabinet."); |
589 | } | 605 | } |
590 | 606 | ||
591 | if (fFlushAfter && pcd->llBytesSinceLastFlush > pcd->llFlushThreshhold) | 607 | if (fFlushAfter && pcd->llBytesSinceLastFlush > pcd->llFlushThreshhold) |
592 | { | 608 | { |
593 | if (!::FCIFlushFolder(pcd->hfci, CabCGetNextCabinet, CabCStatus)) | 609 | if (!::FCIFlushFolder(pcd->hfci, CabCGetNextCabinet, CabCStatus)) |
594 | { | 610 | { |
595 | ExitWithLastError(hr, "failed to flush FCI folder after adding file, Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); | 611 | CabcExitWithLastError(hr, "failed to flush FCI folder after adding file, Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); |
596 | } | 612 | } |
597 | pcd->llBytesSinceLastFlush = 0; | 613 | pcd->llBytesSinceLastFlush = 0; |
598 | } | 614 | } |
@@ -610,10 +626,10 @@ extern "C" HRESULT DAPI CabCFinish( | |||
610 | } | 626 | } |
611 | else | 627 | else |
612 | { | 628 | { |
613 | ExitWithLastError(hr, "failed while creating CAB FCI object Oper: 0x%x Type: 0x%x File: %s", pcd->erf.erfOper, pcd->erf.erfType); | 629 | CabcExitWithLastError(hr, "failed while creating CAB FCI object Oper: 0x%x Type: 0x%x File: %ls", pcd->erf.erfOper, pcd->erf.erfType, fileInfo.wzSourcePath); |
614 | } | 630 | } |
615 | 631 | ||
616 | ExitOnFailure(hr, "failed while creating CAB FCI object Oper: 0x%x Type: 0x%x File: %s", pcd->erf.erfOper, pcd->erf.erfType); // TODO: can these be converted to HRESULTS? | 632 | CabcExitOnFailure(hr, "failed while creating CAB FCI object Oper: 0x%x Type: 0x%x File: %ls", pcd->erf.erfOper, pcd->erf.erfType, fileInfo.wzSourcePath); // TODO: can these be converted to HRESULTS? |
617 | } | 633 | } |
618 | 634 | ||
619 | // Only flush the cabinet if we actually succeeded in previous calls - otherwise we just waste time (a lot on big cabs) | 635 | // Only flush the cabinet if we actually succeeded in previous calls - otherwise we just waste time (a lot on big cabs) |
@@ -621,13 +637,13 @@ extern "C" HRESULT DAPI CabCFinish( | |||
621 | { | 637 | { |
622 | // If we have a last error, use that, otherwise return the useless error | 638 | // If we have a last error, use that, otherwise return the useless error |
623 | hr = FAILED(pcd->hrLastError) ? pcd->hrLastError : E_FAIL; | 639 | hr = FAILED(pcd->hrLastError) ? pcd->hrLastError : E_FAIL; |
624 | ExitOnFailure(hr, "failed to flush FCI object Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); // TODO: can these be converted to HRESULTS? | 640 | CabcExitOnFailure(hr, "failed to flush FCI object Oper: 0x%x Type: 0x%x", pcd->erf.erfOper, pcd->erf.erfType); // TODO: can these be converted to HRESULTS? |
625 | } | 641 | } |
626 | 642 | ||
627 | if (pcd->fGoodCab && pcd->cDuplicates) | 643 | if (pcd->fGoodCab && pcd->cDuplicates) |
628 | { | 644 | { |
629 | hr = UpdateDuplicateFiles(pcd); | 645 | hr = UpdateDuplicateFiles(pcd); |
630 | ExitOnFailure(hr, "Failed to update duplicates in cabinet: %ls", pcd->wzCabinetPath); | 646 | CabcExitOnFailure(hr, "Failed to update duplicates in cabinet: %ls", pcd->wzCabinetPath); |
631 | } | 647 | } |
632 | 648 | ||
633 | LExit: | 649 | LExit: |
@@ -697,8 +713,8 @@ static HRESULT CheckForDuplicateFile( | |||
697 | HRESULT hr = S_OK; | 713 | HRESULT hr = S_OK; |
698 | UINT er = ERROR_SUCCESS; | 714 | UINT er = ERROR_SUCCESS; |
699 | 715 | ||
700 | ExitOnNull(ppcf, hr, E_INVALIDARG, "No file structure sent while checking for duplicate file"); | 716 | CabcExitOnNull(ppcf, hr, E_INVALIDARG, "No file structure sent while checking for duplicate file"); |
701 | ExitOnNull(ppmfHash, hr, E_INVALIDARG, "No file hash structure pointer sent while checking for duplicate file"); | 717 | CabcExitOnNull(ppmfHash, hr, E_INVALIDARG, "No file hash structure pointer sent while checking for duplicate file"); |
702 | 718 | ||
703 | *ppcf = NULL; // By default, we'll set our output to NULL | 719 | *ppcf = NULL; // By default, we'll set our output to NULL |
704 | 720 | ||
@@ -712,7 +728,7 @@ static HRESULT CheckForDuplicateFile( | |||
712 | { | 728 | { |
713 | hr = S_OK; | 729 | hr = S_OK; |
714 | } | 730 | } |
715 | ExitOnFailure(hr, "Failed while searching for file in dictionary of previously added files"); | 731 | CabcExitOnFailure(hr, "Failed while searching for file in dictionary of previously added files"); |
716 | 732 | ||
717 | for (i = 0; i < pcd->cFilePaths; ++i) | 733 | for (i = 0; i < pcd->cFilePaths; ++i) |
718 | { | 734 | { |
@@ -723,22 +739,22 @@ static HRESULT CheckForDuplicateFile( | |||
723 | if (pcd->prgFiles[i].pmfHash == NULL) | 739 | if (pcd->prgFiles[i].pmfHash == NULL) |
724 | { | 740 | { |
725 | pcd->prgFiles[i].pmfHash = (PMSIFILEHASHINFO)MemAlloc(sizeof(MSIFILEHASHINFO), FALSE); | 741 | pcd->prgFiles[i].pmfHash = (PMSIFILEHASHINFO)MemAlloc(sizeof(MSIFILEHASHINFO), FALSE); |
726 | ExitOnNull(pcd->prgFiles[i].pmfHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for candidate duplicate file's MSI file hash"); | 742 | CabcExitOnNull(pcd->prgFiles[i].pmfHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for candidate duplicate file's MSI file hash"); |
727 | 743 | ||
728 | pcd->prgFiles[i].pmfHash->dwFileHashInfoSize = sizeof(MSIFILEHASHINFO); | 744 | pcd->prgFiles[i].pmfHash->dwFileHashInfoSize = sizeof(MSIFILEHASHINFO); |
729 | er = ::MsiGetFileHashW(pcd->prgFiles[i].pwzSourcePath, 0, pcd->prgFiles[i].pmfHash); | 745 | er = ::MsiGetFileHashW(pcd->prgFiles[i].pwzSourcePath, 0, pcd->prgFiles[i].pmfHash); |
730 | ExitOnWin32Error(er, hr, "Failed while getting MSI file hash of candidate duplicate file: %ls", pcd->prgFiles[i].pwzSourcePath); | 746 | CabcExitOnWin32Error(er, hr, "Failed while getting MSI file hash of candidate duplicate file: %ls", pcd->prgFiles[i].pwzSourcePath); |
731 | } | 747 | } |
732 | 748 | ||
733 | // If our own file hasn't yet been hashed, hash it | 749 | // If our own file hasn't yet been hashed, hash it |
734 | if (NULL == *ppmfHash) | 750 | if (NULL == *ppmfHash) |
735 | { | 751 | { |
736 | *ppmfHash = (PMSIFILEHASHINFO)MemAlloc(sizeof(MSIFILEHASHINFO), FALSE); | 752 | *ppmfHash = (PMSIFILEHASHINFO)MemAlloc(sizeof(MSIFILEHASHINFO), FALSE); |
737 | ExitOnNull(*ppmfHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for file's MSI file hash"); | 753 | CabcExitOnNull(*ppmfHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for file's MSI file hash"); |
738 | 754 | ||
739 | (*ppmfHash)->dwFileHashInfoSize = sizeof(MSIFILEHASHINFO); | 755 | (*ppmfHash)->dwFileHashInfoSize = sizeof(MSIFILEHASHINFO); |
740 | er = ::MsiGetFileHashW(wzFileName, 0, *ppmfHash); | 756 | er = ::MsiGetFileHashW(wzFileName, 0, *ppmfHash); |
741 | ExitOnWin32Error(er, hr, "Failed while getting MSI file hash of file: %ls", pcd->prgFiles[i].pwzSourcePath); | 757 | CabcExitOnWin32Error(er, hr, "Failed while getting MSI file hash of file: %ls", pcd->prgFiles[i].pwzSourcePath); |
742 | } | 758 | } |
743 | 759 | ||
744 | // If the two file hashes are both of the expected size, and they match, we've got a match, so return it! | 760 | // If the two file hashes are both of the expected size, and they match, we've got a match, so return it! |
@@ -779,17 +795,17 @@ static HRESULT AddDuplicateFile( | |||
779 | size_t cbDuplicates = 0; | 795 | size_t cbDuplicates = 0; |
780 | 796 | ||
781 | hr = ::SizeTMult(pcd->cMaxDuplicates, sizeof(CABC_DUPLICATEFILE), &cbDuplicates); | 797 | hr = ::SizeTMult(pcd->cMaxDuplicates, sizeof(CABC_DUPLICATEFILE), &cbDuplicates); |
782 | ExitOnFailure(hr, "Maximum allocation exceeded."); | 798 | CabcExitOnFailure(hr, "Maximum allocation exceeded."); |
783 | 799 | ||
784 | if (pcd->cDuplicates) | 800 | if (pcd->cDuplicates) |
785 | { | 801 | { |
786 | pv = MemReAlloc(pcd->prgDuplicates, cbDuplicates, FALSE); | 802 | pv = MemReAlloc(pcd->prgDuplicates, cbDuplicates, FALSE); |
787 | ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate memory for duplicate file."); | 803 | CabcExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate memory for duplicate file."); |
788 | } | 804 | } |
789 | else | 805 | else |
790 | { | 806 | { |
791 | pv = MemAlloc(cbDuplicates, FALSE); | 807 | pv = MemAlloc(cbDuplicates, FALSE); |
792 | ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for duplicate file."); | 808 | CabcExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for duplicate file."); |
793 | } | 809 | } |
794 | 810 | ||
795 | ZeroMemory(reinterpret_cast<BYTE*>(pv) + (pcd->cDuplicates * sizeof(CABC_DUPLICATEFILE)), (pcd->cMaxDuplicates - pcd->cDuplicates) * sizeof(CABC_DUPLICATEFILE)); | 811 | ZeroMemory(reinterpret_cast<BYTE*>(pv) + (pcd->cDuplicates * sizeof(CABC_DUPLICATEFILE)), (pcd->cMaxDuplicates - pcd->cDuplicates) * sizeof(CABC_DUPLICATEFILE)); |
@@ -804,12 +820,12 @@ static HRESULT AddDuplicateFile( | |||
804 | pcd->prgFiles[dwFileArrayIndex].fHasDuplicates = TRUE; // Mark original file as having duplicates | 820 | pcd->prgFiles[dwFileArrayIndex].fHasDuplicates = TRUE; // Mark original file as having duplicates |
805 | 821 | ||
806 | hr = StrAllocString(&pcd->prgDuplicates[pcd->cDuplicates].pwzSourcePath, wzSourcePath, 0); | 822 | hr = StrAllocString(&pcd->prgDuplicates[pcd->cDuplicates].pwzSourcePath, wzSourcePath, 0); |
807 | ExitOnFailure(hr, "Failed to copy duplicate file path: %ls", wzSourcePath); | 823 | CabcExitOnFailure(hr, "Failed to copy duplicate file path: %ls", wzSourcePath); |
808 | 824 | ||
809 | if (wzToken && *wzToken) | 825 | if (wzToken && *wzToken) |
810 | { | 826 | { |
811 | hr = StrAllocString(&pcd->prgDuplicates[pcd->cDuplicates].pwzToken, wzToken, 0); | 827 | hr = StrAllocString(&pcd->prgDuplicates[pcd->cDuplicates].pwzToken, wzToken, 0); |
812 | ExitOnFailure(hr, "Failed to copy duplicate file token: %ls", wzToken); | 828 | CabcExitOnFailure(hr, "Failed to copy duplicate file token: %ls", wzToken); |
813 | } | 829 | } |
814 | 830 | ||
815 | ++pcd->cDuplicates; | 831 | ++pcd->cDuplicates; |
@@ -839,10 +855,10 @@ static HRESULT AddNonDuplicateFile( | |||
839 | size_t cbFilePaths = 0; | 855 | size_t cbFilePaths = 0; |
840 | 856 | ||
841 | hr = ::SizeTMult(pcd->cMaxFilePaths, sizeof(CABC_FILE), &cbFilePaths); | 857 | hr = ::SizeTMult(pcd->cMaxFilePaths, sizeof(CABC_FILE), &cbFilePaths); |
842 | ExitOnFailure(hr, "Maximum allocation exceeded."); | 858 | CabcExitOnFailure(hr, "Maximum allocation exceeded."); |
843 | 859 | ||
844 | pv = MemReAlloc(pcd->prgFiles, cbFilePaths, FALSE); | 860 | pv = MemReAlloc(pcd->prgFiles, cbFilePaths, FALSE); |
845 | ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate memory for file."); | 861 | CabcExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to reallocate memory for file."); |
846 | 862 | ||
847 | ZeroMemory(reinterpret_cast<BYTE*>(pv) + (pcd->cFilePaths * sizeof(CABC_FILE)), (pcd->cMaxFilePaths - pcd->cFilePaths) * sizeof(CABC_FILE)); | 863 | ZeroMemory(reinterpret_cast<BYTE*>(pv) + (pcd->cFilePaths * sizeof(CABC_FILE)), (pcd->cMaxFilePaths - pcd->cFilePaths) * sizeof(CABC_FILE)); |
848 | 864 | ||
@@ -859,7 +875,7 @@ static HRESULT AddNonDuplicateFile( | |||
859 | if (pmfHash && sizeof(MSIFILEHASHINFO) == pmfHash->dwFileHashInfoSize) | 875 | if (pmfHash && sizeof(MSIFILEHASHINFO) == pmfHash->dwFileHashInfoSize) |
860 | { | 876 | { |
861 | pcf->pmfHash = (PMSIFILEHASHINFO)MemAlloc(sizeof(MSIFILEHASHINFO), FALSE); | 877 | pcf->pmfHash = (PMSIFILEHASHINFO)MemAlloc(sizeof(MSIFILEHASHINFO), FALSE); |
862 | ExitOnNull(pcf->pmfHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for individual file's MSI file hash"); | 878 | CabcExitOnNull(pcf->pmfHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for individual file's MSI file hash"); |
863 | 879 | ||
864 | pcf->pmfHash->dwFileHashInfoSize = sizeof(MSIFILEHASHINFO); | 880 | pcf->pmfHash->dwFileHashInfoSize = sizeof(MSIFILEHASHINFO); |
865 | pcf->pmfHash->dwData[0] = pmfHash->dwData[0]; | 881 | pcf->pmfHash->dwData[0] = pmfHash->dwData[0]; |
@@ -869,18 +885,18 @@ static HRESULT AddNonDuplicateFile( | |||
869 | } | 885 | } |
870 | 886 | ||
871 | hr = StrAllocString(&pcf->pwzSourcePath, wzFile, 0); | 887 | hr = StrAllocString(&pcf->pwzSourcePath, wzFile, 0); |
872 | ExitOnFailure(hr, "Failed to copy file path: %ls", wzFile); | 888 | CabcExitOnFailure(hr, "Failed to copy file path: %ls", wzFile); |
873 | 889 | ||
874 | if (wzToken && *wzToken) | 890 | if (wzToken && *wzToken) |
875 | { | 891 | { |
876 | hr = StrAllocString(&pcf->pwzToken, wzToken, 0); | 892 | hr = StrAllocString(&pcf->pwzToken, wzToken, 0); |
877 | ExitOnFailure(hr, "Failed to copy file token: %ls", wzToken); | 893 | CabcExitOnFailure(hr, "Failed to copy file token: %ls", wzToken); |
878 | } | 894 | } |
879 | 895 | ||
880 | ++pcd->cFilePaths; | 896 | ++pcd->cFilePaths; |
881 | 897 | ||
882 | hr = DictAddValue(pcd->shDictHandle, pcf); | 898 | hr = DictAddValue(pcd->shDictHandle, pcf); |
883 | ExitOnFailure(hr, "Failed to add file to dictionary of added files"); | 899 | CabcExitOnFailure(hr, "Failed to add file to dictionary of added files"); |
884 | 900 | ||
885 | LExit: | 901 | LExit: |
886 | ReleaseMem(pv); | 902 | ReleaseMem(pv); |
@@ -903,14 +919,14 @@ static HRESULT UpdateDuplicateFiles( | |||
903 | hCabinet = ::CreateFileW(pcd->wzCabinetPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | 919 | hCabinet = ::CreateFileW(pcd->wzCabinetPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
904 | if (INVALID_HANDLE_VALUE == hCabinet) | 920 | if (INVALID_HANDLE_VALUE == hCabinet) |
905 | { | 921 | { |
906 | ExitWithLastError(hr, "Failed to open cabinet: %ls", pcd->wzCabinetPath); | 922 | CabcExitWithLastError(hr, "Failed to open cabinet: %ls", pcd->wzCabinetPath); |
907 | } | 923 | } |
908 | 924 | ||
909 | // Shouldn't need more than 16 MB to get the whole cabinet header into memory so use that as | 925 | // Shouldn't need more than 16 MB to get the whole cabinet header into memory so use that as |
910 | // the upper bound for the memory map. | 926 | // the upper bound for the memory map. |
911 | if (!::GetFileSizeEx(hCabinet, &liCabinetSize)) | 927 | if (!::GetFileSizeEx(hCabinet, &liCabinetSize)) |
912 | { | 928 | { |
913 | ExitWithLastError(hr, "Failed to get size of cabinet: %ls", pcd->wzCabinetPath); | 929 | CabcExitWithLastError(hr, "Failed to get size of cabinet: %ls", pcd->wzCabinetPath); |
914 | } | 930 | } |
915 | 931 | ||
916 | if (0 == liCabinetSize.HighPart && liCabinetSize.LowPart < MAX_CABINET_HEADER_SIZE) | 932 | if (0 == liCabinetSize.HighPart && liCabinetSize.LowPart < MAX_CABINET_HEADER_SIZE) |
@@ -926,11 +942,11 @@ static HRESULT UpdateDuplicateFiles( | |||
926 | hCabinetMapping = ::CreateFileMappingW(hCabinet, NULL, PAGE_READWRITE | SEC_COMMIT, 0, cbCabinet, NULL); | 942 | hCabinetMapping = ::CreateFileMappingW(hCabinet, NULL, PAGE_READWRITE | SEC_COMMIT, 0, cbCabinet, NULL); |
927 | if (NULL == hCabinetMapping || INVALID_HANDLE_VALUE == hCabinetMapping) | 943 | if (NULL == hCabinetMapping || INVALID_HANDLE_VALUE == hCabinetMapping) |
928 | { | 944 | { |
929 | ExitWithLastError(hr, "Failed to memory map cabinet file: %ls", pcd->wzCabinetPath); | 945 | CabcExitWithLastError(hr, "Failed to memory map cabinet file: %ls", pcd->wzCabinetPath); |
930 | } | 946 | } |
931 | 947 | ||
932 | pv = ::MapViewOfFile(hCabinetMapping, FILE_MAP_WRITE, 0, 0, 0); | 948 | pv = ::MapViewOfFile(hCabinetMapping, FILE_MAP_WRITE, 0, 0, 0); |
933 | ExitOnNullWithLastError(pv, hr, "Failed to map view of cabinet file: %ls", pcd->wzCabinetPath); | 949 | CabcExitOnNullWithLastError(pv, hr, "Failed to map view of cabinet file: %ls", pcd->wzCabinetPath); |
934 | 950 | ||
935 | pCabinetHeader = static_cast<MS_CABINET_HEADER*>(pv); | 951 | pCabinetHeader = static_cast<MS_CABINET_HEADER*>(pv); |
936 | 952 | ||
@@ -939,7 +955,7 @@ static HRESULT UpdateDuplicateFiles( | |||
939 | const CABC_DUPLICATEFILE *pDuplicateFile = pcd->prgDuplicates + i; | 955 | const CABC_DUPLICATEFILE *pDuplicateFile = pcd->prgDuplicates + i; |
940 | 956 | ||
941 | hr = DuplicateFile(pCabinetHeader, pcd, pDuplicateFile); | 957 | hr = DuplicateFile(pCabinetHeader, pcd, pDuplicateFile); |
942 | ExitOnFailure(hr, "Failed to find cabinet file items at index: %d and %d", pDuplicateFile->dwFileArrayIndex, pDuplicateFile->dwDuplicateCabFileIndex); | 958 | CabcExitOnFailure(hr, "Failed to find cabinet file items at index: %d and %d", pDuplicateFile->dwFileArrayIndex, pDuplicateFile->dwDuplicateCabFileIndex); |
943 | } | 959 | } |
944 | 960 | ||
945 | LExit: | 961 | LExit: |
@@ -974,7 +990,7 @@ static HRESULT DuplicateFile( | |||
974 | pDuplicate->dwDuplicateCabFileIndex <= pcd->prgFiles[pDuplicate->dwFileArrayIndex].dwCabFileIndex) | 990 | pDuplicate->dwDuplicateCabFileIndex <= pcd->prgFiles[pDuplicate->dwFileArrayIndex].dwCabFileIndex) |
975 | { | 991 | { |
976 | hr = E_UNEXPECTED; | 992 | hr = E_UNEXPECTED; |
977 | ExitOnFailure(hr, "Unexpected duplicate file indices, header cFiles: %d, file index: %d, duplicate index: %d", pHeader->cFiles, pcd->prgFiles[pDuplicate->dwFileArrayIndex].dwCabFileIndex, pDuplicate->dwDuplicateCabFileIndex); | 993 | CabcExitOnFailure(hr, "Unexpected duplicate file indices, header cFiles: %d, file index: %d, duplicate index: %d", pHeader->cFiles, pcd->prgFiles[pDuplicate->dwFileArrayIndex].dwCabFileIndex, pDuplicate->dwDuplicateCabFileIndex); |
978 | } | 994 | } |
979 | 995 | ||
980 | // Step through each cabinet items until we get to the original | 996 | // Step through each cabinet items until we get to the original |
@@ -1002,7 +1018,7 @@ static HRESULT DuplicateFile( | |||
1002 | if (0 != pDuplicateItem->cbFile) | 1018 | if (0 != pDuplicateItem->cbFile) |
1003 | { | 1019 | { |
1004 | hr = E_UNEXPECTED; | 1020 | hr = E_UNEXPECTED; |
1005 | ExitOnFailure(hr, "Failed because duplicate file does not have a file size of zero: %d", pDuplicateItem->cbFile); | 1021 | CabcExitOnFailure(hr, "Failed because duplicate file does not have a file size of zero: %d", pDuplicateItem->cbFile); |
1006 | } | 1022 | } |
1007 | 1023 | ||
1008 | pDuplicateItem->cbFile = pOriginalItem->cbFile; | 1024 | pDuplicateItem->cbFile = pOriginalItem->cbFile; |
@@ -1031,12 +1047,12 @@ static HRESULT UtcFileTimeToLocalDosDateTime( | |||
1031 | 1047 | ||
1032 | if (!::FileTimeToLocalFileTime(pFileTime, &ftLocal)) | 1048 | if (!::FileTimeToLocalFileTime(pFileTime, &ftLocal)) |
1033 | { | 1049 | { |
1034 | ExitWithLastError(hr, "Filed to convert file time to local file time."); | 1050 | CabcExitWithLastError(hr, "Filed to convert file time to local file time."); |
1035 | } | 1051 | } |
1036 | 1052 | ||
1037 | if (!::FileTimeToDosDateTime(&ftLocal, pDate, pTime)) | 1053 | if (!::FileTimeToDosDateTime(&ftLocal, pDate, pTime)) |
1038 | { | 1054 | { |
1039 | ExitWithLastError(hr, "Filed to convert file time to DOS date time."); | 1055 | CabcExitWithLastError(hr, "Filed to convert file time to DOS date time."); |
1040 | } | 1056 | } |
1041 | 1057 | ||
1042 | LExit: | 1058 | LExit: |
@@ -1053,7 +1069,7 @@ static __callback int DIAMONDAPI CabCFilePlaced( | |||
1053 | __in_z PSTR szFile, | 1069 | __in_z PSTR szFile, |
1054 | __in long cbFile, | 1070 | __in long cbFile, |
1055 | __in BOOL fContinuation, | 1071 | __in BOOL fContinuation, |
1056 | __out_bcount(CABC_HANDLE_BYTES) void *pv | 1072 | __inout_bcount(CABC_HANDLE_BYTES) void *pv |
1057 | ) | 1073 | ) |
1058 | { | 1074 | { |
1059 | UNREFERENCED_PARAMETER(pccab); | 1075 | UNREFERENCED_PARAMETER(pccab); |
@@ -1085,7 +1101,7 @@ static __callback INT_PTR DIAMONDAPI CabCOpen( | |||
1085 | __in int oflag, | 1101 | __in int oflag, |
1086 | __in int pmode, | 1102 | __in int pmode, |
1087 | __out int *err, | 1103 | __out int *err, |
1088 | __out_bcount(CABC_HANDLE_BYTES) void *pv | 1104 | __inout_bcount(CABC_HANDLE_BYTES) void *pv |
1089 | ) | 1105 | ) |
1090 | { | 1106 | { |
1091 | CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv); | 1107 | CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv); |
@@ -1139,7 +1155,7 @@ static __callback INT_PTR DIAMONDAPI CabCOpen( | |||
1139 | 1155 | ||
1140 | if (INVALID_HANDLE_VALUE == reinterpret_cast<HANDLE>(pFile)) | 1156 | if (INVALID_HANDLE_VALUE == reinterpret_cast<HANDLE>(pFile)) |
1141 | { | 1157 | { |
1142 | ExitOnLastError(hr, "failed to open file: %s", pszFile); | 1158 | CabcExitOnLastError(hr, "failed to open file: %s", pszFile); |
1143 | } | 1159 | } |
1144 | 1160 | ||
1145 | LExit: | 1161 | LExit: |
@@ -1155,18 +1171,18 @@ static __callback UINT FAR DIAMONDAPI CabCRead( | |||
1155 | __out_bcount(cb) void FAR *memory, | 1171 | __out_bcount(cb) void FAR *memory, |
1156 | __in UINT cb, | 1172 | __in UINT cb, |
1157 | __out int *err, | 1173 | __out int *err, |
1158 | __out_bcount(CABC_HANDLE_BYTES) void *pv | 1174 | __inout_bcount(CABC_HANDLE_BYTES) void *pv |
1159 | ) | 1175 | ) |
1160 | { | 1176 | { |
1161 | CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv); | 1177 | CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv); |
1162 | HRESULT hr = S_OK; | 1178 | HRESULT hr = S_OK; |
1163 | DWORD cbRead = 0; | 1179 | DWORD cbRead = 0; |
1164 | 1180 | ||
1165 | ExitOnNull(hf, *err, E_INVALIDARG, "Failed to read during cabinet extraction because no file handle was provided"); | 1181 | CabcExitOnNull(hf, *err, E_INVALIDARG, "Failed to read during cabinet extraction because no file handle was provided"); |
1166 | if (!::ReadFile(reinterpret_cast<HANDLE>(hf), memory, cb, &cbRead, NULL)) | 1182 | if (!::ReadFile(reinterpret_cast<HANDLE>(hf), memory, cb, &cbRead, NULL)) |
1167 | { | 1183 | { |
1168 | *err = ::GetLastError(); | 1184 | *err = ::GetLastError(); |
1169 | ExitOnLastError(hr, "failed to read during cabinet extraction"); | 1185 | CabcExitOnLastError(hr, "failed to read during cabinet extraction"); |
1170 | } | 1186 | } |
1171 | 1187 | ||
1172 | LExit: | 1188 | LExit: |
@@ -1184,18 +1200,18 @@ static __callback UINT FAR DIAMONDAPI CabCWrite( | |||
1184 | __in_bcount(cb) void FAR *memory, | 1200 | __in_bcount(cb) void FAR *memory, |
1185 | __in UINT cb, | 1201 | __in UINT cb, |
1186 | __out int *err, | 1202 | __out int *err, |
1187 | __out_bcount(CABC_HANDLE_BYTES) void *pv | 1203 | __inout_bcount(CABC_HANDLE_BYTES) void *pv |
1188 | ) | 1204 | ) |
1189 | { | 1205 | { |
1190 | CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv); | 1206 | CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv); |
1191 | HRESULT hr = S_OK; | 1207 | HRESULT hr = S_OK; |
1192 | DWORD cbWrite = 0; | 1208 | DWORD cbWrite = 0; |
1193 | 1209 | ||
1194 | ExitOnNull(hf, *err, E_INVALIDARG, "Failed to write during cabinet extraction because no file handle was provided"); | 1210 | CabcExitOnNull(hf, *err, E_INVALIDARG, "Failed to write during cabinet extraction because no file handle was provided"); |
1195 | if (!::WriteFile(reinterpret_cast<HANDLE>(hf), memory, cb, &cbWrite, NULL)) | 1211 | if (!::WriteFile(reinterpret_cast<HANDLE>(hf), memory, cb, &cbWrite, NULL)) |
1196 | { | 1212 | { |
1197 | *err = ::GetLastError(); | 1213 | *err = ::GetLastError(); |
1198 | ExitOnLastError(hr, "failed to write during cabinet extraction"); | 1214 | CabcExitOnLastError(hr, "failed to write during cabinet extraction"); |
1199 | } | 1215 | } |
1200 | 1216 | ||
1201 | LExit: | 1217 | LExit: |
@@ -1211,7 +1227,7 @@ static __callback long FAR DIAMONDAPI CabCSeek( | |||
1211 | __in long dist, | 1227 | __in long dist, |
1212 | __in int seektype, | 1228 | __in int seektype, |
1213 | __out int *err, | 1229 | __out int *err, |
1214 | __out_bcount(CABC_HANDLE_BYTES) void *pv | 1230 | __inout_bcount(CABC_HANDLE_BYTES) void *pv |
1215 | ) | 1231 | ) |
1216 | { | 1232 | { |
1217 | CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv); | 1233 | CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv); |
@@ -1233,7 +1249,7 @@ static __callback long FAR DIAMONDAPI CabCSeek( | |||
1233 | default : | 1249 | default : |
1234 | dwMoveMethod = 0; | 1250 | dwMoveMethod = 0; |
1235 | hr = E_UNEXPECTED; | 1251 | hr = E_UNEXPECTED; |
1236 | ExitOnFailure(hr, "unexpected seektype in FCISeek(): %d", seektype); | 1252 | CabcExitOnFailure(hr, "unexpected seektype in FCISeek(): %d", seektype); |
1237 | } | 1253 | } |
1238 | 1254 | ||
1239 | // SetFilePointer returns -1 if it fails (this will cause FDI to quit with an FDIERROR_USER_ABORT error. | 1255 | // SetFilePointer returns -1 if it fails (this will cause FDI to quit with an FDIERROR_USER_ABORT error. |
@@ -1243,7 +1259,7 @@ static __callback long FAR DIAMONDAPI CabCSeek( | |||
1243 | if (DWORD_MAX == lMove) | 1259 | if (DWORD_MAX == lMove) |
1244 | { | 1260 | { |
1245 | *err = ::GetLastError(); | 1261 | *err = ::GetLastError(); |
1246 | ExitOnLastError(hr, "failed to move file pointer %d bytes", dist); | 1262 | CabcExitOnLastError(hr, "failed to move file pointer %d bytes", dist); |
1247 | } | 1263 | } |
1248 | 1264 | ||
1249 | LExit: | 1265 | LExit: |
@@ -1259,7 +1275,7 @@ LExit: | |||
1259 | static __callback int FAR DIAMONDAPI CabCClose( | 1275 | static __callback int FAR DIAMONDAPI CabCClose( |
1260 | __in INT_PTR hf, | 1276 | __in INT_PTR hf, |
1261 | __out int *err, | 1277 | __out int *err, |
1262 | __out_bcount(CABC_HANDLE_BYTES) void *pv | 1278 | __inout_bcount(CABC_HANDLE_BYTES) void *pv |
1263 | ) | 1279 | ) |
1264 | { | 1280 | { |
1265 | CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv); | 1281 | CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv); |
@@ -1268,7 +1284,7 @@ static __callback int FAR DIAMONDAPI CabCClose( | |||
1268 | if (!::CloseHandle(reinterpret_cast<HANDLE>(hf))) | 1284 | if (!::CloseHandle(reinterpret_cast<HANDLE>(hf))) |
1269 | { | 1285 | { |
1270 | *err = ::GetLastError(); | 1286 | *err = ::GetLastError(); |
1271 | ExitOnLastError(hr, "failed to close file during cabinet extraction"); | 1287 | CabcExitOnLastError(hr, "failed to close file during cabinet extraction"); |
1272 | } | 1288 | } |
1273 | 1289 | ||
1274 | LExit: | 1290 | LExit: |
@@ -1283,7 +1299,7 @@ LExit: | |||
1283 | static __callback int DIAMONDAPI CabCDelete( | 1299 | static __callback int DIAMONDAPI CabCDelete( |
1284 | __in_z PSTR szFile, | 1300 | __in_z PSTR szFile, |
1285 | __out int *err, | 1301 | __out int *err, |
1286 | __out_bcount(CABC_HANDLE_BYTES) void *pv | 1302 | __inout_bcount(CABC_HANDLE_BYTES) void *pv |
1287 | ) | 1303 | ) |
1288 | { | 1304 | { |
1289 | UNREFERENCED_PARAMETER(err); | 1305 | UNREFERENCED_PARAMETER(err); |
@@ -1302,7 +1318,7 @@ __success(return != FALSE) | |||
1302 | static __callback BOOL DIAMONDAPI CabCGetTempFile( | 1318 | static __callback BOOL DIAMONDAPI CabCGetTempFile( |
1303 | __out_bcount_z(cbFile) char *szFile, | 1319 | __out_bcount_z(cbFile) char *szFile, |
1304 | __in int cbFile, | 1320 | __in int cbFile, |
1305 | __out_bcount(CABC_HANDLE_BYTES) void *pv | 1321 | __inout_bcount(CABC_HANDLE_BYTES) void *pv |
1306 | ) | 1322 | ) |
1307 | { | 1323 | { |
1308 | CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv); | 1324 | CABC_DATA *pcd = reinterpret_cast<CABC_DATA*>(pv); |
@@ -1316,7 +1332,7 @@ static __callback BOOL DIAMONDAPI CabCGetTempFile( | |||
1316 | 1332 | ||
1317 | if (MAX_PATH < ::GetTempPathA(cchTempPath, szTempPath)) | 1333 | if (MAX_PATH < ::GetTempPathA(cchTempPath, szTempPath)) |
1318 | { | 1334 | { |
1319 | ExitWithLastError(hr, "Failed to get temp path during cabinet creation."); | 1335 | CabcExitWithLastError(hr, "Failed to get temp path during cabinet creation."); |
1320 | } | 1336 | } |
1321 | 1337 | ||
1322 | for (DWORD i = 0; i < DWORD_MAX; ++i) | 1338 | for (DWORD i = 0; i < DWORD_MAX; ++i) |
@@ -1324,7 +1340,7 @@ static __callback BOOL DIAMONDAPI CabCGetTempFile( | |||
1324 | LONG dwTempIndex = ::InterlockedIncrement(reinterpret_cast<volatile LONG*>(&dwIndex)); | 1340 | LONG dwTempIndex = ::InterlockedIncrement(reinterpret_cast<volatile LONG*>(&dwIndex)); |
1325 | 1341 | ||
1326 | hr = ::StringCbPrintfA(szFile, cbFile, "%s\\%08x.%03x", szTempPath, dwTempIndex, dwProcessId); | 1342 | hr = ::StringCbPrintfA(szFile, cbFile, "%s\\%08x.%03x", szTempPath, dwTempIndex, dwProcessId); |
1327 | ExitOnFailure(hr, "failed to format log file path."); | 1343 | CabcExitOnFailure(hr, "failed to format log file path."); |
1328 | 1344 | ||
1329 | hTempFile = ::CreateFileA(szFile, 0, FILE_SHARE_DELETE, NULL, CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL); | 1345 | hTempFile = ::CreateFileA(szFile, 0, FILE_SHARE_DELETE, NULL, CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL); |
1330 | if (INVALID_HANDLE_VALUE != hTempFile) | 1346 | if (INVALID_HANDLE_VALUE != hTempFile) |
@@ -1338,7 +1354,7 @@ static __callback BOOL DIAMONDAPI CabCGetTempFile( | |||
1338 | hr = E_FAIL; // this file was taken so be pessimistic and assume we're not going to find one. | 1354 | hr = E_FAIL; // this file was taken so be pessimistic and assume we're not going to find one. |
1339 | } | 1355 | } |
1340 | } | 1356 | } |
1341 | ExitOnFailure(hr, "failed to find temporary file."); | 1357 | CabcExitOnFailure(hr, "failed to find temporary file."); |
1342 | 1358 | ||
1343 | LExit: | 1359 | LExit: |
1344 | ReleaseFileHandle(hTempFile); | 1360 | ReleaseFileHandle(hTempFile); |
@@ -1377,7 +1393,7 @@ static __callback BOOL DIAMONDAPI CabCGetNextCabinet( | |||
1377 | len -= 4; // remove Extention ".cab" of 8.3 Format | 1393 | len -= 4; // remove Extention ".cab" of 8.3 Format |
1378 | } | 1394 | } |
1379 | hr = ::StringCchCatNW(pcd->wzFirstCabinetName, countof(pcd->wzFirstCabinetName), pwzCabinetName, len); | 1395 | hr = ::StringCchCatNW(pcd->wzFirstCabinetName, countof(pcd->wzFirstCabinetName), pwzCabinetName, len); |
1380 | ExitOnFailure(hr, "Failed to remove extension to create next Cabinet File Name"); | 1396 | CabcExitOnFailure(hr, "Failed to remove extension to create next Cabinet File Name"); |
1381 | } | 1397 | } |
1382 | 1398 | ||
1383 | const int nAlphabets = 26; // Number of Alphabets from a to z | 1399 | const int nAlphabets = 26; // Number of Alphabets from a to z |
@@ -1385,9 +1401,9 @@ static __callback BOOL DIAMONDAPI CabCGetNextCabinet( | |||
1385 | { | 1401 | { |
1386 | // Construct next cab names like cab1a.cab, cab1b.cab, cab1c.cab, ........ | 1402 | // Construct next cab names like cab1a.cab, cab1b.cab, cab1c.cab, ........ |
1387 | hr = ::StringCchPrintfA(pccab->szCab, sizeof(pccab->szCab), "%ls%c.cab", pcd->wzFirstCabinetName, char(((int)('a') - 1) + pccab->iCab)); | 1403 | hr = ::StringCchPrintfA(pccab->szCab, sizeof(pccab->szCab), "%ls%c.cab", pcd->wzFirstCabinetName, char(((int)('a') - 1) + pccab->iCab)); |
1388 | ExitOnFailure(hr, "Failed to create next Cabinet File Name"); | 1404 | CabcExitOnFailure(hr, "Failed to create next Cabinet File Name"); |
1389 | hr = ::StringCchPrintfW(wzNewCabName, countof(wzNewCabName), L"%ls%c.cab", pcd->wzFirstCabinetName, WCHAR(((int)('a') - 1) + pccab->iCab)); | 1405 | hr = ::StringCchPrintfW(wzNewCabName, countof(wzNewCabName), L"%ls%c.cab", pcd->wzFirstCabinetName, WCHAR(((int)('a') - 1) + pccab->iCab)); |
1390 | ExitOnFailure(hr, "Failed to create next Cabinet File Name"); | 1406 | CabcExitOnFailure(hr, "Failed to create next Cabinet File Name"); |
1391 | } | 1407 | } |
1392 | else if (pccab->iCab <= nAlphabets*nAlphabets) | 1408 | else if (pccab->iCab <= nAlphabets*nAlphabets) |
1393 | { | 1409 | { |
@@ -1401,14 +1417,14 @@ static __callback BOOL DIAMONDAPI CabCGetNextCabinet( | |||
1401 | char1--; // First Char must be decremented by 1 | 1417 | char1--; // First Char must be decremented by 1 |
1402 | } | 1418 | } |
1403 | hr = ::StringCchPrintfA(pccab->szCab, sizeof(pccab->szCab), "%ls%c%c.cab", pcd->wzFirstCabinetName, char(((int)('a') - 1) + char1), char(((int)('a') - 1) + char2)); | 1419 | hr = ::StringCchPrintfA(pccab->szCab, sizeof(pccab->szCab), "%ls%c%c.cab", pcd->wzFirstCabinetName, char(((int)('a') - 1) + char1), char(((int)('a') - 1) + char2)); |
1404 | ExitOnFailure(hr, "Failed to create next Cabinet File Name"); | 1420 | CabcExitOnFailure(hr, "Failed to create next Cabinet File Name"); |
1405 | hr = ::StringCchPrintfW(wzNewCabName, countof(wzNewCabName), L"%ls%c%c.cab", pcd->wzFirstCabinetName, WCHAR(((int)('a') - 1) + char1), WCHAR(((int)('a') - 1) + char2)); | 1421 | hr = ::StringCchPrintfW(wzNewCabName, countof(wzNewCabName), L"%ls%c%c.cab", pcd->wzFirstCabinetName, WCHAR(((int)('a') - 1) + char1), WCHAR(((int)('a') - 1) + char2)); |
1406 | ExitOnFailure(hr, "Failed to create next Cabinet File Name"); | 1422 | CabcExitOnFailure(hr, "Failed to create next Cabinet File Name"); |
1407 | } | 1423 | } |
1408 | else | 1424 | else |
1409 | { | 1425 | { |
1410 | hr = DISP_E_BADINDEX; // Value 0x8002000B stands for Invalid index. | 1426 | hr = DISP_E_BADINDEX; // Value 0x8002000B stands for Invalid index. |
1411 | ExitOnFailure(hr, "Cannot Split Cabinet more than 26*26 = 676 times. Failed to create next Cabinet File Name"); | 1427 | CabcExitOnFailure(hr, "Cannot Split Cabinet more than 26*26 = 676 times. Failed to create next Cabinet File Name"); |
1412 | } | 1428 | } |
1413 | 1429 | ||
1414 | // Callback from PFNFCIGETNEXTCABINET CabCGetNextCabinet method | 1430 | // Callback from PFNFCIGETNEXTCABINET CabCGetNextCabinet method |
@@ -1478,7 +1494,7 @@ static __callback INT_PTR DIAMONDAPI CabCGetOpenInfo( | |||
1478 | 1494 | ||
1479 | if (!::GetFileAttributesExW(pFileInfo->wzSourcePath, GetFileExInfoStandard, &fad)) | 1495 | if (!::GetFileAttributesExW(pFileInfo->wzSourcePath, GetFileExInfoStandard, &fad)) |
1480 | { | 1496 | { |
1481 | ExitWithLastError(hr, "Failed to get file attributes on '%s'.", pFileInfo->wzSourcePath); | 1497 | CabcExitWithLastError(hr, "Failed to get file attributes on '%ls'.", pFileInfo->wzSourcePath); |
1482 | } | 1498 | } |
1483 | 1499 | ||
1484 | // Set the attributes but only allow the few attributes that CAB supports. | 1500 | // Set the attributes but only allow the few attributes that CAB supports. |
@@ -1492,7 +1508,7 @@ static __callback INT_PTR DIAMONDAPI CabCGetOpenInfo( | |||
1492 | // found. This would create further problems if the file was written to the CAB without this value. Windows | 1508 | // found. This would create further problems if the file was written to the CAB without this value. Windows |
1493 | // Installer would then fail to extract the file. | 1509 | // Installer would then fail to extract the file. |
1494 | hr = UtcFileTimeToLocalDosDateTime(&fad.ftCreationTime, pdate, ptime); | 1510 | hr = UtcFileTimeToLocalDosDateTime(&fad.ftCreationTime, pdate, ptime); |
1495 | ExitOnFailure(hr, "Filed to read a valid file time stucture on file '%s'.", pszName); | 1511 | CabcExitOnFailure(hr, "Filed to read a valid file time stucture on file '%s'.", pszName); |
1496 | } | 1512 | } |
1497 | 1513 | ||
1498 | iResult = CabCOpen(pszFilePlusMagic, _O_BINARY|_O_RDONLY, 0, err, pv); | 1514 | iResult = CabCOpen(pszFilePlusMagic, _O_BINARY|_O_RDONLY, 0, err, pv); |
@@ -1512,7 +1528,7 @@ static __callback long DIAMONDAPI CabCStatus( | |||
1512 | __in UINT ui, | 1528 | __in UINT ui, |
1513 | __in ULONG cb1, | 1529 | __in ULONG cb1, |
1514 | __in ULONG cb2, | 1530 | __in ULONG cb2, |
1515 | __out_bcount(CABC_HANDLE_BYTES) void *pv | 1531 | __inout_bcount(CABC_HANDLE_BYTES) void *pv |
1516 | ) | 1532 | ) |
1517 | { | 1533 | { |
1518 | UNREFERENCED_PARAMETER(ui); | 1534 | UNREFERENCED_PARAMETER(ui); |
diff --git a/src/dutil/cabutil.cpp b/src/dutil/cabutil.cpp index e0efb717..4a6f7b7b 100644 --- a/src/dutil/cabutil.cpp +++ b/src/dutil/cabutil.cpp | |||
@@ -2,6 +2,22 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define CabExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_CABUTIL, x, s, __VA_ARGS__) | ||
8 | #define CabExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_CABUTIL, x, s, __VA_ARGS__) | ||
9 | #define CabExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_CABUTIL, x, s, __VA_ARGS__) | ||
10 | #define CabExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_CABUTIL, x, s, __VA_ARGS__) | ||
11 | #define CabExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_CABUTIL, x, s, __VA_ARGS__) | ||
12 | #define CabExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_CABUTIL, x, s, __VA_ARGS__) | ||
13 | #define CabExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_CABUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define CabExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_CABUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define CabExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_CABUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define CabExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_CABUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define CabExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_CABUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define CabExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_CABUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
5 | // external prototypes | 21 | // external prototypes |
6 | typedef BOOL (FAR DIAMONDAPI *PFNFDIDESTROY)(VOID*); | 22 | typedef BOOL (FAR DIAMONDAPI *PFNFDIDESTROY)(VOID*); |
7 | typedef HFDI (FAR DIAMONDAPI *PFNFDICREATE)(PFNALLOC, PFNFREE, PFNOPEN, PFNREAD, PFNWRITE, PFNCLOSE, PFNSEEK, int, PERF); | 23 | typedef HFDI (FAR DIAMONDAPI *PFNFDICREATE)(PFNALLOC, PFNFREE, PFNOPEN, PFNREAD, PFNWRITE, PFNCLOSE, PFNSEEK, int, PERF); |
@@ -59,20 +75,20 @@ inline HRESULT LoadCabinetDll() | |||
59 | if (!vhCabinetDll) | 75 | if (!vhCabinetDll) |
60 | { | 76 | { |
61 | hr = LoadSystemLibrary(L"cabinet.dll", &vhCabinetDll); | 77 | hr = LoadSystemLibrary(L"cabinet.dll", &vhCabinetDll); |
62 | ExitOnFailure(hr, "failed to load cabinet.dll"); | 78 | CabExitOnFailure(hr, "failed to load cabinet.dll"); |
63 | 79 | ||
64 | // retrieve all address functions | 80 | // retrieve all address functions |
65 | vpfnFDICreate = reinterpret_cast<PFNFDICREATE>(::GetProcAddress(vhCabinetDll, "FDICreate")); | 81 | vpfnFDICreate = reinterpret_cast<PFNFDICREATE>(::GetProcAddress(vhCabinetDll, "FDICreate")); |
66 | ExitOnNullWithLastError(vpfnFDICreate, hr, "failed to import FDICreate from CABINET.DLL"); | 82 | CabExitOnNullWithLastError(vpfnFDICreate, hr, "failed to import FDICreate from CABINET.DLL"); |
67 | vpfnFDICopy = reinterpret_cast<PFNFDICOPY>(::GetProcAddress(vhCabinetDll, "FDICopy")); | 83 | vpfnFDICopy = reinterpret_cast<PFNFDICOPY>(::GetProcAddress(vhCabinetDll, "FDICopy")); |
68 | ExitOnNullWithLastError(vpfnFDICopy, hr, "failed to import FDICopy from CABINET.DLL"); | 84 | CabExitOnNullWithLastError(vpfnFDICopy, hr, "failed to import FDICopy from CABINET.DLL"); |
69 | vpfnFDIIsCabinet = reinterpret_cast<PFNFDIISCABINET>(::GetProcAddress(vhCabinetDll, "FDIIsCabinet")); | 85 | vpfnFDIIsCabinet = reinterpret_cast<PFNFDIISCABINET>(::GetProcAddress(vhCabinetDll, "FDIIsCabinet")); |
70 | ExitOnNullWithLastError(vpfnFDIIsCabinet, hr, "failed to import FDIIsCabinetfrom CABINET.DLL"); | 86 | CabExitOnNullWithLastError(vpfnFDIIsCabinet, hr, "failed to import FDIIsCabinetfrom CABINET.DLL"); |
71 | vpfnFDIDestroy = reinterpret_cast<PFNFDIDESTROY>(::GetProcAddress(vhCabinetDll, "FDIDestroy")); | 87 | vpfnFDIDestroy = reinterpret_cast<PFNFDIDESTROY>(::GetProcAddress(vhCabinetDll, "FDIDestroy")); |
72 | ExitOnNullWithLastError(vpfnFDIDestroy, hr, "failed to import FDIDestroyfrom CABINET.DLL"); | 88 | CabExitOnNullWithLastError(vpfnFDIDestroy, hr, "failed to import FDIDestroyfrom CABINET.DLL"); |
73 | 89 | ||
74 | vhfdi = vpfnFDICreate(CabExtractAlloc, CabExtractFree, CabExtractOpen, CabExtractRead, CabExtractWrite, CabExtractClose, CabExtractSeek, cpuUNKNOWN, &verf); | 90 | vhfdi = vpfnFDICreate(CabExtractAlloc, CabExtractFree, CabExtractOpen, CabExtractRead, CabExtractWrite, CabExtractClose, CabExtractSeek, cpuUNKNOWN, &verf); |
75 | ExitOnNull(vhfdi, hr, E_FAIL, "failed to initialize cabinet.dll"); | 91 | CabExitOnNull(vhfdi, hr, E_FAIL, "failed to initialize cabinet.dll"); |
76 | } | 92 | } |
77 | 93 | ||
78 | LExit: | 94 | LExit: |
@@ -99,7 +115,7 @@ extern "C" HRESULT DAPI CabInitialize( | |||
99 | if (!fDelayLoad) | 115 | if (!fDelayLoad) |
100 | { | 116 | { |
101 | hr = LoadCabinetDll(); | 117 | hr = LoadCabinetDll(); |
102 | ExitOnFailure(hr, "failed to load CABINET.DLL"); | 118 | CabExitOnFailure(hr, "failed to load CABINET.DLL"); |
103 | } | 119 | } |
104 | 120 | ||
105 | LExit: | 121 | LExit: |
@@ -143,8 +159,8 @@ extern "C" void DAPI CabUninitialize( | |||
143 | in the cabinet | 159 | in the cabinet |
144 | ********************************************************************/ | 160 | ********************************************************************/ |
145 | extern "C" HRESULT DAPI CabEnumerate( | 161 | extern "C" HRESULT DAPI CabEnumerate( |
146 | __in LPCWSTR wzCabinet, | 162 | __in_z LPCWSTR wzCabinet, |
147 | __in LPCWSTR wzEnumerateFile, | 163 | __in_z LPCWSTR wzEnumerateFile, |
148 | __in STDCALL_PFNFDINOTIFY pfnNotify, | 164 | __in STDCALL_PFNFDINOTIFY pfnNotify, |
149 | __in DWORD64 dw64EmbeddedOffset | 165 | __in DWORD64 dw64EmbeddedOffset |
150 | ) | 166 | ) |
@@ -161,9 +177,9 @@ extern "C" HRESULT DAPI CabEnumerate( | |||
161 | if pfnBeginFile is NULL pfnEndFile must be NULL and vice versa | 177 | if pfnBeginFile is NULL pfnEndFile must be NULL and vice versa |
162 | ********************************************************************/ | 178 | ********************************************************************/ |
163 | extern "C" HRESULT DAPI CabExtract( | 179 | extern "C" HRESULT DAPI CabExtract( |
164 | __in LPCWSTR wzCabinet, | 180 | __in_z LPCWSTR wzCabinet, |
165 | __in LPCWSTR wzExtractFile, | 181 | __in_z LPCWSTR wzExtractFile, |
166 | __in LPCWSTR wzExtractDir, | 182 | __in_z LPCWSTR wzExtractDir, |
167 | __in_opt CAB_CALLBACK_PROGRESS pfnProgress, | 183 | __in_opt CAB_CALLBACK_PROGRESS pfnProgress, |
168 | __in_opt LPVOID pvContext, | 184 | __in_opt LPVOID pvContext, |
169 | __in DWORD64 dw64EmbeddedOffset | 185 | __in DWORD64 dw64EmbeddedOffset |
@@ -238,21 +254,21 @@ static HRESULT DAPI CabOperation( | |||
238 | if (!vhfdi) | 254 | if (!vhfdi) |
239 | { | 255 | { |
240 | hr = LoadCabinetDll(); | 256 | hr = LoadCabinetDll(); |
241 | ExitOnFailure(hr, "failed to load CABINET.DLL"); | 257 | CabExitOnFailure(hr, "failed to load CABINET.DLL"); |
242 | } | 258 | } |
243 | 259 | ||
244 | hr = StrAllocString(&sczCabinet, wzCabinet, 0); | 260 | hr = StrAllocString(&sczCabinet, wzCabinet, 0); |
245 | ExitOnFailure(hr, "Failed to make copy of cabinet name:%ls", wzCabinet); | 261 | CabExitOnFailure(hr, "Failed to make copy of cabinet name:%ls", wzCabinet); |
246 | 262 | ||
247 | // | 263 | // |
248 | // split the cabinet full path into directory and filename and convert to multi-byte (ick!) | 264 | // split the cabinet full path into directory and filename and convert to multi-byte (ick!) |
249 | // | 265 | // |
250 | pwz = FileFromPath(sczCabinet); | 266 | pwz = FileFromPath(sczCabinet); |
251 | ExitOnNull(pwz, hr, E_INVALIDARG, "failed to process cabinet path: %ls", wzCabinet); | 267 | CabExitOnNull(pwz, hr, E_INVALIDARG, "failed to process cabinet path: %ls", wzCabinet); |
252 | 268 | ||
253 | if (!::WideCharToMultiByte(CP_UTF8, 0, pwz, -1, szCabFile, countof(szCabFile), NULL, NULL)) | 269 | if (!::WideCharToMultiByte(CP_UTF8, 0, pwz, -1, szCabFile, countof(szCabFile), NULL, NULL)) |
254 | { | 270 | { |
255 | ExitWithLastError(hr, "failed to convert cabinet filename to ASCII: %ls", pwz); | 271 | CabExitWithLastError(hr, "failed to convert cabinet filename to ASCII: %ls", pwz); |
256 | } | 272 | } |
257 | 273 | ||
258 | *pwz = '\0'; | 274 | *pwz = '\0'; |
@@ -261,13 +277,13 @@ static HRESULT DAPI CabOperation( | |||
261 | if (wzCabinet == pwz) | 277 | if (wzCabinet == pwz) |
262 | { | 278 | { |
263 | hr = ::StringCchCopyA(szCabDirectory, countof(szCabDirectory), ".\\"); | 279 | hr = ::StringCchCopyA(szCabDirectory, countof(szCabDirectory), ".\\"); |
264 | ExitOnFailure(hr, "Failed to copy relative current directory as cabinet directory."); | 280 | CabExitOnFailure(hr, "Failed to copy relative current directory as cabinet directory."); |
265 | } | 281 | } |
266 | else | 282 | else |
267 | { | 283 | { |
268 | if (!::WideCharToMultiByte(CP_UTF8, 0, sczCabinet, -1, szCabDirectory, countof(szCabDirectory), NULL, NULL)) | 284 | if (!::WideCharToMultiByte(CP_UTF8, 0, sczCabinet, -1, szCabDirectory, countof(szCabDirectory), NULL, NULL)) |
269 | { | 285 | { |
270 | ExitWithLastError(hr, "failed to convert cabinet directory to ASCII: %ls", sczCabinet); | 286 | CabExitWithLastError(hr, "failed to convert cabinet directory to ASCII: %ls", sczCabinet); |
271 | } | 287 | } |
272 | } | 288 | } |
273 | 289 | ||
@@ -295,7 +311,7 @@ static HRESULT DAPI CabOperation( | |||
295 | fResult = vpfnFDICopy(vhfdi, szCabFile, szCabDirectory, 0, pfnFdiNotify, NULL, static_cast<void*>(&ccs)); | 311 | fResult = vpfnFDICopy(vhfdi, szCabFile, szCabDirectory, 0, pfnFdiNotify, NULL, static_cast<void*>(&ccs)); |
296 | if (!fResult && !ccs.fStopExtracting) // if something went wrong and it wasn't us just stopping the extraction, then return a failure | 312 | if (!fResult && !ccs.fStopExtracting) // if something went wrong and it wasn't us just stopping the extraction, then return a failure |
297 | { | 313 | { |
298 | ExitWithLastError(hr, "failed to extract cabinet file: %ls", sczCabinet); | 314 | CabExitWithLastError(hr, "failed to extract cabinet file: %ls", sczCabinet); |
299 | } | 315 | } |
300 | 316 | ||
301 | LExit: | 317 | LExit: |
@@ -331,22 +347,22 @@ static __callback INT_PTR FAR DIAMONDAPI CabExtractOpen(__in_z PSTR pszFile, __i | |||
331 | if ((oflag != (/*_O_BINARY*/ 0x8000 | /*_O_RDONLY*/ 0x0000)) || (pmode != (_S_IREAD | _S_IWRITE))) | 347 | if ((oflag != (/*_O_BINARY*/ 0x8000 | /*_O_RDONLY*/ 0x0000)) || (pmode != (_S_IREAD | _S_IWRITE))) |
332 | { | 348 | { |
333 | hr = E_OUTOFMEMORY; | 349 | hr = E_OUTOFMEMORY; |
334 | ExitOnFailure(hr, "FDI asked for a scratch file to be created, which is unsupported"); | 350 | CabExitOnFailure(hr, "FDI asked for a scratch file to be created, which is unsupported"); |
335 | } | 351 | } |
336 | 352 | ||
337 | hr = StrAllocStringAnsi(&sczCabFile, pszFile, 0, CP_UTF8); | 353 | hr = StrAllocStringAnsi(&sczCabFile, pszFile, 0, CP_UTF8); |
338 | ExitOnFailure(hr, "Failed to convert UTF8 cab file name to wide character string"); | 354 | CabExitOnFailure(hr, "Failed to convert UTF8 cab file name to wide character string"); |
339 | 355 | ||
340 | pFile = reinterpret_cast<INT_PTR>(::CreateFileW(sczCabFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); | 356 | pFile = reinterpret_cast<INT_PTR>(::CreateFileW(sczCabFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); |
341 | if (INVALID_HANDLE_VALUE == reinterpret_cast<HANDLE>(pFile)) | 357 | if (INVALID_HANDLE_VALUE == reinterpret_cast<HANDLE>(pFile)) |
342 | { | 358 | { |
343 | ExitWithLastError(hr, "failed to open file: %ls", sczCabFile); | 359 | CabExitWithLastError(hr, "failed to open file: %ls", sczCabFile); |
344 | } | 360 | } |
345 | 361 | ||
346 | if (vdw64EmbeddedOffset) | 362 | if (vdw64EmbeddedOffset) |
347 | { | 363 | { |
348 | hr = CabExtractSeek(pFile, 0, 0); | 364 | hr = CabExtractSeek(pFile, 0, 0); |
349 | ExitOnFailure(hr, "Failed to seek to embedded offset %I64d", vdw64EmbeddedOffset); | 365 | CabExitOnFailure(hr, "Failed to seek to embedded offset %I64d", vdw64EmbeddedOffset); |
350 | } | 366 | } |
351 | 367 | ||
352 | LExit: | 368 | LExit: |
@@ -361,10 +377,10 @@ static __callback UINT FAR DIAMONDAPI CabExtractRead(__in INT_PTR hf, __out void | |||
361 | HRESULT hr = S_OK; | 377 | HRESULT hr = S_OK; |
362 | DWORD cbRead = 0; | 378 | DWORD cbRead = 0; |
363 | 379 | ||
364 | ExitOnNull(hf, hr, E_INVALIDARG, "Failed to read file during cabinet extraction - no file given to read"); | 380 | CabExitOnNull(hf, hr, E_INVALIDARG, "Failed to read file during cabinet extraction - no file given to read"); |
365 | if (!::ReadFile(reinterpret_cast<HANDLE>(hf), pv, cb, &cbRead, NULL)) | 381 | if (!::ReadFile(reinterpret_cast<HANDLE>(hf), pv, cb, &cbRead, NULL)) |
366 | { | 382 | { |
367 | ExitWithLastError(hr, "failed to read during cabinet extraction"); | 383 | CabExitWithLastError(hr, "failed to read during cabinet extraction"); |
368 | } | 384 | } |
369 | 385 | ||
370 | LExit: | 386 | LExit: |
@@ -377,10 +393,10 @@ static __callback UINT FAR DIAMONDAPI CabExtractWrite(__in INT_PTR hf, __in void | |||
377 | HRESULT hr = S_OK; | 393 | HRESULT hr = S_OK; |
378 | DWORD cbWrite = 0; | 394 | DWORD cbWrite = 0; |
379 | 395 | ||
380 | ExitOnNull(hf, hr, E_INVALIDARG, "Failed to write file during cabinet extraction - no file given to write"); | 396 | CabExitOnNull(hf, hr, E_INVALIDARG, "Failed to write file during cabinet extraction - no file given to write"); |
381 | if (!::WriteFile(reinterpret_cast<HANDLE>(hf), pv, cb, &cbWrite, NULL)) | 397 | if (!::WriteFile(reinterpret_cast<HANDLE>(hf), pv, cb, &cbWrite, NULL)) |
382 | { | 398 | { |
383 | ExitWithLastError(hr, "failed to write during cabinet extraction"); | 399 | CabExitWithLastError(hr, "failed to write during cabinet extraction"); |
384 | } | 400 | } |
385 | 401 | ||
386 | LExit: | 402 | LExit: |
@@ -409,7 +425,7 @@ static __callback long FAR DIAMONDAPI CabExtractSeek(__in INT_PTR hf, __in long | |||
409 | default : | 425 | default : |
410 | dwMoveMethod = 0; | 426 | dwMoveMethod = 0; |
411 | hr = E_UNEXPECTED; | 427 | hr = E_UNEXPECTED; |
412 | ExitOnFailure(hr, "unexpected seektype in FDISeek(): %d", seektype); | 428 | CabExitOnFailure(hr, "unexpected seektype in FDISeek(): %d", seektype); |
413 | } | 429 | } |
414 | 430 | ||
415 | // SetFilePointer returns -1 if it fails (this will cause FDI to quit with an FDIERROR_USER_ABORT error. | 431 | // SetFilePointer returns -1 if it fails (this will cause FDI to quit with an FDIERROR_USER_ABORT error. |
@@ -417,7 +433,7 @@ static __callback long FAR DIAMONDAPI CabExtractSeek(__in INT_PTR hf, __in long | |||
417 | lMove = ::SetFilePointer(reinterpret_cast<HANDLE>(hf), dist, NULL, dwMoveMethod); | 433 | lMove = ::SetFilePointer(reinterpret_cast<HANDLE>(hf), dist, NULL, dwMoveMethod); |
418 | if (0xFFFFFFFF == lMove) | 434 | if (0xFFFFFFFF == lMove) |
419 | { | 435 | { |
420 | ExitWithLastError(hr, "failed to move file pointer %d bytes", dist); | 436 | CabExitWithLastError(hr, "failed to move file pointer %d bytes", dist); |
421 | } | 437 | } |
422 | 438 | ||
423 | LExit: | 439 | LExit: |
@@ -431,7 +447,7 @@ static __callback int FAR DIAMONDAPI CabExtractClose(__in INT_PTR hf) | |||
431 | 447 | ||
432 | if (!::CloseHandle(reinterpret_cast<HANDLE>(hf))) | 448 | if (!::CloseHandle(reinterpret_cast<HANDLE>(hf))) |
433 | { | 449 | { |
434 | ExitWithLastError(hr, "failed to close file during cabinet extraction"); | 450 | CabExitWithLastError(hr, "failed to close file during cabinet extraction"); |
435 | } | 451 | } |
436 | 452 | ||
437 | LExit: | 453 | LExit: |
@@ -454,8 +470,8 @@ static __callback INT_PTR DIAMONDAPI CabExtractCallback(__in FDINOTIFICATIONTYPE | |||
454 | switch (iNotification) | 470 | switch (iNotification) |
455 | { | 471 | { |
456 | case fdintCOPY_FILE: // begin extracting a resource from cabinet | 472 | case fdintCOPY_FILE: // begin extracting a resource from cabinet |
457 | ExitOnNull(pFDINotify->psz1, hr, E_INVALIDARG, "No cabinet file ID given to convert"); | 473 | CabExitOnNull(pFDINotify->psz1, hr, E_INVALIDARG, "No cabinet file ID given to convert"); |
458 | ExitOnNull(pccs, hr, E_INVALIDARG, "Failed to call cabextract callback, because no callback struct was provided"); | 474 | CabExitOnNull(pccs, hr, E_INVALIDARG, "Failed to call cabextract callback, because no callback struct was provided"); |
459 | 475 | ||
460 | if (pccs->fStopExtracting) | 476 | if (pccs->fStopExtracting) |
461 | { | 477 | { |
@@ -466,7 +482,7 @@ static __callback INT_PTR DIAMONDAPI CabExtractCallback(__in FDINOTIFICATIONTYPE | |||
466 | sz = static_cast<LPCSTR>(pFDINotify->psz1); | 482 | sz = static_cast<LPCSTR>(pFDINotify->psz1); |
467 | if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz))) | 483 | if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz))) |
468 | { | 484 | { |
469 | ExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz); | 485 | CabExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz); |
470 | } | 486 | } |
471 | 487 | ||
472 | if (pccs->pfnProgress) | 488 | if (pccs->pfnProgress) |
@@ -484,21 +500,21 @@ static __callback INT_PTR DIAMONDAPI CabExtractCallback(__in FDINOTIFICATIONTYPE | |||
484 | FILETIME ftLocal; | 500 | FILETIME ftLocal; |
485 | if (!::DosDateTimeToFileTime(pFDINotify->date, pFDINotify->time, &ftLocal)) | 501 | if (!::DosDateTimeToFileTime(pFDINotify->date, pFDINotify->time, &ftLocal)) |
486 | { | 502 | { |
487 | ExitWithLastError(hr, "failed to get time for resource: %ls", wz); | 503 | CabExitWithLastError(hr, "failed to get time for resource: %ls", wz); |
488 | } | 504 | } |
489 | ::LocalFileTimeToFileTime(&ftLocal, &ft); | 505 | ::LocalFileTimeToFileTime(&ftLocal, &ft); |
490 | 506 | ||
491 | 507 | ||
492 | WCHAR wzPath[MAX_PATH]; | 508 | WCHAR wzPath[MAX_PATH]; |
493 | hr = ::StringCchCopyW(wzPath, countof(wzPath), pccs->pwzExtractDir); | 509 | hr = ::StringCchCopyW(wzPath, countof(wzPath), pccs->pwzExtractDir); |
494 | ExitOnFailure(hr, "failed to copy in extract directory: %ls for file: %ls", pccs->pwzExtractDir, wz); | 510 | CabExitOnFailure(hr, "failed to copy in extract directory: %ls for file: %ls", pccs->pwzExtractDir, wz); |
495 | hr = ::StringCchCatW(wzPath, countof(wzPath), wz); | 511 | hr = ::StringCchCatW(wzPath, countof(wzPath), wz); |
496 | ExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, wz); | 512 | CabExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, wz); |
497 | 513 | ||
498 | ipResult = reinterpret_cast<INT_PTR>(::CreateFileW(wzPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); | 514 | ipResult = reinterpret_cast<INT_PTR>(::CreateFileW(wzPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); |
499 | if (INVALID_HANDLE_VALUE == reinterpret_cast<HANDLE>(ipResult)) | 515 | if (INVALID_HANDLE_VALUE == reinterpret_cast<HANDLE>(ipResult)) |
500 | { | 516 | { |
501 | ExitWithLastError(hr, "failed to create file: %s", wzPath); | 517 | CabExitWithLastError(hr, "failed to create file: %ls", wzPath); |
502 | } | 518 | } |
503 | 519 | ||
504 | ::SetFileTime(reinterpret_cast<HANDLE>(ipResult), &ft, &ft, &ft); // try to set the file time (who cares if it fails) | 520 | ::SetFileTime(reinterpret_cast<HANDLE>(ipResult), &ft, &ft, &ft); // try to set the file time (who cares if it fails) |
@@ -520,15 +536,15 @@ static __callback INT_PTR DIAMONDAPI CabExtractCallback(__in FDINOTIFICATIONTYPE | |||
520 | break; | 536 | break; |
521 | case fdintCLOSE_FILE_INFO: // resource extraction complete | 537 | case fdintCLOSE_FILE_INFO: // resource extraction complete |
522 | Assert(pFDINotify->hf && pFDINotify->psz1); | 538 | Assert(pFDINotify->hf && pFDINotify->psz1); |
523 | ExitOnNull(pccs, hr, E_INVALIDARG, "Failed to call cabextract callback, because no callback struct was provided"); | 539 | CabExitOnNull(pccs, hr, E_INVALIDARG, "Failed to call cabextract callback, because no callback struct was provided"); |
524 | 540 | ||
525 | // convert params to useful variables | 541 | // convert params to useful variables |
526 | sz = static_cast<LPCSTR>(pFDINotify->psz1); | 542 | sz = static_cast<LPCSTR>(pFDINotify->psz1); |
527 | ExitOnNull(sz, hr, E_INVALIDARG, "Failed to convert cabinet file id, because no cabinet file id was provided"); | 543 | CabExitOnNull(sz, hr, E_INVALIDARG, "Failed to convert cabinet file id, because no cabinet file id was provided"); |
528 | 544 | ||
529 | if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz))) | 545 | if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz))) |
530 | { | 546 | { |
531 | ExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz); | 547 | CabExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz); |
532 | } | 548 | } |
533 | 549 | ||
534 | if (NULL != pFDINotify->hf) // just close the file | 550 | if (NULL != pFDINotify->hf) // just close the file |
diff --git a/src/dutil/certutil.cpp b/src/dutil/certutil.cpp index 9c0ee256..69897b9e 100644 --- a/src/dutil/certutil.cpp +++ b/src/dutil/certutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define CertExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_CERTUTIL, x, s, __VA_ARGS__) | ||
8 | #define CertExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_CERTUTIL, x, s, __VA_ARGS__) | ||
9 | #define CertExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_CERTUTIL, x, s, __VA_ARGS__) | ||
10 | #define CertExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_CERTUTIL, x, s, __VA_ARGS__) | ||
11 | #define CertExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_CERTUTIL, x, s, __VA_ARGS__) | ||
12 | #define CertExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_CERTUTIL, x, s, __VA_ARGS__) | ||
13 | #define CertExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_CERTUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define CertExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_CERTUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define CertExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_CERTUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define CertExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_CERTUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define CertExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_CERTUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define CertExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_CERTUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | /******************************************************************** | 20 | /******************************************************************** |
6 | CertReadProperty - reads a property from the certificate. | 21 | CertReadProperty - reads a property from the certificate. |
7 | 22 | ||
@@ -20,15 +35,15 @@ extern "C" HRESULT DAPI CertReadProperty( | |||
20 | 35 | ||
21 | if (!::CertGetCertificateContextProperty(pCertContext, dwProperty, NULL, &cb)) | 36 | if (!::CertGetCertificateContextProperty(pCertContext, dwProperty, NULL, &cb)) |
22 | { | 37 | { |
23 | ExitWithLastError(hr, "Failed to get size of certificate property."); | 38 | CertExitWithLastError(hr, "Failed to get size of certificate property."); |
24 | } | 39 | } |
25 | 40 | ||
26 | pv = MemAlloc(cb, TRUE); | 41 | pv = MemAlloc(cb, TRUE); |
27 | ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for certificate property."); | 42 | CertExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for certificate property."); |
28 | 43 | ||
29 | if (!::CertGetCertificateContextProperty(pCertContext, dwProperty, pv, &cb)) | 44 | if (!::CertGetCertificateContextProperty(pCertContext, dwProperty, pv, &cb)) |
30 | { | 45 | { |
31 | ExitWithLastError(hr, "Failed to get certificate property."); | 46 | CertExitWithLastError(hr, "Failed to get certificate property."); |
32 | } | 47 | } |
33 | 48 | ||
34 | *ppvValue = pv; | 49 | *ppvValue = pv; |
@@ -70,11 +85,11 @@ extern "C" HRESULT DAPI CertGetAuthenticodeSigningTimestamp( | |||
70 | if (!pBlob) | 85 | if (!pBlob) |
71 | { | 86 | { |
72 | hr = TRUST_E_FAIL; | 87 | hr = TRUST_E_FAIL; |
73 | ExitOnFailure(hr, "Failed to find countersigner in signer information."); | 88 | CertExitOnFailure(hr, "Failed to find countersigner in signer information."); |
74 | } | 89 | } |
75 | 90 | ||
76 | hr = CrypDecodeObject(PKCS7_SIGNER_INFO, pBlob->pbData, pBlob->cbData, 0, reinterpret_cast<LPVOID*>(&pCounterSignerInfo), NULL); | 91 | hr = CrypDecodeObject(PKCS7_SIGNER_INFO, pBlob->pbData, pBlob->cbData, 0, reinterpret_cast<LPVOID*>(&pCounterSignerInfo), NULL); |
77 | ExitOnFailure(hr, "Failed to decode countersigner information."); | 92 | CertExitOnFailure(hr, "Failed to decode countersigner information."); |
78 | 93 | ||
79 | pBlob = NULL; // reset the blob before searching for the signing time. | 94 | pBlob = NULL; // reset the blob before searching for the signing time. |
80 | 95 | ||
@@ -91,12 +106,12 @@ extern "C" HRESULT DAPI CertGetAuthenticodeSigningTimestamp( | |||
91 | if (!pBlob) | 106 | if (!pBlob) |
92 | { | 107 | { |
93 | hr = TRUST_E_FAIL; | 108 | hr = TRUST_E_FAIL; |
94 | ExitOnFailure(hr, "Failed to find signing time in countersigner information."); | 109 | CertExitOnFailure(hr, "Failed to find signing time in countersigner information."); |
95 | } | 110 | } |
96 | 111 | ||
97 | if (!::CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, szOID_RSA_signingTime, pBlob->pbData, pBlob->cbData, 0, pftSigningTimestamp, &cbSigningTimestamp)) | 112 | if (!::CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, szOID_RSA_signingTime, pBlob->pbData, pBlob->cbData, 0, pftSigningTimestamp, &cbSigningTimestamp)) |
98 | { | 113 | { |
99 | ExitWithLastError(hr, "Failed to decode countersigner signing timestamp."); | 114 | CertExitWithLastError(hr, "Failed to decode countersigner signing timestamp."); |
100 | } | 115 | } |
101 | 116 | ||
102 | LExit: | 117 | LExit: |
@@ -124,10 +139,10 @@ extern "C" HRESULT DAPI GetCryptProvFromCert( | |||
124 | GETCRYPTPROVFROMCERTPTR pGetCryptProvFromCert = NULL; | 139 | GETCRYPTPROVFROMCERTPTR pGetCryptProvFromCert = NULL; |
125 | 140 | ||
126 | hr = LoadSystemLibrary(L"MsSign32.dll", &hMsSign32); | 141 | hr = LoadSystemLibrary(L"MsSign32.dll", &hMsSign32); |
127 | ExitOnFailure(hr, "Failed to get handle to MsSign32.dll"); | 142 | CertExitOnFailure(hr, "Failed to get handle to MsSign32.dll"); |
128 | 143 | ||
129 | pGetCryptProvFromCert = (GETCRYPTPROVFROMCERTPTR)::GetProcAddress(hMsSign32, "GetCryptProvFromCert"); | 144 | pGetCryptProvFromCert = (GETCRYPTPROVFROMCERTPTR)::GetProcAddress(hMsSign32, "GetCryptProvFromCert"); |
130 | ExitOnNullWithLastError(hMsSign32, hr, "Failed to get handle to MsSign32.dll"); | 145 | CertExitOnNullWithLastError(hMsSign32, hr, "Failed to get handle to MsSign32.dll"); |
131 | 146 | ||
132 | if (!pGetCryptProvFromCert(hwnd, | 147 | if (!pGetCryptProvFromCert(hwnd, |
133 | pCert, | 148 | pCert, |
@@ -138,7 +153,7 @@ extern "C" HRESULT DAPI GetCryptProvFromCert( | |||
138 | ppwszProviderName, | 153 | ppwszProviderName, |
139 | pdwProviderType)) | 154 | pdwProviderType)) |
140 | { | 155 | { |
141 | ExitWithLastError(hr, "Failed to get CSP from cert."); | 156 | CertExitWithLastError(hr, "Failed to get CSP from cert."); |
142 | } | 157 | } |
143 | LExit: | 158 | LExit: |
144 | return hr; | 159 | return hr; |
@@ -159,10 +174,10 @@ extern "C" HRESULT DAPI FreeCryptProvFromCert( | |||
159 | FREECRYPTPROVFROMCERT pFreeCryptProvFromCert = NULL; | 174 | FREECRYPTPROVFROMCERT pFreeCryptProvFromCert = NULL; |
160 | 175 | ||
161 | hr = LoadSystemLibrary(L"MsSign32.dll", &hMsSign32); | 176 | hr = LoadSystemLibrary(L"MsSign32.dll", &hMsSign32); |
162 | ExitOnFailure(hr, "Failed to get handle to MsSign32.dll"); | 177 | CertExitOnFailure(hr, "Failed to get handle to MsSign32.dll"); |
163 | 178 | ||
164 | pFreeCryptProvFromCert = (FREECRYPTPROVFROMCERT)::GetProcAddress(hMsSign32, "FreeCryptProvFromCert"); | 179 | pFreeCryptProvFromCert = (FREECRYPTPROVFROMCERT)::GetProcAddress(hMsSign32, "FreeCryptProvFromCert"); |
165 | ExitOnNullWithLastError(hMsSign32, hr, "Failed to get handle to MsSign32.dll"); | 180 | CertExitOnNullWithLastError(hMsSign32, hr, "Failed to get handle to MsSign32.dll"); |
166 | 181 | ||
167 | pFreeCryptProvFromCert(fAcquired, hProv, pwszCapiProvider, dwProviderType, pwszTmpContainer); | 182 | pFreeCryptProvFromCert(fAcquired, hProv, pwszCapiProvider, dwProviderType, pwszTmpContainer); |
168 | LExit: | 183 | LExit: |
@@ -185,12 +200,12 @@ extern "C" HRESULT DAPI GetProvSecurityDesc( | |||
185 | &ulSize, | 200 | &ulSize, |
186 | DACL_SECURITY_INFORMATION)) | 201 | DACL_SECURITY_INFORMATION)) |
187 | { | 202 | { |
188 | ExitWithLastError(hr, "Error getting security descriptor size for CSP."); | 203 | CertExitWithLastError(hr, "Error getting security descriptor size for CSP."); |
189 | } | 204 | } |
190 | 205 | ||
191 | // Allocate the memory for the security descriptor. | 206 | // Allocate the memory for the security descriptor. |
192 | pSecurity = static_cast<SECURITY_DESCRIPTOR *>(MemAlloc(ulSize, TRUE)); | 207 | pSecurity = static_cast<SECURITY_DESCRIPTOR *>(MemAlloc(ulSize, TRUE)); |
193 | ExitOnNullWithLastError(pSecurity, hr, "Error allocating memory for CSP DACL"); | 208 | CertExitOnNullWithLastError(pSecurity, hr, "Error allocating memory for CSP DACL"); |
194 | 209 | ||
195 | // Get the security descriptor. | 210 | // Get the security descriptor. |
196 | if (!::CryptGetProvParam( | 211 | if (!::CryptGetProvParam( |
@@ -201,7 +216,7 @@ extern "C" HRESULT DAPI GetProvSecurityDesc( | |||
201 | DACL_SECURITY_INFORMATION)) | 216 | DACL_SECURITY_INFORMATION)) |
202 | { | 217 | { |
203 | MemFree(pSecurity); | 218 | MemFree(pSecurity); |
204 | ExitWithLastError(hr, "Error getting security descriptor for CSP."); | 219 | CertExitWithLastError(hr, "Error getting security descriptor for CSP."); |
205 | } | 220 | } |
206 | *ppSecurity = pSecurity; | 221 | *ppSecurity = pSecurity; |
207 | 222 | ||
@@ -223,7 +238,7 @@ extern "C" HRESULT DAPI SetProvSecurityDesc( | |||
223 | (BYTE*)pSecurity, | 238 | (BYTE*)pSecurity, |
224 | DACL_SECURITY_INFORMATION)) | 239 | DACL_SECURITY_INFORMATION)) |
225 | { | 240 | { |
226 | ExitWithLastError(hr, "Error setting security descriptor for CSP."); | 241 | CertExitWithLastError(hr, "Error setting security descriptor for CSP."); |
227 | } | 242 | } |
228 | LExit: | 243 | LExit: |
229 | return hr; | 244 | return hr; |
@@ -278,12 +293,12 @@ extern "C" HRESULT DAPI CertInstallSingleCertificate( | |||
278 | 293 | ||
279 | if (!::CertSetCertificateContextProperty(pCertContext, CERT_FRIENDLY_NAME_PROP_ID, 0, &blob)) | 294 | if (!::CertSetCertificateContextProperty(pCertContext, CERT_FRIENDLY_NAME_PROP_ID, 0, &blob)) |
280 | { | 295 | { |
281 | ExitWithLastError(hr, "Failed to set the friendly name of the certificate: %ls", wzName); | 296 | CertExitWithLastError(hr, "Failed to set the friendly name of the certificate: %ls", wzName); |
282 | } | 297 | } |
283 | 298 | ||
284 | if (!::CertAddCertificateContextToStore(hStore, pCertContext, CERT_STORE_ADD_REPLACE_EXISTING, NULL)) | 299 | if (!::CertAddCertificateContextToStore(hStore, pCertContext, CERT_STORE_ADD_REPLACE_EXISTING, NULL)) |
285 | { | 300 | { |
286 | ExitWithLastError(hr, "Failed to add certificate to the store."); | 301 | CertExitWithLastError(hr, "Failed to add certificate to the store."); |
287 | } | 302 | } |
288 | 303 | ||
289 | // if the certificate has a private key, grant Administrators access | 304 | // if the certificate has a private key, grant Administrators access |
@@ -293,16 +308,16 @@ extern "C" HRESULT DAPI CertInstallSingleCertificate( | |||
293 | { | 308 | { |
294 | // We added a CSP key | 309 | // We added a CSP key |
295 | hr = GetCryptProvFromCert(NULL, pCertContext, &hCsp, &dwKeySpec, &fAcquired, &pwszTmpContainer, &pwszProviderName, &dwProviderType); | 310 | hr = GetCryptProvFromCert(NULL, pCertContext, &hCsp, &dwKeySpec, &fAcquired, &pwszTmpContainer, &pwszProviderName, &dwProviderType); |
296 | ExitOnFailure(hr, "Failed to get handle to CSP"); | 311 | CertExitOnFailure(hr, "Failed to get handle to CSP"); |
297 | 312 | ||
298 | hr = GetProvSecurityDesc(hCsp, &pSecurity); | 313 | hr = GetProvSecurityDesc(hCsp, &pSecurity); |
299 | ExitOnFailure(hr, "Failed to get security descriptor of CSP"); | 314 | CertExitOnFailure(hr, "Failed to get security descriptor of CSP"); |
300 | 315 | ||
301 | hr = AclAddAdminToSecurityDescriptor(pSecurity, &pSecurityNew); | 316 | hr = AclAddAdminToSecurityDescriptor(pSecurity, &pSecurityNew); |
302 | ExitOnFailure(hr, "Failed to create new security descriptor"); | 317 | CertExitOnFailure(hr, "Failed to create new security descriptor"); |
303 | 318 | ||
304 | hr = SetProvSecurityDesc(hCsp, pSecurityNew); | 319 | hr = SetProvSecurityDesc(hCsp, pSecurityNew); |
305 | ExitOnFailure(hr, "Failed to set Admin ACL on CSP"); | 320 | CertExitOnFailure(hr, "Failed to set Admin ACL on CSP"); |
306 | } | 321 | } |
307 | 322 | ||
308 | if (CERT_NCRYPT_KEY_SPEC == dwKeySpec) | 323 | if (CERT_NCRYPT_KEY_SPEC == dwKeySpec) |
diff --git a/src/dutil/conutil.cpp b/src/dutil/conutil.cpp index 4c820a1c..33e1b59a 100644 --- a/src/dutil/conutil.cpp +++ b/src/dutil/conutil.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | 5 | ||
6 | // Exit macros | ||
7 | #define ConExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_CONUTIL, x, s, __VA_ARGS__) | ||
8 | #define ConExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_CONUTIL, x, s, __VA_ARGS__) | ||
9 | #define ConExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_CONUTIL, x, s, __VA_ARGS__) | ||
10 | #define ConExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_CONUTIL, x, s, __VA_ARGS__) | ||
11 | #define ConExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_CONUTIL, x, s, __VA_ARGS__) | ||
12 | #define ConExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_CONUTIL, x, s, __VA_ARGS__) | ||
13 | #define ConExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_CONUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define ConExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_CONUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define ConExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_CONUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define ConExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_CONUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define ConExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_CONUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define ConExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_CONUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
6 | static HANDLE vhStdIn = INVALID_HANDLE_VALUE; | 21 | static HANDLE vhStdIn = INVALID_HANDLE_VALUE; |
7 | static HANDLE vhStdOut = INVALID_HANDLE_VALUE; | 22 | static HANDLE vhStdOut = INVALID_HANDLE_VALUE; |
8 | static BOOL vfConsoleIn = FALSE; | 23 | static BOOL vfConsoleIn = FALSE; |
@@ -19,13 +34,13 @@ extern "C" HRESULT DAPI ConsoleInitialize() | |||
19 | vhStdIn = ::GetStdHandle(STD_INPUT_HANDLE); | 34 | vhStdIn = ::GetStdHandle(STD_INPUT_HANDLE); |
20 | if (INVALID_HANDLE_VALUE == vhStdIn) | 35 | if (INVALID_HANDLE_VALUE == vhStdIn) |
21 | { | 36 | { |
22 | ExitOnLastError(hr, "failed to open stdin"); | 37 | ConExitOnLastError(hr, "failed to open stdin"); |
23 | } | 38 | } |
24 | 39 | ||
25 | vhStdOut = ::GetStdHandle(STD_OUTPUT_HANDLE); | 40 | vhStdOut = ::GetStdHandle(STD_OUTPUT_HANDLE); |
26 | if (INVALID_HANDLE_VALUE == vhStdOut) | 41 | if (INVALID_HANDLE_VALUE == vhStdOut) |
27 | { | 42 | { |
28 | ExitOnLastError(hr, "failed to open stdout"); | 43 | ConExitOnLastError(hr, "failed to open stdout"); |
29 | } | 44 | } |
30 | 45 | ||
31 | // check if we have a std in on the console | 46 | // check if we have a std in on the console |
@@ -43,7 +58,7 @@ extern "C" HRESULT DAPI ConsoleInitialize() | |||
43 | } | 58 | } |
44 | else | 59 | else |
45 | { | 60 | { |
46 | ExitOnWin32Error(er, hr, "failed to get input console screen buffer info"); | 61 | ConExitOnWin32Error(er, hr, "failed to get input console screen buffer info"); |
47 | } | 62 | } |
48 | } | 63 | } |
49 | 64 | ||
@@ -62,7 +77,7 @@ extern "C" HRESULT DAPI ConsoleInitialize() | |||
62 | } | 77 | } |
63 | else | 78 | else |
64 | { | 79 | { |
65 | ExitOnWin32Error(er, hr, "failed to get output console screen buffer info"); | 80 | ConExitOnWin32Error(er, hr, "failed to get output console screen buffer info"); |
66 | } | 81 | } |
67 | } | 82 | } |
68 | 83 | ||
@@ -89,6 +104,8 @@ LExit: | |||
89 | 104 | ||
90 | extern "C" void DAPI ConsoleUninitialize() | 105 | extern "C" void DAPI ConsoleUninitialize() |
91 | { | 106 | { |
107 | BOOL fOutEqualsIn = vhStdOut == vhStdIn; | ||
108 | |||
92 | memset(&vcsbiInfo, 0, sizeof(vcsbiInfo)); | 109 | memset(&vcsbiInfo, 0, sizeof(vcsbiInfo)); |
93 | 110 | ||
94 | if (INVALID_HANDLE_VALUE != vhStdOut) | 111 | if (INVALID_HANDLE_VALUE != vhStdOut) |
@@ -96,7 +113,7 @@ extern "C" void DAPI ConsoleUninitialize() | |||
96 | ::CloseHandle(vhStdOut); | 113 | ::CloseHandle(vhStdOut); |
97 | } | 114 | } |
98 | 115 | ||
99 | if (INVALID_HANDLE_VALUE != vhStdIn && vhStdOut != vhStdIn) | 116 | if (INVALID_HANDLE_VALUE != vhStdIn && !fOutEqualsIn) |
100 | { | 117 | { |
101 | ::CloseHandle(vhStdIn); | 118 | ::CloseHandle(vhStdIn); |
102 | } | 119 | } |
@@ -178,14 +195,14 @@ extern "C" HRESULT DAPI ConsoleWrite( | |||
178 | va_start(args, szFormat); | 195 | va_start(args, szFormat); |
179 | hr = StrAnsiAllocFormattedArgs(&pszOutput, szFormat, args); | 196 | hr = StrAnsiAllocFormattedArgs(&pszOutput, szFormat, args); |
180 | va_end(args); | 197 | va_end(args); |
181 | ExitOnFailure(hr, "failed to format message: \"%s\"", szFormat); | 198 | ConExitOnFailure(hr, "failed to format message: \"%s\"", szFormat); |
182 | 199 | ||
183 | cchOutput = lstrlenA(pszOutput); | 200 | cchOutput = lstrlenA(pszOutput); |
184 | while (cbTotal < (sizeof(*pszOutput) * cchOutput)) | 201 | while (cbTotal < (sizeof(*pszOutput) * cchOutput)) |
185 | { | 202 | { |
186 | if (!::WriteFile(vhStdOut, reinterpret_cast<BYTE*>(pszOutput) + cbTotal, cchOutput * sizeof(*pszOutput) - cbTotal, &cbWrote, NULL)) | 203 | if (!::WriteFile(vhStdOut, reinterpret_cast<BYTE*>(pszOutput) + cbTotal, cchOutput * sizeof(*pszOutput) - cbTotal, &cbWrote, NULL)) |
187 | { | 204 | { |
188 | ExitOnLastError(hr, "failed to write output to console: %s", pszOutput); | 205 | ConExitOnLastError(hr, "failed to write output to console: %s", pszOutput); |
189 | } | 206 | } |
190 | 207 | ||
191 | cbTotal += cbWrote; | 208 | cbTotal += cbWrote; |
@@ -236,7 +253,7 @@ extern "C" HRESULT DAPI ConsoleWriteLine( | |||
236 | va_start(args, szFormat); | 253 | va_start(args, szFormat); |
237 | hr = StrAnsiAllocFormattedArgs(&pszOutput, szFormat, args); | 254 | hr = StrAnsiAllocFormattedArgs(&pszOutput, szFormat, args); |
238 | va_end(args); | 255 | va_end(args); |
239 | ExitOnFailure(hr, "failed to format message: \"%s\"", szFormat); | 256 | ConExitOnFailure(hr, "failed to format message: \"%s\"", szFormat); |
240 | 257 | ||
241 | // | 258 | // |
242 | // write the string | 259 | // write the string |
@@ -245,7 +262,7 @@ extern "C" HRESULT DAPI ConsoleWriteLine( | |||
245 | while (cbTotal < (sizeof(*pszOutput) * cchOutput)) | 262 | while (cbTotal < (sizeof(*pszOutput) * cchOutput)) |
246 | { | 263 | { |
247 | if (!::WriteFile(vhStdOut, reinterpret_cast<BYTE*>(pszOutput) + cbTotal, cchOutput * sizeof(*pszOutput) - cbTotal, &cbWrote, NULL)) | 264 | if (!::WriteFile(vhStdOut, reinterpret_cast<BYTE*>(pszOutput) + cbTotal, cchOutput * sizeof(*pszOutput) - cbTotal, &cbWrote, NULL)) |
248 | ExitOnLastError(hr, "failed to write output to console: %s", pszOutput); | 265 | ConExitOnLastError(hr, "failed to write output to console: %s", pszOutput); |
249 | 266 | ||
250 | cbTotal += cbWrote; | 267 | cbTotal += cbWrote; |
251 | } | 268 | } |
@@ -255,7 +272,7 @@ extern "C" HRESULT DAPI ConsoleWriteLine( | |||
255 | // | 272 | // |
256 | if (!::WriteFile(vhStdOut, reinterpret_cast<const BYTE*>(szNewLine), 2, &cbWrote, NULL)) | 273 | if (!::WriteFile(vhStdOut, reinterpret_cast<const BYTE*>(szNewLine), 2, &cbWrote, NULL)) |
257 | { | 274 | { |
258 | ExitOnLastError(hr, "failed to write newline to console"); | 275 | ConExitOnLastError(hr, "failed to write newline to console"); |
259 | } | 276 | } |
260 | 277 | ||
261 | // reset the color to normal | 278 | // reset the color to normal |
@@ -289,7 +306,7 @@ HRESULT ConsoleWriteError( | |||
289 | va_start(args, szFormat); | 306 | va_start(args, szFormat); |
290 | hr = StrAnsiAllocFormattedArgs(&pszMessage, szFormat, args); | 307 | hr = StrAnsiAllocFormattedArgs(&pszMessage, szFormat, args); |
291 | va_end(args); | 308 | va_end(args); |
292 | ExitOnFailure(hr, "failed to format error message: \"%s\"", szFormat); | 309 | ConExitOnFailure(hr, "failed to format error message: \"%s\"", szFormat); |
293 | 310 | ||
294 | if (FAILED(hrError)) | 311 | if (FAILED(hrError)) |
295 | { | 312 | { |
@@ -326,14 +343,14 @@ extern "C" HRESULT DAPI ConsoleReadW( | |||
326 | 343 | ||
327 | cch = 64; | 344 | cch = 64; |
328 | hr = StrAnsiAlloc(&psz, cch); | 345 | hr = StrAnsiAlloc(&psz, cch); |
329 | ExitOnFailure(hr, "failed to allocate memory to read from console"); | 346 | ConExitOnFailure(hr, "failed to allocate memory to read from console"); |
330 | 347 | ||
331 | // loop until we read the \r\n from the console | 348 | // loop until we read the \r\n from the console |
332 | for (;;) | 349 | for (;;) |
333 | { | 350 | { |
334 | // read one character at a time, since that seems to be the only way to make this work | 351 | // read one character at a time, since that seems to be the only way to make this work |
335 | if (!::ReadFile(vhStdIn, psz + cchTotalRead, 1, &cchRead, NULL)) | 352 | if (!::ReadFile(vhStdIn, psz + cchTotalRead, 1, &cchRead, NULL)) |
336 | ExitOnLastError(hr, "failed to read string from console"); | 353 | ConExitOnLastError(hr, "failed to read string from console"); |
337 | 354 | ||
338 | cchTotalRead += cchRead; | 355 | cchTotalRead += cchRead; |
339 | if (1 < cchTotalRead && '\r' == psz[cchTotalRead - 2] || '\n' == psz[cchTotalRead - 1]) | 356 | if (1 < cchTotalRead && '\r' == psz[cchTotalRead - 2] || '\n' == psz[cchTotalRead - 1]) |
@@ -351,7 +368,7 @@ extern "C" HRESULT DAPI ConsoleReadW( | |||
351 | { | 368 | { |
352 | cch *= 2; // double everytime we run out of space | 369 | cch *= 2; // double everytime we run out of space |
353 | hr = StrAnsiAlloc(&psz, cch); | 370 | hr = StrAnsiAlloc(&psz, cch); |
354 | ExitOnFailure(hr, "failed to allocate memory to read from console"); | 371 | ConExitOnFailure(hr, "failed to allocate memory to read from console"); |
355 | } | 372 | } |
356 | } | 373 | } |
357 | 374 | ||
@@ -381,7 +398,7 @@ extern "C" HRESULT DAPI ConsoleReadNonBlockingW( | |||
381 | 398 | ||
382 | LPSTR psz = NULL; | 399 | LPSTR psz = NULL; |
383 | 400 | ||
384 | ExitOnNull(ppwzBuffer, hr, E_INVALIDARG, "Failed to read from console because buffer was not provided"); | 401 | ConExitOnNull(ppwzBuffer, hr, E_INVALIDARG, "Failed to read from console because buffer was not provided"); |
385 | 402 | ||
386 | DWORD dwRead; | 403 | DWORD dwRead; |
387 | DWORD dwNumInput; | 404 | DWORD dwNumInput; |
@@ -412,7 +429,7 @@ extern "C" HRESULT DAPI ConsoleReadNonBlockingW( | |||
412 | 429 | ||
413 | if (!GetNumberOfConsoleInputEvents(vhStdIn, &dwRead)) | 430 | if (!GetNumberOfConsoleInputEvents(vhStdIn, &dwRead)) |
414 | { | 431 | { |
415 | ExitOnLastError(hr, "failed to peek at console input"); | 432 | ConExitOnLastError(hr, "failed to peek at console input"); |
416 | } | 433 | } |
417 | 434 | ||
418 | if (0 == dwRead) | 435 | if (0 == dwRead) |
@@ -424,7 +441,7 @@ extern "C" HRESULT DAPI ConsoleReadNonBlockingW( | |||
424 | { | 441 | { |
425 | if (!ReadConsoleInputW(vhStdIn, &ir, 1, &dwNumInput)) | 442 | if (!ReadConsoleInputW(vhStdIn, &ir, 1, &dwNumInput)) |
426 | { | 443 | { |
427 | ExitOnLastError(hr, "Failed to read input from console"); | 444 | ConExitOnLastError(hr, "Failed to read input from console"); |
428 | } | 445 | } |
429 | 446 | ||
430 | // If what we have is a KEY_EVENT, and that event signifies keyUp, we're interested | 447 | // If what we have is a KEY_EVENT, and that event signifies keyUp, we're interested |
@@ -463,14 +480,14 @@ extern "C" HRESULT DAPI ConsoleReadNonBlockingW( | |||
463 | 480 | ||
464 | cch = 8; | 481 | cch = 8; |
465 | hr = StrAnsiAlloc(&psz, cch); | 482 | hr = StrAnsiAlloc(&psz, cch); |
466 | ExitOnFailure(hr, "failed to allocate memory to read from console"); | 483 | ConExitOnFailure(hr, "failed to allocate memory to read from console"); |
467 | 484 | ||
468 | for (/*dwRead from PeekNamedPipe*/; dwRead > 0; dwRead--) | 485 | for (/*dwRead from PeekNamedPipe*/; dwRead > 0; dwRead--) |
469 | { | 486 | { |
470 | // read one character at a time, since that seems to be the only way to make this work | 487 | // read one character at a time, since that seems to be the only way to make this work |
471 | if (!::ReadFile(vhStdIn, psz + cchTotalRead, 1, &cchRead, NULL)) | 488 | if (!::ReadFile(vhStdIn, psz + cchTotalRead, 1, &cchRead, NULL)) |
472 | { | 489 | { |
473 | ExitOnLastError(hr, "failed to read string from console"); | 490 | ConExitOnLastError(hr, "failed to read string from console"); |
474 | } | 491 | } |
475 | 492 | ||
476 | cchTotalRead += cchRead; | 493 | cchTotalRead += cchRead; |
@@ -490,7 +507,7 @@ extern "C" HRESULT DAPI ConsoleReadNonBlockingW( | |||
490 | { | 507 | { |
491 | cch *= 2; // double everytime we run out of space | 508 | cch *= 2; // double everytime we run out of space |
492 | hr = StrAnsiAlloc(&psz, cch); | 509 | hr = StrAnsiAlloc(&psz, cch); |
493 | ExitOnFailure(hr, "failed to allocate memory to read from console"); | 510 | ConExitOnFailure(hr, "failed to allocate memory to read from console"); |
494 | } | 511 | } |
495 | } | 512 | } |
496 | 513 | ||
@@ -510,7 +527,7 @@ LExit: | |||
510 | 527 | ||
511 | *********************************************************************/ | 528 | *********************************************************************/ |
512 | extern "C" HRESULT DAPI ConsoleReadStringA( | 529 | extern "C" HRESULT DAPI ConsoleReadStringA( |
513 | __deref_out_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPSTR* ppszCharBuffer, | 530 | __deref_inout_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPSTR* ppszCharBuffer, |
514 | CONST DWORD cchCharBuffer, | 531 | CONST DWORD cchCharBuffer, |
515 | __out DWORD* pcchNumCharReturn | 532 | __out DWORD* pcchNumCharReturn |
516 | ) | 533 | ) |
@@ -526,11 +543,11 @@ extern "C" HRESULT DAPI ConsoleReadStringA( | |||
526 | do | 543 | do |
527 | { | 544 | { |
528 | hr = StrAnsiAlloc(ppszCharBuffer, cchCharBuffer * iRead); | 545 | hr = StrAnsiAlloc(ppszCharBuffer, cchCharBuffer * iRead); |
529 | ExitOnFailure(hr, "failed to allocate memory for ConsoleReadStringW"); | 546 | ConExitOnFailure(hr, "failed to allocate memory for ConsoleReadStringW"); |
530 | // ReadConsoleW will not return until <Return>, the last two chars are 13 and 10. | 547 | // ReadConsoleW will not return until <Return>, the last two chars are 13 and 10. |
531 | if (!::ReadConsoleA(vhStdIn, *ppszCharBuffer + iReadCharTotal, cchCharBuffer, pcchNumCharReturn, NULL) || *pcchNumCharReturn == 0) | 548 | if (!::ReadConsoleA(vhStdIn, *ppszCharBuffer + iReadCharTotal, cchCharBuffer, pcchNumCharReturn, NULL) || *pcchNumCharReturn == 0) |
532 | { | 549 | { |
533 | ExitOnLastError(hr, "failed to read string from console"); | 550 | ConExitOnLastError(hr, "failed to read string from console"); |
534 | } | 551 | } |
535 | iReadCharTotal += *pcchNumCharReturn; | 552 | iReadCharTotal += *pcchNumCharReturn; |
536 | iRead += 1; | 553 | iRead += 1; |
@@ -543,7 +560,7 @@ extern "C" HRESULT DAPI ConsoleReadStringA( | |||
543 | if (!::ReadConsoleA(vhStdIn, *ppszCharBuffer, cchCharBuffer, pcchNumCharReturn, NULL) || | 560 | if (!::ReadConsoleA(vhStdIn, *ppszCharBuffer, cchCharBuffer, pcchNumCharReturn, NULL) || |
544 | *pcchNumCharReturn > cchCharBuffer || *pcchNumCharReturn == 0) | 561 | *pcchNumCharReturn > cchCharBuffer || *pcchNumCharReturn == 0) |
545 | { | 562 | { |
546 | ExitOnLastError(hr, "failed to read string from console"); | 563 | ConExitOnLastError(hr, "failed to read string from console"); |
547 | } | 564 | } |
548 | if ((*ppszCharBuffer)[*pcchNumCharReturn - 1] != 10 || | 565 | if ((*ppszCharBuffer)[*pcchNumCharReturn - 1] != 10 || |
549 | (*ppszCharBuffer)[*pcchNumCharReturn - 2] != 13) | 566 | (*ppszCharBuffer)[*pcchNumCharReturn - 2] != 13) |
@@ -567,7 +584,7 @@ LExit: | |||
567 | 584 | ||
568 | *********************************************************************/ | 585 | *********************************************************************/ |
569 | extern "C" HRESULT DAPI ConsoleReadStringW( | 586 | extern "C" HRESULT DAPI ConsoleReadStringW( |
570 | __deref_out_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPWSTR* ppwzCharBuffer, | 587 | __deref_inout_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPWSTR* ppwzCharBuffer, |
571 | const DWORD cchCharBuffer, | 588 | const DWORD cchCharBuffer, |
572 | __out DWORD* pcchNumCharReturn | 589 | __out DWORD* pcchNumCharReturn |
573 | ) | 590 | ) |
@@ -583,11 +600,11 @@ extern "C" HRESULT DAPI ConsoleReadStringW( | |||
583 | do | 600 | do |
584 | { | 601 | { |
585 | hr = StrAlloc(ppwzCharBuffer, cchCharBuffer * iRead); | 602 | hr = StrAlloc(ppwzCharBuffer, cchCharBuffer * iRead); |
586 | ExitOnFailure(hr, "failed to allocate memory for ConsoleReadStringW"); | 603 | ConExitOnFailure(hr, "failed to allocate memory for ConsoleReadStringW"); |
587 | // ReadConsoleW will not return until <Return>, the last two chars are 13 and 10. | 604 | // ReadConsoleW will not return until <Return>, the last two chars are 13 and 10. |
588 | if (!::ReadConsoleW(vhStdIn, *ppwzCharBuffer + iReadCharTotal, cchCharBuffer, pcchNumCharReturn, NULL) || *pcchNumCharReturn == 0) | 605 | if (!::ReadConsoleW(vhStdIn, *ppwzCharBuffer + iReadCharTotal, cchCharBuffer, pcchNumCharReturn, NULL) || *pcchNumCharReturn == 0) |
589 | { | 606 | { |
590 | ExitOnLastError(hr, "failed to read string from console"); | 607 | ConExitOnLastError(hr, "failed to read string from console"); |
591 | } | 608 | } |
592 | iReadCharTotal += *pcchNumCharReturn; | 609 | iReadCharTotal += *pcchNumCharReturn; |
593 | iRead += 1; | 610 | iRead += 1; |
@@ -600,7 +617,7 @@ extern "C" HRESULT DAPI ConsoleReadStringW( | |||
600 | if (!::ReadConsoleW(vhStdIn, *ppwzCharBuffer, cchCharBuffer, pcchNumCharReturn, NULL) || | 617 | if (!::ReadConsoleW(vhStdIn, *ppwzCharBuffer, cchCharBuffer, pcchNumCharReturn, NULL) || |
601 | *pcchNumCharReturn > cchCharBuffer || *pcchNumCharReturn == 0) | 618 | *pcchNumCharReturn > cchCharBuffer || *pcchNumCharReturn == 0) |
602 | { | 619 | { |
603 | ExitOnLastError(hr, "failed to read string from console"); | 620 | ConExitOnLastError(hr, "failed to read string from console"); |
604 | } | 621 | } |
605 | if ((*ppwzCharBuffer)[*pcchNumCharReturn - 1] != 10 || | 622 | if ((*ppwzCharBuffer)[*pcchNumCharReturn - 1] != 10 || |
606 | (*ppwzCharBuffer)[*pcchNumCharReturn - 2] != 13) | 623 | (*ppwzCharBuffer)[*pcchNumCharReturn - 2] != 13) |
@@ -630,7 +647,7 @@ extern "C" HRESULT DAPI ConsoleSetReadHidden(void) | |||
630 | ::FlushConsoleInputBuffer(vhStdIn); | 647 | ::FlushConsoleInputBuffer(vhStdIn); |
631 | if (!::SetConsoleMode(vhStdIn, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT)) | 648 | if (!::SetConsoleMode(vhStdIn, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT)) |
632 | { | 649 | { |
633 | ExitOnLastError(hr, "failed to set console input mode to be hidden"); | 650 | ConExitOnLastError(hr, "failed to set console input mode to be hidden"); |
634 | } | 651 | } |
635 | 652 | ||
636 | LExit: | 653 | LExit: |
@@ -647,7 +664,7 @@ extern "C" HRESULT DAPI ConsoleSetReadNormal(void) | |||
647 | HRESULT hr = S_OK; | 664 | HRESULT hr = S_OK; |
648 | if (!::SetConsoleMode(vhStdIn, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT)) | 665 | if (!::SetConsoleMode(vhStdIn, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT)) |
649 | { | 666 | { |
650 | ExitOnLastError(hr, "failed to set console input mode to be normal"); | 667 | ConExitOnLastError(hr, "failed to set console input mode to be normal"); |
651 | } | 668 | } |
652 | 669 | ||
653 | LExit: | 670 | LExit: |
diff --git a/src/dutil/cryputil.cpp b/src/dutil/cryputil.cpp index 214704b4..c5c1b221 100644 --- a/src/dutil/cryputil.cpp +++ b/src/dutil/cryputil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define CrypExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_CRYPUTIL, x, s, __VA_ARGS__) | ||
8 | #define CrypExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_CRYPUTIL, x, s, __VA_ARGS__) | ||
9 | #define CrypExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_CRYPUTIL, x, s, __VA_ARGS__) | ||
10 | #define CrypExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_CRYPUTIL, x, s, __VA_ARGS__) | ||
11 | #define CrypExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_CRYPUTIL, x, s, __VA_ARGS__) | ||
12 | #define CrypExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_CRYPUTIL, x, s, __VA_ARGS__) | ||
13 | #define CrypExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_CRYPUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define CrypExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_CRYPUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define CrypExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_CRYPUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define CrypExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_CRYPUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define CrypExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_CRYPUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define CrypExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_CRYPUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | static PFN_RTLENCRYPTMEMORY vpfnRtlEncryptMemory = NULL; | 20 | static PFN_RTLENCRYPTMEMORY vpfnRtlEncryptMemory = NULL; |
6 | static PFN_RTLDECRYPTMEMORY vpfnRtlDecryptMemory = NULL; | 21 | static PFN_RTLDECRYPTMEMORY vpfnRtlDecryptMemory = NULL; |
7 | static PFN_CRYPTPROTECTMEMORY vpfnCryptProtectMemory = NULL; | 22 | static PFN_CRYPTPROTECTMEMORY vpfnCryptProtectMemory = NULL; |
@@ -32,17 +47,17 @@ extern "C" HRESULT DAPI CrypInitialize( | |||
32 | if (!vpfnRtlEncryptMemory || !vpfnRtlDecryptMemory) | 47 | if (!vpfnRtlEncryptMemory || !vpfnRtlDecryptMemory) |
33 | { | 48 | { |
34 | hr = LoadSystemLibrary(L"Crypt32.dll", &vhCrypt32Dll); | 49 | hr = LoadSystemLibrary(L"Crypt32.dll", &vhCrypt32Dll); |
35 | ExitOnFailure(hr, "Failed to load Crypt32.dll"); | 50 | CrypExitOnFailure(hr, "Failed to load Crypt32.dll"); |
36 | 51 | ||
37 | vpfnCryptProtectMemory = reinterpret_cast<PFN_CRYPTPROTECTMEMORY>(::GetProcAddress(vhCrypt32Dll, "CryptProtectMemory")); | 52 | vpfnCryptProtectMemory = reinterpret_cast<PFN_CRYPTPROTECTMEMORY>(::GetProcAddress(vhCrypt32Dll, "CryptProtectMemory")); |
38 | if (!vpfnRtlEncryptMemory && !vpfnCryptProtectMemory) | 53 | if (!vpfnRtlEncryptMemory && !vpfnCryptProtectMemory) |
39 | { | 54 | { |
40 | ExitWithLastError(hr, "Failed to load an encryption method"); | 55 | CrypExitWithLastError(hr, "Failed to load an encryption method"); |
41 | } | 56 | } |
42 | vpfnCryptUnprotectMemory = reinterpret_cast<PFN_CRYPTUNPROTECTMEMORY>(::GetProcAddress(vhCrypt32Dll, "CryptUnprotectMemory")); | 57 | vpfnCryptUnprotectMemory = reinterpret_cast<PFN_CRYPTUNPROTECTMEMORY>(::GetProcAddress(vhCrypt32Dll, "CryptUnprotectMemory")); |
43 | if (!vpfnRtlDecryptMemory && !vpfnCryptUnprotectMemory) | 58 | if (!vpfnRtlDecryptMemory && !vpfnCryptUnprotectMemory) |
44 | { | 59 | { |
45 | ExitWithLastError(hr, "Failed to load a decryption method"); | 60 | CrypExitWithLastError(hr, "Failed to load a decryption method"); |
46 | } | 61 | } |
47 | } | 62 | } |
48 | 63 | ||
@@ -94,15 +109,15 @@ extern "C" HRESULT DAPI CrypDecodeObject( | |||
94 | 109 | ||
95 | if (!::CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, szStructType, pbData, cbData, dwFlags, NULL, &cbObject)) | 110 | if (!::CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, szStructType, pbData, cbData, dwFlags, NULL, &cbObject)) |
96 | { | 111 | { |
97 | ExitWithLastError(hr, "Failed to decode object to determine size."); | 112 | CrypExitWithLastError(hr, "Failed to decode object to determine size."); |
98 | } | 113 | } |
99 | 114 | ||
100 | pvObject = MemAlloc(cbObject, TRUE); | 115 | pvObject = MemAlloc(cbObject, TRUE); |
101 | ExitOnNull(pvObject, hr, E_OUTOFMEMORY, "Failed to allocate memory for decoded object."); | 116 | CrypExitOnNull(pvObject, hr, E_OUTOFMEMORY, "Failed to allocate memory for decoded object."); |
102 | 117 | ||
103 | if (!::CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, szStructType, pbData, cbData, dwFlags, pvObject, &cbObject)) | 118 | if (!::CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, szStructType, pbData, cbData, dwFlags, pvObject, &cbObject)) |
104 | { | 119 | { |
105 | ExitWithLastError(hr, "Failed to decode object."); | 120 | CrypExitWithLastError(hr, "Failed to decode object."); |
106 | } | 121 | } |
107 | 122 | ||
108 | *ppvObject = pvObject; | 123 | *ppvObject = pvObject; |
@@ -134,15 +149,15 @@ extern "C" HRESULT DAPI CrypMsgGetParam( | |||
134 | 149 | ||
135 | if (!::CryptMsgGetParam(hCryptMsg, dwType, dwIndex, NULL, &cb)) | 150 | if (!::CryptMsgGetParam(hCryptMsg, dwType, dwIndex, NULL, &cb)) |
136 | { | 151 | { |
137 | ExitWithLastError(hr, "Failed to get crypt message parameter data size."); | 152 | CrypExitWithLastError(hr, "Failed to get crypt message parameter data size."); |
138 | } | 153 | } |
139 | 154 | ||
140 | pv = MemAlloc(cb, TRUE); | 155 | pv = MemAlloc(cb, TRUE); |
141 | ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for crypt message parameter."); | 156 | CrypExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for crypt message parameter."); |
142 | 157 | ||
143 | if (!::CryptMsgGetParam(hCryptMsg, dwType, dwIndex, pv, &cb)) | 158 | if (!::CryptMsgGetParam(hCryptMsg, dwType, dwIndex, pv, &cb)) |
144 | { | 159 | { |
145 | ExitWithLastError(hr, "Failed to get crypt message parameter."); | 160 | CrypExitWithLastError(hr, "Failed to get crypt message parameter."); |
146 | } | 161 | } |
147 | 162 | ||
148 | *ppvData = pv; | 163 | *ppvData = pv; |
@@ -161,7 +176,7 @@ LExit: | |||
161 | 176 | ||
162 | 177 | ||
163 | extern "C" HRESULT DAPI CrypHashFile( | 178 | extern "C" HRESULT DAPI CrypHashFile( |
164 | __in LPCWSTR wzFilePath, | 179 | __in_z LPCWSTR wzFilePath, |
165 | __in DWORD dwProvType, | 180 | __in DWORD dwProvType, |
166 | __in ALG_ID algid, | 181 | __in ALG_ID algid, |
167 | __out_bcount(cbHash) BYTE* pbHash, | 182 | __out_bcount(cbHash) BYTE* pbHash, |
@@ -176,11 +191,11 @@ extern "C" HRESULT DAPI CrypHashFile( | |||
176 | hFile = ::CreateFileW(wzFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); | 191 | hFile = ::CreateFileW(wzFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); |
177 | if (INVALID_HANDLE_VALUE == hFile) | 192 | if (INVALID_HANDLE_VALUE == hFile) |
178 | { | 193 | { |
179 | ExitWithLastError(hr, "Failed to open input file."); | 194 | CrypExitWithLastError(hr, "Failed to open input file."); |
180 | } | 195 | } |
181 | 196 | ||
182 | hr = CrypHashFileHandle(hFile, dwProvType, algid, pbHash, cbHash, pqwBytesHashed); | 197 | hr = CrypHashFileHandle(hFile, dwProvType, algid, pbHash, cbHash, pqwBytesHashed); |
183 | ExitOnFailure(hr, "Failed to hash file: %ls", wzFilePath); | 198 | CrypExitOnFailure(hr, "Failed to hash file: %ls", wzFilePath); |
184 | 199 | ||
185 | LExit: | 200 | LExit: |
186 | ReleaseFileHandle(hFile); | 201 | ReleaseFileHandle(hFile); |
@@ -208,13 +223,13 @@ extern "C" HRESULT DAPI CrypHashFileHandle( | |||
208 | // get handle to the crypto provider | 223 | // get handle to the crypto provider |
209 | if (!::CryptAcquireContextW(&hProv, NULL, NULL, dwProvType, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) | 224 | if (!::CryptAcquireContextW(&hProv, NULL, NULL, dwProvType, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) |
210 | { | 225 | { |
211 | ExitWithLastError(hr, "Failed to acquire crypto context."); | 226 | CrypExitWithLastError(hr, "Failed to acquire crypto context."); |
212 | } | 227 | } |
213 | 228 | ||
214 | // initiate hash | 229 | // initiate hash |
215 | if (!::CryptCreateHash(hProv, algid, 0, 0, &hHash)) | 230 | if (!::CryptCreateHash(hProv, algid, 0, 0, &hHash)) |
216 | { | 231 | { |
217 | ExitWithLastError(hr, "Failed to initiate hash."); | 232 | CrypExitWithLastError(hr, "Failed to initiate hash."); |
218 | } | 233 | } |
219 | 234 | ||
220 | for (;;) | 235 | for (;;) |
@@ -222,7 +237,7 @@ extern "C" HRESULT DAPI CrypHashFileHandle( | |||
222 | // read data block | 237 | // read data block |
223 | if (!::ReadFile(hFile, rgbBuffer, sizeof(rgbBuffer), &cbRead, NULL)) | 238 | if (!::ReadFile(hFile, rgbBuffer, sizeof(rgbBuffer), &cbRead, NULL)) |
224 | { | 239 | { |
225 | ExitWithLastError(hr, "Failed to read data block."); | 240 | CrypExitWithLastError(hr, "Failed to read data block."); |
226 | } | 241 | } |
227 | 242 | ||
228 | if (!cbRead) | 243 | if (!cbRead) |
@@ -233,21 +248,21 @@ extern "C" HRESULT DAPI CrypHashFileHandle( | |||
233 | // hash data block | 248 | // hash data block |
234 | if (!::CryptHashData(hHash, rgbBuffer, cbRead, 0)) | 249 | if (!::CryptHashData(hHash, rgbBuffer, cbRead, 0)) |
235 | { | 250 | { |
236 | ExitWithLastError(hr, "Failed to hash data block."); | 251 | CrypExitWithLastError(hr, "Failed to hash data block."); |
237 | } | 252 | } |
238 | } | 253 | } |
239 | 254 | ||
240 | // get hash value | 255 | // get hash value |
241 | if (!::CryptGetHashParam(hHash, HP_HASHVAL, pbHash, &cbHash, 0)) | 256 | if (!::CryptGetHashParam(hHash, HP_HASHVAL, pbHash, &cbHash, 0)) |
242 | { | 257 | { |
243 | ExitWithLastError(hr, "Failed to get hash value."); | 258 | CrypExitWithLastError(hr, "Failed to get hash value."); |
244 | } | 259 | } |
245 | 260 | ||
246 | if (pqwBytesHashed) | 261 | if (pqwBytesHashed) |
247 | { | 262 | { |
248 | if (!::SetFilePointerEx(hFile, liZero, (LARGE_INTEGER*)pqwBytesHashed, FILE_CURRENT)) | 263 | if (!::SetFilePointerEx(hFile, liZero, (LARGE_INTEGER*)pqwBytesHashed, FILE_CURRENT)) |
249 | { | 264 | { |
250 | ExitWithLastError(hr, "Failed to get file pointer."); | 265 | CrypExitWithLastError(hr, "Failed to get file pointer."); |
251 | } | 266 | } |
252 | } | 267 | } |
253 | 268 | ||
@@ -280,24 +295,24 @@ HRESULT DAPI CrypHashBuffer( | |||
280 | // get handle to the crypto provider | 295 | // get handle to the crypto provider |
281 | if (!::CryptAcquireContextW(&hProv, NULL, NULL, dwProvType, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) | 296 | if (!::CryptAcquireContextW(&hProv, NULL, NULL, dwProvType, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) |
282 | { | 297 | { |
283 | ExitWithLastError(hr, "Failed to acquire crypto context."); | 298 | CrypExitWithLastError(hr, "Failed to acquire crypto context."); |
284 | } | 299 | } |
285 | 300 | ||
286 | // initiate hash | 301 | // initiate hash |
287 | if (!::CryptCreateHash(hProv, algid, 0, 0, &hHash)) | 302 | if (!::CryptCreateHash(hProv, algid, 0, 0, &hHash)) |
288 | { | 303 | { |
289 | ExitWithLastError(hr, "Failed to initiate hash."); | 304 | CrypExitWithLastError(hr, "Failed to initiate hash."); |
290 | } | 305 | } |
291 | 306 | ||
292 | if (!::CryptHashData(hHash, pbBuffer, static_cast<DWORD>(cbBuffer), 0)) | 307 | if (!::CryptHashData(hHash, pbBuffer, static_cast<DWORD>(cbBuffer), 0)) |
293 | { | 308 | { |
294 | ExitWithLastError(hr, "Failed to hash data."); | 309 | CrypExitWithLastError(hr, "Failed to hash data."); |
295 | } | 310 | } |
296 | 311 | ||
297 | // get hash value | 312 | // get hash value |
298 | if (!::CryptGetHashParam(hHash, HP_HASHVAL, pbHash, &cbHash, 0)) | 313 | if (!::CryptGetHashParam(hHash, HP_HASHVAL, pbHash, &cbHash, 0)) |
299 | { | 314 | { |
300 | ExitWithLastError(hr, "Failed to get hash value."); | 315 | CrypExitWithLastError(hr, "Failed to get hash value."); |
301 | } | 316 | } |
302 | 317 | ||
303 | LExit: | 318 | LExit: |
@@ -340,7 +355,7 @@ HRESULT DAPI CrypEncryptMemory( | |||
340 | hr = HRESULT_FROM_WIN32(::GetLastError()); | 355 | hr = HRESULT_FROM_WIN32(::GetLastError()); |
341 | } | 356 | } |
342 | } | 357 | } |
343 | ExitOnFailure(hr, "Failed to encrypt memory"); | 358 | CrypExitOnFailure(hr, "Failed to encrypt memory"); |
344 | LExit: | 359 | LExit: |
345 | return hr; | 360 | return hr; |
346 | } | 361 | } |
@@ -372,7 +387,7 @@ HRESULT DAPI CrypDecryptMemory( | |||
372 | hr = HRESULT_FROM_WIN32(::GetLastError()); | 387 | hr = HRESULT_FROM_WIN32(::GetLastError()); |
373 | } | 388 | } |
374 | } | 389 | } |
375 | ExitOnFailure(hr, "Failed to decrypt memory"); | 390 | CrypExitOnFailure(hr, "Failed to decrypt memory"); |
376 | LExit: | 391 | LExit: |
377 | return hr; | 392 | return hr; |
378 | } | 393 | } |
diff --git a/src/dutil/deputil.cpp b/src/dutil/deputil.cpp index d65c4348..362b3345 100644 --- a/src/dutil/deputil.cpp +++ b/src/dutil/deputil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define DepExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DEPUTIL, x, s, __VA_ARGS__) | ||
8 | #define DepExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DEPUTIL, x, s, __VA_ARGS__) | ||
9 | #define DepExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DEPUTIL, x, s, __VA_ARGS__) | ||
10 | #define DepExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DEPUTIL, x, s, __VA_ARGS__) | ||
11 | #define DepExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DEPUTIL, x, s, __VA_ARGS__) | ||
12 | #define DepExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DEPUTIL, x, s, __VA_ARGS__) | ||
13 | #define DepExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DEPUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define DepExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DEPUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define DepExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DEPUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define DepExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DEPUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define DepExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DEPUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define DepExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DEPUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | #define ARRAY_GROWTH_SIZE 5 | 20 | #define ARRAY_GROWTH_SIZE 5 |
6 | 21 | ||
7 | static LPCWSTR vcszVersionValue = L"Version"; | 22 | static LPCWSTR vcszVersionValue = L"Version"; |
@@ -42,7 +57,7 @@ DAPI_(HRESULT) DepGetProviderInformation( | |||
42 | 57 | ||
43 | // Format the provider dependency registry key. | 58 | // Format the provider dependency registry key. |
44 | hr = AllocDependencyKeyName(wzProviderKey, &sczKey); | 59 | hr = AllocDependencyKeyName(wzProviderKey, &sczKey); |
45 | ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); | 60 | DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); |
46 | 61 | ||
47 | // Try to open the dependency key. | 62 | // Try to open the dependency key. |
48 | hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); | 63 | hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); |
@@ -50,7 +65,7 @@ DAPI_(HRESULT) DepGetProviderInformation( | |||
50 | { | 65 | { |
51 | ExitFunction1(hr = E_NOTFOUND); | 66 | ExitFunction1(hr = E_NOTFOUND); |
52 | } | 67 | } |
53 | ExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey); | 68 | DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey); |
54 | 69 | ||
55 | // Get the Id if requested and available. | 70 | // Get the Id if requested and available. |
56 | if (psczId) | 71 | if (psczId) |
@@ -60,7 +75,7 @@ DAPI_(HRESULT) DepGetProviderInformation( | |||
60 | { | 75 | { |
61 | hr = S_OK; | 76 | hr = S_OK; |
62 | } | 77 | } |
63 | ExitOnFailure(hr, "Failed to get the id for the dependency \"%ls\".", wzProviderKey); | 78 | DepExitOnFailure(hr, "Failed to get the id for the dependency \"%ls\".", wzProviderKey); |
64 | } | 79 | } |
65 | 80 | ||
66 | // Get the DisplayName if requested and available. | 81 | // Get the DisplayName if requested and available. |
@@ -71,7 +86,7 @@ DAPI_(HRESULT) DepGetProviderInformation( | |||
71 | { | 86 | { |
72 | hr = S_OK; | 87 | hr = S_OK; |
73 | } | 88 | } |
74 | ExitOnFailure(hr, "Failed to get the name for the dependency \"%ls\".", wzProviderKey); | 89 | DepExitOnFailure(hr, "Failed to get the name for the dependency \"%ls\".", wzProviderKey); |
75 | } | 90 | } |
76 | 91 | ||
77 | // Get the Version if requested and available. | 92 | // Get the Version if requested and available. |
@@ -82,7 +97,7 @@ DAPI_(HRESULT) DepGetProviderInformation( | |||
82 | { | 97 | { |
83 | hr = S_OK; | 98 | hr = S_OK; |
84 | } | 99 | } |
85 | ExitOnFailure(hr, "Failed to get the version for the dependency \"%ls\".", wzProviderKey); | 100 | DepExitOnFailure(hr, "Failed to get the version for the dependency \"%ls\".", wzProviderKey); |
86 | } | 101 | } |
87 | 102 | ||
88 | LExit: | 103 | LExit: |
@@ -116,19 +131,19 @@ DAPI_(HRESULT) DepCheckDependency( | |||
116 | 131 | ||
117 | // Format the provider dependency registry key. | 132 | // Format the provider dependency registry key. |
118 | hr = AllocDependencyKeyName(wzProviderKey, &sczKey); | 133 | hr = AllocDependencyKeyName(wzProviderKey, &sczKey); |
119 | ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); | 134 | DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); |
120 | 135 | ||
121 | // Try to open the key. If that fails, add the missing dependency key to the dependency array if it doesn't already exist. | 136 | // Try to open the key. If that fails, add the missing dependency key to the dependency array if it doesn't already exist. |
122 | hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); | 137 | hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); |
123 | if (E_FILENOTFOUND != hr) | 138 | if (E_FILENOTFOUND != hr) |
124 | { | 139 | { |
125 | ExitOnFailure(hr, "Failed to open the registry key for dependency \"%ls\".", wzProviderKey); | 140 | DepExitOnFailure(hr, "Failed to open the registry key for dependency \"%ls\".", wzProviderKey); |
126 | 141 | ||
127 | // If there are no registry values, consider the key orphaned and treat it as missing. | 142 | // If there are no registry values, consider the key orphaned and treat it as missing. |
128 | hr = RegReadVersion(hkKey, vcszVersionValue, &dw64Version); | 143 | hr = RegReadVersion(hkKey, vcszVersionValue, &dw64Version); |
129 | if (E_FILENOTFOUND != hr) | 144 | if (E_FILENOTFOUND != hr) |
130 | { | 145 | { |
131 | ExitOnFailure(hr, "Failed to read the %ls registry value for dependency \"%ls\".", vcszVersionValue, wzProviderKey); | 146 | DepExitOnFailure(hr, "Failed to read the %ls registry value for dependency \"%ls\".", vcszVersionValue, wzProviderKey); |
132 | } | 147 | } |
133 | } | 148 | } |
134 | 149 | ||
@@ -138,15 +153,15 @@ DAPI_(HRESULT) DepCheckDependency( | |||
138 | hr = DictKeyExists(sdDependencies, wzProviderKey); | 153 | hr = DictKeyExists(sdDependencies, wzProviderKey); |
139 | if (E_NOTFOUND != hr) | 154 | if (E_NOTFOUND != hr) |
140 | { | 155 | { |
141 | ExitOnFailure(hr, "Failed to check the dictionary for missing dependency \"%ls\".", wzProviderKey); | 156 | DepExitOnFailure(hr, "Failed to check the dictionary for missing dependency \"%ls\".", wzProviderKey); |
142 | } | 157 | } |
143 | else | 158 | else |
144 | { | 159 | { |
145 | hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, NULL); | 160 | hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, NULL); |
146 | ExitOnFailure(hr, "Failed to add the missing dependency \"%ls\" to the array.", wzProviderKey); | 161 | DepExitOnFailure(hr, "Failed to add the missing dependency \"%ls\" to the array.", wzProviderKey); |
147 | 162 | ||
148 | hr = DictAddKey(sdDependencies, wzProviderKey); | 163 | hr = DictAddKey(sdDependencies, wzProviderKey); |
149 | ExitOnFailure(hr, "Failed to add the missing dependency \"%ls\" to the dictionary.", wzProviderKey); | 164 | DepExitOnFailure(hr, "Failed to add the missing dependency \"%ls\" to the dictionary.", wzProviderKey); |
150 | } | 165 | } |
151 | 166 | ||
152 | // Exit since the check already failed. | 167 | // Exit since the check already failed. |
@@ -160,7 +175,7 @@ DAPI_(HRESULT) DepCheckDependency( | |||
160 | if (0 < cchMinVersion) | 175 | if (0 < cchMinVersion) |
161 | { | 176 | { |
162 | hr = FileVersionFromStringEx(wzMinVersion, cchMinVersion, &dw64MinVersion); | 177 | hr = FileVersionFromStringEx(wzMinVersion, cchMinVersion, &dw64MinVersion); |
163 | ExitOnFailure(hr, "Failed to get the 64-bit version number from \"%ls\".", wzMinVersion); | 178 | DepExitOnFailure(hr, "Failed to get the 64-bit version number from \"%ls\".", wzMinVersion); |
164 | 179 | ||
165 | fAllowEqual = iAttributes & RequiresAttributesMinVersionInclusive; | 180 | fAllowEqual = iAttributes & RequiresAttributesMinVersionInclusive; |
166 | if (!(fAllowEqual && dw64MinVersion <= dw64Version || dw64MinVersion < dw64Version)) | 181 | if (!(fAllowEqual && dw64MinVersion <= dw64Version || dw64MinVersion < dw64Version)) |
@@ -168,18 +183,18 @@ DAPI_(HRESULT) DepCheckDependency( | |||
168 | hr = DictKeyExists(sdDependencies, wzProviderKey); | 183 | hr = DictKeyExists(sdDependencies, wzProviderKey); |
169 | if (E_NOTFOUND != hr) | 184 | if (E_NOTFOUND != hr) |
170 | { | 185 | { |
171 | ExitOnFailure(hr, "Failed to check the dictionary for the older dependency \"%ls\".", wzProviderKey); | 186 | DepExitOnFailure(hr, "Failed to check the dictionary for the older dependency \"%ls\".", wzProviderKey); |
172 | } | 187 | } |
173 | else | 188 | else |
174 | { | 189 | { |
175 | hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName); | 190 | hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName); |
176 | ExitOnFailure(hr, "Failed to get the display name of the older dependency \"%ls\".", wzProviderKey); | 191 | DepExitOnFailure(hr, "Failed to get the display name of the older dependency \"%ls\".", wzProviderKey); |
177 | 192 | ||
178 | hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName); | 193 | hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName); |
179 | ExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the dependencies array.", wzProviderKey); | 194 | DepExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the dependencies array.", wzProviderKey); |
180 | 195 | ||
181 | hr = DictAddKey(sdDependencies, wzProviderKey); | 196 | hr = DictAddKey(sdDependencies, wzProviderKey); |
182 | ExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the unique dependency string list.", wzProviderKey); | 197 | DepExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the unique dependency string list.", wzProviderKey); |
183 | } | 198 | } |
184 | 199 | ||
185 | // Exit since the check already failed. | 200 | // Exit since the check already failed. |
@@ -195,7 +210,7 @@ DAPI_(HRESULT) DepCheckDependency( | |||
195 | if (0 < cchMaxVersion) | 210 | if (0 < cchMaxVersion) |
196 | { | 211 | { |
197 | hr = FileVersionFromStringEx(wzMaxVersion, cchMaxVersion, &dw64MaxVersion); | 212 | hr = FileVersionFromStringEx(wzMaxVersion, cchMaxVersion, &dw64MaxVersion); |
198 | ExitOnFailure(hr, "Failed to get the 64-bit version number from \"%ls\".", wzMaxVersion); | 213 | DepExitOnFailure(hr, "Failed to get the 64-bit version number from \"%ls\".", wzMaxVersion); |
199 | 214 | ||
200 | fAllowEqual = iAttributes & RequiresAttributesMaxVersionInclusive; | 215 | fAllowEqual = iAttributes & RequiresAttributesMaxVersionInclusive; |
201 | if (!(fAllowEqual && dw64Version <= dw64MaxVersion || dw64Version < dw64MaxVersion)) | 216 | if (!(fAllowEqual && dw64Version <= dw64MaxVersion || dw64Version < dw64MaxVersion)) |
@@ -203,18 +218,18 @@ DAPI_(HRESULT) DepCheckDependency( | |||
203 | hr = DictKeyExists(sdDependencies, wzProviderKey); | 218 | hr = DictKeyExists(sdDependencies, wzProviderKey); |
204 | if (E_NOTFOUND != hr) | 219 | if (E_NOTFOUND != hr) |
205 | { | 220 | { |
206 | ExitOnFailure(hr, "Failed to check the dictionary for the newer dependency \"%ls\".", wzProviderKey); | 221 | DepExitOnFailure(hr, "Failed to check the dictionary for the newer dependency \"%ls\".", wzProviderKey); |
207 | } | 222 | } |
208 | else | 223 | else |
209 | { | 224 | { |
210 | hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName); | 225 | hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName); |
211 | ExitOnFailure(hr, "Failed to get the display name of the newer dependency \"%ls\".", wzProviderKey); | 226 | DepExitOnFailure(hr, "Failed to get the display name of the newer dependency \"%ls\".", wzProviderKey); |
212 | 227 | ||
213 | hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName); | 228 | hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName); |
214 | ExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the dependencies array.", wzProviderKey); | 229 | DepExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the dependencies array.", wzProviderKey); |
215 | 230 | ||
216 | hr = DictAddKey(sdDependencies, wzProviderKey); | 231 | hr = DictAddKey(sdDependencies, wzProviderKey); |
217 | ExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the unique dependency string list.", wzProviderKey); | 232 | DepExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the unique dependency string list.", wzProviderKey); |
218 | } | 233 | } |
219 | 234 | ||
220 | // Exit since the check already failed. | 235 | // Exit since the check already failed. |
@@ -249,17 +264,17 @@ DAPI_(HRESULT) DepCheckDependents( | |||
249 | 264 | ||
250 | // Format the provider dependency registry key. | 265 | // Format the provider dependency registry key. |
251 | hr = AllocDependencyKeyName(wzProviderKey, &sczKey); | 266 | hr = AllocDependencyKeyName(wzProviderKey, &sczKey); |
252 | ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); | 267 | DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); |
253 | 268 | ||
254 | // Try to open the key. If that fails, the dependency information is corrupt. | 269 | // Try to open the key. If that fails, the dependency information is corrupt. |
255 | hr = RegOpen(hkHive, sczKey, KEY_READ, &hkProviderKey); | 270 | hr = RegOpen(hkHive, sczKey, KEY_READ, &hkProviderKey); |
256 | ExitOnFailure(hr, "Failed to open the registry key \"%ls\". The dependency store is corrupt.", sczKey); | 271 | DepExitOnFailure(hr, "Failed to open the registry key \"%ls\". The dependency store is corrupt.", sczKey); |
257 | 272 | ||
258 | // Try to open the dependencies key. If that does not exist, there are no dependents. | 273 | // Try to open the dependencies key. If that does not exist, there are no dependents. |
259 | hr = RegOpen(hkProviderKey, vsczRegistryDependents, KEY_READ, &hkDependentsKey); | 274 | hr = RegOpen(hkProviderKey, vsczRegistryDependents, KEY_READ, &hkDependentsKey); |
260 | if (E_FILENOTFOUND != hr) | 275 | if (E_FILENOTFOUND != hr) |
261 | { | 276 | { |
262 | ExitOnFailure(hr, "Failed to open the registry key for dependents of \"%ls\".", wzProviderKey); | 277 | DepExitOnFailure(hr, "Failed to open the registry key for dependents of \"%ls\".", wzProviderKey); |
263 | } | 278 | } |
264 | else | 279 | else |
265 | { | 280 | { |
@@ -272,7 +287,7 @@ DAPI_(HRESULT) DepCheckDependents( | |||
272 | hr = RegKeyEnum(hkDependentsKey, dwIndex, &sczDependentKey); | 287 | hr = RegKeyEnum(hkDependentsKey, dwIndex, &sczDependentKey); |
273 | if (E_NOMOREITEMS != hr) | 288 | if (E_NOMOREITEMS != hr) |
274 | { | 289 | { |
275 | ExitOnFailure(hr, "Failed to enumerate the dependents key of \"%ls\".", wzProviderKey); | 290 | DepExitOnFailure(hr, "Failed to enumerate the dependents key of \"%ls\".", wzProviderKey); |
276 | } | 291 | } |
277 | else | 292 | else |
278 | { | 293 | { |
@@ -284,16 +299,16 @@ DAPI_(HRESULT) DepCheckDependents( | |||
284 | hr = DictKeyExists(sdIgnoredDependents, sczDependentKey); | 299 | hr = DictKeyExists(sdIgnoredDependents, sczDependentKey); |
285 | if (E_NOTFOUND != hr) | 300 | if (E_NOTFOUND != hr) |
286 | { | 301 | { |
287 | ExitOnFailure(hr, "Failed to check the dictionary of ignored dependents."); | 302 | DepExitOnFailure(hr, "Failed to check the dictionary of ignored dependents."); |
288 | } | 303 | } |
289 | else | 304 | else |
290 | { | 305 | { |
291 | // Get the name of the dependent from the key. | 306 | // Get the name of the dependent from the key. |
292 | hr = GetDependencyNameFromKey(hkHive, sczDependentKey, &sczDependentName); | 307 | hr = GetDependencyNameFromKey(hkHive, sczDependentKey, &sczDependentName); |
293 | ExitOnFailure(hr, "Failed to get the name of the dependent from the key \"%ls\".", sczDependentKey); | 308 | DepExitOnFailure(hr, "Failed to get the name of the dependent from the key \"%ls\".", sczDependentKey); |
294 | 309 | ||
295 | hr = DepDependencyArrayAlloc(prgDependents, pcDependents, sczDependentKey, sczDependentName); | 310 | hr = DepDependencyArrayAlloc(prgDependents, pcDependents, sczDependentKey, sczDependentName); |
296 | ExitOnFailure(hr, "Failed to add the dependent key \"%ls\" to the string array.", sczDependentKey); | 311 | DepExitOnFailure(hr, "Failed to add the dependent key \"%ls\" to the string array.", sczDependentKey); |
297 | } | 312 | } |
298 | } | 313 | } |
299 | 314 | ||
@@ -323,32 +338,32 @@ DAPI_(HRESULT) DepRegisterDependency( | |||
323 | 338 | ||
324 | // Format the provider dependency registry key. | 339 | // Format the provider dependency registry key. |
325 | hr = AllocDependencyKeyName(wzProviderKey, &sczKey); | 340 | hr = AllocDependencyKeyName(wzProviderKey, &sczKey); |
326 | ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); | 341 | DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); |
327 | 342 | ||
328 | // Create the dependency key (or open it if it already exists). | 343 | // Create the dependency key (or open it if it already exists). |
329 | hr = RegCreateEx(hkHive, sczKey, KEY_WRITE, FALSE, NULL, &hkKey, &fCreated); | 344 | hr = RegCreateEx(hkHive, sczKey, KEY_WRITE, FALSE, NULL, &hkKey, &fCreated); |
330 | ExitOnFailure(hr, "Failed to create the dependency registry key \"%ls\".", sczKey); | 345 | DepExitOnFailure(hr, "Failed to create the dependency registry key \"%ls\".", sczKey); |
331 | 346 | ||
332 | // Set the id if it was provided. | 347 | // Set the id if it was provided. |
333 | if (wzId) | 348 | if (wzId) |
334 | { | 349 | { |
335 | hr = RegWriteString(hkKey, NULL, wzId); | 350 | hr = RegWriteString(hkKey, NULL, wzId); |
336 | ExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", L"default", wzId); | 351 | DepExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", L"default", wzId); |
337 | } | 352 | } |
338 | 353 | ||
339 | // Set the version. | 354 | // Set the version. |
340 | hr = RegWriteString(hkKey, vcszVersionValue, wzVersion); | 355 | hr = RegWriteString(hkKey, vcszVersionValue, wzVersion); |
341 | ExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszVersionValue, wzVersion); | 356 | DepExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszVersionValue, wzVersion); |
342 | 357 | ||
343 | // Set the display name. | 358 | // Set the display name. |
344 | hr = RegWriteString(hkKey, vcszDisplayNameValue, wzDisplayName); | 359 | hr = RegWriteString(hkKey, vcszDisplayNameValue, wzDisplayName); |
345 | ExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszDisplayNameValue, wzDisplayName); | 360 | DepExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszDisplayNameValue, wzDisplayName); |
346 | 361 | ||
347 | // Set the attributes if non-zero. | 362 | // Set the attributes if non-zero. |
348 | if (0 != iAttributes) | 363 | if (0 != iAttributes) |
349 | { | 364 | { |
350 | hr = RegWriteNumber(hkKey, vcszAttributesValue, static_cast<DWORD>(iAttributes)); | 365 | hr = RegWriteNumber(hkKey, vcszAttributesValue, static_cast<DWORD>(iAttributes)); |
351 | ExitOnFailure(hr, "Failed to set the %ls registry value to %d.", vcszAttributesValue, iAttributes); | 366 | DepExitOnFailure(hr, "Failed to set the %ls registry value to %d.", vcszAttributesValue, iAttributes); |
352 | } | 367 | } |
353 | 368 | ||
354 | LExit: | 369 | LExit: |
@@ -370,12 +385,12 @@ DAPI_(HRESULT) DepDependentExists( | |||
370 | 385 | ||
371 | // Format the provider dependents registry key. | 386 | // Format the provider dependents registry key. |
372 | hr = StrAllocFormatted(&sczDependentKey, L"%ls%ls\\%ls\\%ls", vsczRegistryRoot, wzDependencyProviderKey, vsczRegistryDependents, wzProviderKey); | 387 | hr = StrAllocFormatted(&sczDependentKey, L"%ls%ls\\%ls\\%ls", vsczRegistryRoot, wzDependencyProviderKey, vsczRegistryDependents, wzProviderKey); |
373 | ExitOnFailure(hr, "Failed to format registry key to dependent."); | 388 | DepExitOnFailure(hr, "Failed to format registry key to dependent."); |
374 | 389 | ||
375 | hr = RegOpen(hkHive, sczDependentKey, KEY_READ, &hkDependentKey); | 390 | hr = RegOpen(hkHive, sczDependentKey, KEY_READ, &hkDependentKey); |
376 | if (E_FILENOTFOUND != hr) | 391 | if (E_FILENOTFOUND != hr) |
377 | { | 392 | { |
378 | ExitOnFailure(hr, "Failed to open the dependent registry key at: \"%ls\".", sczDependentKey); | 393 | DepExitOnFailure(hr, "Failed to open the dependent registry key at: \"%ls\".", sczDependentKey); |
379 | } | 394 | } |
380 | 395 | ||
381 | LExit: | 396 | LExit: |
@@ -403,32 +418,32 @@ DAPI_(HRESULT) DepRegisterDependent( | |||
403 | 418 | ||
404 | // Format the provider dependency registry key. | 419 | // Format the provider dependency registry key. |
405 | hr = AllocDependencyKeyName(wzDependencyProviderKey, &sczDependencyKey); | 420 | hr = AllocDependencyKeyName(wzDependencyProviderKey, &sczDependencyKey); |
406 | ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzDependencyProviderKey); | 421 | DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzDependencyProviderKey); |
407 | 422 | ||
408 | // Create the dependency key (or open it if it already exists). | 423 | // Create the dependency key (or open it if it already exists). |
409 | hr = RegCreateEx(hkHive, sczDependencyKey, KEY_WRITE, FALSE, NULL, &hkDependencyKey, &fCreated); | 424 | hr = RegCreateEx(hkHive, sczDependencyKey, KEY_WRITE, FALSE, NULL, &hkDependencyKey, &fCreated); |
410 | ExitOnFailure(hr, "Failed to create the dependency registry key \"%ls\".", sczDependencyKey); | 425 | DepExitOnFailure(hr, "Failed to create the dependency registry key \"%ls\".", sczDependencyKey); |
411 | 426 | ||
412 | // Create the subkey to register the dependent. | 427 | // Create the subkey to register the dependent. |
413 | hr = StrAllocFormatted(&sczKey, L"%ls\\%ls", vsczRegistryDependents, wzProviderKey); | 428 | hr = StrAllocFormatted(&sczKey, L"%ls\\%ls", vsczRegistryDependents, wzProviderKey); |
414 | ExitOnFailure(hr, "Failed to allocate dependent subkey \"%ls\" under dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey); | 429 | DepExitOnFailure(hr, "Failed to allocate dependent subkey \"%ls\" under dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey); |
415 | 430 | ||
416 | hr = RegCreateEx(hkDependencyKey, sczKey, KEY_WRITE, FALSE, NULL, &hkKey, &fCreated); | 431 | hr = RegCreateEx(hkDependencyKey, sczKey, KEY_WRITE, FALSE, NULL, &hkKey, &fCreated); |
417 | ExitOnFailure(hr, "Failed to create the dependency subkey \"%ls\".", sczKey); | 432 | DepExitOnFailure(hr, "Failed to create the dependency subkey \"%ls\".", sczKey); |
418 | 433 | ||
419 | // Set the minimum version if not NULL. | 434 | // Set the minimum version if not NULL. |
420 | hr = RegWriteString(hkKey, vcszMinVersionValue, wzMinVersion); | 435 | hr = RegWriteString(hkKey, vcszMinVersionValue, wzMinVersion); |
421 | ExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszMinVersionValue, wzMinVersion); | 436 | DepExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszMinVersionValue, wzMinVersion); |
422 | 437 | ||
423 | // Set the maximum version if not NULL. | 438 | // Set the maximum version if not NULL. |
424 | hr = RegWriteString(hkKey, vcszMaxVersionValue, wzMaxVersion); | 439 | hr = RegWriteString(hkKey, vcszMaxVersionValue, wzMaxVersion); |
425 | ExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszMaxVersionValue, wzMaxVersion); | 440 | DepExitOnFailure(hr, "Failed to set the %ls registry value to \"%ls\".", vcszMaxVersionValue, wzMaxVersion); |
426 | 441 | ||
427 | // Set the attributes if non-zero. | 442 | // Set the attributes if non-zero. |
428 | if (0 != iAttributes) | 443 | if (0 != iAttributes) |
429 | { | 444 | { |
430 | hr = RegWriteNumber(hkKey, vcszAttributesValue, static_cast<DWORD>(iAttributes)); | 445 | hr = RegWriteNumber(hkKey, vcszAttributesValue, static_cast<DWORD>(iAttributes)); |
431 | ExitOnFailure(hr, "Failed to set the %ls registry value to %d.", vcszAttributesValue, iAttributes); | 446 | DepExitOnFailure(hr, "Failed to set the %ls registry value to %d.", vcszAttributesValue, iAttributes); |
432 | } | 447 | } |
433 | 448 | ||
434 | LExit: | 449 | LExit: |
@@ -451,13 +466,13 @@ DAPI_(HRESULT) DepUnregisterDependency( | |||
451 | 466 | ||
452 | // Format the provider dependency registry key. | 467 | // Format the provider dependency registry key. |
453 | hr = AllocDependencyKeyName(wzProviderKey, &sczKey); | 468 | hr = AllocDependencyKeyName(wzProviderKey, &sczKey); |
454 | ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); | 469 | DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); |
455 | 470 | ||
456 | // Delete the entire key including all sub-keys. | 471 | // Delete the entire key including all sub-keys. |
457 | hr = RegDelete(hkHive, sczKey, REG_KEY_DEFAULT, TRUE); | 472 | hr = RegDelete(hkHive, sczKey, REG_KEY_DEFAULT, TRUE); |
458 | if (E_FILENOTFOUND != hr) | 473 | if (E_FILENOTFOUND != hr) |
459 | { | 474 | { |
460 | ExitOnFailure(hr, "Failed to delete the key \"%ls\".", sczKey); | 475 | DepExitOnFailure(hr, "Failed to delete the key \"%ls\".", sczKey); |
461 | } | 476 | } |
462 | 477 | ||
463 | LExit: | 478 | LExit: |
@@ -484,7 +499,7 @@ DAPI_(HRESULT) DepUnregisterDependent( | |||
484 | hr = RegOpen(hkHive, vsczRegistryRoot, KEY_READ, &hkRegistryRoot); | 499 | hr = RegOpen(hkHive, vsczRegistryRoot, KEY_READ, &hkRegistryRoot); |
485 | if (E_FILENOTFOUND != hr) | 500 | if (E_FILENOTFOUND != hr) |
486 | { | 501 | { |
487 | ExitOnFailure(hr, "Failed to open root registry key \"%ls\".", vsczRegistryRoot); | 502 | DepExitOnFailure(hr, "Failed to open root registry key \"%ls\".", vsczRegistryRoot); |
488 | } | 503 | } |
489 | else | 504 | else |
490 | { | 505 | { |
@@ -495,7 +510,7 @@ DAPI_(HRESULT) DepUnregisterDependent( | |||
495 | hr = RegOpen(hkRegistryRoot, wzDependencyProviderKey, KEY_READ, &hkDependencyProviderKey); | 510 | hr = RegOpen(hkRegistryRoot, wzDependencyProviderKey, KEY_READ, &hkDependencyProviderKey); |
496 | if (E_FILENOTFOUND != hr) | 511 | if (E_FILENOTFOUND != hr) |
497 | { | 512 | { |
498 | ExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzDependencyProviderKey); | 513 | DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzDependencyProviderKey); |
499 | } | 514 | } |
500 | else | 515 | else |
501 | { | 516 | { |
@@ -506,7 +521,7 @@ DAPI_(HRESULT) DepUnregisterDependent( | |||
506 | hr = RegOpen(hkDependencyProviderKey, vsczRegistryDependents, KEY_READ, &hkRegistryDependents); | 521 | hr = RegOpen(hkDependencyProviderKey, vsczRegistryDependents, KEY_READ, &hkRegistryDependents); |
507 | if (E_FILENOTFOUND != hr) | 522 | if (E_FILENOTFOUND != hr) |
508 | { | 523 | { |
509 | ExitOnFailure(hr, "Failed to open the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey); | 524 | DepExitOnFailure(hr, "Failed to open the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey); |
510 | } | 525 | } |
511 | else | 526 | else |
512 | { | 527 | { |
@@ -515,11 +530,11 @@ DAPI_(HRESULT) DepUnregisterDependent( | |||
515 | 530 | ||
516 | // Delete the wzProviderKey dependent sub-key. | 531 | // Delete the wzProviderKey dependent sub-key. |
517 | hr = RegDelete(hkRegistryDependents, wzProviderKey, REG_KEY_DEFAULT, TRUE); | 532 | hr = RegDelete(hkRegistryDependents, wzProviderKey, REG_KEY_DEFAULT, TRUE); |
518 | ExitOnFailure(hr, "Failed to delete the dependent \"%ls\" under the dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey); | 533 | DepExitOnFailure(hr, "Failed to delete the dependent \"%ls\" under the dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey); |
519 | 534 | ||
520 | // If there are no remaining dependents, delete the Dependents subkey. | 535 | // If there are no remaining dependents, delete the Dependents subkey. |
521 | hr = RegQueryKey(hkRegistryDependents, &cSubKeys, NULL); | 536 | hr = RegQueryKey(hkRegistryDependents, &cSubKeys, NULL); |
522 | ExitOnFailure(hr, "Failed to get the number of dependent subkeys under the dependency \"%ls\".", wzDependencyProviderKey); | 537 | DepExitOnFailure(hr, "Failed to get the number of dependent subkeys under the dependency \"%ls\".", wzDependencyProviderKey); |
523 | 538 | ||
524 | if (0 < cSubKeys) | 539 | if (0 < cSubKeys) |
525 | { | 540 | { |
@@ -531,11 +546,11 @@ DAPI_(HRESULT) DepUnregisterDependent( | |||
531 | 546 | ||
532 | // Fail if there are any subkeys since we just checked. | 547 | // Fail if there are any subkeys since we just checked. |
533 | hr = RegDelete(hkDependencyProviderKey, vsczRegistryDependents, REG_KEY_DEFAULT, FALSE); | 548 | hr = RegDelete(hkDependencyProviderKey, vsczRegistryDependents, REG_KEY_DEFAULT, FALSE); |
534 | ExitOnFailure(hr, "Failed to delete the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey); | 549 | DepExitOnFailure(hr, "Failed to delete the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey); |
535 | 550 | ||
536 | // If there are no values, delete the provider dependency key. | 551 | // If there are no values, delete the provider dependency key. |
537 | hr = RegQueryKey(hkDependencyProviderKey, NULL, &cValues); | 552 | hr = RegQueryKey(hkDependencyProviderKey, NULL, &cValues); |
538 | ExitOnFailure(hr, "Failed to get the number of values under the dependency \"%ls\".", wzDependencyProviderKey); | 553 | DepExitOnFailure(hr, "Failed to get the number of values under the dependency \"%ls\".", wzDependencyProviderKey); |
539 | 554 | ||
540 | if (0 == cValues) | 555 | if (0 == cValues) |
541 | { | 556 | { |
@@ -544,7 +559,7 @@ DAPI_(HRESULT) DepUnregisterDependent( | |||
544 | 559 | ||
545 | // Fail if there are any subkeys since we just checked. | 560 | // Fail if there are any subkeys since we just checked. |
546 | hr = RegDelete(hkRegistryRoot, wzDependencyProviderKey, REG_KEY_DEFAULT, FALSE); | 561 | hr = RegDelete(hkRegistryRoot, wzDependencyProviderKey, REG_KEY_DEFAULT, FALSE); |
547 | ExitOnFailure(hr, "Failed to delete the dependency \"%ls\".", wzDependencyProviderKey); | 562 | DepExitOnFailure(hr, "Failed to delete the dependency \"%ls\".", wzDependencyProviderKey); |
548 | } | 563 | } |
549 | 564 | ||
550 | LExit: | 565 | LExit: |
@@ -567,21 +582,21 @@ DAPI_(HRESULT) DepDependencyArrayAlloc( | |||
567 | DEPENDENCY* pDependency = NULL; | 582 | DEPENDENCY* pDependency = NULL; |
568 | 583 | ||
569 | hr = ::UIntAdd(*pcDependencies, 1, &cRequired); | 584 | hr = ::UIntAdd(*pcDependencies, 1, &cRequired); |
570 | ExitOnFailure(hr, "Failed to increment the number of elements required in the dependency array."); | 585 | DepExitOnFailure(hr, "Failed to increment the number of elements required in the dependency array."); |
571 | 586 | ||
572 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgDependencies), cRequired, sizeof(DEPENDENCY), ARRAY_GROWTH_SIZE); | 587 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgDependencies), cRequired, sizeof(DEPENDENCY), ARRAY_GROWTH_SIZE); |
573 | ExitOnFailure(hr, "Failed to allocate memory for the dependency array."); | 588 | DepExitOnFailure(hr, "Failed to allocate memory for the dependency array."); |
574 | 589 | ||
575 | pDependency = static_cast<DEPENDENCY*>(&(*prgDependencies)[*pcDependencies]); | 590 | pDependency = static_cast<DEPENDENCY*>(&(*prgDependencies)[*pcDependencies]); |
576 | ExitOnNull(pDependency, hr, E_POINTER, "The dependency element in the array is invalid."); | 591 | DepExitOnNull(pDependency, hr, E_POINTER, "The dependency element in the array is invalid."); |
577 | 592 | ||
578 | hr = StrAllocString(&(pDependency->sczKey), wzKey, 0); | 593 | hr = StrAllocString(&(pDependency->sczKey), wzKey, 0); |
579 | ExitOnFailure(hr, "Failed to allocate the string key in the dependency array."); | 594 | DepExitOnFailure(hr, "Failed to allocate the string key in the dependency array."); |
580 | 595 | ||
581 | if (wzName) | 596 | if (wzName) |
582 | { | 597 | { |
583 | hr = StrAllocString(&(pDependency->sczName), wzName, 0); | 598 | hr = StrAllocString(&(pDependency->sczName), wzName, 0); |
584 | ExitOnFailure(hr, "Failed to allocate the string name in the dependency array."); | 599 | DepExitOnFailure(hr, "Failed to allocate the string name in the dependency array."); |
585 | } | 600 | } |
586 | 601 | ||
587 | // Update the number of current elements in the dependency array. | 602 | // Update the number of current elements in the dependency array. |
@@ -623,18 +638,18 @@ static HRESULT AllocDependencyKeyName( | |||
623 | 638 | ||
624 | // Get the length of the dependency, and add to the length of the root. | 639 | // Get the length of the dependency, and add to the length of the root. |
625 | hr = ::StringCchLengthW(wzName, STRSAFE_MAX_CCH, &cchName); | 640 | hr = ::StringCchLengthW(wzName, STRSAFE_MAX_CCH, &cchName); |
626 | ExitOnFailure(hr, "Failed to get string length of dependency name."); | 641 | DepExitOnFailure(hr, "Failed to get string length of dependency name."); |
627 | 642 | ||
628 | // Add the sizes together to allocate memory once (callee will add space for nul). | 643 | // Add the sizes together to allocate memory once (callee will add space for nul). |
629 | hr = ::SizeTAdd(cchRegistryRoot, cchName, &cchKeyName); | 644 | hr = ::SizeTAdd(cchRegistryRoot, cchName, &cchKeyName); |
630 | ExitOnFailure(hr, "Failed to add the string lengths together."); | 645 | DepExitOnFailure(hr, "Failed to add the string lengths together."); |
631 | 646 | ||
632 | // Allocate and concat the strings together. | 647 | // Allocate and concat the strings together. |
633 | hr = StrAllocString(psczKeyName, vsczRegistryRoot, cchKeyName); | 648 | hr = StrAllocString(psczKeyName, vsczRegistryRoot, cchKeyName); |
634 | ExitOnFailure(hr, "Failed to allocate string for dependency registry root."); | 649 | DepExitOnFailure(hr, "Failed to allocate string for dependency registry root."); |
635 | 650 | ||
636 | hr = StrAllocConcat(psczKeyName, wzName, cchName); | 651 | hr = StrAllocConcat(psczKeyName, wzName, cchName); |
637 | ExitOnFailure(hr, "Failed to concatenate the dependency key name."); | 652 | DepExitOnFailure(hr, "Failed to concatenate the dependency key name."); |
638 | 653 | ||
639 | LExit: | 654 | LExit: |
640 | return hr; | 655 | return hr; |
@@ -656,13 +671,13 @@ static HRESULT GetDependencyNameFromKey( | |||
656 | 671 | ||
657 | // Format the provider dependency registry key. | 672 | // Format the provider dependency registry key. |
658 | hr = AllocDependencyKeyName(wzProviderKey, &sczKey); | 673 | hr = AllocDependencyKeyName(wzProviderKey, &sczKey); |
659 | ExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); | 674 | DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); |
660 | 675 | ||
661 | // Try to open the dependency key. | 676 | // Try to open the dependency key. |
662 | hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); | 677 | hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); |
663 | if (E_FILENOTFOUND != hr) | 678 | if (E_FILENOTFOUND != hr) |
664 | { | 679 | { |
665 | ExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey); | 680 | DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey); |
666 | } | 681 | } |
667 | else | 682 | else |
668 | { | 683 | { |
@@ -673,7 +688,7 @@ static HRESULT GetDependencyNameFromKey( | |||
673 | hr = RegReadString(hkKey, vcszDisplayNameValue, psczName); | 688 | hr = RegReadString(hkKey, vcszDisplayNameValue, psczName); |
674 | if (E_FILENOTFOUND != hr) | 689 | if (E_FILENOTFOUND != hr) |
675 | { | 690 | { |
676 | ExitOnFailure(hr, "Failed to get the dependency name for the dependency \"%ls\".", wzProviderKey); | 691 | DepExitOnFailure(hr, "Failed to get the dependency name for the dependency \"%ls\".", wzProviderKey); |
677 | } | 692 | } |
678 | else | 693 | else |
679 | { | 694 | { |
diff --git a/src/dutil/dictutil.cpp b/src/dutil/dictutil.cpp index 1f0f9e43..0d0743eb 100644 --- a/src/dutil/dictutil.cpp +++ b/src/dutil/dictutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define DictExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__) | ||
8 | #define DictExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__) | ||
9 | #define DictExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__) | ||
10 | #define DictExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__) | ||
11 | #define DictExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__) | ||
12 | #define DictExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__) | ||
13 | #define DictExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DICTUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define DictExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DICTUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define DictExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DICTUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define DictExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DICTUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define DictExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DICTUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define DictExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DICTUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | // These should all be primes, and spaced reasonably apart (currently each is about 4x the last) | 20 | // These should all be primes, and spaced reasonably apart (currently each is about 4x the last) |
6 | const DWORD MAX_BUCKET_SIZES[] = { | 21 | const DWORD MAX_BUCKET_SIZES[] = { |
7 | 503, | 22 | 503, |
@@ -61,7 +76,7 @@ static HRESULT StringHash( | |||
61 | __in const STRINGDICT_STRUCT *psd, | 76 | __in const STRINGDICT_STRUCT *psd, |
62 | __in DWORD dwNumBuckets, | 77 | __in DWORD dwNumBuckets, |
63 | __in_z LPCWSTR pszString, | 78 | __in_z LPCWSTR pszString, |
64 | __out LPDWORD pdwHash | 79 | __out DWORD *pdwHash |
65 | ); | 80 | ); |
66 | static BOOL IsMatchExact( | 81 | static BOOL IsMatchExact( |
67 | __in const STRINGDICT_STRUCT *psd, | 82 | __in const STRINGDICT_STRUCT *psd, |
@@ -122,11 +137,11 @@ extern "C" HRESULT DAPI DictCreateWithEmbeddedKey( | |||
122 | { | 137 | { |
123 | HRESULT hr = S_OK; | 138 | HRESULT hr = S_OK; |
124 | 139 | ||
125 | ExitOnNull(psdHandle, hr, E_INVALIDARG, "Handle not specified while creating dict"); | 140 | DictExitOnNull(psdHandle, hr, E_INVALIDARG, "Handle not specified while creating dict"); |
126 | 141 | ||
127 | // Allocate the handle | 142 | // Allocate the handle |
128 | *psdHandle = static_cast<STRINGDICT_HANDLE>(MemAlloc(sizeof(STRINGDICT_STRUCT), FALSE)); | 143 | *psdHandle = static_cast<STRINGDICT_HANDLE>(MemAlloc(sizeof(STRINGDICT_STRUCT), FALSE)); |
129 | ExitOnNull(*psdHandle, hr, E_OUTOFMEMORY, "Failed to allocate dictionary object"); | 144 | DictExitOnNull(*psdHandle, hr, E_OUTOFMEMORY, "Failed to allocate dictionary object"); |
130 | 145 | ||
131 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(*psdHandle); | 146 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(*psdHandle); |
132 | 147 | ||
@@ -151,7 +166,7 @@ extern "C" HRESULT DAPI DictCreateWithEmbeddedKey( | |||
151 | 166 | ||
152 | // Finally, allocate our initial buckets | 167 | // Finally, allocate our initial buckets |
153 | psd->ppvBuckets = static_cast<void**>(MemAlloc(sizeof(void *) * MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], TRUE)); | 168 | psd->ppvBuckets = static_cast<void**>(MemAlloc(sizeof(void *) * MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], TRUE)); |
154 | ExitOnNull(psd->ppvBuckets, hr, E_OUTOFMEMORY, "Failed to allocate buckets for dictionary"); | 169 | DictExitOnNull(psd->ppvBuckets, hr, E_OUTOFMEMORY, "Failed to allocate buckets for dictionary"); |
155 | 170 | ||
156 | LExit: | 171 | LExit: |
157 | return hr; | 172 | return hr; |
@@ -166,11 +181,11 @@ extern "C" HRESULT DAPI DictCreateStringList( | |||
166 | { | 181 | { |
167 | HRESULT hr = S_OK; | 182 | HRESULT hr = S_OK; |
168 | 183 | ||
169 | ExitOnNull(psdHandle, hr, E_INVALIDARG, "Handle not specified while creating dict"); | 184 | DictExitOnNull(psdHandle, hr, E_INVALIDARG, "Handle not specified while creating dict"); |
170 | 185 | ||
171 | // Allocate the handle | 186 | // Allocate the handle |
172 | *psdHandle = static_cast<STRINGDICT_HANDLE>(MemAlloc(sizeof(STRINGDICT_STRUCT), FALSE)); | 187 | *psdHandle = static_cast<STRINGDICT_HANDLE>(MemAlloc(sizeof(STRINGDICT_STRUCT), FALSE)); |
173 | ExitOnNull(*psdHandle, hr, E_OUTOFMEMORY, "Failed to allocate dictionary object"); | 188 | DictExitOnNull(*psdHandle, hr, E_OUTOFMEMORY, "Failed to allocate dictionary object"); |
174 | 189 | ||
175 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(*psdHandle); | 190 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(*psdHandle); |
176 | 191 | ||
@@ -195,7 +210,7 @@ extern "C" HRESULT DAPI DictCreateStringList( | |||
195 | 210 | ||
196 | // Finally, allocate our initial buckets | 211 | // Finally, allocate our initial buckets |
197 | psd->ppvBuckets = static_cast<void**>(MemAlloc(sizeof(void *) * MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], TRUE)); | 212 | psd->ppvBuckets = static_cast<void**>(MemAlloc(sizeof(void *) * MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], TRUE)); |
198 | ExitOnNull(psd->ppvBuckets, hr, E_OUTOFMEMORY, "Failed to allocate buckets for dictionary"); | 213 | DictExitOnNull(psd->ppvBuckets, hr, E_OUTOFMEMORY, "Failed to allocate buckets for dictionary"); |
199 | 214 | ||
200 | LExit: | 215 | LExit: |
201 | return hr; | 216 | return hr; |
@@ -212,7 +227,7 @@ extern "C" HRESULT DAPI DictCreateStringListFromArray( | |||
212 | STRINGDICT_HANDLE sd = NULL; | 227 | STRINGDICT_HANDLE sd = NULL; |
213 | 228 | ||
214 | hr = DictCreateStringList(&sd, cStringArray, dfFlags); | 229 | hr = DictCreateStringList(&sd, cStringArray, dfFlags); |
215 | ExitOnFailure(hr, "Failed to create the string dictionary."); | 230 | DictExitOnFailure(hr, "Failed to create the string dictionary."); |
216 | 231 | ||
217 | for (DWORD i = 0; i < cStringArray; ++i) | 232 | for (DWORD i = 0; i < cStringArray; ++i) |
218 | { | 233 | { |
@@ -221,12 +236,12 @@ extern "C" HRESULT DAPI DictCreateStringListFromArray( | |||
221 | hr = DictKeyExists(sd, wzKey); | 236 | hr = DictKeyExists(sd, wzKey); |
222 | if (E_NOTFOUND != hr) | 237 | if (E_NOTFOUND != hr) |
223 | { | 238 | { |
224 | ExitOnFailure(hr, "Failed to check the string dictionary."); | 239 | DictExitOnFailure(hr, "Failed to check the string dictionary."); |
225 | } | 240 | } |
226 | else | 241 | else |
227 | { | 242 | { |
228 | hr = DictAddKey(sd, wzKey); | 243 | hr = DictAddKey(sd, wzKey); |
229 | ExitOnFailure(hr, "Failed to add \"%ls\" to the string dictionary.", wzKey); | 244 | DictExitOnFailure(hr, "Failed to add \"%ls\" to the string dictionary.", wzKey); |
230 | } | 245 | } |
231 | } | 246 | } |
232 | 247 | ||
@@ -252,7 +267,7 @@ extern "C" HRESULT DAPI DictCompareStringListToArray( | |||
252 | hr = DictKeyExists(sdStringList, rgwzStringArray[i]); | 267 | hr = DictKeyExists(sdStringList, rgwzStringArray[i]); |
253 | if (E_NOTFOUND != hr) | 268 | if (E_NOTFOUND != hr) |
254 | { | 269 | { |
255 | ExitOnFailure(hr, "Failed to check the string dictionary."); | 270 | DictExitOnFailure(hr, "Failed to check the string dictionary."); |
256 | ExitFunction1(hr = S_OK); | 271 | ExitFunction1(hr = S_OK); |
257 | } | 272 | } |
258 | } | 273 | } |
@@ -273,19 +288,19 @@ extern "C" HRESULT DAPI DictAddKey( | |||
273 | DWORD dwIndex = 0; | 288 | DWORD dwIndex = 0; |
274 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(sdHandle); | 289 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(sdHandle); |
275 | 290 | ||
276 | ExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while adding value to dict"); | 291 | DictExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while adding value to dict"); |
277 | ExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while adding value to dict"); | 292 | DictExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while adding value to dict"); |
278 | 293 | ||
279 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) | 294 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) |
280 | { | 295 | { |
281 | hr = E_INVALIDARG; | 296 | hr = E_INVALIDARG; |
282 | ExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); | 297 | DictExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); |
283 | } | 298 | } |
284 | 299 | ||
285 | if (DICT_STRING_LIST != psd->dtType) | 300 | if (DICT_STRING_LIST != psd->dtType) |
286 | { | 301 | { |
287 | hr = E_INVALIDARG; | 302 | hr = E_INVALIDARG; |
288 | ExitOnFailure(hr, "Tried to add key without value to wrong dictionary type! This dictionary type is: %d", psd->dtType); | 303 | DictExitOnFailure(hr, "Tried to add key without value to wrong dictionary type! This dictionary type is: %d", psd->dtType); |
289 | } | 304 | } |
290 | 305 | ||
291 | if ((psd->dwNumItems + 1) >= MAX_BUCKET_SIZES[psd->dwBucketSizeIndex] / MAX_BUCKETS_TO_ITEMS_RATIO) | 306 | if ((psd->dwNumItems + 1) >= MAX_BUCKET_SIZES[psd->dwBucketSizeIndex] / MAX_BUCKETS_TO_ITEMS_RATIO) |
@@ -299,18 +314,18 @@ extern "C" HRESULT DAPI DictAddKey( | |||
299 | hr = S_OK; | 314 | hr = S_OK; |
300 | } | 315 | } |
301 | } | 316 | } |
302 | ExitOnFailure(hr, "Failed to grow dictionary"); | 317 | DictExitOnFailure(hr, "Failed to grow dictionary"); |
303 | } | 318 | } |
304 | 319 | ||
305 | hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], psd->ppvBuckets, pszString, &dwIndex); | 320 | hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], psd->ppvBuckets, pszString, &dwIndex); |
306 | ExitOnFailure(hr, "Failed to get index to insert into"); | 321 | DictExitOnFailure(hr, "Failed to get index to insert into"); |
307 | 322 | ||
308 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&(psd->ppvItemList)), psd->dwNumItems + 1, sizeof(void *), 1000); | 323 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&(psd->ppvItemList)), psd->dwNumItems + 1, sizeof(void *), 1000); |
309 | ExitOnFailure(hr, "Failed to resize list of items in dictionary"); | 324 | DictExitOnFailure(hr, "Failed to resize list of items in dictionary"); |
310 | ++psd->dwNumItems; | 325 | ++psd->dwNumItems; |
311 | 326 | ||
312 | hr = StrAllocString(reinterpret_cast<LPWSTR *>(&(psd->ppvBuckets[dwIndex])), pszString, 0); | 327 | hr = StrAllocString(reinterpret_cast<LPWSTR *>(&(psd->ppvBuckets[dwIndex])), pszString, 0); |
313 | ExitOnFailure(hr, "Failed to allocate copy of string"); | 328 | DictExitOnFailure(hr, "Failed to allocate copy of string"); |
314 | 329 | ||
315 | psd->ppvItemList[psd->dwNumItems-1] = psd->ppvBuckets[dwIndex]; | 330 | psd->ppvItemList[psd->dwNumItems-1] = psd->ppvBuckets[dwIndex]; |
316 | 331 | ||
@@ -330,23 +345,23 @@ extern "C" HRESULT DAPI DictAddValue( | |||
330 | DWORD dwIndex = 0; | 345 | DWORD dwIndex = 0; |
331 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(sdHandle); | 346 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(sdHandle); |
332 | 347 | ||
333 | ExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while adding value to dict"); | 348 | DictExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while adding value to dict"); |
334 | ExitOnNull(pvValue, hr, E_INVALIDARG, "Value not specified while adding value to dict"); | 349 | DictExitOnNull(pvValue, hr, E_INVALIDARG, "Value not specified while adding value to dict"); |
335 | 350 | ||
336 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) | 351 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) |
337 | { | 352 | { |
338 | hr = E_INVALIDARG; | 353 | hr = E_INVALIDARG; |
339 | ExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); | 354 | DictExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); |
340 | } | 355 | } |
341 | 356 | ||
342 | if (DICT_EMBEDDED_KEY != psd->dtType) | 357 | if (DICT_EMBEDDED_KEY != psd->dtType) |
343 | { | 358 | { |
344 | hr = E_INVALIDARG; | 359 | hr = E_INVALIDARG; |
345 | ExitOnFailure(hr, "Tried to add key/value pair to wrong dictionary type! This dictionary type is: %d", psd->dtType); | 360 | DictExitOnFailure(hr, "Tried to add key/value pair to wrong dictionary type! This dictionary type is: %d", psd->dtType); |
346 | } | 361 | } |
347 | 362 | ||
348 | wzKey = GetKey(psd, pvValue); | 363 | wzKey = GetKey(psd, pvValue); |
349 | ExitOnNull(wzKey, hr, E_INVALIDARG, "String not specified while adding value to dict"); | 364 | DictExitOnNull(wzKey, hr, E_INVALIDARG, "String not specified while adding value to dict"); |
350 | 365 | ||
351 | if ((psd->dwNumItems + 1) >= MAX_BUCKET_SIZES[psd->dwBucketSizeIndex] / MAX_BUCKETS_TO_ITEMS_RATIO) | 366 | if ((psd->dwNumItems + 1) >= MAX_BUCKET_SIZES[psd->dwBucketSizeIndex] / MAX_BUCKETS_TO_ITEMS_RATIO) |
352 | { | 367 | { |
@@ -359,14 +374,14 @@ extern "C" HRESULT DAPI DictAddValue( | |||
359 | hr = S_OK; | 374 | hr = S_OK; |
360 | } | 375 | } |
361 | } | 376 | } |
362 | ExitOnFailure(hr, "Failed to grow dictionary"); | 377 | DictExitOnFailure(hr, "Failed to grow dictionary"); |
363 | } | 378 | } |
364 | 379 | ||
365 | hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], psd->ppvBuckets, wzKey, &dwIndex); | 380 | hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], psd->ppvBuckets, wzKey, &dwIndex); |
366 | ExitOnFailure(hr, "Failed to get index to insert into"); | 381 | DictExitOnFailure(hr, "Failed to get index to insert into"); |
367 | 382 | ||
368 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&(psd->ppvItemList)), psd->dwNumItems + 1, sizeof(void *), 1000); | 383 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&(psd->ppvItemList)), psd->dwNumItems + 1, sizeof(void *), 1000); |
369 | ExitOnFailure(hr, "Failed to resize list of items in dictionary"); | 384 | DictExitOnFailure(hr, "Failed to resize list of items in dictionary"); |
370 | ++psd->dwNumItems; | 385 | ++psd->dwNumItems; |
371 | 386 | ||
372 | pvOffset = TranslateValueToOffset(psd, pvValue); | 387 | pvOffset = TranslateValueToOffset(psd, pvValue); |
@@ -385,15 +400,15 @@ extern "C" HRESULT DAPI DictGetValue( | |||
385 | { | 400 | { |
386 | HRESULT hr = S_OK; | 401 | HRESULT hr = S_OK; |
387 | 402 | ||
388 | ExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while searching dict"); | 403 | DictExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while searching dict"); |
389 | ExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict"); | 404 | DictExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict"); |
390 | 405 | ||
391 | const STRINGDICT_STRUCT *psd = static_cast<const STRINGDICT_STRUCT *>(sdHandle); | 406 | const STRINGDICT_STRUCT *psd = static_cast<const STRINGDICT_STRUCT *>(sdHandle); |
392 | 407 | ||
393 | if (DICT_EMBEDDED_KEY != psd->dtType) | 408 | if (DICT_EMBEDDED_KEY != psd->dtType) |
394 | { | 409 | { |
395 | hr = E_INVALIDARG; | 410 | hr = E_INVALIDARG; |
396 | ExitOnFailure(hr, "Tried to lookup value in wrong dictionary type! This dictionary type is: %d", psd->dtType); | 411 | DictExitOnFailure(hr, "Tried to lookup value in wrong dictionary type! This dictionary type is: %d", psd->dtType); |
397 | } | 412 | } |
398 | 413 | ||
399 | hr = GetValue(psd, pszString, ppvValue); | 414 | hr = GetValue(psd, pszString, ppvValue); |
@@ -401,7 +416,7 @@ extern "C" HRESULT DAPI DictGetValue( | |||
401 | { | 416 | { |
402 | ExitFunction(); | 417 | ExitFunction(); |
403 | } | 418 | } |
404 | ExitOnFailure(hr, "Failed to call internal GetValue()"); | 419 | DictExitOnFailure(hr, "Failed to call internal GetValue()"); |
405 | 420 | ||
406 | LExit: | 421 | LExit: |
407 | return hr; | 422 | return hr; |
@@ -414,8 +429,8 @@ extern "C" HRESULT DAPI DictKeyExists( | |||
414 | { | 429 | { |
415 | HRESULT hr = S_OK; | 430 | HRESULT hr = S_OK; |
416 | 431 | ||
417 | ExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while searching dict"); | 432 | DictExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while searching dict"); |
418 | ExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict"); | 433 | DictExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict"); |
419 | 434 | ||
420 | const STRINGDICT_STRUCT *psd = static_cast<const STRINGDICT_STRUCT *>(sdHandle); | 435 | const STRINGDICT_STRUCT *psd = static_cast<const STRINGDICT_STRUCT *>(sdHandle); |
421 | 436 | ||
@@ -425,7 +440,7 @@ extern "C" HRESULT DAPI DictKeyExists( | |||
425 | { | 440 | { |
426 | ExitFunction(); | 441 | ExitFunction(); |
427 | } | 442 | } |
428 | ExitOnFailure(hr, "Failed to call internal GetValue()"); | 443 | DictExitOnFailure(hr, "Failed to call internal GetValue()"); |
429 | 444 | ||
430 | LExit: | 445 | LExit: |
431 | return hr; | 446 | return hr; |
@@ -467,7 +482,7 @@ static HRESULT StringHash( | |||
467 | if (DICT_FLAG_CASEINSENSITIVE & psd->dfFlags) | 482 | if (DICT_FLAG_CASEINSENSITIVE & psd->dfFlags) |
468 | { | 483 | { |
469 | hr = StrAllocStringToUpperInvariant(&sczNewKey, pszString, 0); | 484 | hr = StrAllocStringToUpperInvariant(&sczNewKey, pszString, 0); |
470 | ExitOnFailure(hr, "Failed to convert the string to upper-case."); | 485 | DictExitOnFailure(hr, "Failed to convert the string to upper-case."); |
471 | 486 | ||
472 | wzKey = sczNewKey; | 487 | wzKey = sczNewKey; |
473 | } | 488 | } |
@@ -522,17 +537,17 @@ static HRESULT GetValue( | |||
522 | void *pvCandidateValue = NULL; | 537 | void *pvCandidateValue = NULL; |
523 | DWORD dwIndex = 0; | 538 | DWORD dwIndex = 0; |
524 | 539 | ||
525 | ExitOnNull(psd, hr, E_INVALIDARG, "Handle not specified while searching dict"); | 540 | DictExitOnNull(psd, hr, E_INVALIDARG, "Handle not specified while searching dict"); |
526 | ExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict"); | 541 | DictExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict"); |
527 | 542 | ||
528 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) | 543 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) |
529 | { | 544 | { |
530 | hr = E_INVALIDARG; | 545 | hr = E_INVALIDARG; |
531 | ExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); | 546 | DictExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); |
532 | } | 547 | } |
533 | 548 | ||
534 | hr = StringHash(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], pszString, &dwOriginalIndexCandidate); | 549 | hr = StringHash(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], pszString, &dwOriginalIndexCandidate); |
535 | ExitOnFailure(hr, "Failed to hash the string."); | 550 | DictExitOnFailure(hr, "Failed to hash the string."); |
536 | 551 | ||
537 | DWORD dwIndexCandidate = dwOriginalIndexCandidate; | 552 | DWORD dwIndexCandidate = dwOriginalIndexCandidate; |
538 | 553 | ||
@@ -553,7 +568,7 @@ static HRESULT GetValue( | |||
553 | { | 568 | { |
554 | ExitFunction(); | 569 | ExitFunction(); |
555 | } | 570 | } |
556 | ExitOnFailure(hr, "Failed to find index to get"); | 571 | DictExitOnFailure(hr, "Failed to find index to get"); |
557 | 572 | ||
558 | if (NULL != ppvValue) | 573 | if (NULL != ppvValue) |
559 | { | 574 | { |
@@ -581,7 +596,7 @@ static HRESULT GetInsertIndex( | |||
581 | DWORD dwOriginalIndexCandidate = 0; | 596 | DWORD dwOriginalIndexCandidate = 0; |
582 | 597 | ||
583 | hr = StringHash(psd, dwBucketCount, pszString, &dwOriginalIndexCandidate); | 598 | hr = StringHash(psd, dwBucketCount, pszString, &dwOriginalIndexCandidate); |
584 | ExitOnFailure(hr, "Failed to hash the string."); | 599 | DictExitOnFailure(hr, "Failed to hash the string."); |
585 | 600 | ||
586 | DWORD dwIndexCandidate = dwOriginalIndexCandidate; | 601 | DWORD dwIndexCandidate = dwOriginalIndexCandidate; |
587 | 602 | ||
@@ -604,7 +619,7 @@ static HRESULT GetInsertIndex( | |||
604 | { | 619 | { |
605 | // The dict table is full - this error seems to be a reasonably close match | 620 | // The dict table is full - this error seems to be a reasonably close match |
606 | hr = HRESULT_FROM_WIN32(ERROR_DATABASE_FULL); | 621 | hr = HRESULT_FROM_WIN32(ERROR_DATABASE_FULL); |
607 | ExitOnRootFailure(hr, "Failed to add item '%ls' to dict table because dict table is full of items", pszString); | 622 | DictExitOnRootFailure(hr, "Failed to add item '%ls' to dict table because dict table is full of items", pszString); |
608 | } | 623 | } |
609 | } | 624 | } |
610 | 625 | ||
@@ -626,11 +641,11 @@ static HRESULT GetIndex( | |||
626 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) | 641 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) |
627 | { | 642 | { |
628 | hr = E_INVALIDARG; | 643 | hr = E_INVALIDARG; |
629 | ExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); | 644 | DictExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); |
630 | } | 645 | } |
631 | 646 | ||
632 | hr = StringHash(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], pszString, &dwOriginalIndexCandidate); | 647 | hr = StringHash(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], pszString, &dwOriginalIndexCandidate); |
633 | ExitOnFailure(hr, "Failed to hash the string."); | 648 | DictExitOnFailure(hr, "Failed to hash the string."); |
634 | 649 | ||
635 | DWORD dwIndexCandidate = dwOriginalIndexCandidate; | 650 | DWORD dwIndexCandidate = dwOriginalIndexCandidate; |
636 | 651 | ||
@@ -704,18 +719,18 @@ static HRESULT GrowDictionary( | |||
704 | } | 719 | } |
705 | 720 | ||
706 | hr = ::SizeTMult(sizeof(void *), MAX_BUCKET_SIZES[dwNewBucketSizeIndex], &cbAllocSize); | 721 | hr = ::SizeTMult(sizeof(void *), MAX_BUCKET_SIZES[dwNewBucketSizeIndex], &cbAllocSize); |
707 | ExitOnFailure(hr, "Overflow while calculating allocation size to grow dictionary"); | 722 | DictExitOnFailure(hr, "Overflow while calculating allocation size to grow dictionary"); |
708 | 723 | ||
709 | ppvNewBuckets = static_cast<void**>(MemAlloc(cbAllocSize, TRUE)); | 724 | ppvNewBuckets = static_cast<void**>(MemAlloc(cbAllocSize, TRUE)); |
710 | ExitOnNull(ppvNewBuckets, hr, E_OUTOFMEMORY, "Failed to allocate %u buckets while growing dictionary", MAX_BUCKET_SIZES[dwNewBucketSizeIndex]); | 725 | DictExitOnNull(ppvNewBuckets, hr, E_OUTOFMEMORY, "Failed to allocate %u buckets while growing dictionary", MAX_BUCKET_SIZES[dwNewBucketSizeIndex]); |
711 | 726 | ||
712 | for (DWORD i = 0; i < psd->dwNumItems; ++i) | 727 | for (DWORD i = 0; i < psd->dwNumItems; ++i) |
713 | { | 728 | { |
714 | wzKey = GetKey(psd, TranslateOffsetToValue(psd, psd->ppvItemList[i])); | 729 | wzKey = GetKey(psd, TranslateOffsetToValue(psd, psd->ppvItemList[i])); |
715 | ExitOnNull(wzKey, hr, E_INVALIDARG, "String not specified in existing dict value"); | 730 | DictExitOnNull(wzKey, hr, E_INVALIDARG, "String not specified in existing dict value"); |
716 | 731 | ||
717 | hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[dwNewBucketSizeIndex], ppvNewBuckets, wzKey, &dwInsertIndex); | 732 | hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[dwNewBucketSizeIndex], ppvNewBuckets, wzKey, &dwInsertIndex); |
718 | ExitOnFailure(hr, "Failed to get index to insert into"); | 733 | DictExitOnFailure(hr, "Failed to get index to insert into"); |
719 | 734 | ||
720 | ppvNewBuckets[dwInsertIndex] = psd->ppvItemList[i]; | 735 | ppvNewBuckets[dwInsertIndex] = psd->ppvItemList[i]; |
721 | } | 736 | } |
diff --git a/src/dutil/dirutil.cpp b/src/dutil/dirutil.cpp index 5e22ee65..81130a8d 100644 --- a/src/dutil/dirutil.cpp +++ b/src/dutil/dirutil.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | 5 | ||
6 | // Exit macros | ||
7 | #define DirExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) | ||
8 | #define DirExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) | ||
9 | #define DirExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) | ||
10 | #define DirExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) | ||
11 | #define DirExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) | ||
12 | #define DirExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) | ||
13 | #define DirExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DIRUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define DirExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define DirExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DIRUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define DirExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define DirExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DIRUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define DirExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DIRUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
6 | /******************************************************************* | 21 | /******************************************************************* |
7 | DirExists | 22 | DirExists |
8 | 23 | ||
@@ -59,12 +74,12 @@ extern "C" HRESULT DAPI DirCreateTempPath( | |||
59 | cch = ::GetTempPathW(countof(wzDir), wzDir); | 74 | cch = ::GetTempPathW(countof(wzDir), wzDir); |
60 | if (!cch || cch >= countof(wzDir)) | 75 | if (!cch || cch >= countof(wzDir)) |
61 | { | 76 | { |
62 | ExitWithLastError(hr, "Failed to GetTempPath."); | 77 | DirExitWithLastError(hr, "Failed to GetTempPath."); |
63 | } | 78 | } |
64 | 79 | ||
65 | if (!::GetTempFileNameW(wzDir, wzPrefix, 0, wzFile)) | 80 | if (!::GetTempFileNameW(wzDir, wzPrefix, 0, wzFile)) |
66 | { | 81 | { |
67 | ExitWithLastError(hr, "Failed to GetTempFileName."); | 82 | DirExitWithLastError(hr, "Failed to GetTempFileName."); |
68 | } | 83 | } |
69 | 84 | ||
70 | hr = ::StringCchCopyW(wzPath, cchPath, wzFile); | 85 | hr = ::StringCchCopyW(wzPath, cchPath, wzFile); |
@@ -111,12 +126,12 @@ extern "C" HRESULT DAPI DirEnsureExists( | |||
111 | } | 126 | } |
112 | 127 | ||
113 | // if there is no parent directory fail | 128 | // if there is no parent directory fail |
114 | ExitOnNullDebugTrace(pwzLastSlash, hr, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "cannot find parent path"); | 129 | DirExitOnNullDebugTrace(pwzLastSlash, hr, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "cannot find parent path"); |
115 | 130 | ||
116 | *pwzLastSlash = L'\0'; // null terminate the parent path | 131 | *pwzLastSlash = L'\0'; // null terminate the parent path |
117 | hr = DirEnsureExists(wzPath, psa); // recurse! | 132 | hr = DirEnsureExists(wzPath, psa); // recurse! |
118 | *pwzLastSlash = L'\\'; // put the slash back | 133 | *pwzLastSlash = L'\\'; // put the slash back |
119 | ExitOnFailureDebugTrace(hr, "failed to create path: %ls", wzPath); | 134 | DirExitOnFailureDebugTrace(hr, "failed to create path: %ls", wzPath); |
120 | 135 | ||
121 | // try to create the directory now that all parents are created | 136 | // try to create the directory now that all parents are created |
122 | if (!::CreateDirectoryW(wzPath, psa)) | 137 | if (!::CreateDirectoryW(wzPath, psa)) |
@@ -197,7 +212,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( | |||
197 | er = ERROR_PATH_NOT_FOUND; | 212 | er = ERROR_PATH_NOT_FOUND; |
198 | } | 213 | } |
199 | hr = HRESULT_FROM_WIN32(er); | 214 | hr = HRESULT_FROM_WIN32(er); |
200 | ExitOnRootFailure(hr, "Failed to get attributes for path: %ls", wzPath); | 215 | DirExitOnRootFailure(hr, "Failed to get attributes for path: %ls", wzPath); |
201 | } | 216 | } |
202 | 217 | ||
203 | if (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) | 218 | if (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) |
@@ -206,7 +221,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( | |||
206 | { | 221 | { |
207 | if (!::SetFileAttributesW(wzPath, FILE_ATTRIBUTE_NORMAL)) | 222 | if (!::SetFileAttributesW(wzPath, FILE_ATTRIBUTE_NORMAL)) |
208 | { | 223 | { |
209 | ExitWithLastError(hr, "Failed to remove read-only attribute from path: %ls", wzPath); | 224 | DirExitWithLastError(hr, "Failed to remove read-only attribute from path: %ls", wzPath); |
210 | } | 225 | } |
211 | } | 226 | } |
212 | 227 | ||
@@ -217,18 +232,18 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( | |||
217 | { | 232 | { |
218 | if (!::GetTempPathW(countof(wzTempDirectory), wzTempDirectory)) | 233 | if (!::GetTempPathW(countof(wzTempDirectory), wzTempDirectory)) |
219 | { | 234 | { |
220 | ExitWithLastError(hr, "Failed to get temp directory."); | 235 | DirExitWithLastError(hr, "Failed to get temp directory."); |
221 | } | 236 | } |
222 | } | 237 | } |
223 | 238 | ||
224 | // Delete everything in this directory. | 239 | // Delete everything in this directory. |
225 | hr = PathConcat(wzPath, L"*.*", &sczDelete); | 240 | hr = PathConcat(wzPath, L"*.*", &sczDelete); |
226 | ExitOnFailure(hr, "Failed to concat wild cards to string: %ls", wzPath); | 241 | DirExitOnFailure(hr, "Failed to concat wild cards to string: %ls", wzPath); |
227 | 242 | ||
228 | hFind = ::FindFirstFileW(sczDelete, &wfd); | 243 | hFind = ::FindFirstFileW(sczDelete, &wfd); |
229 | if (INVALID_HANDLE_VALUE == hFind) | 244 | if (INVALID_HANDLE_VALUE == hFind) |
230 | { | 245 | { |
231 | ExitWithLastError(hr, "failed to get first file in directory: %ls", wzPath); | 246 | DirExitWithLastError(hr, "failed to get first file in directory: %ls", wzPath); |
232 | } | 247 | } |
233 | 248 | ||
234 | do | 249 | do |
@@ -243,18 +258,18 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( | |||
243 | wfd.cFileName[MAX_PATH - 1] = L'\0'; | 258 | wfd.cFileName[MAX_PATH - 1] = L'\0'; |
244 | 259 | ||
245 | hr = PathConcat(wzPath, wfd.cFileName, &sczDelete); | 260 | hr = PathConcat(wzPath, wfd.cFileName, &sczDelete); |
246 | ExitOnFailure(hr, "Failed to concat filename '%ls' to directory: %ls", wfd.cFileName, wzPath); | 261 | DirExitOnFailure(hr, "Failed to concat filename '%ls' to directory: %ls", wfd.cFileName, wzPath); |
247 | 262 | ||
248 | if (fRecurse && wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) | 263 | if (fRecurse && wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
249 | { | 264 | { |
250 | hr = PathBackslashTerminate(&sczDelete); | 265 | hr = PathBackslashTerminate(&sczDelete); |
251 | ExitOnFailure(hr, "Failed to ensure path is backslash terminated: %ls", sczDelete); | 266 | DirExitOnFailure(hr, "Failed to ensure path is backslash terminated: %ls", sczDelete); |
252 | 267 | ||
253 | hr = DirEnsureDeleteEx(sczDelete, dwFlags); // recursive call | 268 | hr = DirEnsureDeleteEx(sczDelete, dwFlags); // recursive call |
254 | if (FAILED(hr)) | 269 | if (FAILED(hr)) |
255 | { | 270 | { |
256 | // if we failed to delete a subdirectory, keep trying to finish any remaining files | 271 | // if we failed to delete a subdirectory, keep trying to finish any remaining files |
257 | ExitTraceSource(DUTIL_SOURCE_DEFAULT, hr, "Failed to delete subdirectory; continuing: %ls", sczDelete); | 272 | ExitTraceSource(DUTIL_SOURCE_DIRUTIL, hr, "Failed to delete subdirectory; continuing: %ls", sczDelete); |
258 | hr = S_OK; | 273 | hr = S_OK; |
259 | } | 274 | } |
260 | } | 275 | } |
@@ -264,7 +279,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( | |||
264 | { | 279 | { |
265 | if (!::SetFileAttributesW(sczDelete, FILE_ATTRIBUTE_NORMAL)) | 280 | if (!::SetFileAttributesW(sczDelete, FILE_ATTRIBUTE_NORMAL)) |
266 | { | 281 | { |
267 | ExitWithLastError(hr, "Failed to remove attributes from file: %ls", sczDelete); | 282 | DirExitWithLastError(hr, "Failed to remove attributes from file: %ls", sczDelete); |
268 | } | 283 | } |
269 | } | 284 | } |
270 | 285 | ||
@@ -274,7 +289,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( | |||
274 | { | 289 | { |
275 | if (!::GetTempFileNameW(wzTempDirectory, L"DEL", 0, wzTempPath)) | 290 | if (!::GetTempFileNameW(wzTempDirectory, L"DEL", 0, wzTempPath)) |
276 | { | 291 | { |
277 | ExitWithLastError(hr, "Failed to get temp file to move to."); | 292 | DirExitWithLastError(hr, "Failed to get temp file to move to."); |
278 | } | 293 | } |
279 | 294 | ||
280 | // Try to move the file to the temp directory then schedule for delete, | 295 | // Try to move the file to the temp directory then schedule for delete, |
@@ -290,7 +305,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( | |||
290 | } | 305 | } |
291 | else | 306 | else |
292 | { | 307 | { |
293 | ExitWithLastError(hr, "Failed to delete file: %ls", sczDelete); | 308 | DirExitWithLastError(hr, "Failed to delete file: %ls", sczDelete); |
294 | } | 309 | } |
295 | } | 310 | } |
296 | } | 311 | } |
@@ -303,7 +318,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( | |||
303 | } | 318 | } |
304 | else | 319 | else |
305 | { | 320 | { |
306 | ExitWithLastError(hr, "Failed while looping through files in directory: %ls", wzPath); | 321 | DirExitWithLastError(hr, "Failed while looping through files in directory: %ls", wzPath); |
307 | } | 322 | } |
308 | } | 323 | } |
309 | 324 | ||
@@ -318,13 +333,13 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( | |||
318 | } | 333 | } |
319 | } | 334 | } |
320 | 335 | ||
321 | ExitOnRootFailure(hr, "Failed to remove directory: %ls", wzPath); | 336 | DirExitOnRootFailure(hr, "Failed to remove directory: %ls", wzPath); |
322 | } | 337 | } |
323 | } | 338 | } |
324 | else | 339 | else |
325 | { | 340 | { |
326 | hr = E_UNEXPECTED; | 341 | hr = E_UNEXPECTED; |
327 | ExitOnFailure(hr, "Directory delete cannot delete file: %ls", wzPath); | 342 | DirExitOnFailure(hr, "Directory delete cannot delete file: %ls", wzPath); |
328 | } | 343 | } |
329 | 344 | ||
330 | Assert(S_OK == hr); | 345 | Assert(S_OK == hr); |
@@ -351,22 +366,22 @@ extern "C" HRESULT DAPI DirGetCurrent( | |||
351 | if (psczCurrentDirectory && *psczCurrentDirectory) | 366 | if (psczCurrentDirectory && *psczCurrentDirectory) |
352 | { | 367 | { |
353 | hr = StrMaxLength(*psczCurrentDirectory, &cch); | 368 | hr = StrMaxLength(*psczCurrentDirectory, &cch); |
354 | ExitOnFailure(hr, "Failed to determine size of current directory."); | 369 | DirExitOnFailure(hr, "Failed to determine size of current directory."); |
355 | } | 370 | } |
356 | 371 | ||
357 | DWORD cchRequired = ::GetCurrentDirectoryW(static_cast<DWORD>(cch), 0 == cch ? NULL : *psczCurrentDirectory); | 372 | DWORD cchRequired = ::GetCurrentDirectoryW(static_cast<DWORD>(cch), 0 == cch ? NULL : *psczCurrentDirectory); |
358 | if (0 == cchRequired) | 373 | if (0 == cchRequired) |
359 | { | 374 | { |
360 | ExitWithLastError(hr, "Failed to get current directory."); | 375 | DirExitWithLastError(hr, "Failed to get current directory."); |
361 | } | 376 | } |
362 | else if (cch < cchRequired) | 377 | else if (cch < cchRequired) |
363 | { | 378 | { |
364 | hr = StrAlloc(psczCurrentDirectory, cchRequired); | 379 | hr = StrAlloc(psczCurrentDirectory, cchRequired); |
365 | ExitOnFailure(hr, "Failed to allocate string for current directory."); | 380 | DirExitOnFailure(hr, "Failed to allocate string for current directory."); |
366 | 381 | ||
367 | if (!::GetCurrentDirectoryW(cchRequired, *psczCurrentDirectory)) | 382 | if (!::GetCurrentDirectoryW(cchRequired, *psczCurrentDirectory)) |
368 | { | 383 | { |
369 | ExitWithLastError(hr, "Failed to get current directory using allocated string."); | 384 | DirExitWithLastError(hr, "Failed to get current directory using allocated string."); |
370 | } | 385 | } |
371 | } | 386 | } |
372 | 387 | ||
@@ -387,7 +402,7 @@ extern "C" HRESULT DAPI DirSetCurrent( | |||
387 | 402 | ||
388 | if (!::SetCurrentDirectoryW(wzDirectory)) | 403 | if (!::SetCurrentDirectoryW(wzDirectory)) |
389 | { | 404 | { |
390 | ExitWithLastError(hr, "Failed to set current directory to: %ls", wzDirectory); | 405 | DirExitWithLastError(hr, "Failed to set current directory to: %ls", wzDirectory); |
391 | } | 406 | } |
392 | 407 | ||
393 | LExit: | 408 | LExit: |
diff --git a/src/dutil/dlutil.cpp b/src/dutil/dlutil.cpp index 1b30f410..70155e6f 100644 --- a/src/dutil/dlutil.cpp +++ b/src/dutil/dlutil.cpp | |||
@@ -5,6 +5,21 @@ | |||
5 | #include <inetutil.h> | 5 | #include <inetutil.h> |
6 | #include <uriutil.h> | 6 | #include <uriutil.h> |
7 | 7 | ||
8 | |||
9 | // Exit macros | ||
10 | #define DlExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__) | ||
11 | #define DlExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__) | ||
12 | #define DlExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__) | ||
13 | #define DlExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__) | ||
14 | #define DlExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__) | ||
15 | #define DlExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__) | ||
16 | #define DlExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DLUTIL, p, x, e, s, __VA_ARGS__) | ||
17 | #define DlExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DLUTIL, p, x, s, __VA_ARGS__) | ||
18 | #define DlExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DLUTIL, p, x, e, s, __VA_ARGS__) | ||
19 | #define DlExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DLUTIL, p, x, s, __VA_ARGS__) | ||
20 | #define DlExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DLUTIL, e, x, s, __VA_ARGS__) | ||
21 | #define DlExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DLUTIL, g, x, s, __VA_ARGS__) | ||
22 | |||
8 | static const DWORD64 DOWNLOAD_ENGINE_TWO_GIGABYTES = DWORD64(2) * 1024 * 1024 * 1024; | 23 | static const DWORD64 DOWNLOAD_ENGINE_TWO_GIGABYTES = DWORD64(2) * 1024 * 1024 * 1024; |
9 | static LPCWSTR DOWNLOAD_ENGINE_ACCEPT_TYPES[] = { L"*/*", NULL }; | 24 | static LPCWSTR DOWNLOAD_ENGINE_ACCEPT_TYPES[] = { L"*/*", NULL }; |
10 | 25 | ||
@@ -41,7 +56,7 @@ static HRESULT DownloadResource( | |||
41 | static HRESULT AllocateRangeRequestHeader( | 56 | static HRESULT AllocateRangeRequestHeader( |
42 | __in DWORD64 dw64ResumeOffset, | 57 | __in DWORD64 dw64ResumeOffset, |
43 | __in DWORD64 dw64ResourceLength, | 58 | __in DWORD64 dw64ResourceLength, |
44 | __deref_out_z LPWSTR* psczHeader | 59 | __deref_inout_z LPWSTR* psczHeader |
45 | ); | 60 | ); |
46 | static HRESULT WriteToFile( | 61 | static HRESULT WriteToFile( |
47 | __in HINTERNET hUrl, | 62 | __in HINTERNET hUrl, |
@@ -126,10 +141,10 @@ extern "C" HRESULT DAPI DownloadUrl( | |||
126 | // Copy the download source into a working variable to handle redirects then | 141 | // Copy the download source into a working variable to handle redirects then |
127 | // open the internet session. | 142 | // open the internet session. |
128 | hr = StrAllocString(&sczUrl, pDownloadSource->sczUrl, 0); | 143 | hr = StrAllocString(&sczUrl, pDownloadSource->sczUrl, 0); |
129 | ExitOnFailure(hr, "Failed to copy download source URL."); | 144 | DlExitOnFailure(hr, "Failed to copy download source URL."); |
130 | 145 | ||
131 | hSession = ::InternetOpenW(L"Burn", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); | 146 | hSession = ::InternetOpenW(L"Burn", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); |
132 | ExitOnNullWithLastError(hSession, hr, "Failed to open internet session"); | 147 | DlExitOnNullWithLastError(hSession, hr, "Failed to open internet session"); |
133 | 148 | ||
134 | // Make a best effort to set the download timeouts to 2 minutes or whatever policy says. | 149 | // Make a best effort to set the download timeouts to 2 minutes or whatever policy says. |
135 | PolcReadNumber(POLICY_BURN_REGISTRY_PATH, L"DownloadTimeout", 2 * 60, &dwTimeout); | 150 | PolcReadNumber(POLICY_BURN_REGISTRY_PATH, L"DownloadTimeout", 2 * 60, &dwTimeout); |
@@ -143,14 +158,14 @@ extern "C" HRESULT DAPI DownloadUrl( | |||
143 | 158 | ||
144 | // Get the resource size and creation time from the internet. | 159 | // Get the resource size and creation time from the internet. |
145 | hr = GetResourceMetadata(hSession, &sczUrl, pDownloadSource->sczUser, pDownloadSource->sczPassword, pAuthenticate, &dw64Size, &ftCreated); | 160 | hr = GetResourceMetadata(hSession, &sczUrl, pDownloadSource->sczUser, pDownloadSource->sczPassword, pAuthenticate, &dw64Size, &ftCreated); |
146 | ExitOnFailure(hr, "Failed to get size and time for URL: %ls", sczUrl); | 161 | DlExitOnFailure(hr, "Failed to get size and time for URL: %ls", sczUrl); |
147 | 162 | ||
148 | // Ignore failure to initialize resume because we will fall back to full download then | 163 | // Ignore failure to initialize resume because we will fall back to full download then |
149 | // download. | 164 | // download. |
150 | InitializeResume(wzDestinationPath, &sczResumePath, &hResumeFile, &dw64ResumeOffset); | 165 | InitializeResume(wzDestinationPath, &sczResumePath, &hResumeFile, &dw64ResumeOffset); |
151 | 166 | ||
152 | hr = DownloadResource(hSession, &sczUrl, pDownloadSource->sczUser, pDownloadSource->sczPassword, wzDestinationPath, dw64AuthoredDownloadSize, dw64Size, dw64ResumeOffset, hResumeFile, pCache, pAuthenticate); | 167 | hr = DownloadResource(hSession, &sczUrl, pDownloadSource->sczUser, pDownloadSource->sczPassword, wzDestinationPath, dw64AuthoredDownloadSize, dw64Size, dw64ResumeOffset, hResumeFile, pCache, pAuthenticate); |
153 | ExitOnFailure(hr, "Failed to download URL: %ls", sczUrl); | 168 | DlExitOnFailure(hr, "Failed to download URL: %ls", sczUrl); |
154 | 169 | ||
155 | // Cleanup the resume file because we successfully downloaded the whole file. | 170 | // Cleanup the resume file because we successfully downloaded the whole file. |
156 | if (sczResumePath && *sczResumePath) | 171 | if (sczResumePath && *sczResumePath) |
@@ -185,19 +200,19 @@ static HRESULT InitializeResume( | |||
185 | *pdw64ResumeOffset = 0; | 200 | *pdw64ResumeOffset = 0; |
186 | 201 | ||
187 | hr = DownloadGetResumePath(wzDestinationPath, psczResumePath); | 202 | hr = DownloadGetResumePath(wzDestinationPath, psczResumePath); |
188 | ExitOnFailure(hr, "Failed to calculate resume path from working path: %ls", wzDestinationPath); | 203 | DlExitOnFailure(hr, "Failed to calculate resume path from working path: %ls", wzDestinationPath); |
189 | 204 | ||
190 | hResumeFile = ::CreateFileW(*psczResumePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | 205 | hResumeFile = ::CreateFileW(*psczResumePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
191 | if (INVALID_HANDLE_VALUE == hResumeFile) | 206 | if (INVALID_HANDLE_VALUE == hResumeFile) |
192 | { | 207 | { |
193 | ExitWithLastError(hr, "Failed to create resume file: %ls", *psczResumePath); | 208 | DlExitWithLastError(hr, "Failed to create resume file: %ls", *psczResumePath); |
194 | } | 209 | } |
195 | 210 | ||
196 | do | 211 | do |
197 | { | 212 | { |
198 | if (!::ReadFile(hResumeFile, reinterpret_cast<BYTE*>(pdw64ResumeOffset) + cbTotalReadResumeData, sizeof(DWORD64) - cbTotalReadResumeData, &cbReadData, NULL)) | 213 | if (!::ReadFile(hResumeFile, reinterpret_cast<BYTE*>(pdw64ResumeOffset) + cbTotalReadResumeData, sizeof(DWORD64) - cbTotalReadResumeData, &cbReadData, NULL)) |
199 | { | 214 | { |
200 | ExitWithLastError(hr, "Failed to read resume file: %ls", *psczResumePath); | 215 | DlExitWithLastError(hr, "Failed to read resume file: %ls", *psczResumePath); |
201 | } | 216 | } |
202 | cbTotalReadResumeData += cbReadData; | 217 | cbTotalReadResumeData += cbReadData; |
203 | } while (cbReadData && sizeof(DWORD64) > cbTotalReadResumeData); | 218 | } while (cbReadData && sizeof(DWORD64) > cbTotalReadResumeData); |
@@ -233,7 +248,7 @@ static HRESULT GetResourceMetadata( | |||
233 | LONGLONG llLength = 0; | 248 | LONGLONG llLength = 0; |
234 | 249 | ||
235 | hr = MakeRequest(hSession, psczUrl, L"HEAD", NULL, wzUser, wzPassword, pAuthenticate, &hConnect, &hUrl, &fRangeRequestsAccepted); | 250 | hr = MakeRequest(hSession, psczUrl, L"HEAD", NULL, wzUser, wzPassword, pAuthenticate, &hConnect, &hUrl, &fRangeRequestsAccepted); |
236 | ExitOnFailure(hr, "Failed to connect to URL: %ls", *psczUrl); | 251 | DlExitOnFailure(hr, "Failed to connect to URL: %ls", *psczUrl); |
237 | 252 | ||
238 | hr = InternetGetSizeByHandle(hUrl, &llLength); | 253 | hr = InternetGetSizeByHandle(hUrl, &llLength); |
239 | if (FAILED(hr)) | 254 | if (FAILED(hr)) |
@@ -286,12 +301,12 @@ static HRESULT DownloadResource( | |||
286 | hPayloadFile = ::CreateFileW(wzDestinationPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | 301 | hPayloadFile = ::CreateFileW(wzDestinationPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
287 | if (INVALID_HANDLE_VALUE == hPayloadFile) | 302 | if (INVALID_HANDLE_VALUE == hPayloadFile) |
288 | { | 303 | { |
289 | ExitWithLastError(hr, "Failed to create download destination file: %ls", wzDestinationPath); | 304 | DlExitWithLastError(hr, "Failed to create download destination file: %ls", wzDestinationPath); |
290 | } | 305 | } |
291 | 306 | ||
292 | // Allocate a memory block on a page boundary in case we want to do optimal writing. | 307 | // Allocate a memory block on a page boundary in case we want to do optimal writing. |
293 | pbData = static_cast<BYTE*>(::VirtualAlloc(NULL, cbMaxData, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); | 308 | pbData = static_cast<BYTE*>(::VirtualAlloc(NULL, cbMaxData, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); |
294 | ExitOnNullWithLastError(pbData, hr, "Failed to allocate buffer to download files into."); | 309 | DlExitOnNullWithLastError(pbData, hr, "Failed to allocate buffer to download files into."); |
295 | 310 | ||
296 | // Let's try downloading the file assuming that range requests are accepted. If range requests | 311 | // Let's try downloading the file assuming that range requests are accepted. If range requests |
297 | // are not supported we'll have to start over and accept the fact that we only get one shot | 312 | // are not supported we'll have to start over and accept the fact that we only get one shot |
@@ -300,13 +315,13 @@ static HRESULT DownloadResource( | |||
300 | while (fRangeRequestsAccepted && (0 == dw64ResourceLength || dw64ResumeOffset < dw64ResourceLength)) | 315 | while (fRangeRequestsAccepted && (0 == dw64ResourceLength || dw64ResumeOffset < dw64ResourceLength)) |
301 | { | 316 | { |
302 | hr = AllocateRangeRequestHeader(dw64ResumeOffset, 0 == dw64ResourceLength ? dw64AuthoredResourceLength : dw64ResourceLength, &sczRangeRequestHeader); | 317 | hr = AllocateRangeRequestHeader(dw64ResumeOffset, 0 == dw64ResourceLength ? dw64AuthoredResourceLength : dw64ResourceLength, &sczRangeRequestHeader); |
303 | ExitOnFailure(hr, "Failed to allocate range request header."); | 318 | DlExitOnFailure(hr, "Failed to allocate range request header."); |
304 | 319 | ||
305 | ReleaseNullInternet(hConnect); | 320 | ReleaseNullInternet(hConnect); |
306 | ReleaseNullInternet(hUrl); | 321 | ReleaseNullInternet(hUrl); |
307 | 322 | ||
308 | hr = MakeRequest(hSession, psczUrl, L"GET", sczRangeRequestHeader, wzUser, wzPassword, pAuthenticate, &hConnect, &hUrl, &fRangeRequestsAccepted); | 323 | hr = MakeRequest(hSession, psczUrl, L"GET", sczRangeRequestHeader, wzUser, wzPassword, pAuthenticate, &hConnect, &hUrl, &fRangeRequestsAccepted); |
309 | ExitOnFailure(hr, "Failed to request URL for download: %ls", *psczUrl); | 324 | DlExitOnFailure(hr, "Failed to request URL for download: %ls", *psczUrl); |
310 | 325 | ||
311 | // If we didn't get the size of the resource from the initial "HEAD" request | 326 | // If we didn't get the size of the resource from the initial "HEAD" request |
312 | // then let's try to get the size from this "GET" request. | 327 | // then let's try to get the size from this "GET" request. |
@@ -335,7 +350,7 @@ static HRESULT DownloadResource( | |||
335 | } | 350 | } |
336 | 351 | ||
337 | hr = WriteToFile(hUrl, hPayloadFile, &dw64ResumeOffset, hResumeFile, dw64ResourceLength, pbData, cbMaxData, pCache); | 352 | hr = WriteToFile(hUrl, hPayloadFile, &dw64ResumeOffset, hResumeFile, dw64ResourceLength, pbData, cbMaxData, pCache); |
338 | ExitOnFailure(hr, "Failed while reading from internet and writing to: %ls", wzDestinationPath); | 353 | DlExitOnFailure(hr, "Failed while reading from internet and writing to: %ls", wzDestinationPath); |
339 | } | 354 | } |
340 | 355 | ||
341 | LExit: | 356 | LExit: |
@@ -354,7 +369,7 @@ LExit: | |||
354 | static HRESULT AllocateRangeRequestHeader( | 369 | static HRESULT AllocateRangeRequestHeader( |
355 | __in DWORD64 dw64ResumeOffset, | 370 | __in DWORD64 dw64ResumeOffset, |
356 | __in DWORD64 dw64ResourceLength, | 371 | __in DWORD64 dw64ResourceLength, |
357 | __deref_out_z LPWSTR* psczHeader | 372 | __deref_inout_z LPWSTR* psczHeader |
358 | ) | 373 | ) |
359 | { | 374 | { |
360 | HRESULT hr = S_OK; | 375 | HRESULT hr = S_OK; |
@@ -368,7 +383,7 @@ static HRESULT AllocateRangeRequestHeader( | |||
368 | if (0 < dw64ResumeOffset) | 383 | if (0 < dw64ResumeOffset) |
369 | { | 384 | { |
370 | hr = StrAllocFormatted(psczHeader, L"Range: bytes=%I64u-", dw64ResumeOffset); | 385 | hr = StrAllocFormatted(psczHeader, L"Range: bytes=%I64u-", dw64ResumeOffset); |
371 | ExitOnFailure(hr, "Failed to add range read header."); | 386 | DlExitOnFailure(hr, "Failed to add range read header."); |
372 | } | 387 | } |
373 | else | 388 | else |
374 | { | 389 | { |
@@ -378,7 +393,7 @@ static HRESULT AllocateRangeRequestHeader( | |||
378 | else // we'll have to download in chunks. | 393 | else // we'll have to download in chunks. |
379 | { | 394 | { |
380 | hr = StrAllocFormatted(psczHeader, L"Range: bytes=%I64u-%I64u", dw64ResumeOffset, dw64ResumeOffset + dw64RemainingLength - 1); | 395 | hr = StrAllocFormatted(psczHeader, L"Range: bytes=%I64u-%I64u", dw64ResumeOffset, dw64ResumeOffset + dw64RemainingLength - 1); |
381 | ExitOnFailure(hr, "Failed to add range read header."); | 396 | DlExitOnFailure(hr, "Failed to add range read header."); |
382 | } | 397 | } |
383 | 398 | ||
384 | LExit: | 399 | LExit: |
@@ -400,14 +415,14 @@ static HRESULT WriteToFile( | |||
400 | DWORD cbReadData = 0; | 415 | DWORD cbReadData = 0; |
401 | 416 | ||
402 | hr = FileSetPointer(hPayloadFile, *pdw64ResumeOffset, NULL, FILE_BEGIN); | 417 | hr = FileSetPointer(hPayloadFile, *pdw64ResumeOffset, NULL, FILE_BEGIN); |
403 | ExitOnFailure(hr, "Failed to seek to start point in file."); | 418 | DlExitOnFailure(hr, "Failed to seek to start point in file."); |
404 | 419 | ||
405 | do | 420 | do |
406 | { | 421 | { |
407 | // Read bits from the internet. | 422 | // Read bits from the internet. |
408 | if (!::InternetReadFile(hUrl, static_cast<void*>(pbData), cbData, &cbReadData)) | 423 | if (!::InternetReadFile(hUrl, static_cast<void*>(pbData), cbData, &cbReadData)) |
409 | { | 424 | { |
410 | ExitWithLastError(hr, "Failed while reading from internet."); | 425 | DlExitWithLastError(hr, "Failed while reading from internet."); |
411 | } | 426 | } |
412 | 427 | ||
413 | // Write bits to disk (if there are any). | 428 | // Write bits to disk (if there are any). |
@@ -419,7 +434,7 @@ static HRESULT WriteToFile( | |||
419 | { | 434 | { |
420 | if (!::WriteFile(hPayloadFile, pbData + cbTotalWritten, cbReadData - cbTotalWritten, &cbWritten, NULL)) | 435 | if (!::WriteFile(hPayloadFile, pbData + cbTotalWritten, cbReadData - cbTotalWritten, &cbWritten, NULL)) |
421 | { | 436 | { |
422 | ExitWithLastError(hr, "Failed to write data from internet."); | 437 | DlExitWithLastError(hr, "Failed to write data from internet."); |
423 | } | 438 | } |
424 | 439 | ||
425 | cbTotalWritten += cbWritten; | 440 | cbTotalWritten += cbWritten; |
@@ -431,7 +446,7 @@ static HRESULT WriteToFile( | |||
431 | if (pCallback && pCallback->pfnProgress) | 446 | if (pCallback && pCallback->pfnProgress) |
432 | { | 447 | { |
433 | hr = DownloadSendProgressCallback(pCallback, *pdw64ResumeOffset, dw64ResourceLength, hPayloadFile); | 448 | hr = DownloadSendProgressCallback(pCallback, *pdw64ResumeOffset, dw64ResourceLength, hPayloadFile); |
434 | ExitOnFailure(hr, "UX aborted on cache progress."); | 449 | DlExitOnFailure(hr, "UX aborted on cache progress."); |
435 | } | 450 | } |
436 | } | 451 | } |
437 | } while (cbReadData); | 452 | } while (cbReadData); |
@@ -456,14 +471,14 @@ static HRESULT UpdateResumeOffset( | |||
456 | DWORD cbWrittenResumeData = 0; | 471 | DWORD cbWrittenResumeData = 0; |
457 | 472 | ||
458 | hr = FileSetPointer(hResumeFile, 0, NULL, FILE_BEGIN); | 473 | hr = FileSetPointer(hResumeFile, 0, NULL, FILE_BEGIN); |
459 | ExitOnFailure(hr, "Failed to seek to start point in file."); | 474 | DlExitOnFailure(hr, "Failed to seek to start point in file."); |
460 | 475 | ||
461 | do | 476 | do |
462 | { | 477 | { |
463 | // Ignore failure to write to the resume file as that should not prevent the download from happening. | 478 | // Ignore failure to write to the resume file as that should not prevent the download from happening. |
464 | if (!::WriteFile(hResumeFile, pdw64ResumeOffset + cbTotalWrittenResumeData, sizeof(DWORD64) - cbTotalWrittenResumeData, &cbWrittenResumeData, NULL)) | 479 | if (!::WriteFile(hResumeFile, pdw64ResumeOffset + cbTotalWrittenResumeData, sizeof(DWORD64) - cbTotalWrittenResumeData, &cbWrittenResumeData, NULL)) |
465 | { | 480 | { |
466 | ExitOnFailure(hr, "Failed to seek to write to file."); | 481 | DlExitOnFailure(hr, "Failed to seek to write to file."); |
467 | } | 482 | } |
468 | 483 | ||
469 | cbTotalWrittenResumeData += cbWrittenResumeData; | 484 | cbTotalWrittenResumeData += cbWrittenResumeData; |
@@ -504,10 +519,10 @@ static HRESULT MakeRequest( | |||
504 | 519 | ||
505 | // Open the url. | 520 | // Open the url. |
506 | hr = UriCrackEx(*psczSourceUrl, &uri); | 521 | hr = UriCrackEx(*psczSourceUrl, &uri); |
507 | ExitOnFailure(hr, "Failed to break URL into server and resource parts."); | 522 | DlExitOnFailure(hr, "Failed to break URL into server and resource parts."); |
508 | 523 | ||
509 | hConnect = ::InternetConnectW(hSession, uri.sczHostName, uri.port, (wzUser && *wzUser) ? wzUser : uri.sczUser, (wzPassword && *wzPassword) ? wzPassword : uri.sczPassword, INTERNET_SCHEME_FTP == uri.scheme ? INTERNET_SERVICE_FTP : INTERNET_SERVICE_HTTP, 0, 0); | 524 | hConnect = ::InternetConnectW(hSession, uri.sczHostName, uri.port, (wzUser && *wzUser) ? wzUser : uri.sczUser, (wzPassword && *wzPassword) ? wzPassword : uri.sczPassword, INTERNET_SCHEME_FTP == uri.scheme ? INTERNET_SERVICE_FTP : INTERNET_SERVICE_HTTP, 0, 0); |
510 | ExitOnNullWithLastError(hConnect, hr, "Failed to connect to URL: %ls", *psczSourceUrl); | 525 | DlExitOnNullWithLastError(hConnect, hr, "Failed to connect to URL: %ls", *psczSourceUrl); |
511 | 526 | ||
512 | // Best effort set the proxy username and password, if they were provided. | 527 | // Best effort set the proxy username and password, if they were provided. |
513 | if ((wzUser && *wzUser) && (wzPassword && *wzPassword)) | 528 | if ((wzUser && *wzUser) && (wzPassword && *wzPassword)) |
@@ -519,10 +534,10 @@ static HRESULT MakeRequest( | |||
519 | } | 534 | } |
520 | 535 | ||
521 | hr = OpenRequest(hConnect, wzMethod, uri.scheme, uri.sczPath, uri.sczQueryString, wzHeaders, &hUrl); | 536 | hr = OpenRequest(hConnect, wzMethod, uri.scheme, uri.sczPath, uri.sczQueryString, wzHeaders, &hUrl); |
522 | ExitOnFailure(hr, "Failed to open internet URL: %ls", *psczSourceUrl); | 537 | DlExitOnFailure(hr, "Failed to open internet URL: %ls", *psczSourceUrl); |
523 | 538 | ||
524 | hr = SendRequest(hUrl, psczSourceUrl, pAuthenticate, &fRetry, pfRangeRequestsAccepted); | 539 | hr = SendRequest(hUrl, psczSourceUrl, pAuthenticate, &fRetry, pfRangeRequestsAccepted); |
525 | ExitOnFailure(hr, "Failed to send request to URL: %ls", *psczSourceUrl); | 540 | DlExitOnFailure(hr, "Failed to send request to URL: %ls", *psczSourceUrl); |
526 | } while (fRetry); | 541 | } while (fRetry); |
527 | 542 | ||
528 | // Okay, we're all ready to start downloading. Update the connection information. | 543 | // Okay, we're all ready to start downloading. Update the connection information. |
@@ -565,23 +580,23 @@ static HRESULT OpenRequest( | |||
565 | 580 | ||
566 | // Allocate the resource name. | 581 | // Allocate the resource name. |
567 | hr = StrAllocString(&sczResource, wzResource, 0); | 582 | hr = StrAllocString(&sczResource, wzResource, 0); |
568 | ExitOnFailure(hr, "Failed to allocate string for resource URI."); | 583 | DlExitOnFailure(hr, "Failed to allocate string for resource URI."); |
569 | 584 | ||
570 | if (wzQueryString && *wzQueryString) | 585 | if (wzQueryString && *wzQueryString) |
571 | { | 586 | { |
572 | hr = StrAllocConcat(&sczResource, wzQueryString, 0); | 587 | hr = StrAllocConcat(&sczResource, wzQueryString, 0); |
573 | ExitOnFailure(hr, "Failed to append query strong to resource from URI."); | 588 | DlExitOnFailure(hr, "Failed to append query strong to resource from URI."); |
574 | } | 589 | } |
575 | 590 | ||
576 | // Open the request and add the header if provided. | 591 | // Open the request and add the header if provided. |
577 | hUrl = ::HttpOpenRequestW(hConnect, wzMethod, sczResource, NULL, NULL, DOWNLOAD_ENGINE_ACCEPT_TYPES, dwRequestFlags, NULL); | 592 | hUrl = ::HttpOpenRequestW(hConnect, wzMethod, sczResource, NULL, NULL, DOWNLOAD_ENGINE_ACCEPT_TYPES, dwRequestFlags, NULL); |
578 | ExitOnNullWithLastError(hUrl, hr, "Failed to open internet request."); | 593 | DlExitOnNullWithLastError(hUrl, hr, "Failed to open internet request."); |
579 | 594 | ||
580 | if (wzHeader && *wzHeader) | 595 | if (wzHeader && *wzHeader) |
581 | { | 596 | { |
582 | if (!::HttpAddRequestHeadersW(hUrl, wzHeader, static_cast<DWORD>(-1), HTTP_ADDREQ_FLAG_COALESCE)) | 597 | if (!::HttpAddRequestHeadersW(hUrl, wzHeader, static_cast<DWORD>(-1), HTTP_ADDREQ_FLAG_COALESCE)) |
583 | { | 598 | { |
584 | ExitWithLastError(hr, "Failed to add header to HTTP request."); | 599 | DlExitWithLastError(hr, "Failed to add header to HTTP request."); |
585 | } | 600 | } |
586 | } | 601 | } |
587 | 602 | ||
@@ -618,12 +633,12 @@ static HRESULT SendRequest( | |||
618 | // Try to get the HTTP status code and, if good, handle via the switch statement below but if it | 633 | // Try to get the HTTP status code and, if good, handle via the switch statement below but if it |
619 | // fails return the error code from the send request above as the result of the function. | 634 | // fails return the error code from the send request above as the result of the function. |
620 | HRESULT hrQueryStatusCode = InternetQueryInfoNumber(hUrl, HTTP_QUERY_STATUS_CODE, &lCode); | 635 | HRESULT hrQueryStatusCode = InternetQueryInfoNumber(hUrl, HTTP_QUERY_STATUS_CODE, &lCode); |
621 | ExitOnFailure(hrQueryStatusCode, "Failed to get HTTP status code for failed request to URL: %ls", *psczUrl); | 636 | DlExitOnFailure(hrQueryStatusCode, "Failed to get HTTP status code for failed request to URL: %ls", *psczUrl); |
622 | } | 637 | } |
623 | else // get the http status code. | 638 | else // get the http status code. |
624 | { | 639 | { |
625 | hr = InternetQueryInfoNumber(hUrl, HTTP_QUERY_STATUS_CODE, &lCode); | 640 | hr = InternetQueryInfoNumber(hUrl, HTTP_QUERY_STATUS_CODE, &lCode); |
626 | ExitOnFailure(hr, "Failed to get HTTP status code for request to URL: %ls", *psczUrl); | 641 | DlExitOnFailure(hr, "Failed to get HTTP status code for request to URL: %ls", *psczUrl); |
627 | } | 642 | } |
628 | 643 | ||
629 | switch (lCode) | 644 | switch (lCode) |
@@ -643,7 +658,7 @@ static HRESULT SendRequest( | |||
643 | case 302: __fallthrough; // temporary | 658 | case 302: __fallthrough; // temporary |
644 | case 303: // redirect method | 659 | case 303: // redirect method |
645 | hr = InternetQueryInfoString(hUrl, HTTP_QUERY_CONTENT_LOCATION, psczUrl); | 660 | hr = InternetQueryInfoString(hUrl, HTTP_QUERY_CONTENT_LOCATION, psczUrl); |
646 | ExitOnFailure(hr, "Failed to get redirect url: %ls", *psczUrl); | 661 | DlExitOnFailure(hr, "Failed to get redirect url: %ls", *psczUrl); |
647 | 662 | ||
648 | *pfRetry = TRUE; | 663 | *pfRetry = TRUE; |
649 | break; | 664 | break; |
@@ -734,7 +749,7 @@ static HRESULT DownloadGetResumePath( | |||
734 | HRESULT hr = S_OK; | 749 | HRESULT hr = S_OK; |
735 | 750 | ||
736 | hr = StrAllocFormatted(psczResumePath, L"%ls.R", wzPayloadWorkingPath); | 751 | hr = StrAllocFormatted(psczResumePath, L"%ls.R", wzPayloadWorkingPath); |
737 | ExitOnFailure(hr, "Failed to create resume path."); | 752 | DlExitOnFailure(hr, "Failed to create resume path."); |
738 | 753 | ||
739 | LExit: | 754 | LExit: |
740 | return hr; | 755 | return hr; |
@@ -769,7 +784,7 @@ static HRESULT DownloadSendProgressCallback( | |||
769 | case PROGRESS_CANCEL: __fallthrough; // TODO: should cancel and stop be treated differently? | 784 | case PROGRESS_CANCEL: __fallthrough; // TODO: should cancel and stop be treated differently? |
770 | case PROGRESS_STOP: | 785 | case PROGRESS_STOP: |
771 | hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT); | 786 | hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT); |
772 | ExitOnRootFailure(hr, "UX aborted on download progress."); | 787 | DlExitOnRootFailure(hr, "UX aborted on download progress."); |
773 | 788 | ||
774 | case PROGRESS_QUIET: // Not actually an error, just an indication to the caller to stop requesting progress. | 789 | case PROGRESS_QUIET: // Not actually an error, just an indication to the caller to stop requesting progress. |
775 | pCallback->pfnProgress = NULL; | 790 | pCallback->pfnProgress = NULL; |
@@ -778,7 +793,7 @@ static HRESULT DownloadSendProgressCallback( | |||
778 | 793 | ||
779 | default: | 794 | default: |
780 | hr = E_UNEXPECTED; | 795 | hr = E_UNEXPECTED; |
781 | ExitOnRootFailure(hr, "Invalid return code from progress routine."); | 796 | DlExitOnRootFailure(hr, "Invalid return code from progress routine."); |
782 | } | 797 | } |
783 | } | 798 | } |
784 | 799 | ||
diff --git a/src/dutil/dutil.cpp b/src/dutil/dutil.cpp index 99ce1bc6..c500191a 100644 --- a/src/dutil/dutil.cpp +++ b/src/dutil/dutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define DExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DUTIL, x, s, __VA_ARGS__) | ||
8 | #define DExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DUTIL, x, s, __VA_ARGS__) | ||
9 | #define DExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DUTIL, x, s, __VA_ARGS__) | ||
10 | #define DExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DUTIL, x, s, __VA_ARGS__) | ||
11 | #define DExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DUTIL, x, s, __VA_ARGS__) | ||
12 | #define DExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DUTIL, x, s, __VA_ARGS__) | ||
13 | #define DExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define DExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define DExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define DExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define DExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define DExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | // No need for OACR to warn us about using non-unicode APIs in this file. | 20 | // No need for OACR to warn us about using non-unicode APIs in this file. |
6 | #pragma prefast(disable:25068) | 21 | #pragma prefast(disable:25068) |
7 | 22 | ||
@@ -84,7 +99,7 @@ extern "C" void DAPI Dutil_AssertMsg( | |||
84 | 99 | ||
85 | char szMsg[DUTIL_STRING_BUFFER]; | 100 | char szMsg[DUTIL_STRING_BUFFER]; |
86 | hr = ::StringCchCopyA(szMsg, countof(szMsg), szMessage); | 101 | hr = ::StringCchCopyA(szMsg, countof(szMsg), szMessage); |
87 | ExitOnFailure(hr, "failed to copy message while building assert message"); | 102 | DExitOnFailure(hr, "failed to copy message while building assert message"); |
88 | 103 | ||
89 | if (Dutil_pfnDisplayAssert) | 104 | if (Dutil_pfnDisplayAssert) |
90 | { | 105 | { |
@@ -123,7 +138,7 @@ extern "C" void DAPI Dutil_AssertMsg( | |||
123 | if (ERROR_SUCCESS != er) | 138 | if (ERROR_SUCCESS != er) |
124 | { | 139 | { |
125 | hr = ::StringCchCatA(szMsg, countof(szMsg), "\nAbort=Debug, Retry=Skip, Ignore=Skip all"); | 140 | hr = ::StringCchCatA(szMsg, countof(szMsg), "\nAbort=Debug, Retry=Skip, Ignore=Skip all"); |
126 | ExitOnFailure(hr, "failed to concat string while building assert message"); | 141 | DExitOnFailure(hr, "failed to concat string while building assert message"); |
127 | 142 | ||
128 | id = ::MessageBoxA(0, szMsg, "Debug Assert Message", | 143 | id = ::MessageBoxA(0, szMsg, "Debug Assert Message", |
129 | MB_SERVICE_NOTIFICATION | MB_TOPMOST | | 144 | MB_SERVICE_NOTIFICATION | MB_TOPMOST | |
@@ -480,24 +495,24 @@ extern "C" HRESULT DAPI LoadSystemLibraryWithPath( | |||
480 | WCHAR wzPath[MAX_PATH] = { }; | 495 | WCHAR wzPath[MAX_PATH] = { }; |
481 | 496 | ||
482 | cch = ::GetSystemDirectoryW(wzPath, MAX_PATH); | 497 | cch = ::GetSystemDirectoryW(wzPath, MAX_PATH); |
483 | ExitOnNullWithLastError(cch, hr, "Failed to get the Windows system directory."); | 498 | DExitOnNullWithLastError(cch, hr, "Failed to get the Windows system directory."); |
484 | 499 | ||
485 | if (L'\\' != wzPath[cch - 1]) | 500 | if (L'\\' != wzPath[cch - 1]) |
486 | { | 501 | { |
487 | hr = ::StringCchCatNW(wzPath, MAX_PATH, L"\\", 1); | 502 | hr = ::StringCchCatNW(wzPath, MAX_PATH, L"\\", 1); |
488 | ExitOnRootFailure(hr, "Failed to terminate the string with a backslash."); | 503 | DExitOnRootFailure(hr, "Failed to terminate the string with a backslash."); |
489 | } | 504 | } |
490 | 505 | ||
491 | hr = ::StringCchCatW(wzPath, MAX_PATH, wzModuleName); | 506 | hr = ::StringCchCatW(wzPath, MAX_PATH, wzModuleName); |
492 | ExitOnRootFailure(hr, "Failed to create the fully-qualified path to %ls.", wzModuleName); | 507 | DExitOnRootFailure(hr, "Failed to create the fully-qualified path to %ls.", wzModuleName); |
493 | 508 | ||
494 | *phModule = ::LoadLibraryW(wzPath); | 509 | *phModule = ::LoadLibraryW(wzPath); |
495 | ExitOnNullWithLastError(*phModule, hr, "Failed to load the library %ls.", wzModuleName); | 510 | DExitOnNullWithLastError(*phModule, hr, "Failed to load the library %ls.", wzModuleName); |
496 | 511 | ||
497 | if (psczPath) | 512 | if (psczPath) |
498 | { | 513 | { |
499 | hr = StrAllocString(psczPath, wzPath, MAX_PATH); | 514 | hr = StrAllocString(psczPath, wzPath, MAX_PATH); |
500 | ExitOnFailure(hr, "Failed to copy the path to library."); | 515 | DExitOnFailure(hr, "Failed to copy the path to library."); |
501 | } | 516 | } |
502 | 517 | ||
503 | LExit: | 518 | LExit: |
diff --git a/src/dutil/eseutil.cpp b/src/dutil/eseutil.cpp index 599a3943..d2bd7dc5 100644 --- a/src/dutil/eseutil.cpp +++ b/src/dutil/eseutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define EseExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__) | ||
8 | #define EseExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__) | ||
9 | #define EseExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__) | ||
10 | #define EseExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__) | ||
11 | #define EseExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__) | ||
12 | #define EseExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__) | ||
13 | #define EseExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_ESEUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define EseExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_ESEUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define EseExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_ESEUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define EseExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_ESEUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define EseExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_ESEUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define EseExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_ESEUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | struct ESE_QUERY | 20 | struct ESE_QUERY |
6 | { | 21 | { |
7 | ESE_QUERY_TYPE qtQueryType; | 22 | ESE_QUERY_TYPE qtQueryType; |
@@ -85,13 +100,13 @@ HRESULT HresultFromJetError(JET_ERR jEr) | |||
85 | } | 100 | } |
86 | 101 | ||
87 | // Log the actual Jet error code so we have record of it before it's morphed into an HRESULT to be compatible with the rest of our code | 102 | // Log the actual Jet error code so we have record of it before it's morphed into an HRESULT to be compatible with the rest of our code |
88 | ExitTraceSource(DUTIL_SOURCE_DEFAULT, hr, "Encountered Jet Error: 0x%08x", jEr); | 103 | ExitTraceSource(DUTIL_SOURCE_ESEUTIL, hr, "Encountered Jet Error: 0x%08x", jEr); |
89 | 104 | ||
90 | return hr; | 105 | return hr; |
91 | } | 106 | } |
92 | 107 | ||
93 | #define ExitOnJetFailure(e, x, s, ...) { x = HresultFromJetError(e); if (S_OK != x) { ExitTraceSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__); goto LExit; }} | 108 | #define ExitOnJetFailure(e, x, s, ...) { x = HresultFromJetError(e); if (S_OK != x) { ExitTraceSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__); goto LExit; }} |
94 | #define ExitOnRootJetFailure(e, x, s, ...) { x = HresultFromJetError(e); if (S_OK != x) { Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__); goto LExit; }} | 109 | #define ExitOnRootJetFailure(e, x, s, ...) { x = HresultFromJetError(e); if (S_OK != x) { Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(DUTIL_SOURCE_ESEUTIL, x, s, __VA_ARGS__); goto LExit; }} |
95 | 110 | ||
96 | HRESULT DAPI EseBeginSession( | 111 | HRESULT DAPI EseBeginSession( |
97 | __out JET_INSTANCE *pjiInstance, | 112 | __out JET_INSTANCE *pjiInstance, |
@@ -106,15 +121,15 @@ HRESULT DAPI EseBeginSession( | |||
106 | LPSTR pszAnsiPath = NULL; | 121 | LPSTR pszAnsiPath = NULL; |
107 | 122 | ||
108 | hr = DirEnsureExists(pszPath, NULL); | 123 | hr = DirEnsureExists(pszPath, NULL); |
109 | ExitOnFailure(hr, "Failed to ensure database directory exists"); | 124 | EseExitOnFailure(hr, "Failed to ensure database directory exists"); |
110 | 125 | ||
111 | // Sigh. JETblue requires Vista and up for the wide character version of this function, so we'll convert to ANSI before calling, | 126 | // Sigh. JETblue requires Vista and up for the wide character version of this function, so we'll convert to ANSI before calling, |
112 | // likely breaking everyone with unicode characters in their path. | 127 | // likely breaking everyone with unicode characters in their path. |
113 | hr = StrAnsiAllocString(&pszAnsiInstance, pszInstance, 0, CP_ACP); | 128 | hr = StrAnsiAllocString(&pszAnsiInstance, pszInstance, 0, CP_ACP); |
114 | ExitOnFailure(hr, "Failed converting instance name to ansi"); | 129 | EseExitOnFailure(hr, "Failed converting instance name to ansi"); |
115 | 130 | ||
116 | hr = StrAnsiAllocString(&pszAnsiPath, pszPath, 0, CP_ACP); | 131 | hr = StrAnsiAllocString(&pszAnsiPath, pszPath, 0, CP_ACP); |
117 | ExitOnFailure(hr, "Failed converting session path name to ansi"); | 132 | EseExitOnFailure(hr, "Failed converting session path name to ansi"); |
118 | 133 | ||
119 | jEr = JetCreateInstanceA(pjiInstance, pszAnsiInstance); | 134 | jEr = JetCreateInstanceA(pjiInstance, pszAnsiInstance); |
120 | ExitOnJetFailure(jEr, hr, "Failed to create instance"); | 135 | ExitOnJetFailure(jEr, hr, "Failed to create instance"); |
@@ -173,17 +188,17 @@ HRESULT AllocColumnCreateStruct( | |||
173 | size_t cbAllocSize = 0; | 188 | size_t cbAllocSize = 0; |
174 | 189 | ||
175 | hr = ::SizeTMult(ptsSchema->dwColumns, sizeof(JET_COLUMNCREATE), &(cbAllocSize)); | 190 | hr = ::SizeTMult(ptsSchema->dwColumns, sizeof(JET_COLUMNCREATE), &(cbAllocSize)); |
176 | ExitOnFailure(hr, "Maximum allocation exceeded."); | 191 | EseExitOnFailure(hr, "Maximum allocation exceeded."); |
177 | 192 | ||
178 | *ppjccColumnCreate = static_cast<JET_COLUMNCREATE*>(MemAlloc(cbAllocSize, TRUE)); | 193 | *ppjccColumnCreate = static_cast<JET_COLUMNCREATE*>(MemAlloc(cbAllocSize, TRUE)); |
179 | ExitOnNull(*ppjccColumnCreate, hr, E_OUTOFMEMORY, "Failed to allocate column create structure for database"); | 194 | EseExitOnNull(*ppjccColumnCreate, hr, E_OUTOFMEMORY, "Failed to allocate column create structure for database"); |
180 | 195 | ||
181 | for (i = 0; i < ptsSchema->dwColumns; ++i) | 196 | for (i = 0; i < ptsSchema->dwColumns; ++i) |
182 | { | 197 | { |
183 | (*ppjccColumnCreate)[i].cbStruct = sizeof(JET_COLUMNCREATE); | 198 | (*ppjccColumnCreate)[i].cbStruct = sizeof(JET_COLUMNCREATE); |
184 | 199 | ||
185 | hr = StrAnsiAllocString(&(*ppjccColumnCreate)[i].szColumnName, ptsSchema->pcsColumns[i].pszName, 0, CP_ACP); | 200 | hr = StrAnsiAllocString(&(*ppjccColumnCreate)[i].szColumnName, ptsSchema->pcsColumns[i].pszName, 0, CP_ACP); |
186 | ExitOnFailure(hr, "Failed to allocate ansi column name: %ls", ptsSchema->pcsColumns[i].pszName); | 201 | EseExitOnFailure(hr, "Failed to allocate ansi column name: %ls", ptsSchema->pcsColumns[i].pszName); |
187 | 202 | ||
188 | (*ppjccColumnCreate)[i].coltyp = ptsSchema->pcsColumns[i].jcColumnType; | 203 | (*ppjccColumnCreate)[i].coltyp = ptsSchema->pcsColumns[i].jcColumnType; |
189 | 204 | ||
@@ -237,7 +252,7 @@ HRESULT FreeColumnCreateStruct( | |||
237 | } | 252 | } |
238 | 253 | ||
239 | hr = MemFree(pjccColumnCreate); | 254 | hr = MemFree(pjccColumnCreate); |
240 | ExitOnFailure(hr, "Failed to release core column create struct"); | 255 | EseExitOnFailure(hr, "Failed to release core column create struct"); |
241 | 256 | ||
242 | LExit: | 257 | LExit: |
243 | return hr; | 258 | return hr; |
@@ -261,20 +276,20 @@ HRESULT AllocIndexCreateStruct( | |||
261 | if (ptsSchema->pcsColumns[i].fKey) | 276 | if (ptsSchema->pcsColumns[i].fKey) |
262 | { | 277 | { |
263 | hr = StrAnsiAllocString(&pszTempString, ptsSchema->pcsColumns[i].pszName, 0, CP_ACP); | 278 | hr = StrAnsiAllocString(&pszTempString, ptsSchema->pcsColumns[i].pszName, 0, CP_ACP); |
264 | ExitOnFailure(hr, "Failed to convert string to ansi: %ls", ptsSchema->pcsColumns[i].pszName); | 279 | EseExitOnFailure(hr, "Failed to convert string to ansi: %ls", ptsSchema->pcsColumns[i].pszName); |
265 | 280 | ||
266 | hr = StrAnsiAllocConcat(&pszMultiSzKeys, "+", 0); | 281 | hr = StrAnsiAllocConcat(&pszMultiSzKeys, "+", 0); |
267 | ExitOnFailure(hr, "Failed to append plus sign to multisz string: %s", pszTempString); | 282 | EseExitOnFailure(hr, "Failed to append plus sign to multisz string: %s", pszTempString); |
268 | 283 | ||
269 | hr = StrAnsiAllocConcat(&pszMultiSzKeys, pszTempString, 0); | 284 | hr = StrAnsiAllocConcat(&pszMultiSzKeys, pszTempString, 0); |
270 | ExitOnFailure(hr, "Failed to append column name to multisz string: %s", pszTempString); | 285 | EseExitOnFailure(hr, "Failed to append column name to multisz string: %s", pszTempString); |
271 | 286 | ||
272 | ReleaseNullStr(pszTempString); | 287 | ReleaseNullStr(pszTempString); |
273 | 288 | ||
274 | // All question marks will be converted to null characters later; this is just to trick dutil | 289 | // All question marks will be converted to null characters later; this is just to trick dutil |
275 | // into letting us create an ansi, double-null-terminated list of single-null-terminated strings | 290 | // into letting us create an ansi, double-null-terminated list of single-null-terminated strings |
276 | hr = StrAnsiAllocConcat(&pszMultiSzKeys, "?", 0); | 291 | hr = StrAnsiAllocConcat(&pszMultiSzKeys, "?", 0); |
277 | ExitOnFailure(hr, "Failed to append placeholder character to multisz string: %ls", pszMultiSzKeys); | 292 | EseExitOnFailure(hr, "Failed to append placeholder character to multisz string: %hs", pszMultiSzKeys); |
278 | 293 | ||
279 | // Record that at least one key column was found | 294 | // Record that at least one key column was found |
280 | fKeyColumns = TRUE; | 295 | fKeyColumns = TRUE; |
@@ -288,18 +303,18 @@ HRESULT AllocIndexCreateStruct( | |||
288 | } | 303 | } |
289 | 304 | ||
290 | hr = StrAnsiAllocString(&pszIndexName, ptsSchema->pszName, 0, CP_ACP); | 305 | hr = StrAnsiAllocString(&pszIndexName, ptsSchema->pszName, 0, CP_ACP); |
291 | ExitOnFailure(hr, "Failed to allocate ansi string version of %ls", ptsSchema->pszName); | 306 | EseExitOnFailure(hr, "Failed to allocate ansi string version of %ls", ptsSchema->pszName); |
292 | 307 | ||
293 | hr = StrAnsiAllocConcat(&pszIndexName, "_Index", 0); | 308 | hr = StrAnsiAllocConcat(&pszIndexName, "_Index", 0); |
294 | ExitOnFailure(hr, "Failed to append table name string version of %ls", ptsSchema->pszName); | 309 | EseExitOnFailure(hr, "Failed to append table name string version of %ls", ptsSchema->pszName); |
295 | 310 | ||
296 | *ppjicIndexCreate = static_cast<JET_INDEXCREATE*>(MemAlloc(sizeof(JET_INDEXCREATE), TRUE)); | 311 | *ppjicIndexCreate = static_cast<JET_INDEXCREATE*>(MemAlloc(sizeof(JET_INDEXCREATE), TRUE)); |
297 | ExitOnNull(*ppjicIndexCreate, hr, E_OUTOFMEMORY, "Failed to allocate index create structure for database"); | 312 | EseExitOnNull(*ppjicIndexCreate, hr, E_OUTOFMEMORY, "Failed to allocate index create structure for database"); |
298 | 313 | ||
299 | // Record the size including both null terminators - the struct requires this | 314 | // Record the size including both null terminators - the struct requires this |
300 | DWORD dwSize = 0; | 315 | DWORD dwSize = 0; |
301 | dwSize = lstrlen(pszMultiSzKeys) + 1; // add 1 to include null character at the end | 316 | dwSize = lstrlen(pszMultiSzKeys) + 1; // add 1 to include null character at the end |
302 | ExitOnFailure(hr, "Failed to get size of keys string"); | 317 | EseExitOnFailure(hr, "Failed to get size of keys string"); |
303 | 318 | ||
304 | // At this point convert all question marks to null characters | 319 | // At this point convert all question marks to null characters |
305 | for (i = 0; i < dwSize; ++i) | 320 | for (i = 0; i < dwSize; ++i) |
@@ -349,7 +364,7 @@ HRESULT EnsureSchema( | |||
349 | jtTableCreate.cIndexes = 1; | 364 | jtTableCreate.cIndexes = 1; |
350 | 365 | ||
351 | hr = EseBeginTransaction(jsSession); | 366 | hr = EseBeginTransaction(jsSession); |
352 | ExitOnFailure(hr, "Failed to begin transaction to create tables"); | 367 | EseExitOnFailure(hr, "Failed to begin transaction to create tables"); |
353 | fTransaction = TRUE; | 368 | fTransaction = TRUE; |
354 | 369 | ||
355 | for (dwTable = 0;dwTable < pdsSchema->dwTables; ++dwTable) | 370 | for (dwTable = 0;dwTable < pdsSchema->dwTables; ++dwTable) |
@@ -363,13 +378,13 @@ HRESULT EnsureSchema( | |||
363 | { | 378 | { |
364 | // Fill out the JET_TABLECREATE struct | 379 | // Fill out the JET_TABLECREATE struct |
365 | hr = StrAnsiAllocString(&jtTableCreate.szTableName, pdsSchema->ptsTables[dwTable].pszName, 0, CP_ACP); | 380 | hr = StrAnsiAllocString(&jtTableCreate.szTableName, pdsSchema->ptsTables[dwTable].pszName, 0, CP_ACP); |
366 | ExitOnFailure(hr, "Failed converting table name to ansi"); | 381 | EseExitOnFailure(hr, "Failed converting table name to ansi"); |
367 | 382 | ||
368 | hr = AllocColumnCreateStruct(&(pdsSchema->ptsTables[dwTable]), &jtTableCreate.rgcolumncreate); | 383 | hr = AllocColumnCreateStruct(&(pdsSchema->ptsTables[dwTable]), &jtTableCreate.rgcolumncreate); |
369 | ExitOnFailure(hr, "Failed to allocate column create struct"); | 384 | EseExitOnFailure(hr, "Failed to allocate column create struct"); |
370 | 385 | ||
371 | hr = AllocIndexCreateStruct(&(pdsSchema->ptsTables[dwTable]), &jtTableCreate.rgindexcreate); | 386 | hr = AllocIndexCreateStruct(&(pdsSchema->ptsTables[dwTable]), &jtTableCreate.rgindexcreate); |
372 | ExitOnFailure(hr, "Failed to allocate index create struct"); | 387 | EseExitOnFailure(hr, "Failed to allocate index create struct"); |
373 | 388 | ||
374 | jtTableCreate.cColumns = pdsSchema->ptsTables[dwTable].dwColumns; | 389 | jtTableCreate.cColumns = pdsSchema->ptsTables[dwTable].dwColumns; |
375 | jtTableCreate.tableid = NULL; | 390 | jtTableCreate.tableid = NULL; |
@@ -392,7 +407,7 @@ HRESULT EnsureSchema( | |||
392 | ReleaseNullStr(jtTableCreate.szTableName); | 407 | ReleaseNullStr(jtTableCreate.szTableName); |
393 | 408 | ||
394 | hr = FreeColumnCreateStruct(jtTableCreate.rgcolumncreate, jtTableCreate.cColumns); | 409 | hr = FreeColumnCreateStruct(jtTableCreate.rgcolumncreate, jtTableCreate.cColumns); |
395 | ExitOnFailure(hr, "Failed to free column create struct"); | 410 | EseExitOnFailure(hr, "Failed to free column create struct"); |
396 | jtTableCreate.rgcolumncreate = NULL; | 411 | jtTableCreate.rgcolumncreate = NULL; |
397 | } | 412 | } |
398 | else | 413 | else |
@@ -422,7 +437,7 @@ HRESULT EnsureSchema( | |||
422 | } | 437 | } |
423 | 438 | ||
424 | hr = EseEnsureColumn(jsSession, pdsSchema->ptsTables[dwTable].jtTable, pcsColumn->pszName, pcsColumn->jcColumnType, ulColumnSize, pcsColumn->fFixed, fNullable, &pcsColumn->jcColumn); | 439 | hr = EseEnsureColumn(jsSession, pdsSchema->ptsTables[dwTable].jtTable, pcsColumn->pszName, pcsColumn->jcColumnType, ulColumnSize, pcsColumn->fFixed, fNullable, &pcsColumn->jcColumn); |
425 | ExitOnFailure(hr, "Failed to create column %u of %ls table", dwColumn, pwzTableName); | 440 | EseExitOnFailure(hr, "Failed to create column %u of %ls table", dwColumn, pwzTableName); |
426 | } | 441 | } |
427 | } | 442 | } |
428 | } | 443 | } |
@@ -464,13 +479,13 @@ HRESULT DAPI EseEnsureDatabase( | |||
464 | // Sigh. JETblue requires Vista and up for the wide character version of this function, so we'll convert to ANSI before calling, | 479 | // Sigh. JETblue requires Vista and up for the wide character version of this function, so we'll convert to ANSI before calling, |
465 | // likely breaking all those with unicode characters in their path. | 480 | // likely breaking all those with unicode characters in their path. |
466 | hr = StrAnsiAllocString(&pszAnsiFile, pszFile, 0, CP_ACP); | 481 | hr = StrAnsiAllocString(&pszAnsiFile, pszFile, 0, CP_ACP); |
467 | ExitOnFailure(hr, "Failed converting database name to ansi"); | 482 | EseExitOnFailure(hr, "Failed converting database name to ansi"); |
468 | 483 | ||
469 | hr = PathGetDirectory(pszFile, &pszDir); | 484 | hr = PathGetDirectory(pszFile, &pszDir); |
470 | ExitOnFailure(hr, "Failed to get directory that will contain database file"); | 485 | EseExitOnFailure(hr, "Failed to get directory that will contain database file"); |
471 | 486 | ||
472 | hr = DirEnsureExists(pszDir, NULL); | 487 | hr = DirEnsureExists(pszDir, NULL); |
473 | ExitOnFailure(hr, "Failed to ensure directory exists for database: %ls", pszDir); | 488 | EseExitOnFailure(hr, "Failed to ensure directory exists for database: %ls", pszDir); |
474 | 489 | ||
475 | if (FileExistsEx(pszFile, NULL)) | 490 | if (FileExistsEx(pszFile, NULL)) |
476 | { | 491 | { |
@@ -498,7 +513,7 @@ HRESULT DAPI EseEnsureDatabase( | |||
498 | } | 513 | } |
499 | 514 | ||
500 | hr = EnsureSchema(*pjdbDb, jsSession, pdsSchema); | 515 | hr = EnsureSchema(*pjdbDb, jsSession, pdsSchema); |
501 | ExitOnFailure(hr, "Failed to ensure database schema matches expectations"); | 516 | EseExitOnFailure(hr, "Failed to ensure database schema matches expectations"); |
502 | 517 | ||
503 | LExit: | 518 | LExit: |
504 | ReleaseStr(pszDir); | 519 | ReleaseStr(pszDir); |
@@ -535,7 +550,7 @@ HRESULT DAPI EseCreateTable( | |||
535 | LPSTR pszAnsiTable = NULL; | 550 | LPSTR pszAnsiTable = NULL; |
536 | 551 | ||
537 | hr = StrAnsiAllocString(&pszAnsiTable, pszTable, 0, CP_ACP); | 552 | hr = StrAnsiAllocString(&pszAnsiTable, pszTable, 0, CP_ACP); |
538 | ExitOnFailure(hr, "Failed converting table name to ansi"); | 553 | EseExitOnFailure(hr, "Failed converting table name to ansi"); |
539 | 554 | ||
540 | jEr = JetCreateTableA(jsSession, jdbDb, pszAnsiTable, 100, 0, pjtTable); | 555 | jEr = JetCreateTableA(jsSession, jdbDb, pszAnsiTable, 100, 0, pjtTable); |
541 | ExitOnJetFailure(jEr, hr, "Failed to create table %s", pszAnsiTable); | 556 | ExitOnJetFailure(jEr, hr, "Failed to create table %s", pszAnsiTable); |
@@ -558,7 +573,7 @@ HRESULT DAPI EseOpenTable( | |||
558 | LPSTR pszAnsiTable = NULL; | 573 | LPSTR pszAnsiTable = NULL; |
559 | 574 | ||
560 | hr = StrAnsiAllocString(&pszAnsiTable, pszTable, 0, CP_ACP); | 575 | hr = StrAnsiAllocString(&pszAnsiTable, pszTable, 0, CP_ACP); |
561 | ExitOnFailure(hr, "Failed converting table name to ansi"); | 576 | EseExitOnFailure(hr, "Failed converting table name to ansi"); |
562 | 577 | ||
563 | jEr = JetOpenTableA(jsSession, jdbDb, pszAnsiTable, NULL, 0, 0, pjtTable); | 578 | jEr = JetOpenTableA(jsSession, jdbDb, pszAnsiTable, NULL, 0, 0, pjtTable); |
564 | ExitOnJetFailure(jEr, hr, "Failed to open table %s", pszAnsiTable); | 579 | ExitOnJetFailure(jEr, hr, "Failed to open table %s", pszAnsiTable); |
@@ -602,7 +617,7 @@ HRESULT DAPI EseEnsureColumn( | |||
602 | JET_COLUMNBASE jcdTempBase = { sizeof(JET_COLUMNBASE) }; | 617 | JET_COLUMNBASE jcdTempBase = { sizeof(JET_COLUMNBASE) }; |
603 | 618 | ||
604 | hr = StrAnsiAllocString(&pszAnsiColumnName, pszColumnName, 0, CP_ACP); | 619 | hr = StrAnsiAllocString(&pszAnsiColumnName, pszColumnName, 0, CP_ACP); |
605 | ExitOnFailure(hr, "Failed converting column name to ansi"); | 620 | EseExitOnFailure(hr, "Failed converting column name to ansi"); |
606 | 621 | ||
607 | jEr = JetGetTableColumnInfoA(jsSession, jtTable, pszAnsiColumnName, &jcdTempBase, sizeof(JET_COLUMNBASE), JET_ColInfoBase); | 622 | jEr = JetGetTableColumnInfoA(jsSession, jtTable, pszAnsiColumnName, &jcdTempBase, sizeof(JET_COLUMNBASE), JET_ColInfoBase); |
608 | if (JET_errSuccess == jEr) | 623 | if (JET_errSuccess == jEr) |
@@ -661,7 +676,7 @@ HRESULT DAPI EseGetColumn( | |||
661 | JET_COLUMNBASE jcdTempBase = { sizeof(JET_COLUMNBASE) }; | 676 | JET_COLUMNBASE jcdTempBase = { sizeof(JET_COLUMNBASE) }; |
662 | 677 | ||
663 | hr = StrAnsiAllocString(&pszAnsiColumnName, pszColumnName, 0, CP_ACP); | 678 | hr = StrAnsiAllocString(&pszAnsiColumnName, pszColumnName, 0, CP_ACP); |
664 | ExitOnFailure(hr, "Failed converting column name to ansi"); | 679 | EseExitOnFailure(hr, "Failed converting column name to ansi"); |
665 | 680 | ||
666 | jEr = JetGetTableColumnInfoA(jsSession, jtTable, pszAnsiColumnName, &jcdTempBase, sizeof(JET_COLUMNBASE), JET_ColInfoBase); | 681 | jEr = JetGetTableColumnInfoA(jsSession, jtTable, pszAnsiColumnName, &jcdTempBase, sizeof(JET_COLUMNBASE), JET_ColInfoBase); |
667 | if (JET_errSuccess == jEr) | 682 | if (JET_errSuccess == jEr) |
@@ -898,7 +913,7 @@ HRESULT DAPI EseGetColumnBinary( | |||
898 | __in JET_SESID jsSession, | 913 | __in JET_SESID jsSession, |
899 | __in ESE_TABLE_SCHEMA tsTable, | 914 | __in ESE_TABLE_SCHEMA tsTable, |
900 | __in DWORD dwColumn, | 915 | __in DWORD dwColumn, |
901 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 916 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
902 | __inout SIZE_T* piBuffer | 917 | __inout SIZE_T* piBuffer |
903 | ) | 918 | ) |
904 | { | 919 | { |
@@ -916,12 +931,12 @@ HRESULT DAPI EseGetColumnBinary( | |||
916 | if (NULL == *ppbBuffer) | 931 | if (NULL == *ppbBuffer) |
917 | { | 932 | { |
918 | *ppbBuffer = reinterpret_cast<BYTE *>(MemAlloc(ulActualSize, FALSE)); | 933 | *ppbBuffer = reinterpret_cast<BYTE *>(MemAlloc(ulActualSize, FALSE)); |
919 | ExitOnNull(*ppbBuffer, hr, E_OUTOFMEMORY, "Failed to allocate memory for reading binary value column"); | 934 | EseExitOnNull(*ppbBuffer, hr, E_OUTOFMEMORY, "Failed to allocate memory for reading binary value column"); |
920 | } | 935 | } |
921 | else | 936 | else |
922 | { | 937 | { |
923 | *ppbBuffer = reinterpret_cast<BYTE *>(MemReAlloc(*ppbBuffer, ulActualSize, FALSE)); | 938 | *ppbBuffer = reinterpret_cast<BYTE *>(MemReAlloc(*ppbBuffer, ulActualSize, FALSE)); |
924 | ExitOnNull(*ppbBuffer, hr, E_OUTOFMEMORY, "Failed to reallocate memory for reading binary value column"); | 939 | EseExitOnNull(*ppbBuffer, hr, E_OUTOFMEMORY, "Failed to reallocate memory for reading binary value column"); |
925 | } | 940 | } |
926 | 941 | ||
927 | jEr = JetRetrieveColumn(jsSession, tsTable.jtTable, tsTable.pcsColumns[dwColumn].jcColumn, *ppbBuffer, ulActualSize, NULL, 0, NULL); | 942 | jEr = JetRetrieveColumn(jsSession, tsTable.jtTable, tsTable.pcsColumns[dwColumn].jcColumn, *ppbBuffer, ulActualSize, NULL, 0, NULL); |
@@ -1001,7 +1016,7 @@ HRESULT DAPI EseGetColumnString( | |||
1001 | ExitOnJetFailure(jEr, hr, "Failed to check size of string value from record"); | 1016 | ExitOnJetFailure(jEr, hr, "Failed to check size of string value from record"); |
1002 | 1017 | ||
1003 | hr = StrAlloc(ppszValue, ulActualSize); | 1018 | hr = StrAlloc(ppszValue, ulActualSize); |
1004 | ExitOnFailure(hr, "Failed to allocate string while retrieving column value"); | 1019 | EseExitOnFailure(hr, "Failed to allocate string while retrieving column value"); |
1005 | 1020 | ||
1006 | jEr = JetRetrieveColumn(jsSession, tsTable.jtTable, tsTable.pcsColumns[dwColumn].jcColumn, *ppszValue, ulActualSize, NULL, 0, NULL); | 1021 | jEr = JetRetrieveColumn(jsSession, tsTable.jtTable, tsTable.pcsColumns[dwColumn].jcColumn, *ppszValue, ulActualSize, NULL, 0, NULL); |
1007 | ExitOnJetFailure(jEr, hr, "Failed to retrieve string value from record"); | 1022 | ExitOnJetFailure(jEr, hr, "Failed to retrieve string value from record"); |
@@ -1023,7 +1038,7 @@ HRESULT DAPI EseBeginQuery( | |||
1023 | HRESULT hr = S_OK; | 1038 | HRESULT hr = S_OK; |
1024 | 1039 | ||
1025 | *peqhHandle = static_cast<ESE_QUERY*>(MemAlloc(sizeof(ESE_QUERY), TRUE)); | 1040 | *peqhHandle = static_cast<ESE_QUERY*>(MemAlloc(sizeof(ESE_QUERY), TRUE)); |
1026 | ExitOnNull(*peqhHandle, hr, E_OUTOFMEMORY, "Failed to allocate new query"); | 1041 | EseExitOnNull(*peqhHandle, hr, E_OUTOFMEMORY, "Failed to allocate new query"); |
1027 | 1042 | ||
1028 | ESE_QUERY *peqHandle = static_cast<ESE_QUERY *>(*peqhHandle); | 1043 | ESE_QUERY *peqHandle = static_cast<ESE_QUERY *>(*peqhHandle); |
1029 | peqHandle->qtQueryType = qtQueryType; | 1044 | peqHandle->qtQueryType = qtQueryType; |
@@ -1050,7 +1065,7 @@ HRESULT DAPI SetQueryColumn( | |||
1050 | if (peqHandle->dwColumns == countof(peqHandle->pvData)) | 1065 | if (peqHandle->dwColumns == countof(peqHandle->pvData)) |
1051 | { | 1066 | { |
1052 | hr = E_NOTIMPL; | 1067 | hr = E_NOTIMPL; |
1053 | ExitOnFailure(hr, "Dutil hasn't implemented support for queries of more than %d columns", countof(peqHandle->pvData)); | 1068 | EseExitOnFailure(hr, "Dutil hasn't implemented support for queries of more than %d columns", countof(peqHandle->pvData)); |
1054 | } | 1069 | } |
1055 | 1070 | ||
1056 | if (0 == peqHandle->dwColumns) // If it's the first column, start a new key | 1071 | if (0 == peqHandle->dwColumns) // If it's the first column, start a new key |
@@ -1065,7 +1080,7 @@ HRESULT DAPI SetQueryColumn( | |||
1065 | if (ESE_QUERY_EXACT != peqHandle->qtQueryType) | 1080 | if (ESE_QUERY_EXACT != peqHandle->qtQueryType) |
1066 | { | 1081 | { |
1067 | peqHandle->pvData[peqHandle->dwColumns] = MemAlloc(cbData, FALSE); | 1082 | peqHandle->pvData[peqHandle->dwColumns] = MemAlloc(cbData, FALSE); |
1068 | ExitOnNull(peqHandle->pvData[peqHandle->dwColumns], hr, E_OUTOFMEMORY, "Failed to allocate memory"); | 1083 | EseExitOnNull(peqHandle->pvData[peqHandle->dwColumns], hr, E_OUTOFMEMORY, "Failed to allocate memory"); |
1069 | 1084 | ||
1070 | memcpy(peqHandle->pvData[peqHandle->dwColumns], pvData, cbData); | 1085 | memcpy(peqHandle->pvData[peqHandle->dwColumns], pvData, cbData); |
1071 | 1086 | ||
@@ -1108,7 +1123,7 @@ HRESULT DAPI EseSetQueryColumnBinary( | |||
1108 | } | 1123 | } |
1109 | 1124 | ||
1110 | hr = SetQueryColumn(eqhHandle, reinterpret_cast<const void *>(pbBuffer), static_cast<DWORD>(cbBuffer), jGrb); | 1125 | hr = SetQueryColumn(eqhHandle, reinterpret_cast<const void *>(pbBuffer), static_cast<DWORD>(cbBuffer), jGrb); |
1111 | ExitOnFailure(hr, "Failed to set value of query colum (as binary) to:"); | 1126 | EseExitOnFailure(hr, "Failed to set value of query colum (as binary) to:"); |
1112 | 1127 | ||
1113 | LExit: | 1128 | LExit: |
1114 | return hr; | 1129 | return hr; |
@@ -1137,7 +1152,7 @@ HRESULT DAPI EseSetQueryColumnDword( | |||
1137 | } | 1152 | } |
1138 | 1153 | ||
1139 | hr = SetQueryColumn(eqhHandle, (const void *)&dwData, sizeof(DWORD), jGrb); | 1154 | hr = SetQueryColumn(eqhHandle, (const void *)&dwData, sizeof(DWORD), jGrb); |
1140 | ExitOnFailure(hr, "Failed to set value of query colum (as dword) to: %u", dwData); | 1155 | EseExitOnFailure(hr, "Failed to set value of query colum (as dword) to: %u", dwData); |
1141 | 1156 | ||
1142 | LExit: | 1157 | LExit: |
1143 | return hr; | 1158 | return hr; |
@@ -1167,7 +1182,7 @@ HRESULT DAPI EseSetQueryColumnBool( | |||
1167 | } | 1182 | } |
1168 | 1183 | ||
1169 | hr = SetQueryColumn(eqhHandle, (const void *)&bByte, 1, jGrb); | 1184 | hr = SetQueryColumn(eqhHandle, (const void *)&bByte, 1, jGrb); |
1170 | ExitOnFailure(hr, "Failed to set value of query colum (as bool) to: %s", fValue ? "TRUE" : "FALSE"); | 1185 | EseExitOnFailure(hr, "Failed to set value of query colum (as bool) to: %s", fValue ? "TRUE" : "FALSE"); |
1171 | 1186 | ||
1172 | LExit: | 1187 | LExit: |
1173 | return hr; | 1188 | return hr; |
@@ -1200,7 +1215,7 @@ HRESULT DAPI EseSetQueryColumnString( | |||
1200 | } | 1215 | } |
1201 | 1216 | ||
1202 | hr = SetQueryColumn(eqhHandle, (const void *)pszString, dwStringSize, jGrb); | 1217 | hr = SetQueryColumn(eqhHandle, (const void *)pszString, dwStringSize, jGrb); |
1203 | ExitOnFailure(hr, "Failed to set value of query colum (as string) to: %ls", pszString); | 1218 | EseExitOnFailure(hr, "Failed to set value of query colum (as string) to: %ls", pszString); |
1204 | 1219 | ||
1205 | LExit: | 1220 | LExit: |
1206 | return hr; | 1221 | return hr; |
diff --git a/src/dutil/fileutil.cpp b/src/dutil/fileutil.cpp index 6191ec06..c76017de 100644 --- a/src/dutil/fileutil.cpp +++ b/src/dutil/fileutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define FileExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_FILEUTIL, x, s, __VA_ARGS__) | ||
8 | #define FileExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_FILEUTIL, x, s, __VA_ARGS__) | ||
9 | #define FileExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_FILEUTIL, x, s, __VA_ARGS__) | ||
10 | #define FileExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_FILEUTIL, x, s, __VA_ARGS__) | ||
11 | #define FileExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_FILEUTIL, x, s, __VA_ARGS__) | ||
12 | #define FileExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_FILEUTIL, x, s, __VA_ARGS__) | ||
13 | #define FileExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_FILEUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define FileExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_FILEUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define FileExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_FILEUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define FileExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_FILEUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define FileExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_FILEUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define FileExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_FILEUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | // constants | 20 | // constants |
6 | 21 | ||
7 | const BYTE UTF8BOM[] = {0xEF, 0xBB, 0xBF}; | 22 | const BYTE UTF8BOM[] = {0xEF, 0xBB, 0xBF}; |
@@ -15,7 +30,7 @@ const LPCWSTR REGISTRY_PENDING_FILE_RENAME_VALUE = L"PendingFileRenameOperations | |||
15 | 30 | ||
16 | ********************************************************************/ | 31 | ********************************************************************/ |
17 | extern "C" LPWSTR DAPI FileFromPath( | 32 | extern "C" LPWSTR DAPI FileFromPath( |
18 | __in LPCWSTR wzPath | 33 | __in_z LPCWSTR wzPath |
19 | ) | 34 | ) |
20 | { | 35 | { |
21 | if (!wzPath) | 36 | if (!wzPath) |
@@ -42,7 +57,7 @@ extern "C" LPWSTR DAPI FileFromPath( | |||
42 | 57 | ||
43 | ********************************************************************/ | 58 | ********************************************************************/ |
44 | extern "C" HRESULT DAPI FileResolvePath( | 59 | extern "C" HRESULT DAPI FileResolvePath( |
45 | __in LPCWSTR wzRelativePath, | 60 | __in_z LPCWSTR wzRelativePath, |
46 | __out LPWSTR *ppwzFullPath | 61 | __out LPWSTR *ppwzFullPath |
47 | ) | 62 | ) |
48 | { | 63 | { |
@@ -63,28 +78,28 @@ extern "C" HRESULT DAPI FileResolvePath( | |||
63 | // | 78 | // |
64 | cchExpandedPath = MAX_PATH; | 79 | cchExpandedPath = MAX_PATH; |
65 | hr = StrAlloc(&pwzExpandedPath, cchExpandedPath); | 80 | hr = StrAlloc(&pwzExpandedPath, cchExpandedPath); |
66 | ExitOnFailure(hr, "Failed to allocate space for expanded path."); | 81 | FileExitOnFailure(hr, "Failed to allocate space for expanded path."); |
67 | 82 | ||
68 | cch = ::ExpandEnvironmentStringsW(wzRelativePath, pwzExpandedPath, cchExpandedPath); | 83 | cch = ::ExpandEnvironmentStringsW(wzRelativePath, pwzExpandedPath, cchExpandedPath); |
69 | if (0 == cch) | 84 | if (0 == cch) |
70 | { | 85 | { |
71 | ExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); | 86 | FileExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); |
72 | } | 87 | } |
73 | else if (cchExpandedPath < cch) | 88 | else if (cchExpandedPath < cch) |
74 | { | 89 | { |
75 | cchExpandedPath = cch; | 90 | cchExpandedPath = cch; |
76 | hr = StrAlloc(&pwzExpandedPath, cchExpandedPath); | 91 | hr = StrAlloc(&pwzExpandedPath, cchExpandedPath); |
77 | ExitOnFailure(hr, "Failed to re-allocate more space for expanded path."); | 92 | FileExitOnFailure(hr, "Failed to re-allocate more space for expanded path."); |
78 | 93 | ||
79 | cch = ::ExpandEnvironmentStringsW(wzRelativePath, pwzExpandedPath, cchExpandedPath); | 94 | cch = ::ExpandEnvironmentStringsW(wzRelativePath, pwzExpandedPath, cchExpandedPath); |
80 | if (0 == cch) | 95 | if (0 == cch) |
81 | { | 96 | { |
82 | ExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); | 97 | FileExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); |
83 | } | 98 | } |
84 | else if (cchExpandedPath < cch) | 99 | else if (cchExpandedPath < cch) |
85 | { | 100 | { |
86 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | 101 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); |
87 | ExitOnRootFailure(hr, "Failed to allocate buffer for expanded path."); | 102 | FileExitOnRootFailure(hr, "Failed to allocate buffer for expanded path."); |
88 | } | 103 | } |
89 | } | 104 | } |
90 | 105 | ||
@@ -93,28 +108,28 @@ extern "C" HRESULT DAPI FileResolvePath( | |||
93 | // | 108 | // |
94 | cchFullPath = MAX_PATH; | 109 | cchFullPath = MAX_PATH; |
95 | hr = StrAlloc(&pwzFullPath, cchFullPath); | 110 | hr = StrAlloc(&pwzFullPath, cchFullPath); |
96 | ExitOnFailure(hr, "Failed to allocate space for full path."); | 111 | FileExitOnFailure(hr, "Failed to allocate space for full path."); |
97 | 112 | ||
98 | cch = ::GetFullPathNameW(pwzExpandedPath, cchFullPath, pwzFullPath, &wzFileName); | 113 | cch = ::GetFullPathNameW(pwzExpandedPath, cchFullPath, pwzFullPath, &wzFileName); |
99 | if (0 == cch) | 114 | if (0 == cch) |
100 | { | 115 | { |
101 | ExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath); | 116 | FileExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath); |
102 | } | 117 | } |
103 | else if (cchFullPath < cch) | 118 | else if (cchFullPath < cch) |
104 | { | 119 | { |
105 | cchFullPath = cch; | 120 | cchFullPath = cch; |
106 | hr = StrAlloc(&pwzFullPath, cchFullPath); | 121 | hr = StrAlloc(&pwzFullPath, cchFullPath); |
107 | ExitOnFailure(hr, "Failed to re-allocate more space for full path."); | 122 | FileExitOnFailure(hr, "Failed to re-allocate more space for full path."); |
108 | 123 | ||
109 | cch = ::GetFullPathNameW(pwzExpandedPath, cchFullPath, pwzFullPath, &wzFileName); | 124 | cch = ::GetFullPathNameW(pwzExpandedPath, cchFullPath, pwzFullPath, &wzFileName); |
110 | if (0 == cch) | 125 | if (0 == cch) |
111 | { | 126 | { |
112 | ExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath); | 127 | FileExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath); |
113 | } | 128 | } |
114 | else if (cchFullPath < cch) | 129 | else if (cchFullPath < cch) |
115 | { | 130 | { |
116 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | 131 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); |
117 | ExitOnRootFailure(hr, "Failed to allocate buffer for full path."); | 132 | FileExitOnRootFailure(hr, "Failed to allocate buffer for full path."); |
118 | } | 133 | } |
119 | } | 134 | } |
120 | 135 | ||
@@ -133,7 +148,7 @@ LExit: | |||
133 | FileStripExtension - Strip extension from filename | 148 | FileStripExtension - Strip extension from filename |
134 | ********************************************************************/ | 149 | ********************************************************************/ |
135 | extern "C" HRESULT DAPI FileStripExtension( | 150 | extern "C" HRESULT DAPI FileStripExtension( |
136 | __in LPCWSTR wzFileName, | 151 | __in_z LPCWSTR wzFileName, |
137 | __out LPWSTR *ppwzFileNameNoExtension | 152 | __out LPWSTR *ppwzFileNameNoExtension |
138 | ) | 153 | ) |
139 | { | 154 | { |
@@ -158,14 +173,14 @@ __out LPWSTR *ppwzFileNameNoExtension | |||
158 | } | 173 | } |
159 | 174 | ||
160 | hr = StrAlloc(&pwzFileNameNoExtension, cchFileNameNoExtension); | 175 | hr = StrAlloc(&pwzFileNameNoExtension, cchFileNameNoExtension); |
161 | ExitOnFailure(hr, "failed to allocate space for File Name without extension"); | 176 | FileExitOnFailure(hr, "failed to allocate space for File Name without extension"); |
162 | 177 | ||
163 | // _wsplitpath_s can handle drive/path/filename/extension | 178 | // _wsplitpath_s can handle drive/path/filename/extension |
164 | errno_t err = _wsplitpath_s(wzFileName, NULL, NULL, NULL, NULL, pwzFileNameNoExtension, cchFileNameNoExtension, NULL, NULL); | 179 | errno_t err = _wsplitpath_s(wzFileName, NULL, NULL, NULL, NULL, pwzFileNameNoExtension, cchFileNameNoExtension, NULL, NULL); |
165 | if (0 != err) | 180 | if (0 != err) |
166 | { | 181 | { |
167 | hr = E_INVALIDARG; | 182 | hr = E_INVALIDARG; |
168 | ExitOnFailure(hr, "failed to parse filename: %ls", wzFileName); | 183 | FileExitOnFailure(hr, "failed to parse filename: %ls", wzFileName); |
169 | } | 184 | } |
170 | 185 | ||
171 | *ppwzFileNameNoExtension = pwzFileNameNoExtension; | 186 | *ppwzFileNameNoExtension = pwzFileNameNoExtension; |
@@ -182,8 +197,8 @@ LExit: | |||
182 | FileChangeExtension - Changes the extension of a filename | 197 | FileChangeExtension - Changes the extension of a filename |
183 | ********************************************************************/ | 198 | ********************************************************************/ |
184 | extern "C" HRESULT DAPI FileChangeExtension( | 199 | extern "C" HRESULT DAPI FileChangeExtension( |
185 | __in LPCWSTR wzFileName, | 200 | __in_z LPCWSTR wzFileName, |
186 | __in LPCWSTR wzNewExtension, | 201 | __in_z LPCWSTR wzNewExtension, |
187 | __out LPWSTR *ppwzFileNameNewExtension | 202 | __out LPWSTR *ppwzFileNameNewExtension |
188 | ) | 203 | ) |
189 | { | 204 | { |
@@ -193,10 +208,10 @@ extern "C" HRESULT DAPI FileChangeExtension( | |||
193 | LPWSTR sczFileName = NULL; | 208 | LPWSTR sczFileName = NULL; |
194 | 209 | ||
195 | hr = FileStripExtension(wzFileName, &sczFileName); | 210 | hr = FileStripExtension(wzFileName, &sczFileName); |
196 | ExitOnFailure(hr, "Failed to strip extension from file name: %ls", wzFileName); | 211 | FileExitOnFailure(hr, "Failed to strip extension from file name: %ls", wzFileName); |
197 | 212 | ||
198 | hr = StrAllocConcat(&sczFileName, wzNewExtension, 0); | 213 | hr = StrAllocConcat(&sczFileName, wzNewExtension, 0); |
199 | ExitOnFailure(hr, "Failed to add new extension."); | 214 | FileExitOnFailure(hr, "Failed to add new extension."); |
200 | 215 | ||
201 | *ppwzFileNameNewExtension = sczFileName; | 216 | *ppwzFileNameNewExtension = sczFileName; |
202 | sczFileName = NULL; | 217 | sczFileName = NULL; |
@@ -238,11 +253,11 @@ extern "C" HRESULT DAPI FileAddSuffixToBaseName( | |||
238 | { | 253 | { |
239 | // no extension, so add the suffix at the end of the whole name | 254 | // no extension, so add the suffix at the end of the whole name |
240 | hr = StrAllocString(&sczNewFileName, wzFileName, 0); | 255 | hr = StrAllocString(&sczNewFileName, wzFileName, 0); |
241 | ExitOnFailure(hr, "Failed to allocate new file name."); | 256 | FileExitOnFailure(hr, "Failed to allocate new file name."); |
242 | 257 | ||
243 | hr = StrAllocConcat(&sczNewFileName, wzSuffix, 0); | 258 | hr = StrAllocConcat(&sczNewFileName, wzSuffix, 0); |
244 | } | 259 | } |
245 | ExitOnFailure(hr, "Failed to allocate new file name with suffix."); | 260 | FileExitOnFailure(hr, "Failed to allocate new file name with suffix."); |
246 | 261 | ||
247 | *psczNewFileName = sczNewFileName; | 262 | *psczNewFileName = sczNewFileName; |
248 | sczNewFileName = NULL; | 263 | sczNewFileName = NULL; |
@@ -259,7 +274,7 @@ LExit: | |||
259 | 274 | ||
260 | ********************************************************************/ | 275 | ********************************************************************/ |
261 | extern "C" HRESULT DAPI FileVersion( | 276 | extern "C" HRESULT DAPI FileVersion( |
262 | __in LPCWSTR wzFilename, | 277 | __in_z LPCWSTR wzFilename, |
263 | __out DWORD *pdwVerMajor, | 278 | __out DWORD *pdwVerMajor, |
264 | __out DWORD* pdwVerMinor | 279 | __out DWORD* pdwVerMinor |
265 | ) | 280 | ) |
@@ -274,20 +289,20 @@ extern "C" HRESULT DAPI FileVersion( | |||
274 | 289 | ||
275 | if (0 == (cbVerBuffer = ::GetFileVersionInfoSizeW(wzFilename, &dwHandle))) | 290 | if (0 == (cbVerBuffer = ::GetFileVersionInfoSizeW(wzFilename, &dwHandle))) |
276 | { | 291 | { |
277 | ExitOnLastErrorDebugTrace(hr, "failed to get version info for file: %ls", wzFilename); | 292 | FileExitOnLastErrorDebugTrace(hr, "failed to get version info for file: %ls", wzFilename); |
278 | } | 293 | } |
279 | 294 | ||
280 | pVerBuffer = ::GlobalAlloc(GMEM_FIXED, cbVerBuffer); | 295 | pVerBuffer = ::GlobalAlloc(GMEM_FIXED, cbVerBuffer); |
281 | ExitOnNullDebugTrace(pVerBuffer, hr, E_OUTOFMEMORY, "failed to allocate version info for file: %ls", wzFilename); | 296 | FileExitOnNullDebugTrace(pVerBuffer, hr, E_OUTOFMEMORY, "failed to allocate version info for file: %ls", wzFilename); |
282 | 297 | ||
283 | if (!::GetFileVersionInfoW(wzFilename, dwHandle, cbVerBuffer, pVerBuffer)) | 298 | if (!::GetFileVersionInfoW(wzFilename, dwHandle, cbVerBuffer, pVerBuffer)) |
284 | { | 299 | { |
285 | ExitOnLastErrorDebugTrace(hr, "failed to get version info for file: %ls", wzFilename); | 300 | FileExitOnLastErrorDebugTrace(hr, "failed to get version info for file: %ls", wzFilename); |
286 | } | 301 | } |
287 | 302 | ||
288 | if (!::VerQueryValueW(pVerBuffer, L"\\", (void**)&pvsFileInfo, &cbFileInfo)) | 303 | if (!::VerQueryValueW(pVerBuffer, L"\\", (void**)&pvsFileInfo, &cbFileInfo)) |
289 | { | 304 | { |
290 | ExitOnLastErrorDebugTrace(hr, "failed to get version value for file: %ls", wzFilename); | 305 | FileExitOnLastErrorDebugTrace(hr, "failed to get version value for file: %ls", wzFilename); |
291 | } | 306 | } |
292 | 307 | ||
293 | *pdwVerMajor = pvsFileInfo->dwFileVersionMS; | 308 | *pdwVerMajor = pvsFileInfo->dwFileVersionMS; |
@@ -307,7 +322,7 @@ LExit: | |||
307 | 322 | ||
308 | *******************************************************************/ | 323 | *******************************************************************/ |
309 | extern "C" HRESULT DAPI FileVersionFromString( | 324 | extern "C" HRESULT DAPI FileVersionFromString( |
310 | __in LPCWSTR wzVersion, | 325 | __in_z LPCWSTR wzVersion, |
311 | __out DWORD* pdwVerMajor, | 326 | __out DWORD* pdwVerMajor, |
312 | __out DWORD* pdwVerMinor | 327 | __out DWORD* pdwVerMinor |
313 | ) | 328 | ) |
@@ -394,7 +409,7 @@ LExit: | |||
394 | 409 | ||
395 | *******************************************************************/ | 410 | *******************************************************************/ |
396 | extern "C" HRESULT DAPI FileVersionFromStringEx( | 411 | extern "C" HRESULT DAPI FileVersionFromStringEx( |
397 | __in LPCWSTR wzVersion, | 412 | __in_z LPCWSTR wzVersion, |
398 | __in DWORD cchVersion, | 413 | __in DWORD cchVersion, |
399 | __out DWORD64* pqwVersion | 414 | __out DWORD64* pqwVersion |
400 | ) | 415 | ) |
@@ -453,11 +468,11 @@ extern "C" HRESULT DAPI FileVersionFromStringEx( | |||
453 | 468 | ||
454 | DWORD cchPart; | 469 | DWORD cchPart; |
455 | hr = ::PtrdiffTToDWord(wzPartEnd - wzPartBegin, &cchPart); | 470 | hr = ::PtrdiffTToDWord(wzPartEnd - wzPartBegin, &cchPart); |
456 | ExitOnFailure(hr, "Version number part was too long."); | 471 | FileExitOnFailure(hr, "Version number part was too long."); |
457 | 472 | ||
458 | // parse version part | 473 | // parse version part |
459 | hr = StrStringToUInt16(wzPartBegin, cchPart, &us); | 474 | hr = StrStringToUInt16(wzPartBegin, cchPart, &us); |
460 | ExitOnFailure(hr, "Failed to parse version number part."); | 475 | FileExitOnFailure(hr, "Failed to parse version number part."); |
461 | 476 | ||
462 | // add part to qword version | 477 | // add part to qword version |
463 | qwVersion |= (DWORD64)us << ((3 - iPart) * 16); | 478 | qwVersion |= (DWORD64)us << ((3 - iPart) * 16); |
@@ -501,7 +516,7 @@ extern "C" HRESULT DAPI FileVersionToStringEx( | |||
501 | 516 | ||
502 | // Format and return the version string. | 517 | // Format and return the version string. |
503 | hr = StrAllocFormatted(psczVersion, L"%u.%u.%u.%u", wMajor, wMinor, wBuild, wRevision); | 518 | hr = StrAllocFormatted(psczVersion, L"%u.%u.%u.%u", wMajor, wMinor, wBuild, wRevision); |
504 | ExitOnFailure(hr, "Failed to allocate and format the version number."); | 519 | FileExitOnFailure(hr, "Failed to allocate and format the version number."); |
505 | 520 | ||
506 | LExit: | 521 | LExit: |
507 | return hr; | 522 | return hr; |
@@ -527,7 +542,7 @@ extern "C" HRESULT DAPI FileSetPointer( | |||
527 | liMove.QuadPart = dw64Move; | 542 | liMove.QuadPart = dw64Move; |
528 | if (!::SetFilePointerEx(hFile, liMove, &liNewPosition, dwMoveMethod)) | 543 | if (!::SetFilePointerEx(hFile, liMove, &liNewPosition, dwMoveMethod)) |
529 | { | 544 | { |
530 | ExitWithLastError(hr, "Failed to set file pointer."); | 545 | FileExitWithLastError(hr, "Failed to set file pointer."); |
531 | } | 546 | } |
532 | 547 | ||
533 | if (pdw64NewPosition) | 548 | if (pdw64NewPosition) |
@@ -545,23 +560,23 @@ LExit: | |||
545 | 560 | ||
546 | ********************************************************************/ | 561 | ********************************************************************/ |
547 | extern "C" HRESULT DAPI FileSize( | 562 | extern "C" HRESULT DAPI FileSize( |
548 | __in LPCWSTR pwzFileName, | 563 | __in_z LPCWSTR pwzFileName, |
549 | __out LONGLONG* pllSize | 564 | __out LONGLONG* pllSize |
550 | ) | 565 | ) |
551 | { | 566 | { |
552 | HRESULT hr = S_OK; | 567 | HRESULT hr = S_OK; |
553 | HANDLE hFile = INVALID_HANDLE_VALUE; | 568 | HANDLE hFile = INVALID_HANDLE_VALUE; |
554 | 569 | ||
555 | ExitOnNull(pwzFileName, hr, E_INVALIDARG, "Attempted to check filename, but no filename was provided"); | 570 | FileExitOnNull(pwzFileName, hr, E_INVALIDARG, "Attempted to check filename, but no filename was provided"); |
556 | 571 | ||
557 | hFile = ::CreateFileW(pwzFileName, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); | 572 | hFile = ::CreateFileW(pwzFileName, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
558 | if (INVALID_HANDLE_VALUE == hFile) | 573 | if (INVALID_HANDLE_VALUE == hFile) |
559 | { | 574 | { |
560 | ExitWithLastError(hr, "Failed to open file %ls while checking file size", pwzFileName); | 575 | FileExitWithLastError(hr, "Failed to open file %ls while checking file size", pwzFileName); |
561 | } | 576 | } |
562 | 577 | ||
563 | hr = FileSizeByHandle(hFile, pllSize); | 578 | hr = FileSizeByHandle(hFile, pllSize); |
564 | ExitOnFailure(hr, "Failed to check size of file %ls by handle", pwzFileName); | 579 | FileExitOnFailure(hr, "Failed to check size of file %ls by handle", pwzFileName); |
565 | 580 | ||
566 | LExit: | 581 | LExit: |
567 | ReleaseFileHandle(hFile); | 582 | ReleaseFileHandle(hFile); |
@@ -587,7 +602,7 @@ extern "C" HRESULT DAPI FileSizeByHandle( | |||
587 | 602 | ||
588 | if (!::GetFileSizeEx(hFile, &li)) | 603 | if (!::GetFileSizeEx(hFile, &li)) |
589 | { | 604 | { |
590 | ExitWithLastError(hr, "Failed to get size of file."); | 605 | FileExitWithLastError(hr, "Failed to get size of file."); |
591 | } | 606 | } |
592 | 607 | ||
593 | *pllSize = li.QuadPart; | 608 | *pllSize = li.QuadPart; |
@@ -602,7 +617,7 @@ LExit: | |||
602 | 617 | ||
603 | ********************************************************************/ | 618 | ********************************************************************/ |
604 | extern "C" BOOL DAPI FileExistsEx( | 619 | extern "C" BOOL DAPI FileExistsEx( |
605 | __in LPCWSTR wzPath, | 620 | __in_z LPCWSTR wzPath, |
606 | __out_opt DWORD *pdwAttributes | 621 | __out_opt DWORD *pdwAttributes |
607 | ) | 622 | ) |
608 | { | 623 | { |
@@ -655,14 +670,14 @@ extern "C" BOOL DAPI FileExistsAfterRestart( | |||
655 | { | 670 | { |
656 | ExitFunction1(hr = S_OK); | 671 | ExitFunction1(hr = S_OK); |
657 | } | 672 | } |
658 | ExitOnFailure(hr, "Failed to open pending file rename registry key."); | 673 | FileExitOnFailure(hr, "Failed to open pending file rename registry key."); |
659 | 674 | ||
660 | hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames); | 675 | hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames); |
661 | if (E_FILENOTFOUND == hr) | 676 | if (E_FILENOTFOUND == hr) |
662 | { | 677 | { |
663 | ExitFunction1(hr = S_OK); | 678 | ExitFunction1(hr = S_OK); |
664 | } | 679 | } |
665 | ExitOnFailure(hr, "Failed to read pending file renames."); | 680 | FileExitOnFailure(hr, "Failed to read pending file renames."); |
666 | 681 | ||
667 | // The pending file renames array is pairs of source and target paths. We only care | 682 | // The pending file renames array is pairs of source and target paths. We only care |
668 | // about checking the source paths so skip the target paths (i += 2). | 683 | // about checking the source paths so skip the target paths (i += 2). |
@@ -678,7 +693,7 @@ extern "C" BOOL DAPI FileExistsAfterRestart( | |||
678 | } | 693 | } |
679 | 694 | ||
680 | hr = PathCompare(wzPath, wzRename, &nCompare); | 695 | hr = PathCompare(wzPath, wzRename, &nCompare); |
681 | ExitOnFailure(hr, "Failed to compare path from pending file rename to check path."); | 696 | FileExitOnFailure(hr, "Failed to compare path from pending file rename to check path."); |
682 | 697 | ||
683 | if (CSTR_EQUAL == nCompare) | 698 | if (CSTR_EQUAL == nCompare) |
684 | { | 699 | { |
@@ -719,14 +734,14 @@ extern "C" HRESULT DAPI FileRemoveFromPendingRename( | |||
719 | { | 734 | { |
720 | ExitFunction1(hr = S_OK); | 735 | ExitFunction1(hr = S_OK); |
721 | } | 736 | } |
722 | ExitOnFailure(hr, "Failed to open pending file rename registry key."); | 737 | FileExitOnFailure(hr, "Failed to open pending file rename registry key."); |
723 | 738 | ||
724 | hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames); | 739 | hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames); |
725 | if (E_FILENOTFOUND == hr) | 740 | if (E_FILENOTFOUND == hr) |
726 | { | 741 | { |
727 | ExitFunction1(hr = S_OK); | 742 | ExitFunction1(hr = S_OK); |
728 | } | 743 | } |
729 | ExitOnFailure(hr, "Failed to read pending file renames."); | 744 | FileExitOnFailure(hr, "Failed to read pending file renames."); |
730 | 745 | ||
731 | // The pending file renames array is pairs of source and target paths. We only care | 746 | // The pending file renames array is pairs of source and target paths. We only care |
732 | // about checking the source paths so skip the target paths (i += 2). | 747 | // about checking the source paths so skip the target paths (i += 2). |
@@ -742,7 +757,7 @@ extern "C" HRESULT DAPI FileRemoveFromPendingRename( | |||
742 | } | 757 | } |
743 | 758 | ||
744 | hr = PathCompare(wzPath, wzRename, &nCompare); | 759 | hr = PathCompare(wzPath, wzRename, &nCompare); |
745 | ExitOnFailure(hr, "Failed to compare path from pending file rename to check path."); | 760 | FileExitOnFailure(hr, "Failed to compare path from pending file rename to check path."); |
746 | 761 | ||
747 | // If we find our path in the list, null out the source and target slot and | 762 | // If we find our path in the list, null out the source and target slot and |
748 | // we'll compact the array next. | 763 | // we'll compact the array next. |
@@ -772,7 +787,7 @@ extern "C" HRESULT DAPI FileRemoveFromPendingRename( | |||
772 | 787 | ||
773 | // Write the new array back to the pending file rename key. | 788 | // Write the new array back to the pending file rename key. |
774 | hr = RegWriteStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, rgsczRenames, cRenames); | 789 | hr = RegWriteStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, rgsczRenames, cRenames); |
775 | ExitOnFailure(hr, "Failed to update pending file renames."); | 790 | FileExitOnFailure(hr, "Failed to update pending file renames."); |
776 | } | 791 | } |
777 | 792 | ||
778 | LExit: | 793 | LExit: |
@@ -790,7 +805,7 @@ LExit: | |||
790 | extern "C" HRESULT DAPI FileRead( | 805 | extern "C" HRESULT DAPI FileRead( |
791 | __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest, | 806 | __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest, |
792 | __out SIZE_T* pcbDest, | 807 | __out SIZE_T* pcbDest, |
793 | __in LPCWSTR wzSrcPath | 808 | __in_z LPCWSTR wzSrcPath |
794 | ) | 809 | ) |
795 | { | 810 | { |
796 | HRESULT hr = FileReadPartial(ppbDest, pcbDest, wzSrcPath, FALSE, 0, 0xFFFFFFFF, FALSE); | 811 | HRESULT hr = FileReadPartial(ppbDest, pcbDest, wzSrcPath, FALSE, 0, 0xFFFFFFFF, FALSE); |
@@ -819,7 +834,7 @@ extern "C" HRESULT DAPI FileReadEx( | |||
819 | extern "C" HRESULT DAPI FileReadUntil( | 834 | extern "C" HRESULT DAPI FileReadUntil( |
820 | __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest, | 835 | __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest, |
821 | __out_range(<=, cbMaxRead) SIZE_T* pcbDest, | 836 | __out_range(<=, cbMaxRead) SIZE_T* pcbDest, |
822 | __in LPCWSTR wzSrcPath, | 837 | __in_z LPCWSTR wzSrcPath, |
823 | __in DWORD cbMaxRead | 838 | __in DWORD cbMaxRead |
824 | ) | 839 | ) |
825 | { | 840 | { |
@@ -835,7 +850,7 @@ extern "C" HRESULT DAPI FileReadUntil( | |||
835 | extern "C" HRESULT DAPI FileReadPartial( | 850 | extern "C" HRESULT DAPI FileReadPartial( |
836 | __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest, | 851 | __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest, |
837 | __out_range(<=, cbMaxRead) SIZE_T* pcbDest, | 852 | __out_range(<=, cbMaxRead) SIZE_T* pcbDest, |
838 | __in LPCWSTR wzSrcPath, | 853 | __in_z LPCWSTR wzSrcPath, |
839 | __in BOOL fSeek, | 854 | __in BOOL fSeek, |
840 | __in DWORD cbStartPosition, | 855 | __in DWORD cbStartPosition, |
841 | __in DWORD cbMaxRead, | 856 | __in DWORD cbMaxRead, |
@@ -850,7 +865,7 @@ extern "C" HRESULT DAPI FileReadPartial( | |||
850 | (with specified share mode) | 865 | (with specified share mode) |
851 | ********************************************************************/ | 866 | ********************************************************************/ |
852 | extern "C" HRESULT DAPI FileReadPartialEx( | 867 | extern "C" HRESULT DAPI FileReadPartialEx( |
853 | __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest, | 868 | __deref_inout_bcount_full(*pcbDest) LPBYTE* ppbDest, |
854 | __out_range(<=, cbMaxRead) SIZE_T* pcbDest, | 869 | __out_range(<=, cbMaxRead) SIZE_T* pcbDest, |
855 | __in_z LPCWSTR wzSrcPath, | 870 | __in_z LPCWSTR wzSrcPath, |
856 | __in BOOL fSeek, | 871 | __in BOOL fSeek, |
@@ -868,10 +883,10 @@ extern "C" HRESULT DAPI FileReadPartialEx( | |||
868 | DWORD cbData = 0; | 883 | DWORD cbData = 0; |
869 | BYTE* pbData = NULL; | 884 | BYTE* pbData = NULL; |
870 | 885 | ||
871 | ExitOnNull(pcbDest, hr, E_INVALIDARG, "Invalid argument pcbDest"); | 886 | FileExitOnNull(pcbDest, hr, E_INVALIDARG, "Invalid argument pcbDest"); |
872 | ExitOnNull(ppbDest, hr, E_INVALIDARG, "Invalid argument ppbDest"); | 887 | FileExitOnNull(ppbDest, hr, E_INVALIDARG, "Invalid argument ppbDest"); |
873 | ExitOnNull(wzSrcPath, hr, E_INVALIDARG, "Invalid argument wzSrcPath"); | 888 | FileExitOnNull(wzSrcPath, hr, E_INVALIDARG, "Invalid argument wzSrcPath"); |
874 | ExitOnNull(*wzSrcPath, hr, E_INVALIDARG, "*wzSrcPath is null"); | 889 | FileExitOnNull(*wzSrcPath, hr, E_INVALIDARG, "*wzSrcPath is null"); |
875 | 890 | ||
876 | hFile = ::CreateFileW(wzSrcPath, GENERIC_READ, dwShareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); | 891 | hFile = ::CreateFileW(wzSrcPath, GENERIC_READ, dwShareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); |
877 | if (INVALID_HANDLE_VALUE == hFile) | 892 | if (INVALID_HANDLE_VALUE == hFile) |
@@ -881,12 +896,12 @@ extern "C" HRESULT DAPI FileReadPartialEx( | |||
881 | { | 896 | { |
882 | ExitFunction1(hr = E_FILENOTFOUND); | 897 | ExitFunction1(hr = E_FILENOTFOUND); |
883 | } | 898 | } |
884 | ExitOnWin32Error(er, hr, "Failed to open file: %ls", wzSrcPath); | 899 | FileExitOnWin32Error(er, hr, "Failed to open file: %ls", wzSrcPath); |
885 | } | 900 | } |
886 | 901 | ||
887 | if (!::GetFileSizeEx(hFile, &liFileSize)) | 902 | if (!::GetFileSizeEx(hFile, &liFileSize)) |
888 | { | 903 | { |
889 | ExitWithLastError(hr, "Failed to get size of file: %ls", wzSrcPath); | 904 | FileExitWithLastError(hr, "Failed to get size of file: %ls", wzSrcPath); |
890 | } | 905 | } |
891 | 906 | ||
892 | if (fSeek) | 907 | if (fSeek) |
@@ -894,13 +909,13 @@ extern "C" HRESULT DAPI FileReadPartialEx( | |||
894 | if (cbStartPosition > liFileSize.QuadPart) | 909 | if (cbStartPosition > liFileSize.QuadPart) |
895 | { | 910 | { |
896 | hr = E_INVALIDARG; | 911 | hr = E_INVALIDARG; |
897 | ExitOnFailure(hr, "Start position %d bigger than file '%ls' size %d", cbStartPosition, wzSrcPath, liFileSize.QuadPart); | 912 | FileExitOnFailure(hr, "Start position %d bigger than file '%ls' size %llu", cbStartPosition, wzSrcPath, liFileSize.QuadPart); |
898 | } | 913 | } |
899 | 914 | ||
900 | DWORD dwErr = ::SetFilePointer(hFile, cbStartPosition, NULL, FILE_CURRENT); | 915 | DWORD dwErr = ::SetFilePointer(hFile, cbStartPosition, NULL, FILE_CURRENT); |
901 | if (INVALID_SET_FILE_POINTER == dwErr) | 916 | if (INVALID_SET_FILE_POINTER == dwErr) |
902 | { | 917 | { |
903 | ExitOnLastError(hr, "Failed to seek position %d", cbStartPosition); | 918 | FileExitOnLastError(hr, "Failed to seek position %d", cbStartPosition); |
904 | } | 919 | } |
905 | } | 920 | } |
906 | else | 921 | else |
@@ -918,7 +933,7 @@ extern "C" HRESULT DAPI FileReadPartialEx( | |||
918 | if (cbMaxRead < liFileSize.QuadPart - cbStartPosition) | 933 | if (cbMaxRead < liFileSize.QuadPart - cbStartPosition) |
919 | { | 934 | { |
920 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | 935 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); |
921 | ExitOnRootFailure(hr, "Failed to load file: %ls, too large.", wzSrcPath); | 936 | FileExitOnRootFailure(hr, "Failed to load file: %ls, too large.", wzSrcPath); |
922 | } | 937 | } |
923 | } | 938 | } |
924 | 939 | ||
@@ -932,7 +947,7 @@ extern "C" HRESULT DAPI FileReadPartialEx( | |||
932 | } | 947 | } |
933 | 948 | ||
934 | LPVOID pv = MemReAlloc(*ppbDest, cbData, TRUE); | 949 | LPVOID pv = MemReAlloc(*ppbDest, cbData, TRUE); |
935 | ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to re-allocate memory to read in file: %ls", wzSrcPath); | 950 | FileExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to re-allocate memory to read in file: %ls", wzSrcPath); |
936 | 951 | ||
937 | pbData = static_cast<BYTE*>(pv); | 952 | pbData = static_cast<BYTE*>(pv); |
938 | } | 953 | } |
@@ -945,7 +960,7 @@ extern "C" HRESULT DAPI FileReadPartialEx( | |||
945 | } | 960 | } |
946 | 961 | ||
947 | pbData = static_cast<BYTE*>(MemAlloc(cbData, TRUE)); | 962 | pbData = static_cast<BYTE*>(MemAlloc(cbData, TRUE)); |
948 | ExitOnNull(pbData, hr, E_OUTOFMEMORY, "Failed to allocate memory to read in file: %ls", wzSrcPath); | 963 | FileExitOnNull(pbData, hr, E_OUTOFMEMORY, "Failed to allocate memory to read in file: %ls", wzSrcPath); |
949 | } | 964 | } |
950 | 965 | ||
951 | DWORD cbTotalRead = 0; | 966 | DWORD cbTotalRead = 0; |
@@ -954,11 +969,11 @@ extern "C" HRESULT DAPI FileReadPartialEx( | |||
954 | { | 969 | { |
955 | DWORD cbRemaining = 0; | 970 | DWORD cbRemaining = 0; |
956 | hr = ::ULongSub(cbData, cbTotalRead, &cbRemaining); | 971 | hr = ::ULongSub(cbData, cbTotalRead, &cbRemaining); |
957 | ExitOnFailure(hr, "Underflow calculating remaining buffer size."); | 972 | FileExitOnFailure(hr, "Underflow calculating remaining buffer size."); |
958 | 973 | ||
959 | if (!::ReadFile(hFile, pbData + cbTotalRead, cbRemaining, &cbRead, NULL)) | 974 | if (!::ReadFile(hFile, pbData + cbTotalRead, cbRemaining, &cbRead, NULL)) |
960 | { | 975 | { |
961 | ExitWithLastError(hr, "Failed to read from file: %ls", wzSrcPath); | 976 | FileExitWithLastError(hr, "Failed to read from file: %ls", wzSrcPath); |
962 | } | 977 | } |
963 | 978 | ||
964 | cbTotalRead += cbRead; | 979 | cbTotalRead += cbRead; |
@@ -967,7 +982,7 @@ extern "C" HRESULT DAPI FileReadPartialEx( | |||
967 | if (cbTotalRead != cbData) | 982 | if (cbTotalRead != cbData) |
968 | { | 983 | { |
969 | hr = E_UNEXPECTED; | 984 | hr = E_UNEXPECTED; |
970 | ExitOnFailure(hr, "Failed to completely read file: %ls", wzSrcPath); | 985 | FileExitOnFailure(hr, "Failed to completely read file: %ls", wzSrcPath); |
971 | } | 986 | } |
972 | 987 | ||
973 | *ppbDest = pbData; | 988 | *ppbDest = pbData; |
@@ -999,10 +1014,10 @@ extern "C" HRESULT DAPI FileWrite( | |||
999 | 1014 | ||
1000 | // Open the file | 1015 | // Open the file |
1001 | hFile = ::CreateFileW(pwzFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, dwFlagsAndAttributes, NULL); | 1016 | hFile = ::CreateFileW(pwzFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, dwFlagsAndAttributes, NULL); |
1002 | ExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file: %ls", pwzFileName); | 1017 | FileExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file: %ls", pwzFileName); |
1003 | 1018 | ||
1004 | hr = FileWriteHandle(hFile, pbData, cbData); | 1019 | hr = FileWriteHandle(hFile, pbData, cbData); |
1005 | ExitOnFailure(hr, "Failed to write to file: %ls", pwzFileName); | 1020 | FileExitOnFailure(hr, "Failed to write to file: %ls", pwzFileName); |
1006 | 1021 | ||
1007 | if (pHandle) | 1022 | if (pHandle) |
1008 | { | 1023 | { |
@@ -1036,7 +1051,7 @@ extern "C" HRESULT DAPI FileWriteHandle( | |||
1036 | { | 1051 | { |
1037 | if (!::WriteFile(hFile, pbData + cbTotal, (DWORD)(cbData - cbTotal), &cbDataWritten, NULL)) | 1052 | if (!::WriteFile(hFile, pbData + cbTotal, (DWORD)(cbData - cbTotal), &cbDataWritten, NULL)) |
1038 | { | 1053 | { |
1039 | ExitOnLastError(hr, "Failed to write data to file handle."); | 1054 | FileExitOnLastError(hr, "Failed to write data to file handle."); |
1040 | } | 1055 | } |
1041 | 1056 | ||
1042 | cbTotal += cbDataWritten; | 1057 | cbTotal += cbDataWritten; |
@@ -1068,13 +1083,13 @@ extern "C" HRESULT DAPI FileCopyUsingHandles( | |||
1068 | cbRead = static_cast<DWORD>((0 == cbCopy) ? countof(rgbData) : min(countof(rgbData), cbCopy - cbTotalCopied)); | 1083 | cbRead = static_cast<DWORD>((0 == cbCopy) ? countof(rgbData) : min(countof(rgbData), cbCopy - cbTotalCopied)); |
1069 | if (!::ReadFile(hSource, rgbData, cbRead, &cbRead, NULL)) | 1084 | if (!::ReadFile(hSource, rgbData, cbRead, &cbRead, NULL)) |
1070 | { | 1085 | { |
1071 | ExitWithLastError(hr, "Failed to read from source."); | 1086 | FileExitWithLastError(hr, "Failed to read from source."); |
1072 | } | 1087 | } |
1073 | 1088 | ||
1074 | if (cbRead) | 1089 | if (cbRead) |
1075 | { | 1090 | { |
1076 | hr = FileWriteHandle(hTarget, rgbData, cbRead); | 1091 | hr = FileWriteHandle(hTarget, rgbData, cbRead); |
1077 | ExitOnFailure(hr, "Failed to write to target."); | 1092 | FileExitOnFailure(hr, "Failed to write to target."); |
1078 | } | 1093 | } |
1079 | 1094 | ||
1080 | cbTotalCopied += cbRead; | 1095 | cbTotalCopied += cbRead; |
@@ -1095,8 +1110,8 @@ LExit: | |||
1095 | 1110 | ||
1096 | *******************************************************************/ | 1111 | *******************************************************************/ |
1097 | extern "C" HRESULT DAPI FileEnsureCopy( | 1112 | extern "C" HRESULT DAPI FileEnsureCopy( |
1098 | __in LPCWSTR wzSource, | 1113 | __in_z LPCWSTR wzSource, |
1099 | __in LPCWSTR wzTarget, | 1114 | __in_z LPCWSTR wzTarget, |
1100 | __in BOOL fOverwrite | 1115 | __in BOOL fOverwrite |
1101 | ) | 1116 | ) |
1102 | { | 1117 | { |
@@ -1132,12 +1147,12 @@ extern "C" HRESULT DAPI FileEnsureCopy( | |||
1132 | *pwzLastSlash = L'\0'; // null terminate | 1147 | *pwzLastSlash = L'\0'; // null terminate |
1133 | hr = DirEnsureExists(wzTarget, NULL); | 1148 | hr = DirEnsureExists(wzTarget, NULL); |
1134 | *pwzLastSlash = L'\\'; // now put the slash back | 1149 | *pwzLastSlash = L'\\'; // now put the slash back |
1135 | ExitOnFailureDebugTrace(hr, "failed to create directory while copying file: '%ls' to: '%ls'", wzSource, wzTarget); | 1150 | FileExitOnFailureDebugTrace(hr, "failed to create directory while copying file: '%ls' to: '%ls'", wzSource, wzTarget); |
1136 | 1151 | ||
1137 | // try to copy again | 1152 | // try to copy again |
1138 | if (!::CopyFileW(wzSource, wzTarget, fOverwrite)) | 1153 | if (!::CopyFileW(wzSource, wzTarget, fOverwrite)) |
1139 | { | 1154 | { |
1140 | ExitOnLastErrorDebugTrace(hr, "failed to copy file: '%ls' to: '%ls'", wzSource, wzTarget); | 1155 | FileExitOnLastErrorDebugTrace(hr, "failed to copy file: '%ls' to: '%ls'", wzSource, wzTarget); |
1141 | } | 1156 | } |
1142 | } | 1157 | } |
1143 | else // no path was specified so just return the error | 1158 | else // no path was specified so just return the error |
@@ -1186,7 +1201,7 @@ extern "C" HRESULT DAPI FileEnsureCopyWithRetry( | |||
1186 | break; // no reason to retry these errors. | 1201 | break; // no reason to retry these errors. |
1187 | } | 1202 | } |
1188 | } | 1203 | } |
1189 | ExitOnFailure(hr, "Failed to copy file: '%ls' to: '%ls' after %u retries.", wzSource, wzTarget, i); | 1204 | FileExitOnFailure(hr, "Failed to copy file: '%ls' to: '%ls' after %u retries.", wzSource, wzTarget, i); |
1190 | 1205 | ||
1191 | LExit: | 1206 | LExit: |
1192 | return hr; | 1207 | return hr; |
@@ -1198,8 +1213,8 @@ LExit: | |||
1198 | 1213 | ||
1199 | *******************************************************************/ | 1214 | *******************************************************************/ |
1200 | extern "C" HRESULT DAPI FileEnsureMove( | 1215 | extern "C" HRESULT DAPI FileEnsureMove( |
1201 | __in LPCWSTR wzSource, | 1216 | __in_z LPCWSTR wzSource, |
1202 | __in LPCWSTR wzTarget, | 1217 | __in_z LPCWSTR wzTarget, |
1203 | __in BOOL fOverwrite, | 1218 | __in BOOL fOverwrite, |
1204 | __in BOOL fAllowCopy | 1219 | __in BOOL fAllowCopy |
1205 | ) | 1220 | ) |
@@ -1260,12 +1275,12 @@ extern "C" HRESULT DAPI FileEnsureMove( | |||
1260 | *pwzLastSlash = L'\0'; // null terminate | 1275 | *pwzLastSlash = L'\0'; // null terminate |
1261 | hr = DirEnsureExists(wzTarget, NULL); | 1276 | hr = DirEnsureExists(wzTarget, NULL); |
1262 | *pwzLastSlash = L'\\'; // now put the slash back | 1277 | *pwzLastSlash = L'\\'; // now put the slash back |
1263 | ExitOnFailureDebugTrace(hr, "failed to create directory while moving file: '%ls' to: '%ls'", wzSource, wzTarget); | 1278 | FileExitOnFailureDebugTrace(hr, "failed to create directory while moving file: '%ls' to: '%ls'", wzSource, wzTarget); |
1264 | 1279 | ||
1265 | // try to move again | 1280 | // try to move again |
1266 | if (!::MoveFileExW(wzSource, wzTarget, dwFlags)) | 1281 | if (!::MoveFileExW(wzSource, wzTarget, dwFlags)) |
1267 | { | 1282 | { |
1268 | ExitOnLastErrorDebugTrace(hr, "failed to move file: '%ls' to: '%ls'", wzSource, wzTarget); | 1283 | FileExitOnLastErrorDebugTrace(hr, "failed to move file: '%ls' to: '%ls'", wzSource, wzTarget); |
1269 | } | 1284 | } |
1270 | } | 1285 | } |
1271 | else // no path was specified so just return the error | 1286 | else // no path was specified so just return the error |
@@ -1310,7 +1325,7 @@ extern "C" HRESULT DAPI FileEnsureMoveWithRetry( | |||
1310 | 1325 | ||
1311 | hr = FileEnsureMove(wzSource, wzTarget, fOverwrite, fAllowCopy); | 1326 | hr = FileEnsureMove(wzSource, wzTarget, fOverwrite, fAllowCopy); |
1312 | } | 1327 | } |
1313 | ExitOnFailure(hr, "Failed to move file: '%ls' to: '%ls' after %u retries.", wzSource, wzTarget, i); | 1328 | FileExitOnFailure(hr, "Failed to move file: '%ls' to: '%ls' after %u retries.", wzSource, wzTarget, i); |
1314 | 1329 | ||
1315 | LExit: | 1330 | LExit: |
1316 | return hr; | 1331 | return hr; |
@@ -1323,8 +1338,8 @@ LExit: | |||
1323 | NOTE: uses ANSI functions internally so it is Win9x safe | 1338 | NOTE: uses ANSI functions internally so it is Win9x safe |
1324 | ********************************************************************/ | 1339 | ********************************************************************/ |
1325 | extern "C" HRESULT DAPI FileCreateTemp( | 1340 | extern "C" HRESULT DAPI FileCreateTemp( |
1326 | __in LPCWSTR wzPrefix, | 1341 | __in_z LPCWSTR wzPrefix, |
1327 | __in LPCWSTR wzExtension, | 1342 | __in_z LPCWSTR wzExtension, |
1328 | __deref_opt_out_z LPWSTR* ppwzTempFile, | 1343 | __deref_opt_out_z LPWSTR* ppwzTempFile, |
1329 | __out_opt HANDLE* phTempFile | 1344 | __out_opt HANDLE* phTempFile |
1330 | ) | 1345 | ) |
@@ -1340,13 +1355,13 @@ extern "C" HRESULT DAPI FileCreateTemp( | |||
1340 | int i = 0; | 1355 | int i = 0; |
1341 | 1356 | ||
1342 | hr = StrAnsiAlloc(&pszTempPath, cchTempPath); | 1357 | hr = StrAnsiAlloc(&pszTempPath, cchTempPath); |
1343 | ExitOnFailure(hr, "failed to allocate memory for the temp path"); | 1358 | FileExitOnFailure(hr, "failed to allocate memory for the temp path"); |
1344 | ::GetTempPathA(cchTempPath, pszTempPath); | 1359 | ::GetTempPathA(cchTempPath, pszTempPath); |
1345 | 1360 | ||
1346 | for (i = 0; i < 1000 && INVALID_HANDLE_VALUE == hTempFile; ++i) | 1361 | for (i = 0; i < 1000 && INVALID_HANDLE_VALUE == hTempFile; ++i) |
1347 | { | 1362 | { |
1348 | hr = StrAnsiAllocFormatted(&pszTempFile, "%s%ls%05d.%ls", pszTempPath, wzPrefix, i, wzExtension); | 1363 | hr = StrAnsiAllocFormatted(&pszTempFile, "%s%ls%05d.%ls", pszTempPath, wzPrefix, i, wzExtension); |
1349 | ExitOnFailure(hr, "failed to allocate memory for log file"); | 1364 | FileExitOnFailure(hr, "failed to allocate memory for log file"); |
1350 | 1365 | ||
1351 | hTempFile = ::CreateFileA(pszTempFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); | 1366 | hTempFile = ::CreateFileA(pszTempFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); |
1352 | if (INVALID_HANDLE_VALUE == hTempFile) | 1367 | if (INVALID_HANDLE_VALUE == hTempFile) |
@@ -1358,7 +1373,7 @@ extern "C" HRESULT DAPI FileCreateTemp( | |||
1358 | hr = S_OK; | 1373 | hr = S_OK; |
1359 | continue; | 1374 | continue; |
1360 | } | 1375 | } |
1361 | ExitOnFailureDebugTrace(hr, "failed to create file: %ls", pszTempFile); | 1376 | FileExitOnFailureDebugTrace(hr, "failed to create file: %hs", pszTempFile); |
1362 | } | 1377 | } |
1363 | } | 1378 | } |
1364 | 1379 | ||
@@ -1387,8 +1402,8 @@ LExit: | |||
1387 | 1402 | ||
1388 | *******************************************************************/ | 1403 | *******************************************************************/ |
1389 | extern "C" HRESULT DAPI FileCreateTempW( | 1404 | extern "C" HRESULT DAPI FileCreateTempW( |
1390 | __in LPCWSTR wzPrefix, | 1405 | __in_z LPCWSTR wzPrefix, |
1391 | __in LPCWSTR wzExtension, | 1406 | __in_z LPCWSTR wzExtension, |
1392 | __deref_opt_out_z LPWSTR* ppwzTempFile, | 1407 | __deref_opt_out_z LPWSTR* ppwzTempFile, |
1393 | __out_opt HANDLE* phTempFile | 1408 | __out_opt HANDLE* phTempFile |
1394 | ) | 1409 | ) |
@@ -1405,13 +1420,13 @@ extern "C" HRESULT DAPI FileCreateTempW( | |||
1405 | 1420 | ||
1406 | if (!::GetTempPathW(cchTempPath, wzTempPath)) | 1421 | if (!::GetTempPathW(cchTempPath, wzTempPath)) |
1407 | { | 1422 | { |
1408 | ExitOnLastError(hr, "failed to get temp path"); | 1423 | FileExitOnLastError(hr, "failed to get temp path"); |
1409 | } | 1424 | } |
1410 | 1425 | ||
1411 | for (i = 0; i < 1000 && INVALID_HANDLE_VALUE == hTempFile; ++i) | 1426 | for (i = 0; i < 1000 && INVALID_HANDLE_VALUE == hTempFile; ++i) |
1412 | { | 1427 | { |
1413 | hr = StrAllocFormatted(&pwzTempFile, L"%s%s%05d.%s", wzTempPath, wzPrefix, i, wzExtension); | 1428 | hr = StrAllocFormatted(&pwzTempFile, L"%s%s%05d.%s", wzTempPath, wzPrefix, i, wzExtension); |
1414 | ExitOnFailure(hr, "failed to allocate memory for temp filename"); | 1429 | FileExitOnFailure(hr, "failed to allocate memory for temp filename"); |
1415 | 1430 | ||
1416 | hTempFile = ::CreateFileW(pwzTempFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); | 1431 | hTempFile = ::CreateFileW(pwzTempFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); |
1417 | if (INVALID_HANDLE_VALUE == hTempFile) | 1432 | if (INVALID_HANDLE_VALUE == hTempFile) |
@@ -1423,7 +1438,7 @@ extern "C" HRESULT DAPI FileCreateTempW( | |||
1423 | hr = S_OK; | 1438 | hr = S_OK; |
1424 | continue; | 1439 | continue; |
1425 | } | 1440 | } |
1426 | ExitOnFailureDebugTrace(hr, "failed to create file: %ls", pwzTempFile); | 1441 | FileExitOnFailureDebugTrace(hr, "failed to create file: %ls", pwzTempFile); |
1427 | } | 1442 | } |
1428 | } | 1443 | } |
1429 | 1444 | ||
@@ -1452,8 +1467,8 @@ LExit: | |||
1452 | 1467 | ||
1453 | ********************************************************************/ | 1468 | ********************************************************************/ |
1454 | extern "C" HRESULT DAPI FileIsSame( | 1469 | extern "C" HRESULT DAPI FileIsSame( |
1455 | __in LPCWSTR wzFile1, | 1470 | __in_z LPCWSTR wzFile1, |
1456 | __in LPCWSTR wzFile2, | 1471 | __in_z LPCWSTR wzFile2, |
1457 | __out LPBOOL lpfSameFile | 1472 | __out LPBOOL lpfSameFile |
1458 | ) | 1473 | ) |
1459 | { | 1474 | { |
@@ -1464,19 +1479,19 @@ extern "C" HRESULT DAPI FileIsSame( | |||
1464 | BY_HANDLE_FILE_INFORMATION fileInfo2 = { }; | 1479 | BY_HANDLE_FILE_INFORMATION fileInfo2 = { }; |
1465 | 1480 | ||
1466 | hFile1 = ::CreateFileW(wzFile1, FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); | 1481 | hFile1 = ::CreateFileW(wzFile1, FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); |
1467 | ExitOnInvalidHandleWithLastError(hFile1, hr, "Failed to open file 1. File = '%ls'", wzFile1); | 1482 | FileExitOnInvalidHandleWithLastError(hFile1, hr, "Failed to open file 1. File = '%ls'", wzFile1); |
1468 | 1483 | ||
1469 | hFile2 = ::CreateFileW(wzFile2, FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); | 1484 | hFile2 = ::CreateFileW(wzFile2, FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); |
1470 | ExitOnInvalidHandleWithLastError(hFile2, hr, "Failed to open file 2. File = '%ls'", wzFile2); | 1485 | FileExitOnInvalidHandleWithLastError(hFile2, hr, "Failed to open file 2. File = '%ls'", wzFile2); |
1471 | 1486 | ||
1472 | if (!::GetFileInformationByHandle(hFile1, &fileInfo1)) | 1487 | if (!::GetFileInformationByHandle(hFile1, &fileInfo1)) |
1473 | { | 1488 | { |
1474 | ExitWithLastError(hr, "Failed to get information for file 1. File = '%ls'", wzFile1); | 1489 | FileExitWithLastError(hr, "Failed to get information for file 1. File = '%ls'", wzFile1); |
1475 | } | 1490 | } |
1476 | 1491 | ||
1477 | if (!::GetFileInformationByHandle(hFile2, &fileInfo2)) | 1492 | if (!::GetFileInformationByHandle(hFile2, &fileInfo2)) |
1478 | { | 1493 | { |
1479 | ExitWithLastError(hr, "Failed to get information for file 2. File = '%ls'", wzFile2); | 1494 | FileExitWithLastError(hr, "Failed to get information for file 2. File = '%ls'", wzFile2); |
1480 | } | 1495 | } |
1481 | 1496 | ||
1482 | *lpfSameFile = fileInfo1.dwVolumeSerialNumber == fileInfo2.dwVolumeSerialNumber && | 1497 | *lpfSameFile = fileInfo1.dwVolumeSerialNumber == fileInfo2.dwVolumeSerialNumber && |
@@ -1495,7 +1510,7 @@ LExit: | |||
1495 | hidden, or system attributes if necessary. | 1510 | hidden, or system attributes if necessary. |
1496 | ********************************************************************/ | 1511 | ********************************************************************/ |
1497 | extern "C" HRESULT DAPI FileEnsureDelete( | 1512 | extern "C" HRESULT DAPI FileEnsureDelete( |
1498 | __in LPCWSTR wzFile | 1513 | __in_z LPCWSTR wzFile |
1499 | ) | 1514 | ) |
1500 | { | 1515 | { |
1501 | HRESULT hr = S_OK; | 1516 | HRESULT hr = S_OK; |
@@ -1507,13 +1522,13 @@ extern "C" HRESULT DAPI FileEnsureDelete( | |||
1507 | { | 1522 | { |
1508 | if (!::SetFileAttributesW(wzFile, FILE_ATTRIBUTE_NORMAL)) | 1523 | if (!::SetFileAttributesW(wzFile, FILE_ATTRIBUTE_NORMAL)) |
1509 | { | 1524 | { |
1510 | ExitOnLastError(hr, "Failed to remove attributes from file: %ls", wzFile); | 1525 | FileExitOnLastError(hr, "Failed to remove attributes from file: %ls", wzFile); |
1511 | } | 1526 | } |
1512 | } | 1527 | } |
1513 | 1528 | ||
1514 | if (!::DeleteFileW(wzFile)) | 1529 | if (!::DeleteFileW(wzFile)) |
1515 | { | 1530 | { |
1516 | ExitOnLastError(hr, "Failed to delete file: %ls", wzFile); | 1531 | FileExitOnLastError(hr, "Failed to delete file: %ls", wzFile); |
1517 | } | 1532 | } |
1518 | } | 1533 | } |
1519 | 1534 | ||
@@ -1525,7 +1540,7 @@ LExit: | |||
1525 | FileGetTime - Gets the file time of a specified file | 1540 | FileGetTime - Gets the file time of a specified file |
1526 | ********************************************************************/ | 1541 | ********************************************************************/ |
1527 | extern "C" HRESULT DAPI FileGetTime( | 1542 | extern "C" HRESULT DAPI FileGetTime( |
1528 | __in LPCWSTR wzFile, | 1543 | __in_z LPCWSTR wzFile, |
1529 | __out_opt LPFILETIME lpCreationTime, | 1544 | __out_opt LPFILETIME lpCreationTime, |
1530 | __out_opt LPFILETIME lpLastAccessTime, | 1545 | __out_opt LPFILETIME lpLastAccessTime, |
1531 | __out_opt LPFILETIME lpLastWriteTime | 1546 | __out_opt LPFILETIME lpLastWriteTime |
@@ -1535,11 +1550,11 @@ extern "C" HRESULT DAPI FileGetTime( | |||
1535 | HANDLE hFile = NULL; | 1550 | HANDLE hFile = NULL; |
1536 | 1551 | ||
1537 | hFile = ::CreateFileW(wzFile, FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL); | 1552 | hFile = ::CreateFileW(wzFile, FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL); |
1538 | ExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile); | 1553 | FileExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile); |
1539 | 1554 | ||
1540 | if (!::GetFileTime(hFile, lpCreationTime, lpLastAccessTime, lpLastWriteTime)) | 1555 | if (!::GetFileTime(hFile, lpCreationTime, lpLastAccessTime, lpLastWriteTime)) |
1541 | { | 1556 | { |
1542 | ExitWithLastError(hr, "Failed to get file time for file. File = '%ls'", wzFile); | 1557 | FileExitWithLastError(hr, "Failed to get file time for file. File = '%ls'", wzFile); |
1543 | } | 1558 | } |
1544 | 1559 | ||
1545 | LExit: | 1560 | LExit: |
@@ -1551,7 +1566,7 @@ LExit: | |||
1551 | FileSetTime - Sets the file time of a specified file | 1566 | FileSetTime - Sets the file time of a specified file |
1552 | ********************************************************************/ | 1567 | ********************************************************************/ |
1553 | extern "C" HRESULT DAPI FileSetTime( | 1568 | extern "C" HRESULT DAPI FileSetTime( |
1554 | __in LPCWSTR wzFile, | 1569 | __in_z LPCWSTR wzFile, |
1555 | __in_opt const FILETIME *lpCreationTime, | 1570 | __in_opt const FILETIME *lpCreationTime, |
1556 | __in_opt const FILETIME *lpLastAccessTime, | 1571 | __in_opt const FILETIME *lpLastAccessTime, |
1557 | __in_opt const FILETIME *lpLastWriteTime | 1572 | __in_opt const FILETIME *lpLastWriteTime |
@@ -1561,11 +1576,11 @@ extern "C" HRESULT DAPI FileSetTime( | |||
1561 | HANDLE hFile = NULL; | 1576 | HANDLE hFile = NULL; |
1562 | 1577 | ||
1563 | hFile = ::CreateFileW(wzFile, FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL); | 1578 | hFile = ::CreateFileW(wzFile, FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL); |
1564 | ExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile); | 1579 | FileExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile); |
1565 | 1580 | ||
1566 | if (!::SetFileTime(hFile, lpCreationTime, lpLastAccessTime, lpLastWriteTime)) | 1581 | if (!::SetFileTime(hFile, lpCreationTime, lpLastAccessTime, lpLastWriteTime)) |
1567 | { | 1582 | { |
1568 | ExitWithLastError(hr, "Failed to set file time for file. File = '%ls'", wzFile); | 1583 | FileExitWithLastError(hr, "Failed to set file time for file. File = '%ls'", wzFile); |
1569 | } | 1584 | } |
1570 | 1585 | ||
1571 | LExit: | 1586 | LExit: |
@@ -1578,7 +1593,7 @@ LExit: | |||
1578 | creation time of the file | 1593 | creation time of the file |
1579 | ********************************************************************/ | 1594 | ********************************************************************/ |
1580 | extern "C" HRESULT DAPI FileResetTime( | 1595 | extern "C" HRESULT DAPI FileResetTime( |
1581 | __in LPCWSTR wzFile | 1596 | __in_z LPCWSTR wzFile |
1582 | ) | 1597 | ) |
1583 | { | 1598 | { |
1584 | HRESULT hr = S_OK; | 1599 | HRESULT hr = S_OK; |
@@ -1586,16 +1601,16 @@ extern "C" HRESULT DAPI FileResetTime( | |||
1586 | FILETIME ftCreateTime; | 1601 | FILETIME ftCreateTime; |
1587 | 1602 | ||
1588 | hFile = ::CreateFileW(wzFile, FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); | 1603 | hFile = ::CreateFileW(wzFile, FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); |
1589 | ExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile); | 1604 | FileExitOnInvalidHandleWithLastError(hFile, hr, "Failed to open file. File = '%ls'", wzFile); |
1590 | 1605 | ||
1591 | if (!::GetFileTime(hFile, &ftCreateTime, NULL, NULL)) | 1606 | if (!::GetFileTime(hFile, &ftCreateTime, NULL, NULL)) |
1592 | { | 1607 | { |
1593 | ExitWithLastError(hr, "Failed to get file time for file. File = '%ls'", wzFile); | 1608 | FileExitWithLastError(hr, "Failed to get file time for file. File = '%ls'", wzFile); |
1594 | } | 1609 | } |
1595 | 1610 | ||
1596 | if (!::SetFileTime(hFile, NULL, NULL, &ftCreateTime)) | 1611 | if (!::SetFileTime(hFile, NULL, NULL, &ftCreateTime)) |
1597 | { | 1612 | { |
1598 | ExitWithLastError(hr, "Failed to reset file time for file. File = '%ls'", wzFile); | 1613 | FileExitWithLastError(hr, "Failed to reset file time for file. File = '%ls'", wzFile); |
1599 | } | 1614 | } |
1600 | 1615 | ||
1601 | LExit: | 1616 | LExit: |
@@ -1609,7 +1624,7 @@ LExit: | |||
1609 | 1624 | ||
1610 | *******************************************************************/ | 1625 | *******************************************************************/ |
1611 | extern "C" HRESULT DAPI FileExecutableArchitecture( | 1626 | extern "C" HRESULT DAPI FileExecutableArchitecture( |
1612 | __in LPCWSTR wzFile, | 1627 | __in_z LPCWSTR wzFile, |
1613 | __out FILE_ARCHITECTURE *pArchitecture | 1628 | __out FILE_ARCHITECTURE *pArchitecture |
1614 | ) | 1629 | ) |
1615 | { | 1630 | { |
@@ -1623,34 +1638,34 @@ extern "C" HRESULT DAPI FileExecutableArchitecture( | |||
1623 | hFile = ::CreateFileW(wzFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); | 1638 | hFile = ::CreateFileW(wzFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
1624 | if (hFile == INVALID_HANDLE_VALUE) | 1639 | if (hFile == INVALID_HANDLE_VALUE) |
1625 | { | 1640 | { |
1626 | ExitWithLastError(hr, "Failed to open file: %ls", wzFile); | 1641 | FileExitWithLastError(hr, "Failed to open file: %ls", wzFile); |
1627 | } | 1642 | } |
1628 | 1643 | ||
1629 | if (!::ReadFile(hFile, &DosImageHeader, sizeof(DosImageHeader), &cbRead, NULL)) | 1644 | if (!::ReadFile(hFile, &DosImageHeader, sizeof(DosImageHeader), &cbRead, NULL)) |
1630 | { | 1645 | { |
1631 | ExitWithLastError(hr, "Failed to read DOS header from file: %ls", wzFile); | 1646 | FileExitWithLastError(hr, "Failed to read DOS header from file: %ls", wzFile); |
1632 | } | 1647 | } |
1633 | 1648 | ||
1634 | if (DosImageHeader.e_magic != IMAGE_DOS_SIGNATURE) | 1649 | if (DosImageHeader.e_magic != IMAGE_DOS_SIGNATURE) |
1635 | { | 1650 | { |
1636 | hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT); | 1651 | hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT); |
1637 | ExitOnRootFailure(hr, "Read invalid DOS header from file: %ls", wzFile); | 1652 | FileExitOnRootFailure(hr, "Read invalid DOS header from file: %ls", wzFile); |
1638 | } | 1653 | } |
1639 | 1654 | ||
1640 | if (INVALID_SET_FILE_POINTER == ::SetFilePointer(hFile, DosImageHeader.e_lfanew, NULL, FILE_BEGIN)) | 1655 | if (INVALID_SET_FILE_POINTER == ::SetFilePointer(hFile, DosImageHeader.e_lfanew, NULL, FILE_BEGIN)) |
1641 | { | 1656 | { |
1642 | ExitWithLastError(hr, "Failed to seek the NT header in file: %ls", wzFile); | 1657 | FileExitWithLastError(hr, "Failed to seek the NT header in file: %ls", wzFile); |
1643 | } | 1658 | } |
1644 | 1659 | ||
1645 | if (!::ReadFile(hFile, &NtImageHeader, sizeof(NtImageHeader), &cbRead, NULL)) | 1660 | if (!::ReadFile(hFile, &NtImageHeader, sizeof(NtImageHeader), &cbRead, NULL)) |
1646 | { | 1661 | { |
1647 | ExitWithLastError(hr, "Failed to read NT header from file: %ls", wzFile); | 1662 | FileExitWithLastError(hr, "Failed to read NT header from file: %ls", wzFile); |
1648 | } | 1663 | } |
1649 | 1664 | ||
1650 | if (NtImageHeader.Signature != IMAGE_NT_SIGNATURE) | 1665 | if (NtImageHeader.Signature != IMAGE_NT_SIGNATURE) |
1651 | { | 1666 | { |
1652 | hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT); | 1667 | hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT); |
1653 | ExitOnRootFailure(hr, "Read invalid NT header from file: %ls", wzFile); | 1668 | FileExitOnRootFailure(hr, "Read invalid NT header from file: %ls", wzFile); |
1654 | } | 1669 | } |
1655 | 1670 | ||
1656 | if (IMAGE_SUBSYSTEM_NATIVE == NtImageHeader.OptionalHeader.Subsystem || | 1671 | if (IMAGE_SUBSYSTEM_NATIVE == NtImageHeader.OptionalHeader.Subsystem || |
@@ -1677,7 +1692,7 @@ extern "C" HRESULT DAPI FileExecutableArchitecture( | |||
1677 | { | 1692 | { |
1678 | hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT); | 1693 | hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT); |
1679 | } | 1694 | } |
1680 | ExitOnFailure(hr, "Unexpected subsystem: %d machine type: %d specified in NT header from file: %ls", NtImageHeader.OptionalHeader.Subsystem, NtImageHeader.FileHeader.Machine, wzFile); | 1695 | FileExitOnFailure(hr, "Unexpected subsystem: %d machine type: %d specified in NT header from file: %ls", NtImageHeader.OptionalHeader.Subsystem, NtImageHeader.FileHeader.Machine, wzFile); |
1681 | 1696 | ||
1682 | LExit: | 1697 | LExit: |
1683 | if (hFile != INVALID_HANDLE_VALUE) | 1698 | if (hFile != INVALID_HANDLE_VALUE) |
@@ -1706,7 +1721,7 @@ extern "C" HRESULT DAPI FileToString( | |||
1706 | 1721 | ||
1707 | // Check if the file is ANSI | 1722 | // Check if the file is ANSI |
1708 | hr = FileRead(&pbFullFileBuffer, &cbFullFileBuffer, wzFile); | 1723 | hr = FileRead(&pbFullFileBuffer, &cbFullFileBuffer, wzFile); |
1709 | ExitOnFailure(hr, "Failed to read file: %ls", wzFile); | 1724 | FileExitOnFailure(hr, "Failed to read file: %ls", wzFile); |
1710 | 1725 | ||
1711 | if (0 == cbFullFileBuffer) | 1726 | if (0 == cbFullFileBuffer) |
1712 | { | 1727 | { |
@@ -1723,7 +1738,7 @@ extern "C" HRESULT DAPI FileToString( | |||
1723 | } | 1738 | } |
1724 | 1739 | ||
1725 | hr = StrAllocStringAnsi(&sczFileText, reinterpret_cast<LPCSTR>(pbFullFileBuffer + 3), cbFullFileBuffer - 3, CP_UTF8); | 1740 | hr = StrAllocStringAnsi(&sczFileText, reinterpret_cast<LPCSTR>(pbFullFileBuffer + 3), cbFullFileBuffer - 3, CP_UTF8); |
1726 | ExitOnFailure(hr, "Failed to convert file %ls from UTF-8 as its BOM indicated", wzFile); | 1741 | FileExitOnFailure(hr, "Failed to convert file %ls from UTF-8 as its BOM indicated", wzFile); |
1727 | 1742 | ||
1728 | *psczString = sczFileText; | 1743 | *psczString = sczFileText; |
1729 | sczFileText = NULL; | 1744 | sczFileText = NULL; |
@@ -1737,7 +1752,7 @@ extern "C" HRESULT DAPI FileToString( | |||
1737 | } | 1752 | } |
1738 | 1753 | ||
1739 | hr = StrAllocString(psczString, reinterpret_cast<LPWSTR>(pbFullFileBuffer + 2), (cbFullFileBuffer - 2) / sizeof(WCHAR)); | 1754 | hr = StrAllocString(psczString, reinterpret_cast<LPWSTR>(pbFullFileBuffer + 2), (cbFullFileBuffer - 2) / sizeof(WCHAR)); |
1740 | ExitOnFailure(hr, "Failed to allocate copy of string"); | 1755 | FileExitOnFailure(hr, "Failed to allocate copy of string"); |
1741 | } | 1756 | } |
1742 | // No BOM, let's try to detect | 1757 | // No BOM, let's try to detect |
1743 | else | 1758 | else |
@@ -1763,7 +1778,7 @@ extern "C" HRESULT DAPI FileToString( | |||
1763 | { | 1778 | { |
1764 | if (E_OUTOFMEMORY == hr) | 1779 | if (E_OUTOFMEMORY == hr) |
1765 | { | 1780 | { |
1766 | ExitOnFailure(hr, "Failed to convert file %ls from UTF-8", wzFile); | 1781 | FileExitOnFailure(hr, "Failed to convert file %ls from UTF-8", wzFile); |
1767 | } | 1782 | } |
1768 | } | 1783 | } |
1769 | else | 1784 | else |
@@ -1780,7 +1795,7 @@ extern "C" HRESULT DAPI FileToString( | |||
1780 | } | 1795 | } |
1781 | 1796 | ||
1782 | hr = StrAllocString(psczString, reinterpret_cast<LPWSTR>(pbFullFileBuffer), cbFullFileBuffer / sizeof(WCHAR)); | 1797 | hr = StrAllocString(psczString, reinterpret_cast<LPWSTR>(pbFullFileBuffer), cbFullFileBuffer / sizeof(WCHAR)); |
1783 | ExitOnFailure(hr, "Failed to allocate copy of string"); | 1798 | FileExitOnFailure(hr, "Failed to allocate copy of string"); |
1784 | } | 1799 | } |
1785 | } | 1800 | } |
1786 | 1801 | ||
@@ -1813,20 +1828,20 @@ extern "C" HRESULT DAPI FileFromString( | |||
1813 | { | 1828 | { |
1814 | case FILE_ENCODING_UTF8: | 1829 | case FILE_ENCODING_UTF8: |
1815 | hr = StrAnsiAllocString(&sczUtf8String, sczString, 0, CP_UTF8); | 1830 | hr = StrAnsiAllocString(&sczUtf8String, sczString, 0, CP_UTF8); |
1816 | ExitOnFailure(hr, "Failed to convert string to UTF-8 to write UTF-8 file"); | 1831 | FileExitOnFailure(hr, "Failed to convert string to UTF-8 to write UTF-8 file"); |
1817 | 1832 | ||
1818 | cbFullFileBuffer = lstrlenA(sczUtf8String); | 1833 | cbFullFileBuffer = lstrlenA(sczUtf8String); |
1819 | pcbFullFileBuffer = reinterpret_cast<BYTE *>(sczUtf8String); | 1834 | pcbFullFileBuffer = reinterpret_cast<BYTE *>(sczUtf8String); |
1820 | break; | 1835 | break; |
1821 | case FILE_ENCODING_UTF8_WITH_BOM: | 1836 | case FILE_ENCODING_UTF8_WITH_BOM: |
1822 | hr = StrAnsiAllocString(&sczUtf8String, sczString, 0, CP_UTF8); | 1837 | hr = StrAnsiAllocString(&sczUtf8String, sczString, 0, CP_UTF8); |
1823 | ExitOnFailure(hr, "Failed to convert string to UTF-8 to write UTF-8 file"); | 1838 | FileExitOnFailure(hr, "Failed to convert string to UTF-8 to write UTF-8 file"); |
1824 | 1839 | ||
1825 | cbStrLen = lstrlenA(sczUtf8String); | 1840 | cbStrLen = lstrlenA(sczUtf8String); |
1826 | cbFullFileBuffer = sizeof(UTF8BOM) + cbStrLen; | 1841 | cbFullFileBuffer = sizeof(UTF8BOM) + cbStrLen; |
1827 | 1842 | ||
1828 | pbFullFileBuffer = reinterpret_cast<BYTE *>(MemAlloc(cbFullFileBuffer, TRUE)); | 1843 | pbFullFileBuffer = reinterpret_cast<BYTE *>(MemAlloc(cbFullFileBuffer, TRUE)); |
1829 | ExitOnNull(pbFullFileBuffer, hr, E_OUTOFMEMORY, "Failed to allocate memory for output file buffer"); | 1844 | FileExitOnNull(pbFullFileBuffer, hr, E_OUTOFMEMORY, "Failed to allocate memory for output file buffer"); |
1830 | 1845 | ||
1831 | memcpy_s(pbFullFileBuffer, sizeof(UTF8BOM), UTF8BOM, sizeof(UTF8BOM)); | 1846 | memcpy_s(pbFullFileBuffer, sizeof(UTF8BOM), UTF8BOM, sizeof(UTF8BOM)); |
1832 | memcpy_s(pbFullFileBuffer + sizeof(UTF8BOM), cbStrLen, sczUtf8String, cbStrLen); | 1847 | memcpy_s(pbFullFileBuffer + sizeof(UTF8BOM), cbStrLen, sczUtf8String, cbStrLen); |
@@ -1841,7 +1856,7 @@ extern "C" HRESULT DAPI FileFromString( | |||
1841 | cbFullFileBuffer = sizeof(UTF16BOM) + cbStrLen; | 1856 | cbFullFileBuffer = sizeof(UTF16BOM) + cbStrLen; |
1842 | 1857 | ||
1843 | pbFullFileBuffer = reinterpret_cast<BYTE *>(MemAlloc(cbFullFileBuffer, TRUE)); | 1858 | pbFullFileBuffer = reinterpret_cast<BYTE *>(MemAlloc(cbFullFileBuffer, TRUE)); |
1844 | ExitOnNull(pbFullFileBuffer, hr, E_OUTOFMEMORY, "Failed to allocate memory for output file buffer"); | 1859 | FileExitOnNull(pbFullFileBuffer, hr, E_OUTOFMEMORY, "Failed to allocate memory for output file buffer"); |
1845 | 1860 | ||
1846 | memcpy_s(pbFullFileBuffer, sizeof(UTF16BOM), UTF16BOM, sizeof(UTF16BOM)); | 1861 | memcpy_s(pbFullFileBuffer, sizeof(UTF16BOM), UTF16BOM, sizeof(UTF16BOM)); |
1847 | memcpy_s(pbFullFileBuffer + sizeof(UTF16BOM), cbStrLen, sczString, cbStrLen); | 1862 | memcpy_s(pbFullFileBuffer + sizeof(UTF16BOM), cbStrLen, sczString, cbStrLen); |
@@ -1850,7 +1865,7 @@ extern "C" HRESULT DAPI FileFromString( | |||
1850 | } | 1865 | } |
1851 | 1866 | ||
1852 | hr = FileWrite(wzFile, dwFlagsAndAttributes, pcbFullFileBuffer, cbFullFileBuffer, NULL); | 1867 | hr = FileWrite(wzFile, dwFlagsAndAttributes, pcbFullFileBuffer, cbFullFileBuffer, NULL); |
1853 | ExitOnFailure(hr, "Failed to write file from string to: %ls", wzFile); | 1868 | FileExitOnFailure(hr, "Failed to write file from string to: %ls", wzFile); |
1854 | 1869 | ||
1855 | LExit: | 1870 | LExit: |
1856 | ReleaseStr(sczUtf8String); | 1871 | ReleaseStr(sczUtf8String); |
diff --git a/src/dutil/gdiputil.cpp b/src/dutil/gdiputil.cpp index aef6178f..b5a0087c 100644 --- a/src/dutil/gdiputil.cpp +++ b/src/dutil/gdiputil.cpp | |||
@@ -4,6 +4,21 @@ | |||
4 | 4 | ||
5 | using namespace Gdiplus; | 5 | using namespace Gdiplus; |
6 | 6 | ||
7 | |||
8 | // Exit macros | ||
9 | #define GdipExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__) | ||
10 | #define GdipExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__) | ||
11 | #define GdipExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__) | ||
12 | #define GdipExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__) | ||
13 | #define GdipExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__) | ||
14 | #define GdipExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__) | ||
15 | #define GdipExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_GDIPUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define GdipExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_GDIPUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define GdipExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_GDIPUTIL, p, x, e, s, __VA_ARGS__) | ||
18 | #define GdipExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_GDIPUTIL, p, x, s, __VA_ARGS__) | ||
19 | #define GdipExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_GDIPUTIL, e, x, s, __VA_ARGS__) | ||
20 | #define GdipExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_GDIPUTIL, g, x, s, __VA_ARGS__) | ||
21 | |||
7 | /******************************************************************** | 22 | /******************************************************************** |
8 | GdipInitialize - initializes GDI+. | 23 | GdipInitialize - initializes GDI+. |
9 | 24 | ||
@@ -22,7 +37,7 @@ extern "C" HRESULT DAPI GdipInitialize( | |||
22 | Status status = Ok; | 37 | Status status = Ok; |
23 | 38 | ||
24 | status = GdiplusStartup(pToken, pInput, pOutput); | 39 | status = GdiplusStartup(pToken, pInput, pOutput); |
25 | ExitOnGdipFailure(status, hr, "Failed to initialize GDI+."); | 40 | GdipExitOnGdipFailure(status, hr, "Failed to initialize GDI+."); |
26 | 41 | ||
27 | LExit: | 42 | LExit: |
28 | return hr; | 43 | return hr; |
@@ -59,15 +74,15 @@ extern "C" HRESULT DAPI GdipBitmapFromResource( | |||
59 | Status gs = Ok; | 74 | Status gs = Ok; |
60 | 75 | ||
61 | hr = ResReadData(hinst, szId, &pvData, &cbData); | 76 | hr = ResReadData(hinst, szId, &pvData, &cbData); |
62 | ExitOnFailure(hr, "Failed to load GDI+ bitmap from resource."); | 77 | GdipExitOnFailure(hr, "Failed to load GDI+ bitmap from resource."); |
63 | 78 | ||
64 | // Have to copy the fixed resource data into moveable (heap) memory | 79 | // Have to copy the fixed resource data into moveable (heap) memory |
65 | // since that's what GDI+ expects. | 80 | // since that's what GDI+ expects. |
66 | hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, cbData); | 81 | hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, cbData); |
67 | ExitOnNullWithLastError(hGlobal, hr, "Failed to allocate global memory."); | 82 | GdipExitOnNullWithLastError(hGlobal, hr, "Failed to allocate global memory."); |
68 | 83 | ||
69 | pv = ::GlobalLock(hGlobal); | 84 | pv = ::GlobalLock(hGlobal); |
70 | ExitOnNullWithLastError(pv, hr, "Failed to lock global memory."); | 85 | GdipExitOnNullWithLastError(pv, hr, "Failed to lock global memory."); |
71 | 86 | ||
72 | memcpy(pv, pvData, cbData); | 87 | memcpy(pv, pvData, cbData); |
73 | 88 | ||
@@ -75,15 +90,15 @@ extern "C" HRESULT DAPI GdipBitmapFromResource( | |||
75 | pv = NULL; | 90 | pv = NULL; |
76 | 91 | ||
77 | hr = ::CreateStreamOnHGlobal(hGlobal, TRUE, &pStream); | 92 | hr = ::CreateStreamOnHGlobal(hGlobal, TRUE, &pStream); |
78 | ExitOnFailure(hr, "Failed to allocate stream from global memory."); | 93 | GdipExitOnFailure(hr, "Failed to allocate stream from global memory."); |
79 | 94 | ||
80 | hGlobal = NULL; // we gave the global memory to the stream object so it will close it | 95 | hGlobal = NULL; // we gave the global memory to the stream object so it will close it |
81 | 96 | ||
82 | pBitmap = Bitmap::FromStream(pStream); | 97 | pBitmap = Bitmap::FromStream(pStream); |
83 | ExitOnNull(pBitmap, hr, E_OUTOFMEMORY, "Failed to allocate bitmap from stream."); | 98 | GdipExitOnNull(pBitmap, hr, E_OUTOFMEMORY, "Failed to allocate bitmap from stream."); |
84 | 99 | ||
85 | gs = pBitmap->GetLastStatus(); | 100 | gs = pBitmap->GetLastStatus(); |
86 | ExitOnGdipFailure(gs, hr, "Failed to load bitmap from stream."); | 101 | GdipExitOnGdipFailure(gs, hr, "Failed to load bitmap from stream."); |
87 | 102 | ||
88 | *ppBitmap = pBitmap; | 103 | *ppBitmap = pBitmap; |
89 | pBitmap = NULL; | 104 | pBitmap = NULL; |
@@ -123,13 +138,13 @@ extern "C" HRESULT DAPI GdipBitmapFromFile( | |||
123 | Bitmap *pBitmap = NULL; | 138 | Bitmap *pBitmap = NULL; |
124 | Status gs = Ok; | 139 | Status gs = Ok; |
125 | 140 | ||
126 | ExitOnNull(ppBitmap, hr, E_INVALIDARG, "Invalid null wzFileName"); | 141 | GdipExitOnNull(ppBitmap, hr, E_INVALIDARG, "Invalid null wzFileName"); |
127 | 142 | ||
128 | pBitmap = Bitmap::FromFile(wzFileName); | 143 | pBitmap = Bitmap::FromFile(wzFileName); |
129 | ExitOnNull(pBitmap, hr, E_OUTOFMEMORY, "Failed to allocate bitmap from file."); | 144 | GdipExitOnNull(pBitmap, hr, E_OUTOFMEMORY, "Failed to allocate bitmap from file."); |
130 | 145 | ||
131 | gs = pBitmap->GetLastStatus(); | 146 | gs = pBitmap->GetLastStatus(); |
132 | ExitOnGdipFailure(gs, hr, "Failed to load bitmap from file: %ls", wzFileName); | 147 | GdipExitOnGdipFailure(gs, hr, "Failed to load bitmap from file: %ls", wzFileName); |
133 | 148 | ||
134 | *ppBitmap = pBitmap; | 149 | *ppBitmap = pBitmap; |
135 | pBitmap = NULL; | 150 | pBitmap = NULL; |
diff --git a/src/dutil/guidutil.cpp b/src/dutil/guidutil.cpp index c0353892..204c9af2 100644 --- a/src/dutil/guidutil.cpp +++ b/src/dutil/guidutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define GuidExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) | ||
8 | #define GuidExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) | ||
9 | #define GuidExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) | ||
10 | #define GuidExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) | ||
11 | #define GuidExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) | ||
12 | #define GuidExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) | ||
13 | #define GuidExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_GUIDUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define GuidExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define GuidExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_GUIDUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define GuidExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define GuidExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_GUIDUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define GuidExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_GUIDUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | extern "C" HRESULT DAPI GuidFixedCreate( | 20 | extern "C" HRESULT DAPI GuidFixedCreate( |
6 | _Out_z_cap_c_(GUID_STRING_LENGTH) WCHAR* wzGuid | 21 | _Out_z_cap_c_(GUID_STRING_LENGTH) WCHAR* wzGuid |
7 | ) | 22 | ) |
@@ -10,12 +25,12 @@ extern "C" HRESULT DAPI GuidFixedCreate( | |||
10 | UUID guid = { }; | 25 | UUID guid = { }; |
11 | 26 | ||
12 | hr = HRESULT_FROM_RPC(::UuidCreate(&guid)); | 27 | hr = HRESULT_FROM_RPC(::UuidCreate(&guid)); |
13 | ExitOnFailure(hr, "UuidCreate failed."); | 28 | GuidExitOnFailure(hr, "UuidCreate failed."); |
14 | 29 | ||
15 | if (!::StringFromGUID2(guid, wzGuid, GUID_STRING_LENGTH)) | 30 | if (!::StringFromGUID2(guid, wzGuid, GUID_STRING_LENGTH)) |
16 | { | 31 | { |
17 | hr = E_OUTOFMEMORY; | 32 | hr = E_OUTOFMEMORY; |
18 | ExitOnRootFailure(hr, "Failed to convert guid into string."); | 33 | GuidExitOnRootFailure(hr, "Failed to convert guid into string."); |
19 | } | 34 | } |
20 | 35 | ||
21 | LExit: | 36 | LExit: |
@@ -29,10 +44,10 @@ extern "C" HRESULT DAPI GuidCreate( | |||
29 | HRESULT hr = S_OK; | 44 | HRESULT hr = S_OK; |
30 | 45 | ||
31 | hr = StrAlloc(psczGuid, GUID_STRING_LENGTH); | 46 | hr = StrAlloc(psczGuid, GUID_STRING_LENGTH); |
32 | ExitOnFailure(hr, "Failed to allocate space for guid"); | 47 | GuidExitOnFailure(hr, "Failed to allocate space for guid"); |
33 | 48 | ||
34 | hr = GuidFixedCreate(*psczGuid); | 49 | hr = GuidFixedCreate(*psczGuid); |
35 | ExitOnFailure(hr, "Failed to create new guid."); | 50 | GuidExitOnFailure(hr, "Failed to create new guid."); |
36 | 51 | ||
37 | LExit: | 52 | LExit: |
38 | return hr; | 53 | return hr; |
diff --git a/src/dutil/iis7util.cpp b/src/dutil/iis7util.cpp index 04165a8d..d0a0b000 100644 --- a/src/dutil/iis7util.cpp +++ b/src/dutil/iis7util.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | #include "iis7util.h" | 4 | #include "iis7util.h" |
5 | 5 | ||
6 | |||
7 | // Exit macros | ||
8 | #define IisExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_IIS7UTIL, x, s, __VA_ARGS__) | ||
9 | #define IisExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_IIS7UTIL, x, s, __VA_ARGS__) | ||
10 | #define IisExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_IIS7UTIL, x, s, __VA_ARGS__) | ||
11 | #define IisExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_IIS7UTIL, x, s, __VA_ARGS__) | ||
12 | #define IisExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_IIS7UTIL, x, s, __VA_ARGS__) | ||
13 | #define IisExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_IIS7UTIL, x, s, __VA_ARGS__) | ||
14 | #define IisExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_IIS7UTIL, p, x, e, s, __VA_ARGS__) | ||
15 | #define IisExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_IIS7UTIL, p, x, s, __VA_ARGS__) | ||
16 | #define IisExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_IIS7UTIL, p, x, e, s, __VA_ARGS__) | ||
17 | #define IisExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_IIS7UTIL, p, x, s, __VA_ARGS__) | ||
18 | #define IisExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_IIS7UTIL, e, x, s, __VA_ARGS__) | ||
19 | #define IisExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_IIS7UTIL, g, x, s, __VA_ARGS__) | ||
20 | |||
6 | #define ISSTRINGVARIANT(vt) (VT_BSTR == vt || VT_LPWSTR == vt) | 21 | #define ISSTRINGVARIANT(vt) (VT_BSTR == vt || VT_LPWSTR == vt) |
7 | 22 | ||
8 | extern "C" HRESULT DAPI Iis7PutPropertyVariant( | 23 | extern "C" HRESULT DAPI Iis7PutPropertyVariant( |
@@ -16,13 +31,13 @@ extern "C" HRESULT DAPI Iis7PutPropertyVariant( | |||
16 | BSTR bstrPropName = NULL; | 31 | BSTR bstrPropName = NULL; |
17 | 32 | ||
18 | bstrPropName = ::SysAllocString(wzPropName); | 33 | bstrPropName = ::SysAllocString(wzPropName); |
19 | ExitOnNull(bstrPropName, hr, E_OUTOFMEMORY, "failed SysAllocString"); | 34 | IisExitOnNull(bstrPropName, hr, E_OUTOFMEMORY, "failed SysAllocString"); |
20 | 35 | ||
21 | hr = pElement->GetPropertyByName(bstrPropName, &pProperty); | 36 | hr = pElement->GetPropertyByName(bstrPropName, &pProperty); |
22 | ExitOnFailure(hr, "Failed to get property object for %ls", wzPropName); | 37 | IisExitOnFailure(hr, "Failed to get property object for %ls", wzPropName); |
23 | 38 | ||
24 | hr = pProperty->put_Value(vtPut); | 39 | hr = pProperty->put_Value(vtPut); |
25 | ExitOnFailure(hr, "Failed to set property value for %ls", wzPropName); | 40 | IisExitOnFailure(hr, "Failed to set property value for %ls", wzPropName); |
26 | 41 | ||
27 | LExit: | 42 | LExit: |
28 | ReleaseBSTR(bstrPropName); | 43 | ReleaseBSTR(bstrPropName); |
@@ -44,7 +59,7 @@ extern "C" HRESULT DAPI Iis7PutPropertyString( | |||
44 | ::VariantInit(&vtPut); | 59 | ::VariantInit(&vtPut); |
45 | vtPut.vt = VT_BSTR; | 60 | vtPut.vt = VT_BSTR; |
46 | vtPut.bstrVal = ::SysAllocString(wzString); | 61 | vtPut.bstrVal = ::SysAllocString(wzString); |
47 | ExitOnNull(vtPut.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString"); | 62 | IisExitOnNull(vtPut.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString"); |
48 | 63 | ||
49 | hr = Iis7PutPropertyVariant(pElement, wzPropName, vtPut); | 64 | hr = Iis7PutPropertyVariant(pElement, wzPropName, vtPut); |
50 | 65 | ||
@@ -92,13 +107,13 @@ extern "C" HRESULT DAPI Iis7GetPropertyVariant( | |||
92 | BSTR bstrPropName = NULL; | 107 | BSTR bstrPropName = NULL; |
93 | 108 | ||
94 | bstrPropName = ::SysAllocString(wzPropName); | 109 | bstrPropName = ::SysAllocString(wzPropName); |
95 | ExitOnNull(bstrPropName, hr, E_OUTOFMEMORY, "failed SysAllocString"); | 110 | IisExitOnNull(bstrPropName, hr, E_OUTOFMEMORY, "failed SysAllocString"); |
96 | 111 | ||
97 | hr = pElement->GetPropertyByName(bstrPropName, &pProperty); | 112 | hr = pElement->GetPropertyByName(bstrPropName, &pProperty); |
98 | ExitOnFailure(hr, "Failed to get property object for %ls", wzPropName); | 113 | IisExitOnFailure(hr, "Failed to get property object for %ls", wzPropName); |
99 | 114 | ||
100 | hr = pProperty->get_Value(vtGet); | 115 | hr = pProperty->get_Value(vtGet); |
101 | ExitOnFailure(hr, "Failed to get property value for %ls", wzPropName); | 116 | IisExitOnFailure(hr, "Failed to get property value for %ls", wzPropName); |
102 | 117 | ||
103 | LExit: | 118 | LExit: |
104 | ReleaseBSTR(bstrPropName); | 119 | ReleaseBSTR(bstrPropName); |
@@ -119,12 +134,12 @@ extern "C" HRESULT DAPI Iis7GetPropertyString( | |||
119 | 134 | ||
120 | ::VariantInit(&vtGet); | 135 | ::VariantInit(&vtGet); |
121 | hr = Iis7GetPropertyVariant(pElement, wzPropName, &vtGet); | 136 | hr = Iis7GetPropertyVariant(pElement, wzPropName, &vtGet); |
122 | ExitOnFailure(hr, "Failed to get iis7 property variant with name: %ls", wzPropName); | 137 | IisExitOnFailure(hr, "Failed to get iis7 property variant with name: %ls", wzPropName); |
123 | 138 | ||
124 | if (!ISSTRINGVARIANT(vtGet.vt)) | 139 | if (!ISSTRINGVARIANT(vtGet.vt)) |
125 | { | 140 | { |
126 | hr = E_UNEXPECTED; | 141 | hr = E_UNEXPECTED; |
127 | ExitOnFailure(hr, "Tried to get property as a string, but type was %d instead.", vtGet.vt); | 142 | IisExitOnFailure(hr, "Tried to get property as a string, but type was %d instead.", vtGet.vt); |
128 | } | 143 | } |
129 | 144 | ||
130 | hr = StrAllocString(psczGet, vtGet.bstrVal, 0); | 145 | hr = StrAllocString(psczGet, vtGet.bstrVal, 0); |
@@ -198,13 +213,13 @@ BOOL DAPI CompareVariantPath( | |||
198 | if (ISSTRINGVARIANT(pVariant1->vt)) | 213 | if (ISSTRINGVARIANT(pVariant1->vt)) |
199 | { | 214 | { |
200 | hr = PathExpand(&wzValue1, pVariant1->bstrVal, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH); | 215 | hr = PathExpand(&wzValue1, pVariant1->bstrVal, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH); |
201 | ExitOnFailure(hr, "Failed to expand path %ls", pVariant1->bstrVal); | 216 | IisExitOnFailure(hr, "Failed to expand path %ls", pVariant1->bstrVal); |
202 | } | 217 | } |
203 | 218 | ||
204 | if (ISSTRINGVARIANT(pVariant2->vt)) | 219 | if (ISSTRINGVARIANT(pVariant2->vt)) |
205 | { | 220 | { |
206 | hr = PathExpand(&wzValue2, pVariant2->bstrVal, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH); | 221 | hr = PathExpand(&wzValue2, pVariant2->bstrVal, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH); |
207 | ExitOnFailure(hr, "Failed to expand path %ls", pVariant2->bstrVal); | 222 | IisExitOnFailure(hr, "Failed to expand path %ls", pVariant2->bstrVal); |
208 | } | 223 | } |
209 | 224 | ||
210 | fEqual = CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, wzValue1, -1, wzValue2, -1); | 225 | fEqual = CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, wzValue1, -1, wzValue2, -1); |
@@ -242,14 +257,14 @@ extern "C" BOOL DAPI Iis7IsMatchingAppHostElement( | |||
242 | VARIANTCOMPARATORPROC pComparator = pComparison->pComparator ? pComparison->pComparator : CompareVariantDefault; | 257 | VARIANTCOMPARATORPROC pComparator = pComparison->pComparator ? pComparison->pComparator : CompareVariantDefault; |
243 | 258 | ||
244 | hr = pElement->get_Name(&bstrElementName); | 259 | hr = pElement->get_Name(&bstrElementName); |
245 | ExitOnFailure(hr, "Failed to get name of element"); | 260 | IisExitOnFailure(hr, "Failed to get name of element"); |
246 | if (CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pComparison->sczElementName, -1, bstrElementName, -1)) | 261 | if (CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pComparison->sczElementName, -1, bstrElementName, -1)) |
247 | { | 262 | { |
248 | ExitFunction(); | 263 | ExitFunction(); |
249 | } | 264 | } |
250 | 265 | ||
251 | hr = Iis7GetPropertyVariant(pElement, pComparison->sczAttributeName, &vPropValue); | 266 | hr = Iis7GetPropertyVariant(pElement, pComparison->sczAttributeName, &vPropValue); |
252 | ExitOnFailure(hr, "Failed to get value of %ls attribute of %ls element", pComparison->sczAttributeName, pComparison->sczElementName); | 267 | IisExitOnFailure(hr, "Failed to get value of %ls attribute of %ls element", pComparison->sczAttributeName, pComparison->sczElementName); |
253 | 268 | ||
254 | if (TRUE == pComparator(pComparison->pvAttributeValue, &vPropValue)) | 269 | if (TRUE == pComparator(pComparison->pvAttributeValue, &vPropValue)) |
255 | { | 270 | { |
@@ -274,7 +289,9 @@ BOOL DAPI IsMatchingAppHostMethod( | |||
274 | BSTR bstrName = NULL; | 289 | BSTR bstrName = NULL; |
275 | 290 | ||
276 | hr = pMethod->get_Name(&bstrName); | 291 | hr = pMethod->get_Name(&bstrName); |
277 | ExitOnFailure(hr, "Failed to get name of element"); | 292 | IisExitOnFailure(hr, "Failed to get name of element"); |
293 | |||
294 | Assert(bstrName); | ||
278 | 295 | ||
279 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, wzMethodName, -1, bstrName, -1)) | 296 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, wzMethodName, -1, bstrName, -1)) |
280 | { | 297 | { |
@@ -303,7 +320,7 @@ extern "C" HRESULT DAPI Iis7FindAppHostElementPath( | |||
303 | 320 | ||
304 | vtValue.vt = VT_BSTR; | 321 | vtValue.vt = VT_BSTR; |
305 | vtValue.bstrVal = ::SysAllocString(wzAttributeValue); | 322 | vtValue.bstrVal = ::SysAllocString(wzAttributeValue); |
306 | ExitOnNull(vtValue.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString"); | 323 | IisExitOnNull(vtValue.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString"); |
307 | 324 | ||
308 | comparison.sczElementName = wzElementName; | 325 | comparison.sczElementName = wzElementName; |
309 | comparison.sczAttributeName = wzAttributeName; | 326 | comparison.sczAttributeName = wzAttributeName; |
@@ -337,7 +354,7 @@ extern "C" HRESULT DAPI Iis7FindAppHostElementString( | |||
337 | 354 | ||
338 | vtValue.vt = VT_BSTR; | 355 | vtValue.vt = VT_BSTR; |
339 | vtValue.bstrVal = ::SysAllocString(wzAttributeValue); | 356 | vtValue.bstrVal = ::SysAllocString(wzAttributeValue); |
340 | ExitOnNull(vtValue.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString"); | 357 | IisExitOnNull(vtValue.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString"); |
341 | 358 | ||
342 | hr = Iis7FindAppHostElementVariant(pCollection, | 359 | hr = Iis7FindAppHostElementVariant(pCollection, |
343 | wzElementName, | 360 | wzElementName, |
@@ -427,14 +444,14 @@ extern "C" HRESULT DAPI Iis7EnumAppHostElements( | |||
427 | } | 444 | } |
428 | 445 | ||
429 | hr = pCollection->get_Count(&dwElements); | 446 | hr = pCollection->get_Count(&dwElements); |
430 | ExitOnFailure(hr, "Failed get application IAppHostElementCollection count"); | 447 | IisExitOnFailure(hr, "Failed get application IAppHostElementCollection count"); |
431 | 448 | ||
432 | vtIndex.vt = VT_UI4; | 449 | vtIndex.vt = VT_UI4; |
433 | for (DWORD i = 0; i < dwElements; ++i) | 450 | for (DWORD i = 0; i < dwElements; ++i) |
434 | { | 451 | { |
435 | vtIndex.ulVal = i; | 452 | vtIndex.ulVal = i; |
436 | hr = pCollection->get_Item(vtIndex , &pElement); | 453 | hr = pCollection->get_Item(vtIndex , &pElement); |
437 | ExitOnFailure(hr, "Failed get IAppHostElement element"); | 454 | IisExitOnFailure(hr, "Failed get IAppHostElement element"); |
438 | 455 | ||
439 | if (pCallback(pElement, pContext)) | 456 | if (pCallback(pElement, pContext)) |
440 | { | 457 | { |
@@ -484,14 +501,14 @@ extern "C" HRESULT DAPI Iis7FindAppHostMethod( | |||
484 | } | 501 | } |
485 | 502 | ||
486 | hr = pCollection->get_Count(&dwMethods); | 503 | hr = pCollection->get_Count(&dwMethods); |
487 | ExitOnFailure(hr, "Failed get application IAppHostMethodCollection count"); | 504 | IisExitOnFailure(hr, "Failed get application IAppHostMethodCollection count"); |
488 | 505 | ||
489 | vtIndex.vt = VT_UI4; | 506 | vtIndex.vt = VT_UI4; |
490 | for (DWORD i = 0; i < dwMethods; ++i) | 507 | for (DWORD i = 0; i < dwMethods; ++i) |
491 | { | 508 | { |
492 | vtIndex.ulVal = i; | 509 | vtIndex.ulVal = i; |
493 | hr = pCollection->get_Item(vtIndex , &pMethod); | 510 | hr = pCollection->get_Item(vtIndex , &pMethod); |
494 | ExitOnFailure(hr, "Failed get IAppHostMethod element"); | 511 | IisExitOnFailure(hr, "Failed get IAppHostMethod element"); |
495 | 512 | ||
496 | if (IsMatchingAppHostMethod(pMethod, wzMethodName)) | 513 | if (IsMatchingAppHostMethod(pMethod, wzMethodName)) |
497 | { | 514 | { |
diff --git a/src/dutil/inc/atomutil.h b/src/dutil/inc/atomutil.h index ff869c4a..9acfc1d5 100644 --- a/src/dutil/inc/atomutil.h +++ b/src/dutil/inc/atomutil.h | |||
@@ -138,7 +138,7 @@ HRESULT DAPI AtomParseFromDocument( | |||
138 | ); | 138 | ); |
139 | 139 | ||
140 | void DAPI AtomFreeFeed( | 140 | void DAPI AtomFreeFeed( |
141 | __in_xcount(pFeed->cItems) ATOM_FEED *pFEED | 141 | __in_xcount(pFeed->cItems) ATOM_FEED* pFeed |
142 | ); | 142 | ); |
143 | 143 | ||
144 | #ifdef __cplusplus | 144 | #ifdef __cplusplus |
diff --git a/src/dutil/inc/buffutil.h b/src/dutil/inc/buffutil.h index a718e9c0..7509f76a 100644 --- a/src/dutil/inc/buffutil.h +++ b/src/dutil/inc/buffutil.h | |||
@@ -50,37 +50,37 @@ HRESULT BuffReadStream( | |||
50 | __in_bcount(cbBuffer) const BYTE* pbBuffer, | 50 | __in_bcount(cbBuffer) const BYTE* pbBuffer, |
51 | __in SIZE_T cbBuffer, | 51 | __in SIZE_T cbBuffer, |
52 | __inout SIZE_T* piBuffer, | 52 | __inout SIZE_T* piBuffer, |
53 | __deref_out_bcount(*pcbStream) BYTE** ppbStream, | 53 | __deref_inout_bcount(*pcbStream) BYTE** ppbStream, |
54 | __out SIZE_T* pcbStream | 54 | __out SIZE_T* pcbStream |
55 | ); | 55 | ); |
56 | 56 | ||
57 | HRESULT BuffWriteNumber( | 57 | HRESULT BuffWriteNumber( |
58 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 58 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
59 | __inout SIZE_T* piBuffer, | 59 | __inout SIZE_T* piBuffer, |
60 | __in DWORD_PTR dw | 60 | __in DWORD_PTR dw |
61 | ); | 61 | ); |
62 | HRESULT BuffWriteNumber64( | 62 | HRESULT BuffWriteNumber64( |
63 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 63 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
64 | __inout SIZE_T* piBuffer, | 64 | __inout SIZE_T* piBuffer, |
65 | __in DWORD64 dw64 | 65 | __in DWORD64 dw64 |
66 | ); | 66 | ); |
67 | HRESULT BuffWritePointer( | 67 | HRESULT BuffWritePointer( |
68 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 68 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
69 | __inout SIZE_T* piBuffer, | 69 | __inout SIZE_T* piBuffer, |
70 | __in DWORD_PTR dw | 70 | __in DWORD_PTR dw |
71 | ); | 71 | ); |
72 | HRESULT BuffWriteString( | 72 | HRESULT BuffWriteString( |
73 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 73 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
74 | __inout SIZE_T* piBuffer, | 74 | __inout SIZE_T* piBuffer, |
75 | __in_z_opt LPCWSTR scz | 75 | __in_z_opt LPCWSTR scz |
76 | ); | 76 | ); |
77 | HRESULT BuffWriteStringAnsi( | 77 | HRESULT BuffWriteStringAnsi( |
78 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 78 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
79 | __inout SIZE_T* piBuffer, | 79 | __inout SIZE_T* piBuffer, |
80 | __in_z_opt LPCSTR scz | 80 | __in_z_opt LPCSTR scz |
81 | ); | 81 | ); |
82 | HRESULT BuffWriteStream( | 82 | HRESULT BuffWriteStream( |
83 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 83 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
84 | __inout SIZE_T* piBuffer, | 84 | __inout SIZE_T* piBuffer, |
85 | __in_bcount(cbStream) const BYTE* pbStream, | 85 | __in_bcount(cbStream) const BYTE* pbStream, |
86 | __in SIZE_T cbStream | 86 | __in SIZE_T cbStream |
diff --git a/src/dutil/inc/conutil.h b/src/dutil/inc/conutil.h index 5f611d01..38aaea84 100644 --- a/src/dutil/inc/conutil.h +++ b/src/dutil/inc/conutil.h | |||
@@ -55,12 +55,12 @@ HRESULT DAPI ConsoleReadW( | |||
55 | ); | 55 | ); |
56 | 56 | ||
57 | HRESULT DAPI ConsoleReadStringA( | 57 | HRESULT DAPI ConsoleReadStringA( |
58 | __deref_out_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPSTR* szCharBuffer, | 58 | __deref_inout_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPSTR* szCharBuffer, |
59 | CONST DWORD cchCharBuffer, | 59 | CONST DWORD cchCharBuffer, |
60 | __out DWORD* pcchNumCharReturn | 60 | __out DWORD* pcchNumCharReturn |
61 | ); | 61 | ); |
62 | HRESULT DAPI ConsoleReadStringW( | 62 | HRESULT DAPI ConsoleReadStringW( |
63 | __deref_out_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPWSTR* szCharBuffer, | 63 | __deref_inout_ecount_part(cchCharBuffer,*pcchNumCharReturn) LPWSTR* szCharBuffer, |
64 | CONST DWORD cchCharBuffer, | 64 | CONST DWORD cchCharBuffer, |
65 | __out DWORD* pcchNumCharReturn | 65 | __out DWORD* pcchNumCharReturn |
66 | ); | 66 | ); |
diff --git a/src/dutil/inc/deputil.h b/src/dutil/inc/deputil.h index 8f5f0ae8..bfe235f3 100644 --- a/src/dutil/inc/deputil.h +++ b/src/dutil/inc/deputil.h | |||
@@ -55,7 +55,7 @@ DAPI_(HRESULT) DepCheckDependency( | |||
55 | DAPI_(HRESULT) DepCheckDependents( | 55 | DAPI_(HRESULT) DepCheckDependents( |
56 | __in HKEY hkHive, | 56 | __in HKEY hkHive, |
57 | __in_z LPCWSTR wzProviderKey, | 57 | __in_z LPCWSTR wzProviderKey, |
58 | __in int iAttributes, | 58 | __reserved int iAttributes, |
59 | __in C_STRINGDICT_HANDLE sdIgnoredDependents, | 59 | __in C_STRINGDICT_HANDLE sdIgnoredDependents, |
60 | __deref_inout_ecount_opt(*pcDependents) DEPENDENCY** prgDependents, | 60 | __deref_inout_ecount_opt(*pcDependents) DEPENDENCY** prgDependents, |
61 | __inout LPUINT pcDependents | 61 | __inout LPUINT pcDependents |
diff --git a/src/dutil/inc/dutil.h b/src/dutil/inc/dutil.h index 15d45d21..fc9ec0f4 100644 --- a/src/dutil/inc/dutil.h +++ b/src/dutil/inc/dutil.h | |||
@@ -44,7 +44,7 @@ void DAPI DutilUninitialize(); | |||
44 | void DAPI Dutil_SetAssertModule(__in HMODULE hAssertModule); | 44 | void DAPI Dutil_SetAssertModule(__in HMODULE hAssertModule); |
45 | void DAPI Dutil_SetAssertDisplayFunction(__in DUTIL_ASSERTDISPLAYFUNCTION pfn); | 45 | void DAPI Dutil_SetAssertDisplayFunction(__in DUTIL_ASSERTDISPLAYFUNCTION pfn); |
46 | void DAPI Dutil_Assert(__in_z LPCSTR szFile, __in int iLine); | 46 | void DAPI Dutil_Assert(__in_z LPCSTR szFile, __in int iLine); |
47 | void DAPI Dutil_AssertSz(__in_z LPCSTR szFile, __in int iLine, __in_z LPCSTR szMessage); | 47 | void DAPI Dutil_AssertSz(__in_z LPCSTR szFile, __in int iLine, __in_z __format_string LPCSTR szMessage); |
48 | 48 | ||
49 | void DAPI Dutil_TraceSetLevel(__in REPORT_LEVEL ll, __in BOOL fTraceFilenames); | 49 | void DAPI Dutil_TraceSetLevel(__in REPORT_LEVEL ll, __in BOOL fTraceFilenames); |
50 | REPORT_LEVEL DAPI Dutil_TraceGetLevel(); | 50 | REPORT_LEVEL DAPI Dutil_TraceGetLevel(); |
diff --git a/src/dutil/inc/eseutil.h b/src/dutil/inc/eseutil.h index 1c408927..bea47b2b 100644 --- a/src/dutil/inc/eseutil.h +++ b/src/dutil/inc/eseutil.h | |||
@@ -160,7 +160,7 @@ HRESULT DAPI EseGetColumnBinary( | |||
160 | __in JET_SESID jsSession, | 160 | __in JET_SESID jsSession, |
161 | __in ESE_TABLE_SCHEMA tsTable, | 161 | __in ESE_TABLE_SCHEMA tsTable, |
162 | __in DWORD dwColumn, | 162 | __in DWORD dwColumn, |
163 | __deref_out_bcount(*piBuffer) BYTE** ppbBuffer, | 163 | __deref_inout_bcount(*piBuffer) BYTE** ppbBuffer, |
164 | __inout SIZE_T* piBuffer | 164 | __inout SIZE_T* piBuffer |
165 | ); | 165 | ); |
166 | HRESULT DAPI EseGetColumnDword( | 166 | HRESULT DAPI EseGetColumnDword( |
diff --git a/src/dutil/inc/fileutil.h b/src/dutil/inc/fileutil.h index d2b2f4fe..7caa62b8 100644 --- a/src/dutil/inc/fileutil.h +++ b/src/dutil/inc/fileutil.h | |||
@@ -121,7 +121,7 @@ HRESULT DAPI FileReadPartial( | |||
121 | __in BOOL fPartialOK | 121 | __in BOOL fPartialOK |
122 | ); | 122 | ); |
123 | HRESULT DAPI FileReadPartialEx( | 123 | HRESULT DAPI FileReadPartialEx( |
124 | __deref_out_bcount_full(*pcbDest) LPBYTE* ppbDest, | 124 | __deref_inout_bcount_full(*pcbDest) LPBYTE* ppbDest, |
125 | __out_range(<=, cbMaxRead) SIZE_T* pcbDest, | 125 | __out_range(<=, cbMaxRead) SIZE_T* pcbDest, |
126 | __in_z LPCWSTR wzSrcPath, | 126 | __in_z LPCWSTR wzSrcPath, |
127 | __in BOOL fSeek, | 127 | __in BOOL fSeek, |
diff --git a/src/dutil/inc/inetutil.h b/src/dutil/inc/inetutil.h index 4cbf510b..19ace88b 100644 --- a/src/dutil/inc/inetutil.h +++ b/src/dutil/inc/inetutil.h | |||
@@ -30,7 +30,7 @@ HRESULT DAPI InternetQueryInfoString( | |||
30 | HRESULT DAPI InternetQueryInfoNumber( | 30 | HRESULT DAPI InternetQueryInfoNumber( |
31 | __in HINTERNET h, | 31 | __in HINTERNET h, |
32 | __in DWORD dwInfo, | 32 | __in DWORD dwInfo, |
33 | __out LONG* plInfo | 33 | __inout LONG* plInfo |
34 | ); | 34 | ); |
35 | 35 | ||
36 | #ifdef __cplusplus | 36 | #ifdef __cplusplus |
diff --git a/src/dutil/inc/iniutil.h b/src/dutil/inc/iniutil.h index d5b50c17..c8503155 100644 --- a/src/dutil/inc/iniutil.h +++ b/src/dutil/inc/iniutil.h | |||
@@ -55,7 +55,7 @@ HRESULT DAPI IniParse( | |||
55 | // (their value will be NULL) | 55 | // (their value will be NULL) |
56 | HRESULT DAPI IniGetValueList( | 56 | HRESULT DAPI IniGetValueList( |
57 | __in_bcount(INI_HANDLE_BYTES) INI_HANDLE piHandle, | 57 | __in_bcount(INI_HANDLE_BYTES) INI_HANDLE piHandle, |
58 | __deref_out_ecount_opt(pcValues) INI_VALUE** prgivValues, | 58 | __deref_out_ecount_opt(*pcValues) INI_VALUE** prgivValues, |
59 | __out DWORD *pcValues | 59 | __out DWORD *pcValues |
60 | ); | 60 | ); |
61 | HRESULT DAPI IniGetValue( | 61 | HRESULT DAPI IniGetValue( |
diff --git a/src/dutil/inc/memutil.h b/src/dutil/inc/memutil.h index 93e53228..49f86e0a 100644 --- a/src/dutil/inc/memutil.h +++ b/src/dutil/inc/memutil.h | |||
@@ -39,13 +39,13 @@ HRESULT DAPI MemReAllocArray( | |||
39 | __in DWORD dwNewItemCount | 39 | __in DWORD dwNewItemCount |
40 | ); | 40 | ); |
41 | HRESULT DAPI MemEnsureArraySize( | 41 | HRESULT DAPI MemEnsureArraySize( |
42 | __deref_out_bcount(cArray * cbArrayType) LPVOID* ppvArray, | 42 | __deref_inout_bcount(cArray * cbArrayType) LPVOID* ppvArray, |
43 | __in DWORD cArray, | 43 | __in DWORD cArray, |
44 | __in SIZE_T cbArrayType, | 44 | __in SIZE_T cbArrayType, |
45 | __in DWORD dwGrowthCount | 45 | __in DWORD dwGrowthCount |
46 | ); | 46 | ); |
47 | HRESULT DAPI MemInsertIntoArray( | 47 | HRESULT DAPI MemInsertIntoArray( |
48 | __deref_out_bcount((cExistingArray + cInsertItems) * cbArrayType) LPVOID* ppvArray, | 48 | __deref_inout_bcount((cExistingArray + cInsertItems) * cbArrayType) LPVOID* ppvArray, |
49 | __in DWORD dwInsertIndex, | 49 | __in DWORD dwInsertIndex, |
50 | __in DWORD cInsertItems, | 50 | __in DWORD cInsertItems, |
51 | __in DWORD cExistingArray, | 51 | __in DWORD cExistingArray, |
@@ -61,7 +61,7 @@ void DAPI MemRemoveFromArray( | |||
61 | __in BOOL fPreserveOrder | 61 | __in BOOL fPreserveOrder |
62 | ); | 62 | ); |
63 | void DAPI MemArraySwapItems( | 63 | void DAPI MemArraySwapItems( |
64 | __inout_bcount((cExistingArray) * cbArrayType) LPVOID pvArray, | 64 | __inout_bcount(cbArrayType) LPVOID pvArray, |
65 | __in DWORD dwIndex1, | 65 | __in DWORD dwIndex1, |
66 | __in DWORD dwIndex2, | 66 | __in DWORD dwIndex2, |
67 | __in SIZE_T cbArrayType | 67 | __in SIZE_T cbArrayType |
diff --git a/src/dutil/inc/pathutil.h b/src/dutil/inc/pathutil.h index bee8ed1b..f4f4e59c 100644 --- a/src/dutil/inc/pathutil.h +++ b/src/dutil/inc/pathutil.h | |||
@@ -19,7 +19,7 @@ typedef enum PATH_EXPAND | |||
19 | (i.e. quote arguments with spaces in them). | 19 | (i.e. quote arguments with spaces in them). |
20 | ********************************************************************/ | 20 | ********************************************************************/ |
21 | DAPI_(HRESULT) PathCommandLineAppend( | 21 | DAPI_(HRESULT) PathCommandLineAppend( |
22 | __deref_out_z LPWSTR* psczCommandLine, | 22 | __deref_inout_z LPWSTR* psczCommandLine, |
23 | __in_z LPCWSTR wzArgument | 23 | __in_z LPCWSTR wzArgument |
24 | ); | 24 | ); |
25 | 25 | ||
@@ -43,7 +43,7 @@ DAPI_(LPCWSTR) PathExtension( | |||
43 | ********************************************************************/ | 43 | ********************************************************************/ |
44 | DAPI_(HRESULT) PathGetDirectory( | 44 | DAPI_(HRESULT) PathGetDirectory( |
45 | __in_z LPCWSTR wzPath, | 45 | __in_z LPCWSTR wzPath, |
46 | __out LPWSTR *psczDirectory | 46 | __out_z LPWSTR *psczDirectory |
47 | ); | 47 | ); |
48 | 48 | ||
49 | /******************************************************************* | 49 | /******************************************************************* |
@@ -206,7 +206,7 @@ DAPI_(HRESULT) PathCompress( | |||
206 | *******************************************************************/ | 206 | *******************************************************************/ |
207 | DAPI_(HRESULT) PathGetHierarchyArray( | 207 | DAPI_(HRESULT) PathGetHierarchyArray( |
208 | __in_z LPCWSTR wzPath, | 208 | __in_z LPCWSTR wzPath, |
209 | __deref_inout_ecount_opt(*pcStrArray) LPWSTR **prgsczPathArray, | 209 | __deref_inout_ecount_opt(*pcPathArray) LPWSTR **prgsczPathArray, |
210 | __inout LPUINT pcPathArray | 210 | __inout LPUINT pcPathArray |
211 | ); | 211 | ); |
212 | 212 | ||
diff --git a/src/dutil/inc/regutil.h b/src/dutil/inc/regutil.h index 897b9d03..2f09d244 100644 --- a/src/dutil/inc/regutil.h +++ b/src/dutil/inc/regutil.h | |||
@@ -50,7 +50,7 @@ typedef LSTATUS (APIENTRY *PFN_REGENUMKEYEXW)( | |||
50 | __out LPWSTR lpName, | 50 | __out LPWSTR lpName, |
51 | __inout LPDWORD lpcName, | 51 | __inout LPDWORD lpcName, |
52 | __reserved LPDWORD lpReserved, | 52 | __reserved LPDWORD lpReserved, |
53 | __inout LPWSTR lpClass, | 53 | __inout_opt LPWSTR lpClass, |
54 | __inout_opt LPDWORD lpcClass, | 54 | __inout_opt LPDWORD lpcClass, |
55 | __out_opt PFILETIME lpftLastWriteTime | 55 | __out_opt PFILETIME lpftLastWriteTime |
56 | ); | 56 | ); |
@@ -66,7 +66,7 @@ typedef LSTATUS (APIENTRY *PFN_REGENUMVALUEW)( | |||
66 | ); | 66 | ); |
67 | typedef LSTATUS (APIENTRY *PFN_REGQUERYINFOKEYW)( | 67 | typedef LSTATUS (APIENTRY *PFN_REGQUERYINFOKEYW)( |
68 | __in HKEY hKey, | 68 | __in HKEY hKey, |
69 | __out LPWSTR lpClass, | 69 | __out_opt LPWSTR lpClass, |
70 | __inout_opt LPDWORD lpcClass, | 70 | __inout_opt LPDWORD lpcClass, |
71 | __reserved LPDWORD lpReserved, | 71 | __reserved LPDWORD lpReserved, |
72 | __out_opt LPDWORD lpcSubKeys, | 72 | __out_opt LPDWORD lpcSubKeys, |
@@ -170,7 +170,7 @@ HRESULT DAPI RegReadString( | |||
170 | HRESULT DAPI RegReadStringArray( | 170 | HRESULT DAPI RegReadStringArray( |
171 | __in HKEY hk, | 171 | __in HKEY hk, |
172 | __in_z_opt LPCWSTR wzName, | 172 | __in_z_opt LPCWSTR wzName, |
173 | __deref_out_ecount_opt(pcStrings) LPWSTR** prgsczStrings, | 173 | __deref_out_ecount_opt(*pcStrings) LPWSTR** prgsczStrings, |
174 | __out DWORD *pcStrings | 174 | __out DWORD *pcStrings |
175 | ); | 175 | ); |
176 | HRESULT DAPI RegReadVersion( | 176 | HRESULT DAPI RegReadVersion( |
@@ -202,7 +202,7 @@ HRESULT DAPI RegWriteString( | |||
202 | HRESULT DAPI RegWriteStringArray( | 202 | HRESULT DAPI RegWriteStringArray( |
203 | __in HKEY hk, | 203 | __in HKEY hk, |
204 | __in_z_opt LPCWSTR wzName, | 204 | __in_z_opt LPCWSTR wzName, |
205 | __in_ecount(cValues) LPWSTR *rgwzStrings, | 205 | __in_ecount(cStrings) LPWSTR *rgwzStrings, |
206 | __in DWORD cStrings | 206 | __in DWORD cStrings |
207 | ); | 207 | ); |
208 | HRESULT DAPI RegWriteStringFormatted( | 208 | HRESULT DAPI RegWriteStringFormatted( |
diff --git a/src/dutil/inc/shelutil.h b/src/dutil/inc/shelutil.h index 21e82672..0b9f539d 100644 --- a/src/dutil/inc/shelutil.h +++ b/src/dutil/inc/shelutil.h | |||
@@ -19,9 +19,9 @@ void DAPI ShelFunctionOverride( | |||
19 | ); | 19 | ); |
20 | HRESULT DAPI ShelExec( | 20 | HRESULT DAPI ShelExec( |
21 | __in_z LPCWSTR wzTargetPath, | 21 | __in_z LPCWSTR wzTargetPath, |
22 | __in_opt LPCWSTR wzParameters, | 22 | __in_z_opt LPCWSTR wzParameters, |
23 | __in_opt LPCWSTR wzVerb, | 23 | __in_z_opt LPCWSTR wzVerb, |
24 | __in_opt LPCWSTR wzWorkingDirectory, | 24 | __in_z_opt LPCWSTR wzWorkingDirectory, |
25 | __in int nShowCmd, | 25 | __in int nShowCmd, |
26 | __in_opt HWND hwndParent, | 26 | __in_opt HWND hwndParent, |
27 | __out_opt HANDLE* phProcess | 27 | __out_opt HANDLE* phProcess |
diff --git a/src/dutil/inc/strutil.h b/src/dutil/inc/strutil.h index 187bfda8..cf8c751c 100644 --- a/src/dutil/inc/strutil.h +++ b/src/dutil/inc/strutil.h | |||
@@ -198,7 +198,7 @@ HRESULT DAPI StrAllocBase85Decode( | |||
198 | 198 | ||
199 | HRESULT DAPI MultiSzLen( | 199 | HRESULT DAPI MultiSzLen( |
200 | __in_ecount(*pcch) __nullnullterminated LPCWSTR pwzMultiSz, | 200 | __in_ecount(*pcch) __nullnullterminated LPCWSTR pwzMultiSz, |
201 | __out SIZE_T* pcbch | 201 | __out SIZE_T* pcch |
202 | ); | 202 | ); |
203 | HRESULT DAPI MultiSzPrepend( | 203 | HRESULT DAPI MultiSzPrepend( |
204 | __deref_inout_ecount(*pcchMultiSz) __nullnullterminated LPWSTR* ppwzMultiSz, | 204 | __deref_inout_ecount(*pcchMultiSz) __nullnullterminated LPWSTR* ppwzMultiSz, |
@@ -222,7 +222,7 @@ HRESULT DAPI MultiSzRemoveString( | |||
222 | __in DWORD_PTR dwIndex | 222 | __in DWORD_PTR dwIndex |
223 | ); | 223 | ); |
224 | HRESULT DAPI MultiSzInsertString( | 224 | HRESULT DAPI MultiSzInsertString( |
225 | __deref_inout_z LPWSTR* ppwzMultiSz, | 225 | __deref_inout __nullnullterminated LPWSTR* ppwzMultiSz, |
226 | __inout_opt SIZE_T* pcchMultiSz, | 226 | __inout_opt SIZE_T* pcchMultiSz, |
227 | __in DWORD_PTR dwIndex, | 227 | __in DWORD_PTR dwIndex, |
228 | __in_z LPCWSTR pwzInsert | 228 | __in_z LPCWSTR pwzInsert |
diff --git a/src/dutil/inc/thmutil.h b/src/dutil/inc/thmutil.h index 11eac9c2..d3dd6d21 100644 --- a/src/dutil/inc/thmutil.h +++ b/src/dutil/inc/thmutil.h | |||
@@ -737,7 +737,7 @@ HRESULT DAPI ThemeSetTextControlEx( | |||
737 | HRESULT DAPI ThemeGetTextControl( | 737 | HRESULT DAPI ThemeGetTextControl( |
738 | __in const THEME* pTheme, | 738 | __in const THEME* pTheme, |
739 | __in DWORD dwControl, | 739 | __in DWORD dwControl, |
740 | __out_z LPWSTR* psczText | 740 | __inout_z LPWSTR* psczText |
741 | ); | 741 | ); |
742 | 742 | ||
743 | /******************************************************************** | 743 | /******************************************************************** |
diff --git a/src/dutil/inc/uriutil.h b/src/dutil/inc/uriutil.h index 52e78308..d6dfdd6b 100644 --- a/src/dutil/inc/uriutil.h +++ b/src/dutil/inc/uriutil.h | |||
@@ -91,7 +91,7 @@ HRESULT DAPI UriResolve( | |||
91 | __in_z LPCWSTR wzUri, | 91 | __in_z LPCWSTR wzUri, |
92 | __in_opt LPCWSTR wzBaseUri, | 92 | __in_opt LPCWSTR wzBaseUri, |
93 | __out LPWSTR* ppwzResolvedUri, | 93 | __out LPWSTR* ppwzResolvedUri, |
94 | __out_opt const URI_PROTOCOL* pResolvedProtocol | 94 | __out_opt URI_PROTOCOL* pResolvedProtocol |
95 | ); | 95 | ); |
96 | 96 | ||
97 | #ifdef __cplusplus | 97 | #ifdef __cplusplus |
diff --git a/src/dutil/inc/wiutil.h b/src/dutil/inc/wiutil.h index 10d003b0..9c2de209 100644 --- a/src/dutil/inc/wiutil.h +++ b/src/dutil/inc/wiutil.h | |||
@@ -330,7 +330,7 @@ HRESULT DAPI WiuEnumRelatedProducts( | |||
330 | ); | 330 | ); |
331 | HRESULT DAPI WiuEnumRelatedProductCodes( | 331 | HRESULT DAPI WiuEnumRelatedProductCodes( |
332 | __in_z LPCWSTR wzUpgradeCode, | 332 | __in_z LPCWSTR wzUpgradeCode, |
333 | __deref_out_ecount_opt(pcRelatedProducts) LPWSTR** prgsczProductCodes, | 333 | __deref_out_ecount_opt(*pcRelatedProducts) LPWSTR** prgsczProductCodes, |
334 | __out DWORD* pcRelatedProducts, | 334 | __out DWORD* pcRelatedProducts, |
335 | __in BOOL fReturnHighestVersionOnly | 335 | __in BOOL fReturnHighestVersionOnly |
336 | ); | 336 | ); |
diff --git a/src/dutil/inetutil.cpp b/src/dutil/inetutil.cpp index 69a0176a..f75849f6 100644 --- a/src/dutil/inetutil.cpp +++ b/src/dutil/inetutil.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | 5 | ||
6 | // Exit macros | ||
7 | #define InetExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_INETUTIL, x, s, __VA_ARGS__) | ||
8 | #define InetExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_INETUTIL, x, s, __VA_ARGS__) | ||
9 | #define InetExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_INETUTIL, x, s, __VA_ARGS__) | ||
10 | #define InetExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_INETUTIL, x, s, __VA_ARGS__) | ||
11 | #define InetExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_INETUTIL, x, s, __VA_ARGS__) | ||
12 | #define InetExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_INETUTIL, x, s, __VA_ARGS__) | ||
13 | #define InetExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_INETUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define InetExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_INETUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define InetExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_INETUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define InetExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_INETUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define InetExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_INETUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define InetExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_INETUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
6 | /******************************************************************* | 21 | /******************************************************************* |
7 | InternetGetSizeByHandle - returns size of file by url handle | 22 | InternetGetSizeByHandle - returns size of file by url handle |
8 | 23 | ||
@@ -15,13 +30,13 @@ extern "C" HRESULT DAPI InternetGetSizeByHandle( | |||
15 | Assert(pllSize); | 30 | Assert(pllSize); |
16 | 31 | ||
17 | HRESULT hr = S_OK; | 32 | HRESULT hr = S_OK; |
18 | DWORD dwSize; | 33 | DWORD dwSize = 0; |
19 | DWORD cb; | 34 | DWORD cb = 0; |
20 | 35 | ||
21 | cb = sizeof(dwSize); | 36 | cb = sizeof(dwSize); |
22 | if (!::HttpQueryInfoW(hiFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, reinterpret_cast<LPVOID>(&dwSize), &cb, NULL)) | 37 | if (!::HttpQueryInfoW(hiFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, reinterpret_cast<LPVOID>(&dwSize), &cb, NULL)) |
23 | { | 38 | { |
24 | ExitOnLastError(hr, "Failed to get size for internet file handle"); | 39 | InetExitOnLastError(hr, "Failed to get size for internet file handle"); |
25 | } | 40 | } |
26 | 41 | ||
27 | *pllSize = dwSize; | 42 | *pllSize = dwSize; |
@@ -47,12 +62,12 @@ extern "C" HRESULT DAPI InternetGetCreateTimeByHandle( | |||
47 | 62 | ||
48 | if (!::HttpQueryInfoW(hiFile, HTTP_QUERY_LAST_MODIFIED | HTTP_QUERY_FLAG_SYSTEMTIME, reinterpret_cast<LPVOID>(&st), &cb, NULL)) | 63 | if (!::HttpQueryInfoW(hiFile, HTTP_QUERY_LAST_MODIFIED | HTTP_QUERY_FLAG_SYSTEMTIME, reinterpret_cast<LPVOID>(&st), &cb, NULL)) |
49 | { | 64 | { |
50 | ExitWithLastError(hr, "failed to get create time for internet file handle"); | 65 | InetExitWithLastError(hr, "failed to get create time for internet file handle"); |
51 | } | 66 | } |
52 | 67 | ||
53 | if (!::SystemTimeToFileTime(&st, pft)) | 68 | if (!::SystemTimeToFileTime(&st, pft)) |
54 | { | 69 | { |
55 | ExitWithLastError(hr, "failed to convert system time to file time"); | 70 | InetExitWithLastError(hr, "failed to convert system time to file time"); |
56 | } | 71 | } |
57 | 72 | ||
58 | LExit: | 73 | LExit: |
@@ -78,11 +93,11 @@ extern "C" HRESULT DAPI InternetQueryInfoString( | |||
78 | if (!*psczValue) | 93 | if (!*psczValue) |
79 | { | 94 | { |
80 | hr = StrAlloc(psczValue, 64); | 95 | hr = StrAlloc(psczValue, 64); |
81 | ExitOnFailure(hr, "Failed to allocate memory for value."); | 96 | InetExitOnFailure(hr, "Failed to allocate memory for value."); |
82 | } | 97 | } |
83 | 98 | ||
84 | hr = StrSize(*psczValue, &cbValue); | 99 | hr = StrSize(*psczValue, &cbValue); |
85 | ExitOnFailure(hr, "Failed to get size of value."); | 100 | InetExitOnFailure(hr, "Failed to get size of value."); |
86 | 101 | ||
87 | if (!::HttpQueryInfoW(hRequest, dwInfo, static_cast<void*>(*psczValue), reinterpret_cast<DWORD*>(&cbValue), &dwIndex)) | 102 | if (!::HttpQueryInfoW(hRequest, dwInfo, static_cast<void*>(*psczValue), reinterpret_cast<DWORD*>(&cbValue), &dwIndex)) |
88 | { | 103 | { |
@@ -92,7 +107,7 @@ extern "C" HRESULT DAPI InternetQueryInfoString( | |||
92 | cbValue += sizeof(WCHAR); // add one character for the null terminator. | 107 | cbValue += sizeof(WCHAR); // add one character for the null terminator. |
93 | 108 | ||
94 | hr = StrAlloc(psczValue, cbValue / sizeof(WCHAR)); | 109 | hr = StrAlloc(psczValue, cbValue / sizeof(WCHAR)); |
95 | ExitOnFailure(hr, "Failed to allocate value."); | 110 | InetExitOnFailure(hr, "Failed to allocate value."); |
96 | 111 | ||
97 | if (!::HttpQueryInfoW(hRequest, dwInfo, static_cast<void*>(*psczValue), reinterpret_cast<DWORD*>(&cbValue), &dwIndex)) | 112 | if (!::HttpQueryInfoW(hRequest, dwInfo, static_cast<void*>(*psczValue), reinterpret_cast<DWORD*>(&cbValue), &dwIndex)) |
98 | { | 113 | { |
@@ -105,7 +120,7 @@ extern "C" HRESULT DAPI InternetQueryInfoString( | |||
105 | } | 120 | } |
106 | 121 | ||
107 | hr = HRESULT_FROM_WIN32(er); | 122 | hr = HRESULT_FROM_WIN32(er); |
108 | ExitOnRootFailure(hr, "Failed to get query information."); | 123 | InetExitOnRootFailure(hr, "Failed to get query information."); |
109 | } | 124 | } |
110 | 125 | ||
111 | LExit: | 126 | LExit: |
@@ -120,7 +135,7 @@ LExit: | |||
120 | extern "C" HRESULT DAPI InternetQueryInfoNumber( | 135 | extern "C" HRESULT DAPI InternetQueryInfoNumber( |
121 | __in HINTERNET hRequest, | 136 | __in HINTERNET hRequest, |
122 | __in DWORD dwInfo, | 137 | __in DWORD dwInfo, |
123 | __out LONG* plInfo | 138 | __inout LONG* plInfo |
124 | ) | 139 | ) |
125 | { | 140 | { |
126 | HRESULT hr = S_OK; | 141 | HRESULT hr = S_OK; |
@@ -129,7 +144,7 @@ extern "C" HRESULT DAPI InternetQueryInfoNumber( | |||
129 | 144 | ||
130 | if (!::HttpQueryInfoW(hRequest, dwInfo | HTTP_QUERY_FLAG_NUMBER, static_cast<void*>(plInfo), &cbCode, &dwIndex)) | 145 | if (!::HttpQueryInfoW(hRequest, dwInfo | HTTP_QUERY_FLAG_NUMBER, static_cast<void*>(plInfo), &cbCode, &dwIndex)) |
131 | { | 146 | { |
132 | ExitWithLastError(hr, "Failed to get query information."); | 147 | InetExitWithLastError(hr, "Failed to get query information."); |
133 | } | 148 | } |
134 | 149 | ||
135 | LExit: | 150 | LExit: |
diff --git a/src/dutil/iniutil.cpp b/src/dutil/iniutil.cpp index c9ef6c3d..70b62995 100644 --- a/src/dutil/iniutil.cpp +++ b/src/dutil/iniutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define IniExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__) | ||
8 | #define IniExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__) | ||
9 | #define IniExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__) | ||
10 | #define IniExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__) | ||
11 | #define IniExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__) | ||
12 | #define IniExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__) | ||
13 | #define IniExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_INIUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define IniExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_INIUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define IniExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_INIUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define IniExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_INIUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define IniExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_INIUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define IniExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_INIUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | const LPCWSTR wzSectionSeparator = L"\\"; | 20 | const LPCWSTR wzSectionSeparator = L"\\"; |
6 | 21 | ||
7 | struct INI_STRUCT | 22 | struct INI_STRUCT |
@@ -33,7 +48,7 @@ const int INI_HANDLE_BYTES = sizeof(INI_STRUCT); | |||
33 | 48 | ||
34 | static HRESULT GetSectionPrefixFromName( | 49 | static HRESULT GetSectionPrefixFromName( |
35 | __in_z LPCWSTR wzName, | 50 | __in_z LPCWSTR wzName, |
36 | __deref_out_z LPWSTR* psczOutput | 51 | __deref_inout_z LPWSTR* psczOutput |
37 | ); | 52 | ); |
38 | static void UninitializeIniValue( | 53 | static void UninitializeIniValue( |
39 | INI_VALUE *pivValue | 54 | INI_VALUE *pivValue |
@@ -47,7 +62,7 @@ extern "C" HRESULT DAPI IniInitialize( | |||
47 | 62 | ||
48 | // Allocate the handle | 63 | // Allocate the handle |
49 | *piHandle = static_cast<INI_HANDLE>(MemAlloc(sizeof(INI_STRUCT), TRUE)); | 64 | *piHandle = static_cast<INI_HANDLE>(MemAlloc(sizeof(INI_STRUCT), TRUE)); |
50 | ExitOnNull(*piHandle, hr, E_OUTOFMEMORY, "Failed to allocate ini object"); | 65 | IniExitOnNull(*piHandle, hr, E_OUTOFMEMORY, "Failed to allocate ini object"); |
51 | 66 | ||
52 | LExit: | 67 | LExit: |
53 | return hr; | 68 | return hr; |
@@ -96,7 +111,7 @@ extern "C" HRESULT DAPI IniSetOpenTag( | |||
96 | if (wzOpenTagPrefix) | 111 | if (wzOpenTagPrefix) |
97 | { | 112 | { |
98 | hr = StrAllocString(&pi->sczOpenTagPrefix, wzOpenTagPrefix, 0); | 113 | hr = StrAllocString(&pi->sczOpenTagPrefix, wzOpenTagPrefix, 0); |
99 | ExitOnFailure(hr, "Failed to copy open tag prefix to ini struct: %ls", wzOpenTagPrefix); | 114 | IniExitOnFailure(hr, "Failed to copy open tag prefix to ini struct: %ls", wzOpenTagPrefix); |
100 | } | 115 | } |
101 | else | 116 | else |
102 | { | 117 | { |
@@ -106,7 +121,7 @@ extern "C" HRESULT DAPI IniSetOpenTag( | |||
106 | if (wzOpenTagPostfix) | 121 | if (wzOpenTagPostfix) |
107 | { | 122 | { |
108 | hr = StrAllocString(&pi->sczOpenTagPostfix, wzOpenTagPostfix, 0); | 123 | hr = StrAllocString(&pi->sczOpenTagPostfix, wzOpenTagPostfix, 0); |
109 | ExitOnFailure(hr, "Failed to copy open tag postfix to ini struct: %ls", wzOpenTagPostfix); | 124 | IniExitOnFailure(hr, "Failed to copy open tag postfix to ini struct: %ls", wzOpenTagPostfix); |
110 | } | 125 | } |
111 | else | 126 | else |
112 | { | 127 | { |
@@ -130,7 +145,7 @@ extern "C" HRESULT DAPI IniSetValueStyle( | |||
130 | if (wzValuePrefix) | 145 | if (wzValuePrefix) |
131 | { | 146 | { |
132 | hr = StrAllocString(&pi->sczValuePrefix, wzValuePrefix, 0); | 147 | hr = StrAllocString(&pi->sczValuePrefix, wzValuePrefix, 0); |
133 | ExitOnFailure(hr, "Failed to copy value prefix to ini struct: %ls", wzValuePrefix); | 148 | IniExitOnFailure(hr, "Failed to copy value prefix to ini struct: %ls", wzValuePrefix); |
134 | } | 149 | } |
135 | else | 150 | else |
136 | { | 151 | { |
@@ -140,7 +155,7 @@ extern "C" HRESULT DAPI IniSetValueStyle( | |||
140 | if (wzValueSeparator) | 155 | if (wzValueSeparator) |
141 | { | 156 | { |
142 | hr = StrAllocString(&pi->sczValueSeparator, wzValueSeparator, 0); | 157 | hr = StrAllocString(&pi->sczValueSeparator, wzValueSeparator, 0); |
143 | ExitOnFailure(hr, "Failed to copy value separator to ini struct: %ls", wzValueSeparator); | 158 | IniExitOnFailure(hr, "Failed to copy value separator to ini struct: %ls", wzValueSeparator); |
144 | } | 159 | } |
145 | else | 160 | else |
146 | { | 161 | { |
@@ -162,12 +177,12 @@ extern "C" HRESULT DAPI IniSetValueSeparatorException( | |||
162 | INI_STRUCT *pi = static_cast<INI_STRUCT *>(piHandle); | 177 | INI_STRUCT *pi = static_cast<INI_STRUCT *>(piHandle); |
163 | 178 | ||
164 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&pi->rgsczValueSeparatorExceptions), pi->cValueSeparatorExceptions + 1, sizeof(LPWSTR), 5); | 179 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&pi->rgsczValueSeparatorExceptions), pi->cValueSeparatorExceptions + 1, sizeof(LPWSTR), 5); |
165 | ExitOnFailure(hr, "Failed to increase array size for value separator exceptions"); | 180 | IniExitOnFailure(hr, "Failed to increase array size for value separator exceptions"); |
166 | dwInsertedIndex = pi->cValueSeparatorExceptions; | 181 | dwInsertedIndex = pi->cValueSeparatorExceptions; |
167 | ++pi->cValueSeparatorExceptions; | 182 | ++pi->cValueSeparatorExceptions; |
168 | 183 | ||
169 | hr = StrAllocString(&pi->rgsczValueSeparatorExceptions[dwInsertedIndex], wzValueNamePrefix, 0); | 184 | hr = StrAllocString(&pi->rgsczValueSeparatorExceptions[dwInsertedIndex], wzValueNamePrefix, 0); |
170 | ExitOnFailure(hr, "Failed to copy value separator exception"); | 185 | IniExitOnFailure(hr, "Failed to copy value separator exception"); |
171 | 186 | ||
172 | LExit: | 187 | LExit: |
173 | return hr; | 188 | return hr; |
@@ -185,7 +200,7 @@ extern "C" HRESULT DAPI IniSetCommentStyle( | |||
185 | if (wzLinePrefix) | 200 | if (wzLinePrefix) |
186 | { | 201 | { |
187 | hr = StrAllocString(&pi->sczCommentLinePrefix, wzLinePrefix, 0); | 202 | hr = StrAllocString(&pi->sczCommentLinePrefix, wzLinePrefix, 0); |
188 | ExitOnFailure(hr, "Failed to copy comment line prefix to ini struct: %ls", wzLinePrefix); | 203 | IniExitOnFailure(hr, "Failed to copy comment line prefix to ini struct: %ls", wzLinePrefix); |
189 | } | 204 | } |
190 | else | 205 | else |
191 | { | 206 | { |
@@ -226,10 +241,10 @@ extern "C" HRESULT DAPI IniParse( | |||
226 | BOOL fValuePrefix = (NULL != pi->sczValuePrefix); | 241 | BOOL fValuePrefix = (NULL != pi->sczValuePrefix); |
227 | 242 | ||
228 | hr = StrAllocString(&pi->sczPath, wzPath, 0); | 243 | hr = StrAllocString(&pi->sczPath, wzPath, 0); |
229 | ExitOnFailure(hr, "Failed to copy path to ini struct: %ls", wzPath); | 244 | IniExitOnFailure(hr, "Failed to copy path to ini struct: %ls", wzPath); |
230 | 245 | ||
231 | hr = FileToString(pi->sczPath, &sczContents, &pi->feEncoding); | 246 | hr = FileToString(pi->sczPath, &sczContents, &pi->feEncoding); |
232 | ExitOnFailure(hr, "Failed to convert file to string: %ls", pi->sczPath); | 247 | IniExitOnFailure(hr, "Failed to convert file to string: %ls", pi->sczPath); |
233 | 248 | ||
234 | if (pfeEncodingFound) | 249 | if (pfeEncodingFound) |
235 | { | 250 | { |
@@ -244,7 +259,7 @@ extern "C" HRESULT DAPI IniParse( | |||
244 | 259 | ||
245 | dwValuePrefixLength = lstrlenW(pi->sczValuePrefix); | 260 | dwValuePrefixLength = lstrlenW(pi->sczValuePrefix); |
246 | hr = StrSplitAllocArray(&pi->rgsczLines, reinterpret_cast<UINT *>(&pi->cLines), sczContents, L"\n"); | 261 | hr = StrSplitAllocArray(&pi->rgsczLines, reinterpret_cast<UINT *>(&pi->cLines), sczContents, L"\n"); |
247 | ExitOnFailure(hr, "Failed to split INI file into lines"); | 262 | IniExitOnFailure(hr, "Failed to split INI file into lines"); |
248 | 263 | ||
249 | for (DWORD i = 0; i < pi->cLines; ++i) | 264 | for (DWORD i = 0; i < pi->cLines; ++i) |
250 | { | 265 | { |
@@ -324,7 +339,7 @@ extern "C" HRESULT DAPI IniParse( | |||
324 | { | 339 | { |
325 | // There is an section starting here, let's keep track of it and move on | 340 | // There is an section starting here, let's keep track of it and move on |
326 | hr = StrAllocString(&sczCurrentSection, wzOpenTagPrefix + lstrlenW(pi->sczOpenTagPrefix), wzOpenTagPostfix - (wzOpenTagPrefix + lstrlenW(pi->sczOpenTagPrefix))); | 341 | hr = StrAllocString(&sczCurrentSection, wzOpenTagPrefix + lstrlenW(pi->sczOpenTagPrefix), wzOpenTagPostfix - (wzOpenTagPrefix + lstrlenW(pi->sczOpenTagPrefix))); |
327 | ExitOnFailure(hr, "Failed to record section name for line: %ls of INI file: %ls", pi->rgsczLines[i], pi->sczPath); | 342 | IniExitOnFailure(hr, "Failed to record section name for line: %ls of INI file: %ls", pi->rgsczLines[i], pi->sczPath); |
328 | 343 | ||
329 | // Sections will be calculated dynamically after any set operations, so don't include this in the list of lines to remember for output | 344 | // Sections will be calculated dynamically after any set operations, so don't include this in the list of lines to remember for output |
330 | ReleaseNullStr(pi->rgsczLines[i]); | 345 | ReleaseNullStr(pi->rgsczLines[i]); |
@@ -342,28 +357,28 @@ extern "C" HRESULT DAPI IniParse( | |||
342 | } | 357 | } |
343 | 358 | ||
344 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&pi->rgivValues), pi->cValues + 1, sizeof(INI_VALUE), 100); | 359 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&pi->rgivValues), pi->cValues + 1, sizeof(INI_VALUE), 100); |
345 | ExitOnFailure(hr, "Failed to increase array size for value array"); | 360 | IniExitOnFailure(hr, "Failed to increase array size for value array"); |
346 | 361 | ||
347 | if (sczCurrentSection) | 362 | if (sczCurrentSection) |
348 | { | 363 | { |
349 | hr = StrAllocString(&sczName, sczCurrentSection, 0); | 364 | hr = StrAllocString(&sczName, sczCurrentSection, 0); |
350 | ExitOnFailure(hr, "Failed to copy current section name"); | 365 | IniExitOnFailure(hr, "Failed to copy current section name"); |
351 | 366 | ||
352 | hr = StrAllocConcat(&sczName, wzSectionSeparator, 0); | 367 | hr = StrAllocConcat(&sczName, wzSectionSeparator, 0); |
353 | ExitOnFailure(hr, "Failed to copy current section name"); | 368 | IniExitOnFailure(hr, "Failed to copy current section name"); |
354 | } | 369 | } |
355 | 370 | ||
356 | hr = StrAllocConcat(&sczName, wzValueBegin, wzValueSeparator - wzValueBegin); | 371 | hr = StrAllocConcat(&sczName, wzValueBegin, wzValueSeparator - wzValueBegin); |
357 | ExitOnFailure(hr, "Failed to copy name"); | 372 | IniExitOnFailure(hr, "Failed to copy name"); |
358 | 373 | ||
359 | hr = StrAllocString(&sczValue, wzValueSeparator + lstrlenW(pi->sczValueSeparator), 0); | 374 | hr = StrAllocString(&sczValue, wzValueSeparator + lstrlenW(pi->sczValueSeparator), 0); |
360 | ExitOnFailure(hr, "Failed to copy value"); | 375 | IniExitOnFailure(hr, "Failed to copy value"); |
361 | 376 | ||
362 | hr = StrTrimWhitespace(&sczNameTrimmed, sczName); | 377 | hr = StrTrimWhitespace(&sczNameTrimmed, sczName); |
363 | ExitOnFailure(hr, "Failed to trim whitespace from name"); | 378 | IniExitOnFailure(hr, "Failed to trim whitespace from name"); |
364 | 379 | ||
365 | hr = StrTrimWhitespace(&sczValueTrimmed, sczValue); | 380 | hr = StrTrimWhitespace(&sczValueTrimmed, sczValue); |
366 | ExitOnFailure(hr, "Failed to trim whitespace from value"); | 381 | IniExitOnFailure(hr, "Failed to trim whitespace from value"); |
367 | 382 | ||
368 | pi->rgivValues[pi->cValues].wzName = const_cast<LPCWSTR>(sczNameTrimmed); | 383 | pi->rgivValues[pi->cValues].wzName = const_cast<LPCWSTR>(sczNameTrimmed); |
369 | sczNameTrimmed = NULL; | 384 | sczNameTrimmed = NULL; |
@@ -397,7 +412,7 @@ LExit: | |||
397 | 412 | ||
398 | extern "C" HRESULT DAPI IniGetValueList( | 413 | extern "C" HRESULT DAPI IniGetValueList( |
399 | __in_bcount(INI_HANDLE_BYTES) INI_HANDLE piHandle, | 414 | __in_bcount(INI_HANDLE_BYTES) INI_HANDLE piHandle, |
400 | __deref_out_ecount_opt(pcValues) INI_VALUE** prgivValues, | 415 | __deref_out_ecount_opt(*pcValues) INI_VALUE** prgivValues, |
401 | __out DWORD *pcValues | 416 | __out DWORD *pcValues |
402 | ) | 417 | ) |
403 | { | 418 | { |
@@ -434,7 +449,7 @@ extern "C" HRESULT DAPI IniGetValue( | |||
434 | if (NULL == pValue) | 449 | if (NULL == pValue) |
435 | { | 450 | { |
436 | hr = E_NOTFOUND; | 451 | hr = E_NOTFOUND; |
437 | ExitOnFailure(hr, "Failed to check for INI value: %ls", wzValueName); | 452 | IniExitOnFailure(hr, "Failed to check for INI value: %ls", wzValueName); |
438 | } | 453 | } |
439 | 454 | ||
440 | if (NULL == pValue->wzValue) | 455 | if (NULL == pValue->wzValue) |
@@ -443,7 +458,7 @@ extern "C" HRESULT DAPI IniGetValue( | |||
443 | } | 458 | } |
444 | 459 | ||
445 | hr = StrAllocString(psczValue, pValue->wzValue, 0); | 460 | hr = StrAllocString(psczValue, pValue->wzValue, 0); |
446 | ExitOnFailure(hr, "Failed to make copy of value while looking up INI value named: %ls", wzValueName); | 461 | IniExitOnFailure(hr, "Failed to make copy of value while looking up INI value named: %ls", wzValueName); |
447 | 462 | ||
448 | LExit: | 463 | LExit: |
449 | return hr; | 464 | return hr; |
@@ -494,7 +509,7 @@ extern "C" HRESULT DAPI IniSetValue( | |||
494 | { | 509 | { |
495 | pi->fModified = TRUE; | 510 | pi->fModified = TRUE; |
496 | hr = StrAllocString(const_cast<LPWSTR *>(&pValue->wzValue), wzValue, 0); | 511 | hr = StrAllocString(const_cast<LPWSTR *>(&pValue->wzValue), wzValue, 0); |
497 | ExitOnFailure(hr, "Failed to update value INI value named: %ls", wzValueName); | 512 | IniExitOnFailure(hr, "Failed to update value INI value named: %ls", wzValueName); |
498 | } | 513 | } |
499 | 514 | ||
500 | ExitFunction1(hr = S_OK); | 515 | ExitFunction1(hr = S_OK); |
@@ -504,7 +519,7 @@ extern "C" HRESULT DAPI IniSetValue( | |||
504 | if (wzValueName) | 519 | if (wzValueName) |
505 | { | 520 | { |
506 | hr = GetSectionPrefixFromName(wzValueName, &sczSectionPrefix); | 521 | hr = GetSectionPrefixFromName(wzValueName, &sczSectionPrefix); |
507 | ExitOnFailure(hr, "Failed to get section prefix from value name: %ls", wzValueName); | 522 | IniExitOnFailure(hr, "Failed to get section prefix from value name: %ls", wzValueName); |
508 | } | 523 | } |
509 | 524 | ||
510 | // If we have a section prefix, figure out the index to insert it (at the end of the section it belongs in) | 525 | // If we have a section prefix, figure out the index to insert it (at the end of the section it belongs in) |
@@ -545,13 +560,13 @@ extern "C" HRESULT DAPI IniSetValue( | |||
545 | 560 | ||
546 | pi->fModified = TRUE; | 561 | pi->fModified = TRUE; |
547 | hr = MemInsertIntoArray(reinterpret_cast<void **>(&pi->rgivValues), dwInsertIndex, 1, pi->cValues + 1, sizeof(INI_VALUE), 100); | 562 | hr = MemInsertIntoArray(reinterpret_cast<void **>(&pi->rgivValues), dwInsertIndex, 1, pi->cValues + 1, sizeof(INI_VALUE), 100); |
548 | ExitOnFailure(hr, "Failed to insert value into array"); | 563 | IniExitOnFailure(hr, "Failed to insert value into array"); |
549 | 564 | ||
550 | hr = StrAllocString(&sczName, wzValueName, 0); | 565 | hr = StrAllocString(&sczName, wzValueName, 0); |
551 | ExitOnFailure(hr, "Failed to copy name"); | 566 | IniExitOnFailure(hr, "Failed to copy name"); |
552 | 567 | ||
553 | hr = StrAllocString(&sczValue, wzValue, 0); | 568 | hr = StrAllocString(&sczValue, wzValue, 0); |
554 | ExitOnFailure(hr, "Failed to copy value"); | 569 | IniExitOnFailure(hr, "Failed to copy value"); |
555 | 570 | ||
556 | pi->rgivValues[dwInsertIndex].wzName = const_cast<LPCWSTR>(sczName); | 571 | pi->rgivValues[dwInsertIndex].wzName = const_cast<LPCWSTR>(sczName); |
557 | sczName = NULL; | 572 | sczName = NULL; |
@@ -611,7 +626,7 @@ extern "C" HRESULT DAPI IniWriteFile( | |||
611 | BOOL fSections = (pi->sczOpenTagPrefix) && (pi->sczOpenTagPostfix); | 626 | BOOL fSections = (pi->sczOpenTagPrefix) && (pi->sczOpenTagPostfix); |
612 | 627 | ||
613 | hr = StrAllocString(&sczContents, L"", 0); | 628 | hr = StrAllocString(&sczContents, L"", 0); |
614 | ExitOnFailure(hr, "Failed to begin contents string as empty string"); | 629 | IniExitOnFailure(hr, "Failed to begin contents string as empty string"); |
615 | 630 | ||
616 | // Insert any beginning lines we didn't understand like comments | 631 | // Insert any beginning lines we didn't understand like comments |
617 | if (0 < pi->cLines) | 632 | if (0 < pi->cLines) |
@@ -619,10 +634,10 @@ extern "C" HRESULT DAPI IniWriteFile( | |||
619 | while (pi->rgsczLines[dwLineArrayIndex]) | 634 | while (pi->rgsczLines[dwLineArrayIndex]) |
620 | { | 635 | { |
621 | hr = StrAllocConcat(&sczContents, pi->rgsczLines[dwLineArrayIndex], 0); | 636 | hr = StrAllocConcat(&sczContents, pi->rgsczLines[dwLineArrayIndex], 0); |
622 | ExitOnFailure(hr, "Failed to add previous line to ini output buffer in-memory"); | 637 | IniExitOnFailure(hr, "Failed to add previous line to ini output buffer in-memory"); |
623 | 638 | ||
624 | hr = StrAllocConcat(&sczContents, L"\r\n", 2); | 639 | hr = StrAllocConcat(&sczContents, L"\r\n", 2); |
625 | ExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory"); | 640 | IniExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory"); |
626 | 641 | ||
627 | ++dwLineArrayIndex; | 642 | ++dwLineArrayIndex; |
628 | } | 643 | } |
@@ -640,23 +655,23 @@ extern "C" HRESULT DAPI IniWriteFile( | |||
640 | 655 | ||
641 | // First see if we need to write a section line | 656 | // First see if we need to write a section line |
642 | hr = GetSectionPrefixFromName(pi->rgivValues[i].wzName, &sczNewSectionPrefix); | 657 | hr = GetSectionPrefixFromName(pi->rgivValues[i].wzName, &sczNewSectionPrefix); |
643 | ExitOnFailure(hr, "Failed to get section prefix from name: %ls", pi->rgivValues[i].wzName); | 658 | IniExitOnFailure(hr, "Failed to get section prefix from name: %ls", pi->rgivValues[i].wzName); |
644 | 659 | ||
645 | // If the new section prefix is different, write a section out for it | 660 | // If the new section prefix is different, write a section out for it |
646 | if (fSections && sczNewSectionPrefix && (NULL == sczCurrentSectionPrefix || CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, 0, sczNewSectionPrefix, -1, sczCurrentSectionPrefix, -1))) | 661 | if (fSections && sczNewSectionPrefix && (NULL == sczCurrentSectionPrefix || CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, 0, sczNewSectionPrefix, -1, sczCurrentSectionPrefix, -1))) |
647 | { | 662 | { |
648 | hr = StrAllocConcat(&sczContents, pi->sczOpenTagPrefix, 0); | 663 | hr = StrAllocConcat(&sczContents, pi->sczOpenTagPrefix, 0); |
649 | ExitOnFailure(hr, "Failed to concat open tag prefix to string"); | 664 | IniExitOnFailure(hr, "Failed to concat open tag prefix to string"); |
650 | 665 | ||
651 | // Exclude section separator (i.e. backslash) from new section prefix | 666 | // Exclude section separator (i.e. backslash) from new section prefix |
652 | hr = StrAllocConcat(&sczContents, sczNewSectionPrefix, lstrlenW(sczNewSectionPrefix)-lstrlenW(wzSectionSeparator)); | 667 | hr = StrAllocConcat(&sczContents, sczNewSectionPrefix, lstrlenW(sczNewSectionPrefix)-lstrlenW(wzSectionSeparator)); |
653 | ExitOnFailure(hr, "Failed to concat section name to string"); | 668 | IniExitOnFailure(hr, "Failed to concat section name to string"); |
654 | 669 | ||
655 | hr = StrAllocConcat(&sczContents, pi->sczOpenTagPostfix, 0); | 670 | hr = StrAllocConcat(&sczContents, pi->sczOpenTagPostfix, 0); |
656 | ExitOnFailure(hr, "Failed to concat open tag postfix to string"); | 671 | IniExitOnFailure(hr, "Failed to concat open tag postfix to string"); |
657 | 672 | ||
658 | hr = StrAllocConcat(&sczContents, L"\r\n", 2); | 673 | hr = StrAllocConcat(&sczContents, L"\r\n", 2); |
659 | ExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory"); | 674 | IniExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory"); |
660 | 675 | ||
661 | ReleaseNullStr(sczCurrentSectionPrefix); | 676 | ReleaseNullStr(sczCurrentSectionPrefix); |
662 | sczCurrentSectionPrefix = sczNewSectionPrefix; | 677 | sczCurrentSectionPrefix = sczNewSectionPrefix; |
@@ -674,10 +689,10 @@ extern "C" HRESULT DAPI IniWriteFile( | |||
674 | } | 689 | } |
675 | 690 | ||
676 | hr = StrAllocConcat(&sczContents, pi->rgsczLines[dwLineArrayIndex++], 0); | 691 | hr = StrAllocConcat(&sczContents, pi->rgsczLines[dwLineArrayIndex++], 0); |
677 | ExitOnFailure(hr, "Failed to add previous line to ini output buffer in-memory"); | 692 | IniExitOnFailure(hr, "Failed to add previous line to ini output buffer in-memory"); |
678 | 693 | ||
679 | hr = StrAllocConcat(&sczContents, L"\r\n", 2); | 694 | hr = StrAllocConcat(&sczContents, L"\r\n", 2); |
680 | ExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory"); | 695 | IniExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory"); |
681 | } | 696 | } |
682 | 697 | ||
683 | wzName = pi->rgivValues[i].wzName; | 698 | wzName = pi->rgivValues[i].wzName; |
@@ -690,20 +705,20 @@ extern "C" HRESULT DAPI IniWriteFile( | |||
690 | if (pi->sczValuePrefix) | 705 | if (pi->sczValuePrefix) |
691 | { | 706 | { |
692 | hr = StrAllocConcat(&sczContents, pi->sczValuePrefix, 0); | 707 | hr = StrAllocConcat(&sczContents, pi->sczValuePrefix, 0); |
693 | ExitOnFailure(hr, "Failed to concat value prefix to ini output buffer"); | 708 | IniExitOnFailure(hr, "Failed to concat value prefix to ini output buffer"); |
694 | } | 709 | } |
695 | 710 | ||
696 | hr = StrAllocConcat(&sczContents, wzName, 0); | 711 | hr = StrAllocConcat(&sczContents, wzName, 0); |
697 | ExitOnFailure(hr, "Failed to concat value name to ini output buffer"); | 712 | IniExitOnFailure(hr, "Failed to concat value name to ini output buffer"); |
698 | 713 | ||
699 | hr = StrAllocConcat(&sczContents, pi->sczValueSeparator, 0); | 714 | hr = StrAllocConcat(&sczContents, pi->sczValueSeparator, 0); |
700 | ExitOnFailure(hr, "Failed to concat value separator to ini output buffer"); | 715 | IniExitOnFailure(hr, "Failed to concat value separator to ini output buffer"); |
701 | 716 | ||
702 | hr = StrAllocConcat(&sczContents, pi->rgivValues[i].wzValue, 0); | 717 | hr = StrAllocConcat(&sczContents, pi->rgivValues[i].wzValue, 0); |
703 | ExitOnFailure(hr, "Failed to concat value to ini output buffer"); | 718 | IniExitOnFailure(hr, "Failed to concat value to ini output buffer"); |
704 | 719 | ||
705 | hr = StrAllocConcat(&sczContents, L"\r\n", 2); | 720 | hr = StrAllocConcat(&sczContents, L"\r\n", 2); |
706 | ExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory"); | 721 | IniExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory"); |
707 | } | 722 | } |
708 | 723 | ||
709 | // If no path was specified, use the path to the file we parsed | 724 | // If no path was specified, use the path to the file we parsed |
@@ -713,7 +728,7 @@ extern "C" HRESULT DAPI IniWriteFile( | |||
713 | } | 728 | } |
714 | 729 | ||
715 | hr = FileFromString(wzPath, 0, sczContents, feEncoding); | 730 | hr = FileFromString(wzPath, 0, sczContents, feEncoding); |
716 | ExitOnFailure(hr, "Failed to write INI contents out to file: %ls", wzPath); | 731 | IniExitOnFailure(hr, "Failed to write INI contents out to file: %ls", wzPath); |
717 | 732 | ||
718 | LExit: | 733 | LExit: |
719 | ReleaseStr(sczContents); | 734 | ReleaseStr(sczContents); |
@@ -733,7 +748,7 @@ static void UninitializeIniValue( | |||
733 | 748 | ||
734 | static HRESULT GetSectionPrefixFromName( | 749 | static HRESULT GetSectionPrefixFromName( |
735 | __in_z LPCWSTR wzName, | 750 | __in_z LPCWSTR wzName, |
736 | __deref_out_z LPWSTR* psczOutput | 751 | __deref_inout_z LPWSTR* psczOutput |
737 | ) | 752 | ) |
738 | { | 753 | { |
739 | HRESULT hr = S_OK; | 754 | HRESULT hr = S_OK; |
@@ -745,7 +760,7 @@ static HRESULT GetSectionPrefixFromName( | |||
745 | if (wzSectionDelimiter && wzSectionDelimiter != wzName) | 760 | if (wzSectionDelimiter && wzSectionDelimiter != wzName) |
746 | { | 761 | { |
747 | hr = StrAllocString(psczOutput, wzName, wzSectionDelimiter - wzName + 1); | 762 | hr = StrAllocString(psczOutput, wzName, wzSectionDelimiter - wzName + 1); |
748 | ExitOnFailure(hr, "Failed to copy section prefix"); | 763 | IniExitOnFailure(hr, "Failed to copy section prefix"); |
749 | } | 764 | } |
750 | 765 | ||
751 | LExit: | 766 | LExit: |
diff --git a/src/dutil/jsonutil.cpp b/src/dutil/jsonutil.cpp index ba088705..3450ba59 100644 --- a/src/dutil/jsonutil.cpp +++ b/src/dutil/jsonutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define JsonExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_JSONUTIL, x, s, __VA_ARGS__) | ||
8 | #define JsonExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_JSONUTIL, x, s, __VA_ARGS__) | ||
9 | #define JsonExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_JSONUTIL, x, s, __VA_ARGS__) | ||
10 | #define JsonExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_JSONUTIL, x, s, __VA_ARGS__) | ||
11 | #define JsonExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_JSONUTIL, x, s, __VA_ARGS__) | ||
12 | #define JsonExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_JSONUTIL, x, s, __VA_ARGS__) | ||
13 | #define JsonExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_JSONUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define JsonExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_JSONUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define JsonExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_JSONUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define JsonExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_JSONUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define JsonExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_JSONUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define JsonExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_JSONUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | const DWORD JSON_STACK_INCREMENT = 5; | 20 | const DWORD JSON_STACK_INCREMENT = 5; |
6 | 21 | ||
7 | // Prototypes | 22 | // Prototypes |
@@ -44,7 +59,7 @@ DAPI_(HRESULT) JsonInitializeReader( | |||
44 | ::InitializeCriticalSection(&pReader->cs); | 59 | ::InitializeCriticalSection(&pReader->cs); |
45 | 60 | ||
46 | hr = StrAllocString(&pReader->sczJson, wzJson, 0); | 61 | hr = StrAllocString(&pReader->sczJson, wzJson, 0); |
47 | ExitOnFailure(hr, "Failed to allocate json string."); | 62 | JsonExitOnFailure(hr, "Failed to allocate json string."); |
48 | 63 | ||
49 | pReader->pwz = pReader->sczJson; | 64 | pReader->pwz = pReader->sczJson; |
50 | 65 | ||
@@ -153,7 +168,7 @@ DAPI_(HRESULT) JsonReadNext( | |||
153 | { | 168 | { |
154 | ExitFunction(); | 169 | ExitFunction(); |
155 | } | 170 | } |
156 | ExitOnFailure(hr, "Failed to get next token."); | 171 | JsonExitOnFailure(hr, "Failed to get next token."); |
157 | 172 | ||
158 | if (JSON_TOKEN_VALUE == *pToken) | 173 | if (JSON_TOKEN_VALUE == *pToken) |
159 | { | 174 | { |
@@ -214,10 +229,10 @@ DAPI_(HRESULT) JsonWriteBool( | |||
214 | LPWSTR sczValue = NULL; | 229 | LPWSTR sczValue = NULL; |
215 | 230 | ||
216 | hr = StrAllocString(&sczValue, fValue ? L"true" : L"false", 0); | 231 | hr = StrAllocString(&sczValue, fValue ? L"true" : L"false", 0); |
217 | ExitOnFailure(hr, "Failed to convert boolean to string."); | 232 | JsonExitOnFailure(hr, "Failed to convert boolean to string."); |
218 | 233 | ||
219 | hr = DoValue(pWriter, sczValue); | 234 | hr = DoValue(pWriter, sczValue); |
220 | ExitOnFailure(hr, "Failed to add boolean to JSON."); | 235 | JsonExitOnFailure(hr, "Failed to add boolean to JSON."); |
221 | 236 | ||
222 | LExit: | 237 | LExit: |
223 | ReleaseStr(sczValue); | 238 | ReleaseStr(sczValue); |
@@ -234,10 +249,10 @@ DAPI_(HRESULT) JsonWriteNumber( | |||
234 | LPWSTR sczValue = NULL; | 249 | LPWSTR sczValue = NULL; |
235 | 250 | ||
236 | hr = StrAllocFormatted(&sczValue, L"%u", dwValue); | 251 | hr = StrAllocFormatted(&sczValue, L"%u", dwValue); |
237 | ExitOnFailure(hr, "Failed to convert number to string."); | 252 | JsonExitOnFailure(hr, "Failed to convert number to string."); |
238 | 253 | ||
239 | hr = DoValue(pWriter, sczValue); | 254 | hr = DoValue(pWriter, sczValue); |
240 | ExitOnFailure(hr, "Failed to add number to JSON."); | 255 | JsonExitOnFailure(hr, "Failed to add number to JSON."); |
241 | 256 | ||
242 | LExit: | 257 | LExit: |
243 | ReleaseStr(sczValue); | 258 | ReleaseStr(sczValue); |
@@ -254,10 +269,10 @@ DAPI_(HRESULT) JsonWriteString( | |||
254 | LPWSTR sczJsonString = NULL; | 269 | LPWSTR sczJsonString = NULL; |
255 | 270 | ||
256 | hr = SerializeJsonString(&sczJsonString, wzValue); | 271 | hr = SerializeJsonString(&sczJsonString, wzValue); |
257 | ExitOnFailure(hr, "Failed to allocate string JSON."); | 272 | JsonExitOnFailure(hr, "Failed to allocate string JSON."); |
258 | 273 | ||
259 | hr = DoValue(pWriter, sczJsonString); | 274 | hr = DoValue(pWriter, sczJsonString); |
260 | ExitOnFailure(hr, "Failed to add string to JSON."); | 275 | JsonExitOnFailure(hr, "Failed to add string to JSON."); |
261 | 276 | ||
262 | LExit: | 277 | LExit: |
263 | ReleaseStr(sczJsonString); | 278 | ReleaseStr(sczJsonString); |
@@ -272,7 +287,7 @@ DAPI_(HRESULT) JsonWriteArrayStart( | |||
272 | HRESULT hr = S_OK; | 287 | HRESULT hr = S_OK; |
273 | 288 | ||
274 | hr = DoStart(pWriter, JSON_TOKEN_ARRAY_START, L"["); | 289 | hr = DoStart(pWriter, JSON_TOKEN_ARRAY_START, L"["); |
275 | ExitOnFailure(hr, "Failed to start JSON array."); | 290 | JsonExitOnFailure(hr, "Failed to start JSON array."); |
276 | 291 | ||
277 | LExit: | 292 | LExit: |
278 | return hr; | 293 | return hr; |
@@ -286,7 +301,7 @@ DAPI_(HRESULT) JsonWriteArrayEnd( | |||
286 | HRESULT hr = S_OK; | 301 | HRESULT hr = S_OK; |
287 | 302 | ||
288 | hr = DoEnd(pWriter, JSON_TOKEN_ARRAY_END, L"]"); | 303 | hr = DoEnd(pWriter, JSON_TOKEN_ARRAY_END, L"]"); |
289 | ExitOnFailure(hr, "Failed to end JSON array."); | 304 | JsonExitOnFailure(hr, "Failed to end JSON array."); |
290 | 305 | ||
291 | LExit: | 306 | LExit: |
292 | return hr; | 307 | return hr; |
@@ -300,7 +315,7 @@ DAPI_(HRESULT) JsonWriteObjectStart( | |||
300 | HRESULT hr = S_OK; | 315 | HRESULT hr = S_OK; |
301 | 316 | ||
302 | hr = DoStart(pWriter, JSON_TOKEN_OBJECT_START, L"{"); | 317 | hr = DoStart(pWriter, JSON_TOKEN_OBJECT_START, L"{"); |
303 | ExitOnFailure(hr, "Failed to start JSON object."); | 318 | JsonExitOnFailure(hr, "Failed to start JSON object."); |
304 | 319 | ||
305 | LExit: | 320 | LExit: |
306 | return hr; | 321 | return hr; |
@@ -316,10 +331,10 @@ DAPI_(HRESULT) JsonWriteObjectKey( | |||
316 | LPWSTR sczObjectKey = NULL; | 331 | LPWSTR sczObjectKey = NULL; |
317 | 332 | ||
318 | hr = StrAllocFormatted(&sczObjectKey, L"\"%ls\":", wzKey); | 333 | hr = StrAllocFormatted(&sczObjectKey, L"\"%ls\":", wzKey); |
319 | ExitOnFailure(hr, "Failed to allocate JSON object key."); | 334 | JsonExitOnFailure(hr, "Failed to allocate JSON object key."); |
320 | 335 | ||
321 | hr = DoKey(pWriter, sczObjectKey); | 336 | hr = DoKey(pWriter, sczObjectKey); |
322 | ExitOnFailure(hr, "Failed to add object key to JSON."); | 337 | JsonExitOnFailure(hr, "Failed to add object key to JSON."); |
323 | 338 | ||
324 | LExit: | 339 | LExit: |
325 | ReleaseStr(sczObjectKey); | 340 | ReleaseStr(sczObjectKey); |
@@ -334,7 +349,7 @@ DAPI_(HRESULT) JsonWriteObjectEnd( | |||
334 | HRESULT hr = S_OK; | 349 | HRESULT hr = S_OK; |
335 | 350 | ||
336 | hr = DoEnd(pWriter, JSON_TOKEN_OBJECT_END, L"}"); | 351 | hr = DoEnd(pWriter, JSON_TOKEN_OBJECT_END, L"}"); |
337 | ExitOnFailure(hr, "Failed to end JSON object."); | 352 | JsonExitOnFailure(hr, "Failed to end JSON object."); |
338 | 353 | ||
339 | LExit: | 354 | LExit: |
340 | return hr; | 355 | return hr; |
@@ -357,7 +372,7 @@ static HRESULT DoStart( | |||
357 | ::EnterCriticalSection(&pWriter->cs); | 372 | ::EnterCriticalSection(&pWriter->cs); |
358 | 373 | ||
359 | hr = EnsureTokenStack(pWriter); | 374 | hr = EnsureTokenStack(pWriter); |
360 | ExitOnFailure(hr, "Failed to ensure token stack for start."); | 375 | JsonExitOnFailure(hr, "Failed to ensure token stack for start."); |
361 | 376 | ||
362 | token = pWriter->rgTokenStack[pWriter->cTokens - 1]; | 377 | token = pWriter->rgTokenStack[pWriter->cTokens - 1]; |
363 | switch (token) | 378 | switch (token) |
@@ -381,16 +396,16 @@ static HRESULT DoStart( | |||
381 | hr = E_UNEXPECTED; | 396 | hr = E_UNEXPECTED; |
382 | break; | 397 | break; |
383 | } | 398 | } |
384 | ExitOnRootFailure(hr, "Cannot start array or object to JSON serializer now."); | 399 | JsonExitOnRootFailure(hr, "Cannot start array or object to JSON serializer now."); |
385 | 400 | ||
386 | if (fNeedComma) | 401 | if (fNeedComma) |
387 | { | 402 | { |
388 | hr = StrAllocConcat(&pWriter->sczJson, L",", 0); | 403 | hr = StrAllocConcat(&pWriter->sczJson, L",", 0); |
389 | ExitOnFailure(hr, "Failed to add comma for start array or object to JSON."); | 404 | JsonExitOnFailure(hr, "Failed to add comma for start array or object to JSON."); |
390 | } | 405 | } |
391 | 406 | ||
392 | hr = StrAllocConcat(&pWriter->sczJson, wzStartString, 0); | 407 | hr = StrAllocConcat(&pWriter->sczJson, wzStartString, 0); |
393 | ExitOnFailure(hr, "Failed to start JSON array or object."); | 408 | JsonExitOnFailure(hr, "Failed to start JSON array or object."); |
394 | 409 | ||
395 | pWriter->rgTokenStack[pWriter->cTokens - 1] = token; | 410 | pWriter->rgTokenStack[pWriter->cTokens - 1] = token; |
396 | if (fPushToken) | 411 | if (fPushToken) |
@@ -418,7 +433,7 @@ static HRESULT DoEnd( | |||
418 | if (!pWriter->rgTokenStack || 0 == pWriter->cTokens) | 433 | if (!pWriter->rgTokenStack || 0 == pWriter->cTokens) |
419 | { | 434 | { |
420 | hr = E_UNEXPECTED; | 435 | hr = E_UNEXPECTED; |
421 | ExitOnRootFailure(hr, "Failure to pop token because the stack is empty."); | 436 | JsonExitOnRootFailure(hr, "Failure to pop token because the stack is empty."); |
422 | } | 437 | } |
423 | else | 438 | else |
424 | { | 439 | { |
@@ -427,12 +442,12 @@ static HRESULT DoEnd( | |||
427 | (JSON_TOKEN_OBJECT_END == tokenEnd && JSON_TOKEN_OBJECT_START != token && JSON_TOKEN_OBJECT_VALUE != token)) | 442 | (JSON_TOKEN_OBJECT_END == tokenEnd && JSON_TOKEN_OBJECT_START != token && JSON_TOKEN_OBJECT_VALUE != token)) |
428 | { | 443 | { |
429 | hr = E_UNEXPECTED; | 444 | hr = E_UNEXPECTED; |
430 | ExitOnRootFailure(hr, "Failure to pop token because the stack did not match the expected token: %d", tokenEnd); | 445 | JsonExitOnRootFailure(hr, "Failure to pop token because the stack did not match the expected token: %d", tokenEnd); |
431 | } | 446 | } |
432 | } | 447 | } |
433 | 448 | ||
434 | hr = StrAllocConcat(&pWriter->sczJson, wzEndString, 0); | 449 | hr = StrAllocConcat(&pWriter->sczJson, wzEndString, 0); |
435 | ExitOnFailure(hr, "Failed to end JSON array or object."); | 450 | JsonExitOnFailure(hr, "Failed to end JSON array or object."); |
436 | 451 | ||
437 | --pWriter->cTokens; | 452 | --pWriter->cTokens; |
438 | 453 | ||
@@ -454,7 +469,7 @@ static HRESULT DoKey( | |||
454 | ::EnterCriticalSection(&pWriter->cs); | 469 | ::EnterCriticalSection(&pWriter->cs); |
455 | 470 | ||
456 | hr = EnsureTokenStack(pWriter); | 471 | hr = EnsureTokenStack(pWriter); |
457 | ExitOnFailure(hr, "Failed to ensure token stack for key."); | 472 | JsonExitOnFailure(hr, "Failed to ensure token stack for key."); |
458 | 473 | ||
459 | token = pWriter->rgTokenStack[pWriter->cTokens - 1]; | 474 | token = pWriter->rgTokenStack[pWriter->cTokens - 1]; |
460 | switch (token) | 475 | switch (token) |
@@ -472,16 +487,16 @@ static HRESULT DoKey( | |||
472 | hr = E_UNEXPECTED; | 487 | hr = E_UNEXPECTED; |
473 | break; | 488 | break; |
474 | } | 489 | } |
475 | ExitOnRootFailure(hr, "Cannot add key to JSON serializer now."); | 490 | JsonExitOnRootFailure(hr, "Cannot add key to JSON serializer now."); |
476 | 491 | ||
477 | if (fNeedComma) | 492 | if (fNeedComma) |
478 | { | 493 | { |
479 | hr = StrAllocConcat(&pWriter->sczJson, L",", 0); | 494 | hr = StrAllocConcat(&pWriter->sczJson, L",", 0); |
480 | ExitOnFailure(hr, "Failed to add comma for key to JSON."); | 495 | JsonExitOnFailure(hr, "Failed to add comma for key to JSON."); |
481 | } | 496 | } |
482 | 497 | ||
483 | hr = StrAllocConcat(&pWriter->sczJson, wzKey, 0); | 498 | hr = StrAllocConcat(&pWriter->sczJson, wzKey, 0); |
484 | ExitOnFailure(hr, "Failed to add key to JSON."); | 499 | JsonExitOnFailure(hr, "Failed to add key to JSON."); |
485 | 500 | ||
486 | pWriter->rgTokenStack[pWriter->cTokens - 1] = token; | 501 | pWriter->rgTokenStack[pWriter->cTokens - 1] = token; |
487 | 502 | ||
@@ -503,7 +518,7 @@ static HRESULT DoValue( | |||
503 | ::EnterCriticalSection(&pWriter->cs); | 518 | ::EnterCriticalSection(&pWriter->cs); |
504 | 519 | ||
505 | hr = EnsureTokenStack(pWriter); | 520 | hr = EnsureTokenStack(pWriter); |
506 | ExitOnFailure(hr, "Failed to ensure token stack for value."); | 521 | JsonExitOnFailure(hr, "Failed to ensure token stack for value."); |
507 | 522 | ||
508 | token = pWriter->rgTokenStack[pWriter->cTokens - 1]; | 523 | token = pWriter->rgTokenStack[pWriter->cTokens - 1]; |
509 | switch (token) | 524 | switch (token) |
@@ -528,23 +543,23 @@ static HRESULT DoValue( | |||
528 | hr = E_UNEXPECTED; | 543 | hr = E_UNEXPECTED; |
529 | break; | 544 | break; |
530 | } | 545 | } |
531 | ExitOnRootFailure(hr, "Cannot add value to JSON serializer now."); | 546 | JsonExitOnRootFailure(hr, "Cannot add value to JSON serializer now."); |
532 | 547 | ||
533 | if (fNeedComma) | 548 | if (fNeedComma) |
534 | { | 549 | { |
535 | hr = StrAllocConcat(&pWriter->sczJson, L",", 0); | 550 | hr = StrAllocConcat(&pWriter->sczJson, L",", 0); |
536 | ExitOnFailure(hr, "Failed to add comma for value to JSON."); | 551 | JsonExitOnFailure(hr, "Failed to add comma for value to JSON."); |
537 | } | 552 | } |
538 | 553 | ||
539 | if (wzValue) | 554 | if (wzValue) |
540 | { | 555 | { |
541 | hr = StrAllocConcat(&pWriter->sczJson, wzValue, 0); | 556 | hr = StrAllocConcat(&pWriter->sczJson, wzValue, 0); |
542 | ExitOnFailure(hr, "Failed to add value to JSON."); | 557 | JsonExitOnFailure(hr, "Failed to add value to JSON."); |
543 | } | 558 | } |
544 | else | 559 | else |
545 | { | 560 | { |
546 | hr = StrAllocConcat(&pWriter->sczJson, L"null", 0); | 561 | hr = StrAllocConcat(&pWriter->sczJson, L"null", 0); |
547 | ExitOnFailure(hr, "Failed to add null value to JSON."); | 562 | JsonExitOnFailure(hr, "Failed to add null value to JSON."); |
548 | } | 563 | } |
549 | 564 | ||
550 | pWriter->rgTokenStack[pWriter->cTokens - 1] = token; | 565 | pWriter->rgTokenStack[pWriter->cTokens - 1] = token; |
@@ -563,7 +578,7 @@ static HRESULT EnsureTokenStack( | |||
563 | DWORD cNumAlloc = pWriter->cTokens != 0 ? pWriter->cTokens : 0; | 578 | DWORD cNumAlloc = pWriter->cTokens != 0 ? pWriter->cTokens : 0; |
564 | 579 | ||
565 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pWriter->rgTokenStack), cNumAlloc, sizeof(JSON_TOKEN), JSON_STACK_INCREMENT); | 580 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pWriter->rgTokenStack), cNumAlloc, sizeof(JSON_TOKEN), JSON_STACK_INCREMENT); |
566 | ExitOnFailure(hr, "Failed to allocate JSON token stack."); | 581 | JsonExitOnFailure(hr, "Failed to allocate JSON token stack."); |
567 | 582 | ||
568 | if (0 == pWriter->cTokens) | 583 | if (0 == pWriter->cTokens) |
569 | { | 584 | { |
@@ -596,7 +611,7 @@ static HRESULT SerializeJsonString( | |||
596 | } | 611 | } |
597 | 612 | ||
598 | hr = StrAlloc(psczJsonString, cchRequired); | 613 | hr = StrAlloc(psczJsonString, cchRequired); |
599 | ExitOnFailure(hr, "Failed to allocate space for JSON string."); | 614 | JsonExitOnFailure(hr, "Failed to allocate space for JSON string."); |
600 | 615 | ||
601 | LPWSTR pchTarget = *psczJsonString; | 616 | LPWSTR pchTarget = *psczJsonString; |
602 | 617 | ||
diff --git a/src/dutil/locutil.cpp b/src/dutil/locutil.cpp index b3cc042c..c4567c03 100644 --- a/src/dutil/locutil.cpp +++ b/src/dutil/locutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define LocExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__) | ||
8 | #define LocExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__) | ||
9 | #define LocExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__) | ||
10 | #define LocExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__) | ||
11 | #define LocExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__) | ||
12 | #define LocExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__) | ||
13 | #define LocExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_LOCUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define LocExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_LOCUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define LocExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_LOCUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define LocExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_LOCUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define LocExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_LOCUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define LocExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_LOCUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | // prototypes | 20 | // prototypes |
6 | static HRESULT ParseWxl( | 21 | static HRESULT ParseWxl( |
7 | __in IXMLDOMDocument* pixd, | 22 | __in IXMLDOMDocument* pixd, |
@@ -63,10 +78,10 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
63 | if (wzLanguage && *wzLanguage) | 78 | if (wzLanguage && *wzLanguage) |
64 | { | 79 | { |
65 | hr = PathConcat(wzBasePath, wzLanguage, &sczProbePath); | 80 | hr = PathConcat(wzBasePath, wzLanguage, &sczProbePath); |
66 | ExitOnFailure(hr, "Failed to concat base path to language."); | 81 | LocExitOnFailure(hr, "Failed to concat base path to language."); |
67 | 82 | ||
68 | hr = PathConcat(sczProbePath, wzLocFileName, &sczProbePath); | 83 | hr = PathConcat(sczProbePath, wzLocFileName, &sczProbePath); |
69 | ExitOnFailure(hr, "Failed to concat loc file name to probe path."); | 84 | LocExitOnFailure(hr, "Failed to concat loc file name to probe path."); |
70 | 85 | ||
71 | if (FileExistsEx(sczProbePath, NULL)) | 86 | if (FileExistsEx(sczProbePath, NULL)) |
72 | { | 87 | { |
@@ -81,16 +96,16 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
81 | DWORD dwFlags = MUI_LANGUAGE_ID | MUI_MERGE_USER_FALLBACK | MUI_MERGE_SYSTEM_FALLBACK; | 96 | DWORD dwFlags = MUI_LANGUAGE_ID | MUI_MERGE_USER_FALLBACK | MUI_MERGE_SYSTEM_FALLBACK; |
82 | if (!(*pvfnGetThreadPreferredUILanguages)(dwFlags, &nLangs, NULL, &cchLangs)) | 97 | if (!(*pvfnGetThreadPreferredUILanguages)(dwFlags, &nLangs, NULL, &cchLangs)) |
83 | { | 98 | { |
84 | ExitWithLastError(hr, "GetThreadPreferredUILanguages failed to return buffer size."); | 99 | LocExitWithLastError(hr, "GetThreadPreferredUILanguages failed to return buffer size."); |
85 | } | 100 | } |
86 | 101 | ||
87 | hr = StrAlloc(&sczLangsBuff, cchLangs); | 102 | hr = StrAlloc(&sczLangsBuff, cchLangs); |
88 | ExitOnFailure(hr, "Failed to allocate buffer for languages"); | 103 | LocExitOnFailure(hr, "Failed to allocate buffer for languages"); |
89 | 104 | ||
90 | nLangs = 0; | 105 | nLangs = 0; |
91 | if (!(*pvfnGetThreadPreferredUILanguages)(dwFlags, &nLangs, sczLangsBuff, &cchLangs)) | 106 | if (!(*pvfnGetThreadPreferredUILanguages)(dwFlags, &nLangs, sczLangsBuff, &cchLangs)) |
92 | { | 107 | { |
93 | ExitWithLastError(hr, "GetThreadPreferredUILanguages failed to return language list."); | 108 | LocExitWithLastError(hr, "GetThreadPreferredUILanguages failed to return language list."); |
94 | } | 109 | } |
95 | 110 | ||
96 | LPWSTR szLangs = sczLangsBuff; | 111 | LPWSTR szLangs = sczLangsBuff; |
@@ -98,14 +113,14 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
98 | { | 113 | { |
99 | // StrHexDecode assumes low byte is first. We'll need to swap the bytes once we parse out the value. | 114 | // StrHexDecode assumes low byte is first. We'll need to swap the bytes once we parse out the value. |
100 | hr = StrHexDecode(szLangs, reinterpret_cast<BYTE*>(&langid), sizeof(langid)); | 115 | hr = StrHexDecode(szLangs, reinterpret_cast<BYTE*>(&langid), sizeof(langid)); |
101 | ExitOnFailure(hr, "Failed to parse langId."); | 116 | LocExitOnFailure(hr, "Failed to parse langId."); |
102 | 117 | ||
103 | langid = MAKEWORD(HIBYTE(langid), LOBYTE(langid)); | 118 | langid = MAKEWORD(HIBYTE(langid), LOBYTE(langid)); |
104 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); | 119 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); |
105 | ExitOnFailure(hr, "Failed to format user preferred langid."); | 120 | LocExitOnFailure(hr, "Failed to format user preferred langid."); |
106 | 121 | ||
107 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); | 122 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); |
108 | ExitOnFailure(hr, "Failed to concat user preferred langid file name to base path."); | 123 | LocExitOnFailure(hr, "Failed to concat user preferred langid file name to base path."); |
109 | 124 | ||
110 | if (FileExistsEx(sczProbePath, NULL)) | 125 | if (FileExistsEx(sczProbePath, NULL)) |
111 | { | 126 | { |
@@ -117,10 +132,10 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
117 | langid = ::GetUserDefaultUILanguage(); | 132 | langid = ::GetUserDefaultUILanguage(); |
118 | 133 | ||
119 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); | 134 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); |
120 | ExitOnFailure(hr, "Failed to format user langid."); | 135 | LocExitOnFailure(hr, "Failed to format user langid."); |
121 | 136 | ||
122 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); | 137 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); |
123 | ExitOnFailure(hr, "Failed to concat user langid file name to base path."); | 138 | LocExitOnFailure(hr, "Failed to concat user langid file name to base path."); |
124 | 139 | ||
125 | if (FileExistsEx(sczProbePath, NULL)) | 140 | if (FileExistsEx(sczProbePath, NULL)) |
126 | { | 141 | { |
@@ -132,10 +147,10 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
132 | langid = MAKELANGID(langid & 0x3FF, SUBLANG_DEFAULT); | 147 | langid = MAKELANGID(langid & 0x3FF, SUBLANG_DEFAULT); |
133 | 148 | ||
134 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); | 149 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); |
135 | ExitOnFailure(hr, "Failed to format user langid (default sublang)."); | 150 | LocExitOnFailure(hr, "Failed to format user langid (default sublang)."); |
136 | 151 | ||
137 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); | 152 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); |
138 | ExitOnFailure(hr, "Failed to concat user langid file name to base path (default sublang)."); | 153 | LocExitOnFailure(hr, "Failed to concat user langid file name to base path (default sublang)."); |
139 | 154 | ||
140 | if (FileExistsEx(sczProbePath, NULL)) | 155 | if (FileExistsEx(sczProbePath, NULL)) |
141 | { | 156 | { |
@@ -146,10 +161,10 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
146 | langid = ::GetSystemDefaultUILanguage(); | 161 | langid = ::GetSystemDefaultUILanguage(); |
147 | 162 | ||
148 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); | 163 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); |
149 | ExitOnFailure(hr, "Failed to format system langid."); | 164 | LocExitOnFailure(hr, "Failed to format system langid."); |
150 | 165 | ||
151 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); | 166 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); |
152 | ExitOnFailure(hr, "Failed to concat system langid file name to base path."); | 167 | LocExitOnFailure(hr, "Failed to concat system langid file name to base path."); |
153 | 168 | ||
154 | if (FileExistsEx(sczProbePath, NULL)) | 169 | if (FileExistsEx(sczProbePath, NULL)) |
155 | { | 170 | { |
@@ -161,10 +176,10 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
161 | langid = MAKELANGID(langid & 0x3FF, SUBLANG_DEFAULT); | 176 | langid = MAKELANGID(langid & 0x3FF, SUBLANG_DEFAULT); |
162 | 177 | ||
163 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); | 178 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); |
164 | ExitOnFailure(hr, "Failed to format user langid (default sublang)."); | 179 | LocExitOnFailure(hr, "Failed to format user langid (default sublang)."); |
165 | 180 | ||
166 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); | 181 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); |
167 | ExitOnFailure(hr, "Failed to concat user langid file name to base path (default sublang)."); | 182 | LocExitOnFailure(hr, "Failed to concat user langid file name to base path (default sublang)."); |
168 | 183 | ||
169 | if (FileExistsEx(sczProbePath, NULL)) | 184 | if (FileExistsEx(sczProbePath, NULL)) |
170 | { | 185 | { |
@@ -174,7 +189,7 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
174 | 189 | ||
175 | // Finally, look for the loc file in the base path. | 190 | // Finally, look for the loc file in the base path. |
176 | hr = PathConcat(wzBasePath, wzLocFileName, &sczProbePath); | 191 | hr = PathConcat(wzBasePath, wzLocFileName, &sczProbePath); |
177 | ExitOnFailure(hr, "Failed to concat loc file name to base path."); | 192 | LocExitOnFailure(hr, "Failed to concat loc file name to base path."); |
178 | 193 | ||
179 | if (!FileExistsEx(sczProbePath, NULL)) | 194 | if (!FileExistsEx(sczProbePath, NULL)) |
180 | { | 195 | { |
@@ -203,10 +218,10 @@ extern "C" HRESULT DAPI LocLoadFromFile( | |||
203 | IXMLDOMDocument* pixd = NULL; | 218 | IXMLDOMDocument* pixd = NULL; |
204 | 219 | ||
205 | hr = XmlLoadDocumentFromFile(wzWxlFile, &pixd); | 220 | hr = XmlLoadDocumentFromFile(wzWxlFile, &pixd); |
206 | ExitOnFailure(hr, "Failed to load WXL file as XML document."); | 221 | LocExitOnFailure(hr, "Failed to load WXL file as XML document."); |
207 | 222 | ||
208 | hr = ParseWxl(pixd, ppWixLoc); | 223 | hr = ParseWxl(pixd, ppWixLoc); |
209 | ExitOnFailure(hr, "Failed to parse WXL."); | 224 | LocExitOnFailure(hr, "Failed to parse WXL."); |
210 | 225 | ||
211 | LExit: | 226 | LExit: |
212 | ReleaseObject(pixd); | 227 | ReleaseObject(pixd); |
@@ -227,16 +242,16 @@ extern "C" HRESULT DAPI LocLoadFromResource( | |||
227 | IXMLDOMDocument* pixd = NULL; | 242 | IXMLDOMDocument* pixd = NULL; |
228 | 243 | ||
229 | hr = ResReadData(hModule, szResource, &pvResource, &cbResource); | 244 | hr = ResReadData(hModule, szResource, &pvResource, &cbResource); |
230 | ExitOnFailure(hr, "Failed to read theme from resource."); | 245 | LocExitOnFailure(hr, "Failed to read theme from resource."); |
231 | 246 | ||
232 | hr = StrAllocStringAnsi(&sczXml, reinterpret_cast<LPCSTR>(pvResource), cbResource, CP_UTF8); | 247 | hr = StrAllocStringAnsi(&sczXml, reinterpret_cast<LPCSTR>(pvResource), cbResource, CP_UTF8); |
233 | ExitOnFailure(hr, "Failed to convert XML document data from UTF-8 to unicode string."); | 248 | LocExitOnFailure(hr, "Failed to convert XML document data from UTF-8 to unicode string."); |
234 | 249 | ||
235 | hr = XmlLoadDocument(sczXml, &pixd); | 250 | hr = XmlLoadDocument(sczXml, &pixd); |
236 | ExitOnFailure(hr, "Failed to load theme resource as XML document."); | 251 | LocExitOnFailure(hr, "Failed to load theme resource as XML document."); |
237 | 252 | ||
238 | hr = ParseWxl(pixd, ppWixLoc); | 253 | hr = ParseWxl(pixd, ppWixLoc); |
239 | ExitOnFailure(hr, "Failed to parse WXL."); | 254 | LocExitOnFailure(hr, "Failed to parse WXL."); |
240 | 255 | ||
241 | LExit: | 256 | LExit: |
242 | ReleaseObject(pixd); | 257 | ReleaseObject(pixd); |
@@ -280,7 +295,7 @@ extern "C" HRESULT DAPI LocLocalizeString( | |||
280 | for (DWORD i = 0; i < pWixLoc->cLocStrings; ++i) | 295 | for (DWORD i = 0; i < pWixLoc->cLocStrings; ++i) |
281 | { | 296 | { |
282 | hr = StrReplaceStringAll(ppsczInput, pWixLoc->rgLocStrings[i].wzId, pWixLoc->rgLocStrings[i].wzText); | 297 | hr = StrReplaceStringAll(ppsczInput, pWixLoc->rgLocStrings[i].wzId, pWixLoc->rgLocStrings[i].wzText); |
283 | ExitOnFailure(hr, "Localizing string failed."); | 298 | LocExitOnFailure(hr, "Localizing string failed."); |
284 | } | 299 | } |
285 | 300 | ||
286 | LExit: | 301 | LExit: |
@@ -348,15 +363,15 @@ extern "C" HRESULT DAPI LocAddString( | |||
348 | 363 | ||
349 | ++pWixLoc->cLocStrings; | 364 | ++pWixLoc->cLocStrings; |
350 | pWixLoc->rgLocStrings = static_cast<LOC_STRING*>(MemReAlloc(pWixLoc->rgLocStrings, sizeof(LOC_STRING) * pWixLoc->cLocStrings, TRUE)); | 365 | pWixLoc->rgLocStrings = static_cast<LOC_STRING*>(MemReAlloc(pWixLoc->rgLocStrings, sizeof(LOC_STRING) * pWixLoc->cLocStrings, TRUE)); |
351 | ExitOnNull(pWixLoc->rgLocStrings, hr, E_OUTOFMEMORY, "Failed to reallocate memory for localization strings."); | 366 | LocExitOnNull(pWixLoc->rgLocStrings, hr, E_OUTOFMEMORY, "Failed to reallocate memory for localization strings."); |
352 | 367 | ||
353 | LOC_STRING* pLocString = pWixLoc->rgLocStrings + (pWixLoc->cLocStrings - 1); | 368 | LOC_STRING* pLocString = pWixLoc->rgLocStrings + (pWixLoc->cLocStrings - 1); |
354 | 369 | ||
355 | hr = StrAllocFormatted(&pLocString->wzId, L"#(loc.%s)", wzId); | 370 | hr = StrAllocFormatted(&pLocString->wzId, L"#(loc.%s)", wzId); |
356 | ExitOnFailure(hr, "Failed to set localization string Id."); | 371 | LocExitOnFailure(hr, "Failed to set localization string Id."); |
357 | 372 | ||
358 | hr = StrAllocString(&pLocString->wzText, wzLocString, 0); | 373 | hr = StrAllocString(&pLocString->wzText, wzLocString, 0); |
359 | ExitOnFailure(hr, "Failed to set localization string Text."); | 374 | LocExitOnFailure(hr, "Failed to set localization string Text."); |
360 | 375 | ||
361 | pLocString->bOverridable = bOverridable; | 376 | pLocString->bOverridable = bOverridable; |
362 | 377 | ||
@@ -376,11 +391,11 @@ static HRESULT ParseWxl( | |||
376 | WIX_LOCALIZATION* pWixLoc = NULL; | 391 | WIX_LOCALIZATION* pWixLoc = NULL; |
377 | 392 | ||
378 | pWixLoc = static_cast<WIX_LOCALIZATION*>(MemAlloc(sizeof(WIX_LOCALIZATION), TRUE)); | 393 | pWixLoc = static_cast<WIX_LOCALIZATION*>(MemAlloc(sizeof(WIX_LOCALIZATION), TRUE)); |
379 | ExitOnNull(pWixLoc, hr, E_OUTOFMEMORY, "Failed to allocate memory for Wxl file."); | 394 | LocExitOnNull(pWixLoc, hr, E_OUTOFMEMORY, "Failed to allocate memory for Wxl file."); |
380 | 395 | ||
381 | // read the WixLocalization tag | 396 | // read the WixLocalization tag |
382 | hr = pixd->get_documentElement(&pWxlElement); | 397 | hr = pixd->get_documentElement(&pWxlElement); |
383 | ExitOnFailure(hr, "Failed to get localization element."); | 398 | LocExitOnFailure(hr, "Failed to get localization element."); |
384 | 399 | ||
385 | // get the Language attribute if present | 400 | // get the Language attribute if present |
386 | pWixLoc->dwLangId = WIX_LOCALIZATION_LANGUAGE_NOT_SET; | 401 | pWixLoc->dwLangId = WIX_LOCALIZATION_LANGUAGE_NOT_SET; |
@@ -389,14 +404,14 @@ static HRESULT ParseWxl( | |||
389 | { | 404 | { |
390 | hr = S_OK; | 405 | hr = S_OK; |
391 | } | 406 | } |
392 | ExitOnFailure(hr, "Failed to get Language value."); | 407 | LocExitOnFailure(hr, "Failed to get Language value."); |
393 | 408 | ||
394 | // store the strings and controls in a node list | 409 | // store the strings and controls in a node list |
395 | hr = ParseWxlStrings(pWxlElement, pWixLoc); | 410 | hr = ParseWxlStrings(pWxlElement, pWixLoc); |
396 | ExitOnFailure(hr, "Parsing localization strings failed."); | 411 | LocExitOnFailure(hr, "Parsing localization strings failed."); |
397 | 412 | ||
398 | hr = ParseWxlControls(pWxlElement, pWixLoc); | 413 | hr = ParseWxlControls(pWxlElement, pWixLoc); |
399 | ExitOnFailure(hr, "Parsing localization controls failed."); | 414 | LocExitOnFailure(hr, "Parsing localization controls failed."); |
400 | 415 | ||
401 | *ppWixLoc = pWixLoc; | 416 | *ppWixLoc = pWixLoc; |
402 | pWixLoc = NULL; | 417 | pWixLoc = NULL; |
@@ -420,27 +435,27 @@ static HRESULT ParseWxlStrings( | |||
420 | DWORD dwIdx = 0; | 435 | DWORD dwIdx = 0; |
421 | 436 | ||
422 | hr = XmlSelectNodes(pElement, L"String", &pixnl); | 437 | hr = XmlSelectNodes(pElement, L"String", &pixnl); |
423 | ExitOnLastError(hr, "Failed to get String child nodes of Wxl File."); | 438 | LocExitOnLastError(hr, "Failed to get String child nodes of Wxl File."); |
424 | 439 | ||
425 | hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocStrings)); | 440 | hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocStrings)); |
426 | ExitOnLastError(hr, "Failed to get number of String child nodes in Wxl File."); | 441 | LocExitOnLastError(hr, "Failed to get number of String child nodes in Wxl File."); |
427 | 442 | ||
428 | if (0 < pWixLoc->cLocStrings) | 443 | if (0 < pWixLoc->cLocStrings) |
429 | { | 444 | { |
430 | pWixLoc->rgLocStrings = static_cast<LOC_STRING*>(MemAlloc(sizeof(LOC_STRING) * pWixLoc->cLocStrings, TRUE)); | 445 | pWixLoc->rgLocStrings = static_cast<LOC_STRING*>(MemAlloc(sizeof(LOC_STRING) * pWixLoc->cLocStrings, TRUE)); |
431 | ExitOnNull(pWixLoc->rgLocStrings, hr, E_OUTOFMEMORY, "Failed to allocate memory for localization strings."); | 446 | LocExitOnNull(pWixLoc->rgLocStrings, hr, E_OUTOFMEMORY, "Failed to allocate memory for localization strings."); |
432 | 447 | ||
433 | while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL))) | 448 | while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL))) |
434 | { | 449 | { |
435 | hr = ParseWxlString(pixn, dwIdx, pWixLoc); | 450 | hr = ParseWxlString(pixn, dwIdx, pWixLoc); |
436 | ExitOnFailure(hr, "Failed to parse localization string."); | 451 | LocExitOnFailure(hr, "Failed to parse localization string."); |
437 | 452 | ||
438 | ++dwIdx; | 453 | ++dwIdx; |
439 | ReleaseNullObject(pixn); | 454 | ReleaseNullObject(pixn); |
440 | } | 455 | } |
441 | 456 | ||
442 | hr = S_OK; | 457 | hr = S_OK; |
443 | ExitOnFailure(hr, "Failed to enumerate all localization strings."); | 458 | LocExitOnFailure(hr, "Failed to enumerate all localization strings."); |
444 | } | 459 | } |
445 | 460 | ||
446 | LExit: | 461 | LExit: |
@@ -472,27 +487,27 @@ static HRESULT ParseWxlControls( | |||
472 | DWORD dwIdx = 0; | 487 | DWORD dwIdx = 0; |
473 | 488 | ||
474 | hr = XmlSelectNodes(pElement, L"UI|Control", &pixnl); | 489 | hr = XmlSelectNodes(pElement, L"UI|Control", &pixnl); |
475 | ExitOnLastError(hr, "Failed to get UI child nodes of Wxl File."); | 490 | LocExitOnLastError(hr, "Failed to get UI child nodes of Wxl File."); |
476 | 491 | ||
477 | hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocControls)); | 492 | hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocControls)); |
478 | ExitOnLastError(hr, "Failed to get number of UI child nodes in Wxl File."); | 493 | LocExitOnLastError(hr, "Failed to get number of UI child nodes in Wxl File."); |
479 | 494 | ||
480 | if (0 < pWixLoc->cLocControls) | 495 | if (0 < pWixLoc->cLocControls) |
481 | { | 496 | { |
482 | pWixLoc->rgLocControls = static_cast<LOC_CONTROL*>(MemAlloc(sizeof(LOC_CONTROL) * pWixLoc->cLocControls, TRUE)); | 497 | pWixLoc->rgLocControls = static_cast<LOC_CONTROL*>(MemAlloc(sizeof(LOC_CONTROL) * pWixLoc->cLocControls, TRUE)); |
483 | ExitOnNull(pWixLoc->rgLocControls, hr, E_OUTOFMEMORY, "Failed to allocate memory for localized controls."); | 498 | LocExitOnNull(pWixLoc->rgLocControls, hr, E_OUTOFMEMORY, "Failed to allocate memory for localized controls."); |
484 | 499 | ||
485 | while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL))) | 500 | while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL))) |
486 | { | 501 | { |
487 | hr = ParseWxlControl(pixn, dwIdx, pWixLoc); | 502 | hr = ParseWxlControl(pixn, dwIdx, pWixLoc); |
488 | ExitOnFailure(hr, "Failed to parse localized control."); | 503 | LocExitOnFailure(hr, "Failed to parse localized control."); |
489 | 504 | ||
490 | ++dwIdx; | 505 | ++dwIdx; |
491 | ReleaseNullObject(pixn); | 506 | ReleaseNullObject(pixn); |
492 | } | 507 | } |
493 | 508 | ||
494 | hr = S_OK; | 509 | hr = S_OK; |
495 | ExitOnFailure(hr, "Failed to enumerate all localized controls."); | 510 | LocExitOnFailure(hr, "Failed to enumerate all localized controls."); |
496 | } | 511 | } |
497 | 512 | ||
498 | LExit: | 513 | LExit: |
@@ -527,16 +542,16 @@ static HRESULT ParseWxlString( | |||
527 | 542 | ||
528 | // Id | 543 | // Id |
529 | hr = XmlGetAttribute(pixn, L"Id", &bstrText); | 544 | hr = XmlGetAttribute(pixn, L"Id", &bstrText); |
530 | ExitOnFailure(hr, "Failed to get Xml attribute Id in Wxl file."); | 545 | LocExitOnFailure(hr, "Failed to get Xml attribute Id in Wxl file."); |
531 | 546 | ||
532 | hr = StrAllocFormatted(&pLocString->wzId, L"#(loc.%s)", bstrText); | 547 | hr = StrAllocFormatted(&pLocString->wzId, L"#(loc.%s)", bstrText); |
533 | ExitOnFailure(hr, "Failed to duplicate Xml attribute Id in Wxl file."); | 548 | LocExitOnFailure(hr, "Failed to duplicate Xml attribute Id in Wxl file."); |
534 | 549 | ||
535 | ReleaseNullBSTR(bstrText); | 550 | ReleaseNullBSTR(bstrText); |
536 | 551 | ||
537 | // Overrideable | 552 | // Overrideable |
538 | hr = XmlGetAttribute(pixn, L"Overridable", &bstrText); | 553 | hr = XmlGetAttribute(pixn, L"Overridable", &bstrText); |
539 | ExitOnFailure(hr, "Failed to get Xml attribute Overridable."); | 554 | LocExitOnFailure(hr, "Failed to get Xml attribute Overridable."); |
540 | 555 | ||
541 | if (S_OK == hr) | 556 | if (S_OK == hr) |
542 | { | 557 | { |
@@ -547,10 +562,10 @@ static HRESULT ParseWxlString( | |||
547 | 562 | ||
548 | // Text | 563 | // Text |
549 | hr = XmlGetText(pixn, &bstrText); | 564 | hr = XmlGetText(pixn, &bstrText); |
550 | ExitOnFailure(hr, "Failed to get Xml text in Wxl file."); | 565 | LocExitOnFailure(hr, "Failed to get Xml text in Wxl file."); |
551 | 566 | ||
552 | hr = StrAllocString(&pLocString->wzText, bstrText, 0); | 567 | hr = StrAllocString(&pLocString->wzText, bstrText, 0); |
553 | ExitOnFailure(hr, "Failed to duplicate Xml text in Wxl file."); | 568 | LocExitOnFailure(hr, "Failed to duplicate Xml text in Wxl file."); |
554 | 569 | ||
555 | LExit: | 570 | LExit: |
556 | ReleaseBSTR(bstrText); | 571 | ReleaseBSTR(bstrText); |
@@ -572,39 +587,39 @@ static HRESULT ParseWxlControl( | |||
572 | 587 | ||
573 | // Id | 588 | // Id |
574 | hr = XmlGetAttribute(pixn, L"Control", &bstrText); | 589 | hr = XmlGetAttribute(pixn, L"Control", &bstrText); |
575 | ExitOnFailure(hr, "Failed to get Xml attribute Control in Wxl file."); | 590 | LocExitOnFailure(hr, "Failed to get Xml attribute Control in Wxl file."); |
576 | 591 | ||
577 | hr = StrAllocString(&pLocControl->wzControl, bstrText, 0); | 592 | hr = StrAllocString(&pLocControl->wzControl, bstrText, 0); |
578 | ExitOnFailure(hr, "Failed to duplicate Xml attribute Control in Wxl file."); | 593 | LocExitOnFailure(hr, "Failed to duplicate Xml attribute Control in Wxl file."); |
579 | 594 | ||
580 | ReleaseNullBSTR(bstrText); | 595 | ReleaseNullBSTR(bstrText); |
581 | 596 | ||
582 | // X | 597 | // X |
583 | pLocControl->nX = LOC_CONTROL_NOT_SET; | 598 | pLocControl->nX = LOC_CONTROL_NOT_SET; |
584 | hr = XmlGetAttributeNumber(pixn, L"X", reinterpret_cast<DWORD*>(&pLocControl->nX)); | 599 | hr = XmlGetAttributeNumber(pixn, L"X", reinterpret_cast<DWORD*>(&pLocControl->nX)); |
585 | ExitOnFailure(hr, "Failed to get control X attribute."); | 600 | LocExitOnFailure(hr, "Failed to get control X attribute."); |
586 | 601 | ||
587 | // Y | 602 | // Y |
588 | pLocControl->nY = LOC_CONTROL_NOT_SET; | 603 | pLocControl->nY = LOC_CONTROL_NOT_SET; |
589 | hr = XmlGetAttributeNumber(pixn, L"Y", reinterpret_cast<DWORD*>(&pLocControl->nY)); | 604 | hr = XmlGetAttributeNumber(pixn, L"Y", reinterpret_cast<DWORD*>(&pLocControl->nY)); |
590 | ExitOnFailure(hr, "Failed to get control Y attribute."); | 605 | LocExitOnFailure(hr, "Failed to get control Y attribute."); |
591 | 606 | ||
592 | // Width | 607 | // Width |
593 | pLocControl->nWidth = LOC_CONTROL_NOT_SET; | 608 | pLocControl->nWidth = LOC_CONTROL_NOT_SET; |
594 | hr = XmlGetAttributeNumber(pixn, L"Width", reinterpret_cast<DWORD*>(&pLocControl->nWidth)); | 609 | hr = XmlGetAttributeNumber(pixn, L"Width", reinterpret_cast<DWORD*>(&pLocControl->nWidth)); |
595 | ExitOnFailure(hr, "Failed to get control width attribute."); | 610 | LocExitOnFailure(hr, "Failed to get control width attribute."); |
596 | 611 | ||
597 | // Height | 612 | // Height |
598 | pLocControl->nHeight = LOC_CONTROL_NOT_SET; | 613 | pLocControl->nHeight = LOC_CONTROL_NOT_SET; |
599 | hr = XmlGetAttributeNumber(pixn, L"Height", reinterpret_cast<DWORD*>(&pLocControl->nHeight)); | 614 | hr = XmlGetAttributeNumber(pixn, L"Height", reinterpret_cast<DWORD*>(&pLocControl->nHeight)); |
600 | ExitOnFailure(hr, "Failed to get control height attribute."); | 615 | LocExitOnFailure(hr, "Failed to get control height attribute."); |
601 | 616 | ||
602 | // Text | 617 | // Text |
603 | hr = XmlGetText(pixn, &bstrText); | 618 | hr = XmlGetText(pixn, &bstrText); |
604 | ExitOnFailure(hr, "Failed to get control text in Wxl file."); | 619 | LocExitOnFailure(hr, "Failed to get control text in Wxl file."); |
605 | 620 | ||
606 | hr = StrAllocString(&pLocControl->wzText, bstrText, 0); | 621 | hr = StrAllocString(&pLocControl->wzText, bstrText, 0); |
607 | ExitOnFailure(hr, "Failed to duplicate control text in Wxl file."); | 622 | LocExitOnFailure(hr, "Failed to duplicate control text in Wxl file."); |
608 | 623 | ||
609 | LExit: | 624 | LExit: |
610 | ReleaseBSTR(bstrText); | 625 | ReleaseBSTR(bstrText); |
diff --git a/src/dutil/logutil.cpp b/src/dutil/logutil.cpp index 438cdbb8..35251274 100644 --- a/src/dutil/logutil.cpp +++ b/src/dutil/logutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define LoguExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_LOGUTIL, x, s, __VA_ARGS__) | ||
8 | #define LoguExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_LOGUTIL, x, s, __VA_ARGS__) | ||
9 | #define LoguExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_LOGUTIL, x, s, __VA_ARGS__) | ||
10 | #define LoguExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_LOGUTIL, x, s, __VA_ARGS__) | ||
11 | #define LoguExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_LOGUTIL, x, s, __VA_ARGS__) | ||
12 | #define LoguExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_LOGUTIL, x, s, __VA_ARGS__) | ||
13 | #define LoguExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_LOGUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define LoguExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_LOGUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define LoguExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_LOGUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define LoguExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_LOGUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define LoguExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_LOGUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define LoguExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_LOGUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | // globals | 20 | // globals |
6 | static HMODULE LogUtil_hModule = NULL; | 21 | static HMODULE LogUtil_hModule = NULL; |
7 | static BOOL LogUtil_fDisabled = FALSE; | 22 | static BOOL LogUtil_fDisabled = FALSE; |
@@ -110,23 +125,23 @@ extern "C" HRESULT DAPI LogOpen( | |||
110 | if (wzExt && *wzExt) | 125 | if (wzExt && *wzExt) |
111 | { | 126 | { |
112 | hr = PathCreateTimeBasedTempFile(wzDirectory, wzLog, wzPostfix, wzExt, &LogUtil_sczLogPath, &LogUtil_hLog); | 127 | hr = PathCreateTimeBasedTempFile(wzDirectory, wzLog, wzPostfix, wzExt, &LogUtil_sczLogPath, &LogUtil_hLog); |
113 | ExitOnFailure(hr, "Failed to create log based on current system time."); | 128 | LoguExitOnFailure(hr, "Failed to create log based on current system time."); |
114 | } | 129 | } |
115 | else | 130 | else |
116 | { | 131 | { |
117 | hr = PathConcat(wzDirectory, wzLog, &LogUtil_sczLogPath); | 132 | hr = PathConcat(wzDirectory, wzLog, &LogUtil_sczLogPath); |
118 | ExitOnFailure(hr, "Failed to combine the log path."); | 133 | LoguExitOnFailure(hr, "Failed to combine the log path."); |
119 | 134 | ||
120 | hr = PathGetDirectory(LogUtil_sczLogPath, &sczLogDirectory); | 135 | hr = PathGetDirectory(LogUtil_sczLogPath, &sczLogDirectory); |
121 | ExitOnFailure(hr, "Failed to get log directory."); | 136 | LoguExitOnFailure(hr, "Failed to get log directory."); |
122 | 137 | ||
123 | hr = DirEnsureExists(sczLogDirectory, NULL); | 138 | hr = DirEnsureExists(sczLogDirectory, NULL); |
124 | ExitOnFailure(hr, "Failed to ensure log file directory exists: %ls", sczLogDirectory); | 139 | LoguExitOnFailure(hr, "Failed to ensure log file directory exists: %ls", sczLogDirectory); |
125 | 140 | ||
126 | LogUtil_hLog = ::CreateFileW(LogUtil_sczLogPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, (fAppend) ? OPEN_ALWAYS : CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | 141 | LogUtil_hLog = ::CreateFileW(LogUtil_sczLogPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, (fAppend) ? OPEN_ALWAYS : CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
127 | if (INVALID_HANDLE_VALUE == LogUtil_hLog) | 142 | if (INVALID_HANDLE_VALUE == LogUtil_hLog) |
128 | { | 143 | { |
129 | ExitOnLastError(hr, "failed to create log file: %ls", LogUtil_sczLogPath); | 144 | LoguExitOnLastError(hr, "failed to create log file: %ls", LogUtil_sczLogPath); |
130 | } | 145 | } |
131 | 146 | ||
132 | if (fAppend) | 147 | if (fAppend) |
@@ -152,7 +167,7 @@ extern "C" HRESULT DAPI LogOpen( | |||
152 | if (psczLogPath) | 167 | if (psczLogPath) |
153 | { | 168 | { |
154 | hr = StrAllocString(psczLogPath, LogUtil_sczLogPath, 0); | 169 | hr = StrAllocString(psczLogPath, LogUtil_sczLogPath, 0); |
155 | ExitOnFailure(hr, "Failed to copy log path."); | 170 | LoguExitOnFailure(hr, "Failed to copy log path."); |
156 | } | 171 | } |
157 | 172 | ||
158 | LExit: | 173 | LExit: |
@@ -217,15 +232,15 @@ HRESULT DAPI LogRename( | |||
217 | ReleaseFileHandle(LogUtil_hLog); | 232 | ReleaseFileHandle(LogUtil_hLog); |
218 | 233 | ||
219 | hr = FileEnsureMove(LogUtil_sczLogPath, wzNewPath, TRUE, TRUE); | 234 | hr = FileEnsureMove(LogUtil_sczLogPath, wzNewPath, TRUE, TRUE); |
220 | ExitOnFailure(hr, "Failed to move logfile to new location: %ls", wzNewPath); | 235 | LoguExitOnFailure(hr, "Failed to move logfile to new location: %ls", wzNewPath); |
221 | 236 | ||
222 | hr = StrAllocString(&LogUtil_sczLogPath, wzNewPath, 0); | 237 | hr = StrAllocString(&LogUtil_sczLogPath, wzNewPath, 0); |
223 | ExitOnFailure(hr, "Failed to store new logfile path: %ls", wzNewPath); | 238 | LoguExitOnFailure(hr, "Failed to store new logfile path: %ls", wzNewPath); |
224 | 239 | ||
225 | LogUtil_hLog = ::CreateFileW(LogUtil_sczLogPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | 240 | LogUtil_hLog = ::CreateFileW(LogUtil_sczLogPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
226 | if (INVALID_HANDLE_VALUE == LogUtil_hLog) | 241 | if (INVALID_HANDLE_VALUE == LogUtil_hLog) |
227 | { | 242 | { |
228 | ExitOnLastError(hr, "failed to create log file: %ls", LogUtil_sczLogPath); | 243 | LoguExitOnLastError(hr, "failed to create log file: %ls", LogUtil_sczLogPath); |
229 | } | 244 | } |
230 | 245 | ||
231 | // Enable "append" mode by moving file pointer to the end | 246 | // Enable "append" mode by moving file pointer to the end |
@@ -307,7 +322,7 @@ HRESULT DAPI LogSetSpecialParams( | |||
307 | else | 322 | else |
308 | { | 323 | { |
309 | hr = StrAllocConcat(&LogUtil_sczSpecialBeginLine, wzSpecialBeginLine, 0); | 324 | hr = StrAllocConcat(&LogUtil_sczSpecialBeginLine, wzSpecialBeginLine, 0); |
310 | ExitOnFailure(hr, "Failed to allocate copy of special beginline string"); | 325 | LoguExitOnFailure(hr, "Failed to allocate copy of special beginline string"); |
311 | } | 326 | } |
312 | 327 | ||
313 | // Handle special string to be appended to every time stamp | 328 | // Handle special string to be appended to every time stamp |
@@ -318,7 +333,7 @@ HRESULT DAPI LogSetSpecialParams( | |||
318 | else | 333 | else |
319 | { | 334 | { |
320 | hr = StrAllocConcat(&LogUtil_sczSpecialAfterTimeStamp, wzSpecialAfterTimeStamp, 0); | 335 | hr = StrAllocConcat(&LogUtil_sczSpecialAfterTimeStamp, wzSpecialAfterTimeStamp, 0); |
321 | ExitOnFailure(hr, "Failed to allocate copy of special post-timestamp string"); | 336 | LoguExitOnFailure(hr, "Failed to allocate copy of special post-timestamp string"); |
322 | } | 337 | } |
323 | 338 | ||
324 | // Handle special string to be appended before every full line | 339 | // Handle special string to be appended before every full line |
@@ -329,7 +344,7 @@ HRESULT DAPI LogSetSpecialParams( | |||
329 | else | 344 | else |
330 | { | 345 | { |
331 | hr = StrAllocConcat(&LogUtil_sczSpecialEndLine, wzSpecialEndLine, 0); | 346 | hr = StrAllocConcat(&LogUtil_sczSpecialEndLine, wzSpecialEndLine, 0); |
332 | ExitOnFailure(hr, "Failed to allocate copy of special endline string"); | 347 | LoguExitOnFailure(hr, "Failed to allocate copy of special endline string"); |
333 | } | 348 | } |
334 | 349 | ||
335 | LExit: | 350 | LExit: |
@@ -597,14 +612,14 @@ extern "C" HRESULT DAPI LogErrorStringArgs( | |||
597 | LPWSTR sczMessage = NULL; | 612 | LPWSTR sczMessage = NULL; |
598 | 613 | ||
599 | hr = StrAllocStringAnsi(&sczFormat, szFormat, 0, CP_ACP); | 614 | hr = StrAllocStringAnsi(&sczFormat, szFormat, 0, CP_ACP); |
600 | ExitOnFailure(hr, "Failed to convert format string to wide character string"); | 615 | LoguExitOnFailure(hr, "Failed to convert format string to wide character string"); |
601 | 616 | ||
602 | // format the string as a unicode string - this is necessary to be able to include | 617 | // format the string as a unicode string - this is necessary to be able to include |
603 | // international characters in our output string. This does have the counterintuitive effect | 618 | // international characters in our output string. This does have the counterintuitive effect |
604 | // that the caller's "%s" is interpreted differently | 619 | // that the caller's "%s" is interpreted differently |
605 | // (so callers should use %hs for LPSTR and %ls for LPWSTR) | 620 | // (so callers should use %hs for LPSTR and %ls for LPWSTR) |
606 | hr = StrAllocFormattedArgs(&sczMessage, sczFormat, args); | 621 | hr = StrAllocFormattedArgs(&sczMessage, sczFormat, args); |
607 | ExitOnFailure(hr, "Failed to format error message: \"%ls\"", sczFormat); | 622 | LoguExitOnFailure(hr, "Failed to format error message: \"%ls\"", sczFormat); |
608 | 623 | ||
609 | hr = LogStringLine(REPORT_ERROR, "Error 0x%x: %ls", hrError, sczMessage); | 624 | hr = LogStringLine(REPORT_ERROR, "Error 0x%x: %ls", hrError, sczMessage); |
610 | 625 | ||
@@ -636,14 +651,14 @@ extern "C" HRESULT DAPI LogErrorIdModule( | |||
636 | WORD cStrings = 1; // guaranteed wzError is in the list | 651 | WORD cStrings = 1; // guaranteed wzError is in the list |
637 | 652 | ||
638 | hr = ::StringCchPrintfW(wzError, countof(wzError), L"0x%08x", hrError); | 653 | hr = ::StringCchPrintfW(wzError, countof(wzError), L"0x%08x", hrError); |
639 | ExitOnFailure(hr, "failed to format error code: \"0%08x\"", hrError); | 654 | LoguExitOnFailure(hr, "failed to format error code: \"0%08x\"", hrError); |
640 | 655 | ||
641 | cStrings += wzString1 ? 1 : 0; | 656 | cStrings += wzString1 ? 1 : 0; |
642 | cStrings += wzString2 ? 1 : 0; | 657 | cStrings += wzString2 ? 1 : 0; |
643 | cStrings += wzString3 ? 1 : 0; | 658 | cStrings += wzString3 ? 1 : 0; |
644 | 659 | ||
645 | hr = LogIdModule(REPORT_ERROR, dwLogId, hModule, wzError, wzString1, wzString2, wzString3); | 660 | hr = LogIdModule(REPORT_ERROR, dwLogId, hModule, wzError, wzString1, wzString2, wzString3); |
646 | ExitOnFailure(hr, "Failed to log id module."); | 661 | LoguExitOnFailure(hr, "Failed to log id module."); |
647 | 662 | ||
648 | LExit: | 663 | LExit: |
649 | return hr; | 664 | return hr; |
@@ -771,7 +786,7 @@ extern "C" HRESULT LogStringWorkRaw( | |||
771 | if (INVALID_HANDLE_VALUE == LogUtil_hLog) | 786 | if (INVALID_HANDLE_VALUE == LogUtil_hLog) |
772 | { | 787 | { |
773 | hr = StrAnsiAllocConcat(&LogUtil_sczPreInitBuffer, szLogData, 0); | 788 | hr = StrAnsiAllocConcat(&LogUtil_sczPreInitBuffer, szLogData, 0); |
774 | ExitOnFailure(hr, "Failed to concatenate string to pre-init buffer"); | 789 | LoguExitOnFailure(hr, "Failed to concatenate string to pre-init buffer"); |
775 | 790 | ||
776 | ExitFunction1(hr = S_OK); | 791 | ExitFunction1(hr = S_OK); |
777 | } | 792 | } |
@@ -781,7 +796,7 @@ extern "C" HRESULT LogStringWorkRaw( | |||
781 | { | 796 | { |
782 | if (!::WriteFile(LogUtil_hLog, reinterpret_cast<const BYTE*>(szLogData) + cbTotal, cbLogData - cbTotal, &cbWrote, NULL)) | 797 | if (!::WriteFile(LogUtil_hLog, reinterpret_cast<const BYTE*>(szLogData) + cbTotal, cbLogData - cbTotal, &cbWrote, NULL)) |
783 | { | 798 | { |
784 | ExitOnLastError(hr, "Failed to write output to log: %ls - %ls", LogUtil_sczLogPath, szLogData); | 799 | LoguExitOnLastError(hr, "Failed to write output to log: %ls - %hs", LogUtil_sczLogPath, szLogData); |
785 | } | 800 | } |
786 | 801 | ||
787 | cbTotal += cbWrote; | 802 | cbTotal += cbWrote; |
@@ -816,7 +831,7 @@ static HRESULT LogIdWork( | |||
816 | 831 | ||
817 | if (0 == cch) | 832 | if (0 == cch) |
818 | { | 833 | { |
819 | ExitOnLastError(hr, "failed to log id: %d", dwLogId); | 834 | LoguExitOnLastError(hr, "failed to log id: %d", dwLogId); |
820 | } | 835 | } |
821 | 836 | ||
822 | if (2 <= cch && L'\r' == pwz[cch-2] && L'\n' == pwz[cch-1]) | 837 | if (2 <= cch && L'\r' == pwz[cch-2] && L'\n' == pwz[cch-1]) |
@@ -850,14 +865,14 @@ static HRESULT LogStringWorkArgs( | |||
850 | LPWSTR sczMessage = NULL; | 865 | LPWSTR sczMessage = NULL; |
851 | 866 | ||
852 | hr = StrAllocStringAnsi(&sczFormat, szFormat, 0, CP_ACP); | 867 | hr = StrAllocStringAnsi(&sczFormat, szFormat, 0, CP_ACP); |
853 | ExitOnFailure(hr, "Failed to convert format string to wide character string"); | 868 | LoguExitOnFailure(hr, "Failed to convert format string to wide character string"); |
854 | 869 | ||
855 | // format the string as a unicode string | 870 | // format the string as a unicode string |
856 | hr = StrAllocFormattedArgs(&sczMessage, sczFormat, args); | 871 | hr = StrAllocFormattedArgs(&sczMessage, sczFormat, args); |
857 | ExitOnFailure(hr, "Failed to format message: \"%ls\"", sczFormat); | 872 | LoguExitOnFailure(hr, "Failed to format message: \"%ls\"", sczFormat); |
858 | 873 | ||
859 | hr = LogStringWork(rl, 0, sczMessage, fLOGUTIL_NEWLINE); | 874 | hr = LogStringWork(rl, 0, sczMessage, fLOGUTIL_NEWLINE); |
860 | ExitOnFailure(hr, "Failed to write formatted string to log:%ls", sczMessage); | 875 | LoguExitOnFailure(hr, "Failed to write formatted string to log:%ls", sczMessage); |
861 | 876 | ||
862 | LExit: | 877 | LExit: |
863 | ReleaseStr(sczFormat); | 878 | ReleaseStr(sczFormat); |
@@ -909,24 +924,24 @@ static HRESULT LogStringWork( | |||
909 | hr = StrAllocFormatted(&scz, L"%ls[%04X:%04X][%04hu-%02hu-%02huT%02hu:%02hu:%02hu]%hs%03d:%ls %ls%ls", LogUtil_sczSpecialBeginLine ? LogUtil_sczSpecialBeginLine : L"", | 924 | hr = StrAllocFormatted(&scz, L"%ls[%04X:%04X][%04hu-%02hu-%02huT%02hu:%02hu:%02hu]%hs%03d:%ls %ls%ls", LogUtil_sczSpecialBeginLine ? LogUtil_sczSpecialBeginLine : L"", |
910 | dwProcessId, dwThreadId, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, szType, dwId, | 925 | dwProcessId, dwThreadId, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, szType, dwId, |
911 | LogUtil_sczSpecialAfterTimeStamp ? LogUtil_sczSpecialAfterTimeStamp : L"", sczString, LogUtil_sczSpecialEndLine ? LogUtil_sczSpecialEndLine : L"\r\n"); | 926 | LogUtil_sczSpecialAfterTimeStamp ? LogUtil_sczSpecialAfterTimeStamp : L"", sczString, LogUtil_sczSpecialEndLine ? LogUtil_sczSpecialEndLine : L"\r\n"); |
912 | ExitOnFailure(hr, "Failed to format line prefix."); | 927 | LoguExitOnFailure(hr, "Failed to format line prefix."); |
913 | } | 928 | } |
914 | 929 | ||
915 | wzLogData = scz ? scz : sczString; | 930 | wzLogData = scz ? scz : sczString; |
916 | 931 | ||
917 | // Convert to UTF-8 before writing out to the log file | 932 | // Convert to UTF-8 before writing out to the log file |
918 | hr = StrAnsiAllocString(&sczMultiByte, wzLogData, 0, CP_UTF8); | 933 | hr = StrAnsiAllocString(&sczMultiByte, wzLogData, 0, CP_UTF8); |
919 | ExitOnFailure(hr, "Failed to convert log string to UTF-8"); | 934 | LoguExitOnFailure(hr, "Failed to convert log string to UTF-8"); |
920 | 935 | ||
921 | if (s_vpfLogStringWorkRaw) | 936 | if (s_vpfLogStringWorkRaw) |
922 | { | 937 | { |
923 | hr = s_vpfLogStringWorkRaw(sczMultiByte, s_vpvLogStringWorkRawContext); | 938 | hr = s_vpfLogStringWorkRaw(sczMultiByte, s_vpvLogStringWorkRawContext); |
924 | ExitOnFailure(hr, "Failed to write string to log using redirected function: %ls", sczString); | 939 | LoguExitOnFailure(hr, "Failed to write string to log using redirected function: %ls", sczString); |
925 | } | 940 | } |
926 | else | 941 | else |
927 | { | 942 | { |
928 | hr = LogStringWorkRaw(sczMultiByte); | 943 | hr = LogStringWorkRaw(sczMultiByte); |
929 | ExitOnFailure(hr, "Failed to write string to log using default function: %ls", sczString); | 944 | LoguExitOnFailure(hr, "Failed to write string to log using default function: %ls", sczString); |
930 | } | 945 | } |
931 | 946 | ||
932 | LExit: | 947 | LExit: |
diff --git a/src/dutil/memutil.cpp b/src/dutil/memutil.cpp index 578c65ee..c805a9c0 100644 --- a/src/dutil/memutil.cpp +++ b/src/dutil/memutil.cpp | |||
@@ -1,10 +1,23 @@ | |||
1 | #pragma once | ||
2 | // 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. | 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. |
3 | 2 | ||
4 | |||
5 | #include "precomp.h" | 3 | #include "precomp.h" |
6 | 4 | ||
7 | 5 | ||
6 | // Exit macros | ||
7 | #define MemExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_MEMUTIL, x, s, __VA_ARGS__) | ||
8 | #define MemExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_MEMUTIL, x, s, __VA_ARGS__) | ||
9 | #define MemExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_MEMUTIL, x, s, __VA_ARGS__) | ||
10 | #define MemExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_MEMUTIL, x, s, __VA_ARGS__) | ||
11 | #define MemExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_MEMUTIL, x, s, __VA_ARGS__) | ||
12 | #define MemExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_MEMUTIL, x, s, __VA_ARGS__) | ||
13 | #define MemExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_MEMUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define MemExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_MEMUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define MemExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_MEMUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define MemExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_MEMUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define MemExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_MEMUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define MemExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_MEMUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
8 | #if DEBUG | 21 | #if DEBUG |
9 | static BOOL vfMemInitialized = FALSE; | 22 | static BOOL vfMemInitialized = FALSE; |
10 | #endif | 23 | #endif |
@@ -51,7 +64,7 @@ extern "C" HRESULT DAPI MemReAllocSecure( | |||
51 | __in LPVOID pv, | 64 | __in LPVOID pv, |
52 | __in SIZE_T cbSize, | 65 | __in SIZE_T cbSize, |
53 | __in BOOL fZero, | 66 | __in BOOL fZero, |
54 | __out LPVOID* ppvNew | 67 | __deref_out LPVOID* ppvNew |
55 | ) | 68 | ) |
56 | { | 69 | { |
57 | // AssertSz(vfMemInitialized, "MemInitialize() not called, this would normally crash"); | 70 | // AssertSz(vfMemInitialized, "MemInitialize() not called, this would normally crash"); |
@@ -72,14 +85,14 @@ extern "C" HRESULT DAPI MemReAllocSecure( | |||
72 | const SIZE_T cbCurrent = MemSize(pv); | 85 | const SIZE_T cbCurrent = MemSize(pv); |
73 | if (-1 == cbCurrent) | 86 | if (-1 == cbCurrent) |
74 | { | 87 | { |
75 | ExitOnFailure(hr = E_INVALIDARG, "Failed to get memory size"); | 88 | MemExitOnRootFailure(hr = E_INVALIDARG, "Failed to get memory size"); |
76 | } | 89 | } |
77 | 90 | ||
78 | // HeapReAlloc may allocate more memory than requested. | 91 | // HeapReAlloc may allocate more memory than requested. |
79 | const SIZE_T cbNew = MemSize(pvNew); | 92 | const SIZE_T cbNew = MemSize(pvNew); |
80 | if (-1 == cbNew) | 93 | if (-1 == cbNew) |
81 | { | 94 | { |
82 | ExitOnFailure(hr = E_INVALIDARG, "Failed to get memory size"); | 95 | MemExitOnRootFailure(hr = E_INVALIDARG, "Failed to get memory size"); |
83 | } | 96 | } |
84 | 97 | ||
85 | cbSize = cbNew; | 98 | cbSize = cbNew; |
@@ -94,7 +107,7 @@ extern "C" HRESULT DAPI MemReAllocSecure( | |||
94 | MemFree(pv); | 107 | MemFree(pv); |
95 | } | 108 | } |
96 | } | 109 | } |
97 | ExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to reallocate memory"); | 110 | MemExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to reallocate memory"); |
98 | 111 | ||
99 | *ppvNew = pvNew; | 112 | *ppvNew = pvNew; |
100 | pvNew = NULL; | 113 | pvNew = NULL; |
@@ -129,10 +142,10 @@ extern "C" HRESULT DAPI MemReAllocArray( | |||
129 | SIZE_T cbNew = 0; | 142 | SIZE_T cbNew = 0; |
130 | 143 | ||
131 | hr = ::DWordAdd(cArray, dwNewItemCount, &cNew); | 144 | hr = ::DWordAdd(cArray, dwNewItemCount, &cNew); |
132 | ExitOnFailure(hr, "Integer overflow when calculating new element count."); | 145 | MemExitOnFailure(hr, "Integer overflow when calculating new element count."); |
133 | 146 | ||
134 | hr = ::SIZETMult(cNew, cbArrayType, &cbNew); | 147 | hr = ::SIZETMult(cNew, cbArrayType, &cbNew); |
135 | ExitOnFailure(hr, "Integer overflow when calculating new block size."); | 148 | MemExitOnFailure(hr, "Integer overflow when calculating new block size."); |
136 | 149 | ||
137 | if (*ppvArray) | 150 | if (*ppvArray) |
138 | { | 151 | { |
@@ -140,7 +153,7 @@ extern "C" HRESULT DAPI MemReAllocArray( | |||
140 | if (cbCurrent < cbNew) | 153 | if (cbCurrent < cbNew) |
141 | { | 154 | { |
142 | pvNew = MemReAlloc(*ppvArray, cbNew, TRUE); | 155 | pvNew = MemReAlloc(*ppvArray, cbNew, TRUE); |
143 | ExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate larger array."); | 156 | MemExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate larger array."); |
144 | 157 | ||
145 | *ppvArray = pvNew; | 158 | *ppvArray = pvNew; |
146 | } | 159 | } |
@@ -148,7 +161,7 @@ extern "C" HRESULT DAPI MemReAllocArray( | |||
148 | else | 161 | else |
149 | { | 162 | { |
150 | pvNew = MemAlloc(cbNew, TRUE); | 163 | pvNew = MemAlloc(cbNew, TRUE); |
151 | ExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate new array."); | 164 | MemExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate new array."); |
152 | 165 | ||
153 | *ppvArray = pvNew; | 166 | *ppvArray = pvNew; |
154 | } | 167 | } |
@@ -159,7 +172,7 @@ LExit: | |||
159 | 172 | ||
160 | 173 | ||
161 | extern "C" HRESULT DAPI MemEnsureArraySize( | 174 | extern "C" HRESULT DAPI MemEnsureArraySize( |
162 | __deref_out_bcount(cArray * cbArrayType) LPVOID* ppvArray, | 175 | __deref_inout_bcount(cArray * cbArrayType) LPVOID* ppvArray, |
163 | __in DWORD cArray, | 176 | __in DWORD cArray, |
164 | __in SIZE_T cbArrayType, | 177 | __in SIZE_T cbArrayType, |
165 | __in DWORD dwGrowthCount | 178 | __in DWORD dwGrowthCount |
@@ -171,10 +184,10 @@ extern "C" HRESULT DAPI MemEnsureArraySize( | |||
171 | SIZE_T cbNew = 0; | 184 | SIZE_T cbNew = 0; |
172 | 185 | ||
173 | hr = ::DWordAdd(cArray, dwGrowthCount, &cNew); | 186 | hr = ::DWordAdd(cArray, dwGrowthCount, &cNew); |
174 | ExitOnFailure(hr, "Integer overflow when calculating new element count."); | 187 | MemExitOnFailure(hr, "Integer overflow when calculating new element count."); |
175 | 188 | ||
176 | hr = ::SIZETMult(cNew, cbArrayType, &cbNew); | 189 | hr = ::SIZETMult(cNew, cbArrayType, &cbNew); |
177 | ExitOnFailure(hr, "Integer overflow when calculating new block size."); | 190 | MemExitOnFailure(hr, "Integer overflow when calculating new block size."); |
178 | 191 | ||
179 | if (*ppvArray) | 192 | if (*ppvArray) |
180 | { | 193 | { |
@@ -183,7 +196,7 @@ extern "C" HRESULT DAPI MemEnsureArraySize( | |||
183 | if (cbCurrent < cbUsed) | 196 | if (cbCurrent < cbUsed) |
184 | { | 197 | { |
185 | pvNew = MemReAlloc(*ppvArray, cbNew, TRUE); | 198 | pvNew = MemReAlloc(*ppvArray, cbNew, TRUE); |
186 | ExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate array larger."); | 199 | MemExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate array larger."); |
187 | 200 | ||
188 | *ppvArray = pvNew; | 201 | *ppvArray = pvNew; |
189 | } | 202 | } |
@@ -191,7 +204,7 @@ extern "C" HRESULT DAPI MemEnsureArraySize( | |||
191 | else | 204 | else |
192 | { | 205 | { |
193 | pvNew = MemAlloc(cbNew, TRUE); | 206 | pvNew = MemAlloc(cbNew, TRUE); |
194 | ExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate new array."); | 207 | MemExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to allocate new array."); |
195 | 208 | ||
196 | *ppvArray = pvNew; | 209 | *ppvArray = pvNew; |
197 | } | 210 | } |
@@ -202,7 +215,7 @@ LExit: | |||
202 | 215 | ||
203 | 216 | ||
204 | extern "C" HRESULT DAPI MemInsertIntoArray( | 217 | extern "C" HRESULT DAPI MemInsertIntoArray( |
205 | __deref_out_bcount((cExistingArray + cInsertItems) * cbArrayType) LPVOID* ppvArray, | 218 | __deref_inout_bcount((cExistingArray + cInsertItems) * cbArrayType) LPVOID* ppvArray, |
206 | __in DWORD dwInsertIndex, | 219 | __in DWORD dwInsertIndex, |
207 | __in DWORD cInsertItems, | 220 | __in DWORD cInsertItems, |
208 | __in DWORD cExistingArray, | 221 | __in DWORD cExistingArray, |
@@ -220,7 +233,7 @@ extern "C" HRESULT DAPI MemInsertIntoArray( | |||
220 | } | 233 | } |
221 | 234 | ||
222 | hr = MemEnsureArraySize(ppvArray, cExistingArray + cInsertItems, cbArrayType, dwGrowthCount); | 235 | hr = MemEnsureArraySize(ppvArray, cExistingArray + cInsertItems, cbArrayType, dwGrowthCount); |
223 | ExitOnFailure(hr, "Failed to resize array while inserting items"); | 236 | MemExitOnFailure(hr, "Failed to resize array while inserting items"); |
224 | 237 | ||
225 | pbArray = reinterpret_cast<BYTE *>(*ppvArray); | 238 | pbArray = reinterpret_cast<BYTE *>(*ppvArray); |
226 | for (i = cExistingArray + cInsertItems - 1; i > dwInsertIndex; --i) | 239 | for (i = cExistingArray + cInsertItems - 1; i > dwInsertIndex; --i) |
@@ -236,7 +249,7 @@ LExit: | |||
236 | } | 249 | } |
237 | 250 | ||
238 | extern "C" void DAPI MemRemoveFromArray( | 251 | extern "C" void DAPI MemRemoveFromArray( |
239 | __inout_bcount((cExistingArray + cInsertItems) * cbArrayType) LPVOID pvArray, | 252 | __inout_bcount((cExistingArray) * cbArrayType) LPVOID pvArray, |
240 | __in DWORD dwRemoveIndex, | 253 | __in DWORD dwRemoveIndex, |
241 | __in DWORD cRemoveItems, | 254 | __in DWORD cRemoveItems, |
242 | __in DWORD cExistingArray, | 255 | __in DWORD cExistingArray, |
@@ -261,7 +274,7 @@ extern "C" void DAPI MemRemoveFromArray( | |||
261 | } | 274 | } |
262 | 275 | ||
263 | extern "C" void DAPI MemArraySwapItems( | 276 | extern "C" void DAPI MemArraySwapItems( |
264 | __inout_bcount((cExistingArray) * cbArrayType) LPVOID pvArray, | 277 | __inout_bcount(cbArrayType) LPVOID pvArray, |
265 | __in DWORD dwIndex1, | 278 | __in DWORD dwIndex1, |
266 | __in DWORD dwIndex2, | 279 | __in DWORD dwIndex2, |
267 | __in SIZE_T cbArrayType | 280 | __in SIZE_T cbArrayType |
diff --git a/src/dutil/metautil.cpp b/src/dutil/metautil.cpp index 612b1127..109cd31e 100644 --- a/src/dutil/metautil.cpp +++ b/src/dutil/metautil.cpp | |||
@@ -9,6 +9,21 @@ | |||
9 | #include "metautil.h" | 9 | #include "metautil.h" |
10 | 10 | ||
11 | 11 | ||
12 | // Exit macros | ||
13 | #define MetaExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__) | ||
14 | #define MetaExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__) | ||
15 | #define MetaExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__) | ||
16 | #define MetaExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__) | ||
17 | #define MetaExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__) | ||
18 | #define MetaExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__) | ||
19 | #define MetaExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_METAUTIL, p, x, e, s, __VA_ARGS__) | ||
20 | #define MetaExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_METAUTIL, p, x, s, __VA_ARGS__) | ||
21 | #define MetaExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_METAUTIL, p, x, e, s, __VA_ARGS__) | ||
22 | #define MetaExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_METAUTIL, p, x, s, __VA_ARGS__) | ||
23 | #define MetaExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_METAUTIL, e, x, s, __VA_ARGS__) | ||
24 | #define MetaExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_METAUTIL, g, x, s, __VA_ARGS__) | ||
25 | |||
26 | |||
12 | // prototypes | 27 | // prototypes |
13 | static void Sort( | 28 | static void Sort( |
14 | __in_ecount(cArray) DWORD dwArray[], | 29 | __in_ecount(cArray) DWORD dwArray[], |
@@ -75,7 +90,7 @@ extern "C" HRESULT DAPI MetaFindWebBase( | |||
75 | hr = S_FALSE; // didn't find anything, try next one | 90 | hr = S_FALSE; // didn't find anything, try next one |
76 | continue; | 91 | continue; |
77 | } | 92 | } |
78 | ExitOnFailure(hr, "failed to get key from metabase while searching for web servers"); | 93 | MetaExitOnFailure(hr, "failed to get key from metabase while searching for web servers"); |
79 | 94 | ||
80 | // if we have an IIsWebServer store the key | 95 | // if we have an IIsWebServer store the key |
81 | if (0 == lstrcmpW(L"IIsWebServer", (LPCWSTR)mr.pbMDData)) | 96 | if (0 == lstrcmpW(L"IIsWebServer", (LPCWSTR)mr.pbMDData)) |
@@ -83,7 +98,7 @@ extern "C" HRESULT DAPI MetaFindWebBase( | |||
83 | hr = MetaGetValue(piMetabase, METADATA_MASTER_ROOT_HANDLE, wzKey, &mrAddress); | 98 | hr = MetaGetValue(piMetabase, METADATA_MASTER_ROOT_HANDLE, wzKey, &mrAddress); |
84 | if (MD_ERROR_DATA_NOT_FOUND == hr) | 99 | if (MD_ERROR_DATA_NOT_FOUND == hr) |
85 | hr = S_FALSE; | 100 | hr = S_FALSE; |
86 | ExitOnFailure(hr, "failed to get address from metabase while searching for web servers"); | 101 | MetaExitOnFailure(hr, "failed to get address from metabase while searching for web servers"); |
87 | 102 | ||
88 | // break down the first address into parts | 103 | // break down the first address into parts |
89 | pwzIPExists = reinterpret_cast<LPWSTR>(mrAddress.pbMDData); | 104 | pwzIPExists = reinterpret_cast<LPWSTR>(mrAddress.pbMDData); |
@@ -111,7 +126,7 @@ extern "C" HRESULT DAPI MetaFindWebBase( | |||
111 | { | 126 | { |
112 | // if the passed in buffer wasn't big enough | 127 | // if the passed in buffer wasn't big enough |
113 | hr = ::StringCchCopyW(wzWebBase, cchWebBase, wzKey); | 128 | hr = ::StringCchCopyW(wzWebBase, cchWebBase, wzKey); |
114 | ExitOnFailure(hr, "failed to copy in web base: %ls", wzKey); | 129 | MetaExitOnFailure(hr, "failed to copy in web base: %ls", wzKey); |
115 | 130 | ||
116 | fFound = TRUE; | 131 | fFound = TRUE; |
117 | break; | 132 | break; |
@@ -182,7 +197,7 @@ extern "C" HRESULT DAPI MetaFindFreeWebBase( | |||
182 | hr = S_FALSE; // didn't find anything, try next one | 197 | hr = S_FALSE; // didn't find anything, try next one |
183 | continue; | 198 | continue; |
184 | } | 199 | } |
185 | ExitOnFailure(hr, "failed to get key from metabase while searching for free web root"); | 200 | MetaExitOnFailure(hr, "failed to get key from metabase while searching for free web root"); |
186 | 201 | ||
187 | // if we have a IIsWebServer get the address information | 202 | // if we have a IIsWebServer get the address information |
188 | if (0 == lstrcmpW(L"IIsWebServer", reinterpret_cast<LPCWSTR>(mr.pbMDData))) | 203 | if (0 == lstrcmpW(L"IIsWebServer", reinterpret_cast<LPCWSTR>(mr.pbMDData))) |
@@ -190,7 +205,7 @@ extern "C" HRESULT DAPI MetaFindFreeWebBase( | |||
190 | if (cSubKeys >= countof(dwSubKeys)) | 205 | if (cSubKeys >= countof(dwSubKeys)) |
191 | { | 206 | { |
192 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | 207 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); |
193 | ExitOnFailure(hr, "Insufficient buffer to track all sub-WebSites"); | 208 | MetaExitOnFailure(hr, "Insufficient buffer to track all sub-WebSites"); |
194 | } | 209 | } |
195 | 210 | ||
196 | dwSubKeys[cSubKeys] = wcstol(wzSubkey, NULL, 10); | 211 | dwSubKeys[cSubKeys] = wcstol(wzSubkey, NULL, 10); |
@@ -201,7 +216,7 @@ extern "C" HRESULT DAPI MetaFindFreeWebBase( | |||
201 | 216 | ||
202 | if (E_NOMOREITEMS == hr) | 217 | if (E_NOMOREITEMS == hr) |
203 | hr = S_OK; | 218 | hr = S_OK; |
204 | ExitOnFailure(hr, "failed to find free web root"); | 219 | MetaExitOnFailure(hr, "failed to find free web root"); |
205 | 220 | ||
206 | // find the lowest free web root | 221 | // find the lowest free web root |
207 | dwKey = 1; | 222 | dwKey = 1; |
@@ -270,18 +285,18 @@ extern "C" HRESULT DAPI MetaGetValue( | |||
270 | if (!piMetabase) | 285 | if (!piMetabase) |
271 | { | 286 | { |
272 | hr = ::CoInitialize(NULL); | 287 | hr = ::CoInitialize(NULL); |
273 | ExitOnFailure(hr, "failed to initialize COM"); | 288 | MetaExitOnFailure(hr, "failed to initialize COM"); |
274 | fInitialized = TRUE; | 289 | fInitialized = TRUE; |
275 | 290 | ||
276 | hr = ::CoCreateInstance(CLSID_MSAdminBase, NULL, CLSCTX_ALL, IID_IMSAdminBase, reinterpret_cast<LPVOID*>(&piMetabase)); | 291 | hr = ::CoCreateInstance(CLSID_MSAdminBase, NULL, CLSCTX_ALL, IID_IMSAdminBase, reinterpret_cast<LPVOID*>(&piMetabase)); |
277 | ExitOnFailure(hr, "failed to get IID_IMSAdminBaseW object"); | 292 | MetaExitOnFailure(hr, "failed to get IID_IMSAdminBaseW object"); |
278 | } | 293 | } |
279 | 294 | ||
280 | if (!pmr->pbMDData) | 295 | if (!pmr->pbMDData) |
281 | { | 296 | { |
282 | pmr->dwMDDataLen = 256; | 297 | pmr->dwMDDataLen = 256; |
283 | pmr->pbMDData = static_cast<BYTE*>(MemAlloc(pmr->dwMDDataLen, TRUE)); | 298 | pmr->pbMDData = static_cast<BYTE*>(MemAlloc(pmr->dwMDDataLen, TRUE)); |
284 | ExitOnNull(pmr->pbMDData, hr, E_OUTOFMEMORY, "failed to allocate memory for metabase value"); | 299 | MetaExitOnNull(pmr->pbMDData, hr, E_OUTOFMEMORY, "failed to allocate memory for metabase value"); |
285 | } | 300 | } |
286 | else // set the size of the data to the actual size of the memory | 301 | else // set the size of the data to the actual size of the memory |
287 | pmr->dwMDDataLen = (DWORD)MemSize(pmr->pbMDData); | 302 | pmr->dwMDDataLen = (DWORD)MemSize(pmr->pbMDData); |
@@ -291,12 +306,12 @@ extern "C" HRESULT DAPI MetaGetValue( | |||
291 | { | 306 | { |
292 | pmr->dwMDDataLen = cbRequired; | 307 | pmr->dwMDDataLen = cbRequired; |
293 | BYTE* pb = static_cast<BYTE*>(MemReAlloc(pmr->pbMDData, pmr->dwMDDataLen, TRUE)); | 308 | BYTE* pb = static_cast<BYTE*>(MemReAlloc(pmr->pbMDData, pmr->dwMDDataLen, TRUE)); |
294 | ExitOnNull(pb, hr, E_OUTOFMEMORY, "failed to reallocate memory for metabase value"); | 309 | MetaExitOnNull(pb, hr, E_OUTOFMEMORY, "failed to reallocate memory for metabase value"); |
295 | 310 | ||
296 | pmr->pbMDData = pb; | 311 | pmr->pbMDData = pb; |
297 | hr = piMetabase->GetData(mhKey, wzKey, pmr, &cbRequired); | 312 | hr = piMetabase->GetData(mhKey, wzKey, pmr, &cbRequired); |
298 | } | 313 | } |
299 | ExitOnFailure(hr, "failed to get metabase data"); | 314 | MetaExitOnFailure(hr, "failed to get metabase data"); |
300 | 315 | ||
301 | LExit: | 316 | LExit: |
302 | if (fInitialized) | 317 | if (fInitialized) |
diff --git a/src/dutil/monutil.cpp b/src/dutil/monutil.cpp index 6f280538..6a7f0596 100644 --- a/src/dutil/monutil.cpp +++ b/src/dutil/monutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define MonExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_MONUTIL, x, s, __VA_ARGS__) | ||
8 | #define MonExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_MONUTIL, x, s, __VA_ARGS__) | ||
9 | #define MonExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_MONUTIL, x, s, __VA_ARGS__) | ||
10 | #define MonExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_MONUTIL, x, s, __VA_ARGS__) | ||
11 | #define MonExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_MONUTIL, x, s, __VA_ARGS__) | ||
12 | #define MonExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_MONUTIL, x, s, __VA_ARGS__) | ||
13 | #define MonExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_MONUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define MonExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_MONUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define MonExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_MONUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define MonExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_MONUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define MonExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_MONUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define MonExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_MONUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | const int MON_THREAD_GROWTH = 5; | 20 | const int MON_THREAD_GROWTH = 5; |
6 | const int MON_ARRAY_GROWTH = 40; | 21 | const int MON_ARRAY_GROWTH = 40; |
7 | const int MON_MAX_MONITORS_PER_THREAD = 63; | 22 | const int MON_MAX_MONITORS_PER_THREAD = 63; |
@@ -218,10 +233,10 @@ static void MonRequestDestroy( | |||
218 | __in MON_REQUEST *pRequest | 233 | __in MON_REQUEST *pRequest |
219 | ); | 234 | ); |
220 | static void MonAddMessageDestroy( | 235 | static void MonAddMessageDestroy( |
221 | __in MON_ADD_MESSAGE *pMessage | 236 | __in_opt MON_ADD_MESSAGE *pMessage |
222 | ); | 237 | ); |
223 | static void MonRemoveMessageDestroy( | 238 | static void MonRemoveMessageDestroy( |
224 | __in MON_REMOVE_MESSAGE *pMessage | 239 | __in_opt MON_REMOVE_MESSAGE *pMessage |
225 | ); | 240 | ); |
226 | static BOOL GetRecursiveFlag( | 241 | static BOOL GetRecursiveFlag( |
227 | __in MON_REQUEST *pRequest, | 242 | __in MON_REQUEST *pRequest, |
@@ -262,7 +277,7 @@ static HRESULT UpdateWaitStatus( | |||
262 | __in HRESULT hrNewStatus, | 277 | __in HRESULT hrNewStatus, |
263 | __inout MON_WAITER_CONTEXT *pWaiterContext, | 278 | __inout MON_WAITER_CONTEXT *pWaiterContext, |
264 | __in DWORD dwRequestIndex, | 279 | __in DWORD dwRequestIndex, |
265 | __out DWORD *pdwNewRequestIndex | 280 | __out_opt DWORD *pdwNewRequestIndex |
266 | ); | 281 | ); |
267 | 282 | ||
268 | extern "C" HRESULT DAPI MonCreate( | 283 | extern "C" HRESULT DAPI MonCreate( |
@@ -277,11 +292,11 @@ extern "C" HRESULT DAPI MonCreate( | |||
277 | HRESULT hr = S_OK; | 292 | HRESULT hr = S_OK; |
278 | DWORD dwRetries = MON_THREAD_INIT_RETRIES; | 293 | DWORD dwRetries = MON_THREAD_INIT_RETRIES; |
279 | 294 | ||
280 | ExitOnNull(pHandle, hr, E_INVALIDARG, "Pointer to handle not specified while creating monitor"); | 295 | MonExitOnNull(pHandle, hr, E_INVALIDARG, "Pointer to handle not specified while creating monitor"); |
281 | 296 | ||
282 | // Allocate the struct | 297 | // Allocate the struct |
283 | *pHandle = static_cast<MON_HANDLE>(MemAlloc(sizeof(MON_STRUCT), TRUE)); | 298 | *pHandle = static_cast<MON_HANDLE>(MemAlloc(sizeof(MON_STRUCT), TRUE)); |
284 | ExitOnNull(*pHandle, hr, E_OUTOFMEMORY, "Failed to allocate monitor object"); | 299 | MonExitOnNull(*pHandle, hr, E_OUTOFMEMORY, "Failed to allocate monitor object"); |
285 | 300 | ||
286 | MON_STRUCT *pm = static_cast<MON_STRUCT *>(*pHandle); | 301 | MON_STRUCT *pm = static_cast<MON_STRUCT *>(*pHandle); |
287 | 302 | ||
@@ -294,7 +309,7 @@ extern "C" HRESULT DAPI MonCreate( | |||
294 | pm->hCoordinatorThread = ::CreateThread(NULL, 0, CoordinatorThread, pm, 0, &pm->dwCoordinatorThreadId); | 309 | pm->hCoordinatorThread = ::CreateThread(NULL, 0, CoordinatorThread, pm, 0, &pm->dwCoordinatorThreadId); |
295 | if (!pm->hCoordinatorThread) | 310 | if (!pm->hCoordinatorThread) |
296 | { | 311 | { |
297 | ExitWithLastError(hr, "Failed to create waiter thread."); | 312 | MonExitWithLastError(hr, "Failed to create waiter thread."); |
298 | } | 313 | } |
299 | 314 | ||
300 | // Ensure the created thread initializes its message queue. It does this first thing, so if it doesn't within 10 seconds, there must be a huge problem. | 315 | // Ensure the created thread initializes its message queue. It does this first thing, so if it doesn't within 10 seconds, there must be a huge problem. |
@@ -307,7 +322,7 @@ extern "C" HRESULT DAPI MonCreate( | |||
307 | if (0 == dwRetries) | 322 | if (0 == dwRetries) |
308 | { | 323 | { |
309 | hr = E_UNEXPECTED; | 324 | hr = E_UNEXPECTED; |
310 | ExitOnFailure(hr, "Waiter thread apparently never initialized its message queue."); | 325 | MonExitOnFailure(hr, "Waiter thread apparently never initialized its message queue."); |
311 | } | 326 | } |
312 | 327 | ||
313 | LExit: | 328 | LExit: |
@@ -329,13 +344,13 @@ extern "C" HRESULT DAPI MonAddDirectory( | |||
329 | MON_ADD_MESSAGE *pMessage = NULL; | 344 | MON_ADD_MESSAGE *pMessage = NULL; |
330 | 345 | ||
331 | hr = StrAllocString(&sczOriginalPathRequest, wzDirectory, 0); | 346 | hr = StrAllocString(&sczOriginalPathRequest, wzDirectory, 0); |
332 | ExitOnFailure(hr, "Failed to convert directory string to UNC path"); | 347 | MonExitOnFailure(hr, "Failed to convert directory string to UNC path"); |
333 | 348 | ||
334 | hr = PathBackslashTerminate(&sczOriginalPathRequest); | 349 | hr = PathBackslashTerminate(&sczOriginalPathRequest); |
335 | ExitOnFailure(hr, "Failed to ensure directory ends in backslash"); | 350 | MonExitOnFailure(hr, "Failed to ensure directory ends in backslash"); |
336 | 351 | ||
337 | pMessage = reinterpret_cast<MON_ADD_MESSAGE *>(MemAlloc(sizeof(MON_ADD_MESSAGE), TRUE)); | 352 | pMessage = reinterpret_cast<MON_ADD_MESSAGE *>(MemAlloc(sizeof(MON_ADD_MESSAGE), TRUE)); |
338 | ExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message"); | 353 | MonExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message"); |
339 | 354 | ||
340 | if (sczOriginalPathRequest[0] == L'\\' && sczOriginalPathRequest[1] == L'\\') | 355 | if (sczOriginalPathRequest[0] == L'\\' && sczOriginalPathRequest[1] == L'\\') |
341 | { | 356 | { |
@@ -356,7 +371,7 @@ extern "C" HRESULT DAPI MonAddDirectory( | |||
356 | hr = S_OK; | 371 | hr = S_OK; |
357 | 372 | ||
358 | hr = StrAllocString(&sczDirectory, sczOriginalPathRequest, 0); | 373 | hr = StrAllocString(&sczDirectory, sczOriginalPathRequest, 0); |
359 | ExitOnFailure(hr, "Failed to copy original path request: %ls", sczOriginalPathRequest); | 374 | MonExitOnFailure(hr, "Failed to copy original path request: %ls", sczOriginalPathRequest); |
360 | } | 375 | } |
361 | 376 | ||
362 | pMessage->handle = INVALID_HANDLE_VALUE; | 377 | pMessage->handle = INVALID_HANDLE_VALUE; |
@@ -369,14 +384,14 @@ extern "C" HRESULT DAPI MonAddDirectory( | |||
369 | sczOriginalPathRequest = NULL; | 384 | sczOriginalPathRequest = NULL; |
370 | 385 | ||
371 | hr = PathGetHierarchyArray(sczDirectory, &pMessage->request.rgsczPathHierarchy, reinterpret_cast<LPUINT>(&pMessage->request.cPathHierarchy)); | 386 | hr = PathGetHierarchyArray(sczDirectory, &pMessage->request.rgsczPathHierarchy, reinterpret_cast<LPUINT>(&pMessage->request.cPathHierarchy)); |
372 | ExitOnFailure(hr, "Failed to get hierarchy array for path %ls", sczDirectory); | 387 | MonExitOnFailure(hr, "Failed to get hierarchy array for path %ls", sczDirectory); |
373 | 388 | ||
374 | if (0 < pMessage->request.cPathHierarchy) | 389 | if (0 < pMessage->request.cPathHierarchy) |
375 | { | 390 | { |
376 | pMessage->request.hrStatus = InitiateWait(&pMessage->request, &pMessage->handle); | 391 | pMessage->request.hrStatus = InitiateWait(&pMessage->request, &pMessage->handle); |
377 | if (!::PostThreadMessageW(pm->dwCoordinatorThreadId, MON_MESSAGE_ADD, reinterpret_cast<WPARAM>(pMessage), 0)) | 392 | if (!::PostThreadMessageW(pm->dwCoordinatorThreadId, MON_MESSAGE_ADD, reinterpret_cast<WPARAM>(pMessage), 0)) |
378 | { | 393 | { |
379 | ExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for path %ls", sczDirectory); | 394 | MonExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for path %ls", sczDirectory); |
380 | } | 395 | } |
381 | pMessage = NULL; | 396 | pMessage = NULL; |
382 | } | 397 | } |
@@ -405,16 +420,16 @@ extern "C" HRESULT DAPI MonAddRegKey( | |||
405 | MON_ADD_MESSAGE *pMessage = NULL; | 420 | MON_ADD_MESSAGE *pMessage = NULL; |
406 | 421 | ||
407 | hr = StrAllocString(&sczSubKey, wzSubKey, 0); | 422 | hr = StrAllocString(&sczSubKey, wzSubKey, 0); |
408 | ExitOnFailure(hr, "Failed to copy subkey string"); | 423 | MonExitOnFailure(hr, "Failed to copy subkey string"); |
409 | 424 | ||
410 | hr = PathBackslashTerminate(&sczSubKey); | 425 | hr = PathBackslashTerminate(&sczSubKey); |
411 | ExitOnFailure(hr, "Failed to ensure subkey path ends in backslash"); | 426 | MonExitOnFailure(hr, "Failed to ensure subkey path ends in backslash"); |
412 | 427 | ||
413 | pMessage = reinterpret_cast<MON_ADD_MESSAGE *>(MemAlloc(sizeof(MON_ADD_MESSAGE), TRUE)); | 428 | pMessage = reinterpret_cast<MON_ADD_MESSAGE *>(MemAlloc(sizeof(MON_ADD_MESSAGE), TRUE)); |
414 | ExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message"); | 429 | MonExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message"); |
415 | 430 | ||
416 | pMessage->handle = ::CreateEventW(NULL, TRUE, FALSE, NULL); | 431 | pMessage->handle = ::CreateEventW(NULL, TRUE, FALSE, NULL); |
417 | ExitOnNullWithLastError(pMessage->handle, hr, "Failed to create anonymous event for regkey monitor"); | 432 | MonExitOnNullWithLastError(pMessage->handle, hr, "Failed to create anonymous event for regkey monitor"); |
418 | 433 | ||
419 | pMessage->request.type = MON_REGKEY; | 434 | pMessage->request.type = MON_REGKEY; |
420 | pMessage->request.regkey.hkRoot = hkRoot; | 435 | pMessage->request.regkey.hkRoot = hkRoot; |
@@ -425,16 +440,16 @@ extern "C" HRESULT DAPI MonAddRegKey( | |||
425 | pMessage->request.pvContext = pvRegKeyContext; | 440 | pMessage->request.pvContext = pvRegKeyContext; |
426 | 441 | ||
427 | hr = PathGetHierarchyArray(sczSubKey, &pMessage->request.rgsczPathHierarchy, reinterpret_cast<LPUINT>(&pMessage->request.cPathHierarchy)); | 442 | hr = PathGetHierarchyArray(sczSubKey, &pMessage->request.rgsczPathHierarchy, reinterpret_cast<LPUINT>(&pMessage->request.cPathHierarchy)); |
428 | ExitOnFailure(hr, "Failed to get hierarchy array for subkey %ls", sczSubKey); | 443 | MonExitOnFailure(hr, "Failed to get hierarchy array for subkey %ls", sczSubKey); |
429 | 444 | ||
430 | if (0 < pMessage->request.cPathHierarchy) | 445 | if (0 < pMessage->request.cPathHierarchy) |
431 | { | 446 | { |
432 | pMessage->request.hrStatus = InitiateWait(&pMessage->request, &pMessage->handle); | 447 | pMessage->request.hrStatus = InitiateWait(&pMessage->request, &pMessage->handle); |
433 | ExitOnFailure(hr, "Failed to initiate wait"); | 448 | MonExitOnFailure(hr, "Failed to initiate wait"); |
434 | 449 | ||
435 | if (!::PostThreadMessageW(pm->dwCoordinatorThreadId, MON_MESSAGE_ADD, reinterpret_cast<WPARAM>(pMessage), 0)) | 450 | if (!::PostThreadMessageW(pm->dwCoordinatorThreadId, MON_MESSAGE_ADD, reinterpret_cast<WPARAM>(pMessage), 0)) |
436 | { | 451 | { |
437 | ExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for regkey %ls", sczSubKey); | 452 | MonExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for regkey %ls", sczSubKey); |
438 | } | 453 | } |
439 | pMessage = NULL; | 454 | pMessage = NULL; |
440 | } | 455 | } |
@@ -458,23 +473,23 @@ extern "C" HRESULT DAPI MonRemoveDirectory( | |||
458 | MON_REMOVE_MESSAGE *pMessage = NULL; | 473 | MON_REMOVE_MESSAGE *pMessage = NULL; |
459 | 474 | ||
460 | hr = StrAllocString(&sczDirectory, wzDirectory, 0); | 475 | hr = StrAllocString(&sczDirectory, wzDirectory, 0); |
461 | ExitOnFailure(hr, "Failed to copy directory string"); | 476 | MonExitOnFailure(hr, "Failed to copy directory string"); |
462 | 477 | ||
463 | hr = PathBackslashTerminate(&sczDirectory); | 478 | hr = PathBackslashTerminate(&sczDirectory); |
464 | ExitOnFailure(hr, "Failed to ensure directory ends in backslash"); | 479 | MonExitOnFailure(hr, "Failed to ensure directory ends in backslash"); |
465 | 480 | ||
466 | pMessage = reinterpret_cast<MON_REMOVE_MESSAGE *>(MemAlloc(sizeof(MON_REMOVE_MESSAGE), TRUE)); | 481 | pMessage = reinterpret_cast<MON_REMOVE_MESSAGE *>(MemAlloc(sizeof(MON_REMOVE_MESSAGE), TRUE)); |
467 | ExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message"); | 482 | MonExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message"); |
468 | 483 | ||
469 | pMessage->type = MON_DIRECTORY; | 484 | pMessage->type = MON_DIRECTORY; |
470 | pMessage->fRecursive = fRecursive; | 485 | pMessage->fRecursive = fRecursive; |
471 | 486 | ||
472 | hr = StrAllocString(&pMessage->directory.sczDirectory, sczDirectory, 0); | 487 | hr = StrAllocString(&pMessage->directory.sczDirectory, sczDirectory, 0); |
473 | ExitOnFailure(hr, "Failed to allocate copy of directory string"); | 488 | MonExitOnFailure(hr, "Failed to allocate copy of directory string"); |
474 | 489 | ||
475 | if (!::PostThreadMessageW(pm->dwCoordinatorThreadId, MON_MESSAGE_REMOVE, reinterpret_cast<WPARAM>(pMessage), 0)) | 490 | if (!::PostThreadMessageW(pm->dwCoordinatorThreadId, MON_MESSAGE_REMOVE, reinterpret_cast<WPARAM>(pMessage), 0)) |
476 | { | 491 | { |
477 | ExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for path %ls", sczDirectory); | 492 | MonExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for path %ls", sczDirectory); |
478 | } | 493 | } |
479 | pMessage = NULL; | 494 | pMessage = NULL; |
480 | 495 | ||
@@ -498,13 +513,13 @@ extern "C" HRESULT DAPI MonRemoveRegKey( | |||
498 | MON_REMOVE_MESSAGE *pMessage = NULL; | 513 | MON_REMOVE_MESSAGE *pMessage = NULL; |
499 | 514 | ||
500 | hr = StrAllocString(&sczSubKey, wzSubKey, 0); | 515 | hr = StrAllocString(&sczSubKey, wzSubKey, 0); |
501 | ExitOnFailure(hr, "Failed to copy subkey string"); | 516 | MonExitOnFailure(hr, "Failed to copy subkey string"); |
502 | 517 | ||
503 | hr = PathBackslashTerminate(&sczSubKey); | 518 | hr = PathBackslashTerminate(&sczSubKey); |
504 | ExitOnFailure(hr, "Failed to ensure subkey path ends in backslash"); | 519 | MonExitOnFailure(hr, "Failed to ensure subkey path ends in backslash"); |
505 | 520 | ||
506 | pMessage = reinterpret_cast<MON_REMOVE_MESSAGE *>(MemAlloc(sizeof(MON_REMOVE_MESSAGE), TRUE)); | 521 | pMessage = reinterpret_cast<MON_REMOVE_MESSAGE *>(MemAlloc(sizeof(MON_REMOVE_MESSAGE), TRUE)); |
507 | ExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message"); | 522 | MonExitOnNull(pMessage, hr, E_OUTOFMEMORY, "Failed to allocate memory for message"); |
508 | 523 | ||
509 | pMessage->type = MON_REGKEY; | 524 | pMessage->type = MON_REGKEY; |
510 | pMessage->regkey.hkRoot = hkRoot; | 525 | pMessage->regkey.hkRoot = hkRoot; |
@@ -512,11 +527,11 @@ extern "C" HRESULT DAPI MonRemoveRegKey( | |||
512 | pMessage->fRecursive = fRecursive; | 527 | pMessage->fRecursive = fRecursive; |
513 | 528 | ||
514 | hr = StrAllocString(&pMessage->regkey.sczSubKey, sczSubKey, 0); | 529 | hr = StrAllocString(&pMessage->regkey.sczSubKey, sczSubKey, 0); |
515 | ExitOnFailure(hr, "Failed to allocate copy of directory string"); | 530 | MonExitOnFailure(hr, "Failed to allocate copy of directory string"); |
516 | 531 | ||
517 | if (!::PostThreadMessageW(pm->dwCoordinatorThreadId, MON_MESSAGE_REMOVE, reinterpret_cast<WPARAM>(pMessage), 0)) | 532 | if (!::PostThreadMessageW(pm->dwCoordinatorThreadId, MON_MESSAGE_REMOVE, reinterpret_cast<WPARAM>(pMessage), 0)) |
518 | { | 533 | { |
519 | ExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for path %ls", sczSubKey); | 534 | MonExitWithLastError(hr, "Failed to send message to worker thread to add directory wait for path %ls", sczSubKey); |
520 | } | 535 | } |
521 | pMessage = NULL; | 536 | pMessage = NULL; |
522 | 537 | ||
@@ -543,7 +558,7 @@ extern "C" void DAPI MonDestroy( | |||
543 | // It already halted, or doesn't exist for some other reason, so let's just ignore it and clean up | 558 | // It already halted, or doesn't exist for some other reason, so let's just ignore it and clean up |
544 | er = ERROR_SUCCESS; | 559 | er = ERROR_SUCCESS; |
545 | } | 560 | } |
546 | ExitOnWin32Error(er, hr, "Failed to send message to background thread to halt"); | 561 | MonExitOnWin32Error(er, hr, "Failed to send message to background thread to halt"); |
547 | } | 562 | } |
548 | 563 | ||
549 | if (pm->hCoordinatorThread) | 564 | if (pm->hCoordinatorThread) |
@@ -577,10 +592,10 @@ static void MonRequestDestroy( | |||
577 | } | 592 | } |
578 | 593 | ||
579 | static void MonAddMessageDestroy( | 594 | static void MonAddMessageDestroy( |
580 | __in MON_ADD_MESSAGE *pMessage | 595 | __in_opt MON_ADD_MESSAGE *pMessage |
581 | ) | 596 | ) |
582 | { | 597 | { |
583 | if (NULL != pMessage) | 598 | if (pMessage) |
584 | { | 599 | { |
585 | MonRequestDestroy(&pMessage->request); | 600 | MonRequestDestroy(&pMessage->request); |
586 | if (MON_DIRECTORY == pMessage->request.type && INVALID_HANDLE_VALUE != pMessage->handle) | 601 | if (MON_DIRECTORY == pMessage->request.type && INVALID_HANDLE_VALUE != pMessage->handle) |
@@ -597,10 +612,10 @@ static void MonAddMessageDestroy( | |||
597 | } | 612 | } |
598 | 613 | ||
599 | static void MonRemoveMessageDestroy( | 614 | static void MonRemoveMessageDestroy( |
600 | __in MON_REMOVE_MESSAGE *pMessage | 615 | __in_opt MON_REMOVE_MESSAGE *pMessage |
601 | ) | 616 | ) |
602 | { | 617 | { |
603 | if (NULL != pMessage) | 618 | if (pMessage) |
604 | { | 619 | { |
605 | switch (pMessage->type) | 620 | switch (pMessage->type) |
606 | { | 621 | { |
@@ -642,17 +657,17 @@ static DWORD WINAPI CoordinatorThread( | |||
642 | pm->fCoordinatorThreadMessageQueueInitialized = TRUE; | 657 | pm->fCoordinatorThreadMessageQueueInitialized = TRUE; |
643 | 658 | ||
644 | hr = CreateMonWindow(pm, &pm->hwnd); | 659 | hr = CreateMonWindow(pm, &pm->hwnd); |
645 | ExitOnFailure(hr, "Failed to create window for status update thread"); | 660 | MonExitOnFailure(hr, "Failed to create window for status update thread"); |
646 | 661 | ||
647 | ::WSAStartup(MAKEWORD(2, 2), &wsaData); | 662 | ::WSAStartup(MAKEWORD(2, 2), &wsaData); |
648 | 663 | ||
649 | hr = WaitForNetworkChanges(&hMonitor, pm); | 664 | hr = WaitForNetworkChanges(&hMonitor, pm); |
650 | ExitOnFailure(hr, "Failed to wait for network changes"); | 665 | MonExitOnFailure(hr, "Failed to wait for network changes"); |
651 | 666 | ||
652 | uTimerSuccessfulNetworkRetry = ::SetTimer(NULL, 1, MON_THREAD_NETWORK_SUCCESSFUL_RETRY_IN_MS, NULL); | 667 | uTimerSuccessfulNetworkRetry = ::SetTimer(NULL, 1, MON_THREAD_NETWORK_SUCCESSFUL_RETRY_IN_MS, NULL); |
653 | if (0 == uTimerSuccessfulNetworkRetry) | 668 | if (0 == uTimerSuccessfulNetworkRetry) |
654 | { | 669 | { |
655 | ExitWithLastError(hr, "Failed to set timer for network successful retry"); | 670 | MonExitWithLastError(hr, "Failed to set timer for network successful retry"); |
656 | } | 671 | } |
657 | 672 | ||
658 | while (0 != (fRet = ::GetMessageW(&msg, NULL, 0, 0))) | 673 | while (0 != (fRet = ::GetMessageW(&msg, NULL, 0, 0))) |
@@ -660,7 +675,7 @@ static DWORD WINAPI CoordinatorThread( | |||
660 | if (-1 == fRet) | 675 | if (-1 == fRet) |
661 | { | 676 | { |
662 | hr = E_UNEXPECTED; | 677 | hr = E_UNEXPECTED; |
663 | ExitOnRootFailure(hr, "Unexpected return value from message pump."); | 678 | MonExitOnRootFailure(hr, "Unexpected return value from message pump."); |
664 | } | 679 | } |
665 | else | 680 | else |
666 | { | 681 | { |
@@ -684,12 +699,12 @@ static DWORD WINAPI CoordinatorThread( | |||
684 | else | 699 | else |
685 | { | 700 | { |
686 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&pm->rgWaiterThreads), pm->cWaiterThreads + 1, sizeof(MON_WAITER_INFO), MON_THREAD_GROWTH); | 701 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&pm->rgWaiterThreads), pm->cWaiterThreads + 1, sizeof(MON_WAITER_INFO), MON_THREAD_GROWTH); |
687 | ExitOnFailure(hr, "Failed to grow waiter thread array size"); | 702 | MonExitOnFailure(hr, "Failed to grow waiter thread array size"); |
688 | ++pm->cWaiterThreads; | 703 | ++pm->cWaiterThreads; |
689 | 704 | ||
690 | dwThreadIndex = pm->cWaiterThreads - 1; | 705 | dwThreadIndex = pm->cWaiterThreads - 1; |
691 | pm->rgWaiterThreads[dwThreadIndex].pWaiterContext = reinterpret_cast<MON_WAITER_CONTEXT*>(MemAlloc(sizeof(MON_WAITER_CONTEXT), TRUE)); | 706 | pm->rgWaiterThreads[dwThreadIndex].pWaiterContext = reinterpret_cast<MON_WAITER_CONTEXT*>(MemAlloc(sizeof(MON_WAITER_CONTEXT), TRUE)); |
692 | ExitOnNull(pm->rgWaiterThreads[dwThreadIndex].pWaiterContext, hr, E_OUTOFMEMORY, "Failed to allocate waiter context struct"); | 707 | MonExitOnNull(pm->rgWaiterThreads[dwThreadIndex].pWaiterContext, hr, E_OUTOFMEMORY, "Failed to allocate waiter context struct"); |
693 | pWaiterContext = pm->rgWaiterThreads[dwThreadIndex].pWaiterContext; | 708 | pWaiterContext = pm->rgWaiterThreads[dwThreadIndex].pWaiterContext; |
694 | pWaiterContext->dwCoordinatorThreadId = ::GetCurrentThreadId(); | 709 | pWaiterContext->dwCoordinatorThreadId = ::GetCurrentThreadId(); |
695 | pWaiterContext->vpfMonGeneral = pm->vpfMonGeneral; | 710 | pWaiterContext->vpfMonGeneral = pm->vpfMonGeneral; |
@@ -698,16 +713,16 @@ static DWORD WINAPI CoordinatorThread( | |||
698 | pWaiterContext->pvContext = pm->pvContext; | 713 | pWaiterContext->pvContext = pm->pvContext; |
699 | 714 | ||
700 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&pWaiterContext->rgHandles), MON_MAX_MONITORS_PER_THREAD + 1, sizeof(HANDLE), 0); | 715 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&pWaiterContext->rgHandles), MON_MAX_MONITORS_PER_THREAD + 1, sizeof(HANDLE), 0); |
701 | ExitOnFailure(hr, "Failed to allocate first handle"); | 716 | MonExitOnFailure(hr, "Failed to allocate first handle"); |
702 | pWaiterContext->cHandles = 1; | 717 | pWaiterContext->cHandles = 1; |
703 | 718 | ||
704 | pWaiterContext->rgHandles[0] = ::CreateEventW(NULL, FALSE, FALSE, NULL); | 719 | pWaiterContext->rgHandles[0] = ::CreateEventW(NULL, FALSE, FALSE, NULL); |
705 | ExitOnNullWithLastError(pWaiterContext->rgHandles[0], hr, "Failed to create general event"); | 720 | MonExitOnNullWithLastError(pWaiterContext->rgHandles[0], hr, "Failed to create general event"); |
706 | 721 | ||
707 | pWaiterContext->hWaiterThread = ::CreateThread(NULL, 0, WaiterThread, pWaiterContext, 0, &pWaiterContext->dwWaiterThreadId); | 722 | pWaiterContext->hWaiterThread = ::CreateThread(NULL, 0, WaiterThread, pWaiterContext, 0, &pWaiterContext->dwWaiterThreadId); |
708 | if (!pWaiterContext->hWaiterThread) | 723 | if (!pWaiterContext->hWaiterThread) |
709 | { | 724 | { |
710 | ExitWithLastError(hr, "Failed to create waiter thread."); | 725 | MonExitWithLastError(hr, "Failed to create waiter thread."); |
711 | } | 726 | } |
712 | 727 | ||
713 | dwRetries = MON_THREAD_INIT_RETRIES; | 728 | dwRetries = MON_THREAD_INIT_RETRIES; |
@@ -720,19 +735,19 @@ static DWORD WINAPI CoordinatorThread( | |||
720 | if (0 == dwRetries) | 735 | if (0 == dwRetries) |
721 | { | 736 | { |
722 | hr = E_UNEXPECTED; | 737 | hr = E_UNEXPECTED; |
723 | ExitOnFailure(hr, "Waiter thread apparently never initialized its message queue."); | 738 | MonExitOnFailure(hr, "Waiter thread apparently never initialized its message queue."); |
724 | } | 739 | } |
725 | } | 740 | } |
726 | 741 | ||
727 | ++pm->rgWaiterThreads[dwThreadIndex].cMonitorCount; | 742 | ++pm->rgWaiterThreads[dwThreadIndex].cMonitorCount; |
728 | if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_ADD, msg.wParam, 0)) | 743 | if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_ADD, msg.wParam, 0)) |
729 | { | 744 | { |
730 | ExitWithLastError(hr, "Failed to send message to waiter thread to add monitor"); | 745 | MonExitWithLastError(hr, "Failed to send message to waiter thread to add monitor"); |
731 | } | 746 | } |
732 | 747 | ||
733 | if (!::SetEvent(pWaiterContext->rgHandles[0])) | 748 | if (!::SetEvent(pWaiterContext->rgHandles[0])) |
734 | { | 749 | { |
735 | ExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming message"); | 750 | MonExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming message"); |
736 | } | 751 | } |
737 | break; | 752 | break; |
738 | 753 | ||
@@ -746,17 +761,17 @@ static DWORD WINAPI CoordinatorThread( | |||
746 | pRemoveMessage = reinterpret_cast<MON_REMOVE_MESSAGE *>(msg.wParam); | 761 | pRemoveMessage = reinterpret_cast<MON_REMOVE_MESSAGE *>(msg.wParam); |
747 | 762 | ||
748 | hr = DuplicateRemoveMessage(pRemoveMessage, &pTempRemoveMessage); | 763 | hr = DuplicateRemoveMessage(pRemoveMessage, &pTempRemoveMessage); |
749 | ExitOnFailure(hr, "Failed to duplicate remove message"); | 764 | MonExitOnFailure(hr, "Failed to duplicate remove message"); |
750 | 765 | ||
751 | if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_REMOVE, reinterpret_cast<WPARAM>(pTempRemoveMessage), msg.lParam)) | 766 | if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_REMOVE, reinterpret_cast<WPARAM>(pTempRemoveMessage), msg.lParam)) |
752 | { | 767 | { |
753 | ExitWithLastError(hr, "Failed to send message to waiter thread to add monitor"); | 768 | MonExitWithLastError(hr, "Failed to send message to waiter thread to add monitor"); |
754 | } | 769 | } |
755 | pTempRemoveMessage = NULL; | 770 | pTempRemoveMessage = NULL; |
756 | 771 | ||
757 | if (!::SetEvent(pWaiterContext->rgHandles[0])) | 772 | if (!::SetEvent(pWaiterContext->rgHandles[0])) |
758 | { | 773 | { |
759 | ExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming remove message"); | 774 | MonExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming remove message"); |
760 | } | 775 | } |
761 | } | 776 | } |
762 | MonRemoveMessageDestroy(pRemoveMessage); | 777 | MonRemoveMessageDestroy(pRemoveMessage); |
@@ -774,7 +789,7 @@ static DWORD WINAPI CoordinatorThread( | |||
774 | { | 789 | { |
775 | if (!::PostThreadMessageW(pm->rgWaiterThreads[i].pWaiterContext->dwWaiterThreadId, MON_MESSAGE_STOP, msg.wParam, msg.lParam)) | 790 | if (!::PostThreadMessageW(pm->rgWaiterThreads[i].pWaiterContext->dwWaiterThreadId, MON_MESSAGE_STOP, msg.wParam, msg.lParam)) |
776 | { | 791 | { |
777 | ExitWithLastError(hr, "Failed to send message to waiter thread to stop"); | 792 | MonExitWithLastError(hr, "Failed to send message to waiter thread to stop"); |
778 | } | 793 | } |
779 | MemRemoveFromArray(reinterpret_cast<LPVOID>(pm->rgWaiterThreads), i, 1, pm->cWaiterThreads, sizeof(MON_WAITER_INFO), TRUE); | 794 | MemRemoveFromArray(reinterpret_cast<LPVOID>(pm->rgWaiterThreads), i, 1, pm->cWaiterThreads, sizeof(MON_WAITER_INFO), TRUE); |
780 | --pm->cWaiterThreads; | 795 | --pm->cWaiterThreads; |
@@ -790,7 +805,7 @@ static DWORD WINAPI CoordinatorThread( | |||
790 | uTimerFailedNetworkRetry = ::SetTimer(NULL, uTimerSuccessfulNetworkRetry + 1, MON_THREAD_NETWORK_FAIL_RETRY_IN_MS, NULL); | 805 | uTimerFailedNetworkRetry = ::SetTimer(NULL, uTimerSuccessfulNetworkRetry + 1, MON_THREAD_NETWORK_FAIL_RETRY_IN_MS, NULL); |
791 | if (0 == uTimerFailedNetworkRetry) | 806 | if (0 == uTimerFailedNetworkRetry) |
792 | { | 807 | { |
793 | ExitWithLastError(hr, "Failed to set timer for network fail retry"); | 808 | MonExitWithLastError(hr, "Failed to set timer for network fail retry"); |
794 | } | 809 | } |
795 | } | 810 | } |
796 | ++dwFailingNetworkWaits; | 811 | ++dwFailingNetworkWaits; |
@@ -802,7 +817,7 @@ static DWORD WINAPI CoordinatorThread( | |||
802 | { | 817 | { |
803 | if (!::KillTimer(NULL, uTimerFailedNetworkRetry)) | 818 | if (!::KillTimer(NULL, uTimerFailedNetworkRetry)) |
804 | { | 819 | { |
805 | ExitWithLastError(hr, "Failed to kill timer for network fail retry"); | 820 | MonExitWithLastError(hr, "Failed to kill timer for network fail retry"); |
806 | } | 821 | } |
807 | uTimerFailedNetworkRetry = 0; | 822 | uTimerFailedNetworkRetry = 0; |
808 | } | 823 | } |
@@ -810,7 +825,7 @@ static DWORD WINAPI CoordinatorThread( | |||
810 | 825 | ||
811 | case MON_MESSAGE_NETWORK_STATUS_UPDATE: | 826 | case MON_MESSAGE_NETWORK_STATUS_UPDATE: |
812 | hr = WaitForNetworkChanges(&hMonitor, pm); | 827 | hr = WaitForNetworkChanges(&hMonitor, pm); |
813 | ExitOnFailure(hr, "Failed to re-wait for network changes"); | 828 | MonExitOnFailure(hr, "Failed to re-wait for network changes"); |
814 | 829 | ||
815 | // Propagate any network status update messages to all waiter threads | 830 | // Propagate any network status update messages to all waiter threads |
816 | for (DWORD i = 0; i < pm->cWaiterThreads; ++i) | 831 | for (DWORD i = 0; i < pm->cWaiterThreads; ++i) |
@@ -819,12 +834,12 @@ static DWORD WINAPI CoordinatorThread( | |||
819 | 834 | ||
820 | if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_NETWORK_STATUS_UPDATE, 0, 0)) | 835 | if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_NETWORK_STATUS_UPDATE, 0, 0)) |
821 | { | 836 | { |
822 | ExitWithLastError(hr, "Failed to send message to waiter thread to notify of network status update"); | 837 | MonExitWithLastError(hr, "Failed to send message to waiter thread to notify of network status update"); |
823 | } | 838 | } |
824 | 839 | ||
825 | if (!::SetEvent(pWaiterContext->rgHandles[0])) | 840 | if (!::SetEvent(pWaiterContext->rgHandles[0])) |
826 | { | 841 | { |
827 | ExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming network status update message"); | 842 | MonExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming network status update message"); |
828 | } | 843 | } |
829 | } | 844 | } |
830 | break; | 845 | break; |
@@ -837,12 +852,12 @@ static DWORD WINAPI CoordinatorThread( | |||
837 | 852 | ||
838 | if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, msg.wParam == uTimerFailedNetworkRetry ? MON_MESSAGE_NETWORK_RETRY_FAILED_NETWORK_WAITS : MON_MESSAGE_NETWORK_RETRY_SUCCESSFUL_NETWORK_WAITS, 0, 0)) | 853 | if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, msg.wParam == uTimerFailedNetworkRetry ? MON_MESSAGE_NETWORK_RETRY_FAILED_NETWORK_WAITS : MON_MESSAGE_NETWORK_RETRY_SUCCESSFUL_NETWORK_WAITS, 0, 0)) |
839 | { | 854 | { |
840 | ExitWithLastError(hr, "Failed to send message to waiter thread to notify of network status update"); | 855 | MonExitWithLastError(hr, "Failed to send message to waiter thread to notify of network status update"); |
841 | } | 856 | } |
842 | 857 | ||
843 | if (!::SetEvent(pWaiterContext->rgHandles[0])) | 858 | if (!::SetEvent(pWaiterContext->rgHandles[0])) |
844 | { | 859 | { |
845 | ExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming network status update message"); | 860 | MonExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming network status update message"); |
846 | } | 861 | } |
847 | } | 862 | } |
848 | break; | 863 | break; |
@@ -861,12 +876,12 @@ static DWORD WINAPI CoordinatorThread( | |||
861 | 876 | ||
862 | if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_DRIVE_STATUS_UPDATE, msg.wParam, msg.lParam)) | 877 | if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_DRIVE_STATUS_UPDATE, msg.wParam, msg.lParam)) |
863 | { | 878 | { |
864 | ExitWithLastError(hr, "Failed to send message to waiter thread to notify of drive status update"); | 879 | MonExitWithLastError(hr, "Failed to send message to waiter thread to notify of drive status update"); |
865 | } | 880 | } |
866 | 881 | ||
867 | if (!::SetEvent(pWaiterContext->rgHandles[0])) | 882 | if (!::SetEvent(pWaiterContext->rgHandles[0])) |
868 | { | 883 | { |
869 | ExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming drive status update message"); | 884 | MonExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming drive status update message"); |
870 | } | 885 | } |
871 | } | 886 | } |
872 | break; | 887 | break; |
@@ -998,7 +1013,7 @@ static HRESULT InitiateWait( | |||
998 | { | 1013 | { |
999 | continue; | 1014 | continue; |
1000 | } | 1015 | } |
1001 | ExitOnWin32Error(er, hr, "Failed to wait on path %ls", pRequest->rgsczPathHierarchy[dwIndex]); | 1016 | MonExitOnWin32Error(er, hr, "Failed to wait on path %ls", pRequest->rgsczPathHierarchy[dwIndex]); |
1002 | } | 1017 | } |
1003 | else | 1018 | else |
1004 | { | 1019 | { |
@@ -1013,7 +1028,7 @@ static HRESULT InitiateWait( | |||
1013 | { | 1028 | { |
1014 | continue; | 1029 | continue; |
1015 | } | 1030 | } |
1016 | ExitOnFailure(hr, "Failed to open regkey %ls", pRequest->rgsczPathHierarchy[dwIndex]); | 1031 | MonExitOnFailure(hr, "Failed to open regkey %ls", pRequest->rgsczPathHierarchy[dwIndex]); |
1017 | 1032 | ||
1018 | er = ::RegNotifyChangeKeyValue(pRequest->regkey.hkSubKey, GetRecursiveFlag(pRequest, dwIndex), REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY, *pHandle, TRUE); | 1033 | er = ::RegNotifyChangeKeyValue(pRequest->regkey.hkSubKey, GetRecursiveFlag(pRequest, dwIndex), REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY, *pHandle, TRUE); |
1019 | ReleaseRegKey(hk); | 1034 | ReleaseRegKey(hk); |
@@ -1024,7 +1039,7 @@ static HRESULT InitiateWait( | |||
1024 | } | 1039 | } |
1025 | else | 1040 | else |
1026 | { | 1041 | { |
1027 | ExitOnWin32Error(er, hr, "Failed to wait on subkey %ls", pRequest->rgsczPathHierarchy[dwIndex]); | 1042 | MonExitOnWin32Error(er, hr, "Failed to wait on subkey %ls", pRequest->rgsczPathHierarchy[dwIndex]); |
1028 | 1043 | ||
1029 | fHandleFound = TRUE; | 1044 | fHandleFound = TRUE; |
1030 | } | 1045 | } |
@@ -1062,7 +1077,7 @@ static HRESULT InitiateWait( | |||
1062 | } | 1077 | } |
1063 | } while (fRedo); | 1078 | } while (fRedo); |
1064 | 1079 | ||
1065 | ExitOnFailure(hr, "Didn't get a successful wait after looping through all available options %ls", pRequest->rgsczPathHierarchy[pRequest->cPathHierarchy - 1]); | 1080 | MonExitOnFailure(hr, "Didn't get a successful wait after looping through all available options %ls", pRequest->rgsczPathHierarchy[pRequest->cPathHierarchy - 1]); |
1066 | 1081 | ||
1067 | if (MON_DIRECTORY == pRequest->type) | 1082 | if (MON_DIRECTORY == pRequest->type) |
1068 | { | 1083 | { |
@@ -1141,7 +1156,7 @@ static DWORD WINAPI WaiterThread( | |||
1141 | } | 1156 | } |
1142 | 1157 | ||
1143 | hr = MemInsertIntoArray(reinterpret_cast<void **>(&pWaiterContext->rgHandles), dwNewRequestIndex + 1, 1, pWaiterContext->cHandles, sizeof(HANDLE), MON_ARRAY_GROWTH); | 1158 | hr = MemInsertIntoArray(reinterpret_cast<void **>(&pWaiterContext->rgHandles), dwNewRequestIndex + 1, 1, pWaiterContext->cHandles, sizeof(HANDLE), MON_ARRAY_GROWTH); |
1144 | ExitOnFailure(hr, "Failed to insert additional handle"); | 1159 | MonExitOnFailure(hr, "Failed to insert additional handle"); |
1145 | ++pWaiterContext->cHandles; | 1160 | ++pWaiterContext->cHandles; |
1146 | 1161 | ||
1147 | // Ugh - directory types start with INVALID_HANDLE_VALUE instead of NULL | 1162 | // Ugh - directory types start with INVALID_HANDLE_VALUE instead of NULL |
@@ -1151,7 +1166,7 @@ static DWORD WINAPI WaiterThread( | |||
1151 | } | 1166 | } |
1152 | 1167 | ||
1153 | hr = MemInsertIntoArray(reinterpret_cast<void **>(&pWaiterContext->rgRequests), dwNewRequestIndex, 1, pWaiterContext->cRequests, sizeof(MON_REQUEST), MON_ARRAY_GROWTH); | 1168 | hr = MemInsertIntoArray(reinterpret_cast<void **>(&pWaiterContext->rgRequests), dwNewRequestIndex, 1, pWaiterContext->cRequests, sizeof(MON_REQUEST), MON_ARRAY_GROWTH); |
1154 | ExitOnFailure(hr, "Failed to insert additional request struct"); | 1169 | MonExitOnFailure(hr, "Failed to insert additional request struct"); |
1155 | ++pWaiterContext->cRequests; | 1170 | ++pWaiterContext->cRequests; |
1156 | 1171 | ||
1157 | pWaiterContext->rgRequests[dwNewRequestIndex] = pAddMessage->request; | 1172 | pWaiterContext->rgRequests[dwNewRequestIndex] = pAddMessage->request; |
@@ -1172,10 +1187,10 @@ static DWORD WINAPI WaiterThread( | |||
1172 | } | 1187 | } |
1173 | else | 1188 | else |
1174 | { | 1189 | { |
1175 | ExitOnFailure(hr, "Failed to find request index for remove message"); | 1190 | MonExitOnFailure(hr, "Failed to find request index for remove message"); |
1176 | 1191 | ||
1177 | hr = RemoveRequest(pWaiterContext, dwRequestIndex); | 1192 | hr = RemoveRequest(pWaiterContext, dwRequestIndex); |
1178 | ExitOnFailure(hr, "Failed to remove request after request from coordinator thread."); | 1193 | MonExitOnFailure(hr, "Failed to remove request after request from coordinator thread."); |
1179 | } | 1194 | } |
1180 | 1195 | ||
1181 | MonRemoveMessageDestroy(pRemoveMessage); | 1196 | MonRemoveMessageDestroy(pRemoveMessage); |
@@ -1204,7 +1219,7 @@ static DWORD WINAPI WaiterThread( | |||
1204 | hrTemp = InitiateWait(pWaiterContext->rgRequests + i, pWaiterContext->rgHandles + i + 1); | 1219 | hrTemp = InitiateWait(pWaiterContext->rgRequests + i, pWaiterContext->rgHandles + i + 1); |
1205 | 1220 | ||
1206 | hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex); | 1221 | hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex); |
1207 | ExitOnFailure(hr, "Failed to update wait status"); | 1222 | MonExitOnFailure(hr, "Failed to update wait status"); |
1208 | hrTemp = S_OK; | 1223 | hrTemp = S_OK; |
1209 | 1224 | ||
1210 | if (dwNewRequestIndex != i) | 1225 | if (dwNewRequestIndex != i) |
@@ -1239,7 +1254,7 @@ static DWORD WINAPI WaiterThread( | |||
1239 | hrTemp = InitiateWait(pWaiterContext->rgRequests + i, pWaiterContext->rgHandles + i + 1); | 1254 | hrTemp = InitiateWait(pWaiterContext->rgRequests + i, pWaiterContext->rgHandles + i + 1); |
1240 | 1255 | ||
1241 | hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex); | 1256 | hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex); |
1242 | ExitOnFailure(hr, "Failed to update wait status"); | 1257 | MonExitOnFailure(hr, "Failed to update wait status"); |
1243 | hrTemp = S_OK; | 1258 | hrTemp = S_OK; |
1244 | 1259 | ||
1245 | if (dwNewRequestIndex != i) | 1260 | if (dwNewRequestIndex != i) |
@@ -1274,7 +1289,7 @@ static DWORD WINAPI WaiterThread( | |||
1274 | hrTemp = InitiateWait(pWaiterContext->rgRequests + i, pWaiterContext->rgHandles + i + 1); | 1289 | hrTemp = InitiateWait(pWaiterContext->rgRequests + i, pWaiterContext->rgHandles + i + 1); |
1275 | 1290 | ||
1276 | hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex); | 1291 | hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex); |
1277 | ExitOnFailure(hr, "Failed to update wait status"); | 1292 | MonExitOnFailure(hr, "Failed to update wait status"); |
1278 | hrTemp = S_OK; | 1293 | hrTemp = S_OK; |
1279 | 1294 | ||
1280 | if (dwNewRequestIndex != i) | 1295 | if (dwNewRequestIndex != i) |
@@ -1311,7 +1326,7 @@ static DWORD WINAPI WaiterThread( | |||
1311 | } | 1326 | } |
1312 | 1327 | ||
1313 | hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex); | 1328 | hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex); |
1314 | ExitOnFailure(hr, "Failed to update wait status"); | 1329 | MonExitOnFailure(hr, "Failed to update wait status"); |
1315 | hrTemp = S_OK; | 1330 | hrTemp = S_OK; |
1316 | 1331 | ||
1317 | if (dwNewRequestIndex != i) | 1332 | if (dwNewRequestIndex != i) |
@@ -1354,7 +1369,7 @@ static DWORD WINAPI WaiterThread( | |||
1354 | hrTemp = E_PATHNOTFOUND; | 1369 | hrTemp = E_PATHNOTFOUND; |
1355 | 1370 | ||
1356 | hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex); | 1371 | hr = UpdateWaitStatus(hrTemp, pWaiterContext, i, &dwNewRequestIndex); |
1357 | ExitOnFailure(hr, "Failed to update wait status"); | 1372 | MonExitOnFailure(hr, "Failed to update wait status"); |
1358 | hrTemp = S_OK; | 1373 | hrTemp = S_OK; |
1359 | break; | 1374 | break; |
1360 | } | 1375 | } |
@@ -1385,7 +1400,7 @@ static DWORD WINAPI WaiterThread( | |||
1385 | // Initiate re-waits before we notify callback, to ensure we don't miss a single update | 1400 | // Initiate re-waits before we notify callback, to ensure we don't miss a single update |
1386 | hrTemp = InitiateWait(pWaiterContext->rgRequests + dwRequestIndex, pWaiterContext->rgHandles + dwRequestIndex + 1); | 1401 | hrTemp = InitiateWait(pWaiterContext->rgRequests + dwRequestIndex, pWaiterContext->rgHandles + dwRequestIndex + 1); |
1387 | hr = UpdateWaitStatus(hrTemp, pWaiterContext, dwRequestIndex, &dwRequestIndex); | 1402 | hr = UpdateWaitStatus(hrTemp, pWaiterContext, dwRequestIndex, &dwRequestIndex); |
1388 | ExitOnFailure(hr, "Failed to update wait status"); | 1403 | MonExitOnFailure(hr, "Failed to update wait status"); |
1389 | hrTemp = S_OK; | 1404 | hrTemp = S_OK; |
1390 | 1405 | ||
1391 | // If there were no errors and we were already waiting on the right target, or if we weren't yet but are able to now, it's a successful notify | 1406 | // If there were no errors and we were already waiting on the right target, or if we weren't yet but are able to now, it's a successful notify |
@@ -1413,7 +1428,7 @@ static DWORD WINAPI WaiterThread( | |||
1413 | } | 1428 | } |
1414 | else if (WAIT_TIMEOUT != dwRet) | 1429 | else if (WAIT_TIMEOUT != dwRet) |
1415 | { | 1430 | { |
1416 | ExitWithLastError(hr, "Failed to wait for multiple objects with return code %u", dwRet); | 1431 | MonExitWithLastError(hr, "Failed to wait for multiple objects with return code %u", dwRet); |
1417 | } | 1432 | } |
1418 | 1433 | ||
1419 | // OK, now that we've checked all triggered handles (resetting silence period timers appropriately), check for any pending notifications that we can finally fire | 1434 | // OK, now that we've checked all triggered handles (resetting silence period timers appropriately), check for any pending notifications that we can finally fire |
@@ -1432,7 +1447,7 @@ static DWORD WINAPI WaiterThread( | |||
1432 | { | 1447 | { |
1433 | Assert(FALSE); | 1448 | Assert(FALSE); |
1434 | hr = HRESULT_FROM_WIN32(ERROR_EA_LIST_INCONSISTENT); | 1449 | hr = HRESULT_FROM_WIN32(ERROR_EA_LIST_INCONSISTENT); |
1435 | ExitOnFailure(hr, "Phantom pending fires were found!"); | 1450 | MonExitOnFailure(hr, "Phantom pending fires were found!"); |
1436 | } | 1451 | } |
1437 | --cRequestsPendingBeforeLoop; | 1452 | --cRequestsPendingBeforeLoop; |
1438 | 1453 | ||
@@ -1470,13 +1485,13 @@ static DWORD WINAPI WaiterThread( | |||
1470 | { | 1485 | { |
1471 | Assert(FALSE); | 1486 | Assert(FALSE); |
1472 | hr = HRESULT_FROM_WIN32(PEERDIST_ERROR_MISSING_DATA); | 1487 | hr = HRESULT_FROM_WIN32(PEERDIST_ERROR_MISSING_DATA); |
1473 | ExitOnFailure(hr, "Missing %u pending fires! Total pending fires: %u, wait: %u", cRequestsPendingBeforeLoop, pWaiterContext->cRequestsPending, dwWait); | 1488 | MonExitOnFailure(hr, "Missing %u pending fires! Total pending fires: %u, wait: %u", cRequestsPendingBeforeLoop, pWaiterContext->cRequestsPending, dwWait); |
1474 | } | 1489 | } |
1475 | if (0 < pWaiterContext->cRequestsPending && DWORD_MAX == dwWait) | 1490 | if (0 < pWaiterContext->cRequestsPending && DWORD_MAX == dwWait) |
1476 | { | 1491 | { |
1477 | Assert(FALSE); | 1492 | Assert(FALSE); |
1478 | hr = HRESULT_FROM_WIN32(ERROR_CANT_WAIT); | 1493 | hr = HRESULT_FROM_WIN32(ERROR_CANT_WAIT); |
1479 | ExitOnFailure(hr, "Pending fires exist, but wait was infinite", cRequestsPendingBeforeLoop); | 1494 | MonExitOnFailure(hr, "Pending fires exist (%u), but wait was infinite", cRequestsPendingBeforeLoop); |
1480 | } | 1495 | } |
1481 | } | 1496 | } |
1482 | } while (fContinue); | 1497 | } while (fContinue); |
@@ -1651,7 +1666,7 @@ static HRESULT RemoveRequest( | |||
1651 | // Notify coordinator thread that a wait was removed | 1666 | // Notify coordinator thread that a wait was removed |
1652 | if (!::PostThreadMessageW(pWaiterContext->dwCoordinatorThreadId, MON_MESSAGE_REMOVED, static_cast<WPARAM>(::GetCurrentThreadId()), 0)) | 1667 | if (!::PostThreadMessageW(pWaiterContext->dwCoordinatorThreadId, MON_MESSAGE_REMOVED, static_cast<WPARAM>(::GetCurrentThreadId()), 0)) |
1653 | { | 1668 | { |
1654 | ExitWithLastError(hr, "Failed to send message to coordinator thread to confirm directory was removed."); | 1669 | MonExitWithLastError(hr, "Failed to send message to coordinator thread to confirm directory was removed."); |
1655 | } | 1670 | } |
1656 | 1671 | ||
1657 | LExit: | 1672 | LExit: |
@@ -1684,7 +1699,7 @@ static HRESULT DuplicateRemoveMessage( | |||
1684 | HRESULT hr = S_OK; | 1699 | HRESULT hr = S_OK; |
1685 | 1700 | ||
1686 | *ppMessage = reinterpret_cast<MON_REMOVE_MESSAGE *>(MemAlloc(sizeof(MON_REMOVE_MESSAGE), TRUE)); | 1701 | *ppMessage = reinterpret_cast<MON_REMOVE_MESSAGE *>(MemAlloc(sizeof(MON_REMOVE_MESSAGE), TRUE)); |
1687 | ExitOnNull(*ppMessage, hr, E_OUTOFMEMORY, "Failed to allocate copy of remove message"); | 1702 | MonExitOnNull(*ppMessage, hr, E_OUTOFMEMORY, "Failed to allocate copy of remove message"); |
1688 | 1703 | ||
1689 | (*ppMessage)->type = pMessage->type; | 1704 | (*ppMessage)->type = pMessage->type; |
1690 | (*ppMessage)->fRecursive = pMessage->fRecursive; | 1705 | (*ppMessage)->fRecursive = pMessage->fRecursive; |
@@ -1693,13 +1708,13 @@ static HRESULT DuplicateRemoveMessage( | |||
1693 | { | 1708 | { |
1694 | case MON_DIRECTORY: | 1709 | case MON_DIRECTORY: |
1695 | hr = StrAllocString(&(*ppMessage)->directory.sczDirectory, pMessage->directory.sczDirectory, 0); | 1710 | hr = StrAllocString(&(*ppMessage)->directory.sczDirectory, pMessage->directory.sczDirectory, 0); |
1696 | ExitOnFailure(hr, "Failed to copy directory"); | 1711 | MonExitOnFailure(hr, "Failed to copy directory"); |
1697 | break; | 1712 | break; |
1698 | case MON_REGKEY: | 1713 | case MON_REGKEY: |
1699 | (*ppMessage)->regkey.hkRoot = pMessage->regkey.hkRoot; | 1714 | (*ppMessage)->regkey.hkRoot = pMessage->regkey.hkRoot; |
1700 | (*ppMessage)->regkey.kbKeyBitness = pMessage->regkey.kbKeyBitness; | 1715 | (*ppMessage)->regkey.kbKeyBitness = pMessage->regkey.kbKeyBitness; |
1701 | hr = StrAllocString(&(*ppMessage)->regkey.sczSubKey, pMessage->regkey.sczSubKey, 0); | 1716 | hr = StrAllocString(&(*ppMessage)->regkey.sczSubKey, pMessage->regkey.sczSubKey, 0); |
1702 | ExitOnFailure(hr, "Failed to copy subkey"); | 1717 | MonExitOnFailure(hr, "Failed to copy subkey"); |
1703 | break; | 1718 | break; |
1704 | default: | 1719 | default: |
1705 | Assert(false); | 1720 | Assert(false); |
@@ -1764,7 +1779,7 @@ static LRESULT CALLBACK MonWndProc( | |||
1764 | // This drive had a status update, so send it out to all threads | 1779 | // This drive had a status update, so send it out to all threads |
1765 | if (!::PostThreadMessageW(::GetCurrentThreadId(), MON_MESSAGE_DRIVE_STATUS_UPDATE, static_cast<WPARAM>(chDrive), static_cast<LPARAM>(fArrival))) | 1780 | if (!::PostThreadMessageW(::GetCurrentThreadId(), MON_MESSAGE_DRIVE_STATUS_UPDATE, static_cast<WPARAM>(chDrive), static_cast<LPARAM>(fArrival))) |
1766 | { | 1781 | { |
1767 | ExitWithLastError(hr, "Failed to send drive status update with drive %wc and arrival %ls", chDrive, fArrival ? L"TRUE" : L"FALSE"); | 1782 | MonExitWithLastError(hr, "Failed to send drive status update with drive %wc and arrival %ls", chDrive, fArrival ? L"TRUE" : L"FALSE"); |
1768 | } | 1783 | } |
1769 | } | 1784 | } |
1770 | dwUnitMask >>= 1; | 1785 | dwUnitMask >>= 1; |
@@ -1773,7 +1788,7 @@ static LRESULT CALLBACK MonWndProc( | |||
1773 | if (chDrive == 'z') | 1788 | if (chDrive == 'z') |
1774 | { | 1789 | { |
1775 | hr = E_UNEXPECTED; | 1790 | hr = E_UNEXPECTED; |
1776 | ExitOnFailure(hr, "UnitMask showed drives beyond z:. Remaining UnitMask at this point: %u", dwUnitMask); | 1791 | MonExitOnFailure(hr, "UnitMask showed drives beyond z:. Remaining UnitMask at this point: %u", dwUnitMask); |
1777 | } | 1792 | } |
1778 | } | 1793 | } |
1779 | } | 1794 | } |
@@ -1785,7 +1800,7 @@ static LRESULT CALLBACK MonWndProc( | |||
1785 | if (!pm) | 1800 | if (!pm) |
1786 | { | 1801 | { |
1787 | hr = E_POINTER; | 1802 | hr = E_POINTER; |
1788 | ExitOnFailure(hr, "DBT_DEVICEQUERYREMOVE message received with no MON_STRUCT pointer, so message was ignored"); | 1803 | MonExitOnFailure(hr, "DBT_DEVICEQUERYREMOVE message received with no MON_STRUCT pointer, so message was ignored"); |
1789 | } | 1804 | } |
1790 | 1805 | ||
1791 | fReturnTrue = TRUE; | 1806 | fReturnTrue = TRUE; |
@@ -1796,7 +1811,7 @@ static LRESULT CALLBACK MonWndProc( | |||
1796 | // We must wait for the actual wait handle to be released by waiter thread before telling windows to proceed with device removal, otherwise it could fail | 1811 | // We must wait for the actual wait handle to be released by waiter thread before telling windows to proceed with device removal, otherwise it could fail |
1797 | // due to handles still being open, so use a MON_INTERNAL_TEMPORARY_WAIT struct to send and receive a reply from a waiter thread | 1812 | // due to handles still being open, so use a MON_INTERNAL_TEMPORARY_WAIT struct to send and receive a reply from a waiter thread |
1798 | pm->internalWait.hWait = ::CreateEventW(NULL, TRUE, FALSE, NULL); | 1813 | pm->internalWait.hWait = ::CreateEventW(NULL, TRUE, FALSE, NULL); |
1799 | ExitOnNullWithLastError(pm->internalWait.hWait, hr, "Failed to create anonymous event for waiter to notify wndproc device can be removed"); | 1814 | MonExitOnNullWithLastError(pm->internalWait.hWait, hr, "Failed to create anonymous event for waiter to notify wndproc device can be removed"); |
1800 | 1815 | ||
1801 | pHandle = reinterpret_cast<DEV_BROADCAST_HANDLE*>(lParam); | 1816 | pHandle = reinterpret_cast<DEV_BROADCAST_HANDLE*>(lParam); |
1802 | pm->internalWait.pvContext = pHandle->dbch_handle; | 1817 | pm->internalWait.pvContext = pHandle->dbch_handle; |
@@ -1808,12 +1823,12 @@ static LRESULT CALLBACK MonWndProc( | |||
1808 | 1823 | ||
1809 | if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_DRIVE_QUERY_REMOVE, reinterpret_cast<WPARAM>(&pm->internalWait), static_cast<LPARAM>(pm->internalWait.dwSendIteration))) | 1824 | if (!::PostThreadMessageW(pWaiterContext->dwWaiterThreadId, MON_MESSAGE_DRIVE_QUERY_REMOVE, reinterpret_cast<WPARAM>(&pm->internalWait), static_cast<LPARAM>(pm->internalWait.dwSendIteration))) |
1810 | { | 1825 | { |
1811 | ExitWithLastError(hr, "Failed to send message to waiter thread to notify of drive query remove"); | 1826 | MonExitWithLastError(hr, "Failed to send message to waiter thread to notify of drive query remove"); |
1812 | } | 1827 | } |
1813 | 1828 | ||
1814 | if (!::SetEvent(pWaiterContext->rgHandles[0])) | 1829 | if (!::SetEvent(pWaiterContext->rgHandles[0])) |
1815 | { | 1830 | { |
1816 | ExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming drive query remove message"); | 1831 | MonExitWithLastError(hr, "Failed to set event to notify waiter thread of incoming drive query remove message"); |
1817 | } | 1832 | } |
1818 | } | 1833 | } |
1819 | 1834 | ||
@@ -1833,7 +1848,7 @@ static LRESULT CALLBACK MonWndProc( | |||
1833 | } | 1848 | } |
1834 | else | 1849 | else |
1835 | { | 1850 | { |
1836 | ExitWithLastError(hr, "WaitForSingleObject failed with non-timeout reason while waiting for response from waiter thread"); | 1851 | MonExitWithLastError(hr, "WaitForSingleObject failed with non-timeout reason while waiting for response from waiter thread"); |
1837 | } | 1852 | } |
1838 | ++pm->internalWait.dwSendIteration; | 1853 | ++pm->internalWait.dwSendIteration; |
1839 | } | 1854 | } |
@@ -1871,12 +1886,12 @@ static HRESULT CreateMonWindow( | |||
1871 | { | 1886 | { |
1872 | if (ERROR_CLASS_ALREADY_EXISTS != ::GetLastError()) | 1887 | if (ERROR_CLASS_ALREADY_EXISTS != ::GetLastError()) |
1873 | { | 1888 | { |
1874 | ExitWithLastError(hr, "Failed to register MonUtil window class."); | 1889 | MonExitWithLastError(hr, "Failed to register MonUtil window class."); |
1875 | } | 1890 | } |
1876 | } | 1891 | } |
1877 | 1892 | ||
1878 | *pHwnd = ::CreateWindowExW(0, wc.lpszClassName, L"", 0, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, HWND_DESKTOP, NULL, wc.hInstance, pm); | 1893 | *pHwnd = ::CreateWindowExW(0, wc.lpszClassName, L"", 0, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, HWND_DESKTOP, NULL, wc.hInstance, pm); |
1879 | ExitOnNullWithLastError(*pHwnd, hr, "Failed to create window."); | 1894 | MonExitOnNullWithLastError(*pHwnd, hr, "Failed to create window."); |
1880 | 1895 | ||
1881 | // Rumor has it that drive arrival / removal events can be lost in the rare event that some other application higher up in z-order is hanging if we don't make our window topmost | 1896 | // Rumor has it that drive arrival / removal events can be lost in the rare event that some other application higher up in z-order is hanging if we don't make our window topmost |
1882 | // SWP_NOACTIVATE is important so the currently active window doesn't lose focus | 1897 | // SWP_NOACTIVATE is important so the currently active window doesn't lose focus |
@@ -1909,7 +1924,7 @@ static HRESULT WaitForNetworkChanges( | |||
1909 | if (::WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL, phMonitor)) | 1924 | if (::WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL, phMonitor)) |
1910 | { | 1925 | { |
1911 | hr = HRESULT_FROM_WIN32(::WSAGetLastError()); | 1926 | hr = HRESULT_FROM_WIN32(::WSAGetLastError()); |
1912 | ExitOnFailure(hr, "WSALookupServiceBegin() failed"); | 1927 | MonExitOnFailure(hr, "WSALookupServiceBegin() failed"); |
1913 | } | 1928 | } |
1914 | 1929 | ||
1915 | wsaCompletion.Type = NSP_NOTIFY_HWND; | 1930 | wsaCompletion.Type = NSP_NOTIFY_HWND; |
@@ -1923,7 +1938,7 @@ static HRESULT WaitForNetworkChanges( | |||
1923 | { | 1938 | { |
1924 | hr = E_FAIL; | 1939 | hr = E_FAIL; |
1925 | } | 1940 | } |
1926 | ExitOnFailure(hr, "WSANSPIoctl() failed with return code %i, wsa last error %u", nResult, ::WSAGetLastError()); | 1941 | MonExitOnFailure(hr, "WSANSPIoctl() failed with return code %i, wsa last error %u", nResult, ::WSAGetLastError()); |
1927 | } | 1942 | } |
1928 | 1943 | ||
1929 | LExit: | 1944 | LExit: |
@@ -1960,7 +1975,7 @@ static HRESULT UpdateWaitStatus( | |||
1960 | // If it's a network wait, notify coordinator thread that a network wait is failing | 1975 | // If it's a network wait, notify coordinator thread that a network wait is failing |
1961 | if (pRequest->fNetwork && !::PostThreadMessageW(pWaiterContext->dwCoordinatorThreadId, MON_MESSAGE_NETWORK_WAIT_FAILED, 0, 0)) | 1976 | if (pRequest->fNetwork && !::PostThreadMessageW(pWaiterContext->dwCoordinatorThreadId, MON_MESSAGE_NETWORK_WAIT_FAILED, 0, 0)) |
1962 | { | 1977 | { |
1963 | ExitWithLastError(hr, "Failed to send message to coordinator thread to notify a network wait started to fail"); | 1978 | MonExitWithLastError(hr, "Failed to send message to coordinator thread to notify a network wait started to fail"); |
1964 | } | 1979 | } |
1965 | 1980 | ||
1966 | // Move the failing wait to the end of the list of waits and increment cRequestsFailing so WaitForMultipleObjects isn't passed an invalid handle | 1981 | // Move the failing wait to the end of the list of waits and increment cRequestsFailing so WaitForMultipleObjects isn't passed an invalid handle |
@@ -1981,7 +1996,7 @@ static HRESULT UpdateWaitStatus( | |||
1981 | // If it's a network wait, notify coordinator thread that a network wait is succeeding again | 1996 | // If it's a network wait, notify coordinator thread that a network wait is succeeding again |
1982 | if (pRequest->fNetwork && !::PostThreadMessageW(pWaiterContext->dwCoordinatorThreadId, MON_MESSAGE_NETWORK_WAIT_SUCCEEDED, 0, 0)) | 1997 | if (pRequest->fNetwork && !::PostThreadMessageW(pWaiterContext->dwCoordinatorThreadId, MON_MESSAGE_NETWORK_WAIT_SUCCEEDED, 0, 0)) |
1983 | { | 1998 | { |
1984 | ExitWithLastError(hr, "Failed to send message to coordinator thread to notify a network wait is succeeding again"); | 1999 | MonExitWithLastError(hr, "Failed to send message to coordinator thread to notify a network wait is succeeding again"); |
1985 | } | 2000 | } |
1986 | 2001 | ||
1987 | --pWaiterContext->cRequestsFailing; | 2002 | --pWaiterContext->cRequestsFailing; |
diff --git a/src/dutil/osutil.cpp b/src/dutil/osutil.cpp index 8834cd30..880ec3ea 100644 --- a/src/dutil/osutil.cpp +++ b/src/dutil/osutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define OsExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__) | ||
8 | #define OsExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__) | ||
9 | #define OsExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__) | ||
10 | #define OsExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__) | ||
11 | #define OsExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__) | ||
12 | #define OsExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__) | ||
13 | #define OsExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_OSUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define OsExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_OSUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define OsExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_OSUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define OsExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_OSUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define OsExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_OSUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define OsExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_OSUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | typedef NTSTATUS(NTAPI* PFN_RTL_GET_VERSION)(_Out_ PRTL_OSVERSIONINFOEXW lpVersionInformation); | 20 | typedef NTSTATUS(NTAPI* PFN_RTL_GET_VERSION)(_Out_ PRTL_OSVERSIONINFOEXW lpVersionInformation); |
6 | 21 | ||
7 | OS_VERSION vOsVersion = OS_VERSION_UNKNOWN; | 22 | OS_VERSION vOsVersion = OS_VERSION_UNKNOWN; |
@@ -127,7 +142,7 @@ extern "C" HRESULT DAPI OsIsRunningPrivileged( | |||
127 | 142 | ||
128 | if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &hToken)) | 143 | if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &hToken)) |
129 | { | 144 | { |
130 | ExitOnLastError(hr, "Failed to open process token."); | 145 | OsExitOnLastError(hr, "Failed to open process token."); |
131 | } | 146 | } |
132 | 147 | ||
133 | if (::GetTokenInformation(hToken, TokenElevationType, &elevationType, sizeof(TOKEN_ELEVATION_TYPE), &dwSize)) | 148 | if (::GetTokenInformation(hToken, TokenElevationType, &elevationType, sizeof(TOKEN_ELEVATION_TYPE), &dwSize)) |
@@ -142,7 +157,7 @@ extern "C" HRESULT DAPI OsIsRunningPrivileged( | |||
142 | { | 157 | { |
143 | er = ERROR_SUCCESS; | 158 | er = ERROR_SUCCESS; |
144 | } | 159 | } |
145 | ExitOnWin32Error(er, hr, "Failed to get process token information."); | 160 | OsExitOnWin32Error(er, hr, "Failed to get process token information."); |
146 | 161 | ||
147 | // Fallback to this check for some OS's (like XP) | 162 | // Fallback to this check for some OS's (like XP) |
148 | *pfPrivileged = ::AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup); | 163 | *pfPrivileged = ::AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup); |
@@ -180,14 +195,14 @@ extern "C" HRESULT DAPI OsIsUacEnabled( | |||
180 | { | 195 | { |
181 | ExitFunction1(hr = S_OK); | 196 | ExitFunction1(hr = S_OK); |
182 | } | 197 | } |
183 | ExitOnFailure(hr, "Failed to open system policy key to detect UAC."); | 198 | OsExitOnFailure(hr, "Failed to open system policy key to detect UAC."); |
184 | 199 | ||
185 | hr = RegReadNumber(hk, L"EnableLUA", &dwUacEnabled); | 200 | hr = RegReadNumber(hk, L"EnableLUA", &dwUacEnabled); |
186 | if (E_FILENOTFOUND == hr) | 201 | if (E_FILENOTFOUND == hr) |
187 | { | 202 | { |
188 | ExitFunction1(hr = S_OK); | 203 | ExitFunction1(hr = S_OK); |
189 | } | 204 | } |
190 | ExitOnFailure(hr, "Failed to read registry value to detect UAC."); | 205 | OsExitOnFailure(hr, "Failed to read registry value to detect UAC."); |
191 | 206 | ||
192 | *pfUacEnabled = (0 != dwUacEnabled); | 207 | *pfUacEnabled = (0 != dwUacEnabled); |
193 | 208 | ||
@@ -215,12 +230,12 @@ HRESULT DAPI OsRtlGetVersion( | |||
215 | hr = LoadSystemLibrary(L"ntdll.dll", &hNtdll); | 230 | hr = LoadSystemLibrary(L"ntdll.dll", &hNtdll); |
216 | if (E_MODNOTFOUND == hr) | 231 | if (E_MODNOTFOUND == hr) |
217 | { | 232 | { |
218 | ExitOnRootFailure(hr = E_NOTIMPL, "Failed to load ntdll.dll"); | 233 | OsExitOnRootFailure(hr = E_NOTIMPL, "Failed to load ntdll.dll"); |
219 | } | 234 | } |
220 | ExitOnFailure(hr, "Failed to load ntdll.dll."); | 235 | OsExitOnFailure(hr, "Failed to load ntdll.dll."); |
221 | 236 | ||
222 | pfnRtlGetVersion = reinterpret_cast<PFN_RTL_GET_VERSION>(::GetProcAddress(hNtdll, "RtlGetVersion")); | 237 | pfnRtlGetVersion = reinterpret_cast<PFN_RTL_GET_VERSION>(::GetProcAddress(hNtdll, "RtlGetVersion")); |
223 | ExitOnNullWithLastError(pfnRtlGetVersion, hr, "Failed to locate RtlGetVersion."); | 238 | OsExitOnNullWithLastError(pfnRtlGetVersion, hr, "Failed to locate RtlGetVersion."); |
224 | 239 | ||
225 | hr = static_cast<HRESULT>(pfnRtlGetVersion(&vovix)); | 240 | hr = static_cast<HRESULT>(pfnRtlGetVersion(&vovix)); |
226 | 241 | ||
diff --git a/src/dutil/path2utl.cpp b/src/dutil/path2utl.cpp index 8f5f03a1..ff3a946d 100644 --- a/src/dutil/path2utl.cpp +++ b/src/dutil/path2utl.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | 5 | ||
6 | // Exit macros | ||
7 | #define PathExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) | ||
8 | #define PathExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) | ||
9 | #define PathExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) | ||
10 | #define PathExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) | ||
11 | #define PathExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) | ||
12 | #define PathExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) | ||
13 | #define PathExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PATHUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define PathExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define PathExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PATHUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define PathExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define PathExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PATHUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define PathExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PATHUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
6 | DAPI_(HRESULT) PathCanonicalizePath( | 21 | DAPI_(HRESULT) PathCanonicalizePath( |
7 | __in_z LPCWSTR wzPath, | 22 | __in_z LPCWSTR wzPath, |
8 | __deref_out_z LPWSTR* psczCanonicalized | 23 | __deref_out_z LPWSTR* psczCanonicalized |
@@ -12,7 +27,7 @@ DAPI_(HRESULT) PathCanonicalizePath( | |||
12 | int cch = MAX_PATH + 1; | 27 | int cch = MAX_PATH + 1; |
13 | 28 | ||
14 | hr = StrAlloc(psczCanonicalized, cch); | 29 | hr = StrAlloc(psczCanonicalized, cch); |
15 | ExitOnFailure(hr, "Failed to allocate string for the canonicalized path."); | 30 | PathExitOnFailure(hr, "Failed to allocate string for the canonicalized path."); |
16 | 31 | ||
17 | if (::PathCanonicalizeW(*psczCanonicalized, wzPath)) | 32 | if (::PathCanonicalizeW(*psczCanonicalized, wzPath)) |
18 | { | 33 | { |
@@ -39,10 +54,10 @@ DAPI_(HRESULT) PathDirectoryContainsPath( | |||
39 | LPWSTR sczOriginalDirectory = NULL; | 54 | LPWSTR sczOriginalDirectory = NULL; |
40 | 55 | ||
41 | hr = PathCanonicalizePath(wzPath, &sczOriginalPath); | 56 | hr = PathCanonicalizePath(wzPath, &sczOriginalPath); |
42 | ExitOnFailure(hr, "Failed to canonicalize the path."); | 57 | PathExitOnFailure(hr, "Failed to canonicalize the path."); |
43 | 58 | ||
44 | hr = PathCanonicalizePath(wzDirectory, &sczOriginalDirectory); | 59 | hr = PathCanonicalizePath(wzDirectory, &sczOriginalDirectory); |
45 | ExitOnFailure(hr, "Failed to canonicalize the directory."); | 60 | PathExitOnFailure(hr, "Failed to canonicalize the directory."); |
46 | 61 | ||
47 | if (!sczOriginalPath || !*sczOriginalPath) | 62 | if (!sczOriginalPath || !*sczOriginalPath) |
48 | { | 63 | { |
diff --git a/src/dutil/pathutil.cpp b/src/dutil/pathutil.cpp index d8894756..ec338f71 100644 --- a/src/dutil/pathutil.cpp +++ b/src/dutil/pathutil.cpp | |||
@@ -2,11 +2,26 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define PathExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) | ||
8 | #define PathExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) | ||
9 | #define PathExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) | ||
10 | #define PathExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) | ||
11 | #define PathExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) | ||
12 | #define PathExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) | ||
13 | #define PathExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PATHUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define PathExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define PathExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PATHUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define PathExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define PathExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PATHUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define PathExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PATHUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | #define PATH_GOOD_ENOUGH 64 | 20 | #define PATH_GOOD_ENOUGH 64 |
6 | 21 | ||
7 | 22 | ||
8 | DAPI_(HRESULT) PathCommandLineAppend( | 23 | DAPI_(HRESULT) PathCommandLineAppend( |
9 | __deref_out_z LPWSTR* psczCommandLine, | 24 | __deref_inout_z LPWSTR* psczCommandLine, |
10 | __in_z LPCWSTR wzArgument | 25 | __in_z LPCWSTR wzArgument |
11 | ) | 26 | ) |
12 | { | 27 | { |
@@ -41,7 +56,7 @@ DAPI_(HRESULT) PathCommandLineAppend( | |||
41 | if (fRequiresQuoting) | 56 | if (fRequiresQuoting) |
42 | { | 57 | { |
43 | hr = StrAlloc(&sczQuotedArg, dwMaxEscapedSize + 3); // plus three for the start and end quote plus null terminator. | 58 | hr = StrAlloc(&sczQuotedArg, dwMaxEscapedSize + 3); // plus three for the start and end quote plus null terminator. |
44 | ExitOnFailure(hr, "Failed to allocate argument to be quoted."); | 59 | PathExitOnFailure(hr, "Failed to allocate argument to be quoted."); |
45 | 60 | ||
46 | LPCWSTR pwz = wzArgument; | 61 | LPCWSTR pwz = wzArgument; |
47 | LPWSTR pwzQuoted = sczQuotedArg; | 62 | LPWSTR pwzQuoted = sczQuotedArg; |
@@ -94,11 +109,11 @@ DAPI_(HRESULT) PathCommandLineAppend( | |||
94 | if (*psczCommandLine && **psczCommandLine) | 109 | if (*psczCommandLine && **psczCommandLine) |
95 | { | 110 | { |
96 | hr = StrAllocConcat(psczCommandLine, L" ", 0); | 111 | hr = StrAllocConcat(psczCommandLine, L" ", 0); |
97 | ExitOnFailure(hr, "Failed to append space to command line with existing data."); | 112 | PathExitOnFailure(hr, "Failed to append space to command line with existing data."); |
98 | } | 113 | } |
99 | 114 | ||
100 | hr = StrAllocConcat(psczCommandLine, sczQuotedArg ? sczQuotedArg : wzArgument, 0); | 115 | hr = StrAllocConcat(psczCommandLine, sczQuotedArg ? sczQuotedArg : wzArgument, 0); |
101 | ExitOnFailure(hr, "Failed to copy command line argument."); | 116 | PathExitOnFailure(hr, "Failed to copy command line argument."); |
102 | 117 | ||
103 | LExit: | 118 | LExit: |
104 | ReleaseStr(sczQuotedArg); | 119 | ReleaseStr(sczQuotedArg); |
@@ -162,7 +177,7 @@ DAPI_(LPCWSTR) PathExtension( | |||
162 | 177 | ||
163 | DAPI_(HRESULT) PathGetDirectory( | 178 | DAPI_(HRESULT) PathGetDirectory( |
164 | __in_z LPCWSTR wzPath, | 179 | __in_z LPCWSTR wzPath, |
165 | __out LPWSTR *psczDirectory | 180 | __out_z LPWSTR *psczDirectory |
166 | ) | 181 | ) |
167 | { | 182 | { |
168 | HRESULT hr = S_OK; | 183 | HRESULT hr = S_OK; |
@@ -193,7 +208,7 @@ DAPI_(HRESULT) PathGetDirectory( | |||
193 | } | 208 | } |
194 | 209 | ||
195 | hr = StrAllocString(psczDirectory, wzPath, cchDirectory); | 210 | hr = StrAllocString(psczDirectory, wzPath, cchDirectory); |
196 | ExitOnFailure(hr, "Failed to copy directory."); | 211 | PathExitOnFailure(hr, "Failed to copy directory."); |
197 | 212 | ||
198 | LExit: | 213 | LExit: |
199 | return hr; | 214 | return hr; |
@@ -223,28 +238,28 @@ DAPI_(HRESULT) PathExpand( | |||
223 | cchExpandedPath = PATH_GOOD_ENOUGH; | 238 | cchExpandedPath = PATH_GOOD_ENOUGH; |
224 | 239 | ||
225 | hr = StrAlloc(&sczExpandedPath, cchExpandedPath); | 240 | hr = StrAlloc(&sczExpandedPath, cchExpandedPath); |
226 | ExitOnFailure(hr, "Failed to allocate space for expanded path."); | 241 | PathExitOnFailure(hr, "Failed to allocate space for expanded path."); |
227 | 242 | ||
228 | cch = ::ExpandEnvironmentStringsW(wzRelativePath, sczExpandedPath, cchExpandedPath); | 243 | cch = ::ExpandEnvironmentStringsW(wzRelativePath, sczExpandedPath, cchExpandedPath); |
229 | if (0 == cch) | 244 | if (0 == cch) |
230 | { | 245 | { |
231 | ExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); | 246 | PathExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); |
232 | } | 247 | } |
233 | else if (cchExpandedPath < cch) | 248 | else if (cchExpandedPath < cch) |
234 | { | 249 | { |
235 | cchExpandedPath = cch; | 250 | cchExpandedPath = cch; |
236 | hr = StrAlloc(&sczExpandedPath, cchExpandedPath); | 251 | hr = StrAlloc(&sczExpandedPath, cchExpandedPath); |
237 | ExitOnFailure(hr, "Failed to re-allocate more space for expanded path."); | 252 | PathExitOnFailure(hr, "Failed to re-allocate more space for expanded path."); |
238 | 253 | ||
239 | cch = ::ExpandEnvironmentStringsW(wzRelativePath, sczExpandedPath, cchExpandedPath); | 254 | cch = ::ExpandEnvironmentStringsW(wzRelativePath, sczExpandedPath, cchExpandedPath); |
240 | if (0 == cch) | 255 | if (0 == cch) |
241 | { | 256 | { |
242 | ExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); | 257 | PathExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); |
243 | } | 258 | } |
244 | else if (cchExpandedPath < cch) | 259 | else if (cchExpandedPath < cch) |
245 | { | 260 | { |
246 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | 261 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); |
247 | ExitOnRootFailure(hr, "Failed to allocate buffer for expanded path."); | 262 | PathExitOnRootFailure(hr, "Failed to allocate buffer for expanded path."); |
248 | } | 263 | } |
249 | } | 264 | } |
250 | 265 | ||
@@ -255,10 +270,10 @@ DAPI_(HRESULT) PathExpand( | |||
255 | { | 270 | { |
256 | hr = S_OK; | 271 | hr = S_OK; |
257 | } | 272 | } |
258 | ExitOnFailure(hr, "Failed to prefix long path after expanding environment variables."); | 273 | PathExitOnFailure(hr, "Failed to prefix long path after expanding environment variables."); |
259 | 274 | ||
260 | hr = StrMaxLength(sczExpandedPath, reinterpret_cast<DWORD_PTR *>(&cchExpandedPath)); | 275 | hr = StrMaxLength(sczExpandedPath, reinterpret_cast<DWORD_PTR *>(&cchExpandedPath)); |
261 | ExitOnFailure(hr, "Failed to get max length of expanded path."); | 276 | PathExitOnFailure(hr, "Failed to get max length of expanded path."); |
262 | } | 277 | } |
263 | } | 278 | } |
264 | 279 | ||
@@ -272,35 +287,35 @@ DAPI_(HRESULT) PathExpand( | |||
272 | DWORD cchFullPath = PATH_GOOD_ENOUGH < cchExpandedPath ? cchExpandedPath : PATH_GOOD_ENOUGH; | 287 | DWORD cchFullPath = PATH_GOOD_ENOUGH < cchExpandedPath ? cchExpandedPath : PATH_GOOD_ENOUGH; |
273 | 288 | ||
274 | hr = StrAlloc(&sczFullPath, cchFullPath); | 289 | hr = StrAlloc(&sczFullPath, cchFullPath); |
275 | ExitOnFailure(hr, "Failed to allocate space for full path."); | 290 | PathExitOnFailure(hr, "Failed to allocate space for full path."); |
276 | 291 | ||
277 | cch = ::GetFullPathNameW(wzPath, cchFullPath, sczFullPath, &wzFileName); | 292 | cch = ::GetFullPathNameW(wzPath, cchFullPath, sczFullPath, &wzFileName); |
278 | if (0 == cch) | 293 | if (0 == cch) |
279 | { | 294 | { |
280 | ExitWithLastError(hr, "Failed to get full path for string: %ls", wzPath); | 295 | PathExitWithLastError(hr, "Failed to get full path for string: %ls", wzPath); |
281 | } | 296 | } |
282 | else if (cchFullPath < cch) | 297 | else if (cchFullPath < cch) |
283 | { | 298 | { |
284 | cchFullPath = cch < MAX_PATH ? cch : cch + 7; // ensure space for "\\?\UNC" prefix if needed | 299 | cchFullPath = cch < MAX_PATH ? cch : cch + 7; // ensure space for "\\?\UNC" prefix if needed |
285 | hr = StrAlloc(&sczFullPath, cchFullPath); | 300 | hr = StrAlloc(&sczFullPath, cchFullPath); |
286 | ExitOnFailure(hr, "Failed to re-allocate more space for full path."); | 301 | PathExitOnFailure(hr, "Failed to re-allocate more space for full path."); |
287 | 302 | ||
288 | cch = ::GetFullPathNameW(wzPath, cchFullPath, sczFullPath, &wzFileName); | 303 | cch = ::GetFullPathNameW(wzPath, cchFullPath, sczFullPath, &wzFileName); |
289 | if (0 == cch) | 304 | if (0 == cch) |
290 | { | 305 | { |
291 | ExitWithLastError(hr, "Failed to get full path for string: %ls", wzPath); | 306 | PathExitWithLastError(hr, "Failed to get full path for string: %ls", wzPath); |
292 | } | 307 | } |
293 | else if (cchFullPath < cch) | 308 | else if (cchFullPath < cch) |
294 | { | 309 | { |
295 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | 310 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); |
296 | ExitOnRootFailure(hr, "Failed to allocate buffer for full path."); | 311 | PathExitOnRootFailure(hr, "Failed to allocate buffer for full path."); |
297 | } | 312 | } |
298 | } | 313 | } |
299 | 314 | ||
300 | if (MAX_PATH < cch) | 315 | if (MAX_PATH < cch) |
301 | { | 316 | { |
302 | hr = PathPrefix(&sczFullPath); | 317 | hr = PathPrefix(&sczFullPath); |
303 | ExitOnFailure(hr, "Failed to prefix long path after expanding."); | 318 | PathExitOnFailure(hr, "Failed to prefix long path after expanding."); |
304 | } | 319 | } |
305 | } | 320 | } |
306 | else | 321 | else |
@@ -310,7 +325,7 @@ DAPI_(HRESULT) PathExpand( | |||
310 | } | 325 | } |
311 | 326 | ||
312 | hr = StrAllocString(psczFullPath, sczFullPath? sczFullPath : wzRelativePath, 0); | 327 | hr = StrAllocString(psczFullPath, sczFullPath? sczFullPath : wzRelativePath, 0); |
313 | ExitOnFailure(hr, "Failed to copy relative path into full path."); | 328 | PathExitOnFailure(hr, "Failed to copy relative path into full path."); |
314 | 329 | ||
315 | LExit: | 330 | LExit: |
316 | ReleaseStr(sczFullPath); | 331 | ReleaseStr(sczFullPath); |
@@ -336,7 +351,7 @@ DAPI_(HRESULT) PathPrefix( | |||
336 | L'\\' == wzFullPath[2]) // normal path | 351 | L'\\' == wzFullPath[2]) // normal path |
337 | { | 352 | { |
338 | hr = StrAllocPrefix(psczFullPath, L"\\\\?\\", 4); | 353 | hr = StrAllocPrefix(psczFullPath, L"\\\\?\\", 4); |
339 | ExitOnFailure(hr, "Failed to add prefix to file path."); | 354 | PathExitOnFailure(hr, "Failed to add prefix to file path."); |
340 | } | 355 | } |
341 | else if (L'\\' == wzFullPath[0] && L'\\' == wzFullPath[1]) // UNC | 356 | else if (L'\\' == wzFullPath[0] && L'\\' == wzFullPath[1]) // UNC |
342 | { | 357 | { |
@@ -344,18 +359,18 @@ DAPI_(HRESULT) PathPrefix( | |||
344 | if (!(L'?' == wzFullPath[2] && L'\\' == wzFullPath[3])) | 359 | if (!(L'?' == wzFullPath[2] && L'\\' == wzFullPath[3])) |
345 | { | 360 | { |
346 | hr = StrSize(*psczFullPath, &cbFullPath); | 361 | hr = StrSize(*psczFullPath, &cbFullPath); |
347 | ExitOnFailure(hr, "Failed to get size of full path."); | 362 | PathExitOnFailure(hr, "Failed to get size of full path."); |
348 | 363 | ||
349 | memmove_s(wzFullPath, cbFullPath, wzFullPath + 1, cbFullPath - sizeof(WCHAR)); | 364 | memmove_s(wzFullPath, cbFullPath, wzFullPath + 1, cbFullPath - sizeof(WCHAR)); |
350 | 365 | ||
351 | hr = StrAllocPrefix(psczFullPath, L"\\\\?\\UNC", 7); | 366 | hr = StrAllocPrefix(psczFullPath, L"\\\\?\\UNC", 7); |
352 | ExitOnFailure(hr, "Failed to add prefix to UNC path."); | 367 | PathExitOnFailure(hr, "Failed to add prefix to UNC path."); |
353 | } | 368 | } |
354 | } | 369 | } |
355 | else | 370 | else |
356 | { | 371 | { |
357 | hr = E_INVALIDARG; | 372 | hr = E_INVALIDARG; |
358 | ExitOnFailure(hr, "Invalid path provided to prefix: %ls.", wzFullPath); | 373 | PathExitOnFailure(hr, "Invalid path provided to prefix: %ls.", wzFullPath); |
359 | } | 374 | } |
360 | 375 | ||
361 | LExit: | 376 | LExit: |
@@ -372,7 +387,7 @@ DAPI_(HRESULT) PathFixedBackslashTerminate( | |||
372 | size_t cchLength = 0; | 387 | size_t cchLength = 0; |
373 | 388 | ||
374 | hr = ::StringCchLengthW(wzPath, cchPath, &cchLength); | 389 | hr = ::StringCchLengthW(wzPath, cchPath, &cchLength); |
375 | ExitOnFailure(hr, "Failed to get length of path."); | 390 | PathExitOnFailure(hr, "Failed to get length of path."); |
376 | 391 | ||
377 | if (cchLength >= cchPath) | 392 | if (cchLength >= cchPath) |
378 | { | 393 | { |
@@ -400,15 +415,15 @@ DAPI_(HRESULT) PathBackslashTerminate( | |||
400 | size_t cchLength = 0; | 415 | size_t cchLength = 0; |
401 | 416 | ||
402 | hr = StrMaxLength(*psczPath, &cchPath); | 417 | hr = StrMaxLength(*psczPath, &cchPath); |
403 | ExitOnFailure(hr, "Failed to get size of path string."); | 418 | PathExitOnFailure(hr, "Failed to get size of path string."); |
404 | 419 | ||
405 | hr = ::StringCchLengthW(*psczPath, cchPath, &cchLength); | 420 | hr = ::StringCchLengthW(*psczPath, cchPath, &cchLength); |
406 | ExitOnFailure(hr, "Failed to get length of path."); | 421 | PathExitOnFailure(hr, "Failed to get length of path."); |
407 | 422 | ||
408 | if (L'\\' != (*psczPath)[cchLength - 1]) | 423 | if (L'\\' != (*psczPath)[cchLength - 1]) |
409 | { | 424 | { |
410 | hr = StrAllocConcat(psczPath, L"\\", 1); | 425 | hr = StrAllocConcat(psczPath, L"\\", 1); |
411 | ExitOnFailure(hr, "Failed to concat backslash onto string."); | 426 | PathExitOnFailure(hr, "Failed to concat backslash onto string."); |
412 | } | 427 | } |
413 | 428 | ||
414 | LExit: | 429 | LExit: |
@@ -427,12 +442,12 @@ DAPI_(HRESULT) PathForCurrentProcess( | |||
427 | do | 442 | do |
428 | { | 443 | { |
429 | hr = StrAlloc(psczFullPath, cch); | 444 | hr = StrAlloc(psczFullPath, cch); |
430 | ExitOnFailure(hr, "Failed to allocate string for module path."); | 445 | PathExitOnFailure(hr, "Failed to allocate string for module path."); |
431 | 446 | ||
432 | DWORD cchRequired = ::GetModuleFileNameW(hModule, *psczFullPath, cch); | 447 | DWORD cchRequired = ::GetModuleFileNameW(hModule, *psczFullPath, cch); |
433 | if (0 == cchRequired) | 448 | if (0 == cchRequired) |
434 | { | 449 | { |
435 | ExitWithLastError(hr, "Failed to get path for executing process."); | 450 | PathExitWithLastError(hr, "Failed to get path for executing process."); |
436 | } | 451 | } |
437 | else if (cchRequired == cch) | 452 | else if (cchRequired == cch) |
438 | { | 453 | { |
@@ -457,15 +472,15 @@ DAPI_(HRESULT) PathRelativeToModule( | |||
457 | ) | 472 | ) |
458 | { | 473 | { |
459 | HRESULT hr = PathForCurrentProcess(psczFullPath, hModule); | 474 | HRESULT hr = PathForCurrentProcess(psczFullPath, hModule); |
460 | ExitOnFailure(hr, "Failed to get current module path."); | 475 | PathExitOnFailure(hr, "Failed to get current module path."); |
461 | 476 | ||
462 | hr = PathGetDirectory(*psczFullPath, psczFullPath); | 477 | hr = PathGetDirectory(*psczFullPath, psczFullPath); |
463 | ExitOnFailure(hr, "Failed to get current module directory."); | 478 | PathExitOnFailure(hr, "Failed to get current module directory."); |
464 | 479 | ||
465 | if (wzFileName) | 480 | if (wzFileName) |
466 | { | 481 | { |
467 | hr = PathConcat(*psczFullPath, wzFileName, psczFullPath); | 482 | hr = PathConcat(*psczFullPath, wzFileName, psczFullPath); |
468 | ExitOnFailure(hr, "Failed to append filename."); | 483 | PathExitOnFailure(hr, "Failed to append filename."); |
469 | } | 484 | } |
470 | 485 | ||
471 | LExit: | 486 | LExit: |
@@ -496,16 +511,16 @@ DAPI_(HRESULT) PathCreateTempFile( | |||
496 | if (wzDirectory && *wzDirectory) | 511 | if (wzDirectory && *wzDirectory) |
497 | { | 512 | { |
498 | hr = StrAllocString(&sczTempPath, wzDirectory, 0); | 513 | hr = StrAllocString(&sczTempPath, wzDirectory, 0); |
499 | ExitOnFailure(hr, "Failed to copy temp path."); | 514 | PathExitOnFailure(hr, "Failed to copy temp path."); |
500 | } | 515 | } |
501 | else | 516 | else |
502 | { | 517 | { |
503 | hr = StrAlloc(&sczTempPath, cchTempPath); | 518 | hr = StrAlloc(&sczTempPath, cchTempPath); |
504 | ExitOnFailure(hr, "Failed to allocate memory for the temp path."); | 519 | PathExitOnFailure(hr, "Failed to allocate memory for the temp path."); |
505 | 520 | ||
506 | if (!::GetTempPathW(cchTempPath, sczTempPath)) | 521 | if (!::GetTempPathW(cchTempPath, sczTempPath)) |
507 | { | 522 | { |
508 | ExitWithLastError(hr, "Failed to get temp path."); | 523 | PathExitWithLastError(hr, "Failed to get temp path."); |
509 | } | 524 | } |
510 | } | 525 | } |
511 | 526 | ||
@@ -514,10 +529,10 @@ DAPI_(HRESULT) PathCreateTempFile( | |||
514 | for (DWORD i = 1; i <= dwUniqueCount && INVALID_HANDLE_VALUE == hTempFile; ++i) | 529 | for (DWORD i = 1; i <= dwUniqueCount && INVALID_HANDLE_VALUE == hTempFile; ++i) |
515 | { | 530 | { |
516 | hr = StrAllocFormatted(&scz, wzFileNameTemplate, i); | 531 | hr = StrAllocFormatted(&scz, wzFileNameTemplate, i); |
517 | ExitOnFailure(hr, "Failed to allocate memory for file template."); | 532 | PathExitOnFailure(hr, "Failed to allocate memory for file template."); |
518 | 533 | ||
519 | hr = StrAllocFormatted(&sczTempFile, L"%s%s", sczTempPath, scz); | 534 | hr = StrAllocFormatted(&sczTempFile, L"%s%s", sczTempPath, scz); |
520 | ExitOnFailure(hr, "Failed to allocate temp file name."); | 535 | PathExitOnFailure(hr, "Failed to allocate temp file name."); |
521 | 536 | ||
522 | hTempFile = ::CreateFileW(sczTempFile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, CREATE_NEW, dwFileAttributes, NULL); | 537 | hTempFile = ::CreateFileW(sczTempFile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, CREATE_NEW, dwFileAttributes, NULL); |
523 | if (INVALID_HANDLE_VALUE == hTempFile) | 538 | if (INVALID_HANDLE_VALUE == hTempFile) |
@@ -528,7 +543,7 @@ DAPI_(HRESULT) PathCreateTempFile( | |||
528 | { | 543 | { |
529 | hr = S_OK; | 544 | hr = S_OK; |
530 | } | 545 | } |
531 | ExitOnFailure(hr, "Failed to create file: %ls", sczTempFile); | 546 | PathExitOnFailure(hr, "Failed to create file: %ls", sczTempFile); |
532 | } | 547 | } |
533 | } | 548 | } |
534 | } | 549 | } |
@@ -538,17 +553,17 @@ DAPI_(HRESULT) PathCreateTempFile( | |||
538 | if (INVALID_HANDLE_VALUE == hTempFile) | 553 | if (INVALID_HANDLE_VALUE == hTempFile) |
539 | { | 554 | { |
540 | hr = StrAlloc(&sczTempFile, MAX_PATH); | 555 | hr = StrAlloc(&sczTempFile, MAX_PATH); |
541 | ExitOnFailure(hr, "Failed to allocate memory for the temp path"); | 556 | PathExitOnFailure(hr, "Failed to allocate memory for the temp path"); |
542 | 557 | ||
543 | if (!::GetTempFileNameW(sczTempPath, L"TMP", 0, sczTempFile)) | 558 | if (!::GetTempFileNameW(sczTempPath, L"TMP", 0, sczTempFile)) |
544 | { | 559 | { |
545 | ExitWithLastError(hr, "Failed to create new temp file name."); | 560 | PathExitWithLastError(hr, "Failed to create new temp file name."); |
546 | } | 561 | } |
547 | 562 | ||
548 | hTempFile = ::CreateFileW(sczTempFile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, dwFileAttributes, NULL); | 563 | hTempFile = ::CreateFileW(sczTempFile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, dwFileAttributes, NULL); |
549 | if (INVALID_HANDLE_VALUE == hTempFile) | 564 | if (INVALID_HANDLE_VALUE == hTempFile) |
550 | { | 565 | { |
551 | ExitWithLastError(hr, "Failed to open new temp file: %ls", sczTempFile); | 566 | PathExitWithLastError(hr, "Failed to open new temp file: %ls", sczTempFile); |
552 | } | 567 | } |
553 | } | 568 | } |
554 | 569 | ||
@@ -556,7 +571,7 @@ DAPI_(HRESULT) PathCreateTempFile( | |||
556 | if (psczTempFile) | 571 | if (psczTempFile) |
557 | { | 572 | { |
558 | hr = StrAllocString(psczTempFile, sczTempFile, 0); | 573 | hr = StrAllocString(psczTempFile, sczTempFile, 0); |
559 | ExitOnFailure(hr, "Failed to copy temp file string."); | 574 | PathExitOnFailure(hr, "Failed to copy temp file string."); |
560 | } | 575 | } |
561 | 576 | ||
562 | if (phTempFile) | 577 | if (phTempFile) |
@@ -602,24 +617,24 @@ DAPI_(HRESULT) PathCreateTimeBasedTempFile( | |||
602 | if (wzDirectory && *wzDirectory) | 617 | if (wzDirectory && *wzDirectory) |
603 | { | 618 | { |
604 | hr = PathConcat(wzDirectory, wzPrefix, &sczPrefix); | 619 | hr = PathConcat(wzDirectory, wzPrefix, &sczPrefix); |
605 | ExitOnFailure(hr, "Failed to combine directory and log prefix."); | 620 | PathExitOnFailure(hr, "Failed to combine directory and log prefix."); |
606 | } | 621 | } |
607 | else | 622 | else |
608 | { | 623 | { |
609 | if (!::GetTempPathW(countof(wzTempPath), wzTempPath)) | 624 | if (!::GetTempPathW(countof(wzTempPath), wzTempPath)) |
610 | { | 625 | { |
611 | ExitWithLastError(hr, "Failed to get temp folder."); | 626 | PathExitWithLastError(hr, "Failed to get temp folder."); |
612 | } | 627 | } |
613 | 628 | ||
614 | hr = PathConcat(wzTempPath, wzPrefix, &sczPrefix); | 629 | hr = PathConcat(wzTempPath, wzPrefix, &sczPrefix); |
615 | ExitOnFailure(hr, "Failed to concatenate the temp folder and log prefix."); | 630 | PathExitOnFailure(hr, "Failed to concatenate the temp folder and log prefix."); |
616 | } | 631 | } |
617 | 632 | ||
618 | hr = PathGetDirectory(sczPrefix, &sczPrefixFolder); | 633 | hr = PathGetDirectory(sczPrefix, &sczPrefixFolder); |
619 | if (S_OK == hr) | 634 | if (S_OK == hr) |
620 | { | 635 | { |
621 | hr = DirEnsureExists(sczPrefixFolder, NULL); | 636 | hr = DirEnsureExists(sczPrefixFolder, NULL); |
622 | ExitOnFailure(hr, "Failed to ensure temp file path exists: %ls", sczPrefixFolder); | 637 | PathExitOnFailure(hr, "Failed to ensure temp file path exists: %ls", sczPrefixFolder); |
623 | } | 638 | } |
624 | 639 | ||
625 | if (!wzPostfix) | 640 | if (!wzPostfix) |
@@ -636,7 +651,7 @@ DAPI_(HRESULT) PathCreateTimeBasedTempFile( | |||
636 | 651 | ||
637 | // Log format: pre YYYY MM dd hh mm ss post ext | 652 | // Log format: pre YYYY MM dd hh mm ss post ext |
638 | hr = StrAllocFormatted(&sczTempPath, L"%ls_%04u%02u%02u%02u%02u%02u%ls%ls%ls", sczPrefix, time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, wzPostfix, L'.' == *wzExtension ? L"" : L".", wzExtension); | 653 | hr = StrAllocFormatted(&sczTempPath, L"%ls_%04u%02u%02u%02u%02u%02u%ls%ls%ls", sczPrefix, time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, wzPostfix, L'.' == *wzExtension ? L"" : L".", wzExtension); |
639 | ExitOnFailure(hr, "failed to allocate memory for the temp path"); | 654 | PathExitOnFailure(hr, "failed to allocate memory for the temp path"); |
640 | 655 | ||
641 | hTempFile = ::CreateFileW(sczTempPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); | 656 | hTempFile = ::CreateFileW(sczTempPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); |
642 | if (INVALID_HANDLE_VALUE == hTempFile) | 657 | if (INVALID_HANDLE_VALUE == hTempFile) |
@@ -655,14 +670,14 @@ DAPI_(HRESULT) PathCreateTimeBasedTempFile( | |||
655 | } | 670 | } |
656 | 671 | ||
657 | hr = HRESULT_FROM_WIN32(er); | 672 | hr = HRESULT_FROM_WIN32(er); |
658 | ExitOnFailureDebugTrace(hr, "Failed to create temp file: %ls", sczTempPath); | 673 | PathExitOnFailureDebugTrace(hr, "Failed to create temp file: %ls", sczTempPath); |
659 | } | 674 | } |
660 | } while (fRetry); | 675 | } while (fRetry); |
661 | 676 | ||
662 | if (psczTempFile) | 677 | if (psczTempFile) |
663 | { | 678 | { |
664 | hr = StrAllocString(psczTempFile, sczTempPath, 0); | 679 | hr = StrAllocString(psczTempFile, sczTempPath, 0); |
665 | ExitOnFailure(hr, "Failed to copy temp path to return."); | 680 | PathExitOnFailure(hr, "Failed to copy temp path to return."); |
666 | } | 681 | } |
667 | 682 | ||
668 | if (phTempFile) | 683 | if (phTempFile) |
@@ -701,29 +716,29 @@ DAPI_(HRESULT) PathCreateTempDirectory( | |||
701 | if (wzDirectory && *wzDirectory) | 716 | if (wzDirectory && *wzDirectory) |
702 | { | 717 | { |
703 | hr = StrAllocString(&sczTempPath, wzDirectory, 0); | 718 | hr = StrAllocString(&sczTempPath, wzDirectory, 0); |
704 | ExitOnFailure(hr, "Failed to copy temp path."); | 719 | PathExitOnFailure(hr, "Failed to copy temp path."); |
705 | 720 | ||
706 | hr = PathBackslashTerminate(&sczTempPath); | 721 | hr = PathBackslashTerminate(&sczTempPath); |
707 | ExitOnFailure(hr, "Failed to ensure path ends in backslash: %ls", wzDirectory); | 722 | PathExitOnFailure(hr, "Failed to ensure path ends in backslash: %ls", wzDirectory); |
708 | } | 723 | } |
709 | else | 724 | else |
710 | { | 725 | { |
711 | hr = StrAlloc(&sczTempPath, cchTempPath); | 726 | hr = StrAlloc(&sczTempPath, cchTempPath); |
712 | ExitOnFailure(hr, "Failed to allocate memory for the temp path."); | 727 | PathExitOnFailure(hr, "Failed to allocate memory for the temp path."); |
713 | 728 | ||
714 | if (!::GetTempPathW(cchTempPath, sczTempPath)) | 729 | if (!::GetTempPathW(cchTempPath, sczTempPath)) |
715 | { | 730 | { |
716 | ExitWithLastError(hr, "Failed to get temp path."); | 731 | PathExitWithLastError(hr, "Failed to get temp path."); |
717 | } | 732 | } |
718 | } | 733 | } |
719 | 734 | ||
720 | for (DWORD i = 1; i <= dwUniqueCount; ++i) | 735 | for (DWORD i = 1; i <= dwUniqueCount; ++i) |
721 | { | 736 | { |
722 | hr = StrAllocFormatted(&scz, wzDirectoryNameTemplate, i); | 737 | hr = StrAllocFormatted(&scz, wzDirectoryNameTemplate, i); |
723 | ExitOnFailure(hr, "Failed to allocate memory for directory name template."); | 738 | PathExitOnFailure(hr, "Failed to allocate memory for directory name template."); |
724 | 739 | ||
725 | hr = StrAllocFormatted(psczTempDirectory, L"%s%s", sczTempPath, scz); | 740 | hr = StrAllocFormatted(psczTempDirectory, L"%s%s", sczTempPath, scz); |
726 | ExitOnFailure(hr, "Failed to allocate temp directory name."); | 741 | PathExitOnFailure(hr, "Failed to allocate temp directory name."); |
727 | 742 | ||
728 | if (!::CreateDirectoryW(*psczTempDirectory, NULL)) | 743 | if (!::CreateDirectoryW(*psczTempDirectory, NULL)) |
729 | { | 744 | { |
@@ -750,10 +765,10 @@ DAPI_(HRESULT) PathCreateTempDirectory( | |||
750 | break; | 765 | break; |
751 | } | 766 | } |
752 | } | 767 | } |
753 | ExitOnFailure(hr, "Failed to create temp directory."); | 768 | PathExitOnFailure(hr, "Failed to create temp directory."); |
754 | 769 | ||
755 | hr = PathBackslashTerminate(psczTempDirectory); | 770 | hr = PathBackslashTerminate(psczTempDirectory); |
756 | ExitOnFailure(hr, "Failed to ensure temp directory is backslash terminated."); | 771 | PathExitOnFailure(hr, "Failed to ensure temp directory is backslash terminated."); |
757 | 772 | ||
758 | LExit: | 773 | LExit: |
759 | ReleaseStr(scz); | 774 | ReleaseStr(scz); |
@@ -771,13 +786,13 @@ DAPI_(HRESULT) PathGetKnownFolder( | |||
771 | HRESULT hr = S_OK; | 786 | HRESULT hr = S_OK; |
772 | 787 | ||
773 | hr = StrAlloc(psczKnownFolder, MAX_PATH); | 788 | hr = StrAlloc(psczKnownFolder, MAX_PATH); |
774 | ExitOnFailure(hr, "Failed to allocate memory for known folder."); | 789 | PathExitOnFailure(hr, "Failed to allocate memory for known folder."); |
775 | 790 | ||
776 | hr = ::SHGetFolderPathW(NULL, csidl, NULL, SHGFP_TYPE_CURRENT, *psczKnownFolder); | 791 | hr = ::SHGetFolderPathW(NULL, csidl, NULL, SHGFP_TYPE_CURRENT, *psczKnownFolder); |
777 | ExitOnFailure(hr, "Failed to get known folder path."); | 792 | PathExitOnFailure(hr, "Failed to get known folder path."); |
778 | 793 | ||
779 | hr = PathBackslashTerminate(psczKnownFolder); | 794 | hr = PathBackslashTerminate(psczKnownFolder); |
780 | ExitOnFailure(hr, "Failed to ensure known folder path is backslash terminated."); | 795 | PathExitOnFailure(hr, "Failed to ensure known folder path is backslash terminated."); |
781 | 796 | ||
782 | LExit: | 797 | LExit: |
783 | return hr; | 798 | return hr; |
@@ -804,23 +819,23 @@ DAPI_(HRESULT) PathConcat( | |||
804 | if (!wzPath2 || !*wzPath2) | 819 | if (!wzPath2 || !*wzPath2) |
805 | { | 820 | { |
806 | hr = StrAllocString(psczCombined, wzPath1, 0); | 821 | hr = StrAllocString(psczCombined, wzPath1, 0); |
807 | ExitOnFailure(hr, "Failed to copy just path1 to output."); | 822 | PathExitOnFailure(hr, "Failed to copy just path1 to output."); |
808 | } | 823 | } |
809 | else if (!wzPath1 || !*wzPath1 || PathIsAbsolute(wzPath2)) | 824 | else if (!wzPath1 || !*wzPath1 || PathIsAbsolute(wzPath2)) |
810 | { | 825 | { |
811 | hr = StrAllocString(psczCombined, wzPath2, 0); | 826 | hr = StrAllocString(psczCombined, wzPath2, 0); |
812 | ExitOnFailure(hr, "Failed to copy just path2 to output."); | 827 | PathExitOnFailure(hr, "Failed to copy just path2 to output."); |
813 | } | 828 | } |
814 | else | 829 | else |
815 | { | 830 | { |
816 | hr = StrAllocString(psczCombined, wzPath1, 0); | 831 | hr = StrAllocString(psczCombined, wzPath1, 0); |
817 | ExitOnFailure(hr, "Failed to copy path1 to output."); | 832 | PathExitOnFailure(hr, "Failed to copy path1 to output."); |
818 | 833 | ||
819 | hr = PathBackslashTerminate(psczCombined); | 834 | hr = PathBackslashTerminate(psczCombined); |
820 | ExitOnFailure(hr, "Failed to backslashify."); | 835 | PathExitOnFailure(hr, "Failed to backslashify."); |
821 | 836 | ||
822 | hr = StrAllocConcat(psczCombined, wzPath2, 0); | 837 | hr = StrAllocConcat(psczCombined, wzPath2, 0); |
823 | ExitOnFailure(hr, "Failed to append path2 to output."); | 838 | PathExitOnFailure(hr, "Failed to append path2 to output."); |
824 | } | 839 | } |
825 | 840 | ||
826 | LExit: | 841 | LExit: |
@@ -839,13 +854,13 @@ DAPI_(HRESULT) PathEnsureQuoted( | |||
839 | size_t cchPath = 0; | 854 | size_t cchPath = 0; |
840 | 855 | ||
841 | hr = ::StringCchLengthW(*ppszPath, STRSAFE_MAX_CCH, &cchPath); | 856 | hr = ::StringCchLengthW(*ppszPath, STRSAFE_MAX_CCH, &cchPath); |
842 | ExitOnFailure(hr, "Failed to get the length of the path."); | 857 | PathExitOnFailure(hr, "Failed to get the length of the path."); |
843 | 858 | ||
844 | // Handle simple special cases. | 859 | // Handle simple special cases. |
845 | if (0 == cchPath || (1 == cchPath && L'"' == (*ppszPath)[0])) | 860 | if (0 == cchPath || (1 == cchPath && L'"' == (*ppszPath)[0])) |
846 | { | 861 | { |
847 | hr = StrAllocString(ppszPath, L"\"\"", 2); | 862 | hr = StrAllocString(ppszPath, L"\"\"", 2); |
848 | ExitOnFailure(hr, "Failed to allocate a quoted empty string."); | 863 | PathExitOnFailure(hr, "Failed to allocate a quoted empty string."); |
849 | 864 | ||
850 | ExitFunction(); | 865 | ExitFunction(); |
851 | } | 866 | } |
@@ -853,7 +868,7 @@ DAPI_(HRESULT) PathEnsureQuoted( | |||
853 | if (L'"' != (*ppszPath)[0]) | 868 | if (L'"' != (*ppszPath)[0]) |
854 | { | 869 | { |
855 | hr = StrAllocPrefix(ppszPath, L"\"", 1); | 870 | hr = StrAllocPrefix(ppszPath, L"\"", 1); |
856 | ExitOnFailure(hr, "Failed to allocate an opening quote."); | 871 | PathExitOnFailure(hr, "Failed to allocate an opening quote."); |
857 | 872 | ||
858 | // Add a char for the opening quote. | 873 | // Add a char for the opening quote. |
859 | ++cchPath; | 874 | ++cchPath; |
@@ -862,7 +877,7 @@ DAPI_(HRESULT) PathEnsureQuoted( | |||
862 | if (L'"' != (*ppszPath)[cchPath - 1]) | 877 | if (L'"' != (*ppszPath)[cchPath - 1]) |
863 | { | 878 | { |
864 | hr = StrAllocConcat(ppszPath, L"\"", 1); | 879 | hr = StrAllocConcat(ppszPath, L"\"", 1); |
865 | ExitOnFailure(hr, "Failed to allocate a closing quote."); | 880 | PathExitOnFailure(hr, "Failed to allocate a closing quote."); |
866 | 881 | ||
867 | // Add a char for the closing quote. | 882 | // Add a char for the closing quote. |
868 | ++cchPath; | 883 | ++cchPath; |
@@ -876,7 +891,7 @@ DAPI_(HRESULT) PathEnsureQuoted( | |||
876 | (*ppszPath)[cchPath - 1] = L'\\'; | 891 | (*ppszPath)[cchPath - 1] = L'\\'; |
877 | 892 | ||
878 | hr = StrAllocConcat(ppszPath, L"\"", 1); | 893 | hr = StrAllocConcat(ppszPath, L"\"", 1); |
879 | ExitOnFailure(hr, "Failed to allocate another closing quote after the backslash."); | 894 | PathExitOnFailure(hr, "Failed to allocate another closing quote after the backslash."); |
880 | } | 895 | } |
881 | } | 896 | } |
882 | 897 | ||
@@ -897,10 +912,10 @@ DAPI_(HRESULT) PathCompare( | |||
897 | LPWSTR sczPath2 = NULL; | 912 | LPWSTR sczPath2 = NULL; |
898 | 913 | ||
899 | hr = PathExpand(&sczPath1, wzPath1, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH); | 914 | hr = PathExpand(&sczPath1, wzPath1, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH); |
900 | ExitOnFailure(hr, "Failed to expand path1."); | 915 | PathExitOnFailure(hr, "Failed to expand path1."); |
901 | 916 | ||
902 | hr = PathExpand(&sczPath2, wzPath2, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH); | 917 | hr = PathExpand(&sczPath2, wzPath2, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH); |
903 | ExitOnFailure(hr, "Failed to expand path2."); | 918 | PathExitOnFailure(hr, "Failed to expand path2."); |
904 | 919 | ||
905 | *pnResult = ::CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, sczPath1, -1, sczPath2, -1); | 920 | *pnResult = ::CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, sczPath1, -1, sczPath2, -1); |
906 | 921 | ||
@@ -922,7 +937,7 @@ DAPI_(HRESULT) PathCompress( | |||
922 | hPath = ::CreateFileW(wzPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | 937 | hPath = ::CreateFileW(wzPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); |
923 | if (INVALID_HANDLE_VALUE == hPath) | 938 | if (INVALID_HANDLE_VALUE == hPath) |
924 | { | 939 | { |
925 | ExitWithLastError(hr, "Failed to open path %ls for compression.", wzPath); | 940 | PathExitWithLastError(hr, "Failed to open path %ls for compression.", wzPath); |
926 | } | 941 | } |
927 | 942 | ||
928 | DWORD dwBytesReturned = 0; | 943 | DWORD dwBytesReturned = 0; |
@@ -933,7 +948,7 @@ DAPI_(HRESULT) PathCompress( | |||
933 | DWORD er = ::GetLastError(); | 948 | DWORD er = ::GetLastError(); |
934 | if (ERROR_INVALID_FUNCTION != er) | 949 | if (ERROR_INVALID_FUNCTION != er) |
935 | { | 950 | { |
936 | ExitOnWin32Error(er, hr, "Failed to set compression state for path %ls.", wzPath); | 951 | PathExitOnWin32Error(er, hr, "Failed to set compression state for path %ls.", wzPath); |
937 | } | 952 | } |
938 | } | 953 | } |
939 | 954 | ||
@@ -945,7 +960,7 @@ LExit: | |||
945 | 960 | ||
946 | DAPI_(HRESULT) PathGetHierarchyArray( | 961 | DAPI_(HRESULT) PathGetHierarchyArray( |
947 | __in_z LPCWSTR wzPath, | 962 | __in_z LPCWSTR wzPath, |
948 | __deref_inout_ecount_opt(*pcStrArray) LPWSTR **prgsczPathArray, | 963 | __deref_inout_ecount_opt(*pcPathArray) LPWSTR **prgsczPathArray, |
949 | __inout LPUINT pcPathArray | 964 | __inout LPUINT pcPathArray |
950 | ) | 965 | ) |
951 | { | 966 | { |
@@ -975,16 +990,16 @@ DAPI_(HRESULT) PathGetHierarchyArray( | |||
975 | Assert(cArraySpacesNeeded >= 1); | 990 | Assert(cArraySpacesNeeded >= 1); |
976 | 991 | ||
977 | hr = MemEnsureArraySize(reinterpret_cast<void **>(prgsczPathArray), cArraySpacesNeeded, sizeof(LPWSTR), 0); | 992 | hr = MemEnsureArraySize(reinterpret_cast<void **>(prgsczPathArray), cArraySpacesNeeded, sizeof(LPWSTR), 0); |
978 | ExitOnFailure(hr, "Failed to allocate array of size %u for parent directories", cArraySpacesNeeded); | 993 | PathExitOnFailure(hr, "Failed to allocate array of size %u for parent directories", cArraySpacesNeeded); |
979 | *pcPathArray = cArraySpacesNeeded; | 994 | *pcPathArray = cArraySpacesNeeded; |
980 | 995 | ||
981 | hr = StrAllocString(&sczPathCopy, wzPath, 0); | 996 | hr = StrAllocString(&sczPathCopy, wzPath, 0); |
982 | ExitOnFailure(hr, "Failed to allocate copy of original path"); | 997 | PathExitOnFailure(hr, "Failed to allocate copy of original path"); |
983 | 998 | ||
984 | for (DWORD i = 0; i < cArraySpacesNeeded; ++i) | 999 | for (DWORD i = 0; i < cArraySpacesNeeded; ++i) |
985 | { | 1000 | { |
986 | hr = StrAllocString((*prgsczPathArray) + cArraySpacesNeeded - 1 - i, sczPathCopy, 0); | 1001 | hr = StrAllocString((*prgsczPathArray) + cArraySpacesNeeded - 1 - i, sczPathCopy, 0); |
987 | ExitOnFailure(hr, "Failed to copy path"); | 1002 | PathExitOnFailure(hr, "Failed to copy path"); |
988 | 1003 | ||
989 | // If it ends in a backslash, it's a directory path, so cut off everything the last backslash before we get the directory portion of the path | 1004 | // If it ends in a backslash, it's a directory path, so cut off everything the last backslash before we get the directory portion of the path |
990 | if (wzPath[lstrlenW(sczPathCopy) - 1] == L'\\') | 1005 | if (wzPath[lstrlenW(sczPathCopy) - 1] == L'\\') |
@@ -993,7 +1008,7 @@ DAPI_(HRESULT) PathGetHierarchyArray( | |||
993 | } | 1008 | } |
994 | 1009 | ||
995 | hr = PathGetDirectory(sczPathCopy, &sczNewPathCopy); | 1010 | hr = PathGetDirectory(sczPathCopy, &sczNewPathCopy); |
996 | ExitOnFailure(hr, "Failed to get directory portion of path"); | 1011 | PathExitOnFailure(hr, "Failed to get directory portion of path"); |
997 | 1012 | ||
998 | ReleaseStr(sczPathCopy); | 1013 | ReleaseStr(sczPathCopy); |
999 | sczPathCopy = sczNewPathCopy; | 1014 | sczPathCopy = sczNewPathCopy; |
diff --git a/src/dutil/perfutil.cpp b/src/dutil/perfutil.cpp index 5c4e0774..bc138d34 100644 --- a/src/dutil/perfutil.cpp +++ b/src/dutil/perfutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define PerfExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__) | ||
8 | #define PerfExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__) | ||
9 | #define PerfExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__) | ||
10 | #define PerfExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__) | ||
11 | #define PerfExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__) | ||
12 | #define PerfExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PERFUTIL, x, s, __VA_ARGS__) | ||
13 | #define PerfExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PERFUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define PerfExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PERFUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define PerfExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PERFUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define PerfExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PERFUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define PerfExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PERFUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define PerfExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PERFUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | static BOOL vfHighPerformanceCounter = TRUE; // assume the system has a high performance counter | 20 | static BOOL vfHighPerformanceCounter = TRUE; // assume the system has a high performance counter |
6 | static double vdFrequency = 1; | 21 | static double vdFrequency = 1; |
7 | 22 | ||
diff --git a/src/dutil/polcutil.cpp b/src/dutil/polcutil.cpp index 1cc29e61..1fdfa18c 100644 --- a/src/dutil/polcutil.cpp +++ b/src/dutil/polcutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define PolcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_POLCUTIL, x, s, __VA_ARGS__) | ||
8 | #define PolcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_POLCUTIL, x, s, __VA_ARGS__) | ||
9 | #define PolcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_POLCUTIL, x, s, __VA_ARGS__) | ||
10 | #define PolcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_POLCUTIL, x, s, __VA_ARGS__) | ||
11 | #define PolcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_POLCUTIL, x, s, __VA_ARGS__) | ||
12 | #define PolcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_POLCUTIL, x, s, __VA_ARGS__) | ||
13 | #define PolcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_POLCUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define PolcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_POLCUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define PolcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_POLCUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define PolcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_POLCUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define PolcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_POLCUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define PolcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_POLCUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | const LPCWSTR REGISTRY_POLICIES_KEY = L"SOFTWARE\\Policies\\"; | 20 | const LPCWSTR REGISTRY_POLICIES_KEY = L"SOFTWARE\\Policies\\"; |
6 | 21 | ||
7 | static HRESULT OpenPolicyKey( | 22 | static HRESULT OpenPolicyKey( |
@@ -25,14 +40,14 @@ extern "C" HRESULT DAPI PolcReadNumber( | |||
25 | { | 40 | { |
26 | ExitFunction1(hr = S_FALSE); | 41 | ExitFunction1(hr = S_FALSE); |
27 | } | 42 | } |
28 | ExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath); | 43 | PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath); |
29 | 44 | ||
30 | hr = RegReadNumber(hk, wzPolicyName, pdw); | 45 | hr = RegReadNumber(hk, wzPolicyName, pdw); |
31 | if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) | 46 | if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) |
32 | { | 47 | { |
33 | ExitFunction1(hr = S_FALSE); | 48 | ExitFunction1(hr = S_FALSE); |
34 | } | 49 | } |
35 | ExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName); | 50 | PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName); |
36 | 51 | ||
37 | LExit: | 52 | LExit: |
38 | ReleaseRegKey(hk); | 53 | ReleaseRegKey(hk); |
@@ -60,14 +75,14 @@ extern "C" HRESULT DAPI PolcReadString( | |||
60 | { | 75 | { |
61 | ExitFunction1(hr = S_FALSE); | 76 | ExitFunction1(hr = S_FALSE); |
62 | } | 77 | } |
63 | ExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath); | 78 | PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath); |
64 | 79 | ||
65 | hr = RegReadString(hk, wzPolicyName, pscz); | 80 | hr = RegReadString(hk, wzPolicyName, pscz); |
66 | if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) | 81 | if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) |
67 | { | 82 | { |
68 | ExitFunction1(hr = S_FALSE); | 83 | ExitFunction1(hr = S_FALSE); |
69 | } | 84 | } |
70 | ExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName); | 85 | PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName); |
71 | 86 | ||
72 | LExit: | 87 | LExit: |
73 | ReleaseRegKey(hk); | 88 | ReleaseRegKey(hk); |
@@ -99,10 +114,10 @@ static HRESULT OpenPolicyKey( | |||
99 | LPWSTR sczPath = NULL; | 114 | LPWSTR sczPath = NULL; |
100 | 115 | ||
101 | hr = PathConcat(REGISTRY_POLICIES_KEY, wzPolicyPath, &sczPath); | 116 | hr = PathConcat(REGISTRY_POLICIES_KEY, wzPolicyPath, &sczPath); |
102 | ExitOnFailure(hr, "Failed to combine logging path with root path."); | 117 | PolcExitOnFailure(hr, "Failed to combine logging path with root path."); |
103 | 118 | ||
104 | hr = RegOpen(HKEY_LOCAL_MACHINE, sczPath, KEY_READ, phk); | 119 | hr = RegOpen(HKEY_LOCAL_MACHINE, sczPath, KEY_READ, phk); |
105 | ExitOnFailure(hr, "Failed to open policy registry key."); | 120 | PolcExitOnFailure(hr, "Failed to open policy registry key."); |
106 | 121 | ||
107 | LExit: | 122 | LExit: |
108 | ReleaseStr(sczPath); | 123 | ReleaseStr(sczPath); |
diff --git a/src/dutil/proc2utl.cpp b/src/dutil/proc2utl.cpp index 8a2fd09b..a59d2ffc 100644 --- a/src/dutil/proc2utl.cpp +++ b/src/dutil/proc2utl.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define ProcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
8 | #define ProcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
9 | #define ProcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
10 | #define ProcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
11 | #define ProcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
12 | #define ProcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
13 | #define ProcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define ProcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define ProcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define ProcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define ProcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PROCUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define ProcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PROCUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | /******************************************************************** | 20 | /******************************************************************** |
6 | ProcFindAllIdsFromExeName() - returns an array of process ids that are running specified executable. | 21 | ProcFindAllIdsFromExeName() - returns an array of process ids that are running specified executable. |
7 | 22 | ||
@@ -21,7 +36,7 @@ extern "C" HRESULT DAPI ProcFindAllIdsFromExeName( | |||
21 | hSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); | 36 | hSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
22 | if (INVALID_HANDLE_VALUE == hSnap) | 37 | if (INVALID_HANDLE_VALUE == hSnap) |
23 | { | 38 | { |
24 | ExitWithLastError(hr, "Failed to create snapshot of processes on system"); | 39 | ProcExitWithLastError(hr, "Failed to create snapshot of processes on system"); |
25 | } | 40 | } |
26 | 41 | ||
27 | fContinue = ::Process32FirstW(hSnap, &peData); | 42 | fContinue = ::Process32FirstW(hSnap, &peData); |
@@ -33,13 +48,13 @@ extern "C" HRESULT DAPI ProcFindAllIdsFromExeName( | |||
33 | if (!*ppdwProcessIds) | 48 | if (!*ppdwProcessIds) |
34 | { | 49 | { |
35 | *ppdwProcessIds = static_cast<DWORD*>(MemAlloc(sizeof(DWORD), TRUE)); | 50 | *ppdwProcessIds = static_cast<DWORD*>(MemAlloc(sizeof(DWORD), TRUE)); |
36 | ExitOnNull(ppdwProcessIds, hr, E_OUTOFMEMORY, "Failed to allocate array for returned process IDs."); | 51 | ProcExitOnNull(ppdwProcessIds, hr, E_OUTOFMEMORY, "Failed to allocate array for returned process IDs."); |
37 | } | 52 | } |
38 | else | 53 | else |
39 | { | 54 | { |
40 | DWORD* pdwReAllocReturnedPids = NULL; | 55 | DWORD* pdwReAllocReturnedPids = NULL; |
41 | pdwReAllocReturnedPids = static_cast<DWORD*>(MemReAlloc(*ppdwProcessIds, sizeof(DWORD) * ((*pcProcessIds) + 1), TRUE)); | 56 | pdwReAllocReturnedPids = static_cast<DWORD*>(MemReAlloc(*ppdwProcessIds, sizeof(DWORD) * ((*pcProcessIds) + 1), TRUE)); |
42 | ExitOnNull(pdwReAllocReturnedPids, hr, E_OUTOFMEMORY, "Failed to re-allocate array for returned process IDs."); | 57 | ProcExitOnNull(pdwReAllocReturnedPids, hr, E_OUTOFMEMORY, "Failed to re-allocate array for returned process IDs."); |
43 | 58 | ||
44 | *ppdwProcessIds = pdwReAllocReturnedPids; | 59 | *ppdwProcessIds = pdwReAllocReturnedPids; |
45 | } | 60 | } |
diff --git a/src/dutil/proc3utl.cpp b/src/dutil/proc3utl.cpp index 038f002b..6d3cbc67 100644 --- a/src/dutil/proc3utl.cpp +++ b/src/dutil/proc3utl.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define ProcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
8 | #define ProcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
9 | #define ProcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
10 | #define ProcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
11 | #define ProcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
12 | #define ProcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
13 | #define ProcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define ProcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define ProcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define ProcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define ProcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PROCUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define ProcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PROCUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | static HRESULT GetActiveSessionUserToken( | 20 | static HRESULT GetActiveSessionUserToken( |
6 | __out HANDLE *phToken | 21 | __out HANDLE *phToken |
7 | ); | 22 | ); |
@@ -25,20 +40,20 @@ extern "C" HRESULT DAPI ProcExecuteAsInteractiveUser( | |||
25 | PROCESS_INFORMATION pi = { }; | 40 | PROCESS_INFORMATION pi = { }; |
26 | 41 | ||
27 | hr = GetActiveSessionUserToken(&hToken); | 42 | hr = GetActiveSessionUserToken(&hToken); |
28 | ExitOnFailure(hr, "Failed to get active session user token."); | 43 | ProcExitOnFailure(hr, "Failed to get active session user token."); |
29 | 44 | ||
30 | if (!::CreateEnvironmentBlock(&pEnvironment, hToken, FALSE)) | 45 | if (!::CreateEnvironmentBlock(&pEnvironment, hToken, FALSE)) |
31 | { | 46 | { |
32 | ExitWithLastError(hr, "Failed to create environment block for UI process."); | 47 | ProcExitWithLastError(hr, "Failed to create environment block for UI process."); |
33 | } | 48 | } |
34 | 49 | ||
35 | hr = StrAllocFormatted(&sczFullCommandLine, L"\"%ls\" %ls", wzExecutablePath, wzCommandLine); | 50 | hr = StrAllocFormatted(&sczFullCommandLine, L"\"%ls\" %ls", wzExecutablePath, wzCommandLine); |
36 | ExitOnFailure(hr, "Failed to allocate full command-line."); | 51 | ProcExitOnFailure(hr, "Failed to allocate full command-line."); |
37 | 52 | ||
38 | si.cb = sizeof(si); | 53 | si.cb = sizeof(si); |
39 | if (!::CreateProcessAsUserW(hToken, wzExecutablePath, sczFullCommandLine, NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT, pEnvironment, NULL, &si, &pi)) | 54 | if (!::CreateProcessAsUserW(hToken, wzExecutablePath, sczFullCommandLine, NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT, pEnvironment, NULL, &si, &pi)) |
40 | { | 55 | { |
41 | ExitWithLastError(hr, "Failed to create UI process: %ls", sczFullCommandLine); | 56 | ProcExitWithLastError(hr, "Failed to create UI process: %ls", sczFullCommandLine); |
42 | } | 57 | } |
43 | 58 | ||
44 | *phProcess = pi.hProcess; | 59 | *phProcess = pi.hProcess; |
@@ -74,7 +89,7 @@ static HRESULT GetActiveSessionUserToken( | |||
74 | // Loop through the sessions looking for the active one. | 89 | // Loop through the sessions looking for the active one. |
75 | if (!::WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &cSessions)) | 90 | if (!::WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &cSessions)) |
76 | { | 91 | { |
77 | ExitWithLastError(hr, "Failed to enumerate sessions."); | 92 | ProcExitWithLastError(hr, "Failed to enumerate sessions."); |
78 | } | 93 | } |
79 | 94 | ||
80 | for (DWORD i = 0; i < cSessions; ++i) | 95 | for (DWORD i = 0; i < cSessions; ++i) |
@@ -96,7 +111,7 @@ static HRESULT GetActiveSessionUserToken( | |||
96 | // Get the user token from the active session. | 111 | // Get the user token from the active session. |
97 | if (!::WTSQueryUserToken(dwSessionId, &hToken)) | 112 | if (!::WTSQueryUserToken(dwSessionId, &hToken)) |
98 | { | 113 | { |
99 | ExitWithLastError(hr, "Failed to get active session user token."); | 114 | ProcExitWithLastError(hr, "Failed to get active session user token."); |
100 | } | 115 | } |
101 | 116 | ||
102 | *phToken = hToken; | 117 | *phToken = hToken; |
diff --git a/src/dutil/procutil.cpp b/src/dutil/procutil.cpp index 9833d0ec..6bfe5017 100644 --- a/src/dutil/procutil.cpp +++ b/src/dutil/procutil.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | 5 | ||
6 | // Exit macros | ||
7 | #define ProcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
8 | #define ProcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
9 | #define ProcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
10 | #define ProcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
11 | #define ProcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
12 | #define ProcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | ||
13 | #define ProcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define ProcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define ProcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define ProcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define ProcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PROCUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define ProcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PROCUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
6 | // private functions | 21 | // private functions |
7 | static HRESULT CreatePipes( | 22 | static HRESULT CreatePipes( |
8 | __out HANDLE *phOutRead, | 23 | __out HANDLE *phOutRead, |
@@ -30,7 +45,7 @@ extern "C" HRESULT DAPI ProcElevated( | |||
30 | 45 | ||
31 | if (!::OpenProcessToken(hProcess, TOKEN_QUERY, &hToken)) | 46 | if (!::OpenProcessToken(hProcess, TOKEN_QUERY, &hToken)) |
32 | { | 47 | { |
33 | ExitWithLastError(hr, "Failed to open process token."); | 48 | ProcExitWithLastError(hr, "Failed to open process token."); |
34 | } | 49 | } |
35 | 50 | ||
36 | if (::GetTokenInformation(hToken, TokenElevation, &tokenElevated, sizeof(TOKEN_ELEVATION), &cbToken)) | 51 | if (::GetTokenInformation(hToken, TokenElevation, &tokenElevated, sizeof(TOKEN_ELEVATION), &cbToken)) |
@@ -50,7 +65,7 @@ extern "C" HRESULT DAPI ProcElevated( | |||
50 | } | 65 | } |
51 | else | 66 | else |
52 | { | 67 | { |
53 | ExitOnRootFailure(hr, "Failed to get elevation token from process."); | 68 | ProcExitOnRootFailure(hr, "Failed to get elevation token from process."); |
54 | } | 69 | } |
55 | } | 70 | } |
56 | 71 | ||
@@ -76,7 +91,7 @@ extern "C" HRESULT DAPI ProcWow64( | |||
76 | USHORT pProcessMachine = IMAGE_FILE_MACHINE_UNKNOWN; | 91 | USHORT pProcessMachine = IMAGE_FILE_MACHINE_UNKNOWN; |
77 | if (!pfnIsWow64Process2(hProcess, &pProcessMachine, nullptr)) | 92 | if (!pfnIsWow64Process2(hProcess, &pProcessMachine, nullptr)) |
78 | { | 93 | { |
79 | ExitWithLastError(hr, "Failed to check WOW64 process - IsWow64Process2."); | 94 | ProcExitWithLastError(hr, "Failed to check WOW64 process - IsWow64Process2."); |
80 | } | 95 | } |
81 | 96 | ||
82 | if (pProcessMachine != IMAGE_FILE_MACHINE_UNKNOWN) | 97 | if (pProcessMachine != IMAGE_FILE_MACHINE_UNKNOWN) |
@@ -93,7 +108,7 @@ extern "C" HRESULT DAPI ProcWow64( | |||
93 | { | 108 | { |
94 | if (!pfnIsWow64Process(hProcess, &fIsWow64)) | 109 | if (!pfnIsWow64Process(hProcess, &fIsWow64)) |
95 | { | 110 | { |
96 | ExitWithLastError(hr, "Failed to check WOW64 process - IsWow64Process."); | 111 | ProcExitWithLastError(hr, "Failed to check WOW64 process - IsWow64Process."); |
97 | } | 112 | } |
98 | } | 113 | } |
99 | } | 114 | } |
@@ -121,7 +136,7 @@ extern "C" HRESULT DAPI ProcDisableWowFileSystemRedirection( | |||
121 | 136 | ||
122 | if (!pfnWow64DisableWow64FsRedirection(&pfsr->pvRevertState)) | 137 | if (!pfnWow64DisableWow64FsRedirection(&pfsr->pvRevertState)) |
123 | { | 138 | { |
124 | ExitWithLastError(hr, "Failed to disable file system redirection."); | 139 | ProcExitWithLastError(hr, "Failed to disable file system redirection."); |
125 | } | 140 | } |
126 | 141 | ||
127 | pfsr->fDisabled = TRUE; | 142 | pfsr->fDisabled = TRUE; |
@@ -143,7 +158,7 @@ extern "C" HRESULT DAPI ProcRevertWowFileSystemRedirection( | |||
143 | 158 | ||
144 | if (!pfnWow64RevertWow64FsRedirection(pfsr->pvRevertState)) | 159 | if (!pfnWow64RevertWow64FsRedirection(pfsr->pvRevertState)) |
145 | { | 160 | { |
146 | ExitWithLastError(hr, "Failed to revert file system redirection."); | 161 | ProcExitWithLastError(hr, "Failed to revert file system redirection."); |
147 | } | 162 | } |
148 | 163 | ||
149 | pfsr->fDisabled = FALSE; | 164 | pfsr->fDisabled = FALSE; |
@@ -168,13 +183,13 @@ extern "C" HRESULT DAPI ProcExec( | |||
168 | PROCESS_INFORMATION pi = { }; | 183 | PROCESS_INFORMATION pi = { }; |
169 | 184 | ||
170 | hr = StrAllocFormatted(&sczFullCommandLine, L"\"%ls\" %ls", wzExecutablePath, wzCommandLine ? wzCommandLine : L""); | 185 | hr = StrAllocFormatted(&sczFullCommandLine, L"\"%ls\" %ls", wzExecutablePath, wzCommandLine ? wzCommandLine : L""); |
171 | ExitOnFailure(hr, "Failed to allocate full command-line."); | 186 | ProcExitOnFailure(hr, "Failed to allocate full command-line."); |
172 | 187 | ||
173 | si.cb = sizeof(si); | 188 | si.cb = sizeof(si); |
174 | si.wShowWindow = static_cast<WORD>(nCmdShow); | 189 | si.wShowWindow = static_cast<WORD>(nCmdShow); |
175 | if (!::CreateProcessW(wzExecutablePath, sczFullCommandLine, NULL, NULL, FALSE, 0, 0, NULL, &si, &pi)) | 190 | if (!::CreateProcessW(wzExecutablePath, sczFullCommandLine, NULL, NULL, FALSE, 0, 0, NULL, &si, &pi)) |
176 | { | 191 | { |
177 | ExitWithLastError(hr, "Failed to create process: %ls", sczFullCommandLine); | 192 | ProcExitWithLastError(hr, "Failed to create process: %ls", sczFullCommandLine); |
178 | } | 193 | } |
179 | 194 | ||
180 | *phProcess = pi.hProcess; | 195 | *phProcess = pi.hProcess; |
@@ -213,7 +228,7 @@ extern "C" HRESULT DAPI ProcExecute( | |||
213 | 228 | ||
214 | // Create redirect pipes. | 229 | // Create redirect pipes. |
215 | hr = CreatePipes(&hOutRead, &hOutWrite, &hErrWrite, &hInRead, &hInWrite); | 230 | hr = CreatePipes(&hOutRead, &hOutWrite, &hErrWrite, &hInRead, &hInWrite); |
216 | ExitOnFailure(hr, "failed to create output pipes"); | 231 | ProcExitOnFailure(hr, "failed to create output pipes"); |
217 | 232 | ||
218 | // Set up startup structure. | 233 | // Set up startup structure. |
219 | si.cb = sizeof(STARTUPINFOW); | 234 | si.cb = sizeof(STARTUPINFOW); |
@@ -249,7 +264,7 @@ extern "C" HRESULT DAPI ProcExecute( | |||
249 | } | 264 | } |
250 | else | 265 | else |
251 | { | 266 | { |
252 | ExitWithLastError(hr, "Process failed to execute."); | 267 | ProcExitWithLastError(hr, "Process failed to execute."); |
253 | } | 268 | } |
254 | 269 | ||
255 | *phProcess = pi.hProcess; | 270 | *phProcess = pi.hProcess; |
@@ -305,7 +320,7 @@ extern "C" HRESULT DAPI ProcWaitForCompletion( | |||
305 | er = ::WaitForSingleObject(hProcess, dwTimeout); | 320 | er = ::WaitForSingleObject(hProcess, dwTimeout); |
306 | if (WAIT_FAILED == er) | 321 | if (WAIT_FAILED == er) |
307 | { | 322 | { |
308 | ExitWithLastError(hr, "Failed to wait for process to complete."); | 323 | ProcExitWithLastError(hr, "Failed to wait for process to complete."); |
309 | } | 324 | } |
310 | else if (WAIT_TIMEOUT == er) | 325 | else if (WAIT_TIMEOUT == er) |
311 | { | 326 | { |
@@ -314,7 +329,7 @@ extern "C" HRESULT DAPI ProcWaitForCompletion( | |||
314 | 329 | ||
315 | if (!::GetExitCodeProcess(hProcess, &er)) | 330 | if (!::GetExitCodeProcess(hProcess, &er)) |
316 | { | 331 | { |
317 | ExitWithLastError(hr, "Failed to get process return code."); | 332 | ProcExitWithLastError(hr, "Failed to get process return code."); |
318 | } | 333 | } |
319 | 334 | ||
320 | *pReturnCode = er; | 335 | *pReturnCode = er; |
@@ -340,7 +355,7 @@ extern "C" HRESULT DAPI ProcWaitForIds( | |||
340 | DWORD cProcesses = 0; | 355 | DWORD cProcesses = 0; |
341 | 356 | ||
342 | rghProcesses = static_cast<HANDLE*>(MemAlloc(sizeof(DWORD) * cProcessIds, TRUE)); | 357 | rghProcesses = static_cast<HANDLE*>(MemAlloc(sizeof(DWORD) * cProcessIds, TRUE)); |
343 | ExitOnNull(rgdwProcessIds, hr, E_OUTOFMEMORY, "Failed to allocate array for process ID Handles."); | 358 | ProcExitOnNull(rgdwProcessIds, hr, E_OUTOFMEMORY, "Failed to allocate array for process ID Handles."); |
344 | 359 | ||
345 | for (DWORD i = 0; i < cProcessIds; ++i) | 360 | for (DWORD i = 0; i < cProcessIds; ++i) |
346 | { | 361 | { |
@@ -354,11 +369,11 @@ extern "C" HRESULT DAPI ProcWaitForIds( | |||
354 | er = ::WaitForMultipleObjects(cProcesses, rghProcesses, TRUE, dwMilliseconds); | 369 | er = ::WaitForMultipleObjects(cProcesses, rghProcesses, TRUE, dwMilliseconds); |
355 | if (WAIT_FAILED == er) | 370 | if (WAIT_FAILED == er) |
356 | { | 371 | { |
357 | ExitWithLastError(hr, "Failed to wait for process to complete."); | 372 | ProcExitWithLastError(hr, "Failed to wait for process to complete."); |
358 | } | 373 | } |
359 | else if (WAIT_TIMEOUT == er) | 374 | else if (WAIT_TIMEOUT == er) |
360 | { | 375 | { |
361 | ExitOnWin32Error(er, hr, "Timed out while waiting for process to complete."); | 376 | ProcExitOnWin32Error(er, hr, "Timed out while waiting for process to complete."); |
362 | } | 377 | } |
363 | 378 | ||
364 | LExit: | 379 | LExit: |
@@ -393,7 +408,7 @@ extern "C" HRESULT DAPI ProcCloseIds( | |||
393 | { | 408 | { |
394 | if (!::EnumWindows(&CloseWindowEnumCallback, pdwProcessIds[i])) | 409 | if (!::EnumWindows(&CloseWindowEnumCallback, pdwProcessIds[i])) |
395 | { | 410 | { |
396 | ExitWithLastError(hr, "Failed to enumerate windows."); | 411 | ProcExitWithLastError(hr, "Failed to enumerate windows."); |
397 | } | 412 | } |
398 | } | 413 | } |
399 | 414 | ||
@@ -430,30 +445,30 @@ static HRESULT CreatePipes( | |||
430 | // Create pipes | 445 | // Create pipes |
431 | if (!::CreatePipe(&hOutTemp, &hOutWrite, &sa, 0)) | 446 | if (!::CreatePipe(&hOutTemp, &hOutWrite, &sa, 0)) |
432 | { | 447 | { |
433 | ExitWithLastError(hr, "failed to create output pipe"); | 448 | ProcExitWithLastError(hr, "failed to create output pipe"); |
434 | } | 449 | } |
435 | 450 | ||
436 | if (!::CreatePipe(&hInRead, &hInTemp, &sa, 0)) | 451 | if (!::CreatePipe(&hInRead, &hInTemp, &sa, 0)) |
437 | { | 452 | { |
438 | ExitWithLastError(hr, "failed to create input pipe"); | 453 | ProcExitWithLastError(hr, "failed to create input pipe"); |
439 | } | 454 | } |
440 | 455 | ||
441 | // Duplicate output pipe so standard error and standard output write to the same pipe. | 456 | // Duplicate output pipe so standard error and standard output write to the same pipe. |
442 | if (!::DuplicateHandle(::GetCurrentProcess(), hOutWrite, ::GetCurrentProcess(), &hErrWrite, 0, TRUE, DUPLICATE_SAME_ACCESS)) | 457 | if (!::DuplicateHandle(::GetCurrentProcess(), hOutWrite, ::GetCurrentProcess(), &hErrWrite, 0, TRUE, DUPLICATE_SAME_ACCESS)) |
443 | { | 458 | { |
444 | ExitWithLastError(hr, "failed to duplicate write handle"); | 459 | ProcExitWithLastError(hr, "failed to duplicate write handle"); |
445 | } | 460 | } |
446 | 461 | ||
447 | // We need to create new "output read" and "input write" handles that are non inheritable. Otherwise CreateProcess will creates handles in | 462 | // We need to create new "output read" and "input write" handles that are non inheritable. Otherwise CreateProcess will creates handles in |
448 | // the child process that can't be closed. | 463 | // the child process that can't be closed. |
449 | if (!::DuplicateHandle(::GetCurrentProcess(), hOutTemp, ::GetCurrentProcess(), &hOutRead, 0, FALSE, DUPLICATE_SAME_ACCESS)) | 464 | if (!::DuplicateHandle(::GetCurrentProcess(), hOutTemp, ::GetCurrentProcess(), &hOutRead, 0, FALSE, DUPLICATE_SAME_ACCESS)) |
450 | { | 465 | { |
451 | ExitWithLastError(hr, "failed to duplicate output pipe"); | 466 | ProcExitWithLastError(hr, "failed to duplicate output pipe"); |
452 | } | 467 | } |
453 | 468 | ||
454 | if (!::DuplicateHandle(::GetCurrentProcess(), hInTemp, ::GetCurrentProcess(), &hInWrite, 0, FALSE, DUPLICATE_SAME_ACCESS)) | 469 | if (!::DuplicateHandle(::GetCurrentProcess(), hInTemp, ::GetCurrentProcess(), &hInWrite, 0, FALSE, DUPLICATE_SAME_ACCESS)) |
455 | { | 470 | { |
456 | ExitWithLastError(hr, "failed to duplicate input pipe"); | 471 | ProcExitWithLastError(hr, "failed to duplicate input pipe"); |
457 | } | 472 | } |
458 | 473 | ||
459 | // now that everything has succeeded, assign to the outputs | 474 | // now that everything has succeeded, assign to the outputs |
diff --git a/src/dutil/regutil.cpp b/src/dutil/regutil.cpp index 1b13af81..e1ef19e8 100644 --- a/src/dutil/regutil.cpp +++ b/src/dutil/regutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define RegExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_REGUTIL, x, s, __VA_ARGS__) | ||
8 | #define RegExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_REGUTIL, x, s, __VA_ARGS__) | ||
9 | #define RegExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_REGUTIL, x, s, __VA_ARGS__) | ||
10 | #define RegExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_REGUTIL, x, s, __VA_ARGS__) | ||
11 | #define RegExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_REGUTIL, x, s, __VA_ARGS__) | ||
12 | #define RegExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_REGUTIL, x, s, __VA_ARGS__) | ||
13 | #define RegExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_REGUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define RegExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_REGUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define RegExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_REGUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define RegExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_REGUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define RegExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_REGUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define RegExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_REGUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | static PFN_REGCREATEKEYEXW vpfnRegCreateKeyExW = ::RegCreateKeyExW; | 20 | static PFN_REGCREATEKEYEXW vpfnRegCreateKeyExW = ::RegCreateKeyExW; |
6 | static PFN_REGOPENKEYEXW vpfnRegOpenKeyExW = ::RegOpenKeyExW; | 21 | static PFN_REGOPENKEYEXW vpfnRegOpenKeyExW = ::RegOpenKeyExW; |
7 | static PFN_REGDELETEKEYEXW vpfnRegDeleteKeyExW = NULL; | 22 | static PFN_REGDELETEKEYEXW vpfnRegDeleteKeyExW = NULL; |
@@ -34,7 +49,7 @@ extern "C" HRESULT DAPI RegInitialize( | |||
34 | HRESULT hr = S_OK; | 49 | HRESULT hr = S_OK; |
35 | 50 | ||
36 | hr = LoadSystemLibrary(L"AdvApi32.dll", &vhAdvApi32Dll); | 51 | hr = LoadSystemLibrary(L"AdvApi32.dll", &vhAdvApi32Dll); |
37 | ExitOnFailure(hr, "Failed to load AdvApi32.dll"); | 52 | RegExitOnFailure(hr, "Failed to load AdvApi32.dll"); |
38 | 53 | ||
39 | // ignore failures - if this doesn't exist, we'll fall back to RegDeleteKeyW | 54 | // ignore failures - if this doesn't exist, we'll fall back to RegDeleteKeyW |
40 | vpfnRegDeleteKeyExWFromLibrary = reinterpret_cast<PFN_REGDELETEKEYEXW>(::GetProcAddress(vhAdvApi32Dll, "RegDeleteKeyExW")); | 55 | vpfnRegDeleteKeyExWFromLibrary = reinterpret_cast<PFN_REGDELETEKEYEXW>(::GetProcAddress(vhAdvApi32Dll, "RegDeleteKeyExW")); |
@@ -114,7 +129,7 @@ extern "C" HRESULT DAPI RegCreate( | |||
114 | DWORD er = ERROR_SUCCESS; | 129 | DWORD er = ERROR_SUCCESS; |
115 | 130 | ||
116 | er = vpfnRegCreateKeyExW(hkRoot, wzSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, dwAccess, NULL, phk, NULL); | 131 | er = vpfnRegCreateKeyExW(hkRoot, wzSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, dwAccess, NULL, phk, NULL); |
117 | ExitOnWin32Error(er, hr, "Failed to create registry key."); | 132 | RegExitOnWin32Error(er, hr, "Failed to create registry key."); |
118 | 133 | ||
119 | LExit: | 134 | LExit: |
120 | return hr; | 135 | return hr; |
@@ -140,7 +155,7 @@ HRESULT DAPI RegCreateEx( | |||
140 | DWORD dwDisposition; | 155 | DWORD dwDisposition; |
141 | 156 | ||
142 | er = vpfnRegCreateKeyExW(hkRoot, wzSubKey, 0, NULL, fVolatile ? REG_OPTION_VOLATILE : REG_OPTION_NON_VOLATILE, dwAccess, pSecurityAttributes, phk, &dwDisposition); | 157 | er = vpfnRegCreateKeyExW(hkRoot, wzSubKey, 0, NULL, fVolatile ? REG_OPTION_VOLATILE : REG_OPTION_NON_VOLATILE, dwAccess, pSecurityAttributes, phk, &dwDisposition); |
143 | ExitOnWin32Error(er, hr, "Failed to create registry key."); | 158 | RegExitOnWin32Error(er, hr, "Failed to create registry key."); |
144 | 159 | ||
145 | if (pfCreated) | 160 | if (pfCreated) |
146 | { | 161 | { |
@@ -171,7 +186,7 @@ extern "C" HRESULT DAPI RegOpen( | |||
171 | { | 186 | { |
172 | ExitFunction1(hr = E_FILENOTFOUND); | 187 | ExitFunction1(hr = E_FILENOTFOUND); |
173 | } | 188 | } |
174 | ExitOnWin32Error(er, hr, "Failed to open registry key."); | 189 | RegExitOnWin32Error(er, hr, "Failed to open registry key."); |
175 | 190 | ||
176 | LExit: | 191 | LExit: |
177 | return hr; | 192 | return hr; |
@@ -199,7 +214,7 @@ extern "C" HRESULT DAPI RegDelete( | |||
199 | if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness) | 214 | if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness) |
200 | { | 215 | { |
201 | hr = E_INVALIDARG; | 216 | hr = E_INVALIDARG; |
202 | ExitOnFailure(hr, "RegInitialize must be called first in order to RegDelete() a key with non-default bit attributes!"); | 217 | RegExitOnFailure(hr, "RegInitialize must be called first in order to RegDelete() a key with non-default bit attributes!"); |
203 | } | 218 | } |
204 | 219 | ||
205 | switch (kbKeyBitness) | 220 | switch (kbKeyBitness) |
@@ -222,18 +237,18 @@ extern "C" HRESULT DAPI RegDelete( | |||
222 | { | 237 | { |
223 | ExitFunction1(hr = S_OK); | 238 | ExitFunction1(hr = S_OK); |
224 | } | 239 | } |
225 | ExitOnFailure(hr, "Failed to open this key for enumerating subkeys", wzSubKey); | 240 | RegExitOnFailure(hr, "Failed to open this key for enumerating subkeys: %ls", wzSubKey); |
226 | 241 | ||
227 | // Yes, keep enumerating the 0th item, because we're deleting it every time | 242 | // Yes, keep enumerating the 0th item, because we're deleting it every time |
228 | while (E_NOMOREITEMS != (hr = RegKeyEnum(hkKey, 0, &pszEnumeratedSubKey))) | 243 | while (E_NOMOREITEMS != (hr = RegKeyEnum(hkKey, 0, &pszEnumeratedSubKey))) |
229 | { | 244 | { |
230 | ExitOnFailure(hr, "Failed to enumerate key 0"); | 245 | RegExitOnFailure(hr, "Failed to enumerate key 0"); |
231 | 246 | ||
232 | hr = PathConcat(wzSubKey, pszEnumeratedSubKey, &pszRecursiveSubKey); | 247 | hr = PathConcat(wzSubKey, pszEnumeratedSubKey, &pszRecursiveSubKey); |
233 | ExitOnFailure(hr, "Failed to concatenate paths while recursively deleting subkeys. Path1: %ls, Path2: %ls", wzSubKey, pszEnumeratedSubKey); | 248 | RegExitOnFailure(hr, "Failed to concatenate paths while recursively deleting subkeys. Path1: %ls, Path2: %ls", wzSubKey, pszEnumeratedSubKey); |
234 | 249 | ||
235 | hr = RegDelete(hkRoot, pszRecursiveSubKey, kbKeyBitness, fDeleteTree); | 250 | hr = RegDelete(hkRoot, pszRecursiveSubKey, kbKeyBitness, fDeleteTree); |
236 | ExitOnFailure(hr, "Failed to recursively delete subkey: %ls", pszRecursiveSubKey); | 251 | RegExitOnFailure(hr, "Failed to recursively delete subkey: %ls", pszRecursiveSubKey); |
237 | } | 252 | } |
238 | 253 | ||
239 | hr = S_OK; | 254 | hr = S_OK; |
@@ -246,7 +261,7 @@ extern "C" HRESULT DAPI RegDelete( | |||
246 | { | 261 | { |
247 | ExitFunction1(hr = E_FILENOTFOUND); | 262 | ExitFunction1(hr = E_FILENOTFOUND); |
248 | } | 263 | } |
249 | ExitOnWin32Error(er, hr, "Failed to delete registry key (ex)."); | 264 | RegExitOnWin32Error(er, hr, "Failed to delete registry key (ex)."); |
250 | } | 265 | } |
251 | else | 266 | else |
252 | { | 267 | { |
@@ -255,7 +270,7 @@ extern "C" HRESULT DAPI RegDelete( | |||
255 | { | 270 | { |
256 | ExitFunction1(hr = E_FILENOTFOUND); | 271 | ExitFunction1(hr = E_FILENOTFOUND); |
257 | } | 272 | } |
258 | ExitOnWin32Error(er, hr, "Failed to delete registry key."); | 273 | RegExitOnWin32Error(er, hr, "Failed to delete registry key."); |
259 | } | 274 | } |
260 | 275 | ||
261 | LExit: | 276 | LExit: |
@@ -284,7 +299,7 @@ extern "C" HRESULT DAPI RegKeyEnum( | |||
284 | if (psczKey && *psczKey) | 299 | if (psczKey && *psczKey) |
285 | { | 300 | { |
286 | hr = StrMaxLength(*psczKey, reinterpret_cast<DWORD_PTR*>(&cch)); | 301 | hr = StrMaxLength(*psczKey, reinterpret_cast<DWORD_PTR*>(&cch)); |
287 | ExitOnFailure(hr, "Failed to determine length of string."); | 302 | RegExitOnFailure(hr, "Failed to determine length of string."); |
288 | } | 303 | } |
289 | 304 | ||
290 | if (2 > cch) | 305 | if (2 > cch) |
@@ -292,18 +307,18 @@ extern "C" HRESULT DAPI RegKeyEnum( | |||
292 | cch = 2; | 307 | cch = 2; |
293 | 308 | ||
294 | hr = StrAlloc(psczKey, cch); | 309 | hr = StrAlloc(psczKey, cch); |
295 | ExitOnFailure(hr, "Failed to allocate string to minimum size."); | 310 | RegExitOnFailure(hr, "Failed to allocate string to minimum size."); |
296 | } | 311 | } |
297 | 312 | ||
298 | er = vpfnRegEnumKeyExW(hk, dwIndex, *psczKey, &cch, NULL, NULL, NULL, NULL); | 313 | er = vpfnRegEnumKeyExW(hk, dwIndex, *psczKey, &cch, NULL, NULL, NULL, NULL); |
299 | if (ERROR_MORE_DATA == er) | 314 | if (ERROR_MORE_DATA == er) |
300 | { | 315 | { |
301 | er = vpfnRegQueryInfoKeyW(hk, NULL, NULL, NULL, NULL, &cch, NULL, NULL, NULL, NULL, NULL, NULL); | 316 | er = vpfnRegQueryInfoKeyW(hk, NULL, NULL, NULL, NULL, &cch, NULL, NULL, NULL, NULL, NULL, NULL); |
302 | ExitOnWin32Error(er, hr, "Failed to get max size of subkey name under registry key."); | 317 | RegExitOnWin32Error(er, hr, "Failed to get max size of subkey name under registry key."); |
303 | 318 | ||
304 | ++cch; // add one because RegQueryInfoKeyW() returns the length of the subkeys without the null terminator. | 319 | ++cch; // add one because RegQueryInfoKeyW() returns the length of the subkeys without the null terminator. |
305 | hr = StrAlloc(psczKey, cch); | 320 | hr = StrAlloc(psczKey, cch); |
306 | ExitOnFailure(hr, "Failed to allocate string bigger for enum registry key."); | 321 | RegExitOnFailure(hr, "Failed to allocate string bigger for enum registry key."); |
307 | 322 | ||
308 | er = vpfnRegEnumKeyExW(hk, dwIndex, *psczKey, &cch, NULL, NULL, NULL, NULL); | 323 | er = vpfnRegEnumKeyExW(hk, dwIndex, *psczKey, &cch, NULL, NULL, NULL, NULL); |
309 | } | 324 | } |
@@ -311,7 +326,7 @@ extern "C" HRESULT DAPI RegKeyEnum( | |||
311 | { | 326 | { |
312 | ExitFunction1(hr = E_NOMOREITEMS); | 327 | ExitFunction1(hr = E_NOMOREITEMS); |
313 | } | 328 | } |
314 | ExitOnWin32Error(er, hr, "Failed to enum registry key."); | 329 | RegExitOnWin32Error(er, hr, "Failed to enum registry key."); |
315 | 330 | ||
316 | // Always ensure the registry key name is null terminated. | 331 | // Always ensure the registry key name is null terminated. |
317 | #pragma prefast(push) | 332 | #pragma prefast(push) |
@@ -340,20 +355,20 @@ HRESULT DAPI RegValueEnum( | |||
340 | DWORD cbValueName = 0; | 355 | DWORD cbValueName = 0; |
341 | 356 | ||
342 | er = vpfnRegQueryInfoKeyW(hk, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &cbValueName, NULL, NULL, NULL); | 357 | er = vpfnRegQueryInfoKeyW(hk, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &cbValueName, NULL, NULL, NULL); |
343 | ExitOnWin32Error(er, hr, "Failed to get max size of value name under registry key."); | 358 | RegExitOnWin32Error(er, hr, "Failed to get max size of value name under registry key."); |
344 | 359 | ||
345 | // Add one for null terminator | 360 | // Add one for null terminator |
346 | ++cbValueName; | 361 | ++cbValueName; |
347 | 362 | ||
348 | hr = StrAlloc(psczName, cbValueName); | 363 | hr = StrAlloc(psczName, cbValueName); |
349 | ExitOnFailure(hr, "Failed to allocate array for registry value name"); | 364 | RegExitOnFailure(hr, "Failed to allocate array for registry value name"); |
350 | 365 | ||
351 | er = vpfnRegEnumValueW(hk, dwIndex, *psczName, &cbValueName, NULL, pdwType, NULL, NULL); | 366 | er = vpfnRegEnumValueW(hk, dwIndex, *psczName, &cbValueName, NULL, pdwType, NULL, NULL); |
352 | if (ERROR_NO_MORE_ITEMS == er) | 367 | if (ERROR_NO_MORE_ITEMS == er) |
353 | { | 368 | { |
354 | ExitFunction1(hr = E_NOMOREITEMS); | 369 | ExitFunction1(hr = E_NOMOREITEMS); |
355 | } | 370 | } |
356 | ExitOnWin32Error(er, hr, "Failed to enumerate registry value"); | 371 | RegExitOnWin32Error(er, hr, "Failed to enumerate registry value"); |
357 | 372 | ||
358 | LExit: | 373 | LExit: |
359 | return hr; | 374 | return hr; |
@@ -376,7 +391,7 @@ HRESULT DAPI RegGetType( | |||
376 | { | 391 | { |
377 | ExitFunction1(hr = E_FILENOTFOUND); | 392 | ExitFunction1(hr = E_FILENOTFOUND); |
378 | } | 393 | } |
379 | ExitOnWin32Error(er, hr, "Failed to read registry value."); | 394 | RegExitOnWin32Error(er, hr, "Failed to read registry value."); |
380 | LExit: | 395 | LExit: |
381 | 396 | ||
382 | return hr; | 397 | return hr; |
@@ -400,20 +415,20 @@ HRESULT DAPI RegReadBinary( | |||
400 | DWORD dwType = 0; | 415 | DWORD dwType = 0; |
401 | 416 | ||
402 | er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, NULL, &cb); | 417 | er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, NULL, &cb); |
403 | ExitOnWin32Error(er, hr, "Failed to get size of registry value."); | 418 | RegExitOnWin32Error(er, hr, "Failed to get size of registry value."); |
404 | 419 | ||
405 | // Zero-length binary values can exist | 420 | // Zero-length binary values can exist |
406 | if (0 < cb) | 421 | if (0 < cb) |
407 | { | 422 | { |
408 | pbBuffer = static_cast<LPBYTE>(MemAlloc(cb, FALSE)); | 423 | pbBuffer = static_cast<LPBYTE>(MemAlloc(cb, FALSE)); |
409 | ExitOnNull(pbBuffer, hr, E_OUTOFMEMORY, "Failed to allocate buffer for binary registry value."); | 424 | RegExitOnNull(pbBuffer, hr, E_OUTOFMEMORY, "Failed to allocate buffer for binary registry value."); |
410 | 425 | ||
411 | er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, pbBuffer, &cb); | 426 | er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, pbBuffer, &cb); |
412 | if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) | 427 | if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) |
413 | { | 428 | { |
414 | ExitFunction1(hr = E_FILENOTFOUND); | 429 | ExitFunction1(hr = E_FILENOTFOUND); |
415 | } | 430 | } |
416 | ExitOnWin32Error(er, hr, "Failed to read registry value."); | 431 | RegExitOnWin32Error(er, hr, "Failed to read registry value."); |
417 | } | 432 | } |
418 | 433 | ||
419 | if (REG_BINARY == dwType) | 434 | if (REG_BINARY == dwType) |
@@ -425,7 +440,7 @@ HRESULT DAPI RegReadBinary( | |||
425 | else | 440 | else |
426 | { | 441 | { |
427 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); | 442 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); |
428 | ExitOnRootFailure(hr, "Error reading binary registry value due to unexpected data type: %u", dwType); | 443 | RegExitOnRootFailure(hr, "Error reading binary registry value due to unexpected data type: %u", dwType); |
429 | } | 444 | } |
430 | 445 | ||
431 | LExit: | 446 | LExit: |
@@ -455,7 +470,7 @@ extern "C" HRESULT DAPI RegReadString( | |||
455 | if (psczValue && *psczValue) | 470 | if (psczValue && *psczValue) |
456 | { | 471 | { |
457 | hr = StrMaxLength(*psczValue, reinterpret_cast<DWORD_PTR*>(&cch)); | 472 | hr = StrMaxLength(*psczValue, reinterpret_cast<DWORD_PTR*>(&cch)); |
458 | ExitOnFailure(hr, "Failed to determine length of string."); | 473 | RegExitOnFailure(hr, "Failed to determine length of string."); |
459 | } | 474 | } |
460 | 475 | ||
461 | if (2 > cch) | 476 | if (2 > cch) |
@@ -463,7 +478,7 @@ extern "C" HRESULT DAPI RegReadString( | |||
463 | cch = 2; | 478 | cch = 2; |
464 | 479 | ||
465 | hr = StrAlloc(psczValue, cch); | 480 | hr = StrAlloc(psczValue, cch); |
466 | ExitOnFailure(hr, "Failed to allocate string to minimum size."); | 481 | RegExitOnFailure(hr, "Failed to allocate string to minimum size."); |
467 | } | 482 | } |
468 | 483 | ||
469 | cb = sizeof(WCHAR) * (cch - 1); // subtract one to ensure there will be a space at the end of the string for the null terminator. | 484 | cb = sizeof(WCHAR) * (cch - 1); // subtract one to ensure there will be a space at the end of the string for the null terminator. |
@@ -472,7 +487,7 @@ extern "C" HRESULT DAPI RegReadString( | |||
472 | { | 487 | { |
473 | cch = cb / sizeof(WCHAR) + 1; // add one to ensure there will be space at the end for the null terminator | 488 | cch = cb / sizeof(WCHAR) + 1; // add one to ensure there will be space at the end for the null terminator |
474 | hr = StrAlloc(psczValue, cch); | 489 | hr = StrAlloc(psczValue, cch); |
475 | ExitOnFailure(hr, "Failed to allocate string bigger for registry value."); | 490 | RegExitOnFailure(hr, "Failed to allocate string bigger for registry value."); |
476 | 491 | ||
477 | er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(*psczValue), &cb); | 492 | er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(*psczValue), &cb); |
478 | } | 493 | } |
@@ -480,7 +495,7 @@ extern "C" HRESULT DAPI RegReadString( | |||
480 | { | 495 | { |
481 | ExitFunction1(hr = E_FILENOTFOUND); | 496 | ExitFunction1(hr = E_FILENOTFOUND); |
482 | } | 497 | } |
483 | ExitOnWin32Error(er, hr, "Failed to read registry key."); | 498 | RegExitOnWin32Error(er, hr, "Failed to read registry key."); |
484 | 499 | ||
485 | if (REG_SZ == dwType || REG_EXPAND_SZ == dwType) | 500 | if (REG_SZ == dwType || REG_EXPAND_SZ == dwType) |
486 | { | 501 | { |
@@ -490,16 +505,16 @@ extern "C" HRESULT DAPI RegReadString( | |||
490 | if (REG_EXPAND_SZ == dwType) | 505 | if (REG_EXPAND_SZ == dwType) |
491 | { | 506 | { |
492 | hr = StrAllocString(&sczExpand, *psczValue, 0); | 507 | hr = StrAllocString(&sczExpand, *psczValue, 0); |
493 | ExitOnFailure(hr, "Failed to copy registry value to expand."); | 508 | RegExitOnFailure(hr, "Failed to copy registry value to expand."); |
494 | 509 | ||
495 | hr = PathExpand(psczValue, sczExpand, PATH_EXPAND_ENVIRONMENT); | 510 | hr = PathExpand(psczValue, sczExpand, PATH_EXPAND_ENVIRONMENT); |
496 | ExitOnFailure(hr, "Failed to expand registry value: %ls", *psczValue); | 511 | RegExitOnFailure(hr, "Failed to expand registry value: %ls", *psczValue); |
497 | } | 512 | } |
498 | } | 513 | } |
499 | else | 514 | else |
500 | { | 515 | { |
501 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); | 516 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); |
502 | ExitOnRootFailure(hr, "Error reading string registry value due to unexpected data type: %u", dwType); | 517 | RegExitOnRootFailure(hr, "Error reading string registry value due to unexpected data type: %u", dwType); |
503 | } | 518 | } |
504 | 519 | ||
505 | LExit: | 520 | LExit: |
@@ -516,7 +531,7 @@ LExit: | |||
516 | HRESULT DAPI RegReadStringArray( | 531 | HRESULT DAPI RegReadStringArray( |
517 | __in HKEY hk, | 532 | __in HKEY hk, |
518 | __in_z_opt LPCWSTR wzName, | 533 | __in_z_opt LPCWSTR wzName, |
519 | __deref_out_ecount_opt(pcStrings) LPWSTR** prgsczStrings, | 534 | __deref_out_ecount_opt(*pcStrings) LPWSTR** prgsczStrings, |
520 | __out DWORD *pcStrings | 535 | __out DWORD *pcStrings |
521 | ) | 536 | ) |
522 | { | 537 | { |
@@ -534,7 +549,7 @@ HRESULT DAPI RegReadStringArray( | |||
534 | { | 549 | { |
535 | cch = cb / sizeof(WCHAR); | 550 | cch = cb / sizeof(WCHAR); |
536 | hr = StrAlloc(&sczValue, cch); | 551 | hr = StrAlloc(&sczValue, cch); |
537 | ExitOnFailure(hr, "Failed to allocate string for registry value."); | 552 | RegExitOnFailure(hr, "Failed to allocate string for registry value."); |
538 | 553 | ||
539 | er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(sczValue), &cb); | 554 | er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(sczValue), &cb); |
540 | } | 555 | } |
@@ -542,18 +557,18 @@ HRESULT DAPI RegReadStringArray( | |||
542 | { | 557 | { |
543 | ExitFunction1(hr = E_FILENOTFOUND); | 558 | ExitFunction1(hr = E_FILENOTFOUND); |
544 | } | 559 | } |
545 | ExitOnWin32Error(er, hr, "Failed to read registry key."); | 560 | RegExitOnWin32Error(er, hr, "Failed to read registry key."); |
546 | 561 | ||
547 | if (cb / sizeof(WCHAR) != cch) | 562 | if (cb / sizeof(WCHAR) != cch) |
548 | { | 563 | { |
549 | hr = E_UNEXPECTED; | 564 | hr = E_UNEXPECTED; |
550 | ExitOnFailure(hr, "The size of registry value %ls unexpected changed between 2 reads", wzName); | 565 | RegExitOnFailure(hr, "The size of registry value %ls unexpected changed between 2 reads", wzName); |
551 | } | 566 | } |
552 | 567 | ||
553 | if (REG_MULTI_SZ != dwType) | 568 | if (REG_MULTI_SZ != dwType) |
554 | { | 569 | { |
555 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); | 570 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); |
556 | ExitOnRootFailure(hr, "Tried to read string array, but registry value %ls is of an incorrect type", wzName); | 571 | RegExitOnRootFailure(hr, "Tried to read string array, but registry value %ls is of an incorrect type", wzName); |
557 | } | 572 | } |
558 | 573 | ||
559 | // Value exists, but is empty, so no strings to return. | 574 | // Value exists, but is empty, so no strings to return. |
@@ -568,7 +583,7 @@ HRESULT DAPI RegReadStringArray( | |||
568 | if (L'\0' != sczValue[cch-1] || L'\0' != sczValue[cch-2]) | 583 | if (L'\0' != sczValue[cch-1] || L'\0' != sczValue[cch-2]) |
569 | { | 584 | { |
570 | hr = E_INVALIDARG; | 585 | hr = E_INVALIDARG; |
571 | ExitOnFailure(hr, "Tried to read string array, but registry value %ls is invalid (isn't double-null-terminated)", wzName); | 586 | RegExitOnFailure(hr, "Tried to read string array, but registry value %ls is invalid (isn't double-null-terminated)", wzName); |
572 | } | 587 | } |
573 | 588 | ||
574 | cch = cb / sizeof(WCHAR); | 589 | cch = cb / sizeof(WCHAR); |
@@ -583,7 +598,7 @@ HRESULT DAPI RegReadStringArray( | |||
583 | // There's one string for every null character encountered (except the extra 1 at the end of the string) | 598 | // There's one string for every null character encountered (except the extra 1 at the end of the string) |
584 | *pcStrings = dwNullCharacters - 1; | 599 | *pcStrings = dwNullCharacters - 1; |
585 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID *>(prgsczStrings), *pcStrings, sizeof(LPWSTR), 0); | 600 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID *>(prgsczStrings), *pcStrings, sizeof(LPWSTR), 0); |
586 | ExitOnFailure(hr, "Failed to resize array while reading REG_MULTI_SZ value"); | 601 | RegExitOnFailure(hr, "Failed to resize array while reading REG_MULTI_SZ value"); |
587 | 602 | ||
588 | #pragma prefast(push) | 603 | #pragma prefast(push) |
589 | #pragma prefast(disable:26010) | 604 | #pragma prefast(disable:26010) |
@@ -591,7 +606,7 @@ HRESULT DAPI RegReadStringArray( | |||
591 | for (DWORD i = 0; i < *pcStrings; ++i) | 606 | for (DWORD i = 0; i < *pcStrings; ++i) |
592 | { | 607 | { |
593 | hr = StrAllocString(&(*prgsczStrings)[i], wzSource, 0); | 608 | hr = StrAllocString(&(*prgsczStrings)[i], wzSource, 0); |
594 | ExitOnFailure(hr, "Failed to allocate copy of string"); | 609 | RegExitOnFailure(hr, "Failed to allocate copy of string"); |
595 | 610 | ||
596 | // Skip past this string | 611 | // Skip past this string |
597 | wzSource += lstrlenW(wzSource) + 1; | 612 | wzSource += lstrlenW(wzSource) + 1; |
@@ -630,19 +645,19 @@ extern "C" HRESULT DAPI RegReadVersion( | |||
630 | if (REG_SZ == dwType || REG_EXPAND_SZ == dwType) | 645 | if (REG_SZ == dwType || REG_EXPAND_SZ == dwType) |
631 | { | 646 | { |
632 | hr = RegReadString(hk, wzName, &sczVersion); | 647 | hr = RegReadString(hk, wzName, &sczVersion); |
633 | ExitOnFailure(hr, "Failed to read registry version as string."); | 648 | RegExitOnFailure(hr, "Failed to read registry version as string."); |
634 | 649 | ||
635 | hr = FileVersionFromStringEx(sczVersion, 0, pdw64Version); | 650 | hr = FileVersionFromStringEx(sczVersion, 0, pdw64Version); |
636 | ExitOnFailure(hr, "Failed to convert registry string to version."); | 651 | RegExitOnFailure(hr, "Failed to convert registry string to version."); |
637 | } | 652 | } |
638 | else if (REG_QWORD == dwType) | 653 | else if (REG_QWORD == dwType) |
639 | { | 654 | { |
640 | ExitOnWin32Error(er, hr, "Failed to read registry key."); | 655 | RegExitOnWin32Error(er, hr, "Failed to read registry key."); |
641 | } | 656 | } |
642 | else // unexpected data type | 657 | else // unexpected data type |
643 | { | 658 | { |
644 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); | 659 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); |
645 | ExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType); | 660 | RegExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType); |
646 | } | 661 | } |
647 | 662 | ||
648 | LExit: | 663 | LExit: |
@@ -672,12 +687,12 @@ extern "C" HRESULT DAPI RegReadNumber( | |||
672 | { | 687 | { |
673 | ExitFunction1(hr = E_FILENOTFOUND); | 688 | ExitFunction1(hr = E_FILENOTFOUND); |
674 | } | 689 | } |
675 | ExitOnWin32Error(er, hr, "Failed to query registry key value."); | 690 | RegExitOnWin32Error(er, hr, "Failed to query registry key value."); |
676 | 691 | ||
677 | if (REG_DWORD != dwType) | 692 | if (REG_DWORD != dwType) |
678 | { | 693 | { |
679 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); | 694 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); |
680 | ExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType); | 695 | RegExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType); |
681 | } | 696 | } |
682 | 697 | ||
683 | LExit: | 698 | LExit: |
@@ -705,12 +720,12 @@ extern "C" HRESULT DAPI RegReadQword( | |||
705 | { | 720 | { |
706 | ExitFunction1(hr = E_FILENOTFOUND); | 721 | ExitFunction1(hr = E_FILENOTFOUND); |
707 | } | 722 | } |
708 | ExitOnWin32Error(er, hr, "Failed to query registry key value."); | 723 | RegExitOnWin32Error(er, hr, "Failed to query registry key value."); |
709 | 724 | ||
710 | if (REG_QWORD != dwType) | 725 | if (REG_QWORD != dwType) |
711 | { | 726 | { |
712 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); | 727 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); |
713 | ExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType); | 728 | RegExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType); |
714 | } | 729 | } |
715 | 730 | ||
716 | LExit: | 731 | LExit: |
@@ -733,7 +748,7 @@ HRESULT DAPI RegWriteBinary( | |||
733 | DWORD er = ERROR_SUCCESS; | 748 | DWORD er = ERROR_SUCCESS; |
734 | 749 | ||
735 | er = vpfnRegSetValueExW(hk, wzName, 0, REG_BINARY, pbBuffer, cbBuffer); | 750 | er = vpfnRegSetValueExW(hk, wzName, 0, REG_BINARY, pbBuffer, cbBuffer); |
736 | ExitOnWin32Error(er, hr, "Failed to write binary registry value with name: %ls", wzName); | 751 | RegExitOnWin32Error(er, hr, "Failed to write binary registry value with name: %ls", wzName); |
737 | 752 | ||
738 | LExit: | 753 | LExit: |
739 | return hr; | 754 | return hr; |
@@ -788,7 +803,7 @@ extern "C" HRESULT DAPI RegWriteStringFormatted( | |||
788 | va_start(args, szFormat); | 803 | va_start(args, szFormat); |
789 | hr = StrAllocFormattedArgs(&sczValue, szFormat, args); | 804 | hr = StrAllocFormattedArgs(&sczValue, szFormat, args); |
790 | va_end(args); | 805 | va_end(args); |
791 | ExitOnFailure(hr, "Failed to allocate %ls value.", wzName); | 806 | RegExitOnFailure(hr, "Failed to allocate %ls value.", wzName); |
792 | 807 | ||
793 | hr = WriteStringToRegistry(hk, wzName, sczValue, REG_SZ); | 808 | hr = WriteStringToRegistry(hk, wzName, sczValue, REG_SZ); |
794 | 809 | ||
@@ -832,18 +847,18 @@ HRESULT DAPI RegWriteStringArray( | |||
832 | { | 847 | { |
833 | dwTemp = dwTotalStringSize; | 848 | dwTemp = dwTotalStringSize; |
834 | hr = ::DWordAdd(dwTemp, 1 + lstrlenW(rgwzValues[i]), &dwTotalStringSize); | 849 | hr = ::DWordAdd(dwTemp, 1 + lstrlenW(rgwzValues[i]), &dwTotalStringSize); |
835 | ExitOnFailure(hr, "DWORD Overflow while adding length of string to write REG_MULTI_SZ"); | 850 | RegExitOnFailure(hr, "DWORD Overflow while adding length of string to write REG_MULTI_SZ"); |
836 | } | 851 | } |
837 | 852 | ||
838 | hr = StrAlloc(&sczWriteValue, dwTotalStringSize); | 853 | hr = StrAlloc(&sczWriteValue, dwTotalStringSize); |
839 | ExitOnFailure(hr, "Failed to allocate space for string while writing REG_MULTI_SZ"); | 854 | RegExitOnFailure(hr, "Failed to allocate space for string while writing REG_MULTI_SZ"); |
840 | 855 | ||
841 | wzCopyDestination = sczWriteValue; | 856 | wzCopyDestination = sczWriteValue; |
842 | dwTemp = dwTotalStringSize; | 857 | dwTemp = dwTotalStringSize; |
843 | for (DWORD i = 0; i < cValues; ++i) | 858 | for (DWORD i = 0; i < cValues; ++i) |
844 | { | 859 | { |
845 | hr = ::StringCchCopyW(wzCopyDestination, dwTotalStringSize, rgwzValues[i]); | 860 | hr = ::StringCchCopyW(wzCopyDestination, dwTotalStringSize, rgwzValues[i]); |
846 | ExitOnFailure(hr, "failed to copy string: %ls", rgwzValues[i]); | 861 | RegExitOnFailure(hr, "failed to copy string: %ls", rgwzValues[i]); |
847 | 862 | ||
848 | dwTemp -= lstrlenW(rgwzValues[i]) + 1; | 863 | dwTemp -= lstrlenW(rgwzValues[i]) + 1; |
849 | wzCopyDestination += lstrlenW(rgwzValues[i]) + 1; | 864 | wzCopyDestination += lstrlenW(rgwzValues[i]) + 1; |
@@ -853,10 +868,10 @@ HRESULT DAPI RegWriteStringArray( | |||
853 | } | 868 | } |
854 | 869 | ||
855 | hr = ::DWordMult(dwTotalStringSize, sizeof(WCHAR), &cbTotalStringSize); | 870 | hr = ::DWordMult(dwTotalStringSize, sizeof(WCHAR), &cbTotalStringSize); |
856 | ExitOnFailure(hr, "Failed to get total string size in bytes"); | 871 | RegExitOnFailure(hr, "Failed to get total string size in bytes"); |
857 | 872 | ||
858 | er = vpfnRegSetValueExW(hk, wzName, 0, REG_MULTI_SZ, reinterpret_cast<const BYTE *>(wzWriteValue), cbTotalStringSize); | 873 | er = vpfnRegSetValueExW(hk, wzName, 0, REG_MULTI_SZ, reinterpret_cast<const BYTE *>(wzWriteValue), cbTotalStringSize); |
859 | ExitOnWin32Error(er, hr, "Failed to set registry value to array of strings (first string of which is): %ls", wzWriteValue); | 874 | RegExitOnWin32Error(er, hr, "Failed to set registry value to array of strings (first string of which is): %ls", wzWriteValue); |
860 | 875 | ||
861 | LExit: | 876 | LExit: |
862 | ReleaseStr(sczWriteValue); | 877 | ReleaseStr(sczWriteValue); |
@@ -878,7 +893,7 @@ extern "C" HRESULT DAPI RegWriteNumber( | |||
878 | DWORD er = ERROR_SUCCESS; | 893 | DWORD er = ERROR_SUCCESS; |
879 | 894 | ||
880 | er = vpfnRegSetValueExW(hk, wzName, 0, REG_DWORD, reinterpret_cast<const BYTE *>(&dwValue), sizeof(dwValue)); | 895 | er = vpfnRegSetValueExW(hk, wzName, 0, REG_DWORD, reinterpret_cast<const BYTE *>(&dwValue), sizeof(dwValue)); |
881 | ExitOnWin32Error(er, hr, "Failed to set %ls value.", wzName); | 896 | RegExitOnWin32Error(er, hr, "Failed to set %ls value.", wzName); |
882 | 897 | ||
883 | LExit: | 898 | LExit: |
884 | return hr; | 899 | return hr; |
@@ -898,7 +913,7 @@ extern "C" HRESULT DAPI RegWriteQword( | |||
898 | DWORD er = ERROR_SUCCESS; | 913 | DWORD er = ERROR_SUCCESS; |
899 | 914 | ||
900 | er = vpfnRegSetValueExW(hk, wzName, 0, REG_QWORD, reinterpret_cast<const BYTE *>(&qwValue), sizeof(qwValue)); | 915 | er = vpfnRegSetValueExW(hk, wzName, 0, REG_QWORD, reinterpret_cast<const BYTE *>(&qwValue), sizeof(qwValue)); |
901 | ExitOnWin32Error(er, hr, "Failed to set %ls value.", wzName); | 916 | RegExitOnWin32Error(er, hr, "Failed to set %ls value.", wzName); |
902 | 917 | ||
903 | LExit: | 918 | LExit: |
904 | return hr; | 919 | return hr; |
@@ -918,7 +933,7 @@ extern "C" HRESULT DAPI RegQueryKey( | |||
918 | DWORD er = ERROR_SUCCESS; | 933 | DWORD er = ERROR_SUCCESS; |
919 | 934 | ||
920 | er = vpfnRegQueryInfoKeyW(hk, NULL, NULL, NULL, pcSubKeys, NULL, NULL, pcValues, NULL, NULL, NULL, NULL); | 935 | er = vpfnRegQueryInfoKeyW(hk, NULL, NULL, NULL, pcSubKeys, NULL, NULL, pcValues, NULL, NULL, NULL, NULL); |
921 | ExitOnWin32Error(er, hr, "Failed to get the number of subkeys and values under registry key."); | 936 | RegExitOnWin32Error(er, hr, "Failed to get the number of subkeys and values under registry key."); |
922 | 937 | ||
923 | LExit: | 938 | LExit: |
924 | return hr; | 939 | return hr; |
@@ -938,11 +953,11 @@ static HRESULT WriteStringToRegistry( | |||
938 | 953 | ||
939 | if (wzValue) | 954 | if (wzValue) |
940 | { | 955 | { |
941 | hr = ::StringCbLengthW(wzValue, DWORD_MAX, reinterpret_cast<size_t*>(&cbValue)); | 956 | hr = ::StringCbLengthW(wzValue, STRSAFE_MAX_CCH * sizeof(TCHAR), reinterpret_cast<size_t*>(&cbValue)); |
942 | ExitOnFailure(hr, "Failed to determine length of registry value: %ls", wzName); | 957 | RegExitOnFailure(hr, "Failed to determine length of registry value: %ls", wzName); |
943 | 958 | ||
944 | er = vpfnRegSetValueExW(hk, wzName, 0, dwType, reinterpret_cast<const BYTE *>(wzValue), cbValue); | 959 | er = vpfnRegSetValueExW(hk, wzName, 0, dwType, reinterpret_cast<const BYTE *>(wzValue), cbValue); |
945 | ExitOnWin32Error(er, hr, "Failed to set registry value: %ls", wzName); | 960 | RegExitOnWin32Error(er, hr, "Failed to set registry value: %ls", wzName); |
946 | } | 961 | } |
947 | else | 962 | else |
948 | { | 963 | { |
@@ -951,7 +966,7 @@ static HRESULT WriteStringToRegistry( | |||
951 | { | 966 | { |
952 | er = ERROR_SUCCESS; | 967 | er = ERROR_SUCCESS; |
953 | } | 968 | } |
954 | ExitOnWin32Error(er, hr, "Failed to delete registry value: %ls", wzName); | 969 | RegExitOnWin32Error(er, hr, "Failed to delete registry value: %ls", wzName); |
955 | } | 970 | } |
956 | 971 | ||
957 | LExit: | 972 | LExit: |
diff --git a/src/dutil/resrutil.cpp b/src/dutil/resrutil.cpp index 1da03ed9..a6a7ee23 100644 --- a/src/dutil/resrutil.cpp +++ b/src/dutil/resrutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define ResrExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_RESRUTIL, x, s, __VA_ARGS__) | ||
8 | #define ResrExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_RESRUTIL, x, s, __VA_ARGS__) | ||
9 | #define ResrExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_RESRUTIL, x, s, __VA_ARGS__) | ||
10 | #define ResrExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_RESRUTIL, x, s, __VA_ARGS__) | ||
11 | #define ResrExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_RESRUTIL, x, s, __VA_ARGS__) | ||
12 | #define ResrExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_RESRUTIL, x, s, __VA_ARGS__) | ||
13 | #define ResrExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_RESRUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define ResrExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_RESRUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define ResrExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_RESRUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define ResrExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_RESRUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define ResrExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_RESRUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define ResrExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_RESRUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | #define RES_STRINGS_PER_BLOCK 16 | 20 | #define RES_STRINGS_PER_BLOCK 16 |
6 | 21 | ||
7 | 22 | ||
@@ -33,7 +48,7 @@ extern "C" HRESULT DAPI ResGetStringLangId( | |||
33 | if (wzPath && *wzPath) | 48 | if (wzPath && *wzPath) |
34 | { | 49 | { |
35 | hModule = LoadLibraryExW(wzPath, NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); | 50 | hModule = LoadLibraryExW(wzPath, NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); |
36 | ExitOnNullWithLastError(hModule, hr, "Failed to open resource file: %ls", wzPath); | 51 | ResrExitOnNullWithLastError(hModule, hr, "Failed to open resource file: %ls", wzPath); |
37 | } | 52 | } |
38 | 53 | ||
39 | #pragma prefast(push) | 54 | #pragma prefast(push) |
@@ -41,7 +56,7 @@ extern "C" HRESULT DAPI ResGetStringLangId( | |||
41 | if (!::EnumResourceLanguagesA(hModule, RT_STRING, MAKEINTRESOURCE(dwBlockId), static_cast<ENUMRESLANGPROC>(EnumLangIdProc), reinterpret_cast<LONG_PTR>(&wFoundLangId))) | 56 | if (!::EnumResourceLanguagesA(hModule, RT_STRING, MAKEINTRESOURCE(dwBlockId), static_cast<ENUMRESLANGPROC>(EnumLangIdProc), reinterpret_cast<LONG_PTR>(&wFoundLangId))) |
42 | #pragma prefast(pop) | 57 | #pragma prefast(pop) |
43 | { | 58 | { |
44 | ExitWithLastError(hr, "Failed to find string language identifier."); | 59 | ResrExitWithLastError(hr, "Failed to find string language identifier."); |
45 | } | 60 | } |
46 | 61 | ||
47 | *pwLangId = wFoundLangId; | 62 | *pwLangId = wFoundLangId; |
@@ -76,12 +91,12 @@ extern "C" HRESULT DAPI ResReadString( | |||
76 | do | 91 | do |
77 | { | 92 | { |
78 | hr = StrAlloc(ppwzString, cch); | 93 | hr = StrAlloc(ppwzString, cch); |
79 | ExitOnFailureDebugTrace(hr, "Failed to allocate string for resource id: %d", uID); | 94 | ResrExitOnFailureDebugTrace(hr, "Failed to allocate string for resource id: %d", uID); |
80 | 95 | ||
81 | cchReturned = ::LoadStringW(hinst, uID, *ppwzString, cch); | 96 | cchReturned = ::LoadStringW(hinst, uID, *ppwzString, cch); |
82 | if (0 == cchReturned) | 97 | if (0 == cchReturned) |
83 | { | 98 | { |
84 | ExitWithLastError(hr, "Failed to load string resource id: %d", uID); | 99 | ResrExitWithLastError(hr, "Failed to load string resource id: %d", uID); |
85 | } | 100 | } |
86 | 101 | ||
87 | // if the returned string count is one character too small, it's likely we have | 102 | // if the returned string count is one character too small, it's likely we have |
@@ -92,7 +107,7 @@ extern "C" HRESULT DAPI ResReadString( | |||
92 | hr = S_FALSE; | 107 | hr = S_FALSE; |
93 | } | 108 | } |
94 | } while (S_FALSE == hr); | 109 | } while (S_FALSE == hr); |
95 | ExitOnFailure(hr, "Failed to load string resource id: %d", uID); | 110 | ResrExitOnFailure(hr, "Failed to load string resource id: %d", uID); |
96 | 111 | ||
97 | LExit: | 112 | LExit: |
98 | return hr; | 113 | return hr; |
@@ -119,7 +134,7 @@ extern "C" HRESULT DAPI ResReadStringAnsi( | |||
119 | do | 134 | do |
120 | { | 135 | { |
121 | hr = StrAnsiAlloc(ppszString, cch); | 136 | hr = StrAnsiAlloc(ppszString, cch); |
122 | ExitOnFailureDebugTrace(hr, "Failed to allocate string for resource id: %d", uID); | 137 | ResrExitOnFailureDebugTrace(hr, "Failed to allocate string for resource id: %d", uID); |
123 | 138 | ||
124 | #pragma prefast(push) | 139 | #pragma prefast(push) |
125 | #pragma prefast(disable:25068) | 140 | #pragma prefast(disable:25068) |
@@ -127,7 +142,7 @@ extern "C" HRESULT DAPI ResReadStringAnsi( | |||
127 | #pragma prefast(pop) | 142 | #pragma prefast(pop) |
128 | if (0 == cchReturned) | 143 | if (0 == cchReturned) |
129 | { | 144 | { |
130 | ExitWithLastError(hr, "Failed to load string resource id: %d", uID); | 145 | ResrExitWithLastError(hr, "Failed to load string resource id: %d", uID); |
131 | } | 146 | } |
132 | 147 | ||
133 | // if the returned string count is one character too small, it's likely we have | 148 | // if the returned string count is one character too small, it's likely we have |
@@ -138,7 +153,7 @@ extern "C" HRESULT DAPI ResReadStringAnsi( | |||
138 | hr = S_FALSE; | 153 | hr = S_FALSE; |
139 | } | 154 | } |
140 | } while (S_FALSE == hr); | 155 | } while (S_FALSE == hr); |
141 | ExitOnFailure(hr, "failed to load string resource id: %d", uID); | 156 | ResrExitOnFailure(hr, "failed to load string resource id: %d", uID); |
142 | 157 | ||
143 | LExit: | 158 | LExit: |
144 | return hr; | 159 | return hr; |
@@ -169,19 +184,19 @@ extern "C" HRESULT DAPI ResReadData( | |||
169 | #pragma prefast(disable:25068) | 184 | #pragma prefast(disable:25068) |
170 | hRsrc = ::FindResourceExA(hinst, RT_RCDATA, szDataName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); | 185 | hRsrc = ::FindResourceExA(hinst, RT_RCDATA, szDataName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); |
171 | #pragma prefast(pop) | 186 | #pragma prefast(pop) |
172 | ExitOnNullWithLastError(hRsrc, hr, "Failed to find resource."); | 187 | ResrExitOnNullWithLastError(hRsrc, hr, "Failed to find resource."); |
173 | 188 | ||
174 | hData = ::LoadResource(hinst, hRsrc); | 189 | hData = ::LoadResource(hinst, hRsrc); |
175 | ExitOnNullWithLastError(hData, hr, "Failed to load resource."); | 190 | ResrExitOnNullWithLastError(hData, hr, "Failed to load resource."); |
176 | 191 | ||
177 | cbData = ::SizeofResource(hinst, hRsrc); | 192 | cbData = ::SizeofResource(hinst, hRsrc); |
178 | if (!cbData) | 193 | if (!cbData) |
179 | { | 194 | { |
180 | ExitWithLastError(hr, "Failed to get size of resource."); | 195 | ResrExitWithLastError(hr, "Failed to get size of resource."); |
181 | } | 196 | } |
182 | 197 | ||
183 | *ppv = ::LockResource(hData); | 198 | *ppv = ::LockResource(hData); |
184 | ExitOnNullWithLastError(*ppv, hr, "Failed to lock data resource."); | 199 | ResrExitOnNullWithLastError(*ppv, hr, "Failed to lock data resource."); |
185 | *pcb = cbData; | 200 | *pcb = cbData; |
186 | 201 | ||
187 | LExit: | 202 | LExit: |
@@ -207,18 +222,18 @@ extern "C" HRESULT DAPI ResExportDataToFile( | |||
207 | BOOL bCreatedFile = FALSE; | 222 | BOOL bCreatedFile = FALSE; |
208 | 223 | ||
209 | hr = ResReadData(NULL, szDataName, &pData, &cbData); | 224 | hr = ResReadData(NULL, szDataName, &pData, &cbData); |
210 | ExitOnFailure(hr, "Failed to GetData from %s.", szDataName); | 225 | ResrExitOnFailure(hr, "Failed to GetData from %s.", szDataName); |
211 | 226 | ||
212 | hFile = ::CreateFileW(wzTargetFile, GENERIC_WRITE, 0, NULL, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL); | 227 | hFile = ::CreateFileW(wzTargetFile, GENERIC_WRITE, 0, NULL, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL); |
213 | if (INVALID_HANDLE_VALUE == hFile) | 228 | if (INVALID_HANDLE_VALUE == hFile) |
214 | { | 229 | { |
215 | ExitWithLastError(hr, "Failed to CreateFileW for %ls.", wzTargetFile); | 230 | ResrExitWithLastError(hr, "Failed to CreateFileW for %ls.", wzTargetFile); |
216 | } | 231 | } |
217 | bCreatedFile = TRUE; | 232 | bCreatedFile = TRUE; |
218 | 233 | ||
219 | if (!::WriteFile(hFile, pData, cbData, &cbWritten, NULL)) | 234 | if (!::WriteFile(hFile, pData, cbData, &cbWritten, NULL)) |
220 | { | 235 | { |
221 | ExitWithLastError(hr, "Failed to ::WriteFile for %ls.", wzTargetFile); | 236 | ResrExitWithLastError(hr, "Failed to ::WriteFile for %ls.", wzTargetFile); |
222 | } | 237 | } |
223 | 238 | ||
224 | LExit: | 239 | LExit: |
diff --git a/src/dutil/reswutil.cpp b/src/dutil/reswutil.cpp index e534fc09..42b49c55 100644 --- a/src/dutil/reswutil.cpp +++ b/src/dutil/reswutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define ReswExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_RESWUTIL, x, s, __VA_ARGS__) | ||
8 | #define ReswExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_RESWUTIL, x, s, __VA_ARGS__) | ||
9 | #define ReswExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_RESWUTIL, x, s, __VA_ARGS__) | ||
10 | #define ReswExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_RESWUTIL, x, s, __VA_ARGS__) | ||
11 | #define ReswExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_RESWUTIL, x, s, __VA_ARGS__) | ||
12 | #define ReswExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_RESWUTIL, x, s, __VA_ARGS__) | ||
13 | #define ReswExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_RESWUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define ReswExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_RESWUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define ReswExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_RESWUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define ReswExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_RESWUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define ReswExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_RESWUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define ReswExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_RESWUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | #define RES_STRINGS_PER_BLOCK 16 | 20 | #define RES_STRINGS_PER_BLOCK 16 |
6 | 21 | ||
7 | // Internal data structure format for a string block in a resource table. | 22 | // Internal data structure format for a string block in a resource table. |
@@ -66,31 +81,31 @@ extern "C" HRESULT DAPI ResWriteString( | |||
66 | DWORD dwStringId = (dwDataId % RES_STRINGS_PER_BLOCK); | 81 | DWORD dwStringId = (dwDataId % RES_STRINGS_PER_BLOCK); |
67 | 82 | ||
68 | hModule = LoadLibraryExW(wzResourceFile, NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); | 83 | hModule = LoadLibraryExW(wzResourceFile, NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); |
69 | ExitOnNullWithLastError(hModule, hr, "Failed to load library: %ls", wzResourceFile); | 84 | ReswExitOnNullWithLastError(hModule, hr, "Failed to load library: %ls", wzResourceFile); |
70 | 85 | ||
71 | hr = StringBlockInitialize(hModule, dwBlockId, wLangId, &StrBlock); | 86 | hr = StringBlockInitialize(hModule, dwBlockId, wLangId, &StrBlock); |
72 | ExitOnFailure(hr, "Failed to get string block to update."); | 87 | ReswExitOnFailure(hr, "Failed to get string block to update."); |
73 | 88 | ||
74 | hr = StringBlockChangeString(&StrBlock, dwStringId, wzData); | 89 | hr = StringBlockChangeString(&StrBlock, dwStringId, wzData); |
75 | ExitOnFailure(hr, "Failed to update string block string."); | 90 | ReswExitOnFailure(hr, "Failed to update string block string."); |
76 | 91 | ||
77 | hr = StringBlockConvertToResourceData(&StrBlock, &pvData, &cbData); | 92 | hr = StringBlockConvertToResourceData(&StrBlock, &pvData, &cbData); |
78 | ExitOnFailure(hr, "Failed to convert string block to resource data."); | 93 | ReswExitOnFailure(hr, "Failed to convert string block to resource data."); |
79 | 94 | ||
80 | ::FreeLibrary(hModule); | 95 | ::FreeLibrary(hModule); |
81 | hModule = NULL; | 96 | hModule = NULL; |
82 | 97 | ||
83 | hUpdate = ::BeginUpdateResourceW(wzResourceFile, FALSE); | 98 | hUpdate = ::BeginUpdateResourceW(wzResourceFile, FALSE); |
84 | ExitOnNullWithLastError(hUpdate, hr, "Failed to ::BeginUpdateResourcesW."); | 99 | ReswExitOnNullWithLastError(hUpdate, hr, "Failed to ::BeginUpdateResourcesW."); |
85 | 100 | ||
86 | if (!::UpdateResourceA(hUpdate, RT_STRING, MAKEINTRESOURCE(dwBlockId), wLangId, pvData, cbData)) | 101 | if (!::UpdateResourceA(hUpdate, RT_STRING, MAKEINTRESOURCE(dwBlockId), wLangId, pvData, cbData)) |
87 | { | 102 | { |
88 | ExitWithLastError(hr, "Failed to ::UpdateResourceA."); | 103 | ReswExitWithLastError(hr, "Failed to ::UpdateResourceA."); |
89 | } | 104 | } |
90 | 105 | ||
91 | if (!::EndUpdateResource(hUpdate, FALSE)) | 106 | if (!::EndUpdateResource(hUpdate, FALSE)) |
92 | { | 107 | { |
93 | ExitWithLastError(hr, "Failed to ::EndUpdateResourceW."); | 108 | ReswExitWithLastError(hr, "Failed to ::EndUpdateResourceW."); |
94 | } | 109 | } |
95 | 110 | ||
96 | hUpdate = NULL; | 111 | hUpdate = NULL; |
@@ -134,16 +149,16 @@ extern "C" HRESULT DAPI ResWriteData( | |||
134 | HANDLE hUpdate = NULL; | 149 | HANDLE hUpdate = NULL; |
135 | 150 | ||
136 | hUpdate = ::BeginUpdateResourceW(wzResourceFile, FALSE); | 151 | hUpdate = ::BeginUpdateResourceW(wzResourceFile, FALSE); |
137 | ExitOnNullWithLastError(hUpdate, hr, "Failed to ::BeginUpdateResourcesW."); | 152 | ReswExitOnNullWithLastError(hUpdate, hr, "Failed to ::BeginUpdateResourcesW."); |
138 | 153 | ||
139 | if (!::UpdateResourceA(hUpdate, RT_RCDATA, szDataName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), pData, cbData)) | 154 | if (!::UpdateResourceA(hUpdate, RT_RCDATA, szDataName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), pData, cbData)) |
140 | { | 155 | { |
141 | ExitWithLastError(hr, "Failed to ::UpdateResourceA."); | 156 | ReswExitWithLastError(hr, "Failed to ::UpdateResourceA."); |
142 | } | 157 | } |
143 | 158 | ||
144 | if (!::EndUpdateResource(hUpdate, FALSE)) | 159 | if (!::EndUpdateResource(hUpdate, FALSE)) |
145 | { | 160 | { |
146 | ExitWithLastError(hr, "Failed to ::EndUpdateResourceW."); | 161 | ReswExitWithLastError(hr, "Failed to ::EndUpdateResourceW."); |
147 | } | 162 | } |
148 | 163 | ||
149 | hUpdate = NULL; | 164 | hUpdate = NULL; |
@@ -177,23 +192,23 @@ extern "C" HRESULT DAPI ResImportDataFromFile( | |||
177 | hFile = ::CreateFileW(wzSourceFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | 192 | hFile = ::CreateFileW(wzSourceFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
178 | if (INVALID_HANDLE_VALUE == hFile) | 193 | if (INVALID_HANDLE_VALUE == hFile) |
179 | { | 194 | { |
180 | ExitWithLastError(hr, "Failed to CreateFileW for %ls.", wzSourceFile); | 195 | ReswExitWithLastError(hr, "Failed to CreateFileW for %ls.", wzSourceFile); |
181 | } | 196 | } |
182 | 197 | ||
183 | cbFile = ::GetFileSize(hFile, NULL); | 198 | cbFile = ::GetFileSize(hFile, NULL); |
184 | if (!cbFile) | 199 | if (!cbFile) |
185 | { | 200 | { |
186 | ExitWithLastError(hr, "Failed to GetFileSize for %ls.", wzSourceFile); | 201 | ReswExitWithLastError(hr, "Failed to GetFileSize for %ls.", wzSourceFile); |
187 | } | 202 | } |
188 | 203 | ||
189 | hMap = ::CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); | 204 | hMap = ::CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); |
190 | ExitOnNullWithLastError(hMap, hr, "Failed to CreateFileMapping for %ls.", wzSourceFile); | 205 | ReswExitOnNullWithLastError(hMap, hr, "Failed to CreateFileMapping for %ls.", wzSourceFile); |
191 | 206 | ||
192 | pv = ::MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, cbFile); | 207 | pv = ::MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, cbFile); |
193 | ExitOnNullWithLastError(pv, hr, "Failed to MapViewOfFile for %ls.", wzSourceFile); | 208 | ReswExitOnNullWithLastError(pv, hr, "Failed to MapViewOfFile for %ls.", wzSourceFile); |
194 | 209 | ||
195 | hr = ResWriteData(wzTargetFile, szDataName, pv, cbFile); | 210 | hr = ResWriteData(wzTargetFile, szDataName, pv, cbFile); |
196 | ExitOnFailure(hr, "Failed to ResSetData %s on file %ls.", szDataName, wzTargetFile); | 211 | ReswExitOnFailure(hr, "Failed to ResSetData %s on file %ls.", szDataName, wzTargetFile); |
197 | 212 | ||
198 | LExit: | 213 | LExit: |
199 | if (pv) | 214 | if (pv) |
@@ -226,25 +241,25 @@ static HRESULT StringBlockInitialize( | |||
226 | DWORD cbData = 0; | 241 | DWORD cbData = 0; |
227 | 242 | ||
228 | hRsrc = ::FindResourceExA(hModule, RT_STRING, MAKEINTRESOURCE(dwBlockId), wLangId); | 243 | hRsrc = ::FindResourceExA(hModule, RT_STRING, MAKEINTRESOURCE(dwBlockId), wLangId); |
229 | ExitOnNullWithLastError(hRsrc, hr, "Failed to ::FindResourceExW."); | 244 | ReswExitOnNullWithLastError(hRsrc, hr, "Failed to ::FindResourceExW."); |
230 | 245 | ||
231 | hData = ::LoadResource(hModule, hRsrc); | 246 | hData = ::LoadResource(hModule, hRsrc); |
232 | ExitOnNullWithLastError(hData, hr, "Failed to ::LoadResource."); | 247 | ReswExitOnNullWithLastError(hData, hr, "Failed to ::LoadResource."); |
233 | 248 | ||
234 | cbData = ::SizeofResource(hModule, hRsrc); | 249 | cbData = ::SizeofResource(hModule, hRsrc); |
235 | if (!cbData) | 250 | if (!cbData) |
236 | { | 251 | { |
237 | ExitWithLastError(hr, "Failed to ::SizeofResource."); | 252 | ReswExitWithLastError(hr, "Failed to ::SizeofResource."); |
238 | } | 253 | } |
239 | 254 | ||
240 | pvData = ::LockResource(hData); | 255 | pvData = ::LockResource(hData); |
241 | ExitOnNullWithLastError(pvData, hr, "Failed to lock data resource."); | 256 | ReswExitOnNullWithLastError(pvData, hr, "Failed to lock data resource."); |
242 | 257 | ||
243 | pStrBlock->dwBlockId = dwBlockId; | 258 | pStrBlock->dwBlockId = dwBlockId; |
244 | pStrBlock->wLangId = wLangId; | 259 | pStrBlock->wLangId = wLangId; |
245 | 260 | ||
246 | hr = StringBlockConvertFromResourceData(pStrBlock, pvData, cbData); | 261 | hr = StringBlockConvertFromResourceData(pStrBlock, pvData, cbData); |
247 | ExitOnFailure(hr, "Failed to convert string block from resource data."); | 262 | ReswExitOnFailure(hr, "Failed to convert string block from resource data."); |
248 | 263 | ||
249 | LExit: | 264 | LExit: |
250 | return hr; | 265 | return hr; |
@@ -276,10 +291,10 @@ static HRESULT StringBlockChangeString( | |||
276 | DWORD cchData = lstrlenW(szData); | 291 | DWORD cchData = lstrlenW(szData); |
277 | 292 | ||
278 | pwzData = static_cast<LPWSTR>(MemAlloc((cchData + 1) * sizeof(WCHAR), TRUE)); | 293 | pwzData = static_cast<LPWSTR>(MemAlloc((cchData + 1) * sizeof(WCHAR), TRUE)); |
279 | ExitOnNull(pwzData, hr, E_OUTOFMEMORY, "Failed to allocate new block string."); | 294 | ReswExitOnNull(pwzData, hr, E_OUTOFMEMORY, "Failed to allocate new block string."); |
280 | 295 | ||
281 | hr = ::StringCchCopyW(pwzData, cchData + 1, szData); | 296 | hr = ::StringCchCopyW(pwzData, cchData + 1, szData); |
282 | ExitOnFailure(hr, "Failed to copy new block string."); | 297 | ReswExitOnFailure(hr, "Failed to copy new block string."); |
283 | 298 | ||
284 | ReleaseNullMem(pStrBlock->rgwz[dwStringId]); | 299 | ReleaseNullMem(pStrBlock->rgwz[dwStringId]); |
285 | 300 | ||
@@ -311,7 +326,7 @@ static HRESULT StringBlockConvertToResourceData( | |||
311 | cbData *= sizeof(WCHAR); | 326 | cbData *= sizeof(WCHAR); |
312 | 327 | ||
313 | pvData = MemAlloc(cbData, TRUE); | 328 | pvData = MemAlloc(cbData, TRUE); |
314 | ExitOnNull(pvData, hr, E_OUTOFMEMORY, "Failed to allocate buffer to convert string block."); | 329 | ReswExitOnNull(pvData, hr, E_OUTOFMEMORY, "Failed to allocate buffer to convert string block."); |
315 | 330 | ||
316 | pwz = static_cast<LPWSTR>(pvData); | 331 | pwz = static_cast<LPWSTR>(pvData); |
317 | for (DWORD i = 0; i < RES_STRINGS_PER_BLOCK; ++i) | 332 | for (DWORD i = 0; i < RES_STRINGS_PER_BLOCK; ++i) |
@@ -355,10 +370,10 @@ static HRESULT StringBlockConvertFromResourceData( | |||
355 | ++pwzParse; | 370 | ++pwzParse; |
356 | 371 | ||
357 | pStrBlock->rgwz[i] = static_cast<LPWSTR>(MemAlloc((cchParse + 1) * sizeof(WCHAR), TRUE)); | 372 | pStrBlock->rgwz[i] = static_cast<LPWSTR>(MemAlloc((cchParse + 1) * sizeof(WCHAR), TRUE)); |
358 | ExitOnNull(pStrBlock->rgwz[i], hr, E_OUTOFMEMORY, "Failed to populate pStrBlock."); | 373 | ReswExitOnNull(pStrBlock->rgwz[i], hr, E_OUTOFMEMORY, "Failed to populate pStrBlock."); |
359 | 374 | ||
360 | hr = ::StringCchCopyNExW(pStrBlock->rgwz[i], cchParse + 1, pwzParse, cchParse, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); | 375 | hr = ::StringCchCopyNExW(pStrBlock->rgwz[i], cchParse + 1, pwzParse, cchParse, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); |
361 | ExitOnFailure(hr, "Failed to copy parsed resource data into string block."); | 376 | ReswExitOnFailure(hr, "Failed to copy parsed resource data into string block."); |
362 | 377 | ||
363 | pwzParse += cchParse; | 378 | pwzParse += cchParse; |
364 | } | 379 | } |
diff --git a/src/dutil/rexutil.cpp b/src/dutil/rexutil.cpp index 73500630..155ca714 100644 --- a/src/dutil/rexutil.cpp +++ b/src/dutil/rexutil.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | #include "rexutil.h" | 4 | #include "rexutil.h" |
5 | 5 | ||
6 | |||
7 | // Exit macros | ||
8 | #define RexExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__) | ||
9 | #define RexExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__) | ||
10 | #define RexExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__) | ||
11 | #define RexExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__) | ||
12 | #define RexExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__) | ||
13 | #define RexExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__) | ||
14 | #define RexExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_REXUTIL, p, x, e, s, __VA_ARGS__) | ||
15 | #define RexExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_REXUTIL, p, x, s, __VA_ARGS__) | ||
16 | #define RexExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_REXUTIL, p, x, e, s, __VA_ARGS__) | ||
17 | #define RexExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_REXUTIL, p, x, s, __VA_ARGS__) | ||
18 | #define RexExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_REXUTIL, e, x, s, __VA_ARGS__) | ||
19 | #define RexExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_REXUTIL, g, x, s, __VA_ARGS__) | ||
20 | |||
6 | // | 21 | // |
7 | // static globals | 22 | // static globals |
8 | // | 23 | // |
@@ -60,7 +75,7 @@ extern "C" HRESULT RexInitialize() | |||
60 | if (!vhfdi) | 75 | if (!vhfdi) |
61 | { | 76 | { |
62 | hr = E_FAIL; | 77 | hr = E_FAIL; |
63 | ExitOnFailure(hr, "failed to initialize cabinet.dll"); // TODO: put verf info in trace message here | 78 | RexExitOnFailure(hr, "failed to initialize cabinet.dll"); // TODO: put verf info in trace message here |
64 | } | 79 | } |
65 | 80 | ||
66 | ::ZeroMemory(vrgffFileTable, sizeof(vrgffFileTable)); | 81 | ::ZeroMemory(vrgffFileTable, sizeof(vrgffFileTable)); |
@@ -123,12 +138,12 @@ extern "C" HRESULT RexExtract( | |||
123 | // load the cabinet resource | 138 | // load the cabinet resource |
124 | // | 139 | // |
125 | hResInfo = ::FindResourceExA(NULL, RT_RCDATA, szResource, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); | 140 | hResInfo = ::FindResourceExA(NULL, RT_RCDATA, szResource, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); |
126 | ExitOnNullWithLastError(hResInfo, hr, "Failed to find resource."); | 141 | RexExitOnNullWithLastError(hResInfo, hr, "Failed to find resource."); |
127 | //hResInfo = ::FindResourceW(NULL, wzResource, /*RT_RCDATA*/MAKEINTRESOURCEW(10)); | 142 | //hResInfo = ::FindResourceW(NULL, wzResource, /*RT_RCDATA*/MAKEINTRESOURCEW(10)); |
128 | //ExitOnNullWithLastError(hResInfo, hr, "failed to load resource info"); | 143 | //ExitOnNullWithLastError(hResInfo, hr, "failed to load resource info"); |
129 | 144 | ||
130 | hRes = ::LoadResource(NULL, hResInfo); | 145 | hRes = ::LoadResource(NULL, hResInfo); |
131 | ExitOnNullWithLastError(hRes, hr, "failed to load resource"); | 146 | RexExitOnNullWithLastError(hRes, hr, "failed to load resource"); |
132 | 147 | ||
133 | vcbRes = ::SizeofResource(NULL, hResInfo); | 148 | vcbRes = ::SizeofResource(NULL, hResInfo); |
134 | vpbRes = (const BYTE*)::LockResource(hRes); | 149 | vpbRes = (const BYTE*)::LockResource(hRes); |
@@ -140,11 +155,11 @@ extern "C" HRESULT RexExtract( | |||
140 | // | 155 | // |
141 | //if (!::WideCharToMultiByte(CP_ACP, 0, wzResource, -1, vszResource, countof(vszResource), NULL, NULL)) | 156 | //if (!::WideCharToMultiByte(CP_ACP, 0, wzResource, -1, vszResource, countof(vszResource), NULL, NULL)) |
142 | //{ | 157 | //{ |
143 | // ExitOnLastError(hr, "failed to convert cabinet resource name to ASCII: %ls", wzResource); | 158 | // RexExitOnLastError(hr, "failed to convert cabinet resource name to ASCII: %ls", wzResource); |
144 | //} | 159 | //} |
145 | 160 | ||
146 | hr = ::StringCchCopyA(vszResource, countof(vszResource), szResource); | 161 | hr = ::StringCchCopyA(vszResource, countof(vszResource), szResource); |
147 | ExitOnFailure(hr, "Failed to copy resource name to global."); | 162 | RexExitOnFailure(hr, "Failed to copy resource name to global."); |
148 | 163 | ||
149 | // | 164 | // |
150 | // iterate through files in cabinet extracting them to the callback function | 165 | // iterate through files in cabinet extracting them to the callback function |
@@ -193,7 +208,7 @@ static __callback INT_PTR FAR DIAMONDAPI RexOpen(__in_z char FAR *pszFile, int o | |||
193 | if ((oflag != (/*_O_BINARY*/ 0x8000 | /*_O_RDONLY*/ 0x0000)) || (pmode != (_S_IREAD | _S_IWRITE))) | 208 | if ((oflag != (/*_O_BINARY*/ 0x8000 | /*_O_RDONLY*/ 0x0000)) || (pmode != (_S_IREAD | _S_IWRITE))) |
194 | { | 209 | { |
195 | hr = E_OUTOFMEMORY; | 210 | hr = E_OUTOFMEMORY; |
196 | ExitOnFailure(hr, "FDI asked for to create a scratch file, which is unusual"); | 211 | RexExitOnFailure(hr, "FDI asked for to create a scratch file, which is unusual"); |
197 | } | 212 | } |
198 | 213 | ||
199 | // find an empty spot in the fake file table | 214 | // find an empty spot in the fake file table |
@@ -209,7 +224,7 @@ static __callback INT_PTR FAR DIAMONDAPI RexOpen(__in_z char FAR *pszFile, int o | |||
209 | if (FILETABLESIZE <= i) | 224 | if (FILETABLESIZE <= i) |
210 | { | 225 | { |
211 | hr = E_OUTOFMEMORY; | 226 | hr = E_OUTOFMEMORY; |
212 | ExitOnFailure(hr, "File table exceeded"); | 227 | RexExitOnFailure(hr, "File table exceeded"); |
213 | } | 228 | } |
214 | 229 | ||
215 | if (0 == lstrcmpA(vszResource, pszFile)) | 230 | if (0 == lstrcmpA(vszResource, pszFile)) |
@@ -225,7 +240,7 @@ static __callback INT_PTR FAR DIAMONDAPI RexOpen(__in_z char FAR *pszFile, int o | |||
225 | hFile = ::CreateFileA(pszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | 240 | hFile = ::CreateFileA(pszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
226 | if (INVALID_HANDLE_VALUE == hFile) | 241 | if (INVALID_HANDLE_VALUE == hFile) |
227 | { | 242 | { |
228 | ExitWithLastError(hr, "failed to open file: %s", pszFile); | 243 | RexExitWithLastError(hr, "failed to open file: %s", pszFile); |
229 | } | 244 | } |
230 | 245 | ||
231 | vrgffFileTable[i].fUsed = TRUE; | 246 | vrgffFileTable[i].fUsed = TRUE; |
@@ -267,7 +282,7 @@ static __callback UINT FAR DIAMONDAPI RexRead(INT_PTR hf, __out_bcount(cb) void | |||
267 | 282 | ||
268 | if (!::ReadFile(vrgffFileTable[hf].hFile, pv, cb, &cbRead, NULL)) | 283 | if (!::ReadFile(vrgffFileTable[hf].hFile, pv, cb, &cbRead, NULL)) |
269 | { | 284 | { |
270 | ExitWithLastError(hr, "failed to read during cabinet extraction"); | 285 | RexExitWithLastError(hr, "failed to read during cabinet extraction"); |
271 | } | 286 | } |
272 | } | 287 | } |
273 | 288 | ||
@@ -292,7 +307,7 @@ static __callback UINT FAR DIAMONDAPI RexWrite(INT_PTR hf, __in_bcount(cb) void | |||
292 | Assert(vrgffFileTable[hf].hFile && vrgffFileTable[hf].hFile != INVALID_HANDLE_VALUE); | 307 | Assert(vrgffFileTable[hf].hFile && vrgffFileTable[hf].hFile != INVALID_HANDLE_VALUE); |
293 | if (!::WriteFile(reinterpret_cast<HANDLE>(vrgffFileTable[hf].hFile), pv, cb, &cbWrite, NULL)) | 308 | if (!::WriteFile(reinterpret_cast<HANDLE>(vrgffFileTable[hf].hFile), pv, cb, &cbWrite, NULL)) |
294 | { | 309 | { |
295 | ExitWithLastError(hr, "failed to write during cabinet extraction"); | 310 | RexExitWithLastError(hr, "failed to write during cabinet extraction"); |
296 | } | 311 | } |
297 | 312 | ||
298 | // call the writer callback if defined | 313 | // call the writer callback if defined |
@@ -333,7 +348,7 @@ static __callback long FAR DIAMONDAPI RexSeek(INT_PTR hf, long dist, int seektyp | |||
333 | default : | 348 | default : |
334 | dwMoveMethod = 0; | 349 | dwMoveMethod = 0; |
335 | hr = E_UNEXPECTED; | 350 | hr = E_UNEXPECTED; |
336 | ExitOnFailure(hr, "unexpected seektype in FDISeek(): %d", seektype); | 351 | RexExitOnFailure(hr, "unexpected seektype in FDISeek(): %d", seektype); |
337 | } | 352 | } |
338 | 353 | ||
339 | if (MEMORY_FILE == vrgffFileTable[hf].fftType) | 354 | if (MEMORY_FILE == vrgffFileTable[hf].fftType) |
@@ -362,7 +377,7 @@ static __callback long FAR DIAMONDAPI RexSeek(INT_PTR hf, long dist, int seektyp | |||
362 | lMove = ::SetFilePointer(vrgffFileTable[hf].hFile, dist, NULL, dwMoveMethod); | 377 | lMove = ::SetFilePointer(vrgffFileTable[hf].hFile, dist, NULL, dwMoveMethod); |
363 | if (0xFFFFFFFF == lMove) | 378 | if (0xFFFFFFFF == lMove) |
364 | { | 379 | { |
365 | ExitWithLastError(hr, "failed to move file pointer %d bytes", dist); | 380 | RexExitWithLastError(hr, "failed to move file pointer %d bytes", dist); |
366 | } | 381 | } |
367 | } | 382 | } |
368 | 383 | ||
@@ -394,7 +409,7 @@ __callback int FAR DIAMONDAPI RexClose(INT_PTR hf) | |||
394 | 409 | ||
395 | if (!::CloseHandle(vrgffFileTable[hf].hFile)) | 410 | if (!::CloseHandle(vrgffFileTable[hf].hFile)) |
396 | { | 411 | { |
397 | ExitWithLastError(hr, "failed to close file during cabinet extraction"); | 412 | RexExitWithLastError(hr, "failed to close file during cabinet extraction"); |
398 | } | 413 | } |
399 | 414 | ||
400 | vrgffFileTable[hf].hFile = INVALID_HANDLE_VALUE; | 415 | vrgffFileTable[hf].hFile = INVALID_HANDLE_VALUE; |
@@ -440,7 +455,7 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati | |||
440 | sz = static_cast<LPCSTR>(pFDINotify->psz1); | 455 | sz = static_cast<LPCSTR>(pFDINotify->psz1); |
441 | if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz))) | 456 | if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz))) |
442 | { | 457 | { |
443 | ExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz); | 458 | RexExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz); |
444 | } | 459 | } |
445 | 460 | ||
446 | if (prcs->pfnProgress) | 461 | if (prcs->pfnProgress) |
@@ -457,25 +472,25 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati | |||
457 | // get the created date for the resource in the cabinet | 472 | // get the created date for the resource in the cabinet |
458 | if (!::DosDateTimeToFileTime(pFDINotify->date, pFDINotify->time, &ft)) | 473 | if (!::DosDateTimeToFileTime(pFDINotify->date, pFDINotify->time, &ft)) |
459 | { | 474 | { |
460 | ExitWithLastError(hr, "failed to get time for resource: %ls", wz); | 475 | RexExitWithLastError(hr, "failed to get time for resource: %ls", wz); |
461 | } | 476 | } |
462 | 477 | ||
463 | WCHAR wzPath[MAX_PATH]; | 478 | WCHAR wzPath[MAX_PATH]; |
464 | 479 | ||
465 | hr = ::StringCchCopyW(wzPath, countof(wzPath), prcs->pwzExtractDir); | 480 | hr = ::StringCchCopyW(wzPath, countof(wzPath), prcs->pwzExtractDir); |
466 | ExitOnFailure(hr, "failed to copy extract directory: %ls for file: %ls", prcs->pwzExtractDir, wz); | 481 | RexExitOnFailure(hr, "failed to copy extract directory: %ls for file: %ls", prcs->pwzExtractDir, wz); |
467 | 482 | ||
468 | if (L'*' == *prcs->pwzExtract) | 483 | if (L'*' == *prcs->pwzExtract) |
469 | { | 484 | { |
470 | hr = ::StringCchCatW(wzPath, countof(wzPath), wz); | 485 | hr = ::StringCchCatW(wzPath, countof(wzPath), wz); |
471 | ExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, wz); | 486 | RexExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, wz); |
472 | } | 487 | } |
473 | else | 488 | else |
474 | { | 489 | { |
475 | Assert(*prcs->pwzExtractName); | 490 | Assert(*prcs->pwzExtractName); |
476 | 491 | ||
477 | hr = ::StringCchCatW(wzPath, countof(wzPath), prcs->pwzExtractName); | 492 | hr = ::StringCchCatW(wzPath, countof(wzPath), prcs->pwzExtractName); |
478 | ExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, prcs->pwzExtractName); | 493 | RexExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, prcs->pwzExtractName); |
479 | } | 494 | } |
480 | 495 | ||
481 | // Quickly chop off the file name part of the path to ensure the path exists | 496 | // Quickly chop off the file name part of the path to ensure the path exists |
@@ -486,7 +501,7 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati | |||
486 | *wzFile = L'\0'; | 501 | *wzFile = L'\0'; |
487 | 502 | ||
488 | hr = DirEnsureExists(wzPath, NULL); | 503 | hr = DirEnsureExists(wzPath, NULL); |
489 | ExitOnFailure(hr, "failed to ensure directory: %ls", wzPath); | 504 | RexExitOnFailure(hr, "failed to ensure directory: %ls", wzPath); |
490 | 505 | ||
491 | hr = S_OK; | 506 | hr = S_OK; |
492 | 507 | ||
@@ -505,14 +520,14 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati | |||
505 | if (FILETABLESIZE <= i) | 520 | if (FILETABLESIZE <= i) |
506 | { | 521 | { |
507 | hr = E_OUTOFMEMORY; | 522 | hr = E_OUTOFMEMORY; |
508 | ExitOnFailure(hr, "File table exceeded"); | 523 | RexExitOnFailure(hr, "File table exceeded"); |
509 | } | 524 | } |
510 | 525 | ||
511 | // open the file | 526 | // open the file |
512 | hFile = ::CreateFileW(wzPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | 527 | hFile = ::CreateFileW(wzPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
513 | if (INVALID_HANDLE_VALUE == hFile) | 528 | if (INVALID_HANDLE_VALUE == hFile) |
514 | { | 529 | { |
515 | ExitWithLastError(hr, "failed to open file: %ls", wzPath); | 530 | RexExitWithLastError(hr, "failed to open file: %ls", wzPath); |
516 | } | 531 | } |
517 | 532 | ||
518 | vrgffFileTable[i].fUsed = TRUE; | 533 | vrgffFileTable[i].fUsed = TRUE; |
@@ -545,7 +560,7 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati | |||
545 | sz = static_cast<LPCSTR>(pFDINotify->psz1); | 560 | sz = static_cast<LPCSTR>(pFDINotify->psz1); |
546 | if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz))) | 561 | if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz))) |
547 | { | 562 | { |
548 | ExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz); | 563 | RexExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz); |
549 | } | 564 | } |
550 | 565 | ||
551 | RexClose(pFDINotify->hf); | 566 | RexClose(pFDINotify->hf); |
diff --git a/src/dutil/rmutil.cpp b/src/dutil/rmutil.cpp index 75d3e277..95c8c8a4 100644 --- a/src/dutil/rmutil.cpp +++ b/src/dutil/rmutil.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | #include <restartmanager.h> | 4 | #include <restartmanager.h> |
5 | 5 | ||
6 | |||
7 | // Exit macros | ||
8 | #define RmExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_RMUTIL, x, s, __VA_ARGS__) | ||
9 | #define RmExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_RMUTIL, x, s, __VA_ARGS__) | ||
10 | #define RmExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_RMUTIL, x, s, __VA_ARGS__) | ||
11 | #define RmExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_RMUTIL, x, s, __VA_ARGS__) | ||
12 | #define RmExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_RMUTIL, x, s, __VA_ARGS__) | ||
13 | #define RmExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_RMUTIL, x, s, __VA_ARGS__) | ||
14 | #define RmExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_RMUTIL, p, x, e, s, __VA_ARGS__) | ||
15 | #define RmExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_RMUTIL, p, x, s, __VA_ARGS__) | ||
16 | #define RmExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_RMUTIL, p, x, e, s, __VA_ARGS__) | ||
17 | #define RmExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_RMUTIL, p, x, s, __VA_ARGS__) | ||
18 | #define RmExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_RMUTIL, e, x, s, __VA_ARGS__) | ||
19 | #define RmExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_RMUTIL, g, x, s, __VA_ARGS__) | ||
20 | |||
6 | #define ARRAY_GROWTH_SIZE 5 | 21 | #define ARRAY_GROWTH_SIZE 5 |
7 | 22 | ||
8 | typedef DWORD (WINAPI *PFNRMJOINSESSION)( | 23 | typedef DWORD (WINAPI *PFNRMJOINSESSION)( |
@@ -80,13 +95,13 @@ extern "C" HRESULT DAPI RmuJoinSession( | |||
80 | *ppSession = NULL; | 95 | *ppSession = NULL; |
81 | 96 | ||
82 | pSession = static_cast<PRMU_SESSION>(MemAlloc(sizeof(RMU_SESSION), TRUE)); | 97 | pSession = static_cast<PRMU_SESSION>(MemAlloc(sizeof(RMU_SESSION), TRUE)); |
83 | ExitOnNull(pSession, hr, E_OUTOFMEMORY, "Failed to allocate the RMU_SESSION structure."); | 98 | RmExitOnNull(pSession, hr, E_OUTOFMEMORY, "Failed to allocate the RMU_SESSION structure."); |
84 | 99 | ||
85 | hr = RmuInitialize(); | 100 | hr = RmuInitialize(); |
86 | ExitOnFailure(hr, "Failed to initialize Restart Manager."); | 101 | RmExitOnFailure(hr, "Failed to initialize Restart Manager."); |
87 | 102 | ||
88 | er = vpfnRmJoinSession(&pSession->dwSessionHandle, wzSessionKey); | 103 | er = vpfnRmJoinSession(&pSession->dwSessionHandle, wzSessionKey); |
89 | ExitOnWin32Error(er, hr, "Failed to join Restart Manager session %ls.", wzSessionKey); | 104 | RmExitOnWin32Error(er, hr, "Failed to join Restart Manager session %ls.", wzSessionKey); |
90 | 105 | ||
91 | ::InitializeCriticalSection(&pSession->cs); | 106 | ::InitializeCriticalSection(&pSession->cs); |
92 | pSession->fInitialized = TRUE; | 107 | pSession->fInitialized = TRUE; |
@@ -120,7 +135,7 @@ extern "C" HRESULT DAPI RmuAddFile( | |||
120 | 135 | ||
121 | // Create or grow the jagged array. | 136 | // Create or grow the jagged array. |
122 | hr = StrArrayAllocString(&pSession->rgsczFilenames, &pSession->cFilenames, wzPath, 0); | 137 | hr = StrArrayAllocString(&pSession->rgsczFilenames, &pSession->cFilenames, wzPath, 0); |
123 | ExitOnFailure(hr, "Failed to add the filename to the array."); | 138 | RmExitOnFailure(hr, "Failed to add the filename to the array."); |
124 | 139 | ||
125 | LExit: | 140 | LExit: |
126 | ::LeaveCriticalSection(&pSession->cs); | 141 | ::LeaveCriticalSection(&pSession->cs); |
@@ -161,29 +176,29 @@ extern "C" HRESULT DAPI RmuAddProcessById( | |||
161 | // Adding SeDebugPrivilege in the event that the process targeted by ::OpenProcess() is in a another user context. | 176 | // Adding SeDebugPrivilege in the event that the process targeted by ::OpenProcess() is in a another user context. |
162 | if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken)) | 177 | if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken)) |
163 | { | 178 | { |
164 | ExitWithLastError(hr, "Failed to get process token."); | 179 | RmExitWithLastError(hr, "Failed to get process token."); |
165 | } | 180 | } |
166 | 181 | ||
167 | priv.PrivilegeCount = 1; | 182 | priv.PrivilegeCount = 1; |
168 | priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; | 183 | priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; |
169 | if (!::LookupPrivilegeValueW(NULL, L"SeDebugPrivilege", &priv.Privileges[0].Luid)) | 184 | if (!::LookupPrivilegeValueW(NULL, L"SeDebugPrivilege", &priv.Privileges[0].Luid)) |
170 | { | 185 | { |
171 | ExitWithLastError(hr, "Failed to get debug privilege LUID."); | 186 | RmExitWithLastError(hr, "Failed to get debug privilege LUID."); |
172 | } | 187 | } |
173 | 188 | ||
174 | cbPrevPriv = sizeof(TOKEN_PRIVILEGES); | 189 | cbPrevPriv = sizeof(TOKEN_PRIVILEGES); |
175 | pPrevPriv = static_cast<TOKEN_PRIVILEGES*>(MemAlloc(cbPrevPriv, TRUE)); | 190 | pPrevPriv = static_cast<TOKEN_PRIVILEGES*>(MemAlloc(cbPrevPriv, TRUE)); |
176 | ExitOnNull(pPrevPriv, hr, E_OUTOFMEMORY, "Failed to allocate memory for empty previous privileges."); | 191 | RmExitOnNull(pPrevPriv, hr, E_OUTOFMEMORY, "Failed to allocate memory for empty previous privileges."); |
177 | 192 | ||
178 | if (!::AdjustTokenPrivileges(hToken, FALSE, &priv, cbPrevPriv, pPrevPriv, &cbPrevPriv)) | 193 | if (!::AdjustTokenPrivileges(hToken, FALSE, &priv, cbPrevPriv, pPrevPriv, &cbPrevPriv)) |
179 | { | 194 | { |
180 | LPVOID pv = MemReAlloc(pPrevPriv, cbPrevPriv, TRUE); | 195 | LPVOID pv = MemReAlloc(pPrevPriv, cbPrevPriv, TRUE); |
181 | ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for previous privileges."); | 196 | RmExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for previous privileges."); |
182 | pPrevPriv = static_cast<TOKEN_PRIVILEGES*>(pv); | 197 | pPrevPriv = static_cast<TOKEN_PRIVILEGES*>(pv); |
183 | 198 | ||
184 | if (!::AdjustTokenPrivileges(hToken, FALSE, &priv, cbPrevPriv, pPrevPriv, &cbPrevPriv)) | 199 | if (!::AdjustTokenPrivileges(hToken, FALSE, &priv, cbPrevPriv, pPrevPriv, &cbPrevPriv)) |
185 | { | 200 | { |
186 | ExitWithLastError(hr, "Failed to get debug privilege LUID."); | 201 | RmExitWithLastError(hr, "Failed to get debug privilege LUID."); |
187 | } | 202 | } |
188 | } | 203 | } |
189 | 204 | ||
@@ -195,13 +210,13 @@ extern "C" HRESULT DAPI RmuAddProcessById( | |||
195 | { | 210 | { |
196 | if (!::GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) | 211 | if (!::GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) |
197 | { | 212 | { |
198 | ExitWithLastError(hr, "Failed to get the process times for process ID %d.", dwProcessId); | 213 | RmExitWithLastError(hr, "Failed to get the process times for process ID %d.", dwProcessId); |
199 | } | 214 | } |
200 | 215 | ||
201 | ::EnterCriticalSection(&pSession->cs); | 216 | ::EnterCriticalSection(&pSession->cs); |
202 | fLocked = TRUE; | 217 | fLocked = TRUE; |
203 | hr = RmuApplicationArrayAlloc(&pSession->rgApplications, &pSession->cApplications, dwProcessId, CreationTime); | 218 | hr = RmuApplicationArrayAlloc(&pSession->rgApplications, &pSession->cApplications, dwProcessId, CreationTime); |
204 | ExitOnFailure(hr, "Failed to add the application to the array."); | 219 | RmExitOnFailure(hr, "Failed to add the application to the array."); |
205 | } | 220 | } |
206 | else | 221 | else |
207 | { | 222 | { |
@@ -213,7 +228,7 @@ extern "C" HRESULT DAPI RmuAddProcessById( | |||
213 | } | 228 | } |
214 | else | 229 | else |
215 | { | 230 | { |
216 | ExitOnWin32Error(er, hr, "Failed to open the process ID %d.", dwProcessId); | 231 | RmExitOnWin32Error(er, hr, "Failed to open the process ID %d.", dwProcessId); |
217 | } | 232 | } |
218 | } | 233 | } |
219 | 234 | ||
@@ -258,7 +273,7 @@ extern "C" HRESULT DAPI RmuAddProcessesByName( | |||
258 | BOOL fNotFound = FALSE; | 273 | BOOL fNotFound = FALSE; |
259 | 274 | ||
260 | hr = ProcFindAllIdsFromExeName(wzProcessName, &pdwProcessIds, &cProcessIds); | 275 | hr = ProcFindAllIdsFromExeName(wzProcessName, &pdwProcessIds, &cProcessIds); |
261 | ExitOnFailure(hr, "Failed to enumerate all the processes by name %ls.", wzProcessName); | 276 | RmExitOnFailure(hr, "Failed to enumerate all the processes by name %ls.", wzProcessName); |
262 | 277 | ||
263 | for (DWORD i = 0; i < cProcessIds; ++i) | 278 | for (DWORD i = 0; i < cProcessIds; ++i) |
264 | { | 279 | { |
@@ -270,7 +285,7 @@ extern "C" HRESULT DAPI RmuAddProcessesByName( | |||
270 | } | 285 | } |
271 | else | 286 | else |
272 | { | 287 | { |
273 | ExitOnFailure(hr, "Failed to add process %ls (%d) to the Restart Manager session.", wzProcessName, pdwProcessIds[i]); | 288 | RmExitOnFailure(hr, "Failed to add process %ls (%d) to the Restart Manager session.", wzProcessName, pdwProcessIds[i]); |
274 | } | 289 | } |
275 | } | 290 | } |
276 | 291 | ||
@@ -303,7 +318,7 @@ extern "C" HRESULT DAPI RmuAddService( | |||
303 | ::EnterCriticalSection(&pSession->cs); | 318 | ::EnterCriticalSection(&pSession->cs); |
304 | 319 | ||
305 | hr = StrArrayAllocString(&pSession->rgsczServiceNames, &pSession->cServiceNames, wzServiceName, 0); | 320 | hr = StrArrayAllocString(&pSession->rgsczServiceNames, &pSession->cServiceNames, wzServiceName, 0); |
306 | ExitOnFailure(hr, "Failed to add the service name to the array."); | 321 | RmExitOnFailure(hr, "Failed to add the service name to the array."); |
307 | 322 | ||
308 | LExit: | 323 | LExit: |
309 | ::LeaveCriticalSection(&pSession->cs); | 324 | ::LeaveCriticalSection(&pSession->cs); |
@@ -341,7 +356,7 @@ extern "C" HRESULT DAPI RmuRegisterResources( | |||
341 | pSession->cServiceNames, | 356 | pSession->cServiceNames, |
342 | pSession->rgsczServiceNames | 357 | pSession->rgsczServiceNames |
343 | ); | 358 | ); |
344 | ExitOnWin32Error(er, hr, "Failed to register the resources with the Restart Manager session."); | 359 | RmExitOnWin32Error(er, hr, "Failed to register the resources with the Restart Manager session."); |
345 | 360 | ||
346 | // Empty the arrays if registered in case additional resources are added later. | 361 | // Empty the arrays if registered in case additional resources are added later. |
347 | ReleaseNullStrArray(pSession->rgsczFilenames, pSession->cFilenames); | 362 | ReleaseNullStrArray(pSession->rgsczFilenames, pSession->cFilenames); |
@@ -373,11 +388,11 @@ extern "C" HRESULT DAPI RmuEndSession( | |||
373 | if (!pSession->fStartedSessionHandle) | 388 | if (!pSession->fStartedSessionHandle) |
374 | { | 389 | { |
375 | hr = RmuRegisterResources(pSession); | 390 | hr = RmuRegisterResources(pSession); |
376 | ExitOnFailure(hr, "Failed to register remaining resources."); | 391 | RmExitOnFailure(hr, "Failed to register remaining resources."); |
377 | } | 392 | } |
378 | 393 | ||
379 | er = vpfnRmEndSession(pSession->dwSessionHandle); | 394 | er = vpfnRmEndSession(pSession->dwSessionHandle); |
380 | ExitOnWin32Error(er, hr, "Failed to end the Restart Manager session."); | 395 | RmExitOnWin32Error(er, hr, "Failed to end the Restart Manager session."); |
381 | 396 | ||
382 | LExit: | 397 | LExit: |
383 | if (pSession->fInitialized) | 398 | if (pSession->fInitialized) |
@@ -404,16 +419,16 @@ static HRESULT RmuInitialize() | |||
404 | if (1 == iRef && !vhModule) | 419 | if (1 == iRef && !vhModule) |
405 | { | 420 | { |
406 | hr = LoadSystemLibrary(L"rstrtmgr.dll", &hModule); | 421 | hr = LoadSystemLibrary(L"rstrtmgr.dll", &hModule); |
407 | ExitOnFailure(hr, "Failed to load the rstrtmgr.dll module."); | 422 | RmExitOnFailure(hr, "Failed to load the rstrtmgr.dll module."); |
408 | 423 | ||
409 | vpfnRmJoinSession = reinterpret_cast<PFNRMJOINSESSION>(::GetProcAddress(hModule, "RmJoinSession")); | 424 | vpfnRmJoinSession = reinterpret_cast<PFNRMJOINSESSION>(::GetProcAddress(hModule, "RmJoinSession")); |
410 | ExitOnNullWithLastError(vpfnRmJoinSession, hr, "Failed to get the RmJoinSession procedure from rstrtmgr.dll."); | 425 | RmExitOnNullWithLastError(vpfnRmJoinSession, hr, "Failed to get the RmJoinSession procedure from rstrtmgr.dll."); |
411 | 426 | ||
412 | vpfnRmRegisterResources = reinterpret_cast<PFNRMREGISTERRESOURCES>(::GetProcAddress(hModule, "RmRegisterResources")); | 427 | vpfnRmRegisterResources = reinterpret_cast<PFNRMREGISTERRESOURCES>(::GetProcAddress(hModule, "RmRegisterResources")); |
413 | ExitOnNullWithLastError(vpfnRmRegisterResources, hr, "Failed to get the RmRegisterResources procedure from rstrtmgr.dll."); | 428 | RmExitOnNullWithLastError(vpfnRmRegisterResources, hr, "Failed to get the RmRegisterResources procedure from rstrtmgr.dll."); |
414 | 429 | ||
415 | vpfnRmEndSession = reinterpret_cast<PFNRMENDSESSION>(::GetProcAddress(hModule, "RmEndSession")); | 430 | vpfnRmEndSession = reinterpret_cast<PFNRMENDSESSION>(::GetProcAddress(hModule, "RmEndSession")); |
416 | ExitOnNullWithLastError(vpfnRmEndSession, hr, "Failed to get the RmEndSession procedure from rstrtmgr.dll."); | 431 | RmExitOnNullWithLastError(vpfnRmEndSession, hr, "Failed to get the RmEndSession procedure from rstrtmgr.dll."); |
417 | 432 | ||
418 | vhModule = hModule; | 433 | vhModule = hModule; |
419 | } | 434 | } |
@@ -447,7 +462,7 @@ static HRESULT RmuApplicationArrayAlloc( | |||
447 | RM_UNIQUE_PROCESS *pApplication = NULL; | 462 | RM_UNIQUE_PROCESS *pApplication = NULL; |
448 | 463 | ||
449 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgApplications), *pcApplications + 1, sizeof(RM_UNIQUE_PROCESS), ARRAY_GROWTH_SIZE); | 464 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgApplications), *pcApplications + 1, sizeof(RM_UNIQUE_PROCESS), ARRAY_GROWTH_SIZE); |
450 | ExitOnFailure(hr, "Failed to allocate memory for the application array."); | 465 | RmExitOnFailure(hr, "Failed to allocate memory for the application array."); |
451 | 466 | ||
452 | pApplication = static_cast<RM_UNIQUE_PROCESS*>(&(*prgApplications)[*pcApplications]); | 467 | pApplication = static_cast<RM_UNIQUE_PROCESS*>(&(*prgApplications)[*pcApplications]); |
453 | pApplication->dwProcessId = dwProcessId; | 468 | pApplication->dwProcessId = dwProcessId; |
@@ -466,7 +481,7 @@ static HRESULT RmuApplicationArrayFree( | |||
466 | HRESULT hr = S_OK; | 481 | HRESULT hr = S_OK; |
467 | 482 | ||
468 | hr = MemFree(rgApplications); | 483 | hr = MemFree(rgApplications); |
469 | ExitOnFailure(hr, "Failed to free memory for the application array."); | 484 | RmExitOnFailure(hr, "Failed to free memory for the application array."); |
470 | 485 | ||
471 | LExit: | 486 | LExit: |
472 | return hr; | 487 | return hr; |
diff --git a/src/dutil/rssutil.cpp b/src/dutil/rssutil.cpp index db49d954..8f994dfc 100644 --- a/src/dutil/rssutil.cpp +++ b/src/dutil/rssutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define RssExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_RSSUTIL, x, s, __VA_ARGS__) | ||
8 | #define RssExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_RSSUTIL, x, s, __VA_ARGS__) | ||
9 | #define RssExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_RSSUTIL, x, s, __VA_ARGS__) | ||
10 | #define RssExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_RSSUTIL, x, s, __VA_ARGS__) | ||
11 | #define RssExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_RSSUTIL, x, s, __VA_ARGS__) | ||
12 | #define RssExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_RSSUTIL, x, s, __VA_ARGS__) | ||
13 | #define RssExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_RSSUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define RssExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_RSSUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define RssExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_RSSUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define RssExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_RSSUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define RssExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_RSSUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define RssExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_RSSUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | static HRESULT ParseRssDocument( | 20 | static HRESULT ParseRssDocument( |
6 | __in IXMLDOMDocument *pixd, | 21 | __in IXMLDOMDocument *pixd, |
7 | __out RSS_CHANNEL **ppChannel | 22 | __out RSS_CHANNEL **ppChannel |
@@ -68,10 +83,10 @@ extern "C" HRESULT DAPI RssParseFromString( | |||
68 | IXMLDOMDocument *pixdRss = NULL; | 83 | IXMLDOMDocument *pixdRss = NULL; |
69 | 84 | ||
70 | hr = XmlLoadDocument(wzRssString, &pixdRss); | 85 | hr = XmlLoadDocument(wzRssString, &pixdRss); |
71 | ExitOnFailure(hr, "Failed to load RSS string as XML document."); | 86 | RssExitOnFailure(hr, "Failed to load RSS string as XML document."); |
72 | 87 | ||
73 | hr = ParseRssDocument(pixdRss, &pNewChannel); | 88 | hr = ParseRssDocument(pixdRss, &pNewChannel); |
74 | ExitOnFailure(hr, "Failed to parse RSS document."); | 89 | RssExitOnFailure(hr, "Failed to parse RSS document."); |
75 | 90 | ||
76 | *ppChannel = pNewChannel; | 91 | *ppChannel = pNewChannel; |
77 | pNewChannel = NULL; | 92 | pNewChannel = NULL; |
@@ -102,10 +117,10 @@ extern "C" HRESULT DAPI RssParseFromFile( | |||
102 | IXMLDOMDocument *pixdRss = NULL; | 117 | IXMLDOMDocument *pixdRss = NULL; |
103 | 118 | ||
104 | hr = XmlLoadDocumentFromFile(wzRssFile, &pixdRss); | 119 | hr = XmlLoadDocumentFromFile(wzRssFile, &pixdRss); |
105 | ExitOnFailure(hr, "Failed to load RSS string as XML document."); | 120 | RssExitOnFailure(hr, "Failed to load RSS string as XML document."); |
106 | 121 | ||
107 | hr = ParseRssDocument(pixdRss, &pNewChannel); | 122 | hr = ParseRssDocument(pixdRss, &pNewChannel); |
108 | ExitOnFailure(hr, "Failed to parse RSS document."); | 123 | RssExitOnFailure(hr, "Failed to parse RSS document."); |
109 | 124 | ||
110 | *ppChannel = pNewChannel; | 125 | *ppChannel = pNewChannel; |
111 | pNewChannel = NULL; | 126 | pNewChannel = NULL; |
@@ -175,17 +190,17 @@ static HRESULT ParseRssDocument( | |||
175 | // Get the document element and start processing channels. | 190 | // Get the document element and start processing channels. |
176 | // | 191 | // |
177 | hr = pixd ->get_documentElement(&pRssElement); | 192 | hr = pixd ->get_documentElement(&pRssElement); |
178 | ExitOnFailure(hr, "failed get_documentElement in ParseRssDocument"); | 193 | RssExitOnFailure(hr, "failed get_documentElement in ParseRssDocument"); |
179 | 194 | ||
180 | hr = pRssElement->get_childNodes(&pChannelNodes); | 195 | hr = pRssElement->get_childNodes(&pChannelNodes); |
181 | ExitOnFailure(hr, "Failed to get child nodes of Rss Document element."); | 196 | RssExitOnFailure(hr, "Failed to get child nodes of Rss Document element."); |
182 | 197 | ||
183 | while (S_OK == (hr = XmlNextElement(pChannelNodes, &pNode, &bstrNodeName))) | 198 | while (S_OK == (hr = XmlNextElement(pChannelNodes, &pNode, &bstrNodeName))) |
184 | { | 199 | { |
185 | if (0 == lstrcmpW(bstrNodeName, L"channel")) | 200 | if (0 == lstrcmpW(bstrNodeName, L"channel")) |
186 | { | 201 | { |
187 | hr = ParseRssChannel(pNode, &pNewChannel); | 202 | hr = ParseRssChannel(pNode, &pNewChannel); |
188 | ExitOnFailure(hr, "Failed to parse RSS channel."); | 203 | RssExitOnFailure(hr, "Failed to parse RSS channel."); |
189 | } | 204 | } |
190 | else if (0 == lstrcmpW(bstrNodeName, L"link")) | 205 | else if (0 == lstrcmpW(bstrNodeName, L"link")) |
191 | { | 206 | { |
@@ -242,13 +257,13 @@ static HRESULT ParseRssChannel( | |||
242 | // the RSS_CHANNEL structure | 257 | // the RSS_CHANNEL structure |
243 | // | 258 | // |
244 | hr = XmlSelectNodes(pixnChannel, L"item", &pNodeList); | 259 | hr = XmlSelectNodes(pixnChannel, L"item", &pNodeList); |
245 | ExitOnFailure(hr, "Failed to select all RSS items in an RSS channel."); | 260 | RssExitOnFailure(hr, "Failed to select all RSS items in an RSS channel."); |
246 | 261 | ||
247 | hr = pNodeList->get_length(&cItems); | 262 | hr = pNodeList->get_length(&cItems); |
248 | ExitOnFailure(hr, "Failed to count the number of RSS items in RSS channel."); | 263 | RssExitOnFailure(hr, "Failed to count the number of RSS items in RSS channel."); |
249 | 264 | ||
250 | pNewChannel = static_cast<RSS_CHANNEL*>(MemAlloc(sizeof(RSS_CHANNEL) + sizeof(RSS_ITEM) * cItems, TRUE)); | 265 | pNewChannel = static_cast<RSS_CHANNEL*>(MemAlloc(sizeof(RSS_CHANNEL) + sizeof(RSS_ITEM) * cItems, TRUE)); |
251 | ExitOnNull(pNewChannel, hr, E_OUTOFMEMORY, "Failed to allocate RSS channel structure."); | 266 | RssExitOnNull(pNewChannel, hr, E_OUTOFMEMORY, "Failed to allocate RSS channel structure."); |
252 | 267 | ||
253 | pNewChannel->cItems = cItems; | 268 | pNewChannel->cItems = cItems; |
254 | 269 | ||
@@ -256,7 +271,7 @@ static HRESULT ParseRssChannel( | |||
256 | // Process the elements under a channel now. | 271 | // Process the elements under a channel now. |
257 | // | 272 | // |
258 | hr = pixnChannel->get_childNodes(&pNodeList); | 273 | hr = pixnChannel->get_childNodes(&pNodeList); |
259 | ExitOnFailure(hr, "Failed to get child nodes of RSS channel element."); | 274 | RssExitOnFailure(hr, "Failed to get child nodes of RSS channel element."); |
260 | 275 | ||
261 | cItems = 0; // reset the counter and use this to walk through the channel items | 276 | cItems = 0; // reset the counter and use this to walk through the channel items |
262 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) | 277 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) |
@@ -264,45 +279,45 @@ static HRESULT ParseRssChannel( | |||
264 | if (0 == lstrcmpW(bstrNodeName, L"title")) | 279 | if (0 == lstrcmpW(bstrNodeName, L"title")) |
265 | { | 280 | { |
266 | hr = XmlGetText(pNode, &bstrNodeValue); | 281 | hr = XmlGetText(pNode, &bstrNodeValue); |
267 | ExitOnFailure(hr, "Failed to get RSS channel title."); | 282 | RssExitOnFailure(hr, "Failed to get RSS channel title."); |
268 | 283 | ||
269 | hr = StrAllocString(&pNewChannel->wzTitle, bstrNodeValue, 0); | 284 | hr = StrAllocString(&pNewChannel->wzTitle, bstrNodeValue, 0); |
270 | ExitOnFailure(hr, "Failed to allocate RSS channel title."); | 285 | RssExitOnFailure(hr, "Failed to allocate RSS channel title."); |
271 | } | 286 | } |
272 | else if (0 == lstrcmpW(bstrNodeName, L"link")) | 287 | else if (0 == lstrcmpW(bstrNodeName, L"link")) |
273 | { | 288 | { |
274 | hr = XmlGetText(pNode, &bstrNodeValue); | 289 | hr = XmlGetText(pNode, &bstrNodeValue); |
275 | ExitOnFailure(hr, "Failed to get RSS channel link."); | 290 | RssExitOnFailure(hr, "Failed to get RSS channel link."); |
276 | 291 | ||
277 | hr = StrAllocString(&pNewChannel->wzLink, bstrNodeValue, 0); | 292 | hr = StrAllocString(&pNewChannel->wzLink, bstrNodeValue, 0); |
278 | ExitOnFailure(hr, "Failed to allocate RSS channel link."); | 293 | RssExitOnFailure(hr, "Failed to allocate RSS channel link."); |
279 | } | 294 | } |
280 | else if (0 == lstrcmpW(bstrNodeName, L"description")) | 295 | else if (0 == lstrcmpW(bstrNodeName, L"description")) |
281 | { | 296 | { |
282 | hr = XmlGetText(pNode, &bstrNodeValue); | 297 | hr = XmlGetText(pNode, &bstrNodeValue); |
283 | ExitOnFailure(hr, "Failed to get RSS channel description."); | 298 | RssExitOnFailure(hr, "Failed to get RSS channel description."); |
284 | 299 | ||
285 | hr = StrAllocString(&pNewChannel->wzDescription, bstrNodeValue, 0); | 300 | hr = StrAllocString(&pNewChannel->wzDescription, bstrNodeValue, 0); |
286 | ExitOnFailure(hr, "Failed to allocate RSS channel description."); | 301 | RssExitOnFailure(hr, "Failed to allocate RSS channel description."); |
287 | } | 302 | } |
288 | else if (0 == lstrcmpW(bstrNodeName, L"ttl")) | 303 | else if (0 == lstrcmpW(bstrNodeName, L"ttl")) |
289 | { | 304 | { |
290 | hr = XmlGetText(pNode, &bstrNodeValue); | 305 | hr = XmlGetText(pNode, &bstrNodeValue); |
291 | ExitOnFailure(hr, "Failed to get RSS channel description."); | 306 | RssExitOnFailure(hr, "Failed to get RSS channel description."); |
292 | 307 | ||
293 | pNewChannel->dwTimeToLive = (DWORD)wcstoul(bstrNodeValue, NULL, 10); | 308 | pNewChannel->dwTimeToLive = (DWORD)wcstoul(bstrNodeValue, NULL, 10); |
294 | } | 309 | } |
295 | else if (0 == lstrcmpW(bstrNodeName, L"item")) | 310 | else if (0 == lstrcmpW(bstrNodeName, L"item")) |
296 | { | 311 | { |
297 | hr = ParseRssItem(pNode, cItems, pNewChannel); | 312 | hr = ParseRssItem(pNode, cItems, pNewChannel); |
298 | ExitOnFailure(hr, "Failed to parse RSS item."); | 313 | RssExitOnFailure(hr, "Failed to parse RSS item."); |
299 | 314 | ||
300 | ++cItems; | 315 | ++cItems; |
301 | } | 316 | } |
302 | else | 317 | else |
303 | { | 318 | { |
304 | hr = ParseRssUnknownElement(pNode, &pNewChannel->pUnknownElements); | 319 | hr = ParseRssUnknownElement(pNode, &pNewChannel->pUnknownElements); |
305 | ExitOnFailure(hr, "Failed to parse unknown RSS channel element: %ls", bstrNodeName); | 320 | RssExitOnFailure(hr, "Failed to parse unknown RSS channel element: %ls", bstrNodeName); |
306 | } | 321 | } |
307 | 322 | ||
308 | ReleaseNullBSTR(bstrNodeValue); | 323 | ReleaseNullBSTR(bstrNodeValue); |
@@ -349,7 +364,7 @@ static HRESULT ParseRssItem( | |||
349 | if (pChannel->cItems <= cItem) | 364 | if (pChannel->cItems <= cItem) |
350 | { | 365 | { |
351 | hr = E_UNEXPECTED; | 366 | hr = E_UNEXPECTED; |
352 | ExitOnFailure(hr, "Unexpected number of items parsed."); | 367 | RssExitOnFailure(hr, "Unexpected number of items parsed."); |
353 | } | 368 | } |
354 | 369 | ||
355 | pItem = pChannel->rgItems + cItem; | 370 | pItem = pChannel->rgItems + cItem; |
@@ -358,71 +373,71 @@ static HRESULT ParseRssItem( | |||
358 | // Process the elements under an item now. | 373 | // Process the elements under an item now. |
359 | // | 374 | // |
360 | hr = pixnItem->get_childNodes(&pNodeList); | 375 | hr = pixnItem->get_childNodes(&pNodeList); |
361 | ExitOnFailure(hr, "Failed to get child nodes of RSS item element."); | 376 | RssExitOnFailure(hr, "Failed to get child nodes of RSS item element."); |
362 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) | 377 | while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, &bstrNodeName))) |
363 | { | 378 | { |
364 | if (0 == lstrcmpW(bstrNodeName, L"title")) | 379 | if (0 == lstrcmpW(bstrNodeName, L"title")) |
365 | { | 380 | { |
366 | hr = XmlGetText(pNode, &bstrNodeValue); | 381 | hr = XmlGetText(pNode, &bstrNodeValue); |
367 | ExitOnFailure(hr, "Failed to get RSS channel title."); | 382 | RssExitOnFailure(hr, "Failed to get RSS channel title."); |
368 | 383 | ||
369 | hr = StrAllocString(&pItem->wzTitle, bstrNodeValue, 0); | 384 | hr = StrAllocString(&pItem->wzTitle, bstrNodeValue, 0); |
370 | ExitOnFailure(hr, "Failed to allocate RSS item title."); | 385 | RssExitOnFailure(hr, "Failed to allocate RSS item title."); |
371 | } | 386 | } |
372 | else if (0 == lstrcmpW(bstrNodeName, L"link")) | 387 | else if (0 == lstrcmpW(bstrNodeName, L"link")) |
373 | { | 388 | { |
374 | hr = XmlGetText(pNode, &bstrNodeValue); | 389 | hr = XmlGetText(pNode, &bstrNodeValue); |
375 | ExitOnFailure(hr, "Failed to get RSS channel link."); | 390 | RssExitOnFailure(hr, "Failed to get RSS channel link."); |
376 | 391 | ||
377 | hr = StrAllocString(&pItem->wzLink, bstrNodeValue, 0); | 392 | hr = StrAllocString(&pItem->wzLink, bstrNodeValue, 0); |
378 | ExitOnFailure(hr, "Failed to allocate RSS item link."); | 393 | RssExitOnFailure(hr, "Failed to allocate RSS item link."); |
379 | } | 394 | } |
380 | else if (0 == lstrcmpW(bstrNodeName, L"description")) | 395 | else if (0 == lstrcmpW(bstrNodeName, L"description")) |
381 | { | 396 | { |
382 | hr = XmlGetText(pNode, &bstrNodeValue); | 397 | hr = XmlGetText(pNode, &bstrNodeValue); |
383 | ExitOnFailure(hr, "Failed to get RSS item description."); | 398 | RssExitOnFailure(hr, "Failed to get RSS item description."); |
384 | 399 | ||
385 | hr = StrAllocString(&pItem->wzDescription, bstrNodeValue, 0); | 400 | hr = StrAllocString(&pItem->wzDescription, bstrNodeValue, 0); |
386 | ExitOnFailure(hr, "Failed to allocate RSS item description."); | 401 | RssExitOnFailure(hr, "Failed to allocate RSS item description."); |
387 | } | 402 | } |
388 | else if (0 == lstrcmpW(bstrNodeName, L"guid")) | 403 | else if (0 == lstrcmpW(bstrNodeName, L"guid")) |
389 | { | 404 | { |
390 | hr = XmlGetText(pNode, &bstrNodeValue); | 405 | hr = XmlGetText(pNode, &bstrNodeValue); |
391 | ExitOnFailure(hr, "Failed to get RSS item guid."); | 406 | RssExitOnFailure(hr, "Failed to get RSS item guid."); |
392 | 407 | ||
393 | hr = StrAllocString(&pItem->wzGuid, bstrNodeValue, 0); | 408 | hr = StrAllocString(&pItem->wzGuid, bstrNodeValue, 0); |
394 | ExitOnFailure(hr, "Failed to allocate RSS item guid."); | 409 | RssExitOnFailure(hr, "Failed to allocate RSS item guid."); |
395 | } | 410 | } |
396 | else if (0 == lstrcmpW(bstrNodeName, L"pubDate")) | 411 | else if (0 == lstrcmpW(bstrNodeName, L"pubDate")) |
397 | { | 412 | { |
398 | hr = XmlGetText(pNode, &bstrNodeValue); | 413 | hr = XmlGetText(pNode, &bstrNodeValue); |
399 | ExitOnFailure(hr, "Failed to get RSS item guid."); | 414 | RssExitOnFailure(hr, "Failed to get RSS item guid."); |
400 | 415 | ||
401 | hr = TimeFromString(bstrNodeValue, &pItem->ftPublished); | 416 | hr = TimeFromString(bstrNodeValue, &pItem->ftPublished); |
402 | ExitOnFailure(hr, "Failed to convert RSS item time."); | 417 | RssExitOnFailure(hr, "Failed to convert RSS item time."); |
403 | } | 418 | } |
404 | else if (0 == lstrcmpW(bstrNodeName, L"enclosure")) | 419 | else if (0 == lstrcmpW(bstrNodeName, L"enclosure")) |
405 | { | 420 | { |
406 | hr = XmlGetAttribute(pNode, L"url", &bstrNodeValue); | 421 | hr = XmlGetAttribute(pNode, L"url", &bstrNodeValue); |
407 | ExitOnFailure(hr, "Failed to get RSS item enclosure url."); | 422 | RssExitOnFailure(hr, "Failed to get RSS item enclosure url."); |
408 | 423 | ||
409 | hr = StrAllocString(&pItem->wzEnclosureUrl, bstrNodeValue, 0); | 424 | hr = StrAllocString(&pItem->wzEnclosureUrl, bstrNodeValue, 0); |
410 | ExitOnFailure(hr, "Failed to allocate RSS item enclosure url."); | 425 | RssExitOnFailure(hr, "Failed to allocate RSS item enclosure url."); |
411 | ReleaseNullBSTR(bstrNodeValue); | 426 | ReleaseNullBSTR(bstrNodeValue); |
412 | 427 | ||
413 | hr = XmlGetAttributeNumber(pNode, L"length", &pItem->dwEnclosureSize); | 428 | hr = XmlGetAttributeNumber(pNode, L"length", &pItem->dwEnclosureSize); |
414 | ExitOnFailure(hr, "Failed to get RSS item enclosure length."); | 429 | RssExitOnFailure(hr, "Failed to get RSS item enclosure length."); |
415 | 430 | ||
416 | hr = XmlGetAttribute(pNode, L"type", &bstrNodeValue); | 431 | hr = XmlGetAttribute(pNode, L"type", &bstrNodeValue); |
417 | ExitOnFailure(hr, "Failed to get RSS item enclosure type."); | 432 | RssExitOnFailure(hr, "Failed to get RSS item enclosure type."); |
418 | 433 | ||
419 | hr = StrAllocString(&pItem->wzEnclosureType, bstrNodeValue, 0); | 434 | hr = StrAllocString(&pItem->wzEnclosureType, bstrNodeValue, 0); |
420 | ExitOnFailure(hr, "Failed to allocate RSS item enclosure type."); | 435 | RssExitOnFailure(hr, "Failed to allocate RSS item enclosure type."); |
421 | } | 436 | } |
422 | else | 437 | else |
423 | { | 438 | { |
424 | hr = ParseRssUnknownElement(pNode, &pItem->pUnknownElements); | 439 | hr = ParseRssUnknownElement(pNode, &pItem->pUnknownElements); |
425 | ExitOnFailure(hr, "Failed to parse unknown RSS item element: %ls", bstrNodeName); | 440 | RssExitOnFailure(hr, "Failed to parse unknown RSS item element: %ls", bstrNodeName); |
426 | } | 441 | } |
427 | 442 | ||
428 | ReleaseNullBSTR(bstrNodeValue); | 443 | ReleaseNullBSTR(bstrNodeValue); |
@@ -460,39 +475,39 @@ static HRESULT ParseRssUnknownElement( | |||
460 | RSS_UNKNOWN_ELEMENT* pNewUnknownElement; | 475 | RSS_UNKNOWN_ELEMENT* pNewUnknownElement; |
461 | 476 | ||
462 | pNewUnknownElement = static_cast<RSS_UNKNOWN_ELEMENT*>(MemAlloc(sizeof(RSS_UNKNOWN_ELEMENT), TRUE)); | 477 | pNewUnknownElement = static_cast<RSS_UNKNOWN_ELEMENT*>(MemAlloc(sizeof(RSS_UNKNOWN_ELEMENT), TRUE)); |
463 | ExitOnNull(pNewUnknownElement, hr, E_OUTOFMEMORY, "Failed to allocate unknown element."); | 478 | RssExitOnNull(pNewUnknownElement, hr, E_OUTOFMEMORY, "Failed to allocate unknown element."); |
464 | 479 | ||
465 | hr = pNode->get_namespaceURI(&bstrNodeNamespace); | 480 | hr = pNode->get_namespaceURI(&bstrNodeNamespace); |
466 | if (S_OK == hr) | 481 | if (S_OK == hr) |
467 | { | 482 | { |
468 | hr = StrAllocString(&pNewUnknownElement->wzNamespace, bstrNodeNamespace, 0); | 483 | hr = StrAllocString(&pNewUnknownElement->wzNamespace, bstrNodeNamespace, 0); |
469 | ExitOnFailure(hr, "Failed to allocate RSS unknown element namespace."); | 484 | RssExitOnFailure(hr, "Failed to allocate RSS unknown element namespace."); |
470 | } | 485 | } |
471 | else if (S_FALSE == hr) | 486 | else if (S_FALSE == hr) |
472 | { | 487 | { |
473 | hr = S_OK; | 488 | hr = S_OK; |
474 | } | 489 | } |
475 | ExitOnFailure(hr, "Failed to get unknown element namespace."); | 490 | RssExitOnFailure(hr, "Failed to get unknown element namespace."); |
476 | 491 | ||
477 | hr = pNode->get_baseName(&bstrNodeName); | 492 | hr = pNode->get_baseName(&bstrNodeName); |
478 | ExitOnFailure(hr, "Failed to get unknown element name."); | 493 | RssExitOnFailure(hr, "Failed to get unknown element name."); |
479 | 494 | ||
480 | hr = StrAllocString(&pNewUnknownElement->wzElement, bstrNodeName, 0); | 495 | hr = StrAllocString(&pNewUnknownElement->wzElement, bstrNodeName, 0); |
481 | ExitOnFailure(hr, "Failed to allocate RSS unknown element name."); | 496 | RssExitOnFailure(hr, "Failed to allocate RSS unknown element name."); |
482 | 497 | ||
483 | hr = XmlGetText(pNode, &bstrNodeValue); | 498 | hr = XmlGetText(pNode, &bstrNodeValue); |
484 | ExitOnFailure(hr, "Failed to get unknown element value."); | 499 | RssExitOnFailure(hr, "Failed to get unknown element value."); |
485 | 500 | ||
486 | hr = StrAllocString(&pNewUnknownElement->wzValue, bstrNodeValue, 0); | 501 | hr = StrAllocString(&pNewUnknownElement->wzValue, bstrNodeValue, 0); |
487 | ExitOnFailure(hr, "Failed to allocate RSS unknown element value."); | 502 | RssExitOnFailure(hr, "Failed to allocate RSS unknown element value."); |
488 | 503 | ||
489 | hr = pNode->get_attributes(&pixnnmAttributes); | 504 | hr = pNode->get_attributes(&pixnnmAttributes); |
490 | ExitOnFailure(hr, "Failed get attributes on RSS unknown element."); | 505 | RssExitOnFailure(hr, "Failed get attributes on RSS unknown element."); |
491 | 506 | ||
492 | while (S_OK == (hr = pixnnmAttributes->nextNode(&pixnAttribute))) | 507 | while (S_OK == (hr = pixnnmAttributes->nextNode(&pixnAttribute))) |
493 | { | 508 | { |
494 | hr = ParseRssUnknownAttribute(pixnAttribute, &pNewUnknownElement->pAttributes); | 509 | hr = ParseRssUnknownAttribute(pixnAttribute, &pNewUnknownElement->pAttributes); |
495 | ExitOnFailure(hr, "Failed to parse attribute on RSS unknown element."); | 510 | RssExitOnFailure(hr, "Failed to parse attribute on RSS unknown element."); |
496 | 511 | ||
497 | ReleaseNullObject(pixnAttribute); | 512 | ReleaseNullObject(pixnAttribute); |
498 | } | 513 | } |
@@ -501,7 +516,7 @@ static HRESULT ParseRssUnknownElement( | |||
501 | { | 516 | { |
502 | hr = S_OK; | 517 | hr = S_OK; |
503 | } | 518 | } |
504 | ExitOnFailure(hr, "Failed to enumerate all attributes on RSS unknown element."); | 519 | RssExitOnFailure(hr, "Failed to enumerate all attributes on RSS unknown element."); |
505 | 520 | ||
506 | RSS_UNKNOWN_ELEMENT** ppTail = ppUnknownElement; | 521 | RSS_UNKNOWN_ELEMENT** ppTail = ppUnknownElement; |
507 | while (*ppTail) | 522 | while (*ppTail) |
@@ -543,31 +558,31 @@ static HRESULT ParseRssUnknownAttribute( | |||
543 | RSS_UNKNOWN_ATTRIBUTE* pNewUnknownAttribute; | 558 | RSS_UNKNOWN_ATTRIBUTE* pNewUnknownAttribute; |
544 | 559 | ||
545 | pNewUnknownAttribute = static_cast<RSS_UNKNOWN_ATTRIBUTE*>(MemAlloc(sizeof(RSS_UNKNOWN_ATTRIBUTE), TRUE)); | 560 | pNewUnknownAttribute = static_cast<RSS_UNKNOWN_ATTRIBUTE*>(MemAlloc(sizeof(RSS_UNKNOWN_ATTRIBUTE), TRUE)); |
546 | ExitOnNull(pNewUnknownAttribute, hr, E_OUTOFMEMORY, "Failed to allocate unknown attribute."); | 561 | RssExitOnNull(pNewUnknownAttribute, hr, E_OUTOFMEMORY, "Failed to allocate unknown attribute."); |
547 | 562 | ||
548 | hr = pNode->get_namespaceURI(&bstrNodeNamespace); | 563 | hr = pNode->get_namespaceURI(&bstrNodeNamespace); |
549 | if (S_OK == hr) | 564 | if (S_OK == hr) |
550 | { | 565 | { |
551 | hr = StrAllocString(&pNewUnknownAttribute->wzNamespace, bstrNodeNamespace, 0); | 566 | hr = StrAllocString(&pNewUnknownAttribute->wzNamespace, bstrNodeNamespace, 0); |
552 | ExitOnFailure(hr, "Failed to allocate RSS unknown attribute namespace."); | 567 | RssExitOnFailure(hr, "Failed to allocate RSS unknown attribute namespace."); |
553 | } | 568 | } |
554 | else if (S_FALSE == hr) | 569 | else if (S_FALSE == hr) |
555 | { | 570 | { |
556 | hr = S_OK; | 571 | hr = S_OK; |
557 | } | 572 | } |
558 | ExitOnFailure(hr, "Failed to get unknown attribute namespace."); | 573 | RssExitOnFailure(hr, "Failed to get unknown attribute namespace."); |
559 | 574 | ||
560 | hr = pNode->get_baseName(&bstrNodeName); | 575 | hr = pNode->get_baseName(&bstrNodeName); |
561 | ExitOnFailure(hr, "Failed to get unknown attribute name."); | 576 | RssExitOnFailure(hr, "Failed to get unknown attribute name."); |
562 | 577 | ||
563 | hr = StrAllocString(&pNewUnknownAttribute->wzAttribute, bstrNodeName, 0); | 578 | hr = StrAllocString(&pNewUnknownAttribute->wzAttribute, bstrNodeName, 0); |
564 | ExitOnFailure(hr, "Failed to allocate RSS unknown attribute name."); | 579 | RssExitOnFailure(hr, "Failed to allocate RSS unknown attribute name."); |
565 | 580 | ||
566 | hr = XmlGetText(pNode, &bstrNodeValue); | 581 | hr = XmlGetText(pNode, &bstrNodeValue); |
567 | ExitOnFailure(hr, "Failed to get unknown attribute value."); | 582 | RssExitOnFailure(hr, "Failed to get unknown attribute value."); |
568 | 583 | ||
569 | hr = StrAllocString(&pNewUnknownAttribute->wzValue, bstrNodeValue, 0); | 584 | hr = StrAllocString(&pNewUnknownAttribute->wzValue, bstrNodeValue, 0); |
570 | ExitOnFailure(hr, "Failed to allocate RSS unknown attribute value."); | 585 | RssExitOnFailure(hr, "Failed to allocate RSS unknown attribute value."); |
571 | 586 | ||
572 | RSS_UNKNOWN_ATTRIBUTE** ppTail = ppUnknownAttribute; | 587 | RSS_UNKNOWN_ATTRIBUTE** ppTail = ppUnknownAttribute; |
573 | while (*ppTail) | 588 | while (*ppTail) |
diff --git a/src/dutil/shelutil.cpp b/src/dutil/shelutil.cpp index a69c9eaa..2eb9a52a 100644 --- a/src/dutil/shelutil.cpp +++ b/src/dutil/shelutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define ShelExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_SHELUTIL, x, s, __VA_ARGS__) | ||
8 | #define ShelExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_SHELUTIL, x, s, __VA_ARGS__) | ||
9 | #define ShelExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_SHELUTIL, x, s, __VA_ARGS__) | ||
10 | #define ShelExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_SHELUTIL, x, s, __VA_ARGS__) | ||
11 | #define ShelExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_SHELUTIL, x, s, __VA_ARGS__) | ||
12 | #define ShelExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_SHELUTIL, x, s, __VA_ARGS__) | ||
13 | #define ShelExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_SHELUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define ShelExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_SHELUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define ShelExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_SHELUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define ShelExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_SHELUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define ShelExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_SHELUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define ShelExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_SHELUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | static PFN_SHELLEXECUTEEXW vpfnShellExecuteExW = ::ShellExecuteExW; | 20 | static PFN_SHELLEXECUTEEXW vpfnShellExecuteExW = ::ShellExecuteExW; |
6 | 21 | ||
7 | static HRESULT GetDesktopShellView( | 22 | static HRESULT GetDesktopShellView( |
@@ -55,7 +70,7 @@ extern "C" HRESULT DAPI ShelExec( | |||
55 | 70 | ||
56 | if (!vpfnShellExecuteExW(&shExecInfo)) | 71 | if (!vpfnShellExecuteExW(&shExecInfo)) |
57 | { | 72 | { |
58 | ExitWithLastError(hr, "ShellExecEx failed with return code: %d", Dutil_er); | 73 | ShelExitWithLastError(hr, "ShellExecEx failed with return code: %d", Dutil_er); |
59 | } | 74 | } |
60 | 75 | ||
61 | if (phProcess) | 76 | if (phProcess) |
@@ -93,44 +108,44 @@ extern "C" HRESULT DAPI ShelExecUnelevated( | |||
93 | IShellDispatch2* psd = NULL; | 108 | IShellDispatch2* psd = NULL; |
94 | 109 | ||
95 | bstrTargetPath = ::SysAllocString(wzTargetPath); | 110 | bstrTargetPath = ::SysAllocString(wzTargetPath); |
96 | ExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate target path BSTR."); | 111 | ShelExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate target path BSTR."); |
97 | 112 | ||
98 | if (wzParameters && *wzParameters) | 113 | if (wzParameters && *wzParameters) |
99 | { | 114 | { |
100 | vtParameters.vt = VT_BSTR; | 115 | vtParameters.vt = VT_BSTR; |
101 | vtParameters.bstrVal = ::SysAllocString(wzParameters); | 116 | vtParameters.bstrVal = ::SysAllocString(wzParameters); |
102 | ExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate parameters BSTR."); | 117 | ShelExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate parameters BSTR."); |
103 | } | 118 | } |
104 | 119 | ||
105 | if (wzVerb && *wzVerb) | 120 | if (wzVerb && *wzVerb) |
106 | { | 121 | { |
107 | vtVerb.vt = VT_BSTR; | 122 | vtVerb.vt = VT_BSTR; |
108 | vtVerb.bstrVal = ::SysAllocString(wzVerb); | 123 | vtVerb.bstrVal = ::SysAllocString(wzVerb); |
109 | ExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate verb BSTR."); | 124 | ShelExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate verb BSTR."); |
110 | } | 125 | } |
111 | 126 | ||
112 | if (wzWorkingDirectory && *wzWorkingDirectory) | 127 | if (wzWorkingDirectory && *wzWorkingDirectory) |
113 | { | 128 | { |
114 | vtWorkingDirectory.vt = VT_BSTR; | 129 | vtWorkingDirectory.vt = VT_BSTR; |
115 | vtWorkingDirectory.bstrVal = ::SysAllocString(wzWorkingDirectory); | 130 | vtWorkingDirectory.bstrVal = ::SysAllocString(wzWorkingDirectory); |
116 | ExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate working directory BSTR."); | 131 | ShelExitOnNull(bstrTargetPath, hr, E_OUTOFMEMORY, "Failed to allocate working directory BSTR."); |
117 | } | 132 | } |
118 | 133 | ||
119 | vtShow.vt = VT_INT; | 134 | vtShow.vt = VT_INT; |
120 | vtShow.intVal = nShowCmd; | 135 | vtShow.intVal = nShowCmd; |
121 | 136 | ||
122 | hr = GetDesktopShellView(IID_PPV_ARGS(&psv)); | 137 | hr = GetDesktopShellView(IID_PPV_ARGS(&psv)); |
123 | ExitOnFailure(hr, "Failed to get desktop shell view."); | 138 | ShelExitOnFailure(hr, "Failed to get desktop shell view."); |
124 | 139 | ||
125 | hr = GetShellDispatchFromView(psv, IID_PPV_ARGS(&psd)); | 140 | hr = GetShellDispatchFromView(psv, IID_PPV_ARGS(&psd)); |
126 | ExitOnFailure(hr, "Failed to get shell dispatch from view."); | 141 | ShelExitOnFailure(hr, "Failed to get shell dispatch from view."); |
127 | 142 | ||
128 | hr = psd->ShellExecute(bstrTargetPath, vtParameters, vtWorkingDirectory, vtVerb, vtShow); | 143 | hr = psd->ShellExecute(bstrTargetPath, vtParameters, vtWorkingDirectory, vtVerb, vtShow); |
129 | if (S_FALSE == hr) | 144 | if (S_FALSE == hr) |
130 | { | 145 | { |
131 | hr = HRESULT_FROM_WIN32(ERROR_CANCELLED); | 146 | hr = HRESULT_FROM_WIN32(ERROR_CANCELLED); |
132 | } | 147 | } |
133 | ExitOnRootFailure(hr, "Failed to launch unelevate executable: %ls", bstrTargetPath); | 148 | ShelExitOnRootFailure(hr, "Failed to launch unelevate executable: %ls", bstrTargetPath); |
134 | 149 | ||
135 | LExit: | 150 | LExit: |
136 | ReleaseObject(psd); | 151 | ReleaseObject(psd); |
@@ -157,13 +172,13 @@ extern "C" HRESULT DAPI ShelGetFolder( | |||
157 | WCHAR wzPath[MAX_PATH]; | 172 | WCHAR wzPath[MAX_PATH]; |
158 | 173 | ||
159 | hr = ::SHGetFolderPathW(NULL, csidlFolder | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, wzPath); | 174 | hr = ::SHGetFolderPathW(NULL, csidlFolder | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, wzPath); |
160 | ExitOnFailure(hr, "Failed to get folder path for CSIDL: %d", csidlFolder); | 175 | ShelExitOnFailure(hr, "Failed to get folder path for CSIDL: %d", csidlFolder); |
161 | 176 | ||
162 | hr = StrAllocString(psczFolderPath, wzPath, 0); | 177 | hr = StrAllocString(psczFolderPath, wzPath, 0); |
163 | ExitOnFailure(hr, "Failed to copy shell folder path: %ls", wzPath); | 178 | ShelExitOnFailure(hr, "Failed to copy shell folder path: %ls", wzPath); |
164 | 179 | ||
165 | hr = PathBackslashTerminate(psczFolderPath); | 180 | hr = PathBackslashTerminate(psczFolderPath); |
166 | ExitOnFailure(hr, "Failed to backslash terminate shell folder path: %ls", *psczFolderPath); | 181 | ShelExitOnFailure(hr, "Failed to backslash terminate shell folder path: %ls", *psczFolderPath); |
167 | 182 | ||
168 | LExit: | 183 | LExit: |
169 | return hr; | 184 | return hr; |
@@ -206,19 +221,19 @@ extern "C" HRESULT DAPI ShelGetKnownFolder( | |||
206 | TraceError(hr, "Failed to load shell32.dll"); | 221 | TraceError(hr, "Failed to load shell32.dll"); |
207 | ExitFunction1(hr = E_NOTIMPL); | 222 | ExitFunction1(hr = E_NOTIMPL); |
208 | } | 223 | } |
209 | ExitOnFailure(hr, "Failed to load shell32.dll."); | 224 | ShelExitOnFailure(hr, "Failed to load shell32.dll."); |
210 | 225 | ||
211 | pfn = reinterpret_cast<PFN_SHGetKnownFolderPath>(::GetProcAddress(hShell32Dll, "SHGetKnownFolderPath")); | 226 | pfn = reinterpret_cast<PFN_SHGetKnownFolderPath>(::GetProcAddress(hShell32Dll, "SHGetKnownFolderPath")); |
212 | ExitOnNull(pfn, hr, E_NOTIMPL, "Failed to find SHGetKnownFolderPath entry point."); | 227 | ShelExitOnNull(pfn, hr, E_NOTIMPL, "Failed to find SHGetKnownFolderPath entry point."); |
213 | 228 | ||
214 | hr = pfn(rfidFolder, KF_FLAG_CREATE, NULL, &pwzPath); | 229 | hr = pfn(rfidFolder, KF_FLAG_CREATE, NULL, &pwzPath); |
215 | ExitOnFailure(hr, "Failed to get known folder path."); | 230 | ShelExitOnFailure(hr, "Failed to get known folder path."); |
216 | 231 | ||
217 | hr = StrAllocString(psczFolderPath, pwzPath, 0); | 232 | hr = StrAllocString(psczFolderPath, pwzPath, 0); |
218 | ExitOnFailure(hr, "Failed to copy shell folder path: %ls", pwzPath); | 233 | ShelExitOnFailure(hr, "Failed to copy shell folder path: %ls", pwzPath); |
219 | 234 | ||
220 | hr = PathBackslashTerminate(psczFolderPath); | 235 | hr = PathBackslashTerminate(psczFolderPath); |
221 | ExitOnFailure(hr, "Failed to backslash terminate shell folder path: %ls", *psczFolderPath); | 236 | ShelExitOnFailure(hr, "Failed to backslash terminate shell folder path: %ls", *psczFolderPath); |
222 | 237 | ||
223 | LExit: | 238 | LExit: |
224 | if (pwzPath) | 239 | if (pwzPath) |
@@ -255,32 +270,32 @@ static HRESULT GetDesktopShellView( | |||
255 | // desktop web browser and then grabs its view | 270 | // desktop web browser and then grabs its view |
256 | // returns IShellView, IFolderView and related interfaces | 271 | // returns IShellView, IFolderView and related interfaces |
257 | hr = ::CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&psw)); | 272 | hr = ::CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&psw)); |
258 | ExitOnFailure(hr, "Failed to get shell view."); | 273 | ShelExitOnFailure(hr, "Failed to get shell view."); |
259 | 274 | ||
260 | hr = psw->FindWindowSW(&vEmpty, &vEmpty, SWC_DESKTOP, (long*)&hwnd, SWFO_NEEDDISPATCH, &pdisp); | 275 | hr = psw->FindWindowSW(&vEmpty, &vEmpty, SWC_DESKTOP, (long*)&hwnd, SWFO_NEEDDISPATCH, &pdisp); |
261 | if (S_OK == hr) | 276 | if (S_OK == hr) |
262 | { | 277 | { |
263 | hr = IUnknown_QueryService(pdisp, SID_STopLevelBrowser, IID_PPV_ARGS(&psb)); | 278 | hr = IUnknown_QueryService(pdisp, SID_STopLevelBrowser, IID_PPV_ARGS(&psb)); |
264 | ExitOnFailure(hr, "Failed to get desktop window."); | 279 | ShelExitOnFailure(hr, "Failed to get desktop window."); |
265 | 280 | ||
266 | hr = psb->QueryActiveShellView(&psv); | 281 | hr = psb->QueryActiveShellView(&psv); |
267 | ExitOnFailure(hr, "Failed to get active shell view."); | 282 | ShelExitOnFailure(hr, "Failed to get active shell view."); |
268 | 283 | ||
269 | hr = psv->QueryInterface(riid, ppv); | 284 | hr = psv->QueryInterface(riid, ppv); |
270 | ExitOnFailure(hr, "Failed to query for the desktop shell view."); | 285 | ShelExitOnFailure(hr, "Failed to query for the desktop shell view."); |
271 | } | 286 | } |
272 | else if (S_FALSE == hr) | 287 | else if (S_FALSE == hr) |
273 | { | 288 | { |
274 | //Windows XP | 289 | //Windows XP |
275 | hr = SHGetDesktopFolder(&psf); | 290 | hr = SHGetDesktopFolder(&psf); |
276 | ExitOnFailure(hr, "Failed to get desktop folder."); | 291 | ShelExitOnFailure(hr, "Failed to get desktop folder."); |
277 | 292 | ||
278 | hr = psf->CreateViewObject(NULL, IID_IShellView, ppv); | 293 | hr = psf->CreateViewObject(NULL, IID_IShellView, ppv); |
279 | ExitOnFailure(hr, "Failed to query for the desktop shell view."); | 294 | ShelExitOnFailure(hr, "Failed to query for the desktop shell view."); |
280 | } | 295 | } |
281 | else | 296 | else |
282 | { | 297 | { |
283 | ExitOnFailure(hr, "Failed to get desktop window."); | 298 | ShelExitOnFailure(hr, "Failed to get desktop window."); |
284 | } | 299 | } |
285 | 300 | ||
286 | LExit: | 301 | LExit: |
@@ -307,16 +322,16 @@ static HRESULT GetShellDispatchFromView( | |||
307 | // From a shell view object, gets its automation interface and from that get the shell | 322 | // From a shell view object, gets its automation interface and from that get the shell |
308 | // application object that implements IShellDispatch2 and related interfaces. | 323 | // application object that implements IShellDispatch2 and related interfaces. |
309 | hr = psv->GetItemObject(SVGIO_BACKGROUND, IID_PPV_ARGS(&pdispBackground)); | 324 | hr = psv->GetItemObject(SVGIO_BACKGROUND, IID_PPV_ARGS(&pdispBackground)); |
310 | ExitOnFailure(hr, "Failed to get the automation interface for shell."); | 325 | ShelExitOnFailure(hr, "Failed to get the automation interface for shell."); |
311 | 326 | ||
312 | hr = pdispBackground->QueryInterface(IID_PPV_ARGS(&psfvd)); | 327 | hr = pdispBackground->QueryInterface(IID_PPV_ARGS(&psfvd)); |
313 | ExitOnFailure(hr, "Failed to get shell folder view dual."); | 328 | ShelExitOnFailure(hr, "Failed to get shell folder view dual."); |
314 | 329 | ||
315 | hr = psfvd->get_Application(&pdisp); | 330 | hr = psfvd->get_Application(&pdisp); |
316 | ExitOnFailure(hr, "Failed to application object."); | 331 | ShelExitOnFailure(hr, "Failed to application object."); |
317 | 332 | ||
318 | hr = pdisp->QueryInterface(riid, ppv); | 333 | hr = pdisp->QueryInterface(riid, ppv); |
319 | ExitOnFailure(hr, "Failed to get IShellDispatch2."); | 334 | ShelExitOnFailure(hr, "Failed to get IShellDispatch2."); |
320 | 335 | ||
321 | LExit: | 336 | LExit: |
322 | ReleaseObject(pdisp); | 337 | ReleaseObject(pdisp); |
diff --git a/src/dutil/sqlutil.cpp b/src/dutil/sqlutil.cpp index 099c6ae9..63ee80ac 100644 --- a/src/dutil/sqlutil.cpp +++ b/src/dutil/sqlutil.cpp | |||
@@ -9,6 +9,21 @@ | |||
9 | #define DBINITCONSTANTS | 9 | #define DBINITCONSTANTS |
10 | #include "sqlutil.h" | 10 | #include "sqlutil.h" |
11 | 11 | ||
12 | |||
13 | // Exit macros | ||
14 | #define SqlExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__) | ||
15 | #define SqlExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__) | ||
16 | #define SqlExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__) | ||
17 | #define SqlExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__) | ||
18 | #define SqlExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__) | ||
19 | #define SqlExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_SQLUTIL, x, s, __VA_ARGS__) | ||
20 | #define SqlExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_SQLUTIL, p, x, e, s, __VA_ARGS__) | ||
21 | #define SqlExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_SQLUTIL, p, x, s, __VA_ARGS__) | ||
22 | #define SqlExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_SQLUTIL, p, x, e, s, __VA_ARGS__) | ||
23 | #define SqlExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_SQLUTIL, p, x, s, __VA_ARGS__) | ||
24 | #define SqlExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_SQLUTIL, e, x, s, __VA_ARGS__) | ||
25 | #define SqlExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_SQLUTIL, g, x, s, __VA_ARGS__) | ||
26 | |||
12 | // private prototypes | 27 | // private prototypes |
13 | static HRESULT FileSpecToString( | 28 | static HRESULT FileSpecToString( |
14 | __in const SQL_FILESPEC* psf, | 29 | __in const SQL_FILESPEC* psf, |
@@ -54,7 +69,7 @@ extern "C" HRESULT DAPI SqlConnectDatabase( | |||
54 | //obtain access to the SQLOLEDB provider | 69 | //obtain access to the SQLOLEDB provider |
55 | hr = ::CoCreateInstance(CLSID_SQLOLEDB, NULL, CLSCTX_INPROC_SERVER, | 70 | hr = ::CoCreateInstance(CLSID_SQLOLEDB, NULL, CLSCTX_INPROC_SERVER, |
56 | IID_IDBInitialize, (LPVOID*)&pidbInitialize); | 71 | IID_IDBInitialize, (LPVOID*)&pidbInitialize); |
57 | ExitOnFailure(hr, "failed to create IID_IDBInitialize object"); | 72 | SqlExitOnFailure(hr, "failed to create IID_IDBInitialize object"); |
58 | 73 | ||
59 | // if there is an instance | 74 | // if there is an instance |
60 | if (wzInstance && *wzInstance) | 75 | if (wzInstance && *wzInstance) |
@@ -65,7 +80,7 @@ extern "C" HRESULT DAPI SqlConnectDatabase( | |||
65 | { | 80 | { |
66 | hr = StrAllocString(&pwzServerInstance, wzServer, 0); | 81 | hr = StrAllocString(&pwzServerInstance, wzServer, 0); |
67 | } | 82 | } |
68 | ExitOnFailure(hr, "failed to allocate memory for the server instance"); | 83 | SqlExitOnFailure(hr, "failed to allocate memory for the server instance"); |
69 | 84 | ||
70 | // server[\instance] | 85 | // server[\instance] |
71 | rgdbpInit[cProperties].dwPropertyID = DBPROP_INIT_DATASOURCE; | 86 | rgdbpInit[cProperties].dwPropertyID = DBPROP_INIT_DATASOURCE; |
@@ -124,13 +139,13 @@ extern "C" HRESULT DAPI SqlConnectDatabase( | |||
124 | 139 | ||
125 | // create and set the property set | 140 | // create and set the property set |
126 | hr = pidbInitialize->QueryInterface(IID_IDBProperties, (LPVOID*)&pidbProperties); | 141 | hr = pidbInitialize->QueryInterface(IID_IDBProperties, (LPVOID*)&pidbProperties); |
127 | ExitOnFailure(hr, "failed to get IID_IDBProperties object"); | 142 | SqlExitOnFailure(hr, "failed to get IID_IDBProperties object"); |
128 | hr = pidbProperties->SetProperties(1, rgdbpsetInit); | 143 | hr = pidbProperties->SetProperties(1, rgdbpsetInit); |
129 | ExitOnFailure(hr, "failed to set properties"); | 144 | SqlExitOnFailure(hr, "failed to set properties"); |
130 | 145 | ||
131 | //initialize connection to datasource | 146 | //initialize connection to datasource |
132 | hr = pidbInitialize->Initialize(); | 147 | hr = pidbInitialize->Initialize(); |
133 | ExitOnFailure(hr, "failed to initialize connection to database: %ls", wzDatabase); | 148 | SqlExitOnFailure(hr, "failed to initialize connection to database: %ls", wzDatabase); |
134 | 149 | ||
135 | hr = pidbInitialize->QueryInterface(IID_IDBCreateSession, (LPVOID*)ppidbSession); | 150 | hr = pidbInitialize->QueryInterface(IID_IDBCreateSession, (LPVOID*)ppidbSession); |
136 | 151 | ||
@@ -163,10 +178,10 @@ extern "C" HRESULT DAPI SqlStartTransaction( | |||
163 | HRESULT hr = S_OK; | 178 | HRESULT hr = S_OK; |
164 | 179 | ||
165 | hr = pidbSession->CreateSession(NULL, IID_IDBCreateCommand, (IUnknown**)ppidbCommand); | 180 | hr = pidbSession->CreateSession(NULL, IID_IDBCreateCommand, (IUnknown**)ppidbCommand); |
166 | ExitOnFailure(hr, "unable to create command from session"); | 181 | SqlExitOnFailure(hr, "unable to create command from session"); |
167 | 182 | ||
168 | hr = (*ppidbCommand)->QueryInterface(IID_ITransactionLocal, (LPVOID*)ppit); | 183 | hr = (*ppidbCommand)->QueryInterface(IID_ITransactionLocal, (LPVOID*)ppit); |
169 | ExitOnFailure(hr, "Unable to QueryInterface session to get ITransactionLocal"); | 184 | SqlExitOnFailure(hr, "Unable to QueryInterface session to get ITransactionLocal"); |
170 | 185 | ||
171 | hr = ((ITransactionLocal*)*ppit)->StartTransaction(ISOLATIONLEVEL_SERIALIZABLE, 0, NULL, NULL); | 186 | hr = ((ITransactionLocal*)*ppit)->StartTransaction(ISOLATIONLEVEL_SERIALIZABLE, 0, NULL, NULL); |
172 | 187 | ||
@@ -192,12 +207,12 @@ extern "C" HRESULT DAPI SqlEndTransaction( | |||
192 | if (fCommit) | 207 | if (fCommit) |
193 | { | 208 | { |
194 | hr = pit->Commit(FALSE, XACTTC_SYNC, 0); | 209 | hr = pit->Commit(FALSE, XACTTC_SYNC, 0); |
195 | ExitOnFailure(hr, "commit of transaction failed"); | 210 | SqlExitOnFailure(hr, "commit of transaction failed"); |
196 | } | 211 | } |
197 | else | 212 | else |
198 | { | 213 | { |
199 | hr = pit->Abort(NULL, FALSE, FALSE); | 214 | hr = pit->Abort(NULL, FALSE, FALSE); |
200 | ExitOnFailure(hr, "abort of transaction failed"); | 215 | SqlExitOnFailure(hr, "abort of transaction failed"); |
201 | } | 216 | } |
202 | 217 | ||
203 | LExit: | 218 | LExit: |
@@ -231,7 +246,7 @@ extern "C" HRESULT DAPI SqlDatabaseExists( | |||
231 | IDBCreateSession* pidbSession = NULL; | 246 | IDBCreateSession* pidbSession = NULL; |
232 | 247 | ||
233 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); | 248 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); |
234 | ExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer); | 249 | SqlExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer); |
235 | 250 | ||
236 | hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription); | 251 | hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription); |
237 | 252 | ||
@@ -271,17 +286,17 @@ extern "C" HRESULT DAPI SqlSessionDatabaseExists( | |||
271 | // query to see if the database exists | 286 | // query to see if the database exists |
272 | // | 287 | // |
273 | hr = StrAllocFormatted(&pwzQuery, L"SELECT name FROM sysdatabases WHERE name='%s'", wzDatabase); | 288 | hr = StrAllocFormatted(&pwzQuery, L"SELECT name FROM sysdatabases WHERE name='%s'", wzDatabase); |
274 | ExitOnFailure(hr, "failed to allocate query string to ensure database exists"); | 289 | SqlExitOnFailure(hr, "failed to allocate query string to ensure database exists"); |
275 | 290 | ||
276 | hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, &pirs, NULL, pbstrErrorDescription); | 291 | hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, &pirs, NULL, pbstrErrorDescription); |
277 | ExitOnFailure(hr, "failed to get database list from 'master' database"); | 292 | SqlExitOnFailure(hr, "failed to get database list from 'master' database"); |
278 | Assert(pirs); | 293 | Assert(pirs); |
279 | 294 | ||
280 | // | 295 | // |
281 | // check to see if the database was returned | 296 | // check to see if the database was returned |
282 | // | 297 | // |
283 | hr = pirs->GetNextRows(DB_NULL_HCHAPTER, 0, 1, &cRows, &prow); | 298 | hr = pirs->GetNextRows(DB_NULL_HCHAPTER, 0, 1, &cRows, &prow); |
284 | ExitOnFailure(hr, "failed to get row with database name"); | 299 | SqlExitOnFailure(hr, "failed to get row with database name"); |
285 | 300 | ||
286 | // succeeded but no database | 301 | // succeeded but no database |
287 | if ((DB_S_ENDOFROWSET == hr) || (0 == cRows)) | 302 | if ((DB_S_ENDOFROWSET == hr) || (0 == cRows)) |
@@ -324,10 +339,10 @@ extern "C" HRESULT DAPI SqlDatabaseEnsureExists( | |||
324 | // connect to the master database to create the new database | 339 | // connect to the master database to create the new database |
325 | // | 340 | // |
326 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); | 341 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); |
327 | ExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer); | 342 | SqlExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer); |
328 | 343 | ||
329 | hr = SqlSessionDatabaseEnsureExists(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription); | 344 | hr = SqlSessionDatabaseEnsureExists(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription); |
330 | ExitOnFailure(hr, "failed to create database: %ls", wzDatabase); | 345 | SqlExitOnFailure(hr, "failed to create database: %ls", wzDatabase); |
331 | 346 | ||
332 | Assert(S_OK == hr); | 347 | Assert(S_OK == hr); |
333 | LExit: | 348 | LExit: |
@@ -355,12 +370,12 @@ extern "C" HRESULT DAPI SqlSessionDatabaseEnsureExists( | |||
355 | HRESULT hr = S_OK; | 370 | HRESULT hr = S_OK; |
356 | 371 | ||
357 | hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription); | 372 | hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription); |
358 | ExitOnFailure(hr, "failed to determine if exists, database: %ls", wzDatabase); | 373 | SqlExitOnFailure(hr, "failed to determine if exists, database: %ls", wzDatabase); |
359 | 374 | ||
360 | if (S_FALSE == hr) | 375 | if (S_FALSE == hr) |
361 | { | 376 | { |
362 | hr = SqlSessionCreateDatabase(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription); | 377 | hr = SqlSessionCreateDatabase(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription); |
363 | ExitOnFailure(hr, "failed to create database: %1", wzDatabase); | 378 | SqlExitOnFailure(hr, "failed to create database: %ls", wzDatabase); |
364 | } | 379 | } |
365 | // else database already exists, return S_FALSE | 380 | // else database already exists, return S_FALSE |
366 | 381 | ||
@@ -398,10 +413,10 @@ extern "C" HRESULT DAPI SqlCreateDatabase( | |||
398 | // connect to the master database to create the new database | 413 | // connect to the master database to create the new database |
399 | // | 414 | // |
400 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); | 415 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); |
401 | ExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer); | 416 | SqlExitOnFailure(hr, "failed to connect to 'master' database on server %ls", wzServer); |
402 | 417 | ||
403 | hr = SqlSessionCreateDatabase(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription); | 418 | hr = SqlSessionCreateDatabase(pidbSession, wzDatabase, psfDatabase, psfLog, pbstrErrorDescription); |
404 | ExitOnFailure(hr, "failed to create database: %ls", wzDatabase); | 419 | SqlExitOnFailure(hr, "failed to create database: %ls", wzDatabase); |
405 | 420 | ||
406 | Assert(S_OK == hr); | 421 | Assert(S_OK == hr); |
407 | LExit: | 422 | LExit: |
@@ -433,23 +448,23 @@ extern "C" HRESULT DAPI SqlSessionCreateDatabase( | |||
433 | if (psfDatabase) | 448 | if (psfDatabase) |
434 | { | 449 | { |
435 | hr = FileSpecToString(psfDatabase, &pwzDbFile); | 450 | hr = FileSpecToString(psfDatabase, &pwzDbFile); |
436 | ExitOnFailure(hr, "failed to convert db filespec to string"); | 451 | SqlExitOnFailure(hr, "failed to convert db filespec to string"); |
437 | } | 452 | } |
438 | 453 | ||
439 | if (psfLog) | 454 | if (psfLog) |
440 | { | 455 | { |
441 | hr = FileSpecToString(psfLog, &pwzLogFile); | 456 | hr = FileSpecToString(psfLog, &pwzLogFile); |
442 | ExitOnFailure(hr, "failed to convert log filespec to string"); | 457 | SqlExitOnFailure(hr, "failed to convert log filespec to string"); |
443 | } | 458 | } |
444 | 459 | ||
445 | hr = EscapeSqlIdentifier(wzDatabase, &pwzDatabaseEscaped); | 460 | hr = EscapeSqlIdentifier(wzDatabase, &pwzDatabaseEscaped); |
446 | ExitOnFailure(hr, "failed to escape database string"); | 461 | SqlExitOnFailure(hr, "failed to escape database string"); |
447 | 462 | ||
448 | hr = StrAllocFormatted(&pwzQuery, L"CREATE DATABASE %s %s%s %s%s", pwzDatabaseEscaped, pwzDbFile ? L"ON " : L"", pwzDbFile ? pwzDbFile : L"", pwzLogFile ? L"LOG ON " : L"", pwzLogFile ? pwzLogFile : L""); | 463 | hr = StrAllocFormatted(&pwzQuery, L"CREATE DATABASE %s %s%s %s%s", pwzDatabaseEscaped, pwzDbFile ? L"ON " : L"", pwzDbFile ? pwzDbFile : L"", pwzLogFile ? L"LOG ON " : L"", pwzLogFile ? pwzLogFile : L""); |
449 | ExitOnFailure(hr, "failed to allocate query to create database: %ls", pwzDatabaseEscaped); | 464 | SqlExitOnFailure(hr, "failed to allocate query to create database: %ls", pwzDatabaseEscaped); |
450 | 465 | ||
451 | hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, NULL, NULL, pbstrErrorDescription); | 466 | hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, NULL, NULL, pbstrErrorDescription); |
452 | ExitOnFailure(hr, "failed to create database: %ls, Query: %ls", pwzDatabaseEscaped, pwzQuery); | 467 | SqlExitOnFailure(hr, "failed to create database: %ls, Query: %ls", pwzDatabaseEscaped, pwzQuery); |
453 | 468 | ||
454 | LExit: | 469 | LExit: |
455 | ReleaseStr(pwzQuery); | 470 | ReleaseStr(pwzQuery); |
@@ -486,7 +501,7 @@ extern "C" HRESULT DAPI SqlDropDatabase( | |||
486 | // connect to the master database to search for wzDatabase | 501 | // connect to the master database to search for wzDatabase |
487 | // | 502 | // |
488 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); | 503 | hr = SqlConnectDatabase(wzServer, wzInstance, L"master", fIntegratedAuth, wzUser, wzPassword, &pidbSession); |
489 | ExitOnFailure(hr, "Failed to connect to 'master' database"); | 504 | SqlExitOnFailure(hr, "Failed to connect to 'master' database"); |
490 | 505 | ||
491 | hr = SqlSessionDropDatabase(pidbSession, wzDatabase, pbstrErrorDescription); | 506 | hr = SqlSessionDropDatabase(pidbSession, wzDatabase, pbstrErrorDescription); |
492 | 507 | ||
@@ -515,18 +530,18 @@ extern "C" HRESULT DAPI SqlSessionDropDatabase( | |||
515 | LPWSTR pwzDatabaseEscaped = NULL; | 530 | LPWSTR pwzDatabaseEscaped = NULL; |
516 | 531 | ||
517 | hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription); | 532 | hr = SqlSessionDatabaseExists(pidbSession, wzDatabase, pbstrErrorDescription); |
518 | ExitOnFailure(hr, "failed to determine if exists, database: %ls", wzDatabase); | 533 | SqlExitOnFailure(hr, "failed to determine if exists, database: %ls", wzDatabase); |
519 | 534 | ||
520 | hr = EscapeSqlIdentifier(wzDatabase, &pwzDatabaseEscaped); | 535 | hr = EscapeSqlIdentifier(wzDatabase, &pwzDatabaseEscaped); |
521 | ExitOnFailure(hr, "failed to escape database string"); | 536 | SqlExitOnFailure(hr, "failed to escape database string"); |
522 | 537 | ||
523 | if (S_OK == hr) | 538 | if (S_OK == hr) |
524 | { | 539 | { |
525 | hr = StrAllocFormatted(&pwzQuery, L"DROP DATABASE %s", pwzDatabaseEscaped); | 540 | hr = StrAllocFormatted(&pwzQuery, L"DROP DATABASE %s", pwzDatabaseEscaped); |
526 | ExitOnFailure(hr, "failed to allocate query to drop database: %ls", pwzDatabaseEscaped); | 541 | SqlExitOnFailure(hr, "failed to allocate query to drop database: %ls", pwzDatabaseEscaped); |
527 | 542 | ||
528 | hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, NULL, NULL, pbstrErrorDescription); | 543 | hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, NULL, NULL, pbstrErrorDescription); |
529 | ExitOnFailure(hr, "Failed to drop database"); | 544 | SqlExitOnFailure(hr, "Failed to drop database"); |
530 | } | 545 | } |
531 | 546 | ||
532 | LExit: | 547 | LExit: |
@@ -567,23 +582,23 @@ extern "C" HRESULT DAPI SqlSessionExecuteQuery( | |||
567 | // create the command | 582 | // create the command |
568 | // | 583 | // |
569 | hr = pidbSession->CreateSession(NULL, IID_IDBCreateCommand, (IUnknown**)&pidbCommand); | 584 | hr = pidbSession->CreateSession(NULL, IID_IDBCreateCommand, (IUnknown**)&pidbCommand); |
570 | ExitOnFailure(hr, "failed to create database session"); | 585 | SqlExitOnFailure(hr, "failed to create database session"); |
571 | hr = pidbCommand->CreateCommand(NULL, IID_ICommand, (IUnknown**)&picmd); | 586 | hr = pidbCommand->CreateCommand(NULL, IID_ICommand, (IUnknown**)&picmd); |
572 | ExitOnFailure(hr, "failed to create command to execute session"); | 587 | SqlExitOnFailure(hr, "failed to create command to execute session"); |
573 | 588 | ||
574 | // | 589 | // |
575 | // set the sql text into the command | 590 | // set the sql text into the command |
576 | // | 591 | // |
577 | hr = picmd->QueryInterface(IID_ICommandText, (LPVOID*)&picmdText); | 592 | hr = picmd->QueryInterface(IID_ICommandText, (LPVOID*)&picmdText); |
578 | ExitOnFailure(hr, "failed to get command text object for command"); | 593 | SqlExitOnFailure(hr, "failed to get command text object for command"); |
579 | hr = picmdText->SetCommandText(DBGUID_DEFAULT , wzSql); | 594 | hr = picmdText->SetCommandText(DBGUID_DEFAULT , wzSql); |
580 | ExitOnFailure(hr, "failed to set SQL string: %ls", wzSql); | 595 | SqlExitOnFailure(hr, "failed to set SQL string: %ls", wzSql); |
581 | 596 | ||
582 | // | 597 | // |
583 | // execute the command | 598 | // execute the command |
584 | // | 599 | // |
585 | hr = picmd->Execute(NULL, (ppirs) ? IID_IRowset : IID_NULL, NULL, &cRows, reinterpret_cast<IUnknown**>(ppirs)); | 600 | hr = picmd->Execute(NULL, (ppirs) ? IID_IRowset : IID_NULL, NULL, &cRows, reinterpret_cast<IUnknown**>(ppirs)); |
586 | ExitOnFailure(hr, "failed to execute SQL string: %ls", wzSql); | 601 | SqlExitOnFailure(hr, "failed to execute SQL string: %ls", wzSql); |
587 | 602 | ||
588 | if (DB_S_ERRORSOCCURRED == hr) | 603 | if (DB_S_ERRORSOCCURRED == hr) |
589 | { | 604 | { |
@@ -642,21 +657,21 @@ extern "C" HRESULT DAPI SqlCommandExecuteQuery( | |||
642 | // create the command | 657 | // create the command |
643 | // | 658 | // |
644 | hr = pidbCommand->CreateCommand(NULL, IID_ICommand, (IUnknown**)&picmd); | 659 | hr = pidbCommand->CreateCommand(NULL, IID_ICommand, (IUnknown**)&picmd); |
645 | ExitOnFailure(hr, "failed to create command to execute session"); | 660 | SqlExitOnFailure(hr, "failed to create command to execute session"); |
646 | 661 | ||
647 | // | 662 | // |
648 | // set the sql text into the command | 663 | // set the sql text into the command |
649 | // | 664 | // |
650 | hr = picmd->QueryInterface(IID_ICommandText, (LPVOID*)&picmdText); | 665 | hr = picmd->QueryInterface(IID_ICommandText, (LPVOID*)&picmdText); |
651 | ExitOnFailure(hr, "failed to get command text object for command"); | 666 | SqlExitOnFailure(hr, "failed to get command text object for command"); |
652 | hr = picmdText->SetCommandText(DBGUID_DEFAULT , wzSql); | 667 | hr = picmdText->SetCommandText(DBGUID_DEFAULT , wzSql); |
653 | ExitOnFailure(hr, "failed to set SQL string: %ls", wzSql); | 668 | SqlExitOnFailure(hr, "failed to set SQL string: %ls", wzSql); |
654 | 669 | ||
655 | // | 670 | // |
656 | // execute the command | 671 | // execute the command |
657 | // | 672 | // |
658 | hr = picmd->Execute(NULL, (ppirs) ? IID_IRowset : IID_NULL, NULL, &cRows, reinterpret_cast<IUnknown**>(ppirs)); | 673 | hr = picmd->Execute(NULL, (ppirs) ? IID_IRowset : IID_NULL, NULL, &cRows, reinterpret_cast<IUnknown**>(ppirs)); |
659 | ExitOnFailure(hr, "failed to execute SQL string: %ls", wzSql); | 674 | SqlExitOnFailure(hr, "failed to execute SQL string: %ls", wzSql); |
660 | 675 | ||
661 | if (DB_S_ERRORSOCCURRED == hr) | 676 | if (DB_S_ERRORSOCCURRED == hr) |
662 | { | 677 | { |
@@ -700,14 +715,14 @@ extern "C" HRESULT DAPI SqlGetErrorInfo( | |||
700 | 715 | ||
701 | // only ask for error information if the interface supports it. | 716 | // only ask for error information if the interface supports it. |
702 | hr = pObjectWithError->QueryInterface(IID_ISupportErrorInfo,(void**)&pISupportErrorInfo); | 717 | hr = pObjectWithError->QueryInterface(IID_ISupportErrorInfo,(void**)&pISupportErrorInfo); |
703 | ExitOnFailure(hr, "No error information was found for object."); | 718 | SqlExitOnFailure(hr, "No error information was found for object."); |
704 | 719 | ||
705 | hr = pISupportErrorInfo->InterfaceSupportsErrorInfo(IID_InterfaceWithError); | 720 | hr = pISupportErrorInfo->InterfaceSupportsErrorInfo(IID_InterfaceWithError); |
706 | ExitOnFailure(hr, "InterfaceWithError is not supported for object with error"); | 721 | SqlExitOnFailure(hr, "InterfaceWithError is not supported for object with error"); |
707 | 722 | ||
708 | // ignore the return of GetErrorInfo it can succeed and return a NULL pointer in pIErrorInfoAll anyway | 723 | // ignore the return of GetErrorInfo it can succeed and return a NULL pointer in pIErrorInfoAll anyway |
709 | hr = ::GetErrorInfo(0, &pIErrorInfoAll); | 724 | hr = ::GetErrorInfo(0, &pIErrorInfoAll); |
710 | ExitOnFailure(hr, "failed to get error info"); | 725 | SqlExitOnFailure(hr, "failed to get error info"); |
711 | 726 | ||
712 | if (S_OK == hr && pIErrorInfoAll) | 727 | if (S_OK == hr && pIErrorInfoAll) |
713 | { | 728 | { |
@@ -787,37 +802,37 @@ static HRESULT FileSpecToString( | |||
787 | LPWSTR pwz = NULL; | 802 | LPWSTR pwz = NULL; |
788 | 803 | ||
789 | hr = StrAllocString(&pwz, L"(", 1024); | 804 | hr = StrAllocString(&pwz, L"(", 1024); |
790 | ExitOnFailure(hr, "failed to allocate string for database file info"); | 805 | SqlExitOnFailure(hr, "failed to allocate string for database file info"); |
791 | 806 | ||
792 | ExitOnNull(*psf->wzName, hr, E_INVALIDARG, "logical name not specified in database file info"); | 807 | SqlExitOnNull(*psf->wzName, hr, E_INVALIDARG, "logical name not specified in database file info"); |
793 | ExitOnNull(*psf->wzFilename, hr, E_INVALIDARG, "filename not specified in database file info"); | 808 | SqlExitOnNull(*psf->wzFilename, hr, E_INVALIDARG, "filename not specified in database file info"); |
794 | 809 | ||
795 | hr = StrAllocFormatted(&pwz, L"%sNAME=%s", pwz, psf->wzName); | 810 | hr = StrAllocFormatted(&pwz, L"%sNAME=%s", pwz, psf->wzName); |
796 | ExitOnFailure(hr, "failed to format database file info name: %ls", psf->wzName); | 811 | SqlExitOnFailure(hr, "failed to format database file info name: %ls", psf->wzName); |
797 | 812 | ||
798 | hr = StrAllocFormatted(&pwz, L"%s, FILENAME='%s'", pwz, psf->wzFilename); | 813 | hr = StrAllocFormatted(&pwz, L"%s, FILENAME='%s'", pwz, psf->wzFilename); |
799 | ExitOnFailure(hr, "failed to format database file info filename: %ls", psf->wzFilename); | 814 | SqlExitOnFailure(hr, "failed to format database file info filename: %ls", psf->wzFilename); |
800 | 815 | ||
801 | if (0 != psf->wzSize[0]) | 816 | if (0 != psf->wzSize[0]) |
802 | { | 817 | { |
803 | hr = StrAllocFormatted(&pwz, L"%s, SIZE=%s", pwz, psf->wzSize); | 818 | hr = StrAllocFormatted(&pwz, L"%s, SIZE=%s", pwz, psf->wzSize); |
804 | ExitOnFailure(hr, "failed to format database file info size: %s", psf->wzSize); | 819 | SqlExitOnFailure(hr, "failed to format database file info size: %ls", psf->wzSize); |
805 | } | 820 | } |
806 | 821 | ||
807 | if (0 != psf->wzMaxSize[0]) | 822 | if (0 != psf->wzMaxSize[0]) |
808 | { | 823 | { |
809 | hr = StrAllocFormatted(&pwz, L"%s, MAXSIZE=%s", pwz, psf->wzMaxSize); | 824 | hr = StrAllocFormatted(&pwz, L"%s, MAXSIZE=%s", pwz, psf->wzMaxSize); |
810 | ExitOnFailure(hr, "failed to format database file info maxsize: %s", psf->wzMaxSize); | 825 | SqlExitOnFailure(hr, "failed to format database file info maxsize: %ls", psf->wzMaxSize); |
811 | } | 826 | } |
812 | 827 | ||
813 | if (0 != psf->wzGrow[0]) | 828 | if (0 != psf->wzGrow[0]) |
814 | { | 829 | { |
815 | hr = StrAllocFormatted(&pwz, L"%s, FILEGROWTH=%s", pwz, psf->wzGrow); | 830 | hr = StrAllocFormatted(&pwz, L"%s, FILEGROWTH=%s", pwz, psf->wzGrow); |
816 | ExitOnFailure(hr, "failed to format database file info growth: %s", psf->wzGrow); | 831 | SqlExitOnFailure(hr, "failed to format database file info growth: %ls", psf->wzGrow); |
817 | } | 832 | } |
818 | 833 | ||
819 | hr = StrAllocFormatted(&pwz, L"%s)", pwz); | 834 | hr = StrAllocFormatted(&pwz, L"%s)", pwz); |
820 | ExitOnFailure(hr, "failed to allocate string for file spec"); | 835 | SqlExitOnFailure(hr, "failed to allocate string for file spec"); |
821 | 836 | ||
822 | *ppwz = pwz; | 837 | *ppwz = pwz; |
823 | pwz = NULL; // null here so it doesn't get freed below | 838 | pwz = NULL; // null here so it doesn't get freed below |
@@ -850,13 +865,13 @@ static HRESULT EscapeSqlIdentifier( | |||
850 | if (cchIdentifier == 0 || (wzIdentifier[0] == '[' && wzIdentifier[cchIdentifier-1] == ']')) | 865 | if (cchIdentifier == 0 || (wzIdentifier[0] == '[' && wzIdentifier[cchIdentifier-1] == ']')) |
851 | { | 866 | { |
852 | hr = StrAllocString(&pwz, wzIdentifier, 0); | 867 | hr = StrAllocString(&pwz, wzIdentifier, 0); |
853 | ExitOnFailure(hr, "failed to format database name: %ls", wzIdentifier); | 868 | SqlExitOnFailure(hr, "failed to format database name: %ls", wzIdentifier); |
854 | } | 869 | } |
855 | else | 870 | else |
856 | { | 871 | { |
857 | //escape it | 872 | //escape it |
858 | hr = StrAllocFormatted(&pwz, L"[%s]", wzIdentifier); | 873 | hr = StrAllocFormatted(&pwz, L"[%s]", wzIdentifier); |
859 | ExitOnFailure(hr, "failed to format escaped database name: %ls", wzIdentifier); | 874 | SqlExitOnFailure(hr, "failed to format escaped database name: %ls", wzIdentifier); |
860 | } | 875 | } |
861 | 876 | ||
862 | *ppwz = pwz; | 877 | *ppwz = pwz; |
diff --git a/src/dutil/srputil.cpp b/src/dutil/srputil.cpp index 9fc2f94a..e44536cc 100644 --- a/src/dutil/srputil.cpp +++ b/src/dutil/srputil.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | 5 | ||
6 | // Exit macros | ||
7 | #define SrpExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__) | ||
8 | #define SrpExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__) | ||
9 | #define SrpExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__) | ||
10 | #define SrpExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__) | ||
11 | #define SrpExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__) | ||
12 | #define SrpExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__) | ||
13 | #define SrpExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_SRPUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define SrpExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_SRPUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define SrpExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_SRPUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define SrpExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_SRPUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define SrpExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_SRPUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define SrpExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_SRPUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
6 | typedef BOOL (WINAPI *PFN_SETRESTOREPTW)( | 21 | typedef BOOL (WINAPI *PFN_SETRESTOREPTW)( |
7 | __in PRESTOREPOINTINFOW pRestorePtSpec, | 22 | __in PRESTOREPOINTINFOW pRestorePtSpec, |
8 | __out PSTATEMGRSTATUS pSMgrStatus | 23 | __out PSTATEMGRSTATUS pSMgrStatus |
@@ -28,7 +43,7 @@ DAPI_(HRESULT) SrpInitialize( | |||
28 | } | 43 | } |
29 | 44 | ||
30 | vpfnSRSetRestorePointW = reinterpret_cast<PFN_SETRESTOREPTW>(::GetProcAddress(vhSrClientDll, "SRSetRestorePointW")); | 45 | vpfnSRSetRestorePointW = reinterpret_cast<PFN_SETRESTOREPTW>(::GetProcAddress(vhSrClientDll, "SRSetRestorePointW")); |
31 | ExitOnNullWithLastError(vpfnSRSetRestorePointW, hr, "Failed to find set restore point proc address."); | 46 | SrpExitOnNullWithLastError(vpfnSRSetRestorePointW, hr, "Failed to find set restore point proc address."); |
32 | 47 | ||
33 | // If allowed, initialize COM security to enable NetworkService, | 48 | // If allowed, initialize COM security to enable NetworkService, |
34 | // LocalService and System to make callbacks to the process | 49 | // LocalService and System to make callbacks to the process |
@@ -37,7 +52,7 @@ DAPI_(HRESULT) SrpInitialize( | |||
37 | if (fInitializeComSecurity) | 52 | if (fInitializeComSecurity) |
38 | { | 53 | { |
39 | hr = InitializeComSecurity(); | 54 | hr = InitializeComSecurity(); |
40 | ExitOnFailure(hr, "Failed to initialize security for COM to talk to system restore."); | 55 | SrpExitOnFailure(hr, "Failed to initialize security for COM to talk to system restore."); |
41 | } | 56 | } |
42 | 57 | ||
43 | LExit: | 58 | LExit: |
@@ -79,7 +94,7 @@ DAPI_(HRESULT) SrpCreateRestorePoint( | |||
79 | 94 | ||
80 | if (!vpfnSRSetRestorePointW(&restorePoint, &status)) | 95 | if (!vpfnSRSetRestorePointW(&restorePoint, &status)) |
81 | { | 96 | { |
82 | ExitOnWin32Error(status.nStatus, hr, "Failed to create system restore point."); | 97 | SrpExitOnWin32Error(status.nStatus, hr, "Failed to create system restore point."); |
83 | } | 98 | } |
84 | 99 | ||
85 | LExit: | 100 | LExit: |
@@ -116,42 +131,42 @@ static HRESULT InitializeComSecurity() | |||
116 | // Initialize the security descriptor. | 131 | // Initialize the security descriptor. |
117 | if (!::InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) | 132 | if (!::InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) |
118 | { | 133 | { |
119 | ExitWithLastError(hr, "Failed to initialize security descriptor for system restore."); | 134 | SrpExitWithLastError(hr, "Failed to initialize security descriptor for system restore."); |
120 | } | 135 | } |
121 | 136 | ||
122 | // Create an administrator group security identifier (SID). | 137 | // Create an administrator group security identifier (SID). |
123 | cbSid = sizeof(rgSidBA); | 138 | cbSid = sizeof(rgSidBA); |
124 | if (!::CreateWellKnownSid(WinBuiltinAdministratorsSid, NULL, rgSidBA, &cbSid)) | 139 | if (!::CreateWellKnownSid(WinBuiltinAdministratorsSid, NULL, rgSidBA, &cbSid)) |
125 | { | 140 | { |
126 | ExitWithLastError(hr, "Failed to create administrator SID for system restore."); | 141 | SrpExitWithLastError(hr, "Failed to create administrator SID for system restore."); |
127 | } | 142 | } |
128 | 143 | ||
129 | // Create a local service security identifier (SID). | 144 | // Create a local service security identifier (SID). |
130 | cbSid = sizeof(rgSidLS); | 145 | cbSid = sizeof(rgSidLS); |
131 | if (!::CreateWellKnownSid(WinLocalServiceSid, NULL, rgSidLS, &cbSid)) | 146 | if (!::CreateWellKnownSid(WinLocalServiceSid, NULL, rgSidLS, &cbSid)) |
132 | { | 147 | { |
133 | ExitWithLastError(hr, "Failed to create local service SID for system restore."); | 148 | SrpExitWithLastError(hr, "Failed to create local service SID for system restore."); |
134 | } | 149 | } |
135 | 150 | ||
136 | // Create a network service security identifier (SID). | 151 | // Create a network service security identifier (SID). |
137 | cbSid = sizeof(rgSidNS); | 152 | cbSid = sizeof(rgSidNS); |
138 | if (!::CreateWellKnownSid(WinNetworkServiceSid, NULL, rgSidNS, &cbSid)) | 153 | if (!::CreateWellKnownSid(WinNetworkServiceSid, NULL, rgSidNS, &cbSid)) |
139 | { | 154 | { |
140 | ExitWithLastError(hr, "Failed to create network service SID for system restore."); | 155 | SrpExitWithLastError(hr, "Failed to create network service SID for system restore."); |
141 | } | 156 | } |
142 | 157 | ||
143 | // Create a personal account security identifier (SID). | 158 | // Create a personal account security identifier (SID). |
144 | cbSid = sizeof(rgSidPS); | 159 | cbSid = sizeof(rgSidPS); |
145 | if (!::CreateWellKnownSid(WinSelfSid, NULL, rgSidPS, &cbSid)) | 160 | if (!::CreateWellKnownSid(WinSelfSid, NULL, rgSidPS, &cbSid)) |
146 | { | 161 | { |
147 | ExitWithLastError(hr, "Failed to create self SID for system restore."); | 162 | SrpExitWithLastError(hr, "Failed to create self SID for system restore."); |
148 | } | 163 | } |
149 | 164 | ||
150 | // Create a local service security identifier (SID). | 165 | // Create a local service security identifier (SID). |
151 | cbSid = sizeof(rgSidSY); | 166 | cbSid = sizeof(rgSidSY); |
152 | if (!::CreateWellKnownSid(WinLocalSystemSid, NULL, rgSidSY, &cbSid)) | 167 | if (!::CreateWellKnownSid(WinLocalSystemSid, NULL, rgSidSY, &cbSid)) |
153 | { | 168 | { |
154 | ExitWithLastError(hr, "Failed to create local system SID for system restore."); | 169 | SrpExitWithLastError(hr, "Failed to create local system SID for system restore."); |
155 | } | 170 | } |
156 | 171 | ||
157 | // Setup the access control entries (ACE) for COM. COM_RIGHTS_EXECUTE and | 172 | // Setup the access control entries (ACE) for COM. COM_RIGHTS_EXECUTE and |
@@ -203,29 +218,29 @@ static HRESULT InitializeComSecurity() | |||
203 | 218 | ||
204 | // Create an access control list (ACL) using this ACE list. | 219 | // Create an access control list (ACL) using this ACE list. |
205 | er = ::SetEntriesInAcl(countof(ea), ea, NULL, &pAcl); | 220 | er = ::SetEntriesInAcl(countof(ea), ea, NULL, &pAcl); |
206 | ExitOnWin32Error(er, hr, "Failed to create ACL for system restore."); | 221 | SrpExitOnWin32Error(er, hr, "Failed to create ACL for system restore."); |
207 | 222 | ||
208 | // Set the security descriptor owner to Administrators. | 223 | // Set the security descriptor owner to Administrators. |
209 | if (!::SetSecurityDescriptorOwner(&sd, rgSidBA, FALSE)) | 224 | if (!::SetSecurityDescriptorOwner(&sd, rgSidBA, FALSE)) |
210 | { | 225 | { |
211 | ExitWithLastError(hr, "Failed to set administrators owner for system restore."); | 226 | SrpExitWithLastError(hr, "Failed to set administrators owner for system restore."); |
212 | } | 227 | } |
213 | 228 | ||
214 | // Set the security descriptor group to Administrators. | 229 | // Set the security descriptor group to Administrators. |
215 | if (!::SetSecurityDescriptorGroup(&sd, rgSidBA, FALSE)) | 230 | if (!::SetSecurityDescriptorGroup(&sd, rgSidBA, FALSE)) |
216 | { | 231 | { |
217 | ExitWithLastError(hr, "Failed to set administrators group access for system restore."); | 232 | SrpExitWithLastError(hr, "Failed to set administrators group access for system restore."); |
218 | } | 233 | } |
219 | 234 | ||
220 | // Set the discretionary access control list (DACL) to the ACL. | 235 | // Set the discretionary access control list (DACL) to the ACL. |
221 | if (!::SetSecurityDescriptorDacl(&sd, TRUE, pAcl, FALSE)) | 236 | if (!::SetSecurityDescriptorDacl(&sd, TRUE, pAcl, FALSE)) |
222 | { | 237 | { |
223 | ExitWithLastError(hr, "Failed to set DACL for system restore."); | 238 | SrpExitWithLastError(hr, "Failed to set DACL for system restore."); |
224 | } | 239 | } |
225 | 240 | ||
226 | // Note that an explicit security descriptor is being passed in. | 241 | // Note that an explicit security descriptor is being passed in. |
227 | hr= ::CoInitializeSecurity(&sd, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_DISABLE_AAA | EOAC_NO_CUSTOM_MARSHAL, NULL); | 242 | hr= ::CoInitializeSecurity(&sd, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_DISABLE_AAA | EOAC_NO_CUSTOM_MARSHAL, NULL); |
228 | ExitOnFailure(hr, "Failed to initialize COM security for system restore."); | 243 | SrpExitOnFailure(hr, "Failed to initialize COM security for system restore."); |
229 | 244 | ||
230 | LExit: | 245 | LExit: |
231 | if (pAcl) | 246 | if (pAcl) |
diff --git a/src/dutil/strutil.cpp b/src/dutil/strutil.cpp index c1d701d3..daa090c9 100644 --- a/src/dutil/strutil.cpp +++ b/src/dutil/strutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define StrExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_STRUTIL, x, s, __VA_ARGS__) | ||
8 | #define StrExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_STRUTIL, x, s, __VA_ARGS__) | ||
9 | #define StrExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_STRUTIL, x, s, __VA_ARGS__) | ||
10 | #define StrExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_STRUTIL, x, s, __VA_ARGS__) | ||
11 | #define StrExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_STRUTIL, x, s, __VA_ARGS__) | ||
12 | #define StrExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_STRUTIL, x, s, __VA_ARGS__) | ||
13 | #define StrExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_STRUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define StrExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_STRUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define StrExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_STRUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define StrExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_STRUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define StrExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_STRUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define StrExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_STRUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | #define ARRAY_GROWTH_SIZE 5 | 20 | #define ARRAY_GROWTH_SIZE 5 |
6 | 21 | ||
7 | // Forward declarations. | 22 | // Forward declarations. |
@@ -84,7 +99,7 @@ static HRESULT AllocHelper( | |||
84 | if (cch >= MAXDWORD / sizeof(WCHAR)) | 99 | if (cch >= MAXDWORD / sizeof(WCHAR)) |
85 | { | 100 | { |
86 | hr = E_OUTOFMEMORY; | 101 | hr = E_OUTOFMEMORY; |
87 | ExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch); | 102 | StrExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch); |
88 | } | 103 | } |
89 | 104 | ||
90 | if (*ppwz) | 105 | if (*ppwz) |
@@ -93,7 +108,7 @@ static HRESULT AllocHelper( | |||
93 | { | 108 | { |
94 | LPVOID pvNew = NULL; | 109 | LPVOID pvNew = NULL; |
95 | hr = MemReAllocSecure(*ppwz, sizeof(WCHAR)* cch, FALSE, &pvNew); | 110 | hr = MemReAllocSecure(*ppwz, sizeof(WCHAR)* cch, FALSE, &pvNew); |
96 | ExitOnFailure(hr, "Failed to reallocate string"); | 111 | StrExitOnFailure(hr, "Failed to reallocate string"); |
97 | pwz = static_cast<LPWSTR>(pvNew); | 112 | pwz = static_cast<LPWSTR>(pvNew); |
98 | } | 113 | } |
99 | else | 114 | else |
@@ -106,7 +121,7 @@ static HRESULT AllocHelper( | |||
106 | pwz = static_cast<LPWSTR>(MemAlloc(sizeof(WCHAR) * cch, TRUE)); | 121 | pwz = static_cast<LPWSTR>(MemAlloc(sizeof(WCHAR) * cch, TRUE)); |
107 | } | 122 | } |
108 | 123 | ||
109 | ExitOnNull(pwz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch); | 124 | StrExitOnNull(pwz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch); |
110 | 125 | ||
111 | *ppwz = pwz; | 126 | *ppwz = pwz; |
112 | LExit: | 127 | LExit: |
@@ -131,12 +146,12 @@ HRESULT DAPI StrTrimCapacity( | |||
131 | SIZE_T cchLen = 0; | 146 | SIZE_T cchLen = 0; |
132 | 147 | ||
133 | hr = ::StringCchLengthW(*ppwz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen)); | 148 | hr = ::StringCchLengthW(*ppwz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen)); |
134 | ExitOnFailure(hr, "Failed to calculate length of string"); | 149 | StrExitOnFailure(hr, "Failed to calculate length of string"); |
135 | 150 | ||
136 | ++cchLen; // Add 1 for null-terminator | 151 | ++cchLen; // Add 1 for null-terminator |
137 | 152 | ||
138 | hr = StrAlloc(ppwz, cchLen); | 153 | hr = StrAlloc(ppwz, cchLen); |
139 | ExitOnFailure(hr, "Failed to reallocate string"); | 154 | StrExitOnFailure(hr, "Failed to reallocate string"); |
140 | 155 | ||
141 | LExit: | 156 | LExit: |
142 | return hr; | 157 | return hr; |
@@ -181,7 +196,7 @@ HRESULT DAPI StrTrimWhitespace( | |||
181 | } | 196 | } |
182 | 197 | ||
183 | hr = StrAllocString(&sczResult, wzSource, i); | 198 | hr = StrAllocString(&sczResult, wzSource, i); |
184 | ExitOnFailure(hr, "Failed to copy result string"); | 199 | StrExitOnFailure(hr, "Failed to copy result string"); |
185 | 200 | ||
186 | // Output result | 201 | // Output result |
187 | *ppwz = sczResult; | 202 | *ppwz = sczResult; |
@@ -212,7 +227,7 @@ extern "C" HRESULT DAPI StrAnsiAlloc( | |||
212 | if (cch >= MAXDWORD / sizeof(WCHAR)) | 227 | if (cch >= MAXDWORD / sizeof(WCHAR)) |
213 | { | 228 | { |
214 | hr = E_OUTOFMEMORY; | 229 | hr = E_OUTOFMEMORY; |
215 | ExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch); | 230 | StrExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch); |
216 | } | 231 | } |
217 | 232 | ||
218 | if (*ppsz) | 233 | if (*ppsz) |
@@ -224,7 +239,7 @@ extern "C" HRESULT DAPI StrAnsiAlloc( | |||
224 | psz = static_cast<LPSTR>(MemAlloc(sizeof(CHAR) * cch, TRUE)); | 239 | psz = static_cast<LPSTR>(MemAlloc(sizeof(CHAR) * cch, TRUE)); |
225 | } | 240 | } |
226 | 241 | ||
227 | ExitOnNull(psz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch); | 242 | StrExitOnNull(psz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch); |
228 | 243 | ||
229 | *ppsz = psz; | 244 | *ppsz = psz; |
230 | LExit: | 245 | LExit: |
@@ -252,12 +267,12 @@ HRESULT DAPI StrAnsiTrimCapacity( | |||
252 | #pragma prefast(disable:25068) | 267 | #pragma prefast(disable:25068) |
253 | hr = ::StringCchLengthA(*ppz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen)); | 268 | hr = ::StringCchLengthA(*ppz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen)); |
254 | #pragma prefast(pop) | 269 | #pragma prefast(pop) |
255 | ExitOnFailure(hr, "Failed to calculate length of string"); | 270 | StrExitOnFailure(hr, "Failed to calculate length of string"); |
256 | 271 | ||
257 | ++cchLen; // Add 1 for null-terminator | 272 | ++cchLen; // Add 1 for null-terminator |
258 | 273 | ||
259 | hr = StrAnsiAlloc(ppz, cchLen); | 274 | hr = StrAnsiAlloc(ppz, cchLen); |
260 | ExitOnFailure(hr, "Failed to reallocate string"); | 275 | StrExitOnFailure(hr, "Failed to reallocate string"); |
261 | 276 | ||
262 | LExit: | 277 | LExit: |
263 | return hr; | 278 | return hr; |
@@ -302,7 +317,7 @@ HRESULT DAPI StrAnsiTrimWhitespace( | |||
302 | } | 317 | } |
303 | 318 | ||
304 | hr = StrAnsiAllocStringAnsi(&sczResult, szSource, i); | 319 | hr = StrAnsiAllocStringAnsi(&sczResult, szSource, i); |
305 | ExitOnFailure(hr, "Failed to copy result string"); | 320 | StrExitOnFailure(hr, "Failed to copy result string"); |
306 | 321 | ||
307 | // Output result | 322 | // Output result |
308 | *ppz = sczResult; | 323 | *ppz = sczResult; |
@@ -375,7 +390,7 @@ static HRESULT AllocStringHelper( | |||
375 | if (-1 == cch) | 390 | if (-1 == cch) |
376 | { | 391 | { |
377 | hr = E_INVALIDARG; | 392 | hr = E_INVALIDARG; |
378 | ExitOnFailure(hr, "failed to get size of destination string"); | 393 | StrExitOnFailure(hr, "failed to get size of destination string"); |
379 | } | 394 | } |
380 | cch /= sizeof(WCHAR); //convert the count in bytes to count in characters | 395 | cch /= sizeof(WCHAR); //convert the count in bytes to count in characters |
381 | } | 396 | } |
@@ -387,13 +402,13 @@ static HRESULT AllocStringHelper( | |||
387 | 402 | ||
388 | SIZE_T cchNeeded; | 403 | SIZE_T cchNeeded; |
389 | hr = ::ULongPtrAdd(cchSource, 1, &cchNeeded); // add one for the null terminator | 404 | hr = ::ULongPtrAdd(cchSource, 1, &cchNeeded); // add one for the null terminator |
390 | ExitOnFailure(hr, "source string is too long"); | 405 | StrExitOnFailure(hr, "source string is too long"); |
391 | 406 | ||
392 | if (cch < cchNeeded) | 407 | if (cch < cchNeeded) |
393 | { | 408 | { |
394 | cch = cchNeeded; | 409 | cch = cchNeeded; |
395 | hr = AllocHelper(ppwz, cch, fZeroOnRealloc); | 410 | hr = AllocHelper(ppwz, cch, fZeroOnRealloc); |
396 | ExitOnFailure(hr, "failed to allocate string from string."); | 411 | StrExitOnFailure(hr, "failed to allocate string from string."); |
397 | } | 412 | } |
398 | 413 | ||
399 | // copy everything (the NULL terminator will be included) | 414 | // copy everything (the NULL terminator will be included) |
@@ -431,7 +446,7 @@ extern "C" HRESULT DAPI StrAnsiAllocString( | |||
431 | if (-1 == cch) | 446 | if (-1 == cch) |
432 | { | 447 | { |
433 | hr = E_INVALIDARG; | 448 | hr = E_INVALIDARG; |
434 | ExitOnFailure(hr, "failed to get size of destination string"); | 449 | StrExitOnFailure(hr, "failed to get size of destination string"); |
435 | } | 450 | } |
436 | cch /= sizeof(CHAR); //convert the count in bytes to count in characters | 451 | cch /= sizeof(CHAR); //convert the count in bytes to count in characters |
437 | } | 452 | } |
@@ -441,7 +456,7 @@ extern "C" HRESULT DAPI StrAnsiAllocString( | |||
441 | cchDest = ::WideCharToMultiByte(uiCodepage, 0, wzSource, -1, NULL, 0, NULL, NULL); | 456 | cchDest = ::WideCharToMultiByte(uiCodepage, 0, wzSource, -1, NULL, 0, NULL, NULL); |
442 | if (0 == cchDest) | 457 | if (0 == cchDest) |
443 | { | 458 | { |
444 | ExitWithLastError(hr, "failed to get required size for conversion to ANSI: %ls", wzSource); | 459 | StrExitWithLastError(hr, "failed to get required size for conversion to ANSI: %ls", wzSource); |
445 | } | 460 | } |
446 | 461 | ||
447 | --cchDest; // subtract one because WideChageToMultiByte includes space for the NULL terminator that we track below | 462 | --cchDest; // subtract one because WideChageToMultiByte includes space for the NULL terminator that we track below |
@@ -457,7 +472,7 @@ extern "C" HRESULT DAPI StrAnsiAllocString( | |||
457 | if (cch >= MAXDWORD / sizeof(WCHAR)) | 472 | if (cch >= MAXDWORD / sizeof(WCHAR)) |
458 | { | 473 | { |
459 | hr = E_OUTOFMEMORY; | 474 | hr = E_OUTOFMEMORY; |
460 | ExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch); | 475 | StrExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch); |
461 | } | 476 | } |
462 | 477 | ||
463 | if (*ppsz) | 478 | if (*ppsz) |
@@ -468,14 +483,14 @@ extern "C" HRESULT DAPI StrAnsiAllocString( | |||
468 | { | 483 | { |
469 | psz = static_cast<LPSTR>(MemAlloc(sizeof(CHAR) * cch, TRUE)); | 484 | psz = static_cast<LPSTR>(MemAlloc(sizeof(CHAR) * cch, TRUE)); |
470 | } | 485 | } |
471 | ExitOnNull(psz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch); | 486 | StrExitOnNull(psz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch); |
472 | 487 | ||
473 | *ppsz = psz; | 488 | *ppsz = psz; |
474 | } | 489 | } |
475 | 490 | ||
476 | if (0 == ::WideCharToMultiByte(uiCodepage, 0, wzSource, 0 == cchSource ? -1 : (int)cchSource, *ppsz, (int)cch, NULL, NULL)) | 491 | if (0 == ::WideCharToMultiByte(uiCodepage, 0, wzSource, 0 == cchSource ? -1 : (int)cchSource, *ppsz, (int)cch, NULL, NULL)) |
477 | { | 492 | { |
478 | ExitWithLastError(hr, "failed to convert to ansi: %ls", wzSource); | 493 | StrExitWithLastError(hr, "failed to convert to ansi: %ls", wzSource); |
479 | } | 494 | } |
480 | (*ppsz)[cchDest] = L'\0'; | 495 | (*ppsz)[cchDest] = L'\0'; |
481 | 496 | ||
@@ -511,7 +526,7 @@ extern "C" HRESULT DAPI StrAllocStringAnsi( | |||
511 | if (-1 == cch) | 526 | if (-1 == cch) |
512 | { | 527 | { |
513 | hr = E_INVALIDARG; | 528 | hr = E_INVALIDARG; |
514 | ExitOnFailure(hr, "failed to get size of destination string"); | 529 | StrExitOnFailure(hr, "failed to get size of destination string"); |
515 | } | 530 | } |
516 | cch /= sizeof(WCHAR); //convert the count in bytes to count in characters | 531 | cch /= sizeof(WCHAR); //convert the count in bytes to count in characters |
517 | } | 532 | } |
@@ -521,7 +536,7 @@ extern "C" HRESULT DAPI StrAllocStringAnsi( | |||
521 | cchDest = ::MultiByteToWideChar(uiCodepage, 0, szSource, -1, NULL, 0); | 536 | cchDest = ::MultiByteToWideChar(uiCodepage, 0, szSource, -1, NULL, 0); |
522 | if (0 == cchDest) | 537 | if (0 == cchDest) |
523 | { | 538 | { |
524 | ExitWithLastError(hr, "failed to get required size for conversion to unicode: %s", szSource); | 539 | StrExitWithLastError(hr, "failed to get required size for conversion to unicode: %s", szSource); |
525 | } | 540 | } |
526 | 541 | ||
527 | --cchDest; //subtract one because MultiByteToWideChar includes space for the NULL terminator that we track below | 542 | --cchDest; //subtract one because MultiByteToWideChar includes space for the NULL terminator that we track below |
@@ -537,7 +552,7 @@ extern "C" HRESULT DAPI StrAllocStringAnsi( | |||
537 | if (cch >= MAXDWORD / sizeof(WCHAR)) | 552 | if (cch >= MAXDWORD / sizeof(WCHAR)) |
538 | { | 553 | { |
539 | hr = E_OUTOFMEMORY; | 554 | hr = E_OUTOFMEMORY; |
540 | ExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch); | 555 | StrExitOnFailure(hr, "Not enough memory to allocate string of size: %u", cch); |
541 | } | 556 | } |
542 | 557 | ||
543 | if (*ppwz) | 558 | if (*ppwz) |
@@ -549,14 +564,14 @@ extern "C" HRESULT DAPI StrAllocStringAnsi( | |||
549 | pwz = static_cast<LPWSTR>(MemAlloc(sizeof(WCHAR) * cch, TRUE)); | 564 | pwz = static_cast<LPWSTR>(MemAlloc(sizeof(WCHAR) * cch, TRUE)); |
550 | } | 565 | } |
551 | 566 | ||
552 | ExitOnNull(pwz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch); | 567 | StrExitOnNull(pwz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %u", cch); |
553 | 568 | ||
554 | *ppwz = pwz; | 569 | *ppwz = pwz; |
555 | } | 570 | } |
556 | 571 | ||
557 | if (0 == ::MultiByteToWideChar(uiCodepage, 0, szSource, 0 == cchSource ? -1 : (int)cchSource, *ppwz, (int)cch)) | 572 | if (0 == ::MultiByteToWideChar(uiCodepage, 0, szSource, 0 == cchSource ? -1 : (int)cchSource, *ppwz, (int)cch)) |
558 | { | 573 | { |
559 | ExitWithLastError(hr, "failed to convert to unicode: %s", szSource); | 574 | StrExitWithLastError(hr, "failed to convert to unicode: %s", szSource); |
560 | } | 575 | } |
561 | (*ppwz)[cchDest] = L'\0'; | 576 | (*ppwz)[cchDest] = L'\0'; |
562 | 577 | ||
@@ -589,7 +604,7 @@ HRESULT DAPI StrAnsiAllocStringAnsi( | |||
589 | if (-1 == cch) | 604 | if (-1 == cch) |
590 | { | 605 | { |
591 | hr = E_INVALIDARG; | 606 | hr = E_INVALIDARG; |
592 | ExitOnFailure(hr, "failed to get size of destination string"); | 607 | StrExitOnFailure(hr, "failed to get size of destination string"); |
593 | } | 608 | } |
594 | cch /= sizeof(CHAR); //convert the count in bytes to count in characters | 609 | cch /= sizeof(CHAR); //convert the count in bytes to count in characters |
595 | } | 610 | } |
@@ -601,13 +616,13 @@ HRESULT DAPI StrAnsiAllocStringAnsi( | |||
601 | 616 | ||
602 | SIZE_T cchNeeded; | 617 | SIZE_T cchNeeded; |
603 | hr = ::ULongPtrAdd(cchSource, 1, &cchNeeded); // add one for the null terminator | 618 | hr = ::ULongPtrAdd(cchSource, 1, &cchNeeded); // add one for the null terminator |
604 | ExitOnFailure(hr, "source string is too long"); | 619 | StrExitOnFailure(hr, "source string is too long"); |
605 | 620 | ||
606 | if (cch < cchNeeded) | 621 | if (cch < cchNeeded) |
607 | { | 622 | { |
608 | cch = cchNeeded; | 623 | cch = cchNeeded; |
609 | hr = StrAnsiAlloc(ppsz, cch); | 624 | hr = StrAnsiAlloc(ppsz, cch); |
610 | ExitOnFailure(hr, "failed to allocate string from string."); | 625 | StrExitOnFailure(hr, "failed to allocate string from string."); |
611 | } | 626 | } |
612 | 627 | ||
613 | // copy everything (the NULL terminator will be included) | 628 | // copy everything (the NULL terminator will be included) |
@@ -647,12 +662,12 @@ extern "C" HRESULT DAPI StrAllocPrefix( | |||
647 | if (-1 == cch) | 662 | if (-1 == cch) |
648 | { | 663 | { |
649 | hr = E_INVALIDARG; | 664 | hr = E_INVALIDARG; |
650 | ExitOnFailure(hr, "failed to get size of destination string"); | 665 | StrExitOnFailure(hr, "failed to get size of destination string"); |
651 | } | 666 | } |
652 | cch /= sizeof(WCHAR); //convert the count in bytes to count in characters | 667 | cch /= sizeof(WCHAR); //convert the count in bytes to count in characters |
653 | 668 | ||
654 | hr = ::StringCchLengthW(*ppwz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen)); | 669 | hr = ::StringCchLengthW(*ppwz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen)); |
655 | ExitOnFailure(hr, "Failed to calculate length of string"); | 670 | StrExitOnFailure(hr, "Failed to calculate length of string"); |
656 | } | 671 | } |
657 | 672 | ||
658 | Assert(cchLen <= cch); | 673 | Assert(cchLen <= cch); |
@@ -660,14 +675,14 @@ extern "C" HRESULT DAPI StrAllocPrefix( | |||
660 | if (0 == cchPrefix) | 675 | if (0 == cchPrefix) |
661 | { | 676 | { |
662 | hr = ::StringCchLengthW(wzPrefix, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchPrefix)); | 677 | hr = ::StringCchLengthW(wzPrefix, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchPrefix)); |
663 | ExitOnFailure(hr, "Failed to calculate length of string"); | 678 | StrExitOnFailure(hr, "Failed to calculate length of string"); |
664 | } | 679 | } |
665 | 680 | ||
666 | if (cch - cchLen < cchPrefix + 1) | 681 | if (cch - cchLen < cchPrefix + 1) |
667 | { | 682 | { |
668 | cch = cchPrefix + cchLen + 1; | 683 | cch = cchPrefix + cchLen + 1; |
669 | hr = StrAlloc(ppwz, cch); | 684 | hr = StrAlloc(ppwz, cch); |
670 | ExitOnFailure(hr, "failed to allocate string from string: %ls", wzPrefix); | 685 | StrExitOnFailure(hr, "failed to allocate string from string: %ls", wzPrefix); |
671 | } | 686 | } |
672 | 687 | ||
673 | if (*ppwz) | 688 | if (*ppwz) |
@@ -681,7 +696,7 @@ extern "C" HRESULT DAPI StrAllocPrefix( | |||
681 | else | 696 | else |
682 | { | 697 | { |
683 | hr = E_UNEXPECTED; | 698 | hr = E_UNEXPECTED; |
684 | ExitOnFailure(hr, "for some reason our buffer is still null"); | 699 | StrExitOnFailure(hr, "for some reason our buffer is still null"); |
685 | } | 700 | } |
686 | 701 | ||
687 | LExit: | 702 | LExit: |
@@ -753,12 +768,12 @@ static HRESULT AllocConcatHelper( | |||
753 | if (-1 == cch) | 768 | if (-1 == cch) |
754 | { | 769 | { |
755 | hr = E_INVALIDARG; | 770 | hr = E_INVALIDARG; |
756 | ExitOnFailure(hr, "failed to get size of destination string"); | 771 | StrExitOnFailure(hr, "failed to get size of destination string"); |
757 | } | 772 | } |
758 | cch /= sizeof(WCHAR); //convert the count in bytes to count in characters | 773 | cch /= sizeof(WCHAR); //convert the count in bytes to count in characters |
759 | 774 | ||
760 | hr = ::StringCchLengthW(*ppwz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen)); | 775 | hr = ::StringCchLengthW(*ppwz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen)); |
761 | ExitOnFailure(hr, "Failed to calculate length of string"); | 776 | StrExitOnFailure(hr, "Failed to calculate length of string"); |
762 | } | 777 | } |
763 | 778 | ||
764 | Assert(cchLen <= cch); | 779 | Assert(cchLen <= cch); |
@@ -766,14 +781,14 @@ static HRESULT AllocConcatHelper( | |||
766 | if (0 == cchSource) | 781 | if (0 == cchSource) |
767 | { | 782 | { |
768 | hr = ::StringCchLengthW(wzSource, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchSource)); | 783 | hr = ::StringCchLengthW(wzSource, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchSource)); |
769 | ExitOnFailure(hr, "Failed to calculate length of string"); | 784 | StrExitOnFailure(hr, "Failed to calculate length of string"); |
770 | } | 785 | } |
771 | 786 | ||
772 | if (cch - cchLen < cchSource + 1) | 787 | if (cch - cchLen < cchSource + 1) |
773 | { | 788 | { |
774 | cch = (cchSource + cchLen + 1) * 2; | 789 | cch = (cchSource + cchLen + 1) * 2; |
775 | hr = AllocHelper(ppwz, cch, fZeroOnRealloc); | 790 | hr = AllocHelper(ppwz, cch, fZeroOnRealloc); |
776 | ExitOnFailure(hr, "failed to allocate string from string: %ls", wzSource); | 791 | StrExitOnFailure(hr, "failed to allocate string from string: %ls", wzSource); |
777 | } | 792 | } |
778 | 793 | ||
779 | if (*ppwz) | 794 | if (*ppwz) |
@@ -783,7 +798,7 @@ static HRESULT AllocConcatHelper( | |||
783 | else | 798 | else |
784 | { | 799 | { |
785 | hr = E_UNEXPECTED; | 800 | hr = E_UNEXPECTED; |
786 | ExitOnFailure(hr, "for some reason our buffer is still null"); | 801 | StrExitOnFailure(hr, "for some reason our buffer is still null"); |
787 | } | 802 | } |
788 | 803 | ||
789 | LExit: | 804 | LExit: |
@@ -816,7 +831,7 @@ extern "C" HRESULT DAPI StrAnsiAllocConcat( | |||
816 | if (-1 == cch) | 831 | if (-1 == cch) |
817 | { | 832 | { |
818 | hr = E_INVALIDARG; | 833 | hr = E_INVALIDARG; |
819 | ExitOnFailure(hr, "failed to get size of destination string"); | 834 | StrExitOnFailure(hr, "failed to get size of destination string"); |
820 | } | 835 | } |
821 | cch /= sizeof(CHAR); // convert the count in bytes to count in characters | 836 | cch /= sizeof(CHAR); // convert the count in bytes to count in characters |
822 | 837 | ||
@@ -824,7 +839,7 @@ extern "C" HRESULT DAPI StrAnsiAllocConcat( | |||
824 | #pragma prefast(disable:25068) | 839 | #pragma prefast(disable:25068) |
825 | hr = ::StringCchLengthA(*ppz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen)); | 840 | hr = ::StringCchLengthA(*ppz, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchLen)); |
826 | #pragma prefast(pop) | 841 | #pragma prefast(pop) |
827 | ExitOnFailure(hr, "Failed to calculate length of string"); | 842 | StrExitOnFailure(hr, "Failed to calculate length of string"); |
828 | } | 843 | } |
829 | 844 | ||
830 | Assert(cchLen <= cch); | 845 | Assert(cchLen <= cch); |
@@ -835,14 +850,14 @@ extern "C" HRESULT DAPI StrAnsiAllocConcat( | |||
835 | #pragma prefast(disable:25068) | 850 | #pragma prefast(disable:25068) |
836 | hr = ::StringCchLengthA(pzSource, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchSource)); | 851 | hr = ::StringCchLengthA(pzSource, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchSource)); |
837 | #pragma prefast(pop) | 852 | #pragma prefast(pop) |
838 | ExitOnFailure(hr, "Failed to calculate length of string"); | 853 | StrExitOnFailure(hr, "Failed to calculate length of string"); |
839 | } | 854 | } |
840 | 855 | ||
841 | if (cch - cchLen < cchSource + 1) | 856 | if (cch - cchLen < cchSource + 1) |
842 | { | 857 | { |
843 | cch = (cchSource + cchLen + 1) * 2; | 858 | cch = (cchSource + cchLen + 1) * 2; |
844 | hr = StrAnsiAlloc(ppz, cch); | 859 | hr = StrAnsiAlloc(ppz, cch); |
845 | ExitOnFailure(hr, "failed to allocate string from string: %hs", pzSource); | 860 | StrExitOnFailure(hr, "failed to allocate string from string: %hs", pzSource); |
846 | } | 861 | } |
847 | 862 | ||
848 | if (*ppz) | 863 | if (*ppz) |
@@ -855,7 +870,7 @@ extern "C" HRESULT DAPI StrAnsiAllocConcat( | |||
855 | else | 870 | else |
856 | { | 871 | { |
857 | hr = E_UNEXPECTED; | 872 | hr = E_UNEXPECTED; |
858 | ExitOnFailure(hr, "for some reason our buffer is still null"); | 873 | StrExitOnFailure(hr, "for some reason our buffer is still null"); |
859 | } | 874 | } |
860 | 875 | ||
861 | LExit: | 876 | LExit: |
@@ -908,7 +923,7 @@ extern "C" HRESULT __cdecl StrAllocConcatFormatted( | |||
908 | va_start(args, wzFormat); | 923 | va_start(args, wzFormat); |
909 | hr = StrAllocFormattedArgs(&sczFormatted, wzFormat, args); | 924 | hr = StrAllocFormattedArgs(&sczFormatted, wzFormat, args); |
910 | va_end(args); | 925 | va_end(args); |
911 | ExitOnFailure(hr, "Failed to allocate formatted string"); | 926 | StrExitOnFailure(hr, "Failed to allocate formatted string"); |
912 | 927 | ||
913 | hr = StrAllocConcat(ppwz, sczFormatted, 0); | 928 | hr = StrAllocConcat(ppwz, sczFormatted, 0); |
914 | 929 | ||
@@ -942,7 +957,7 @@ extern "C" HRESULT __cdecl StrAllocConcatFormattedSecure( | |||
942 | va_start(args, wzFormat); | 957 | va_start(args, wzFormat); |
943 | hr = StrAllocFormattedArgsSecure(&sczFormatted, wzFormat, args); | 958 | hr = StrAllocFormattedArgsSecure(&sczFormatted, wzFormat, args); |
944 | va_end(args); | 959 | va_end(args); |
945 | ExitOnFailure(hr, "Failed to allocate formatted string"); | 960 | StrExitOnFailure(hr, "Failed to allocate formatted string"); |
946 | 961 | ||
947 | hr = StrAllocConcatSecure(ppwz, sczFormatted, 0); | 962 | hr = StrAllocConcatSecure(ppwz, sczFormatted, 0); |
948 | 963 | ||
@@ -1068,7 +1083,7 @@ static HRESULT AllocFormattedArgsHelper( | |||
1068 | if (-1 == cbOriginal) | 1083 | if (-1 == cbOriginal) |
1069 | { | 1084 | { |
1070 | hr = E_INVALIDARG; | 1085 | hr = E_INVALIDARG; |
1071 | ExitOnFailure(hr, "failed to get size of destination string"); | 1086 | StrExitOnFailure(hr, "failed to get size of destination string"); |
1072 | } | 1087 | } |
1073 | 1088 | ||
1074 | cch = cbOriginal / sizeof(WCHAR); //convert the count in bytes to count in characters | 1089 | cch = cbOriginal / sizeof(WCHAR); //convert the count in bytes to count in characters |
@@ -1080,7 +1095,7 @@ static HRESULT AllocFormattedArgsHelper( | |||
1080 | cch = 256; | 1095 | cch = 256; |
1081 | 1096 | ||
1082 | hr = AllocHelper(ppwz, cch, fZeroOnRealloc); | 1097 | hr = AllocHelper(ppwz, cch, fZeroOnRealloc); |
1083 | ExitOnFailure(hr, "failed to allocate string to format: %ls", wzFormat); | 1098 | StrExitOnFailure(hr, "failed to allocate string to format: %ls", wzFormat); |
1084 | } | 1099 | } |
1085 | 1100 | ||
1086 | // format the message (grow until it fits or there is a failure) | 1101 | // format the message (grow until it fits or there is a failure) |
@@ -1104,12 +1119,12 @@ static HRESULT AllocFormattedArgsHelper( | |||
1104 | cch *= 2; | 1119 | cch *= 2; |
1105 | 1120 | ||
1106 | hr = AllocHelper(ppwz, cch, fZeroOnRealloc); | 1121 | hr = AllocHelper(ppwz, cch, fZeroOnRealloc); |
1107 | ExitOnFailure(hr, "failed to allocate string to format: %ls", wzFormat); | 1122 | StrExitOnFailure(hr, "failed to allocate string to format: %ls", wzFormat); |
1108 | 1123 | ||
1109 | hr = S_FALSE; | 1124 | hr = S_FALSE; |
1110 | } | 1125 | } |
1111 | } while (S_FALSE == hr); | 1126 | } while (S_FALSE == hr); |
1112 | ExitOnFailure(hr, "failed to format string"); | 1127 | StrExitOnFailure(hr, "failed to format string"); |
1113 | 1128 | ||
1114 | LExit: | 1129 | LExit: |
1115 | if (pwzOriginal && fZeroOnRealloc) | 1130 | if (pwzOriginal && fZeroOnRealloc) |
@@ -1148,7 +1163,7 @@ extern "C" HRESULT DAPI StrAnsiAllocFormattedArgs( | |||
1148 | if (-1 == cch) | 1163 | if (-1 == cch) |
1149 | { | 1164 | { |
1150 | hr = E_INVALIDARG; | 1165 | hr = E_INVALIDARG; |
1151 | ExitOnFailure(hr, "failed to get size of destination string"); | 1166 | StrExitOnFailure(hr, "failed to get size of destination string"); |
1152 | } | 1167 | } |
1153 | cch /= sizeof(CHAR); //convert the count in bytes to count in characters | 1168 | cch /= sizeof(CHAR); //convert the count in bytes to count in characters |
1154 | 1169 | ||
@@ -1159,7 +1174,7 @@ extern "C" HRESULT DAPI StrAnsiAllocFormattedArgs( | |||
1159 | { | 1174 | { |
1160 | cch = 256; | 1175 | cch = 256; |
1161 | hr = StrAnsiAlloc(ppsz, cch); | 1176 | hr = StrAnsiAlloc(ppsz, cch); |
1162 | ExitOnFailure(hr, "failed to allocate string to format: %s", szFormat); | 1177 | StrExitOnFailure(hr, "failed to allocate string to format: %s", szFormat); |
1163 | } | 1178 | } |
1164 | 1179 | ||
1165 | // format the message (grow until it fits or there is a failure) | 1180 | // format the message (grow until it fits or there is a failure) |
@@ -1183,11 +1198,11 @@ extern "C" HRESULT DAPI StrAnsiAllocFormattedArgs( | |||
1183 | } | 1198 | } |
1184 | cch *= 2; | 1199 | cch *= 2; |
1185 | hr = StrAnsiAlloc(ppsz, cch); | 1200 | hr = StrAnsiAlloc(ppsz, cch); |
1186 | ExitOnFailure(hr, "failed to allocate string to format: %hs", szFormat); | 1201 | StrExitOnFailure(hr, "failed to allocate string to format: %hs", szFormat); |
1187 | hr = S_FALSE; | 1202 | hr = S_FALSE; |
1188 | } | 1203 | } |
1189 | } while (S_FALSE == hr); | 1204 | } while (S_FALSE == hr); |
1190 | ExitOnFailure(hr, "failed to format string"); | 1205 | StrExitOnFailure(hr, "failed to format string"); |
1191 | 1206 | ||
1192 | LExit: | 1207 | LExit: |
1193 | ReleaseStr(pszOriginal); | 1208 | ReleaseStr(pszOriginal); |
@@ -1224,11 +1239,11 @@ extern "C" HRESULT DAPI StrAllocFromError( | |||
1224 | 1239 | ||
1225 | if (0 == cchMessage) | 1240 | if (0 == cchMessage) |
1226 | { | 1241 | { |
1227 | ExitWithLastError(hr, "Failed to format message for error: 0x%x", hrError); | 1242 | StrExitWithLastError(hr, "Failed to format message for error: 0x%x", hrError); |
1228 | } | 1243 | } |
1229 | 1244 | ||
1230 | hr = StrAllocString(ppwzMessage, reinterpret_cast<LPCWSTR>(pvMessage), cchMessage); | 1245 | hr = StrAllocString(ppwzMessage, reinterpret_cast<LPCWSTR>(pvMessage), cchMessage); |
1231 | ExitOnFailure(hr, "Failed to allocate string for message."); | 1246 | StrExitOnFailure(hr, "Failed to allocate string for message."); |
1232 | 1247 | ||
1233 | LExit: | 1248 | LExit: |
1234 | if (pvMessage) | 1249 | if (pvMessage) |
@@ -1308,7 +1323,7 @@ extern "C" HRESULT DAPI StrFree( | |||
1308 | Assert(p); | 1323 | Assert(p); |
1309 | 1324 | ||
1310 | HRESULT hr = MemFree(p); | 1325 | HRESULT hr = MemFree(p); |
1311 | ExitOnFailure(hr, "failed to free string"); | 1326 | StrExitOnFailure(hr, "failed to free string"); |
1312 | 1327 | ||
1313 | LExit: | 1328 | LExit: |
1314 | return hr; | 1329 | return hr; |
@@ -1332,7 +1347,7 @@ extern "C" HRESULT DAPI StrReplaceStringAll( | |||
1332 | do | 1347 | do |
1333 | { | 1348 | { |
1334 | hr = StrReplaceString(ppwzOriginal, &dwStartIndex, wzOldSubString, wzNewSubString); | 1349 | hr = StrReplaceString(ppwzOriginal, &dwStartIndex, wzOldSubString, wzNewSubString); |
1335 | ExitOnFailure(hr, "Failed to replace substring"); | 1350 | StrExitOnFailure(hr, "Failed to replace substring"); |
1336 | } | 1351 | } |
1337 | while (S_OK == hr); | 1352 | while (S_OK == hr); |
1338 | 1353 | ||
@@ -1373,21 +1388,21 @@ extern "C" HRESULT DAPI StrReplaceString( | |||
1373 | } | 1388 | } |
1374 | 1389 | ||
1375 | hr = ::PtrdiffTToDWord(wzSubLocation - *ppwzOriginal, pdwStartIndex); | 1390 | hr = ::PtrdiffTToDWord(wzSubLocation - *ppwzOriginal, pdwStartIndex); |
1376 | ExitOnFailure(hr, "Failed to diff pointers."); | 1391 | StrExitOnFailure(hr, "Failed to diff pointers."); |
1377 | 1392 | ||
1378 | hr = StrAllocString(&pwzBuffer, *ppwzOriginal, wzSubLocation - *ppwzOriginal); | 1393 | hr = StrAllocString(&pwzBuffer, *ppwzOriginal, wzSubLocation - *ppwzOriginal); |
1379 | ExitOnFailure(hr, "Failed to duplicate string."); | 1394 | StrExitOnFailure(hr, "Failed to duplicate string."); |
1380 | 1395 | ||
1381 | pwzBuffer[wzSubLocation - *ppwzOriginal] = '\0'; | 1396 | pwzBuffer[wzSubLocation - *ppwzOriginal] = '\0'; |
1382 | 1397 | ||
1383 | hr = StrAllocConcat(&pwzBuffer, wzNewSubString, 0); | 1398 | hr = StrAllocConcat(&pwzBuffer, wzNewSubString, 0); |
1384 | ExitOnFailure(hr, "Failed to append new string."); | 1399 | StrExitOnFailure(hr, "Failed to append new string."); |
1385 | 1400 | ||
1386 | hr = StrAllocConcat(&pwzBuffer, wzSubLocation + wcslen(wzOldSubString), 0); | 1401 | hr = StrAllocConcat(&pwzBuffer, wzSubLocation + wcslen(wzOldSubString), 0); |
1387 | ExitOnFailure(hr, "Failed to append post string."); | 1402 | StrExitOnFailure(hr, "Failed to append post string."); |
1388 | 1403 | ||
1389 | hr = StrFree(*ppwzOriginal); | 1404 | hr = StrFree(*ppwzOriginal); |
1390 | ExitOnFailure(hr, "Failed to free original string."); | 1405 | StrExitOnFailure(hr, "Failed to free original string."); |
1391 | 1406 | ||
1392 | *ppwzOriginal = pwzBuffer; | 1407 | *ppwzOriginal = pwzBuffer; |
1393 | *pdwStartIndex = *pdwStartIndex + static_cast<DWORD>(wcslen(wzNewSubString)); | 1408 | *pdwStartIndex = *pdwStartIndex + static_cast<DWORD>(wcslen(wzNewSubString)); |
@@ -1477,10 +1492,10 @@ HRESULT DAPI StrAllocHexEncode( | |||
1477 | SIZE_T cchSource = sizeof(WCHAR) * (cbSource + 1); | 1492 | SIZE_T cchSource = sizeof(WCHAR) * (cbSource + 1); |
1478 | 1493 | ||
1479 | hr = StrAlloc(ppwzDest, cchSource); | 1494 | hr = StrAlloc(ppwzDest, cchSource); |
1480 | ExitOnFailure(hr, "Failed to allocate hex string."); | 1495 | StrExitOnFailure(hr, "Failed to allocate hex string."); |
1481 | 1496 | ||
1482 | hr = StrHexEncode(pbSource, cbSource, *ppwzDest, cchSource); | 1497 | hr = StrHexEncode(pbSource, cbSource, *ppwzDest, cchSource); |
1483 | ExitOnFailure(hr, "Failed to encode hex string."); | 1498 | StrExitOnFailure(hr, "Failed to encode hex string."); |
1484 | 1499 | ||
1485 | LExit: | 1500 | LExit: |
1486 | return hr; | 1501 | return hr; |
@@ -1509,7 +1524,7 @@ extern "C" HRESULT DAPI StrHexDecode( | |||
1509 | if (cbDest < cchSource / 2) | 1524 | if (cbDest < cchSource / 2) |
1510 | { | 1525 | { |
1511 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | 1526 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); |
1512 | ExitOnRootFailure(hr, "Insufficient buffer to decode string '%ls' len: %u into %u bytes.", wzSource, cchSource, cbDest); | 1527 | StrExitOnRootFailure(hr, "Insufficient buffer to decode string '%ls' len: %u into %u bytes.", wzSource, cchSource, cbDest); |
1513 | } | 1528 | } |
1514 | 1529 | ||
1515 | for (i = 0; i < cchSource / 2; ++i) | 1530 | for (i = 0; i < cchSource / 2; ++i) |
@@ -1547,20 +1562,20 @@ extern "C" HRESULT DAPI StrAllocHexDecode( | |||
1547 | DWORD cb = 0; | 1562 | DWORD cb = 0; |
1548 | 1563 | ||
1549 | hr = ::StringCchLengthW(wzSource, STRSAFE_MAX_CCH, &cch); | 1564 | hr = ::StringCchLengthW(wzSource, STRSAFE_MAX_CCH, &cch); |
1550 | ExitOnFailure(hr, "Failed to calculate length of source string."); | 1565 | StrExitOnFailure(hr, "Failed to calculate length of source string."); |
1551 | 1566 | ||
1552 | if (cch % 2) | 1567 | if (cch % 2) |
1553 | { | 1568 | { |
1554 | hr = E_INVALIDARG; | 1569 | hr = E_INVALIDARG; |
1555 | ExitOnFailure(hr, "Invalid source parameter, string must be even length or it cannot be decoded."); | 1570 | StrExitOnFailure(hr, "Invalid source parameter, string must be even length or it cannot be decoded."); |
1556 | } | 1571 | } |
1557 | 1572 | ||
1558 | cb = static_cast<DWORD>(cch / 2); | 1573 | cb = static_cast<DWORD>(cch / 2); |
1559 | pb = static_cast<BYTE*>(MemAlloc(cb, TRUE)); | 1574 | pb = static_cast<BYTE*>(MemAlloc(cb, TRUE)); |
1560 | ExitOnNull(pb, hr, E_OUTOFMEMORY, "Failed to allocate memory for hex decode."); | 1575 | StrExitOnNull(pb, hr, E_OUTOFMEMORY, "Failed to allocate memory for hex decode."); |
1561 | 1576 | ||
1562 | hr = StrHexDecode(wzSource, pb, cb); | 1577 | hr = StrHexDecode(wzSource, pb, cb); |
1563 | ExitOnFailure(hr, "Failed to decode source string."); | 1578 | StrExitOnFailure(hr, "Failed to decode source string."); |
1564 | 1579 | ||
1565 | *ppbDest = pb; | 1580 | *ppbDest = pb; |
1566 | pb = NULL; | 1581 | pb = NULL; |
@@ -1637,7 +1652,7 @@ extern "C" HRESULT DAPI StrAllocBase85Encode( | |||
1637 | ++cchDest; // add room for null terminator | 1652 | ++cchDest; // add room for null terminator |
1638 | 1653 | ||
1639 | hr = StrAlloc(pwzDest, cchDest); | 1654 | hr = StrAlloc(pwzDest, cchDest); |
1640 | ExitOnFailure(hr, "failed to allocate destination string"); | 1655 | StrExitOnFailure(hr, "failed to allocate destination string"); |
1641 | 1656 | ||
1642 | wzDest = *pwzDest; | 1657 | wzDest = *pwzDest; |
1643 | 1658 | ||
@@ -1740,7 +1755,7 @@ extern "C" HRESULT DAPI StrAllocBase85Decode( | |||
1740 | } | 1755 | } |
1741 | 1756 | ||
1742 | *ppbDest = static_cast<BYTE*>(MemAlloc(cbDest, FALSE)); | 1757 | *ppbDest = static_cast<BYTE*>(MemAlloc(cbDest, FALSE)); |
1743 | ExitOnNull(*ppbDest, hr, E_OUTOFMEMORY, "failed allocate memory to decode the string"); | 1758 | StrExitOnNull(*ppbDest, hr, E_OUTOFMEMORY, "failed allocate memory to decode the string"); |
1744 | 1759 | ||
1745 | pbDest = *ppbDest; | 1760 | pbDest = *ppbDest; |
1746 | *pcbDest = cbDest; | 1761 | *pcbDest = cbDest; |
@@ -1860,7 +1875,7 @@ extern "C" HRESULT DAPI MultiSzLen( | |||
1860 | DWORD_PTR dwMaxSize = 0; | 1875 | DWORD_PTR dwMaxSize = 0; |
1861 | 1876 | ||
1862 | hr = StrMaxLength(pwzMultiSz, &dwMaxSize); | 1877 | hr = StrMaxLength(pwzMultiSz, &dwMaxSize); |
1863 | ExitOnFailure(hr, "failed to get the max size of a string while calculating MULTISZ length"); | 1878 | StrExitOnFailure(hr, "failed to get the max size of a string while calculating MULTISZ length"); |
1864 | 1879 | ||
1865 | *pcch = 0; | 1880 | *pcch = 0; |
1866 | while (*pcch < dwMaxSize) | 1881 | while (*pcch < dwMaxSize) |
@@ -1914,7 +1929,7 @@ extern "C" HRESULT DAPI MultiSzPrepend( | |||
1914 | else | 1929 | else |
1915 | { | 1930 | { |
1916 | hr = MultiSzLen(*ppwzMultiSz, &cchMultiSz); | 1931 | hr = MultiSzLen(*ppwzMultiSz, &cchMultiSz); |
1917 | ExitOnFailure(hr, "failed to get length of multisz"); | 1932 | StrExitOnFailure(hr, "failed to get length of multisz"); |
1918 | } | 1933 | } |
1919 | 1934 | ||
1920 | cchInsert = lstrlenW(pwzInsert); | 1935 | cchInsert = lstrlenW(pwzInsert); |
@@ -1923,11 +1938,11 @@ extern "C" HRESULT DAPI MultiSzPrepend( | |||
1923 | 1938 | ||
1924 | // Allocate the result buffer | 1939 | // Allocate the result buffer |
1925 | hr = StrAlloc(&pwzResult, cchResult + 1); | 1940 | hr = StrAlloc(&pwzResult, cchResult + 1); |
1926 | ExitOnFailure(hr, "failed to allocate result string"); | 1941 | StrExitOnFailure(hr, "failed to allocate result string"); |
1927 | 1942 | ||
1928 | // Prepend | 1943 | // Prepend |
1929 | hr = ::StringCchCopyW(pwzResult, cchResult, pwzInsert); | 1944 | hr = ::StringCchCopyW(pwzResult, cchResult, pwzInsert); |
1930 | ExitOnFailure(hr, "failed to copy prepend string: %ls", pwzInsert); | 1945 | StrExitOnFailure(hr, "failed to copy prepend string: %ls", pwzInsert); |
1931 | 1946 | ||
1932 | // If there was no MULTISZ, double null terminate our result, otherwise, copy the MULTISZ in | 1947 | // If there was no MULTISZ, double null terminate our result, otherwise, copy the MULTISZ in |
1933 | if (0 == cchMultiSz) | 1948 | if (0 == cchMultiSz) |
@@ -1983,7 +1998,7 @@ extern "C" HRESULT DAPI MultiSzFindSubstring( | |||
1983 | SIZE_T cchProgress = 0; | 1998 | SIZE_T cchProgress = 0; |
1984 | 1999 | ||
1985 | hr = MultiSzLen(pwzMultiSz, &cchMultiSz); | 2000 | hr = MultiSzLen(pwzMultiSz, &cchMultiSz); |
1986 | ExitOnFailure(hr, "failed to get the length of a MULTISZ string"); | 2001 | StrExitOnFailure(hr, "failed to get the length of a MULTISZ string"); |
1987 | 2002 | ||
1988 | // Find the string containing the sub string | 2003 | // Find the string containing the sub string |
1989 | hr = S_OK; | 2004 | hr = S_OK; |
@@ -2049,7 +2064,7 @@ extern "C" HRESULT DAPI MultiSzFindString( | |||
2049 | SIZE_T cchProgress = 0; | 2064 | SIZE_T cchProgress = 0; |
2050 | 2065 | ||
2051 | hr = MultiSzLen(pwzMultiSz, &cchMutliSz); | 2066 | hr = MultiSzLen(pwzMultiSz, &cchMutliSz); |
2052 | ExitOnFailure(hr, "failed to get the length of a MULTISZ string"); | 2067 | StrExitOnFailure(hr, "failed to get the length of a MULTISZ string"); |
2053 | 2068 | ||
2054 | // Find the string | 2069 | // Find the string |
2055 | hr = S_OK; | 2070 | hr = S_OK; |
@@ -2116,7 +2131,7 @@ extern "C" HRESULT DAPI MultiSzRemoveString( | |||
2116 | SIZE_T cchProgress = 0; | 2131 | SIZE_T cchProgress = 0; |
2117 | 2132 | ||
2118 | hr = MultiSzLen(*ppwzMultiSz, &cchMultiSz); | 2133 | hr = MultiSzLen(*ppwzMultiSz, &cchMultiSz); |
2119 | ExitOnFailure(hr, "failed to get the length of a MULTISZ string"); | 2134 | StrExitOnFailure(hr, "failed to get the length of a MULTISZ string"); |
2120 | 2135 | ||
2121 | // Find the index we want to remove | 2136 | // Find the index we want to remove |
2122 | hr = S_OK; | 2137 | hr = S_OK; |
@@ -2159,7 +2174,7 @@ extern "C" HRESULT DAPI MultiSzRemoveString( | |||
2159 | if (cchProgress > cchMultiSz) | 2174 | if (cchProgress > cchMultiSz) |
2160 | { | 2175 | { |
2161 | hr = E_UNEXPECTED; | 2176 | hr = E_UNEXPECTED; |
2162 | ExitOnFailure(hr, "failed to move past the string to be removed from MULTISZ"); | 2177 | StrExitOnFailure(hr, "failed to move past the string to be removed from MULTISZ"); |
2163 | } | 2178 | } |
2164 | 2179 | ||
2165 | // Move on to the next character | 2180 | // Move on to the next character |
@@ -2181,7 +2196,7 @@ extern "C" HRESULT DAPI MultiSzInsertString( | |||
2181 | __deref_inout __nullnullterminated LPWSTR* ppwzMultiSz, | 2196 | __deref_inout __nullnullterminated LPWSTR* ppwzMultiSz, |
2182 | __inout_opt SIZE_T* pcchMultiSz, | 2197 | __inout_opt SIZE_T* pcchMultiSz, |
2183 | __in DWORD_PTR dwIndex, | 2198 | __in DWORD_PTR dwIndex, |
2184 | __in __nullnullterminated LPCWSTR pwzInsert | 2199 | __in_z LPCWSTR pwzInsert |
2185 | ) | 2200 | ) |
2186 | { | 2201 | { |
2187 | Assert(ppwzMultiSz && pwzInsert && *pwzInsert); | 2202 | Assert(ppwzMultiSz && pwzInsert && *pwzInsert); |
@@ -2202,7 +2217,7 @@ extern "C" HRESULT DAPI MultiSzInsertString( | |||
2202 | else | 2217 | else |
2203 | { | 2218 | { |
2204 | hr = MultiSzLen(*ppwzMultiSz, &cchMultiSz); | 2219 | hr = MultiSzLen(*ppwzMultiSz, &cchMultiSz); |
2205 | ExitOnFailure(hr, "failed to get the length of a MULTISZ string"); | 2220 | StrExitOnFailure(hr, "failed to get the length of a MULTISZ string"); |
2206 | } | 2221 | } |
2207 | 2222 | ||
2208 | // Find the index we want to insert at | 2223 | // Find the index we want to insert at |
@@ -2220,7 +2235,7 @@ extern "C" HRESULT DAPI MultiSzInsertString( | |||
2220 | if ((dwCurrentIndex + 1 != dwIndex && L'\0' == *(wz + 1)) || cchProgress >= cchMultiSz) | 2235 | if ((dwCurrentIndex + 1 != dwIndex && L'\0' == *(wz + 1)) || cchProgress >= cchMultiSz) |
2221 | { | 2236 | { |
2222 | hr = HRESULT_FROM_WIN32(ERROR_OBJECT_NOT_FOUND); | 2237 | hr = HRESULT_FROM_WIN32(ERROR_OBJECT_NOT_FOUND); |
2223 | ExitOnRootFailure(hr, "requested to insert into an invalid index: %u in a MULTISZ", dwIndex); | 2238 | StrExitOnRootFailure(hr, "requested to insert into an invalid index: %u in a MULTISZ", dwIndex); |
2224 | } | 2239 | } |
2225 | 2240 | ||
2226 | // Move on to the next string | 2241 | // Move on to the next string |
@@ -2235,7 +2250,7 @@ extern "C" HRESULT DAPI MultiSzInsertString( | |||
2235 | cchResult = cchMultiSz + cchString + 1; | 2250 | cchResult = cchMultiSz + cchString + 1; |
2236 | 2251 | ||
2237 | hr = StrAlloc(&pwzResult, cchResult); | 2252 | hr = StrAlloc(&pwzResult, cchResult); |
2238 | ExitOnFailure(hr, "failed to allocate result string for MULTISZ insert"); | 2253 | StrExitOnFailure(hr, "failed to allocate result string for MULTISZ insert"); |
2239 | 2254 | ||
2240 | // Copy the part before the insert | 2255 | // Copy the part before the insert |
2241 | ::CopyMemory(pwzResult, *ppwzMultiSz, cchProgress * sizeof(WCHAR)); | 2256 | ::CopyMemory(pwzResult, *ppwzMultiSz, cchProgress * sizeof(WCHAR)); |
@@ -2273,7 +2288,7 @@ MultiSzReplaceString - replaces string at the specified index with a new one | |||
2273 | extern "C" HRESULT DAPI MultiSzReplaceString( | 2288 | extern "C" HRESULT DAPI MultiSzReplaceString( |
2274 | __deref_inout __nullnullterminated LPWSTR* ppwzMultiSz, | 2289 | __deref_inout __nullnullterminated LPWSTR* ppwzMultiSz, |
2275 | __in DWORD_PTR dwIndex, | 2290 | __in DWORD_PTR dwIndex, |
2276 | __in __nullnullterminated LPCWSTR pwzString | 2291 | __in_z LPCWSTR pwzString |
2277 | ) | 2292 | ) |
2278 | { | 2293 | { |
2279 | Assert(ppwzMultiSz && pwzString && *pwzString); | 2294 | Assert(ppwzMultiSz && pwzString && *pwzString); |
@@ -2281,10 +2296,10 @@ extern "C" HRESULT DAPI MultiSzReplaceString( | |||
2281 | HRESULT hr = S_OK; | 2296 | HRESULT hr = S_OK; |
2282 | 2297 | ||
2283 | hr = MultiSzRemoveString(ppwzMultiSz, dwIndex); | 2298 | hr = MultiSzRemoveString(ppwzMultiSz, dwIndex); |
2284 | ExitOnFailure(hr, "failed to remove string from MULTISZ at the specified index: %u", dwIndex); | 2299 | StrExitOnFailure(hr, "failed to remove string from MULTISZ at the specified index: %u", dwIndex); |
2285 | 2300 | ||
2286 | hr = MultiSzInsertString(ppwzMultiSz, NULL, dwIndex, pwzString); | 2301 | hr = MultiSzInsertString(ppwzMultiSz, NULL, dwIndex, pwzString); |
2287 | ExitOnFailure(hr, "failed to insert string into MULTISZ at the specified index: %u", dwIndex); | 2302 | StrExitOnFailure(hr, "failed to insert string into MULTISZ at the specified index: %u", dwIndex); |
2288 | 2303 | ||
2289 | LExit: | 2304 | LExit: |
2290 | return hr; | 2305 | return hr; |
@@ -2344,7 +2359,7 @@ extern "C" HRESULT DAPI StrStringToInt16( | |||
2344 | LONGLONG ll = 0; | 2359 | LONGLONG ll = 0; |
2345 | 2360 | ||
2346 | hr = StrStringToInt64(wzIn, cchIn, &ll); | 2361 | hr = StrStringToInt64(wzIn, cchIn, &ll); |
2347 | ExitOnFailure(hr, "Failed to parse int64."); | 2362 | StrExitOnFailure(hr, "Failed to parse int64."); |
2348 | 2363 | ||
2349 | if (SHORT_MAX < ll || SHORT_MIN > ll) | 2364 | if (SHORT_MAX < ll || SHORT_MIN > ll) |
2350 | { | 2365 | { |
@@ -2370,7 +2385,7 @@ extern "C" HRESULT DAPI StrStringToUInt16( | |||
2370 | ULONGLONG ull = 0; | 2385 | ULONGLONG ull = 0; |
2371 | 2386 | ||
2372 | hr = StrStringToUInt64(wzIn, cchIn, &ull); | 2387 | hr = StrStringToUInt64(wzIn, cchIn, &ull); |
2373 | ExitOnFailure(hr, "Failed to parse uint64."); | 2388 | StrExitOnFailure(hr, "Failed to parse uint64."); |
2374 | 2389 | ||
2375 | if (USHORT_MAX < ull) | 2390 | if (USHORT_MAX < ull) |
2376 | { | 2391 | { |
@@ -2396,7 +2411,7 @@ extern "C" HRESULT DAPI StrStringToInt32( | |||
2396 | LONGLONG ll = 0; | 2411 | LONGLONG ll = 0; |
2397 | 2412 | ||
2398 | hr = StrStringToInt64(wzIn, cchIn, &ll); | 2413 | hr = StrStringToInt64(wzIn, cchIn, &ll); |
2399 | ExitOnFailure(hr, "Failed to parse int64."); | 2414 | StrExitOnFailure(hr, "Failed to parse int64."); |
2400 | 2415 | ||
2401 | if (INT_MAX < ll || INT_MIN > ll) | 2416 | if (INT_MAX < ll || INT_MIN > ll) |
2402 | { | 2417 | { |
@@ -2422,7 +2437,7 @@ extern "C" HRESULT DAPI StrStringToUInt32( | |||
2422 | ULONGLONG ull = 0; | 2437 | ULONGLONG ull = 0; |
2423 | 2438 | ||
2424 | hr = StrStringToUInt64(wzIn, cchIn, &ull); | 2439 | hr = StrStringToUInt64(wzIn, cchIn, &ull); |
2425 | ExitOnFailure(hr, "Failed to parse uint64."); | 2440 | StrExitOnFailure(hr, "Failed to parse uint64."); |
2426 | 2441 | ||
2427 | if (UINT_MAX < ull) | 2442 | if (UINT_MAX < ull) |
2428 | { | 2443 | { |
@@ -2607,13 +2622,13 @@ extern "C" HRESULT DAPI StrArrayAllocString( | |||
2607 | UINT cNewStrArray; | 2622 | UINT cNewStrArray; |
2608 | 2623 | ||
2609 | hr = ::UIntAdd(*pcStrArray, 1, &cNewStrArray); | 2624 | hr = ::UIntAdd(*pcStrArray, 1, &cNewStrArray); |
2610 | ExitOnFailure(hr, "Failed to increment the string array element count."); | 2625 | StrExitOnFailure(hr, "Failed to increment the string array element count."); |
2611 | 2626 | ||
2612 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgsczStrArray), cNewStrArray, sizeof(LPWSTR), ARRAY_GROWTH_SIZE); | 2627 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgsczStrArray), cNewStrArray, sizeof(LPWSTR), ARRAY_GROWTH_SIZE); |
2613 | ExitOnFailure(hr, "Failed to allocate memory for the string array."); | 2628 | StrExitOnFailure(hr, "Failed to allocate memory for the string array."); |
2614 | 2629 | ||
2615 | hr = StrAllocString(&(*prgsczStrArray)[*pcStrArray], wzSource, cchSource); | 2630 | hr = StrAllocString(&(*prgsczStrArray)[*pcStrArray], wzSource, cchSource); |
2616 | ExitOnFailure(hr, "Failed to allocate and assign the string."); | 2631 | StrExitOnFailure(hr, "Failed to allocate and assign the string."); |
2617 | 2632 | ||
2618 | *pcStrArray = cNewStrArray; | 2633 | *pcStrArray = cNewStrArray; |
2619 | 2634 | ||
@@ -2639,12 +2654,12 @@ extern "C" HRESULT DAPI StrArrayFree( | |||
2639 | if (NULL != rgsczStrArray[i]) | 2654 | if (NULL != rgsczStrArray[i]) |
2640 | { | 2655 | { |
2641 | hr = StrFree(rgsczStrArray[i]); | 2656 | hr = StrFree(rgsczStrArray[i]); |
2642 | ExitOnFailure(hr, "Failed to free the string at index %u.", i); | 2657 | StrExitOnFailure(hr, "Failed to free the string at index %u.", i); |
2643 | } | 2658 | } |
2644 | } | 2659 | } |
2645 | 2660 | ||
2646 | hr = MemFree(rgsczStrArray); | 2661 | hr = MemFree(rgsczStrArray); |
2647 | ExitOnFailure(hr, "Failed to free memory for the string array."); | 2662 | StrExitOnFailure(hr, "Failed to free memory for the string array."); |
2648 | 2663 | ||
2649 | LExit: | 2664 | LExit: |
2650 | return hr; | 2665 | return hr; |
@@ -2667,12 +2682,12 @@ extern "C" HRESULT DAPI StrSplitAllocArray( | |||
2667 | 2682 | ||
2668 | // Copy wzSource so it is not modified. | 2683 | // Copy wzSource so it is not modified. |
2669 | hr = StrAllocString(&sczCopy, wzSource, 0); | 2684 | hr = StrAllocString(&sczCopy, wzSource, 0); |
2670 | ExitOnFailure(hr, "Failed to copy the source string."); | 2685 | StrExitOnFailure(hr, "Failed to copy the source string."); |
2671 | 2686 | ||
2672 | for (LPCWSTR wzToken = ::wcstok_s(sczCopy, wzDelim, &wzContext); wzToken; wzToken = ::wcstok_s(NULL, wzDelim, &wzContext)) | 2687 | for (LPCWSTR wzToken = ::wcstok_s(sczCopy, wzDelim, &wzContext); wzToken; wzToken = ::wcstok_s(NULL, wzDelim, &wzContext)) |
2673 | { | 2688 | { |
2674 | hr = StrArrayAllocString(prgsczStrArray, pcStrArray, wzToken, 0); | 2689 | hr = StrArrayAllocString(prgsczStrArray, pcStrArray, wzToken, 0); |
2675 | ExitOnFailure(hr, "Failed to add the string to the string array."); | 2690 | StrExitOnFailure(hr, "Failed to add the string to the string array."); |
2676 | } | 2691 | } |
2677 | 2692 | ||
2678 | LExit: | 2693 | LExit: |
@@ -2696,20 +2711,20 @@ static HRESULT StrAllocStringMapInvariant( | |||
2696 | HRESULT hr = S_OK; | 2711 | HRESULT hr = S_OK; |
2697 | 2712 | ||
2698 | hr = StrAllocString(pscz, wzSource, cchSource); | 2713 | hr = StrAllocString(pscz, wzSource, cchSource); |
2699 | ExitOnFailure(hr, "Failed to allocate a copy of the source string."); | 2714 | StrExitOnFailure(hr, "Failed to allocate a copy of the source string."); |
2700 | 2715 | ||
2701 | if (0 == cchSource) | 2716 | if (0 == cchSource) |
2702 | { | 2717 | { |
2703 | // Need the actual string size for LCMapString. This includes the null-terminator | 2718 | // Need the actual string size for LCMapString. This includes the null-terminator |
2704 | // but LCMapString doesn't care either way. | 2719 | // but LCMapString doesn't care either way. |
2705 | hr = ::StringCchLengthW(*pscz, INT_MAX, reinterpret_cast<size_t*>(&cchSource)); | 2720 | hr = ::StringCchLengthW(*pscz, INT_MAX, reinterpret_cast<size_t*>(&cchSource)); |
2706 | ExitOnFailure(hr, "Failed to get the length of the string."); | 2721 | StrExitOnFailure(hr, "Failed to get the length of the string."); |
2707 | } | 2722 | } |
2708 | 2723 | ||
2709 | // Convert the copy of the string to upper or lower case in-place. | 2724 | // Convert the copy of the string to upper or lower case in-place. |
2710 | if (0 == ::LCMapStringW(LOCALE_INVARIANT, dwMapFlags, *pscz, cchSource, *pscz, cchSource)) | 2725 | if (0 == ::LCMapStringW(LOCALE_INVARIANT, dwMapFlags, *pscz, cchSource, *pscz, cchSource)) |
2711 | { | 2726 | { |
2712 | ExitWithLastError(hr, "Failed to convert the string case."); | 2727 | StrExitWithLastError(hr, "Failed to convert the string case."); |
2713 | } | 2728 | } |
2714 | 2729 | ||
2715 | LExit: | 2730 | LExit: |
@@ -2734,7 +2749,7 @@ extern "C" DAPI_(HRESULT) StrSecureZeroString( | |||
2734 | if (-1 == cch) | 2749 | if (-1 == cch) |
2735 | { | 2750 | { |
2736 | hr = E_INVALIDARG; | 2751 | hr = E_INVALIDARG; |
2737 | ExitOnFailure(hr, "Failed to get size of string"); | 2752 | StrExitOnFailure(hr, "Failed to get size of string"); |
2738 | } | 2753 | } |
2739 | else | 2754 | else |
2740 | { | 2755 | { |
diff --git a/src/dutil/svcutil.cpp b/src/dutil/svcutil.cpp index 9da2b5b3..1a39bfee 100644 --- a/src/dutil/svcutil.cpp +++ b/src/dutil/svcutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define SvcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__) | ||
8 | #define SvcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__) | ||
9 | #define SvcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__) | ||
10 | #define SvcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__) | ||
11 | #define SvcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__) | ||
12 | #define SvcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__) | ||
13 | #define SvcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_SVCUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define SvcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_SVCUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define SvcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_SVCUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define SvcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_SVCUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define SvcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_SVCUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define SvcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_SVCUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | /******************************************************************** | 20 | /******************************************************************** |
6 | SvcQueryConfig - queries the configuration of a service | 21 | SvcQueryConfig - queries the configuration of a service |
7 | 22 | ||
@@ -21,16 +36,16 @@ extern "C" HRESULT DAPI SvcQueryConfig( | |||
21 | if (ERROR_INSUFFICIENT_BUFFER == er) | 36 | if (ERROR_INSUFFICIENT_BUFFER == er) |
22 | { | 37 | { |
23 | pConfig = static_cast<QUERY_SERVICE_CONFIGW*>(MemAlloc(cbConfig, TRUE)); | 38 | pConfig = static_cast<QUERY_SERVICE_CONFIGW*>(MemAlloc(cbConfig, TRUE)); |
24 | ExitOnNull(pConfig, hr, E_OUTOFMEMORY, "Failed to allocate memory to get configuration."); | 39 | SvcExitOnNull(pConfig, hr, E_OUTOFMEMORY, "Failed to allocate memory to get configuration."); |
25 | 40 | ||
26 | if (!::QueryServiceConfigW(sch, pConfig, cbConfig, &cbConfig)) | 41 | if (!::QueryServiceConfigW(sch, pConfig, cbConfig, &cbConfig)) |
27 | { | 42 | { |
28 | ExitWithLastError(hr, "Failed to read service configuration."); | 43 | SvcExitWithLastError(hr, "Failed to read service configuration."); |
29 | } | 44 | } |
30 | } | 45 | } |
31 | else | 46 | else |
32 | { | 47 | { |
33 | ExitOnWin32Error(er, hr, "Failed to query service configuration."); | 48 | SvcExitOnWin32Error(er, hr, "Failed to query service configuration."); |
34 | } | 49 | } |
35 | } | 50 | } |
36 | 51 | ||
diff --git a/src/dutil/thmutil.cpp b/src/dutil/thmutil.cpp index 9b9bf15e..d87e997d 100644 --- a/src/dutil/thmutil.cpp +++ b/src/dutil/thmutil.cpp | |||
@@ -693,7 +693,7 @@ DAPI_(HRESULT) ThemeCreateParentWindow( | |||
693 | } | 693 | } |
694 | 694 | ||
695 | LExit: | 695 | LExit: |
696 | MemFree(pMonitorContext); | 696 | ReleaseMem(pMonitorContext); |
697 | 697 | ||
698 | return hr; | 698 | return hr; |
699 | } | 699 | } |
@@ -1514,7 +1514,7 @@ LExit: | |||
1514 | DAPI_(HRESULT) ThemeGetTextControl( | 1514 | DAPI_(HRESULT) ThemeGetTextControl( |
1515 | __in const THEME* pTheme, | 1515 | __in const THEME* pTheme, |
1516 | __in DWORD dwControl, | 1516 | __in DWORD dwControl, |
1517 | __out_z LPWSTR* psczText | 1517 | __inout_z LPWSTR* psczText |
1518 | ) | 1518 | ) |
1519 | { | 1519 | { |
1520 | HRESULT hr = S_OK; | 1520 | HRESULT hr = S_OK; |
@@ -1729,6 +1729,7 @@ static HRESULT ParseImage( | |||
1729 | LPWSTR sczImageFile = NULL; | 1729 | LPWSTR sczImageFile = NULL; |
1730 | int iResourceId = 0; | 1730 | int iResourceId = 0; |
1731 | Gdiplus::Bitmap* pBitmap = NULL; | 1731 | Gdiplus::Bitmap* pBitmap = NULL; |
1732 | *phImage = NULL; | ||
1732 | 1733 | ||
1733 | hr = XmlGetAttribute(pElement, L"ImageResource", &bstr); | 1734 | hr = XmlGetAttribute(pElement, L"ImageResource", &bstr); |
1734 | ThmExitOnFailure(hr, "Failed to get image resource attribute."); | 1735 | ThmExitOnFailure(hr, "Failed to get image resource attribute."); |
@@ -1801,6 +1802,7 @@ static HRESULT ParseIcon( | |||
1801 | BSTR bstr = NULL; | 1802 | BSTR bstr = NULL; |
1802 | LPWSTR sczImageFile = NULL; | 1803 | LPWSTR sczImageFile = NULL; |
1803 | int iResourceId = 0; | 1804 | int iResourceId = 0; |
1805 | *phIcon = NULL; | ||
1804 | 1806 | ||
1805 | hr = XmlGetAttribute(pElement, L"IconResource", &bstr); | 1807 | hr = XmlGetAttribute(pElement, L"IconResource", &bstr); |
1806 | ThmExitOnFailure(hr, "Failed to get icon resource attribute."); | 1808 | ThmExitOnFailure(hr, "Failed to get icon resource attribute."); |
@@ -4720,7 +4722,7 @@ static HRESULT ShowControl( | |||
4720 | 4722 | ||
4721 | hr = S_OK; | 4723 | hr = S_OK; |
4722 | 4724 | ||
4723 | Button_SetCheck(hWnd, (!sczText && !pControl->sczValue) || CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, sczText, -1, pControl->sczValue, -1)); | 4725 | Button_SetCheck(hWnd, (!sczText && !pControl->sczValue) || (sczText && CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, sczText, -1, pControl->sczValue, -1))); |
4724 | } | 4726 | } |
4725 | } | 4727 | } |
4726 | 4728 | ||
diff --git a/src/dutil/timeutil.cpp b/src/dutil/timeutil.cpp index dacb2660..b7953c94 100644 --- a/src/dutil/timeutil.cpp +++ b/src/dutil/timeutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define TimeExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__) | ||
8 | #define TimeExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__) | ||
9 | #define TimeExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__) | ||
10 | #define TimeExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__) | ||
11 | #define TimeExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__) | ||
12 | #define TimeExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__) | ||
13 | #define TimeExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_TIMEUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define TimeExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_TIMEUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define TimeExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_TIMEUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define TimeExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_TIMEUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define TimeExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_TIMEUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define TimeExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_TIMEUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | const LPCWSTR DAY_OF_WEEK[] = { L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat" }; | 20 | const LPCWSTR DAY_OF_WEEK[] = { L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat" }; |
6 | const LPCWSTR MONTH_OF_YEAR[] = { L"None", L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec" }; | 21 | const LPCWSTR MONTH_OF_YEAR[] = { L"None", L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec" }; |
7 | enum TIME_PARSER { DayOfWeek, DayOfMonth, MonthOfYear, Year, Hours, Minutes, Seconds, TimeZone }; | 22 | enum TIME_PARSER { DayOfWeek, DayOfMonth, MonthOfYear, Year, Hours, Minutes, Seconds, TimeZone }; |
@@ -39,7 +54,7 @@ extern "C" HRESULT DAPI TimeFromString( | |||
39 | LPWSTR pwzEnd = NULL; | 54 | LPWSTR pwzEnd = NULL; |
40 | 55 | ||
41 | hr = StrAllocString(&pwzTime, wzTime, 0); | 56 | hr = StrAllocString(&pwzTime, wzTime, 0); |
42 | ExitOnFailure(hr, "Failed to copy time."); | 57 | TimeExitOnFailure(hr, "Failed to copy time."); |
43 | 58 | ||
44 | pwzStart = pwzEnd = pwzTime; | 59 | pwzStart = pwzEnd = pwzTime; |
45 | while (pwzEnd && *pwzEnd) | 60 | while (pwzEnd && *pwzEnd) |
@@ -58,7 +73,7 @@ extern "C" HRESULT DAPI TimeFromString( | |||
58 | { | 73 | { |
59 | case DayOfWeek: | 74 | case DayOfWeek: |
60 | hr = DayFromString(pwzStart, &sysTime.wDayOfWeek); | 75 | hr = DayFromString(pwzStart, &sysTime.wDayOfWeek); |
61 | ExitOnFailure(hr, "Failed to convert string to day: %ls", pwzStart); | 76 | TimeExitOnFailure(hr, "Failed to convert string to day: %ls", pwzStart); |
62 | break; | 77 | break; |
63 | 78 | ||
64 | case DayOfMonth: | 79 | case DayOfMonth: |
@@ -67,7 +82,7 @@ extern "C" HRESULT DAPI TimeFromString( | |||
67 | 82 | ||
68 | case MonthOfYear: | 83 | case MonthOfYear: |
69 | hr = MonthFromString(pwzStart, &sysTime.wMonth); | 84 | hr = MonthFromString(pwzStart, &sysTime.wMonth); |
70 | ExitOnFailure(hr, "Failed to convert to month: %ls", pwzStart); | 85 | TimeExitOnFailure(hr, "Failed to convert to month: %ls", pwzStart); |
71 | break; | 86 | break; |
72 | 87 | ||
73 | case Year: | 88 | case Year: |
@@ -104,7 +119,7 @@ extern "C" HRESULT DAPI TimeFromString( | |||
104 | 119 | ||
105 | if (!::SystemTimeToFileTime(&sysTime, pFileTime)) | 120 | if (!::SystemTimeToFileTime(&sysTime, pFileTime)) |
106 | { | 121 | { |
107 | ExitWithLastError(hr, "Failed to convert system time to file time."); | 122 | TimeExitWithLastError(hr, "Failed to convert system time to file time."); |
108 | } | 123 | } |
109 | 124 | ||
110 | LExit: | 125 | LExit: |
@@ -134,7 +149,7 @@ extern "C" HRESULT DAPI TimeFromString3339( | |||
134 | LPWSTR pwzEnd = NULL; | 149 | LPWSTR pwzEnd = NULL; |
135 | 150 | ||
136 | hr = StrAllocString(&pwzTime, wzTime, 0); | 151 | hr = StrAllocString(&pwzTime, wzTime, 0); |
137 | ExitOnFailure(hr, "Failed to copy time."); | 152 | TimeExitOnFailure(hr, "Failed to copy time."); |
138 | 153 | ||
139 | pwzStart = pwzEnd = pwzTime; | 154 | pwzStart = pwzEnd = pwzTime; |
140 | while (pwzEnd && *pwzEnd) | 155 | while (pwzEnd && *pwzEnd) |
@@ -188,7 +203,7 @@ extern "C" HRESULT DAPI TimeFromString3339( | |||
188 | 203 | ||
189 | if (!::SystemTimeToFileTime(&sysTime, pFileTime)) | 204 | if (!::SystemTimeToFileTime(&sysTime, pFileTime)) |
190 | { | 205 | { |
191 | ExitWithLastError(hr, "Failed to convert system time to file time."); | 206 | TimeExitWithLastError(hr, "Failed to convert system time to file time."); |
192 | } | 207 | } |
193 | 208 | ||
194 | LExit: | 209 | LExit: |
@@ -291,29 +306,29 @@ HRESULT DAPI TimeSystemToDateTimeString( | |||
291 | iLenDate = ::GetDateFormatW(locale, 0, pst, DATE_FORMAT, NULL, 0); | 306 | iLenDate = ::GetDateFormatW(locale, 0, pst, DATE_FORMAT, NULL, 0); |
292 | if (0 >= iLenDate) | 307 | if (0 >= iLenDate) |
293 | { | 308 | { |
294 | ExitWithLastError(hr, "Failed to get date format with NULL"); | 309 | TimeExitWithLastError(hr, "Failed to get date format with NULL"); |
295 | } | 310 | } |
296 | 311 | ||
297 | iLenTime = ::GetTimeFormatW(locale, 0, pst, TIME_FORMAT, NULL, 0); | 312 | iLenTime = ::GetTimeFormatW(locale, 0, pst, TIME_FORMAT, NULL, 0); |
298 | if (0 >= iLenTime) | 313 | if (0 >= iLenTime) |
299 | { | 314 | { |
300 | ExitWithLastError(hr, "Failed to get time format with NULL"); | 315 | TimeExitWithLastError(hr, "Failed to get time format with NULL"); |
301 | } | 316 | } |
302 | 317 | ||
303 | // Between both lengths we account for 2 null terminators, and only need one, so we subtract one | 318 | // Between both lengths we account for 2 null terminators, and only need one, so we subtract one |
304 | hr = StrAlloc(ppwz, iLenDate + iLenTime - 1); | 319 | hr = StrAlloc(ppwz, iLenDate + iLenTime - 1); |
305 | ExitOnFailure(hr, "Failed to allocate string"); | 320 | TimeExitOnFailure(hr, "Failed to allocate string"); |
306 | 321 | ||
307 | if (!::GetDateFormatW(locale, 0, pst, DATE_FORMAT, *ppwz, iLenDate)) | 322 | if (!::GetDateFormatW(locale, 0, pst, DATE_FORMAT, *ppwz, iLenDate)) |
308 | { | 323 | { |
309 | ExitWithLastError(hr, "Failed to get date format with buffer"); | 324 | TimeExitWithLastError(hr, "Failed to get date format with buffer"); |
310 | } | 325 | } |
311 | // Space to separate them | 326 | // Space to separate them |
312 | (*ppwz)[iLenDate - 1] = ' '; | 327 | (*ppwz)[iLenDate - 1] = ' '; |
313 | 328 | ||
314 | if (!::GetTimeFormatW(locale, 0, pst, TIME_FORMAT, (*ppwz) + iLenDate - 1, iLenTime)) | 329 | if (!::GetTimeFormatW(locale, 0, pst, TIME_FORMAT, (*ppwz) + iLenDate - 1, iLenTime)) |
315 | { | 330 | { |
316 | ExitWithLastError(hr, "Failed to get time format with buffer"); | 331 | TimeExitWithLastError(hr, "Failed to get time format with buffer"); |
317 | } | 332 | } |
318 | 333 | ||
319 | LExit: | 334 | LExit: |
diff --git a/src/dutil/uncutil.cpp b/src/dutil/uncutil.cpp index 6deb43bd..415ea198 100644 --- a/src/dutil/uncutil.cpp +++ b/src/dutil/uncutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define UncExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__) | ||
8 | #define UncExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__) | ||
9 | #define UncExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__) | ||
10 | #define UncExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__) | ||
11 | #define UncExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__) | ||
12 | #define UncExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_UNCUTIL, x, s, __VA_ARGS__) | ||
13 | #define UncExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_UNCUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define UncExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_UNCUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define UncExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_UNCUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define UncExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_UNCUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define UncExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_UNCUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define UncExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_UNCUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | DAPI_(HRESULT) UncConvertFromMountedDrive( | 20 | DAPI_(HRESULT) UncConvertFromMountedDrive( |
6 | __inout LPWSTR *psczUNCPath, | 21 | __inout LPWSTR *psczUNCPath, |
7 | __in LPCWSTR sczMountedDrivePath | 22 | __in LPCWSTR sczMountedDrivePath |
@@ -14,7 +29,7 @@ DAPI_(HRESULT) UncConvertFromMountedDrive( | |||
14 | 29 | ||
15 | // Only copy drive letter and colon | 30 | // Only copy drive letter and colon |
16 | hr = StrAllocString(&sczDrive, sczMountedDrivePath, 2); | 31 | hr = StrAllocString(&sczDrive, sczMountedDrivePath, 2); |
17 | ExitOnFailure(hr, "Failed to copy drive"); | 32 | UncExitOnFailure(hr, "Failed to copy drive"); |
18 | 33 | ||
19 | // ERROR_NOT_CONNECTED means it's not a mapped drive | 34 | // ERROR_NOT_CONNECTED means it's not a mapped drive |
20 | er = ::WNetGetConnectionW(sczDrive, NULL, &dwLength); | 35 | er = ::WNetGetConnectionW(sczDrive, NULL, &dwLength); |
@@ -23,7 +38,7 @@ DAPI_(HRESULT) UncConvertFromMountedDrive( | |||
23 | er = ERROR_SUCCESS; | 38 | er = ERROR_SUCCESS; |
24 | 39 | ||
25 | hr = StrAlloc(psczUNCPath, dwLength); | 40 | hr = StrAlloc(psczUNCPath, dwLength); |
26 | ExitOnFailure(hr, "Failed to allocate string to get raw UNC path of length %u", dwLength); | 41 | UncExitOnFailure(hr, "Failed to allocate string to get raw UNC path of length %u", dwLength); |
27 | 42 | ||
28 | er = ::WNetGetConnectionW(sczDrive, *psczUNCPath, &dwLength); | 43 | er = ::WNetGetConnectionW(sczDrive, *psczUNCPath, &dwLength); |
29 | if (ERROR_CONNECTION_UNAVAIL == er) | 44 | if (ERROR_CONNECTION_UNAVAIL == er) |
@@ -31,11 +46,11 @@ DAPI_(HRESULT) UncConvertFromMountedDrive( | |||
31 | // This means the drive is remembered but not currently connected, this can mean the location is accessible via UNC path but not via mounted drive path | 46 | // This means the drive is remembered but not currently connected, this can mean the location is accessible via UNC path but not via mounted drive path |
32 | er = ERROR_SUCCESS; | 47 | er = ERROR_SUCCESS; |
33 | } | 48 | } |
34 | ExitOnWin32Error(er, hr, "::WNetGetConnectionW() failed with buffer provided on drive %ls", sczDrive); | 49 | UncExitOnWin32Error(er, hr, "::WNetGetConnectionW() failed with buffer provided on drive %ls", sczDrive); |
35 | 50 | ||
36 | // Skip drive letter and colon | 51 | // Skip drive letter and colon |
37 | hr = StrAllocConcat(psczUNCPath, sczMountedDrivePath + 2, 0); | 52 | hr = StrAllocConcat(psczUNCPath, sczMountedDrivePath + 2, 0); |
38 | ExitOnFailure(hr, "Failed to copy rest of database path"); | 53 | UncExitOnFailure(hr, "Failed to copy rest of database path"); |
39 | } | 54 | } |
40 | else | 55 | else |
41 | { | 56 | { |
@@ -44,7 +59,7 @@ DAPI_(HRESULT) UncConvertFromMountedDrive( | |||
44 | er = ERROR_NO_DATA; | 59 | er = ERROR_NO_DATA; |
45 | } | 60 | } |
46 | 61 | ||
47 | ExitOnWin32Error(er, hr, "::WNetGetConnectionW() failed on drive %ls", sczDrive); | 62 | UncExitOnWin32Error(er, hr, "::WNetGetConnectionW() failed on drive %ls", sczDrive); |
48 | } | 63 | } |
49 | 64 | ||
50 | LExit: | 65 | LExit: |
diff --git a/src/dutil/uriutil.cpp b/src/dutil/uriutil.cpp index fc192b3f..7913c22e 100644 --- a/src/dutil/uriutil.cpp +++ b/src/dutil/uriutil.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | 5 | ||
6 | // Exit macros | ||
7 | #define UriExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_URIUTIL, x, s, __VA_ARGS__) | ||
8 | #define UriExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_URIUTIL, x, s, __VA_ARGS__) | ||
9 | #define UriExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_URIUTIL, x, s, __VA_ARGS__) | ||
10 | #define UriExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_URIUTIL, x, s, __VA_ARGS__) | ||
11 | #define UriExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_URIUTIL, x, s, __VA_ARGS__) | ||
12 | #define UriExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_URIUTIL, x, s, __VA_ARGS__) | ||
13 | #define UriExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_URIUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define UriExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_URIUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define UriExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_URIUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define UriExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_URIUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define UriExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_URIUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define UriExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_URIUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
6 | // | 21 | // |
7 | // UriCanonicalize - canonicalizes a URI. | 22 | // UriCanonicalize - canonicalizes a URI. |
8 | // | 23 | // |
@@ -16,11 +31,11 @@ extern "C" HRESULT DAPI UriCanonicalize( | |||
16 | 31 | ||
17 | if (!::InternetCanonicalizeUrlW(*psczUri, wz, &cch, ICU_DECODE)) | 32 | if (!::InternetCanonicalizeUrlW(*psczUri, wz, &cch, ICU_DECODE)) |
18 | { | 33 | { |
19 | ExitWithLastError(hr, "Failed to canonicalize URI."); | 34 | UriExitWithLastError(hr, "Failed to canonicalize URI."); |
20 | } | 35 | } |
21 | 36 | ||
22 | hr = StrAllocString(psczUri, wz, cch); | 37 | hr = StrAllocString(psczUri, wz, cch); |
23 | ExitOnFailure(hr, "Failed copy canonicalized URI."); | 38 | UriExitOnFailure(hr, "Failed copy canonicalized URI."); |
24 | 39 | ||
25 | LExit: | 40 | LExit: |
26 | return hr; | 41 | return hr; |
@@ -83,7 +98,7 @@ extern "C" HRESULT DAPI UriCrack( | |||
83 | 98 | ||
84 | if (!::InternetCrackUrlW(wzUri, 0, ICU_DECODE | ICU_ESCAPE, &components)) | 99 | if (!::InternetCrackUrlW(wzUri, 0, ICU_DECODE | ICU_ESCAPE, &components)) |
85 | { | 100 | { |
86 | ExitWithLastError(hr, "Failed to crack URI."); | 101 | UriExitWithLastError(hr, "Failed to crack URI."); |
87 | } | 102 | } |
88 | 103 | ||
89 | if (pScheme) | 104 | if (pScheme) |
@@ -94,7 +109,7 @@ extern "C" HRESULT DAPI UriCrack( | |||
94 | if (psczHostName) | 109 | if (psczHostName) |
95 | { | 110 | { |
96 | hr = StrAllocString(psczHostName, components.lpszHostName, components.dwHostNameLength); | 111 | hr = StrAllocString(psczHostName, components.lpszHostName, components.dwHostNameLength); |
97 | ExitOnFailure(hr, "Failed to copy host name."); | 112 | UriExitOnFailure(hr, "Failed to copy host name."); |
98 | } | 113 | } |
99 | 114 | ||
100 | if (pPort) | 115 | if (pPort) |
@@ -105,25 +120,25 @@ extern "C" HRESULT DAPI UriCrack( | |||
105 | if (psczUser) | 120 | if (psczUser) |
106 | { | 121 | { |
107 | hr = StrAllocString(psczUser, components.lpszUserName, components.dwUserNameLength); | 122 | hr = StrAllocString(psczUser, components.lpszUserName, components.dwUserNameLength); |
108 | ExitOnFailure(hr, "Failed to copy user name."); | 123 | UriExitOnFailure(hr, "Failed to copy user name."); |
109 | } | 124 | } |
110 | 125 | ||
111 | if (psczPassword) | 126 | if (psczPassword) |
112 | { | 127 | { |
113 | hr = StrAllocString(psczPassword, components.lpszPassword, components.dwPasswordLength); | 128 | hr = StrAllocString(psczPassword, components.lpszPassword, components.dwPasswordLength); |
114 | ExitOnFailure(hr, "Failed to copy password."); | 129 | UriExitOnFailure(hr, "Failed to copy password."); |
115 | } | 130 | } |
116 | 131 | ||
117 | if (psczPath) | 132 | if (psczPath) |
118 | { | 133 | { |
119 | hr = StrAllocString(psczPath, components.lpszUrlPath, components.dwUrlPathLength); | 134 | hr = StrAllocString(psczPath, components.lpszUrlPath, components.dwUrlPathLength); |
120 | ExitOnFailure(hr, "Failed to copy path."); | 135 | UriExitOnFailure(hr, "Failed to copy path."); |
121 | } | 136 | } |
122 | 137 | ||
123 | if (psczQueryString) | 138 | if (psczQueryString) |
124 | { | 139 | { |
125 | hr = StrAllocString(psczQueryString, components.lpszExtraInfo, components.dwExtraInfoLength); | 140 | hr = StrAllocString(psczQueryString, components.lpszExtraInfo, components.dwExtraInfoLength); |
126 | ExitOnFailure(hr, "Failed to copy query string."); | 141 | UriExitOnFailure(hr, "Failed to copy query string."); |
127 | } | 142 | } |
128 | 143 | ||
129 | LExit: | 144 | LExit: |
@@ -142,7 +157,7 @@ extern "C" HRESULT DAPI UriCrackEx( | |||
142 | HRESULT hr = S_OK; | 157 | HRESULT hr = S_OK; |
143 | 158 | ||
144 | hr = UriCrack(wzUri, &pUriInfo->scheme, &pUriInfo->sczHostName, &pUriInfo->port, &pUriInfo->sczUser, &pUriInfo->sczPassword, &pUriInfo->sczPath, &pUriInfo->sczQueryString); | 159 | hr = UriCrack(wzUri, &pUriInfo->scheme, &pUriInfo->sczHostName, &pUriInfo->port, &pUriInfo->sczUser, &pUriInfo->sczPassword, &pUriInfo->sczPath, &pUriInfo->sczQueryString); |
145 | ExitOnFailure(hr, "Failed to crack URI."); | 160 | UriExitOnFailure(hr, "Failed to crack URI."); |
146 | 161 | ||
147 | LExit: | 162 | LExit: |
148 | return hr; | 163 | return hr; |
@@ -195,11 +210,11 @@ extern "C" HRESULT DAPI UriCreate( | |||
195 | 210 | ||
196 | if (!::InternetCreateUrlW(&components, ICU_ESCAPE, wz, &cch)) | 211 | if (!::InternetCreateUrlW(&components, ICU_ESCAPE, wz, &cch)) |
197 | { | 212 | { |
198 | ExitWithLastError(hr, "Failed to create URI."); | 213 | UriExitWithLastError(hr, "Failed to create URI."); |
199 | } | 214 | } |
200 | 215 | ||
201 | hr = StrAllocString(psczUri, wz, cch); | 216 | hr = StrAllocString(psczUri, wz, cch); |
202 | ExitOnFailure(hr, "Failed copy created URI."); | 217 | UriExitOnFailure(hr, "Failed copy created URI."); |
203 | 218 | ||
204 | LExit: | 219 | LExit: |
205 | return hr; | 220 | return hr; |
@@ -227,13 +242,13 @@ extern "C" HRESULT DAPI UriGetServerAndResource( | |||
227 | LPWSTR sczQueryString = NULL; | 242 | LPWSTR sczQueryString = NULL; |
228 | 243 | ||
229 | hr = UriCrack(wzUri, &scheme, &sczHostName, &port, &sczUser, &sczPassword, &sczPath, &sczQueryString); | 244 | hr = UriCrack(wzUri, &scheme, &sczHostName, &port, &sczUser, &sczPassword, &sczPath, &sczQueryString); |
230 | ExitOnFailure(hr, "Failed to crack URI."); | 245 | UriExitOnFailure(hr, "Failed to crack URI."); |
231 | 246 | ||
232 | hr = UriCreate(psczServer, scheme, sczHostName, port, sczUser, sczPassword, NULL, NULL); | 247 | hr = UriCreate(psczServer, scheme, sczHostName, port, sczUser, sczPassword, NULL, NULL); |
233 | ExitOnFailure(hr, "Failed to allocate server URI."); | 248 | UriExitOnFailure(hr, "Failed to allocate server URI."); |
234 | 249 | ||
235 | hr = UriCreate(psczResource, INTERNET_SCHEME_UNKNOWN, NULL, INTERNET_INVALID_PORT_NUMBER, NULL, NULL, sczPath, sczQueryString); | 250 | hr = UriCreate(psczResource, INTERNET_SCHEME_UNKNOWN, NULL, INTERNET_INVALID_PORT_NUMBER, NULL, NULL, sczPath, sczQueryString); |
236 | ExitOnFailure(hr, "Failed to allocate resource URI."); | 251 | UriExitOnFailure(hr, "Failed to allocate resource URI."); |
237 | 252 | ||
238 | LExit: | 253 | LExit: |
239 | ReleaseStr(sczQueryString); | 254 | ReleaseStr(sczQueryString); |
@@ -265,13 +280,13 @@ extern "C" HRESULT DAPI UriFile( | |||
265 | 280 | ||
266 | if (!::InternetCrackUrlW(wzUri, 0, ICU_DECODE | ICU_ESCAPE, &uc)) | 281 | if (!::InternetCrackUrlW(wzUri, 0, ICU_DECODE | ICU_ESCAPE, &uc)) |
267 | { | 282 | { |
268 | ExitWithLastError(hr, "Failed to crack URI."); | 283 | UriExitWithLastError(hr, "Failed to crack URI."); |
269 | } | 284 | } |
270 | 285 | ||
271 | // Copy only the file name. Fortunately, PathFile() understands that | 286 | // Copy only the file name. Fortunately, PathFile() understands that |
272 | // forward slashes can be directory separators like backslashes. | 287 | // forward slashes can be directory separators like backslashes. |
273 | hr = StrAllocString(psczFile, PathFile(wz), 0); | 288 | hr = StrAllocString(psczFile, PathFile(wz), 0); |
274 | ExitOnFailure(hr, "Failed to copy file name"); | 289 | UriExitOnFailure(hr, "Failed to copy file name"); |
275 | 290 | ||
276 | LExit: | 291 | LExit: |
277 | return hr; | 292 | return hr; |
@@ -367,7 +382,7 @@ extern "C" HRESULT DAPI UriRoot( | |||
367 | LPCWSTR pwcSlash = NULL; | 382 | LPCWSTR pwcSlash = NULL; |
368 | 383 | ||
369 | hr = UriProtocol(wzUri, &protocol); | 384 | hr = UriProtocol(wzUri, &protocol); |
370 | ExitOnFailure(hr, "Invalid URI."); | 385 | UriExitOnFailure(hr, "Invalid URI."); |
371 | 386 | ||
372 | switch (protocol) | 387 | switch (protocol) |
373 | { | 388 | { |
@@ -377,7 +392,7 @@ extern "C" HRESULT DAPI UriRoot( | |||
377 | if (((L'a' <= wzUri[8] && L'z' >= wzUri[8]) || (L'A' <= wzUri[8] && L'Z' >= wzUri[8])) && L':' == wzUri[9]) | 392 | if (((L'a' <= wzUri[8] && L'z' >= wzUri[8]) || (L'A' <= wzUri[8] && L'Z' >= wzUri[8])) && L':' == wzUri[9]) |
378 | { | 393 | { |
379 | hr = StrAlloc(ppwzRoot, 4); | 394 | hr = StrAlloc(ppwzRoot, 4); |
380 | ExitOnFailure(hr, "Failed to allocate string for root of URI."); | 395 | UriExitOnFailure(hr, "Failed to allocate string for root of URI."); |
381 | *ppwzRoot[0] = wzUri[8]; | 396 | *ppwzRoot[0] = wzUri[8]; |
382 | *ppwzRoot[1] = L':'; | 397 | *ppwzRoot[1] = L':'; |
383 | *ppwzRoot[2] = L'\\'; | 398 | *ppwzRoot[2] = L'\\'; |
@@ -386,7 +401,7 @@ extern "C" HRESULT DAPI UriRoot( | |||
386 | else | 401 | else |
387 | { | 402 | { |
388 | hr = E_INVALIDARG; | 403 | hr = E_INVALIDARG; |
389 | ExitOnFailure(hr, "Invalid file path in URI."); | 404 | UriExitOnFailure(hr, "Invalid file path in URI."); |
390 | } | 405 | } |
391 | } | 406 | } |
392 | else // UNC share | 407 | else // UNC share |
@@ -395,23 +410,23 @@ extern "C" HRESULT DAPI UriRoot( | |||
395 | if (!pwcSlash) | 410 | if (!pwcSlash) |
396 | { | 411 | { |
397 | hr = E_INVALIDARG; | 412 | hr = E_INVALIDARG; |
398 | ExitOnFailure(hr, "Invalid server name in URI."); | 413 | UriExitOnFailure(hr, "Invalid server name in URI."); |
399 | } | 414 | } |
400 | else | 415 | else |
401 | { | 416 | { |
402 | hr = StrAllocString(ppwzRoot, L"\\\\", 64); | 417 | hr = StrAllocString(ppwzRoot, L"\\\\", 64); |
403 | ExitOnFailure(hr, "Failed to allocate string for root of URI."); | 418 | UriExitOnFailure(hr, "Failed to allocate string for root of URI."); |
404 | 419 | ||
405 | pwcSlash = wcschr(pwcSlash + 1, L'/'); | 420 | pwcSlash = wcschr(pwcSlash + 1, L'/'); |
406 | if (pwcSlash) | 421 | if (pwcSlash) |
407 | { | 422 | { |
408 | hr = StrAllocConcat(ppwzRoot, wzUri + 8, pwcSlash - wzUri - 8); | 423 | hr = StrAllocConcat(ppwzRoot, wzUri + 8, pwcSlash - wzUri - 8); |
409 | ExitOnFailure(hr, "Failed to add server/share to root of URI."); | 424 | UriExitOnFailure(hr, "Failed to add server/share to root of URI."); |
410 | } | 425 | } |
411 | else | 426 | else |
412 | { | 427 | { |
413 | hr = StrAllocConcat(ppwzRoot, wzUri + 8, 0); | 428 | hr = StrAllocConcat(ppwzRoot, wzUri + 8, 0); |
414 | ExitOnFailure(hr, "Failed to add server/share to root of URI."); | 429 | UriExitOnFailure(hr, "Failed to add server/share to root of URI."); |
415 | } | 430 | } |
416 | 431 | ||
417 | // replace all slashes with backslashes to be truly UNC. | 432 | // replace all slashes with backslashes to be truly UNC. |
@@ -431,12 +446,12 @@ extern "C" HRESULT DAPI UriRoot( | |||
431 | if (pwcSlash) | 446 | if (pwcSlash) |
432 | { | 447 | { |
433 | hr = StrAllocString(ppwzRoot, wzUri, pwcSlash - wzUri); | 448 | hr = StrAllocString(ppwzRoot, wzUri, pwcSlash - wzUri); |
434 | ExitOnFailure(hr, "Failed allocate root from URI."); | 449 | UriExitOnFailure(hr, "Failed allocate root from URI."); |
435 | } | 450 | } |
436 | else | 451 | else |
437 | { | 452 | { |
438 | hr = StrAllocString(ppwzRoot, wzUri, 0); | 453 | hr = StrAllocString(ppwzRoot, wzUri, 0); |
439 | ExitOnFailure(hr, "Failed allocate root from URI."); | 454 | UriExitOnFailure(hr, "Failed allocate root from URI."); |
440 | } | 455 | } |
441 | break; | 456 | break; |
442 | 457 | ||
@@ -445,18 +460,18 @@ extern "C" HRESULT DAPI UriRoot( | |||
445 | if (pwcSlash) | 460 | if (pwcSlash) |
446 | { | 461 | { |
447 | hr = StrAllocString(ppwzRoot, wzUri, pwcSlash - wzUri); | 462 | hr = StrAllocString(ppwzRoot, wzUri, pwcSlash - wzUri); |
448 | ExitOnFailure(hr, "Failed allocate root from URI."); | 463 | UriExitOnFailure(hr, "Failed allocate root from URI."); |
449 | } | 464 | } |
450 | else | 465 | else |
451 | { | 466 | { |
452 | hr = StrAllocString(ppwzRoot, wzUri, 0); | 467 | hr = StrAllocString(ppwzRoot, wzUri, 0); |
453 | ExitOnFailure(hr, "Failed allocate root from URI."); | 468 | UriExitOnFailure(hr, "Failed allocate root from URI."); |
454 | } | 469 | } |
455 | break; | 470 | break; |
456 | 471 | ||
457 | default: | 472 | default: |
458 | hr = E_INVALIDARG; | 473 | hr = E_INVALIDARG; |
459 | ExitOnFailure(hr, "Unknown URI protocol."); | 474 | UriExitOnFailure(hr, "Unknown URI protocol."); |
460 | } | 475 | } |
461 | 476 | ||
462 | if (pProtocol) | 477 | if (pProtocol) |
@@ -473,7 +488,7 @@ extern "C" HRESULT DAPI UriResolve( | |||
473 | __in_z LPCWSTR wzUri, | 488 | __in_z LPCWSTR wzUri, |
474 | __in_opt LPCWSTR wzBaseUri, | 489 | __in_opt LPCWSTR wzBaseUri, |
475 | __out LPWSTR* ppwzResolvedUri, | 490 | __out LPWSTR* ppwzResolvedUri, |
476 | __out_opt const URI_PROTOCOL* pResolvedProtocol | 491 | __out_opt URI_PROTOCOL* pResolvedProtocol |
477 | ) | 492 | ) |
478 | { | 493 | { |
479 | UNREFERENCED_PARAMETER(wzUri); | 494 | UNREFERENCED_PARAMETER(wzUri); |
@@ -486,45 +501,45 @@ extern "C" HRESULT DAPI UriResolve( | |||
486 | URI_PROTOCOL protocol = URI_PROTOCOL_UNKNOWN; | 501 | URI_PROTOCOL protocol = URI_PROTOCOL_UNKNOWN; |
487 | 502 | ||
488 | hr = UriProtocol(wzUri, &protocol); | 503 | hr = UriProtocol(wzUri, &protocol); |
489 | ExitOnFailure(hr, "Failed to determine protocol for URL: %ls", wzUri); | 504 | UriExitOnFailure(hr, "Failed to determine protocol for URL: %ls", wzUri); |
490 | 505 | ||
491 | ExitOnNull(ppwzResolvedUri, hr, E_INVALIDARG, "Failed to resolve URI, because no method of output was provided"); | 506 | UriExitOnNull(ppwzResolvedUri, hr, E_INVALIDARG, "Failed to resolve URI, because no method of output was provided"); |
492 | 507 | ||
493 | if (URI_PROTOCOL_UNKNOWN == protocol) | 508 | if (URI_PROTOCOL_UNKNOWN == protocol) |
494 | { | 509 | { |
495 | ExitOnNull(wzBaseUri, hr, E_INVALIDARG, "Failed to resolve URI - base URI provided was NULL"); | 510 | UriExitOnNull(wzBaseUri, hr, E_INVALIDARG, "Failed to resolve URI - base URI provided was NULL"); |
496 | 511 | ||
497 | if (L'/' == *wzUri || L'\\' == *wzUri) | 512 | if (L'/' == *wzUri || L'\\' == *wzUri) |
498 | { | 513 | { |
499 | hr = UriRoot(wzBaseUri, ppwzResolvedUri, &protocol); | 514 | hr = UriRoot(wzBaseUri, ppwzResolvedUri, &protocol); |
500 | ExitOnFailure(hr, "Failed to get root from URI: %ls", wzBaseUri); | 515 | UriExitOnFailure(hr, "Failed to get root from URI: %ls", wzBaseUri); |
501 | 516 | ||
502 | hr = StrAllocConcat(ppwzResolvedUri, wzUri, 0); | 517 | hr = StrAllocConcat(ppwzResolvedUri, wzUri, 0); |
503 | ExitOnFailure(hr, "Failed to concat file to base URI."); | 518 | UriExitOnFailure(hr, "Failed to concat file to base URI."); |
504 | } | 519 | } |
505 | else | 520 | else |
506 | { | 521 | { |
507 | hr = UriProtocol(wzBaseUri, &protocol); | 522 | hr = UriProtocol(wzBaseUri, &protocol); |
508 | ExitOnFailure(hr, "Failed to get protocol of base URI: %ls", wzBaseUri); | 523 | UriExitOnFailure(hr, "Failed to get protocol of base URI: %ls", wzBaseUri); |
509 | 524 | ||
510 | LPCWSTR pwcFile = const_cast<LPCWSTR> (UriFile(wzBaseUri)); | 525 | LPCWSTR pwcFile = const_cast<LPCWSTR> (UriFile(wzBaseUri)); |
511 | if (!pwcFile) | 526 | if (!pwcFile) |
512 | { | 527 | { |
513 | hr = E_INVALIDARG; | 528 | hr = E_INVALIDARG; |
514 | ExitOnFailure(hr, "Failed to get file from base URI: %ls", wzBaseUri); | 529 | UriExitOnFailure(hr, "Failed to get file from base URI: %ls", wzBaseUri); |
515 | } | 530 | } |
516 | 531 | ||
517 | hr = StrAllocString(ppwzResolvedUri, wzBaseUri, pwcFile - wzBaseUri); | 532 | hr = StrAllocString(ppwzResolvedUri, wzBaseUri, pwcFile - wzBaseUri); |
518 | ExitOnFailure(hr, "Failed to allocate string for resolved URI."); | 533 | UriExitOnFailure(hr, "Failed to allocate string for resolved URI."); |
519 | 534 | ||
520 | hr = StrAllocConcat(ppwzResolvedUri, wzUri, 0); | 535 | hr = StrAllocConcat(ppwzResolvedUri, wzUri, 0); |
521 | ExitOnFailure(hr, "Failed to concat file to resolved URI."); | 536 | UriExitOnFailure(hr, "Failed to concat file to resolved URI."); |
522 | } | 537 | } |
523 | } | 538 | } |
524 | else | 539 | else |
525 | { | 540 | { |
526 | hr = StrAllocString(ppwzResolvedUri, wzUri, 0); | 541 | hr = StrAllocString(ppwzResolvedUri, wzUri, 0); |
527 | ExitOnFailure(hr, "Failed to copy resolved URI."); | 542 | UriExitOnFailure(hr, "Failed to copy resolved URI."); |
528 | } | 543 | } |
529 | 544 | ||
530 | if (pResolvedProtocol) | 545 | if (pResolvedProtocol) |
diff --git a/src/dutil/userutil.cpp b/src/dutil/userutil.cpp index 2e77f1df..ca6d5480 100644 --- a/src/dutil/userutil.cpp +++ b/src/dutil/userutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // UserExit macros | ||
7 | #define UserExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__) | ||
8 | #define UserExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__) | ||
9 | #define UserExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__) | ||
10 | #define UserExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__) | ||
11 | #define UserExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__) | ||
12 | #define UserExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__) | ||
13 | #define UserExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_USERUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define UserExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_USERUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define UserExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_USERUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define UserExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_USERUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define UserExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_USERUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define UserExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_USERUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | static BOOL CheckIsMemberHelper( | 20 | static BOOL CheckIsMemberHelper( |
6 | __in_z LPCWSTR pwzGroupUserDomain, | 21 | __in_z LPCWSTR pwzGroupUserDomain, |
7 | __in_ecount(cguiGroupData) const GROUP_USERS_INFO_0 *pguiGroupData, | 22 | __in_ecount(cguiGroupData) const GROUP_USERS_INFO_0 *pguiGroupData, |
@@ -29,14 +44,14 @@ extern "C" HRESULT DAPI UserBuildDomainUserName( | |||
29 | if (cch >= cchLeft) | 44 | if (cch >= cchLeft) |
30 | { | 45 | { |
31 | hr = ERROR_MORE_DATA; | 46 | hr = ERROR_MORE_DATA; |
32 | ExitOnFailure(hr, "Buffer size is not big enough to hold domain name: %ls", pwzDomain); | 47 | UserExitOnFailure(hr, "Buffer size is not big enough to hold domain name: %ls", pwzDomain); |
33 | } | 48 | } |
34 | else if (cch > 0) | 49 | else if (cch > 0) |
35 | { | 50 | { |
36 | // handle the domain case | 51 | // handle the domain case |
37 | 52 | ||
38 | hr = ::StringCchCopyNW(pwz, cchWz, pwzDomain, cchLeft - 1); // last parameter does not include '\0' | 53 | hr = ::StringCchCopyNW(pwz, cchWz, pwzDomain, cchLeft - 1); // last parameter does not include '\0' |
39 | ExitOnFailure(hr, "Failed to copy Domain onto string."); | 54 | UserExitOnFailure(hr, "Failed to copy Domain onto string."); |
40 | 55 | ||
41 | cchLeft -= cch; | 56 | cchLeft -= cch; |
42 | pwz += cch; | 57 | pwz += cch; |
@@ -45,11 +60,11 @@ extern "C" HRESULT DAPI UserBuildDomainUserName( | |||
45 | if (1 >= cchLeft) | 60 | if (1 >= cchLeft) |
46 | { | 61 | { |
47 | hr = ERROR_MORE_DATA; | 62 | hr = ERROR_MORE_DATA; |
48 | ExitOnFailure(hr, "Insufficient buffer size while building domain user name"); | 63 | UserExitOnFailure(hr, "Insufficient buffer size while building domain user name"); |
49 | } | 64 | } |
50 | 65 | ||
51 | hr = ::StringCchCopyNW(pwz, cchWz, L"\\", cchLeft - 1); // last parameter does not include '\0' | 66 | hr = ::StringCchCopyNW(pwz, cchWz, L"\\", cchLeft - 1); // last parameter does not include '\0' |
52 | ExitOnFailure(hr, "Failed to copy backslash onto string."); | 67 | UserExitOnFailure(hr, "Failed to copy backslash onto string."); |
53 | 68 | ||
54 | --cchLeft; | 69 | --cchLeft; |
55 | ++pwz; | 70 | ++pwz; |
@@ -60,11 +75,11 @@ extern "C" HRESULT DAPI UserBuildDomainUserName( | |||
60 | if (cch >= cchLeft) | 75 | if (cch >= cchLeft) |
61 | { | 76 | { |
62 | hr = ERROR_MORE_DATA; | 77 | hr = ERROR_MORE_DATA; |
63 | ExitOnFailure(hr, "Buffer size is not big enough to hold user name: %ls", pwzName); | 78 | UserExitOnFailure(hr, "Buffer size is not big enough to hold user name: %ls", pwzName); |
64 | } | 79 | } |
65 | 80 | ||
66 | hr = ::StringCchCopyNW(pwz, cchWz, pwzName, cchLeft - 1); // last parameter does not include '\0' | 81 | hr = ::StringCchCopyNW(pwz, cchWz, pwzName, cchLeft - 1); // last parameter does not include '\0' |
67 | ExitOnFailure(hr, "Failed to copy User name onto string."); | 82 | UserExitOnFailure(hr, "Failed to copy User name onto string."); |
68 | 83 | ||
69 | LExit: | 84 | LExit: |
70 | return hr; | 85 | return hr; |
@@ -98,10 +113,10 @@ extern "C" HRESULT DAPI UserCheckIsMember( | |||
98 | VARIANT_BOOL vtBoolResult = VARIANT_FALSE; | 113 | VARIANT_BOOL vtBoolResult = VARIANT_FALSE; |
99 | 114 | ||
100 | hr = UserBuildDomainUserName(wzGroupUserDomain, countof(wzGroupUserDomain), pwzGroupName, pwzGroupDomain); | 115 | hr = UserBuildDomainUserName(wzGroupUserDomain, countof(wzGroupUserDomain), pwzGroupName, pwzGroupDomain); |
101 | ExitOnFailure(hr, "Failed to build group name from group domain %ls, group name %ls", pwzGroupDomain, pwzGroupName); | 116 | UserExitOnFailure(hr, "Failed to build group name from group domain %ls, group name %ls", pwzGroupDomain, pwzGroupName); |
102 | 117 | ||
103 | hr = UserBuildDomainUserName(wzUserDomain, countof(wzUserDomain), pwzName, pwzDomain); | 118 | hr = UserBuildDomainUserName(wzUserDomain, countof(wzUserDomain), pwzName, pwzDomain); |
104 | ExitOnFailure(hr, "Failed to build group name from group domain %ls, group name %ls", pwzGroupDomain, pwzGroupName); | 119 | UserExitOnFailure(hr, "Failed to build group name from group domain %ls, group name %ls", pwzGroupDomain, pwzGroupName); |
105 | 120 | ||
106 | if (pwzDomain && *pwzDomain) | 121 | if (pwzDomain && *pwzDomain) |
107 | { | 122 | { |
@@ -115,12 +130,12 @@ extern "C" HRESULT DAPI UserCheckIsMember( | |||
115 | Trace(REPORT_VERBOSE, "failed to get groups for user %ls from domain %ls with error code 0x%x - continuing", pwzName, (wz != NULL) ? wz : L"", HRESULT_FROM_WIN32(er)); | 130 | Trace(REPORT_VERBOSE, "failed to get groups for user %ls from domain %ls with error code 0x%x - continuing", pwzName, (wz != NULL) ? wz : L"", HRESULT_FROM_WIN32(er)); |
116 | er = ERROR_SUCCESS; | 131 | er = ERROR_SUCCESS; |
117 | } | 132 | } |
118 | ExitOnWin32Error(er, hr, "Failed to get list of global groups for user while checking group membership information for user: %ls", pwzName); | 133 | UserExitOnWin32Error(er, hr, "Failed to get list of global groups for user while checking group membership information for user: %ls", pwzName); |
119 | 134 | ||
120 | if (dwRead != dwTotal) | 135 | if (dwRead != dwTotal) |
121 | { | 136 | { |
122 | hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA); | 137 | hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA); |
123 | ExitOnRootFailure(hr, "Failed to get entire list of groups (global) for user while checking group membership information for user: %ls", pwzName); | 138 | UserExitOnRootFailure(hr, "Failed to get entire list of groups (global) for user while checking group membership information for user: %ls", pwzName); |
124 | } | 139 | } |
125 | 140 | ||
126 | if (CheckIsMemberHelper(wzGroupUserDomain, pguiGroupData, dwRead)) | 141 | if (CheckIsMemberHelper(wzGroupUserDomain, pguiGroupData, dwRead)) |
@@ -143,12 +158,12 @@ extern "C" HRESULT DAPI UserCheckIsMember( | |||
143 | Trace(REPORT_VERBOSE, "failed to get local groups for user %ls from domain %ls with error code 0x%x - continuing", pwzName, (wz != NULL) ? wz : L"", HRESULT_FROM_WIN32(er)); | 158 | Trace(REPORT_VERBOSE, "failed to get local groups for user %ls from domain %ls with error code 0x%x - continuing", pwzName, (wz != NULL) ? wz : L"", HRESULT_FROM_WIN32(er)); |
144 | er = ERROR_SUCCESS; | 159 | er = ERROR_SUCCESS; |
145 | } | 160 | } |
146 | ExitOnWin32Error(er, hr, "Failed to get list of groups for user while checking group membership information for user: %ls", pwzName); | 161 | UserExitOnWin32Error(er, hr, "Failed to get list of groups for user while checking group membership information for user: %ls", pwzName); |
147 | 162 | ||
148 | if (dwRead != dwTotal) | 163 | if (dwRead != dwTotal) |
149 | { | 164 | { |
150 | hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA); | 165 | hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA); |
151 | ExitOnRootFailure(hr, "Failed to get entire list of groups (local) for user while checking group membership information for user: %ls", pwzName); | 166 | UserExitOnRootFailure(hr, "Failed to get entire list of groups (local) for user while checking group membership information for user: %ls", pwzName); |
152 | } | 167 | } |
153 | 168 | ||
154 | if (CheckIsMemberHelper(wzGroupUserDomain, pguiGroupData, dwRead)) | 169 | if (CheckIsMemberHelper(wzGroupUserDomain, pguiGroupData, dwRead)) |
@@ -159,18 +174,18 @@ extern "C" HRESULT DAPI UserCheckIsMember( | |||
159 | 174 | ||
160 | // If the above methods failed, let's try active directory | 175 | // If the above methods failed, let's try active directory |
161 | hr = UserCreateADsPath(pwzDomain, pwzName, &bstrUser); | 176 | hr = UserCreateADsPath(pwzDomain, pwzName, &bstrUser); |
162 | ExitOnFailure(hr, "failed to create user ADsPath in order to check group membership for group: %ls domain: %ls", pwzName, pwzDomain); | 177 | UserExitOnFailure(hr, "failed to create user ADsPath in order to check group membership for group: %ls domain: %ls", pwzName, pwzDomain); |
163 | 178 | ||
164 | hr = UserCreateADsPath(pwzGroupDomain, pwzGroupName, &bstrGroup); | 179 | hr = UserCreateADsPath(pwzGroupDomain, pwzGroupName, &bstrGroup); |
165 | ExitOnFailure(hr, "failed to create group ADsPath in order to check group membership for group: %ls domain: %ls", pwzGroupName, pwzGroupDomain); | 180 | UserExitOnFailure(hr, "failed to create group ADsPath in order to check group membership for group: %ls domain: %ls", pwzGroupName, pwzGroupDomain); |
166 | 181 | ||
167 | if (lstrlenW(pwzGroupDomain) > 0) | 182 | if (lstrlenW(pwzGroupDomain) > 0) |
168 | { | 183 | { |
169 | hr = ::ADsGetObject(bstrGroup, IID_IADsGroup, reinterpret_cast<void**>(&pGroup)); | 184 | hr = ::ADsGetObject(bstrGroup, IID_IADsGroup, reinterpret_cast<void**>(&pGroup)); |
170 | ExitOnFailure(hr, "Failed to get group '%ls' from active directory.", reinterpret_cast<WCHAR*>(bstrGroup) ); | 185 | UserExitOnFailure(hr, "Failed to get group '%ls' from active directory.", reinterpret_cast<WCHAR*>(bstrGroup) ); |
171 | 186 | ||
172 | hr = pGroup->IsMember(bstrUser, &vtBoolResult); | 187 | hr = pGroup->IsMember(bstrUser, &vtBoolResult); |
173 | ExitOnFailure(hr, "Failed to check if user %ls is a member of group '%ls' using active directory.", reinterpret_cast<WCHAR*>(bstrUser), reinterpret_cast<WCHAR*>(bstrGroup) ); | 188 | UserExitOnFailure(hr, "Failed to check if user %ls is a member of group '%ls' using active directory.", reinterpret_cast<WCHAR*>(bstrUser), reinterpret_cast<WCHAR*>(bstrGroup) ); |
174 | } | 189 | } |
175 | 190 | ||
176 | if (vtBoolResult) | 191 | if (vtBoolResult) |
@@ -180,10 +195,10 @@ extern "C" HRESULT DAPI UserCheckIsMember( | |||
180 | } | 195 | } |
181 | 196 | ||
182 | hr = ::ADsGetObject(bstrGroup, IID_IADsGroup, reinterpret_cast<void**>(&pGroup)); | 197 | hr = ::ADsGetObject(bstrGroup, IID_IADsGroup, reinterpret_cast<void**>(&pGroup)); |
183 | ExitOnFailure(hr, "Failed to get group '%ls' from active directory.", reinterpret_cast<WCHAR*>(bstrGroup) ); | 198 | UserExitOnFailure(hr, "Failed to get group '%ls' from active directory.", reinterpret_cast<WCHAR*>(bstrGroup) ); |
184 | 199 | ||
185 | hr = pGroup->IsMember(bstrUser, &vtBoolResult); | 200 | hr = pGroup->IsMember(bstrUser, &vtBoolResult); |
186 | ExitOnFailure(hr, "Failed to check if user %ls is a member of group '%ls' using active directory.", reinterpret_cast<WCHAR*>(bstrUser), reinterpret_cast<WCHAR*>(bstrGroup) ); | 201 | UserExitOnFailure(hr, "Failed to check if user %ls is a member of group '%ls' using active directory.", reinterpret_cast<WCHAR*>(bstrUser), reinterpret_cast<WCHAR*>(bstrGroup) ); |
187 | 202 | ||
188 | if (vtBoolResult) | 203 | if (vtBoolResult) |
189 | { | 204 | { |
@@ -222,25 +237,25 @@ extern "C" HRESULT DAPI UserCreateADsPath( | |||
222 | LPWSTR pwzAdsPath = NULL; | 237 | LPWSTR pwzAdsPath = NULL; |
223 | 238 | ||
224 | hr = StrAllocString(&pwzAdsPath, L"WinNT://", 0); | 239 | hr = StrAllocString(&pwzAdsPath, L"WinNT://", 0); |
225 | ExitOnFailure(hr, "failed to allocate AdsPath string"); | 240 | UserExitOnFailure(hr, "failed to allocate AdsPath string"); |
226 | 241 | ||
227 | if (*wzObjectDomain) | 242 | if (*wzObjectDomain) |
228 | { | 243 | { |
229 | hr = StrAllocFormatted(&pwzAdsPath, L"%s/%s", wzObjectDomain, wzObjectName); | 244 | hr = StrAllocFormatted(&pwzAdsPath, L"%s/%s", wzObjectDomain, wzObjectName); |
230 | ExitOnFailure(hr, "failed to allocate AdsPath string"); | 245 | UserExitOnFailure(hr, "failed to allocate AdsPath string"); |
231 | } | 246 | } |
232 | else if (NULL != wcsstr(wzObjectName, L"\\") || NULL != wcsstr(wzObjectName, L"/")) | 247 | else if (NULL != wcsstr(wzObjectName, L"\\") || NULL != wcsstr(wzObjectName, L"/")) |
233 | { | 248 | { |
234 | hr = StrAllocConcat(&pwzAdsPath, wzObjectName, 0); | 249 | hr = StrAllocConcat(&pwzAdsPath, wzObjectName, 0); |
235 | ExitOnFailure(hr, "failed to concat objectname: %ls", wzObjectName); | 250 | UserExitOnFailure(hr, "failed to concat objectname: %ls", wzObjectName); |
236 | } | 251 | } |
237 | else | 252 | else |
238 | { | 253 | { |
239 | hr = StrAllocConcat(&pwzAdsPath, L"Localhost/", 0); | 254 | hr = StrAllocConcat(&pwzAdsPath, L"Localhost/", 0); |
240 | ExitOnFailure(hr, "failed to concat LocalHost/"); | 255 | UserExitOnFailure(hr, "failed to concat LocalHost/"); |
241 | 256 | ||
242 | hr = StrAllocConcat(&pwzAdsPath, wzObjectName, 0); | 257 | hr = StrAllocConcat(&pwzAdsPath, wzObjectName, 0); |
243 | ExitOnFailure(hr, "failed to concat object name: %ls", wzObjectName); | 258 | UserExitOnFailure(hr, "failed to concat object name: %ls", wzObjectName); |
244 | } | 259 | } |
245 | 260 | ||
246 | *pbstrAdsPath = ::SysAllocString(pwzAdsPath); | 261 | *pbstrAdsPath = ::SysAllocString(pwzAdsPath); |
diff --git a/src/dutil/wiutil.cpp b/src/dutil/wiutil.cpp index 7336d685..ffbfe85a 100644 --- a/src/dutil/wiutil.cpp +++ b/src/dutil/wiutil.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | 5 | ||
6 | // Exit macros | ||
7 | #define WiuExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__) | ||
8 | #define WiuExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__) | ||
9 | #define WiuExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__) | ||
10 | #define WiuExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__) | ||
11 | #define WiuExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__) | ||
12 | #define WiuExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__) | ||
13 | #define WiuExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_WIUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define WiuExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_WIUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define WiuExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_WIUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define WiuExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_WIUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define WiuExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_WIUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define WiuExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_WIUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
6 | // constants | 21 | // constants |
7 | 22 | ||
8 | const DWORD WIU_MSI_PROGRESS_INVALID = 0xFFFFFFFF; | 23 | const DWORD WIU_MSI_PROGRESS_INVALID = 0xFFFFFFFF; |
@@ -112,8 +127,8 @@ static DWORD CalculatePhaseProgress( | |||
112 | __in DWORD dwWeightPercentage | 127 | __in DWORD dwWeightPercentage |
113 | ); | 128 | ); |
114 | void InitializeMessageData( | 129 | void InitializeMessageData( |
115 | __in MSIHANDLE hRecord, | 130 | __in_opt MSIHANDLE hRecord, |
116 | __out LPWSTR** prgsczData, | 131 | __deref_out_ecount(*pcData) LPWSTR** prgsczData, |
117 | __out DWORD* pcData | 132 | __out DWORD* pcData |
118 | ); | 133 | ); |
119 | void UninitializeMessageData( | 134 | void UninitializeMessageData( |
@@ -133,7 +148,7 @@ extern "C" HRESULT DAPI WiuInitialize( | |||
133 | LPWSTR sczMsiDllPath = NULL; | 148 | LPWSTR sczMsiDllPath = NULL; |
134 | 149 | ||
135 | hr = LoadSystemLibraryWithPath(L"Msi.dll", &vhMsiDll, &sczMsiDllPath); | 150 | hr = LoadSystemLibraryWithPath(L"Msi.dll", &vhMsiDll, &sczMsiDllPath); |
136 | ExitOnFailure(hr, "Failed to load Msi.DLL"); | 151 | WiuExitOnFailure(hr, "Failed to load Msi.DLL"); |
137 | 152 | ||
138 | // Ignore failures | 153 | // Ignore failures |
139 | FileVersion(sczMsiDllPath, &vdwMsiDllMajorMinor, &vdwMsiDllBuildRevision); | 154 | FileVersion(sczMsiDllPath, &vdwMsiDllMajorMinor, &vdwMsiDllBuildRevision); |
@@ -275,7 +290,7 @@ extern "C" HRESULT DAPI WiuGetComponentPath( | |||
275 | DWORD cchCompare; | 290 | DWORD cchCompare; |
276 | 291 | ||
277 | hr = StrAlloc(psczValue, cch); | 292 | hr = StrAlloc(psczValue, cch); |
278 | ExitOnFailure(hr, "Failed to allocate string for component path."); | 293 | WiuExitOnFailure(hr, "Failed to allocate string for component path."); |
279 | 294 | ||
280 | cchCompare = cch; | 295 | cchCompare = cch; |
281 | *pInstallState = vpfnMsiGetComponentPathW(wzProductCode, wzComponentId, *psczValue, &cch); | 296 | *pInstallState = vpfnMsiGetComponentPathW(wzProductCode, wzComponentId, *psczValue, &cch); |
@@ -283,7 +298,7 @@ extern "C" HRESULT DAPI WiuGetComponentPath( | |||
283 | { | 298 | { |
284 | ++cch; | 299 | ++cch; |
285 | hr = StrAlloc(psczValue, cch); | 300 | hr = StrAlloc(psczValue, cch); |
286 | ExitOnFailure(hr, "Failed to reallocate string for component path."); | 301 | WiuExitOnFailure(hr, "Failed to reallocate string for component path."); |
287 | 302 | ||
288 | cchCompare = cch; | 303 | cchCompare = cch; |
289 | *pInstallState = vpfnMsiGetComponentPathW(wzProductCode, wzComponentId, *psczValue, &cch); | 304 | *pInstallState = vpfnMsiGetComponentPathW(wzProductCode, wzComponentId, *psczValue, &cch); |
@@ -292,7 +307,7 @@ extern "C" HRESULT DAPI WiuGetComponentPath( | |||
292 | if (INSTALLSTATE_INVALIDARG == *pInstallState) | 307 | if (INSTALLSTATE_INVALIDARG == *pInstallState) |
293 | { | 308 | { |
294 | hr = E_INVALIDARG; | 309 | hr = E_INVALIDARG; |
295 | ExitOnRootFailure(hr, "Invalid argument when getting component path."); | 310 | WiuExitOnRootFailure(hr, "Invalid argument when getting component path."); |
296 | } | 311 | } |
297 | else if (INSTALLSTATE_UNKNOWN == *pInstallState) | 312 | else if (INSTALLSTATE_UNKNOWN == *pInstallState) |
298 | { | 313 | { |
@@ -306,7 +321,7 @@ extern "C" HRESULT DAPI WiuGetComponentPath( | |||
306 | { | 321 | { |
307 | ++cch; | 322 | ++cch; |
308 | hr = StrAlloc(psczValue, cch); | 323 | hr = StrAlloc(psczValue, cch); |
309 | ExitOnFailure(hr, "Failed to reallocate string for component path."); | 324 | WiuExitOnFailure(hr, "Failed to reallocate string for component path."); |
310 | 325 | ||
311 | *pInstallState = vpfnMsiGetComponentPathW(wzProductCode, wzComponentId, *psczValue, &cch); | 326 | *pInstallState = vpfnMsiGetComponentPathW(wzProductCode, wzComponentId, *psczValue, &cch); |
312 | } | 327 | } |
@@ -327,7 +342,7 @@ extern "C" HRESULT DAPI WiuLocateComponent( | |||
327 | DWORD cchCompare; | 342 | DWORD cchCompare; |
328 | 343 | ||
329 | hr = StrAlloc(psczValue, cch); | 344 | hr = StrAlloc(psczValue, cch); |
330 | ExitOnFailure(hr, "Failed to allocate string for component path."); | 345 | WiuExitOnFailure(hr, "Failed to allocate string for component path."); |
331 | 346 | ||
332 | cchCompare = cch; | 347 | cchCompare = cch; |
333 | *pInstallState = vpfnMsiLocateComponentW(wzComponentId, *psczValue, &cch); | 348 | *pInstallState = vpfnMsiLocateComponentW(wzComponentId, *psczValue, &cch); |
@@ -335,7 +350,7 @@ extern "C" HRESULT DAPI WiuLocateComponent( | |||
335 | { | 350 | { |
336 | ++cch; | 351 | ++cch; |
337 | hr = StrAlloc(psczValue, cch); | 352 | hr = StrAlloc(psczValue, cch); |
338 | ExitOnFailure(hr, "Failed to reallocate string for component path."); | 353 | WiuExitOnFailure(hr, "Failed to reallocate string for component path."); |
339 | 354 | ||
340 | cchCompare = cch; | 355 | cchCompare = cch; |
341 | *pInstallState = vpfnMsiLocateComponentW(wzComponentId, *psczValue, &cch); | 356 | *pInstallState = vpfnMsiLocateComponentW(wzComponentId, *psczValue, &cch); |
@@ -344,7 +359,7 @@ extern "C" HRESULT DAPI WiuLocateComponent( | |||
344 | if (INSTALLSTATE_INVALIDARG == *pInstallState) | 359 | if (INSTALLSTATE_INVALIDARG == *pInstallState) |
345 | { | 360 | { |
346 | hr = E_INVALIDARG; | 361 | hr = E_INVALIDARG; |
347 | ExitOnRootFailure(hr, "Invalid argument when locating component."); | 362 | WiuExitOnRootFailure(hr, "Invalid argument when locating component."); |
348 | } | 363 | } |
349 | else if (INSTALLSTATE_UNKNOWN == *pInstallState) | 364 | else if (INSTALLSTATE_UNKNOWN == *pInstallState) |
350 | { | 365 | { |
@@ -358,7 +373,7 @@ extern "C" HRESULT DAPI WiuLocateComponent( | |||
358 | { | 373 | { |
359 | ++cch; | 374 | ++cch; |
360 | hr = StrAlloc(psczValue, cch); | 375 | hr = StrAlloc(psczValue, cch); |
361 | ExitOnFailure(hr, "Failed to reallocate string for component path."); | 376 | WiuExitOnFailure(hr, "Failed to reallocate string for component path."); |
362 | 377 | ||
363 | *pInstallState = vpfnMsiLocateComponentW(wzComponentId, *psczValue, &cch); | 378 | *pInstallState = vpfnMsiLocateComponentW(wzComponentId, *psczValue, &cch); |
364 | } | 379 | } |
@@ -380,7 +395,7 @@ extern "C" HRESULT DAPI WiuQueryFeatureState( | |||
380 | if (INSTALLSTATE_INVALIDARG == *pInstallState) | 395 | if (INSTALLSTATE_INVALIDARG == *pInstallState) |
381 | { | 396 | { |
382 | hr = E_INVALIDARG; | 397 | hr = E_INVALIDARG; |
383 | ExitOnRootFailure(hr, "Failed to query state of feature: %ls in product: %ls", wzFeature, wzProduct); | 398 | WiuExitOnRootFailure(hr, "Failed to query state of feature: %ls in product: %ls", wzFeature, wzProduct); |
384 | } | 399 | } |
385 | 400 | ||
386 | LExit: | 401 | LExit: |
@@ -399,18 +414,18 @@ extern "C" HRESULT DAPI WiuGetProductInfo( | |||
399 | DWORD cch = WIU_GOOD_ENOUGH_PROPERTY_LENGTH; | 414 | DWORD cch = WIU_GOOD_ENOUGH_PROPERTY_LENGTH; |
400 | 415 | ||
401 | hr = StrAlloc(psczValue, cch); | 416 | hr = StrAlloc(psczValue, cch); |
402 | ExitOnFailure(hr, "Failed to allocate string for product info."); | 417 | WiuExitOnFailure(hr, "Failed to allocate string for product info."); |
403 | 418 | ||
404 | er = vpfnMsiGetProductInfoW(wzProductCode, wzProperty, *psczValue, &cch); | 419 | er = vpfnMsiGetProductInfoW(wzProductCode, wzProperty, *psczValue, &cch); |
405 | if (ERROR_MORE_DATA == er) | 420 | if (ERROR_MORE_DATA == er) |
406 | { | 421 | { |
407 | ++cch; | 422 | ++cch; |
408 | hr = StrAlloc(psczValue, cch); | 423 | hr = StrAlloc(psczValue, cch); |
409 | ExitOnFailure(hr, "Failed to reallocate string for product info."); | 424 | WiuExitOnFailure(hr, "Failed to reallocate string for product info."); |
410 | 425 | ||
411 | er = vpfnMsiGetProductInfoW(wzProductCode, wzProperty, *psczValue, &cch); | 426 | er = vpfnMsiGetProductInfoW(wzProductCode, wzProperty, *psczValue, &cch); |
412 | } | 427 | } |
413 | ExitOnWin32Error(er, hr, "Failed to get product info."); | 428 | WiuExitOnWin32Error(er, hr, "Failed to get product info."); |
414 | 429 | ||
415 | LExit: | 430 | LExit: |
416 | return hr; | 431 | return hr; |
@@ -432,24 +447,24 @@ extern "C" HRESULT DAPI WiuGetProductInfoEx( | |||
432 | if (!vpfnMsiGetProductInfoExW) | 447 | if (!vpfnMsiGetProductInfoExW) |
433 | { | 448 | { |
434 | hr = WiuGetProductInfo(wzProductCode, wzProperty, psczValue); | 449 | hr = WiuGetProductInfo(wzProductCode, wzProperty, psczValue); |
435 | ExitOnFailure(hr, "Failed to get product info when extended info was not available."); | 450 | WiuExitOnFailure(hr, "Failed to get product info when extended info was not available."); |
436 | 451 | ||
437 | ExitFunction(); | 452 | ExitFunction(); |
438 | } | 453 | } |
439 | 454 | ||
440 | hr = StrAlloc(psczValue, cch); | 455 | hr = StrAlloc(psczValue, cch); |
441 | ExitOnFailure(hr, "Failed to allocate string for extended product info."); | 456 | WiuExitOnFailure(hr, "Failed to allocate string for extended product info."); |
442 | 457 | ||
443 | er = vpfnMsiGetProductInfoExW(wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch); | 458 | er = vpfnMsiGetProductInfoExW(wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch); |
444 | if (ERROR_MORE_DATA == er) | 459 | if (ERROR_MORE_DATA == er) |
445 | { | 460 | { |
446 | ++cch; | 461 | ++cch; |
447 | hr = StrAlloc(psczValue, cch); | 462 | hr = StrAlloc(psczValue, cch); |
448 | ExitOnFailure(hr, "Failed to reallocate string for extended product info."); | 463 | WiuExitOnFailure(hr, "Failed to reallocate string for extended product info."); |
449 | 464 | ||
450 | er = vpfnMsiGetProductInfoExW(wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch); | 465 | er = vpfnMsiGetProductInfoExW(wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch); |
451 | } | 466 | } |
452 | ExitOnWin32Error(er, hr, "Failed to get extended product info."); | 467 | WiuExitOnWin32Error(er, hr, "Failed to get extended product info."); |
453 | 468 | ||
454 | LExit: | 469 | LExit: |
455 | return hr; | 470 | return hr; |
@@ -467,18 +482,18 @@ extern "C" HRESULT DAPI WiuGetProductProperty( | |||
467 | DWORD cch = WIU_GOOD_ENOUGH_PROPERTY_LENGTH; | 482 | DWORD cch = WIU_GOOD_ENOUGH_PROPERTY_LENGTH; |
468 | 483 | ||
469 | hr = StrAlloc(psczValue, cch); | 484 | hr = StrAlloc(psczValue, cch); |
470 | ExitOnFailure(hr, "Failed to allocate string for product property."); | 485 | WiuExitOnFailure(hr, "Failed to allocate string for product property."); |
471 | 486 | ||
472 | er = ::MsiGetProductPropertyW(hProduct, wzProperty, *psczValue, &cch); | 487 | er = ::MsiGetProductPropertyW(hProduct, wzProperty, *psczValue, &cch); |
473 | if (ERROR_MORE_DATA == er) | 488 | if (ERROR_MORE_DATA == er) |
474 | { | 489 | { |
475 | ++cch; | 490 | ++cch; |
476 | hr = StrAlloc(psczValue, cch); | 491 | hr = StrAlloc(psczValue, cch); |
477 | ExitOnFailure(hr, "Failed to reallocate string for product property."); | 492 | WiuExitOnFailure(hr, "Failed to reallocate string for product property."); |
478 | 493 | ||
479 | er = ::MsiGetProductPropertyW(hProduct, wzProperty, *psczValue, &cch); | 494 | er = ::MsiGetProductPropertyW(hProduct, wzProperty, *psczValue, &cch); |
480 | } | 495 | } |
481 | ExitOnWin32Error(er, hr, "Failed to get product property."); | 496 | WiuExitOnWin32Error(er, hr, "Failed to get product property."); |
482 | 497 | ||
483 | LExit: | 498 | LExit: |
484 | return hr; | 499 | return hr; |
@@ -504,18 +519,18 @@ extern "C" HRESULT DAPI WiuGetPatchInfoEx( | |||
504 | } | 519 | } |
505 | 520 | ||
506 | hr = StrAlloc(psczValue, cch); | 521 | hr = StrAlloc(psczValue, cch); |
507 | ExitOnFailure(hr, "Failed to allocate string for extended patch info."); | 522 | WiuExitOnFailure(hr, "Failed to allocate string for extended patch info."); |
508 | 523 | ||
509 | er = vpfnMsiGetPatchInfoExW(wzPatchCode, wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch); | 524 | er = vpfnMsiGetPatchInfoExW(wzPatchCode, wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch); |
510 | if (ERROR_MORE_DATA == er) | 525 | if (ERROR_MORE_DATA == er) |
511 | { | 526 | { |
512 | ++cch; | 527 | ++cch; |
513 | hr = StrAlloc(psczValue, cch); | 528 | hr = StrAlloc(psczValue, cch); |
514 | ExitOnFailure(hr, "Failed to reallocate string for extended patch info."); | 529 | WiuExitOnFailure(hr, "Failed to reallocate string for extended patch info."); |
515 | 530 | ||
516 | er = vpfnMsiGetPatchInfoExW(wzPatchCode, wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch); | 531 | er = vpfnMsiGetPatchInfoExW(wzPatchCode, wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch); |
517 | } | 532 | } |
518 | ExitOnWin32Error(er, hr, "Failed to get extended patch info."); | 533 | WiuExitOnWin32Error(er, hr, "Failed to get extended patch info."); |
519 | 534 | ||
520 | LExit: | 535 | LExit: |
521 | return hr; | 536 | return hr; |
@@ -539,7 +554,7 @@ extern "C" HRESULT DAPI WiuDeterminePatchSequence( | |||
539 | } | 554 | } |
540 | 555 | ||
541 | er = vpfnMsiDeterminePatchSequenceW(wzProductCode, wzUserSid, context, cPatchInfo, pPatchInfo); | 556 | er = vpfnMsiDeterminePatchSequenceW(wzProductCode, wzUserSid, context, cPatchInfo, pPatchInfo); |
542 | ExitOnWin32Error(er, hr, "Failed to determine patch sequence for product code."); | 557 | WiuExitOnWin32Error(er, hr, "Failed to determine patch sequence for product code."); |
543 | 558 | ||
544 | LExit: | 559 | LExit: |
545 | return hr; | 560 | return hr; |
@@ -561,7 +576,7 @@ extern "C" HRESULT DAPI WiuDetermineApplicablePatches( | |||
561 | } | 576 | } |
562 | 577 | ||
563 | er = vpfnMsiDetermineApplicablePatchesW(wzProductPackagePath, cPatchInfo, pPatchInfo); | 578 | er = vpfnMsiDetermineApplicablePatchesW(wzProductPackagePath, cPatchInfo, pPatchInfo); |
564 | ExitOnWin32Error(er, hr, "Failed to determine applicable patches for product package."); | 579 | WiuExitOnWin32Error(er, hr, "Failed to determine applicable patches for product package."); |
565 | 580 | ||
566 | LExit: | 581 | LExit: |
567 | return hr; | 582 | return hr; |
@@ -581,7 +596,7 @@ extern "C" HRESULT DAPI WiuEnumProducts( | |||
581 | { | 596 | { |
582 | ExitFunction1(hr = HRESULT_FROM_WIN32(er)); | 597 | ExitFunction1(hr = HRESULT_FROM_WIN32(er)); |
583 | } | 598 | } |
584 | ExitOnWin32Error(er, hr, "Failed to enumerate products."); | 599 | WiuExitOnWin32Error(er, hr, "Failed to enumerate products."); |
585 | 600 | ||
586 | LExit: | 601 | LExit: |
587 | return hr; | 602 | return hr; |
@@ -612,7 +627,7 @@ extern "C" HRESULT DAPI WiuEnumProductsEx( | |||
612 | { | 627 | { |
613 | ExitFunction1(hr = HRESULT_FROM_WIN32(er)); | 628 | ExitFunction1(hr = HRESULT_FROM_WIN32(er)); |
614 | } | 629 | } |
615 | ExitOnWin32Error(er, hr, "Failed to enumerate products."); | 630 | WiuExitOnWin32Error(er, hr, "Failed to enumerate products."); |
616 | 631 | ||
617 | LExit: | 632 | LExit: |
618 | return hr; | 633 | return hr; |
@@ -633,7 +648,7 @@ extern "C" HRESULT DAPI WiuEnumRelatedProducts( | |||
633 | { | 648 | { |
634 | ExitFunction1(hr = HRESULT_FROM_WIN32(er)); | 649 | ExitFunction1(hr = HRESULT_FROM_WIN32(er)); |
635 | } | 650 | } |
636 | ExitOnWin32Error(er, hr, "Failed to enumerate related products for updgrade code: %ls", wzUpgradeCode); | 651 | WiuExitOnWin32Error(er, hr, "Failed to enumerate related products for updgrade code: %ls", wzUpgradeCode); |
637 | 652 | ||
638 | LExit: | 653 | LExit: |
639 | return hr; | 654 | return hr; |
@@ -650,7 +665,7 @@ LExit: | |||
650 | ********************************************************************/ | 665 | ********************************************************************/ |
651 | extern "C" HRESULT DAPI WiuEnumRelatedProductCodes( | 666 | extern "C" HRESULT DAPI WiuEnumRelatedProductCodes( |
652 | __in_z LPCWSTR wzUpgradeCode, | 667 | __in_z LPCWSTR wzUpgradeCode, |
653 | __deref_out_ecount_opt(pcRelatedProducts) LPWSTR** prgsczProductCodes, | 668 | __deref_out_ecount_opt(*pcRelatedProducts) LPWSTR** prgsczProductCodes, |
654 | __out DWORD* pcRelatedProducts, | 669 | __out DWORD* pcRelatedProducts, |
655 | __in BOOL fReturnHighestVersionOnly | 670 | __in BOOL fReturnHighestVersionOnly |
656 | ) | 671 | ) |
@@ -673,16 +688,16 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes( | |||
673 | hr = S_OK; | 688 | hr = S_OK; |
674 | break; | 689 | break; |
675 | } | 690 | } |
676 | ExitOnFailure(hr, "Failed to enumerate related products for upgrade code: %ls", wzUpgradeCode); | 691 | WiuExitOnFailure(hr, "Failed to enumerate related products for upgrade code: %ls", wzUpgradeCode); |
677 | 692 | ||
678 | if (fReturnHighestVersionOnly) | 693 | if (fReturnHighestVersionOnly) |
679 | { | 694 | { |
680 | // get the version | 695 | // get the version |
681 | hr = WiuGetProductInfo(wzCurrentProductCode, L"VersionString", &sczInstalledVersion); | 696 | hr = WiuGetProductInfo(wzCurrentProductCode, L"VersionString", &sczInstalledVersion); |
682 | ExitOnFailure(hr, "Failed to get version for product code: %ls", wzCurrentProductCode); | 697 | WiuExitOnFailure(hr, "Failed to get version for product code: %ls", wzCurrentProductCode); |
683 | 698 | ||
684 | hr = FileVersionFromStringEx(sczInstalledVersion, 0, &qwCurrentVersion); | 699 | hr = FileVersionFromStringEx(sczInstalledVersion, 0, &qwCurrentVersion); |
685 | ExitOnFailure(hr, "Failed to convert version: %ls to DWORD64 for product code: %ls", sczInstalledVersion, wzCurrentProductCode); | 700 | WiuExitOnFailure(hr, "Failed to convert version: %ls to DWORD64 for product code: %ls", sczInstalledVersion, wzCurrentProductCode); |
686 | 701 | ||
687 | // if this is the first product found then it is the highest version (for now) | 702 | // if this is the first product found then it is the highest version (for now) |
688 | if (0 == *pcRelatedProducts) | 703 | if (0 == *pcRelatedProducts) |
@@ -698,7 +713,7 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes( | |||
698 | qwHighestVersion = qwCurrentVersion; | 713 | qwHighestVersion = qwCurrentVersion; |
699 | 714 | ||
700 | hr = StrAllocString(prgsczProductCodes[0], wzCurrentProductCode, 0); | 715 | hr = StrAllocString(prgsczProductCodes[0], wzCurrentProductCode, 0); |
701 | ExitOnFailure(hr, "Failed to update array with higher versioned product code."); | 716 | WiuExitOnFailure(hr, "Failed to update array with higher versioned product code."); |
702 | } | 717 | } |
703 | 718 | ||
704 | // continue here as we don't want anything else added to the list | 719 | // continue here as we don't want anything else added to the list |
@@ -707,7 +722,7 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes( | |||
707 | } | 722 | } |
708 | 723 | ||
709 | hr = StrArrayAllocString(prgsczProductCodes, (LPUINT)(pcRelatedProducts), wzCurrentProductCode, 0); | 724 | hr = StrArrayAllocString(prgsczProductCodes, (LPUINT)(pcRelatedProducts), wzCurrentProductCode, 0); |
710 | ExitOnFailure(hr, "Failed to add product code to array."); | 725 | WiuExitOnFailure(hr, "Failed to add product code to array."); |
711 | } | 726 | } |
712 | 727 | ||
713 | LExit: | 728 | LExit: |
@@ -726,7 +741,7 @@ extern "C" HRESULT DAPI WiuEnableLog( | |||
726 | DWORD er = ERROR_SUCCESS; | 741 | DWORD er = ERROR_SUCCESS; |
727 | 742 | ||
728 | er = vpfnMsiEnableLogW(dwLogMode, wzLogFile, dwLogAttributes); | 743 | er = vpfnMsiEnableLogW(dwLogMode, wzLogFile, dwLogAttributes); |
729 | ExitOnWin32Error(er, hr, "Failed to enable MSI internal logging."); | 744 | WiuExitOnWin32Error(er, hr, "Failed to enable MSI internal logging."); |
730 | 745 | ||
731 | LExit: | 746 | LExit: |
732 | return hr; | 747 | return hr; |
@@ -780,7 +795,7 @@ extern "C" HRESULT DAPI WiuInitializeExternalUI( | |||
780 | 795 | ||
781 | // Wire the internal and external UI handler. | 796 | // Wire the internal and external UI handler. |
782 | hr = WiuInitializeInternalUI(internalUILevel, hwndParent, pExecuteContext); | 797 | hr = WiuInitializeInternalUI(internalUILevel, hwndParent, pExecuteContext); |
783 | ExitOnFailure(hr, "Failed to set internal UI level and window."); | 798 | WiuExitOnFailure(hr, "Failed to set internal UI level and window."); |
784 | 799 | ||
785 | pExecuteContext->fRollback = fRollback; | 800 | pExecuteContext->fRollback = fRollback; |
786 | pExecuteContext->pfnMessageHandler = pfnMessageHandler; | 801 | pExecuteContext->pfnMessageHandler = pfnMessageHandler; |
@@ -791,7 +806,7 @@ extern "C" HRESULT DAPI WiuInitializeExternalUI( | |||
791 | if (vpfnMsiSetExternalUIRecord) | 806 | if (vpfnMsiSetExternalUIRecord) |
792 | { | 807 | { |
793 | er = vpfnMsiSetExternalUIRecord(InstallEngineRecordCallback, dwMessageFilter, pExecuteContext, &pExecuteContext->pfnPreviousExternalUIRecord); | 808 | er = vpfnMsiSetExternalUIRecord(InstallEngineRecordCallback, dwMessageFilter, pExecuteContext, &pExecuteContext->pfnPreviousExternalUIRecord); |
794 | ExitOnWin32Error(er, hr, "Failed to wire up external UI record handler."); | 809 | WiuExitOnWin32Error(er, hr, "Failed to wire up external UI record handler."); |
795 | pExecuteContext->fSetPreviousExternalUIRecord = TRUE; | 810 | pExecuteContext->fSetPreviousExternalUIRecord = TRUE; |
796 | } | 811 | } |
797 | else | 812 | else |
@@ -841,7 +856,7 @@ extern "C" HRESULT DAPI WiuConfigureProductEx( | |||
841 | 856 | ||
842 | er = vpfnMsiConfigureProductExW(wzProduct, iInstallLevel, eInstallState, wzCommandLine); | 857 | er = vpfnMsiConfigureProductExW(wzProduct, iInstallLevel, eInstallState, wzCommandLine); |
843 | er = CheckForRestartErrorCode(er, pRestart); | 858 | er = CheckForRestartErrorCode(er, pRestart); |
844 | ExitOnWin32Error(er, hr, "Failed to configure product: %ls", wzProduct); | 859 | WiuExitOnWin32Error(er, hr, "Failed to configure product: %ls", wzProduct); |
845 | 860 | ||
846 | LExit: | 861 | LExit: |
847 | return hr; | 862 | return hr; |
@@ -859,7 +874,7 @@ extern "C" HRESULT DAPI WiuInstallProduct( | |||
859 | 874 | ||
860 | er = vpfnMsiInstallProductW(wzPackagePath, wzCommandLine); | 875 | er = vpfnMsiInstallProductW(wzPackagePath, wzCommandLine); |
861 | er = CheckForRestartErrorCode(er, pRestart); | 876 | er = CheckForRestartErrorCode(er, pRestart); |
862 | ExitOnWin32Error(er, hr, "Failed to install product: %ls", wzPackagePath); | 877 | WiuExitOnWin32Error(er, hr, "Failed to install product: %ls", wzPackagePath); |
863 | 878 | ||
864 | LExit: | 879 | LExit: |
865 | return hr; | 880 | return hr; |
@@ -878,7 +893,7 @@ extern "C" HRESULT DAPI WiuRemovePatches( | |||
878 | 893 | ||
879 | er = vpfnMsiRemovePatchesW(wzPatchList, wzProductCode, INSTALLTYPE_SINGLE_INSTANCE, wzPropertyList); | 894 | er = vpfnMsiRemovePatchesW(wzPatchList, wzProductCode, INSTALLTYPE_SINGLE_INSTANCE, wzPropertyList); |
880 | er = CheckForRestartErrorCode(er, pRestart); | 895 | er = CheckForRestartErrorCode(er, pRestart); |
881 | ExitOnWin32Error(er, hr, "Failed to remove patches."); | 896 | WiuExitOnWin32Error(er, hr, "Failed to remove patches."); |
882 | 897 | ||
883 | LExit: | 898 | LExit: |
884 | return hr; | 899 | return hr; |
@@ -898,7 +913,7 @@ extern "C" HRESULT DAPI WiuSourceListAddSourceEx( | |||
898 | DWORD er = ERROR_SUCCESS; | 913 | DWORD er = ERROR_SUCCESS; |
899 | 914 | ||
900 | er = vpfnMsiSourceListAddSourceExW(wzProductCodeOrPatchCode, wzUserSid, dwContext, MSISOURCETYPE_NETWORK | dwCode, wzSource, dwIndex); | 915 | er = vpfnMsiSourceListAddSourceExW(wzProductCodeOrPatchCode, wzUserSid, dwContext, MSISOURCETYPE_NETWORK | dwCode, wzSource, dwIndex); |
901 | ExitOnWin32Error(er, hr, "Failed to add source."); | 916 | WiuExitOnWin32Error(er, hr, "Failed to add source."); |
902 | 917 | ||
903 | LExit: | 918 | LExit: |
904 | return hr; | 919 | return hr; |
@@ -924,14 +939,14 @@ extern "C" HRESULT DAPI WiuBeginTransaction( | |||
924 | 939 | ||
925 | if (!WiuIsMsiTransactionSupported()) | 940 | if (!WiuIsMsiTransactionSupported()) |
926 | { | 941 | { |
927 | ExitOnFailure(hr = E_NOTIMPL, "Msi transactions are not supported"); | 942 | WiuExitOnFailure(hr = E_NOTIMPL, "Msi transactions are not supported"); |
928 | } | 943 | } |
929 | 944 | ||
930 | hr = WiuEnableLog(dwLogMode, szLogPath, INSTALLLOGATTRIBUTES_APPEND); | 945 | hr = WiuEnableLog(dwLogMode, szLogPath, INSTALLLOGATTRIBUTES_APPEND); |
931 | ExitOnFailure(hr, "Failed to enable logging for MSI transaction"); | 946 | WiuExitOnFailure(hr, "Failed to enable logging for MSI transaction"); |
932 | 947 | ||
933 | er = vpfnMsiBeginTransaction(szName, dwTransactionAttributes, phTransactionHandle, phChangeOfOwnerEvent); | 948 | er = vpfnMsiBeginTransaction(szName, dwTransactionAttributes, phTransactionHandle, phChangeOfOwnerEvent); |
934 | ExitOnWin32Error(er, hr, "Failed to begin transaction."); | 949 | WiuExitOnWin32Error(er, hr, "Failed to begin transaction."); |
935 | 950 | ||
936 | LExit: | 951 | LExit: |
937 | return hr; | 952 | return hr; |
@@ -948,14 +963,14 @@ extern "C" HRESULT DAPI WiuEndTransaction( | |||
948 | 963 | ||
949 | if (!WiuIsMsiTransactionSupported()) | 964 | if (!WiuIsMsiTransactionSupported()) |
950 | { | 965 | { |
951 | ExitOnFailure(hr = E_NOTIMPL, "Msi transactions are not supported"); | 966 | WiuExitOnFailure(hr = E_NOTIMPL, "Msi transactions are not supported"); |
952 | } | 967 | } |
953 | 968 | ||
954 | hr = WiuEnableLog(dwLogMode, szLogPath, INSTALLLOGATTRIBUTES_APPEND); | 969 | hr = WiuEnableLog(dwLogMode, szLogPath, INSTALLLOGATTRIBUTES_APPEND); |
955 | ExitOnFailure(hr, "Failed to enable logging for MSI transaction"); | 970 | WiuExitOnFailure(hr, "Failed to enable logging for MSI transaction"); |
956 | 971 | ||
957 | er = vpfnMsiEndTransaction(dwTransactionState); | 972 | er = vpfnMsiEndTransaction(dwTransactionState); |
958 | ExitOnWin32Error(er, hr, "Failed to end transaction."); | 973 | WiuExitOnWin32Error(er, hr, "Failed to end transaction."); |
959 | 974 | ||
960 | LExit: | 975 | LExit: |
961 | return hr; | 976 | return hr; |
@@ -1048,10 +1063,10 @@ static INT CALLBACK InstallEngineRecordCallback( | |||
1048 | { | 1063 | { |
1049 | hr = HRESULT_FROM_WIN32(er); | 1064 | hr = HRESULT_FROM_WIN32(er); |
1050 | } | 1065 | } |
1051 | ExitOnFailure(hr, "Failed to allocate string for formated message."); | 1066 | WiuExitOnFailure(hr, "Failed to allocate string for formated message."); |
1052 | 1067 | ||
1053 | er = ::MsiFormatRecordW(NULL, hRecord, sczMessage, &cchMessage); | 1068 | er = ::MsiFormatRecordW(NULL, hRecord, sczMessage, &cchMessage); |
1054 | ExitOnWin32Error(er, hr, "Failed to format message record."); | 1069 | WiuExitOnWin32Error(er, hr, "Failed to format message record."); |
1055 | 1070 | ||
1056 | // Pass to handler including both the formated message and the original record. | 1071 | // Pass to handler including both the formated message and the original record. |
1057 | nResult = HandleInstallMessage(pContext, mt, uiFlags, sczMessage, hRecord); | 1072 | nResult = HandleInstallMessage(pContext, mt, uiFlags, sczMessage, hRecord); |
@@ -1213,7 +1228,7 @@ static INT HandleInstallProgress( | |||
1213 | 1228 | ||
1214 | // parse number | 1229 | // parse number |
1215 | hr = StrStringToInt32(pwz, cch, &iFields[cFields]); | 1230 | hr = StrStringToInt32(pwz, cch, &iFields[cFields]); |
1216 | ExitOnFailure(hr, "Failed to parse MSI message part."); | 1231 | WiuExitOnFailure(hr, "Failed to parse MSI message part."); |
1217 | 1232 | ||
1218 | // increment field count | 1233 | // increment field count |
1219 | ++cFields; | 1234 | ++cFields; |
@@ -1255,7 +1270,7 @@ static INT HandleInstallProgress( | |||
1255 | else | 1270 | else |
1256 | { | 1271 | { |
1257 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | 1272 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); |
1258 | ExitOnRootFailure(hr, "Insufficient space to hold progress information."); | 1273 | WiuExitOnRootFailure(hr, "Insufficient space to hold progress information."); |
1259 | } | 1274 | } |
1260 | 1275 | ||
1261 | // we only care about the first stage after script execution has started | 1276 | // we only care about the first stage after script execution has started |
diff --git a/src/dutil/wuautil.cpp b/src/dutil/wuautil.cpp index 94ab659d..dfb28818 100644 --- a/src/dutil/wuautil.cpp +++ b/src/dutil/wuautil.cpp | |||
@@ -3,6 +3,21 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | 5 | ||
6 | // Exit macros | ||
7 | #define WuaExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__) | ||
8 | #define WuaExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__) | ||
9 | #define WuaExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__) | ||
10 | #define WuaExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__) | ||
11 | #define WuaExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__) | ||
12 | #define WuaExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_WUAUTIL, x, s, __VA_ARGS__) | ||
13 | #define WuaExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_WUAUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define WuaExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_WUAUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define WuaExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_WUAUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define WuaExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_WUAUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define WuaExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_WUAUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define WuaExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_WUAUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
20 | |||
6 | // internal function declarations | 21 | // internal function declarations |
7 | 22 | ||
8 | static HRESULT GetAutomaticUpdatesService( | 23 | static HRESULT GetAutomaticUpdatesService( |
@@ -18,10 +33,10 @@ extern "C" HRESULT DAPI WuaPauseAutomaticUpdates() | |||
18 | IAutomaticUpdates *pAutomaticUpdates = NULL; | 33 | IAutomaticUpdates *pAutomaticUpdates = NULL; |
19 | 34 | ||
20 | hr = GetAutomaticUpdatesService(&pAutomaticUpdates); | 35 | hr = GetAutomaticUpdatesService(&pAutomaticUpdates); |
21 | ExitOnFailure(hr, "Failed to get the Automatic Updates service."); | 36 | WuaExitOnFailure(hr, "Failed to get the Automatic Updates service."); |
22 | 37 | ||
23 | hr = pAutomaticUpdates->Pause(); | 38 | hr = pAutomaticUpdates->Pause(); |
24 | ExitOnFailure(hr, "Failed to pause the Automatic Updates service."); | 39 | WuaExitOnFailure(hr, "Failed to pause the Automatic Updates service."); |
25 | 40 | ||
26 | LExit: | 41 | LExit: |
27 | ReleaseObject(pAutomaticUpdates); | 42 | ReleaseObject(pAutomaticUpdates); |
@@ -35,10 +50,10 @@ extern "C" HRESULT DAPI WuaResumeAutomaticUpdates() | |||
35 | IAutomaticUpdates *pAutomaticUpdates = NULL; | 50 | IAutomaticUpdates *pAutomaticUpdates = NULL; |
36 | 51 | ||
37 | hr = GetAutomaticUpdatesService(&pAutomaticUpdates); | 52 | hr = GetAutomaticUpdatesService(&pAutomaticUpdates); |
38 | ExitOnFailure(hr, "Failed to get the Automatic Updates service."); | 53 | WuaExitOnFailure(hr, "Failed to get the Automatic Updates service."); |
39 | 54 | ||
40 | hr = pAutomaticUpdates->Resume(); | 55 | hr = pAutomaticUpdates->Resume(); |
41 | ExitOnFailure(hr, "Failed to resume the Automatic Updates service."); | 56 | WuaExitOnFailure(hr, "Failed to resume the Automatic Updates service."); |
42 | 57 | ||
43 | LExit: | 58 | LExit: |
44 | ReleaseObject(pAutomaticUpdates); | 59 | ReleaseObject(pAutomaticUpdates); |
@@ -55,10 +70,10 @@ extern "C" HRESULT DAPI WuaRestartRequired( | |||
55 | VARIANT_BOOL bRestartRequired; | 70 | VARIANT_BOOL bRestartRequired; |
56 | 71 | ||
57 | hr = ::CoCreateInstance(__uuidof(SystemInformation), NULL, CLSCTX_INPROC_SERVER, __uuidof(ISystemInformation), reinterpret_cast<LPVOID*>(&pSystemInformation)); | 72 | hr = ::CoCreateInstance(__uuidof(SystemInformation), NULL, CLSCTX_INPROC_SERVER, __uuidof(ISystemInformation), reinterpret_cast<LPVOID*>(&pSystemInformation)); |
58 | ExitOnRootFailure(hr, "Failed to get WUA system information interface."); | 73 | WuaExitOnRootFailure(hr, "Failed to get WUA system information interface."); |
59 | 74 | ||
60 | hr = pSystemInformation->get_RebootRequired(&bRestartRequired); | 75 | hr = pSystemInformation->get_RebootRequired(&bRestartRequired); |
61 | ExitOnRootFailure(hr, "Failed to determine if restart is required from WUA."); | 76 | WuaExitOnRootFailure(hr, "Failed to determine if restart is required from WUA."); |
62 | 77 | ||
63 | *pfRestartRequired = (VARIANT_FALSE != bRestartRequired); | 78 | *pfRestartRequired = (VARIANT_FALSE != bRestartRequired); |
64 | 79 | ||
@@ -79,10 +94,10 @@ static HRESULT GetAutomaticUpdatesService( | |||
79 | CLSID clsidAutomaticUpdates = { }; | 94 | CLSID clsidAutomaticUpdates = { }; |
80 | 95 | ||
81 | hr = ::CLSIDFromProgID(L"Microsoft.Update.AutoUpdate", &clsidAutomaticUpdates); | 96 | hr = ::CLSIDFromProgID(L"Microsoft.Update.AutoUpdate", &clsidAutomaticUpdates); |
82 | ExitOnFailure(hr, "Failed to get CLSID for Microsoft.Update.AutoUpdate."); | 97 | WuaExitOnFailure(hr, "Failed to get CLSID for Microsoft.Update.AutoUpdate."); |
83 | 98 | ||
84 | hr = ::CoCreateInstance(clsidAutomaticUpdates, NULL, CLSCTX_INPROC_SERVER, IID_IAutomaticUpdates, reinterpret_cast<LPVOID*>(ppAutomaticUpdates)); | 99 | hr = ::CoCreateInstance(clsidAutomaticUpdates, NULL, CLSCTX_INPROC_SERVER, IID_IAutomaticUpdates, reinterpret_cast<LPVOID*>(ppAutomaticUpdates)); |
85 | ExitOnFailure(hr, "Failed to create instance of Microsoft.Update.AutoUpdate."); | 100 | WuaExitOnFailure(hr, "Failed to create instance of Microsoft.Update.AutoUpdate."); |
86 | 101 | ||
87 | LExit: | 102 | LExit: |
88 | return hr; | 103 | return hr; |
diff --git a/src/dutil/xmlutil.cpp b/src/dutil/xmlutil.cpp index f97ca962..6ecd2449 100644 --- a/src/dutil/xmlutil.cpp +++ b/src/dutil/xmlutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define XmlExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__) | ||
8 | #define XmlExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__) | ||
9 | #define XmlExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__) | ||
10 | #define XmlExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__) | ||
11 | #define XmlExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__) | ||
12 | #define XmlExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__) | ||
13 | #define XmlExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_XMLUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define XmlExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_XMLUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define XmlExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_XMLUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define XmlExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_XMLUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define XmlExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_XMLUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define XmlExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_XMLUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | // intialization globals | 20 | // intialization globals |
6 | CLSID vclsidXMLDOM = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0} }; | 21 | CLSID vclsidXMLDOM = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0} }; |
7 | static volatile LONG vcXmlInitialized = 0; | 22 | static volatile LONG vcXmlInitialized = 0; |
@@ -23,7 +38,7 @@ extern "C" HRESULT DAPI XmlInitialize( | |||
23 | hr = ::CoInitialize(0); | 38 | hr = ::CoInitialize(0); |
24 | if (RPC_E_CHANGED_MODE != hr) | 39 | if (RPC_E_CHANGED_MODE != hr) |
25 | { | 40 | { |
26 | ExitOnFailure(hr, "failed to initialize COM"); | 41 | XmlExitOnFailure(hr, "failed to initialize COM"); |
27 | fComInitialized = TRUE; | 42 | fComInitialized = TRUE; |
28 | } | 43 | } |
29 | } | 44 | } |
@@ -47,7 +62,7 @@ extern "C" HRESULT DAPI XmlInitialize( | |||
47 | // try to fall back to old MSXML | 62 | // try to fall back to old MSXML |
48 | hr = ::CLSIDFromProgID(L"MSXML.DOMDocument", &vclsidXMLDOM); | 63 | hr = ::CLSIDFromProgID(L"MSXML.DOMDocument", &vclsidXMLDOM); |
49 | } | 64 | } |
50 | ExitOnFailure(hr, "failed to get CLSID for XML DOM"); | 65 | XmlExitOnFailure(hr, "failed to get CLSID for XML DOM"); |
51 | 66 | ||
52 | Assert(IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument) || | 67 | Assert(IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument) || |
53 | IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument20) || | 68 | IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument20) || |
@@ -99,7 +114,7 @@ extern "C" HRESULT DAPI XmlCreateElement( | |||
99 | 114 | ||
100 | HRESULT hr = S_OK; | 115 | HRESULT hr = S_OK; |
101 | BSTR bstrElementName = ::SysAllocString(wzElementName); | 116 | BSTR bstrElementName = ::SysAllocString(wzElementName); |
102 | ExitOnNull(bstrElementName, hr, E_OUTOFMEMORY, "failed SysAllocString"); | 117 | XmlExitOnNull(bstrElementName, hr, E_OUTOFMEMORY, "failed SysAllocString"); |
103 | hr = pixdDocument->createElement(bstrElementName, ppixnElement); | 118 | hr = pixdDocument->createElement(bstrElementName, ppixnElement); |
104 | LExit: | 119 | LExit: |
105 | ReleaseBSTR(bstrElementName); | 120 | ReleaseBSTR(bstrElementName); |
@@ -130,7 +145,7 @@ extern "C" HRESULT DAPI XmlCreateDocument( | |||
130 | 145 | ||
131 | // Test if we have access to the Wow64 API, and store the result in fWow64Available | 146 | // Test if we have access to the Wow64 API, and store the result in fWow64Available |
132 | HMODULE hKernel32 = ::GetModuleHandleA("kernel32.dll"); | 147 | HMODULE hKernel32 = ::GetModuleHandleA("kernel32.dll"); |
133 | ExitOnNullWithLastError(hKernel32, hr, "failed to get handle to kernel32.dll"); | 148 | XmlExitOnNullWithLastError(hKernel32, hr, "failed to get handle to kernel32.dll"); |
134 | 149 | ||
135 | // This will test if we have access to the Wow64 API | 150 | // This will test if we have access to the Wow64 API |
136 | if (NULL != GetProcAddress(hKernel32, "IsWow64Process")) | 151 | if (NULL != GetProcAddress(hKernel32, "IsWow64Process")) |
@@ -155,7 +170,7 @@ extern "C" HRESULT DAPI XmlCreateDocument( | |||
155 | } | 170 | } |
156 | 171 | ||
157 | hr = ::CoCreateInstance(vclsidXMLDOM, NULL, CLSCTX_INPROC_SERVER, XmlUtil_IID_IXMLDOMDocument, (void**)&pixdDocument); | 172 | hr = ::CoCreateInstance(vclsidXMLDOM, NULL, CLSCTX_INPROC_SERVER, XmlUtil_IID_IXMLDOMDocument, (void**)&pixdDocument); |
158 | ExitOnFailure(hr, "failed to create XML DOM Document"); | 173 | XmlExitOnFailure(hr, "failed to create XML DOM Document"); |
159 | Assert(pixdDocument); | 174 | Assert(pixdDocument); |
160 | 175 | ||
161 | if (IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument30) || IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument20)) | 176 | if (IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument30) || IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument20)) |
@@ -166,9 +181,9 @@ extern "C" HRESULT DAPI XmlCreateDocument( | |||
166 | if (pwzElementName) | 181 | if (pwzElementName) |
167 | { | 182 | { |
168 | hr = XmlCreateElement(pixdDocument, pwzElementName, &pixeRootElement); | 183 | hr = XmlCreateElement(pixdDocument, pwzElementName, &pixeRootElement); |
169 | ExitOnFailure(hr, "failed XmlCreateElement"); | 184 | XmlExitOnFailure(hr, "failed XmlCreateElement"); |
170 | hr = pixdDocument->appendChild(pixeRootElement, NULL); | 185 | hr = pixdDocument->appendChild(pixeRootElement, NULL); |
171 | ExitOnFailure(hr, "failed appendChild"); | 186 | XmlExitOnFailure(hr, "failed appendChild"); |
172 | } | 187 | } |
173 | 188 | ||
174 | *ppixdDocument = pixdDocument; | 189 | *ppixdDocument = pixdDocument; |
@@ -222,28 +237,28 @@ static void XmlReportParseError( | |||
222 | Trace(REPORT_STANDARD, "Failed to parse XML. IXMLDOMParseError reports:"); | 237 | Trace(REPORT_STANDARD, "Failed to parse XML. IXMLDOMParseError reports:"); |
223 | 238 | ||
224 | hr = pixpe->get_errorCode(&lNumber); | 239 | hr = pixpe->get_errorCode(&lNumber); |
225 | ExitOnFailure(hr, "Failed to query IXMLDOMParseError.errorCode."); | 240 | XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.errorCode."); |
226 | Trace(REPORT_STANDARD, "errorCode = 0x%x", lNumber); | 241 | Trace(REPORT_STANDARD, "errorCode = 0x%x", lNumber); |
227 | 242 | ||
228 | hr = pixpe->get_filepos(&lNumber); | 243 | hr = pixpe->get_filepos(&lNumber); |
229 | ExitOnFailure(hr, "Failed to query IXMLDOMParseError.filepos."); | 244 | XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.filepos."); |
230 | Trace(REPORT_STANDARD, "filepos = %d", lNumber); | 245 | Trace(REPORT_STANDARD, "filepos = %d", lNumber); |
231 | 246 | ||
232 | hr = pixpe->get_line(&lNumber); | 247 | hr = pixpe->get_line(&lNumber); |
233 | ExitOnFailure(hr, "Failed to query IXMLDOMParseError.line."); | 248 | XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.line."); |
234 | Trace(REPORT_STANDARD, "line = %d", lNumber); | 249 | Trace(REPORT_STANDARD, "line = %d", lNumber); |
235 | 250 | ||
236 | hr = pixpe->get_linepos(&lNumber); | 251 | hr = pixpe->get_linepos(&lNumber); |
237 | ExitOnFailure(hr, "Failed to query IXMLDOMParseError.linepos."); | 252 | XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.linepos."); |
238 | Trace(REPORT_STANDARD, "linepos = %d", lNumber); | 253 | Trace(REPORT_STANDARD, "linepos = %d", lNumber); |
239 | 254 | ||
240 | hr = pixpe->get_reason(&bstr); | 255 | hr = pixpe->get_reason(&bstr); |
241 | ExitOnFailure(hr, "Failed to query IXMLDOMParseError.reason."); | 256 | XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.reason."); |
242 | Trace(REPORT_STANDARD, "reason = %ls", bstr); | 257 | Trace(REPORT_STANDARD, "reason = %ls", bstr); |
243 | ReleaseNullBSTR(bstr); | 258 | ReleaseNullBSTR(bstr); |
244 | 259 | ||
245 | hr = pixpe->get_srcText (&bstr); | 260 | hr = pixpe->get_srcText (&bstr); |
246 | ExitOnFailure(hr, "Failed to query IXMLDOMParseError.srcText ."); | 261 | XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.srcText ."); |
247 | Trace(REPORT_STANDARD, "srcText = %ls", bstr); | 262 | Trace(REPORT_STANDARD, "srcText = %ls", bstr); |
248 | ReleaseNullBSTR(bstr); | 263 | ReleaseNullBSTR(bstr); |
249 | 264 | ||
@@ -272,7 +287,7 @@ extern "C" HRESULT DAPI XmlLoadDocumentEx( | |||
272 | if (!wzDocument || !*wzDocument) | 287 | if (!wzDocument || !*wzDocument) |
273 | { | 288 | { |
274 | hr = E_UNEXPECTED; | 289 | hr = E_UNEXPECTED; |
275 | ExitOnFailure(hr, "string must be non-null"); | 290 | XmlExitOnFailure(hr, "string must be non-null"); |
276 | } | 291 | } |
277 | 292 | ||
278 | hr = XmlCreateDocument(NULL, &pixd); | 293 | hr = XmlCreateDocument(NULL, &pixd); |
@@ -280,22 +295,22 @@ extern "C" HRESULT DAPI XmlLoadDocumentEx( | |||
280 | { | 295 | { |
281 | hr = E_FAIL; | 296 | hr = E_FAIL; |
282 | } | 297 | } |
283 | ExitOnFailure(hr, "failed XmlCreateDocument"); | 298 | XmlExitOnFailure(hr, "failed XmlCreateDocument"); |
284 | 299 | ||
285 | if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE) | 300 | if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE) |
286 | { | 301 | { |
287 | hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE); | 302 | hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE); |
288 | ExitOnFailure(hr, "failed put_preserveWhiteSpace"); | 303 | XmlExitOnFailure(hr, "failed put_preserveWhiteSpace"); |
289 | } | 304 | } |
290 | 305 | ||
291 | // Security issue. Avoid triggering anything external. | 306 | // Security issue. Avoid triggering anything external. |
292 | hr = pixd->put_validateOnParse(VARIANT_FALSE); | 307 | hr = pixd->put_validateOnParse(VARIANT_FALSE); |
293 | ExitOnFailure(hr, "failed put_validateOnParse"); | 308 | XmlExitOnFailure(hr, "failed put_validateOnParse"); |
294 | hr = pixd->put_resolveExternals(VARIANT_FALSE); | 309 | hr = pixd->put_resolveExternals(VARIANT_FALSE); |
295 | ExitOnFailure(hr, "failed put_resolveExternals"); | 310 | XmlExitOnFailure(hr, "failed put_resolveExternals"); |
296 | 311 | ||
297 | bstrLoad = ::SysAllocString(wzDocument); | 312 | bstrLoad = ::SysAllocString(wzDocument); |
298 | ExitOnNull(bstrLoad, hr, E_OUTOFMEMORY, "failed to allocate bstr for Load in XmlLoadDocumentEx"); | 313 | XmlExitOnNull(bstrLoad, hr, E_OUTOFMEMORY, "failed to allocate bstr for Load in XmlLoadDocumentEx"); |
299 | 314 | ||
300 | hr = pixd->loadXML(bstrLoad, &vbSuccess); | 315 | hr = pixd->loadXML(bstrLoad, &vbSuccess); |
301 | if (S_FALSE == hr) | 316 | if (S_FALSE == hr) |
@@ -308,7 +323,7 @@ extern "C" HRESULT DAPI XmlLoadDocumentEx( | |||
308 | XmlReportParseError(pixpe); | 323 | XmlReportParseError(pixpe); |
309 | } | 324 | } |
310 | 325 | ||
311 | ExitOnFailure(hr, "failed loadXML"); | 326 | XmlExitOnFailure(hr, "failed loadXML"); |
312 | 327 | ||
313 | 328 | ||
314 | hr = S_OK; | 329 | hr = S_OK; |
@@ -359,26 +374,26 @@ extern "C" HRESULT DAPI XmlLoadDocumentFromFileEx( | |||
359 | ::VariantInit(&varPath); | 374 | ::VariantInit(&varPath); |
360 | varPath.vt = VT_BSTR; | 375 | varPath.vt = VT_BSTR; |
361 | varPath.bstrVal = ::SysAllocString(wzPath); | 376 | varPath.bstrVal = ::SysAllocString(wzPath); |
362 | ExitOnNull(varPath.bstrVal, hr, E_OUTOFMEMORY, "failed to allocate bstr for Path in XmlLoadDocumentFromFileEx"); | 377 | XmlExitOnNull(varPath.bstrVal, hr, E_OUTOFMEMORY, "failed to allocate bstr for Path in XmlLoadDocumentFromFileEx"); |
363 | 378 | ||
364 | hr = XmlCreateDocument(NULL, &pixd); | 379 | hr = XmlCreateDocument(NULL, &pixd); |
365 | if (hr == S_FALSE) | 380 | if (hr == S_FALSE) |
366 | { | 381 | { |
367 | hr = E_FAIL; | 382 | hr = E_FAIL; |
368 | } | 383 | } |
369 | ExitOnFailure(hr, "failed XmlCreateDocument"); | 384 | XmlExitOnFailure(hr, "failed XmlCreateDocument"); |
370 | 385 | ||
371 | if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE) | 386 | if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE) |
372 | { | 387 | { |
373 | hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE); | 388 | hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE); |
374 | ExitOnFailure(hr, "failed put_preserveWhiteSpace"); | 389 | XmlExitOnFailure(hr, "failed put_preserveWhiteSpace"); |
375 | } | 390 | } |
376 | 391 | ||
377 | // Avoid triggering anything external. | 392 | // Avoid triggering anything external. |
378 | hr = pixd->put_validateOnParse(VARIANT_FALSE); | 393 | hr = pixd->put_validateOnParse(VARIANT_FALSE); |
379 | ExitOnFailure(hr, "failed put_validateOnParse"); | 394 | XmlExitOnFailure(hr, "failed put_validateOnParse"); |
380 | hr = pixd->put_resolveExternals(VARIANT_FALSE); | 395 | hr = pixd->put_resolveExternals(VARIANT_FALSE); |
381 | ExitOnFailure(hr, "failed put_resolveExternals"); | 396 | XmlExitOnFailure(hr, "failed put_resolveExternals"); |
382 | 397 | ||
383 | pixd->put_async(VARIANT_FALSE); | 398 | pixd->put_async(VARIANT_FALSE); |
384 | hr = pixd->load(varPath, &vbSuccess); | 399 | hr = pixd->load(varPath, &vbSuccess); |
@@ -392,7 +407,7 @@ extern "C" HRESULT DAPI XmlLoadDocumentFromFileEx( | |||
392 | XmlReportParseError(pixpe); | 407 | XmlReportParseError(pixpe); |
393 | } | 408 | } |
394 | 409 | ||
395 | ExitOnFailure(hr, "failed to load XML from: %ls", wzPath); | 410 | XmlExitOnFailure(hr, "failed to load XML from: %ls", wzPath); |
396 | 411 | ||
397 | if (ppixdDocument) | 412 | if (ppixdDocument) |
398 | { | 413 | { |
@@ -434,13 +449,13 @@ extern "C" HRESULT DAPI XmlLoadDocumentFromBuffer( | |||
434 | { | 449 | { |
435 | hr = E_FAIL; | 450 | hr = E_FAIL; |
436 | } | 451 | } |
437 | ExitOnFailure(hr, "failed XmlCreateDocument"); | 452 | XmlExitOnFailure(hr, "failed XmlCreateDocument"); |
438 | 453 | ||
439 | // Security issue. Avoid triggering anything external. | 454 | // Security issue. Avoid triggering anything external. |
440 | hr = pixdDocument->put_validateOnParse(VARIANT_FALSE); | 455 | hr = pixdDocument->put_validateOnParse(VARIANT_FALSE); |
441 | ExitOnFailure(hr, "failed put_validateOnParse"); | 456 | XmlExitOnFailure(hr, "failed put_validateOnParse"); |
442 | hr = pixdDocument->put_resolveExternals(VARIANT_FALSE); | 457 | hr = pixdDocument->put_resolveExternals(VARIANT_FALSE); |
443 | ExitOnFailure(hr, "failed put_resolveExternals"); | 458 | XmlExitOnFailure(hr, "failed put_resolveExternals"); |
444 | 459 | ||
445 | // load document | 460 | // load document |
446 | sa.cDims = 1; | 461 | sa.cDims = 1; |
@@ -456,7 +471,7 @@ extern "C" HRESULT DAPI XmlLoadDocumentFromBuffer( | |||
456 | { | 471 | { |
457 | hr = HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); | 472 | hr = HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); |
458 | } | 473 | } |
459 | ExitOnFailure(hr, "failed loadXML"); | 474 | XmlExitOnFailure(hr, "failed loadXML"); |
460 | 475 | ||
461 | // return value | 476 | // return value |
462 | *ppixdDocument = pixdDocument; | 477 | *ppixdDocument = pixdDocument; |
@@ -488,20 +503,20 @@ extern "C" HRESULT DAPI XmlSetAttribute( | |||
488 | IXMLDOMAttribute* pixaAttribute = NULL; | 503 | IXMLDOMAttribute* pixaAttribute = NULL; |
489 | IXMLDOMNode* pixaNode = NULL; | 504 | IXMLDOMNode* pixaNode = NULL; |
490 | BSTR bstrAttributeName = ::SysAllocString(pwzAttribute); | 505 | BSTR bstrAttributeName = ::SysAllocString(pwzAttribute); |
491 | ExitOnNull(bstrAttributeName, hr, E_OUTOFMEMORY, "failed to allocate bstr for AttributeName in XmlSetAttribute"); | 506 | XmlExitOnNull(bstrAttributeName, hr, E_OUTOFMEMORY, "failed to allocate bstr for AttributeName in XmlSetAttribute"); |
492 | 507 | ||
493 | hr = pixnNode->get_attributes(&pixnnmAttributes); | 508 | hr = pixnNode->get_attributes(&pixnnmAttributes); |
494 | ExitOnFailure(hr, "failed get_attributes in XmlSetAttribute(%ls)", pwzAttribute); | 509 | XmlExitOnFailure(hr, "failed get_attributes in XmlSetAttribute(%ls)", pwzAttribute); |
495 | 510 | ||
496 | hr = pixnNode->get_ownerDocument(&pixdDocument); | 511 | hr = pixnNode->get_ownerDocument(&pixdDocument); |
497 | if (hr == S_FALSE) | 512 | if (hr == S_FALSE) |
498 | { | 513 | { |
499 | hr = E_FAIL; | 514 | hr = E_FAIL; |
500 | } | 515 | } |
501 | ExitOnFailure(hr, "failed get_ownerDocument in XmlSetAttribute"); | 516 | XmlExitOnFailure(hr, "failed get_ownerDocument in XmlSetAttribute"); |
502 | 517 | ||
503 | hr = pixdDocument->createAttribute(bstrAttributeName, &pixaAttribute); | 518 | hr = pixdDocument->createAttribute(bstrAttributeName, &pixaAttribute); |
504 | ExitOnFailure(hr, "failed createAttribute in XmlSetAttribute(%ls)", pwzAttribute); | 519 | XmlExitOnFailure(hr, "failed createAttribute in XmlSetAttribute(%ls)", pwzAttribute); |
505 | 520 | ||
506 | varAttributeValue.vt = VT_BSTR; | 521 | varAttributeValue.vt = VT_BSTR; |
507 | varAttributeValue.bstrVal = ::SysAllocString(pwzAttributeValue); | 522 | varAttributeValue.bstrVal = ::SysAllocString(pwzAttributeValue); |
@@ -509,13 +524,13 @@ extern "C" HRESULT DAPI XmlSetAttribute( | |||
509 | { | 524 | { |
510 | hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); | 525 | hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); |
511 | } | 526 | } |
512 | ExitOnFailure(hr, "failed SysAllocString in XmlSetAttribute"); | 527 | XmlExitOnFailure(hr, "failed SysAllocString in XmlSetAttribute"); |
513 | 528 | ||
514 | hr = pixaAttribute->put_nodeValue(varAttributeValue); | 529 | hr = pixaAttribute->put_nodeValue(varAttributeValue); |
515 | ExitOnFailure(hr, "failed put_nodeValue in XmlSetAttribute(%ls)", pwzAttribute); | 530 | XmlExitOnFailure(hr, "failed put_nodeValue in XmlSetAttribute(%ls)", pwzAttribute); |
516 | 531 | ||
517 | hr = pixnnmAttributes->setNamedItem(pixaAttribute, &pixaNode); | 532 | hr = pixnnmAttributes->setNamedItem(pixaAttribute, &pixaNode); |
518 | ExitOnFailure(hr, "failed setNamedItem in XmlSetAttribute(%ls)", pwzAttribute); | 533 | XmlExitOnFailure(hr, "failed setNamedItem in XmlSetAttribute(%ls)", pwzAttribute); |
519 | 534 | ||
520 | LExit: | 535 | LExit: |
521 | ReleaseObject(pixdDocument); | 536 | ReleaseObject(pixdDocument); |
@@ -543,11 +558,11 @@ extern "C" HRESULT DAPI XmlSelectSingleNode( | |||
543 | 558 | ||
544 | BSTR bstrXPath = NULL; | 559 | BSTR bstrXPath = NULL; |
545 | 560 | ||
546 | ExitOnNull(pixnParent, hr, E_UNEXPECTED, "pixnParent parameter was null in XmlSelectSingleNode"); | 561 | XmlExitOnNull(pixnParent, hr, E_UNEXPECTED, "pixnParent parameter was null in XmlSelectSingleNode"); |
547 | ExitOnNull(ppixnChild, hr, E_UNEXPECTED, "ppixnChild parameter was null in XmlSelectSingleNode"); | 562 | XmlExitOnNull(ppixnChild, hr, E_UNEXPECTED, "ppixnChild parameter was null in XmlSelectSingleNode"); |
548 | 563 | ||
549 | bstrXPath = ::SysAllocString(wzXPath ? wzXPath : L""); | 564 | bstrXPath = ::SysAllocString(wzXPath ? wzXPath : L""); |
550 | ExitOnNull(bstrXPath, hr, E_OUTOFMEMORY, "failed to allocate bstr for XPath expression in XmlSelectSingleNode"); | 565 | XmlExitOnNull(bstrXPath, hr, E_OUTOFMEMORY, "failed to allocate bstr for XPath expression in XmlSelectSingleNode"); |
551 | 566 | ||
552 | hr = pixnParent->selectSingleNode(bstrXPath, ppixnChild); | 567 | hr = pixnParent->selectSingleNode(bstrXPath, ppixnChild); |
553 | 568 | ||
@@ -575,7 +590,7 @@ extern "C" HRESULT DAPI XmlCreateTextNode( | |||
575 | 590 | ||
576 | HRESULT hr = S_OK; | 591 | HRESULT hr = S_OK; |
577 | BSTR bstrText = ::SysAllocString(wzText); | 592 | BSTR bstrText = ::SysAllocString(wzText); |
578 | ExitOnNull(bstrText, hr, E_OUTOFMEMORY, "failed SysAllocString"); | 593 | XmlExitOnNull(bstrText, hr, E_OUTOFMEMORY, "failed SysAllocString"); |
579 | hr = pixdDocument->createTextNode(bstrText, ppixnTextNode); | 594 | hr = pixdDocument->createTextNode(bstrText, ppixnTextNode); |
580 | LExit: | 595 | LExit: |
581 | ReleaseBSTR(bstrText); | 596 | ReleaseBSTR(bstrText); |
@@ -621,7 +636,7 @@ extern "C" HRESULT DAPI XmlGetAttribute( | |||
621 | 636 | ||
622 | // get attribute value from source | 637 | // get attribute value from source |
623 | hr = pixnNode->get_attributes(&pixnnmAttributes); | 638 | hr = pixnNode->get_attributes(&pixnnmAttributes); |
624 | ExitOnFailure(hr, "failed get_attributes"); | 639 | XmlExitOnFailure(hr, "failed get_attributes"); |
625 | 640 | ||
626 | hr = XmlGetNamedItem(pixnnmAttributes, bstrAttribute, &pixnAttribute); | 641 | hr = XmlGetNamedItem(pixnnmAttributes, bstrAttribute, &pixnAttribute); |
627 | if (S_FALSE == hr) | 642 | if (S_FALSE == hr) |
@@ -629,10 +644,10 @@ extern "C" HRESULT DAPI XmlGetAttribute( | |||
629 | // hr = E_FAIL; | 644 | // hr = E_FAIL; |
630 | ExitFunction(); | 645 | ExitFunction(); |
631 | } | 646 | } |
632 | ExitOnFailure(hr, "failed getNamedItem in XmlGetAttribute(%ls)", pwzAttribute); | 647 | XmlExitOnFailure(hr, "failed getNamedItem in XmlGetAttribute(%ls)", pwzAttribute); |
633 | 648 | ||
634 | hr = pixnAttribute->get_nodeValue(&varAttributeValue); | 649 | hr = pixnAttribute->get_nodeValue(&varAttributeValue); |
635 | ExitOnFailure(hr, "failed get_nodeValue in XmlGetAttribute(%ls)", pwzAttribute); | 650 | XmlExitOnFailure(hr, "failed get_nodeValue in XmlGetAttribute(%ls)", pwzAttribute); |
636 | 651 | ||
637 | // steal the BSTR from the VARIANT | 652 | // steal the BSTR from the VARIANT |
638 | if (S_OK == hr && pbstrAttributeValue) | 653 | if (S_OK == hr && pbstrAttributeValue) |
@@ -672,28 +687,28 @@ HRESULT DAPI XmlGetAttributeEx( | |||
672 | 687 | ||
673 | // get attribute value from source | 688 | // get attribute value from source |
674 | hr = pixnNode->get_attributes(&pixnnmAttributes); | 689 | hr = pixnNode->get_attributes(&pixnnmAttributes); |
675 | ExitOnFailure(hr, "Failed get_attributes."); | 690 | XmlExitOnFailure(hr, "Failed get_attributes."); |
676 | 691 | ||
677 | bstrAttribute = ::SysAllocString(wzAttribute); | 692 | bstrAttribute = ::SysAllocString(wzAttribute); |
678 | ExitOnNull(bstrAttribute, hr, E_OUTOFMEMORY, "Failed to allocate attribute name BSTR."); | 693 | XmlExitOnNull(bstrAttribute, hr, E_OUTOFMEMORY, "Failed to allocate attribute name BSTR."); |
679 | 694 | ||
680 | hr = XmlGetNamedItem(pixnnmAttributes, bstrAttribute, &pixnAttribute); | 695 | hr = XmlGetNamedItem(pixnnmAttributes, bstrAttribute, &pixnAttribute); |
681 | if (S_FALSE == hr) | 696 | if (S_FALSE == hr) |
682 | { | 697 | { |
683 | ExitFunction1(hr = E_NOTFOUND); | 698 | ExitFunction1(hr = E_NOTFOUND); |
684 | } | 699 | } |
685 | ExitOnFailure(hr, "Failed getNamedItem in XmlGetAttribute(%ls)", wzAttribute); | 700 | XmlExitOnFailure(hr, "Failed getNamedItem in XmlGetAttribute(%ls)", wzAttribute); |
686 | 701 | ||
687 | hr = pixnAttribute->get_nodeValue(&varAttributeValue); | 702 | hr = pixnAttribute->get_nodeValue(&varAttributeValue); |
688 | if (S_FALSE == hr) | 703 | if (S_FALSE == hr) |
689 | { | 704 | { |
690 | ExitFunction1(hr = E_NOTFOUND); | 705 | ExitFunction1(hr = E_NOTFOUND); |
691 | } | 706 | } |
692 | ExitOnFailure(hr, "Failed get_nodeValue in XmlGetAttribute(%ls)", wzAttribute); | 707 | XmlExitOnFailure(hr, "Failed get_nodeValue in XmlGetAttribute(%ls)", wzAttribute); |
693 | 708 | ||
694 | // copy value | 709 | // copy value |
695 | hr = StrAllocString(psczAttributeValue, varAttributeValue.bstrVal, 0); | 710 | hr = StrAllocString(psczAttributeValue, varAttributeValue.bstrVal, 0); |
696 | ExitOnFailure(hr, "Failed to copy attribute value."); | 711 | XmlExitOnFailure(hr, "Failed to copy attribute value."); |
697 | 712 | ||
698 | LExit: | 713 | LExit: |
699 | ReleaseObject(pixnnmAttributes); | 714 | ReleaseObject(pixnnmAttributes); |
@@ -721,7 +736,7 @@ HRESULT DAPI XmlGetYesNoAttribute( | |||
721 | hr = XmlGetAttributeEx(pixnNode, wzAttribute, &sczValue); | 736 | hr = XmlGetAttributeEx(pixnNode, wzAttribute, &sczValue); |
722 | if (E_NOTFOUND != hr) | 737 | if (E_NOTFOUND != hr) |
723 | { | 738 | { |
724 | ExitOnFailure(hr, "Failed to get attribute."); | 739 | XmlExitOnFailure(hr, "Failed to get attribute."); |
725 | 740 | ||
726 | *pfYes = CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, sczValue, -1, L"yes", -1); | 741 | *pfYes = CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, sczValue, -1, L"yes", -1); |
727 | } | 742 | } |
@@ -764,7 +779,7 @@ extern "C" HRESULT DAPI XmlGetAttributeNumberBase( | |||
764 | BSTR bstrPointer = NULL; | 779 | BSTR bstrPointer = NULL; |
765 | 780 | ||
766 | hr = XmlGetAttribute(pixnNode, pwzAttribute, &bstrPointer); | 781 | hr = XmlGetAttribute(pixnNode, pwzAttribute, &bstrPointer); |
767 | ExitOnFailure(hr, "Failed to get value from attribute."); | 782 | XmlExitOnFailure(hr, "Failed to get value from attribute."); |
768 | 783 | ||
769 | if (S_OK == hr) | 784 | if (S_OK == hr) |
770 | { | 785 | { |
@@ -791,13 +806,13 @@ extern "C" HRESULT DAPI XmlGetAttributeLargeNumber( | |||
791 | BSTR bstrValue = NULL; | 806 | BSTR bstrValue = NULL; |
792 | 807 | ||
793 | hr = XmlGetAttribute(pixnNode, pwzAttribute, &bstrValue); | 808 | hr = XmlGetAttribute(pixnNode, pwzAttribute, &bstrValue); |
794 | ExitOnFailure(hr, "failed XmlGetAttribute"); | 809 | XmlExitOnFailure(hr, "failed XmlGetAttribute"); |
795 | 810 | ||
796 | if (S_OK == hr) | 811 | if (S_OK == hr) |
797 | { | 812 | { |
798 | LONGLONG ll = 0; | 813 | LONGLONG ll = 0; |
799 | hr = StrStringToInt64(bstrValue, 0, &ll); | 814 | hr = StrStringToInt64(bstrValue, 0, &ll); |
800 | ExitOnFailure(hr, "Failed to treat attribute value as number."); | 815 | XmlExitOnFailure(hr, "Failed to treat attribute value as number."); |
801 | 816 | ||
802 | *pdw64Value = ll; | 817 | *pdw64Value = ll; |
803 | } | 818 | } |
@@ -829,7 +844,7 @@ extern "C" HRESULT DAPI XmlGetNamedItem( | |||
829 | 844 | ||
830 | HRESULT hr = S_OK; | 845 | HRESULT hr = S_OK; |
831 | BSTR bstrName = ::SysAllocString(wzName); | 846 | BSTR bstrName = ::SysAllocString(wzName); |
832 | ExitOnNull(bstrName, hr, E_OUTOFMEMORY, "failed SysAllocString"); | 847 | XmlExitOnNull(bstrName, hr, E_OUTOFMEMORY, "failed SysAllocString"); |
833 | 848 | ||
834 | hr = pixnmAttributes->getNamedItem(bstrName, ppixnNamedItem); | 849 | hr = pixnmAttributes->getNamedItem(bstrName, ppixnNamedItem); |
835 | 850 | ||
@@ -863,12 +878,12 @@ extern "C" HRESULT DAPI XmlSetText( | |||
863 | 878 | ||
864 | // find the text node | 879 | // find the text node |
865 | hr = pixnNode->get_childNodes(&pixnlNodeList); | 880 | hr = pixnNode->get_childNodes(&pixnlNodeList); |
866 | ExitOnFailure(hr, "failed to get child nodes"); | 881 | XmlExitOnFailure(hr, "failed to get child nodes"); |
867 | 882 | ||
868 | while (S_OK == (hr = pixnlNodeList->nextNode(&pixnChildNode))) | 883 | while (S_OK == (hr = pixnlNodeList->nextNode(&pixnChildNode))) |
869 | { | 884 | { |
870 | hr = pixnChildNode->get_nodeType(&dnType); | 885 | hr = pixnChildNode->get_nodeType(&dnType); |
871 | ExitOnFailure(hr, "failed to get node type"); | 886 | XmlExitOnFailure(hr, "failed to get node type"); |
872 | 887 | ||
873 | if (NODE_TEXT == dnType) | 888 | if (NODE_TEXT == dnType) |
874 | break; | 889 | break; |
@@ -887,10 +902,10 @@ extern "C" HRESULT DAPI XmlSetText( | |||
887 | { | 902 | { |
888 | hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); | 903 | hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); |
889 | } | 904 | } |
890 | ExitOnFailure(hr, "failed SysAllocString in XmlSetText"); | 905 | XmlExitOnFailure(hr, "failed SysAllocString in XmlSetText"); |
891 | 906 | ||
892 | hr = pixnChildNode->put_nodeValue(varText); | 907 | hr = pixnChildNode->put_nodeValue(varText); |
893 | ExitOnFailure(hr, "failed IXMLDOMNode::put_nodeValue"); | 908 | XmlExitOnFailure(hr, "failed IXMLDOMNode::put_nodeValue"); |
894 | } | 909 | } |
895 | else | 910 | else |
896 | { | 911 | { |
@@ -899,13 +914,13 @@ extern "C" HRESULT DAPI XmlSetText( | |||
899 | { | 914 | { |
900 | hr = E_FAIL; | 915 | hr = E_FAIL; |
901 | } | 916 | } |
902 | ExitOnFailure(hr, "failed get_ownerDocument in XmlSetAttribute"); | 917 | XmlExitOnFailure(hr, "failed get_ownerDocument in XmlSetAttribute"); |
903 | 918 | ||
904 | hr = XmlCreateTextNode(pixdDocument, pwzText, &pixtTextNode); | 919 | hr = XmlCreateTextNode(pixdDocument, pwzText, &pixtTextNode); |
905 | ExitOnFailure(hr, "failed createTextNode in XmlSetText(%ls)", pwzText); | 920 | XmlExitOnFailure(hr, "failed createTextNode in XmlSetText(%ls)", pwzText); |
906 | 921 | ||
907 | hr = pixnNode->appendChild(pixtTextNode, NULL); | 922 | hr = pixnNode->appendChild(pixtTextNode, NULL); |
908 | ExitOnFailure(hr, "failed appendChild in XmlSetText(%ls)", pwzText); | 923 | XmlExitOnFailure(hr, "failed appendChild in XmlSetText(%ls)", pwzText); |
909 | } | 924 | } |
910 | 925 | ||
911 | hr = *pwzText ? S_OK : S_FALSE; | 926 | hr = *pwzText ? S_OK : S_FALSE; |
@@ -933,7 +948,7 @@ extern "C" HRESULT DAPI XmlSetTextNumber( | |||
933 | WCHAR wzValue[12]; | 948 | WCHAR wzValue[12]; |
934 | 949 | ||
935 | hr = ::StringCchPrintfW(wzValue, countof(wzValue), L"%u", dwValue); | 950 | hr = ::StringCchPrintfW(wzValue, countof(wzValue), L"%u", dwValue); |
936 | ExitOnFailure(hr, "Failed to format numeric value as string."); | 951 | XmlExitOnFailure(hr, "Failed to format numeric value as string."); |
937 | 952 | ||
938 | hr = XmlSetText(pixnNode, wzValue); | 953 | hr = XmlSetText(pixnNode, wzValue); |
939 | 954 | ||
@@ -963,21 +978,21 @@ extern "C" HRESULT DAPI XmlCreateChild( | |||
963 | { | 978 | { |
964 | hr = E_FAIL; | 979 | hr = E_FAIL; |
965 | } | 980 | } |
966 | ExitOnFailure(hr, "failed get_ownerDocument"); | 981 | XmlExitOnFailure(hr, "failed get_ownerDocument"); |
967 | 982 | ||
968 | hr = XmlCreateElement(pixdDocument, pwzElementType, (IXMLDOMElement**) &pixnChild); | 983 | hr = XmlCreateElement(pixdDocument, pwzElementType, (IXMLDOMElement**) &pixnChild); |
969 | if (hr == S_FALSE) | 984 | if (hr == S_FALSE) |
970 | { | 985 | { |
971 | hr = E_FAIL; | 986 | hr = E_FAIL; |
972 | } | 987 | } |
973 | ExitOnFailure(hr, "failed createElement"); | 988 | XmlExitOnFailure(hr, "failed createElement"); |
974 | 989 | ||
975 | pixnParent->appendChild(pixnChild,NULL); | 990 | pixnParent->appendChild(pixnChild,NULL); |
976 | if (hr == S_FALSE) | 991 | if (hr == S_FALSE) |
977 | { | 992 | { |
978 | hr = E_FAIL; | 993 | hr = E_FAIL; |
979 | } | 994 | } |
980 | ExitOnFailure(hr, "failed appendChild"); | 995 | XmlExitOnFailure(hr, "failed appendChild"); |
981 | 996 | ||
982 | if (ppixnChild) | 997 | if (ppixnChild) |
983 | { | 998 | { |
@@ -1005,13 +1020,13 @@ extern "C" HRESULT DAPI XmlRemoveAttribute( | |||
1005 | // RELEASEME | 1020 | // RELEASEME |
1006 | IXMLDOMNamedNodeMap* pixnnmAttributes = NULL; | 1021 | IXMLDOMNamedNodeMap* pixnnmAttributes = NULL; |
1007 | BSTR bstrAttribute = ::SysAllocString(pwzAttribute); | 1022 | BSTR bstrAttribute = ::SysAllocString(pwzAttribute); |
1008 | ExitOnNull(bstrAttribute, hr, E_OUTOFMEMORY, "failed to allocate bstr for attribute in XmlRemoveAttribute"); | 1023 | XmlExitOnNull(bstrAttribute, hr, E_OUTOFMEMORY, "failed to allocate bstr for attribute in XmlRemoveAttribute"); |
1009 | 1024 | ||
1010 | hr = pixnNode->get_attributes(&pixnnmAttributes); | 1025 | hr = pixnNode->get_attributes(&pixnnmAttributes); |
1011 | ExitOnFailure(hr, "failed get_attributes in RemoveXmlAttribute(%ls)", pwzAttribute); | 1026 | XmlExitOnFailure(hr, "failed get_attributes in RemoveXmlAttribute(%ls)", pwzAttribute); |
1012 | 1027 | ||
1013 | hr = pixnnmAttributes->removeNamedItem(bstrAttribute, NULL); | 1028 | hr = pixnnmAttributes->removeNamedItem(bstrAttribute, NULL); |
1014 | ExitOnFailure(hr, "failed removeNamedItem in RemoveXmlAttribute(%ls)", pwzAttribute); | 1029 | XmlExitOnFailure(hr, "failed removeNamedItem in RemoveXmlAttribute(%ls)", pwzAttribute); |
1015 | 1030 | ||
1016 | LExit: | 1031 | LExit: |
1017 | ReleaseObject(pixnnmAttributes); | 1032 | ReleaseObject(pixnnmAttributes); |
@@ -1035,11 +1050,11 @@ extern "C" HRESULT DAPI XmlSelectNodes( | |||
1035 | 1050 | ||
1036 | BSTR bstrXPath = NULL; | 1051 | BSTR bstrXPath = NULL; |
1037 | 1052 | ||
1038 | ExitOnNull(pixnParent, hr, E_UNEXPECTED, "pixnParent parameter was null in XmlSelectNodes"); | 1053 | XmlExitOnNull(pixnParent, hr, E_UNEXPECTED, "pixnParent parameter was null in XmlSelectNodes"); |
1039 | ExitOnNull(ppixnlChildren, hr, E_UNEXPECTED, "ppixnChild parameter was null in XmlSelectNodes"); | 1054 | XmlExitOnNull(ppixnlChildren, hr, E_UNEXPECTED, "ppixnChild parameter was null in XmlSelectNodes"); |
1040 | 1055 | ||
1041 | bstrXPath = ::SysAllocString(wzXPath ? wzXPath : L""); | 1056 | bstrXPath = ::SysAllocString(wzXPath ? wzXPath : L""); |
1042 | ExitOnNull(bstrXPath, hr, E_OUTOFMEMORY, "failed to allocate bstr for XPath expression in XmlSelectNodes"); | 1057 | XmlExitOnNull(bstrXPath, hr, E_OUTOFMEMORY, "failed to allocate bstr for XPath expression in XmlSelectNodes"); |
1043 | 1058 | ||
1044 | hr = pixnParent->selectNodes(bstrXPath, ppixnlChildren); | 1059 | hr = pixnParent->selectNodes(bstrXPath, ppixnlChildren); |
1045 | 1060 | ||
@@ -1077,24 +1092,24 @@ extern "C" HRESULT DAPI XmlNextAttribute( | |||
1077 | } | 1092 | } |
1078 | 1093 | ||
1079 | hr = pixnnm->nextNode(&pixn); | 1094 | hr = pixnnm->nextNode(&pixn); |
1080 | ExitOnFailure(hr, "Failed to get next attribute."); | 1095 | XmlExitOnFailure(hr, "Failed to get next attribute."); |
1081 | 1096 | ||
1082 | if (S_OK == hr) | 1097 | if (S_OK == hr) |
1083 | { | 1098 | { |
1084 | hr = pixn->get_nodeType(&nt); | 1099 | hr = pixn->get_nodeType(&nt); |
1085 | ExitOnFailure(hr, "failed to get node type"); | 1100 | XmlExitOnFailure(hr, "failed to get node type"); |
1086 | 1101 | ||
1087 | if (NODE_ATTRIBUTE != nt) | 1102 | if (NODE_ATTRIBUTE != nt) |
1088 | { | 1103 | { |
1089 | hr = E_UNEXPECTED; | 1104 | hr = E_UNEXPECTED; |
1090 | ExitOnFailure(hr, "Failed to get expected node type back: attribute"); | 1105 | XmlExitOnFailure(hr, "Failed to get expected node type back: attribute"); |
1091 | } | 1106 | } |
1092 | 1107 | ||
1093 | // if the caller asked for the attribute name | 1108 | // if the caller asked for the attribute name |
1094 | if (pbstrAttribute) | 1109 | if (pbstrAttribute) |
1095 | { | 1110 | { |
1096 | hr = pixn->get_baseName(pbstrAttribute); | 1111 | hr = pixn->get_baseName(pbstrAttribute); |
1097 | ExitOnFailure(hr, "failed to get attribute name"); | 1112 | XmlExitOnFailure(hr, "failed to get attribute name"); |
1098 | } | 1113 | } |
1099 | 1114 | ||
1100 | *pixnAttribute = pixn; | 1115 | *pixnAttribute = pixn; |
@@ -1140,20 +1155,20 @@ extern "C" HRESULT DAPI XmlNextElement( | |||
1140 | while (S_OK == (hr = pixnl->nextNode(&pixn))) | 1155 | while (S_OK == (hr = pixnl->nextNode(&pixn))) |
1141 | { | 1156 | { |
1142 | hr = pixn->get_nodeType(&nt); | 1157 | hr = pixn->get_nodeType(&nt); |
1143 | ExitOnFailure(hr, "failed to get node type"); | 1158 | XmlExitOnFailure(hr, "failed to get node type"); |
1144 | 1159 | ||
1145 | if (NODE_ELEMENT == nt) | 1160 | if (NODE_ELEMENT == nt) |
1146 | break; | 1161 | break; |
1147 | 1162 | ||
1148 | ReleaseNullObject(pixn); | 1163 | ReleaseNullObject(pixn); |
1149 | } | 1164 | } |
1150 | ExitOnFailure(hr, "failed to get next element"); | 1165 | XmlExitOnFailure(hr, "failed to get next element"); |
1151 | 1166 | ||
1152 | // if we have a node and the caller asked for the element name | 1167 | // if we have a node and the caller asked for the element name |
1153 | if (pixn && pbstrElement) | 1168 | if (pixn && pbstrElement) |
1154 | { | 1169 | { |
1155 | hr = pixn->get_baseName(pbstrElement); | 1170 | hr = pixn->get_baseName(pbstrElement); |
1156 | ExitOnFailure(hr, "failed to get element name"); | 1171 | XmlExitOnFailure(hr, "failed to get element name"); |
1157 | } | 1172 | } |
1158 | 1173 | ||
1159 | *pixnElement = pixn; | 1174 | *pixnElement = pixn; |
@@ -1185,12 +1200,12 @@ extern "C" HRESULT DAPI XmlRemoveChildren( | |||
1185 | if (pwzXPath) | 1200 | if (pwzXPath) |
1186 | { | 1201 | { |
1187 | hr = XmlSelectNodes(pixnSource, pwzXPath, &pixnlNodeList); | 1202 | hr = XmlSelectNodes(pixnSource, pwzXPath, &pixnlNodeList); |
1188 | ExitOnFailure(hr, "failed XmlSelectNodes"); | 1203 | XmlExitOnFailure(hr, "failed XmlSelectNodes"); |
1189 | } | 1204 | } |
1190 | else | 1205 | else |
1191 | { | 1206 | { |
1192 | hr = pixnSource->get_childNodes(&pixnlNodeList); | 1207 | hr = pixnSource->get_childNodes(&pixnlNodeList); |
1193 | ExitOnFailure(hr, "failed childNodes"); | 1208 | XmlExitOnFailure(hr, "failed childNodes"); |
1194 | } | 1209 | } |
1195 | if (S_FALSE == hr) | 1210 | if (S_FALSE == hr) |
1196 | { | 1211 | { |
@@ -1200,7 +1215,7 @@ extern "C" HRESULT DAPI XmlRemoveChildren( | |||
1200 | while (S_OK == (hr = pixnlNodeList->nextNode(&pixnNode))) | 1215 | while (S_OK == (hr = pixnlNodeList->nextNode(&pixnNode))) |
1201 | { | 1216 | { |
1202 | hr = pixnSource->removeChild(pixnNode, &pixnRemoveChild); | 1217 | hr = pixnSource->removeChild(pixnNode, &pixnRemoveChild); |
1203 | ExitOnFailure(hr, "failed removeChild"); | 1218 | XmlExitOnFailure(hr, "failed removeChild"); |
1204 | 1219 | ||
1205 | ReleaseNullObject(pixnRemoveChild); | 1220 | ReleaseNullObject(pixnRemoveChild); |
1206 | ReleaseNullObject(pixnNode); | 1221 | ReleaseNullObject(pixnNode); |
@@ -1240,14 +1255,14 @@ extern "C" HRESULT DAPI XmlSaveDocument( | |||
1240 | { | 1255 | { |
1241 | hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); | 1256 | hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); |
1242 | } | 1257 | } |
1243 | ExitOnFailure(hr, "failed to create BSTR"); | 1258 | XmlExitOnFailure(hr, "failed to create BSTR"); |
1244 | 1259 | ||
1245 | hr = pixdDocument->save(varsDestPath); | 1260 | hr = pixdDocument->save(varsDestPath); |
1246 | if (hr == S_FALSE) | 1261 | if (hr == S_FALSE) |
1247 | { | 1262 | { |
1248 | hr = E_FAIL; | 1263 | hr = E_FAIL; |
1249 | } | 1264 | } |
1250 | ExitOnFailure(hr, "failed save in WriteDocument"); | 1265 | XmlExitOnFailure(hr, "failed save in WriteDocument"); |
1251 | 1266 | ||
1252 | LExit: | 1267 | LExit: |
1253 | ReleaseVariant(varsDestPath); | 1268 | ReleaseVariant(varsDestPath); |
@@ -1277,33 +1292,33 @@ extern "C" HRESULT DAPI XmlSaveDocumentToBuffer( | |||
1277 | 1292 | ||
1278 | // create stream | 1293 | // create stream |
1279 | hr = ::CreateStreamOnHGlobal(NULL, TRUE, &pStream); | 1294 | hr = ::CreateStreamOnHGlobal(NULL, TRUE, &pStream); |
1280 | ExitOnFailure(hr, "Failed to create stream."); | 1295 | XmlExitOnFailure(hr, "Failed to create stream."); |
1281 | 1296 | ||
1282 | // write document to stream | 1297 | // write document to stream |
1283 | vtDestination.vt = VT_UNKNOWN; | 1298 | vtDestination.vt = VT_UNKNOWN; |
1284 | vtDestination.punkVal = (IUnknown*)pStream; | 1299 | vtDestination.punkVal = (IUnknown*)pStream; |
1285 | hr = pixdDocument->save(vtDestination); | 1300 | hr = pixdDocument->save(vtDestination); |
1286 | ExitOnFailure(hr, "Failed to save document."); | 1301 | XmlExitOnFailure(hr, "Failed to save document."); |
1287 | 1302 | ||
1288 | // get stream size | 1303 | // get stream size |
1289 | hr = pStream->Stat(&statstg, STATFLAG_NONAME); | 1304 | hr = pStream->Stat(&statstg, STATFLAG_NONAME); |
1290 | ExitOnFailure(hr, "Failed to get stream size."); | 1305 | XmlExitOnFailure(hr, "Failed to get stream size."); |
1291 | 1306 | ||
1292 | // allocate buffer | 1307 | // allocate buffer |
1293 | pbDest = static_cast<BYTE*>(MemAlloc((SIZE_T)statstg.cbSize.LowPart, TRUE)); | 1308 | pbDest = static_cast<BYTE*>(MemAlloc((SIZE_T)statstg.cbSize.LowPart, TRUE)); |
1294 | ExitOnNull(pbDest, hr, E_OUTOFMEMORY, "Failed to allocate destination buffer."); | 1309 | XmlExitOnNull(pbDest, hr, E_OUTOFMEMORY, "Failed to allocate destination buffer."); |
1295 | 1310 | ||
1296 | // read data from stream | 1311 | // read data from stream |
1297 | li.QuadPart = 0; | 1312 | li.QuadPart = 0; |
1298 | hr = pStream->Seek(li, STREAM_SEEK_SET, NULL); | 1313 | hr = pStream->Seek(li, STREAM_SEEK_SET, NULL); |
1299 | ExitOnFailure(hr, "Failed to seek stream."); | 1314 | XmlExitOnFailure(hr, "Failed to seek stream."); |
1300 | 1315 | ||
1301 | hr = pStream->Read(pbDest, statstg.cbSize.LowPart, &cbRead); | 1316 | hr = pStream->Read(pbDest, statstg.cbSize.LowPart, &cbRead); |
1302 | if (cbRead < statstg.cbSize.LowPart) | 1317 | if (cbRead < statstg.cbSize.LowPart) |
1303 | { | 1318 | { |
1304 | hr = E_FAIL; | 1319 | hr = E_FAIL; |
1305 | } | 1320 | } |
1306 | ExitOnFailure(hr, "Failed to read stream content to buffer."); | 1321 | XmlExitOnFailure(hr, "Failed to read stream content to buffer."); |
1307 | 1322 | ||
1308 | // return value | 1323 | // return value |
1309 | *ppbDest = pbDest; | 1324 | *ppbDest = pbDest; |