I#27 - [IMAPx] Ignore DavMail's CR/LF in BODYSTRUCTURE response
[evolution-data-server.git] / src / libedataserverui / e-credentials-prompter-impl.c
blobe339bfc8bb001dfd21a5ecac618aa584ae9a706b
1 /*
2 * Copyright (C) 2015 Red Hat, Inc. (www.redhat.com)
4 * This library is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 * for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library. If not, see <http://www.gnu.org/licenses/>.
18 #include "evolution-data-server-config.h"
20 #include "e-credentials-prompter.h"
21 #include "e-credentials-prompter-impl.h"
23 struct _ECredentialsPrompterImplPrivate {
24 GCancellable *cancellable;
27 enum {
28 PROMPT_FINISHED,
29 LAST_SIGNAL
32 static guint signals[LAST_SIGNAL];
34 G_DEFINE_ABSTRACT_TYPE (ECredentialsPrompterImpl, e_credentials_prompter_impl, E_TYPE_EXTENSION)
36 static void
37 e_credentials_prompter_impl_constructed (GObject *object)
39 ECredentialsPrompterImpl *prompter_impl = E_CREDENTIALS_PROMPTER_IMPL (object);
40 ECredentialsPrompterImplClass *klass;
41 ECredentialsPrompter *prompter;
42 gint ii;
44 /* Chain up to parent's method. */
45 G_OBJECT_CLASS (e_credentials_prompter_impl_parent_class)->constructed (object);
47 prompter = E_CREDENTIALS_PROMPTER (e_extension_get_extensible (E_EXTENSION (prompter_impl)));
49 klass = E_CREDENTIALS_PROMPTER_IMPL_GET_CLASS (object);
50 g_return_if_fail (klass != NULL);
51 g_return_if_fail (klass->authentication_methods != NULL);
53 for (ii = 0; klass->authentication_methods[ii]; ii++) {
54 e_credentials_prompter_register_impl (prompter, klass->authentication_methods[ii], prompter_impl);
58 static void
59 e_credentials_prompter_impl_dispose (GObject *object)
61 ECredentialsPrompterImpl *prompter_impl = E_CREDENTIALS_PROMPTER_IMPL (object);
63 if (prompter_impl->priv->cancellable) {
64 g_cancellable_cancel (prompter_impl->priv->cancellable);
65 g_clear_object (&prompter_impl->priv->cancellable);
68 /* Chain up to parent's method. */
69 G_OBJECT_CLASS (e_credentials_prompter_impl_parent_class)->dispose (object);
72 static void
73 e_credentials_prompter_impl_class_init (ECredentialsPrompterImplClass *klass)
75 GObjectClass *object_class;
76 EExtensionClass *extension_class;
78 g_type_class_add_private (klass, sizeof (ECredentialsPrompterImplPrivate));
80 object_class = G_OBJECT_CLASS (klass);
81 object_class->dispose = e_credentials_prompter_impl_dispose;
82 object_class->constructed = e_credentials_prompter_impl_constructed;
84 extension_class = E_EXTENSION_CLASS (klass);
85 extension_class->extensible_type = E_TYPE_CREDENTIALS_PROMPTER;
87 /**
88 * ECredentialsPrompterImpl::prompt-finished:
89 * @prompter_impl: an #ECredentialsPrompterImpl which emitted the signal
90 * @prompt_id: an ID of the prompt which was finished
91 * @credentials: (allow-none): entered credentials, or %NULL for cancelled prompts
93 * Emitted when a prompt of ID @prompt_id is finished.
95 * Since: 3.16
96 **/
97 signals[PROMPT_FINISHED] = g_signal_new (
98 "prompt-finished",
99 G_OBJECT_CLASS_TYPE (object_class),
100 G_SIGNAL_RUN_LAST,
101 G_STRUCT_OFFSET (ECredentialsPrompterImplClass, prompt_finished),
102 NULL, NULL, NULL,
103 G_TYPE_NONE, 2, G_TYPE_POINTER, E_TYPE_NAMED_PARAMETERS);
106 static void
107 e_credentials_prompter_impl_init (ECredentialsPrompterImpl *prompter_impl)
109 prompter_impl->priv = G_TYPE_INSTANCE_GET_PRIVATE (prompter_impl,
110 E_TYPE_CREDENTIALS_PROMPTER_IMPL, ECredentialsPrompterImplPrivate);
112 prompter_impl->priv->cancellable = g_cancellable_new ();
116 * e_credentials_prompter_impl_get_credentials_prompter:
117 * @prompter_impl: an #ECredentialsPrompterImpl
119 * Returns an #ECredentialsPrompter with which the @prompter_impl is associated.
121 * Returns: (transfer none): an #ECredentialsPrompter
123 * Since: 3.16
125 ECredentialsPrompter *
126 e_credentials_prompter_impl_get_credentials_prompter (ECredentialsPrompterImpl *prompter_impl)
128 EExtensible *extensible;
130 g_return_val_if_fail (E_IS_CREDENTIALS_PROMPTER_IMPL (prompter_impl), NULL);
132 extensible = e_extension_get_extensible (E_EXTENSION (prompter_impl));
133 if (!extensible)
134 return NULL;
136 return E_CREDENTIALS_PROMPTER (extensible);
140 * e_credentials_prompter_impl_prompt:
141 * @prompter_impl: an #ECredentialsPrompterImpl
142 * @prompt_id: a prompt ID to be passed to e_credentials_prompter_impl_prompt_finish()
143 * @auth_source: an #ESource, to prompt the credentials for (the source which asked for credentials)
144 * @cred_source: a parent #ESource, from which credentials were taken, or should be stored to
145 * @error_text: (allow-none): an optional error text from the previous credentials prompt; can be %NULL
146 * @credentials: credentials, as saved in keyring; can be empty, but not %NULL
148 * Runs a credentials prompt for the @prompter_impl. The actual prompter implementation
149 * receives the prompt through ECredentialsPrompterImplClass::process_prompt(), where the given
150 * @prompt_id is used for an identification. The prompt is left 'active' as long as it is
151 * not finished with a call of e_credentials_prompter_impl_prompt_finish(). This should be
152 * called even for cancelled prompts. The prompt can be cancelled before it's processed,
153 * using the e_credentials_prompter_impl_cancel_prompt().
155 * The @auth_source can be the same as @cred_source, in case the credentials
156 * are stored only for that particular source. If the sources share credentials,
157 * which can be a case when the @auth_source is part of a collection, then
158 * the @cred_stource can be that collection source.
160 * Since: 3.16
162 void
163 e_credentials_prompter_impl_prompt (ECredentialsPrompterImpl *prompter_impl,
164 gpointer prompt_id,
165 ESource *auth_source,
166 ESource *cred_source,
167 const gchar *error_text,
168 const ENamedParameters *credentials)
170 ECredentialsPrompterImplClass *klass;
172 g_return_if_fail (E_IS_CREDENTIALS_PROMPTER_IMPL (prompter_impl));
173 g_return_if_fail (E_IS_SOURCE (auth_source));
174 g_return_if_fail (E_IS_SOURCE (cred_source));
175 g_return_if_fail (credentials != NULL);
177 klass = E_CREDENTIALS_PROMPTER_IMPL_GET_CLASS (prompter_impl);
178 g_return_if_fail (klass != NULL);
179 g_return_if_fail (klass->process_prompt != NULL);
181 klass->process_prompt (prompter_impl, prompt_id, auth_source, cred_source, error_text, credentials);
185 * e_credentials_prompter_impl_prompt_finish:
186 * @prompter_impl: an #ECredentialsPrompterImpl
187 * @prompt_id: a prompt ID
188 * @credentials: (allow-none): credentials to use; can be %NULL for cancelled prompts
190 * The actual credentials prompt implementation finishes a previously started
191 * credentials prompt @prompt_id with ECredentialsPrompterImplClass::process_prompt()
192 * by a call to this function. This function should be called regardless the prompt
193 * was or was not cancelled with e_credentials_prompter_impl_cancel_prompt().
194 * Once the prompt is finished another queued is started, if any pending exists.
195 * Use %NULL @credentials for cancelled prompts, otherwise the credentials are used
196 * for authentication of the associated #ESource.
198 * Since: 3.16
200 void
201 e_credentials_prompter_impl_prompt_finish (ECredentialsPrompterImpl *prompter_impl,
202 gpointer prompt_id,
203 const ENamedParameters *credentials)
205 g_return_if_fail (E_IS_CREDENTIALS_PROMPTER_IMPL (prompter_impl));
206 g_return_if_fail (prompt_id != NULL);
208 g_signal_emit (prompter_impl, signals[PROMPT_FINISHED], 0, prompt_id, credentials);
212 * e_credentials_prompter_impl_cancel_prompt:
213 * @prompter_impl: an #ECredentialsPrompterImpl
214 * @prompt_id: a prompt ID to cancel
216 * Asks the @prompt_impl to cancel current prompt, which should have ID @prompt_id.
218 * Since: 3.16
220 void
221 e_credentials_prompter_impl_cancel_prompt (ECredentialsPrompterImpl *prompter_impl,
222 gpointer prompt_id)
224 ECredentialsPrompterImplClass *klass;
226 g_return_if_fail (E_IS_CREDENTIALS_PROMPTER_IMPL (prompter_impl));
228 klass = E_CREDENTIALS_PROMPTER_IMPL_GET_CLASS (prompter_impl);
229 g_return_if_fail (klass != NULL);
230 g_return_if_fail (klass->cancel_prompt != NULL);
232 klass->cancel_prompt (prompter_impl, prompt_id);