Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/DefaultWebRequestCurl.cpp

Issue 29428650: Issue 5180 - introduce asynchronous web request (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created May 3, 2017, 2:21 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/DefaultWebRequest.cpp ('k') | src/DefaultWebRequestDummy.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 status = 0; 34 status = 0;
35 expectingStatus = true; 35 expectingStatus = true;
36 } 36 }
37 }; 37 };
38 38
39 unsigned int ConvertErrorCode(CURLcode code) 39 unsigned int ConvertErrorCode(CURLcode code)
40 { 40 {
41 switch (code) 41 switch (code)
42 { 42 {
43 case CURLE_OK: 43 case CURLE_OK:
44 return AdblockPlus::WebRequest::NS_OK; 44 return AdblockPlus::IWebRequest::NS_OK;
45 case CURLE_FAILED_INIT: 45 case CURLE_FAILED_INIT:
46 return AdblockPlus::WebRequest::NS_ERROR_NOT_INITIALIZED; 46 return AdblockPlus::IWebRequest::NS_ERROR_NOT_INITIALIZED;
47 case CURLE_UNSUPPORTED_PROTOCOL: 47 case CURLE_UNSUPPORTED_PROTOCOL:
48 return AdblockPlus::WebRequest::NS_ERROR_UNKNOWN_PROTOCOL; 48 return AdblockPlus::IWebRequest::NS_ERROR_UNKNOWN_PROTOCOL;
49 case CURLE_URL_MALFORMAT: 49 case CURLE_URL_MALFORMAT:
50 return AdblockPlus::WebRequest::NS_ERROR_MALFORMED_URI; 50 return AdblockPlus::IWebRequest::NS_ERROR_MALFORMED_URI;
51 case CURLE_COULDNT_RESOLVE_PROXY: 51 case CURLE_COULDNT_RESOLVE_PROXY:
52 return AdblockPlus::WebRequest::NS_ERROR_UNKNOWN_PROXY_HOST; 52 return AdblockPlus::IWebRequest::NS_ERROR_UNKNOWN_PROXY_HOST;
53 case CURLE_COULDNT_RESOLVE_HOST: 53 case CURLE_COULDNT_RESOLVE_HOST:
54 return AdblockPlus::WebRequest::NS_ERROR_UNKNOWN_HOST; 54 return AdblockPlus::IWebRequest::NS_ERROR_UNKNOWN_HOST;
55 case CURLE_COULDNT_CONNECT: 55 case CURLE_COULDNT_CONNECT:
56 return AdblockPlus::WebRequest::NS_ERROR_CONNECTION_REFUSED; 56 return AdblockPlus::IWebRequest::NS_ERROR_CONNECTION_REFUSED;
57 case CURLE_OUT_OF_MEMORY: 57 case CURLE_OUT_OF_MEMORY:
58 return AdblockPlus::WebRequest::NS_ERROR_OUT_OF_MEMORY; 58 return AdblockPlus::IWebRequest::NS_ERROR_OUT_OF_MEMORY;
59 case CURLE_OPERATION_TIMEDOUT: 59 case CURLE_OPERATION_TIMEDOUT:
60 return AdblockPlus::WebRequest::NS_ERROR_NET_TIMEOUT; 60 return AdblockPlus::IWebRequest::NS_ERROR_NET_TIMEOUT;
61 case CURLE_TOO_MANY_REDIRECTS: 61 case CURLE_TOO_MANY_REDIRECTS:
62 return AdblockPlus::WebRequest::NS_ERROR_REDIRECT_LOOP; 62 return AdblockPlus::IWebRequest::NS_ERROR_REDIRECT_LOOP;
63 case CURLE_GOT_NOTHING: 63 case CURLE_GOT_NOTHING:
64 return AdblockPlus::WebRequest::NS_ERROR_NO_CONTENT; 64 return AdblockPlus::IWebRequest::NS_ERROR_NO_CONTENT;
65 case CURLE_SEND_ERROR: 65 case CURLE_SEND_ERROR:
66 return AdblockPlus::WebRequest::NS_ERROR_NET_RESET; 66 return AdblockPlus::IWebRequest::NS_ERROR_NET_RESET;
67 case CURLE_RECV_ERROR: 67 case CURLE_RECV_ERROR:
68 return AdblockPlus::WebRequest::NS_ERROR_NET_RESET; 68 return AdblockPlus::IWebRequest::NS_ERROR_NET_RESET;
69 default: 69 default:
70 return AdblockPlus::WebRequest::NS_CUSTOM_ERROR_BASE + code; 70 return AdblockPlus::IWebRequest::NS_CUSTOM_ERROR_BASE + code;
71 } 71 }
72 } 72 }
73 73
74 size_t ReceiveData(char* ptr, size_t size, size_t nmemb, void* userdata) 74 size_t ReceiveData(char* ptr, size_t size, size_t nmemb, void* userdata)
75 { 75 {
76 std::stringstream* stream = static_cast<std::stringstream*>(userdata); 76 std::stringstream* stream = static_cast<std::stringstream*>(userdata);
77 stream->write(ptr, size * nmemb); 77 stream->write(ptr, size * nmemb);
78 return nmemb; 78 return nmemb;
79 } 79 }
80 80
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 if (headerEnd) 116 if (headerEnd)
117 data->headers.push_back(header.substr(0, headerEnd)); 117 data->headers.push_back(header.substr(0, headerEnd));
118 else 118 else
119 data->expectingStatus = true; 119 data->expectingStatus = true;
120 } 120 }
121 return nmemb; 121 return nmemb;
122 } 122 }
123 } 123 }
124 124
125 AdblockPlus::ServerResponse AdblockPlus::DefaultWebRequest::GET( 125 AdblockPlus::ServerResponse AdblockPlus::DefaultWebRequestSync::GET(
126 const std::string& url, const HeaderList& requestHeaders) const 126 const std::string& url, const HeaderList& requestHeaders) const
127 { 127 {
128 AdblockPlus::ServerResponse result; 128 AdblockPlus::ServerResponse result;
129 result.status = NS_ERROR_NOT_INITIALIZED; 129 result.status = IWebRequest::NS_ERROR_NOT_INITIALIZED;
130 result.responseStatus = 0; 130 result.responseStatus = 0;
131 131
132 CURL *curl = curl_easy_init(); 132 CURL *curl = curl_easy_init();
133 if (curl) 133 if (curl)
134 { 134 {
135 std::stringstream responseText; 135 std::stringstream responseText;
136 HeaderData headerData; 136 HeaderData headerData;
137 curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); 137 curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
138 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); 138 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
139 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ReceiveData); 139 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ReceiveData);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 180 }
181 } 181 }
182 } 182 }
183 183
184 if (headerList) 184 if (headerList)
185 curl_slist_free_all(headerList); 185 curl_slist_free_all(headerList);
186 curl_easy_cleanup(curl); 186 curl_easy_cleanup(curl);
187 } 187 }
188 return result; 188 return result;
189 } 189 }
OLDNEW
« no previous file with comments | « src/DefaultWebRequest.cpp ('k') | src/DefaultWebRequestDummy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld