[Spice-devel] [PATCH spice-gtk 2/2] spice-channel: Factor out code for storing caps
Pavel Grunt
pgrunt at redhat.com
Thu Jun 29 10:38:36 UTC 2017
Signed-off-by: Pavel Grunt <pgrunt at redhat.com>
---
src/spice-channel.c | 41 +++++++++++++++++++++++++----------------
1 file changed, 25 insertions(+), 16 deletions(-)
diff --git a/src/spice-channel.c b/src/spice-channel.c
index b8cf19c..2422811 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -1884,11 +1884,32 @@ cleanup:
#endif /* HAVE_SASL */
/* coroutine context */
+static void store_remote_caps(SpiceChannel *channel,
+ const bool are_common,
+ const uint8_t *caps_src,
+ const guint num_caps)
+{
+ SpiceChannelPrivate *c = channel->priv;
+ uint32_t *caps;
+ guint i;
+ GArray *remote_caps = are_common ? c->remote_common_caps : c->remote_caps;
+ const gchar *caps_name = are_common ? "common" : "channel";
+
+ g_array_set_size(remote_caps, num_caps);
+ caps = &g_array_index(remote_caps, uint32_t, 0);
+ memcpy(caps, caps_src, num_caps * sizeof(uint32_t));
+ for (i = 0; i < num_caps; i++, caps++) {
+ *caps = GUINT32_FROM_LE(*caps);
+ CHANNEL_DEBUG(channel, "got %s caps %u:0x%X", caps_name, i, *caps);
+ }
+}
+
+/* coroutine context */
static gboolean spice_channel_recv_link_msg(SpiceChannel *channel)
{
SpiceChannelPrivate *c;
- int rc, num_caps, i;
- uint32_t *caps, num_channel_caps, num_common_caps;
+ int rc, num_caps;
+ uint32_t num_channel_caps, num_common_caps;
uint8_t *caps_src;
SpiceChannelEvent event = SPICE_CHANNEL_ERROR_LINK;
@@ -1930,22 +1951,10 @@ static gboolean spice_channel_recv_link_msg(SpiceChannel *channel)
/* g_return_if_fail(c->peer_msg + c->peer_msg->caps_offset * sizeof(uint32_t) > c->peer_msg + c->peer_hdr.size); */
caps_src = (uint8_t *)c->peer_msg + GUINT32_FROM_LE(c->peer_msg->caps_offset);
- g_array_set_size(c->remote_common_caps, num_common_caps);
- caps = &g_array_index(c->remote_common_caps, uint32_t, 0);
- memcpy(caps, caps_src, num_common_caps * sizeof(uint32_t));
- for (i = 0; i < num_common_caps; i++, caps++) {
- *caps = GUINT32_FROM_LE(*caps);
- CHANNEL_DEBUG(channel, "got common caps %d:0x%X", i, *caps);
- }
+ store_remote_caps(channel, true, caps_src, num_common_caps);
caps_src += num_common_caps * sizeof(uint32_t);
- g_array_set_size(c->remote_caps, num_channel_caps);
- caps = &g_array_index(c->remote_caps, uint32_t, 0);
- memcpy(caps, caps_src, num_channel_caps * sizeof(uint32_t));
- for (i = 0; i < num_channel_caps; i++, caps++) {
- *caps = GUINT32_FROM_LE(*caps);
- CHANNEL_DEBUG(channel, "got channel caps %d:0x%X", i, *caps);
- }
+ store_remote_caps(channel, false, caps_src, num_channel_caps);
if (!spice_channel_test_common_capability(channel,
SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION)) {
--
2.13.0
More information about the Spice-devel
mailing list