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