toolkit/crashreporter/google-breakpad/src/tools/linux/symupload/minidump_upload.cc

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial