From ac52b69f88ee80bcf0aa48221097a57d01a33a6c Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Thu, 12 Apr 2012 09:33:50 +0300 Subject: [PATCH] Use new D-Bus APIs from signond --- libsignon-glib/signon-identity-info.c | 147 +++++++++++++++++++--------------- libsignon-glib/signon-identity.c | 35 ++++---- libsignon-glib/signon-internals.h | 3 +- 3 files changed, 105 insertions(+), 80 deletions(-) diff --git a/libsignon-glib/signon-identity-info.c b/libsignon-glib/signon-identity-info.c index c4fa878..c0996f7 100644 --- a/libsignon-glib/signon-identity-info.c +++ b/libsignon-glib/signon-identity-info.c @@ -97,9 +97,9 @@ add_method (gpointer key, gpointer value, gpointer user_data) } SignonIdentityInfo * -identity_ptrarray_to_identity_info (const GPtrArray *identity_array) +signon_identity_info_new_from_hash_table (GHashTable *map) { - if (!identity_array) + if (!map) return NULL; SignonIdentityInfo *info = signon_identity_info_new (); @@ -108,80 +108,101 @@ identity_ptrarray_to_identity_info (const GPtrArray *identity_array) GValue *value; /* get the id (gint) */ - value = g_ptr_array_index (identity_array, 0); - g_assert (G_VALUE_HOLDS_UINT (value)); - identity_info_set_id (info, g_value_get_uint (value)); - g_value_unset (value); + value = g_hash_table_lookup (map, SIGNOND_IDENTITY_INFO_ID); + if (value != NULL) + { + g_assert (G_VALUE_HOLDS_UINT (value)); + identity_info_set_id (info, g_value_get_uint (value)); + } /* get the user name (gchar*) */ - value = g_ptr_array_index (identity_array, 1); - g_assert (G_VALUE_HOLDS_STRING (value)); - signon_identity_info_set_username (info, g_value_get_string (value)); - g_value_unset (value); - - /* get the password (gchar*) - * TODO: fix it as soon - * as reply from server will - * be changed - * */ - - value = g_ptr_array_index (identity_array, 2); - g_assert (G_VALUE_HOLDS_STRING (value)); - info->store_secret = (g_value_get_string (value) != NULL); - g_value_unset (value); + value = g_hash_table_lookup (map, SIGNOND_IDENTITY_INFO_USERNAME); + if (value != NULL) + { + g_assert (G_VALUE_HOLDS_STRING (value)); + signon_identity_info_set_username (info, g_value_get_string (value)); + } - /* get the caption (gchar*) */ - value = g_ptr_array_index (identity_array, 3); - g_assert (G_VALUE_HOLDS_STRING (value)); - signon_identity_info_set_caption (info, g_value_get_string (value)); - g_value_unset (value); + /* get the password (gchar*) */ + value = g_hash_table_lookup (map, SIGNOND_IDENTITY_INFO_SECRET); + if (value != NULL) + { + GValue *v_store_secret; + gboolean store_secret; - /* get the realms (gchar**) */ - value = g_ptr_array_index (identity_array, 4); - g_assert (G_VALUE_TYPE (value) == G_TYPE_STRV); - signon_identity_info_set_realms (info, - (const gchar* const *)g_value_get_boxed (value)); - g_value_unset (value); + g_assert (G_VALUE_HOLDS_STRING (value)); - /* get the methods GPtrArray (QVariantMap in original) */ - value = g_ptr_array_index (identity_array, 5); - g_assert (G_VALUE_HOLDS_BOXED (value)); + v_store_secret = g_hash_table_lookup (map, SIGNOND_IDENTITY_INFO_STORESECRET); + store_secret = (v_store_secret != NULL) ? + g_value_get_boolean (v_store_secret) : FALSE; - info->methods = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, (GDestroyNotify)g_strfreev); - /* 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)) + signon_identity_info_set_secret (info, g_value_get_string (value), + store_secret); + } + + /* get the caption (gchar*) */ + value = g_hash_table_lookup (map, SIGNOND_IDENTITY_INFO_CAPTION); + if (value != NULL) { - g_hash_table_foreach ((GHashTable *)g_value_get_boxed(value), - add_method, - info->methods); + g_assert (G_VALUE_HOLDS_STRING (value)); + signon_identity_info_set_caption (info, g_value_get_string (value)); } - else + + /* get the realms (gchar**) */ + value = g_hash_table_lookup (map, SIGNOND_IDENTITY_INFO_REALMS); + if (value != NULL) { - g_hash_table_foreach ((GHashTable *)g_value_get_boxed(value), - identity_value_to_stringarray, - info->methods); + g_assert (G_VALUE_TYPE (value) == G_TYPE_STRV); + signon_identity_info_set_realms (info, + (const gchar* const *) + g_value_get_boxed (value)); } - g_value_unset (value); + + /* get the methods */ + value = g_hash_table_lookup (map, SIGNOND_IDENTITY_INFO_AUTHMETHODS); + if (value != NULL) + { + g_assert (G_VALUE_HOLDS_BOXED (value)); + + info->methods = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, (GDestroyNotify)g_strfreev); + /* 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); + } + } + /* get the accessControlList (gchar**) */ - value = g_ptr_array_index (identity_array, 6); - g_assert (G_VALUE_TYPE (value) == G_TYPE_STRV); - signon_identity_info_set_access_control_list (info, - (const gchar* const *)g_value_get_boxed (value)); - g_value_unset (value); + value = g_hash_table_lookup (map, SIGNOND_IDENTITY_INFO_ACL); + if (value != NULL) + { + g_assert (G_VALUE_TYPE (value) == G_TYPE_STRV); + signon_identity_info_set_access_control_list (info, + (const gchar* const *) + g_value_get_boxed (value)); + } /* get the type (gint) */ - value = g_ptr_array_index (identity_array, 7); - g_assert (G_VALUE_HOLDS_INT(value)); - signon_identity_info_set_identity_type (info, g_value_get_int (value)); - g_value_unset (value); - - /* ignore the ref_count (8th field) */ + value = g_hash_table_lookup (map, SIGNOND_IDENTITY_INFO_TYPE); + if (value != NULL) + { + g_assert (G_VALUE_HOLDS_INT(value)); + signon_identity_info_set_identity_type (info, g_value_get_int (value)); + } return info; } diff --git a/libsignon-glib/signon-identity.c b/libsignon-glib/signon-identity.c index 0a15754..0a39dc2 100644 --- a/libsignon-glib/signon-identity.c +++ b/libsignon-glib/signon-identity.c @@ -143,10 +143,10 @@ typedef struct _IdentityVoidData } IdentityVoidData; static void identity_registered (SignonIdentity *identity, DBusGProxy *proxy, char *object_path, - GPtrArray *identity_array, GError *error); + GHashTable *identity_data, GError *error); static void identity_check_remote_registration (SignonIdentity *self); static void identity_new_cb (DBusGProxy *proxy, char *objectPath, GError *error, gpointer userdata); -static void identity_new_from_db_cb (DBusGProxy *proxy, char *objectPath, GPtrArray *identityData, +static void identity_new_from_db_cb (DBusGProxy *proxy, char *objectPath, GHashTable *identityData, GError *error, gpointer userdata); static void identity_store_credentials_ready_cb (gpointer object, const GError *error, gpointer user_data); static void identity_store_credentials_reply (DBusGProxy *proxy, guint id, GError *error, gpointer userdata); @@ -158,8 +158,9 @@ static void identity_verify_reply (DBusGProxy *proxy, gboolean valid, GError *er static void identity_signout_reply (DBusGProxy *proxy, gboolean result, GError *error, gpointer userdata); static void identity_removed_reply (DBusGProxy *proxy, GError *error, gpointer userdata); -static void identity_info_reply(DBusGProxy *proxy, GPtrArray *identity_array, - GError *error, gpointer userdata); +static void identity_info_reply(DBusGProxy *proxy, + GHashTable *identity_data, + GError *error, gpointer userdata); static void identity_remove_ready_cb (gpointer object, const GError *error, gpointer user_data); static void identity_signout_ready_cb (gpointer object, const GError *error, gpointer user_data); static void identity_info_ready_cb (gpointer object, const GError *error, gpointer user_data); @@ -378,7 +379,7 @@ identity_remote_object_destroyed_cb(DBusGProxy *proxy, static void identity_registered (SignonIdentity *identity, DBusGProxy *proxy, - char *object_path, GPtrArray *identity_array, + char *object_path, GHashTable *identity_data, GError *error) { g_return_if_fail (SIGNON_IS_IDENTITY (identity)); @@ -431,11 +432,12 @@ identity_registered (SignonIdentity *identity, DBusGProxy *proxy, identity, NULL); - if (identity_array) + if (identity_data) { DEBUG("%s: ", G_STRFUNC); - priv->identity_info = identity_ptrarray_to_identity_info (identity_array); - g_ptr_array_free (identity_array, TRUE); + priv->identity_info = + signon_identity_info_new_from_hash_table (identity_data); + g_hash_table_unref (identity_data); } priv->updated = TRUE; @@ -492,7 +494,7 @@ identity_new_cb (DBusGProxy *proxy, static void identity_new_from_db_cb (DBusGProxy *proxy, char *objectPath, - GPtrArray *identityData, + GHashTable *identityData, GError *error, gpointer userdata) { @@ -515,7 +517,7 @@ identity_check_remote_registration (SignonIdentity *self) return; if (priv->id != 0) - SSO_AuthService_register_stored_identity_async + SSO_AuthService_get_identity_async (DBUS_G_PROXY (priv->signon_proxy), priv->id, identity_new_from_db_cb, self); else SSO_AuthService_register_new_identity_async @@ -1087,7 +1089,7 @@ identity_removed_reply (DBusGProxy *proxy, } static void -identity_info_reply(DBusGProxy *proxy, GPtrArray *identity_array, +identity_info_reply(DBusGProxy *proxy, GHashTable *identity_data, GError *error, gpointer userdata) { DEBUG ("%d %s", __LINE__, __func__); @@ -1102,8 +1104,9 @@ identity_info_reply(DBusGProxy *proxy, GPtrArray *identity_array, SignonIdentityPrivate *priv = cb_data->self->priv; new_error = _signon_errors_get_error_from_dbus (error); - priv->identity_info = identity_ptrarray_to_identity_info (identity_array); - g_ptr_array_free (identity_array, TRUE); + priv->identity_info = + signon_identity_info_new_from_hash_table (identity_data); + g_hash_table_unref (identity_data); if (cb_data->cb) { @@ -1161,9 +1164,9 @@ identity_info_ready_cb(gpointer object, const GError *error, gpointer user_data) else if (priv->updated == FALSE) { g_return_if_fail (priv->proxy != NULL); - SSO_Identity_query_info_async (priv->proxy, - identity_info_reply, - cb_data); + SSO_Identity_get_info_async (priv->proxy, + identity_info_reply, + cb_data); } else { diff --git a/libsignon-glib/signon-internals.h b/libsignon-glib/signon-internals.h index ab2bdcd..ba4b650 100644 --- a/libsignon-glib/signon-internals.h +++ b/libsignon-glib/signon-internals.h @@ -57,7 +57,8 @@ struct _SignonIdentityInfo }; G_GNUC_INTERNAL -SignonIdentityInfo *identity_ptrarray_to_identity_info (const GPtrArray *identity_array); +SignonIdentityInfo * +signon_identity_info_new_from_hash_table (GHashTable *map); G_GNUC_INTERNAL GHashTable * -- 2.7.4