Index: src/DefaultWebRequestCurl.cpp |
=================================================================== |
rename from src/WebRequest.cpp |
rename to src/DefaultWebRequestCurl.cpp |
--- a/src/WebRequest.cpp |
+++ b/src/DefaultWebRequestCurl.cpp |
@@ -1,20 +1,13 @@ |
-#include <AdblockPlus/WebRequest.h> |
- |
-AdblockPlus::WebRequest::~WebRequest() |
-{ |
-} |
- |
-#if defined(HAVE_CURL) |
- |
#include <sstream> |
#include <cctype> |
#include <algorithm> |
#include <curl/curl.h> |
+#include <AdblockPlus/WebRequest.h> |
namespace |
{ |
struct HeaderData |
{ |
int status; |
bool expectingStatus; |
std::vector<std::string> headers; |
@@ -26,43 +19,43 @@ namespace |
} |
}; |
unsigned int ConvertErrorCode(CURLcode code) |
{ |
switch (code) |
{ |
case CURLE_OK: |
- return NS_OK; |
+ return AdblockPlus::WebRequest::NS_OK; |
case CURLE_FAILED_INIT: |
- return NS_ERROR_NOT_INITIALIZED; |
+ return AdblockPlus::WebRequest::NS_ERROR_NOT_INITIALIZED; |
case CURLE_UNSUPPORTED_PROTOCOL: |
- return NS_ERROR_UNKNOWN_PROTOCOL; |
+ return AdblockPlus::WebRequest::NS_ERROR_UNKNOWN_PROTOCOL; |
case CURLE_URL_MALFORMAT: |
- return NS_ERROR_MALFORMED_URI; |
+ return AdblockPlus::WebRequest::NS_ERROR_MALFORMED_URI; |
case CURLE_COULDNT_RESOLVE_PROXY: |
- return NS_ERROR_UNKNOWN_PROXY_HOST; |
+ return AdblockPlus::WebRequest::NS_ERROR_UNKNOWN_PROXY_HOST; |
case CURLE_COULDNT_RESOLVE_HOST: |
- return NS_ERROR_UNKNOWN_HOST; |
+ return AdblockPlus::WebRequest::NS_ERROR_UNKNOWN_HOST; |
case CURLE_COULDNT_CONNECT: |
- return NS_ERROR_CONNECTION_REFUSED; |
+ return AdblockPlus::WebRequest::NS_ERROR_CONNECTION_REFUSED; |
case CURLE_OUT_OF_MEMORY: |
- return NS_ERROR_OUT_OF_MEMORY; |
+ return AdblockPlus::WebRequest::NS_ERROR_OUT_OF_MEMORY; |
case CURLE_OPERATION_TIMEDOUT: |
- return NS_ERROR_NET_TIMEOUT; |
+ return AdblockPlus::WebRequest::NS_ERROR_NET_TIMEOUT; |
case CURLE_TOO_MANY_REDIRECTS: |
- return NS_ERROR_REDIRECT_LOOP; |
+ return AdblockPlus::WebRequest::NS_ERROR_REDIRECT_LOOP; |
case CURLE_GOT_NOTHING: |
- return NS_ERROR_NO_CONTENT; |
+ return AdblockPlus::WebRequest::NS_ERROR_NO_CONTENT; |
case CURLE_SEND_ERROR: |
- return NS_ERROR_NET_RESET; |
+ return AdblockPlus::WebRequest::NS_ERROR_NET_RESET; |
case CURLE_RECV_ERROR: |
- return NS_ERROR_NET_RESET; |
+ return AdblockPlus::WebRequest::NS_ERROR_NET_RESET; |
default: |
- return NS_CUSTOM_ERROR_BASE + code; |
+ return AdblockPlus::WebRequest::NS_CUSTOM_ERROR_BASE + code; |
} |
} |
size_t ReceiveData(char* ptr, size_t size, size_t nmemb, void* userdata) |
{ |
std::stringstream* stream = static_cast<std::stringstream*>(userdata); |
stream->write(ptr, size * nmemb); |
return nmemb; |
@@ -130,17 +123,17 @@ AdblockPlus::ServerResponse AdblockPlus: |
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseText); |
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, ReceiveHeader); |
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &headerData); |
struct curl_slist* headerList = 0; |
for (HeaderList::const_iterator it = requestHeaders.begin(); |
it != requestHeaders.end(); ++it) |
{ |
- curl_slist_append(headerList, (it->first + ": " + it->second).c_str()); |
+ headerList = curl_slist_append(headerList, (it->first + ": " + it->second).c_str()); |
} |
if (headerList) |
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerList); |
result.status = ConvertErrorCode(curl_easy_perform(curl)); |
result.responseStatus = headerData.status; |
result.responseText = responseText.str(); |
for (std::vector<std::string>::iterator it = headerData.headers.begin(); |
@@ -173,18 +166,8 @@ AdblockPlus::ServerResponse AdblockPlus: |
} |
if (headerList) |
curl_slist_free_all(headerList); |
curl_easy_cleanup(curl); |
} |
return result; |
} |
-#else |
-AdblockPlus::ServerResponse AdblockPlus::DefaultWebRequest::GET( |
- const std::string& url, const HeaderList& requestHeaders) const |
-{ |
- AdblockPlus::ServerResponse result; |
- result.status = NS_ERROR_FAILURE; |
- result.responseStatus = 0; |
- return result; |
-} |
-#endif |