1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright 2001 Ximian, Inc. (www.ximian.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.
30 #include <glib/gi18n-lib.h>
32 #include "camel-sasl-login.h"
33 #include "camel-service.h"
35 CamelServiceAuthType camel_sasl_login_authtype = {
38 N_("This option will connect to the server using a "
50 static CamelSaslClass *parent_class = NULL;
52 /* Returns the class for a CamelSaslLogin */
53 #define CSP_CLASS(so) CAMEL_SASL_LOGIN_CLASS (CAMEL_OBJECT_GET_CLASS (so))
55 static GByteArray *login_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
57 struct _CamelSaslLoginPrivate {
62 camel_sasl_login_class_init (CamelSaslLoginClass *camel_sasl_login_class)
64 CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_login_class);
66 parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
68 /* virtual method overload */
69 camel_sasl_class->challenge = login_challenge;
73 camel_sasl_login_init (gpointer object, gpointer klass)
75 CamelSaslLogin *sasl_login = CAMEL_SASL_LOGIN (object);
77 sasl_login->priv = g_new0 (struct _CamelSaslLoginPrivate, 1);
81 camel_sasl_login_finalize (CamelObject *object)
83 CamelSaslLogin *sasl = CAMEL_SASL_LOGIN (object);
90 camel_sasl_login_get_type (void)
92 static CamelType type = CAMEL_INVALID_TYPE;
94 if (type == CAMEL_INVALID_TYPE) {
95 type = camel_type_register (camel_sasl_get_type (),
97 sizeof (CamelSaslLogin),
98 sizeof (CamelSaslLoginClass),
99 (CamelObjectClassInitFunc) camel_sasl_login_class_init,
101 (CamelObjectInitFunc) camel_sasl_login_init,
102 (CamelObjectFinalizeFunc) camel_sasl_login_finalize);
109 login_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
111 struct _CamelSaslLoginPrivate *priv = CAMEL_SASL_LOGIN (sasl)->priv;
112 GByteArray *buf = NULL;
113 CamelURL *url = sasl->service->url;
115 g_return_val_if_fail (url->passwd != NULL, NULL);
117 /* Need to wait for the server */
121 switch (priv->state) {
123 buf = g_byte_array_new ();
124 g_byte_array_append (buf, url->user, strlen (url->user));
127 buf = g_byte_array_new ();
128 g_byte_array_append (buf, url->passwd, strlen (url->passwd));
130 sasl->authenticated = TRUE;
133 if (!camel_exception_is_set (ex)) {
134 camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
135 _("Unknown authentication state."));