diff options
author | Zach Mullen <zach.mullen@kitware.com> | 2009-12-22 19:37:06 (GMT) |
---|---|---|
committer | Zach Mullen <zach.mullen@kitware.com> | 2009-12-22 19:37:06 (GMT) |
commit | 3cb2a0ffa6f87954825cb311999fde1902b576de (patch) | |
tree | 25c17b2af4e41bbee08606554b765f3e2d2dbcf0 /Source | |
parent | 766ef1d01136747605b58c243e6074dda00667f8 (diff) | |
download | CMake-3cb2a0ffa6f87954825cb311999fde1902b576de.zip CMake-3cb2a0ffa6f87954825cb311999fde1902b576de.tar.gz CMake-3cb2a0ffa6f87954825cb311999fde1902b576de.tar.bz2 |
Move cURL dependent code out of CMakeLib to fix complex tests.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCTest.cxx | 54 | ||||
-rw-r--r-- | Source/cmCTest.h | 13 | ||||
-rw-r--r-- | Source/cmSystemTools.cxx | 53 | ||||
-rw-r--r-- | Source/cmSystemTools.h | 12 |
4 files changed, 66 insertions, 66 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 01f5836..c9ef5f3 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -154,6 +154,58 @@ std::string cmCTest::CurrentTime() return cmXMLSafe(cmCTest::CleanString(current_time)).str(); } +#ifdef CMAKE_BUILD_WITH_CMAKE +//---------------------------------------------------------------------------- +static size_t +HTTPResponseCallback(void *ptr, size_t size, size_t nmemb, void *data) +{ + register int realsize = (int)(size * nmemb); + + std::string *response + = static_cast<std::string*>(data); + const char* chPtr = static_cast<char*>(ptr); + *response += chPtr; + + return realsize; +} + +//---------------------------------------------------------------------------- +int cmCTest::HTTPRequest(std::string url, HTTPMethod method, + std::string& response, + std::string fields, int timeout) +{ + CURL* curl; + ::curl_global_init(CURL_GLOBAL_ALL); + curl = ::curl_easy_init(); + + //set request options + if(method == cmCTest::HTTP_GET && fields.size()) + { + url += "?" + fields; + } + else + { + ::curl_easy_setopt(curl, CURLOPT_POST, 1); + ::curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fields.c_str()); + } + ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); + ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); + + //set response options + ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPResponseCallback); + ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&response); + ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); + + CURLcode res = ::curl_easy_perform(curl); + + ::curl_easy_cleanup(curl); + ::curl_global_cleanup(); + + return static_cast<int>(res); +} +#endif + //---------------------------------------------------------------------- std::string cmCTest::MakeURLSafe(const std::string& str) { @@ -326,7 +378,7 @@ std::string cmCTest::GetCDashVersion() std::string url = "http://"; url += this->GetCTestConfiguration("DropSite") + "/CDash/api/getversion.php"; - int res = cmSystemTools::HTTPRequest(url, cmSystemTools::HTTP_GET, response); + int res = cmCTest::HTTPRequest(url, cmCTest::HTTP_GET, response); return res ? this->GetCTestConfiguration("CDashVersion") : response; #else diff --git a/Source/cmCTest.h b/Source/cmCTest.h index d0b9e1e..eb88f62 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -80,6 +80,19 @@ public: bool Enabled; std::string Name; }; +#ifdef CMAKE_BUILD_WITH_CMAKE + enum HTTPMethod { + HTTP_GET, + HTTP_POST + }; + + /** + * Perform an HTTP request. + */ + static int HTTPRequest(std::string url, HTTPMethod method, + std::string& response, + std::string fields = "", int timeout = 10); +#endif /** Get a testing part id from its string name. Returns PartCount if the string does not name a valid part. */ diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index e89c479..89a241d 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -26,7 +26,6 @@ #include <cmlibarchive/libarchive/archive.h> #include <cmlibarchive/libarchive/archive_entry.h> # include <cmsys/Terminal.h> -#include "cm_curl.h" #endif #include <cmsys/stl/algorithm> @@ -2926,55 +2925,3 @@ bool cmSystemTools::CheckRPath(std::string const& file, return false; #endif } - -//---------------------------------------------------------------------------- -static size_t -HTTPResponseCallback(void *ptr, size_t size, size_t nmemb, void *data) -{ - register int realsize = (int)(size * nmemb); - - std::string *response - = static_cast<std::string*>(data); - const char* chPtr = static_cast<char*>(ptr); - *response += chPtr; - - return realsize; -} - -#ifdef CMAKE_BUILD_WITH_CMAKE -//---------------------------------------------------------------------------- -int cmSystemTools::HTTPRequest(std::string url, HTTPMethod method, - std::string& response, - std::string fields, int timeout) -{ - CURL* curl; - ::curl_global_init(CURL_GLOBAL_ALL); - curl = ::curl_easy_init(); - - //set request options - if(method == cmSystemTools::HTTP_GET && fields.size()) - { - url += "?" + fields; - } - else - { - ::curl_easy_setopt(curl, CURLOPT_POST, 1); - ::curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fields.c_str()); - } - ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); - ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); - - //set response options - ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPResponseCallback); - ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&response); - ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); - - CURLcode res = ::curl_easy_perform(curl); - - ::curl_easy_cleanup(curl); - ::curl_global_cleanup(); - - return static_cast<int>(res); -} -#endif diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 7bdc14f..e5bb305 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -342,18 +342,6 @@ public: static std::string RelativePath(const char* local, const char* remote); #ifdef CMAKE_BUILD_WITH_CMAKE - enum HTTPMethod { - HTTP_GET, - HTTP_POST - }; - - /** - * Perform an HTTP request. - */ - static int HTTPRequest(std::string url, HTTPMethod method, - std::string& response, - std::string fields = "", int timeout = 10); - /** Remove an environment variable */ static bool UnsetEnv(const char* value); |