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-internet-address.h"
32 #include "camel-sasl-anonymous.h"
34 static CamelServiceAuthType sasl_anonymous_auth_type = {
37 N_("This option will connect to the server using an anonymous login."),
43 G_DEFINE_TYPE (CamelSaslAnonymous, camel_sasl_anonymous, CAMEL_TYPE_SASL)
46 sasl_anonymous_finalize (GObject *object)
48 CamelSaslAnonymous *sasl = CAMEL_SASL_ANONYMOUS (object);
50 g_free (sasl->trace_info);
52 /* Chain up to parent's finalize() method. */
53 G_OBJECT_CLASS (camel_sasl_anonymous_parent_class)->finalize (object);
57 sasl_anonymous_challenge_sync (CamelSasl *sasl,
59 GCancellable *cancellable,
62 CamelSaslAnonymous *sasl_anon = CAMEL_SASL_ANONYMOUS (sasl);
63 CamelInternetAddress *cia;
64 GByteArray *ret = NULL;
68 error, CAMEL_SERVICE_ERROR,
69 CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
70 _("Authentication failed."));
74 switch (sasl_anon->type) {
75 case CAMEL_SASL_ANON_TRACE_EMAIL:
76 cia = camel_internet_address_new ();
77 if (camel_internet_address_add (cia, NULL, sasl_anon->trace_info) != 1) {
79 error, CAMEL_SERVICE_ERROR,
80 CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
81 _("Invalid email address trace information:\n%s"),
82 sasl_anon->trace_info);
87 ret = g_byte_array_new ();
88 g_byte_array_append (ret, (guint8 *) sasl_anon->trace_info, strlen (sasl_anon->trace_info));
90 case CAMEL_SASL_ANON_TRACE_OPAQUE:
91 if (strchr (sasl_anon->trace_info, '@')) {
93 error, CAMEL_SERVICE_ERROR,
94 CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
95 _("Invalid opaque trace information:\n%s"),
96 sasl_anon->trace_info);
99 ret = g_byte_array_new ();
100 g_byte_array_append (ret, (guint8 *) sasl_anon->trace_info, strlen (sasl_anon->trace_info));
102 case CAMEL_SASL_ANON_TRACE_EMPTY:
103 ret = g_byte_array_new ();
107 error, CAMEL_SERVICE_ERROR,
108 CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
109 _("Invalid trace information:\n%s"),
110 sasl_anon->trace_info);
114 camel_sasl_set_authenticated (sasl, TRUE);
119 camel_sasl_anonymous_class_init (CamelSaslAnonymousClass *class)
121 GObjectClass *object_class;
122 CamelSaslClass *sasl_class;
124 object_class = G_OBJECT_CLASS (class);
125 object_class->finalize = sasl_anonymous_finalize;
127 sasl_class = CAMEL_SASL_CLASS (class);
128 sasl_class->auth_type = &sasl_anonymous_auth_type;
129 sasl_class->challenge_sync = sasl_anonymous_challenge_sync;
133 camel_sasl_anonymous_init (CamelSaslAnonymous *sasl_anonymous)
138 * camel_sasl_anonymous_new:
140 * @trace_info: trace info
142 * Create a new #CamelSaslAnonymous object.
144 * Returns: a new #CamelSasl object
147 camel_sasl_anonymous_new (CamelSaslAnonTraceType type,
148 const gchar *trace_info)
150 CamelSaslAnonymous *sasl_anon;
152 if (!trace_info && type != CAMEL_SASL_ANON_TRACE_EMPTY)
155 sasl_anon = g_object_new (CAMEL_TYPE_SASL_ANONYMOUS, NULL);
156 sasl_anon->trace_info = g_strdup (trace_info);
157 sasl_anon->type = type;
159 return CAMEL_SASL (sasl_anon);