cmCTestSubmitHandler.cxx 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCTestSubmitHandler.h"
  4. #include "cm_curl.h"
  5. #include "cm_jsoncpp_reader.h"
  6. #include "cm_jsoncpp_value.h"
  7. #include "cmsys/Process.h"
  8. #include <chrono>
  9. #include <cstring>
  10. #include <sstream>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "cmAlgorithms.h"
  14. #include "cmCTest.h"
  15. #include "cmCTestCurl.h"
  16. #include "cmCTestScriptHandler.h"
  17. #include "cmCryptoHash.h"
  18. #include "cmCurl.h"
  19. #include "cmDuration.h"
  20. #include "cmGeneratedFileStream.h"
  21. #include "cmProcessOutput.h"
  22. #include "cmState.h"
  23. #include "cmSystemTools.h"
  24. #include "cmThirdParty.h"
  25. #include "cmWorkingDirectory.h"
  26. #include "cmXMLParser.h"
  27. #include "cmake.h"
  28. #if defined(CTEST_USE_XMLRPC)
  29. # include "cmVersion.h"
  30. # include "cm_sys_stat.h"
  31. # include "cm_xmlrpc.h"
  32. #endif
  33. #define SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT 120
  34. typedef std::vector<char> cmCTestSubmitHandlerVectorOfChar;
  35. class cmCTestSubmitHandler::ResponseParser : public cmXMLParser
  36. {
  37. public:
  38. ResponseParser() { this->Status = STATUS_OK; }
  39. ~ResponseParser() override {}
  40. public:
  41. enum StatusType
  42. {
  43. STATUS_OK,
  44. STATUS_WARNING,
  45. STATUS_ERROR
  46. };
  47. StatusType Status;
  48. std::string Filename;
  49. std::string MD5;
  50. std::string Message;
  51. std::string BuildID;
  52. private:
  53. std::vector<char> CurrentValue;
  54. std::string GetCurrentValue()
  55. {
  56. std::string val;
  57. if (!this->CurrentValue.empty()) {
  58. val.assign(&this->CurrentValue[0], this->CurrentValue.size());
  59. }
  60. return val;
  61. }
  62. void StartElement(const std::string& /*name*/,
  63. const char** /*atts*/) override
  64. {
  65. this->CurrentValue.clear();
  66. }
  67. void CharacterDataHandler(const char* data, int length) override
  68. {
  69. this->CurrentValue.insert(this->CurrentValue.end(), data, data + length);
  70. }
  71. void EndElement(const std::string& name) override
  72. {
  73. if (name == "status") {
  74. std::string status = cmSystemTools::UpperCase(this->GetCurrentValue());
  75. if (status == "OK" || status == "SUCCESS") {
  76. this->Status = STATUS_OK;
  77. } else if (status == "WARNING") {
  78. this->Status = STATUS_WARNING;
  79. } else {
  80. this->Status = STATUS_ERROR;
  81. }
  82. } else if (name == "filename") {
  83. this->Filename = this->GetCurrentValue();
  84. } else if (name == "md5") {
  85. this->MD5 = this->GetCurrentValue();
  86. } else if (name == "message") {
  87. this->Message = this->GetCurrentValue();
  88. } else if (name == "buildId") {
  89. this->BuildID = this->GetCurrentValue();
  90. }
  91. }
  92. };
  93. static size_t cmCTestSubmitHandlerWriteMemoryCallback(void* ptr, size_t size,
  94. size_t nmemb, void* data)
  95. {
  96. int realsize = static_cast<int>(size * nmemb);
  97. cmCTestSubmitHandlerVectorOfChar* vec =
  98. static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
  99. const char* chPtr = static_cast<char*>(ptr);
  100. vec->insert(vec->end(), chPtr, chPtr + realsize);
  101. return realsize;
  102. }
  103. static size_t cmCTestSubmitHandlerCurlDebugCallback(CURL* /*unused*/,
  104. curl_infotype /*unused*/,
  105. char* chPtr, size_t size,
  106. void* data)
  107. {
  108. cmCTestSubmitHandlerVectorOfChar* vec =
  109. static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
  110. vec->insert(vec->end(), chPtr, chPtr + size);
  111. return size;
  112. }
  113. cmCTestSubmitHandler::cmCTestSubmitHandler()
  114. : HTTPProxy()
  115. , FTPProxy()
  116. {
  117. this->Initialize();
  118. }
  119. void cmCTestSubmitHandler::Initialize()
  120. {
  121. // We submit all available parts by default.
  122. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  123. p = cmCTest::Part(p + 1)) {
  124. this->SubmitPart[p] = true;
  125. }
  126. this->CDash = false;
  127. this->HasWarnings = false;
  128. this->HasErrors = false;
  129. this->Superclass::Initialize();
  130. this->HTTPProxy.clear();
  131. this->HTTPProxyType = 0;
  132. this->HTTPProxyAuth.clear();
  133. this->FTPProxy.clear();
  134. this->FTPProxyType = 0;
  135. this->LogFile = nullptr;
  136. this->Files.clear();
  137. }
  138. bool cmCTestSubmitHandler::SubmitUsingFTP(
  139. const std::string& localprefix, const std::vector<std::string>& files,
  140. const std::string& remoteprefix, const std::string& url)
  141. {
  142. CURL* curl;
  143. CURLcode res;
  144. FILE* ftpfile;
  145. char error_buffer[1024];
  146. /* In windows, this will init the winsock stuff */
  147. ::curl_global_init(CURL_GLOBAL_ALL);
  148. for (std::string const& file : files) {
  149. /* get a curl handle */
  150. curl = curl_easy_init();
  151. if (curl) {
  152. // Using proxy
  153. if (this->FTPProxyType > 0) {
  154. curl_easy_setopt(curl, CURLOPT_PROXY, this->FTPProxy.c_str());
  155. switch (this->FTPProxyType) {
  156. case 2:
  157. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  158. break;
  159. case 3:
  160. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  161. break;
  162. default:
  163. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  164. }
  165. }
  166. // enable uploading
  167. ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  168. // if there is little to no activity for too long stop submitting
  169. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
  170. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME,
  171. SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
  172. ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  173. std::string local_file = file;
  174. if (!cmSystemTools::FileExists(local_file)) {
  175. local_file = localprefix + "/" + file;
  176. }
  177. std::string upload_as =
  178. url + "/" + remoteprefix + cmSystemTools::GetFilenameName(file);
  179. if (!cmSystemTools::FileExists(local_file)) {
  180. cmCTestLog(this->CTest, ERROR_MESSAGE,
  181. " Cannot find file: " << local_file << std::endl);
  182. ::curl_easy_cleanup(curl);
  183. ::curl_global_cleanup();
  184. return false;
  185. }
  186. unsigned long filelen = cmSystemTools::FileLength(local_file);
  187. ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
  188. *this->LogFile << "\tUpload file: " << local_file << " to " << upload_as
  189. << std::endl;
  190. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  191. " Upload file: " << local_file << " to "
  192. << upload_as << std::endl,
  193. this->Quiet);
  194. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  195. // specify target
  196. ::curl_easy_setopt(curl, CURLOPT_URL, upload_as.c_str());
  197. // now specify which file to upload
  198. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  199. // and give the size of the upload (optional)
  200. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(filelen));
  201. // and give curl the buffer for errors
  202. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  203. // specify handler for output
  204. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  205. cmCTestSubmitHandlerWriteMemoryCallback);
  206. ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  207. cmCTestSubmitHandlerCurlDebugCallback);
  208. /* we pass our 'chunk' struct to the callback function */
  209. cmCTestSubmitHandlerVectorOfChar chunk;
  210. cmCTestSubmitHandlerVectorOfChar chunkDebug;
  211. ::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
  212. ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
  213. // Now run off and do what you've been told!
  214. res = ::curl_easy_perform(curl);
  215. if (!chunk.empty()) {
  216. cmCTestOptionalLog(this->CTest, DEBUG,
  217. "CURL output: ["
  218. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  219. << "]" << std::endl,
  220. this->Quiet);
  221. }
  222. if (!chunkDebug.empty()) {
  223. cmCTestOptionalLog(
  224. this->CTest, DEBUG,
  225. "CURL debug output: ["
  226. << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
  227. << std::endl,
  228. this->Quiet);
  229. }
  230. fclose(ftpfile);
  231. if (res) {
  232. cmCTestLog(this->CTest, ERROR_MESSAGE,
  233. " Error when uploading file: " << local_file
  234. << std::endl);
  235. cmCTestLog(this->CTest, ERROR_MESSAGE,
  236. " Error message was: " << error_buffer << std::endl);
  237. *this->LogFile << " Error when uploading file: " << local_file
  238. << std::endl
  239. << " Error message was: " << error_buffer << std::endl
  240. << " Curl output was: ";
  241. // avoid dereference of empty vector
  242. if (!chunk.empty()) {
  243. *this->LogFile << cmCTestLogWrite(&*chunk.begin(), chunk.size());
  244. cmCTestLog(this->CTest, ERROR_MESSAGE,
  245. "CURL output: ["
  246. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  247. << std::endl);
  248. }
  249. *this->LogFile << std::endl;
  250. ::curl_easy_cleanup(curl);
  251. ::curl_global_cleanup();
  252. return false;
  253. }
  254. // always cleanup
  255. ::curl_easy_cleanup(curl);
  256. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  257. " Uploaded: " + local_file << std::endl,
  258. this->Quiet);
  259. }
  260. }
  261. ::curl_global_cleanup();
  262. return true;
  263. }
  264. // Uploading files is simpler
  265. bool cmCTestSubmitHandler::SubmitUsingHTTP(
  266. const std::string& localprefix, const std::vector<std::string>& files,
  267. const std::string& remoteprefix, const std::string& url)
  268. {
  269. CURL* curl;
  270. CURLcode res;
  271. FILE* ftpfile;
  272. char error_buffer[1024];
  273. // Set Content-Type to satisfy fussy modsecurity rules.
  274. struct curl_slist* headers =
  275. ::curl_slist_append(nullptr, "Content-Type: text/xml");
  276. // Add any additional headers that the user specified.
  277. for (std::string const& h : this->HttpHeaders) {
  278. cmCTestOptionalLog(this->CTest, DEBUG,
  279. " Add HTTP Header: \"" << h << "\"" << std::endl,
  280. this->Quiet);
  281. headers = ::curl_slist_append(headers, h.c_str());
  282. }
  283. /* In windows, this will init the winsock stuff */
  284. ::curl_global_init(CURL_GLOBAL_ALL);
  285. std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
  286. std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions"));
  287. std::vector<std::string> args;
  288. cmSystemTools::ExpandListArgument(curlopt, args);
  289. bool verifyPeerOff = false;
  290. bool verifyHostOff = false;
  291. for (std::string const& arg : args) {
  292. if (arg == "CURLOPT_SSL_VERIFYPEER_OFF") {
  293. verifyPeerOff = true;
  294. }
  295. if (arg == "CURLOPT_SSL_VERIFYHOST_OFF") {
  296. verifyHostOff = true;
  297. }
  298. }
  299. for (std::string const& file : files) {
  300. /* get a curl handle */
  301. curl = curl_easy_init();
  302. if (curl) {
  303. cmCurlSetCAInfo(curl);
  304. if (verifyPeerOff) {
  305. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  306. " Set CURLOPT_SSL_VERIFYPEER to off\n",
  307. this->Quiet);
  308. curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
  309. }
  310. if (verifyHostOff) {
  311. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  312. " Set CURLOPT_SSL_VERIFYHOST to off\n",
  313. this->Quiet);
  314. curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
  315. }
  316. // Using proxy
  317. if (this->HTTPProxyType > 0) {
  318. curl_easy_setopt(curl, CURLOPT_PROXY, this->HTTPProxy.c_str());
  319. switch (this->HTTPProxyType) {
  320. case 2:
  321. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  322. break;
  323. case 3:
  324. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  325. break;
  326. default:
  327. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  328. if (!this->HTTPProxyAuth.empty()) {
  329. curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
  330. this->HTTPProxyAuth.c_str());
  331. }
  332. }
  333. }
  334. if (this->CTest->ShouldUseHTTP10()) {
  335. curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
  336. }
  337. // enable HTTP ERROR parsing
  338. curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
  339. /* enable uploading */
  340. curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  341. // if there is little to no activity for too long stop submitting
  342. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
  343. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME,
  344. SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
  345. /* HTTP PUT please */
  346. ::curl_easy_setopt(curl, CURLOPT_PUT, 1);
  347. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  348. ::curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  349. std::string local_file = file;
  350. bool initialize_cdash_buildid = false;
  351. if (!cmSystemTools::FileExists(local_file)) {
  352. local_file = localprefix + "/" + file;
  353. // If this file exists within the local Testing directory we assume
  354. // that it will be associated with the current build in CDash.
  355. initialize_cdash_buildid = true;
  356. }
  357. std::string remote_file =
  358. remoteprefix + cmSystemTools::GetFilenameName(file);
  359. *this->LogFile << "\tUpload file: " << local_file << " to "
  360. << remote_file << std::endl;
  361. std::string ofile;
  362. for (char c : remote_file) {
  363. char hexCh[4] = { 0, 0, 0, 0 };
  364. hexCh[0] = c;
  365. switch (c) {
  366. case '+':
  367. case '?':
  368. case '/':
  369. case '\\':
  370. case '&':
  371. case ' ':
  372. case '=':
  373. case '%':
  374. sprintf(hexCh, "%%%02X", static_cast<int>(c));
  375. ofile.append(hexCh);
  376. break;
  377. default:
  378. ofile.append(hexCh);
  379. }
  380. }
  381. std::string upload_as = url +
  382. ((url.find('?') == std::string::npos) ? '?' : '&') +
  383. "FileName=" + ofile;
  384. if (initialize_cdash_buildid) {
  385. // Provide extra arguments to CDash so that it can initialize and
  386. // return a buildid.
  387. cmCTestCurl ctest_curl(this->CTest);
  388. upload_as += "&build=";
  389. upload_as +=
  390. ctest_curl.Escape(this->CTest->GetCTestConfiguration("BuildName"));
  391. upload_as += "&site=";
  392. upload_as +=
  393. ctest_curl.Escape(this->CTest->GetCTestConfiguration("Site"));
  394. upload_as += "&stamp=";
  395. upload_as += ctest_curl.Escape(this->CTest->GetCurrentTag());
  396. upload_as += "-";
  397. upload_as += ctest_curl.Escape(this->CTest->GetTestModelString());
  398. cmCTestScriptHandler* ch = static_cast<cmCTestScriptHandler*>(
  399. this->CTest->GetHandler("script"));
  400. cmake* cm = ch->GetCMake();
  401. if (cm) {
  402. const char* subproject =
  403. cm->GetState()->GetGlobalProperty("SubProject");
  404. if (subproject) {
  405. upload_as += "&subproject=";
  406. upload_as += ctest_curl.Escape(subproject);
  407. }
  408. }
  409. }
  410. upload_as += "&MD5=";
  411. if (cmSystemTools::IsOn(this->GetOption("InternalTest"))) {
  412. upload_as += "bad_md5sum";
  413. } else {
  414. upload_as +=
  415. cmSystemTools::ComputeFileHash(local_file, cmCryptoHash::AlgoMD5);
  416. }
  417. // Generate Done.xml right before it is submitted.
  418. // The reason for this is two-fold:
  419. // 1) It must be generated after some other part has been submitted
  420. // so we have a buildId to refer to in its contents.
  421. // 2) By generating Done.xml here its timestamp will be as late as
  422. // possible. This gives us a more accurate record of how long the
  423. // entire build took to complete.
  424. if (file == "Done.xml") {
  425. this->CTest->GenerateDoneFile();
  426. }
  427. if (!cmSystemTools::FileExists(local_file)) {
  428. cmCTestLog(this->CTest, ERROR_MESSAGE,
  429. " Cannot find file: " << local_file << std::endl);
  430. ::curl_easy_cleanup(curl);
  431. ::curl_slist_free_all(headers);
  432. ::curl_global_cleanup();
  433. return false;
  434. }
  435. unsigned long filelen = cmSystemTools::FileLength(local_file);
  436. ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
  437. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  438. " Upload file: " << local_file << " to "
  439. << upload_as << " Size: "
  440. << filelen << std::endl,
  441. this->Quiet);
  442. // specify target
  443. ::curl_easy_setopt(curl, CURLOPT_URL, upload_as.c_str());
  444. // CURLAUTH_BASIC is default, and here we allow additional methods,
  445. // including more secure ones
  446. ::curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  447. // now specify which file to upload
  448. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  449. // and give the size of the upload (optional)
  450. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(filelen));
  451. // and give curl the buffer for errors
  452. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  453. // specify handler for output
  454. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  455. cmCTestSubmitHandlerWriteMemoryCallback);
  456. ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  457. cmCTestSubmitHandlerCurlDebugCallback);
  458. /* we pass our 'chunk' struct to the callback function */
  459. cmCTestSubmitHandlerVectorOfChar chunk;
  460. cmCTestSubmitHandlerVectorOfChar chunkDebug;
  461. ::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
  462. ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
  463. // Now run off and do what you've been told!
  464. res = ::curl_easy_perform(curl);
  465. if (!chunk.empty()) {
  466. cmCTestOptionalLog(this->CTest, DEBUG,
  467. "CURL output: ["
  468. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  469. << "]" << std::endl,
  470. this->Quiet);
  471. this->ParseResponse(chunk);
  472. }
  473. if (!chunkDebug.empty()) {
  474. cmCTestOptionalLog(
  475. this->CTest, DEBUG,
  476. "CURL debug output: ["
  477. << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
  478. << std::endl,
  479. this->Quiet);
  480. }
  481. // If curl failed for any reason, or checksum fails, wait and retry
  482. //
  483. if (res != CURLE_OK || this->HasErrors) {
  484. std::string retryDelay = this->GetOption("RetryDelay") == nullptr
  485. ? ""
  486. : this->GetOption("RetryDelay");
  487. std::string retryCount = this->GetOption("RetryCount") == nullptr
  488. ? ""
  489. : this->GetOption("RetryCount");
  490. auto delay = cmDuration(
  491. retryDelay.empty()
  492. ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryDelay")
  493. .c_str())
  494. : atoi(retryDelay.c_str()));
  495. int count = retryCount.empty()
  496. ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryCount")
  497. .c_str())
  498. : atoi(retryCount.c_str());
  499. for (int i = 0; i < count; i++) {
  500. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  501. " Submit failed, waiting " << delay.count()
  502. << " seconds...\n",
  503. this->Quiet);
  504. auto stop = std::chrono::steady_clock::now() + delay;
  505. while (std::chrono::steady_clock::now() < stop) {
  506. cmSystemTools::Delay(100);
  507. }
  508. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  509. " Retry submission: Attempt "
  510. << (i + 1) << " of " << count << std::endl,
  511. this->Quiet);
  512. ::fclose(ftpfile);
  513. ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
  514. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  515. chunk.clear();
  516. chunkDebug.clear();
  517. this->HasErrors = false;
  518. res = ::curl_easy_perform(curl);
  519. if (!chunk.empty()) {
  520. cmCTestOptionalLog(
  521. this->CTest, DEBUG,
  522. "CURL output: ["
  523. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  524. << std::endl,
  525. this->Quiet);
  526. this->ParseResponse(chunk);
  527. }
  528. if (res == CURLE_OK && !this->HasErrors) {
  529. break;
  530. }
  531. }
  532. }
  533. fclose(ftpfile);
  534. if (res) {
  535. cmCTestLog(this->CTest, ERROR_MESSAGE,
  536. " Error when uploading file: " << local_file
  537. << std::endl);
  538. cmCTestLog(this->CTest, ERROR_MESSAGE,
  539. " Error message was: " << error_buffer << std::endl);
  540. *this->LogFile << " Error when uploading file: " << local_file
  541. << std::endl
  542. << " Error message was: " << error_buffer
  543. << std::endl;
  544. // avoid deref of begin for zero size array
  545. if (!chunk.empty()) {
  546. *this->LogFile << " Curl output was: "
  547. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  548. << std::endl;
  549. cmCTestLog(this->CTest, ERROR_MESSAGE,
  550. "CURL output: ["
  551. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  552. << std::endl);
  553. }
  554. ::curl_easy_cleanup(curl);
  555. ::curl_slist_free_all(headers);
  556. ::curl_global_cleanup();
  557. return false;
  558. }
  559. // always cleanup
  560. ::curl_easy_cleanup(curl);
  561. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  562. " Uploaded: " + local_file << std::endl,
  563. this->Quiet);
  564. }
  565. }
  566. ::curl_slist_free_all(headers);
  567. ::curl_global_cleanup();
  568. return true;
  569. }
  570. void cmCTestSubmitHandler::ParseResponse(
  571. cmCTestSubmitHandlerVectorOfChar chunk)
  572. {
  573. std::string output;
  574. output.append(chunk.begin(), chunk.end());
  575. if (output.find("<cdash") != std::string::npos) {
  576. ResponseParser parser;
  577. parser.Parse(output.c_str());
  578. if (parser.Status != ResponseParser::STATUS_OK) {
  579. this->HasErrors = true;
  580. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  581. " Submission failed: " << parser.Message << std::endl);
  582. return;
  583. }
  584. this->CTest->SetBuildID(parser.BuildID);
  585. }
  586. output = cmSystemTools::UpperCase(output);
  587. if (output.find("WARNING") != std::string::npos) {
  588. this->HasWarnings = true;
  589. }
  590. if (output.find("ERROR") != std::string::npos) {
  591. this->HasErrors = true;
  592. }
  593. if (this->HasWarnings || this->HasErrors) {
  594. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  595. " Server Response:\n"
  596. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "\n");
  597. }
  598. }
  599. bool cmCTestSubmitHandler::TriggerUsingHTTP(
  600. const std::vector<std::string>& files, const std::string& remoteprefix,
  601. const std::string& url)
  602. {
  603. CURL* curl;
  604. char error_buffer[1024];
  605. /* In windows, this will init the winsock stuff */
  606. ::curl_global_init(CURL_GLOBAL_ALL);
  607. for (std::string const& file : files) {
  608. /* get a curl handle */
  609. curl = curl_easy_init();
  610. if (curl) {
  611. // Using proxy
  612. if (this->HTTPProxyType > 0) {
  613. curl_easy_setopt(curl, CURLOPT_PROXY, this->HTTPProxy.c_str());
  614. switch (this->HTTPProxyType) {
  615. case 2:
  616. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  617. break;
  618. case 3:
  619. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  620. break;
  621. default:
  622. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  623. if (!this->HTTPProxyAuth.empty()) {
  624. curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
  625. this->HTTPProxyAuth.c_str());
  626. }
  627. }
  628. }
  629. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  630. // and give curl the buffer for errors
  631. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  632. // specify handler for output
  633. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  634. cmCTestSubmitHandlerWriteMemoryCallback);
  635. ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  636. cmCTestSubmitHandlerCurlDebugCallback);
  637. /* we pass our 'chunk' struct to the callback function */
  638. cmCTestSubmitHandlerVectorOfChar chunk;
  639. cmCTestSubmitHandlerVectorOfChar chunkDebug;
  640. ::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
  641. ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
  642. std::string rfile = remoteprefix + cmSystemTools::GetFilenameName(file);
  643. std::string ofile;
  644. for (char c : rfile) {
  645. char hexCh[4] = { 0, 0, 0, 0 };
  646. hexCh[0] = c;
  647. switch (c) {
  648. case '+':
  649. case '?':
  650. case '/':
  651. case '\\':
  652. case '&':
  653. case ' ':
  654. case '=':
  655. case '%':
  656. sprintf(hexCh, "%%%02X", static_cast<int>(c));
  657. ofile.append(hexCh);
  658. break;
  659. default:
  660. ofile.append(hexCh);
  661. }
  662. }
  663. std::string turl = url +
  664. ((url.find('?') == std::string::npos) ? '?' : '&') +
  665. "xmlfile=" + ofile;
  666. *this->LogFile << "Trigger url: " << turl << std::endl;
  667. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  668. " Trigger url: " << turl << std::endl, this->Quiet);
  669. curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  670. curl_easy_setopt(curl, CURLOPT_URL, turl.c_str());
  671. if (curl_easy_perform(curl)) {
  672. cmCTestLog(this->CTest, ERROR_MESSAGE,
  673. " Error when triggering: " << turl << std::endl);
  674. cmCTestLog(this->CTest, ERROR_MESSAGE,
  675. " Error message was: " << error_buffer << std::endl);
  676. *this->LogFile << "\tTriggering failed with error: " << error_buffer
  677. << std::endl
  678. << " Error message was: " << error_buffer
  679. << std::endl;
  680. if (!chunk.empty()) {
  681. *this->LogFile << " Curl output was: "
  682. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  683. << std::endl;
  684. cmCTestLog(this->CTest, ERROR_MESSAGE,
  685. "CURL output: ["
  686. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  687. << std::endl);
  688. }
  689. ::curl_easy_cleanup(curl);
  690. ::curl_global_cleanup();
  691. return false;
  692. }
  693. if (!chunk.empty()) {
  694. cmCTestOptionalLog(this->CTest, DEBUG,
  695. "CURL output: ["
  696. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  697. << "]" << std::endl,
  698. this->Quiet);
  699. }
  700. if (!chunkDebug.empty()) {
  701. cmCTestOptionalLog(
  702. this->CTest, DEBUG,
  703. "CURL debug output: ["
  704. << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
  705. << std::endl,
  706. this->Quiet);
  707. }
  708. // always cleanup
  709. ::curl_easy_cleanup(curl);
  710. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl,
  711. this->Quiet);
  712. }
  713. }
  714. ::curl_global_cleanup();
  715. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  716. " Dart server triggered..." << std::endl, this->Quiet);
  717. return true;
  718. }
  719. bool cmCTestSubmitHandler::SubmitUsingSCP(
  720. const std::string& scp_command, const std::string& localprefix,
  721. const std::vector<std::string>& files, const std::string& remoteprefix,
  722. const std::string& url)
  723. {
  724. if (scp_command.empty() || localprefix.empty() || files.empty() ||
  725. remoteprefix.empty() || url.empty()) {
  726. return false;
  727. }
  728. std::vector<const char*> argv;
  729. argv.push_back(scp_command.c_str()); // Scp command
  730. argv.push_back(scp_command.c_str()); // Dummy string for file
  731. argv.push_back(scp_command.c_str()); // Dummy string for remote url
  732. argv.push_back(nullptr);
  733. cmsysProcess* cp = cmsysProcess_New();
  734. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  735. // cmsysProcess_SetTimeout(cp, timeout);
  736. int problems = 0;
  737. for (std::string const& file : files) {
  738. int retVal;
  739. std::string lfname = localprefix;
  740. cmSystemTools::ConvertToUnixSlashes(lfname);
  741. lfname += "/" + file;
  742. lfname = cmSystemTools::ConvertToOutputPath(lfname);
  743. argv[1] = lfname.c_str();
  744. std::string rfname = url + "/" + remoteprefix + file;
  745. argv[2] = rfname.c_str();
  746. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  747. "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
  748. << argv[2] << "\"" << std::endl,
  749. this->Quiet);
  750. *this->LogFile << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
  751. << argv[2] << "\"" << std::endl;
  752. cmsysProcess_SetCommand(cp, &*argv.begin());
  753. cmsysProcess_Execute(cp);
  754. char* data;
  755. int length;
  756. cmProcessOutput processOutput;
  757. std::string strdata;
  758. while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
  759. processOutput.DecodeText(data, length, strdata);
  760. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  761. cmCTestLogWrite(strdata.c_str(), strdata.size()),
  762. this->Quiet);
  763. }
  764. processOutput.DecodeText(std::string(), strdata);
  765. if (!strdata.empty()) {
  766. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  767. cmCTestLogWrite(strdata.c_str(), strdata.size()),
  768. this->Quiet);
  769. }
  770. cmsysProcess_WaitForExit(cp, nullptr);
  771. int result = cmsysProcess_GetState(cp);
  772. if (result == cmsysProcess_State_Exited) {
  773. retVal = cmsysProcess_GetExitValue(cp);
  774. if (retVal != 0) {
  775. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  776. "\tSCP returned: " << retVal << std::endl,
  777. this->Quiet);
  778. *this->LogFile << "\tSCP returned: " << retVal << std::endl;
  779. problems++;
  780. }
  781. } else if (result == cmsysProcess_State_Exception) {
  782. retVal = cmsysProcess_GetExitException(cp);
  783. cmCTestLog(this->CTest, ERROR_MESSAGE,
  784. "\tThere was an exception: " << retVal << std::endl);
  785. *this->LogFile << "\tThere was an exception: " << retVal << std::endl;
  786. problems++;
  787. } else if (result == cmsysProcess_State_Expired) {
  788. cmCTestLog(this->CTest, ERROR_MESSAGE,
  789. "\tThere was a timeout" << std::endl);
  790. *this->LogFile << "\tThere was a timeout" << std::endl;
  791. problems++;
  792. } else if (result == cmsysProcess_State_Error) {
  793. cmCTestLog(this->CTest, ERROR_MESSAGE,
  794. "\tError executing SCP: " << cmsysProcess_GetErrorString(cp)
  795. << std::endl);
  796. *this->LogFile << "\tError executing SCP: "
  797. << cmsysProcess_GetErrorString(cp) << std::endl;
  798. problems++;
  799. }
  800. }
  801. cmsysProcess_Delete(cp);
  802. return problems == 0;
  803. }
  804. bool cmCTestSubmitHandler::SubmitUsingCP(const std::string& localprefix,
  805. const std::vector<std::string>& files,
  806. const std::string& remoteprefix,
  807. const std::string& destination)
  808. {
  809. if (localprefix.empty() || files.empty() || remoteprefix.empty() ||
  810. destination.empty()) {
  811. /* clang-format off */
  812. cmCTestLog(this->CTest, ERROR_MESSAGE,
  813. "Missing arguments for submit via cp:\n"
  814. << "\tlocalprefix: " << localprefix << "\n"
  815. << "\tNumber of files: " << files.size() << "\n"
  816. << "\tremoteprefix: " << remoteprefix << "\n"
  817. << "\tdestination: " << destination << std::endl);
  818. /* clang-format on */
  819. return false;
  820. }
  821. for (std::string const& file : files) {
  822. std::string lfname = localprefix;
  823. cmSystemTools::ConvertToUnixSlashes(lfname);
  824. lfname += "/" + file;
  825. std::string rfname = destination + "/" + remoteprefix + file;
  826. cmSystemTools::CopyFileAlways(lfname, rfname);
  827. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  828. " Copy file: " << lfname << " to " << rfname
  829. << std::endl,
  830. this->Quiet);
  831. }
  832. std::string tagDoneFile = destination + "/" + remoteprefix + "DONE";
  833. cmSystemTools::Touch(tagDoneFile, true);
  834. return true;
  835. }
  836. #if defined(CTEST_USE_XMLRPC)
  837. bool cmCTestSubmitHandler::SubmitUsingXMLRPC(
  838. const std::string& localprefix, const std::vector<std::string>& files,
  839. const std::string& remoteprefix, const std::string& url)
  840. {
  841. xmlrpc_env env;
  842. char ctestString[] = "CTest";
  843. std::string ctestVersionString = cmVersion::GetCMakeVersion();
  844. char* ctestVersion = const_cast<char*>(ctestVersionString.c_str());
  845. std::string realURL = url + "/" + remoteprefix + "/Command/";
  846. /* Start up our XML-RPC client library. */
  847. xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, ctestString, ctestVersion);
  848. /* Initialize our error-handling environment. */
  849. xmlrpc_env_init(&env);
  850. /* Call the famous server at UserLand. */
  851. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  852. " Submitting to: " << realURL << " (" << remoteprefix
  853. << ")" << std::endl,
  854. this->Quiet);
  855. for (std::string const& file : files) {
  856. xmlrpc_value* result;
  857. std::string local_file = file;
  858. if (!cmSystemTools::FileExists(local_file)) {
  859. local_file = localprefix + "/" + file;
  860. }
  861. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  862. " Submit file: " << local_file << std::endl,
  863. this->Quiet);
  864. struct stat st;
  865. if (::stat(local_file.c_str(), &st)) {
  866. cmCTestLog(this->CTest, ERROR_MESSAGE,
  867. " Cannot find file: " << local_file << std::endl);
  868. return false;
  869. }
  870. // off_t can be bigger than size_t. fread takes size_t.
  871. // make sure the file is not too big.
  872. if (static_cast<off_t>(static_cast<size_t>(st.st_size)) !=
  873. static_cast<off_t>(st.st_size)) {
  874. cmCTestLog(this->CTest, ERROR_MESSAGE,
  875. " File too big: " << local_file << std::endl);
  876. return false;
  877. }
  878. size_t fileSize = static_cast<size_t>(st.st_size);
  879. FILE* fp = cmsys::SystemTools::Fopen(local_file, "rb");
  880. if (!fp) {
  881. cmCTestLog(this->CTest, ERROR_MESSAGE,
  882. " Cannot open file: " << local_file << std::endl);
  883. return false;
  884. }
  885. unsigned char* fileBuffer = new unsigned char[fileSize];
  886. if (fread(fileBuffer, 1, fileSize, fp) != fileSize) {
  887. delete[] fileBuffer;
  888. fclose(fp);
  889. cmCTestLog(this->CTest, ERROR_MESSAGE,
  890. " Cannot read file: " << local_file << std::endl);
  891. return false;
  892. }
  893. fclose(fp);
  894. char remoteCommand[] = "Submit.put";
  895. char* pRealURL = const_cast<char*>(realURL.c_str());
  896. result =
  897. xmlrpc_client_call(&env, pRealURL, remoteCommand, "(6)", fileBuffer,
  898. static_cast<xmlrpc_int32>(fileSize));
  899. delete[] fileBuffer;
  900. if (env.fault_occurred) {
  901. cmCTestLog(this->CTest, ERROR_MESSAGE,
  902. " Submission problem: " << env.fault_string << " ("
  903. << env.fault_code << ")"
  904. << std::endl);
  905. xmlrpc_env_clean(&env);
  906. xmlrpc_client_cleanup();
  907. return false;
  908. }
  909. /* Dispose of our result value. */
  910. xmlrpc_DECREF(result);
  911. }
  912. /* Clean up our error-handling environment. */
  913. xmlrpc_env_clean(&env);
  914. /* Shutdown our XML-RPC client library. */
  915. xmlrpc_client_cleanup();
  916. return true;
  917. }
  918. #else
  919. bool cmCTestSubmitHandler::SubmitUsingXMLRPC(
  920. std::string const& /*unused*/, std::vector<std::string> const& /*unused*/,
  921. std::string const& /*unused*/, std::string const& /*unused*/)
  922. {
  923. return false;
  924. }
  925. #endif
  926. void cmCTestSubmitHandler::ConstructCDashURL(std::string& dropMethod,
  927. std::string& url)
  928. {
  929. dropMethod = this->CTest->GetCTestConfiguration("DropMethod");
  930. url = dropMethod;
  931. url += "://";
  932. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  933. url += this->CTest->GetCTestConfiguration("DropSiteUser");
  934. cmCTestOptionalLog(
  935. this->CTest, HANDLER_OUTPUT,
  936. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(), this->Quiet);
  937. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  938. url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
  939. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******", this->Quiet);
  940. }
  941. url += "@";
  942. }
  943. url += this->CTest->GetCTestConfiguration("DropSite") +
  944. this->CTest->GetCTestConfiguration("DropLocation");
  945. }
  946. int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
  947. std::string const& typeString)
  948. {
  949. if (file.empty()) {
  950. cmCTestLog(this->CTest, ERROR_MESSAGE, "Upload file not specified\n");
  951. return -1;
  952. }
  953. if (!cmSystemTools::FileExists(file)) {
  954. cmCTestLog(this->CTest, ERROR_MESSAGE,
  955. "Upload file not found: '" << file << "'\n");
  956. return -1;
  957. }
  958. cmCTestCurl curl(this->CTest);
  959. curl.SetQuiet(this->Quiet);
  960. std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions"));
  961. std::vector<std::string> args;
  962. cmSystemTools::ExpandListArgument(curlopt, args);
  963. curl.SetCurlOptions(args);
  964. curl.SetTimeOutSeconds(SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
  965. curl.SetHttpHeaders(this->HttpHeaders);
  966. std::string dropMethod;
  967. std::string url;
  968. this->ConstructCDashURL(dropMethod, url);
  969. std::string::size_type pos = url.find("submit.php?");
  970. url = url.substr(0, pos + 10);
  971. if (!(dropMethod == "http" || dropMethod == "https")) {
  972. cmCTestLog(this->CTest, ERROR_MESSAGE,
  973. "Only http and https are supported for CDASH_UPLOAD\n");
  974. return -1;
  975. }
  976. bool internalTest = cmSystemTools::IsOn(this->GetOption("InternalTest"));
  977. // Get RETRY_COUNT and RETRY_DELAY values if they were set.
  978. std::string retryDelayString = this->GetOption("RetryDelay") == nullptr
  979. ? ""
  980. : this->GetOption("RetryDelay");
  981. std::string retryCountString = this->GetOption("RetryCount") == nullptr
  982. ? ""
  983. : this->GetOption("RetryCount");
  984. auto retryDelay = std::chrono::seconds(0);
  985. if (!retryDelayString.empty()) {
  986. unsigned long retryDelayValue = 0;
  987. if (!cmSystemTools::StringToULong(retryDelayString.c_str(),
  988. &retryDelayValue)) {
  989. cmCTestLog(this->CTest, WARNING,
  990. "Invalid value for 'RETRY_DELAY' : " << retryDelayString
  991. << std::endl);
  992. } else {
  993. retryDelay = std::chrono::seconds(retryDelayValue);
  994. }
  995. }
  996. unsigned long retryCount = 0;
  997. if (!retryCountString.empty()) {
  998. if (!cmSystemTools::StringToULong(retryCountString.c_str(), &retryCount)) {
  999. cmCTestLog(this->CTest, WARNING,
  1000. "Invalid value for 'RETRY_DELAY' : " << retryCountString
  1001. << std::endl);
  1002. }
  1003. }
  1004. std::string md5sum =
  1005. cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5);
  1006. // 1. request the buildid and check to see if the file
  1007. // has already been uploaded
  1008. // TODO I added support for subproject. You would need to add
  1009. // a "&subproject=subprojectname" to the first POST.
  1010. cmCTestScriptHandler* ch =
  1011. static_cast<cmCTestScriptHandler*>(this->CTest->GetHandler("script"));
  1012. cmake* cm = ch->GetCMake();
  1013. const char* subproject = cm->GetState()->GetGlobalProperty("SubProject");
  1014. // TODO: Encode values for a URL instead of trusting caller.
  1015. std::ostringstream str;
  1016. str << "project="
  1017. << curl.Escape(this->CTest->GetCTestConfiguration("ProjectName")) << "&";
  1018. if (subproject) {
  1019. str << "subproject=" << curl.Escape(subproject) << "&";
  1020. }
  1021. auto timeNow =
  1022. std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
  1023. str << "stamp=" << curl.Escape(this->CTest->GetCurrentTag()) << "-"
  1024. << curl.Escape(this->CTest->GetTestModelString()) << "&"
  1025. << "model=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
  1026. << "build="
  1027. << curl.Escape(this->CTest->GetCTestConfiguration("BuildName")) << "&"
  1028. << "site=" << curl.Escape(this->CTest->GetCTestConfiguration("Site"))
  1029. << "&"
  1030. << "track=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
  1031. << "starttime=" << timeNow << "&"
  1032. << "endtime=" << timeNow << "&"
  1033. << "datafilesmd5[0]=" << md5sum << "&"
  1034. << "type=" << curl.Escape(typeString);
  1035. std::string fields = str.str();
  1036. cmCTestOptionalLog(this->CTest, DEBUG,
  1037. "fields: " << fields << "\nurl:" << url
  1038. << "\nfile: " << file << "\n",
  1039. this->Quiet);
  1040. std::string response;
  1041. bool requestSucceeded = curl.HttpRequest(url, fields, response);
  1042. if (!internalTest && !requestSucceeded) {
  1043. // If request failed, wait and retry.
  1044. for (unsigned long i = 0; i < retryCount; i++) {
  1045. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1046. " Request failed, waiting " << retryDelay.count()
  1047. << " seconds...\n",
  1048. this->Quiet);
  1049. auto stop = std::chrono::steady_clock::now() + retryDelay;
  1050. while (std::chrono::steady_clock::now() < stop) {
  1051. cmSystemTools::Delay(100);
  1052. }
  1053. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1054. " Retry request: Attempt "
  1055. << (i + 1) << " of " << retryCount << std::endl,
  1056. this->Quiet);
  1057. requestSucceeded = curl.HttpRequest(url, fields, response);
  1058. if (requestSucceeded) {
  1059. break;
  1060. }
  1061. }
  1062. }
  1063. if (!internalTest && !requestSucceeded) {
  1064. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1065. "Error in HttpRequest\n"
  1066. << response);
  1067. return -1;
  1068. }
  1069. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1070. "Request upload response: [" << response << "]\n",
  1071. this->Quiet);
  1072. Json::Value json;
  1073. Json::Reader reader;
  1074. if (!internalTest && !reader.parse(response, json)) {
  1075. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1076. "error parsing json string ["
  1077. << response << "]\n"
  1078. << reader.getFormattedErrorMessages() << "\n");
  1079. return -1;
  1080. }
  1081. if (!internalTest && json["status"].asInt() != 0) {
  1082. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1083. "Bad status returned from CDash: " << json["status"].asInt());
  1084. return -1;
  1085. }
  1086. if (!internalTest) {
  1087. if (json["datafilesmd5"].isArray()) {
  1088. int datares = json["datafilesmd5"][0].asInt();
  1089. if (datares == 1) {
  1090. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1091. "File already exists on CDash, skip upload "
  1092. << file << "\n",
  1093. this->Quiet);
  1094. return 0;
  1095. }
  1096. } else {
  1097. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1098. "bad datafilesmd5 value in response " << response << "\n");
  1099. return -1;
  1100. }
  1101. }
  1102. std::string upload_as = cmSystemTools::GetFilenameName(file);
  1103. std::ostringstream fstr;
  1104. fstr << "type=" << curl.Escape(typeString) << "&"
  1105. << "md5=" << md5sum << "&"
  1106. << "filename=" << curl.Escape(upload_as) << "&"
  1107. << "buildid=" << json["buildid"].asString();
  1108. bool uploadSucceeded = false;
  1109. if (!internalTest) {
  1110. uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response);
  1111. }
  1112. if (!uploadSucceeded) {
  1113. // If upload failed, wait and retry.
  1114. for (unsigned long i = 0; i < retryCount; i++) {
  1115. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1116. " Upload failed, waiting " << retryDelay.count()
  1117. << " seconds...\n",
  1118. this->Quiet);
  1119. auto stop = std::chrono::steady_clock::now() + retryDelay;
  1120. while (std::chrono::steady_clock::now() < stop) {
  1121. cmSystemTools::Delay(100);
  1122. }
  1123. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1124. " Retry upload: Attempt "
  1125. << (i + 1) << " of " << retryCount << std::endl,
  1126. this->Quiet);
  1127. if (!internalTest) {
  1128. uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response);
  1129. }
  1130. if (uploadSucceeded) {
  1131. break;
  1132. }
  1133. }
  1134. }
  1135. if (!uploadSucceeded) {
  1136. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1137. "error uploading to CDash. " << file << " " << url << " "
  1138. << fstr.str());
  1139. return -1;
  1140. }
  1141. if (!reader.parse(response, json)) {
  1142. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1143. "error parsing json string ["
  1144. << response << "]\n"
  1145. << reader.getFormattedErrorMessages() << "\n");
  1146. return -1;
  1147. }
  1148. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1149. "Upload file response: [" << response << "]\n",
  1150. this->Quiet);
  1151. return 0;
  1152. }
  1153. int cmCTestSubmitHandler::ProcessHandler()
  1154. {
  1155. const char* cdashUploadFile = this->GetOption("CDashUploadFile");
  1156. const char* cdashUploadType = this->GetOption("CDashUploadType");
  1157. if (cdashUploadFile && cdashUploadType) {
  1158. return this->HandleCDashUploadFile(cdashUploadFile, cdashUploadType);
  1159. }
  1160. std::string iscdash = this->CTest->GetCTestConfiguration("IsCDash");
  1161. // cdash does not need to trigger so just return true
  1162. if (!iscdash.empty()) {
  1163. this->CDash = true;
  1164. }
  1165. const std::string& buildDirectory =
  1166. this->CTest->GetCTestConfiguration("BuildDirectory");
  1167. if (buildDirectory.empty()) {
  1168. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1169. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  1170. << std::endl);
  1171. return -1;
  1172. }
  1173. if (getenv("HTTP_PROXY")) {
  1174. this->HTTPProxyType = 1;
  1175. this->HTTPProxy = getenv("HTTP_PROXY");
  1176. if (getenv("HTTP_PROXY_PORT")) {
  1177. this->HTTPProxy += ":";
  1178. this->HTTPProxy += getenv("HTTP_PROXY_PORT");
  1179. }
  1180. if (getenv("HTTP_PROXY_TYPE")) {
  1181. std::string type = getenv("HTTP_PROXY_TYPE");
  1182. // HTTP/SOCKS4/SOCKS5
  1183. if (type == "HTTP") {
  1184. this->HTTPProxyType = 1;
  1185. } else if (type == "SOCKS4") {
  1186. this->HTTPProxyType = 2;
  1187. } else if (type == "SOCKS5") {
  1188. this->HTTPProxyType = 3;
  1189. }
  1190. }
  1191. if (getenv("HTTP_PROXY_USER")) {
  1192. this->HTTPProxyAuth = getenv("HTTP_PROXY_USER");
  1193. }
  1194. if (getenv("HTTP_PROXY_PASSWD")) {
  1195. this->HTTPProxyAuth += ":";
  1196. this->HTTPProxyAuth += getenv("HTTP_PROXY_PASSWD");
  1197. }
  1198. }
  1199. if (getenv("FTP_PROXY")) {
  1200. this->FTPProxyType = 1;
  1201. this->FTPProxy = getenv("FTP_PROXY");
  1202. if (getenv("FTP_PROXY_PORT")) {
  1203. this->FTPProxy += ":";
  1204. this->FTPProxy += getenv("FTP_PROXY_PORT");
  1205. }
  1206. if (getenv("FTP_PROXY_TYPE")) {
  1207. std::string type = getenv("FTP_PROXY_TYPE");
  1208. // HTTP/SOCKS4/SOCKS5
  1209. if (type == "HTTP") {
  1210. this->FTPProxyType = 1;
  1211. } else if (type == "SOCKS4") {
  1212. this->FTPProxyType = 2;
  1213. } else if (type == "SOCKS5") {
  1214. this->FTPProxyType = 3;
  1215. }
  1216. }
  1217. }
  1218. if (!this->HTTPProxy.empty()) {
  1219. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1220. " Use HTTP Proxy: " << this->HTTPProxy << std::endl,
  1221. this->Quiet);
  1222. }
  1223. if (!this->FTPProxy.empty()) {
  1224. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1225. " Use FTP Proxy: " << this->FTPProxy << std::endl,
  1226. this->Quiet);
  1227. }
  1228. cmGeneratedFileStream ofs;
  1229. this->StartLogFile("Submit", ofs);
  1230. std::vector<std::string> files;
  1231. std::string prefix = this->GetSubmitResultsPrefix();
  1232. if (!this->Files.empty()) {
  1233. // Submit the explicitly selected files:
  1234. //
  1235. files.insert(files.end(), this->Files.begin(), this->Files.end());
  1236. }
  1237. // Add to the list of files to submit from any selected, existing parts:
  1238. //
  1239. // TODO:
  1240. // Check if test is enabled
  1241. this->CTest->AddIfExists(cmCTest::PartUpdate, "Update.xml");
  1242. this->CTest->AddIfExists(cmCTest::PartConfigure, "Configure.xml");
  1243. this->CTest->AddIfExists(cmCTest::PartBuild, "Build.xml");
  1244. this->CTest->AddIfExists(cmCTest::PartTest, "Test.xml");
  1245. if (this->CTest->AddIfExists(cmCTest::PartCoverage, "Coverage.xml")) {
  1246. std::vector<std::string> gfiles;
  1247. std::string gpath =
  1248. buildDirectory + "/Testing/" + this->CTest->GetCurrentTag();
  1249. std::string::size_type glen = gpath.size() + 1;
  1250. gpath = gpath + "/CoverageLog*";
  1251. cmCTestOptionalLog(this->CTest, DEBUG,
  1252. "Globbing for: " << gpath << std::endl, this->Quiet);
  1253. if (cmSystemTools::SimpleGlob(gpath, gfiles, 1)) {
  1254. for (std::string& gfile : gfiles) {
  1255. gfile = gfile.substr(glen);
  1256. cmCTestOptionalLog(this->CTest, DEBUG,
  1257. "Glob file: " << gfile << std::endl, this->Quiet);
  1258. this->CTest->AddSubmitFile(cmCTest::PartCoverage, gfile.c_str());
  1259. }
  1260. } else {
  1261. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem globbing" << std::endl);
  1262. }
  1263. }
  1264. this->CTest->AddIfExists(cmCTest::PartMemCheck, "DynamicAnalysis.xml");
  1265. this->CTest->AddIfExists(cmCTest::PartMemCheck, "Purify.xml");
  1266. this->CTest->AddIfExists(cmCTest::PartNotes, "Notes.xml");
  1267. this->CTest->AddIfExists(cmCTest::PartUpload, "Upload.xml");
  1268. // Query parts for files to submit.
  1269. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  1270. p = cmCTest::Part(p + 1)) {
  1271. // Skip parts we are not submitting.
  1272. if (!this->SubmitPart[p]) {
  1273. continue;
  1274. }
  1275. // Submit files from this part.
  1276. std::vector<std::string> const& pfiles = this->CTest->GetSubmitFiles(p);
  1277. files.insert(files.end(), pfiles.begin(), pfiles.end());
  1278. }
  1279. // Make sure files are unique, but preserve order.
  1280. {
  1281. // This endPos intermediate is needed to work around non-conformant C++11
  1282. // standard libraries that have erase(iterator,iterator) instead of
  1283. // erase(const_iterator,const_iterator).
  1284. size_t endPos = cmRemoveDuplicates(files) - files.cbegin();
  1285. files.erase(files.begin() + endPos, files.end());
  1286. }
  1287. // Submit Done.xml last
  1288. if (this->SubmitPart[cmCTest::PartDone]) {
  1289. files.push_back("Done.xml");
  1290. }
  1291. if (ofs) {
  1292. ofs << "Upload files:" << std::endl;
  1293. int cnt = 0;
  1294. for (std::string const& file : files) {
  1295. ofs << cnt << "\t" << file << std::endl;
  1296. cnt++;
  1297. }
  1298. }
  1299. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1300. "Submit files (using "
  1301. << this->CTest->GetCTestConfiguration("DropMethod")
  1302. << ")" << std::endl,
  1303. this->Quiet);
  1304. const char* specificTrack = this->CTest->GetSpecificTrack();
  1305. if (specificTrack) {
  1306. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1307. " Send to track: " << specificTrack << std::endl,
  1308. this->Quiet);
  1309. }
  1310. this->SetLogFile(&ofs);
  1311. std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
  1312. if (dropMethod.empty() || dropMethod == "ftp") {
  1313. ofs << "Using drop method: FTP" << std::endl;
  1314. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1315. " Using FTP submit method" << std::endl
  1316. << " Drop site: ftp://",
  1317. this->Quiet);
  1318. std::string url = "ftp://";
  1319. url += cmCTest::MakeURLSafe(
  1320. this->CTest->GetCTestConfiguration("DropSiteUser")) +
  1321. ":" +
  1322. cmCTest::MakeURLSafe(
  1323. this->CTest->GetCTestConfiguration("DropSitePassword")) +
  1324. "@" + this->CTest->GetCTestConfiguration("DropSite") +
  1325. cmCTest::MakeURLSafe(this->CTest->GetCTestConfiguration("DropLocation"));
  1326. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1327. cmCTestOptionalLog(
  1328. this->CTest, HANDLER_OUTPUT,
  1329. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
  1330. this->Quiet);
  1331. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  1332. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
  1333. this->Quiet);
  1334. }
  1335. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
  1336. }
  1337. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1338. this->CTest->GetCTestConfiguration("DropSite")
  1339. << this->CTest->GetCTestConfiguration("DropLocation")
  1340. << std::endl,
  1341. this->Quiet);
  1342. if (!this->SubmitUsingFTP(buildDirectory + "/Testing/" +
  1343. this->CTest->GetCurrentTag(),
  1344. files, prefix, url)) {
  1345. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1346. " Problems when submitting via FTP" << std::endl);
  1347. ofs << " Problems when submitting via FTP" << std::endl;
  1348. return -1;
  1349. }
  1350. if (!this->CDash) {
  1351. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1352. " Using HTTP trigger method"
  1353. << std::endl
  1354. << " Trigger site: "
  1355. << this->CTest->GetCTestConfiguration("TriggerSite")
  1356. << std::endl,
  1357. this->Quiet);
  1358. if (!this->TriggerUsingHTTP(
  1359. files, prefix,
  1360. this->CTest->GetCTestConfiguration("TriggerSite"))) {
  1361. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1362. " Problems when triggering via HTTP" << std::endl);
  1363. ofs << " Problems when triggering via HTTP" << std::endl;
  1364. return -1;
  1365. }
  1366. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1367. " Submission successful" << std::endl, this->Quiet);
  1368. ofs << " Submission successful" << std::endl;
  1369. return 0;
  1370. }
  1371. } else if (dropMethod == "http" || dropMethod == "https") {
  1372. std::string url = dropMethod;
  1373. url += "://";
  1374. ofs << "Using drop method: " << dropMethod << std::endl;
  1375. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1376. " Using HTTP submit method" << std::endl
  1377. << " Drop site:" << url,
  1378. this->Quiet);
  1379. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1380. url += this->CTest->GetCTestConfiguration("DropSiteUser");
  1381. cmCTestOptionalLog(
  1382. this->CTest, HANDLER_OUTPUT,
  1383. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
  1384. this->Quiet);
  1385. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  1386. url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
  1387. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
  1388. this->Quiet);
  1389. }
  1390. url += "@";
  1391. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
  1392. }
  1393. url += this->CTest->GetCTestConfiguration("DropSite") +
  1394. this->CTest->GetCTestConfiguration("DropLocation");
  1395. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1396. this->CTest->GetCTestConfiguration("DropSite")
  1397. << this->CTest->GetCTestConfiguration("DropLocation")
  1398. << std::endl,
  1399. this->Quiet);
  1400. if (!this->SubmitUsingHTTP(buildDirectory + "/Testing/" +
  1401. this->CTest->GetCurrentTag(),
  1402. files, prefix, url)) {
  1403. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1404. " Problems when submitting via HTTP" << std::endl);
  1405. ofs << " Problems when submitting via HTTP" << std::endl;
  1406. return -1;
  1407. }
  1408. if (!this->CDash) {
  1409. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1410. " Using HTTP trigger method"
  1411. << std::endl
  1412. << " Trigger site: "
  1413. << this->CTest->GetCTestConfiguration("TriggerSite")
  1414. << std::endl,
  1415. this->Quiet);
  1416. if (!this->TriggerUsingHTTP(
  1417. files, prefix,
  1418. this->CTest->GetCTestConfiguration("TriggerSite"))) {
  1419. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1420. " Problems when triggering via HTTP" << std::endl);
  1421. ofs << " Problems when triggering via HTTP" << std::endl;
  1422. return -1;
  1423. }
  1424. }
  1425. if (this->HasErrors) {
  1426. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  1427. " Errors occurred during "
  1428. "submission."
  1429. << std::endl);
  1430. ofs << " Errors occurred during submission. " << std::endl;
  1431. } else {
  1432. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1433. " Submission successful"
  1434. << (this->HasWarnings ? ", with warnings." : "")
  1435. << std::endl,
  1436. this->Quiet);
  1437. ofs << " Submission successful"
  1438. << (this->HasWarnings ? ", with warnings." : "") << std::endl;
  1439. }
  1440. return 0;
  1441. } else if (dropMethod == "xmlrpc") {
  1442. #if defined(CTEST_USE_XMLRPC)
  1443. ofs << "Using drop method: XML-RPC" << std::endl;
  1444. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1445. " Using XML-RPC submit method" << std::endl,
  1446. this->Quiet);
  1447. std::string url = this->CTest->GetCTestConfiguration("DropSite");
  1448. prefix = this->CTest->GetCTestConfiguration("DropLocation");
  1449. if (!this->SubmitUsingXMLRPC(buildDirectory + "/Testing/" +
  1450. this->CTest->GetCurrentTag(),
  1451. files, prefix, url)) {
  1452. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1453. " Problems when submitting via XML-RPC" << std::endl);
  1454. ofs << " Problems when submitting via XML-RPC" << std::endl;
  1455. return -1;
  1456. }
  1457. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1458. " Submission successful" << std::endl, this->Quiet);
  1459. ofs << " Submission successful" << std::endl;
  1460. return 0;
  1461. #else
  1462. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1463. " Submission method \"xmlrpc\" not compiled into CTest!"
  1464. << std::endl);
  1465. return -1;
  1466. #endif
  1467. } else if (dropMethod == "scp") {
  1468. std::string url;
  1469. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1470. url += this->CTest->GetCTestConfiguration("DropSiteUser") + "@";
  1471. }
  1472. url += this->CTest->GetCTestConfiguration("DropSite") + ":" +
  1473. this->CTest->GetCTestConfiguration("DropLocation");
  1474. // change to the build directory so that we can uses a relative path
  1475. // on windows since scp doesn't support "c:" a drive in the path
  1476. cmWorkingDirectory workdir(buildDirectory);
  1477. if (workdir.Failed()) {
  1478. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1479. " Failed to change directory to "
  1480. << buildDirectory << " : "
  1481. << std::strerror(workdir.GetLastResult()) << std::endl);
  1482. ofs << " Failed to change directory to " << buildDirectory << " : "
  1483. << std::strerror(workdir.GetLastResult()) << std::endl;
  1484. return -1;
  1485. }
  1486. if (!this->SubmitUsingSCP(this->CTest->GetCTestConfiguration("ScpCommand"),
  1487. "Testing/" + this->CTest->GetCurrentTag(), files,
  1488. prefix, url)) {
  1489. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1490. " Problems when submitting via SCP" << std::endl);
  1491. ofs << " Problems when submitting via SCP" << std::endl;
  1492. return -1;
  1493. }
  1494. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1495. " Submission successful" << std::endl, this->Quiet);
  1496. ofs << " Submission successful" << std::endl;
  1497. return 0;
  1498. } else if (dropMethod == "cp") {
  1499. std::string location = this->CTest->GetCTestConfiguration("DropLocation");
  1500. // change to the build directory so that we can uses a relative path
  1501. // on windows since scp doesn't support "c:" a drive in the path
  1502. cmWorkingDirectory workdir(buildDirectory);
  1503. if (workdir.Failed()) {
  1504. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1505. " Failed to change directory to "
  1506. << buildDirectory << " : "
  1507. << std::strerror(workdir.GetLastResult()) << std::endl);
  1508. ofs << " Failed to change directory to " << buildDirectory << " : "
  1509. << std::strerror(workdir.GetLastResult()) << std::endl;
  1510. return -1;
  1511. }
  1512. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1513. " Change directory: " << buildDirectory << std::endl,
  1514. this->Quiet);
  1515. if (!this->SubmitUsingCP("Testing/" + this->CTest->GetCurrentTag(), files,
  1516. prefix, location)) {
  1517. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1518. " Problems when submitting via CP" << std::endl);
  1519. ofs << " Problems when submitting via cp" << std::endl;
  1520. return -1;
  1521. }
  1522. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1523. " Submission successful" << std::endl, this->Quiet);
  1524. ofs << " Submission successful" << std::endl;
  1525. return 0;
  1526. }
  1527. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1528. " Unknown submission method: \"" << dropMethod << "\""
  1529. << std::endl);
  1530. return -1;
  1531. }
  1532. std::string cmCTestSubmitHandler::GetSubmitResultsPrefix()
  1533. {
  1534. std::string buildname =
  1535. cmCTest::SafeBuildIdField(this->CTest->GetCTestConfiguration("BuildName"));
  1536. std::string name = this->CTest->GetCTestConfiguration("Site") + "___" +
  1537. buildname + "___" + this->CTest->GetCurrentTag() + "-" +
  1538. this->CTest->GetTestModelString() + "___XML___";
  1539. return name;
  1540. }
  1541. void cmCTestSubmitHandler::SelectParts(std::set<cmCTest::Part> const& parts)
  1542. {
  1543. // Check whether each part is selected.
  1544. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  1545. p = cmCTest::Part(p + 1)) {
  1546. this->SubmitPart[p] =
  1547. (std::set<cmCTest::Part>::const_iterator(parts.find(p)) != parts.end());
  1548. }
  1549. }
  1550. void cmCTestSubmitHandler::SelectFiles(cmCTest::SetOfStrings const& files)
  1551. {
  1552. this->Files.insert(files.begin(), files.end());
  1553. }