file(DOWNLOAD|UPLOAD): Add 'USERPWD' suboption

This commit is contained in:
Ruslan Baratov 2016-09-13 20:24:12 +03:00
parent 112f758223
commit e5ba1041be
9 changed files with 43 additions and 0 deletions

View File

@ -222,6 +222,9 @@ Options to both ``DOWNLOAD`` and ``UPLOAD`` are:
``TIMEOUT <seconds>`` ``TIMEOUT <seconds>``
Terminate the operation after a given total time has elapsed. Terminate the operation after a given total time has elapsed.
``USERPWD <username>:<password>``
Set username and password for operation.
Additional options to ``DOWNLOAD`` are: Additional options to ``DOWNLOAD`` are:
``EXPECTED_HASH ALGO=<value>`` ``EXPECTED_HASH ALGO=<value>``

View File

@ -2481,6 +2481,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
std::string hashMatchMSG; std::string hashMatchMSG;
CM_AUTO_PTR<cmCryptoHash> hash; CM_AUTO_PTR<cmCryptoHash> hash;
bool showProgress = false; bool showProgress = false;
std::string userpwd;
while (i != args.end()) { while (i != args.end()) {
if (*i == "TIMEOUT") { if (*i == "TIMEOUT") {
@ -2564,6 +2565,13 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
return false; return false;
} }
hashMatchMSG = algo + " hash"; hashMatchMSG = algo + " hash";
} else if (*i == "USERPWD") {
++i;
if (i == args.end()) {
this->SetError("DOWNLOAD missing string for USERPWD.");
return false;
}
userpwd = *i;
} else { } else {
// Do not return error for compatibility reason. // Do not return error for compatibility reason.
std::string err = "Unexpected argument: "; std::string err = "Unexpected argument: ";
@ -2703,6 +2711,11 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
check_curl_result(res, "DOWNLOAD cannot set progress data: "); check_curl_result(res, "DOWNLOAD cannot set progress data: ");
} }
if (!userpwd.empty()) {
res = ::curl_easy_setopt(curl, CURLOPT_USERPWD, userpwd.c_str());
check_curl_result(res, "DOWNLOAD cannot set user password: ");
}
res = ::curl_easy_perform(curl); res = ::curl_easy_perform(curl);
/* always cleanup */ /* always cleanup */
@ -2783,6 +2796,7 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
std::string logVar; std::string logVar;
std::string statusVar; std::string statusVar;
bool showProgress = false; bool showProgress = false;
std::string userpwd;
while (i != args.end()) { while (i != args.end()) {
if (*i == "TIMEOUT") { if (*i == "TIMEOUT") {
@ -2817,6 +2831,13 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
statusVar = *i; statusVar = *i;
} else if (*i == "SHOW_PROGRESS") { } else if (*i == "SHOW_PROGRESS") {
showProgress = true; showProgress = true;
} else if (*i == "USERPWD") {
++i;
if (i == args.end()) {
this->SetError("UPLOAD missing string for USERPWD.");
return false;
}
userpwd = *i;
} else { } else {
// Do not return error for compatibility reason. // Do not return error for compatibility reason.
std::string err = "Unexpected argument: "; std::string err = "Unexpected argument: ";
@ -2930,6 +2951,11 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(file_size)); ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(file_size));
check_curl_result(res, "UPLOAD cannot set input file size: "); check_curl_result(res, "UPLOAD cannot set input file size: ");
if (!userpwd.empty()) {
res = ::curl_easy_setopt(curl, CURLOPT_USERPWD, userpwd.c_str());
check_curl_result(res, "UPLOAD cannot set user password: ");
}
res = ::curl_easy_perform(curl); res = ::curl_easy_perform(curl);
/* always cleanup */ /* always cleanup */

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
^CMake Error at DOWNLOAD-pass-not-set.cmake:[0-9]+ \(file\):
file DOWNLOAD missing string for USERPWD.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)$

View File

@ -0,0 +1 @@
file(DOWNLOAD "" "" USERPWD)

View File

@ -2,7 +2,9 @@ include(RunCMake)
run_cmake(DOWNLOAD-hash-mismatch) run_cmake(DOWNLOAD-hash-mismatch)
run_cmake(DOWNLOAD-unused-argument) run_cmake(DOWNLOAD-unused-argument)
run_cmake(DOWNLOAD-pass-not-set)
run_cmake(UPLOAD-unused-argument) run_cmake(UPLOAD-unused-argument)
run_cmake(UPLOAD-pass-not-set)
run_cmake(INSTALL-DIRECTORY) run_cmake(INSTALL-DIRECTORY)
run_cmake(INSTALL-MESSAGE-bad) run_cmake(INSTALL-MESSAGE-bad)
run_cmake(FileOpenFailRead) run_cmake(FileOpenFailRead)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
^CMake Error at UPLOAD-pass-not-set.cmake:[0-9]+ \(file\):
file UPLOAD missing string for USERPWD.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)$

View File

@ -0,0 +1 @@
file(UPLOAD "" "" USERPWD)