cmCTestSubmitHandler.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestSubmitHandler.h"
  14. #include "cmSystemTools.h"
  15. #include "cmVersion.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmCTest.h"
  18. #include <cmsys/Process.h>
  19. #include <cmsys/Base64.h>
  20. // For XML-RPC submission
  21. #include "xmlrpc.h"
  22. #include "xmlrpc_client.h"
  23. // For curl submission
  24. #include "CTest/Curl/curl/curl.h"
  25. #include <sys/stat.h>
  26. //----------------------------------------------------------------------------
  27. cmCTestSubmitHandler::cmCTestSubmitHandler() : m_HTTPProxy(), m_FTPProxy()
  28. {
  29. m_Verbose = false;
  30. m_HTTPProxy = "";
  31. m_HTTPProxyType = 0;
  32. m_HTTPProxyAuth = "";
  33. if ( getenv("HTTP_PROXY") )
  34. {
  35. m_HTTPProxyType = 1;
  36. m_HTTPProxy = getenv("HTTP_PROXY");
  37. if ( getenv("HTTP_PROXY_PORT") )
  38. {
  39. m_HTTPProxy += ":";
  40. m_HTTPProxy += getenv("HTTP_PROXY_PORT");
  41. }
  42. if ( getenv("HTTP_PROXY_TYPE") )
  43. {
  44. cmStdString type = getenv("HTTP_PROXY_TYPE");
  45. // HTTP/SOCKS4/SOCKS5
  46. if ( type == "HTTP" )
  47. {
  48. m_HTTPProxyType = 1;
  49. }
  50. else if ( type == "SOCKS4" )
  51. {
  52. m_HTTPProxyType = 2;
  53. }
  54. else if ( type == "SOCKS5" )
  55. {
  56. m_HTTPProxyType = 3;
  57. }
  58. }
  59. if ( getenv("HTTP_PROXY_USER") )
  60. {
  61. m_HTTPProxyAuth = getenv("HTTP_PROXY_USER");
  62. }
  63. if ( getenv("HTTP_PROXY_PASSWD") )
  64. {
  65. m_HTTPProxyAuth += ":";
  66. m_HTTPProxyAuth += getenv("HTTP_PROXY_PASSWD");
  67. }
  68. }
  69. m_FTPProxy = "";
  70. m_FTPProxyType = 0;
  71. if ( getenv("FTP_PROXY") )
  72. {
  73. m_FTPProxyType = 1;
  74. m_FTPProxy = getenv("FTP_PROXY");
  75. if ( getenv("FTP_PROXY_PORT") )
  76. {
  77. m_FTPProxy += ":";
  78. m_FTPProxy += getenv("FTP_PROXY_PORT");
  79. }
  80. if ( getenv("FTP_PROXY_TYPE") )
  81. {
  82. cmStdString type = getenv("FTP_PROXY_TYPE");
  83. // HTTP/SOCKS4/SOCKS5
  84. if ( type == "HTTP" )
  85. {
  86. m_FTPProxyType = 1;
  87. }
  88. else if ( type == "SOCKS4" )
  89. {
  90. m_FTPProxyType = 2;
  91. }
  92. else if ( type == "SOCKS5" )
  93. {
  94. m_FTPProxyType = 3;
  95. }
  96. }
  97. }
  98. if ( m_HTTPProxy.size() > 0 )
  99. {
  100. std::cout << " Use HTTP Proxy: " << m_HTTPProxy << std::endl;
  101. }
  102. if ( m_FTPProxy.size() > 0 )
  103. {
  104. std::cout << " Use FTP Proxy: " << m_FTPProxy << std::endl;
  105. }
  106. }
  107. //----------------------------------------------------------------------------
  108. bool cmCTestSubmitHandler::SubmitUsingFTP(const cmStdString& localprefix,
  109. const std::vector<cmStdString>& files,
  110. const cmStdString& remoteprefix,
  111. const cmStdString& url)
  112. {
  113. CURL *curl;
  114. CURLcode res;
  115. FILE* ftpfile;
  116. char error_buffer[1024];
  117. /* In windows, this will init the winsock stuff */
  118. ::curl_global_init(CURL_GLOBAL_ALL);
  119. cmStdString::size_type cc;
  120. for ( cc = 0; cc < files.size(); cc ++ )
  121. {
  122. /* get a curl handle */
  123. curl = curl_easy_init();
  124. if(curl)
  125. {
  126. // Using proxy
  127. if ( m_FTPProxyType > 0 )
  128. {
  129. curl_easy_setopt(curl, CURLOPT_PROXY, m_FTPProxy.c_str());
  130. switch (m_FTPProxyType)
  131. {
  132. case 2:
  133. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  134. break;
  135. case 3:
  136. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  137. break;
  138. default:
  139. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  140. }
  141. }
  142. // enable uploading
  143. ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1) ;
  144. cmStdString local_file = localprefix + "/" + files[cc];
  145. cmStdString upload_as = url + "/" + remoteprefix + files[cc];
  146. struct stat st;
  147. if ( ::stat(local_file.c_str(), &st) )
  148. {
  149. return false;
  150. }
  151. ftpfile = ::fopen(local_file.c_str(), "rb");
  152. *m_LogFile << "\tUpload file: " << local_file.c_str() << " to "
  153. << upload_as.c_str() << std::endl;
  154. if ( m_Verbose )
  155. {
  156. std::cout << " Upload file: " << local_file.c_str() << " to "
  157. << upload_as.c_str() << std::endl;
  158. }
  159. if ( m_Verbose )
  160. {
  161. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  162. }
  163. // specify target
  164. ::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
  165. // now specify which file to upload
  166. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  167. // and give the size of the upload (optional)
  168. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(st.st_size));
  169. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  170. // Now run off and do what you've been told!
  171. res = ::curl_easy_perform(curl);
  172. fclose(ftpfile);
  173. if ( res )
  174. {
  175. std::cerr << " Error when uploading file: " << local_file.c_str() << std::endl;
  176. std::cerr << " Error message was: " << error_buffer << std::endl;
  177. *m_LogFile << " Error when uploading file: " << local_file.c_str() << std::endl
  178. << " Error message was: " << error_buffer << std::endl;
  179. ::curl_easy_cleanup(curl);
  180. ::curl_global_cleanup();
  181. return false;
  182. }
  183. // always cleanup
  184. ::curl_easy_cleanup(curl);
  185. std::cout << " Uploaded: " + local_file << std::endl;
  186. }
  187. }
  188. ::curl_global_cleanup();
  189. return true;
  190. }
  191. //----------------------------------------------------------------------------
  192. // Uploading files is simpler
  193. bool cmCTestSubmitHandler::SubmitUsingHTTP(const cmStdString& localprefix,
  194. const std::vector<cmStdString>& files,
  195. const cmStdString& remoteprefix,
  196. const cmStdString& url)
  197. {
  198. CURL *curl;
  199. CURLcode res;
  200. FILE* ftpfile;
  201. char error_buffer[1024];
  202. /* In windows, this will init the winsock stuff */
  203. ::curl_global_init(CURL_GLOBAL_ALL);
  204. cmStdString::size_type cc, kk;
  205. for ( cc = 0; cc < files.size(); cc ++ )
  206. {
  207. /* get a curl handle */
  208. curl = curl_easy_init();
  209. if(curl)
  210. {
  211. // Using proxy
  212. if ( m_HTTPProxyType > 0 )
  213. {
  214. curl_easy_setopt(curl, CURLOPT_PROXY, m_HTTPProxy.c_str());
  215. switch (m_HTTPProxyType)
  216. {
  217. case 2:
  218. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  219. break;
  220. case 3:
  221. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  222. break;
  223. default:
  224. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  225. if (m_HTTPProxyAuth.size() > 0)
  226. {
  227. curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
  228. m_HTTPProxyAuth.c_str());
  229. }
  230. }
  231. }
  232. /* enable uploading */
  233. curl_easy_setopt(curl, CURLOPT_UPLOAD, 1) ;
  234. /* HTTP PUT please */
  235. curl_easy_setopt(curl, CURLOPT_PUT, 1);
  236. if ( m_Verbose )
  237. {
  238. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  239. }
  240. cmStdString local_file = localprefix + "/" + files[cc];
  241. cmStdString remote_file = remoteprefix + files[cc];
  242. *m_LogFile << "\tUpload file: " << local_file.c_str() << " to "
  243. << remote_file.c_str() << std::endl;
  244. cmStdString ofile = "";
  245. for ( kk = 0; kk < remote_file.size(); kk ++ )
  246. {
  247. char c = remote_file[kk];
  248. char hex[4] = { 0, 0, 0, 0 };
  249. hex[0] = c;
  250. switch ( c )
  251. {
  252. case '+':
  253. case '?':
  254. case '/':
  255. case '\\':
  256. case '&':
  257. case ' ':
  258. case '=':
  259. case '%':
  260. sprintf(hex, "%%%02X", (int)c);
  261. ofile.append(hex);
  262. break;
  263. default:
  264. ofile.append(hex);
  265. }
  266. }
  267. cmStdString upload_as
  268. = url + ((url.find("?",0) == cmStdString::npos) ? "?" : "&")
  269. + "FileName=" + ofile;
  270. struct stat st;
  271. if ( ::stat(local_file.c_str(), &st) )
  272. {
  273. return false;
  274. }
  275. ftpfile = ::fopen(local_file.c_str(), "rb");
  276. if ( m_Verbose )
  277. {
  278. std::cout << " Upload file: " << local_file.c_str() << " to "
  279. << upload_as.c_str() << " Size: " << st.st_size << std::endl;
  280. }
  281. // specify target
  282. ::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
  283. // now specify which file to upload
  284. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  285. // and give the size of the upload (optional)
  286. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(st.st_size));
  287. // and give curl the buffer for errors
  288. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  289. // Now run off and do what you've been told!
  290. res = ::curl_easy_perform(curl);
  291. fclose(ftpfile);
  292. if ( res )
  293. {
  294. std::cerr << " Error when uploading file: " << local_file.c_str() << std::endl;
  295. *m_LogFile << " Error when uploading file: " << local_file.c_str() << std::endl
  296. << " Error message was: " << error_buffer << std::endl;
  297. ::curl_easy_cleanup(curl);
  298. ::curl_global_cleanup();
  299. return false;
  300. }
  301. // always cleanup
  302. ::curl_easy_cleanup(curl);
  303. std::cout << " Uploaded: " + local_file << std::endl;
  304. }
  305. }
  306. ::curl_global_cleanup();
  307. return true;
  308. }
  309. //----------------------------------------------------------------------------
  310. bool cmCTestSubmitHandler::TriggerUsingHTTP(const std::vector<cmStdString>& files,
  311. const cmStdString& remoteprefix,
  312. const cmStdString& url)
  313. {
  314. CURL *curl;
  315. char error_buffer[1024];
  316. /* In windows, this will init the winsock stuff */
  317. ::curl_global_init(CURL_GLOBAL_ALL);
  318. cmStdString::size_type cc, kk;
  319. for ( cc = 0; cc < files.size(); cc ++ )
  320. {
  321. /* get a curl handle */
  322. curl = curl_easy_init();
  323. if(curl)
  324. {
  325. // Using proxy
  326. if ( m_HTTPProxyType > 0 )
  327. {
  328. curl_easy_setopt(curl, CURLOPT_PROXY, m_HTTPProxy.c_str());
  329. switch (m_HTTPProxyType)
  330. {
  331. case 2:
  332. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  333. break;
  334. case 3:
  335. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  336. break;
  337. default:
  338. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  339. if (m_HTTPProxyAuth.size() > 0)
  340. {
  341. curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
  342. m_HTTPProxyAuth.c_str());
  343. }
  344. }
  345. }
  346. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
  347. if ( m_Verbose )
  348. {
  349. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  350. }
  351. // and give curl the buffer for errors
  352. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  353. cmStdString file = remoteprefix + files[cc];
  354. cmStdString ofile = "";
  355. for ( kk = 0; kk < file.size(); kk ++ )
  356. {
  357. char c = file[kk];
  358. char hex[4] = { 0, 0, 0, 0 };
  359. hex[0] = c;
  360. switch ( c )
  361. {
  362. case '+':
  363. case '?':
  364. case '/':
  365. case '\\':
  366. case '&':
  367. case ' ':
  368. case '=':
  369. case '%':
  370. sprintf(hex, "%%%02X", (int)c);
  371. ofile.append(hex);
  372. break;
  373. default:
  374. ofile.append(hex);
  375. }
  376. }
  377. cmStdString turl
  378. = url + ((url.find("?",0) == cmStdString::npos) ? "?" : "&")
  379. + "xmlfile=" + ofile;
  380. *m_LogFile << "Trigger url: " << turl.c_str() << std::endl;
  381. if ( m_Verbose )
  382. {
  383. std::cout << " Trigger url: " << turl.c_str() << std::endl;
  384. }
  385. curl_easy_setopt(curl, CURLOPT_URL, turl.c_str());
  386. if ( curl_easy_perform(curl) )
  387. {
  388. std::cerr << " Error when triggering: " << turl.c_str() << std::endl;
  389. *m_LogFile << "\tTrigerring failed with error: " << error_buffer << std::endl;
  390. ::curl_easy_cleanup(curl);
  391. ::curl_global_cleanup();
  392. return false;
  393. }
  394. // always cleanup
  395. ::curl_easy_cleanup(curl);
  396. std::cout << std::endl;
  397. }
  398. }
  399. ::curl_global_cleanup();
  400. std::cout << " Dart server triggered..." << std::endl;
  401. return true;
  402. }
  403. //----------------------------------------------------------------------------
  404. bool cmCTestSubmitHandler::SubmitUsingSCP(
  405. const cmStdString& scp_command,
  406. const cmStdString& localprefix,
  407. const std::vector<cmStdString>& files,
  408. const cmStdString& remoteprefix,
  409. const cmStdString& url)
  410. {
  411. if ( !scp_command.size() || !localprefix.size() ||
  412. !files.size() || !remoteprefix.size() || !url.size() )
  413. {
  414. return 0;
  415. }
  416. std::vector<const char*> argv;
  417. argv.push_back(scp_command.c_str()); // Scp command
  418. argv.push_back(scp_command.c_str()); // Dummy string for file
  419. argv.push_back(scp_command.c_str()); // Dummy string for remote url
  420. argv.push_back(0);
  421. cmsysProcess* cp = cmsysProcess_New();
  422. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  423. //cmsysProcess_SetTimeout(cp, timeout);
  424. int problems = 0;
  425. std::vector<cmStdString>::const_iterator it;
  426. for ( it = files.begin();
  427. it != files.end();
  428. it ++ )
  429. {
  430. int retVal;
  431. std::string lfname = localprefix;
  432. cmSystemTools::ConvertToUnixSlashes(lfname);
  433. lfname += "/" + *it;
  434. lfname = cmSystemTools::ConvertToOutputPath(lfname.c_str());
  435. argv[1] = lfname.c_str();
  436. std::string rfname = url + "/" + remoteprefix + *it;
  437. argv[2] = rfname.c_str();
  438. if ( m_Verbose )
  439. {
  440. std::cout << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
  441. << argv[2] << "\"" << std::endl;
  442. }
  443. *m_LogFile << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
  444. << argv[2] << "\"" << std::endl;
  445. cmsysProcess_SetCommand(cp, &*argv.begin());
  446. cmsysProcess_Execute(cp);
  447. char* data;
  448. int length;
  449. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  450. {
  451. std::cout.write(data, length);
  452. }
  453. cmsysProcess_WaitForExit(cp, 0);
  454. int result = cmsysProcess_GetState(cp);
  455. if(result == cmsysProcess_State_Exited)
  456. {
  457. retVal = cmsysProcess_GetExitValue(cp);
  458. if ( retVal != 0 )
  459. {
  460. if ( m_Verbose )
  461. {
  462. std::cout << "\tSCP returned: " << retVal << std::endl;
  463. }
  464. *m_LogFile << "\tSCP returned: " << retVal << std::endl;
  465. problems ++;
  466. }
  467. }
  468. else if(result == cmsysProcess_State_Exception)
  469. {
  470. retVal = cmsysProcess_GetExitException(cp);
  471. if ( m_Verbose )
  472. {
  473. std::cerr << "\tThere was an exception: " << retVal << std::endl;
  474. }
  475. *m_LogFile << "\tThere was an exception: " << retVal << std::endl;
  476. problems ++;
  477. }
  478. else if(result == cmsysProcess_State_Expired)
  479. {
  480. if ( m_Verbose )
  481. {
  482. std::cerr << "\tThere was a timeout" << std::endl;
  483. }
  484. *m_LogFile << "\tThere was a timeout" << std::endl;
  485. problems ++;
  486. }
  487. else if(result == cmsysProcess_State_Error)
  488. {
  489. if ( m_Verbose )
  490. {
  491. std::cerr << "\tError executing SCP: "
  492. << cmsysProcess_GetErrorString(cp) << std::endl;
  493. }
  494. *m_LogFile << "\tError executing SCP: "
  495. << cmsysProcess_GetErrorString(cp) << std::endl;
  496. problems ++;
  497. }
  498. }
  499. cmsysProcess_Delete(cp);
  500. if ( problems )
  501. {
  502. return false;
  503. }
  504. return true;
  505. }
  506. //----------------------------------------------------------------------------
  507. bool cmCTestSubmitHandler::SubmitUsingXMLRPC(const cmStdString& localprefix,
  508. const std::vector<cmStdString>& files,
  509. const cmStdString& remoteprefix,
  510. const cmStdString& url)
  511. {
  512. xmlrpc_env env;
  513. std::string ctestVersion = cmVersion::GetCMakeVersion();
  514. const char *state_name;
  515. /* Start up our XML-RPC client library. */
  516. xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, "CTest", ctestVersion.c_str());
  517. /* Initialize our error-handling environment. */
  518. xmlrpc_env_init(&env);
  519. /* Call the famous server at UserLand. */
  520. std::cout << " Submitting to: " << url.c_str() << " (" << remoteprefix.c_str() << ")" << std::endl;
  521. std::vector<cmStdString>::const_iterator it;
  522. for ( it = files.begin(); it != files.end(); ++it )
  523. {
  524. xmlrpc_value *result;
  525. std::string local_file = localprefix + "/" + *it;
  526. std::cout << " Submit file: " << local_file.c_str() << std::endl;
  527. struct stat st;
  528. if ( ::stat(local_file.c_str(), &st) )
  529. {
  530. return false;
  531. }
  532. size_t fileSize = st.st_size;
  533. FILE* fp = fopen(local_file.c_str(), "r");
  534. if ( !fp )
  535. {
  536. return false;
  537. }
  538. unsigned char *fileBuffer = new unsigned char[fileSize];
  539. if ( fread(fileBuffer, 1, fileSize, fp) != fileSize )
  540. {
  541. delete [] fileBuffer;
  542. fclose(fp);
  543. return false;
  544. }
  545. fclose(fp);
  546. std::string remoteCommand = remoteprefix + ".put";
  547. result = xmlrpc_client_call(&env, url.c_str(),
  548. remoteCommand.c_str(),
  549. "(6)", fileBuffer, (xmlrpc_int32)fileSize );
  550. delete [] fileBuffer;
  551. if ( env.fault_occurred )
  552. {
  553. std::cerr << " Submission problem: " << env.fault_string << " (" << env.fault_code << ")" << std::endl;
  554. xmlrpc_env_clean(&env);
  555. xmlrpc_client_cleanup();
  556. return false;
  557. }
  558. /* Get our state name and print it out. */
  559. xmlrpc_parse_value(&env, result, "s", &state_name);
  560. if ( env.fault_occurred )
  561. {
  562. std::cerr << " Submission problem: " << env.fault_string << " (" << env.fault_code << ")" << std::endl;
  563. xmlrpc_DECREF(result);
  564. xmlrpc_env_clean(&env);
  565. xmlrpc_client_cleanup();
  566. return false;
  567. }
  568. /* Dispose of our result value. */
  569. xmlrpc_DECREF(result);
  570. }
  571. /* Clean up our error-handling environment. */
  572. xmlrpc_env_clean(&env);
  573. /* Shutdown our XML-RPC client library. */
  574. xmlrpc_client_cleanup();
  575. return true;
  576. }
  577. //----------------------------------------------------------------------------
  578. int cmCTestSubmitHandler::ProcessHandler()
  579. {
  580. const std::string &buildDirectory = m_CTest->GetDartConfiguration("BuildDirectory");
  581. if ( buildDirectory.size() == 0 )
  582. {
  583. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  584. return -1;
  585. }
  586. cmGeneratedFileStream ofs;
  587. m_CTest->OpenOutputFile("Temporary", "LastSubmit.log", ofs);
  588. cmCTest::tm_VectorOfStrings files;
  589. std::string prefix = this->GetSubmitResultsPrefix();
  590. // TODO:
  591. // Check if test is enabled
  592. m_CTest->AddIfExists(files, "Update.xml");
  593. m_CTest->AddIfExists(files, "Configure.xml");
  594. m_CTest->AddIfExists(files, "Build.xml");
  595. m_CTest->AddIfExists(files, "Test.xml");
  596. if ( m_CTest->AddIfExists(files, "Coverage.xml") )
  597. {
  598. cmCTest::tm_VectorOfStrings gfiles;
  599. std::string gpath = buildDirectory + "/Testing/" + m_CTest->GetCurrentTag();
  600. std::string::size_type glen = gpath.size() + 1;
  601. gpath = gpath + "/CoverageLog*";
  602. //std::cout << "Globbing for: " << gpath.c_str() << std::endl;
  603. if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) )
  604. {
  605. size_t cc;
  606. for ( cc = 0; cc < gfiles.size(); cc ++ )
  607. {
  608. gfiles[cc] = gfiles[cc].substr(glen);
  609. //std::cout << "Glob file: " << gfiles[cc].c_str() << std::endl;
  610. files.push_back(gfiles[cc]);
  611. }
  612. }
  613. else
  614. {
  615. std::cerr << "Problem globbing" << std::endl;
  616. }
  617. }
  618. m_CTest->AddIfExists(files, "DynamicAnalysis.xml");
  619. m_CTest->AddIfExists(files, "Purify.xml");
  620. m_CTest->AddIfExists(files, "Notes.xml");
  621. if ( ofs )
  622. {
  623. ofs << "Upload files:" << std::endl;
  624. int cnt = 0;
  625. cmCTest::tm_VectorOfStrings::iterator it;
  626. for ( it = files.begin(); it != files.end(); ++ it )
  627. {
  628. ofs << cnt << "\t" << it->c_str() << std::endl;
  629. cnt ++;
  630. }
  631. }
  632. std::cout << "Submit files (using " << m_CTest->GetDartConfiguration("DropMethod") << ")"
  633. << std::endl;
  634. this->SetLogFile(&ofs);
  635. if ( m_CTest->GetDartConfiguration("DropMethod") == "" ||
  636. m_CTest->GetDartConfiguration("DropMethod") == "ftp" )
  637. {
  638. ofs << "Using drop method: FTP" << std::endl;
  639. std::cout << " Using FTP submit method" << std::endl;
  640. std::string url = "ftp://";
  641. url += cmCTest::MakeURLSafe(m_CTest->GetDartConfiguration("DropSiteUser")) + ":" +
  642. cmCTest::MakeURLSafe(m_CTest->GetDartConfiguration("DropSitePassword")) + "@" +
  643. m_CTest->GetDartConfiguration("DropSite") +
  644. cmCTest::MakeURLSafe(m_CTest->GetDartConfiguration("DropLocation"));
  645. if ( !this->SubmitUsingFTP(buildDirectory+"/Testing/"+m_CTest->GetCurrentTag(),
  646. files, prefix, url) )
  647. {
  648. std::cerr << " Problems when submitting via FTP" << std::endl;
  649. ofs << " Problems when submitting via FTP" << std::endl;
  650. return -1;
  651. }
  652. if ( !this->TriggerUsingHTTP(files, prefix, m_CTest->GetDartConfiguration("TriggerSite")) )
  653. {
  654. std::cerr << " Problems when triggering via HTTP" << std::endl;
  655. ofs << " Problems when triggering via HTTP" << std::endl;
  656. return -1;
  657. }
  658. std::cout << " Submission successful" << std::endl;
  659. ofs << " Submission successful" << std::endl;
  660. return 0;
  661. }
  662. else if ( m_CTest->GetDartConfiguration("DropMethod") == "http" )
  663. {
  664. ofs << "Using drop method: HTTP" << std::endl;
  665. std::cout << " Using HTTP submit method" << std::endl;
  666. std::string url = "http://";
  667. if ( m_CTest->GetDartConfiguration("DropSiteUser").size() > 0 )
  668. {
  669. url += m_CTest->GetDartConfiguration("DropSiteUser");
  670. if ( m_CTest->GetDartConfiguration("DropSitePassword").size() > 0 )
  671. {
  672. url += ":" + m_CTest->GetDartConfiguration("DropSitePassword");
  673. }
  674. url += "@";
  675. }
  676. url += m_CTest->GetDartConfiguration("DropSite") + m_CTest->GetDartConfiguration("DropLocation");
  677. if ( !this->SubmitUsingHTTP(buildDirectory +"/Testing/"+m_CTest->GetCurrentTag(), files, prefix, url) )
  678. {
  679. std::cerr << " Problems when submitting via HTTP" << std::endl;
  680. ofs << " Problems when submitting via HTTP" << std::endl;
  681. return -1;
  682. }
  683. if ( !this->TriggerUsingHTTP(files, prefix, m_CTest->GetDartConfiguration("TriggerSite")) )
  684. {
  685. std::cerr << " Problems when triggering via HTTP" << std::endl;
  686. ofs << " Problems when triggering via HTTP" << std::endl;
  687. return -1;
  688. }
  689. std::cout << " Submission successful" << std::endl;
  690. ofs << " Submission successful" << std::endl;
  691. return 0;
  692. }
  693. else if ( m_CTest->GetDartConfiguration("DropMethod") == "xmlrpc" )
  694. {
  695. ofs << "Using drop method: XML-RPC" << std::endl;
  696. std::cout << " Using XML-RPC submit method" << std::endl;
  697. std::string url = m_CTest->GetDartConfiguration("DropSite");
  698. prefix = m_CTest->GetDartConfiguration("DropLocation");
  699. if ( !this->SubmitUsingXMLRPC(buildDirectory+"/Testing/"+m_CTest->GetCurrentTag(), files, prefix, url) )
  700. {
  701. std::cerr << " Problems when submitting via XML-RPC" << std::endl;
  702. ofs << " Problems when submitting via XML-RPC" << std::endl;
  703. return -1;
  704. }
  705. std::cout << " Submission successful" << std::endl;
  706. ofs << " Submission successful" << std::endl;
  707. return 0;
  708. }
  709. else if ( m_CTest->GetDartConfiguration("DropMethod") == "scp" )
  710. {
  711. std::string url;
  712. if ( m_CTest->GetDartConfiguration("DropSiteUser").size() > 0 )
  713. {
  714. url += m_CTest->GetDartConfiguration("DropSiteUser") + "@";
  715. }
  716. url += m_CTest->GetDartConfiguration("DropSite") + ":" + m_CTest->GetDartConfiguration("DropLocation");
  717. if ( !this->SubmitUsingSCP(m_CTest->GetDartConfiguration("ScpCommand"),
  718. buildDirectory+"/Testing/"+m_CTest->GetCurrentTag(), files, prefix, url) )
  719. {
  720. std::cerr << " Problems when submitting via SCP" << std::endl;
  721. ofs << " Problems when submitting via SCP" << std::endl;
  722. return -1;
  723. }
  724. std::cout << " Submission successful" << std::endl;
  725. ofs << " Submission successful" << std::endl;
  726. }
  727. std::cout << " Unknown submission method: \"" << m_CTest->GetDartConfiguration("DropMethod") << "\"" << std::endl;
  728. return -1;
  729. }
  730. //----------------------------------------------------------------------------
  731. std::string cmCTestSubmitHandler::GetSubmitResultsPrefix()
  732. {
  733. std::string name = m_CTest->GetDartConfiguration("Site") +
  734. "___" + m_CTest->GetDartConfiguration("BuildName") +
  735. "___" + m_CTest->GetCurrentTag() + "-" +
  736. m_CTest->GetTestModelString() + "___XML___";
  737. return name;
  738. }