1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/linux/google_crashdump_uploader.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,199 @@ 1.4 +// Copyright (c) 2009, Google Inc. 1.5 +// All rights reserved. 1.6 +// 1.7 +// Redistribution and use in source and binary forms, with or without 1.8 +// modification, are permitted provided that the following conditions are 1.9 +// met: 1.10 +// 1.11 +// * Redistributions of source code must retain the above copyright 1.12 +// notice, this list of conditions and the following disclaimer. 1.13 +// * Redistributions in binary form must reproduce the above 1.14 +// copyright notice, this list of conditions and the following disclaimer 1.15 +// in the documentation and/or other materials provided with the 1.16 +// distribution. 1.17 +// * Neither the name of Google Inc. nor the names of its 1.18 +// contributors may be used to endorse or promote products derived from 1.19 +// this software without specific prior written permission. 1.20 +// 1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.32 + 1.33 + 1.34 +#include "common/linux/google_crashdump_uploader.h" 1.35 +#include "common/linux/libcurl_wrapper.h" 1.36 + 1.37 +#include <sys/types.h> 1.38 +#include <sys/stat.h> 1.39 +#include <unistd.h> 1.40 + 1.41 +#include <iostream> 1.42 + 1.43 +#include "common/using_std_string.h" 1.44 + 1.45 +namespace google_breakpad { 1.46 + 1.47 +GoogleCrashdumpUploader::GoogleCrashdumpUploader(const string& product, 1.48 + const string& version, 1.49 + const string& guid, 1.50 + const string& ptime, 1.51 + const string& ctime, 1.52 + const string& email, 1.53 + const string& comments, 1.54 + const string& minidump_pathname, 1.55 + const string& crash_server, 1.56 + const string& proxy_host, 1.57 + const string& proxy_userpassword) { 1.58 + LibcurlWrapper* http_layer = new LibcurlWrapper(); 1.59 + Init(product, 1.60 + version, 1.61 + guid, 1.62 + ptime, 1.63 + ctime, 1.64 + email, 1.65 + comments, 1.66 + minidump_pathname, 1.67 + crash_server, 1.68 + proxy_host, 1.69 + proxy_userpassword, 1.70 + http_layer); 1.71 +} 1.72 + 1.73 +GoogleCrashdumpUploader::GoogleCrashdumpUploader(const string& product, 1.74 + const string& version, 1.75 + const string& guid, 1.76 + const string& ptime, 1.77 + const string& ctime, 1.78 + const string& email, 1.79 + const string& comments, 1.80 + const string& minidump_pathname, 1.81 + const string& crash_server, 1.82 + const string& proxy_host, 1.83 + const string& proxy_userpassword, 1.84 + LibcurlWrapper* http_layer) { 1.85 + Init(product, 1.86 + version, 1.87 + guid, 1.88 + ptime, 1.89 + ctime, 1.90 + email, 1.91 + comments, 1.92 + minidump_pathname, 1.93 + crash_server, 1.94 + proxy_host, 1.95 + proxy_userpassword, 1.96 + http_layer); 1.97 +} 1.98 + 1.99 +void GoogleCrashdumpUploader::Init(const string& product, 1.100 + const string& version, 1.101 + const string& guid, 1.102 + const string& ptime, 1.103 + const string& ctime, 1.104 + const string& email, 1.105 + const string& comments, 1.106 + const string& minidump_pathname, 1.107 + const string& crash_server, 1.108 + const string& proxy_host, 1.109 + const string& proxy_userpassword, 1.110 + LibcurlWrapper* http_layer) { 1.111 + product_ = product; 1.112 + version_ = version; 1.113 + guid_ = guid; 1.114 + ptime_ = ptime; 1.115 + ctime_ = ctime; 1.116 + email_ = email; 1.117 + comments_ = comments; 1.118 + http_layer_ = http_layer; 1.119 + 1.120 + crash_server_ = crash_server; 1.121 + proxy_host_ = proxy_host; 1.122 + proxy_userpassword_ = proxy_userpassword; 1.123 + minidump_pathname_ = minidump_pathname; 1.124 + std::cout << "Uploader initializing"; 1.125 + std::cout << "\tProduct: " << product_; 1.126 + std::cout << "\tVersion: " << version_; 1.127 + std::cout << "\tGUID: " << guid_; 1.128 + if (!ptime_.empty()) { 1.129 + std::cout << "\tProcess uptime: " << ptime_; 1.130 + } 1.131 + if (!ctime_.empty()) { 1.132 + std::cout << "\tCumulative Process uptime: " << ctime_; 1.133 + } 1.134 + if (!email_.empty()) { 1.135 + std::cout << "\tEmail: " << email_; 1.136 + } 1.137 + if (!comments_.empty()) { 1.138 + std::cout << "\tComments: " << comments_; 1.139 + } 1.140 +} 1.141 + 1.142 +bool GoogleCrashdumpUploader::CheckRequiredParametersArePresent() { 1.143 + string error_text; 1.144 + if (product_.empty()) { 1.145 + error_text.append("\nProduct name must be specified."); 1.146 + } 1.147 + 1.148 + if (version_.empty()) { 1.149 + error_text.append("\nProduct version must be specified."); 1.150 + } 1.151 + 1.152 + if (guid_.empty()) { 1.153 + error_text.append("\nClient ID must be specified."); 1.154 + } 1.155 + 1.156 + if (minidump_pathname_.empty()) { 1.157 + error_text.append("\nMinidump pathname must be specified."); 1.158 + } 1.159 + 1.160 + if (!error_text.empty()) { 1.161 + std::cout << error_text; 1.162 + return false; 1.163 + } 1.164 + return true; 1.165 + 1.166 +} 1.167 + 1.168 +bool GoogleCrashdumpUploader::Upload() { 1.169 + bool ok = http_layer_->Init(); 1.170 + if (!ok) { 1.171 + std::cout << "http layer init failed"; 1.172 + return ok; 1.173 + } 1.174 + 1.175 + if (!CheckRequiredParametersArePresent()) { 1.176 + return false; 1.177 + } 1.178 + 1.179 + struct stat st; 1.180 + int err = stat(minidump_pathname_.c_str(), &st); 1.181 + if (err) { 1.182 + std::cout << minidump_pathname_ << " could not be found"; 1.183 + return false; 1.184 + } 1.185 + 1.186 + parameters_["prod"] = product_; 1.187 + parameters_["ver"] = version_; 1.188 + parameters_["guid"] = guid_; 1.189 + parameters_["ptime"] = ptime_; 1.190 + parameters_["ctime"] = ctime_; 1.191 + parameters_["email"] = email_; 1.192 + parameters_["comments_"] = comments_; 1.193 + if (!http_layer_->AddFile(minidump_pathname_, 1.194 + "upload_file_minidump")) { 1.195 + return false; 1.196 + } 1.197 + std::cout << "Sending request to " << crash_server_; 1.198 + return http_layer_->SendRequest(crash_server_, 1.199 + parameters_, 1.200 + NULL); 1.201 +} 1.202 +}