From 1fda5599e097d37c2b45247606b0e7f0fd864b85 Mon Sep 17 00:00:00 2001 From: Bjoern Sikora Date: Fri, 9 Oct 2009 17:27:47 +0200 Subject: [PATCH] Bugfix: Curl appends rather than overrites writedata buff, so we need to copy and clear it. --- src/httphelper.cpp | 8 +++++++- src/httphelper.h | 1 + 2 files changed, 8 insertions(+), 1 deletions(-) diff --git a/src/httphelper.cpp b/src/httphelper.cpp index f5082b4..8f7d183 100644 --- a/src/httphelper.cpp +++ b/src/httphelper.cpp @@ -69,16 +69,22 @@ long HTTPHelper::http_get(const string& url) if ( (curl_err_code = curl_easy_perform(CurlEasyHandle) ) != 0 ) { Log->print_curl_error(url,curl_err_code,CurlErrBuff); + CurlWritedataBuff.clear(); return -1; } if ( (curl_err_code = curl_easy_getinfo(CurlEasyHandle,CURLINFO_RESPONSE_CODE,&curl_info)) != 0 ) { Log->print_curl_error(url,curl_err_code); + CurlWritedataBuff.clear(); return -1; } Log->print_curl_data(CurlWritedataBuff); + // Copy the received data received via curl from the curl data buffer member to the received data member. This is needed because curl appends data to the buffer rather than overrites it. + ReceivedCurlData = CurlWritedataBuff; + CurlWritedataBuff.clear(); + // Operation performed without any problems so we can return the curl_info return curl_info; } @@ -90,7 +96,7 @@ long HTTPHelper::http_get(const string& url) */ string HTTPHelper::get_curl_data() const { - return CurlWritedataBuff; + return ReceivedCurlData; } diff --git a/src/httphelper.h b/src/httphelper.h index 09701d0..bbec3ec 100644 --- a/src/httphelper.h +++ b/src/httphelper.h @@ -26,6 +26,7 @@ private: int ProxyPort; CURL* CurlEasyHandle; std::string CurlWritedataBuff; + std::string ReceivedCurlData; char CurlErrBuff[CURL_ERROR_SIZE]; void set_curl_url(const std::string& url); -- 1.7.1