1
// Copyright (c) 2009, Google Inc.
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
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
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.
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.
31
#include "common/linux/google_crashdump_uploader.h"
32
#include "common/linux/libcurl_wrapper.h"
34
#include <sys/types.h>
42
namespace google_breakpad {
44
GoogleCrashdumpUploader::GoogleCrashdumpUploader(const std::string& product,
45
const std::string& version,
46
const std::string& guid,
47
const std::string& ptime,
48
const std::string& ctime,
49
const std::string& email,
50
const std::string& comments,
51
const std::string& minidump_pathname,
52
const std::string& crash_server,
53
const std::string& proxy_host,
54
const std::string& proxy_userpassword) {
55
LibcurlWrapper* http_layer = new LibcurlWrapper();
70
GoogleCrashdumpUploader::GoogleCrashdumpUploader(const std::string& product,
71
const std::string& version,
72
const std::string& guid,
73
const std::string& ptime,
74
const std::string& ctime,
75
const std::string& email,
76
const std::string& comments,
77
const std::string& minidump_pathname,
78
const std::string& crash_server,
79
const std::string& proxy_host,
80
const std::string& proxy_userpassword,
81
LibcurlWrapper* http_layer) {
96
void GoogleCrashdumpUploader::Init(const std::string& product,
97
const std::string& version,
98
const std::string& guid,
99
const std::string& ptime,
100
const std::string& ctime,
101
const std::string& email,
102
const std::string& comments,
103
const std::string& minidump_pathname,
104
const std::string& crash_server,
105
const std::string& proxy_host,
106
const std::string& proxy_userpassword,
107
LibcurlWrapper* http_layer) {
114
comments_ = comments;
115
http_layer_ = http_layer;
117
crash_server_ = crash_server;
118
proxy_host_ = proxy_host;
119
proxy_userpassword_ = proxy_userpassword;
120
minidump_pathname_ = minidump_pathname;
121
std::cout << "Uploader initializing";
122
std::cout << "\tProduct: " << product_;
123
std::cout << "\tVersion: " << version_;
124
std::cout << "\tGUID: " << guid_;
125
if (!ptime_.empty()) {
126
std::cout << "\tProcess uptime: " << ptime_;
128
if (!ctime_.empty()) {
129
std::cout << "\tCumulative Process uptime: " << ctime_;
131
if (!email_.empty()) {
132
std::cout << "\tEmail: " << email_;
134
if (!comments_.empty()) {
135
std::cout << "\tComments: " << comments_;
139
bool GoogleCrashdumpUploader::CheckRequiredParametersArePresent() {
140
std::string error_text;
141
if (product_.empty()) {
142
error_text.append("\nProduct name must be specified.");
145
if (version_.empty()) {
146
error_text.append("\nProduct version must be specified.");
150
error_text.append("\nClient ID must be specified.");
153
if (minidump_pathname_.empty()) {
154
error_text.append("\nMinidump pathname must be specified.");
157
if (!error_text.empty()) {
158
std::cout << error_text;
165
bool GoogleCrashdumpUploader::Upload() {
166
bool ok = http_layer_->Init();
168
std::cout << "http layer init failed";
172
if (!CheckRequiredParametersArePresent()) {
177
int err = stat(minidump_pathname_.c_str(), &st);
179
std::cout << minidump_pathname_ << " could not be found";
183
parameters_["prod"] = product_;
184
parameters_["ver"] = version_;
185
parameters_["guid"] = guid_;
186
parameters_["ptime"] = ptime_;
187
parameters_["ctime"] = ctime_;
188
parameters_["email"] = email_;
189
parameters_["comments_"] = comments_;
190
if (!http_layer_->AddFile(minidump_pathname_,
191
"upload_file_minidump")) {
194
std::cout << "Sending request to " << crash_server_;
195
return http_layer_->SendRequest(crash_server_,