cmCTestSubmitHandler.cxx 58 KB

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