[X2Go-Commits] [nx-libs] 387/429: Clipboard.c: check target cache for valid targets

git-admin at x2go.org git-admin at x2go.org
Mon Oct 18 09:37:13 CEST 2021


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch 3.6.x
in repository nx-libs.

commit d97e5022e8e04f5316908dc772a491e5fe422b4c
Author: Ulrich Sibiller <uli42 at gmx.de>
Date:   Fri Feb 12 23:26:16 2021 +0100

    Clipboard.c: check target cache for valid targets
    
    Instead of passing the target to the remote side and then receiving an
    "invalid target" reply we can do that check directly (if the target
    cache is filled). This way we can save some more roundtrips due to the
    target cache.
---
 nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 98 ++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)

diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c
index 4c0c6d320..c85e61298 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c
@@ -1187,6 +1187,55 @@ void nxagentHandleSelectionRequestFromXServer(XEvent *X)
    * can process it now.
    */
 
+  if (!nxagentOption(TextClipboard))
+  {
+    /* Optimization: if we have a current target cache check if the
+     * requested target is supported by the owner. If not we can take
+     * a shortcut and deny the request immediately without doing any
+     * further communication */
+    if (targetCache[index].type == FORREM && targetCache[index].forRem)
+    {
+      XlibAtom *targets = targetCache[index].forRem;
+
+      #ifdef DEBUG
+      fprintf(stderr, "%s: Checking target validity\n", __func__);
+      #endif
+      Bool match = False;
+      for (int i = 0; i < targetCache[index].numTargets; i++)
+      {
+        if (targets[i] == X->xselectionrequest.target)
+        {
+          match = True;
+          break;
+        }
+      }
+      if (!match)
+      {
+        #ifdef DEBUG
+        fprintf(stderr, "%s: target [%ld][%s] is not supported by the owner - denying request.\n",
+                    __func__, X->xselectionrequest.target, NameForRemAtom(X->xselectionrequest.target));
+        #endif
+        replyRequestSelectionToXServer(X, False);
+        return;
+      }
+    }
+    else
+    {
+      /*
+       * at this stage we know a remote client has asked for a selection
+       * target without having retrieved the list of supported targets
+       * first.
+       */
+      #ifdef DEBUG
+      if (X->xselectionrequest.target != serverTARGETS)
+      {
+         fprintf(stderr, "%s: WARNING: remote client has not retrieved TARGETS before asking for selection!\n",
+                   __func__);
+      }
+      #endif
+    }
+  }
+
   /*
    * This is required for nxagentGetClipboardWindow.
    */
@@ -2620,6 +2669,55 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
               NameForIntAtom(target));
   #endif
 
+  if (!nxagentOption(TextClipboard))
+  {
+    /* Optimization: if we have a current target cache check if the
+     * requested target is supported by the owner. If not we can take
+     * a shortcut and deny the request immediately without doing any
+     * further communication */
+    if (targetCache[index].type == FORINT && targetCache[index].forInt)
+    {
+      Atom *targets = targetCache[index].forInt;
+
+      #ifdef DEBUG
+      fprintf(stderr, "%s: Checking target validity\n", __func__);
+      #endif
+      Bool match = False;
+      for (int i = 0; i < targetCache[index].numTargets; i++)
+      {
+        if (targets[i] == target)
+        {
+          match = True;
+          break;
+        }
+      }
+      if (!match)
+      {
+        #ifdef DEBUG
+        fprintf(stderr, "%s: target [%d][%s] is not supported by the owner - denying request.\n",
+                    __func__, target, NameForIntAtom(target));
+        #endif
+        sendSelectionNotifyEventToClient(client, time, requestor, selection, target, None);
+        return 1;
+      }
+    }
+    else
+    {
+      /*
+       * at this stage we know a client has asked for a selection
+       * target without having retrieved the list of supported targets
+       * first.
+       */
+      #ifdef DEBUG
+      if (target != clientTARGETS)
+      {
+         fprintf(stderr, "%s: WARNING: client has not retrieved TARGETS before asking for selection!\n",
+                   __func__);
+      }
+      #endif
+    }
+  }
+
   if (lastClients[index].clientPtr == client)
   {
     #ifdef DEBUG

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/nx-libs.git


More information about the x2go-commits mailing list