/thirdparty/breakpad/common/linux/google_crashdump_uploader.cc

http://github.com/tomahawk-player/tomahawk · C++ · 199 lines · 151 code · 20 blank · 28 comment · 13 complexity · 364e7696ae3096e864878064a2db4788 MD5 · raw file

  1. // Copyright (c) 2009, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. #include "common/linux/google_crashdump_uploader.h"
  30. #include "common/linux/libcurl_wrapper.h"
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33. #include <unistd.h>
  34. #include <iostream>
  35. using std::string;
  36. namespace google_breakpad {
  37. GoogleCrashdumpUploader::GoogleCrashdumpUploader(const std::string& product,
  38. const std::string& version,
  39. const std::string& guid,
  40. const std::string& ptime,
  41. const std::string& ctime,
  42. const std::string& email,
  43. const std::string& comments,
  44. const std::string& minidump_pathname,
  45. const std::string& crash_server,
  46. const std::string& proxy_host,
  47. const std::string& proxy_userpassword) {
  48. LibcurlWrapper* http_layer = new LibcurlWrapper();
  49. Init(product,
  50. version,
  51. guid,
  52. ptime,
  53. ctime,
  54. email,
  55. comments,
  56. minidump_pathname,
  57. crash_server,
  58. proxy_host,
  59. proxy_userpassword,
  60. http_layer);
  61. }
  62. GoogleCrashdumpUploader::GoogleCrashdumpUploader(const std::string& product,
  63. const std::string& version,
  64. const std::string& guid,
  65. const std::string& ptime,
  66. const std::string& ctime,
  67. const std::string& email,
  68. const std::string& comments,
  69. const std::string& minidump_pathname,
  70. const std::string& crash_server,
  71. const std::string& proxy_host,
  72. const std::string& proxy_userpassword,
  73. LibcurlWrapper* http_layer) {
  74. Init(product,
  75. version,
  76. guid,
  77. ptime,
  78. ctime,
  79. email,
  80. comments,
  81. minidump_pathname,
  82. crash_server,
  83. proxy_host,
  84. proxy_userpassword,
  85. http_layer);
  86. }
  87. void GoogleCrashdumpUploader::Init(const std::string& product,
  88. const std::string& version,
  89. const std::string& guid,
  90. const std::string& ptime,
  91. const std::string& ctime,
  92. const std::string& email,
  93. const std::string& comments,
  94. const std::string& minidump_pathname,
  95. const std::string& crash_server,
  96. const std::string& proxy_host,
  97. const std::string& proxy_userpassword,
  98. LibcurlWrapper* http_layer) {
  99. product_ = product;
  100. version_ = version;
  101. guid_ = guid;
  102. ptime_ = ptime;
  103. ctime_ = ctime;
  104. email_ = email;
  105. comments_ = comments;
  106. http_layer_ = http_layer;
  107. crash_server_ = crash_server;
  108. proxy_host_ = proxy_host;
  109. proxy_userpassword_ = proxy_userpassword;
  110. minidump_pathname_ = minidump_pathname;
  111. std::cout << "Uploader initializing";
  112. std::cout << "\tProduct: " << product_;
  113. std::cout << "\tVersion: " << version_;
  114. std::cout << "\tGUID: " << guid_;
  115. if (!ptime_.empty()) {
  116. std::cout << "\tProcess uptime: " << ptime_;
  117. }
  118. if (!ctime_.empty()) {
  119. std::cout << "\tCumulative Process uptime: " << ctime_;
  120. }
  121. if (!email_.empty()) {
  122. std::cout << "\tEmail: " << email_;
  123. }
  124. if (!comments_.empty()) {
  125. std::cout << "\tComments: " << comments_;
  126. }
  127. }
  128. bool GoogleCrashdumpUploader::CheckRequiredParametersArePresent() {
  129. std::string error_text;
  130. if (product_.empty()) {
  131. error_text.append("\nProduct name must be specified.");
  132. }
  133. if (version_.empty()) {
  134. error_text.append("\nProduct version must be specified.");
  135. }
  136. if (guid_.empty()) {
  137. error_text.append("\nClient ID must be specified.");
  138. }
  139. if (minidump_pathname_.empty()) {
  140. error_text.append("\nMinidump pathname must be specified.");
  141. }
  142. if (!error_text.empty()) {
  143. std::cout << error_text;
  144. return false;
  145. }
  146. return true;
  147. }
  148. bool GoogleCrashdumpUploader::Upload() {
  149. bool ok = http_layer_->Init();
  150. if (!ok) {
  151. std::cout << "http layer init failed";
  152. return ok;
  153. }
  154. if (!CheckRequiredParametersArePresent()) {
  155. return false;
  156. }
  157. struct stat st;
  158. int err = stat(minidump_pathname_.c_str(), &st);
  159. if (err) {
  160. std::cout << minidump_pathname_ << " could not be found";
  161. return false;
  162. }
  163. parameters_["prod"] = product_;
  164. parameters_["ver"] = version_;
  165. parameters_["guid"] = guid_;
  166. parameters_["ptime"] = ptime_;
  167. parameters_["ctime"] = ctime_;
  168. parameters_["email"] = email_;
  169. parameters_["comments_"] = comments_;
  170. if (!http_layer_->AddFile(minidump_pathname_,
  171. "upload_file_minidump")) {
  172. return false;
  173. }
  174. std::cout << "Sending request to " << crash_server_;
  175. return http_layer_->SendRequest(crash_server_,
  176. parameters_,
  177. NULL);
  178. }
  179. }