diff options
author | Brad King <brad.king@kitware.com> | 2024-03-01 15:47:38 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-03-12 14:43:38 (GMT) |
commit | 8a3a486fb50d179be34e3b2165008f5495112a19 (patch) | |
tree | c7ac4c5d113696597ee52a54a28f36d759161ce0 /Source/CTest | |
parent | 7f668bb94fcf4a556495bbfa34a7c64b63747112 (diff) | |
download | CMake-8a3a486fb50d179be34e3b2165008f5495112a19.zip CMake-8a3a486fb50d179be34e3b2165008f5495112a19.tar.gz CMake-8a3a486fb50d179be34e3b2165008f5495112a19.tar.bz2 |
cmCTestCurl: Factor out helper struct for curl options
Diffstat (limited to 'Source/CTest')
-rw-r--r-- | Source/CTest/cmCTestCurl.cxx | 9 | ||||
-rw-r--r-- | Source/CTest/cmCTestCurl.h | 13 | ||||
-rw-r--r-- | Source/CTest/cmCTestSubmitHandler.cxx | 21 |
3 files changed, 17 insertions, 26 deletions
diff --git a/Source/CTest/cmCTestCurl.cxx b/Source/CTest/cmCTestCurl.cxx index e90b494..d3a0a13 100644 --- a/Source/CTest/cmCTestCurl.cxx +++ b/Source/CTest/cmCTestCurl.cxx @@ -9,11 +9,13 @@ #include "cmCTest.h" #include "cmCurl.h" +#include "cmList.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" cmCTestCurl::cmCTestCurl(cmCTest* ctest) : CTest(ctest) + , CurlOpts(ctest) { this->SetProxyType(); // In windows, this will init the winsock stuff @@ -53,8 +55,9 @@ size_t curlDebugCallback(CURL* /*unused*/, curl_infotype /*unused*/, } } -void cmCTestCurl::SetCurlOptions(std::vector<std::string> const& args) +cmCTestCurlOpts::cmCTestCurlOpts(cmCTest* ctest) { + cmList args{ ctest->GetCTestConfiguration("CurlOptions") }; for (std::string const& arg : args) { if (arg == "CURLOPT_SSL_VERIFYPEER_OFF") { this->VerifyPeerOff = true; @@ -71,10 +74,10 @@ bool cmCTestCurl::InitCurl() return false; } cmCurlSetCAInfo(this->Curl); - if (this->VerifyPeerOff) { + if (this->CurlOpts.VerifyPeerOff) { curl_easy_setopt(this->Curl, CURLOPT_SSL_VERIFYPEER, 0); } - if (this->VerifyHostOff) { + if (this->CurlOpts.VerifyHostOff) { curl_easy_setopt(this->Curl, CURLOPT_SSL_VERIFYHOST, 0); } if (!this->HTTPProxy.empty()) { diff --git a/Source/CTest/cmCTestCurl.h b/Source/CTest/cmCTestCurl.h index 44c1828..ea60f19 100644 --- a/Source/CTest/cmCTestCurl.h +++ b/Source/CTest/cmCTestCurl.h @@ -11,6 +11,13 @@ class cmCTest; +struct cmCTestCurlOpts +{ + cmCTestCurlOpts(cmCTest* ctest); + bool VerifyPeerOff = false; + bool VerifyHostOff = false; +}; + class cmCTestCurl { public: @@ -22,9 +29,6 @@ public: std::string const& fields, std::string& response); bool HttpRequest(std::string const& url, std::string const& fields, std::string& response); - // currently only supports CURLOPT_SSL_VERIFYPEER_OFF - // and CURLOPT_SSL_VERIFYHOST_OFF - void SetCurlOptions(std::vector<std::string> const& args); void SetHttpHeaders(std::vector<std::string> const& v) { this->HttpHeaders = v; @@ -40,13 +44,12 @@ protected: private: cmCTest* CTest; + cmCTestCurlOpts CurlOpts; CURL* Curl = nullptr; std::vector<std::string> HttpHeaders; std::string HTTPProxyAuth; std::string HTTPProxy; curl_proxytype HTTPProxyType; - bool VerifyHostOff = false; - bool VerifyPeerOff = false; bool UseHttp10 = false; bool Quiet = false; int TimeOutSeconds = 0; diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index db8a054..654fbfa 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -22,7 +22,6 @@ #include "cmCurl.h" #include "cmDuration.h" #include "cmGeneratedFileStream.h" -#include "cmList.h" #include "cmState.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -172,30 +171,19 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( /* In windows, this will init the winsock stuff */ ::curl_global_init(CURL_GLOBAL_ALL); - std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions")); - cmList args{ curlopt }; - bool verifyPeerOff = false; - bool verifyHostOff = false; - for (std::string const& arg : args) { - if (arg == "CURLOPT_SSL_VERIFYPEER_OFF") { - verifyPeerOff = true; - } - if (arg == "CURLOPT_SSL_VERIFYHOST_OFF") { - verifyHostOff = true; - } - } + cmCTestCurlOpts curlOpts(this->CTest); for (std::string const& file : files) { /* get a curl handle */ curl = curl_easy_init(); if (curl) { cmCurlSetCAInfo(curl); - if (verifyPeerOff) { + if (curlOpts.VerifyPeerOff) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Set CURLOPT_SSL_VERIFYPEER to off\n", this->Quiet); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); } - if (verifyHostOff) { + if (curlOpts.VerifyHostOff) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Set CURLOPT_SSL_VERIFYHOST to off\n", this->Quiet); @@ -518,9 +506,6 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file, } cmCTestCurl curl(this->CTest); curl.SetQuiet(this->Quiet); - std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions")); - cmList args{ curlopt }; - curl.SetCurlOptions(args); auto submitInactivityTimeout = this->GetSubmitInactivityTimeout(); if (submitInactivityTimeout != 0) { curl.SetTimeOutSeconds(submitInactivityTimeout); |