[Spice-devel] [PATCH spice-server 6/8] red-channel: Make parser function compulsory

Frediano Ziglio fziglio at redhat.com
Mon Oct 7 10:39:04 UTC 2019


As base messages require parsing better channels should always use
the generated parser.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/red-channel-client.c       | 13 ++-----------
 server/red-channel.c              |  1 +
 server/tests/test-stream-device.c |  3 +++
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index 66b8fd4a..35eafa7a 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -1175,18 +1175,9 @@ static uint8_t *red_channel_client_parse(RedChannelClient *rcc, uint8_t *message
 {
     RedChannel *channel = red_channel_client_get_channel(rcc);
     RedChannelClass *klass = RED_CHANNEL_GET_CLASS(channel);
-    uint8_t *parsed_message;
 
-    if (klass->parser) {
-        parsed_message = klass->parser(message, message + message_size, message_type,
-                                       SPICE_VERSION_MINOR, size_out, free_message);
-    } else {
-        parsed_message = message;
-        *size_out = message_size;
-        *free_message = NULL;
-    }
-
-    return parsed_message;
+    return klass->parser(message, message + message_size, message_type,
+                         SPICE_VERSION_MINOR, size_out, free_message);
 }
 
 // TODO: this implementation, as opposed to the old implementation in red_worker,
diff --git a/server/red-channel.c b/server/red-channel.c
index c36b68dc..0ed58dc8 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -208,6 +208,7 @@ red_channel_constructed(GObject *object)
 
     G_OBJECT_CLASS(red_channel_parent_class)->constructed(object);
 
+    spice_assert(klass->parser != NULL);
     spice_assert(klass->handle_migrate_data ||
                  !(self->priv->migration_flags & SPICE_MIGRATE_NEED_DATA_TRANSFER));
 }
diff --git a/server/tests/test-stream-device.c b/server/tests/test-stream-device.c
index 613caed3..abf66f04 100644
--- a/server/tests/test-stream-device.c
+++ b/server/tests/test-stream-device.c
@@ -122,6 +122,9 @@ stream_channel_init(StreamChannel *channel)
 static void
 stream_channel_class_init(StreamChannelClass *klass)
 {
+    RedChannelClass *channel_class = RED_CHANNEL_CLASS(klass);
+
+    channel_class->parser = spice_get_client_channel_parser(SPICE_CHANNEL_DISPLAY, NULL);
 }
 
 void stream_channel_change_format(StreamChannel *channel,
-- 
2.21.0



More information about the Spice-devel mailing list