Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / camel-sasl-plain.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  *  Authors: Jeffrey Stedfast <fejj@ximian.com>
4  *
5  *  Copyright 2001 Ximian, Inc. (www.ximian.com)
6  *
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.
10  *
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.
15  *
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.
20  *
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <string.h>
28
29 #include <glib.h>
30 #include <glib/gi18n-lib.h>
31
32 #include "camel-sasl-plain.h"
33 #include "camel-service.h"
34
35 CamelServiceAuthType camel_sasl_plain_authtype = {
36         N_("PLAIN"),
37
38         N_("This option will connect to the server using a "
39            "simple password."),
40
41         "PLAIN",
42         TRUE
43 };
44
45 static CamelSaslClass *parent_class = NULL;
46
47 /* Returns the class for a CamelSaslPlain */
48 #define CSP_CLASS(so) CAMEL_SASL_PLAIN_CLASS (CAMEL_OBJECT_GET_CLASS (so))
49
50 static GByteArray *plain_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
51
52 static void
53 camel_sasl_plain_class_init (CamelSaslPlainClass *camel_sasl_plain_class)
54 {
55         CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_plain_class);
56         
57         parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
58         
59         /* virtual method overload */
60         camel_sasl_class->challenge = plain_challenge;
61 }
62
63 CamelType
64 camel_sasl_plain_get_type (void)
65 {
66         static CamelType type = CAMEL_INVALID_TYPE;
67         
68         if (type == CAMEL_INVALID_TYPE) {
69                 type = camel_type_register (camel_sasl_get_type (),
70                                             "CamelSaslPlain",
71                                             sizeof (CamelSaslPlain),
72                                             sizeof (CamelSaslPlainClass),
73                                             (CamelObjectClassInitFunc) camel_sasl_plain_class_init,
74                                             NULL,
75                                             NULL,
76                                             NULL);
77         }
78         
79         return type;
80 }
81
82 static GByteArray *
83 plain_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
84 {
85         GByteArray *buf = NULL;
86         CamelURL *url = sasl->service->url;
87
88 #if 0
89         if (token) {
90                 camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
91                                      _("Authentication failed."));
92                 return NULL;
93         }
94 #endif
95         
96         g_return_val_if_fail (url->passwd != NULL, NULL);
97         
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));
104         
105         sasl->authenticated = TRUE;
106         
107         return buf;
108 }