cmCTestSubmit.cxx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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 "cmCTestSubmit.h"
  14. #include "cmSystemTools.h"
  15. #include "cmVersion.h"
  16. #include <cmsys/Process.h>
  17. #include <cmsys/Base64.h>
  18. #include "xmlrpc.h"
  19. #include "xmlrpc_client.h"
  20. #include "CTest/Curl/curl/curl.h"
  21. #include <sys/stat.h>
  22. //----------------------------------------------------------------------------
  23. cmCTestSubmit::cmCTestSubmit() : m_HTTPProxy(), m_FTPProxy()
  24. {
  25. m_Verbose = false;
  26. m_HTTPProxy = "";
  27. m_HTTPProxyType = 0;
  28. m_HTTPProxyAuth = "";
  29. if ( getenv("HTTP_PROXY") )
  30. {
  31. m_HTTPProxyType = 1;
  32. m_HTTPProxy = getenv("HTTP_PROXY");
  33. if ( getenv("HTTP_PROXY_PORT") )
  34. {
  35. m_HTTPProxy += ":";
  36. m_HTTPProxy += getenv("HTTP_PROXY_PORT");
  37. }
  38. if ( getenv("HTTP_PROXY_TYPE") )
  39. {
  40. cmStdString type = getenv("HTTP_PROXY_TYPE");
  41. // HTTP/SOCKS4/SOCKS5
  42. if ( type == "HTTP" )
  43. {
  44. m_HTTPProxyType = 1;
  45. }
  46. else if ( type == "SOCKS4" )
  47. {
  48. m_HTTPProxyType = 2;
  49. }
  50. else if ( type == "SOCKS5" )
  51. {
  52. m_HTTPProxyType = 3;
  53. }
  54. }
  55. if ( getenv("HTTP_PROXY_USER") )
  56. {
  57. m_HTTPProxyAuth = getenv("HTTP_PROXY_USER");
  58. }
  59. if ( getenv("HTTP_PROXY_PASSWD") )
  60. {
  61. m_HTTPProxyAuth += ":";
  62. m_HTTPProxyAuth += getenv("HTTP_PROXY_PASSWD");
  63. }
  64. }
  65. m_FTPProxy = "";
  66. m_FTPProxyType = 0;
  67. if ( getenv("FTP_PROXY") )
  68. {
  69. m_FTPProxyType = 1;
  70. m_FTPProxy = getenv("FTP_PROXY");
  71. if ( getenv("FTP_PROXY_PORT") )
  72. {
  73. m_FTPProxy += ":";
  74. m_FTPProxy += getenv("FTP_PROXY_PORT");
  75. }
  76. if ( getenv("FTP_PROXY_TYPE") )
  77. {
  78. cmStdString type = getenv("FTP_PROXY_TYPE");
  79. // HTTP/SOCKS4/SOCKS5
  80. if ( type == "HTTP" )
  81. {
  82. m_FTPProxyType = 1;
  83. }
  84. else if ( type == "SOCKS4" )
  85. {
  86. m_FTPProxyType = 2;
  87. }
  88. else if ( type == "SOCKS5" )
  89. {
  90. m_FTPProxyType = 3;
  91. }
  92. }
  93. }
  94. if ( m_HTTPProxy.size() > 0 )
  95. {
  96. std::cout << " Use HTTP Proxy: " << m_HTTPProxy << std::endl;
  97. }
  98. if ( m_FTPProxy.size() > 0 )
  99. {
  100. std::cout << " Use FTP Proxy: " << m_FTPProxy << std::endl;
  101. }
  102. }
  103. //----------------------------------------------------------------------------
  104. bool cmCTestSubmit::SubmitUsingFTP(const cmStdString& localprefix,
  105. const std::vector<cmStdString>& files,
  106. const cmStdString& remoteprefix,
  107. const cmStdString& url)
  108. {
  109. CURL *curl;
  110. CURLcode res;
  111. FILE* ftpfile;
  112. char error_buffer[1024];
  113. /* In windows, this will init the winsock stuff */
  114. ::curl_global_init(CURL_GLOBAL_ALL);
  115. cmStdString::size_type cc;
  116. for ( cc = 0; cc < files.size(); cc ++ )
  117. {
  118. /* get a curl handle */
  119. curl = curl_easy_init();
  120. if(curl)
  121. {
  122. // Using proxy
  123. if ( m_FTPProxyType > 0 )
  124. {
  125. curl_easy_setopt(curl, CURLOPT_PROXY, m_FTPProxy.c_str());
  126. switch (m_FTPProxyType)
  127. {
  128. case 2:
  129. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  130. break;
  131. case 3:
  132. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  133. break;
  134. default:
  135. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  136. }
  137. }
  138. // enable uploading
  139. ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1) ;
  140. cmStdString local_file = localprefix + "/" + files[cc];
  141. cmStdString upload_as = url + "/" + remoteprefix + files[cc];
  142. struct stat st;
  143. if ( ::stat(local_file.c_str(), &st) )
  144. {
  145. return false;
  146. }
  147. ftpfile = ::fopen(local_file.c_str(), "rb");
  148. *m_LogFile << "\tUpload file: " << local_file.c_str() << " to "
  149. << upload_as.c_str() << std::endl;
  150. if ( m_Verbose )
  151. {
  152. std::cout << " Upload file: " << local_file.c_str() << " to "
  153. << upload_as.c_str() << std::endl;
  154. }
  155. if ( m_Verbose )
  156. {
  157. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  158. }
  159. // specify target
  160. ::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
  161. // now specify which file to upload
  162. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  163. // and give the size of the upload (optional)
  164. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(st.st_size));
  165. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  166. // Now run off and do what you've been told!
  167. res = ::curl_easy_perform(curl);
  168. fclose(ftpfile);
  169. if ( res )
  170. {
  171. std::cerr << " Error when uploading file: " << local_file.c_str() << std::endl;
  172. std::cerr << " Error message was: " << error_buffer << std::endl;
  173. *m_LogFile << " Error when uploading file: " << local_file.c_str() << std::endl
  174. << " Error message was: " << error_buffer << std::endl;
  175. ::curl_easy_cleanup(curl);
  176. ::curl_global_cleanup();
  177. return false;
  178. }
  179. // always cleanup
  180. ::curl_easy_cleanup(curl);
  181. std::cout << " Uploaded: " + local_file << std::endl;
  182. }
  183. }
  184. ::curl_global_cleanup();
  185. return true;
  186. }
  187. //----------------------------------------------------------------------------
  188. // Uploading files is simpler
  189. bool cmCTestSubmit::SubmitUsingHTTP(const cmStdString& localprefix,
  190. const std::vector<cmStdString>& files,
  191. const cmStdString& remoteprefix,
  192. const cmStdString& url)
  193. {
  194. CURL *curl;
  195. CURLcode res;
  196. FILE* ftpfile;
  197. char error_buffer[1024];
  198. /* In windows, this will init the winsock stuff */
  199. ::curl_global_init(CURL_GLOBAL_ALL);
  200. cmStdString::size_type cc, kk;
  201. for ( cc = 0; cc < files.size(); cc ++ )
  202. {
  203. /* get a curl handle */
  204. curl = curl_easy_init();
  205. if(curl)
  206. {
  207. // Using proxy
  208. if ( m_HTTPProxyType > 0 )
  209. {
  210. curl_easy_setopt(curl, CURLOPT_PROXY, m_HTTPProxy.c_str());
  211. switch (m_HTTPProxyType)
  212. {
  213. case 2:
  214. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  215. break;
  216. case 3:
  217. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  218. break;
  219. default:
  220. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  221. if (m_HTTPProxyAuth.size() > 0)
  222. {
  223. curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
  224. m_HTTPProxyAuth.c_str());
  225. }
  226. }
  227. }
  228. /* enable uploading */
  229. curl_easy_setopt(curl, CURLOPT_UPLOAD, 1) ;
  230. /* HTTP PUT please */
  231. curl_easy_setopt(curl, CURLOPT_PUT, 1);
  232. if ( m_Verbose )
  233. {
  234. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  235. }
  236. cmStdString local_file = localprefix + "/" + files[cc];
  237. cmStdString remote_file = remoteprefix + files[cc];
  238. *m_LogFile << "\tUpload file: " << local_file.c_str() << " to "
  239. << remote_file.c_str() << std::endl;
  240. cmStdString ofile = "";
  241. for ( kk = 0; kk < remote_file.size(); kk ++ )
  242. {
  243. char c = remote_file[kk];
  244. char hex[4] = { 0, 0, 0, 0 };
  245. hex[0] = c;
  246. switch ( c )
  247. {
  248. case '+':
  249. case '?':
  250. case '/':
  251. case '\\':
  252. case '&':
  253. case ' ':
  254. case '=':
  255. case '%':
  256. sprintf(hex, "%%%02X", (int)c);
  257. ofile.append(hex);
  258. break;
  259. default:
  260. ofile.append(hex);
  261. }
  262. }
  263. cmStdString upload_as
  264. = url + ((url.find("?",0) == cmStdString::npos) ? "?" : "&")
  265. + "FileName=" + ofile;
  266. struct stat st;
  267. if ( ::stat(local_file.c_str(), &st) )
  268. {
  269. return false;
  270. }
  271. ftpfile = ::fopen(local_file.c_str(), "rb");
  272. if ( m_Verbose )
  273. {
  274. std::cout << " Upload file: " << local_file.c_str() << " to "
  275. << upload_as.c_str() << " Size: " << st.st_size << std::endl;
  276. }
  277. // specify target
  278. ::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
  279. // now specify which file to upload
  280. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  281. // and give the size of the upload (optional)
  282. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(st.st_size));
  283. // and give curl the buffer for errors
  284. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  285. // Now run off and do what you've been told!
  286. res = ::curl_easy_perform(curl);
  287. fclose(ftpfile);
  288. if ( res )
  289. {
  290. std::cerr << " Error when uploading file: " << local_file.c_str() << std::endl;
  291. *m_LogFile << " Error when uploading file: " << local_file.c_str() << std::endl
  292. << " Error message was: " << error_buffer << std::endl;
  293. ::curl_easy_cleanup(curl);
  294. ::curl_global_cleanup();
  295. return false;
  296. }
  297. // always cleanup
  298. ::curl_easy_cleanup(curl);
  299. std::cout << " Uploaded: " + local_file << std::endl;
  300. }
  301. }
  302. ::curl_global_cleanup();
  303. return true;
  304. }
  305. //----------------------------------------------------------------------------
  306. bool cmCTestSubmit::TriggerUsingHTTP(const std::vector<cmStdString>& files,
  307. const cmStdString& remoteprefix,
  308. const cmStdString& url)
  309. {
  310. CURL *curl;
  311. char error_buffer[1024];
  312. /* In windows, this will init the winsock stuff */
  313. ::curl_global_init(CURL_GLOBAL_ALL);
  314. cmStdString::size_type cc, kk;
  315. for ( cc = 0; cc < files.size(); cc ++ )
  316. {
  317. /* get a curl handle */
  318. curl = curl_easy_init();
  319. if(curl)
  320. {
  321. // Using proxy
  322. if ( m_HTTPProxyType > 0 )
  323. {
  324. curl_easy_setopt(curl, CURLOPT_PROXY, m_HTTPProxy.c_str());
  325. switch (m_HTTPProxyType)
  326. {
  327. case 2:
  328. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  329. break;
  330. case 3:
  331. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  332. break;
  333. default:
  334. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  335. if (m_HTTPProxyAuth.size() > 0)
  336. {
  337. curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
  338. m_HTTPProxyAuth.c_str());
  339. }
  340. }
  341. }
  342. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
  343. if ( m_Verbose )
  344. {
  345. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  346. }
  347. // and give curl the buffer for errors
  348. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  349. cmStdString file = remoteprefix + files[cc];
  350. cmStdString ofile = "";
  351. for ( kk = 0; kk < file.size(); kk ++ )
  352. {
  353. char c = file[kk];
  354. char hex[4] = { 0, 0, 0, 0 };
  355. hex[0] = c;
  356. switch ( c )
  357. {
  358. case '+':
  359. case '?':
  360. case '/':
  361. case '\\':
  362. case '&':
  363. case ' ':
  364. case '=':
  365. case '%':
  366. sprintf(hex, "%%%02X", (int)c);
  367. ofile.append(hex);
  368. break;
  369. default:
  370. ofile.append(hex);
  371. }
  372. }
  373. cmStdString turl
  374. = url + ((url.find("?",0) == cmStdString::npos) ? "?" : "&")
  375. + "xmlfile=" + ofile;
  376. *m_LogFile << "Trigger url: " << turl.c_str() << std::endl;
  377. if ( m_Verbose )
  378. {
  379. std::cout << " Trigger url: " << turl.c_str() << std::endl;
  380. }
  381. curl_easy_setopt(curl, CURLOPT_URL, turl.c_str());
  382. if ( curl_easy_perform(curl) )
  383. {
  384. std::cerr << " Error when triggering: " << turl.c_str() << std::endl;
  385. *m_LogFile << "\tTrigerring failed with error: " << error_buffer << std::endl;
  386. ::curl_easy_cleanup(curl);
  387. ::curl_global_cleanup();
  388. return false;
  389. }
  390. // always cleanup
  391. ::curl_easy_cleanup(curl);
  392. std::cout << std::endl;
  393. }
  394. }
  395. ::curl_global_cleanup();
  396. std::cout << " Dart server triggered..." << std::endl;
  397. return true;
  398. }
  399. //----------------------------------------------------------------------------
  400. bool cmCTestSubmit::SubmitUsingSCP(
  401. const cmStdString& scp_command,
  402. const cmStdString& localprefix,
  403. const std::vector<cmStdString>& files,
  404. const cmStdString& remoteprefix,
  405. const cmStdString& url)
  406. {
  407. if ( !scp_command.size() || !localprefix.size() ||
  408. !files.size() || !remoteprefix.size() || !url.size() )
  409. {
  410. return 0;
  411. }
  412. std::vector<const char*> argv;
  413. argv.push_back(scp_command.c_str()); // Scp command
  414. argv.push_back(scp_command.c_str()); // Dummy string for file
  415. argv.push_back(scp_command.c_str()); // Dummy string for remote url
  416. argv.push_back(0);
  417. cmsysProcess* cp = cmsysProcess_New();
  418. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  419. //cmsysProcess_SetTimeout(cp, timeout);
  420. int problems = 0;
  421. std::vector<cmStdString>::const_iterator it;
  422. for ( it = files.begin();
  423. it != files.end();
  424. it ++ )
  425. {
  426. int retVal;
  427. std::string lfname = localprefix;
  428. cmSystemTools::ConvertToUnixSlashes(lfname);
  429. lfname += "/" + *it;
  430. lfname = cmSystemTools::ConvertToOutputPath(lfname.c_str());
  431. argv[1] = lfname.c_str();
  432. std::string rfname = url + "/" + remoteprefix + *it;
  433. argv[2] = rfname.c_str();
  434. if ( m_Verbose )
  435. {
  436. std::cout << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
  437. << argv[2] << "\"" << std::endl;
  438. }
  439. *m_LogFile << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
  440. << argv[2] << "\"" << std::endl;
  441. cmsysProcess_SetCommand(cp, &*argv.begin());
  442. cmsysProcess_Execute(cp);
  443. char* data;
  444. int length;
  445. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  446. {
  447. std::cout.write(data, length);
  448. }
  449. cmsysProcess_WaitForExit(cp, 0);
  450. int result = cmsysProcess_GetState(cp);
  451. if(result == cmsysProcess_State_Exited)
  452. {
  453. retVal = cmsysProcess_GetExitValue(cp);
  454. if ( retVal != 0 )
  455. {
  456. if ( m_Verbose )
  457. {
  458. std::cout << "\tSCP returned: " << retVal << std::endl;
  459. }
  460. *m_LogFile << "\tSCP returned: " << retVal << std::endl;
  461. problems ++;
  462. }
  463. }
  464. else if(result == cmsysProcess_State_Exception)
  465. {
  466. retVal = cmsysProcess_GetExitException(cp);
  467. if ( m_Verbose )
  468. {
  469. std::cerr << "\tThere was an exception: " << retVal << std::endl;
  470. }
  471. *m_LogFile << "\tThere was an exception: " << retVal << std::endl;
  472. problems ++;
  473. }
  474. else if(result == cmsysProcess_State_Expired)
  475. {
  476. if ( m_Verbose )
  477. {
  478. std::cerr << "\tThere was a timeout" << std::endl;
  479. }
  480. *m_LogFile << "\tThere was a timeout" << std::endl;
  481. problems ++;
  482. }
  483. else if(result == cmsysProcess_State_Error)
  484. {
  485. if ( m_Verbose )
  486. {
  487. std::cerr << "\tError executing SCP: "
  488. << cmsysProcess_GetErrorString(cp) << std::endl;
  489. }
  490. *m_LogFile << "\tError executing SCP: "
  491. << cmsysProcess_GetErrorString(cp) << std::endl;
  492. problems ++;
  493. }
  494. }
  495. cmsysProcess_Delete(cp);
  496. if ( problems )
  497. {
  498. return false;
  499. }
  500. return true;
  501. }
  502. //----------------------------------------------------------------------------
  503. bool cmCTestSubmit::SubmitUsingXMLRPC(const cmStdString& localprefix,
  504. const std::vector<cmStdString>& files,
  505. const cmStdString& remoteprefix,
  506. const cmStdString& url)
  507. {
  508. xmlrpc_env env;
  509. std::string ctestVersion = cmVersion::GetCMakeVersion();
  510. const char *state_name;
  511. /* Start up our XML-RPC client library. */
  512. xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, "CTest", ctestVersion.c_str());
  513. /* Initialize our error-handling environment. */
  514. xmlrpc_env_init(&env);
  515. /* Call the famous server at UserLand. */
  516. std::cout << "RemotePrefix: " << remoteprefix.c_str() << std::endl;
  517. std::cout << "RemoteURL: " << url.c_str() << std::endl;
  518. std::cout << "Files: " << files.size() << std::endl;
  519. std::vector<cmStdString>::const_iterator it;
  520. int cnt = 32;
  521. for ( it = files.begin(); it != files.end(); ++it )
  522. {
  523. xmlrpc_value *result;
  524. std::string local_file = localprefix + "/" + *it;
  525. std::cout << "Submit file: " << local_file.c_str() << std::endl;
  526. struct stat st;
  527. if ( ::stat(local_file.c_str(), &st) )
  528. {
  529. return false;
  530. }
  531. size_t fileSize = st.st_size;
  532. size_t encodedSize = static_cast<size_t>(fileSize * 1.5); // Enough space for base64
  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. unsigned char *encodedFileBuffer = new unsigned char[encodedSize];
  540. if ( fread(fileBuffer, 1, fileSize, fp) != fileSize )
  541. {
  542. delete [] fileBuffer;
  543. delete [] encodedFileBuffer;
  544. fclose(fp);
  545. return false;
  546. }
  547. fclose(fp);
  548. size_t realEncodedSize = cmsysBase64_Encode(
  549. fileBuffer, fileSize,
  550. encodedFileBuffer, 1);
  551. if ( realEncodedSize < fileSize )
  552. {
  553. return false;
  554. }
  555. std::cout << "Buffer: [";
  556. std::cout.write(reinterpret_cast<const char*>(encodedFileBuffer),
  557. realEncodedSize);
  558. std::cout << "]" << std::endl;
  559. /*
  560. result = xmlrpc_client_call(&env, "http://betty.userland.com/RPC2",
  561. "examples.getStateName",
  562. "(i)", (xmlrpc_int32) cnt++);
  563. */
  564. std::string remoteCommand = remoteprefix + ".put";
  565. result = xmlrpc_client_call(&env, url.c_str(),
  566. remoteCommand.c_str(),
  567. "(6)", encodedFileBuffer, (xmlrpc_int32) realEncodedSize);
  568. delete [] fileBuffer;
  569. delete [] encodedFileBuffer;
  570. if ( env.fault_occurred )
  571. {
  572. std::cerr << "XML-RPC Fault: " << env.fault_string << " (" << env.fault_code << ")" << std::endl;
  573. xmlrpc_env_clean(&env);
  574. xmlrpc_client_cleanup();
  575. return 0;
  576. }
  577. /* Get our state name and print it out. */
  578. xmlrpc_parse_value(&env, result, "s", &state_name);
  579. if ( env.fault_occurred )
  580. {
  581. std::cerr << "XML-RPC Fault: " << env.fault_string << " (" << env.fault_code << ")" << std::endl;
  582. xmlrpc_DECREF(result);
  583. xmlrpc_env_clean(&env);
  584. xmlrpc_client_cleanup();
  585. return 0;
  586. }
  587. printf("%d: %s\n", cnt, state_name);
  588. /* Dispose of our result value. */
  589. xmlrpc_DECREF(result);
  590. }
  591. /* Clean up our error-handling environment. */
  592. xmlrpc_env_clean(&env);
  593. /* Shutdown our XML-RPC client library. */
  594. xmlrpc_client_cleanup();
  595. return 1;
  596. }