diff options
author | David Zeuthen <davidz@redhat.com> | 2011-05-19 17:33:07 -0400 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2011-05-19 17:33:07 -0400 |
commit | 7682546bc4f7a6a957d35695cb98fdc95d5722ad (patch) | |
tree | 8eba9eb662a799dd17bb705cce47c836a5b2fb99 | |
parent | fb771f93169beb07e31935d5e53725fe6e7a4f14 (diff) |
Add "generic" provider
This is to support non-branded accounts - for example, for my work
account, it looks like this
[Account my_rh_account]
Type=generic
Name=Red Hat Account
ImapHost=mail.corp.redhat.com
ImapUseTls=true
ImapIgnoreBadTls=true
ImapPassword=****
The main idea behind this is that the admin can drop a file in
/etc/goa-1.0/accounts.conf.d (e.g. install an RPM supplying that file)
that look like this
[Account rh_account]
Type=generic
Name=Red Hat Account
ImapHost=mail.corp.redhat.com
ImapUseTls=true
CalendarHost=...
and then things should just work out of the box.
This is not done yet; e.g.
- we need to read the password(s) from the keyring instead of
from the config file (or at least support that)
- do we need UI for this? or do we tell people to edit their
config file for this? We definitely need _some_ kind of UI to
set the password....
Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r-- | doc/goa-docs.xml | 2 | ||||
-rw-r--r-- | doc/goa-sections.txt | 21 | ||||
-rw-r--r-- | doc/goa.types | 2 | ||||
-rw-r--r-- | src/goabackend/Makefile.am | 4 | ||||
-rw-r--r-- | src/goabackend/goabackend.h | 2 | ||||
-rw-r--r-- | src/goabackend/goabackendtypes.h | 6 | ||||
-rw-r--r-- | src/goabackend/goagenericprovider.c | 189 | ||||
-rw-r--r-- | src/goabackend/goagenericprovider.h | 42 | ||||
-rw-r--r-- | src/goabackend/goagoogleprovider.c | 5 | ||||
-rw-r--r-- | src/goabackend/goaimapauthlogin.c | 326 | ||||
-rw-r--r-- | src/goabackend/goaimapauthlogin.h | 47 | ||||
-rw-r--r-- | src/goabackend/goaimapclient.c | 8 | ||||
-rw-r--r-- | src/goabackend/goaimapclient.h | 1 | ||||
-rw-r--r-- | src/goabackend/goaimapmail.c | 36 | ||||
-rw-r--r-- | src/goabackend/goaimapmail.h | 1 | ||||
-rw-r--r-- | src/goabackend/goaprovider.c | 20 |
16 files changed, 706 insertions, 6 deletions
diff --git a/doc/goa-docs.xml b/doc/goa-docs.xml index 3c89c8c..428ffe4 100644 --- a/doc/goa-docs.xml +++ b/doc/goa-docs.xml @@ -133,6 +133,7 @@ <title>Backend Library API Reference</title> <xi:include href="xml/goalog.xml"/> <xi:include href="xml/goaprovider.xml"/> + <xi:include href="xml/goagenericprovider.xml"/> <xi:include href="xml/goaoauthprovider.xml"/> <xi:include href="xml/goaoauth2provider.xml"/> <xi:include href="xml/goagoogleprovider.xml"/> @@ -140,6 +141,7 @@ <xi:include href="xml/goayahooprovider.xml"/> <xi:include href="xml/goatwitterprovider.xml"/> <xi:include href="xml/goaimapauth.xml"/> + <xi:include href="xml/goaimapauthlogin.xml"/> <xi:include href="xml/goaimapauthoauth.xml"/> <xi:include href="xml/goaimapclient.xml"/> <xi:include href="xml/goaimapmail.xml"/> diff --git a/doc/goa-sections.txt b/doc/goa-sections.txt index 09140dc..b329bb1 100644 --- a/doc/goa-sections.txt +++ b/doc/goa-sections.txt @@ -563,6 +563,16 @@ goa_oauth_provider_get_type </SECTION> <SECTION> +<FILE>goagenericprovider</FILE> +GoaGenericProvider +<SUBSECTION Standard> +GOA_GENERIC_PROVIDER +GOA_IS_GENERIC_PROVIDER +GOA_TYPE_GENERIC_PROVIDER +goa_generic_provider_get_type +</SECTION> + +<SECTION> <FILE>goagoogleprovider</FILE> GoaGoogleProvider <SUBSECTION Standard> @@ -752,6 +762,17 @@ goa_imap_auth_oauth_get_type </SECTION> <SECTION> +<FILE>goaimapauthlogin</FILE> +GoaImapAuthLogin +goa_imap_auth_login_new +<SUBSECTION Standard> +GOA_IMAP_AUTH_LOGIN +GOA_IS_IMAP_AUTH_LOGIN +GOA_TYPE_IMAP_AUTH_LOGIN +goa_imap_auth_login_get_type +</SECTION> + +<SECTION> <FILE>goalog</FILE> GoaLogLevel goa_log diff --git a/doc/goa.types b/doc/goa.types index 5a73646..1eb1531 100644 --- a/doc/goa.types +++ b/doc/goa.types @@ -31,6 +31,7 @@ goa_mail_monitor_proxy_get_type goa_mail_monitor_skeleton_get_type goa_provider_get_type +goa_generic_provider_get_type goa_oauth_provider_get_type goa_oauth2_provider_get_type goa_google_provider_get_type @@ -38,6 +39,7 @@ goa_facebook_provider_get_type goa_yahoo_provider_get_type goa_twitter_provider_get_type goa_imap_auth_get_type +goa_imap_auth_login_get_type goa_imap_auth_oauth_get_type goa_imap_client_get_type goa_imap_mail_get_type diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am index c32c67f..fdf832e 100644 --- a/src/goabackend/Makefile.am +++ b/src/goabackend/Makefile.am @@ -45,6 +45,7 @@ libgoa_backend_1_0_la_HEADERS = \ goabackendenumtypes.h \ goalogging.h \ goaprovider.h \ + goagenericprovider.h \ goaoauthprovider.h \ goaoauth2provider.h \ goagoogleprovider.h \ @@ -52,6 +53,7 @@ libgoa_backend_1_0_la_HEADERS = \ goayahooprovider.h \ goatwitterprovider.h \ goaimapauth.h \ + goaimapauthlogin.h \ goaimapauthoauth.h \ goaimapclient.h \ goaimapmail.h \ @@ -64,6 +66,7 @@ libgoa_backend_1_0_la_SOURCES = \ goabackendenumtypes.h goabackendenumtypes.c \ goaprovider.h goaprovider.c \ goalogging.h goalogging.c \ + goagenericprovider.h goagenericprovider.c \ goaoauthprovider.h goaoauthprovider.c \ goaoauth2provider.h goaoauth2provider.c \ goagoogleprovider.h goagoogleprovider.c \ @@ -71,6 +74,7 @@ libgoa_backend_1_0_la_SOURCES = \ goayahooprovider.h goayahooprovider.c \ goatwitterprovider.h goatwitterprovider.c \ goaimapauth.h goaimapauth.c \ + goaimapauthlogin.h goaimapauthlogin.c \ goaimapauthoauth.h goaimapauthoauth.c \ goaimapclient.h goaimapclient.c \ goaimapmail.h goaimapmail.c \ diff --git a/src/goabackend/goabackend.h b/src/goabackend/goabackend.h index 6e96c8f..909b6bf 100644 --- a/src/goabackend/goabackend.h +++ b/src/goabackend/goabackend.h @@ -31,6 +31,7 @@ #include <goabackend/goabackendtypes.h> #include <goabackend/goalogging.h> #include <goabackend/goaprovider.h> +#include <goabackend/goagenericprovider.h> #include <goabackend/goaoauthprovider.h> #include <goabackend/goaoauth2provider.h> #include <goabackend/goagoogleprovider.h> @@ -38,6 +39,7 @@ #include <goabackend/goayahooprovider.h> #include <goabackend/goatwitterprovider.h> #include <goabackend/goaimapauth.h> +#include <goabackend/goaimapauthlogin.h> #include <goabackend/goaimapauthoauth.h> #include <goabackend/goaimapclient.h> #include <goabackend/goaimapmail.h> diff --git a/src/goabackend/goabackendtypes.h b/src/goabackend/goabackendtypes.h index 2ffb784..65b20da 100644 --- a/src/goabackend/goabackendtypes.h +++ b/src/goabackend/goabackendtypes.h @@ -36,6 +36,9 @@ G_BEGIN_DECLS struct _GoaProvider; typedef struct _GoaProvider GoaProvider; +struct _GoaGenericProvider; +typedef struct _GoaGenericProvider GoaGenericProvider; + struct _GoaOAuthProvider; typedef struct _GoaOAuthProvider GoaOAuthProvider; @@ -57,6 +60,9 @@ typedef struct _GoaTwitterProvider GoaTwitterProvider; struct _GoaImapAuth; typedef struct _GoaImapAuth GoaImapAuth; +struct _GoaImapAuthLogin; +typedef struct _GoaImapAuthLogin GoaImapAuthLogin; + struct _GoaImapAuthOAuth; typedef struct _GoaImapAuthOAuth GoaImapAuthOAuth; diff --git a/src/goabackend/goagenericprovider.c b/src/goabackend/goagenericprovider.c new file mode 100644 index 0000000..f35256f --- /dev/null +++ b/src/goabackend/goagenericprovider.c @@ -0,0 +1,189 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright (C) 2011 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#include "config.h" +#include <glib/gi18n-lib.h> + +#include "goaprovider.h" +#include "goagenericprovider.h" +#include "goaimapauthlogin.h" + +#include "goaimapmail.h" + +/** + * GoaGenericProvider: + * + * The #GoaGenericProvider structure contains only private data and should + * only be accessed using the provided API. + */ +struct _GoaGenericProvider +{ + /*< private >*/ + GoaProvider parent_instance; +}; + +typedef struct _GoaGenericProviderClass GoaGenericProviderClass; + +struct _GoaGenericProviderClass +{ + GoaProviderClass parent_class; +}; + +/** + * SECTION:goagenericprovider + * @title: GoaGenericProvider + * @short_description: A provider for standards-based Internet services + * + * #GoaGenericProvider is used to access generic standards-based + * Internet services. + */ + +G_DEFINE_TYPE_WITH_CODE (GoaGenericProvider, goa_generic_provider, GOA_TYPE_PROVIDER, + g_io_extension_point_implement (GOA_PROVIDER_EXTENSION_POINT_NAME, + g_define_type_id, + "generic", + 0)); + +/* ---------------------------------------------------------------------------------------------------- */ + +static const gchar * +get_provider_type (GoaProvider *_provider) +{ + return "generic"; +} + +static const gchar * +get_name (GoaProvider *_provider) +{ + return _("Generic Account"); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static gboolean +build_object (GoaProvider *provider, + GoaObjectSkeleton *object, + GKeyFile *key_file, + const gchar *group, + GError **error) +{ + GoaAccount *account; + GoaMail *mail; + gboolean ret; + gchar *imap_host_and_port; + gboolean imap_use_tls; + gboolean imap_ignore_bad_tls; + gchar *imap_user_name; + gchar *imap_password; + + account = NULL; + mail = NULL; + imap_host_and_port = NULL; + imap_user_name = NULL; + imap_password = NULL; + ret = FALSE; + + /* Chain up */ + if (!GOA_PROVIDER_CLASS (goa_generic_provider_parent_class)->build_object (provider, + object, + key_file, + group, + error)) + goto out; + + account = goa_object_get_account (GOA_OBJECT (object)); + + /* mail */ + imap_host_and_port = g_key_file_get_string (key_file, group, "ImapHost", NULL); + imap_use_tls = g_key_file_get_boolean (key_file, group, "ImapUseTls", NULL); + imap_ignore_bad_tls = g_key_file_get_boolean (key_file, group, "ImapIgnoreBadTls", NULL); + imap_user_name = g_key_file_get_string (key_file, group, "ImapUserName", NULL); + imap_password = g_key_file_get_string (key_file, group, "ImapPassword", NULL); + /* TODO: want this from the keyring */ + mail = goa_object_get_mail (GOA_OBJECT (object)); + if (imap_host_and_port != NULL) + { + if (mail == NULL) + { + GoaImapAuth *auth; + if (imap_user_name == NULL) + imap_user_name = g_strdup (g_get_user_name ()); + auth = goa_imap_auth_login_new (provider, GOA_OBJECT (object), imap_user_name, imap_password); + mail = goa_imap_mail_new (imap_host_and_port, imap_use_tls, imap_ignore_bad_tls, auth); + goa_object_skeleton_set_mail (object, mail); + g_object_unref (auth); + } + } + else + { + if (mail != NULL) + goa_object_skeleton_set_mail (object, NULL); + } + + ret = TRUE; + + out: + if (mail != NULL) + g_object_unref (mail); + g_free (imap_host_and_port); + g_free (imap_user_name); + g_free (imap_password); + if (account != NULL) + g_object_unref (account); + return ret; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static gboolean +ensure_credentials_sync (GoaProvider *provider, + GoaObject *object, + gint *out_expires_in, + GCancellable *cancellable, + GError **error) +{ + /* TODO: we could try and log into the mail server etc. but for now we don't */ + if (out_expires_in != NULL) + *out_expires_in = 0; + return TRUE; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +goa_generic_provider_init (GoaGenericProvider *client) +{ +} + +static void +goa_generic_provider_class_init (GoaGenericProviderClass *klass) +{ + GoaProviderClass *provider_class; + + provider_class = GOA_PROVIDER_CLASS (klass); + provider_class->get_provider_type = get_provider_type; + provider_class->get_name = get_name; + provider_class->build_object = build_object; + provider_class->ensure_credentials_sync = ensure_credentials_sync; +} + +/* ---------------------------------------------------------------------------------------------------- */ diff --git a/src/goabackend/goagenericprovider.h b/src/goabackend/goagenericprovider.h new file mode 100644 index 0000000..77003a2 --- /dev/null +++ b/src/goabackend/goagenericprovider.h @@ -0,0 +1,42 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright (C) 2011 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#if !defined (__GOA_BACKEND_INSIDE_GOA_BACKEND_H__) && !defined (GOA_BACKEND_COMPILATION) +#error "Only <goabackend/goabackend.h> can be included directly." +#endif + +#ifndef __GOA_GENERIC_PROVIDER_H__ +#define __GOA_GENERIC_PROVIDER_H__ + +#include <goabackend/goabackendtypes.h> + +G_BEGIN_DECLS + +#define GOA_TYPE_GENERIC_PROVIDER (goa_generic_provider_get_type ()) +#define GOA_GENERIC_PROVIDER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOA_TYPE_GENERIC_PROVIDER, GoaGenericProvider)) +#define GOA_IS_GENERIC_PROVIDER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOA_TYPE_GENERIC_PROVIDER)) + +GType goa_generic_provider_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* __GOA_GENERIC_PROVIDER_H__ */ diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c index 8653eb8..6822d61 100644 --- a/src/goabackend/goagoogleprovider.c +++ b/src/goabackend/goagoogleprovider.c @@ -291,7 +291,10 @@ build_object (GoaProvider *provider, auth = goa_imap_auth_oauth_new (GOA_OAUTH_PROVIDER (provider), GOA_OBJECT (object), request_uri); - mail = goa_imap_mail_new ("imap.gmail.com", TRUE, auth); + mail = goa_imap_mail_new ("imap.gmail.com", + TRUE, /* use_tls */ + FALSE, /* ignore_bad_tls */ + auth); goa_object_skeleton_set_mail (object, mail); g_object_unref (auth); g_free (request_uri); diff --git a/src/goabackend/goaimapauthlogin.c b/src/goabackend/goaimapauthlogin.c new file mode 100644 index 0000000..016476d --- /dev/null +++ b/src/goabackend/goaimapauthlogin.c @@ -0,0 +1,326 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright (C) 2011 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#include "config.h" +#include <glib/gi18n-lib.h> +#include <stdlib.h> + +#include "goaprovider.h" +#include "goaimapauth.h" +#include "goaimapauthlogin.h" + +/** + * SECTION:goaimapauthlogin + * @title: GoaImapAuthLogin + * @short_description: LOGIN authentication method for IMAP + * + * #GoaImapAuthLogin implements the standard <ulink + * url="http://tools.ietf.org/html/rfc3501#section-6.2.3">LOGIN</ulink> + * authentication method (e.g. using usernames / passwords) for IMAP. + */ + +/** + * GoaImapAuthLogin: + * + * The #GoaImapAuthLogin structure contains only private data + * and should only be accessed using the provided API. + */ +struct _GoaImapAuthLogin +{ + GoaImapAuth parent_instance; + + GoaProvider *provider; + GoaObject *object; + gchar *user_name; + gchar *password; +}; + +typedef struct +{ + GoaImapAuthClass parent_class; + +} GoaImapAuthLoginClass; + +enum +{ + PROP_0, + PROP_PROVIDER, + PROP_OBJECT, + PROP_USER_NAME, + PROP_PASSWORD +}; + +static gboolean goa_imap_auth_login_run_sync (GoaImapAuth *_auth, + GDataInputStream *input, + GDataOutputStream *output, + GCancellable *cancellable, + GError **error); + +G_DEFINE_TYPE (GoaImapAuthLogin, goa_imap_auth_login, GOA_TYPE_IMAP_AUTH); + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +goa_imap_auth_login_finalize (GObject *object) +{ + GoaImapAuthLogin *auth = GOA_IMAP_AUTH_LOGIN (object); + + g_object_unref (auth->provider); + g_object_unref (auth->object); + g_free (auth->user_name); + g_free (auth->password); + + G_OBJECT_CLASS (goa_imap_auth_login_parent_class)->finalize (object); +} + +static void +goa_imap_auth_login_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GoaImapAuthLogin *auth = GOA_IMAP_AUTH_LOGIN (object); + + switch (prop_id) + { + case PROP_PROVIDER: + g_value_set_object (value, auth->provider); + break; + + case PROP_OBJECT: + g_value_set_object (value, auth->object); + break; + + case PROP_USER_NAME: + g_value_set_string (value, auth->user_name); + break; + + case PROP_PASSWORD: + g_value_set_string (value, auth->password); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +goa_imap_auth_login_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GoaImapAuthLogin *auth = GOA_IMAP_AUTH_LOGIN (object); + + switch (prop_id) + { + case PROP_PROVIDER: + auth->provider = g_value_dup_object (value); + break; + + case PROP_OBJECT: + auth->object = g_value_dup_object (value); + break; + + case PROP_USER_NAME: + auth->user_name = g_value_dup_string (value); + break; + + case PROP_PASSWORD: + auth->password = g_value_dup_string (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/* ---------------------------------------------------------------------------------------------------- */ + + +static void +goa_imap_auth_login_init (GoaImapAuthLogin *client) +{ +} + +static void +goa_imap_auth_login_class_init (GoaImapAuthLoginClass *klass) +{ + GObjectClass *gobject_class; + GoaImapAuthClass *auth_class; + + gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = goa_imap_auth_login_finalize; + gobject_class->get_property = goa_imap_auth_login_get_property; + gobject_class->set_property = goa_imap_auth_login_set_property; + + auth_class = GOA_IMAP_AUTH_CLASS (klass); + auth_class->run_sync = goa_imap_auth_login_run_sync; + + /** + * GoaImapAuthLogin:provider: + * + * The #GoaProvider object for the account. + */ + g_object_class_install_property (gobject_class, + PROP_PROVIDER, + g_param_spec_object ("provider", + "provider", + "provider", + GOA_TYPE_PROVIDER, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + /** + * GoaImapAuthLogin:object: + * + * The #GoaObject object for the account. + */ + g_object_class_install_property (gobject_class, + PROP_OBJECT, + g_param_spec_object ("object", + "object", + "object", + GOA_TYPE_OBJECT, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + /** + * GoaImapAuthLogin:user-name: + * + * The user name. + */ + g_object_class_install_property (gobject_class, + PROP_USER_NAME, + g_param_spec_string ("user-name", + "user-name", + "user-name", + NULL, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + /** + * GoaImapAuthLogin:password: + * + * The password (TODO: if %NULL, look up via the keyring). + */ + g_object_class_install_property (gobject_class, + PROP_PASSWORD, + g_param_spec_string ("password", + "password", + "password", + NULL, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +/** + * goa_imap_auth_login_new: + * @provider: A #GoaLoginProvider. + * @object: An account object. + * @user_name: The user name to use. + * @password: The password to use. + * + * Creates a new #GoaImapAuth to be used for username/password authentication. + * + * Returns: (type GoaImapAuthLogin): A #GoaImapAuthLogin. Free with g_object_unref(). + */ +GoaImapAuth * +goa_imap_auth_login_new (GoaProvider *provider, + GoaObject *object, + const gchar *user_name, + const gchar *password) +{ + g_return_val_if_fail (GOA_IS_PROVIDER (provider), NULL); + g_return_val_if_fail (GOA_IS_OBJECT (object), NULL); + g_return_val_if_fail (user_name != NULL, NULL); + return GOA_IMAP_AUTH (g_object_new (GOA_TYPE_IMAP_AUTH_LOGIN, + "provider", provider, + "object", object, + "user-name", user_name, + "password", password, + NULL)); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static gboolean +goa_imap_auth_login_run_sync (GoaImapAuth *_auth, + GDataInputStream *input, + GDataOutputStream *output, + GCancellable *cancellable, + GError **error) +{ + GoaImapAuthLogin *auth = GOA_IMAP_AUTH_LOGIN (_auth); + gchar *request; + gchar *response; + gboolean ret; + + request = NULL; + response = NULL; + ret = FALSE; + + /* TODO: support looking up the password from the keyring */ + + request = g_strdup_printf ("A001 LOGIN %s %s\r\n", auth->user_name, auth->password); + if (!g_data_output_stream_put_string (output, request, cancellable, error)) + goto out; + + again: + response = g_data_input_stream_read_line (input, NULL, cancellable, error); + if (response == NULL) + goto out; + /* ignore untagged responses */ + if (g_str_has_prefix (response, "*")) + { + g_free (response); + goto again; + } + if (!g_str_has_prefix (response, "A001 OK")) + { + g_set_error (error, + GOA_ERROR, + GOA_ERROR_FAILED, + "Unexpected response `%s' while doing LOGIN authentication", + response); + goto out; + } + + ret = TRUE; + + out: + g_free (response); + g_free (request); + return ret; +} diff --git a/src/goabackend/goaimapauthlogin.h b/src/goabackend/goaimapauthlogin.h new file mode 100644 index 0000000..5d2a1ba --- /dev/null +++ b/src/goabackend/goaimapauthlogin.h @@ -0,0 +1,47 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright (C) 2011 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#if !defined (__GOA_BACKEND_INSIDE_GOA_BACKEND_H__) && !defined (GOA_BACKEND_COMPILATION) +#error "Only <goabackend/goabackend.h> can be included directly." +#endif + +#ifndef __GOA_IMAP_AUTH_LOGIN_H__ +#define __GOA_IMAP_AUTH_LOGIN_H__ + +#include <goabackend/goabackendtypes.h> + +G_BEGIN_DECLS + +#define GOA_TYPE_IMAP_AUTH_LOGIN (goa_imap_auth_login_get_type ()) +#define GOA_IMAP_AUTH_LOGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOA_TYPE_IMAP_AUTH_LOGIN, GoaImapAuthLogin)) +#define GOA_IS_IMAP_AUTH_LOGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOA_TYPE_IMAP_AUTH_LOGIN)) + + +GType goa_imap_auth_login_get_type (void) G_GNUC_CONST; +GoaImapAuth *goa_imap_auth_login_new (GoaProvider *provider, + GoaObject *object, + const gchar *user_name, + const gchar *password); + +G_END_DECLS + +#endif /* __GOA_IMAP_AUTH_LOGIN_H__ */ diff --git a/src/goabackend/goaimapclient.c b/src/goabackend/goaimapclient.c index f57f9e3..4d413d0 100644 --- a/src/goabackend/goaimapclient.c +++ b/src/goabackend/goaimapclient.c @@ -175,6 +175,7 @@ goa_imap_client_new (void) * @client: A #GoaImapClient. * @host_and_port: The name and optionally port to connect to. * @use_tls: Whether TLS should be used. + * @ignore_bad_tls: Whether errors (e.g. %G_TLS_ERROR_BAD_CERTIFICATE) about TLS certificates should be ignored. * @auth: Object used for authenticating the connection. * @cancellable: (allow-none): A #GCancellable or %NULL. * @error: Return location for error or %NULL. @@ -190,6 +191,7 @@ gboolean goa_imap_client_connect_sync (GoaImapClient *client, const gchar *host_and_port, gboolean use_tls, + gboolean ignore_bad_tls, GoaImapAuth *auth, GCancellable *cancellable, GError **error) @@ -219,7 +221,11 @@ goa_imap_client_connect_sync (GoaImapClient *client, if (use_tls) g_socket_client_set_tls (client->sc, TRUE); - /* TODO: TLS validation etc etc */ + if (ignore_bad_tls) + { + /* TODO: is it correct to just pass 0? */ + g_socket_client_set_tls_validation_flags (client->sc, 0); + } client->c = g_socket_client_connect_to_host (client->sc, host_and_port, diff --git a/src/goabackend/goaimapclient.h b/src/goabackend/goaimapclient.h index 0a9f2ea..439c43d 100644 --- a/src/goabackend/goaimapclient.h +++ b/src/goabackend/goaimapclient.h @@ -40,6 +40,7 @@ GoaImapClient *goa_imap_client_new (void); gboolean goa_imap_client_connect_sync (GoaImapClient *client, const gchar *host_and_port, gboolean use_tls, + gboolean ignore_bad_tls, GoaImapAuth *auth, GCancellable *cancellable, GError **error); diff --git a/src/goabackend/goaimapmail.c b/src/goabackend/goaimapmail.c index eac25ce..e7f599d 100644 --- a/src/goabackend/goaimapmail.c +++ b/src/goabackend/goaimapmail.c @@ -46,6 +46,7 @@ struct _GoaImapMail gchar *host_and_port; gboolean use_tls; + gboolean ignore_bad_tls; GoaImapAuth *auth; }; @@ -61,6 +62,7 @@ enum PROP_0, PROP_HOST_AND_PORT, PROP_USE_TLS, + PROP_IGNORE_BAD_TLS, PROP_AUTH }; @@ -110,6 +112,10 @@ goa_imap_mail_get_property (GObject *object, g_value_set_boolean (value, mail->use_tls); break; + case PROP_IGNORE_BAD_TLS: + g_value_set_boolean (value, mail->ignore_bad_tls); + break; + case PROP_AUTH: g_value_set_object (value, mail->auth); break; @@ -138,6 +144,10 @@ goa_imap_mail_set_property (GObject *object, mail->use_tls = g_value_get_boolean (value); break; + case PROP_IGNORE_BAD_TLS: + mail->ignore_bad_tls = g_value_get_boolean (value); + break; + case PROP_AUTH: mail->auth = g_value_dup_object (value); break; @@ -189,6 +199,17 @@ goa_imap_mail_class_init (GoaImapMailClass *klass) G_PARAM_STATIC_STRINGS)); g_object_class_install_property (gobject_class, + PROP_IGNORE_BAD_TLS, + g_param_spec_boolean ("ignore-bad-tls", + "ignore-bad-tls", + "ignore-bad-tls", + TRUE, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (gobject_class, PROP_AUTH, g_param_spec_object ("auth", "auth", @@ -206,6 +227,7 @@ goa_imap_mail_class_init (GoaImapMailClass *klass) * goa_imap_mail_new: * @host_and_port: The name and optionally port to connect to. * @use_tls: Whether TLS should be used. + * @ignore_bad_tls: Whether errors (e.g. %G_TLS_ERROR_BAD_CERTIFICATE) about TLS certificates should be ignored. * @auth: Object used for authenticating the connection. * * Creates a new #GoaMail object. @@ -215,12 +237,14 @@ goa_imap_mail_class_init (GoaImapMailClass *klass) GoaMail * goa_imap_mail_new (const gchar *host_and_port, gboolean use_tls, + gboolean ignore_bad_tls, GoaImapAuth *auth) { g_return_val_if_fail (host_and_port != NULL, NULL); return GOA_MAIL (g_object_new (GOA_TYPE_IMAP_MAIL, "host-and-port", host_and_port, "use-tls", use_tls, + "ignore-bad-tls", ignore_bad_tls, "auth", auth, NULL)); } @@ -376,7 +400,7 @@ fetch_check (const gchar *data, ret = FALSE; key_len = strlen (key); - if (strncmp (data + *pos, key, key_len) == 0 && data[*pos + key_len] == ' ') + if (g_ascii_strncasecmp (data + *pos, key, key_len) == 0 && data[*pos + key_len] == ' ') { ret = TRUE; *pos += key_len + 1; @@ -683,7 +707,7 @@ imap_client_handle_fetch_response (ImapClientData *data, if (!parsed) { /* Use goa_warning() since we want bug-reports in order to improve the FETCH parser */ - goa_warning ("Was unable to parse FETCH response for message with sequence number %d and parameters `%s'. " + goa_warning ("Failed parsing FETCH response for message with sequence number %d and parameters `%s'. " "Please report this to %s", message_seqnum, params, @@ -844,6 +868,7 @@ imap_client_sync_single (ImapClientData *data) if (!goa_imap_client_connect_sync (client, data->monitor_data->mail->host_and_port, data->monitor_data->mail->use_tls, + data->monitor_data->mail->ignore_bad_tls, data->monitor_data->mail->auth, NULL, /* GCancellable */ &error)) @@ -1234,6 +1259,7 @@ typedef gboolean (*ImapHelperFunc) (GoaImapClient *client, static gboolean imap_helper (const gchar *host_and_port, gboolean use_tls, + gboolean ignore_bad_tls, GoaImapAuth *auth, guint uidvalidity, ImapHelperFunc func, @@ -1257,6 +1283,7 @@ imap_helper (const gchar *host_and_port, if (!goa_imap_client_connect_sync (client, host_and_port, use_tls, + ignore_bad_tls, auth, NULL, /* GCancellable */ error)) @@ -1366,6 +1393,7 @@ monitor_on_handle_add_star (GoaMailMonitor *monitor, data->starred_folder); imap_helper (data->mail->host_and_port, data->mail->use_tls, + data->mail->ignore_bad_tls, data->mail->auth, (message_uid >> 32), add_star_func, @@ -1442,15 +1470,15 @@ monitor_on_handle_mark_as_spam (GoaMailMonitor *monitor, goto out; } - requests = g_new0 (gchar*, 4); + requests = g_new0 (gchar*, 3); requests[0] = g_strdup_printf ("UID COPY %d %s", (gint) (message_uid & 0xffffffff), data->spam_folder); requests[1] = g_strdup_printf ("UID STORE %d +FLAGS (\\Deleted)", (gint) (message_uid & 0xffffffff)); - requests[2] = g_strdup_printf ("EXPUNGE"); imap_helper (data->mail->host_and_port, data->mail->use_tls, + data->mail->ignore_bad_tls, data->mail->auth, (message_uid >> 32), mark_as_spam_func, diff --git a/src/goabackend/goaimapmail.h b/src/goabackend/goaimapmail.h index 6f30fee..b8a5899 100644 --- a/src/goabackend/goaimapmail.h +++ b/src/goabackend/goaimapmail.h @@ -38,6 +38,7 @@ G_BEGIN_DECLS GType goa_imap_mail_get_type (void) G_GNUC_CONST; GoaMail *goa_imap_mail_new (const gchar *host_and_port, gboolean use_tls, + gboolean ignore_bad_tls, GoaImapAuth *auth); G_END_DECLS diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c index 7ec7741..e901829 100644 --- a/src/goabackend/goaprovider.c +++ b/src/goabackend/goaprovider.c @@ -29,6 +29,7 @@ #include "goafacebookprovider.h" #include "goayahooprovider.h" #include "goatwitterprovider.h" +#include "goagenericprovider.h" /** * SECTION:goaprovider @@ -44,6 +45,12 @@ static gboolean goa_provider_ensure_credentials_sync_real (GoaProvider *provid GCancellable *cancellable, GError **error); +static gboolean goa_provider_build_object_real (GoaProvider *provider, + GoaObjectSkeleton *object, + GKeyFile *key_file, + const gchar *group, + GError **error); + G_DEFINE_ABSTRACT_TYPE (GoaProvider, goa_provider, G_TYPE_OBJECT); static void @@ -54,6 +61,7 @@ goa_provider_init (GoaProvider *client) static void goa_provider_class_init (GoaProviderClass *klass) { + klass->build_object = goa_provider_build_object_real; klass->ensure_credentials_sync = goa_provider_ensure_credentials_sync_real; } @@ -413,6 +421,17 @@ goa_provider_ensure_credentials_sync_real (GoaProvider *provider, return FALSE; } +static gboolean +goa_provider_build_object_real (GoaProvider *provider, + GoaObjectSkeleton *object, + GKeyFile *key_file, + const gchar *group, + GError **error) +{ + /* does nothing */ + return TRUE; +} + /* ---------------------------------------------------------------------------------------------------- */ static void @@ -432,6 +451,7 @@ ensure_ep_and_builtins (void) type = GOA_TYPE_FACEBOOK_PROVIDER; type = GOA_TYPE_YAHOO_PROVIDER; type = GOA_TYPE_TWITTER_PROVIDER; + type = GOA_TYPE_GENERIC_PROVIDER; type = type; /* for -Wunused-but-set-variable */ g_once_init_leave (&once_init_value, 1); |