]> git.0d.be Git - empathy.git/commitdiff
Properly handle corner cases of _prepare_async() called twice
authorCosimo Cecchi <cosimoc@gnome.org>
Tue, 24 Aug 2010 13:20:06 +0000 (15:20 +0200)
committerCosimo Cecchi <cosimoc@gnome.org>
Tue, 24 Aug 2010 13:20:06 +0000 (15:20 +0200)
- If it's called twice before the first call returned, emit an error.
- If it's called twice on an already-prepared object, just successfully
  return.

libempathy/empathy-tls-certificate.c

index 00ff4d54769d1d0908a16c41d9826f363efa3bfc..acb94c79d3000b9b4b8e5e5eb7490d068618d83c 100644 (file)
@@ -52,6 +52,8 @@ typedef struct {
   gchar *cert_type;
   GPtrArray *cert_data;
   EmpTLSCertificateState state;
+
+  gboolean is_prepared;
 } EmpathyTLSCertificatePriv;
 
 G_DEFINE_TYPE (EmpathyTLSCertificate, empathy_tls_certificate,
@@ -106,6 +108,8 @@ tls_certificate_got_all_cb (TpProxy *proxy,
   DEBUG ("Got a certificate chain long %u, of type %s",
       priv->cert_data->len, priv->cert_type);
 
+  priv->is_prepared = TRUE;
+
   g_simple_async_result_complete (priv->async_prepare_res);
   tp_clear_object (&priv->async_prepare_res);
 }
@@ -117,6 +121,28 @@ empathy_tls_certificate_prepare_async (EmpathyTLSCertificate *self,
 {
   EmpathyTLSCertificatePriv *priv = GET_PRIV (self);
 
+  /* emit an error if we're already preparing the object */
+  if (priv->async_prepare_res != NULL)
+    {
+      g_simple_async_report_error_in_idle (G_OBJECT (self),
+          callback, user_data,
+          G_IO_ERROR, G_IO_ERROR_PENDING,
+          "%s",
+          "Prepare operation already in progress on the TLS certificate.");
+
+      return;
+    }
+                     
+
+  /* if the object is already prepared, just complete in idle */
+  if (priv->is_prepared)
+    {    
+      tp_simple_async_report_success_in_idle (G_OBJECT (self),
+          callback, user_data, empathy_tls_certificate_prepare_async);
+
+      return;
+    }
+
   priv->async_prepare_res = g_simple_async_result_new (G_OBJECT (self),
       callback, user_data, empathy_tls_certificate_prepare_async);