diff --git a/crash-handler-process/CMakeLists.txt b/crash-handler-process/CMakeLists.txt index 3ff8461..dcd3fe2 100644 --- a/crash-handler-process/CMakeLists.txt +++ b/crash-handler-process/CMakeLists.txt @@ -38,7 +38,9 @@ ENDIF() SET(PROJECT_SOURCE "${PROJECT_SOURCE_DIR}/process.hpp" "${PROJECT_SOURCE_DIR}/process-manager.cpp" "${PROJECT_SOURCE_DIR}/process-manager.hpp" + "${PROJECT_SOURCE_DIR}/brief-crash-info-uploader.cpp" "${PROJECT_SOURCE_DIR}/brief-crash-info-uploader.hpp" "${PROJECT_SOURCE_DIR}/message.cpp" "${PROJECT_SOURCE_DIR}/message.hpp" + "${PROJECT_SOURCE_DIR}/http-helper.hpp" "${PROJECT_SOURCE_DIR}/socket.hpp" "${PROJECT_SOURCE_DIR}/logger.cpp" "${PROJECT_SOURCE_DIR}/logger.hpp" "${PROJECT_SOURCE_DIR}/main.cpp" @@ -50,7 +52,9 @@ IF(WIN32) "${PROJECT_SOURCE_DIR}/platforms/util-win.cpp" "${PROJECT_SOURCE_DIR}/platforms/socket-win.cpp" "${PROJECT_SOURCE_DIR}/platforms/socket-win.hpp" "${PROJECT_SOURCE_DIR}/platforms/process-win.cpp" "${PROJECT_SOURCE_DIR}/platforms/process-win.hpp" - "${PROJECT_SOURCE_DIR}/platforms/upload-window-win.cpp" "${PROJECT_SOURCE_DIR}/platforms/upload-window-win.hpp" + "${PROJECT_SOURCE_DIR}/platforms/upload-window-win.cpp" "${PROJECT_SOURCE_DIR}/platforms/upload-window-win.hpp" + "${PROJECT_SOURCE_DIR}/platforms/httprequest_i.c" "${PROJECT_SOURCE_DIR}/platforms/httprequest.h" + "${PROJECT_SOURCE_DIR}/platforms/http-helper-win.cpp" "${PROJECT_SOURCE_DIR}/platforms/http-helper-win.hpp" "${PROJECT_SOURCE_DIR}/minizip/zip.c" "${PROJECT_SOURCE_DIR}/minizip/zip.h" "${PROJECT_SOURCE_DIR}/minizip/ioapi.c" "${PROJECT_SOURCE_DIR}/minizip/ioapi.h" "${PROJECT_SOURCE_DIR}/minizip/iowin32.c" "${PROJECT_SOURCE_DIR}/minizip/iowin32.h" @@ -60,7 +64,7 @@ ELSE(APPLE) "${PROJECT_SOURCE_DIR}/platforms/util-osx.mm" "${PROJECT_SOURCE_DIR}/platforms/socket-osx.cpp" "${PROJECT_SOURCE_DIR}/platforms/socket-osx.hpp" "${PROJECT_SOURCE_DIR}/platforms/process-osx.mm" "${PROJECT_SOURCE_DIR}/platforms/process-osx.hpp" - + "${PROJECT_SOURCE_DIR}/platforms/http-helper-osx.mm" "${PROJECT_SOURCE_DIR}/platforms/http-helper-osx.hpp" ) find_library(COCOA Cocoa) # Prepare gettext diff --git a/crash-handler-process/brief-crash-info-uploader.cpp b/crash-handler-process/brief-crash-info-uploader.cpp new file mode 100644 index 0000000..c72d440 --- /dev/null +++ b/crash-handler-process/brief-crash-info-uploader.cpp @@ -0,0 +1,117 @@ +/****************************************************************************** + Copyright (C) 2016-2020 by Streamlabs (General Workings Inc) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +******************************************************************************/ + +#include +#include +#include +#include +#include + +#include "logger.hpp" +#include "util.hpp" + +#include "http-helper.hpp" +#include "brief-crash-info-uploader.hpp" + +#if defined(_WIN32) +std::string_view g_pathSeparator("\\"); +#else +std::string_view g_pathSeparator("/"); +#endif + +std::string_view g_briefCrashDataFilename("brief-crash-info.json"); + +BriefCrashInfoUploader::BriefCrashInfoUploader(const std::string &appDataPath) : m_filename(appDataPath) +{ + if (*m_filename.rbegin() != '/' && *m_filename.rbegin() != '\\') { + m_filename += g_pathSeparator; + } + m_filename += g_briefCrashDataFilename; +} + +BriefCrashInfoUploader::~BriefCrashInfoUploader() {} + +void BriefCrashInfoUploader::Run(std::int64_t maxFileWaitTimeMs) +{ + std::string json = ProcessBriefCrashInfoJson(maxFileWaitTimeMs); + if (json.size()) { + UploadJson(json); + } +} + +std::string BriefCrashInfoUploader::ProcessBriefCrashInfoJson(std::int64_t maxFileWaitTimeMs) +{ + log_info << "Waiting for brief crash info file: " << m_filename << std::endl; + std::string json; + std::filesystem::path briefCrashInfoPath = std::filesystem::u8path(m_filename); + std::int64_t realFileWaitTimeMs = 0; + while (realFileWaitTimeMs < maxFileWaitTimeMs) { + if (std::filesystem::exists(briefCrashInfoPath) && std::filesystem::is_regular_file(briefCrashInfoPath)) { + json = LoadBriefCrashInfoJson(); + std::filesystem::remove(briefCrashInfoPath); + log_info << "The brief crash info file has been loaded." << std::endl; + break; + } + // Obviously the sleep can take more than 100ms but not much so we ignore the difference + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + realFileWaitTimeMs += 100; + } + log_info << "Waited for the brief crash info file (ms): " << realFileWaitTimeMs << std::endl; + return json; +} + +std::string BriefCrashInfoUploader::LoadBriefCrashInfoJson() +{ +#if defined(_WIN32) + std::wstring_convert> converter; + std::ifstream file(converter.from_bytes(m_filename)); +#else + std::ifstream file(m_filename); +#endif + file.seekg(0, std::ios::end); + size_t fileSize = file.tellg(); + + std::string buffer(fileSize, ' '); + file.seekg(0); + file.read(&buffer.front(), fileSize); + file.close(); + + return buffer; +} + +void BriefCrashInfoUploader::UploadJson(const std::string &json) +{ + log_info << "Uploading the brief crash info..." << std::endl; + + HttpHelper::Headers requestHeaders = {{"Content-Type", "application/json; Charset=UTF-8"}}; + HttpHelper::Headers responseHeaders; + std::string response; + + std::uint32_t statusCode = 0; + + auto httpHelper = HttpHelper::Create(); + HttpHelper::Result result = httpHelper->PostRequest("https://httpbin.org/post", requestHeaders, json, &statusCode, &responseHeaders, &response); + + log_info << "Brief crash info upload result (0 means SUCCESS): " << static_cast(result) << std::endl; + log_info << "Brief crash info upload HTTP status code: " << statusCode << std::endl; + log_info << "Brief crash info upload response: " << response << std::endl; + + for (const auto &[header, value] : responseHeaders) { + log_info << "Brief crash info upload response header: " << header << " = " << value << std::endl; + } +} diff --git a/crash-handler-process/brief-crash-info-uploader.hpp b/crash-handler-process/brief-crash-info-uploader.hpp new file mode 100644 index 0000000..04c8bd5 --- /dev/null +++ b/crash-handler-process/brief-crash-info-uploader.hpp @@ -0,0 +1,38 @@ +/****************************************************************************** + Copyright (C) 2016-2020 by Streamlabs (General Workings Inc) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +******************************************************************************/ + +#pragma once + +#include +#include +#include + +class BriefCrashInfoUploader final { +public: + BriefCrashInfoUploader(const std::string &appDataPath); + ~BriefCrashInfoUploader(); + + void Run(std::int64_t maxFileWaitTimeMs = 10000); + +private: + std::string ProcessBriefCrashInfoJson(std::int64_t maxFileWaitTimeMs); + std::string LoadBriefCrashInfoJson(); + void UploadJson(const std::string &json); + + std::string m_filename; +}; diff --git a/crash-handler-process/dependencies/crash-handler-process.exe.txt b/crash-handler-process/dependencies/crash-handler-process.exe.txt index a5603d0..ca0cdfe 100644 Binary files a/crash-handler-process/dependencies/crash-handler-process.exe.txt and b/crash-handler-process/dependencies/crash-handler-process.exe.txt differ diff --git a/crash-handler-process/http-helper.hpp b/crash-handler-process/http-helper.hpp new file mode 100644 index 0000000..4ff10b9 --- /dev/null +++ b/crash-handler-process/http-helper.hpp @@ -0,0 +1,54 @@ +/****************************************************************************** + Copyright (C) 2016-2020 by Streamlabs (General Workings Inc) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +******************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +class HttpHelper { +public: + enum class Result { + Success = 0, + InvalidParam, + CouldNotInit, + ConnectFailed, + RequestFailed, + ResponseFailed, + }; + + enum class Method { Undefined = 0, Get, Post }; + + using Headers = std::map; + + static std::unique_ptr Create(); + + virtual ~HttpHelper() {} + + virtual Result Request(Method method, std::string_view url, const Headers &requestHeaders, std::string_view body, std::uint32_t *statusCode, + Headers *responseHeaders, std::string *response) = 0; + + virtual Result GetRequest(std::string_view url, const Headers &requestHeaders, std::uint32_t *statusCode, Headers *responseHeaders, + std::string *response) = 0; + + virtual Result PostRequest(std::string_view url, const Headers &requestHeaders, std::string_view body, std::uint32_t *statusCode, + Headers *responseHeaders, std::string *response) = 0; +}; \ No newline at end of file diff --git a/crash-handler-process/main.cpp b/crash-handler-process/main.cpp index 6e15d48..b0dec70 100644 --- a/crash-handler-process/main.cpp +++ b/crash-handler-process/main.cpp @@ -20,6 +20,11 @@ #include "process-manager.hpp" #include "util.hpp" #include +#include + +#include "brief-crash-info-uploader.hpp" + +#include "http-helper.hpp" #if defined(WIN32) const std::string log_file_name = "\\crash-handler.log"; @@ -29,6 +34,9 @@ const std::wstring log_file_name = L"/crash-handler.log"; int main(int argc, char **argv) { +#if defined(_WIN32) + CoInitialize(NULL); +#endif Util::setupLocale(); std::string pid_path(Util::get_temp_directory()); @@ -40,6 +48,7 @@ int main(int argc, char **argv) std::wstring version; std::wstring isDevEnv; std::wstring ipc_path; + std::string appData_path; std::cout << "Launched with number of arguments = " << argc << std::endl; #if defined(WIN32) @@ -65,6 +74,7 @@ int main(int argc, char **argv) logging_start(w_log_path); log_info << "=== Started CrashHandler ===" << std::endl; Util::setCachePath(w_cache_path); + appData_path = cache_path; } if (nArgs >= 6) { ipc_path = szArglist[5]; @@ -87,22 +97,31 @@ int main(int argc, char **argv) logging_start(log_path); log_info << "=== Started CrashHandler ===" << std::endl; Util::setCachePath(cache_path); + appData_path = argv[4]; } if (argc >= 6) { ipc_path = converter.from_bytes(argv[5]); log_info << "ipc path option recieve : " << std::string(ipc_path.begin(), ipc_path.end()) << std::endl; Socket::set_ipc_path(ipc_path); } - #endif + ProcessManager *pm = new ProcessManager(); pm->runWatcher(); - if (pm->m_applicationCrashed) + if (pm->m_applicationCrashed) { pm->handleCrash(path); + BriefCrashInfoUploader(appData_path).Run(); + } delete pm; + log_info << "=== Terminating CrashHandler ===" << std::endl; logging_end(); + +#if defined(_WIN32) + CoUninitialize(); +#endif + return 0; } diff --git a/crash-handler-process/platforms/http-helper-osx.hpp b/crash-handler-process/platforms/http-helper-osx.hpp new file mode 100644 index 0000000..8ba48d7 --- /dev/null +++ b/crash-handler-process/platforms/http-helper-osx.hpp @@ -0,0 +1,38 @@ +/****************************************************************************** + Copyright (C) 2016-2020 by Streamlabs (General Workings Inc) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +******************************************************************************/ + +#pragma once + +#include "../http-helper.hpp" + +class HttpHelper_OSX : public HttpHelper { +public: + HttpHelper_OSX(); + ~HttpHelper_OSX() override; + + Result Request(Method method, std::string_view url, const Headers &requestHeaders, std::string_view body, std::uint32_t *statusCode, + Headers *responseHeaders, std::string *response) override; + + Result GetRequest(std::string_view url, const Headers &requestHeaders, std::uint32_t *statusCode, Headers *responseHeaders, + std::string *response) override; + + Result PostRequest(std::string_view url, const Headers &requestHeaders, std::string_view body, std::uint32_t *statusCode, Headers *responseHeaders, + std::string *response) override; + +private: +}; diff --git a/crash-handler-process/platforms/http-helper-osx.mm b/crash-handler-process/platforms/http-helper-osx.mm new file mode 100644 index 0000000..82618c8 --- /dev/null +++ b/crash-handler-process/platforms/http-helper-osx.mm @@ -0,0 +1,137 @@ +/****************************************************************************** + Copyright (C) 2016-2020 by Streamlabs (General Workings Inc) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +******************************************************************************/ + +#import +#import +#import +#import +#import +#import + +#include + +#include "../util.hpp" +#include "../logger.hpp" + +#include "http-helper-osx.hpp" + +std::unique_ptr HttpHelper::Create() +{ + return std::make_unique(); +} + +HttpHelper_OSX::HttpHelper_OSX() {} + +HttpHelper_OSX::~HttpHelper_OSX() {} + +HttpHelper_OSX::Result HttpHelper_OSX::Request(Method method, std::string_view url, const Headers &requestHeaders, std::string_view body, + std::uint32_t *statusCode, Headers *responseHeaders, std::string *response) +{ + dispatch_semaphore_t completionSemaphore = dispatch_semaphore_create(0); + + NSString *u = [NSString stringWithUTF8String:url.data()]; + NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:u]]; + switch (method) { + case Method::Get: + [urlRequest setHTTPMethod:@"GET"]; + break; + case Method::Post: + [urlRequest setHTTPMethod:@"POST"]; + break; + default: + return Result::InvalidParam; + } + + for (const auto &[header, value] : requestHeaders) { + NSString *h = [NSString stringWithUTF8String:header.data()]; + NSString *v = [NSString stringWithUTF8String:value.data()]; + [urlRequest setValue:v forHTTPHeaderField:h]; + } + + if (method == Method::Post) { + NSData *b = [NSData dataWithBytes:body.data() length:static_cast(body.size())]; + [urlRequest setHTTPBody:b]; + } + + NSURLSession *session = [NSURLSession sharedSession]; + + std::string errorDescription; + std::string *errorDescriptionPtr = &errorDescription; + + NSURLSessionDataTask *dataTask = [session + dataTaskWithRequest:urlRequest + completionHandler:^(NSData *data, NSURLResponse *resp, NSError *error) { + if (error) { + *errorDescriptionPtr = [[error localizedDescription] UTF8String]; + return; + } + + NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)resp; + + if (statusCode) { + *statusCode = static_cast(httpResponse.statusCode); + } + + if (responseHeaders) { + if ([httpResponse respondsToSelector:@selector(allHeaderFields)]) { + NSDictionary *dict = [httpResponse allHeaderFields]; + for (id key in dict) { + id value = [dict objectForKey:key]; + if ([key isKindOfClass:[NSString class]]) { + if ([value isKindOfClass:[NSString class]]) { + responseHeaders->emplace(std::string([key UTF8String]), std::string([value UTF8String])); + } + } + } + } + } + + if (response) { + response->clear(); + NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + if (responseString) { + response->append([responseString UTF8String]); + } + } + + dispatch_semaphore_signal(completionSemaphore); + }]; + + [dataTask resume]; + + dispatch_semaphore_wait(completionSemaphore, DISPATCH_TIME_FOREVER); + + if (errorDescription.size()) { + log_error << "HTTP request error: " << errorDescription << std::endl; + return Result::RequestFailed; + } + + return Result::Success; +} + +HttpHelper_OSX::Result HttpHelper_OSX::GetRequest(std::string_view url, const Headers &requestHeaders, std::uint32_t *statusCode, Headers *responseHeaders, + std::string *response) +{ + return Request(Method::Get, url, requestHeaders, "", statusCode, responseHeaders, response); +} + +HttpHelper_OSX::Result HttpHelper_OSX::PostRequest(std::string_view url, const Headers &requestHeaders, std::string_view body, std::uint32_t *statusCode, + Headers *responseHeaders, std::string *response) +{ + return Request(Method::Post, url, requestHeaders, body, statusCode, responseHeaders, response); +} \ No newline at end of file diff --git a/crash-handler-process/platforms/http-helper-win.cpp b/crash-handler-process/platforms/http-helper-win.cpp new file mode 100644 index 0000000..1efcbc3 --- /dev/null +++ b/crash-handler-process/platforms/http-helper-win.cpp @@ -0,0 +1,190 @@ +/****************************************************************************** + Copyright (C) 2016-2020 by Streamlabs (General Workings Inc) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +******************************************************************************/ + +#include +#include +#include +#include +#include + +#include +#include + +#include "../util.hpp" +#include "../logger.hpp" + +#include "httprequest.h" +#include "http-helper-win.hpp" + +#pragma comment(lib, "ole32.lib") +#pragma comment(lib, "oleaut32.lib") +#pragma comment(lib, "comsuppw.lib") + +// IID for IWinHttpRequest. +//const IID IID_IWinHttpRequest = +//{ +// 0x06f29373, +// 0x5c5a, +// 0x4b54, +// {0xb0, 0x25, 0x6e, 0xf1, 0xbf, 0x8a, 0xbf, 0x0e} +//}; + +std::string from_utf16_wide_to_utf8(const wchar_t *from, size_t length = -1); +std::wstring from_utf8_to_utf16_wide(const char *from, size_t length = -1); + +std::unique_ptr HttpHelper::Create() +{ + return std::make_unique(); +} + +HttpHelper_WIN::HttpHelper_WIN() {} + +HttpHelper_WIN::~HttpHelper_WIN() {} + +HttpHelper::Result HttpHelper_WIN::Request(Method method, std::string_view url, const Headers &requestHeaders, std::string_view body, std::uint32_t *statusCode, + Headers *responseHeaders, std::string *response) +{ + VARIANT varFalse; + VariantInit(&varFalse); + V_VT(&varFalse) = VT_BOOL; + V_BOOL(&varFalse) = VARIANT_FALSE; + + VARIANT varEmpty; + VariantInit(&varEmpty); + V_VT(&varEmpty) = VT_ERROR; + + CLSID clsid; + HRESULT hr = CLSIDFromProgID(L"WinHttp.WinHttpRequest.5.1", &clsid); + if (FAILED(hr)) { + return Result::CouldNotInit; + } + + _bstr_t bstrMethod; + switch (method) { + case Method::Get: + bstrMethod = L"GET"; + break; + case Method::Post: + bstrMethod = L"POST"; + break; + default: + return Result::InvalidParam; + } + + std::wstring wsUrl = from_utf8_to_utf16_wide(url.data()); + _bstr_t bstrUrl(wsUrl.data()); + + std::wstring wsBody = from_utf8_to_utf16_wide(body.data()); + _bstr_t bstrBody(wsBody.data()); + + VARIANT varBody; + VariantInit(&varBody); + V_VT(&varBody) = VT_BSTR; + varBody.bstrVal = bstrBody.GetBSTR(); + + Microsoft::WRL::ComPtr winHttpRequest; + hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IWinHttpRequest, &winHttpRequest); + if (FAILED(hr)) { + return Result::CouldNotInit; + } + + hr = winHttpRequest->Open(bstrMethod, bstrUrl, varFalse); + if (FAILED(hr)) { + return Result::ConnectFailed; + } + + for (const auto &[header, value] : requestHeaders) { + std::wstring wsHeader = from_utf8_to_utf16_wide(header.data()); + _bstr_t bstrHeader(wsHeader.data()); + std::wstring wsValue = from_utf8_to_utf16_wide(value.data()); + _bstr_t bstrValue(wsValue.data()); + + hr = winHttpRequest->SetRequestHeader(bstrHeader, bstrValue); + if (FAILED(hr)) { + log_error << "Incorrectly formatted header: " << header << " = " << value << std::endl; + return Result::InvalidParam; + } + } + + hr = winHttpRequest->Send((method == Method::Post) ? varBody : varEmpty); + if (FAILED(hr)) { + return Result::RequestFailed; + } + + if (statusCode) { + hr = winHttpRequest->get_Status(static_cast(static_cast(statusCode))); + if (FAILED(hr)) { + return Result::RequestFailed; + } + } + + if (responseHeaders) { + BSTR bstrTmp = NULL; + hr = winHttpRequest->GetAllResponseHeaders(&bstrTmp); + if (FAILED(hr)) { + return Result::ResponseFailed; + } + + _bstr_t bstrResponseHeaders(bstrTmp, false); + std::wstring wsResponseHeaders(bstrResponseHeaders, SysStringLen(bstrResponseHeaders)); + std::wstringstream wss(wsResponseHeaders); + std::wstring token; + while (std::getline(wss, token, L'\n')) { + std::string::size_type pos = token.find(L':'); + if (pos != std::string::npos) { + std::wstring wsHeader = token.substr(0, pos); + _bstr_t bstrHeader(wsHeader.data()); + hr = winHttpRequest->GetResponseHeader(bstrHeader, &bstrTmp); + if (SUCCEEDED(hr)) { + _bstr_t bstrValue(bstrTmp, false); + std::wstring wsValue(bstrValue, SysStringLen(bstrValue)); + std::string value = from_utf16_wide_to_utf8(wsValue.data()); + std::string header = from_utf16_wide_to_utf8(wsHeader.data()); + responseHeaders->emplace(header, value); + } + } + } + } + + if (response) { + BSTR bstrTmp = NULL; + hr = winHttpRequest->get_ResponseText(&bstrTmp); + if (FAILED(hr)) { + return Result::ResponseFailed; + } + + _bstr_t bstrResponse(bstrTmp, false); + std::wstring wsResponse(bstrResponse, SysStringLen(bstrResponse)); + + *response = from_utf16_wide_to_utf8(wsResponse.data()); + } + + return Result::Success; +} + +HttpHelper::Result HttpHelper_WIN::GetRequest(std::string_view url, const Headers &requestHeaders, std::uint32_t *statusCode, Headers *responseHeaders, + std::string *response) +{ + return Request(Method::Get, url, requestHeaders, "", statusCode, responseHeaders, response); +} + +HttpHelper::Result HttpHelper_WIN::PostRequest(std::string_view url, const Headers &requestHeaders, std::string_view body, std::uint32_t *statusCode, + Headers *responseHeaders, std::string *response) +{ + return Request(Method::Post, url, requestHeaders, body, statusCode, responseHeaders, response); +} diff --git a/crash-handler-process/platforms/http-helper-win.hpp b/crash-handler-process/platforms/http-helper-win.hpp new file mode 100644 index 0000000..f5224fc --- /dev/null +++ b/crash-handler-process/platforms/http-helper-win.hpp @@ -0,0 +1,43 @@ +/****************************************************************************** + Copyright (C) 2016-2020 by Streamlabs (General Workings Inc) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "../http-helper.hpp" + +class HttpHelper_WIN : public HttpHelper { +public: + HttpHelper_WIN(); + ~HttpHelper_WIN() override; + + Result Request(Method method, std::string_view url, const Headers &requestHeaders, std::string_view body, std::uint32_t *statusCode, + Headers *responseHeaders, std::string *response) override; + + Result GetRequest(std::string_view url, const Headers &requestHeaders, std::uint32_t *statusCode, Headers *responseHeaders, + std::string *response) override; + + Result PostRequest(std::string_view url, const Headers &requestHeaders, std::string_view body, std::uint32_t *statusCode, Headers *responseHeaders, + std::string *response) override; +}; \ No newline at end of file diff --git a/crash-handler-process/platforms/httprequest.h b/crash-handler-process/platforms/httprequest.h new file mode 100644 index 0000000..6cada67 --- /dev/null +++ b/crash-handler-process/platforms/httprequest.h @@ -0,0 +1,591 @@ + + +/* this ALWAYS GENERATED file contains the definitions for the interfaces */ + +/* File created by MIDL compiler version 8.01.0626 */ +/* at Mon Jan 18 22:14:07 2038 + */ +/* Compiler settings for httprequest.idl: + Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0626 + protocol : dce , ms_ext, c_ext, robust + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +/* @@MIDL_FILE_HEADING( ) */ + +#pragma warning(disable : 4049) /* more than 64k source lines */ + +/* verify that the version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCNDR_H_VERSION__ +#define __REQUIRED_RPCNDR_H_VERSION__ 475 +#endif + +#include "rpc.h" +#include "rpcndr.h" + +#ifndef __RPCNDR_H_VERSION__ +#error this stub requires an updated version of +#endif /* __RPCNDR_H_VERSION__ */ + +#ifndef __httprequest_h__ +#define __httprequest_h__ + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +#pragma once +#endif + +#ifndef DECLSPEC_XFGVIRT +#if _CONTROL_FLOW_GUARD_XFG +#define DECLSPEC_XFGVIRT(base, func) __declspec(xfg_virtual(base, func)) +#else +#define DECLSPEC_XFGVIRT(base, func) +#endif +#endif + +/* Forward Declarations */ + +#ifndef __IWinHttpRequest_FWD_DEFINED__ +#define __IWinHttpRequest_FWD_DEFINED__ +typedef interface IWinHttpRequest IWinHttpRequest; + +#endif /* __IWinHttpRequest_FWD_DEFINED__ */ + +#ifndef __IWinHttpRequestEvents_FWD_DEFINED__ +#define __IWinHttpRequestEvents_FWD_DEFINED__ +typedef interface IWinHttpRequestEvents IWinHttpRequestEvents; + +#endif /* __IWinHttpRequestEvents_FWD_DEFINED__ */ + +#ifndef __WinHttpRequest_FWD_DEFINED__ +#define __WinHttpRequest_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class WinHttpRequest WinHttpRequest; +#else +typedef struct WinHttpRequest WinHttpRequest; +#endif /* __cplusplus */ + +#endif /* __WinHttpRequest_FWD_DEFINED__ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* interface __MIDL_itf_httprequest_0000_0000 */ +/* [local] */ + +//+------------------------------------------------------------------------- +// +// Microsoft Windows HTTP Services (WinHTTP) version 5.1 +// Copyright (C) Microsoft Corporation. All rights reserved. +// +//-------------------------------------------------------------------------- +#include +#pragma region Desktop Family or OneCore Family +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) +#pragma warning(push) +#pragma warning(disable : 4001) +#pragma once +#pragma warning(push) +#pragma warning(disable : 4001) +#pragma once +#pragma warning(pop) +#pragma warning(pop) +#pragma region Desktop Family or OneCore Family +#pragma endregion + +extern RPC_IF_HANDLE __MIDL_itf_httprequest_0000_0000_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_httprequest_0000_0000_v0_0_s_ifspec; + +#ifndef __WinHttp_LIBRARY_DEFINED__ +#define __WinHttp_LIBRARY_DEFINED__ + +/* library WinHttp */ +/* [version][lcid][helpstring][uuid] */ + +typedef /* [public] */ long HTTPREQUEST_PROXY_SETTING; + +#define HTTPREQUEST_PROXYSETTING_DEFAULT (0) + +#define HTTPREQUEST_PROXYSETTING_PRECONFIG (0) + +#define HTTPREQUEST_PROXYSETTING_DIRECT (0x1) + +#define HTTPREQUEST_PROXYSETTING_PROXY (0x2) + +typedef /* [public] */ long HTTPREQUEST_SETCREDENTIALS_FLAGS; + +#define HTTPREQUEST_SETCREDENTIALS_FOR_SERVER (0) + +#define HTTPREQUEST_SETCREDENTIALS_FOR_PROXY (0x1) + +typedef /* [helpstring][uuid] */ DECLSPEC_UUID("12782009-FE90-4877-9730-E5E183669B19") enum WinHttpRequestOption { + WinHttpRequestOption_UserAgentString = 0, + WinHttpRequestOption_URL = (WinHttpRequestOption_UserAgentString + 1), + WinHttpRequestOption_URLCodePage = (WinHttpRequestOption_URL + 1), + WinHttpRequestOption_EscapePercentInURL = (WinHttpRequestOption_URLCodePage + 1), + WinHttpRequestOption_SslErrorIgnoreFlags = (WinHttpRequestOption_EscapePercentInURL + 1), + WinHttpRequestOption_SelectCertificate = (WinHttpRequestOption_SslErrorIgnoreFlags + 1), + WinHttpRequestOption_EnableRedirects = (WinHttpRequestOption_SelectCertificate + 1), + WinHttpRequestOption_UrlEscapeDisable = (WinHttpRequestOption_EnableRedirects + 1), + WinHttpRequestOption_UrlEscapeDisableQuery = (WinHttpRequestOption_UrlEscapeDisable + 1), + WinHttpRequestOption_SecureProtocols = (WinHttpRequestOption_UrlEscapeDisableQuery + 1), + WinHttpRequestOption_EnableTracing = (WinHttpRequestOption_SecureProtocols + 1), + WinHttpRequestOption_RevertImpersonationOverSsl = (WinHttpRequestOption_EnableTracing + 1), + WinHttpRequestOption_EnableHttpsToHttpRedirects = (WinHttpRequestOption_RevertImpersonationOverSsl + 1), + WinHttpRequestOption_EnablePassportAuthentication = (WinHttpRequestOption_EnableHttpsToHttpRedirects + 1), + WinHttpRequestOption_MaxAutomaticRedirects = (WinHttpRequestOption_EnablePassportAuthentication + 1), + WinHttpRequestOption_MaxResponseHeaderSize = (WinHttpRequestOption_MaxAutomaticRedirects + 1), + WinHttpRequestOption_MaxResponseDrainSize = (WinHttpRequestOption_MaxResponseHeaderSize + 1), + WinHttpRequestOption_EnableHttp1_1 = (WinHttpRequestOption_MaxResponseDrainSize + 1), + WinHttpRequestOption_EnableCertificateRevocationCheck = (WinHttpRequestOption_EnableHttp1_1 + 1), + WinHttpRequestOption_RejectUserpwd = (WinHttpRequestOption_EnableCertificateRevocationCheck + 1) +} WinHttpRequestOption; + +typedef /* [uuid] */ DECLSPEC_UUID("9d8a6df8-13de-4b1f-a330-67c719d62514") enum WinHttpRequestAutoLogonPolicy { + AutoLogonPolicy_Always = 0, + AutoLogonPolicy_OnlyIfBypassProxy = (AutoLogonPolicy_Always + 1), + AutoLogonPolicy_Never = (AutoLogonPolicy_OnlyIfBypassProxy + 1) +} WinHttpRequestAutoLogonPolicy; + +typedef /* [uuid] */ DECLSPEC_UUID("152a1ca2-55a9-43a3-b187-0605bb886349") enum WinHttpRequestSslErrorFlags { + SslErrorFlag_UnknownCA = 0x100, + SslErrorFlag_CertWrongUsage = 0x200, + SslErrorFlag_CertCNInvalid = 0x1000, + SslErrorFlag_CertDateInvalid = 0x2000, + SslErrorFlag_Ignore_All = 0x3300 +} WinHttpRequestSslErrorFlags; + +typedef /* [uuid] */ DECLSPEC_UUID("6b2c51c1-a8ea-46bd-b928-c9b76f9f14dd") enum WinHttpRequestSecureProtocols { + SecureProtocol_SSL2 = 0x8, + SecureProtocol_SSL3 = 0x20, + SecureProtocol_TLS1 = 0x80, + SecureProtocol_TLS1_1 = 0x200, + SecureProtocol_TLS1_2 = 0x800, + SecureProtocol_ALL = 0xa8 +} WinHttpRequestSecureProtocols; + +EXTERN_C const IID LIBID_WinHttp; + +#ifndef __IWinHttpRequest_INTERFACE_DEFINED__ +#define __IWinHttpRequest_INTERFACE_DEFINED__ + +/* interface IWinHttpRequest */ +/* [unique][helpstring][nonextensible][oleautomation][dual][uuid][object] */ + +EXTERN_C const IID IID_IWinHttpRequest; + +#if defined(__cplusplus) && !defined(CINTERFACE) + +MIDL_INTERFACE("016fe2ec-b2c8-45f8-b23b-39e53a75396b") +IWinHttpRequest : public IDispatch +{ +public: + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE SetProxy( + /* [in] */ HTTPREQUEST_PROXY_SETTING ProxySetting, + /* [optional][in] */ VARIANT ProxyServer, + /* [optional][in] */ VARIANT BypassList) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE SetCredentials( + /* [in] */ BSTR UserName, + /* [in] */ BSTR Password, + /* [in] */ HTTPREQUEST_SETCREDENTIALS_FLAGS Flags) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE Open( + /* [in] */ BSTR Method, + /* [in] */ BSTR Url, + /* [optional][in] */ VARIANT Async) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE SetRequestHeader( + /* [in] */ BSTR Header, + /* [in] */ BSTR Value) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE GetResponseHeader( + /* [in] */ BSTR Header, + /* [retval][out] */ BSTR * Value) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE GetAllResponseHeaders( + /* [retval][out] */ BSTR * Headers) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE Send( + /* [optional][in] */ VARIANT Body) = 0; + + virtual /* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE get_Status( + /* [retval][out] */ long *Status) = 0; + + virtual /* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE get_StatusText( + /* [retval][out] */ BSTR * Status) = 0; + + virtual /* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE get_ResponseText( + /* [retval][out] */ BSTR * Body) = 0; + + virtual /* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE get_ResponseBody( + /* [retval][out] */ VARIANT * Body) = 0; + + virtual /* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE get_ResponseStream( + /* [retval][out] */ VARIANT * Body) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Option( + /* [in] */ WinHttpRequestOption Option, + /* [retval][out] */ VARIANT * Value) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_Option( + /* [in] */ WinHttpRequestOption Option, + /* [in] */ VARIANT Value) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE WaitForResponse( + /* [optional][in] */ VARIANT Timeout, + /* [retval][out] */ VARIANT_BOOL * Succeeded) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE Abort(void) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE SetTimeouts( + /* [in] */ long ResolveTimeout, + /* [in] */ long ConnectTimeout, + /* [in] */ long SendTimeout, + /* [in] */ long ReceiveTimeout) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE SetClientCertificate( + /* [in] */ BSTR ClientCertificate) = 0; + + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE SetAutoLogonPolicy( + /* [in] */ WinHttpRequestAutoLogonPolicy AutoLogonPolicy) = 0; +}; + +#else /* C style interface */ + +typedef struct IWinHttpRequestVtbl { + BEGIN_INTERFACE + + DECLSPEC_XFGVIRT(IUnknown, QueryInterface) + HRESULT(STDMETHODCALLTYPE *QueryInterface) + (IWinHttpRequest *This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + DECLSPEC_XFGVIRT(IUnknown, AddRef) + ULONG(STDMETHODCALLTYPE *AddRef)(IWinHttpRequest *This); + + DECLSPEC_XFGVIRT(IUnknown, Release) + ULONG(STDMETHODCALLTYPE *Release)(IWinHttpRequest *This); + + DECLSPEC_XFGVIRT(IDispatch, GetTypeInfoCount) + HRESULT(STDMETHODCALLTYPE *GetTypeInfoCount) + (IWinHttpRequest *This, + /* [out] */ UINT *pctinfo); + + DECLSPEC_XFGVIRT(IDispatch, GetTypeInfo) + HRESULT(STDMETHODCALLTYPE *GetTypeInfo) + (IWinHttpRequest *This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + DECLSPEC_XFGVIRT(IDispatch, GetIDsOfNames) + HRESULT(STDMETHODCALLTYPE *GetIDsOfNames) + (IWinHttpRequest *This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [range][in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + DECLSPEC_XFGVIRT(IDispatch, Invoke) + /* [local] */ HRESULT(STDMETHODCALLTYPE *Invoke)(IWinHttpRequest *This, + /* [annotation][in] */ + _In_ DISPID dispIdMember, + /* [annotation][in] */ + _In_ REFIID riid, + /* [annotation][in] */ + _In_ LCID lcid, + /* [annotation][in] */ + _In_ WORD wFlags, + /* [annotation][out][in] */ + _In_ DISPPARAMS *pDispParams, + /* [annotation][out] */ + _Out_opt_ VARIANT *pVarResult, + /* [annotation][out] */ + _Out_opt_ EXCEPINFO *pExcepInfo, + /* [annotation][out] */ + _Out_opt_ UINT *puArgErr); + + DECLSPEC_XFGVIRT(IWinHttpRequest, SetProxy) + /* [helpstring][id] */ HRESULT(STDMETHODCALLTYPE *SetProxy)(IWinHttpRequest *This, + /* [in] */ HTTPREQUEST_PROXY_SETTING ProxySetting, + /* [optional][in] */ VARIANT ProxyServer, + /* [optional][in] */ VARIANT BypassList); + + DECLSPEC_XFGVIRT(IWinHttpRequest, SetCredentials) + /* [helpstring][id] */ HRESULT(STDMETHODCALLTYPE *SetCredentials)(IWinHttpRequest *This, + /* [in] */ BSTR UserName, + /* [in] */ BSTR Password, + /* [in] */ HTTPREQUEST_SETCREDENTIALS_FLAGS Flags); + + DECLSPEC_XFGVIRT(IWinHttpRequest, Open) + /* [helpstring][id] */ HRESULT(STDMETHODCALLTYPE *Open)(IWinHttpRequest *This, + /* [in] */ BSTR Method, + /* [in] */ BSTR Url, + /* [optional][in] */ VARIANT Async); + + DECLSPEC_XFGVIRT(IWinHttpRequest, SetRequestHeader) + /* [helpstring][id] */ HRESULT(STDMETHODCALLTYPE *SetRequestHeader)(IWinHttpRequest *This, + /* [in] */ BSTR Header, + /* [in] */ BSTR Value); + + DECLSPEC_XFGVIRT(IWinHttpRequest, GetResponseHeader) + /* [helpstring][id] */ HRESULT(STDMETHODCALLTYPE *GetResponseHeader)(IWinHttpRequest *This, + /* [in] */ BSTR Header, + /* [retval][out] */ BSTR *Value); + + DECLSPEC_XFGVIRT(IWinHttpRequest, GetAllResponseHeaders) + /* [helpstring][id] */ HRESULT(STDMETHODCALLTYPE *GetAllResponseHeaders)(IWinHttpRequest *This, + /* [retval][out] */ BSTR *Headers); + + DECLSPEC_XFGVIRT(IWinHttpRequest, Send) + /* [helpstring][id] */ HRESULT(STDMETHODCALLTYPE *Send)(IWinHttpRequest *This, + /* [optional][in] */ VARIANT Body); + + DECLSPEC_XFGVIRT(IWinHttpRequest, get_Status) + /* [helpstring][id][propget] */ HRESULT(STDMETHODCALLTYPE *get_Status)(IWinHttpRequest *This, + /* [retval][out] */ long *Status); + + DECLSPEC_XFGVIRT(IWinHttpRequest, get_StatusText) + /* [helpstring][id][propget] */ HRESULT(STDMETHODCALLTYPE *get_StatusText)(IWinHttpRequest *This, + /* [retval][out] */ BSTR *Status); + + DECLSPEC_XFGVIRT(IWinHttpRequest, get_ResponseText) + /* [helpstring][id][propget] */ HRESULT(STDMETHODCALLTYPE *get_ResponseText)(IWinHttpRequest *This, + /* [retval][out] */ BSTR *Body); + + DECLSPEC_XFGVIRT(IWinHttpRequest, get_ResponseBody) + /* [helpstring][id][propget] */ HRESULT(STDMETHODCALLTYPE *get_ResponseBody)(IWinHttpRequest *This, + /* [retval][out] */ VARIANT *Body); + + DECLSPEC_XFGVIRT(IWinHttpRequest, get_ResponseStream) + /* [helpstring][id][propget] */ HRESULT(STDMETHODCALLTYPE *get_ResponseStream)(IWinHttpRequest *This, + /* [retval][out] */ VARIANT *Body); + + DECLSPEC_XFGVIRT(IWinHttpRequest, get_Option) + /* [id][propget] */ HRESULT(STDMETHODCALLTYPE *get_Option)(IWinHttpRequest *This, + /* [in] */ WinHttpRequestOption Option, + /* [retval][out] */ VARIANT *Value); + + DECLSPEC_XFGVIRT(IWinHttpRequest, put_Option) + /* [id][propput] */ HRESULT(STDMETHODCALLTYPE *put_Option)(IWinHttpRequest *This, + /* [in] */ WinHttpRequestOption Option, + /* [in] */ VARIANT Value); + + DECLSPEC_XFGVIRT(IWinHttpRequest, WaitForResponse) + /* [helpstring][id] */ HRESULT(STDMETHODCALLTYPE *WaitForResponse)(IWinHttpRequest *This, + /* [optional][in] */ VARIANT Timeout, + /* [retval][out] */ VARIANT_BOOL *Succeeded); + + DECLSPEC_XFGVIRT(IWinHttpRequest, Abort) + /* [helpstring][id] */ HRESULT(STDMETHODCALLTYPE *Abort)(IWinHttpRequest *This); + + DECLSPEC_XFGVIRT(IWinHttpRequest, SetTimeouts) + /* [helpstring][id] */ HRESULT(STDMETHODCALLTYPE *SetTimeouts)(IWinHttpRequest *This, + /* [in] */ long ResolveTimeout, + /* [in] */ long ConnectTimeout, + /* [in] */ long SendTimeout, + /* [in] */ long ReceiveTimeout); + + DECLSPEC_XFGVIRT(IWinHttpRequest, SetClientCertificate) + /* [helpstring][id] */ HRESULT(STDMETHODCALLTYPE *SetClientCertificate)(IWinHttpRequest *This, + /* [in] */ BSTR ClientCertificate); + + DECLSPEC_XFGVIRT(IWinHttpRequest, SetAutoLogonPolicy) + /* [helpstring][id] */ HRESULT(STDMETHODCALLTYPE *SetAutoLogonPolicy)(IWinHttpRequest *This, + /* [in] */ WinHttpRequestAutoLogonPolicy AutoLogonPolicy); + + END_INTERFACE +} IWinHttpRequestVtbl; + +interface IWinHttpRequest { + CONST_VTBL struct IWinHttpRequestVtbl *lpVtbl; +}; + +#ifdef COBJMACROS + +#define IWinHttpRequest_QueryInterface(This, riid, ppvObject) ((This)->lpVtbl->QueryInterface(This, riid, ppvObject)) + +#define IWinHttpRequest_AddRef(This) ((This)->lpVtbl->AddRef(This)) + +#define IWinHttpRequest_Release(This) ((This)->lpVtbl->Release(This)) + +#define IWinHttpRequest_GetTypeInfoCount(This, pctinfo) ((This)->lpVtbl->GetTypeInfoCount(This, pctinfo)) + +#define IWinHttpRequest_GetTypeInfo(This, iTInfo, lcid, ppTInfo) ((This)->lpVtbl->GetTypeInfo(This, iTInfo, lcid, ppTInfo)) + +#define IWinHttpRequest_GetIDsOfNames(This, riid, rgszNames, cNames, lcid, rgDispId) \ + ((This)->lpVtbl->GetIDsOfNames(This, riid, rgszNames, cNames, lcid, rgDispId)) + +#define IWinHttpRequest_Invoke(This, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr) \ + ((This)->lpVtbl->Invoke(This, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr)) + +#define IWinHttpRequest_SetProxy(This, ProxySetting, ProxyServer, BypassList) ((This)->lpVtbl->SetProxy(This, ProxySetting, ProxyServer, BypassList)) + +#define IWinHttpRequest_SetCredentials(This, UserName, Password, Flags) ((This)->lpVtbl->SetCredentials(This, UserName, Password, Flags)) + +#define IWinHttpRequest_Open(This, Method, Url, Async) ((This)->lpVtbl->Open(This, Method, Url, Async)) + +#define IWinHttpRequest_SetRequestHeader(This, Header, Value) ((This)->lpVtbl->SetRequestHeader(This, Header, Value)) + +#define IWinHttpRequest_GetResponseHeader(This, Header, Value) ((This)->lpVtbl->GetResponseHeader(This, Header, Value)) + +#define IWinHttpRequest_GetAllResponseHeaders(This, Headers) ((This)->lpVtbl->GetAllResponseHeaders(This, Headers)) + +#define IWinHttpRequest_Send(This, Body) ((This)->lpVtbl->Send(This, Body)) + +#define IWinHttpRequest_get_Status(This, Status) ((This)->lpVtbl->get_Status(This, Status)) + +#define IWinHttpRequest_get_StatusText(This, Status) ((This)->lpVtbl->get_StatusText(This, Status)) + +#define IWinHttpRequest_get_ResponseText(This, Body) ((This)->lpVtbl->get_ResponseText(This, Body)) + +#define IWinHttpRequest_get_ResponseBody(This, Body) ((This)->lpVtbl->get_ResponseBody(This, Body)) + +#define IWinHttpRequest_get_ResponseStream(This, Body) ((This)->lpVtbl->get_ResponseStream(This, Body)) + +#define IWinHttpRequest_get_Option(This, Option, Value) ((This)->lpVtbl->get_Option(This, Option, Value)) + +#define IWinHttpRequest_put_Option(This, Option, Value) ((This)->lpVtbl->put_Option(This, Option, Value)) + +#define IWinHttpRequest_WaitForResponse(This, Timeout, Succeeded) ((This)->lpVtbl->WaitForResponse(This, Timeout, Succeeded)) + +#define IWinHttpRequest_Abort(This) ((This)->lpVtbl->Abort(This)) + +#define IWinHttpRequest_SetTimeouts(This, ResolveTimeout, ConnectTimeout, SendTimeout, ReceiveTimeout) \ + ((This)->lpVtbl->SetTimeouts(This, ResolveTimeout, ConnectTimeout, SendTimeout, ReceiveTimeout)) + +#define IWinHttpRequest_SetClientCertificate(This, ClientCertificate) ((This)->lpVtbl->SetClientCertificate(This, ClientCertificate)) + +#define IWinHttpRequest_SetAutoLogonPolicy(This, AutoLogonPolicy) ((This)->lpVtbl->SetAutoLogonPolicy(This, AutoLogonPolicy)) + +#endif /* COBJMACROS */ + +#endif /* C style interface */ + +#endif /* __IWinHttpRequest_INTERFACE_DEFINED__ */ + +#ifndef __IWinHttpRequestEvents_INTERFACE_DEFINED__ +#define __IWinHttpRequestEvents_INTERFACE_DEFINED__ + +/* interface IWinHttpRequestEvents */ +/* [unique][helpstring][nonextensible][oleautomation][uuid][object] */ + +EXTERN_C const IID IID_IWinHttpRequestEvents; + +#if defined(__cplusplus) && !defined(CINTERFACE) + +MIDL_INTERFACE("f97f4e15-b787-4212-80d1-d380cbbf982e") +IWinHttpRequestEvents : public IUnknown +{ +public: + virtual void STDMETHODCALLTYPE OnResponseStart( + /* [in] */ long Status, + /* [in] */ BSTR ContentType) = 0; + + virtual void STDMETHODCALLTYPE OnResponseDataAvailable( + /* [in] */ SAFEARRAY * *Data) = 0; + + virtual void STDMETHODCALLTYPE OnResponseFinished(void) = 0; + + virtual void STDMETHODCALLTYPE OnError( + /* [in] */ long ErrorNumber, + /* [in] */ BSTR ErrorDescription) = 0; +}; + +#else /* C style interface */ + +typedef struct IWinHttpRequestEventsVtbl { + BEGIN_INTERFACE + + DECLSPEC_XFGVIRT(IUnknown, QueryInterface) + HRESULT(STDMETHODCALLTYPE *QueryInterface) + (IWinHttpRequestEvents *This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + DECLSPEC_XFGVIRT(IUnknown, AddRef) + ULONG(STDMETHODCALLTYPE *AddRef)(IWinHttpRequestEvents *This); + + DECLSPEC_XFGVIRT(IUnknown, Release) + ULONG(STDMETHODCALLTYPE *Release)(IWinHttpRequestEvents *This); + + DECLSPEC_XFGVIRT(IWinHttpRequestEvents, OnResponseStart) + void(STDMETHODCALLTYPE *OnResponseStart)(IWinHttpRequestEvents *This, + /* [in] */ long Status, + /* [in] */ BSTR ContentType); + + DECLSPEC_XFGVIRT(IWinHttpRequestEvents, OnResponseDataAvailable) + void(STDMETHODCALLTYPE *OnResponseDataAvailable)(IWinHttpRequestEvents *This, + /* [in] */ SAFEARRAY **Data); + + DECLSPEC_XFGVIRT(IWinHttpRequestEvents, OnResponseFinished) + void(STDMETHODCALLTYPE *OnResponseFinished)(IWinHttpRequestEvents *This); + + DECLSPEC_XFGVIRT(IWinHttpRequestEvents, OnError) + void(STDMETHODCALLTYPE *OnError)(IWinHttpRequestEvents *This, + /* [in] */ long ErrorNumber, + /* [in] */ BSTR ErrorDescription); + + END_INTERFACE +} IWinHttpRequestEventsVtbl; + +interface IWinHttpRequestEvents { + CONST_VTBL struct IWinHttpRequestEventsVtbl *lpVtbl; +}; + +#ifdef COBJMACROS + +#define IWinHttpRequestEvents_QueryInterface(This, riid, ppvObject) ((This)->lpVtbl->QueryInterface(This, riid, ppvObject)) + +#define IWinHttpRequestEvents_AddRef(This) ((This)->lpVtbl->AddRef(This)) + +#define IWinHttpRequestEvents_Release(This) ((This)->lpVtbl->Release(This)) + +#define IWinHttpRequestEvents_OnResponseStart(This, Status, ContentType) ((This)->lpVtbl->OnResponseStart(This, Status, ContentType)) + +#define IWinHttpRequestEvents_OnResponseDataAvailable(This, Data) ((This)->lpVtbl->OnResponseDataAvailable(This, Data)) + +#define IWinHttpRequestEvents_OnResponseFinished(This) ((This)->lpVtbl->OnResponseFinished(This)) + +#define IWinHttpRequestEvents_OnError(This, ErrorNumber, ErrorDescription) ((This)->lpVtbl->OnError(This, ErrorNumber, ErrorDescription)) + +#endif /* COBJMACROS */ + +#endif /* C style interface */ + +#endif /* __IWinHttpRequestEvents_INTERFACE_DEFINED__ */ + +EXTERN_C const CLSID CLSID_WinHttpRequest; + +#ifdef __cplusplus + +class DECLSPEC_UUID("2087c2f4-2cef-4953-a8ab-66779b670495") WinHttpRequest; +#endif +#endif /* __WinHttp_LIBRARY_DEFINED__ */ + +/* interface __MIDL_itf_httprequest_0000_0001 */ +/* [local] */ + +#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) */ +#pragma endregion + +extern RPC_IF_HANDLE __MIDL_itf_httprequest_0000_0001_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_httprequest_0000_0001_v0_0_s_ifspec; + +/* Additional Prototypes for ALL interfaces */ + +/* end of Additional Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/crash-handler-process/platforms/httprequest_i.c b/crash-handler-process/platforms/httprequest_i.c new file mode 100644 index 0000000..9d84027 --- /dev/null +++ b/crash-handler-process/platforms/httprequest_i.c @@ -0,0 +1,77 @@ + + +/* this ALWAYS GENERATED file contains the IIDs and CLSIDs */ + +/* link this file in with the server and any clients */ + +/* File created by MIDL compiler version 8.01.0626 */ +/* at Mon Jan 18 22:14:07 2038 + */ +/* Compiler settings for httprequest.idl: + Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0626 + protocol : dce , ms_ext, c_ext, robust + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +/* @@MIDL_FILE_HEADING( ) */ + +#pragma warning(disable : 4049) /* more than 64k source lines */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef _MIDL_USE_GUIDDEF_ + +#ifndef INITGUID +#define INITGUID +#include +#undef INITGUID +#else +#include +#endif + +#define MIDL_DEFINE_GUID(type, name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) + +#else // !_MIDL_USE_GUIDDEF_ + +#ifndef __IID_DEFINED__ +#define __IID_DEFINED__ + +typedef struct _IID { + unsigned long x; + unsigned short s1; + unsigned short s2; + unsigned char c[8]; +} IID; + +#endif // __IID_DEFINED__ + +#ifndef CLSID_DEFINED +#define CLSID_DEFINED +typedef IID CLSID; +#endif // CLSID_DEFINED + +#define MIDL_DEFINE_GUID(type, name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + EXTERN_C __declspec(selectany) const type name = {l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}} + +#endif // !_MIDL_USE_GUIDDEF_ + +MIDL_DEFINE_GUID(IID, LIBID_WinHttp, 0x662901fc, 0x6951, 0x4854, 0x9e, 0xb2, 0xd9, 0xa2, 0x57, 0x0f, 0x2b, 0x2e); + +MIDL_DEFINE_GUID(IID, IID_IWinHttpRequest, 0x016fe2ec, 0xb2c8, 0x45f8, 0xb2, 0x3b, 0x39, 0xe5, 0x3a, 0x75, 0x39, 0x6b); + +MIDL_DEFINE_GUID(IID, IID_IWinHttpRequestEvents, 0xf97f4e15, 0xb787, 0x4212, 0x80, 0xd1, 0xd3, 0x80, 0xcb, 0xbf, 0x98, 0x2e); + +MIDL_DEFINE_GUID(CLSID, CLSID_WinHttpRequest, 0x2087c2f4, 0x2cef, 0x4953, 0xa8, 0xab, 0x66, 0x77, 0x9b, 0x67, 0x04, 0x95); + +#undef MIDL_DEFINE_GUID + +#ifdef __cplusplus +} +#endif