Merge pull request #10257 from akallabeth/unify-config-settings

[core,settings] unify configuration path
This commit is contained in:
akallabeth 2024-06-06 12:09:51 +02:00 committed by GitHub
commit 22d9f070ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 76 additions and 302 deletions

View File

@ -77,6 +77,13 @@ if (NOT SDL2_FOUND AND NOT SDL3_FOUND)
message(FATAL_ERROR "No SDL library detected, giving up. Install SDL2 or SDL3 development package to fix")
endif()
# Configuration settings for manpages
if (NOT WITH_FULL_CONFIG_PATH AND "${VENDOR}" STREQUAL "${PRODUCT}")
string(TOLOWER "${VENDOR}" VENDOR_PRODUCT)
else()
set(VENDOR_PRODUCT "${VENDOR}/${PRODUCT}")
endif()
add_subdirectory(common)
include_directories(common)

View File

@ -1,8 +1,8 @@
set(DEPS
sdl2-freerdp-channels.1.xml
sdl2-freerdp-config.1.xml
sdl2-freerdp-examples.1.xml
sdl2-freerdp-envvar.1.xml
../../common/man/sdl-freerdp-channels.1.xml
../../common/man/sdl-freerdp-config.1.xml
../../common/man/sdl-freerdp-examples.1.xml
../../common/man/sdl-freerdp-envvar.1.xml
)
generate_and_install_freerdp_man_from_xml(${MODULE_NAME} "1" "${DEPS}")

View File

@ -3,9 +3,9 @@
PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY syntax SYSTEM "freerdp-argument.1.xml">
<!ENTITY config SYSTEM "sdl2-freerdp-config.1.xml">
<!ENTITY envvar SYSTEM "sdl2-freerdp-envvar.1.xml">
<!ENTITY examples SYSTEM "sdl2-freerdp-examples.1.xml">
<!ENTITY config SYSTEM "sdl-freerdp-config.1.xml">
<!ENTITY envvar SYSTEM "sdl-freerdp-envvar.1.xml">
<!ENTITY examples SYSTEM "sdl-freerdp-examples.1.xml">
]
>

View File

@ -326,7 +326,7 @@ bool SDLConnectionDialog::createWindow()
const size_t widget_width = 600;
const size_t total_height = 300;
auto rc = SDL_CreateWindowAndRenderer(title.c_str(), widget_width, total_height,
auto rc = SDL_CreateWindowAndRenderer(_title.c_str(), widget_width, total_height,
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_MOUSE_FOCUS |
SDL_WINDOW_INPUT_FOCUS,
&_window, &_renderer);

View File

@ -1,8 +1,8 @@
set(DEPS
sdl3-freerdp-channels.1.xml
sdl3-freerdp-config.1.xml
sdl3-freerdp-examples.1.xml
sdl3-freerdp-envvar.1.xml
../../common/man/sdl-freerdp-channels.1.xml
../../common/man/sdl-freerdp-config.1.xml
../../common/man/sdl-freerdp-examples.1.xml
../../common/man/sdl-freerdp-envvar.1.xml
)
generate_and_install_freerdp_man_from_xml(${MODULE_NAME} "1" "${DEPS}")

View File

@ -1,81 +0,0 @@
<refsect1>
<title>Configuration file</title>
<variablelist>
<varlistentry>
<term>Format and Location:</term>
<listitem>
<para>The configuration file is stored per user.<sbr/>
The <replaceable>XDG_CONFIG_HOME</replaceable> environment variable can be used to override the base directory.<sbr/>
This defaults to <replaceable>~/.config</replaceable>
The location relative to <replaceable>XDG_CONFIG_HOME</replaceable> is <replaceable>$XDG_CONFIG_HOME/@VENDOR@/@PRODUCT@/@MODULE_NAME@.json</replaceable><sbr/>
The configuration is stored in JSON format</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Supported options:</term>
<listitem>
<varlistentry>
<term><replaceable>SDL_KeyModMask</replaceable></term>
<listitem>
<varlistentry>
<listitem>
<para>Defines the key combination required for SDL client shortcuts.<sbr/>
Default <replaceable>KMOD_RSHIFT</replaceable><sbr/>
An array of <replaceable>SDL_Keymod</replaceable> strings as defined at <replaceable>https://wiki.libsdl.org/SDL2/SDL_Keymod</replaceable></para>
</listitem>
</varlistentry>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>SDL_Fullscreen</replaceable></term>
<listitem>
<varlistentry>
<listitem>
<para>Toggles client fullscreen state.<sbr/>
Default <replaceable>SDL_SCANCODE_RETURN</replaceable>.<sbr/>
A string as defined at <replaceable>https://wiki.libsdl.org/SDL2/SDLScancodeLookup</replaceable></para>
</listitem>
</varlistentry>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>SDL_Resizeable</replaceable></term>
<listitem>
<varlistentry>
<listitem>
<para>Toggles local window resizeable state.<sbr/>
Default <replaceable>SDL_SCANCODE_R</replaceable>.<sbr/>
A string as defined at <replaceable>https://wiki.libsdl.org/SDL2/SDLScancodeLookup</replaceable></para>
</listitem>
</varlistentry>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>SDL_Grab</replaceable></term>
<listitem>
<varlistentry>
<listitem>
<para>Toggles keyboard and mouse grab state.<sbr/>
Default <replaceable>SDL_SCANCODE_G</replaceable>.<sbr/>
A string as defined at <replaceable>https://wiki.libsdl.org/SDL2/SDLScancodeLookup</replaceable></para>
</listitem>
</varlistentry>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>SDL_Disconnect</replaceable></term>
<listitem>
<varlistentry>
<listitem>
<para>Disconnects from the RDP session.<sbr/>
Default <replaceable>SDL_SCANCODE_D</replaceable>.<sbr/>
A string as defined at <replaceable>https://wiki.libsdl.org/SDL2/SDLScancodeLookup</replaceable></para>
</listitem>
</varlistentry>
</listitem>
</varlistentry>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@ -1,15 +0,0 @@
<refsect1>
<title>Environment variables</title>
<variablelist>
<varlistentry>
<term>wlog environment variable</term>
<listitem>
<para>sdl-freerdp uses wLog as its log facility, you can refer to the
corresponding man page (wlog(7)) for more informations. Arguments passed
via the <replaceable>/log-level</replaceable> or <replaceable>/log-filters</replaceable>
have precedence over the environment variables.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@ -1,95 +0,0 @@
<refsect1>
<title>Examples</title>
<variablelist>
<varlistentry>
<term><command>sdl-freerdp connection.rdp /p:Pwd123! /f</command></term>
<listitem>
<para>Connect in fullscreen mode using a stored configuration <replaceable>connection.rdp</replaceable> and the password <replaceable>Pwd123!</replaceable></para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>sdl-freerdp /u:USER /size:50%h /v:rdp.contoso.com</command></term>
<listitem>
<para>Connect to host <replaceable>rdp.contoso.com</replaceable> with user <replaceable>USER</replaceable> and a size of <replaceable>50 percent of the height</replaceable>. If width (w) is set instead of height (h) like /size:50%w. 50 percent of the width is used.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>sdl-freerdp /u:CONTOSO\\JohnDoe /p:Pwd123! /v:rdp.contoso.com</command></term>
<listitem>
<para>Connect to host <replaceable>rdp.contoso.com</replaceable> with user <replaceable>CONTOSO\\JohnDoe</replaceable> and password <replaceable>Pwd123!</replaceable></para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>sdl-freerdp /u:JohnDoe /p:Pwd123! /w:1366 /h:768 /v:192.168.1.100:4489</command></term>
<listitem>
<para>Connect to host <replaceable>192.168.1.100</replaceable> on port <replaceable>4489</replaceable> with user <replaceable>JohnDoe</replaceable>, password <replaceable>Pwd123!</replaceable>. The screen width is set to <replaceable>1366</replaceable> and the height to <replaceable>768</replaceable></para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>sdl-freerdp /u:JohnDoe /p:Pwd123! /vmconnect:C824F53E-95D2-46C6-9A18-23A5BB403532 /v:192.168.1.100</command></term>
<listitem>
<para>Establish a connection to host <replaceable>192.168.1.100</replaceable> with user <replaceable>JohnDoe</replaceable>, password <replaceable>Pwd123!</replaceable> and connect to Hyper-V console (use port 2179, disable negotiation) with VMID <replaceable>C824F53E-95D2-46C6-9A18-23A5BB403532</replaceable></para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>+clipboard</command></term>
<listitem>
<para>Activate clipboard redirection</para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>/drive:home,/home/user</command></term>
<listitem>
<para>Activate drive redirection of <replaceable>/home/user</replaceable> as home drive</para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>/smartcard:&lt;device&gt;</command></term>
<listitem>
<para>Activate smartcard redirection for device <replaceable>device</replaceable></para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>/printer:&lt;device&gt;,&lt;driver&gt;</command></term>
<listitem>
<para>Activate printer redirection for printer <replaceable>device</replaceable> using driver <replaceable>driver</replaceable></para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>/serial:&lt;device&gt;</command></term>
<listitem>
<para>Activate serial port redirection for port <replaceable>device</replaceable></para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>/parallel:&lt;device&gt;</command></term>
<listitem>
<para>Activate parallel port redirection for port <replaceable>device</replaceable></para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>/sound:sys:alsa</command></term>
<listitem>
<para>Activate audio output redirection using device <replaceable>sys:alsa</replaceable></para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>/microphone:sys:alsa</command></term>
<listitem>
<para>Activate audio input redirection using device <replaceable>sys:alsa</replaceable></para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>/multimedia:sys:alsa</command></term>
<listitem>
<para>Activate multimedia redirection using device <replaceable>sys:alsa</replaceable></para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>/usb:id,dev:054c:0268</command></term>
<listitem>
<para>Activate USB device redirection for the device identified by <replaceable>054c:0268</replaceable></para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@ -3,9 +3,9 @@
PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY syntax SYSTEM "freerdp-argument.1.xml">
<!ENTITY config SYSTEM "sdl3-freerdp-config.1.xml">
<!ENTITY envvar SYSTEM "sdl3-freerdp-envvar.1.xml">
<!ENTITY examples SYSTEM "sdl3-freerdp-examples.1.xml">
<!ENTITY config SYSTEM "sdl-freerdp-config.1.xml">
<!ENTITY envvar SYSTEM "sdl-freerdp-envvar.1.xml">
<!ENTITY examples SYSTEM "sdl-freerdp-examples.1.xml">
]
>

View File

@ -23,7 +23,7 @@ add_library(sdl-common-prefs STATIC
sdl_prefs.hpp
sdl_prefs.cpp
)
target_link_libraries(sdl-common-prefs winpr)
target_link_libraries(sdl-common-prefs winpr freerdp)
if(BUILD_TESTING)
add_subdirectory(test)

View File

@ -8,7 +8,7 @@
<para>The configuration file is stored per user.<sbr/>
The <replaceable>XDG_CONFIG_HOME</replaceable> environment variable can be used to override the base directory.<sbr/>
This defaults to <replaceable>~/.config</replaceable>
The location relative to <replaceable>XDG_CONFIG_HOME</replaceable> is <replaceable>$XDG_CONFIG_HOME/@VENDOR@/@PRODUCT@/@MODULE_NAME@.json</replaceable><sbr/>
The location relative to <replaceable>XDG_CONFIG_HOME</replaceable> is <replaceable>$XDG_CONFIG_HOME/@VENDOR_PRODUCT@/sdl-freerdp.json</replaceable><sbr/>
The configuration is stored in JSON format</para>
</listitem>
</varlistentry>

View File

@ -34,6 +34,7 @@ namespace fs = std::experimental::filesystem;
#include <winpr/config.h>
#include <freerdp/version.h>
#include <winpr/json.h>
#include <freerdp/settings.h>
SdlPref::WINPR_JSONPtr SdlPref::get()
{
@ -108,13 +109,11 @@ SdlPref::SdlPref(const std::string& file) : _name(file), _config(get())
std::string SdlPref::get_pref_dir()
{
using CStringPtr = std::unique_ptr<char, decltype(&free)>;
CStringPtr path(GetKnownPath(KNOWN_PATH_XDG_CONFIG_HOME), free);
CStringPtr path(freerdp_settings_get_config_path(), free);
if (!path)
return {};
fs::path config{ path.get() };
config /= FREERDP_VENDOR;
config /= FREERDP_PRODUCT;
return config.string();
}

View File

@ -237,3 +237,5 @@ if (BUILD_FUZZERS)
>
)
endif()
option(WITH_FULL_CONFIG_PATH "Use <appdata>/Vendor/Product instead of <appdata>/product (lowercase, only if vendor equals product) as config directory" OFF)

View File

@ -35,8 +35,9 @@ function(generate_and_install_freerdp_man_from_xml target section dependencies)
configure_file(${template}.xml.in ${manpage}.xml @ONLY IMMEDIATE)
foreach(DEP IN LISTS dependencies)
get_filename_component(DNAME "${DEP}" NAME)
set(SRC ${CMAKE_CURRENT_SOURCE_DIR}/${DEP}.in)
set(DST ${CMAKE_CURRENT_BINARY_DIR}/${DEP})
set(DST ${CMAKE_CURRENT_BINARY_DIR}/${DNAME})
if (EXISTS ${SRC})
message("generating ${DST} from ${SRC}")

View File

@ -713,6 +713,10 @@ typedef struct rdp_settings rdpSettings;
FREERDP_API const char* freerdp_supported_color_depths_string(UINT16 mask, char* buffer,
size_t size);
/** \brief return the configuration directory for the library
*/
FREERDP_API char* freerdp_settings_get_config_path(void);
#ifdef __cplusplus
}
#endif

View File

@ -398,6 +398,10 @@ AddTargetWithResourceFile(${MODULE_NAME} FALSE "${FREERDP_VERSION}" LIBFREERDP_S
add_definitions(${LIBFREERDP_DEFINITIONS})
if (WITH_FULL_CONFIG_PATH)
add_definitions(-DWITH_FULL_CONFIG_PATH)
endif()
target_include_directories(${MODULE_NAME} INTERFACE $<INSTALL_INTERFACE:include>)
target_link_libraries(${MODULE_NAME} PRIVATE ${LIBFREERDP_LIBS})
target_link_libraries(${MODULE_NAME} PUBLIC ${LIBFREERDP_PUB_LIBS})

View File

@ -350,9 +350,39 @@ BOOL freerdp_capability_buffer_allocate(rdpSettings* settings, UINT32 count)
settings->ReceivedCapabilityDataSizes);
}
#if !defined(WITH_FULL_CONFIG_PATH)
static char* freerdp_settings_get_legacy_config_path(void)
{
char product[sizeof(FREERDP_PRODUCT_STRING)] = { 0 };
for (size_t i = 0; i < sizeof(product); i++)
product[i] = tolower(FREERDP_PRODUCT_STRING[i]);
return GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, product);
}
#endif
char* freerdp_settings_get_config_path(void)
{
char* path = NULL;
/* For default FreeRDP continue using same config directory
* as in old releases.
* Custom builds use <Vendor>/<Product> as config folder. */
#if !defined(WITH_FULL_CONFIG_PATH)
if (_stricmp(FREERDP_VENDOR_STRING, FREERDP_PRODUCT_STRING) == 0)
return freerdp_settings_get_legacy_config_path();
#endif
char* base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, FREERDP_VENDOR_STRING);
if (base)
path = GetCombinedPath(base, FREERDP_PRODUCT_STRING);
free(base);
return path;
}
rdpSettings* freerdp_settings_new(DWORD flags)
{
char* base = NULL;
char* issuers[] = { "FreeRDP", "FreeRDP-licenser" };
const BOOL server = (flags & FREERDP_SETTINGS_SERVER_MODE) != 0 ? TRUE : FALSE;
const BOOL remote = (flags & FREERDP_SETTINGS_REMOTE_MODE) != 0 ? TRUE : FALSE;
@ -728,7 +758,7 @@ rdpSettings* freerdp_settings_new(DWORD flags)
if (!freerdp_settings_get_bool(settings, FreeRDP_ServerMode))
{
BOOL rc = 0;
BOOL rc = FALSE;
char* path = NULL;
if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectClipboard, TRUE))
goto out_fail;
@ -740,42 +770,10 @@ rdpSettings* freerdp_settings_new(DWORD flags)
if (!rc || !freerdp_settings_get_string(settings, FreeRDP_HomePath))
goto out_fail;
/* For default FreeRDP continue using same config directory
* as in old releases.
* Custom builds use <Vendor>/<Product> as config folder. */
if (_stricmp(FREERDP_VENDOR_STRING, FREERDP_PRODUCT_STRING))
{
BOOL res = TRUE;
base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, FREERDP_VENDOR_STRING);
if (base)
{
char* combined = GetCombinedPath(base, FREERDP_PRODUCT_STRING);
res = freerdp_settings_set_string(settings, FreeRDP_ConfigPath, combined);
free(combined);
}
free(base);
if (!res)
goto out_fail;
}
else
{
BOOL res = 0;
char* cpath = NULL;
char product[sizeof(FREERDP_PRODUCT_STRING)] = { 0 };
for (size_t i = 0; i < sizeof(product); i++)
product[i] = tolower(FREERDP_PRODUCT_STRING[i]);
cpath = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, product);
res = freerdp_settings_set_string(settings, FreeRDP_ConfigPath, cpath);
free(cpath);
if (!res)
goto out_fail;
}
if (!freerdp_settings_get_string(settings, FreeRDP_ConfigPath))
char* config = freerdp_settings_get_config_path();
rc = freerdp_settings_set_string(settings, FreeRDP_ConfigPath, config);
free(config);
if (!rc)
goto out_fail;
}

View File

@ -734,58 +734,9 @@ int shadow_server_stop(rdpShadowServer* server)
static int shadow_server_init_config_path(rdpShadowServer* server)
{
#ifdef _WIN32
if (!server->ConfigPath)
{
server->ConfigPath = GetEnvironmentSubPath("LOCALAPPDATA", "freerdp");
}
#endif
#ifdef __APPLE__
if (!server->ConfigPath)
{
char* userLibraryPath;
char* userApplicationSupportPath;
userLibraryPath = GetKnownSubPath(KNOWN_PATH_HOME, "Library");
if (userLibraryPath)
{
if (!winpr_PathFileExists(userLibraryPath) && !winpr_PathMakePath(userLibraryPath, 0))
{
WLog_ERR(TAG, "Failed to create directory '%s'", userLibraryPath);
free(userLibraryPath);
return -1;
}
userApplicationSupportPath = GetCombinedPath(userLibraryPath, "Application Support");
if (userApplicationSupportPath)
{
if (!winpr_PathFileExists(userApplicationSupportPath) &&
!winpr_PathMakePath(userApplicationSupportPath, 0))
{
WLog_ERR(TAG, "Failed to create directory '%s'", userApplicationSupportPath);
free(userLibraryPath);
free(userApplicationSupportPath);
return -1;
}
server->ConfigPath = GetCombinedPath(userApplicationSupportPath, "freerdp");
}
free(userLibraryPath);
free(userApplicationSupportPath);
}
}
#endif
if (!server->ConfigPath)
{
char* configHome = NULL;
configHome = GetKnownPath(KNOWN_PATH_XDG_CONFIG_HOME);
char* configHome = freerdp_settings_get_config_path();
if (configHome)
{
@ -796,8 +747,7 @@ static int shadow_server_init_config_path(rdpShadowServer* server)
return -1;
}
server->ConfigPath = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp");
free(configHome);
server->ConfigPath = configHome;
}
}