Milestone 5: deliver embedded RDP sessions and lifecycle hardening
This commit is contained in:
108
third_party/FreeRDP/client/SDL/common/res/CMakeLists.txt
vendored
Normal file
108
third_party/FreeRDP/client/SDL/common/res/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
# FreeRDP: A Remote Desktop Protocol Implementation
|
||||
# FreeRDP SDL Client
|
||||
#
|
||||
# Copyright 2024 Armin Novak <anovak@thincast.com>
|
||||
# Copyright 2024 Thincast Technologies GmbH
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
set(FACTORY_SRCS "")
|
||||
set(FACTORY_HDR "")
|
||||
set(FACTORY_CLASSES "")
|
||||
|
||||
include(ConvertFileToHexArray)
|
||||
|
||||
macro(convert_to_bin FILE FILE_TYPE)
|
||||
get_filename_component(FILE_NAME ${FILE} NAME)
|
||||
string(REGEX REPLACE "[^a-zA-Z0-9]" "_" TARGET_NAME ${FILE_NAME})
|
||||
|
||||
set(FILE_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
|
||||
set(FILENAME ${FILE_NAME})
|
||||
set(CLASSNAME ${TARGET_NAME})
|
||||
set(CLASSTYPE ${FILE_TYPE})
|
||||
|
||||
file_to_hex_array("${FILE}" FILEDATA)
|
||||
|
||||
cleaning_configure_file(resource.hpp.in ${FILE_BIN_DIR}/${TARGET_NAME}.hpp @ONLY)
|
||||
|
||||
cleaning_configure_file(resource.cpp.in ${FILE_BIN_DIR}/${TARGET_NAME}.cpp @ONLY)
|
||||
|
||||
list(APPEND FACTORY_HDR ${FILE_BIN_DIR}/${TARGET_NAME}.hpp)
|
||||
list(APPEND FACTORY_SRCS ${FILE_BIN_DIR}/${TARGET_NAME}.cpp)
|
||||
|
||||
list(APPEND FACTORY_CLASSES ${TARGET_NAME})
|
||||
endmacro()
|
||||
|
||||
set(SRCS sdl_resource_manager.cpp sdl_resource_manager.hpp)
|
||||
|
||||
set(RES_SVG_FILES ${CMAKE_SOURCE_DIR}/resources/FreeRDP_Icon.svg ${CMAKE_SOURCE_DIR}/resources/icon_info.svg
|
||||
${CMAKE_SOURCE_DIR}/resources/icon_warning.svg ${CMAKE_SOURCE_DIR}/resources/icon_error.svg
|
||||
)
|
||||
|
||||
set(RES_FONT_FILES ${CMAKE_SOURCE_DIR}/resources/font/OpenSans-VariableFont_wdth,wght.ttf)
|
||||
|
||||
option(SDL_USE_COMPILED_RESOURCES "Compile in images/fonts" ON)
|
||||
|
||||
if(SDL_USE_COMPILED_RESOURCES)
|
||||
list(APPEND SRCS sdl_resource_file.cpp sdl_resource_file.hpp)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if(WITH_SDL_IMAGE_DIALOGS)
|
||||
foreach(FILE ${RES_SVG_FILES})
|
||||
convert_to_bin("${FILE}" "images")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
foreach(FILE ${RES_FONT_FILES})
|
||||
convert_to_bin("${FILE}" "fonts")
|
||||
endforeach()
|
||||
add_compile_definitions(SDL_USE_COMPILED_RESOURCES)
|
||||
|
||||
set(FINIT ${CMAKE_CURRENT_BINARY_DIR}/resource-init.cpp)
|
||||
list(APPEND FACTORY_SRCS ${FINIT})
|
||||
|
||||
write_file(${FINIT} "#include <sdl_resource_manager.hpp>")
|
||||
foreach(HDR ${FACTORY_HDR})
|
||||
write_file(${FINIT} "#include <${HDR}>" APPEND)
|
||||
endforeach()
|
||||
|
||||
write_file(${FINIT} "void SDLResourceManager::init() {" APPEND)
|
||||
foreach(CLASS ${FACTORY_CLASSES})
|
||||
write_file(${FINIT} "\t${CLASS}::init();" APPEND)
|
||||
endforeach()
|
||||
write_file(${FINIT} "}" APPEND)
|
||||
else()
|
||||
option(SDL_USE_VENDOR_PRODUCT_CONFIG_DIR "Use <vendor>/<product> path for resources" OFF)
|
||||
set(SDL_RESOURCE_ROOT ${CMAKE_INSTALL_FULL_DATAROOTDIR})
|
||||
if(SDL_USE_VENDOR_PRODUCT_CONFIG_DIR)
|
||||
string(APPEND SDL_RESOURCE_ROOT "/${VENDOR}")
|
||||
endif()
|
||||
string(APPEND SDL_RESOURCE_ROOT "/${PRODUCT}")
|
||||
|
||||
if(WITH_BINARY_VERSIONING)
|
||||
string(APPEND SDL_RESOURCE_ROOT "${FREERDP_VERSION_MAJOR}")
|
||||
endif()
|
||||
|
||||
add_compile_definitions(SDL_RESOURCE_ROOT="${SDL_RESOURCE_ROOT}")
|
||||
|
||||
if(WITH_SDL_IMAGE_DIALOGS)
|
||||
install(FILES ${RES_SVG_FILES} DESTINATION ${SDL_RESOURCE_ROOT}/images)
|
||||
endif()
|
||||
|
||||
install(FILES ${RES_FONT_FILES} DESTINATION ${SDL_RESOURCE_ROOT}/fonts)
|
||||
endif()
|
||||
|
||||
add_library(sdl-common-client-res STATIC ${RES_FILES} ${SRCS} ${FACTORY_HDR} ${FACTORY_SRCS})
|
||||
set_property(TARGET sdl-common-client-res PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
set_property(TARGET sdl-common-client-res PROPERTY FOLDER "Client/Common")
|
||||
28
third_party/FreeRDP/client/SDL/common/res/resource.cpp.in
vendored
Normal file
28
third_party/FreeRDP/client/SDL/common/res/resource.cpp.in
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
/* AUTOGENERATED file, do not edit
|
||||
*
|
||||
* part of @PROJECT_NAME@
|
||||
* generated by 'CMake' from common/res/resource.cpp.in
|
||||
*
|
||||
* contains the converted file '@FILENAME@'
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include "@CLASSNAME@.hpp"
|
||||
|
||||
std::string @CLASSNAME@::name() noexcept {
|
||||
return "@FILENAME@";
|
||||
}
|
||||
std::string @CLASSNAME@::type() noexcept {
|
||||
return "@CLASSTYPE@";
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(clang-diagnostic-global-constructors)
|
||||
const SDLResourceFile @CLASSNAME@::_initializer(type(), name(), init());
|
||||
|
||||
std::vector<unsigned char> @CLASSNAME@::init() noexcept {
|
||||
static const unsigned char data[] = {
|
||||
@FILEDATA@
|
||||
};
|
||||
return std::vector<unsigned char>(data, data + sizeof(data));
|
||||
}
|
||||
|
||||
34
third_party/FreeRDP/client/SDL/common/res/resource.hpp.in
vendored
Normal file
34
third_party/FreeRDP/client/SDL/common/res/resource.hpp.in
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/* AUTOGENERATED file, do not edit
|
||||
*
|
||||
* part of @PROJECT_NAME@
|
||||
* generated by 'CMake' from common/res/resource.hpp.in
|
||||
*
|
||||
* contains the converted file '@FILENAME@'
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "sdl_resource_file.hpp"
|
||||
|
||||
class @CLASSNAME@
|
||||
{
|
||||
friend class SDLResourceManager;
|
||||
|
||||
public:
|
||||
@CLASSNAME@() = delete;
|
||||
~@CLASSNAME@() = delete;
|
||||
|
||||
@CLASSNAME@(const @CLASSNAME@&) = delete;
|
||||
@CLASSNAME@(@CLASSNAME@&&) = delete;
|
||||
|
||||
@CLASSNAME@& operator=(const @CLASSNAME@&) = delete;
|
||||
@CLASSNAME@& operator=(@CLASSNAME@&&) = delete;
|
||||
|
||||
static std::string name() noexcept;
|
||||
static std::string type() noexcept;
|
||||
|
||||
protected:
|
||||
static std::vector<unsigned char> init() noexcept;
|
||||
static const SDLResourceFile _initializer;
|
||||
};
|
||||
27
third_party/FreeRDP/client/SDL/common/res/sdl_resource_file.cpp
vendored
Normal file
27
third_party/FreeRDP/client/SDL/common/res/sdl_resource_file.cpp
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
*
|
||||
* Copyright 2023 Armin Novak <armin.novak@thincast.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "sdl_resource_file.hpp"
|
||||
#include "sdl_resource_manager.hpp"
|
||||
|
||||
SDLResourceFile::SDLResourceFile(const std::string& type, const std::string& id,
|
||||
const std::vector<unsigned char>& data) noexcept
|
||||
{
|
||||
SDLResourceManager::insert(type, id, data);
|
||||
}
|
||||
|
||||
SDLResourceFile::~SDLResourceFile() = default;
|
||||
34
third_party/FreeRDP/client/SDL/common/res/sdl_resource_file.hpp
vendored
Normal file
34
third_party/FreeRDP/client/SDL/common/res/sdl_resource_file.hpp
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
*
|
||||
* Copyright 2023 Armin Novak <armin.novak@thincast.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class SDLResourceFile
|
||||
{
|
||||
public:
|
||||
SDLResourceFile(const std::string& type, const std::string& id,
|
||||
const std::vector<unsigned char>& data) noexcept;
|
||||
virtual ~SDLResourceFile();
|
||||
|
||||
SDLResourceFile(const SDLResourceFile& other) = delete;
|
||||
SDLResourceFile(SDLResourceFile&& other) = delete;
|
||||
SDLResourceFile& operator=(const SDLResourceFile& other) = delete;
|
||||
SDLResourceFile& operator=(SDLResourceFile&& other) = delete;
|
||||
};
|
||||
102
third_party/FreeRDP/client/SDL/common/res/sdl_resource_manager.cpp
vendored
Normal file
102
third_party/FreeRDP/client/SDL/common/res/sdl_resource_manager.cpp
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
*
|
||||
* Copyright 2023 Armin Novak <armin.novak@thincast.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "sdl_resource_manager.hpp"
|
||||
#include <iostream>
|
||||
#if __has_include(<filesystem>)
|
||||
#include <filesystem>
|
||||
namespace fs = std::filesystem;
|
||||
#elif __has_include(<experimental/filesystem>)
|
||||
#include <experimental/filesystem>
|
||||
namespace fs = std::experimental::filesystem;
|
||||
#else
|
||||
#error Could not find system header "<filesystem>" or "<experimental/filesystem>"
|
||||
#endif
|
||||
|
||||
std::string SDLResourceManager::typeFonts()
|
||||
{
|
||||
return "fonts";
|
||||
}
|
||||
|
||||
std::string SDLResourceManager::typeImages()
|
||||
{
|
||||
return "images";
|
||||
}
|
||||
|
||||
void SDLResourceManager::insert(const std::string& type, const std::string& id,
|
||||
const std::vector<unsigned char>& data)
|
||||
{
|
||||
std::string uuid = type + "/" + id;
|
||||
resources().emplace(uuid, data);
|
||||
}
|
||||
|
||||
bool SDLResourceManager::useCompiledResources()
|
||||
{
|
||||
#if defined(SDL_USE_COMPILED_RESOURCES)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
const std::vector<unsigned char>* SDLResourceManager::data(const std::string& type,
|
||||
const std::string& id)
|
||||
{
|
||||
#if defined(SDL_USE_COMPILED_RESOURCES)
|
||||
std::string uuid = type + "/" + id;
|
||||
auto val = resources().find(uuid);
|
||||
if (val == resources().end())
|
||||
return nullptr;
|
||||
|
||||
return &val->second;
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string SDLResourceManager::filename([[maybe_unused]] const std::string& type,
|
||||
[[maybe_unused]] const std::string& id)
|
||||
{
|
||||
#if defined(SDL_RESOURCE_ROOT)
|
||||
std::string uuid = type + "/" + id;
|
||||
fs::path path(SDL_RESOURCE_ROOT);
|
||||
path /= type;
|
||||
path /= id;
|
||||
|
||||
if (!fs::exists(path))
|
||||
{
|
||||
std::cerr << "sdl-freerdp expects resource '" << uuid << "' at location "
|
||||
<< fs::absolute(path) << std::endl;
|
||||
std::cerr << "file not found, application will fail" << std::endl;
|
||||
return "";
|
||||
}
|
||||
return path.u8string();
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
std::map<std::string, std::vector<unsigned char>>& SDLResourceManager::resources()
|
||||
{
|
||||
|
||||
static std::map<std::string, std::vector<unsigned char>> resources = {};
|
||||
#if defined(SDL_USE_COMPILED_RESOURCES)
|
||||
if (resources.empty())
|
||||
init();
|
||||
#endif
|
||||
return resources;
|
||||
}
|
||||
54
third_party/FreeRDP/client/SDL/common/res/sdl_resource_manager.hpp
vendored
Normal file
54
third_party/FreeRDP/client/SDL/common/res/sdl_resource_manager.hpp
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
*
|
||||
* Copyright 2023 Armin Novak <armin.novak@thincast.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class SDLResourceManager
|
||||
{
|
||||
friend class SDLResourceFile;
|
||||
|
||||
public:
|
||||
SDLResourceManager() = delete;
|
||||
SDLResourceManager(const SDLResourceManager& other) = delete;
|
||||
SDLResourceManager(const SDLResourceManager&& other) = delete;
|
||||
~SDLResourceManager() = delete;
|
||||
SDLResourceManager operator=(const SDLResourceManager& other) = delete;
|
||||
SDLResourceManager& operator=(SDLResourceManager&& other) = delete;
|
||||
|
||||
[[nodiscard]] static std::string typeFonts();
|
||||
[[nodiscard]] static std::string typeImages();
|
||||
|
||||
protected:
|
||||
static void insert(const std::string& type, const std::string& id,
|
||||
const std::vector<unsigned char>& data);
|
||||
|
||||
[[nodiscard]] static const std::vector<unsigned char>* data(const std::string& type,
|
||||
const std::string& id);
|
||||
[[nodiscard]] static std::string filename(const std::string& type, const std::string& id);
|
||||
|
||||
[[nodiscard]] static bool useCompiledResources();
|
||||
|
||||
private:
|
||||
[[nodiscard]] static std::map<std::string, std::vector<unsigned char>>& resources();
|
||||
#if defined(SDL_USE_COMPILED_RESOURCES)
|
||||
static void init(); // implemented in generated file
|
||||
#endif
|
||||
};
|
||||
Reference in New Issue
Block a user