diff options
author | Zach Mullen <zach.mullen@kitware.com> | 2009-12-30 16:10:42 (GMT) |
---|---|---|
committer | Zach Mullen <zach.mullen@kitware.com> | 2009-12-30 16:10:42 (GMT) |
commit | 0a0788a72d72ffe40624c6e47fdf5c30a7ab8ac6 (patch) | |
tree | 6ea2148de0638fd7d63af8cf676a09bddc045bd0 /Source | |
parent | 646e71f29021d76998d1161dc00d52f00ad2b94b (diff) | |
download | CMake-0a0788a72d72ffe40624c6e47fdf5c30a7ab8ac6.zip CMake-0a0788a72d72ffe40624c6e47fdf5c30a7ab8ac6.tar.gz CMake-0a0788a72d72ffe40624c6e47fdf5c30a7ab8ac6.tar.bz2 |
Enhanced CTest HTTP Request API to support PUT file uploads.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCTest.cxx | 38 | ||||
-rw-r--r-- | Source/cmCTest.h | 6 |
2 files changed, 33 insertions, 11 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index bcbe18e..c6dffd7 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -172,22 +172,42 @@ HTTPResponseCallback(void *ptr, size_t size, size_t nmemb, void *data) //---------------------------------------------------------------------------- int cmCTest::HTTPRequest(std::string url, HTTPMethod method, std::string& response, - std::string fields, int timeout) + std::string fields, + std::string putFile, int timeout) { CURL* curl; + FILE* file; ::curl_global_init(CURL_GLOBAL_ALL); curl = ::curl_easy_init(); - //set request options - if(method == cmCTest::HTTP_GET && fields.size()) + //set request options based on method + switch(method) { - url += "?" + fields; - } - else - { - ::curl_easy_setopt(curl, CURLOPT_POST, 1); - ::curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fields.c_str()); + case cmCTest::HTTP_POST: + ::curl_easy_setopt(curl, CURLOPT_POST, 1); + ::curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fields.c_str()); + break; + case cmCTest::HTTP_PUT: + if(!cmSystemTools::FileExists(putFile.c_str())) + { + response = "Error: File "; + response += putFile + " does not exist.\n"; + return -1; + } + ::curl_easy_setopt(curl, CURLOPT_PUT, 1); + file = ::fopen(putFile.c_str(), "rb"); + ::curl_easy_setopt(curl, CURLOPT_INFILE, file); + //fall through to append GET fields + case cmCTest::HTTP_GET: + if(fields.size()) + { + url += "?" + fields; + } + break; + default: + break; } + ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 2b7912c..8621b10 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -83,7 +83,8 @@ public: #ifdef CMAKE_BUILD_WITH_CMAKE enum HTTPMethod { HTTP_GET, - HTTP_POST + HTTP_POST, + HTTP_PUT }; /** @@ -91,7 +92,8 @@ public: */ static int HTTPRequest(std::string url, HTTPMethod method, std::string& response, - std::string fields = "", int timeout = 10); + std::string fields = "", + std::string putFile = "", int timeout = 0); #endif /** Get a testing part id from its string name. Returns PartCount |