forked from msys2/MINGW-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0020-Support-for-multiple-upload-files-in-Breakpad.patch
327 lines (301 loc) · 14.3 KB
/
0020-Support-for-multiple-upload-files-in-Breakpad.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
From 2b9f8e15393a39a53896f3b8b820b3a2607fb1c1 Mon Sep 17 00:00:00 2001
From: Jon TURNEY <[email protected]>
Date: Mon, 13 Oct 2014 16:26:30 +0100
Subject: [PATCH 20/24] Support for multiple upload files in Breakpad
https://bugzilla.mozilla.org/show_bug.cgi?id=1048091
Signed-off-by: Jon TURNEY <[email protected]>
---
src/client/windows/sender/crash_report_sender.cc | 4 +-
src/client/windows/sender/crash_report_sender.h | 4 +-
src/common/http_upload.cc | 15 ++++---
src/common/http_upload.h | 9 ++--
src/common/windows/http_upload.cc | 56 ++++++++++++------------
src/common/windows/http_upload.h | 14 +++---
src/tools/common/symupload/minidump_upload.cc | 6 ++-
src/tools/common/symupload/sym_upload.cc | 7 ++-
src/tools/windows/symupload/symupload.cc | 6 ++-
9 files changed, 63 insertions(+), 58 deletions(-)
diff --git a/src/client/windows/sender/crash_report_sender.cc b/src/client/windows/sender/crash_report_sender.cc
index ecf626d..70c36b0 100644
--- a/src/client/windows/sender/crash_report_sender.cc
+++ b/src/client/windows/sender/crash_report_sender.cc
@@ -59,7 +59,7 @@ CrashReportSender::CrashReportSender(const wstring &checkpoint_file)
ReportResult CrashReportSender::SendCrashReport(
const wstring &url, const map<wstring, wstring> ¶meters,
- const wstring &dump_file_name, wstring *report_code) {
+ const map<wstring, wstring> &files, wstring *report_code) {
int today = GetCurrentDate();
if (today == last_sent_date_ &&
max_reports_per_day_ != -1 &&
@@ -69,7 +69,7 @@ ReportResult CrashReportSender::SendCrashReport(
int http_response = 0;
bool result = HTTPUpload::SendRequest(
- url, parameters, dump_file_name, L"upload_file_minidump", NULL, report_code,
+ url, parameters, files, NULL, report_code,
&http_response);
if (result) {
diff --git a/src/client/windows/sender/crash_report_sender.h b/src/client/windows/sender/crash_report_sender.h
index da1ed0a..7786cc6 100644
--- a/src/client/windows/sender/crash_report_sender.h
+++ b/src/client/windows/sender/crash_report_sender.h
@@ -77,7 +77,7 @@ class CrashReportSender {
int max_reports_per_day() const { return max_reports_per_day_; }
- // Sends the specified minidump file, along with the map of
+ // Sends the specified files, along with the map of
// name value pairs, as a multipart POST request to the given URL.
// Parameter names must contain only printable ASCII characters,
// and may not contain a quote (") character.
@@ -89,7 +89,7 @@ class CrashReportSender {
// (Otherwise, report_code will be unchanged.)
ReportResult SendCrashReport(const wstring &url,
const map<wstring, wstring> ¶meters,
- const wstring &dump_file_name,
+ const map<wstring, wstring> &files,
wstring *report_code);
private:
diff --git a/src/common/http_upload.cc b/src/common/http_upload.cc
index 91fedf2..4dbbaa8 100644
--- a/src/common/http_upload.cc
+++ b/src/common/http_upload.cc
@@ -56,8 +56,7 @@ static const char kUserAgent[] = "Breakpad/1.0 (Linux)";
// static
bool HTTPUpload::SendRequest(const string &url,
const map<string, string> ¶meters,
- const string &upload_file,
- const string &file_part_name,
+ const map<string, string> &files,
const string &proxy,
const string &proxy_user_pwd,
const string &ca_certificate_file,
@@ -96,11 +95,13 @@ bool HTTPUpload::SendRequest(const string &url,
CURLFORM_COPYCONTENTS, iter->second.c_str(),
CURLFORM_END);
- // Add form file.
- curl_formadd(&formpost, &lastptr,
- CURLFORM_COPYNAME, file_part_name.c_str(),
- CURLFORM_FILE, upload_file.c_str(),
- CURLFORM_END);
+ // Add form files.
+ for (iter = files.begin(); iter != files.end(); ++iter) {
+ (*curl_formadd)(&formpost, &lastptr,
+ CURLFORM_COPYNAME, iter->first.c_str(),
+ CURLFORM_FILE, iter->second.c_str(),
+ CURLFORM_END);
+ }
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
diff --git a/src/common/http_upload.h b/src/common/http_upload.h
index 6dd36ea..4f0e452 100644
--- a/src/common/http_upload.h
+++ b/src/common/http_upload.h
@@ -45,9 +45,9 @@ using std::map;
class HTTPUpload {
public:
- // Sends the given set of parameters, along with the contents of
- // upload_file, as a multipart POST request to the given URL.
- // file_part_name contains the name of the file part of the request
+ // Sends the given sets of parameters and files as a multipart POST
+ // request to the given URL.
+ // Each key in |files| is the name of the file part of the request
// (i.e. it corresponds to the name= attribute on an <input type="file">.
// Parameter names must contain only printable ASCII characters,
// and may not contain a quote (") character.
@@ -60,8 +60,7 @@ class HTTPUpload {
// returned in error_description.
static bool SendRequest(const string &url,
const map<string, string> ¶meters,
- const string &upload_file,
- const string &file_part_name,
+ const map<string, string> &files,
const string &proxy,
const string &proxy_user_pwd,
const string &ca_certificate_file,
diff --git a/src/common/windows/http_upload.cc b/src/common/windows/http_upload.cc
index ba04d7d..7676bdc 100644
--- a/src/common/windows/http_upload.cc
+++ b/src/common/windows/http_upload.cc
@@ -64,8 +64,7 @@ class HTTPUpload::AutoInternetHandle {
// static
bool HTTPUpload::SendRequest(const wstring &url,
const map<wstring, wstring> ¶meters,
- const wstring &upload_file,
- const wstring &file_part_name,
+ const map<wstring, wstring> &files,
int *timeout,
wstring *response_body,
int *response_code) {
@@ -143,8 +142,7 @@ bool HTTPUpload::SendRequest(const wstring &url,
HTTP_ADDREQ_FLAG_ADD);
string request_body;
- if (!GenerateRequestBody(parameters, upload_file,
- file_part_name, boundary, &request_body)) {
+ if (!GenerateRequestBody(parameters, files, boundary, &request_body)) {
return false;
}
@@ -268,15 +266,9 @@ wstring HTTPUpload::GenerateRequestHeader(const wstring &boundary) {
// static
bool HTTPUpload::GenerateRequestBody(const map<wstring, wstring> ¶meters,
- const wstring &upload_file,
- const wstring &file_part_name,
+ const map<wstring, wstring> &files,
const wstring &boundary,
string *request_body) {
- vector<char> contents;
- if (!GetFileContents(upload_file, &contents)) {
- return false;
- }
-
string boundary_str = WideToUTF8(boundary);
if (boundary_str.empty()) {
return false;
@@ -293,28 +285,36 @@ bool HTTPUpload::GenerateRequestBody(const map<wstring, wstring> ¶meters,
WideToUTF8(pos->second) + "\r\n");
}
- // Now append the upload file as a binary (octet-stream) part
- string filename_utf8 = WideToUTF8(upload_file);
- if (filename_utf8.empty()) {
- return false;
- }
+ for (map<wstring, wstring>::const_iterator pos = files.begin();
+ pos != files.end(); ++pos) {
+ vector<char> contents;
+ if (!GetFileContents(pos->second, &contents)) {
+ return false;
+ }
- string file_part_name_utf8 = WideToUTF8(file_part_name);
- if (file_part_name_utf8.empty()) {
- return false;
- }
+ // Now append the upload files as a binary (octet-stream) part
+ string filename_utf8 = WideToUTF8(pos->second);
+ if (filename_utf8.empty()) {
+ return false;
+ }
+
+ string file_part_name_utf8 = WideToUTF8(pos->first);
+ if (file_part_name_utf8.empty()) {
+ return false;
+ }
- request_body->append("--" + boundary_str + "\r\n");
- request_body->append("Content-Disposition: form-data; "
- "name=\"" + file_part_name_utf8 + "\"; "
- "filename=\"" + filename_utf8 + "\"\r\n");
- request_body->append("Content-Type: application/octet-stream\r\n");
- request_body->append("\r\n");
+ request_body->append("--" + boundary_str + "\r\n");
+ request_body->append("Content-Disposition: form-data; "
+ "name=\"" + file_part_name_utf8 + "\"; "
+ "filename=\"" + filename_utf8 + "\"\r\n");
+ request_body->append("Content-Type: application/octet-stream\r\n");
+ request_body->append("\r\n");
- if (!contents.empty()) {
+ if (!contents.empty()) {
request_body->append(&(contents[0]), contents.size());
+ }
+ request_body->append("\r\n");
}
- request_body->append("\r\n");
request_body->append("--" + boundary_str + "--\r\n");
return true;
}
diff --git a/src/common/windows/http_upload.h b/src/common/windows/http_upload.h
index e485b70..f8d48cb 100644
--- a/src/common/windows/http_upload.h
+++ b/src/common/windows/http_upload.h
@@ -54,9 +54,9 @@ using std::vector;
class HTTPUpload {
public:
- // Sends the given set of parameters, along with the contents of
- // upload_file, as a multipart POST request to the given URL.
- // file_part_name contains the name of the file part of the request
+ // Sends the given sets of parameters and files as a multipart POST
+ // request to the given URL.
+ // Each key in |files| is the name of the file part of the request
// (i.e. it corresponds to the name= attribute on an <input type="file">.
// Parameter names must contain only printable ASCII characters,
// and may not contain a quote (") character.
@@ -67,8 +67,7 @@ class HTTPUpload {
// received (or 0 if the request failed before getting an HTTP response).
static bool SendRequest(const wstring &url,
const map<wstring, wstring> ¶meters,
- const wstring &upload_file,
- const wstring &file_part_name,
+ const map<wstring, wstring> &files,
int *timeout,
wstring *response_body,
int *response_code);
@@ -88,12 +87,11 @@ class HTTPUpload {
// Generates a HTTP request header for a multipart form submit.
static wstring GenerateRequestHeader(const wstring &boundary);
- // Given a set of parameters, an upload filename, and a file part name,
+ // Given a set of parameters, a set of upload files, and a file part name,
// generates a multipart request body string with these parameters
// and minidump contents. Returns true on success.
static bool GenerateRequestBody(const map<wstring, wstring> ¶meters,
- const wstring &upload_file,
- const wstring &file_part_name,
+ const map<wstring, wstring> &files,
const wstring &boundary,
string *request_body);
diff --git a/src/tools/common/symupload/minidump_upload.cc b/src/tools/common/symupload/minidump_upload.cc
index f1146ac..ed0dd5f 100644
--- a/src/tools/common/symupload/minidump_upload.cc
+++ b/src/tools/common/symupload/minidump_upload.cc
@@ -62,12 +62,14 @@ static void Start(Options *options) {
parameters["prod"] = options->product;
parameters["ver"] = options->version;
+ std::map<string, string> files;
+ files["upload_file_minidump"] = options->minidumpPath;
+
// Send it
string response, error;
bool success = HTTPUpload::SendRequest(options->uploadURLStr,
parameters,
- options->minidumpPath,
- "upload_file_minidump",
+ files,
options->proxy,
options->proxy_user_pwd,
"",
diff --git a/src/tools/common/symupload/sym_upload.cc b/src/tools/common/symupload/sym_upload.cc
index bc2693e..0246044 100644
--- a/src/tools/common/symupload/sym_upload.cc
+++ b/src/tools/common/symupload/sym_upload.cc
@@ -139,12 +139,15 @@ static void Start(Options *options) {
parameters["debug_file"] = module_parts[4];
parameters["code_file"] = module_parts[4];
parameters["debug_identifier"] = compacted_id;
+
+ std::map<string, string> files;
+ files["symbol_file"] = options->symbolsPath;
+
string response, error;
long response_code;
bool success = HTTPUpload::SendRequest(options->uploadURLStr,
parameters,
- options->symbolsPath,
- "symbol_file",
+ files,
options->proxy,
options->proxy_user_pwd,
"",
diff --git a/src/tools/windows/symupload/symupload.cc b/src/tools/windows/symupload/symupload.cc
index df4bb69..fa5294d 100644
--- a/src/tools/windows/symupload/symupload.cc
+++ b/src/tools/windows/symupload/symupload.cc
@@ -228,12 +228,14 @@ int wmain(int argc, wchar_t *argv[]) {
fwprintf(stderr, L"Warning: Could not get file version for %s\n", module);
}
+ map<wstring, wstring> files;
+ files[L"symbol_file"] = symbol_file;
+
bool success = true;
while (currentarg < argc) {
int response_code;
- if (!HTTPUpload::SendRequest(argv[currentarg], parameters,
- symbol_file, L"symbol_file",
+ if (!HTTPUpload::SendRequest(argv[currentarg], parameters, files,
timeout == -1 ? NULL : &timeout,
nullptr, &response_code)) {
success = false;
--
2.1.1