aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/linux/http_upload.cc15
-rw-r--r--src/common/linux/http_upload.h9
-rw-r--r--src/common/windows/http_upload.cc56
-rw-r--r--src/common/windows/http_upload.h14
4 files changed, 46 insertions, 48 deletions
diff --git a/src/common/linux/http_upload.cc b/src/common/linux/http_upload.cc
index d49f2276..4492fe84 100644
--- a/src/common/linux/http_upload.cc
+++ b/src/common/linux/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> &parameters,
- 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,
@@ -135,11 +134,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/linux/http_upload.h b/src/common/linux/http_upload.h
index 6dd36ea0..4f0e452f 100644
--- a/src/common/linux/http_upload.h
+++ b/src/common/linux/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> &parameters,
- 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 ba04d7d0..7676bdc5 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> &parameters,
- 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> &parameters,
- 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> &parameters,
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 e485b70e..f8d48cb1 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> &parameters,
- 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> &parameters,
- const wstring &upload_file,
- const wstring &file_part_name,
+ const map<wstring, wstring> &files,
const wstring &boundary,
string *request_body);