#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,
(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);
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:
*/
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));
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;
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 ()
{
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);
}
/**
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
{
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);
}
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,
*/
#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)
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);
-}
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);
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;