Revert revision 658 ('Add glog style logging to symupload').

R=nealsid at http://breakpad.appspot.com/190001


git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@685 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
erikwright@chromium.org 2010-09-15 17:38:03 +00:00
parent 90a41b68ad
commit 7fde9a879d
4 changed files with 8 additions and 227 deletions

View file

@ -35,15 +35,9 @@
#include <fstream>
#include "common/windows/string_utils-inl.h"
#include "common/windows/wchar_logging.h"
#include "common/windows/http_upload.h"
// See comment in symupload.cc about #undef ERROR. Unfortunately this has to
// violate style guide and come after http_upload.h.
#undef ERROR
#include "third_party/glog/glog/src/windows/glog/logging.h"
namespace google_breakpad {
using std::ifstream;
@ -51,28 +45,6 @@ using std::ios;
static const wchar_t kUserAgent[] = L"Breakpad/1.0 (Windows)";
wchar_t lastErrorMessageBuffer[1024];
// Helper method to convert Last Error into a text message. Uses a static
// buffer, so don't save the message across Win32 calls that might change
// the last error.
//
// This function saves/restores the last error and it isn't thread safe.
const wchar_t* FormatLastError() {
DWORD oldLastError = GetLastError();
wchar_t lastErrorTempBuffer[1024];
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
lastErrorTempBuffer, 1024, NULL) == 0) {
wsprintf(lastErrorMessageBuffer, L"%d: (format message failed: %d)",
oldLastError, GetLastError());
} else {
wsprintf(lastErrorMessageBuffer, L"%d: %s", oldLastError,
lastErrorTempBuffer);
}
SetLastError(oldLastError);
return lastErrorMessageBuffer;
}
// Helper class which closes an internet handle when it goes away
class HTTPUpload::AutoInternetHandle {
public:
@ -100,19 +72,7 @@ bool HTTPUpload::SendRequest(const wstring &url,
if (response_code) {
*response_code = 0;
}
VLOG(1) << "HTTPUpload::SendRequest";
VLOG(1) << "\tURL: " << url;
VLOG(1) << "\tUpload_File: " << upload_file;
VLOG(1) << "\tFile_part_name: " << file_part_name;
VLOG(1) << "\tParameters: ";
string s;
if (VLOG_IS_ON(1)) {
for (std::map<wstring, wstring>::const_iterator it = parameters.begin();
it != parameters.end(); ++it) {
VLOG(1) << "\t\t" << it->first << " = " << it->second;
}
}
// TODO(bryner): support non-ASCII parameter names
if (!CheckParameters(parameters)) {
return false;
@ -130,9 +90,7 @@ bool HTTPUpload::SendRequest(const wstring &url,
components.lpszUrlPath = path;
components.dwUrlPathLength = sizeof(path) / sizeof(path[0]);
if (!InternetCrackUrl(url.c_str(), static_cast<DWORD>(url.size()),
0, &components)) {
LOG(ERROR) << "InternetCrackUrl failed: " << FormatLastError();
LOG(ERROR) << "This indicates a malformed upload server name";
0, &components)) {
return false;
}
bool secure = false;
@ -148,7 +106,6 @@ bool HTTPUpload::SendRequest(const wstring &url,
NULL, // proxy bypass
0)); // flags
if (!internet.get()) {
LOG(ERROR) << "InternetOpen returned NULL: " << FormatLastError();
return false;
}
@ -161,7 +118,6 @@ bool HTTPUpload::SendRequest(const wstring &url,
0, // flags
NULL)); // context
if (!connection.get()) {
LOG(ERROR) << "InternetConnect returned NULL: " << FormatLastError();
return false;
}
@ -176,7 +132,6 @@ bool HTTPUpload::SendRequest(const wstring &url,
http_open_flags,
NULL)); // context
if (!request.get()) {
LOG(ERROR) << "HttpOpenRequest returned NULL: " << FormatLastError();
return false;
}
@ -198,17 +153,13 @@ bool HTTPUpload::SendRequest(const wstring &url,
INTERNET_OPTION_SEND_TIMEOUT,
timeout,
sizeof(timeout))) {
LOG(ERROR) << "InternetSetOption on send timeout returned NULL: "
<< FormatLastError();
fwprintf(stderr, L"Could not unset send timeout, continuing...\n");
fwprintf(stderr, L"Could not unset send timeout, continuing...\n");
}
if (!InternetSetOption(request.get(),
INTERNET_OPTION_RECEIVE_TIMEOUT,
timeout,
sizeof(timeout))) {
LOG(ERROR) << "InternetSetOption on receive timeout returned NULL: "
<< FormatLastError();
fwprintf(stderr, L"Could not unset receive timeout, continuing...\n");
}
}
@ -216,7 +167,6 @@ bool HTTPUpload::SendRequest(const wstring &url,
if (!HttpSendRequest(request.get(), NULL, 0,
const_cast<char *>(request_body.data()),
static_cast<DWORD>(request_body.size()))) {
LOG(ERROR) << "HttpSendRequest on send returned NULL: " << FormatLastError();
return false;
}
@ -226,7 +176,6 @@ bool HTTPUpload::SendRequest(const wstring &url,
if (!HttpQueryInfo(request.get(), HTTP_QUERY_STATUS_CODE,
static_cast<LPVOID>(&http_status), &http_status_size,
0)) {
LOG(ERROR) << "HttpQueryInfo after send returned NULL: " << FormatLastError();
return false;
}
@ -239,8 +188,6 @@ bool HTTPUpload::SendRequest(const wstring &url,
if (result) {
result = ReadResponse(request.get(), response_body);
} else {
LOG(ERROR) << "Http send request returned: " << result;
}
return result;
@ -451,13 +398,11 @@ bool HTTPUpload::CheckParameters(const map<wstring, wstring> &parameters) {
pos != parameters.end(); ++pos) {
const wstring &str = pos->first;
if (str.size() == 0) {
LOG(ERROR) << "Parameter " << str << " had non ascii characters";
return false; // disallow empty parameter names
}
for (unsigned int i = 0; i < str.size(); ++i) {
wchar_t c = str[i];
if (c < 32 || c == '"' || c > 127) {
LOG(ERROR) << "Parameter " << str << " had non ascii characters";
return false;
}
}

View file

@ -1,59 +0,0 @@
// Copyright (c) 2010, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// This header file defines << for wchar, which is necessary for google glog
// to correctly log strings that have that constituent type.
// See http://code.google.com/p/google-glog/issues/detail?id=4
#ifndef WCHAR_LOGGING_H_
#define WCHAR_LOGGING_H_
#include <wchar.h>
#include <iostream>
#include <string>
inline std::ostream& operator<<(std::ostream& out, const wchar_t* str) {
size_t len;
wcstombs_s(&len, NULL, 0, str, _TRUNCATE);
char* buf = (char*)malloc(len + 1);
buf[len] = 0;
size_t converted;
wcstombs_s(&converted, buf, len, str, _TRUNCATE);
out << buf;
free(buf);
return out;
}
inline std::ostream& operator<<(std::ostream& out, const std::wstring& str) {
return operator<<(out, str.c_str());
}
#endif // WCHAR_LOGGING_H_