Handle new registerStoredIdentity return value
authorAlberto Mardegan <alberto.mardegan@canonical.com>
Tue, 10 Apr 2012 13:40:13 +0000 (16:40 +0300)
committerAlberto Mardegan <alberto.mardegan@canonical.com>
Tue, 10 Apr 2012 13:40:13 +0000 (16:40 +0300)
The registerStoredIdentity method in signond is being changed to remove
the unnecessary variant wrapping of the mechanisms.
This commit let us support both versions of the API, by adding a runtime
check.

libsignon-glib/signon-identity-info.c

index cb16be8e57a5a0b5c5e9973511c79856cb3ee9d3..c4fa878990615627de87856918c024252a88cf2a 100644 (file)
@@ -88,6 +88,14 @@ identity_value_to_stringarray (gpointer key, gpointer value, gpointer user_data)
                          g_strdupv (stringarray));
 }
 
+static void
+add_method (gpointer key, gpointer value, gpointer user_data)
+{
+    gchar **stringarray = (gchar **)value;
+    g_hash_table_insert ((GHashTable *)user_data, g_strdup((gchar *)key),
+                         g_strdupv (stringarray));
+}
+
 SignonIdentityInfo *
 identity_ptrarray_to_identity_info (const GPtrArray *identity_array)
 {
@@ -141,9 +149,24 @@ identity_ptrarray_to_identity_info (const GPtrArray *identity_array)
 
     info->methods = g_hash_table_new_full (g_str_hash, g_str_equal,
                                            g_free, (GDestroyNotify)g_strfreev);
-    g_hash_table_foreach ((GHashTable *)g_value_get_boxed(value),
-                          identity_value_to_stringarray,
-                          info->methods);
+    /* TODO: this check is needed only for a (hopefully short) transitional period,
+     * until signond has been updated to remove the unnecessary wrapping of the
+     * mechanisms into a D-Bus variant.
+     * Once that is done, the else branch can be removed.
+     */
+    if (G_VALUE_TYPE (value) == dbus_g_type_get_map ("GHashTable",
+                                                     G_TYPE_STRING, G_TYPE_STRV))
+    {
+        g_hash_table_foreach ((GHashTable *)g_value_get_boxed(value),
+                              add_method,
+                              info->methods);
+    }
+    else
+    {
+        g_hash_table_foreach ((GHashTable *)g_value_get_boxed(value),
+                              identity_value_to_stringarray,
+                              info->methods);
+    }
     g_value_unset (value);
     /* get the accessControlList (gchar**) */
     value = g_ptr_array_index (identity_array, 6);