I have made the following changes intended for : CE:MW:Shared / telepathy-accounts-signon
Please review and accept or decline. BOSS has already run some checks on this request. See the "Messages from BOSS" section below. https://build.pub.meego.com//request/show/7571 Thank You, John Brooks [This message was auto-generated] --- Request # 7571: Messages from BOSS: State: review at 2012-12-20T13:20:18 by bossbot Reviews: accepted by bossbot : Prechecks succeeded. new for CE-maintainers : Please replace this text with a review and approve/reject the review (not the SR). BOSS will take care of the rest Changes: submit: home:special:branches:CE:MW:Shared / telepathy-accounts-signon -> CE:MW:Shared / telepathy-accounts-signon changes files: -------------- --- telepathy-accounts-signon.changes +++ telepathy-accounts-signon.changes @@ -0,0 +1,4 @@ +* Wed Dec 19 2012 John Brooks <[email protected]> - 0.0.2 +- Fix reading non-string settings from accounts +- Use libsignon to read credentials + old: ---- telepathy-accounts-signon-0.0.1.tar.bz2 new: ---- telepathy-accounts-signon-0.0.2.tar.bz2 spec files: ----------- --- telepathy-accounts-signon.spec +++ telepathy-accounts-signon.spec @@ -1,5 +1,5 @@ Name: telepathy-accounts-signon -Version: 0.0.1 +Version: 0.0.2 Release: 1 Summary: Telepathy providers for libaccounts/libsignon Group: System/Libraries other changes: -------------- ++++++ telepathy-accounts-signon-0.0.1.tar.bz2 -> telepathy-accounts-signon-0.0.2.tar.bz2 --- mcp-account-manager-uoa/mcp-account-manager-uoa.c +++ mcp-account-manager-uoa/mcp-account-manager-uoa.c @@ -25,6 +25,9 @@ #include <libaccounts-glib/ag-account-service.h> #include <libaccounts-glib/ag-manager.h> #include <libaccounts-glib/ag-service.h> +#include <libaccounts-glib/ag-auth-data.h> + +#include <libsignon-glib/signon-identity.h> #include <string.h> #include <ctype.h> @@ -82,6 +85,27 @@ AgAccountId account_id; } DelayedSignalData; +static gboolean +_tp_transform_to_string(const GValue *src, GValue *dst) +{ + g_value_init(dst, G_TYPE_STRING); + gboolean ret = FALSE; + + if (G_VALUE_TYPE(src) == G_TYPE_BOOLEAN) + { + if (g_value_get_boolean(src)) + g_value_set_static_string(dst, "true"); + else + g_value_set_static_string(dst, "false"); + ret = TRUE; + } + else + { + ret = g_value_transform(src, dst); + } + + return ret; +} static gchar * _service_dup_tp_value (AgAccountService *service, @@ -92,10 +116,41 @@ gchar *ret; g_value_init (&value, G_TYPE_STRING); - ag_account_service_get_value (service, real_key, &value); - ret = g_value_dup_string (&value); - g_value_unset (&value); + AgSettingSource re = ag_account_service_get_value (service, real_key, &value); + if (re == AG_SETTING_SOURCE_NONE) + { + /* Retry as int */ + g_value_unset (&value); + g_value_init (&value, G_TYPE_INT); + re = ag_account_service_get_value (service, real_key, &value); + + if (re == AG_SETTING_SOURCE_NONE) + { + /* Retry as boolean.. */ + g_value_unset (&value); + g_value_init (&value, G_TYPE_BOOLEAN); + re = ag_account_service_get_value (service, real_key, &value); + + if (re == AG_SETTING_SOURCE_NONE) + { + g_value_unset(&value); + g_value_init (&value, G_TYPE_STRING); + } + } + } + if (G_VALUE_TYPE(&value) != G_TYPE_STRING) + { + GValue tmp = G_VALUE_INIT; + _tp_transform_to_string(&value, &tmp); + ret = g_value_dup_string (&tmp); + g_value_unset(&tmp); + } + else + ret = g_value_dup_string (&value); + + g_value_unset (&value); + g_free(real_key); return ret; } @@ -149,6 +204,8 @@ DEBUG ("UOA account %s toggled: %s", account_name, enabled ? "enabled" : "disabled"); + /* FIXME: Should this update the username from signon credentials first, + * in case that was changed? */ g_signal_emit_by_name (self, "toggled", account_name, enabled); g_free (account_name); @@ -165,6 +222,7 @@ DEBUG ("UOA account %s changed", account_name); + /* FIXME: Should check signon credentials for changed username */ /* FIXME: Could use ag_account_service_get_changed_fields() * and emit "altered-one" */ g_signal_emit_by_name (self, "altered", account_name); @@ -210,6 +268,64 @@ return TRUE; } +typedef struct +{ + AgAccount *account; + AgAccountService *service; + McpAccountManagerUoa *self; +} AccountCreateData; + +static void +_account_created_signon_cb(SignonIdentity *signon, + const SignonIdentityInfo *info, + const GError *error, + gpointer user_data) +{ + AccountCreateData *data = (AccountCreateData*) user_data; + gchar *username = g_strdup (signon_identity_info_get_username (info)); + gchar *account_name = NULL; + + gchar *cm_name = _service_dup_tp_value (data->service, "manager"); + gchar *protocol_name = _service_dup_tp_value (data->service, "protocol"); + + if (!tp_str_empty (cm_name) && + !tp_str_empty (protocol_name) && + !tp_str_empty (username)) + { + GHashTable *params; + + params = tp_asv_new ( + "account", G_TYPE_STRING, username, + NULL); + + account_name = mcp_account_manager_get_unique_name (data->self->priv->am, + cm_name, protocol_name, params); + _service_set_tp_account_name (data->service, account_name); + + /* Must be stored for CMs */ + _service_set_tp_value (data->service, "param-account", username); + + ag_account_store (data->account, _account_stored_cb, data->self); + + g_hash_table_unref (params); + } + + g_free (cm_name); + g_free (protocol_name); + + if (account_name != NULL) + { + if (_add_service (data->self, data->service, account_name)) + g_signal_emit_by_name (data->self, "created", account_name); + } + + g_free (account_name); + g_object_unref (data->service); + g_object_unref (data->account); + g_object_unref (signon); + g_free(data); +} + static void _account_created_cb (AgManager *manager, AgAccountId id, @@ -237,43 +353,32 @@ AgAccountService *service = ag_account_service_new (account, l->data); gchar *account_name = _service_dup_tp_account_name (service); + ag_service_unref (l->data); + l = g_list_delete_link (l, l); + /* If this is the first time we see this service, we have to generate an * account_name for it. */ if (account_name == NULL) { - gchar *cm_name = NULL; - gchar *protocol_name = NULL; - gchar *account_param = NULL; - - cm_name = _service_dup_tp_value (service, "manager"); - protocol_name = _service_dup_tp_value (service, "protocol"); - account_param = _service_dup_tp_value (service, "param-account"); - - if (!tp_str_empty (cm_name) && - !tp_str_empty (protocol_name) && - !tp_str_empty (account_param)) - { - GHashTable *params; - - params = tp_asv_new ( - "account", G_TYPE_STRING, account_param, - NULL); - - account_name = mcp_account_manager_get_unique_name (self->priv->am, - cm_name, protocol_name, params); - _service_set_tp_account_name (service, account_name); - - ag_account_store (account, _account_stored_cb, self); - - g_hash_table_unref (params); - } - - g_free (cm_name); - g_free (protocol_name); - g_free (account_param); + /* Request auth data to get the username from signon; it's not available + * from the account. */ + AgAuthData *auth_data = ag_account_service_get_auth_data (service); + guint cred_id = ag_auth_data_get_credentials_id (auth_data); + ag_auth_data_unref(auth_data); + + SignonIdentity *signon = signon_identity_new_from_db (cred_id); + + /* Callback frees/unrefs data */ + AccountCreateData *data = g_new(AccountCreateData, 1); + data->account = account; + data->service = service; + data->self = self; + + DEBUG("UOA querying account info from signon"); + signon_identity_query_info(signon, _account_created_signon_cb, data); + return; } - - if (account_name != NULL) + else { if (_add_service (self, service, account_name)) g_signal_emit_by_name (self, "created", account_name); @@ -281,8 +386,6 @@ g_free (account_name); g_object_unref (service); - ag_service_unref (l->data); - l = g_list_delete_link (l, l); } g_object_unref (account); @@ -487,10 +590,23 @@ while (ag_account_service_settings_iter_next (&iter, &k, &v)) { if (!G_VALUE_HOLDS_STRING (v)) - continue; - - mcp_account_manager_set_value (am, account_name, - k, g_value_get_string (v)); + { + GValue strv = G_VALUE_INIT; + if (!_tp_transform_to_string(v, &strv)) + { + g_value_unset(&strv); + continue; + } + + mcp_account_manager_set_value (am, account_name, + k, g_value_get_string (&strv)); + g_value_unset(&strv); + } + else + { + mcp_account_manager_set_value (am, account_name, + k, g_value_get_string (v)); + } } } --- mcp-account-manager-uoa/mcp-account-manager-uoa.pro +++ mcp-account-manager-uoa/mcp-account-manager-uoa.pro @@ -3,7 +3,7 @@ CONFIG += link_pkgconfig use_c_linker plugin no_plugin_name_prefix CONFIG -= qt -PKGCONFIG += mission-control-plugins libaccounts-glib +PKGCONFIG += mission-control-plugins libaccounts-glib libsignon-glib SOURCES = empathy-webcredentials-monitor.c \ mcp-account-manager-uoa.c \ --- telepathy-sasl-signon/telepathy-sasl-signon.pro +++ telepathy-sasl-signon/telepathy-sasl-signon.pro @@ -2,7 +2,7 @@ CONFIG -= qt CONFIG += link_pkgconfig -PKGCONFIG += telepathy-glib libsignon-glib libaccounts-glib libsoup-2.4 +PKGCONFIG += libsignon-glib telepathy-glib libaccounts-glib libsoup-2.4 DEFINES += HAVE_UOA \ EMPATHY_UOA_PROVIDER=\\\"im.telepathy.Account.Storage.UOA\\\"
