[glib/tls-database] Cleanup of GTlsDatabase based on Dan Winship's comments.
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/tls-database] Cleanup of GTlsDatabase based on Dan Winship's comments.
- Date: Thu, 16 Dec 2010 16:44:43 +0000 (UTC)
commit 6865b55cdd615afe579e5e7dc8a5b5eb45d88021
Author: Stef Walter <stefw collabora co uk>
Date: Thu Dec 16 16:25:43 2010 +0000
Cleanup of GTlsDatabase based on Dan Winship's comments.
* Rename build_chain_and_verify() to verify_chain()
* Modify the input chain to verify_chain
* Return verify result from verify_chain
* Add typedef GTlsDatabaseVerifyFlags
* GTlsDatabaseLookup -> GTlsDatabaseLookupType
* Use GTlsCertificate as chain instead of GList
https://bugzilla.gnome.org/show_bug.cgi?id=636572#c5
gio/gtlsdatabase.c | 218 ++++++++++++++++++++++++----------------------------
gio/gtlsdatabase.h | 124 +++++++++++++++---------------
2 files changed, 162 insertions(+), 180 deletions(-)
---
diff --git a/gio/gtlsdatabase.c b/gio/gtlsdatabase.c
index 410aa77..d61c7d4 100644
--- a/gio/gtlsdatabase.c
+++ b/gio/gtlsdatabase.c
@@ -38,112 +38,96 @@ g_tls_database_init (GTlsDatabase *cert)
}
-typedef struct _AsyncBuildChainAndVerify {
- GList *input;
+typedef struct _AsyncVerifyChain {
+ GTlsCertificate *chain;
GSocketConnectable *identity;
- gint flags;
- GList *chain;
+ GTlsDatabaseVerifyFlags flags;
GTlsCertificateFlags verify_result;
-} AsyncBuildChainAndVerify;
+} AsyncVerifyChain;
static void
-async_build_chain_and_verify_free (gpointer data)
+async_verify_chain_free (gpointer data)
{
- AsyncBuildChainAndVerify *args = data;
- GList *l;
-
+ AsyncVerifyChain *args = data;
+ g_object_unref (args->chain);
if (args->identity)
g_object_unref (args->identity);
- for (l = args->input; l; l = g_list_next (l))
- g_object_unref (l->data);
- g_list_free (args->input);
- for (l = args->chain; l; l = g_list_next (l))
- g_object_unref (l->data);
- g_list_free (args->chain);
- g_slice_free (AsyncBuildChainAndVerify, args);
+ g_slice_free (AsyncVerifyChain, args);
}
static void
-async_build_chain_and_verify_thread (GSimpleAsyncResult *res,
+async_verify_chain_thread (GSimpleAsyncResult *res,
GObject *object,
GCancellable *cancellable)
{
- AsyncBuildChainAndVerify *args = g_object_get_qdata (G_OBJECT (res), Q_ASYNC_DATA);
+ AsyncVerifyChain *args = g_object_get_qdata (G_OBJECT (res), Q_ASYNC_DATA);
GError *error = NULL;
- args->chain = g_tls_database_build_chain_and_verify (G_TLS_DATABASE (object),
- args->input,
- args->identity,
- args->flags,
- cancellable,
- &args->verify_result,
- &error);
+ args->verify_result = g_tls_database_verify_chain (G_TLS_DATABASE (object),
+ args->chain,
+ args->identity,
+ args->flags,
+ cancellable,
+ &error);
if (error)
g_simple_async_result_take_error (res, error);
}
static void
-g_tls_database_real_build_chain_and_verify_async (GTlsDatabase *self,
- GList *input,
- GSocketConnectable *identity,
- gint flags,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+g_tls_database_real_verify_chain_async (GTlsDatabase *self,
+ GTlsCertificate *chain,
+ GSocketConnectable *identity,
+ GTlsDatabaseVerifyFlags flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
GSimpleAsyncResult *res;
- AsyncBuildChainAndVerify *args;
- GList *l;
+ AsyncVerifyChain *args;
g_return_if_fail (callback);
+ g_return_if_fail (G_IS_TLS_CERTIFICATE (chain));
+ g_return_if_fail (!identity || G_IS_SOCKET_CONNECTABLE (identity));
- args = g_slice_new0 (AsyncBuildChainAndVerify);
- args->input = NULL;
- for (l = input; l; l = g_list_next (l))
- args->input = g_list_append (args->input, l->data);
- args->identity = g_object_ref (identity);
+ args = g_slice_new0 (AsyncVerifyChain);
+ args->chain = g_object_ref (chain);
+ args->identity = identity ? g_object_ref (identity) : NULL;
args->flags = flags;
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
- g_tls_database_real_build_chain_and_verify_async);
- g_object_set_qdata_full (G_OBJECT (res), Q_ASYNC_DATA, args, async_build_chain_and_verify_free);
- g_simple_async_result_run_in_thread (res, async_build_chain_and_verify_thread,
+ g_tls_database_real_verify_chain_async);
+ g_object_set_qdata_full (G_OBJECT (res), Q_ASYNC_DATA, args, async_verify_chain_free);
+ g_simple_async_result_run_in_thread (res, async_verify_chain_thread,
G_PRIORITY_DEFAULT, cancellable);
g_object_unref (res);
}
-static GList*
-g_tls_database_real_build_chain_and_verify_finish (GTlsDatabase *self,
- GAsyncResult *result,
- GTlsCertificateFlags *verify_result,
- GError **error)
+static GTlsCertificateFlags
+g_tls_database_real_verify_chain_finish (GTlsDatabase *self,
+ GAsyncResult *result,
+ GError **error)
{
- AsyncBuildChainAndVerify *args;
- GList *chain;
+ AsyncVerifyChain *args;
- 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 (verify_result, NULL);
- g_return_val_if_fail (!error || !*error, NULL);
+ g_return_val_if_fail (G_IS_TLS_DATABASE (self), G_TLS_CERTIFICATE_GENERIC_ERROR);
+ g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), G_TLS_CERTIFICATE_GENERIC_ERROR);
+ g_return_val_if_fail (!error || !*error, G_TLS_CERTIFICATE_GENERIC_ERROR);
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
- g_tls_database_real_build_chain_and_verify_async), FALSE);
+ g_tls_database_real_verify_chain_async), FALSE);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
- return NULL;
+ return G_TLS_CERTIFICATE_GENERIC_ERROR;
args = g_object_get_qdata (G_OBJECT (result), Q_ASYNC_DATA);
- *verify_result = args->verify_result;
- chain = args->chain;
- args->chain = NULL;
- return chain;
+ return args->verify_result;
}
typedef struct _AsyncLookupCertificates {
- GTlsDatabaseLookup lookup_type;
+ GTlsDatabaseLookupType lookup_type;
gpointer identifier;
- gsize n_identifier;
+ gsize identifier_length;
GList *results;
} AsyncLookupCertificates;
@@ -171,7 +155,7 @@ async_lookup_certificates_thread (GSimpleAsyncResult *res,
args->results = g_tls_database_lookup_certificates (G_TLS_DATABASE (object),
args->lookup_type,
args->identifier,
- args->n_identifier,
+ args->identifier_length,
cancellable,
&error);
@@ -181,9 +165,9 @@ async_lookup_certificates_thread (GSimpleAsyncResult *res,
static void
g_tls_database_real_lookup_certificates_async (GTlsDatabase *self,
- GTlsDatabaseLookup lookup_type,
+ GTlsDatabaseLookupType lookup_type,
gconstpointer identifier,
- gsize n_identifier,
+ gsize identifier_length,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -195,8 +179,8 @@ g_tls_database_real_lookup_certificates_async (GTlsDatabase *self,
args = g_slice_new0 (AsyncLookupCertificates);
args->lookup_type = lookup_type;
- args->identifier = g_memdup (identifier, n_identifier);
- args->n_identifier = n_identifier;
+ args->identifier = g_memdup (identifier, identifier_length);
+ args->identifier_length = identifier_length;
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
g_tls_database_real_lookup_certificates_async);
@@ -219,7 +203,7 @@ g_tls_database_real_lookup_certificates_finish (GTlsDatabase *self,
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_build_chain_and_verify_async), FALSE);
+ g_tls_database_real_verify_chain_async), FALSE);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
return NULL;
@@ -233,73 +217,71 @@ g_tls_database_real_lookup_certificates_finish (GTlsDatabase *self,
static void
g_tls_database_class_init (GTlsDatabaseClass *klass)
{
- klass->build_chain_and_verify_async = g_tls_database_real_build_chain_and_verify_async;
- klass->build_chain_and_verify_finish = g_tls_database_real_build_chain_and_verify_finish;
+ 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;
Q_ASYNC_DATA = g_quark_from_static_string ("GTlsDatabase::AsyncArgs");
}
-GList*
-g_tls_database_build_chain_and_verify (GTlsDatabase *self,
- GList *input,
- GSocketConnectable *identity,
- gint flags,
- GCancellable *cancellable,
- GTlsCertificateFlags *verify_result,
- GError **error)
+GTlsCertificateFlags
+g_tls_database_verify_chain (GTlsDatabase *self,
+ GTlsCertificate *chain,
+ GSocketConnectable *identity,
+ GTlsDatabaseVerifyFlags flags,
+ 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)->build_chain_and_verify, NULL);
- return G_TLS_DATABASE_GET_CLASS (self)->build_chain_and_verify (self,
- input,
- identity,
- flags,
- cancellable,
- verify_result,
- error);
+ g_return_val_if_fail (G_IS_TLS_DATABASE (self), G_TLS_CERTIFICATE_GENERIC_ERROR);
+ g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->verify_chain,
+ G_TLS_CERTIFICATE_GENERIC_ERROR);
+ return G_TLS_DATABASE_GET_CLASS (self)->verify_chain (self,
+ chain,
+ identity,
+ flags,
+ cancellable,
+ error);
}
void
-g_tls_database_build_chain_and_verify_async (GTlsDatabase *self,
- GList *input,
- GSocketConnectable *identity,
- gint flags,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+g_tls_database_verify_chain_async (GTlsDatabase *self,
+ GTlsCertificate *chain,
+ GSocketConnectable *identity,
+ GTlsDatabaseVerifyFlags flags,
+ 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)->build_chain_and_verify_async);
- G_TLS_DATABASE_GET_CLASS (self)->build_chain_and_verify_async (self,
- input,
- identity,
- flags,
- cancellable,
- callback,
- user_data);
+ g_return_if_fail (G_TLS_DATABASE_GET_CLASS (self)->verify_chain_async);
+ G_TLS_DATABASE_GET_CLASS (self)->verify_chain_async (self,
+ chain,
+ identity,
+ flags,
+ cancellable,
+ callback,
+ user_data);
}
-GList*
-g_tls_database_build_chain_and_verify_finish (GTlsDatabase *self,
- GAsyncResult *result,
- GTlsCertificateFlags *verify_result,
- GError **error)
+GTlsCertificateFlags
+g_tls_database_verify_chain_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)->build_chain_and_verify_finish, NULL);
- return G_TLS_DATABASE_GET_CLASS (self)->build_chain_and_verify_finish (self,
- result,
- verify_result,
- error);
+ g_return_val_if_fail (G_IS_TLS_DATABASE (self), G_TLS_CERTIFICATE_GENERIC_ERROR);
+ g_return_val_if_fail (G_TLS_DATABASE_GET_CLASS (self)->verify_chain_finish,
+ G_TLS_CERTIFICATE_GENERIC_ERROR);
+ return G_TLS_DATABASE_GET_CLASS (self)->verify_chain_finish (self,
+ result,
+ error);
}
GList*
g_tls_database_lookup_certificates (GTlsDatabase *self,
- GTlsDatabaseLookup lookup_type,
+ GTlsDatabaseLookupType lookup_type,
gconstpointer identifier,
- gsize n_identifier,
+ gsize identifier_length,
GCancellable *cancellable,
GError **error)
{
@@ -308,16 +290,16 @@ g_tls_database_lookup_certificates (GTlsDatabase *self,
return G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates (self,
lookup_type,
identifier,
- n_identifier,
+ identifier_length,
cancellable,
error);
}
void
g_tls_database_lookup_certificates_async (GTlsDatabase *self,
- GTlsDatabaseLookup lookup_type,
+ GTlsDatabaseLookupType lookup_type,
gconstpointer identifier,
- gsize n_identifier,
+ gsize identifier_length,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -327,7 +309,7 @@ g_tls_database_lookup_certificates_async (GTlsDatabase *self,
G_TLS_DATABASE_GET_CLASS (self)->lookup_certificates_async (self,
lookup_type,
identifier,
- n_identifier,
+ identifier_length,
cancellable,
callback,
user_data);
diff --git a/gio/gtlsdatabase.h b/gio/gtlsdatabase.h
index 6e478cd..1c41249 100644
--- a/gio/gtlsdatabase.h
+++ b/gio/gtlsdatabase.h
@@ -33,7 +33,11 @@ G_BEGIN_DECLS
typedef enum {
G_TLS_DATABASE_LOOKUP_ISSUER,
-} GTlsDatabaseLookup;
+} GTlsDatabaseLookupType;
+
+typedef enum {
+ G_TLS_DATABASE_VERIFY_NOFLAGS = 0,
+} GTlsDatabaseVerifyFlags;
#define G_TYPE_TLS_DATABASE (g_tls_certificate_get_type ())
#define G_TLS_DATABASE(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), G_TYPE_TLS_DATABASE, GTlsDatabase))
@@ -55,46 +59,44 @@ struct _GTlsDatabaseClass
{
GObjectClass parent_class;
- GList* (*build_chain_and_verify) (GTlsDatabase *self,
- GList *input,
- GSocketConnectable *identity,
- gint flags,
- GCancellable *cancellable,
- GTlsCertificateFlags *verify_result,
- GError **error);
-
- void (*build_chain_and_verify_async) (GTlsDatabase *self,
- GList *input,
- GSocketConnectable *identity,
- gint flags,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
- GList* (*build_chain_and_verify_finish) (GTlsDatabase *self,
- GAsyncResult *result,
- GTlsCertificateFlags *verify_result,
- GError **error);
-
- GList* (*lookup_certificates) (GTlsDatabase *self,
- GTlsDatabaseLookup lookup_type,
- gconstpointer identifier,
- gsize n_identifier,
- GCancellable *cancellable,
- GError **error);
-
- void (*lookup_certificates_async) (GTlsDatabase *self,
- GTlsDatabaseLookup lookup_type,
- gconstpointer identifier,
- gsize n_identifier,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
- GList* (*lookup_certificates_finish) (GTlsDatabase *self,
+ GTlsCertificateFlags (*verify_chain) (GTlsDatabase *self,
+ GTlsCertificate *chain,
+ GSocketConnectable *identity,
+ GTlsDatabaseVerifyFlags flags,
+ GCancellable *cancellable,
+ GError **error);
+
+ void (*verify_chain_async) (GTlsDatabase *self,
+ GTlsCertificate *chain,
+ GSocketConnectable *identity,
+ GTlsDatabaseVerifyFlags flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+ GTlsCertificateFlags (*verify_chain_finish) (GTlsDatabase *self,
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);
+
/*< private >*/
/* Padding for future expansion */
gpointer padding[16];
@@ -102,38 +104,36 @@ struct _GTlsDatabaseClass
GType g_tls_database_get_type (void) G_GNUC_CONST;
-GList* g_tls_database_build_chain_and_verify (GTlsDatabase *self,
- GList *input,
- GSocketConnectable *identity,
- gint flags,
- GCancellable *cancellable,
- GTlsCertificateFlags *verify_result,
- GError **error);
-
-void g_tls_database_build_chain_and_verify_async (GTlsDatabase *self,
- GList *input,
- GSocketConnectable *identity,
- gint flags,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-GList* g_tls_database_build_chain_and_verify_finish (GTlsDatabase *self,
- GAsyncResult *result,
- GTlsCertificateFlags *verify_result,
- GError **error);
+GTlsCertificateFlags g_tls_database_verify_chain (GTlsDatabase *self,
+ GTlsCertificate *chain,
+ GSocketConnectable *identity,
+ GTlsDatabaseVerifyFlags flags,
+ GCancellable *cancellable,
+ GError **error);
+
+void g_tls_database_verify_chain_async (GTlsDatabase *self,
+ GTlsCertificate *chain,
+ GSocketConnectable *identity,
+ GTlsDatabaseVerifyFlags flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+GTlsCertificateFlags g_tls_database_verify_chain_finish (GTlsDatabase *self,
+ GAsyncResult *result,
+ GError **error);
GList* g_tls_database_lookup_certificates (GTlsDatabase *self,
- GTlsDatabaseLookup lookup_type,
+ GTlsDatabaseLookupType lookup_type,
gconstpointer identifier,
- gsize n_identifier,
+ gsize identifier_length,
GCancellable *cancellable,
GError **error);
void g_tls_database_lookup_certificates_async (GTlsDatabase *self,
- GTlsDatabaseLookup lookup_type,
+ GTlsDatabaseLookupType lookup_type,
gconstpointer identifier,
- gsize n_identifier,
+ gsize identifier_length,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]