Sync DrDump crash handler with TortoiseSVN codebase
[TortoiseGit.git] / ext / CrashServer / CrashHandler / SendRpt / DoctorDump.h
bloba84d51d725a6de0f50b72efbbd05e91947daa975
1 // Copyright 2014 Idol Software, Inc.
2 //
3 // This file is part of Doctor Dump SDK.
4 //
5 // Doctor Dump SDK is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #pragma once
20 #include <exception>
21 #include <functional>
22 #include "..\..\CommonLibs\Log\log.h"
23 #include "..\DumpUploaderServiceLib\DumpUploaderWebService.h"
24 #include "DumpUploader.h"
26 struct soap;
28 namespace soap_helpers
30 template <typename S>
31 class SoapStuct
33 std::function<S* (soap*, int)> m_create;
34 std::function<void (soap*, S*)> m_deleter;
35 S* m_s;
36 soap* m_webService;
37 SoapStuct(const SoapStuct&);
38 SoapStuct(const SoapStuct&& other);
39 public:
40 SoapStuct(soap* webService,
41 std::function<S* (soap*, int)> create,
42 std::function<void (soap*, S*)> deleter)
43 : m_webService(webService)
44 , m_create(create)
45 , m_deleter(deleter)
47 m_s = m_create(m_webService, 1);
49 ~SoapStuct()
51 if (m_s)
52 m_deleter(m_webService, m_s);
55 operator S*() { return m_s; }
56 S* operator->() { return m_s; }
57 S* get() { return m_s; }
59 std::shared_ptr<void> m_data;
61 #define SOAP_STRUCT(Str, Var) soap_helpers::SoapStuct<Str> Var(&m_webService, soap_new_##Str, soap_delete_##Str)
62 #define SOAP_SHARED_STRUCT(Str, Var) std::shared_ptr<soap_helpers::SoapStuct<Str>> Var(new soap_helpers::SoapStuct<Str>(&m_webService, soap_new_##Str, soap_delete_##Str))
65 namespace doctor_dump
67 struct DumpAdditionalInfo
69 time_t crashDate;
70 int PCID;
71 int submitterID;
72 std::wstring group;
73 std::wstring description;
76 struct Response
78 std::wstring clientID;
79 int problemID;
80 int dumpGroupID;
81 int dumpID;
82 std::wstring urlToProblem;
83 std::vector<BYTE> context;
85 enum ResponseType {
86 HaveSolutionResponseType,
87 NeedMiniDumpResponseType,
88 NeedFullDumpResponseType,
89 NeedMoreInfoResponseType,
90 StopResponseType,
91 ErrorResponseType,
94 virtual ResponseType GetResponseType() const = 0;
96 static std::unique_ptr<Response> CreateResponse(const ns1__Response& response, Log& log);
99 struct HaveSolutionResponse: public Response
101 bool askConfirmation;
102 ns4__HaveSolutionResponse_SolutionType type;
103 std::wstring url;
104 std::vector<BYTE> exe;
105 ResponseType GetResponseType() const override { return HaveSolutionResponseType; }
108 struct NeedMiniDumpResponse: public Response
110 ResponseType GetResponseType() const override { return NeedMiniDumpResponseType; }
113 struct NeedFullDumpResponse: public Response
115 DWORD restrictedDumpType;
116 bool attachUserInfo;
117 ResponseType GetResponseType() const override { return NeedFullDumpResponseType; }
120 struct NeedMoreInfoResponse: public Response
122 std::vector<BYTE> infoModule;
123 std::wstring infoModuleCfg;
124 ResponseType GetResponseType() const override { return NeedMoreInfoResponseType; }
127 struct StopResponse: public Response
129 ResponseType GetResponseType() const override { return StopResponseType; }
132 struct ErrorResponse: public Response
134 std::wstring error;
135 ResponseType GetResponseType() const override { return ErrorResponseType; }
138 struct IUploadProgress
140 virtual void OnProgress(SIZE_T total, SIZE_T sent) = 0;
143 class SoapException: public std::runtime_error
145 public:
146 explicit SoapException(int soapError, const std::string& message) : m_soapError(soapError), std::runtime_error(message) {}
147 explicit SoapException(int soapError, const char* message) : m_soapError(soapError), std::runtime_error(message) {}
148 int m_soapError;
149 bool IsNetworkProblem() const { return m_soapError == SOAP_TCP_ERROR; }
152 class DumpUploaderWebServiceEx
154 public:
155 DumpUploaderWebServiceEx(Log& log_);
157 std::unique_ptr<Response> Hello(const Application& app, std::wstring appName, std::wstring companyName,const DumpAdditionalInfo& addInfo);
158 std::unique_ptr<Response> UploadMiniDump(const std::vector<BYTE>& context, const Application& app, const DumpAdditionalInfo& addInfo, const std::wstring& dumpFile);
159 std::unique_ptr<Response> UploadFullDump(const std::vector<BYTE>& context, const Application& app, int miniDumpId, const std::wstring& fullDumpZipPath, IUploadProgress* uploadProgress);
160 std::unique_ptr<Response> UploadAdditionalInfo(const std::vector<BYTE>& context, const Application& app, int miniDumpId, const std::wstring& addInfoFile, IUploadProgress* uploadProgress);
161 std::unique_ptr<Response> RejectedToSendAdditionalInfo(const std::vector<BYTE>& context, const Application& app, int miniDumpId);
163 private:
164 Log& m_log;
165 DumpUploaderWebService m_webService;
167 typedef std::vector<std::shared_ptr<void>> DeferredDelete;
168 _xop__Include* CreateXopInclude(DeferredDelete& context, const std::vector<BYTE>& data);
169 _xop__Include* CreateXopIncludeFromFile(DeferredDelete& context, const std::wstring& path);
170 ns1__ClientLib* CreateClientLib(DeferredDelete& context);
171 ns1__Application* CreateApp(DeferredDelete& context, const Application& appsrc);
172 ns1__AppAdditionalInfo* CreateAppAddInfo(DeferredDelete& context, std::wstring& appName, std::wstring& companyName);
173 ns1__DumpAdditionalInfo* CreateDumpAddInfo(DeferredDelete& context, const DumpAdditionalInfo &addInfo);
174 void ThrowOnSoapFail(int res);
175 static std::vector<unsigned char> ReadFile(const std::wstring& path);