| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #ifndef ADBLOCK_PLUS_WEB_REQUEST_H | 18 #ifndef ADBLOCK_PLUS_WEB_REQUEST_H |
| 19 #define ADBLOCK_PLUS_WEB_REQUEST_H | 19 #define ADBLOCK_PLUS_WEB_REQUEST_H |
| 20 | 20 |
| 21 #include <stdint.h> | 21 #include <stdint.h> |
| 22 #include <string> | 22 #include <string> |
| 23 #include <vector> | 23 #include <vector> |
| 24 | 24 |
| 25 #include "tr1_memory.h" | 25 #include "tr1_memory.h" |
| 26 | 26 |
| 27 namespace AdblockPlus | 27 namespace AdblockPlus |
| 28 { | 28 { |
| 29 /** |
| 30 * List of HTTP headers. |
| 31 */ |
| 29 typedef std::vector<std::pair<std::string, std::string> > HeaderList; | 32 typedef std::vector<std::pair<std::string, std::string> > HeaderList; |
| 30 | 33 |
| 34 /** |
| 35 * HTTP response. |
| 36 */ |
| 31 struct ServerResponse | 37 struct ServerResponse |
| 32 { | 38 { |
| 39 //@{ |
| 40 /** |
| 41 * [Mozilla status code](https://developer.mozilla.org/en/docs/Table_Of_Erro
rs#Network_Errors) |
| 42 * indicating the network-level request status. |
| 43 * This should be 0 (NS_OK) if the request succeeded. Note that this should |
| 44 * be NS_OK if the server responded with an error code like "404 Not Found". |
| 45 */ |
| 33 #ifdef _WIN32 | 46 #ifdef _WIN32 |
| 34 __int64 status; | 47 __int64 status; |
| 35 #else | 48 #else |
| 36 int64_t status; | 49 int64_t status; |
| 37 #endif | 50 #endif |
| 51 //@} |
| 52 |
| 53 /** |
| 54 * List of response headers. |
| 55 */ |
| 38 HeaderList responseHeaders; | 56 HeaderList responseHeaders; |
| 57 |
| 58 /** |
| 59 * HTTP status of the response (e.g.\ 404). |
| 60 */ |
| 39 int responseStatus; | 61 int responseStatus; |
| 62 |
| 63 /** |
| 64 * Body text of the response. |
| 65 */ |
| 40 std::string responseText; | 66 std::string responseText; |
| 41 }; | 67 }; |
| 42 | 68 |
| 69 /** |
| 70 * Web request interface. |
| 71 */ |
| 43 class WebRequest | 72 class WebRequest |
| 44 { | 73 { |
| 45 public: | 74 public: |
| 75 /** |
| 76 * Possible [Mozilla status codes](https://developer.mozilla.org/en/docs/Tab
le_Of_Errors#Network_Errors). |
| 77 */ |
| 46 enum | 78 enum |
| 47 { | 79 { |
| 48 NS_OK = 0, | 80 NS_OK = 0, |
| 49 NS_ERROR_FAILURE = 0x80004005, | 81 NS_ERROR_FAILURE = 0x80004005, |
| 50 NS_ERROR_OUT_OF_MEMORY = 0x8007000e, | 82 NS_ERROR_OUT_OF_MEMORY = 0x8007000e, |
| 51 NS_ERROR_MALFORMED_URI = 0x804b000a, | 83 NS_ERROR_MALFORMED_URI = 0x804b000a, |
| 52 NS_ERROR_CONNECTION_REFUSED = 0x804b000d, | 84 NS_ERROR_CONNECTION_REFUSED = 0x804b000d, |
| 53 NS_ERROR_NET_TIMEOUT = 0x804b000e, | 85 NS_ERROR_NET_TIMEOUT = 0x804b000e, |
| 54 NS_ERROR_NO_CONTENT = 0x804b0011, | 86 NS_ERROR_NO_CONTENT = 0x804b0011, |
| 55 NS_ERROR_UNKNOWN_PROTOCOL = 0x804b0012, | 87 NS_ERROR_UNKNOWN_PROTOCOL = 0x804b0012, |
| 56 NS_ERROR_NET_RESET = 0x804b0014, | 88 NS_ERROR_NET_RESET = 0x804b0014, |
| 57 NS_ERROR_UNKNOWN_HOST = 0x804b001e, | 89 NS_ERROR_UNKNOWN_HOST = 0x804b001e, |
| 58 NS_ERROR_REDIRECT_LOOP = 0x804b001f, | 90 NS_ERROR_REDIRECT_LOOP = 0x804b001f, |
| 59 NS_ERROR_UNKNOWN_PROXY_HOST = 0x804b002a, | 91 NS_ERROR_UNKNOWN_PROXY_HOST = 0x804b002a, |
| 60 NS_ERROR_NET_INTERRUPT = 0x804b0047, | 92 NS_ERROR_NET_INTERRUPT = 0x804b0047, |
| 61 NS_ERROR_UNKNOWN_PROXY_CONNECTION_REFUSED = 0x804b0048, | 93 NS_ERROR_UNKNOWN_PROXY_CONNECTION_REFUSED = 0x804b0048, |
| 62 NS_CUSTOM_ERROR_BASE = 0x80850000, | 94 NS_CUSTOM_ERROR_BASE = 0x80850000, |
| 63 NS_ERROR_NOT_INITIALIZED = 0xc1f30001 | 95 NS_ERROR_NOT_INITIALIZED = 0xc1f30001 |
| 64 }; | 96 }; |
| 65 | 97 |
| 66 virtual inline ~WebRequest() {}; | 98 virtual inline ~WebRequest() {}; |
| 99 |
| 100 /** |
| 101 * Performs a GET request. |
| 102 * @param url Request URL. |
| 103 * @param requestHeaders Request headers. |
| 104 * @return HTTP response. |
| 105 */ |
| 67 virtual ServerResponse GET(const std::string& url, const HeaderList& request
Headers) const = 0; | 106 virtual ServerResponse GET(const std::string& url, const HeaderList& request
Headers) const = 0; |
| 68 }; | 107 }; |
| 69 | 108 |
| 109 /** |
| 110 * Shared smart pointer to a `WebRequest` instance. |
| 111 */ |
| 70 typedef std::tr1::shared_ptr<WebRequest> WebRequestPtr; | 112 typedef std::tr1::shared_ptr<WebRequest> WebRequestPtr; |
| 71 } | 113 } |
| 72 | 114 |
| 73 #endif | 115 #endif |
| OLD | NEW |