Use com.nokia.SingleSignOn.Identity.store
authorAlberto Mardegan <alberto.mardegan@canonical.com>
Tue, 10 Apr 2012 13:38:43 +0000 (16:38 +0300)
committerAlberto Mardegan <alberto.mardegan@canonical.com>
Tue, 10 Apr 2012 13:38:43 +0000 (16:38 +0300)
Use the more flexible com.nokia.SingleSignOn.Identity.store instead of
com.nokia.SingleSignOn.Identity.storeCredentials.

libsignon-glib/signon-identity-info.c
libsignon-glib/signon-identity.c
libsignon-glib/signon-internals.h
libsignon-glib/signon-utils.c
libsignon-glib/signon-utils.h
tests/check_signon.c

index 40683c8e33a706d073f310d5b2c436d7162b67b9..cb16be8e57a5a0b5c5e9973511c79856cb3ee9d3 100644 (file)
@@ -34,6 +34,7 @@
 #include "signon-identity-info.h"
 
 #include "signon-internals.h"
+#include "signon-utils.h"
 
 G_DEFINE_BOXED_TYPE (SignonIdentityInfo, signon_identity_info,
                      (GBoxedCopyFunc)signon_identity_info_copy,
@@ -62,7 +63,7 @@ static void identity_methods_copy (gpointer key, gpointer value, gpointer user_d
                                      (const gchar* const *)value);
 }
 
-static void identity_info_set_methods (SignonIdentityInfo *info,
+void signon_identity_info_set_methods (SignonIdentityInfo *info,
                                        const GHashTable *methods)
 {
     g_return_if_fail (info != NULL);
@@ -162,6 +163,58 @@ identity_ptrarray_to_identity_info (const GPtrArray *identity_array)
     return info;
 }
 
+GHashTable *
+signon_identity_info_to_hash_table (const SignonIdentityInfo *self)
+{
+    GHashTable *map;
+    GValue *value;
+    GType type;
+
+    map = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                 NULL,
+                                 signon_gvalue_free);
+
+    value = signon_gvalue_new (G_TYPE_UINT);
+    g_value_set_uint (value, self->id);
+    g_hash_table_insert (map, SIGNOND_IDENTITY_INFO_ID, value);
+
+    value = signon_gvalue_new (G_TYPE_STRING);
+    g_value_set_string (value, self->username);
+    g_hash_table_insert (map, SIGNOND_IDENTITY_INFO_USERNAME, value);
+
+    value = signon_gvalue_new (G_TYPE_STRING);
+    g_value_set_string (value, self->secret);
+    g_hash_table_insert (map, SIGNOND_IDENTITY_INFO_SECRET, value);
+
+    value = signon_gvalue_new (G_TYPE_STRING);
+    g_value_set_string (value, self->caption);
+    g_hash_table_insert (map, SIGNOND_IDENTITY_INFO_CAPTION, value);
+
+    value = signon_gvalue_new (G_TYPE_BOOLEAN);
+    g_value_set_boolean (value, self->store_secret);
+    g_hash_table_insert (map, SIGNOND_IDENTITY_INFO_STORESECRET, value);
+
+    type = dbus_g_type_get_map ("GHashTable",
+                                G_TYPE_STRING, G_TYPE_STRV);
+    value = signon_gvalue_new (type);
+    g_value_set_boxed (value, self->methods);
+    g_hash_table_insert (map, SIGNOND_IDENTITY_INFO_AUTHMETHODS, value);
+
+    value = signon_gvalue_new (G_TYPE_STRV);
+    g_value_set_boxed (value, self->realms);
+    g_hash_table_insert (map, SIGNOND_IDENTITY_INFO_REALMS, value);
+
+    value = signon_gvalue_new (G_TYPE_STRV);
+    g_value_set_boxed (value, self->access_control_list);
+    g_hash_table_insert (map, SIGNOND_IDENTITY_INFO_ACL, value);
+
+    value = signon_gvalue_new (G_TYPE_INT);
+    g_value_set_int (value, self->type);
+    g_hash_table_insert (map, SIGNOND_IDENTITY_INFO_TYPE, value);
+
+    return map;
+}
+
 /*
  * Public methods:
  */
@@ -227,7 +280,7 @@ SignonIdentityInfo *signon_identity_info_copy (const SignonIdentityInfo *other)
 
     signon_identity_info_set_caption (info, signon_identity_info_get_caption(other));
 
-    identity_info_set_methods (info, signon_identity_info_get_methods (other));
+    signon_identity_info_set_methods (info, signon_identity_info_get_methods (other));
 
     signon_identity_info_set_realms (info, signon_identity_info_get_realms (other));
 
index 61fc0df2e5fb49c84ddff22d78bab802040f3f8a..0a157548c0e84b2bdb27f050085bbba0ed489654 100644 (file)
@@ -95,14 +95,7 @@ typedef struct _IdentityStoreCredentialsCbData
 
 typedef struct _IdentityStoreCredentialsData
 {
-    gchar *username;
-    gchar *secret;
-    gboolean store_secret;
-    GHashTable *methods;
-    gchar *caption;
-    gchar **realms;
-    gchar **access_control_list;
-    gint type;
+    GHashTable *info_map;
     gpointer cb_data;
 } IdentityStoreCredentialsData;
 
@@ -177,8 +170,6 @@ static void identity_process_signout (SignonIdentity *self);
 static void identity_process_updated (SignonIdentity *self);
 static void identity_process_removed (SignonIdentity *self);
 
-static GHashTable *identity_methods_to_valuearray (const GHashTable *methods);
-
 static GQuark
 identity_object_quark ()
 {
@@ -681,30 +672,27 @@ signon_identity_store_credentials_with_info(SignonIdentity *self,
                                             SignonIdentityStoreCredentialsCb cb,
                                             gpointer user_data)
 {
-    g_return_if_fail(info != NULL);
-
-    signon_identity_store_credentials_with_args(self,
-                                                info->username,
-                                                info->secret,
-                                                info->store_secret,
-                                                info->methods,
-                                                info->caption,
-                                                (const gchar* const *)info->realms,
-                                                (const gchar* const *)info->access_control_list,
-                                                info->type,
-                                                cb,
-                                                user_data);
-}
+    IdentityStoreCredentialsCbData *cb_data;
+    IdentityStoreCredentialsData *operation_data;
 
-static GHashTable *
-identity_methods_to_valuearray (const GHashTable *methods)
-{
-    DEBUG ("%s", __func__);
-    GHashTable *valuearray = g_hash_table_new_full (g_str_hash, g_str_equal,
-                                                    g_free, signon_gvalue_free);
-    g_hash_table_foreach ((GHashTable *)methods,
-                            signon_stringarray_to_value, valuearray);
-    return valuearray;
+    DEBUG ();
+    g_return_if_fail (SIGNON_IS_IDENTITY (self));
+    g_return_if_fail (info != NULL);
+
+    cb_data = g_slice_new0 (IdentityStoreCredentialsCbData);
+    cb_data->self = self;
+    cb_data->cb = cb;
+    cb_data->user_data = user_data;
+
+    operation_data = g_slice_new0 (IdentityStoreCredentialsData);
+    operation_data->info_map = signon_identity_info_to_hash_table (info);
+    operation_data->cb_data = cb_data;
+
+    identity_check_remote_registration (self);
+    _signon_object_call_when_ready (self,
+                                    identity_object_quark(),
+                                    identity_store_credentials_ready_cb,
+                                    operation_data);
 }
 
 /**
@@ -735,37 +723,21 @@ void signon_identity_store_credentials_with_args(SignonIdentity *self,
                                                  SignonIdentityStoreCredentialsCb cb,
                                                  gpointer user_data)
 {
-    g_return_if_fail (SIGNON_IS_IDENTITY (self));
-
-    SignonIdentityPrivate *priv = self->priv;
-    g_return_if_fail (priv != NULL);
-
-    g_return_if_fail (methods != NULL);
-
-    DEBUG ("%s %d", G_STRFUNC, __LINE__);
-
-    IdentityStoreCredentialsCbData *cb_data = g_slice_new0 (IdentityStoreCredentialsCbData);
-    cb_data->self = self;
-    cb_data->cb = cb;
-    cb_data->user_data = user_data;
+    SignonIdentityInfo *info;
 
-    IdentityStoreCredentialsData *operation_data = g_slice_new0 (IdentityStoreCredentialsData);
-
-    operation_data->username = g_strdup (username);
-    operation_data->secret = g_strdup (secret);
-    operation_data->store_secret = store_secret;
-    operation_data->methods = identity_methods_to_valuearray (methods);
-    operation_data->caption = g_strdup (caption);
-    operation_data->realms = g_strdupv((gchar **)realms);
-    operation_data->access_control_list = g_strdupv((gchar **)access_control_list);
-    operation_data->type = (gint)type;
-    operation_data->cb_data = cb_data;
+    g_return_if_fail (SIGNON_IS_IDENTITY (self));
 
-    identity_check_remote_registration (self);
-    _signon_object_call_when_ready (self,
-                                    identity_object_quark(),
-                                    identity_store_credentials_ready_cb,
-                                    operation_data);
+    info = signon_identity_info_new ();
+    signon_identity_info_set_username (info, username);
+    signon_identity_info_set_secret (info, secret, store_secret);
+    signon_identity_info_set_methods (info, methods);
+    signon_identity_info_set_caption (info, caption);
+    signon_identity_info_set_realms (info, realms);
+    signon_identity_info_set_access_control_list (info, access_control_list);
+    signon_identity_info_set_identity_type (info, type);
+
+    signon_identity_store_credentials_with_info (self, info, cb, user_data);
+    signon_identity_info_free (info);
 }
 
 static void
@@ -801,28 +773,14 @@ identity_store_credentials_ready_cb (gpointer object, const GError *error, gpoin
     {
         g_return_if_fail (priv->proxy != NULL);
 
-        SSO_Identity_store_credentials_async(
+        SSO_Identity_store_async(
             priv->proxy,
-            priv->id,
-            operation_data->username,
-            operation_data->secret,
-            operation_data->store_secret,
-            operation_data->methods,
-            operation_data->caption,
-            (const char **)operation_data->realms,
-            (const char **)operation_data->access_control_list,
-            operation_data->type,
+            operation_data->info_map,
             identity_store_credentials_reply,
             cb_data);
     }
 
-    g_free (operation_data->username);
-    g_free (operation_data->secret);
-    g_free (operation_data->caption);
-    g_hash_table_destroy (operation_data->methods);
-    g_strfreev (operation_data->realms);
-    g_strfreev (operation_data->access_control_list);
-
+    g_hash_table_unref (operation_data->info_map);
     g_slice_free (IdentityStoreCredentialsData, operation_data);
 }
 
index 1c00e8dca3bda80727e9d87879bc586dd72270e5..ab2bdcd2c03699ac948f87879b68510b47aa340d 100644 (file)
@@ -59,6 +59,14 @@ struct _SignonIdentityInfo
 G_GNUC_INTERNAL
 SignonIdentityInfo *identity_ptrarray_to_identity_info (const GPtrArray *identity_array);
 
+G_GNUC_INTERNAL
+GHashTable *
+signon_identity_info_to_hash_table (const SignonIdentityInfo *self);
+
+G_GNUC_INTERNAL
+void signon_identity_info_set_methods (SignonIdentityInfo *self,
+                                       const GHashTable *methods);
+
 G_GNUC_INTERNAL
 void _signon_identity_registered (SignonIdentity *identity, DBusGProxy *proxy,
                                   char *objectPath, GPtrArray *identityArray,
index a4beeb226e160c90e2f000dd6c9646d013156243..ba09001a3fb1a7e02a5b06bd9801a904c6cef98b 100644 (file)
  */
 #include "signon-utils.h"
 
+GValue *
+signon_gvalue_new (GType type)
+{
+    GValue *value = g_slice_new0 (GValue);
+    g_value_init (value, type);
+    return value;
+}
+
 static void signon_gvalue_copy (gchar *key,
                                 GValue *value,
                                 GHashTable *dest)
@@ -59,10 +67,3 @@ GHashTable *signon_copy_variant_map (const GHashTable *old_map)
 
    return new_map;
 }
-
-void signon_stringarray_to_value (gpointer key, gpointer value, gpointer user_data)
-{
-    GValue *gvalue = g_value_init(g_slice_new0 (GValue), G_TYPE_STRV);
-    g_value_set_boxed (gvalue, (gchar **)value);
-    g_hash_table_insert ((GHashTable *)user_data, g_strdup((gchar *)key), gvalue);
-}
index 8f4892e28403a69961c0d50aa3bb063e59512a55..d73f63353d31b49577ae63e1780a820ee27ba29a 100644 (file)
@@ -28,8 +28,9 @@
 
 G_GNUC_INTERNAL
 GHashTable *signon_copy_variant_map (const GHashTable *old_map);
+
 G_GNUC_INTERNAL
-void signon_stringarray_to_value (gpointer key, gpointer value, gpointer user_data);
+GValue *signon_gvalue_new (GType type);
 G_GNUC_INTERNAL
 void signon_gvalue_free (gpointer val);
 
index 21ccc4f7afe3735a9a775ca45129f216116900db..4481b287e59d9912dc1fc638c3a9f3504e4b2a75 100644 (file)
@@ -502,68 +502,54 @@ static GHashTable *create_methods_hashtable()
     return methods;
 }
 
-static guint
-new_identity()
+static void new_identity_store_credentials_cb(SignonIdentity *self,
+                                              guint32 id,
+                                              const GError *error,
+                                              gpointer user_data)
 {
-    DBusGConnection *connection;
-    DBusGProxy *proxy = NULL;
-    guint id = 0;
-    GError *error = NULL;
-
-    g_debug("%s", G_STRFUNC);
-    connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+    gint *new_id = user_data;
 
-    if(connection)
-    {
-        proxy = dbus_g_proxy_new_for_name (connection,
-                                           "com.nokia.SingleSignOn",
-                                           "/com/nokia/SingleSignOn",
-                                           "com.nokia.SingleSignOn.AuthService");
-    }
-    else if (error)
+    if(error)
     {
-        g_warning ("%s %d returned error: %s", G_STRFUNC, __LINE__, error->message);
-        g_error_free (error);
-        return -1;
+        g_warning ("%s %d: %s", G_STRFUNC, __LINE__, error->message);
+        fail();
     }
 
-    gchar *objectPath;
-    SSO_AuthService_register_new_identity (proxy, &objectPath, &error);
+    fail_unless (id > 0);
 
-    if (error)
-    {
-        g_warning ("%s %d returned error: %s", G_STRFUNC, __LINE__, error->message);
-        g_error_free (error);
-        fail();
-    }
+    *new_id = id;
+
+    g_main_loop_quit (main_loop);
+}
 
-    GHashTable *methods = g_hash_table_new (g_str_hash, g_str_equal);
-
-    proxy = dbus_g_proxy_new_for_name (connection,
-                                       "com.nokia.SingleSignOn",
-                                       objectPath,
-                                       "com.nokia.SingleSignOn.Identity");
-
-    SSO_Identity_store_credentials (proxy,
-                                    0,
-                                    "James Bond",
-                                    "007",
-                                    1,
-                                    methods,
-                                    "caption",
-                                    NULL,
-                                    NULL,
-                                    0,
-                                    &id,
-                                    &error);
+static guint
+new_identity()
+{
+    SignonIdentity *identity;
+    GHashTable *methods;
+    guint id = 0;
+
+    if (main_loop == NULL)
+        main_loop = g_main_loop_new (NULL, FALSE);
 
+    identity = signon_identity_new(NULL, NULL);
+    fail_unless (SIGNON_IS_IDENTITY (identity));
+    methods = g_hash_table_new (g_str_hash, g_str_equal);
+    signon_identity_store_credentials_with_args (identity,
+                                                 "James Bond",
+                                                 "007",
+                                                 1,
+                                                 methods,
+                                                 "caption",
+                                                 NULL,
+                                                 NULL,
+                                                 0,
+                                                 new_identity_store_credentials_cb,
+                                                 &id);
     g_hash_table_destroy (methods);
 
-    if(error)
-    {
-        g_warning ("%s %d: %s", G_STRFUNC, __LINE__, error->message);
-        fail();
-    }
+    if (id == 0)
+        g_main_loop_run (main_loop);
 
     return id;