[gnome-online-accounts] mail-auth: Support servers that don't require authentication



commit f47d2b499f4741ffe305c1d15a58d6a6741c6726
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Mar 1 11:59:00 2013 +0100

    mail-auth: Support servers that don't require authentication
    
    Added a is_needed pure virtual method which GoaImapAuthLogin and
    GoaSmtpAuthPlain should implement to indicate whether the server
    requires authentication or not.
    
    Currently the GoaImapAuthLogin implementation is a dummy and assumes
    that authentication is always required.

 src/goabackend/goaimapauthlogin.c |   11 +++++++++++
 src/goabackend/goamailauth.c      |    9 +++++++++
 src/goabackend/goamailauth.h      |    2 ++
 src/goabackend/goasmtpauthplain.c |   18 ++++++++++++++----
 4 files changed, 36 insertions(+), 4 deletions(-)
---
diff --git a/src/goabackend/goaimapauthlogin.c b/src/goabackend/goaimapauthlogin.c
index ad46340..ec489c2 100644
--- a/src/goabackend/goaimapauthlogin.c
+++ b/src/goabackend/goaimapauthlogin.c
@@ -70,6 +70,7 @@ enum
   PROP_PASSWORD
 };
 
+static gboolean goa_imap_auth_login_is_needed (GoaMailAuth        *auth);
 static gboolean goa_imap_auth_login_run_sync (GoaMailAuth         *_auth,
                                               GDataInputStream    *input,
                                               GDataOutputStream   *output,
@@ -177,6 +178,7 @@ goa_imap_auth_login_class_init (GoaImapAuthLoginClass *klass)
   gobject_class->set_property = goa_imap_auth_login_set_property;
 
   auth_class = GOA_MAIL_AUTH_CLASS (klass);
+  auth_class->is_needed = goa_imap_auth_login_is_needed;
   auth_class->run_sync = goa_imap_auth_login_run_sync;
 
   /**
@@ -287,6 +289,15 @@ goa_imap_auth_login_new (GoaProvider       *provider,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static gboolean
+goa_imap_auth_login_is_needed (GoaMailAuth *_auth)
+{
+  /* TODO: support authentication-less IMAP servers */
+  return TRUE;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static gboolean
 goa_imap_auth_login_run_sync (GoaMailAuth         *_auth,
                               GDataInputStream    *input,
                               GDataOutputStream   *output,
diff --git a/src/goabackend/goamailauth.c b/src/goabackend/goamailauth.c
index 8c733c9..b7f0f90 100644
--- a/src/goabackend/goamailauth.c
+++ b/src/goabackend/goamailauth.c
@@ -115,6 +115,15 @@ goa_mail_auth_class_init (GoaMailAuthClass *klass)
 /* ---------------------------------------------------------------------------------------------------- */
 
 gboolean
+goa_mail_auth_is_needed (GoaMailAuth *auth)
+{
+  g_return_val_if_fail (GOA_IS_MAIL_AUTH (auth), FALSE);
+  return GOA_MAIL_AUTH_GET_CLASS (auth)->is_needed (auth);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+gboolean
 goa_mail_auth_run_sync (GoaMailAuth         *auth,
                         GDataInputStream    *input,
                         GDataOutputStream   *output,
diff --git a/src/goabackend/goamailauth.h b/src/goabackend/goamailauth.h
index 89df120..841e78e 100644
--- a/src/goabackend/goamailauth.h
+++ b/src/goabackend/goamailauth.h
@@ -55,6 +55,7 @@ struct _GoaMailAuth
 struct _GoaMailAuthClass
 {
   GObjectClass parent_class;
+  gboolean (*is_needed) (GoaMailAuth        *auth);
   gboolean (*run_sync) (GoaMailAuth         *auth,
                         GDataInputStream    *input,
                         GDataOutputStream   *output,
@@ -63,6 +64,7 @@ struct _GoaMailAuthClass
 };
 
 GType     goa_mail_auth_get_type     (void) G_GNUC_CONST;
+gboolean  goa_mail_auth_is_needed    (GoaMailAuth         *auth);
 void      goa_mail_auth_run          (GoaMailAuth         *auth,
                                       GDataInputStream    *input,
                                       GDataOutputStream   *output,
diff --git a/src/goabackend/goasmtpauthplain.c b/src/goabackend/goasmtpauthplain.c
index 5a97c80..a735008 100644
--- a/src/goabackend/goasmtpauthplain.c
+++ b/src/goabackend/goasmtpauthplain.c
@@ -53,6 +53,7 @@ struct _GoaSmtpAuthPlain
 
   GoaProvider *provider;
   GoaObject *object;
+  gboolean auth_supported;
   gchar *domain;
   gchar *username;
   gchar *password;
@@ -74,6 +75,7 @@ enum
   PROP_PASSWORD
 };
 
+static gboolean goa_smtp_auth_plain_is_needed (GoaMailAuth        *_auth);
 static gboolean goa_smtp_auth_plain_run_sync (GoaMailAuth         *_auth,
                                               GDataInputStream    *input,
                                               GDataOutputStream   *output,
@@ -190,6 +192,7 @@ goa_smtp_auth_plain_class_init (GoaSmtpAuthPlainClass *klass)
   gobject_class->set_property = goa_smtp_auth_plain_set_property;
 
   auth_class = GOA_MAIL_AUTH_CLASS (klass);
+  auth_class->is_needed = goa_smtp_auth_plain_is_needed;
   auth_class->run_sync = goa_smtp_auth_plain_run_sync;
 
   /**
@@ -323,6 +326,15 @@ goa_smtp_auth_plain_new (GoaProvider       *provider,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static gboolean
+goa_smtp_auth_plain_is_needed (GoaMailAuth *_auth)
+{
+  GoaSmtpAuthPlain *auth = GOA_SMTP_AUTH_PLAIN (_auth);
+  return auth->auth_supported;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static gboolean
 goa_smtp_auth_plain_run_sync (GoaMailAuth         *_auth,
                               GDataInputStream    *input,
                               GDataOutputStream   *output,
@@ -330,7 +342,6 @@ goa_smtp_auth_plain_run_sync (GoaMailAuth         *_auth,
                               GError             **error)
 {
   GoaSmtpAuthPlain *auth = GOA_SMTP_AUTH_PLAIN (_auth);
-  gboolean auth_supported;
   gboolean plain_supported;
   gboolean ret;
   gchar *auth_arg_base64;
@@ -341,7 +352,6 @@ goa_smtp_auth_plain_run_sync (GoaMailAuth         *_auth,
   gchar *response;
   gsize auth_arg_plain_len;
 
-  auth_supported = FALSE;
   plain_supported = FALSE;
   auth_arg_base64 = NULL;
   auth_arg_plain = NULL;
@@ -489,7 +499,7 @@ goa_smtp_auth_plain_run_sync (GoaMailAuth         *_auth,
 
   if (g_str_has_prefix (response + 4, "AUTH"))
     {
-      auth_supported = TRUE;
+      auth->auth_supported = TRUE;
       if (strstr (response, "PLAIN") != NULL)
         plain_supported = TRUE;
     }
@@ -499,7 +509,7 @@ goa_smtp_auth_plain_run_sync (GoaMailAuth         *_auth,
       g_free (response);
       goto ehlo_again;
     }
-  else if (!auth_supported)
+  else if (!auth->auth_supported)
     {
       ret = TRUE;
       goto out;


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