[gnome-remote-desktop] Explicitly enable/disable backends via a setting
- From: Jonas Ådahl <jadahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-remote-desktop] Explicitly enable/disable backends via a setting
- Date: Fri, 25 Feb 2022 20:19:20 +0000 (UTC)
commit 4f80037a1e17e3205d1a07cf8060a46f92a12f48
Author: Jonas Ådahl <jadahl gmail com>
Date: Mon Jan 24 09:36:25 2022 +0100
Explicitly enable/disable backends via a setting
One might want to run the RDP server without enabling VNC, or vice
versa. Make this more explicit and less dependent on things being
configured by adding a setting under each backends settings schema.
This also removes session tracking from GrdContext, and responsibility
of management of sessions are fully moved to the corresponding server
implementations.
.gitlab-ci.yml | 1 +
.gitlab-ci/run-tests.sh | 1 +
src/grd-context.c | 24 -----
src/grd-context.h | 5 -
src/grd-daemon.c | 106 +++++++++++++++------
src/grd-rdp-server.c | 1 -
src/grd-settings.c | 62 +++++++++++-
src/grd-settings.h | 4 +
src/grd-vnc-server.c | 1 -
...org.gnome.desktop.remote-desktop.gschema.xml.in | 14 +++
10 files changed, 155 insertions(+), 64 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5ae7012e..f2616576 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -105,6 +105,7 @@ test-gnome-remote-desktop:
variables:
XDG_RUNTIME_DIR: "$CI_PROJECT_DIR/runtime-dir"
GSETTINGS_SCHEMA_DIR: "$CI_PROJECT_DIR/build/src"
+ GSETTINGS_BACKEND: "keyfile"
script:
- mkdir -m 700 $XDG_RUNTIME_DIR
- glib-compile-schemas $GSETTINGS_SCHEMA_DIR
diff --git a/.gitlab-ci/run-tests.sh b/.gitlab-ci/run-tests.sh
index 88867a74..5f7aea4a 100755
--- a/.gitlab-ci/run-tests.sh
+++ b/.gitlab-ci/run-tests.sh
@@ -7,4 +7,5 @@ sleep 1
wireplumber &
sleep 1
+gsettings set org.gnome.desktop.remote-desktop.vnc enable true
meson test -C build --no-rebuild --verbose --no-stdsplit -t 10
diff --git a/src/grd-context.c b/src/grd-context.c
index 0d9bed1d..fd62ec97 100644
--- a/src/grd-context.c
+++ b/src/grd-context.c
@@ -46,8 +46,6 @@ struct _GrdContext
GrdSettings *settings;
- GList *sessions;
-
GrdDebugFlags debug_flags;
};
@@ -87,28 +85,6 @@ grd_context_get_main_context (GrdContext *context)
return context->main_context;
}
-static void
-on_session_stopped (GrdSession *session,
- GrdContext *context)
-{
- context->sessions = g_list_remove (context->sessions, session);
-}
-
-void
-grd_context_add_session (GrdContext *context,
- GrdSession *session)
-{
- context->sessions = g_list_append (context->sessions, session);
- g_signal_connect (session, "stopped",
- G_CALLBACK (on_session_stopped), context);
-}
-
-GList *
-grd_context_get_sessions (GrdContext *context)
-{
- return context->sessions;
-}
-
GrdSettings *
grd_context_get_settings (GrdContext *context)
{
diff --git a/src/grd-context.h b/src/grd-context.h
index a7b9cb87..d94d8054 100644
--- a/src/grd-context.h
+++ b/src/grd-context.h
@@ -53,11 +53,6 @@ GrdPipeWireStreamMonitor *grd_context_get_pipewire_stream_monitor (GrdContext *c
GMainContext *grd_context_get_main_context (GrdContext *context);
-void grd_context_add_session (GrdContext *context,
- GrdSession *session);
-
-GList * grd_context_get_sessions (GrdContext *context);
-
GrdSettings * grd_context_get_settings (GrdContext *context);
GrdEglThread * grd_context_get_egl_thread (GrdContext *context);
diff --git a/src/grd-daemon.c b/src/grd-daemon.c
index 64fe5ed2..54a27888 100644
--- a/src/grd-daemon.c
+++ b/src/grd-daemon.c
@@ -68,29 +68,27 @@ is_daemon_ready (GrdDaemon *daemon)
}
#ifdef HAVE_RDP
-static gboolean
-init_rdp_server (GrdDaemon *daemon)
+static void
+start_rdp_server (GrdDaemon *daemon)
{
GrdSettings *settings = grd_context_get_settings (daemon->context);
g_autoptr (GError) error = NULL;
- gboolean result = FALSE;
- daemon->rdp_server = NULL;
+ g_assert (!daemon->rdp_server);
+
if (!g_access (grd_settings_get_rdp_server_cert (settings), F_OK) &&
!g_access (grd_settings_get_rdp_server_key (settings), F_OK))
{
daemon->rdp_server = grd_rdp_server_new (daemon->context);
- if (!(result = grd_rdp_server_start (daemon->rdp_server, &error)))
- g_warning ("Failed to initialize RDP server: %s\n", error->message);
+ if (!grd_rdp_server_start (daemon->rdp_server, &error))
+ g_warning ("Failed to start RDP server: %s\n", error->message);
else
- g_message ("Initialized RDP server");
+ g_message ("RDP server started");
}
else
{
- g_message ("Didn't initialize RDP server: not configured");
+ g_warning ("RDP TLS certificate and key not configured properly");
}
-
- return result;
}
static void
@@ -99,26 +97,25 @@ stop_rdp_server (GrdDaemon *daemon)
if (!daemon->rdp_server)
return;
- g_message ("Stopping RDP server");
grd_rdp_server_stop (daemon->rdp_server);
g_clear_object (&daemon->rdp_server);
+ g_message ("RDP server stopped");
}
#endif /* HAVE_RDP */
#ifdef HAVE_VNC
-static gboolean
-init_vnc_server (GrdDaemon *daemon)
+static void
+start_vnc_server (GrdDaemon *daemon)
{
g_autoptr (GError) error = NULL;
- gboolean result;
+
+ g_assert (!daemon->vnc_server);
daemon->vnc_server = grd_vnc_server_new (daemon->context);
- if (!(result = grd_vnc_server_start (daemon->vnc_server, &error)))
+ if (!grd_vnc_server_start (daemon->vnc_server, &error))
g_warning ("Failed to initialize VNC server: %s\n", error->message);
else
- g_message ("Initialized VNC server");
-
- return result;
+ g_message ("VNC server started");
}
static void
@@ -127,33 +124,29 @@ stop_vnc_server (GrdDaemon *daemon)
if (!daemon->vnc_server)
return;
- g_message ("Stopping VNC server");
grd_vnc_server_stop (daemon->vnc_server);
g_clear_object (&daemon->vnc_server);
+ g_message ("VNC server stopped");
}
#endif /* HAVE_VNC */
static void
maybe_enable_services (GrdDaemon *daemon)
{
- gboolean has_one_backend = FALSE;
+ GrdSettings *settings = grd_context_get_settings (daemon->context);
if (!is_daemon_ready (daemon))
return;
#ifdef HAVE_RDP
- has_one_backend = init_rdp_server (daemon) || has_one_backend;
+ if (grd_settings_is_rdp_enabled (settings))
+ start_rdp_server (daemon);
#endif
#ifdef HAVE_VNC
- has_one_backend = init_vnc_server (daemon) || has_one_backend;
+ if (grd_settings_is_vnc_enabled (settings))
+ start_vnc_server (daemon);
#endif
-
- if (!has_one_backend)
- {
- g_warning ("No backend initialized successfully. Exiting");
- g_application_release (G_APPLICATION (daemon));
- }
}
static void
@@ -165,8 +158,6 @@ disable_services (GrdDaemon *daemon)
#ifdef HAVE_VNC
stop_vnc_server (daemon);
#endif
-
- g_assert (!grd_context_get_sessions (daemon->context));
}
static void
@@ -268,10 +259,65 @@ on_screen_cast_name_vanished (GDBusConnection *connection,
grd_context_set_screen_cast_proxy (daemon->context, NULL);
}
+#ifdef HAVE_RDP
+static void
+on_rdp_enabled_changed (GrdSettings *settings,
+ GrdDaemon *daemon)
+{
+ if (!is_daemon_ready (daemon))
+ return;
+
+ if (grd_settings_is_rdp_enabled (settings))
+ {
+ g_return_if_fail (!daemon->rdp_server);
+ start_rdp_server (daemon);
+ }
+ else
+ {
+ stop_rdp_server (daemon);
+ }
+}
+#endif /* HAVE_RDP */
+
+#ifdef HAVE_VNC
+static void
+on_vnc_enabled_changed (GrdSettings *settings,
+ GrdDaemon *daemon)
+{
+ if (!is_daemon_ready (daemon))
+ return;
+
+ if (grd_settings_is_vnc_enabled (settings))
+ {
+ g_return_if_fail (!daemon->vnc_server);
+ start_vnc_server (daemon);
+ }
+ else
+ {
+ stop_vnc_server (daemon);
+ }
+}
+#endif /* HAVE_VNC */
+
static void
grd_daemon_init (GrdDaemon *daemon)
{
+ GrdSettings *settings;
+
daemon->context = g_object_new (GRD_TYPE_CONTEXT, NULL);
+
+ settings = grd_context_get_settings (daemon->context);
+
+#ifdef HAVE_RDP
+ g_signal_connect (settings, "rdp-enabled-changed",
+ G_CALLBACK (on_rdp_enabled_changed),
+ daemon);
+#endif
+#ifdef HAVE_VNC
+ g_signal_connect (settings, "vnc-enabled-changed",
+ G_CALLBACK (on_vnc_enabled_changed),
+ daemon);
+#endif
}
static void
diff --git a/src/grd-rdp-server.c b/src/grd-rdp-server.c
index 3d986377..41963f9b 100644
--- a/src/grd-rdp-server.c
+++ b/src/grd-rdp-server.c
@@ -146,7 +146,6 @@ on_incoming (GSocketService *service,
return TRUE;
rdp_server->sessions = g_list_append (rdp_server->sessions, session_rdp);
- grd_context_add_session (rdp_server->context, GRD_SESSION (session_rdp));
g_signal_connect (session_rdp, "stopped",
G_CALLBACK (on_session_stopped),
diff --git a/src/grd-settings.c b/src/grd-settings.c
index 0d23f70f..c8f28fb4 100644
--- a/src/grd-settings.c
+++ b/src/grd-settings.c
@@ -34,10 +34,12 @@
enum
{
+ RDP_ENABLED_CHANGED,
RDP_SCREEN_SHARE_MODE_CHANGED,
RDP_SERVER_CERT_CHANGED,
RDP_SERVER_KEY_CHANGED,
RDP_VIEW_ONLY_CHANGED,
+ VNC_ENABLED_CHANGED,
VNC_VIEW_ONLY_CHANGED,
VNC_AUTH_METHOD_CHANGED,
VNC_ENCRYPTION_CHANGED,
@@ -54,6 +56,7 @@ struct _GrdSettings
struct {
GSettings *settings;
+ gboolean is_enabled;
GrdRdpScreenShareMode screen_share_mode;
char *server_cert;
char *server_key;
@@ -62,6 +65,7 @@ struct _GrdSettings
} rdp;
struct {
GSettings *settings;
+ gboolean is_enabled;
gboolean view_only;
GrdVncAuthMethod auth_method;
int port;
@@ -220,6 +224,18 @@ grd_settings_get_vnc_view_only (GrdSettings *settings)
return settings->vnc.view_only;
}
+gboolean
+grd_settings_is_rdp_enabled (GrdSettings *settings)
+{
+ return settings->rdp.is_enabled;
+}
+
+gboolean
+grd_settings_is_vnc_enabled (GrdSettings *settings)
+{
+ return settings->vnc.is_enabled;
+}
+
GrdVncAuthMethod
grd_settings_get_vnc_auth_method (GrdSettings *settings)
{
@@ -236,6 +252,13 @@ update_screen_share_mode (GrdSettings *settings)
g_settings_get_enum (settings->rdp.settings, "screen-share-mode");
}
+static void
+update_rdp_enabled (GrdSettings *settings)
+{
+ settings->rdp.is_enabled = g_settings_get_boolean (settings->rdp.settings,
+ "enable");
+}
+
static void
update_rdp_tls_cert (GrdSettings *settings)
{
@@ -259,6 +282,13 @@ update_rdp_view_only (GrdSettings *settings)
"view-only");
}
+static void
+update_vnc_enabled (GrdSettings *settings)
+{
+ settings->vnc.is_enabled = g_settings_get_boolean (settings->vnc.settings,
+ "enable");
+}
+
static void
update_vnc_view_only (GrdSettings *settings)
{
@@ -278,12 +308,17 @@ on_rdp_settings_changed (GSettings *rdp_settings,
const char *key,
GrdSettings *settings)
{
- if (strcmp (key, "screen-share-mode") == 0)
+ if (strcmp (key, "enable") == 0)
+ {
+ update_rdp_enabled (settings);
+ g_signal_emit (settings, signals[RDP_ENABLED_CHANGED], 0);
+ }
+ else if (strcmp (key, "screen-share-mode") == 0)
{
update_screen_share_mode (settings);
g_signal_emit (settings, signals[RDP_SCREEN_SHARE_MODE_CHANGED], 0);
}
- if (strcmp (key, "tls-cert") == 0)
+ else if (strcmp (key, "tls-cert") == 0)
{
update_rdp_tls_cert (settings);
g_signal_emit (settings, signals[RDP_SERVER_CERT_CHANGED], 0);
@@ -305,7 +340,12 @@ on_vnc_settings_changed (GSettings *vnc_settings,
const char *key,
GrdSettings *settings)
{
- if (strcmp (key, "view-only") == 0)
+ if (strcmp (key, "enable") == 0)
+ {
+ update_vnc_enabled (settings);
+ g_signal_emit (settings, signals[VNC_ENABLED_CHANGED], 0);
+ }
+ else if (strcmp (key, "view-only") == 0)
{
update_vnc_view_only (settings);
g_signal_emit (settings, signals[VNC_VIEW_ONLY_CHANGED], 0);
@@ -341,10 +381,12 @@ grd_settings_init (GrdSettings *settings)
g_signal_connect (settings->vnc.settings, "changed",
G_CALLBACK (on_vnc_settings_changed), settings);
+ update_rdp_enabled (settings);
update_screen_share_mode (settings);
update_rdp_tls_cert (settings);
update_rdp_tls_key (settings);
update_rdp_view_only (settings);
+ update_vnc_enabled (settings);
update_vnc_view_only (settings);
update_vnc_auth_method (settings);
@@ -359,6 +401,13 @@ grd_settings_class_init (GrdSettingsClass *klass)
object_class->finalize = grd_settings_finalize;
+ signals[RDP_ENABLED_CHANGED] =
+ g_signal_new ("rdp-enabled-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
signals[RDP_SCREEN_SHARE_MODE_CHANGED] =
g_signal_new ("rdp-screen-share-mode-changed",
G_TYPE_FROM_CLASS (klass),
@@ -387,6 +436,13 @@ grd_settings_class_init (GrdSettingsClass *klass)
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
+ signals[VNC_ENABLED_CHANGED] =
+ g_signal_new ("vnc-enabled-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
signals[VNC_VIEW_ONLY_CHANGED] =
g_signal_new ("vnc-view-only-changed",
G_TYPE_FROM_CLASS (klass),
diff --git a/src/grd-settings.h b/src/grd-settings.h
index 4ba70cbc..449894ae 100644
--- a/src/grd-settings.h
+++ b/src/grd-settings.h
@@ -30,6 +30,10 @@
G_DECLARE_FINAL_TYPE (GrdSettings, grd_settings,
GRD, SETTINGS, GObject)
+gboolean grd_settings_is_rdp_enabled (GrdSettings *settings);
+
+gboolean grd_settings_is_vnc_enabled (GrdSettings *settings);
+
int grd_settings_get_rdp_port (GrdSettings *settings);
int grd_settings_get_vnc_port (GrdSettings *settings);
diff --git a/src/grd-vnc-server.c b/src/grd-vnc-server.c
index b2531079..633fa858 100644
--- a/src/grd-vnc-server.c
+++ b/src/grd-vnc-server.c
@@ -121,7 +121,6 @@ on_incoming (GSocketService *service,
session_vnc = grd_session_vnc_new (vnc_server, connection);
vnc_server->sessions = g_list_append (vnc_server->sessions, session_vnc);
- grd_context_add_session (vnc_server->context, GRD_SESSION (session_vnc));
g_signal_connect (session_vnc, "stopped",
G_CALLBACK (on_session_stopped),
diff --git a/src/org.gnome.desktop.remote-desktop.gschema.xml.in
b/src/org.gnome.desktop.remote-desktop.gschema.xml.in
index e61e6bc5..939b9a68 100644
--- a/src/org.gnome.desktop.remote-desktop.gschema.xml.in
+++ b/src/org.gnome.desktop.remote-desktop.gschema.xml.in
@@ -2,6 +2,13 @@
<schema id='org.gnome.desktop.remote-desktop' path='/org/gnome/desktop/remote-desktop/'>
</schema>
<schema id='org.gnome.desktop.remote-desktop.rdp' path='/org/gnome/desktop/remote-desktop/rdp/'>
+ <key name='enable' type='b'>
+ <default>false</default>
+ <summary>Whether the RDP backend is enabled or not</summary>
+ <description>
+ If set to to 'true' the RDP backend will be initialized.
+ </description>
+ </key>
<key name='screen-share-mode' enum='org.gnome.desktop.remote-desktop.GrdRdpScreenShareMode'>
<default>'mirror-primary'</default>
<summary>Screenshare mode of RDP connections</summary>
@@ -55,6 +62,13 @@
</key>
</schema>
<schema id='org.gnome.desktop.remote-desktop.vnc' path='/org/gnome/desktop/remote-desktop/vnc/'>
+ <key name='enable' type='b'>
+ <default>false</default>
+ <summary>Whether the VNC backend is enabled or not</summary>
+ <description>
+ If set to to 'true' the VNC backend will be initialized.
+ </description>
+ </key>
<key name='view-only' type='b'>
<default>true</default>
<summary>Only allow remote connections to view the screen content</summary>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]