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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/tools/linux/symupload/minidump_upload.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,149 @@
     1.4 +// Copyright (c) 2006, 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 +// minidump_upload.cc: Upload a minidump to a HTTP server.
    1.34 +// The upload is sent as a multipart/form-data POST request with
    1.35 +// the following parameters:
    1.36 +//  prod: the product name
    1.37 +//  ver: the product version
    1.38 +//  symbol_file: the breakpad format symbol file
    1.39 +
    1.40 +#include <stdio.h>
    1.41 +#include <stdlib.h>
    1.42 +#include <unistd.h>
    1.43 +
    1.44 +#include <string>
    1.45 +
    1.46 +#include "common/linux/http_upload.h"
    1.47 +
    1.48 +using google_breakpad::HTTPUpload;
    1.49 +
    1.50 +struct Options {
    1.51 +  std::string minidumpPath;
    1.52 +  std::string uploadURLStr;
    1.53 +  std::string product;
    1.54 +  std::string version;
    1.55 +  std::string proxy;
    1.56 +  std::string proxy_user_pwd;
    1.57 +  bool success;
    1.58 +};
    1.59 +
    1.60 +//=============================================================================
    1.61 +static void Start(Options *options) {
    1.62 +  std::map<std::string, std::string> parameters;
    1.63 +  // Add parameters
    1.64 +  parameters["prod"] = options->product;
    1.65 +  parameters["ver"] = options->version;
    1.66 +
    1.67 +  // Send it
    1.68 +  std::string response, error;
    1.69 +  bool success = HTTPUpload::SendRequest(options->uploadURLStr,
    1.70 +                                         parameters,
    1.71 +                                         options->minidumpPath,
    1.72 +                                         "upload_file_minidump",
    1.73 +                                         options->proxy,
    1.74 +                                         options->proxy_user_pwd,
    1.75 +                                         "",
    1.76 +                                         &response,
    1.77 +                                         NULL,
    1.78 +                                         &error);
    1.79 +
    1.80 +  if (success) {
    1.81 +    printf("Successfully sent the minidump file.\n");
    1.82 +  } else {
    1.83 +    printf("Failed to send minidump: %s\n", error.c_str());
    1.84 +    printf("Response:\n");
    1.85 +    printf("%s\n", response.c_str());
    1.86 +  }
    1.87 +  options->success = success;
    1.88 +}
    1.89 +
    1.90 +//=============================================================================
    1.91 +static void
    1.92 +Usage(int argc, const char *argv[]) {
    1.93 +  fprintf(stderr, "Submit minidump information.\n");
    1.94 +  fprintf(stderr, "Usage: %s [options...] -p <product> -v <version> <minidump> "
    1.95 +          "<upload-URL>\n", argv[0]);
    1.96 +  fprintf(stderr, "Options:\n");
    1.97 +  fprintf(stderr, "<minidump> should be a minidump.\n");
    1.98 +  fprintf(stderr, "<upload-URL> is the destination for the upload\n");
    1.99 +
   1.100 +  fprintf(stderr, "-p:\t <product> Product name\n");
   1.101 +  fprintf(stderr, "-v:\t <version> Product version\n");
   1.102 +  fprintf(stderr, "-x:\t <host[:port]> Use HTTP proxy on given port\n");
   1.103 +  fprintf(stderr, "-u:\t <user[:password]> Set proxy user and password\n");
   1.104 +  fprintf(stderr, "-h:\t Usage\n");
   1.105 +  fprintf(stderr, "-?:\t Usage\n");
   1.106 +}
   1.107 +
   1.108 +//=============================================================================
   1.109 +static void
   1.110 +SetupOptions(int argc, const char *argv[], Options *options) {
   1.111 +  extern int optind;
   1.112 +  char ch;
   1.113 +
   1.114 +  while ((ch = getopt(argc, (char * const *)argv, "p:u:v:x:h?")) != -1) {
   1.115 +    switch (ch) {
   1.116 +      case 'p':
   1.117 +        options->product = optarg;
   1.118 +        break;
   1.119 +      case 'u':
   1.120 +        options->proxy_user_pwd = optarg;
   1.121 +        break;
   1.122 +      case 'v':
   1.123 +        options->version = optarg;
   1.124 +        break;
   1.125 +      case 'x':
   1.126 +        options->proxy = optarg;
   1.127 +        break;
   1.128 +
   1.129 +      default:
   1.130 +        Usage(argc, argv);
   1.131 +        exit(0);
   1.132 +        break;
   1.133 +    }
   1.134 +  }
   1.135 +
   1.136 +  if ((argc - optind) != 2) {
   1.137 +    fprintf(stderr, "%s: Missing symbols file and/or upload-URL\n", argv[0]);
   1.138 +    Usage(argc, argv);
   1.139 +    exit(1);
   1.140 +  }
   1.141 +
   1.142 +  options->minidumpPath = argv[optind];
   1.143 +  options->uploadURLStr = argv[optind + 1];
   1.144 +}
   1.145 +
   1.146 +//=============================================================================
   1.147 +int main (int argc, const char * argv[]) {
   1.148 +  Options options;
   1.149 +  SetupOptions(argc, argv, &options);
   1.150 +  Start(&options);
   1.151 +  return options.success ? 0 : 1;
   1.152 +}

mercurial