| 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 |
| 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_IWEB_REQUEST_H |
| 19 #define ADBLOCK_PLUS_WEB_REQUEST_H | 19 #define ADBLOCK_PLUS_IWEB_REQUEST_H |
| 20 | 20 |
| 21 #include <cstdint> |
| 22 #include <functional> |
| 21 #include <memory> | 23 #include <memory> |
| 22 #include <stdint.h> | 24 #include <vector> |
| 23 #include <string> | 25 #include <string> |
| 24 #include <vector> | |
| 25 | 26 |
| 26 namespace AdblockPlus | 27 namespace AdblockPlus |
| 27 { | 28 { |
| 28 /** | 29 /** |
| 29 * List of HTTP headers. | 30 * List of HTTP headers. |
| 30 */ | 31 */ |
| 31 typedef std::vector<std::pair<std::string, std::string> > HeaderList; | 32 typedef std::vector<std::pair<std::string, std::string>> HeaderList; |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * HTTP response. | 35 * HTTP response. |
| 35 */ | 36 */ |
| 36 struct ServerResponse | 37 struct ServerResponse |
| 37 { | 38 { |
| 38 //@{ | 39 //@{ |
| 39 /** | 40 /** |
| 40 * [Mozilla status code](https://developer.mozilla.org/en/docs/Table_Of_Erro
rs#Network_Errors) | 41 * [Mozilla status code](https://developer.mozilla.org/en/docs/Table_Of_Erro
rs#Network_Errors) |
| 41 * indicating the network-level request status. | 42 * indicating the network-level request status. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 59 */ | 60 */ |
| 60 int responseStatus; | 61 int responseStatus; |
| 61 | 62 |
| 62 /** | 63 /** |
| 63 * Body text of the response. | 64 * Body text of the response. |
| 64 */ | 65 */ |
| 65 std::string responseText; | 66 std::string responseText; |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 /** | 69 /** |
| 69 * Web request interface. | 70 * Web request interface used to implement XMLHttpRequest. |
| 70 */ | 71 */ |
| 71 class WebRequest | 72 struct IWebRequest |
| 72 { | 73 { |
| 73 public: | |
| 74 /** | 74 /** |
| 75 * Possible [Mozilla status codes](https://developer.mozilla.org/en/docs/Tab
le_Of_Errors#Network_Errors). | 75 * Possible [Mozilla status codes](https://developer.mozilla.org/en/docs/Tab
le_Of_Errors#Network_Errors). |
| 76 */ | 76 */ |
| 77 enum | 77 enum MozillaStatusCode |
| 78 { | 78 { |
| 79 NS_OK = 0, | 79 NS_OK = 0, |
| 80 NS_ERROR_FAILURE = 0x80004005, | 80 NS_ERROR_FAILURE = 0x80004005, |
| 81 NS_ERROR_OUT_OF_MEMORY = 0x8007000e, | 81 NS_ERROR_OUT_OF_MEMORY = 0x8007000e, |
| 82 NS_ERROR_MALFORMED_URI = 0x804b000a, | 82 NS_ERROR_MALFORMED_URI = 0x804b000a, |
| 83 NS_ERROR_CONNECTION_REFUSED = 0x804b000d, | 83 NS_ERROR_CONNECTION_REFUSED = 0x804b000d, |
| 84 NS_ERROR_NET_TIMEOUT = 0x804b000e, | 84 NS_ERROR_NET_TIMEOUT = 0x804b000e, |
| 85 NS_ERROR_NO_CONTENT = 0x804b0011, | 85 NS_ERROR_NO_CONTENT = 0x804b0011, |
| 86 NS_ERROR_UNKNOWN_PROTOCOL = 0x804b0012, | 86 NS_ERROR_UNKNOWN_PROTOCOL = 0x804b0012, |
| 87 NS_ERROR_NET_RESET = 0x804b0014, | 87 NS_ERROR_NET_RESET = 0x804b0014, |
| 88 NS_ERROR_UNKNOWN_HOST = 0x804b001e, | 88 NS_ERROR_UNKNOWN_HOST = 0x804b001e, |
| 89 NS_ERROR_REDIRECT_LOOP = 0x804b001f, | 89 NS_ERROR_REDIRECT_LOOP = 0x804b001f, |
| 90 NS_ERROR_UNKNOWN_PROXY_HOST = 0x804b002a, | 90 NS_ERROR_UNKNOWN_PROXY_HOST = 0x804b002a, |
| 91 NS_ERROR_NET_INTERRUPT = 0x804b0047, | 91 NS_ERROR_NET_INTERRUPT = 0x804b0047, |
| 92 NS_ERROR_UNKNOWN_PROXY_CONNECTION_REFUSED = 0x804b0048, | 92 NS_ERROR_UNKNOWN_PROXY_CONNECTION_REFUSED = 0x804b0048, |
| 93 NS_CUSTOM_ERROR_BASE = 0x80850000, | 93 NS_CUSTOM_ERROR_BASE = 0x80850000, |
| 94 NS_ERROR_NOT_INITIALIZED = 0xc1f30001 | 94 NS_ERROR_NOT_INITIALIZED = 0xc1f30001 |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 virtual inline ~WebRequest() {}; | 97 /** |
| 98 * Callback type invoked when the server response is ready. |
| 99 * The parameter is the server response. |
| 100 */ |
| 101 typedef std::function<void(const ServerResponse&)> GetCallback; |
| 102 virtual ~IWebRequest() {}; |
| 98 | 103 |
| 99 /** | 104 /** |
| 100 * Performs a GET request. | 105 * Performs a GET request. |
| 101 * @param url Request URL. | 106 * @param url Request URL. |
| 102 * @param requestHeaders Request headers. | 107 * @param requestHeaders Request headers. |
| 103 * @return HTTP response. | 108 * @param getCallback to invoke when the server response is ready. |
| 104 */ | 109 */ |
| 105 virtual ServerResponse GET(const std::string& url, const HeaderList& request
Headers) const = 0; | 110 virtual void GET(const std::string& url, const HeaderList& requestHeaders, c
onst GetCallback& getCallback) = 0; |
| 106 }; | 111 }; |
| 107 | 112 |
| 108 /** | 113 /** |
| 109 * Shared smart pointer to a `WebRequest` instance. | 114 * Unique smart pointer to an instance of `IWebRequest` implementation. |
| 110 */ | 115 */ |
| 111 typedef std::shared_ptr<WebRequest> WebRequestSharedPtr; | 116 typedef std::unique_ptr<IWebRequest> WebRequestPtr; |
| 112 } | 117 } |
| 113 | 118 |
| 114 #endif | 119 #endif |
| OLD | NEW |