[gnome-remote-desktop] rdp: Only initialize clipboard if CLIPRDR channel is joined



commit 81ec1007d68a08437373997d8220f736bae1a8ff
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Sun Feb 13 17:21:13 2022 +0100

    rdp: Only initialize clipboard if CLIPRDR channel is joined
    
    There is no need to attempt to initialize the clipboard, if the channel
    is not even joined, as in that case the clipboard would be torn down
    anyway after the initialization.

 src/grd-clipboard-rdp.c | 14 +++++---------
 src/grd-session-rdp.c   | 11 ++++++++---
 2 files changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/src/grd-clipboard-rdp.c b/src/grd-clipboard-rdp.c
index 292f3bfe..8abbd8f0 100644
--- a/src/grd-clipboard-rdp.c
+++ b/src/grd-clipboard-rdp.c
@@ -2278,17 +2278,15 @@ grd_clipboard_rdp_new (GrdSessionRdp *session_rdp,
                        HANDLE         vcm,
                        HANDLE         stop_event)
 {
-  GrdClipboardRdp *clipboard_rdp;
+  g_autoptr (GrdClipboardRdp) clipboard_rdp = NULL;
   GrdClipboard *clipboard;
   CliprdrServerContext *cliprdr_context;
 
   clipboard_rdp = g_object_new (GRD_TYPE_CLIPBOARD_RDP, NULL);
   cliprdr_context = cliprdr_server_context_new (vcm);
-  if (!clipboard_rdp || !cliprdr_context)
+  if (!cliprdr_context)
     {
-      g_warning ("[RDP.CLIPRDR] An error occurred while creating the RDP clipboard");
-      g_clear_pointer (&cliprdr_context, cliprdr_server_context_free);
-      g_clear_object (&clipboard_rdp);
+      g_warning ("[RDP.CLIPRDR] Failed to create server context");
       return NULL;
     }
 
@@ -2318,15 +2316,13 @@ grd_clipboard_rdp_new (GrdSessionRdp *session_rdp,
 
   if (cliprdr_context->Start (cliprdr_context))
     {
-      g_message ("[RDP.CLIPRDR] An error occurred while starting the RDP "
-                 "clipboard. The RDP client might not support the CLIPRDR channel");
+      g_warning ("[RDP.CLIPRDR] Failed to open CLIPRDR channel");
       g_clear_pointer (&clipboard_rdp->cliprdr_context,
                        cliprdr_server_context_free);
-      g_clear_object (&clipboard_rdp);
       return NULL;
     }
 
-  return clipboard_rdp;
+  return g_steal_pointer (&clipboard_rdp);
 }
 
 static gboolean
diff --git a/src/grd-session-rdp.c b/src/grd-session-rdp.c
index 1e11dbfd..67d03279 100644
--- a/src/grd-session-rdp.c
+++ b/src/grd-session-rdp.c
@@ -2219,9 +2219,14 @@ grd_session_rdp_remote_desktop_session_ready (GrdSession *session)
   freerdp_peer *peer = session_rdp->peer;
   RdpPeerContext *rdp_peer_context = (RdpPeerContext *) peer->context;
 
-  rdp_peer_context->clipboard_rdp = grd_clipboard_rdp_new (session_rdp,
-                                                           rdp_peer_context->vcm,
-                                                           session_rdp->stop_event);
+  if (WTSVirtualChannelManagerIsChannelJoined (rdp_peer_context->vcm,
+                                               "cliprdr"))
+    {
+      rdp_peer_context->clipboard_rdp =
+        grd_clipboard_rdp_new (session_rdp,
+                               rdp_peer_context->vcm,
+                               session_rdp->stop_event);
+    }
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]