1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of version 2 of the GNU Lesser General Public
9 * License as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
29 #include <glib/gi18n-lib.h>
31 #include "camel-network-settings.h"
32 #include "camel-sasl-login.h"
33 #include "camel-service.h"
35 #define CAMEL_SASL_LOGIN_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE \
37 ((obj), CAMEL_TYPE_SASL_LOGIN, CamelSaslLoginPrivate))
39 static CamelServiceAuthType sasl_login_auth_type = {
42 N_("This option will connect to the server using a "
54 struct _CamelSaslLoginPrivate {
58 G_DEFINE_TYPE (CamelSaslLogin, camel_sasl_login, CAMEL_TYPE_SASL)
61 sasl_login_challenge_sync (CamelSasl *sasl,
63 GCancellable *cancellable,
66 CamelSaslLoginPrivate *priv;
67 CamelNetworkSettings *network_settings;
68 CamelSettings *settings;
69 CamelService *service;
70 GByteArray *buf = NULL;
71 const gchar *password;
74 /* Need to wait for the server */
78 priv = CAMEL_SASL_LOGIN_GET_PRIVATE (sasl);
80 service = camel_sasl_get_service (sasl);
82 settings = camel_service_ref_settings (service);
83 g_return_val_if_fail (CAMEL_IS_NETWORK_SETTINGS (settings), NULL);
85 network_settings = CAMEL_NETWORK_SETTINGS (settings);
86 user = camel_network_settings_dup_user (network_settings);
88 g_object_unref (settings);
90 g_return_val_if_fail (user != NULL, NULL);
92 password = camel_service_get_password (service);
93 g_return_val_if_fail (password != NULL, NULL);
95 switch (priv->state) {
97 buf = g_byte_array_new ();
98 g_byte_array_append (buf, (guint8 *) user, strlen (user));
101 buf = g_byte_array_new ();
102 g_byte_array_append (buf, (guint8 *) password, strlen (password));
104 camel_sasl_set_authenticated (sasl, TRUE);
108 error, CAMEL_SERVICE_ERROR,
109 CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
110 _("Unknown authentication state."));
121 camel_sasl_login_class_init (CamelSaslLoginClass *class)
123 CamelSaslClass *sasl_class;
125 g_type_class_add_private (class, sizeof (CamelSaslLoginPrivate));
127 sasl_class = CAMEL_SASL_CLASS (class);
128 sasl_class->auth_type = &sasl_login_auth_type;
129 sasl_class->challenge_sync = sasl_login_challenge_sync;
133 camel_sasl_login_init (CamelSaslLogin *sasl)
135 sasl->priv = CAMEL_SASL_LOGIN_GET_PRIVATE (sasl);