diff --git a/crash-handler-process/CMakeLists.txt b/crash-handler-process/CMakeLists.txt
index 3ff8461..dcd3fe2 100644
--- a/crash-handler-process/CMakeLists.txt
+++ b/crash-handler-process/CMakeLists.txt
@@ -38,7 +38,9 @@ ENDIF()
SET(PROJECT_SOURCE
"${PROJECT_SOURCE_DIR}/process.hpp"
"${PROJECT_SOURCE_DIR}/process-manager.cpp" "${PROJECT_SOURCE_DIR}/process-manager.hpp"
+ "${PROJECT_SOURCE_DIR}/brief-crash-info-uploader.cpp" "${PROJECT_SOURCE_DIR}/brief-crash-info-uploader.hpp"
"${PROJECT_SOURCE_DIR}/message.cpp" "${PROJECT_SOURCE_DIR}/message.hpp"
+ "${PROJECT_SOURCE_DIR}/http-helper.hpp"
"${PROJECT_SOURCE_DIR}/socket.hpp"
"${PROJECT_SOURCE_DIR}/logger.cpp" "${PROJECT_SOURCE_DIR}/logger.hpp"
"${PROJECT_SOURCE_DIR}/main.cpp"
@@ -50,7 +52,9 @@ IF(WIN32)
"${PROJECT_SOURCE_DIR}/platforms/util-win.cpp"
"${PROJECT_SOURCE_DIR}/platforms/socket-win.cpp" "${PROJECT_SOURCE_DIR}/platforms/socket-win.hpp"
"${PROJECT_SOURCE_DIR}/platforms/process-win.cpp" "${PROJECT_SOURCE_DIR}/platforms/process-win.hpp"
- "${PROJECT_SOURCE_DIR}/platforms/upload-window-win.cpp" "${PROJECT_SOURCE_DIR}/platforms/upload-window-win.hpp"
+ "${PROJECT_SOURCE_DIR}/platforms/upload-window-win.cpp" "${PROJECT_SOURCE_DIR}/platforms/upload-window-win.hpp"
+ "${PROJECT_SOURCE_DIR}/platforms/httprequest_i.c" "${PROJECT_SOURCE_DIR}/platforms/httprequest.h"
+ "${PROJECT_SOURCE_DIR}/platforms/http-helper-win.cpp" "${PROJECT_SOURCE_DIR}/platforms/http-helper-win.hpp"
"${PROJECT_SOURCE_DIR}/minizip/zip.c" "${PROJECT_SOURCE_DIR}/minizip/zip.h"
"${PROJECT_SOURCE_DIR}/minizip/ioapi.c" "${PROJECT_SOURCE_DIR}/minizip/ioapi.h"
"${PROJECT_SOURCE_DIR}/minizip/iowin32.c" "${PROJECT_SOURCE_DIR}/minizip/iowin32.h"
@@ -60,7 +64,7 @@ ELSE(APPLE)
"${PROJECT_SOURCE_DIR}/platforms/util-osx.mm"
"${PROJECT_SOURCE_DIR}/platforms/socket-osx.cpp" "${PROJECT_SOURCE_DIR}/platforms/socket-osx.hpp"
"${PROJECT_SOURCE_DIR}/platforms/process-osx.mm" "${PROJECT_SOURCE_DIR}/platforms/process-osx.hpp"
-
+ "${PROJECT_SOURCE_DIR}/platforms/http-helper-osx.mm" "${PROJECT_SOURCE_DIR}/platforms/http-helper-osx.hpp"
)
find_library(COCOA Cocoa)
# Prepare gettext
diff --git a/crash-handler-process/brief-crash-info-uploader.cpp b/crash-handler-process/brief-crash-info-uploader.cpp
new file mode 100644
index 0000000..c72d440
--- /dev/null
+++ b/crash-handler-process/brief-crash-info-uploader.cpp
@@ -0,0 +1,117 @@
+/******************************************************************************
+ Copyright (C) 2016-2020 by Streamlabs (General Workings Inc)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+******************************************************************************/
+
+#include
+#include
+#include
+#include
+#include
+
+#include "logger.hpp"
+#include "util.hpp"
+
+#include "http-helper.hpp"
+#include "brief-crash-info-uploader.hpp"
+
+#if defined(_WIN32)
+std::string_view g_pathSeparator("\\");
+#else
+std::string_view g_pathSeparator("/");
+#endif
+
+std::string_view g_briefCrashDataFilename("brief-crash-info.json");
+
+BriefCrashInfoUploader::BriefCrashInfoUploader(const std::string &appDataPath) : m_filename(appDataPath)
+{
+ if (*m_filename.rbegin() != '/' && *m_filename.rbegin() != '\\') {
+ m_filename += g_pathSeparator;
+ }
+ m_filename += g_briefCrashDataFilename;
+}
+
+BriefCrashInfoUploader::~BriefCrashInfoUploader() {}
+
+void BriefCrashInfoUploader::Run(std::int64_t maxFileWaitTimeMs)
+{
+ std::string json = ProcessBriefCrashInfoJson(maxFileWaitTimeMs);
+ if (json.size()) {
+ UploadJson(json);
+ }
+}
+
+std::string BriefCrashInfoUploader::ProcessBriefCrashInfoJson(std::int64_t maxFileWaitTimeMs)
+{
+ log_info << "Waiting for brief crash info file: " << m_filename << std::endl;
+ std::string json;
+ std::filesystem::path briefCrashInfoPath = std::filesystem::u8path(m_filename);
+ std::int64_t realFileWaitTimeMs = 0;
+ while (realFileWaitTimeMs < maxFileWaitTimeMs) {
+ if (std::filesystem::exists(briefCrashInfoPath) && std::filesystem::is_regular_file(briefCrashInfoPath)) {
+ json = LoadBriefCrashInfoJson();
+ std::filesystem::remove(briefCrashInfoPath);
+ log_info << "The brief crash info file has been loaded." << std::endl;
+ break;
+ }
+ // Obviously the sleep can take more than 100ms but not much so we ignore the difference
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ realFileWaitTimeMs += 100;
+ }
+ log_info << "Waited for the brief crash info file (ms): " << realFileWaitTimeMs << std::endl;
+ return json;
+}
+
+std::string BriefCrashInfoUploader::LoadBriefCrashInfoJson()
+{
+#if defined(_WIN32)
+ std::wstring_convert> converter;
+ std::ifstream file(converter.from_bytes(m_filename));
+#else
+ std::ifstream file(m_filename);
+#endif
+ file.seekg(0, std::ios::end);
+ size_t fileSize = file.tellg();
+
+ std::string buffer(fileSize, ' ');
+ file.seekg(0);
+ file.read(&buffer.front(), fileSize);
+ file.close();
+
+ return buffer;
+}
+
+void BriefCrashInfoUploader::UploadJson(const std::string &json)
+{
+ log_info << "Uploading the brief crash info..." << std::endl;
+
+ HttpHelper::Headers requestHeaders = {{"Content-Type", "application/json; Charset=UTF-8"}};
+ HttpHelper::Headers responseHeaders;
+ std::string response;
+
+ std::uint32_t statusCode = 0;
+
+ auto httpHelper = HttpHelper::Create();
+ HttpHelper::Result result = httpHelper->PostRequest("https://httpbin.org/post", requestHeaders, json, &statusCode, &responseHeaders, &response);
+
+ log_info << "Brief crash info upload result (0 means SUCCESS): " << static_cast(result) << std::endl;
+ log_info << "Brief crash info upload HTTP status code: " << statusCode << std::endl;
+ log_info << "Brief crash info upload response: " << response << std::endl;
+
+ for (const auto &[header, value] : responseHeaders) {
+ log_info << "Brief crash info upload response header: " << header << " = " << value << std::endl;
+ }
+}
diff --git a/crash-handler-process/brief-crash-info-uploader.hpp b/crash-handler-process/brief-crash-info-uploader.hpp
new file mode 100644
index 0000000..04c8bd5
--- /dev/null
+++ b/crash-handler-process/brief-crash-info-uploader.hpp
@@ -0,0 +1,38 @@
+/******************************************************************************
+ Copyright (C) 2016-2020 by Streamlabs (General Workings Inc)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+******************************************************************************/
+
+#pragma once
+
+#include
+#include
+#include
+
+class BriefCrashInfoUploader final {
+public:
+ BriefCrashInfoUploader(const std::string &appDataPath);
+ ~BriefCrashInfoUploader();
+
+ void Run(std::int64_t maxFileWaitTimeMs = 10000);
+
+private:
+ std::string ProcessBriefCrashInfoJson(std::int64_t maxFileWaitTimeMs);
+ std::string LoadBriefCrashInfoJson();
+ void UploadJson(const std::string &json);
+
+ std::string m_filename;
+};
diff --git a/crash-handler-process/dependencies/crash-handler-process.exe.txt b/crash-handler-process/dependencies/crash-handler-process.exe.txt
index a5603d0..ca0cdfe 100644
Binary files a/crash-handler-process/dependencies/crash-handler-process.exe.txt and b/crash-handler-process/dependencies/crash-handler-process.exe.txt differ
diff --git a/crash-handler-process/http-helper.hpp b/crash-handler-process/http-helper.hpp
new file mode 100644
index 0000000..4ff10b9
--- /dev/null
+++ b/crash-handler-process/http-helper.hpp
@@ -0,0 +1,54 @@
+/******************************************************************************
+ Copyright (C) 2016-2020 by Streamlabs (General Workings Inc)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+******************************************************************************/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include