[glib-networking/mcatanzaro/#92] Rename certificate_error to interaction_error and simplify usage



commit 2038de3e7e84a25c4f9625b5e9168e6c1e231cec
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Mon Jul 15 09:57:56 2019 -0500

    Rename certificate_error to interaction_error and simplify usage
    
    There's no need for g_tls_connection_base_request_certificate() to have
    an error parameter, because the only error passed to it is
    g_tls_connection_base_get_certificate_error(). We can just assign to
    that error directly. Then we no longer need
    g_tls_connection_base_get_certificate_error() anymore either.
    
    Also, the certificate_error is only ever used here, to hold the error
    from the TLS interaction, so it would be better to name it
    interaction_error. This will avoid confusing between certificate_error
    and the similarly-named certificate_errors.

 tls/base/gtlsconnection-base.c             | 26 ++++++++++----------------
 tls/base/gtlsconnection-base.h             |  4 +---
 tls/gnutls/gtlsclientconnection-gnutls.c   |  3 +--
 tls/openssl/gtlsclientconnection-openssl.c |  4 +---
 4 files changed, 13 insertions(+), 24 deletions(-)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index 0c5868f..804eea3 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -88,7 +88,7 @@ typedef struct
 
   GTlsCertificate       *certificate;
   gboolean               missing_requested_client_certificate;
-  GError                *certificate_error;
+  GError                *interaction_error;
   GTlsCertificate       *peer_certificate;
   GTlsCertificateFlags   peer_certificate_errors;
 
@@ -251,7 +251,7 @@ g_tls_connection_base_finalize (GObject *object)
 
   g_clear_object (&priv->database);
   g_clear_object (&priv->certificate);
-  g_clear_error (&priv->certificate_error);
+  g_clear_error (&priv->interaction_error);
   g_clear_object (&priv->peer_certificate);
 
   g_mutex_clear (&priv->verify_certificate_mutex);
@@ -1384,10 +1384,10 @@ handshake_thread (GTask        *task,
   if (error && priv->missing_requested_client_certificate)
     {
       g_clear_error (&error);
-      if (priv->certificate_error)
+      if (priv->interaction_error)
         {
-          error = priv->certificate_error;
-          priv->certificate_error = NULL;
+          error = priv->interaction_error;
+          priv->interaction_error = NULL;
         }
       else
         {
@@ -2416,14 +2416,6 @@ g_tls_connection_base_set_missing_requested_client_certificate (GTlsConnectionBa
   priv->missing_requested_client_certificate = TRUE;
 }
 
-GError **
-g_tls_connection_base_get_certificate_error (GTlsConnectionBase *tls)
-{
-  GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
-
-  return &priv->certificate_error;
-}
-
 GError **
 g_tls_connection_base_get_read_error (GTlsConnectionBase *tls)
 {
@@ -2489,8 +2481,7 @@ g_tls_connection_base_ever_handshaked (GTlsConnectionBase *tls)
 }
 
 gboolean
-g_tls_connection_base_request_certificate (GTlsConnectionBase  *tls,
-                                           GError             **error)
+g_tls_connection_base_request_certificate (GTlsConnectionBase *tls)
 {
   GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
   GTlsInteractionResult res = G_TLS_INTERACTION_UNHANDLED;
@@ -2501,12 +2492,15 @@ g_tls_connection_base_request_certificate (GTlsConnectionBase  *tls,
 
   conn = G_TLS_CONNECTION (tls);
 
+  g_clear_error (&priv->interaction_error);
+
   interaction = g_tls_connection_get_interaction (conn);
   if (!interaction)
     return FALSE;
 
   res = g_tls_interaction_invoke_request_certificate (interaction, conn, 0,
-                                                      priv->read_cancellable, error);
+                                                      priv->read_cancellable,
+                                                      &priv->interaction_error);
   return res != G_TLS_INTERACTION_FAILED;
 }
 
diff --git a/tls/base/gtlsconnection-base.h b/tls/base/gtlsconnection-base.h
index 4361717..483b41a 100644
--- a/tls/base/gtlsconnection-base.h
+++ b/tls/base/gtlsconnection-base.h
@@ -178,7 +178,6 @@ void                      g_tls_connection_base_set_missing_requested_client_cer
 gboolean                  g_tls_connection_base_get_missing_requested_client_certificate
                                                                         (GTlsConnectionBase *tls);
 
-GError                  **g_tls_connection_base_get_certificate_error   (GTlsConnectionBase *tls);
 GError                  **g_tls_connection_base_get_read_error          (GTlsConnectionBase *tls);
 GError                  **g_tls_connection_base_get_write_error         (GTlsConnectionBase *tls);
 
@@ -192,8 +191,7 @@ gboolean                  g_tls_connection_base_is_handshaking          (GTlsCon
 
 gboolean                  g_tls_connection_base_ever_handshaked         (GTlsConnectionBase *tls);
 
-gboolean                  g_tls_connection_base_request_certificate     (GTlsConnectionBase  *tls,
-                                                                         GError             **error);
+gboolean                  g_tls_connection_base_request_certificate     (GTlsConnectionBase  *tls);
 
 void                      g_tls_connection_base_buffer_application_data (GTlsConnectionBase *tls,
                                                                          guint8             *data,
diff --git a/tls/gnutls/gtlsclientconnection-gnutls.c b/tls/gnutls/gtlsclientconnection-gnutls.c
index f1a8921..384df22 100644
--- a/tls/gnutls/gtlsclientconnection-gnutls.c
+++ b/tls/gnutls/gtlsclientconnection-gnutls.c
@@ -352,9 +352,8 @@ g_tls_client_connection_gnutls_retrieve_function (gnutls_session_t
   if (*pcert_length == 0)
     {
       g_tls_certificate_gnutls_copy_free (*pcert, *pcert_length, *pkey);
-      g_clear_error (g_tls_connection_base_get_certificate_error (tls));
 
-      if (g_tls_connection_base_request_certificate (tls, g_tls_connection_base_get_certificate_error (tls)))
+      if (g_tls_connection_base_request_certificate (tls))
         g_tls_connection_gnutls_get_certificate (conn, pcert, pcert_length, pkey);
 
       if (*pcert_length == 0)
diff --git a/tls/openssl/gtlsclientconnection-openssl.c b/tls/openssl/gtlsclientconnection-openssl.c
index 02d06fc..3926029 100644
--- a/tls/openssl/gtlsclientconnection-openssl.c
+++ b/tls/openssl/gtlsclientconnection-openssl.c
@@ -351,9 +351,7 @@ retrieve_certificate (SSL       *ssl,
   cert = g_tls_connection_get_certificate (G_TLS_CONNECTION (client));
   if (!cert)
     {
-      g_clear_error (g_tls_connection_base_get_certificate_error (tls));
-
-      if (g_tls_connection_base_request_certificate (tls, g_tls_connection_base_get_certificate_error (tls)))
+      if (g_tls_connection_base_request_certificate (tls))
         cert = g_tls_connection_get_certificate (G_TLS_CONNECTION (client));
     }
 


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