FreeRDP
Loading...
Searching...
No Matches
shadow_subsystem_builtin.c
1
19#include <freerdp/config.h>
20
21#include <freerdp/server/shadow.h>
22#include <freerdp/log.h>
23
24#define TAG SERVER_TAG("shadow")
25
26typedef struct
27{
28 const char* (*name)(void);
29 pfnShadowSubsystemEntry entry;
30} RDP_SHADOW_SUBSYSTEM;
31
32#if defined(WITH_SHADOW_MUTTER)
33extern int MutterShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints);
34extern const char* MutterShadowSubsystemName(void);
35#endif
36
37#if defined(WITH_SHADOW_PLATFORM)
38/* The platform's own: Win, Mac, X11 or Sample */
39extern int ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints);
40extern const char* ShadowSubsystemName(void);
41#endif
42
43/* In the order they are tried. Mutter comes first: inside a GNOME session on
44 * Wayland, X11 would only see Xwayland, and outside GNOME Mutter finds nothing. */
45static const RDP_SHADOW_SUBSYSTEM g_Subsystems[] = {
46#if defined(WITH_SHADOW_MUTTER)
47 { MutterShadowSubsystemName, MutterShadowSubsystemEntry },
48#endif
49#if defined(WITH_SHADOW_PLATFORM)
50 { ShadowSubsystemName, ShadowSubsystemEntry },
51#endif
52};
53
54static const size_t g_SubsystemCount = ARRAYSIZE(g_Subsystems);
55
56WINPR_ATTR_NODISCARD
57static pfnShadowSubsystemEntry shadow_subsystem_load_static_entry(const char* name)
58{
59 WINPR_ASSERT(name);
60
61 for (size_t index = 0; index < g_SubsystemCount; index++)
62 {
63 const RDP_SHADOW_SUBSYSTEM* cur = &g_Subsystems[index];
64 WINPR_ASSERT(cur->name);
65 WINPR_ASSERT(cur->entry);
66
67 if (strcmp(name, cur->name()) == 0)
68 return cur->entry;
69 }
70
71 return nullptr;
72}
73
74void shadow_subsystem_set_entry_builtin(const char* name)
75{
76 if (!name)
77 {
78 /* all of them: the server picks one when it starts (see /subsystem) */
79 for (size_t index = 0; index < g_SubsystemCount; index++)
80 {
81 const RDP_SHADOW_SUBSYSTEM* cur = &g_Subsystems[index];
82 if (!shadow_subsystem_add_entry(cur->name(), cur->entry))
83 WLog_ERR(TAG, "cannot add the %s subsystem", cur->name());
84 }
85 return;
86 }
87
88 pfnShadowSubsystemEntry entry = shadow_subsystem_load_static_entry(name);
89
90 if (entry)
91 shadow_subsystem_set_entry(entry);
92}