cmCTestSubmit.cxx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 "curl/curl.h"
  16. #include <sys/stat.h>
  17. bool cmCTestSubmit::SubmitUsingFTP(const std::string& localprefix,
  18. const std::vector<std::string>& files,
  19. const std::string& remoteprefix,
  20. const std::string& url)
  21. {
  22. CURL *curl;
  23. CURLcode res;
  24. FILE* ftpfile;
  25. /* In windows, this will init the winsock stuff */
  26. ::curl_global_init(CURL_GLOBAL_ALL);
  27. /* get a curl handle */
  28. curl = curl_easy_init();
  29. if(curl)
  30. {
  31. // enable uploading
  32. ::curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
  33. std::string::size_type cc;
  34. for ( cc = 0; cc < files.size(); cc ++ )
  35. {
  36. std::string local_file = localprefix + "/" + files[cc];
  37. std::string upload_as = url + "/" + remoteprefix + files[cc];
  38. struct stat st;
  39. if ( ::stat(local_file.c_str(), &st) )
  40. {
  41. return false;
  42. }
  43. ftpfile = ::fopen(local_file.c_str(), "rb");
  44. std::cout << "upload file: " << local_file.c_str() << " to "
  45. << upload_as.c_str() << std::endl;
  46. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  47. // specify target
  48. ::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
  49. // now specify which file to upload
  50. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  51. // and give the size of the upload (optional)
  52. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, st.st_size);
  53. // Now run off and do what you've been told!
  54. res = ::curl_easy_perform(curl);
  55. fclose(ftpfile);
  56. if ( res )
  57. {
  58. std::cout << "Error when uploading" << std::endl;
  59. ::curl_easy_cleanup(curl);
  60. ::curl_global_cleanup();
  61. return false;
  62. }
  63. }
  64. // always cleanup
  65. ::curl_easy_cleanup(curl);
  66. }
  67. ::curl_global_cleanup();
  68. return true;
  69. }
  70. bool cmCTestSubmit::TriggerUsingHTTP(const std::vector<std::string>& files,
  71. const std::string& remoteprefix,
  72. const std::string& url)
  73. {
  74. CURL *curl;
  75. CURLcode res = CURLcode();
  76. FILE* ftpfile;
  77. /* In windows, this will init the winsock stuff */
  78. ::curl_global_init(CURL_GLOBAL_ALL);
  79. /* get a curl handle */
  80. curl = curl_easy_init();
  81. if(curl)
  82. {
  83. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  84. std::string::size_type cc, kk;
  85. for ( cc = 0; cc < files.size(); cc ++ )
  86. {
  87. std::string file = remoteprefix + files[cc];
  88. std::string ofile = "";
  89. for ( kk = 0; kk < file.size(); kk ++ )
  90. {
  91. char c = file[kk];
  92. char hex[4] = { 0, 0, 0, 0 };
  93. hex[0] = c;
  94. switch ( c )
  95. {
  96. case '+':
  97. case '?':
  98. case '/':
  99. case '\\':
  100. case '&':
  101. case ' ':
  102. case '=':
  103. case '%':
  104. sprintf(hex, "%%%02X", (int)c);
  105. ofile.append(hex);
  106. break;
  107. break;
  108. default:
  109. ofile.append(hex);
  110. }
  111. }
  112. std::string turl = url + "?xmlfile=" + ofile;
  113. std::cout << "Trigger url: " << turl.c_str() << std::endl;
  114. curl_easy_setopt(curl, CURLOPT_URL, turl.c_str());
  115. res = curl_easy_perform(curl);
  116. if ( res )
  117. {
  118. std::cout << "Error when uploading" << std::endl;
  119. ::curl_easy_cleanup(curl);
  120. ::curl_global_cleanup();
  121. return false;
  122. }
  123. }
  124. // always cleanup
  125. ::curl_easy_cleanup(curl);
  126. }
  127. ::curl_global_cleanup();
  128. return true;
  129. }
  130. bool cmCTestSubmit::SubmitUsingSCP(const std::string& localprefix,
  131. const std::vector<std::string>& files,
  132. const std::string& remoteprefix,
  133. const std::string& url)
  134. {
  135. std::cout << "SubmitUsingSCP is not yet implemented" << std::endl;
  136. return false;
  137. }