Blame SOURCES/0005-Notify-client-of-the-creation-of-new-channels-dynami.patch

ad1357
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
ad1357
From: Frediano Ziglio <fziglio@redhat.com>
ad1357
Date: Thu, 24 Aug 2017 23:37:25 +0100
ad1357
Subject: [spice-server] Notify client of the creation of new channels
ad1357
 dynamically
ad1357
ad1357
This allows the server to add channels after the client is connected.
ad1357
ad1357
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
ad1357
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
ad1357
---
ad1357
 server/main-channel-client.c | 51 ++++++++++++++++++++++++++++++++++++++++++++
ad1357
 server/main-channel-client.h |  3 +++
ad1357
 server/main-channel.c        |  6 ++++++
ad1357
 server/main-channel.h        |  3 +++
ad1357
 server/reds.c                |  2 ++
ad1357
 5 files changed, 65 insertions(+)
ad1357
ad1357
diff --git a/server/main-channel-client.c b/server/main-channel-client.c
ad1357
index b7b60eddb..61a2830fa 100644
ad1357
--- a/server/main-channel-client.c
ad1357
+++ b/server/main-channel-client.c
ad1357
@@ -62,6 +62,7 @@ struct MainChannelClientPrivate {
ad1357
     int mig_wait_prev_try_seamless;
ad1357
     int init_sent;
ad1357
     int seamless_mig_dst;
ad1357
+    bool initial_channels_list_sent;
ad1357
     uint8_t recv_buf[MAIN_CHANNEL_RECEIVE_BUF_SIZE];
ad1357
 };
ad1357
 
ad1357
@@ -119,6 +120,12 @@ typedef struct RedMultiMediaTimePipeItem {
ad1357
     uint32_t time;
ad1357
 } RedMultiMediaTimePipeItem;
ad1357
 
ad1357
+typedef struct RedRegisteredChannelPipeItem {
ad1357
+    RedPipeItem base;
ad1357
+    uint32_t channel_type;
ad1357
+    uint32_t channel_id;
ad1357
+} RedRegisteredChannelPipeItem;
ad1357
+
ad1357
 #define ZERO_BUF_SIZE 4096
ad1357
 
ad1357
 static const uint8_t zero_page[ZERO_BUF_SIZE] = {0};
ad1357
@@ -446,6 +453,20 @@ RedPipeItem *main_multi_media_time_item_new(uint32_t mm_time)
ad1357
     return &item->base;
ad1357
 }
ad1357
 
ad1357
+RedPipeItem *registered_channel_item_new(RedChannel *channel)
ad1357
+{
ad1357
+    RedRegisteredChannelPipeItem *item;
ad1357
+
ad1357
+    item = g_new0(RedRegisteredChannelPipeItem, 1);
ad1357
+    red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_MAIN_REGISTERED_CHANNEL);
ad1357
+
ad1357
+    uint32_t type, id;
ad1357
+    g_object_get(channel, "channel-type", &type, "id", &id, NULL);
ad1357
+    item->channel_type = type;
ad1357
+    item->channel_id = id;
ad1357
+    return &item->base;
ad1357
+}
ad1357
+
ad1357
 void main_channel_client_handle_migrate_connected(MainChannelClient *mcc,
ad1357
                                                   int success,
ad1357
                                                   int seamless)
ad1357
@@ -927,6 +948,25 @@ static void main_channel_marshall_agent_connected(SpiceMarshaller *m,
ad1357
     spice_marshall_msg_main_agent_connected_tokens(m, &connected);
ad1357
 }
ad1357
 
ad1357
+static void main_channel_marshall_registered_channel(RedChannelClient *rcc,
ad1357
+                                                     SpiceMarshaller *m,
ad1357
+                                                     RedRegisteredChannelPipeItem *item)
ad1357
+{
ad1357
+    struct {
ad1357
+        SpiceMsgChannels info;
ad1357
+        SpiceChannelId ids[1];
ad1357
+    } channels_info_buffer;
ad1357
+    SpiceMsgChannels* channels_info = &channels_info_buffer.info;
ad1357
+
ad1357
+    red_channel_client_init_send_data(rcc, SPICE_MSG_MAIN_CHANNELS_LIST);
ad1357
+
ad1357
+    channels_info->channels[0].type = item->channel_type;
ad1357
+    channels_info->channels[0].id = item->channel_id;
ad1357
+    channels_info->num_of_channels = 1;
ad1357
+
ad1357
+    spice_marshall_msg_main_channels_list(m, channels_info);
ad1357
+}
ad1357
+
ad1357
 void main_channel_client_send_item(RedChannelClient *rcc, RedPipeItem *base)
ad1357
 {
ad1357
     MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
ad1357
@@ -947,6 +987,7 @@ void main_channel_client_send_item(RedChannelClient *rcc, RedPipeItem *base)
ad1357
     switch (base->type) {
ad1357
         case RED_PIPE_ITEM_TYPE_MAIN_CHANNELS_LIST:
ad1357
             main_channel_marshall_channels(rcc, m, base);
ad1357
+            mcc->priv->initial_channels_list_sent = true;
ad1357
             break;
ad1357
         case RED_PIPE_ITEM_TYPE_MAIN_PING:
ad1357
             main_channel_marshall_ping(rcc, m,
ad1357
@@ -1003,6 +1044,16 @@ void main_channel_client_send_item(RedChannelClient *rcc, RedPipeItem *base)
ad1357
         case RED_PIPE_ITEM_TYPE_MAIN_AGENT_CONNECTED_TOKENS:
ad1357
             main_channel_marshall_agent_connected(m, rcc, base);
ad1357
             break;
ad1357
+        case RED_PIPE_ITEM_TYPE_MAIN_REGISTERED_CHANNEL:
ad1357
+            /* The spice protocol requires that the server receive a ATTACH_CHANNELS
ad1357
+             * message from the client before sending any CHANNEL_LIST message. If
ad1357
+             * we've already sent our initial CHANNELS_LIST message, then it should be
ad1357
+             * safe to send new ones for newly-registered channels. */
ad1357
+            if (mcc->priv->initial_channels_list_sent) {
ad1357
+                main_channel_marshall_registered_channel(rcc, m,
ad1357
+                    SPICE_UPCAST(RedRegisteredChannelPipeItem, base));
ad1357
+            }
ad1357
+            break;
ad1357
         default:
ad1357
             break;
ad1357
     };
ad1357
diff --git a/server/main-channel-client.h b/server/main-channel-client.h
ad1357
index 26b7e20b8..2cf2e3424 100644
ad1357
--- a/server/main-channel-client.h
ad1357
+++ b/server/main-channel-client.h
ad1357
@@ -122,12 +122,15 @@ enum {
ad1357
     RED_PIPE_ITEM_TYPE_MAIN_NAME,
ad1357
     RED_PIPE_ITEM_TYPE_MAIN_UUID,
ad1357
     RED_PIPE_ITEM_TYPE_MAIN_AGENT_CONNECTED_TOKENS,
ad1357
+    RED_PIPE_ITEM_TYPE_MAIN_REGISTERED_CHANNEL,
ad1357
 };
ad1357
 
ad1357
 RedPipeItem *main_mouse_mode_item_new(SpiceMouseMode current_mode, int is_client_mouse_allowed);
ad1357
 
ad1357
 RedPipeItem *main_multi_media_time_item_new(uint32_t mm_time);
ad1357
 
ad1357
+RedPipeItem *registered_channel_item_new(RedChannel *channel);
ad1357
+
ad1357
 G_END_DECLS
ad1357
 
ad1357
 #endif /* MAIN_CHANNEL_CLIENT_H_ */
ad1357
diff --git a/server/main-channel.c b/server/main-channel.c
ad1357
index eca857f6b..4dc130e40 100644
ad1357
--- a/server/main-channel.c
ad1357
+++ b/server/main-channel.c
ad1357
@@ -149,6 +149,12 @@ static void main_channel_fill_mig_target(MainChannel *main_channel, RedsMigSpice
ad1357
     main_channel->mig_target.sport = mig_target->sport;
ad1357
 }
ad1357
 
ad1357
+void
ad1357
+main_channel_registered_new_channel(MainChannel *main_chan, RedChannel *channel)
ad1357
+{
ad1357
+    red_channel_pipes_add(RED_CHANNEL(main_chan), registered_channel_item_new(channel));
ad1357
+}
ad1357
+
ad1357
 void main_channel_migrate_switch(MainChannel *main_chan, RedsMigSpice *mig_target)
ad1357
 {
ad1357
     main_channel_fill_mig_target(main_chan, mig_target);
ad1357
diff --git a/server/main-channel.h b/server/main-channel.h
ad1357
index eb3bcec3a..0cb5be728 100644
ad1357
--- a/server/main-channel.h
ad1357
+++ b/server/main-channel.h
ad1357
@@ -66,6 +66,9 @@ void main_channel_push_mouse_mode(MainChannel *main_chan, SpiceMouseMode current
ad1357
 void main_channel_push_agent_connected(MainChannel *main_chan);
ad1357
 void main_channel_push_agent_disconnected(MainChannel *main_chan);
ad1357
 void main_channel_push_multi_media_time(MainChannel *main_chan, uint32_t time);
ad1357
+/* tell MainChannel we have a new channel ready */
ad1357
+void main_channel_registered_new_channel(MainChannel *main_chan,
ad1357
+                                         RedChannel *channel);
ad1357
 
ad1357
 int main_channel_is_connected(MainChannel *main_chan);
ad1357
 
ad1357
diff --git a/server/reds.c b/server/reds.c
ad1357
index 1b1ab94ea..99b1fd76b 100644
ad1357
--- a/server/reds.c
ad1357
+++ b/server/reds.c
ad1357
@@ -387,6 +387,8 @@ void reds_register_channel(RedsState *reds, RedChannel *channel)
ad1357
 {
ad1357
     spice_assert(reds);
ad1357
     reds->channels = g_list_prepend(reds->channels, channel);
ad1357
+    // create new channel in the client if possible
ad1357
+    main_channel_registered_new_channel(reds->main_channel, channel);
ad1357
 }
ad1357
 
ad1357
 void reds_unregister_channel(RedsState *reds, RedChannel *channel)