]> git.0d.be Git - empathy.git/commitdiff
Unescape _ and _2d in the protocol from mission-control
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>
Tue, 21 Jul 2009 17:02:47 +0000 (18:02 +0100)
committerSjoerd Simons <sjoerd.simons@collabora.co.uk>
Tue, 21 Jul 2009 17:02:47 +0000 (18:02 +0100)
libempathy/empathy-account.c

index 21ece6f0d14ea3f760d8a7dfaa67b8dd441c6b1b..4cd96e393ba1834e9afedffdfa83b9d19e700c1d 100644 (file)
@@ -345,6 +345,41 @@ empathy_account_got_all_cb (TpProxy *proxy,
   empathy_account_update (account, properties);
 }
 
+static gchar *
+empathy_account_unescape_protocol (const gchar *protocol, gssize len)
+{
+  gchar  *result, *escape;
+  /* Bad implementation might accidentally use tp_escape_as_identifier,
+   * which escapes - in the wrong way... */
+  if ((escape = g_strstr_len (protocol, len, "_2d")) != NULL)
+    {
+      GString *str;
+      const gchar *input;
+
+      str = g_string_new ("");
+      input = protocol;
+      do {
+        g_string_append_len (str, input, escape - input);
+        g_string_append_c (str, '-');
+
+        len -= escape - input + 3;
+        input = escape + 3;
+      } while ((escape = g_strstr_len (input, len, "_2d")) != NULL);
+
+      g_string_append_len (str, input, len);
+
+      result = g_string_free (str, FALSE);
+    }
+  else
+    {
+      result = g_strndup (protocol, len);
+    }
+
+  g_strdelimit (result, "_", '-');
+
+  return result;
+}
+
 static gboolean
 empathy_account_parse_unique_name (const gchar *bus_name,
   gchar **protocol, gchar **manager)
@@ -375,7 +410,9 @@ empathy_account_parse_unique_name (const gchar *bus_name,
     return FALSE;
 
   if (protocol != NULL)
-    *protocol = g_strndup (proto, proto_end - proto);
+    {
+      *protocol = empathy_account_unescape_protocol (proto, proto_end - proto);
+    }
 
   if (manager != NULL)
     *manager = g_strndup (cm, cm_end - cm);