OLD | NEW |
| (Empty) |
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 | |
40 namespace google_breakpad { | |
41 | |
42 using std::string; | |
43 using std::map; | |
44 | |
45 class 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 the send fails, a description of the error will be | |
57 // returned in error_description. | |
58 static bool SendRequest(const string &url, | |
59 const map<string, string> ¶meters, | |
60 const string &upload_file, | |
61 const string &file_part_name, | |
62 const string &proxy, | |
63 const string &proxy_user_pwd, | |
64 string *response_body, | |
65 string *error_description); | |
66 | |
67 private: | |
68 // Checks that the given list of parameters has only printable | |
69 // ASCII characters in the parameter name, and does not contain | |
70 // any quote (") characters. Returns true if so. | |
71 static bool CheckParameters(const map<string, string> ¶meters); | |
72 | |
73 // No instances of this class should be created. | |
74 // Disallow all constructors, destructors, and operator=. | |
75 HTTPUpload(); | |
76 explicit HTTPUpload(const HTTPUpload &); | |
77 void operator=(const HTTPUpload &); | |
78 ~HTTPUpload(); | |
79 }; | |
80 | |
81 } // namespace google_breakpad | |
82 | |
83 #endif // COMMON_LINUX_HTTP_UPLOAD_H__ | |
OLD | NEW |