From dc73f3d3e51958edaf3b0508c4205c387e735547 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 24 Aug 2010 15:20:06 +0200 Subject: Properly handle corner cases of _prepare_async() called twice - 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 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'libempathy') diff --git a/libempathy/empathy-tls-certificate.c b/libempathy/empathy-tls-certificate.c index 00ff4d547..acb94c79d 100644 --- a/libempathy/empathy-tls-certificate.c +++ b/libempathy/empathy-tls-certificate.c @@ -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); -- cgit v1.2.3