michael@0: // Copyright (c) 2006, Google Inc. michael@0: // All rights reserved. michael@0: // michael@0: // Redistribution and use in source and binary forms, with or without michael@0: // modification, are permitted provided that the following conditions are michael@0: // met: michael@0: // michael@0: // * Redistributions of source code must retain the above copyright michael@0: // notice, this list of conditions and the following disclaimer. michael@0: // * Redistributions in binary form must reproduce the above michael@0: // copyright notice, this list of conditions and the following disclaimer michael@0: // in the documentation and/or other materials provided with the michael@0: // distribution. michael@0: // * Neither the name of Google Inc. nor the names of its michael@0: // contributors may be used to endorse or promote products derived from michael@0: // this software without specific prior written permission. michael@0: // michael@0: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT michael@0: // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@0: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, michael@0: // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY michael@0: // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: michael@0: // minidump_upload.cc: Upload a minidump to a HTTP server. michael@0: // The upload is sent as a multipart/form-data POST request with michael@0: // the following parameters: michael@0: // prod: the product name michael@0: // ver: the product version michael@0: // symbol_file: the breakpad format symbol file michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: michael@0: #include "common/linux/http_upload.h" michael@0: michael@0: using google_breakpad::HTTPUpload; michael@0: michael@0: struct Options { michael@0: std::string minidumpPath; michael@0: std::string uploadURLStr; michael@0: std::string product; michael@0: std::string version; michael@0: std::string proxy; michael@0: std::string proxy_user_pwd; michael@0: bool success; michael@0: }; michael@0: michael@0: //============================================================================= michael@0: static void Start(Options *options) { michael@0: std::map parameters; michael@0: // Add parameters michael@0: parameters["prod"] = options->product; michael@0: parameters["ver"] = options->version; michael@0: michael@0: // Send it michael@0: std::string response, error; michael@0: bool success = HTTPUpload::SendRequest(options->uploadURLStr, michael@0: parameters, michael@0: options->minidumpPath, michael@0: "upload_file_minidump", michael@0: options->proxy, michael@0: options->proxy_user_pwd, michael@0: "", michael@0: &response, michael@0: NULL, michael@0: &error); michael@0: michael@0: if (success) { michael@0: printf("Successfully sent the minidump file.\n"); michael@0: } else { michael@0: printf("Failed to send minidump: %s\n", error.c_str()); michael@0: printf("Response:\n"); michael@0: printf("%s\n", response.c_str()); michael@0: } michael@0: options->success = success; michael@0: } michael@0: michael@0: //============================================================================= michael@0: static void michael@0: Usage(int argc, const char *argv[]) { michael@0: fprintf(stderr, "Submit minidump information.\n"); michael@0: fprintf(stderr, "Usage: %s [options...] -p -v " michael@0: "\n", argv[0]); michael@0: fprintf(stderr, "Options:\n"); michael@0: fprintf(stderr, " should be a minidump.\n"); michael@0: fprintf(stderr, " is the destination for the upload\n"); michael@0: michael@0: fprintf(stderr, "-p:\t Product name\n"); michael@0: fprintf(stderr, "-v:\t Product version\n"); michael@0: fprintf(stderr, "-x:\t Use HTTP proxy on given port\n"); michael@0: fprintf(stderr, "-u:\t Set proxy user and password\n"); michael@0: fprintf(stderr, "-h:\t Usage\n"); michael@0: fprintf(stderr, "-?:\t Usage\n"); michael@0: } michael@0: michael@0: //============================================================================= michael@0: static void michael@0: SetupOptions(int argc, const char *argv[], Options *options) { michael@0: extern int optind; michael@0: char ch; michael@0: michael@0: while ((ch = getopt(argc, (char * const *)argv, "p:u:v:x:h?")) != -1) { michael@0: switch (ch) { michael@0: case 'p': michael@0: options->product = optarg; michael@0: break; michael@0: case 'u': michael@0: options->proxy_user_pwd = optarg; michael@0: break; michael@0: case 'v': michael@0: options->version = optarg; michael@0: break; michael@0: case 'x': michael@0: options->proxy = optarg; michael@0: break; michael@0: michael@0: default: michael@0: Usage(argc, argv); michael@0: exit(0); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: if ((argc - optind) != 2) { michael@0: fprintf(stderr, "%s: Missing symbols file and/or upload-URL\n", argv[0]); michael@0: Usage(argc, argv); michael@0: exit(1); michael@0: } michael@0: michael@0: options->minidumpPath = argv[optind]; michael@0: options->uploadURLStr = argv[optind + 1]; michael@0: } michael@0: michael@0: //============================================================================= michael@0: int main (int argc, const char * argv[]) { michael@0: Options options; michael@0: SetupOptions(argc, argv, &options); michael@0: Start(&options); michael@0: return options.success ? 0 : 1; michael@0: }