aboutsummaryrefslogtreecommitdiff
path: root/src/common/windows/http_upload.cc
diff options
context:
space:
mode:
authorincrementalist <incrementalist@4c0a9323-5329-0410-9bdc-e9ce6186880e>2006-12-08 20:45:20 +0000
committerincrementalist <incrementalist@4c0a9323-5329-0410-9bdc-e9ce6186880e>2006-12-08 20:45:20 +0000
commitdd7c38baae8c9a08d3568217d3cad6309add576d (patch)
treee089a477c4cefbbc5a670da3e4ca97b4afca6353 /src/common/windows/http_upload.cc
parentProvide a mechanism for SymbolSuppliers to interrupt processing (#93) (diff)
downloadbreakpad-dd7c38baae8c9a08d3568217d3cad6309add576d.tar.xz
This patch fixes Airbag issue #44.
Summary of this patch: * It adds a new wstring* parameter to the end of both SendCrashReport() and HTTPUpload::SendRequest(), which can be NULL. * If the request isn't successful, the result parameter isn't touched. * It adds HTTPUpload::UTF8ToWide() to allow the response to be returned as a wstring, * It changes the return value of SendRequest (and by extension, SendCrashReport) so that if the size of the response body isn't exactly the same as the value given in the Content-Length header, the return value is false (in addition to the previous semantics). * It also updates symupload.cc to account for the new parameter in SendRequest(). git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@81 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/common/windows/http_upload.cc')
-rw-r--r--src/common/windows/http_upload.cc64
1 files changed, 60 insertions, 4 deletions
diff --git a/src/common/windows/http_upload.cc b/src/common/windows/http_upload.cc
index 54e7ff85..59e541f0 100644
--- a/src/common/windows/http_upload.cc
+++ b/src/common/windows/http_upload.cc
@@ -28,8 +28,6 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assert.h>
-#include <Windows.h>
-#include <WinInet.h>
// Disable exception handler warnings.
#pragma warning( disable : 4530 )
@@ -67,7 +65,8 @@ class HTTPUpload::AutoInternetHandle {
bool HTTPUpload::SendRequest(const wstring &url,
const map<wstring, wstring> &parameters,
const wstring &upload_file,
- const wstring &file_part_name) {
+ const wstring &file_part_name,
+ wstring *response_body) {
// TODO(bryner): support non-ASCII parameter names
if (!CheckParameters(parameters)) {
return false;
@@ -154,7 +153,43 @@ bool HTTPUpload::SendRequest(const wstring &url,
return false;
}
- return (wcscmp(http_status, L"200") == 0);
+ bool result = (wcscmp(http_status, L"200") == 0);
+
+ if (result) {
+ result = ReadResponse(request.get(), response_body);
+ }
+
+ return result;
+}
+
+// static
+bool HTTPUpload::ReadResponse(HINTERNET request, wstring *response) {
+ wchar_t content_length[32];
+ DWORD content_length_size = sizeof(content_length);
+ if (!HttpQueryInfo(request, HTTP_QUERY_CONTENT_LENGTH,
+ static_cast<LPVOID>(&content_length), &content_length_size,
+ 0)) {
+ return false;
+ }
+ DWORD claimed_size = wcstol(content_length, NULL, 10);
+
+ char *response_buffer = new char[claimed_size];
+ DWORD size_read;
+ DWORD total_read = 0;
+ BOOL read_result;
+ do {
+ read_result = InternetReadFile(request, response_buffer + total_read,
+ claimed_size - total_read, &size_read);
+ total_read += size_read;
+ } while (read_result && (size_read != 0) && (total_read < claimed_size));
+
+ bool succeeded = (total_read == claimed_size);
+ if (succeeded && response) {
+ *response = UTF8ToWide(string(response_buffer, total_read));
+ }
+
+ delete[] response_buffer;
+ return succeeded;
}
// static
@@ -262,6 +297,27 @@ void HTTPUpload::GetFileContents(const wstring &filename,
}
// static
+wstring HTTPUpload::UTF8ToWide(const string &utf8) {
+ if (utf8.length() == 0) {
+ return wstring();
+ }
+
+ // compute the length of the buffer we'll need
+ int charcount = MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), -1, NULL, 0);
+
+ if (charcount == 0) {
+ return wstring();
+ }
+
+ // convert
+ wchar_t* buf = new wchar_t[charcount];
+ MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), -1, buf, charcount);
+ wstring result(buf);
+ delete[] buf;
+ return result;
+}
+
+// static
string HTTPUpload::WideToUTF8(const wstring &wide) {
if (wide.length() == 0) {
return string();