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