[glib-networking/mcatanzaro/base-rebase: 40/44] gtlsbackend-openssl: use G_DECLARE_FINAL_TYPE



commit ce51dd70845a813f57ecdb6605efad7d3230ce2a
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Sun Apr 7 16:57:36 2019 -0500

    gtlsbackend-openssl: use G_DECLARE_FINAL_TYPE
    
    There's no reason for this to be derivable. It has one vfunc that is not
    needed because nothing inherits from it. (It used to be derivable for
    GnuTLS only to support the old GnuTLS PKCS#11 backend's separate
    GTlsDatabase.)

 tls/openssl/gtlsbackend-openssl.c | 70 +++++++++++++++++++++++++++------------
 tls/openssl/gtlsbackend-openssl.h |  7 +---
 2 files changed, 49 insertions(+), 28 deletions(-)
---
diff --git a/tls/openssl/gtlsbackend-openssl.c b/tls/openssl/gtlsbackend-openssl.c
index e6b8cd9..486dd1c 100644
--- a/tls/openssl/gtlsbackend-openssl.c
+++ b/tls/openssl/gtlsbackend-openssl.c
@@ -37,16 +37,17 @@
 #include "gtlsclientconnection-openssl.h"
 #include "gtlsfiledatabase-openssl.h"
 
-typedef struct _GTlsBackendOpensslPrivate
+struct _GTlsBackendOpenssl
 {
+  GObject parent_instance;
+
   GMutex mutex;
   GTlsDatabase *default_database;
-} GTlsBackendOpensslPrivate;
+};
 
 static void g_tls_backend_openssl_interface_init (GTlsBackendInterface *iface);
 
 G_DEFINE_DYNAMIC_TYPE_EXTENDED (GTlsBackendOpenssl, g_tls_backend_openssl, G_TYPE_OBJECT, 0,
-                                G_ADD_PRIVATE_DYNAMIC (GTlsBackendOpenssl)
                                 G_IMPLEMENT_INTERFACE_DYNAMIC (G_TYPE_TLS_BACKEND,
                                                                g_tls_backend_openssl_interface_init))
 
@@ -149,10 +150,6 @@ static GOnce openssl_inited = G_ONCE_INIT;
 static void
 g_tls_backend_openssl_init (GTlsBackendOpenssl *backend)
 {
-  GTlsBackendOpensslPrivate *priv;
-
-  priv = g_tls_backend_openssl_get_instance_private (backend);
-
   /* Once we call gtls_openssl_init(), we can't allow the module to be
    * unloaded (since if openssl gets unloaded but gcrypt doesn't, then
    * gcrypt will have dangling pointers to openssl's mutex functions).
@@ -162,7 +159,7 @@ g_tls_backend_openssl_init (GTlsBackendOpenssl *backend)
    */
   g_once (&openssl_inited, gtls_openssl_init, NULL);
 
-  g_mutex_init (&priv->mutex);
+  g_mutex_init (&backend->mutex);
 }
 
 static void
@@ -171,12 +168,9 @@ g_tls_backend_openssl_finalize (GObject *object)
   int i;
 
   GTlsBackendOpenssl *backend = G_TLS_BACKEND_OPENSSL (object);
-  GTlsBackendOpensslPrivate *priv;
-
-  priv = g_tls_backend_openssl_get_instance_private (backend);
 
-  g_clear_object (&priv->default_database);
-  g_mutex_clear (&priv->mutex);
+  g_clear_object (&backend->default_database);
+  g_mutex_clear (&backend->mutex);
 
   CRYPTO_set_id_callback (NULL);
   CRYPTO_set_locking_callback (NULL);
@@ -190,6 +184,41 @@ g_tls_backend_openssl_finalize (GObject *object)
   G_OBJECT_CLASS (g_tls_backend_openssl_parent_class)->finalize (object);
 }
 
+static GTlsDatabase *
+g_tls_backend_openssl_create_database (GTlsBackendOpenssl  *self,
+                                       GError             **error)
+{
+  gchar *anchor_file = NULL;
+  GTlsDatabase *database;
+
+#ifdef G_OS_WIN32
+  if (g_getenv ("G_TLS_OPENSSL_HANDLE_CERT_RELOCATABLE") != NULL)
+    {
+      gchar *module_dir;
+
+      module_dir = g_win32_get_package_installation_directory_of_module (NULL);
+      anchor_file = g_build_filename (module_dir, "bin", "cert.pem", NULL);
+      g_free (module_dir);
+    }
+#endif
+
+  if (anchor_file == NULL)
+    {
+      const gchar *openssl_cert_file;
+
+      openssl_cert_file = g_getenv (X509_get_default_cert_file_env ());
+      if (openssl_cert_file == NULL)
+        openssl_cert_file = X509_get_default_cert_file ();
+
+      anchor_file = g_strdup (openssl_cert_file);
+    }
+
+  database = g_tls_file_database_new (anchor_file, error);
+  g_free (anchor_file);
+
+  return database;
+}
+
 static void
 g_tls_backend_openssl_class_init (GTlsBackendOpensslClass *klass)
 {
@@ -203,21 +232,18 @@ g_tls_backend_openssl_class_finalize (GTlsBackendOpensslClass *backend_class)
 {
 }
 
-static GTlsDatabase*
+static GTlsDatabase *
 g_tls_backend_openssl_get_default_database (GTlsBackend *backend)
 {
   GTlsBackendOpenssl *openssl_backend = G_TLS_BACKEND_OPENSSL (backend);
-  GTlsBackendOpensslPrivate *priv;
   GTlsDatabase *result;
   GError *error = NULL;
 
-  priv = g_tls_backend_openssl_get_instance_private (openssl_backend);
-
-  g_mutex_lock (&priv->mutex);
+  g_mutex_lock (&openssl_backend->mutex);
 
-  if (priv->default_database)
+  if (openssl_backend->default_database)
     {
-      result = g_object_ref (priv->default_database);
+      result = g_object_ref (openssl_backend->default_database);
     }
   else
     {
@@ -231,11 +257,11 @@ g_tls_backend_openssl_get_default_database (GTlsBackend *backend)
       else
         {
           g_assert (result);
-          priv->default_database = g_object_ref (result);
+          openssl_backend->default_database = g_object_ref (result);
         }
     }
 
-  g_mutex_unlock (&priv->mutex);
+  g_mutex_unlock (&openssl_backend->mutex);
 
   return result;
 }
diff --git a/tls/openssl/gtlsbackend-openssl.h b/tls/openssl/gtlsbackend-openssl.h
index f34c5f8..557691f 100644
--- a/tls/openssl/gtlsbackend-openssl.h
+++ b/tls/openssl/gtlsbackend-openssl.h
@@ -31,13 +31,8 @@
 G_BEGIN_DECLS
 
 #define G_TYPE_TLS_BACKEND_OPENSSL (g_tls_backend_openssl_get_type ())
-G_DECLARE_DERIVABLE_TYPE (GTlsBackendOpenssl, g_tls_backend_openssl,
-                          G, TLS_BACKEND_OPENSSL, GObject)
 
-struct _GTlsBackendOpensslClass
-{
-  GObjectClass parent_class;
-};
+G_DECLARE_FINAL_TYPE (GTlsBackendOpenssl, g_tls_backend_openssl, G, TLS_BACKEND_OPENSSL, GObject)
 
 void    g_tls_backend_openssl_register       (GIOModule *module);
 


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