From 7faac2aef4084d70479521acd85dce9c03affa96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 29 Aug 2023 20:31:30 +0200 Subject: [PATCH] remote-desktop/session: Add API to acquire new mapping ID They are guaranteed to be unique per session, and never reused. Part-of: --- src/backends/meta-remote-desktop-session.c | 25 ++++++++++++++++++++++ src/backends/meta-remote-desktop-session.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/src/backends/meta-remote-desktop-session.c b/src/backends/meta-remote-desktop-session.c index 7cd374fea..60b34fade 100644 --- a/src/backends/meta-remote-desktop-session.c +++ b/src/backends/meta-remote-desktop-session.c @@ -102,6 +102,8 @@ struct _MetaRemoteDesktopSession MetaSelectionSourceRemote *current_source; GHashTable *transfer_requests; guint transfer_request_timeout_id; + + GHashTable *mapping_ids; }; static void initable_init_iface (GInitableIface *iface); @@ -296,6 +298,25 @@ meta_remote_desktop_session_register_screen_cast (MetaRemoteDesktopSession *ses return TRUE; } +const char * +meta_remote_desktop_session_acquire_mapping_id (MetaRemoteDesktopSession *session) +{ + while (TRUE) + { + char *mapping_id; + + mapping_id = g_uuid_string_random (); + if (g_hash_table_contains (session->mapping_ids, mapping_id)) + { + g_free (mapping_id); + continue; + } + + g_hash_table_add (session->mapping_ids, mapping_id); + return mapping_id; + } +} + static gboolean check_permission (MetaRemoteDesktopSession *session, GDBusMethodInvocation *invocation) @@ -1731,6 +1752,8 @@ meta_remote_desktop_session_initable_init (GInitable *initable, session, "num-lock-state", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE); + session->mapping_ids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + return TRUE; } @@ -1784,6 +1807,8 @@ meta_remote_desktop_session_finalize (GObject *object) cancel_selection_read (session); g_hash_table_unref (session->transfer_requests); + g_clear_pointer (&session->mapping_ids, g_hash_table_unref); + g_clear_object (&session->handle); g_free (session->peer_name); g_free (session->session_id); diff --git a/src/backends/meta-remote-desktop-session.h b/src/backends/meta-remote-desktop-session.h index efbe12730..6555fc310 100644 --- a/src/backends/meta-remote-desktop-session.h +++ b/src/backends/meta-remote-desktop-session.h @@ -42,6 +42,8 @@ gboolean meta_remote_desktop_session_register_screen_cast (MetaRemoteDesktopSess MetaScreenCastSession *screen_cast_session, GError **error); +const char * meta_remote_desktop_session_acquire_mapping_id (MetaRemoteDesktopSession *session); + void meta_remote_desktop_session_request_transfer (MetaRemoteDesktopSession *session, const char *mime_type, GTask *task);