[evolution-data-server] CamelSession: Simplify trust_prompt() signature.



commit 5930214b6a0a29d2950c05ff4a00a12cf5f75523
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Sep 27 07:56:52 2013 -0400

    CamelSession: Simplify trust_prompt() signature.
    
    Let the CamelSession subclass encode the certificate data if it needs to.
    That's an Evolution-specific implementation detail Camel doesn't need to
    know about.  The method signature is now:
    
      CamelCertTrust  (*trust_prompt)  (CamelSession *session,
                                        CamelService *service,
                                        GTlsCertificate *certificate,
                                        GTlsCertificateFlags errors);

 camel/camel-network-service.c |   17 +++------------
 camel/camel-session.c         |   44 +++++++++++++++++++++-------------------
 camel/camel-session.h         |   16 +++++---------
 3 files changed, 33 insertions(+), 44 deletions(-)
---
diff --git a/camel/camel-network-service.c b/camel/camel-network-service.c
index 0163449..fc80fb8 100644
--- a/camel/camel-network-service.c
+++ b/camel/camel-network-service.c
@@ -337,27 +337,18 @@ network_service_accept_certificate_cb (GTlsConnection *connection,
                new_cert = TRUE;
        }
 
-       if (cert->trust == CAMEL_CERT_TRUST_UNKNOWN) {
-               GByteArray *der;
-               gchar *base64;
-
-               /* XXX No accessor function for this property. */
-               g_object_get (peer_certificate, "certificate", &der, NULL);
-               g_return_val_if_fail (der != NULL, FALSE);
-
-               base64 = g_base64_encode (der->data, der->len);
+       g_free (host);
 
+       if (cert->trust == CAMEL_CERT_TRUST_UNKNOWN) {
                cert->trust = camel_session_trust_prompt (
-                       session, host, base64, errors, 0, NULL);
+                       session, CAMEL_SERVICE (service),
+                       peer_certificate, errors);
 
                if (new_cert)
                        network_service_certdb_store (
                                certdb, cert, peer_certificate);
 
                camel_certdb_touch (certdb);
-
-               g_free (base64);
-               g_byte_array_unref (der);
        }
 
        switch (cert->trust) {
diff --git a/camel/camel-session.c b/camel/camel-session.c
index 0ab9081..2bba415 100644
--- a/camel/camel-session.c
+++ b/camel/camel-session.c
@@ -1324,40 +1324,42 @@ camel_session_alert_user (CamelSession *session,
 /**
  * camel_session_trust_prompt:
  * @session: a #CamelSession
- * @host: host name, to which the @certificate belongs
- * @certificate: base64-encoded DER certificate on which to ask
- * @certificate_errors: errors found with the certificate; a bit-OR of a #GTlsCertificateFlags
- * @issuers: (allow-none): chain of issuers, or %NULL
- * @cancellable: (allow-non): optional #GCancellable object, or %NULL
+ * @service: a #CamelService
+ * @certificate: the peer's #GTlsCertificate
+ * @errors: the problems with @certificate
  *
- * Prompts user about trust of a certificate. The @certificate is not
- * considered trusted, due to reasons set in @certificate_errors.
- * There can be passed a list of @issuers, which has as items also base64-encoded
- * DER certificates. The first item in the list is an issuer of the @certificate,
- * the second item is an issuer of the first item, and so on.
+ * Prompts the user whether to accept @certificate for @service.  The
+ * set of flags given in @errors indicate why the @certificate failed
+ * validation.
  *
- * Returns: What trust level should be used for this certificate. It returns
- *   #CAMEL_CERT_TRUST_UNKNOWN on error or if user cancelled the dialog prompt.
+ * If an error occurs during prompting or if the user declines to respond,
+ * the function returns #CAMEL_CERT_TRUST_UNKNOWN and the certificate will
+ * be rejected.
+ *
+ * Returns: the user's trust level for @certificate
  *
  * Since: 3.8
  **/
 CamelCertTrust
 camel_session_trust_prompt (CamelSession *session,
-                            const gchar *host,
-                            const gchar *certificate,
-                            guint32 certificate_errors,
-                            GList *issuers,
-                            GCancellable *cancellable)
+                            CamelService *service,
+                            GTlsCertificate *certificate,
+                            GTlsCertificateFlags errors)
 {
        CamelSessionClass *class;
 
-       g_return_val_if_fail (CAMEL_IS_SESSION (session), CAMEL_CERT_TRUST_UNKNOWN);
-       g_return_val_if_fail (certificate != NULL, CAMEL_CERT_TRUST_UNKNOWN);
+       g_return_val_if_fail (
+               CAMEL_IS_SESSION (session), CAMEL_CERT_TRUST_UNKNOWN);
+       g_return_val_if_fail (
+               CAMEL_IS_SERVICE (service), CAMEL_CERT_TRUST_UNKNOWN);
+       g_return_val_if_fail (
+               G_IS_TLS_CERTIFICATE (certificate), CAMEL_CERT_TRUST_UNKNOWN);
 
        class = CAMEL_SESSION_GET_CLASS (session);
-       g_return_val_if_fail (class->trust_prompt != NULL, CAMEL_CERT_TRUST_UNKNOWN);
+       g_return_val_if_fail (
+               class->trust_prompt != NULL, CAMEL_CERT_TRUST_UNKNOWN);
 
-       return class->trust_prompt (session, host, certificate, certificate_errors, issuers, cancellable);
+       return class->trust_prompt (session, service, certificate, errors);
 }
 
 /**
diff --git a/camel/camel-session.h b/camel/camel-session.h
index 5925443..62172ba 100644
--- a/camel/camel-session.h
+++ b/camel/camel-session.h
@@ -119,11 +119,9 @@ struct _CamelSessionClass {
                                                 GList *button_captions,
                                                 GCancellable *cancellable);
        CamelCertTrust  (*trust_prompt)         (CamelSession *session,
-                                                const gchar *host,
-                                                const gchar *certificate,
-                                                guint32 certificate_errors,
-                                                GList *issuers,
-                                                GCancellable *cancellable);
+                                                CamelService *service,
+                                                GTlsCertificate *certificate,
+                                                GTlsCertificateFlags errors);
        CamelFilterDriver *
                        (*get_filter_driver)    (CamelSession *session,
                                                 const gchar *type,
@@ -219,11 +217,9 @@ gint               camel_session_alert_user        (CamelSession *session,
                                                 GList *button_captions,
                                                 GCancellable *cancellable);
 CamelCertTrust camel_session_trust_prompt      (CamelSession *session,
-                                                const gchar *host,
-                                                const gchar *certificate,
-                                                guint32 certificate_errors,
-                                                GList *issuers,
-                                                GCancellable *cancellable);
+                                                CamelService *service,
+                                                GTlsCertificate *certificate,
+                                                GTlsCertificateFlags errors);
 gchar *                camel_session_build_password_prompt
                                                (const gchar *type,
                                                 const gchar *user,


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