/thirdparty/breakpad/client/windows/sender/crash_report_sender.h

http://github.com/tomahawk-player/tomahawk · C++ Header · 125 lines · 42 code · 20 blank · 63 comment · 0 complexity · afcdf05997bccf83747e5c0b366874ba 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. #ifndef CLIENT_WINDOWS_SENDER_CRASH_REPORT_SENDER_H__
  30. #define CLIENT_WINDOWS_SENDER_CRASH_REPORT_SENDER_H__
  31. // CrashReportSender is a "static" class which provides an API to upload
  32. // crash reports via HTTP(S). A crash report is formatted as a multipart POST
  33. // request, which contains a set of caller-supplied string key/value pairs,
  34. // and a minidump file to upload.
  35. //
  36. // To use this library in your project, you will need to link against
  37. // wininet.lib.
  38. #pragma warning( push )
  39. // Disable exception handler warnings.
  40. #pragma warning( disable : 4530 )
  41. #include <map>
  42. #include <string>
  43. namespace google_breakpad {
  44. using std::wstring;
  45. using std::map;
  46. typedef enum {
  47. RESULT_FAILED = 0, // Failed to communicate with the server; try later.
  48. RESULT_REJECTED, // Successfully sent the crash report, but the
  49. // server rejected it; don't resend this report.
  50. RESULT_SUCCEEDED, // The server accepted the crash report.
  51. RESULT_THROTTLED // No attempt was made to send the crash report, because
  52. // we exceeded the maximum reports per day.
  53. } ReportResult;
  54. class CrashReportSender {
  55. public:
  56. // Initializes a CrashReportSender instance.
  57. // If checkpoint_file is non-empty, breakpad will persist crash report
  58. // state to this file. A checkpoint file is required for
  59. // set_max_reports_per_day() to function properly.
  60. explicit CrashReportSender(const wstring &checkpoint_file);
  61. ~CrashReportSender() {}
  62. // Sets the maximum number of crash reports that will be sent in a 24-hour
  63. // period. This uses the state persisted to the checkpoint file.
  64. // The default value of -1 means that there is no limit on reports sent.
  65. void set_max_reports_per_day(int reports) {
  66. max_reports_per_day_ = reports;
  67. }
  68. int max_reports_per_day() const { return max_reports_per_day_; }
  69. // Sends the specified minidump file, along with the map of
  70. // name value pairs, as a multipart POST request to the given URL.
  71. // Parameter names must contain only printable ASCII characters,
  72. // and may not contain a quote (") character.
  73. // Only HTTP(S) URLs are currently supported. The return value indicates
  74. // the result of the operation (see above for possible results).
  75. // If report_code is non-NULL and the report is sent successfully (that is,
  76. // the return value is RESULT_SUCCEEDED), a code uniquely identifying the
  77. // report will be returned in report_code.
  78. // (Otherwise, report_code will be unchanged.)
  79. ReportResult SendCrashReport(const wstring &url,
  80. const map<wstring, wstring> &parameters,
  81. const wstring &dump_file_name,
  82. wstring *report_code);
  83. private:
  84. // Reads persistent state from a checkpoint file.
  85. void ReadCheckpoint(FILE *fd);
  86. // Called when a new report has been sent, to update the checkpoint state.
  87. void ReportSent(int today);
  88. // Returns today's date (UTC) formatted as YYYYMMDD.
  89. int GetCurrentDate() const;
  90. // Opens the checkpoint file with the specified mode.
  91. // Returns zero on success, or an error code on failure.
  92. int OpenCheckpointFile(const wchar_t *mode, FILE **fd);
  93. wstring checkpoint_file_;
  94. int max_reports_per_day_;
  95. // The last date on which we sent a report, expressed as YYYYMMDD.
  96. int last_sent_date_;
  97. // Number of reports sent on last_sent_date_
  98. int reports_sent_;
  99. // Disallow copy constructor and operator=
  100. explicit CrashReportSender(const CrashReportSender &);
  101. void operator=(const CrashReportSender &);
  102. };
  103. } // namespace google_breakpad
  104. #pragma warning( pop )
  105. #endif // CLIENT_WINDOWS_SENDER_CRASH_REPORT_SENDER_H__