OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 }; | 41 }; |
42 | 42 |
43 | 43 |
44 long WindowsErrorToGeckoError(DWORD err) | 44 long WindowsErrorToGeckoError(DWORD err) |
45 { | 45 { |
46 // TODO: Add some more error code translations for easier debugging | 46 // TODO: Add some more error code translations for easier debugging |
47 switch (err) | 47 switch (err) |
48 { | 48 { |
49 case ERROR_INVALID_HANDLE: | 49 case ERROR_INVALID_HANDLE: |
50 return AdblockPlus::WebRequest::NS_ERROR_NOT_INITIALIZED; | 50 return AdblockPlus::IWebRequest::NS_ERROR_NOT_INITIALIZED; |
51 case ERROR_OUTOFMEMORY: | 51 case ERROR_OUTOFMEMORY: |
52 return AdblockPlus::WebRequest::NS_ERROR_OUT_OF_MEMORY; | 52 return AdblockPlus::IWebRequest::NS_ERROR_OUT_OF_MEMORY; |
53 case ERROR_WINHTTP_UNRECOGNIZED_SCHEME: | 53 case ERROR_WINHTTP_UNRECOGNIZED_SCHEME: |
54 return AdblockPlus::WebRequest::NS_ERROR_UNKNOWN_PROTOCOL; | 54 return AdblockPlus::IWebRequest::NS_ERROR_UNKNOWN_PROTOCOL; |
55 case ERROR_WINHTTP_CONNECTION_ERROR: | 55 case ERROR_WINHTTP_CONNECTION_ERROR: |
56 return AdblockPlus::WebRequest::NS_ERROR_NET_INTERRUPT; | 56 return AdblockPlus::IWebRequest::NS_ERROR_NET_INTERRUPT; |
57 case ERROR_WINHTTP_INVALID_URL: | 57 case ERROR_WINHTTP_INVALID_URL: |
58 return AdblockPlus::WebRequest::NS_ERROR_MALFORMED_URI; | 58 return AdblockPlus::IWebRequest::NS_ERROR_MALFORMED_URI; |
59 case ERROR_WINHTTP_TIMEOUT: | 59 case ERROR_WINHTTP_TIMEOUT: |
60 return AdblockPlus::WebRequest::NS_ERROR_NET_TIMEOUT; | 60 return AdblockPlus::IWebRequest::NS_ERROR_NET_TIMEOUT; |
61 case ERROR_WINHTTP_NAME_NOT_RESOLVED: | 61 case ERROR_WINHTTP_NAME_NOT_RESOLVED: |
62 return AdblockPlus::WebRequest::NS_ERROR_UNKNOWN_HOST; | 62 return AdblockPlus::IWebRequest::NS_ERROR_UNKNOWN_HOST; |
63 | 63 |
64 default: | 64 default: |
65 return AdblockPlus::WebRequest::NS_CUSTOM_ERROR_BASE + err; | 65 return AdblockPlus::IWebRequest::NS_CUSTOM_ERROR_BASE + err; |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 BOOL GetProxySettings(std::wstring& proxyName, std::wstring& proxyBypass) | 69 BOOL GetProxySettings(std::wstring& proxyName, std::wstring& proxyBypass) |
70 { | 70 { |
71 BOOL bResult = TRUE; | 71 BOOL bResult = TRUE; |
72 | 72 |
73 // Get Proxy config info. | 73 // Get Proxy config info. |
74 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxyConfig; | 74 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxyConfig; |
75 | 75 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 { | 177 { |
178 throw std::exception("Can't parse the status code"); | 178 throw std::exception("Can't parse the status code"); |
179 } | 179 } |
180 statusStr.resize(statusLen / sizeof(std::wstring::value_type) + 1); | 180 statusStr.resize(statusLen / sizeof(std::wstring::value_type) + 1); |
181 res = WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_STATUS_CODE, WINHTTP_HEADER_
NAME_BY_INDEX, &statusStr[0], &statusLen, WINHTTP_NO_HEADER_INDEX); | 181 res = WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_STATUS_CODE, WINHTTP_HEADER_
NAME_BY_INDEX, &statusStr[0], &statusLen, WINHTTP_NO_HEADER_INDEX); |
182 if ((statusLen == 0) || (!res)) | 182 if ((statusLen == 0) || (!res)) |
183 { | 183 { |
184 throw std::exception("Can't parse the status code"); | 184 throw std::exception("Can't parse the status code"); |
185 } | 185 } |
186 std::wistringstream(statusStr) >> result->responseStatus; | 186 std::wistringstream(statusStr) >> result->responseStatus; |
187 result->status = AdblockPlus::DefaultWebRequest::NS_OK; | 187 result->status = AdblockPlus::IWebRequest::NS_OK; |
188 | 188 |
189 } | 189 } |
190 | 190 |
191 AdblockPlus::ServerResponse AdblockPlus::DefaultWebRequest::GET( | 191 AdblockPlus::ServerResponse AdblockPlus::DefaultWebRequestSync::GET( |
192 const std::string& url, const HeaderList& requestHeaders) const | 192 const std::string& url, const HeaderList& requestHeaders) const |
193 { | 193 { |
194 AdblockPlus::ServerResponse result; | 194 AdblockPlus::ServerResponse result; |
195 result.status = NS_ERROR_FAILURE; | 195 result.status = IWebRequest::NS_ERROR_FAILURE; |
196 result.responseStatus = 0; | 196 result.responseStatus = 0; |
197 | 197 |
198 HRESULT hr; | 198 HRESULT hr; |
199 BOOL res; | 199 BOOL res; |
200 | 200 |
201 std::wstring canonizedUrl = Utils::CanonizeUrl(Utils::ToUtf16String(url)); | 201 std::wstring canonizedUrl = Utils::CanonizeUrl(Utils::ToUtf16String(url)); |
202 | 202 |
203 std::string headersString = ""; | 203 std::string headersString = ""; |
204 for (int i = 0; i < requestHeaders.size(); i++) | 204 for (int i = 0; i < requestHeaders.size(); i++) |
205 { | 205 { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 if (!WinHttpQueryDataAvailable(hRequest, &downloadSize)) | 321 if (!WinHttpQueryDataAvailable(hRequest, &downloadSize)) |
322 { | 322 { |
323 result.responseStatus = WindowsErrorToGeckoError(GetLastError()); | 323 result.responseStatus = WindowsErrorToGeckoError(GetLastError()); |
324 break; | 324 break; |
325 } | 325 } |
326 // Allocate space for the buffer. | 326 // Allocate space for the buffer. |
327 outBuffer.reset(new char[downloadSize+1]); | 327 outBuffer.reset(new char[downloadSize+1]); |
328 if (!outBuffer.get()) | 328 if (!outBuffer.get()) |
329 { | 329 { |
330 //Out of memory? | 330 //Out of memory? |
331 result.status = NS_ERROR_OUT_OF_MEMORY; | 331 result.status = IWebRequest::NS_ERROR_OUT_OF_MEMORY; |
332 break; | 332 break; |
333 } | 333 } |
334 else | 334 else |
335 { | 335 { |
336 // Read the data. | 336 // Read the data. |
337 ZeroMemory(outBuffer.get(), downloadSize+1); | 337 ZeroMemory(outBuffer.get(), downloadSize+1); |
338 | 338 |
339 if (WinHttpReadData(hRequest, outBuffer.get(), downloadSize, &downloaded)) | 339 if (WinHttpReadData(hRequest, outBuffer.get(), downloadSize, &downloaded)) |
340 { | 340 { |
341 result.responseText.append(outBuffer.get(), downloaded); | 341 result.responseText.append(outBuffer.get(), downloaded); |
342 } | 342 } |
343 } | 343 } |
344 } while (downloadSize > 0); | 344 } while (downloadSize > 0); |
345 return result; | 345 return result; |
346 } | 346 } |
OLD | NEW |