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 library is free software you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library; if not, see <http://www.gnu.org/licenses/>.
27 #include <glib/gi18n-lib.h>
29 #include "camel-internet-address.h"
30 #include "camel-sasl-anonymous.h"
32 static CamelServiceAuthType sasl_anonymous_auth_type = {
35 N_("This option will connect to the server using an anonymous login."),
41 G_DEFINE_TYPE (CamelSaslAnonymous, camel_sasl_anonymous, CAMEL_TYPE_SASL)
44 sasl_anonymous_finalize (GObject *object)
46 CamelSaslAnonymous *sasl = CAMEL_SASL_ANONYMOUS (object);
48 g_free (sasl->trace_info);
50 /* Chain up to parent's finalize() method. */
51 G_OBJECT_CLASS (camel_sasl_anonymous_parent_class)->finalize (object);
55 sasl_anonymous_challenge_sync (CamelSasl *sasl,
57 GCancellable *cancellable,
60 CamelSaslAnonymous *sasl_anon = CAMEL_SASL_ANONYMOUS (sasl);
61 CamelInternetAddress *cia;
62 GByteArray *ret = NULL;
66 error, CAMEL_SERVICE_ERROR,
67 CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
68 _("Authentication failed."));
72 switch (sasl_anon->type) {
73 case CAMEL_SASL_ANON_TRACE_EMAIL:
74 cia = camel_internet_address_new ();
75 if (camel_internet_address_add (cia, NULL, sasl_anon->trace_info) != 1) {
77 error, CAMEL_SERVICE_ERROR,
78 CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
79 _("Invalid email address trace information:\n%s"),
80 sasl_anon->trace_info);
85 ret = g_byte_array_new ();
86 g_byte_array_append (ret, (guint8 *) sasl_anon->trace_info, strlen (sasl_anon->trace_info));
88 case CAMEL_SASL_ANON_TRACE_OPAQUE:
89 if (strchr (sasl_anon->trace_info, '@')) {
91 error, CAMEL_SERVICE_ERROR,
92 CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
93 _("Invalid opaque trace information:\n%s"),
94 sasl_anon->trace_info);
97 ret = g_byte_array_new ();
98 g_byte_array_append (ret, (guint8 *) sasl_anon->trace_info, strlen (sasl_anon->trace_info));
100 case CAMEL_SASL_ANON_TRACE_EMPTY:
101 ret = g_byte_array_new ();
105 error, CAMEL_SERVICE_ERROR,
106 CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
107 _("Invalid trace information:\n%s"),
108 sasl_anon->trace_info);
112 camel_sasl_set_authenticated (sasl, TRUE);
117 camel_sasl_anonymous_class_init (CamelSaslAnonymousClass *class)
119 GObjectClass *object_class;
120 CamelSaslClass *sasl_class;
122 object_class = G_OBJECT_CLASS (class);
123 object_class->finalize = sasl_anonymous_finalize;
125 sasl_class = CAMEL_SASL_CLASS (class);
126 sasl_class->auth_type = &sasl_anonymous_auth_type;
127 sasl_class->challenge_sync = sasl_anonymous_challenge_sync;
131 camel_sasl_anonymous_init (CamelSaslAnonymous *sasl_anonymous)
136 * camel_sasl_anonymous_new:
138 * @trace_info: trace info
140 * Create a new #CamelSaslAnonymous object.
142 * Returns: a new #CamelSasl object
145 camel_sasl_anonymous_new (CamelSaslAnonTraceType type,
146 const gchar *trace_info)
148 CamelSaslAnonymous *sasl_anon;
150 if (!trace_info && type != CAMEL_SASL_ANON_TRACE_EMPTY)
153 sasl_anon = g_object_new (CAMEL_TYPE_SASL_ANONYMOUS, NULL);
154 sasl_anon->trace_info = g_strdup (trace_info);
155 sasl_anon->type = type;
157 return CAMEL_SASL (sasl_anon);