[folks] Don't assume that "CONNECTED" Tp.Accounts have valid Tp.Connections



commit e45a9630f5f81d4c706959f975300e26acb013ad
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Mon Sep 26 15:07:05 2011 -0700

    Don't assume that "CONNECTED" Tp.Accounts have valid Tp.Connections
    
    There's an in-between state where the Tp.Account is "CONNECTED" but hasn't
    finished preparing its Tp.Connection (and thus, it's null).
    
    Closes: bgo#659041 â tpf-persona-store.vala: try to connect to a NULL object

 NEWS                                          |    1 +
 backends/telepathy/lib/tpf-persona-store.vala |   31 +++++++++---------------
 2 files changed, 13 insertions(+), 19 deletions(-)
---
diff --git a/NEWS b/NEWS
index 5d97b51..f129533 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Overview of changes from libfolks 0.6.3.1 to libfolks 0.6.4
 ===========================================================
 * Bug 660140 â contacts_contact_find_persona_from_store: assertion `store !=
   NULL' failed
+* Bug 659041 â tpf-persona-store.vala: try to connect to a NULL object
 
 Overview of changes from libfolks 0.6.3 to libfolks 0.6.3.1
 ===========================================================
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index fb7363b..6b6f930 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -583,18 +583,14 @@ public class Tpf.PersonaStore : Folks.PersonaStore
               /* Ensure the account's prepared first. */
               yield this.account.prepare_async (null);
 
-              this.account.status_changed.connect (
-                  this._account_status_changed_cb);
+              this.account.notify["connection"].connect (
+                  this._notify_connection_cb);
 
-              TelepathyGLib.ConnectionStatusReason reason;
-              var status = this.account.get_connection_status (out reason);
               /* immediately handle accounts which are not currently being
                * disconnected */
-              if (status != TelepathyGLib.ConnectionStatus.DISCONNECTED)
+              if (this.account.connection != null)
                 {
-                  this._account_status_changed_cb (
-                      TelepathyGLib.ConnectionStatus.DISCONNECTED, status,
-                      reason, null, null);
+                  this._notify_connection_cb (this.account, null);
                 }
               else
                 {
@@ -759,16 +755,15 @@ public class Tpf.PersonaStore : Folks.PersonaStore
         }
     }
 
-  /* FIXME: the second generic type for details is "weak GLib.Value", but Vala
-   * doesn't accept it as a generic type */
-  private void _account_status_changed_cb (uint old_status, uint new_status,
-      uint reason, string? dbus_error_name,
-      GLib.HashTable<weak string, weak void*>? details)
+  private void _notify_connection_cb (Object s, ParamSpec? p)
     {
-      debug ("Account '%s' changed status from %u to %u.", this.id, old_status,
-          new_status);
+      var account = s as TelepathyGLib.Account;
 
-      if (new_status == TelepathyGLib.ConnectionStatus.DISCONNECTED)
+      debug ("Account '%s' connection changed to %p", this.id,
+          account.connection);
+
+      /* account disconnected */
+      if (account.connection == null)
         {
           /* When disconnecting, we want the PersonaStore to remain alive, but
            * all its Personas to be removed. We do *not* want the PersonaStore
@@ -780,7 +775,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
            *
            * Before we do this, we store the current set of personas to the
            * cache, assuming we were connected before. */
-          if (old_status == TelepathyGLib.ConnectionStatus.CONNECTED)
+          if (this._conn != null)
             {
               this._store_cache.begin ((o, r) =>
                 {
@@ -814,8 +809,6 @@ public class Tpf.PersonaStore : Folks.PersonaStore
 
           return;
         }
-      else if (new_status != TelepathyGLib.ConnectionStatus.CONNECTED)
-        return;
 
       // We're connected, so can stop advertising personas from the cache
       this._unload_cache ();



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