[Spice-devel] [PATCH 0.8 6/9] server: add discard all option to agent message filter

Hans de Goede hdegoede at redhat.com
Fri Apr 1 08:13:06 PDT 2011


---
 server/agent-msg-filter.c |   30 ++++++++++++++++++------------
 server/agent-msg-filter.h |    5 +++--
 server/reds.c             |    9 +++++----
 3 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/server/agent-msg-filter.c b/server/agent-msg-filter.c
index 3867d11..cd1f78c 100644
--- a/server/agent-msg-filter.c
+++ b/server/agent-msg-filter.c
@@ -22,10 +22,12 @@
 #include "red_common.h"
 #include "agent-msg-filter.h"
 
-void agent_msg_filter_init(struct AgentMsgFilter *filter, int copy_paste)
+void agent_msg_filter_init(struct AgentMsgFilter *filter,
+    int copy_paste, int discard_all)
 {
     memset(filter, 0, sizeof(*filter));
     filter->copy_paste_enabled = copy_paste;
+    filter->discard_all = discard_all;
 }
 
 int agent_msg_filter_process_data(struct AgentMsgFilter *filter,
@@ -61,19 +63,23 @@ data_to_read:
         return AGENT_MSG_FILTER_PROTO_ERROR;
     }
 
-    switch (msg_header.type) {
-    case VD_AGENT_CLIPBOARD:
-    case VD_AGENT_CLIPBOARD_GRAB:
-    case VD_AGENT_CLIPBOARD_REQUEST:
-    case VD_AGENT_CLIPBOARD_RELEASE:
-        if (filter->copy_paste_enabled) {
+    if (filter->discard_all) {
+        filter->result = AGENT_MSG_FILTER_DISCARD;
+    } else {
+        switch (msg_header.type) {
+        case VD_AGENT_CLIPBOARD:
+        case VD_AGENT_CLIPBOARD_GRAB:
+        case VD_AGENT_CLIPBOARD_REQUEST:
+        case VD_AGENT_CLIPBOARD_RELEASE:
+            if (filter->copy_paste_enabled) {
+                filter->result = AGENT_MSG_FILTER_OK;
+            } else {
+                filter->result = AGENT_MSG_FILTER_DISCARD;
+            }
+            break;
+        default:
             filter->result = AGENT_MSG_FILTER_OK;
-        } else {
-            filter->result = AGENT_MSG_FILTER_DISCARD;
         }
-        break;
-    default:
-        filter->result = AGENT_MSG_FILTER_OK;
     }
 
     filter->msg_data_to_read = msg_header.size;
diff --git a/server/agent-msg-filter.h b/server/agent-msg-filter.h
index 99dbb8c..ecccfc7 100644
--- a/server/agent-msg-filter.h
+++ b/server/agent-msg-filter.h
@@ -32,13 +32,14 @@ enum {
 };
 
 typedef struct AgentMsgFilter {
-    struct VDAgentMessage msg_header;
     int msg_data_to_read;
     int result;
     int copy_paste_enabled;
+    int discard_all;
 } AgentMsgFilter;
 
-void agent_msg_filter_init(struct AgentMsgFilter *filter, int copy_paste);
+void agent_msg_filter_init(struct AgentMsgFilter *filter,
+                           int copy_paste, int discard_all);
 int agent_msg_filter_process_data(struct AgentMsgFilter *filter,
                                   uint8_t *data, uint32_t len);
 
diff --git a/server/reds.c b/server/reds.c
index 7a3399e..40b6bb0 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -713,7 +713,7 @@ static void reds_reset_vdp()
         ring_add(&state->read_bufs, &state->current_read_buf->link);
         state->current_read_buf = NULL;
     }
-    agent_msg_filter_init(&state->read_filter, agent_copypaste);
+    agent_msg_filter_init(&state->read_filter, agent_copypaste, FALSE);
     state->client_agent_started = FALSE;
 }
 
@@ -744,7 +744,8 @@ static void reds_disconnect()
     red_printf("");
     reds->disconnecting = TRUE;
     reds_reset_outgoing();
-    agent_msg_filter_init(&reds->agent_state.write_filter, agent_copypaste);
+    agent_msg_filter_init(&reds->agent_state.write_filter, agent_copypaste,
+                          FALSE);
 
     if (reds->agent_state.connected) {
         SpiceCharDeviceInterface *sif;
@@ -3750,8 +3751,8 @@ static void init_vd_agent_resources()
     ring_init(&state->internal_bufs);
     ring_init(&state->write_queue);
     ring_init(&state->read_bufs);
-    agent_msg_filter_init(&state->write_filter, agent_copypaste);
-    agent_msg_filter_init(&state->read_filter, agent_copypaste);
+    agent_msg_filter_init(&state->write_filter, agent_copypaste, FALSE);
+    agent_msg_filter_init(&state->read_filter, agent_copypaste, FALSE);
 
     state->read_state = VDI_PORT_READ_STATE_READ_HADER;
     state->recive_pos = (uint8_t *)&state->vdi_chunk_header;
-- 
1.7.4.2



More information about the Spice-devel mailing list