summaryrefslogtreecommitdiffstats
path: root/server/reds.c
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2011-03-24 16:29:25 +0100
committerHans de Goede <hdegoede@redhat.com>2011-03-24 17:28:21 +0100
commitc2db6d1066bcb73c5ddf9e38c4ef30545706eae9 (patch)
treea8941330bc01f58443c0afbd08a15aa295171291 /server/reds.c
parent66dde82fee3c4eb5262d582aeb77935efd40def0 (diff)
downloadspice-c2db6d1066bcb73c5ddf9e38c4ef30545706eae9.tar.gz
spice-c2db6d1066bcb73c5ddf9e38c4ef30545706eae9.tar.xz
spice-c2db6d1066bcb73c5ddf9e38c4ef30545706eae9.zip
spice-server: Add the ability to filter agent messages
Diffstat (limited to 'server/reds.c')
-rw-r--r--server/reds.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/server/reds.c b/server/reds.c
index c1873efb..4663a852 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -49,6 +49,7 @@
#include "reds.h"
#include <spice/protocol.h>
#include <spice/vd_agent.h>
+#include "agent-msg-filter.h"
#include "inputs_channel.h"
#include "main_channel.h"
@@ -158,6 +159,7 @@ typedef struct VDIPortState {
Ring external_bufs;
Ring internal_bufs;
Ring write_queue;
+ AgentMsgFilter write_filter;
Ring read_bufs;
uint32_t read_state;
@@ -165,6 +167,7 @@ typedef struct VDIPortState {
uint8_t *recive_pos;
uint32_t recive_len;
VDIReadBuf *current_read_buf;
+ AgentMsgFilter read_filter;
VDIChunkHeader vdi_chunk_header;
@@ -806,9 +809,24 @@ void vdi_read_buf_release(uint8_t *data, void *opaque)
static void dispatch_vdi_port_data(int port, VDIReadBuf *buf)
{
VDIPortState *state = &reds->agent_state;
+ int res;
switch (port) {
case VDP_CLIENT_PORT: {
+ res = agent_msg_filter_process_data(&state->read_filter,
+ buf->data, buf->len);
+ switch (res) {
+ case AGENT_MSG_FILTER_OK:
+ break;
+ case AGENT_MSG_FILTER_DISCARD:
+ ring_add(&state->read_bufs, &buf->link);
+ return;
+ case AGENT_MSG_FILTER_PROTO_ERROR:
+ ring_add(&state->read_bufs, &buf->link);
+ reds_agent_remove();
+ return;
+ }
+
if (reds->agent_state.connected) {
main_channel_push_agent_data(reds->main_channel, buf->data, buf->len,
vdi_read_buf_release, buf);
@@ -994,6 +1012,7 @@ void reds_on_main_agent_data(void *message, size_t size)
{
RingItem *ring_item;
VDAgentExtBuf *buf;
+ int res;
if (!reds->agent_state.num_client_tokens) {
red_printf("token violation");
@@ -1013,8 +1032,15 @@ void reds_on_main_agent_data(void *message, size_t size)
return;
}
- if (size > SPICE_AGENT_MAX_DATA_SIZE) {
- red_printf("invalid agent message");
+ res = agent_msg_filter_process_data(&reds->agent_state.write_filter,
+ message, size);
+ switch (res) {
+ case AGENT_MSG_FILTER_OK:
+ break;
+ case AGENT_MSG_FILTER_DISCARD:
+ add_token();
+ return;
+ case AGENT_MSG_FILTER_PROTO_ERROR:
reds_disconnect();
return;
}
@@ -3384,6 +3410,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, TRUE);
+ agent_msg_filter_init(&state->read_filter, TRUE);
state->read_state = VDI_PORT_READ_STATE_READ_HADER;
state->recive_pos = (uint8_t *)&state->vdi_chunk_header;