From 961fd91323271704b0cd503bc1efe633f3b07442 Mon Sep 17 00:00:00 2001 From: Eugen <97041180+eugen15@users.noreply.github.com> Date: Tue, 18 Apr 2023 15:58:12 -0400 Subject: [PATCH 01/10] Upload brief crash info (Windows only) --- crash-handler-process/CMakeLists.txt | 6 +- .../brief-crash-info-uploader.cpp | 118 +++ .../brief-crash-info-uploader.hpp | 41 + .../crash-handler-process.exe.txt | Bin 866 -> 948 bytes crash-handler-process/http-helper.hpp | 64 ++ crash-handler-process/main.cpp | 24 +- .../platforms/http-helper-win.cpp | 186 +++++ .../platforms/http-helper-win.hpp | 45 ++ crash-handler-process/platforms/httprequest.h | 700 ++++++++++++++++++ .../platforms/httprequest_i.c | 88 +++ 10 files changed, 1269 insertions(+), 3 deletions(-) create mode 100644 crash-handler-process/brief-crash-info-uploader.cpp create mode 100644 crash-handler-process/brief-crash-info-uploader.hpp create mode 100644 crash-handler-process/http-helper.hpp create mode 100644 crash-handler-process/platforms/http-helper-win.cpp create mode 100644 crash-handler-process/platforms/http-helper-win.hpp create mode 100644 crash-handler-process/platforms/httprequest.h create mode 100644 crash-handler-process/platforms/httprequest_i.c diff --git a/crash-handler-process/CMakeLists.txt b/crash-handler-process/CMakeLists.txt index 3ff8461..92e7e1b 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" 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..6e14bcf --- /dev/null +++ b/crash-handler-process/brief-crash-info-uploader.cpp @@ -0,0 +1,118 @@ +/****************************************************************************** + 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; + + auto httpHelper = HttpHelper::Create(); + HttpHelper::Result result = httpHelper->PostRequest("https://httpbin.org/post", + requestHeaders, json, &responseHeaders, &response); + + log_info << "Brief crash info upload result (0 means SUCCESS): " << static_cast(result) << 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; + } +} \ No newline at end of file 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..d2780ef --- /dev/null +++ b/crash-handler-process/brief-crash-info-uploader.hpp @@ -0,0 +1,41 @@ +/****************************************************************************** + 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; + +}; \ No newline at end of file diff --git a/crash-handler-process/dependencies/crash-handler-process.exe.txt b/crash-handler-process/dependencies/crash-handler-process.exe.txt index a5603d0df7e4e67fc58fd34dacdf0b9d0dad904a..ca0cdfeb3aa98a013e897c6dc29535dc45a100f5 100644 GIT binary patch delta 40 ucmaFFwuOCz1@puO9IW{aISi?j=QAmC`!o13xH330gffHx`I3_@n6&`#MhbiY delta 11 ScmdnO{)laZ1@q)CW-S03cmvr0 diff --git a/crash-handler-process/http-helper.hpp b/crash-handler-process/http-helper.hpp new file mode 100644 index 0000000..6adde66 --- /dev/null +++ b/crash-handler-process/http-helper.hpp @@ -0,0 +1,64 @@ +/****************************************************************************** + 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, Headers* responseHeaders, std::string* response) = 0; + + virtual Result GetRequest(std::string_view url, const Headers& requestHeaders, + Headers* responseHeaders, std::string* response) = 0; + + virtual Result PostRequest(std::string_view url, const Headers& requestHeaders, + std::string_view body, 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..5cf2e97 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 + +#if defined(_WIN32) +#include "brief-crash-info-uploader.hpp" +#endif #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,32 @@ 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); +#if defined(_WIN32) + BriefCrashInfoUploader(appData_path).Run(); +#endif + } 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-win.cpp b/crash-handler-process/platforms/http-helper-win.cpp new file mode 100644 index 0000000..ff0a9a5 --- /dev/null +++ b/crash-handler-process/platforms/http-helper-win.cpp @@ -0,0 +1,186 @@ +/****************************************************************************** + 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, 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 (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, + Headers* responseHeaders, std::string* response) +{ + return Request(Method::Get, url, requestHeaders, "", responseHeaders, response); +} + +HttpHelper::Result HttpHelper_WIN::PostRequest(std::string_view url, const Headers& requestHeaders, + std::string_view body, Headers* responseHeaders, std::string* response) +{ + return Request(Method::Post, url, requestHeaders, body, 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..7beb5c8 --- /dev/null +++ b/crash-handler-process/platforms/http-helper-win.hpp @@ -0,0 +1,45 @@ +/****************************************************************************** + 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, Headers* responseHeaders, std::string* response) override; + + Result GetRequest(std::string_view url, const Headers& requestHeaders, + Headers* responseHeaders, std::string* response) override; + + Result PostRequest(std::string_view url, const Headers& requestHeaders, + std::string_view body, 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..f961cd6 --- /dev/null +++ b/crash-handler-process/platforms/httprequest.h @@ -0,0 +1,700 @@ + + +/* 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..e3aae6b --- /dev/null +++ b/crash-handler-process/platforms/httprequest_i.c @@ -0,0 +1,88 @@ + + +/* 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 + + + From a125cb02cb27381f03be052c11389d8f2ee5132b Mon Sep 17 00:00:00 2001 From: Eugen <97041180+eugen15@users.noreply.github.com> Date: Tue, 18 Apr 2023 16:06:37 -0400 Subject: [PATCH 02/10] Clang format --- .../brief-crash-info-uploader.cpp | 42 +- .../brief-crash-info-uploader.hpp | 19 +- crash-handler-process/http-helper.hpp | 47 +- .../platforms/http-helper-win.cpp | 242 +++-- .../platforms/http-helper-win.hpp | 19 +- crash-handler-process/platforms/httprequest.h | 889 ++++++++---------- .../platforms/httprequest_i.c | 43 +- 7 files changed, 578 insertions(+), 723 deletions(-) diff --git a/crash-handler-process/brief-crash-info-uploader.cpp b/crash-handler-process/brief-crash-info-uploader.cpp index 6e14bcf..a1c707f 100644 --- a/crash-handler-process/brief-crash-info-uploader.cpp +++ b/crash-handler-process/brief-crash-info-uploader.cpp @@ -36,8 +36,7 @@ std::string_view g_pathSeparator("/"); std::string_view g_briefCrashDataFilename("brief-crash-info.json"); -BriefCrashInfoUploader::BriefCrashInfoUploader(const std::string& appDataPath) - : m_filename(appDataPath) +BriefCrashInfoUploader::BriefCrashInfoUploader(const std::string &appDataPath) : m_filename(appDataPath) { if (*m_filename.rbegin() != '/' && *m_filename.rbegin() != '\\') { m_filename += g_pathSeparator; @@ -45,16 +44,14 @@ BriefCrashInfoUploader::BriefCrashInfoUploader(const std::string& appDataPath) m_filename += g_briefCrashDataFilename; } -BriefCrashInfoUploader::~BriefCrashInfoUploader() -{ -} +BriefCrashInfoUploader::~BriefCrashInfoUploader() {} void BriefCrashInfoUploader::Run(std::int64_t maxFileWaitTimeMs) { std::string json = ProcessBriefCrashInfoJson(maxFileWaitTimeMs); - if (json.size()) { - UploadJson(json); - } + if (json.size()) { + UploadJson(json); + } } std::string BriefCrashInfoUploader::ProcessBriefCrashInfoJson(std::int64_t maxFileWaitTimeMs) @@ -65,7 +62,7 @@ std::string BriefCrashInfoUploader::ProcessBriefCrashInfoJson(std::int64_t maxFi std::int64_t realFileWaitTimeMs = 0; while (realFileWaitTimeMs < maxFileWaitTimeMs) { if (std::filesystem::exists(briefCrashInfoPath) && std::filesystem::is_regular_file(briefCrashInfoPath)) { - json = LoadBriefCrashInfoJson(); + json = LoadBriefCrashInfoJson(); std::filesystem::remove(briefCrashInfoPath); log_info << "The brief crash info file has been loaded." << std::endl; break; @@ -81,23 +78,23 @@ std::string BriefCrashInfoUploader::ProcessBriefCrashInfoJson(std::int64_t maxFi std::string BriefCrashInfoUploader::LoadBriefCrashInfoJson() { #if defined(_WIN32) - std::wstring_convert> converter; - std::ifstream file(converter.from_bytes(m_filename)); + std::wstring_convert> converter; + std::ifstream file(converter.from_bytes(m_filename)); #else - std::ifstream file(m_filename); + std::ifstream file(m_filename); #endif - file.seekg(0, std::ios::end); - size_t fileSize = file.tellg(); + 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(); + std::string buffer(fileSize, ' '); + file.seekg(0); + file.read(&buffer.front(), fileSize); + file.close(); - return buffer; + return buffer; } -void BriefCrashInfoUploader::UploadJson(const std::string& json) +void BriefCrashInfoUploader::UploadJson(const std::string &json) { log_info << "Uploading the brief crash info..." << std::endl; @@ -106,13 +103,12 @@ void BriefCrashInfoUploader::UploadJson(const std::string& json) std::string response; auto httpHelper = HttpHelper::Create(); - HttpHelper::Result result = httpHelper->PostRequest("https://httpbin.org/post", - requestHeaders, json, &responseHeaders, &response); + HttpHelper::Result result = httpHelper->PostRequest("https://httpbin.org/post", requestHeaders, json, &responseHeaders, &response); log_info << "Brief crash info upload result (0 means SUCCESS): " << static_cast(result) << std::endl; log_info << "Brief crash info upload response: " << response << std::endl; - for (const auto& [header, value] : responseHeaders) { + for (const auto &[header, value] : responseHeaders) { log_info << "Brief crash info upload response header: " << header << " = " << value << std::endl; } } \ No newline at end of file diff --git a/crash-handler-process/brief-crash-info-uploader.hpp b/crash-handler-process/brief-crash-info-uploader.hpp index d2780ef..73d759f 100644 --- a/crash-handler-process/brief-crash-info-uploader.hpp +++ b/crash-handler-process/brief-crash-info-uploader.hpp @@ -22,20 +22,17 @@ #include #include -class BriefCrashInfoUploader final -{ +class BriefCrashInfoUploader final { public: + BriefCrashInfoUploader(const std::string &appDataPath); + ~BriefCrashInfoUploader(); - BriefCrashInfoUploader(const std::string& appDataPath); - ~BriefCrashInfoUploader(); - - void Run(std::int64_t maxFileWaitTimeMs = 10000); + 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; + std::string ProcessBriefCrashInfoJson(std::int64_t maxFileWaitTimeMs); + std::string LoadBriefCrashInfoJson(); + void UploadJson(const std::string &json); + std::string m_filename; }; \ No newline at end of file diff --git a/crash-handler-process/http-helper.hpp b/crash-handler-process/http-helper.hpp index 6adde66..13fbc49 100644 --- a/crash-handler-process/http-helper.hpp +++ b/crash-handler-process/http-helper.hpp @@ -24,41 +24,30 @@ #include #include -class HttpHelper -{ +class HttpHelper { public: + enum class Result { + Success = 0, + InvalidParam, + CouldNotInit, + ConnectFailed, + RequestFailed, + ResponseFailed, + }; - enum class Result - { - Success = 0, - InvalidParam, - CouldNotInit, - ConnectFailed, - RequestFailed, - ResponseFailed, - }; + enum class Method { Undefined = 0, Get, Post }; - enum class Method - { - Undefined = 0, - Get, - Post - }; + using Headers = std::map; - using Headers = std::map; + static std::unique_ptr Create(); - static std::unique_ptr Create(); + virtual ~HttpHelper() {} - virtual ~HttpHelper() {} - - virtual Result Request(Method method, std::string_view url, const Headers& requestHeaders, - std::string_view body, Headers* responseHeaders, std::string* response) = 0; - - virtual Result GetRequest(std::string_view url, const Headers& requestHeaders, - Headers* responseHeaders, std::string* response) = 0; - - virtual Result PostRequest(std::string_view url, const Headers& requestHeaders, - std::string_view body, Headers* responseHeaders, std::string* response) = 0; + virtual Result Request(Method method, std::string_view url, const Headers &requestHeaders, std::string_view body, Headers *responseHeaders, + std::string *response) = 0; + virtual Result GetRequest(std::string_view url, const Headers &requestHeaders, Headers *responseHeaders, std::string *response) = 0; + virtual Result PostRequest(std::string_view url, const Headers &requestHeaders, std::string_view body, Headers *responseHeaders, + std::string *response) = 0; }; \ 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 index ff0a9a5..2c5a1cc 100644 --- a/crash-handler-process/platforms/http-helper-win.cpp +++ b/crash-handler-process/platforms/http-helper-win.cpp @@ -49,138 +49,134 @@ std::wstring from_utf8_to_utf16_wide(const char *from, size_t length = -1); std::unique_ptr HttpHelper::Create() { - return std::make_unique(); + return std::make_unique(); } -HttpHelper_WIN::HttpHelper_WIN() -{ +HttpHelper_WIN::HttpHelper_WIN() {} -} +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, 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 (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::Request(Method method, std::string_view url, const Headers& requestHeaders, - std::string_view body, Headers* responseHeaders, std::string* response) +HttpHelper::Result HttpHelper_WIN::GetRequest(std::string_view url, const Headers &requestHeaders, 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 (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; + return Request(Method::Get, url, requestHeaders, "", responseHeaders, response); } -HttpHelper::Result HttpHelper_WIN::GetRequest(std::string_view url, const Headers& requestHeaders, - Headers* responseHeaders, std::string* response) +HttpHelper::Result HttpHelper_WIN::PostRequest(std::string_view url, const Headers &requestHeaders, std::string_view body, Headers *responseHeaders, + std::string *response) { - return Request(Method::Get, url, requestHeaders, "", responseHeaders, response); + return Request(Method::Post, url, requestHeaders, body, responseHeaders, response); } - -HttpHelper::Result HttpHelper_WIN::PostRequest(std::string_view url, const Headers& requestHeaders, - std::string_view body, Headers* responseHeaders, std::string* response) -{ - return Request(Method::Post, url, requestHeaders, body, responseHeaders, response); -} - diff --git a/crash-handler-process/platforms/http-helper-win.hpp b/crash-handler-process/platforms/http-helper-win.hpp index 7beb5c8..8302ed3 100644 --- a/crash-handler-process/platforms/http-helper-win.hpp +++ b/crash-handler-process/platforms/http-helper-win.hpp @@ -27,19 +27,16 @@ #include "../http-helper.hpp" -class HttpHelper_WIN : public HttpHelper -{ +class HttpHelper_WIN : public HttpHelper { public: + HttpHelper_WIN(); + ~HttpHelper_WIN() override; - HttpHelper_WIN(); - ~HttpHelper_WIN() override; + Result Request(Method method, std::string_view url, const Headers &requestHeaders, std::string_view body, Headers *responseHeaders, + std::string *response) override; - Result Request(Method method, std::string_view url, const Headers& requestHeaders, - std::string_view body, Headers* responseHeaders, std::string* response) override; + Result GetRequest(std::string_view url, const Headers &requestHeaders, Headers *responseHeaders, std::string *response) override; - Result GetRequest(std::string_view url, const Headers& requestHeaders, - Headers* responseHeaders, std::string* response) override; - - Result PostRequest(std::string_view url, const Headers& requestHeaders, - std::string_view body, Headers* responseHeaders, std::string* response) override; + Result PostRequest(std::string_view url, const Headers &requestHeaders, std::string_view body, 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 index f961cd6..6cada67 100644 --- a/crash-handler-process/platforms/httprequest.h +++ b/crash-handler-process/platforms/httprequest.h @@ -2,8 +2,7 @@ /* this ALWAYS GENERATED file contains the definitions for the interfaces */ - - /* File created by MIDL compiler version 8.01.0626 */ +/* File created by MIDL compiler version 8.01.0626 */ /* at Mon Jan 18 22:14:07 2038 */ /* Compiler settings for httprequest.idl: @@ -16,8 +15,7 @@ */ /* @@MIDL_FILE_HEADING( ) */ -#pragma warning( disable: 4049 ) /* more than 64k source lines */ - +#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__ @@ -31,7 +29,6 @@ #error this stub requires an updated version of #endif /* __RPCNDR_H_VERSION__ */ - #ifndef __httprequest_h__ #define __httprequest_h__ @@ -47,21 +44,19 @@ #endif #endif -/* Forward Declarations */ +/* Forward Declarations */ #ifndef __IWinHttpRequest_FWD_DEFINED__ #define __IWinHttpRequest_FWD_DEFINED__ typedef interface IWinHttpRequest IWinHttpRequest; -#endif /* __IWinHttpRequest_FWD_DEFINED__ */ - +#endif /* __IWinHttpRequest_FWD_DEFINED__ */ #ifndef __IWinHttpRequestEvents_FWD_DEFINED__ #define __IWinHttpRequestEvents_FWD_DEFINED__ typedef interface IWinHttpRequestEvents IWinHttpRequestEvents; -#endif /* __IWinHttpRequestEvents_FWD_DEFINED__ */ - +#endif /* __IWinHttpRequestEvents_FWD_DEFINED__ */ #ifndef __WinHttpRequest_FWD_DEFINED__ #define __WinHttpRequest_FWD_DEFINED__ @@ -72,16 +67,14 @@ typedef class WinHttpRequest WinHttpRequest; typedef struct WinHttpRequest WinHttpRequest; #endif /* __cplusplus */ -#endif /* __WinHttpRequest_FWD_DEFINED__ */ - +#endif /* __WinHttpRequest_FWD_DEFINED__ */ #ifdef __cplusplus -extern "C"{ -#endif - +extern "C" { +#endif /* interface __MIDL_itf_httprequest_0000_0000 */ -/* [local] */ +/* [local] */ //+------------------------------------------------------------------------- // @@ -93,97 +86,86 @@ extern "C"{ #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 warning(disable : 4001) #pragma once #pragma warning(push) -#pragma warning(disable:4001) +#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] */ +/* [version][lcid][helpstring][uuid] */ typedef /* [public] */ long HTTPREQUEST_PROXY_SETTING; -#define HTTPREQUEST_PROXYSETTING_DEFAULT ( 0 ) +#define HTTPREQUEST_PROXYSETTING_DEFAULT (0) -#define HTTPREQUEST_PROXYSETTING_PRECONFIG ( 0 ) +#define HTTPREQUEST_PROXYSETTING_PRECONFIG (0) -#define HTTPREQUEST_PROXYSETTING_DIRECT ( 0x1 ) +#define HTTPREQUEST_PROXYSETTING_DIRECT (0x1) -#define HTTPREQUEST_PROXYSETTING_PROXY ( 0x2 ) +#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; - +#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; @@ -191,499 +173,410 @@ EXTERN_C const IID LIBID_WinHttp; #define __IWinHttpRequest_INTERFACE_DEFINED__ /* interface IWinHttpRequest */ -/* [unique][helpstring][nonextensible][oleautomation][dual][uuid][object] */ - +/* [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 +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; -#define IWinHttpRequest_QueryInterface(This,riid,ppvObject) \ - ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + 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; +}; -#define IWinHttpRequest_AddRef(This) \ - ( (This)->lpVtbl -> AddRef(This) ) +#ifdef COBJMACROS -#define IWinHttpRequest_Release(This) \ - ( (This)->lpVtbl -> Release(This) ) +#define IWinHttpRequest_QueryInterface(This, riid, ppvObject) ((This)->lpVtbl->QueryInterface(This, riid, ppvObject)) +#define IWinHttpRequest_AddRef(This) ((This)->lpVtbl->AddRef(This)) -#define IWinHttpRequest_GetTypeInfoCount(This,pctinfo) \ - ( (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) ) +#define IWinHttpRequest_Release(This) ((This)->lpVtbl->Release(This)) -#define IWinHttpRequest_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ - ( (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) ) +#define IWinHttpRequest_GetTypeInfoCount(This, pctinfo) ((This)->lpVtbl->GetTypeInfoCount(This, pctinfo)) -#define IWinHttpRequest_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ - ( (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) ) +#define IWinHttpRequest_GetTypeInfo(This, iTInfo, lcid, ppTInfo) ((This)->lpVtbl->GetTypeInfo(This, iTInfo, lcid, ppTInfo)) -#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_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_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_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_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_SetRequestHeader(This, Header, Value) ((This)->lpVtbl->SetRequestHeader(This, Header, Value)) -#define IWinHttpRequest_GetResponseHeader(This,Header,Value) \ - ( (This)->lpVtbl -> GetResponseHeader(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_GetAllResponseHeaders(This, Headers) ((This)->lpVtbl->GetAllResponseHeaders(This, Headers)) -#define IWinHttpRequest_Send(This,Body) \ - ( (This)->lpVtbl -> Send(This,Body) ) +#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_Status(This, Status) ((This)->lpVtbl->get_Status(This, Status)) -#define IWinHttpRequest_get_StatusText(This,Status) \ - ( (This)->lpVtbl -> get_StatusText(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_ResponseText(This, Body) ((This)->lpVtbl->get_ResponseText(This, Body)) -#define IWinHttpRequest_get_ResponseBody(This,Body) \ - ( (This)->lpVtbl -> get_ResponseBody(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_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_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_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_WaitForResponse(This, Timeout, Succeeded) ((This)->lpVtbl->WaitForResponse(This, Timeout, Succeeded)) -#define IWinHttpRequest_Abort(This) \ - ( (This)->lpVtbl -> Abort(This) ) +#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_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_SetClientCertificate(This, ClientCertificate) ((This)->lpVtbl->SetClientCertificate(This, ClientCertificate)) -#define IWinHttpRequest_SetAutoLogonPolicy(This,AutoLogonPolicy) \ - ( (This)->lpVtbl -> SetAutoLogonPolicy(This,AutoLogonPolicy) ) +#define IWinHttpRequest_SetAutoLogonPolicy(This, AutoLogonPolicy) ((This)->lpVtbl->SetAutoLogonPolicy(This, AutoLogonPolicy)) #endif /* COBJMACROS */ +#endif /* C style interface */ -#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; -#endif /* __IWinHttpRequest_INTERFACE_DEFINED__ */ +#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; -#ifndef __IWinHttpRequestEvents_INTERFACE_DEFINED__ -#define __IWinHttpRequestEvents_INTERFACE_DEFINED__ + virtual void STDMETHODCALLTYPE OnResponseDataAvailable( + /* [in] */ SAFEARRAY * *Data) = 0; -/* interface IWinHttpRequestEvents */ -/* [unique][helpstring][nonextensible][oleautomation][uuid][object] */ + virtual void STDMETHODCALLTYPE OnResponseFinished(void) = 0; + virtual void STDMETHODCALLTYPE OnError( + /* [in] */ long ErrorNumber, + /* [in] */ BSTR ErrorDescription) = 0; +}; -EXTERN_C const IID IID_IWinHttpRequestEvents; +#else /* C style interface */ -#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; - }; - - +typedef struct IWinHttpRequestEventsVtbl { + BEGIN_INTERFACE -#ifdef COBJMACROS + 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); -#define IWinHttpRequestEvents_QueryInterface(This,riid,ppvObject) \ - ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + DECLSPEC_XFGVIRT(IUnknown, Release) + ULONG(STDMETHODCALLTYPE *Release)(IWinHttpRequestEvents *This); -#define IWinHttpRequestEvents_AddRef(This) \ - ( (This)->lpVtbl -> AddRef(This) ) + DECLSPEC_XFGVIRT(IWinHttpRequestEvents, OnResponseStart) + void(STDMETHODCALLTYPE *OnResponseStart)(IWinHttpRequestEvents *This, + /* [in] */ long Status, + /* [in] */ BSTR ContentType); -#define IWinHttpRequestEvents_Release(This) \ - ( (This)->lpVtbl -> Release(This) ) + DECLSPEC_XFGVIRT(IWinHttpRequestEvents, OnResponseDataAvailable) + void(STDMETHODCALLTYPE *OnResponseDataAvailable)(IWinHttpRequestEvents *This, + /* [in] */ SAFEARRAY **Data); + DECLSPEC_XFGVIRT(IWinHttpRequestEvents, OnResponseFinished) + void(STDMETHODCALLTYPE *OnResponseFinished)(IWinHttpRequestEvents *This); -#define IWinHttpRequestEvents_OnResponseStart(This,Status,ContentType) \ - ( (This)->lpVtbl -> OnResponseStart(This,Status,ContentType) ) + DECLSPEC_XFGVIRT(IWinHttpRequestEvents, OnError) + void(STDMETHODCALLTYPE *OnError)(IWinHttpRequestEvents *This, + /* [in] */ long ErrorNumber, + /* [in] */ BSTR ErrorDescription); -#define IWinHttpRequestEvents_OnResponseDataAvailable(This,Data) \ - ( (This)->lpVtbl -> OnResponseDataAvailable(This,Data) ) + END_INTERFACE +} IWinHttpRequestEventsVtbl; -#define IWinHttpRequestEvents_OnResponseFinished(This) \ - ( (This)->lpVtbl -> OnResponseFinished(This) ) +interface IWinHttpRequestEvents { + CONST_VTBL struct IWinHttpRequestEventsVtbl *lpVtbl; +}; -#define IWinHttpRequestEvents_OnError(This,ErrorNumber,ErrorDescription) \ - ( (This)->lpVtbl -> OnError(This,ErrorNumber,ErrorDescription) ) +#ifdef COBJMACROS -#endif /* 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)) -#endif /* C style interface */ +#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 /* __IWinHttpRequestEvents_INTERFACE_DEFINED__ */ +#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; +class DECLSPEC_UUID("2087c2f4-2cef-4953-a8ab-66779b670495") WinHttpRequest; #endif #endif /* __WinHttp_LIBRARY_DEFINED__ */ /* interface __MIDL_itf_httprequest_0000_0001 */ -/* [local] */ +/* [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; @@ -696,5 +589,3 @@ extern RPC_IF_HANDLE __MIDL_itf_httprequest_0000_0001_v0_0_s_ifspec; #endif #endif - - diff --git a/crash-handler-process/platforms/httprequest_i.c b/crash-handler-process/platforms/httprequest_i.c index e3aae6b..9d84027 100644 --- a/crash-handler-process/platforms/httprequest_i.c +++ b/crash-handler-process/platforms/httprequest_i.c @@ -4,8 +4,7 @@ /* link this file in with the server and any clients */ - - /* File created by MIDL compiler version 8.01.0626 */ +/* File created by MIDL compiler version 8.01.0626 */ /* at Mon Jan 18 22:14:07 2038 */ /* Compiler settings for httprequest.idl: @@ -18,13 +17,11 @@ */ /* @@MIDL_FILE_HEADING( ) */ -#pragma warning( disable: 4049 ) /* more than 64k source lines */ - +#pragma warning(disable : 4049) /* more than 64k source lines */ #ifdef __cplusplus -extern "C"{ -#endif - +extern "C" { +#endif #include #include @@ -39,20 +36,18 @@ extern "C"{ #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) +#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]; +typedef struct _IID { + unsigned long x; + unsigned short s1; + unsigned short s2; + unsigned char c[8]; } IID; #endif // __IID_DEFINED__ @@ -62,27 +57,21 @@ typedef struct _IID 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}} +#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, 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_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(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); +MIDL_DEFINE_GUID(CLSID, CLSID_WinHttpRequest, 0x2087c2f4, 0x2cef, 0x4953, 0xa8, 0xab, 0x66, 0x77, 0x9b, 0x67, 0x04, 0x95); #undef MIDL_DEFINE_GUID #ifdef __cplusplus } #endif - - - From b6c07d7183b2df47bba8118936fae4f5db23df99 Mon Sep 17 00:00:00 2001 From: Eugen <97041180+eugen15@users.noreply.github.com> Date: Tue, 18 Apr 2023 16:10:12 -0400 Subject: [PATCH 03/10] Temporary macOS compilation fix --- crash-handler-process/brief-crash-info-uploader.cpp | 6 +++++- crash-handler-process/brief-crash-info-uploader.hpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crash-handler-process/brief-crash-info-uploader.cpp b/crash-handler-process/brief-crash-info-uploader.cpp index a1c707f..6d2bcd9 100644 --- a/crash-handler-process/brief-crash-info-uploader.cpp +++ b/crash-handler-process/brief-crash-info-uploader.cpp @@ -36,6 +36,8 @@ std::string_view g_pathSeparator("/"); std::string_view g_briefCrashDataFilename("brief-crash-info.json"); +#if defined(_WIN32) + BriefCrashInfoUploader::BriefCrashInfoUploader(const std::string &appDataPath) : m_filename(appDataPath) { if (*m_filename.rbegin() != '/' && *m_filename.rbegin() != '\\') { @@ -111,4 +113,6 @@ void BriefCrashInfoUploader::UploadJson(const std::string &json) for (const auto &[header, value] : responseHeaders) { log_info << "Brief crash info upload response header: " << header << " = " << value << std::endl; } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/crash-handler-process/brief-crash-info-uploader.hpp b/crash-handler-process/brief-crash-info-uploader.hpp index 73d759f..a70bb03 100644 --- a/crash-handler-process/brief-crash-info-uploader.hpp +++ b/crash-handler-process/brief-crash-info-uploader.hpp @@ -22,6 +22,8 @@ #include #include +#if defined(_WIN32) + class BriefCrashInfoUploader final { public: BriefCrashInfoUploader(const std::string &appDataPath); @@ -35,4 +37,6 @@ class BriefCrashInfoUploader final { void UploadJson(const std::string &json); std::string m_filename; -}; \ No newline at end of file +}; + +#endif \ No newline at end of file From 6f510235bfba0dfe105eba88d2473c916b792a4f Mon Sep 17 00:00:00 2001 From: Eugen <97041180+eugen15@users.noreply.github.com> Date: Thu, 27 Apr 2023 16:44:08 -0400 Subject: [PATCH 04/10] macos --- crash-handler-process/CMakeLists.txt | 2 +- .../brief-crash-info-uploader.cpp | 7 +- .../brief-crash-info-uploader.hpp | 4 - crash-handler-process/http-helper.hpp | 6 +- crash-handler-process/main.cpp | 17 ++- .../platforms/http-helper-osx.hpp | 40 ++++++ .../platforms/http-helper-osx.mm | 126 ++++++++++++++++++ .../platforms/http-helper-win.cpp | 10 +- .../platforms/http-helper-win.hpp | 9 +- 9 files changed, 196 insertions(+), 25 deletions(-) create mode 100644 crash-handler-process/platforms/http-helper-osx.hpp create mode 100644 crash-handler-process/platforms/http-helper-osx.mm diff --git a/crash-handler-process/CMakeLists.txt b/crash-handler-process/CMakeLists.txt index 92e7e1b..dcd3fe2 100644 --- a/crash-handler-process/CMakeLists.txt +++ b/crash-handler-process/CMakeLists.txt @@ -64,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 index 6d2bcd9..05d5d8d 100644 --- a/crash-handler-process/brief-crash-info-uploader.cpp +++ b/crash-handler-process/brief-crash-info-uploader.cpp @@ -36,8 +36,6 @@ std::string_view g_pathSeparator("/"); std::string_view g_briefCrashDataFilename("brief-crash-info.json"); -#if defined(_WIN32) - BriefCrashInfoUploader::BriefCrashInfoUploader(const std::string &appDataPath) : m_filename(appDataPath) { if (*m_filename.rbegin() != '/' && *m_filename.rbegin() != '\\') { @@ -104,8 +102,10 @@ void BriefCrashInfoUploader::UploadJson(const std::string &json) 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, &responseHeaders, &response); + 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 response: " << response << std::endl; @@ -115,4 +115,3 @@ void BriefCrashInfoUploader::UploadJson(const std::string &json) } } -#endif \ No newline at end of file diff --git a/crash-handler-process/brief-crash-info-uploader.hpp b/crash-handler-process/brief-crash-info-uploader.hpp index a70bb03..04c8bd5 100644 --- a/crash-handler-process/brief-crash-info-uploader.hpp +++ b/crash-handler-process/brief-crash-info-uploader.hpp @@ -22,8 +22,6 @@ #include #include -#if defined(_WIN32) - class BriefCrashInfoUploader final { public: BriefCrashInfoUploader(const std::string &appDataPath); @@ -38,5 +36,3 @@ class BriefCrashInfoUploader final { std::string m_filename; }; - -#endif \ No newline at end of file diff --git a/crash-handler-process/http-helper.hpp b/crash-handler-process/http-helper.hpp index 13fbc49..9a8bcda 100644 --- a/crash-handler-process/http-helper.hpp +++ b/crash-handler-process/http-helper.hpp @@ -43,11 +43,11 @@ class HttpHelper { virtual ~HttpHelper() {} - virtual Result Request(Method method, std::string_view url, const Headers &requestHeaders, std::string_view body, Headers *responseHeaders, + 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, 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, Headers *responseHeaders, + 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 5cf2e97..4def09d 100644 --- a/crash-handler-process/main.cpp +++ b/crash-handler-process/main.cpp @@ -22,9 +22,9 @@ #include #include -#if defined(_WIN32) #include "brief-crash-info-uploader.hpp" -#endif + +#include "http-helper.hpp" #if defined(WIN32) const std::string log_file_name = "\\crash-handler.log"; @@ -111,12 +111,21 @@ int main(int argc, char **argv) if (pm->m_applicationCrashed) { pm->handleCrash(path); -#if defined(_WIN32) BriefCrashInfoUploader(appData_path).Run(); -#endif } delete pm; + + /*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, "{\"id\":\"qqqq\"}", &statusCode, &responseHeaders, &response);*/ + log_info << "=== Terminating CrashHandler ===" << std::endl; logging_end(); 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..31d2dd2 --- /dev/null +++ b/crash-handler-process/platforms/http-helper-osx.hpp @@ -0,0 +1,40 @@ +/****************************************************************************** + 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..e0cc7a7 --- /dev/null +++ b/crash-handler-process/platforms/http-helper-osx.mm @@ -0,0 +1,126 @@ +/****************************************************************************** + 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]; + + NSURLSessionDataTask *dataTask = + [session dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *resp, NSError *error) + { + 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])); + log_info << "HEADER: " << [key UTF8String] << " > " << [value UTF8String] << std::endl; + } + } + } + } + } + + 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); + + 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 index 2c5a1cc..035f319 100644 --- a/crash-handler-process/platforms/http-helper-win.cpp +++ b/crash-handler-process/platforms/http-helper-win.cpp @@ -56,7 +56,7 @@ 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, Headers *responseHeaders, +HttpHelper::Result HttpHelper_WIN::Request(Method method, std::string_view url, const Headers &requestHeaders, std::string_view body, std::uint32_t* statucCode, Headers *responseHeaders, std::string *response) { VARIANT varFalse; @@ -170,13 +170,13 @@ HttpHelper::Result HttpHelper_WIN::Request(Method method, std::string_view url, return Result::Success; } -HttpHelper::Result HttpHelper_WIN::GetRequest(std::string_view url, const Headers &requestHeaders, Headers *responseHeaders, std::string *response) +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, "", responseHeaders, 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, Headers *responseHeaders, +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, responseHeaders, 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 index 8302ed3..32f37e0 100644 --- a/crash-handler-process/platforms/http-helper-win.hpp +++ b/crash-handler-process/platforms/http-helper-win.hpp @@ -27,16 +27,17 @@ #include "../http-helper.hpp" -class HttpHelper_WIN : public HttpHelper { +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, Headers *responseHeaders, + 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, 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, Headers *responseHeaders, + 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 From 7db4eda3a31cab0f9c63efc3d617bd2c94d117c6 Mon Sep 17 00:00:00 2001 From: Eugen <97041180+eugen15@users.noreply.github.com> Date: Thu, 27 Apr 2023 16:47:27 -0400 Subject: [PATCH 05/10] clang format --- .../brief-crash-info-uploader.cpp | 1 - crash-handler-process/http-helper.hpp | 11 +- .../platforms/http-helper-osx.hpp | 14 +- .../platforms/http-helper-osx.mm | 157 +++++++++--------- .../platforms/http-helper-win.cpp | 11 +- .../platforms/http-helper-win.hpp | 12 +- 6 files changed, 102 insertions(+), 104 deletions(-) diff --git a/crash-handler-process/brief-crash-info-uploader.cpp b/crash-handler-process/brief-crash-info-uploader.cpp index 05d5d8d..377ceef 100644 --- a/crash-handler-process/brief-crash-info-uploader.cpp +++ b/crash-handler-process/brief-crash-info-uploader.cpp @@ -114,4 +114,3 @@ void BriefCrashInfoUploader::UploadJson(const std::string &json) log_info << "Brief crash info upload response header: " << header << " = " << value << std::endl; } } - diff --git a/crash-handler-process/http-helper.hpp b/crash-handler-process/http-helper.hpp index 9a8bcda..4ff10b9 100644 --- a/crash-handler-process/http-helper.hpp +++ b/crash-handler-process/http-helper.hpp @@ -43,11 +43,12 @@ class HttpHelper { 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 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 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; + 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/platforms/http-helper-osx.hpp b/crash-handler-process/platforms/http-helper-osx.hpp index 31d2dd2..8ba48d7 100644 --- a/crash-handler-process/platforms/http-helper-osx.hpp +++ b/crash-handler-process/platforms/http-helper-osx.hpp @@ -20,21 +20,19 @@ #include "../http-helper.hpp" -class HttpHelper_OSX : public HttpHelper -{ +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 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 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, + 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 index e0cc7a7..3e78290 100644 --- a/crash-handler-process/platforms/http-helper-osx.mm +++ b/crash-handler-process/platforms/http-helper-osx.mm @@ -35,92 +35,91 @@ return std::make_unique(); } -HttpHelper_OSX::HttpHelper_OSX() -{ - -} +HttpHelper_OSX::HttpHelper_OSX() {} -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) +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]; - - NSURLSessionDataTask *dataTask = - [session dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *resp, NSError *error) - { - 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])); - log_info << "HEADER: " << [key UTF8String] << " > " << [value UTF8String] << std::endl; - } - } - } - } - } - - 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); - - return Result::Success; + 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]; + + NSURLSessionDataTask *dataTask = [session + dataTaskWithRequest:urlRequest + completionHandler:^(NSData *data, NSURLResponse *resp, NSError *error) { + 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])); + log_info << "HEADER: " << [key UTF8String] << " > " << [value UTF8String] << std::endl; + } + } + } + } + } + + 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); + + 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) +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); + 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) +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); + 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 index 035f319..523903e 100644 --- a/crash-handler-process/platforms/http-helper-win.cpp +++ b/crash-handler-process/platforms/http-helper-win.cpp @@ -56,8 +56,8 @@ 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* statucCode, Headers *responseHeaders, - std::string *response) +HttpHelper::Result HttpHelper_WIN::Request(Method method, std::string_view url, const Headers &requestHeaders, std::string_view body, std::uint32_t *statucCode, + Headers *responseHeaders, std::string *response) { VARIANT varFalse; VariantInit(&varFalse); @@ -170,13 +170,14 @@ HttpHelper::Result HttpHelper_WIN::Request(Method method, std::string_view url, return Result::Success; } -HttpHelper::Result HttpHelper_WIN::GetRequest(std::string_view url, const Headers &requestHeaders, std::uint32_t* statusCode, Headers *responseHeaders, std::string *response) +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) +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 index 32f37e0..f5224fc 100644 --- a/crash-handler-process/platforms/http-helper-win.hpp +++ b/crash-handler-process/platforms/http-helper-win.hpp @@ -27,17 +27,17 @@ #include "../http-helper.hpp" -class HttpHelper_WIN : public HttpHelper -{ +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 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 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, + 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 From 8a9e680f141b5df821fd48306986dd2ccea688ac Mon Sep 17 00:00:00 2001 From: Eugen <97041180+eugen15@users.noreply.github.com> Date: Fri, 28 Apr 2023 13:39:06 -0400 Subject: [PATCH 06/10] removed some test code --- crash-handler-process/main.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/crash-handler-process/main.cpp b/crash-handler-process/main.cpp index 4def09d..b0dec70 100644 --- a/crash-handler-process/main.cpp +++ b/crash-handler-process/main.cpp @@ -116,16 +116,6 @@ int main(int argc, char **argv) delete pm; - /*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, "{\"id\":\"qqqq\"}", &statusCode, &responseHeaders, &response);*/ - log_info << "=== Terminating CrashHandler ===" << std::endl; logging_end(); From dba37796233f4b44a5e6a872550bb9a969176cf6 Mon Sep 17 00:00:00 2001 From: Eugen <97041180+eugen15@users.noreply.github.com> Date: Fri, 28 Apr 2023 16:07:36 -0400 Subject: [PATCH 07/10] fixed some macOS issues --- .../brief-crash-info-uploader.cpp | 1 + .../platforms/http-helper-osx.mm | 80 +++++++++++-------- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/crash-handler-process/brief-crash-info-uploader.cpp b/crash-handler-process/brief-crash-info-uploader.cpp index 377ceef..c72d440 100644 --- a/crash-handler-process/brief-crash-info-uploader.cpp +++ b/crash-handler-process/brief-crash-info-uploader.cpp @@ -108,6 +108,7 @@ void BriefCrashInfoUploader::UploadJson(const std::string &json) 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) { diff --git a/crash-handler-process/platforms/http-helper-osx.mm b/crash-handler-process/platforms/http-helper-osx.mm index 3e78290..3f60d44 100644 --- a/crash-handler-process/platforms/http-helper-osx.mm +++ b/crash-handler-process/platforms/http-helper-osx.mm @@ -70,45 +70,57 @@ NSURLSession *session = [NSURLSession sharedSession]; - NSURLSessionDataTask *dataTask = [session - dataTaskWithRequest:urlRequest - completionHandler:^(NSData *data, NSURLResponse *resp, NSError *error) { - 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])); - log_info << "HEADER: " << [key UTF8String] << " > " << [value UTF8String] << std::endl; - } - } - } - } - } - - if (response) { - response->clear(); - NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - if (responseString) { - response->append([responseString UTF8String]); - } - } - - dispatch_semaphore_signal(completionSemaphore); - }]; + 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; } From 36d2c4710b841b8c59add0c57cc717583d14d707 Mon Sep 17 00:00:00 2001 From: Eugen <97041180+eugen15@users.noreply.github.com> Date: Mon, 1 May 2023 18:37:35 -0400 Subject: [PATCH 08/10] clang format --- .../platforms/http-helper-osx.mm | 90 +++++++++---------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/crash-handler-process/platforms/http-helper-osx.mm b/crash-handler-process/platforms/http-helper-osx.mm index 3f60d44..82618c8 100644 --- a/crash-handler-process/platforms/http-helper-osx.mm +++ b/crash-handler-process/platforms/http-helper-osx.mm @@ -70,56 +70,56 @@ 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); - }]; + 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; - } + if (errorDescription.size()) { + log_error << "HTTP request error: " << errorDescription << std::endl; + return Result::RequestFailed; + } return Result::Success; } From ca3b311548aaa91e50ea58f01c2ffdc15560deb0 Mon Sep 17 00:00:00 2001 From: Eugen <97041180+eugen15@users.noreply.github.com> Date: Mon, 1 May 2023 19:28:08 -0400 Subject: [PATCH 09/10] windows HTTP status code --- crash-handler-process/platforms/http-helper-win.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crash-handler-process/platforms/http-helper-win.cpp b/crash-handler-process/platforms/http-helper-win.cpp index 523903e..6d690a1 100644 --- a/crash-handler-process/platforms/http-helper-win.cpp +++ b/crash-handler-process/platforms/http-helper-win.cpp @@ -56,7 +56,7 @@ 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 *statucCode, +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; @@ -126,6 +126,13 @@ HttpHelper::Result HttpHelper_WIN::Request(Method method, std::string_view url, 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); From 27ad1747f64602bc0aea37ea5cf3038a0c031723 Mon Sep 17 00:00:00 2001 From: Eugen <97041180+eugen15@users.noreply.github.com> Date: Mon, 1 May 2023 19:29:32 -0400 Subject: [PATCH 10/10] clang format --- crash-handler-process/platforms/http-helper-win.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crash-handler-process/platforms/http-helper-win.cpp b/crash-handler-process/platforms/http-helper-win.cpp index 6d690a1..1efcbc3 100644 --- a/crash-handler-process/platforms/http-helper-win.cpp +++ b/crash-handler-process/platforms/http-helper-win.cpp @@ -127,7 +127,7 @@ HttpHelper::Result HttpHelper_WIN::Request(Method method, std::string_view url, } if (statusCode) { - hr = winHttpRequest->get_Status(static_cast(static_cast(statusCode))); + hr = winHttpRequest->get_Status(static_cast(static_cast(statusCode))); if (FAILED(hr)) { return Result::RequestFailed; }