[Spice-commits] 2 commits - doc/reference gtk/channel-main.c gtk/map-file gtk/spice-channel.c gtk/spice-glib-sym-file
Hans de Goede
jwrdegoede at kemper.freedesktop.org
Thu Jun 27 05:28:22 PDT 2013
doc/reference/spice-gtk-sections.txt | 1
gtk/channel-main.c | 73 +++++++++++++++++++++++++++++++++--
gtk/map-file | 1
gtk/spice-channel.c | 18 ++++++++
gtk/spice-glib-sym-file | 1
5 files changed, 90 insertions(+), 4 deletions(-)
New commits:
commit b85ca792af72d5f1e10aa6af9515eb96a044fc5c
Author: Hans de Goede <hdegoede at redhat.com>
Date: Wed Jun 26 17:39:39 2013 +0200
Add spice_channel_string_to_type to map files
And document both spice_channel_string_to_type and
spice_channel_type_to_string.
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
diff --git a/doc/reference/spice-gtk-sections.txt b/doc/reference/spice-gtk-sections.txt
index e1e2833..8d61aa9 100644
--- a/doc/reference/spice-gtk-sections.txt
+++ b/doc/reference/spice-gtk-sections.txt
@@ -98,6 +98,7 @@ spice_channel_disconnect
spice_channel_test_capability
spice_channel_test_common_capability
spice_channel_type_to_string
+spice_channel_string_to_type
spice_channel_set_capability
spice_channel_flush_async
spice_channel_flush_finish
diff --git a/gtk/map-file b/gtk/map-file
index a0b7330..a69eb40 100644
--- a/gtk/map-file
+++ b/gtk/map-file
@@ -11,6 +11,7 @@ spice_channel_get_type;
spice_channel_new;
spice_channel_open_fd;
spice_channel_set_capability;
+spice_channel_string_to_type;
spice_channel_test_capability;
spice_channel_test_common_capability;
spice_channel_type_to_string;
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index 0a32d6c..093b292 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -1884,6 +1884,15 @@ static const char *to_string[] = {
[ SPICE_CHANNEL_PORT ] = "port",
};
+/**
+ * spice_channel_type_to_string:
+ * @type: a channel-type property value
+ *
+ * Convert a channel-type property value to a string.
+ *
+ * Returns: string representation of @type.
+ * Since: 0.20
+ **/
const gchar* spice_channel_type_to_string(gint type)
{
const char *str = NULL;
@@ -1895,6 +1904,15 @@ const gchar* spice_channel_type_to_string(gint type)
return str ? str : "unknown channel type";
}
+/**
+ * spice_channel_string_to_type:
+ * @str: a string representation of the channel-type property
+ *
+ * Convert a channel-type property value to a string.
+ *
+ * Returns: the channel-type property value for a @str channel
+ * Since: 0.21
+ **/
gint spice_channel_string_to_type(const gchar *str)
{
int i;
diff --git a/gtk/spice-glib-sym-file b/gtk/spice-glib-sym-file
index 2b172d0..8540307 100644
--- a/gtk/spice-glib-sym-file
+++ b/gtk/spice-glib-sym-file
@@ -14,6 +14,7 @@ spice_channel_set_capability
spice_channel_test_capability
spice_channel_test_common_capability
spice_channel_type_to_string
+spice_channel_string_to_type
spice_client_error_quark
spice_cursor_channel_get_type
spice_display_channel_get_type
commit e45a446a9981ad4adaeff9c885962a8c6140333e
Author: Hans de Goede <hdegoede at redhat.com>
Date: Mon Jun 24 14:30:43 2013 +0200
channel-main: Convert text line-endings if necessary (rhbz#752350)
This implements line-ending conversion following the specification in the
commit message of spice-protocol commit 7be0e88e7e03a956b364cc847aad11b96ed4 :
vd_agent: Add caps for the agent to signal the guest line-ending (rhbz#752350)
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index b58af52..b9e0da2 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -1181,6 +1181,24 @@ static void agent_announce_caps(SpiceMainChannel *channel)
#define HAS_CLIPBOARD_SELECTION(c) \
VD_AGENT_HAS_CAPABILITY((c)->agent_caps, G_N_ELEMENTS((c)->agent_caps), VD_AGENT_CAP_CLIPBOARD_SELECTION)
+#define GUEST_LINEEND_LF(c) \
+ VD_AGENT_HAS_CAPABILITY((c)->agent_caps, G_N_ELEMENTS((c)->agent_caps), VD_AGENT_CAP_GUEST_LINEEND_LF)
+
+#define GUEST_LINEEND_CRLF(c) \
+ VD_AGENT_HAS_CAPABILITY((c)->agent_caps, G_N_ELEMENTS((c)->agent_caps), VD_AGENT_CAP_GUEST_LINEEND_CRLF)
+
+#ifdef G_OS_UNIX
+#define CLIENT_LINEEND_LF 1
+#else
+#define CLIENT_LINEEND_LF 0
+#endif
+
+#ifdef G_OS_WIN32
+#define CLIENT_LINEEND_CRLF 1
+#else
+#define CLIENT_LINEEND_CRLF 0
+#endif
+
/* any context: the message is not flushed immediately,
you can wakeup() the channel coroutine or send_msg_queue() */
static void agent_clipboard_grab(SpiceMainChannel *channel, guint selection,
@@ -1751,6 +1769,29 @@ static void file_xfer_handle_status(SpiceMainChannel *channel,
file_xfer_completed(task, error);
}
+/* any context */
+static guchar *convert_lineend(const guchar *in, gsize *size,
+ const gchar *from, const gchar *to)
+{
+ gchar *nul_terminated, **split, *out;
+
+ /* Nul-terminate */
+ nul_terminated = g_malloc(*size + 1);
+ memcpy(nul_terminated, in, *size);
+ nul_terminated[*size] = 0;
+
+ /* Convert */
+ split = g_strsplit(nul_terminated, from, -1);
+ out = g_strjoinv(to, split);
+ *size = strlen(out);
+
+ /* Clean-up */
+ g_strfreev(split);
+ g_free(nul_terminated);
+
+ return (guchar *)out;
+}
+
/* coroutine context */
static void main_agent_handle_msg(SpiceChannel *channel,
VDAgentMessage *msg, gpointer payload)
@@ -1809,12 +1850,22 @@ static void main_agent_handle_msg(SpiceChannel *channel,
case VD_AGENT_CLIPBOARD:
{
VDAgentClipboard *cb = payload;
+ guchar *data = cb->data;
+ gsize size = msg->size - sizeof(VDAgentClipboard);
+ if (cb->type == VD_AGENT_CLIPBOARD_UTF8_TEXT) {
+ if (GUEST_LINEEND_LF(c) && CLIENT_LINEEND_CRLF)
+ data = convert_lineend(data, &size, "\n", "\r\n");
+ if (GUEST_LINEEND_CRLF(c) && CLIENT_LINEEND_LF)
+ data = convert_lineend(data, &size, "\r\n", "\n");
+ }
emit_main_context(channel, SPICE_MAIN_CLIPBOARD_SELECTION, selection,
- cb->type, cb->data, msg->size - sizeof(VDAgentClipboard));
+ cb->type, data, size);
- if (selection == VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD)
+ if (selection == VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD)
emit_main_context(channel, SPICE_MAIN_CLIPBOARD,
- cb->type, cb->data, msg->size - sizeof(VDAgentClipboard));
+ cb->type, data, size);
+ if (data != cb->data)
+ g_free(data);
break;
}
case VD_AGENT_CLIPBOARD_GRAB:
@@ -2554,13 +2605,27 @@ void spice_main_clipboard_notify(SpiceMainChannel *channel,
* Since: 0.6
**/
void spice_main_clipboard_selection_notify(SpiceMainChannel *channel, guint selection,
- guint32 type, const guchar *data, size_t size)
+ guint32 type, const guchar *_data, size_t _size)
{
+ const guchar *data = _data;
+ gsize size = _size;
+
g_return_if_fail(channel != NULL);
g_return_if_fail(SPICE_IS_MAIN_CHANNEL(channel));
+ SpiceMainChannelPrivate *c = channel->priv;
+
+ if (type == VD_AGENT_CLIPBOARD_UTF8_TEXT) {
+ if (CLIENT_LINEEND_CRLF && GUEST_LINEEND_LF(c))
+ data = convert_lineend(data, &size, "\r\n", "\n");
+ if (CLIENT_LINEEND_LF && GUEST_LINEEND_CRLF(c))
+ data = convert_lineend(data, &size, "\n", "\r\n");
+ }
agent_clipboard_notify(channel, selection, type, data, size);
spice_channel_wakeup(SPICE_CHANNEL(channel), FALSE);
+
+ if (data != _data)
+ g_free((guchar *)data);
}
/**
More information about the Spice-commits
mailing list