diff options
Diffstat (limited to '')
-rw-r--r-- | src/dutil/inetutil.cpp | 37 |
1 files changed, 26 insertions, 11 deletions
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: |