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-plain.h"
33 #include "camel-service.h"
35 CamelServiceAuthType camel_sasl_plain_authtype = {
38 N_("This option will connect to the server using a "
45 static CamelSaslClass *parent_class = NULL;
47 /* Returns the class for a CamelSaslPlain */
48 #define CSP_CLASS(so) CAMEL_SASL_PLAIN_CLASS (CAMEL_OBJECT_GET_CLASS (so))
50 static GByteArray *plain_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
53 camel_sasl_plain_class_init (CamelSaslPlainClass *camel_sasl_plain_class)
55 CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_plain_class);
57 parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
59 /* virtual method overload */
60 camel_sasl_class->challenge = plain_challenge;
64 camel_sasl_plain_get_type (void)
66 static CamelType type = CAMEL_INVALID_TYPE;
68 if (type == CAMEL_INVALID_TYPE) {
69 type = camel_type_register (camel_sasl_get_type (),
71 sizeof (CamelSaslPlain),
72 sizeof (CamelSaslPlainClass),
73 (CamelObjectClassInitFunc) camel_sasl_plain_class_init,
83 plain_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
85 GByteArray *buf = NULL;
86 CamelURL *url = sasl->service->url;
90 camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
91 _("Authentication failed."));
96 g_return_val_if_fail (url->passwd != NULL, NULL);
98 /* FIXME: make sure these are "UTF8-SAFE" */
99 buf = g_byte_array_new ();
100 g_byte_array_append (buf, "", 1);
101 g_byte_array_append (buf, url->user, strlen (url->user));
102 g_byte_array_append (buf, "", 1);
103 g_byte_array_append (buf, url->passwd, strlen (url->passwd));
105 sasl->authenticated = TRUE;