PageRenderTime 22ms CodeModel.GetById 17ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/thirdparty/breakpad/common/linux/http_upload.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 87 lines | 28 code | 10 blank | 49 comment | 0 complexity | 05d19adc7037683c1c311fae0fadcc6a MD5 | raw file
 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// HTTPUpload provides a "nice" API to send a multipart HTTP(S) POST
31// request using libcurl.  It currently supports requests that contain
32// a set of string parameters (key/value pairs), and a file to upload.
33
34#ifndef COMMON_LINUX_HTTP_UPLOAD_H__
35#define COMMON_LINUX_HTTP_UPLOAD_H__
36
37#include <map>
38#include <string>
39
40namespace google_breakpad {
41
42using std::string;
43using std::map;
44
45class HTTPUpload {
46 public:
47  // Sends the given set of parameters, along with the contents of
48  // upload_file, as a multipart POST request to the given URL.
49  // file_part_name contains the name of the file part of the request
50  // (i.e. it corresponds to the name= attribute on an <input type="file">.
51  // Parameter names must contain only printable ASCII characters,
52  // and may not contain a quote (") character.
53  // Only HTTP(S) URLs are currently supported.  Returns true on success.
54  // If the request is successful and response_body is non-NULL,
55  // the response body will be returned in response_body.
56  // If response_code is non-NULL, it will be set to the HTTP response code
57  // received (or 0 if the request failed before getting an HTTP response).
58  // If the send fails, a description of the error will be
59  // returned in error_description.
60  static bool SendRequest(const string &url,
61                          const map<string, string> &parameters,
62                          const string &upload_file,
63                          const string &file_part_name,
64                          const string &proxy,
65                          const string &proxy_user_pwd,
66                          const string &ca_certificate_file,
67                          string *response_body,
68                          long *response_code,
69                          string *error_description);
70
71 private:
72  // Checks that the given list of parameters has only printable
73  // ASCII characters in the parameter name, and does not contain
74  // any quote (") characters.  Returns true if so.
75  static bool CheckParameters(const map<string, string> &parameters);
76
77  // No instances of this class should be created.
78  // Disallow all constructors, destructors, and operator=.
79  HTTPUpload();
80  explicit HTTPUpload(const HTTPUpload &);
81  void operator=(const HTTPUpload &);
82  ~HTTPUpload();
83};
84
85}  // namespace google_breakpad
86
87#endif  // COMMON_LINUX_HTTP_UPLOAD_H__