[gnome-online-accounts] utils: Look at the presentation_identity when checking for duplicates



commit 3a6013ecb66047613285e392f72be9879df9ea16
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Mar 18 18:15:46 2013 +0100

    utils: Look at the presentation_identity when checking for duplicates
    
    Fixes: https://bugzilla.gnome.org/696085

 src/goabackend/goaexchangeprovider.c |    1 +
 src/goabackend/goaimapsmtpprovider.c |    1 +
 src/goabackend/goakerberosprovider.c |    7 ++++---
 src/goabackend/goaoauth2provider.c   |    1 +
 src/goabackend/goaoauthprovider.c    |    1 +
 src/goabackend/goaowncloudprovider.c |    7 +++++--
 src/goabackend/goautils.c            |    8 +++++---
 src/goabackend/goautils.h            |    1 +
 8 files changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/src/goabackend/goaexchangeprovider.c b/src/goabackend/goaexchangeprovider.c
index 144d046..4ece894 100644
--- a/src/goabackend/goaexchangeprovider.c
+++ b/src/goabackend/goaexchangeprovider.c
@@ -681,6 +681,7 @@ add_account (GoaProvider    *provider,
   provider_type = goa_provider_get_provider_type (provider);
   if (!goa_utils_check_duplicate (client,
                                   username,
+                                  email_address,
                                   provider_type,
                                   (GoaPeekInterfaceFunc) goa_object_peek_password_based,
                                   &data.error))
diff --git a/src/goabackend/goaimapsmtpprovider.c b/src/goabackend/goaimapsmtpprovider.c
index 36f4955..0972f7b 100644
--- a/src/goabackend/goaimapsmtpprovider.c
+++ b/src/goabackend/goaimapsmtpprovider.c
@@ -938,6 +938,7 @@ add_account (GoaProvider    *provider,
   provider_type = goa_provider_get_provider_type (provider);
   if (!goa_utils_check_duplicate (client,
                                   email_address,
+                                  email_address,
                                   provider_type,
                                   (GoaPeekInterfaceFunc) goa_object_peek_password_based,
                                   &data.error))
diff --git a/src/goabackend/goakerberosprovider.c b/src/goabackend/goakerberosprovider.c
index abded27..261f144 100644
--- a/src/goabackend/goakerberosprovider.c
+++ b/src/goabackend/goakerberosprovider.c
@@ -1583,6 +1583,9 @@ start_over:
   g_free (principal);
   principal = g_strdup_printf ("%s %s", username, realm);
 
+  g_free (principal_for_display);
+  principal_for_display = g_strdup_printf ("%s %s", username, realm);
+
   /* See if there's already an account of this type with the
    * given identity
    */
@@ -1590,6 +1593,7 @@ start_over:
 
   if (!goa_utils_check_duplicate (client,
                                   principal,
+                                  principal_for_display,
                                   provider_type,
                                   (GoaPeekInterfaceFunc) goa_object_peek_account,
                                   &request.error))
@@ -1604,9 +1608,6 @@ start_over:
   g_variant_builder_add (&details, "{ss}", "IsTemporary", "true");
   g_variant_builder_add (&details, "{ss}", "TicketingEnabled", "true");
 
-  g_free (principal_for_display);
-  principal_for_display = g_strdup_printf ("%s %s", username, realm);
-
   g_free (realm);
 
   goa_manager_call_add_account (goa_client_get_manager (client),
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index eea3b20..0ba327a 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -1319,6 +1319,7 @@ goa_oauth2_provider_add_account (GoaProvider *_provider,
    */
   if (!goa_utils_check_duplicate (client,
                                   identity,
+                                  presentation_identity,
                                   goa_provider_get_provider_type (GOA_PROVIDER (provider)),
                                   (GoaPeekInterfaceFunc) goa_object_peek_oauth2_based,
                                   &data.error))
diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
index c1dae98..c646d8e 100644
--- a/src/goabackend/goaoauthprovider.c
+++ b/src/goabackend/goaoauthprovider.c
@@ -1244,6 +1244,7 @@ goa_oauth_provider_add_account (GoaProvider *_provider,
    */
   if (!goa_utils_check_duplicate (client,
                                   identity,
+                                  presentation_identity,
                                   goa_provider_get_provider_type (GOA_PROVIDER (provider)),
                                   (GoaPeekInterfaceFunc) goa_object_peek_oauth_based,
                                   &data.error))
diff --git a/src/goabackend/goaowncloudprovider.c b/src/goabackend/goaowncloudprovider.c
index 2c3069b..894add5 100644
--- a/src/goabackend/goaowncloudprovider.c
+++ b/src/goabackend/goaowncloudprovider.c
@@ -767,18 +767,21 @@ add_account (GoaProvider    *provider,
   username = gtk_entry_get_text (GTK_ENTRY (data.username));
   password = gtk_entry_get_text (GTK_ENTRY (data.password));
 
+  uri = normalize_uri (uri_text, &server);
+  presentation_identity = g_strconcat (username, "@", server, NULL);
+
   /* See if there's already an account of this type with the
    * given identity
    */
   provider_type = goa_provider_get_provider_type (provider);
   if (!goa_utils_check_duplicate (client,
                                   username,
+                                  presentation_identity,
                                   provider_type,
                                   (GoaPeekInterfaceFunc) goa_object_peek_password_based,
                                   &data.error))
     goto out;
 
-  uri = normalize_uri (uri_text, &server);
   uri_webdav = g_strconcat (uri, WEBDAV_ENDPOINT, NULL);
   g_cancellable_reset (data.cancellable);
   goa_http_client_check (http_client,
@@ -831,6 +834,7 @@ add_account (GoaProvider    *provider,
       gtk_widget_set_no_show_all (data.cluebar, FALSE);
       gtk_widget_show_all (data.cluebar);
 
+      g_clear_pointer (&presentation_identity, g_free);
       g_clear_pointer (&server, g_free);
       g_clear_pointer (&uri, g_free);
       goto http_again;
@@ -853,7 +857,6 @@ add_account (GoaProvider    *provider,
    * can create a proxy for the new object) so run the mainloop while
    * waiting for this to complete
    */
-  presentation_identity = g_strconcat (username, "@", server, NULL);
   goa_manager_call_add_account (goa_client_get_manager (client),
                                 goa_provider_get_provider_type (provider),
                                 username,
diff --git a/src/goabackend/goautils.c b/src/goabackend/goautils.c
index 167752f..b1b3537 100644
--- a/src/goabackend/goautils.c
+++ b/src/goabackend/goautils.c
@@ -42,6 +42,7 @@ static const SecretSchema secret_password_schema =
 gboolean
 goa_utils_check_duplicate (GoaClient              *client,
                            const gchar            *identity,
+                           const gchar            *presentation_identity,
                            const gchar            *provider_type,
                            GoaPeekInterfaceFunc    func,
                            GError                **error)
@@ -59,6 +60,7 @@ goa_utils_check_duplicate (GoaClient              *client,
       GoaAccount *account;
       gpointer *interface;
       const gchar *identity_from_object;
+      const gchar *presentation_identity_from_object;
       const gchar *provider_type_from_object;
 
       account = goa_object_peek_account (object);
@@ -71,12 +73,12 @@ goa_utils_check_duplicate (GoaClient              *client,
         continue;
 
       identity_from_object = goa_account_get_identity (account);
-      if (g_strcmp0 (identity_from_object, identity) == 0)
+      presentation_identity_from_object = goa_account_get_presentation_identity (account);
+      if (g_strcmp0 (identity_from_object, identity) == 0
+          && g_strcmp0 (presentation_identity_from_object, presentation_identity) == 0)
         {
-          const gchar *presentation_identity;
           const gchar *provider_name;
 
-          presentation_identity = goa_account_get_presentation_identity (account);
           provider_name = goa_account_get_provider_name (account);
           g_set_error (error,
                        GOA_ERROR,
diff --git a/src/goabackend/goautils.h b/src/goabackend/goautils.h
index 3c6b5af..454e702 100644
--- a/src/goabackend/goautils.h
+++ b/src/goabackend/goautils.h
@@ -38,6 +38,7 @@ typedef gpointer (*GoaPeekInterfaceFunc)   (GoaObject *);
 
 gboolean         goa_utils_check_duplicate (GoaClient              *client,
                                             const gchar            *identity,
+                                            const gchar            *presentation_identity,
                                             const gchar            *provider_type,
                                             GoaPeekInterfaceFunc    func,
                                             GError                **error);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]