~ubuntu-branches/ubuntu/karmic/gears/karmic

« back to all changes in this revision

Viewing changes to third_party/breakpad/src/tools/linux/symupload/minidump_upload.cc

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2009-04-30 19:15:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090430191525-0790sb5wzg8ou0xb
Tags: upstream-0.5.21.0~svn3334+dfsg
ImportĀ upstreamĀ versionĀ 0.5.21.0~svn3334+dfsg

Show diffs side-by-side

added added

removed removed

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