[Spice-devel] [PATCH] [spice-gtk] fix bug: g_key_get_string() of vd_agent failed when keystring contains '['

Cody Chan int64ago at gmail.com
Fri Aug 8 05:38:00 PDT 2014


See here:
http://lists.freedesktop.org/archives/spice-devel/2014-August/017180.html

​---
 gtk/channel-main.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index 7a299a4..26dad7f 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -2656,6 +2656,43 @@ static void file_xfer_completed(SpiceFileXferTask
*task, GError *error)
     task->pending = TRUE;
 }

+/**
+ * g_string_replace:
+ * @src: original string
+ * @old_string: substring you want to replace
+ * @new_string: string you want to replace with
+ *
+ * Replace all @old_string with @new_string in @src.
+ *
+ * Returns: %NULL if any of @src/@old_string/@new_string is illegal
+ **/
+gchar *g_string_replace(const gchar *src, const gchar *old_string, const
gchar *new_string)
+{
+    if (!src || !old_string || !new_string || !g_strcmp0(src, "") ||
+                !g_strcmp0(old_string, ""))
+        return NULL;
+    gchar *retstr = NULL;
+    gchar *srcstr = g_strdup(src);
+    gchar *ptr = g_strstr_len(srcstr, strlen(srcstr), old_string);
+    if (ptr != NULL){
+        gchar *after = g_string_replace(ptr + strlen(old_string),
old_string, new_string);
+        gchar *before = g_strndup(srcstr, ptr - srcstr);
+        retstr = g_strconcat(before, new_string, after, NULL);
+        g_free(after);
+        g_free(before);
+        g_free(srcstr);
+        return retstr;
+    }
+    return g_strdup(src);
+}
+
+gchar *g_key_string_replace(const gchar *string, const gchar *group_name)
+{
+    gchar *old_group_name = g_strconcat("[", group_name, "]", NULL);
+    gchar *new_group_name = g_strconcat("<", group_name, ">", NULL);
+    return g_string_replace(string, old_group_name, new_group_name);
+}
+
 static void file_xfer_info_async_cb(GObject *obj, GAsyncResult *res,
gpointer data)
 {
     GFileInfo *info;
@@ -2665,7 +2702,7 @@ static void file_xfer_info_async_cb(GObject *obj,
GAsyncResult *res, gpointer da
     gchar *basename = NULL;
     VDAgentFileXferStartMessage msg;
     gsize /*msg_size*/ data_len;
-    gchar *string;
+    gchar *string, *new_string;
     SpiceFileXferTask *task = (SpiceFileXferTask *)data;

     task->pending = FALSE;
@@ -2687,6 +2724,9 @@ static void file_xfer_info_async_cb(GObject *obj,
GAsyncResult *res, gpointer da
     /* Save keyfile content to memory. TODO: more file attributions
        need to be sent to guest */
     string = g_key_file_to_data(keyfile, &data_len, &error);
+
+    /* For each group_name do this */
+    new_string = g_key_string_replace(string, "vdagent-file-xfer");
     g_key_file_free(keyfile);
     if (error)
         goto failed;
@@ -2695,8 +2735,9 @@ static void file_xfer_info_async_cb(GObject *obj,
GAsyncResult *res, gpointer da
     msg.id = task->id;
     agent_msg_queue_many(task->channel, VD_AGENT_FILE_XFER_START,
                          &msg, sizeof(msg),
-                         string, data_len + 1, NULL);
+                         new_string, data_len + 1, NULL);
     g_free(string);
+    g_free(new_string);
     spice_channel_wakeup(SPICE_CHANNEL(task->channel), FALSE);
     return;

-- ​

-- 
QSBDT0RFUiBGUk9NIFJJRVNUIE9GIENUU0VV
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20140808/331290c2/attachment-0001.html>


More information about the Spice-devel mailing list