[Spice-commits] 2 commits - spice-protocol vdagent/vdagent.cpp

Uri Lublin uril at kemper.freedesktop.org
Thu Mar 20 05:49:05 PDT 2014


 spice-protocol      |    2 +-
 vdagent/vdagent.cpp |   42 ++++++++++++++++++++++++++++++++++++++----
 2 files changed, 39 insertions(+), 5 deletions(-)

New commits:
commit 4171d11bb69af84d45aee537a113eb4eebd09aa9
Author: Uri Lublin <uril at redhat.com>
Date:   Thu Feb 27 14:53:52 2014 +0200

    vdagent: clipboard: Add VD_AGENT_CAP_MAX_CLIPBOARD support
    
    Do not send clipboard data bigger than last received
    VDAgentMaxClipboard.
    
    If a larger amount of data needs to be transferred between client and guest,
    a different mechanism should be used, not clipboard.
    
    The spice-protocol git-submodule is updated to include VD_AGENT_MAX_CLIPBOARD
    and related definitions.

diff --git a/spice-protocol b/spice-protocol
index 784407f..5ff3fa7 160000
--- a/spice-protocol
+++ b/spice-protocol
@@ -1 +1 @@
-Subproject commit 784407f248e7f99d2bfcc9368f9acd1efb2b9617
+Subproject commit 5ff3fa7080bd08392fc011175657264d57dddcec
diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index 3131376..15216d9 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -92,6 +92,7 @@ private:
     bool handle_clipboard_request(VDAgentClipboardRequest* clipboard_request);
     void handle_clipboard_release();
     bool handle_display_config(VDAgentDisplayConfig* display_config, uint32_t port);
+    bool handle_max_clipboard(VDAgentMaxClipboard *msg, uint32_t size);
     void handle_chunk(VDIChunk* chunk);
     void on_clipboard_grab();
     void on_clipboard_request(UINT format);
@@ -164,6 +165,7 @@ private:
     bool _display_setting_initialized;
     bool _logon_occured;
 
+    int32_t _max_clipboard;
     uint32_t *_client_caps;
     uint32_t _client_caps_size;
 
@@ -210,6 +212,7 @@ VDAgent::VDAgent()
     , _write_pos (0)
     , _logon_desktop (false)
     , _display_setting_initialized (false)
+    , _max_clipboard (-1)
     , _client_caps (NULL)
     , _client_caps_size (0)
     , _log (NULL)
@@ -799,6 +802,7 @@ bool VDAgent::send_announce_capabilities(bool request)
     VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND);
     VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_SPARSE_MONITORS_CONFIG);
     VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_GUEST_LINEEND_CRLF);
+    VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_MAX_CLIPBOARD);
     vd_printf("Sending capabilities:");
     for (uint32_t i = 0 ; i < caps_size; ++i) {
         vd_printf("%X", caps->caps[i]);
@@ -874,6 +878,18 @@ bool VDAgent::handle_display_config(VDAgentDisplayConfig* display_config, uint32
     return true;
 }
 
+bool VDAgent::handle_max_clipboard(VDAgentMaxClipboard *msg, uint32_t size)
+{
+    if (size != sizeof(VDAgentMaxClipboard)) {
+        vd_printf("VDAgentMaxClipboard: unexpected msg size %u (expected %u)",
+                  size, sizeof(VDAgentMaxClipboard));
+        return false;
+    }
+    vd_printf("Set max clipboard size: %d", msg->max);
+    _max_clipboard = msg->max;
+    return true;
+}
+
 #define MIN(a, b) ((a) > (b) ? (b) : (a))
 
 bool VDAgent::write_clipboard(VDAgentMessage* msg, uint32_t size)
@@ -1109,6 +1125,11 @@ bool VDAgent::handle_clipboard_request(VDAgentClipboardRequest* clipboard_reques
         vd_printf("clipboard is empty");
         goto handle_clipboard_request_fail;
     }
+    if ((_max_clipboard != -1) && (new_size > _max_clipboard)) {
+        vd_printf("clipboard is too large (%ld > %d), discarding",
+                  new_size, _max_clipboard);
+        goto handle_clipboard_request_fail;
+    }
 
     msg_size = sizeof(VDAgentMessage) + sizeof(VDAgentClipboard) + new_size;
     msg = (VDAgentMessage*)new uint8_t[msg_size];
@@ -1262,6 +1283,9 @@ void VDAgent::dispatch_message(VDAgentMessage* msg, uint32_t port)
         vd_printf("Client disconnected, agent to be restarted");
         set_control_event(CONTROL_STOP);
         break;
+    case VD_AGENT_MAX_CLIPBOARD:
+        res = handle_max_clipboard((VDAgentMaxClipboard*)msg->data, msg->size);
+        break;
     default:
         vd_printf("Unsupported message type %u size %u", msg->type, msg->size);
     }
commit aed39aeccfec9b9b269fe117d852c4bf7b7af4be
Author: Uri Lublin <uril at redhat.com>
Date:   Thu Feb 27 14:49:59 2014 +0200

    vdagent: clipboard: GlobalUnlock on handle_request failure
    
    Moved clipboard definition to the beginning of the function, as
    mingw-gcc complains about gotos that jump over definitions.

diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index 260ee40..3131376 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -1051,9 +1051,10 @@ bool VDAgent::handle_clipboard_request(VDAgentClipboardRequest* clipboard_reques
     UINT format;
     HANDLE clip_data;
     uint8_t* new_data = NULL;
-    long new_size;
+    long new_size = 0;
     size_t len = 0;
     CxImage image;
+    VDAgentClipboard* clipboard = NULL;
 
     if (_clipboard_owner != owner_guest) {
         vd_printf("Received clipboard request from client while clipboard is not owned by guest");
@@ -1103,17 +1104,19 @@ bool VDAgent::handle_clipboard_request(VDAgentClipboardRequest* clipboard_reques
         break;
     }
     }
+
     if (!new_size) {
-        CloseClipboard();
-        return false;
+        vd_printf("clipboard is empty");
+        goto handle_clipboard_request_fail;
     }
+
     msg_size = sizeof(VDAgentMessage) + sizeof(VDAgentClipboard) + new_size;
     msg = (VDAgentMessage*)new uint8_t[msg_size];
     msg->protocol = VD_AGENT_PROTOCOL;
     msg->type = VD_AGENT_CLIPBOARD;
     msg->opaque = 0;
     msg->size = (uint32_t)(sizeof(VDAgentClipboard) + new_size);
-    VDAgentClipboard* clipboard = (VDAgentClipboard*)msg->data;
+    clipboard = (VDAgentClipboard*)msg->data;
     clipboard->type = clipboard_request->type;
 
     switch (clipboard_request->type) {
@@ -1132,6 +1135,13 @@ bool VDAgent::handle_clipboard_request(VDAgentClipboardRequest* clipboard_reques
     write_clipboard(msg, msg_size);
     delete[] (uint8_t *)msg;
     return true;
+
+handle_clipboard_request_fail:
+    if (clipboard_request->type == VD_AGENT_CLIPBOARD_UTF8_TEXT) {
+       GlobalUnlock(clip_data);
+    }
+    CloseClipboard();
+    return false;
 }
 
 void VDAgent::handle_clipboard_release()


More information about the Spice-commits mailing list