[glib/tls-database] Per lookup operation virtual methods in GTlsDatabase



commit 3b9fc8887c539cb22e952d76ea1fba14b14cfbd6
Author: Stef Walter <stefw collabora co uk>
Date:   Tue Dec 21 17:26:15 2010 +0000

    Per lookup operation virtual methods in GTlsDatabase
    
     * Rather than trying to cram all the different kinds of
       certificate lookups into a single virtual method
       use multiple virtual methods for different kinds of
       lookups.
     * Start with the lookup_issuer() virtual method.

 gio/gtlsdatabase.c |  161 +++++++++++++++++++++++-----------------------------
 gio/gtlsdatabase.h |   68 +++++++++-------------
 2 files changed, 100 insertions(+), 129 deletions(-)
---
diff --git a/gio/gtlsdatabase.c b/gio/gtlsdatabase.c
index d61c7d4..55d6eb5 100644
--- a/gio/gtlsdatabase.c
+++ b/gio/gtlsdatabase.c
@@ -124,94 +124,85 @@ g_tls_database_real_verify_chain_finish (GTlsDatabase          *self,
   return args->verify_result;
 }
 
-typedef struct _AsyncLookupCertificates {
-  GTlsDatabaseLookupType lookup_type;
-  gpointer identifier;
-  gsize identifier_length;
-  GList *results;
-} AsyncLookupCertificates;
+typedef struct _AsyncLookupIssuer {
+  GTlsCertificate *certificate;
+  GTlsCertificate *issuer;
+} AsyncLookupIssuer;
 
 static void
-async_lookup_certificates_free (gpointer data)
+async_lookup_issuer_free (gpointer data)
 {
-  AsyncLookupCertificates *args = data;
-  GList *l;
-
-  g_free (args->identifier);
-  for (l = args->results; l; l = g_list_next (l))
-    g_object_unref (l->data);
-  g_list_free (args->results);
-  g_slice_free (AsyncLookupCertificates, args);
+  AsyncLookupIssuer *args = data;
+
+  g_object_unref (args->certificate);
+  if (args->issuer)
+    g_object_unref (args->issuer);
+  g_slice_free (AsyncLookupIssuer, args);
 }
 
 static void
-async_lookup_certificates_thread (GSimpleAsyncResult *res,
-                                  GObject            *object,
-                                  GCancellable       *cancellable)
+async_lookup_issuer_thread (GSimpleAsyncResult *res,
+                            GObject            *object,
+                            GCancellable       *cancellable)
 {
-  AsyncLookupCertificates *args = g_object_get_qdata (G_OBJECT (res), Q_ASYNC_DATA);
+  AsyncLookupIssuer *args = g_object_get_qdata (G_OBJECT (res), Q_ASYNC_DATA);
   GError *error = NULL;
 
-  args->results = g_tls_database_lookup_certificates (G_TLS_DATABASE (object),
-                                                      args->lookup_type,
-                                                      args->identifier,
-                                                      args->identifier_length,
-                                                      cancellable,
-                                                      &error);
+  args->issuer = g_tls_database_lookup_issuer (G_TLS_DATABASE (object),
+                                               args->certificate,
+                                               cancellable,
+                                               &error);
 
   if (error)
       g_simple_async_result_take_error (res, error);
 }
 
 static void
-g_tls_database_real_lookup_certificates_async (GTlsDatabase          *self,
-                                               GTlsDatabaseLookupType lookup_type,
-                                               gconstpointer          identifier,
-                                               gsize                  identifier_length,
-                                               GCancellable          *cancellable,
-                                               GAsyncReadyCallback    callback,
-                                               gpointer               user_data)
+g_tls_database_real_lookup_issuer_async (GTlsDatabase          *self,
+                                         GTlsCertificate       *certificate,
+                                         GCancellable          *cancellable,
+                                         GAsyncReadyCallback    callback,
+                                         gpointer               user_data)
 {
   GSimpleAsyncResult *res;
-  AsyncLookupCertificates *args;
+  AsyncLookupIssuer *args;
 
+  g_return_if_fail (G_IS_TLS_CERTIFICATE (certificate));
   g_return_if_fail (callback);
 
-  args = g_slice_new0 (AsyncLookupCertificates);
-  args->lookup_type = lookup_type;
-  args->identifier = g_memdup (identifier, identifier_length);
-  args->identifier_length = identifier_length;
+  args = g_slice_new0 (AsyncLookupIssuer);
+  args->certificate = g_object_ref (certificate);
 
   res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
-                                   g_tls_database_real_lookup_certificates_async);
-  g_object_set_qdata_full (G_OBJECT (res), Q_ASYNC_DATA, args, async_lookup_certificates_free);
-  g_simple_async_result_run_in_thread (res, async_lookup_certificates_thread,
+                                   g_tls_database_real_lookup_issuer_async);
+  g_object_set_qdata_full (G_OBJECT (res), Q_ASYNC_DATA, args, async_lookup_issuer_free);
+  g_simple_async_result_run_in_thread (res, async_lookup_issuer_thread,
                                        G_PRIORITY_DEFAULT, cancellable);
   g_object_unref (res);
 }
 
-static GList*
-g_tls_database_real_lookup_certificates_finish (GTlsDatabase          *self,
-                                                GAsyncResult          *result,
-                                                GError               **error)
+static GTlsCertificate*
+g_tls_database_real_lookup_issuer_finish (GTlsDatabase          *self,
+                                          GAsyncResult          *result,
+                                          GError               **error)
 {
-  AsyncLookupCertificates *args;
-  GList *results;
+  AsyncLookupIssuer *args;
+  GTlsCertificate *issuer;
 
   g_return_val_if_fail (G_IS_TLS_DATABASE (self), NULL);
   g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
   g_return_val_if_fail (!error || !*error, NULL);
 
   g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
-                        g_tls_database_real_verify_chain_async), FALSE);
+                        g_tls_database_real_lookup_issuer_async), FALSE);
 
   if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
     return NULL;
 
   args = g_object_get_qdata (G_OBJECT (result), Q_ASYNC_DATA);
-  results = args->results;
-  args->results = NULL;
-  return results;
+  issuer = args->issuer;
+  args->issuer = NULL;
+  return issuer;
 }
 
 static void
@@ -219,8 +210,8 @@ g_tls_database_class_init (GTlsDatabaseClass *klass)
 {
   klass->verify_chain_async = g_tls_database_real_verify_chain_async;
   klass->verify_chain_finish = g_tls_database_real_verify_chain_finish;
-  klass->lookup_certificates_async = g_tls_database_real_lookup_certificates_async;
-  klass->lookup_certificates_finish = g_tls_database_real_lookup_certificates_finish;
+  klass->lookup_issuer_async = g_tls_database_real_lookup_issuer_async;
+  klass->lookup_issuer_finish = g_tls_database_real_lookup_issuer_finish;
 
   Q_ASYNC_DATA = g_quark_from_static_string ("GTlsDatabase::AsyncArgs");
 }
@@ -277,52 +268,44 @@ g_tls_database_verify_chain_finish (GTlsDatabase          *self,
                                                                error);
 }
 
-GList*
-g_tls_database_lookup_certificates (GTlsDatabase          *self,
-                                    GTlsDatabaseLookupType lookup_type,
-                                    gconstpointer          identifier,
-                                    gsize                  identifier_length,
-                                    GCancellable          *cancellable,
-                                    GError               **error)
+GTlsCertificate*
+g_tls_database_lookup_issuer (GTlsDatabase          *self,
+                              GTlsCertificate       *certificate,
+                              GCancellable          *cancellable,
+                              GError               **error)
 {
   g_return_val_if_fail (G_IS_TLS_DATABASE (self), NULL);
-  g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates, NULL);
-  return G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates (self,
-                                                               lookup_type,
-                                                               identifier,
-                                                               identifier_length,
-                                                               cancellable,
-                                                               error);
+  g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_issuer, NULL);
+  return G_TLS_DATABASE_GET_CLASS (self)->lookup_issuer (self,
+                                                         certificate,
+                                                         cancellable,
+                                                         error);
 }
 
 void
-g_tls_database_lookup_certificates_async (GTlsDatabase          *self,
-                                          GTlsDatabaseLookupType lookup_type,
-                                          gconstpointer          identifier,
-                                          gsize                  identifier_length,
-                                          GCancellable          *cancellable,
-                                          GAsyncReadyCallback    callback,
-                                          gpointer               user_data)
+g_tls_database_lookup_issuer_async (GTlsDatabase          *self,
+                                    GTlsCertificate       *certificate,
+                                    GCancellable          *cancellable,
+                                    GAsyncReadyCallback    callback,
+                                    gpointer               user_data)
 {
   g_return_if_fail (G_IS_TLS_DATABASE (self));
-  g_return_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates_async);
-  G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates_async (self,
-                                                              lookup_type,
-                                                              identifier,
-                                                              identifier_length,
-                                                              cancellable,
-                                                              callback,
-                                                              user_data);
+  g_return_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_issuer_async);
+  G_TLS_DATABASE_GET_CLASS (self)->lookup_issuer_async (self,
+                                                        certificate,
+                                                        cancellable,
+                                                        callback,
+                                                        user_data);
 }
 
-GList*
-g_tls_database_lookup_certificates_finish (GTlsDatabase          *self,
-                                           GAsyncResult          *result,
-                                           GError               **error)
+GTlsCertificate*
+g_tls_database_lookup_issuer_finish (GTlsDatabase          *self,
+                                     GAsyncResult          *result,
+                                     GError               **error)
 {
   g_return_val_if_fail (G_IS_TLS_DATABASE (self), NULL);
-  g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates_finish, NULL);
-  return G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates_finish (self,
-                                                                      result,
-                                                                      error);
+  g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_issuer_finish, NULL);
+  return G_TLS_DATABASE_GET_CLASS (self)->lookup_issuer_finish (self,
+                                                                result,
+                                                                error);
 }
diff --git a/gio/gtlsdatabase.h b/gio/gtlsdatabase.h
index 1c41249..ca9be5e 100644
--- a/gio/gtlsdatabase.h
+++ b/gio/gtlsdatabase.h
@@ -32,10 +32,6 @@
 G_BEGIN_DECLS
 
 typedef enum {
-  G_TLS_DATABASE_LOOKUP_ISSUER,
-} GTlsDatabaseLookupType;
-
-typedef enum {
   G_TLS_DATABASE_VERIFY_NOFLAGS = 0,
 } GTlsDatabaseVerifyFlags;
 
@@ -78,24 +74,20 @@ struct _GTlsDatabaseClass
                                                    GAsyncResult          *result,
                                                    GError               **error);
 
-  GList*                (*lookup_certificates)        (GTlsDatabase          *self,
-                                                       GTlsDatabaseLookupType lookup_type,
-                                                       gconstpointer          identifier,
-                                                       gsize                  identifier_length,
-                                                       GCancellable          *cancellable,
-                                                       GError               **error);
-
-  void                  (*lookup_certificates_async)  (GTlsDatabase          *self,
-                                                       GTlsDatabaseLookupType lookup_type,
-                                                       gconstpointer          identifier,
-                                                       gsize                  n_identifier,
-                                                       GCancellable          *cancellable,
-                                                       GAsyncReadyCallback    callback,
-                                                       gpointer               user_data);
-
-  GList*                (*lookup_certificates_finish) (GTlsDatabase          *self,
-                                                       GAsyncResult          *result,
-                                                       GError               **error);
+  GTlsCertificate*      (*lookup_issuer)          (GTlsDatabase            *self,
+                                                   GTlsCertificate         *certificate,
+                                                   GCancellable            *cancellable,
+                                                   GError                 **error);
+
+  void                  (*lookup_issuer_async)    (GTlsDatabase            *self,
+                                                   GTlsCertificate         *certificate,
+                                                   GCancellable            *cancellable,
+                                                   GAsyncReadyCallback      callback,
+                                                   gpointer                 user_data);
+
+  GTlsCertificate*      (*lookup_issuer_finish)   (GTlsDatabase            *self,
+                                                   GAsyncResult            *result,
+                                                   GError                 **error);
 
   /*< private >*/
   /* Padding for future expansion */
@@ -123,24 +115,20 @@ GTlsCertificateFlags   g_tls_database_verify_chain_finish   (GTlsDatabase
                                                              GAsyncResult            *result,
                                                              GError                 **error);
 
-GList*                  g_tls_database_lookup_certificates            (GTlsDatabase          *self,
-                                                                       GTlsDatabaseLookupType lookup_type,
-                                                                       gconstpointer          identifier,
-                                                                       gsize                  identifier_length,
-                                                                       GCancellable          *cancellable,
-                                                                       GError               **error);
-
-void                    g_tls_database_lookup_certificates_async      (GTlsDatabase          *self,
-                                                                       GTlsDatabaseLookupType lookup_type,
-                                                                       gconstpointer          identifier,
-                                                                       gsize                  identifier_length,
-                                                                       GCancellable          *cancellable,
-                                                                       GAsyncReadyCallback    callback,
-                                                                       gpointer               user_data);
-
-GList*                  g_tls_database_lookup_certificates_finish     (GTlsDatabase          *self,
-                                                                       GAsyncResult          *result,
-                                                                       GError               **error);
+GTlsCertificate*       g_tls_database_lookup_issuer         (GTlsDatabase            *self,
+                                                             GTlsCertificate         *certificate,
+                                                             GCancellable            *cancellable,
+                                                             GError                 **error);
+
+void                   g_tls_database_lookup_issuer_async   (GTlsDatabase          *self,
+                                                             GTlsCertificate         *certificate,
+                                                             GCancellable          *cancellable,
+                                                             GAsyncReadyCallback    callback,
+                                                             gpointer               user_data);
+
+GTlsCertificate*       g_tls_database_lookup_issuer_finish  (GTlsDatabase          *self,
+                                                             GAsyncResult          *result,
+                                                             GError               **error);
 
 G_END_DECLS
 



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