Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | // Copyright (c) 2006, 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 | // minidump_upload.cc: Upload a minidump to a HTTP server. |
michael@0 | 31 | // The upload is sent as a multipart/form-data POST request with |
michael@0 | 32 | // the following parameters: |
michael@0 | 33 | // prod: the product name |
michael@0 | 34 | // ver: the product version |
michael@0 | 35 | // symbol_file: the breakpad format symbol file |
michael@0 | 36 | |
michael@0 | 37 | #include <stdio.h> |
michael@0 | 38 | #include <stdlib.h> |
michael@0 | 39 | #include <unistd.h> |
michael@0 | 40 | |
michael@0 | 41 | #include <string> |
michael@0 | 42 | |
michael@0 | 43 | #include "common/linux/http_upload.h" |
michael@0 | 44 | |
michael@0 | 45 | using google_breakpad::HTTPUpload; |
michael@0 | 46 | |
michael@0 | 47 | struct Options { |
michael@0 | 48 | std::string minidumpPath; |
michael@0 | 49 | std::string uploadURLStr; |
michael@0 | 50 | std::string product; |
michael@0 | 51 | std::string version; |
michael@0 | 52 | std::string proxy; |
michael@0 | 53 | std::string proxy_user_pwd; |
michael@0 | 54 | bool success; |
michael@0 | 55 | }; |
michael@0 | 56 | |
michael@0 | 57 | //============================================================================= |
michael@0 | 58 | static void Start(Options *options) { |
michael@0 | 59 | std::map<std::string, std::string> parameters; |
michael@0 | 60 | // Add parameters |
michael@0 | 61 | parameters["prod"] = options->product; |
michael@0 | 62 | parameters["ver"] = options->version; |
michael@0 | 63 | |
michael@0 | 64 | // Send it |
michael@0 | 65 | std::string response, error; |
michael@0 | 66 | bool success = HTTPUpload::SendRequest(options->uploadURLStr, |
michael@0 | 67 | parameters, |
michael@0 | 68 | options->minidumpPath, |
michael@0 | 69 | "upload_file_minidump", |
michael@0 | 70 | options->proxy, |
michael@0 | 71 | options->proxy_user_pwd, |
michael@0 | 72 | "", |
michael@0 | 73 | &response, |
michael@0 | 74 | NULL, |
michael@0 | 75 | &error); |
michael@0 | 76 | |
michael@0 | 77 | if (success) { |
michael@0 | 78 | printf("Successfully sent the minidump file.\n"); |
michael@0 | 79 | } else { |
michael@0 | 80 | printf("Failed to send minidump: %s\n", error.c_str()); |
michael@0 | 81 | printf("Response:\n"); |
michael@0 | 82 | printf("%s\n", response.c_str()); |
michael@0 | 83 | } |
michael@0 | 84 | options->success = success; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | //============================================================================= |
michael@0 | 88 | static void |
michael@0 | 89 | Usage(int argc, const char *argv[]) { |
michael@0 | 90 | fprintf(stderr, "Submit minidump information.\n"); |
michael@0 | 91 | fprintf(stderr, "Usage: %s [options...] -p <product> -v <version> <minidump> " |
michael@0 | 92 | "<upload-URL>\n", argv[0]); |
michael@0 | 93 | fprintf(stderr, "Options:\n"); |
michael@0 | 94 | fprintf(stderr, "<minidump> should be a minidump.\n"); |
michael@0 | 95 | fprintf(stderr, "<upload-URL> is the destination for the upload\n"); |
michael@0 | 96 | |
michael@0 | 97 | fprintf(stderr, "-p:\t <product> Product name\n"); |
michael@0 | 98 | fprintf(stderr, "-v:\t <version> Product version\n"); |
michael@0 | 99 | fprintf(stderr, "-x:\t <host[:port]> Use HTTP proxy on given port\n"); |
michael@0 | 100 | fprintf(stderr, "-u:\t <user[:password]> Set proxy user and password\n"); |
michael@0 | 101 | fprintf(stderr, "-h:\t Usage\n"); |
michael@0 | 102 | fprintf(stderr, "-?:\t Usage\n"); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | //============================================================================= |
michael@0 | 106 | static void |
michael@0 | 107 | SetupOptions(int argc, const char *argv[], Options *options) { |
michael@0 | 108 | extern int optind; |
michael@0 | 109 | char ch; |
michael@0 | 110 | |
michael@0 | 111 | while ((ch = getopt(argc, (char * const *)argv, "p:u:v:x:h?")) != -1) { |
michael@0 | 112 | switch (ch) { |
michael@0 | 113 | case 'p': |
michael@0 | 114 | options->product = optarg; |
michael@0 | 115 | break; |
michael@0 | 116 | case 'u': |
michael@0 | 117 | options->proxy_user_pwd = optarg; |
michael@0 | 118 | break; |
michael@0 | 119 | case 'v': |
michael@0 | 120 | options->version = optarg; |
michael@0 | 121 | break; |
michael@0 | 122 | case 'x': |
michael@0 | 123 | options->proxy = optarg; |
michael@0 | 124 | break; |
michael@0 | 125 | |
michael@0 | 126 | default: |
michael@0 | 127 | Usage(argc, argv); |
michael@0 | 128 | exit(0); |
michael@0 | 129 | break; |
michael@0 | 130 | } |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | if ((argc - optind) != 2) { |
michael@0 | 134 | fprintf(stderr, "%s: Missing symbols file and/or upload-URL\n", argv[0]); |
michael@0 | 135 | Usage(argc, argv); |
michael@0 | 136 | exit(1); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | options->minidumpPath = argv[optind]; |
michael@0 | 140 | options->uploadURLStr = argv[optind + 1]; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | //============================================================================= |
michael@0 | 144 | int main (int argc, const char * argv[]) { |
michael@0 | 145 | Options options; |
michael@0 | 146 | SetupOptions(argc, argv, &options); |
michael@0 | 147 | Start(&options); |
michael@0 | 148 | return options.success ? 0 : 1; |
michael@0 | 149 | } |