cmCTestCurl: Factor out helper struct for curl options
This commit is contained in:
parent
7f668bb94f
commit
8a3a486fb5
@ -9,11 +9,13 @@
|
|||||||
|
|
||||||
#include "cmCTest.h"
|
#include "cmCTest.h"
|
||||||
#include "cmCurl.h"
|
#include "cmCurl.h"
|
||||||
|
#include "cmList.h"
|
||||||
#include "cmStringAlgorithms.h"
|
#include "cmStringAlgorithms.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
|
|
||||||
cmCTestCurl::cmCTestCurl(cmCTest* ctest)
|
cmCTestCurl::cmCTestCurl(cmCTest* ctest)
|
||||||
: CTest(ctest)
|
: CTest(ctest)
|
||||||
|
, CurlOpts(ctest)
|
||||||
{
|
{
|
||||||
this->SetProxyType();
|
this->SetProxyType();
|
||||||
// In windows, this will init the winsock stuff
|
// 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) {
|
for (std::string const& arg : args) {
|
||||||
if (arg == "CURLOPT_SSL_VERIFYPEER_OFF") {
|
if (arg == "CURLOPT_SSL_VERIFYPEER_OFF") {
|
||||||
this->VerifyPeerOff = true;
|
this->VerifyPeerOff = true;
|
||||||
@ -71,10 +74,10 @@ bool cmCTestCurl::InitCurl()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cmCurlSetCAInfo(this->Curl);
|
cmCurlSetCAInfo(this->Curl);
|
||||||
if (this->VerifyPeerOff) {
|
if (this->CurlOpts.VerifyPeerOff) {
|
||||||
curl_easy_setopt(this->Curl, CURLOPT_SSL_VERIFYPEER, 0);
|
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);
|
curl_easy_setopt(this->Curl, CURLOPT_SSL_VERIFYHOST, 0);
|
||||||
}
|
}
|
||||||
if (!this->HTTPProxy.empty()) {
|
if (!this->HTTPProxy.empty()) {
|
||||||
|
@ -11,6 +11,13 @@
|
|||||||
|
|
||||||
class cmCTest;
|
class cmCTest;
|
||||||
|
|
||||||
|
struct cmCTestCurlOpts
|
||||||
|
{
|
||||||
|
cmCTestCurlOpts(cmCTest* ctest);
|
||||||
|
bool VerifyPeerOff = false;
|
||||||
|
bool VerifyHostOff = false;
|
||||||
|
};
|
||||||
|
|
||||||
class cmCTestCurl
|
class cmCTestCurl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -22,9 +29,6 @@ public:
|
|||||||
std::string const& fields, std::string& response);
|
std::string const& fields, std::string& response);
|
||||||
bool HttpRequest(std::string const& url, std::string const& fields,
|
bool HttpRequest(std::string const& url, std::string const& fields,
|
||||||
std::string& response);
|
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)
|
void SetHttpHeaders(std::vector<std::string> const& v)
|
||||||
{
|
{
|
||||||
this->HttpHeaders = v;
|
this->HttpHeaders = v;
|
||||||
@ -40,13 +44,12 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
cmCTest* CTest;
|
cmCTest* CTest;
|
||||||
|
cmCTestCurlOpts CurlOpts;
|
||||||
CURL* Curl = nullptr;
|
CURL* Curl = nullptr;
|
||||||
std::vector<std::string> HttpHeaders;
|
std::vector<std::string> HttpHeaders;
|
||||||
std::string HTTPProxyAuth;
|
std::string HTTPProxyAuth;
|
||||||
std::string HTTPProxy;
|
std::string HTTPProxy;
|
||||||
curl_proxytype HTTPProxyType;
|
curl_proxytype HTTPProxyType;
|
||||||
bool VerifyHostOff = false;
|
|
||||||
bool VerifyPeerOff = false;
|
|
||||||
bool UseHttp10 = false;
|
bool UseHttp10 = false;
|
||||||
bool Quiet = false;
|
bool Quiet = false;
|
||||||
int TimeOutSeconds = 0;
|
int TimeOutSeconds = 0;
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "cmCurl.h"
|
#include "cmCurl.h"
|
||||||
#include "cmDuration.h"
|
#include "cmDuration.h"
|
||||||
#include "cmGeneratedFileStream.h"
|
#include "cmGeneratedFileStream.h"
|
||||||
#include "cmList.h"
|
|
||||||
#include "cmState.h"
|
#include "cmState.h"
|
||||||
#include "cmStringAlgorithms.h"
|
#include "cmStringAlgorithms.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
@ -172,30 +171,19 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(
|
|||||||
|
|
||||||
/* In windows, this will init the winsock stuff */
|
/* In windows, this will init the winsock stuff */
|
||||||
::curl_global_init(CURL_GLOBAL_ALL);
|
::curl_global_init(CURL_GLOBAL_ALL);
|
||||||
std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions"));
|
cmCTestCurlOpts curlOpts(this->CTest);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (std::string const& file : files) {
|
for (std::string const& file : files) {
|
||||||
/* get a curl handle */
|
/* get a curl handle */
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if (curl) {
|
if (curl) {
|
||||||
cmCurlSetCAInfo(curl);
|
cmCurlSetCAInfo(curl);
|
||||||
if (verifyPeerOff) {
|
if (curlOpts.VerifyPeerOff) {
|
||||||
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
||||||
" Set CURLOPT_SSL_VERIFYPEER to off\n",
|
" Set CURLOPT_SSL_VERIFYPEER to off\n",
|
||||||
this->Quiet);
|
this->Quiet);
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||||
}
|
}
|
||||||
if (verifyHostOff) {
|
if (curlOpts.VerifyHostOff) {
|
||||||
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
||||||
" Set CURLOPT_SSL_VERIFYHOST to off\n",
|
" Set CURLOPT_SSL_VERIFYHOST to off\n",
|
||||||
this->Quiet);
|
this->Quiet);
|
||||||
@ -518,9 +506,6 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
|
|||||||
}
|
}
|
||||||
cmCTestCurl curl(this->CTest);
|
cmCTestCurl curl(this->CTest);
|
||||||
curl.SetQuiet(this->Quiet);
|
curl.SetQuiet(this->Quiet);
|
||||||
std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions"));
|
|
||||||
cmList args{ curlopt };
|
|
||||||
curl.SetCurlOptions(args);
|
|
||||||
auto submitInactivityTimeout = this->GetSubmitInactivityTimeout();
|
auto submitInactivityTimeout = this->GetSubmitInactivityTimeout();
|
||||||
if (submitInactivityTimeout != 0) {
|
if (submitInactivityTimeout != 0) {
|
||||||
curl.SetTimeOutSeconds(submitInactivityTimeout);
|
curl.SetTimeOutSeconds(submitInactivityTimeout);
|
||||||
|
Loading…
Reference in New Issue
Block a user