No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-authenticator.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-authenticator.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-authenticator.c
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
16 *
17 */
18
19 #include "e-mail-authenticator.h"
20
21 #include <config.h>
22 #include <glib/gi18n-lib.h>
23
24 #define E_MAIL_AUTHENTICATOR_GET_PRIVATE(obj) \
25 (G_TYPE_INSTANCE_GET_PRIVATE \
26 ((obj), E_TYPE_MAIL_AUTHENTICATOR, EMailAuthenticatorPrivate))
27
28 struct _EMailAuthenticatorPrivate {
29 CamelService *service;
30 gchar *mechanism;
31 };
32
33 enum {
34 PROP_0,
35 PROP_MECHANISM,
36 PROP_SERVICE
37 };
38
39 /* Forward Declarations */
40 static void e_mail_authenticator_interface_init
41 (ESourceAuthenticatorInterface *interface);
42
43 G_DEFINE_TYPE_WITH_CODE (
44 EMailAuthenticator,
45 e_mail_authenticator,
46 G_TYPE_OBJECT,
47 G_IMPLEMENT_INTERFACE (
48 E_TYPE_SOURCE_AUTHENTICATOR,
49 e_mail_authenticator_interface_init))
50
51 static void
52 mail_authenticator_set_mechanism (EMailAuthenticator *auth,
53 const gchar *mechanism)
54 {
55 g_return_if_fail (auth->priv->mechanism == NULL);
56
57 auth->priv->mechanism = g_strdup (mechanism);
58 }
59
60 static void
61 mail_authenticator_set_service (EMailAuthenticator *auth,
62 CamelService *service)
63 {
64 g_return_if_fail (CAMEL_IS_SERVICE (service));
65 g_return_if_fail (auth->priv->service == NULL);
66
67 auth->priv->service = g_object_ref (service);
68 }
69
70 static void
71 mail_authenticator_set_property (GObject *object,
72 guint property_id,
73 const GValue *value,
74 GParamSpec *pspec)
75 {
76 switch (property_id) {
77 case PROP_MECHANISM:
78 mail_authenticator_set_mechanism (
79 E_MAIL_AUTHENTICATOR (object),
80 g_value_get_string (value));
81 return;
82
83 case PROP_SERVICE:
84 mail_authenticator_set_service (
85 E_MAIL_AUTHENTICATOR (object),
86 g_value_get_object (value));
87 return;
88 }
89
90 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
91 }
92
93 static void
94 mail_authenticator_get_property (GObject *object,
95 guint property_id,
96 GValue *value,
97 GParamSpec *pspec)
98 {
99 switch (property_id) {
100 case PROP_MECHANISM:
101 g_value_set_string (
102 value,
103 e_mail_authenticator_get_mechanism (
104 E_MAIL_AUTHENTICATOR (object)));
105 return;
106
107 case PROP_SERVICE:
108 g_value_set_object (
109 value,
110 e_mail_authenticator_get_service (
111 E_MAIL_AUTHENTICATOR (object)));
112 return;
113 }
114
115 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
116 }
117
118 static void
119 mail_authenticator_dispose (GObject *object)
120 {
121 EMailAuthenticatorPrivate *priv;
122
123 priv = E_MAIL_AUTHENTICATOR_GET_PRIVATE (object);
124
125 if (priv->service != NULL) {
126 g_object_unref (priv->service);
127 priv->service = NULL;
128 }
129
130 /* Chain up to parent's dispose() method. */
131 G_OBJECT_CLASS (e_mail_authenticator_parent_class)->dispose (object);
132 }
133
134 static void
135 mail_authenticator_finalize (GObject *object)
136 {
137 EMailAuthenticatorPrivate *priv;
138
139 priv = E_MAIL_AUTHENTICATOR_GET_PRIVATE (object);
140
141 g_free (priv->mechanism);
142
143 /* Chain up to parent's finalize() method. */
144 G_OBJECT_CLASS (e_mail_authenticator_parent_class)->finalize (object);
145 }
146
147 static ESourceAuthenticationResult
148 mail_authenticator_try_password_sync (ESourceAuthenticator *auth,
149 const GString *password,
150 GCancellable *cancellable,
151 GError **error)
152 {
153 CamelService *service;
154 EMailAuthenticator *mail_auth;
155 CamelAuthenticationResult camel_result;
156 ESourceAuthenticationResult source_result;
157 const gchar *mechanism;
158
159 mail_auth = E_MAIL_AUTHENTICATOR (auth);
160 service = e_mail_authenticator_get_service (mail_auth);
161 mechanism = e_mail_authenticator_get_mechanism (mail_auth);
162
163 camel_service_set_password (service, password->str);
164
165 camel_result = camel_service_authenticate_sync (
166 service, mechanism, cancellable, error);
167
168 switch (camel_result) {
169 case CAMEL_AUTHENTICATION_ERROR:
170 source_result = E_SOURCE_AUTHENTICATION_ERROR;
171 break;
172 case CAMEL_AUTHENTICATION_ACCEPTED:
173 source_result = E_SOURCE_AUTHENTICATION_ACCEPTED;
174 break;
175 case CAMEL_AUTHENTICATION_REJECTED:
176 source_result = E_SOURCE_AUTHENTICATION_REJECTED;
177 break;
178 default:
179 g_set_error (
180 error, CAMEL_SERVICE_ERROR,
181 CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
182 _("Invalid authentication result code (%d)"),
183 camel_result);
184 source_result = E_SOURCE_AUTHENTICATION_ERROR;
185 break;
186 }
187
188 return source_result;
189 }
190
191 static void
192 e_mail_authenticator_class_init (EMailAuthenticatorClass *class)
193 {
194 GObjectClass *object_class;
195
196 g_type_class_add_private (class, sizeof (EMailAuthenticatorPrivate));
197
198 object_class = G_OBJECT_CLASS (class);
199 object_class->set_property = mail_authenticator_set_property;
200 object_class->get_property = mail_authenticator_get_property;
201 object_class->dispose = mail_authenticator_dispose;
202 object_class->finalize = mail_authenticator_finalize;
203
204 g_object_class_install_property (
205 object_class,
206 PROP_MECHANISM,
207 g_param_spec_string (
208 "mechanism",
209 "Mechanism",
210 "Authentication mechanism",
211 NULL,
212 G_PARAM_READWRITE |
213 G_PARAM_CONSTRUCT_ONLY |
214 G_PARAM_STATIC_STRINGS));
215
216 g_object_class_install_property (
217 object_class,
218 PROP_SERVICE,
219 g_param_spec_object (
220 "service",
221 "Service",
222 "The CamelService to authenticate",
223 CAMEL_TYPE_SERVICE,
224 G_PARAM_READWRITE |
225 G_PARAM_CONSTRUCT_ONLY |
226 G_PARAM_STATIC_STRINGS));
227 }
228
229 static void
230 e_mail_authenticator_interface_init (ESourceAuthenticatorInterface *interface)
231 {
232 interface->try_password_sync = mail_authenticator_try_password_sync;
233 }
234
235 static void
236 e_mail_authenticator_init (EMailAuthenticator *auth)
237 {
238 auth->priv = E_MAIL_AUTHENTICATOR_GET_PRIVATE (auth);
239 }
240
241 ESourceAuthenticator *
242 e_mail_authenticator_new (CamelService *service,
243 const gchar *mechanism)
244 {
245 g_return_val_if_fail (CAMEL_IS_SERVICE (service), NULL);
246
247 return g_object_new (
248 E_TYPE_MAIL_AUTHENTICATOR,
249 "service", service, "mechanism", mechanism, NULL);
250 }
251
252 CamelService *
253 e_mail_authenticator_get_service (EMailAuthenticator *auth)
254 {
255 g_return_val_if_fail (E_IS_MAIL_AUTHENTICATOR (auth), NULL);
256
257 return auth->priv->service;
258 }
259
260 const gchar *
261 e_mail_authenticator_get_mechanism (EMailAuthenticator *auth)
262 {
263 g_return_val_if_fail (E_IS_MAIL_AUTHENTICATOR (auth), NULL);
264
265 return auth->priv->mechanism;
266 }