[glib/tls-database] Better precondition checks in GTlsDatabase methods.



commit bc0bb77971f83fbba27b5279760a879f7ecb26a2
Author: Stef Walter <stefw collabora co uk>
Date:   Tue Dec 28 10:52:29 2010 -0600

    Better precondition checks in GTlsDatabase methods.

 gio/gtlsdatabase.c |   38 +++++++++++++++++++++++++++-----------
 1 files changed, 27 insertions(+), 11 deletions(-)
---
diff --git a/gio/gtlsdatabase.c b/gio/gtlsdatabase.c
index ec373e9..deb5309 100644
--- a/gio/gtlsdatabase.c
+++ b/gio/gtlsdatabase.c
@@ -24,6 +24,8 @@
 
 #include "gtlsdatabase.h"
 
+#include "gasyncresult.h"
+#include "gcancellable.h"
 #include "gsimpleasyncresult.h"
 #include "gsocketconnectable.h"
 #include "gtlscertificate.h"
@@ -126,11 +128,6 @@ g_tls_database_real_verify_chain_async (GTlsDatabase           *self,
   GSimpleAsyncResult *res;
   AsyncVerifyChain *args;
 
-  g_return_if_fail (callback);
-  g_return_if_fail (G_IS_TLS_CERTIFICATE (chain));
-  g_return_if_fail (purpose);
-  g_return_if_fail (!identity || G_IS_SOCKET_CONNECTABLE (identity));
-
   args = g_slice_new0 (AsyncVerifyChain);
   args->chain = g_object_ref (chain);
   args->purpose = g_strdup (purpose);
@@ -152,10 +149,7 @@ g_tls_database_real_verify_chain_finish (GTlsDatabase          *self,
 {
   AsyncVerifyChain *args;
 
-  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_verify_chain_async), FALSE);
 
@@ -231,10 +225,7 @@ g_tls_database_real_lookup_issuer_finish (GTlsDatabase          *self,
   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_lookup_issuer_async), FALSE);
 
@@ -306,6 +297,15 @@ g_tls_database_verify_chain (GTlsDatabase           *self,
                              GError                **error)
 {
   g_return_val_if_fail (G_IS_TLS_DATABASE (self), G_TLS_CERTIFICATE_GENERIC_ERROR);
+  g_return_val_if_fail (G_IS_TLS_DATABASE (self),
+                        G_TLS_CERTIFICATE_GENERIC_ERROR);
+  g_return_val_if_fail (G_IS_TLS_CERTIFICATE (chain),
+                        G_TLS_CERTIFICATE_GENERIC_ERROR);
+  g_return_val_if_fail (purpose, G_TLS_CERTIFICATE_GENERIC_ERROR);
+  g_return_val_if_fail (!identity || G_IS_SOCKET_CONNECTABLE (identity),
+                        G_TLS_CERTIFICATE_GENERIC_ERROR);
+  g_return_val_if_fail (!error || !*error, 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,
@@ -346,6 +346,12 @@ g_tls_database_verify_chain_async (GTlsDatabase           *self,
                                    gpointer                user_data)
 {
   g_return_if_fail (G_IS_TLS_DATABASE (self));
+  g_return_if_fail (G_IS_TLS_CERTIFICATE (chain));
+  g_return_if_fail (purpose);
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+  g_return_if_fail (!identity || G_IS_SOCKET_CONNECTABLE (identity));
+  g_return_if_fail (callback);
+
   g_return_if_fail (G_TLS_DATABASE_GET_CLASS (self)->verify_chain_async);
   G_TLS_DATABASE_GET_CLASS (self)->verify_chain_async (self,
                                                        chain,
@@ -376,6 +382,8 @@ g_tls_database_verify_chain_finish (GTlsDatabase          *self,
                                     GError               **error)
 {
   g_return_val_if_fail (G_IS_TLS_DATABASE (self), G_TLS_CERTIFICATE_GENERIC_ERROR);
+  g_return_val_if_fail (G_IS_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_TLS_DATABASE_GET_CLASS (self)->verify_chain_finish,
                         G_TLS_CERTIFICATE_GENERIC_ERROR);
   return G_TLS_DATABASE_GET_CLASS (self)->verify_chain_finish (self,
@@ -411,6 +419,9 @@ g_tls_database_lookup_issuer (GTlsDatabase          *self,
                               GError               **error)
 {
   g_return_val_if_fail (G_IS_TLS_DATABASE (self), NULL);
+  g_return_val_if_fail (G_IS_TLS_CERTIFICATE (certificate), NULL);
+  g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
+  g_return_val_if_fail (!error || !*error, NULL);
   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,
@@ -439,6 +450,9 @@ g_tls_database_lookup_issuer_async (GTlsDatabase          *self,
                                     gpointer               user_data)
 {
   g_return_if_fail (G_IS_TLS_DATABASE (self));
+  g_return_if_fail (G_IS_TLS_CERTIFICATE (certificate));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+  g_return_if_fail (callback);
   g_return_if_fail (G_TLS_DATABASE_GET_CLASS (self)->lookup_issuer_async);
   G_TLS_DATABASE_GET_CLASS (self)->lookup_issuer_async (self,
                                                         certificate,
@@ -467,6 +481,8 @@ g_tls_database_lookup_issuer_finish (GTlsDatabase          *self,
                                      GError               **error)
 {
   g_return_val_if_fail (G_IS_TLS_DATABASE (self), NULL);
+  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
+  g_return_val_if_fail (!error || !*error, NULL);
   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,



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