From 43c01e07504e2ab61e7a30b428c1c9601791f948 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 28 May 2015 10:15:00 -0400 Subject: [PATCH 1/4] cmFileCommand: Remove leftover no-op debugging logic Remove debugging logic left from commit v2.6.0~305 (add DOWNLOAD option to FILE command, 2008-02-06). The CURLE_OPERATION_TIMEOUTED code path does nothing that the code immediately after it does not do. --- Source/cmFileCommand.cxx | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 0af4688e5..f0d02862c 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -3290,17 +3290,6 @@ cmFileCommand::HandleDownloadCommand(std::vector const& args) if(!chunkDebug.empty()) { chunkDebug.push_back(0); - if(CURLE_OPERATION_TIMEOUTED == res) - { - std::string output = &*chunkDebug.begin(); - - if(!verboseLog.empty()) - { - this->Makefile->AddDefinition(verboseLog, - &*chunkDebug.begin()); - } - } - this->Makefile->AddDefinition(verboseLog, &*chunkDebug.begin()); } From 0d37dcd33534be17ac0ae13cb59b18743dbdb4f1 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 28 May 2015 10:33:44 -0400 Subject: [PATCH 2/4] cmFileCommand: Rename variable verboseLog => logVar This makes the LOG variable name consistent between UPLOAD and DOWNLOAD implementations. --- Source/cmFileCommand.cxx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index f0d02862c..984989e4b 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -2963,7 +2963,7 @@ cmFileCommand::HandleDownloadCommand(std::vector const& args) long timeout = 0; long inactivity_timeout = 0; - std::string verboseLog; + std::string logVar; std::string statusVar; bool tls_verify = this->Makefile->IsOn("CMAKE_TLS_VERIFY"); const char* cainfo = this->Makefile->GetDefinition("CMAKE_TLS_CAINFO"); @@ -3008,7 +3008,7 @@ cmFileCommand::HandleDownloadCommand(std::vector const& args) this->SetError("DOWNLOAD missing VAR for LOG."); return false; } - verboseLog = *i; + logVar = *i; } else if(*i == "STATUS") { @@ -3200,7 +3200,7 @@ cmFileCommand::HandleDownloadCommand(std::vector const& args) res = ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); check_curl_result(res, "DOWNLOAD cannot set follow-redirect option: "); - if(!verboseLog.empty()) + if(!logVar.empty()) { res = ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); check_curl_result(res, "DOWNLOAD cannot set verbose: "); @@ -3290,8 +3290,7 @@ cmFileCommand::HandleDownloadCommand(std::vector const& args) if(!chunkDebug.empty()) { chunkDebug.push_back(0); - this->Makefile->AddDefinition(verboseLog, - &*chunkDebug.begin()); + this->Makefile->AddDefinition(logVar, &*chunkDebug.begin()); } return true; From 7e10f1691f61949430180882e3a2484d0859b9e2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 28 May 2015 10:35:08 -0400 Subject: [PATCH 3/4] cmFileCommand: Clarify logic for populating LOG variable The chunkDebug buffer we use to accumulate the LOG variable content is populated if and only if a log variable was requested by the call, but it is much clearer to check that a log variable was requested explicitly before populating it. --- Source/cmFileCommand.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 984989e4b..2c2c1c03b 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -3287,7 +3287,7 @@ cmFileCommand::HandleDownloadCommand(std::vector const& args) } } - if(!chunkDebug.empty()) + if (!logVar.empty()) { chunkDebug.push_back(0); this->Makefile->AddDefinition(logVar, &*chunkDebug.begin()); From eba12a43615ee603f7e90a8e4e8c7669e7d63cf8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 28 May 2015 10:54:39 -0400 Subject: [PATCH 4/4] cmFileCommand: Do not log raw protocol data from curl (#15589) Teach cmFileCommandCurlDebugCallback to filter the debug data by type and show only summary information instead of the raw data. This avoids allocating memory for all data transferred by UPLOAD or DOWNLOAD. --- Source/cmFileCommand.cxx | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 2c2c1c03b..469846815 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -2798,13 +2798,36 @@ namespace { static size_t - cmFileCommandCurlDebugCallback(CURL *, curl_infotype, char *chPtr, + cmFileCommandCurlDebugCallback(CURL *, curl_infotype type, char *chPtr, size_t size, void *data) { cmFileCommandVectorOfChar *vec = static_cast(data); - vec->insert(vec->end(), chPtr, chPtr + size); - return size; + switch(type) + { + case CURLINFO_TEXT: + case CURLINFO_HEADER_IN: + case CURLINFO_HEADER_OUT: + vec->insert(vec->end(), chPtr, chPtr + size); + break; + case CURLINFO_DATA_IN: + case CURLINFO_DATA_OUT: + case CURLINFO_SSL_DATA_IN: + case CURLINFO_SSL_DATA_OUT: + { + char buf[128]; + int n = sprintf(buf, "[%" cmIML_INT_PRIu64 " bytes data]\n", + static_cast(size)); + if (n > 0) + { + vec->insert(vec->end(), buf, buf + n); + } + } + break; + default: + break; + } + return 0; }