1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gio.TlsInteraction;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.TlsConnection;
30 private import gio.TlsPassword;
31 private import gio.c.functions;
32 public  import gio.c.types;
33 private import glib.ErrorG;
34 private import glib.GException;
35 private import gobject.ObjectG;
36 public  import gtkc.giotypes;
37 
38 
39 /**
40  * #GTlsInteraction provides a mechanism for the TLS connection and database
41  * code to interact with the user. It can be used to ask the user for passwords.
42  * 
43  * To use a #GTlsInteraction with a TLS connection use
44  * g_tls_connection_set_interaction().
45  * 
46  * Callers should instantiate a derived class that implements the various
47  * interaction methods to show the required dialogs.
48  * 
49  * Callers should use the 'invoke' functions like
50  * g_tls_interaction_invoke_ask_password() to run interaction methods. These
51  * functions make sure that the interaction is invoked in the main loop
52  * and not in the current thread, if the current thread is not running the
53  * main loop.
54  * 
55  * Derived classes can choose to implement whichever interactions methods they'd
56  * like to support by overriding those virtual methods in their class
57  * initialization function. Any interactions not implemented will return
58  * %G_TLS_INTERACTION_UNHANDLED. If a derived class implements an async method,
59  * it must also implement the corresponding finish method.
60  *
61  * Since: 2.30
62  */
63 public class TlsInteraction : ObjectG
64 {
65 	/** the main Gtk struct */
66 	protected GTlsInteraction* gTlsInteraction;
67 
68 	/** Get the main Gtk struct */
69 	public GTlsInteraction* getTlsInteractionStruct(bool transferOwnership = false)
70 	{
71 		if (transferOwnership)
72 			ownedRef = false;
73 		return gTlsInteraction;
74 	}
75 
76 	/** the main Gtk struct as a void* */
77 	protected override void* getStruct()
78 	{
79 		return cast(void*)gTlsInteraction;
80 	}
81 
82 	/**
83 	 * Sets our main struct and passes it to the parent class.
84 	 */
85 	public this (GTlsInteraction* gTlsInteraction, bool ownedRef = false)
86 	{
87 		this.gTlsInteraction = gTlsInteraction;
88 		super(cast(GObject*)gTlsInteraction, ownedRef);
89 	}
90 
91 
92 	/** */
93 	public static GType getType()
94 	{
95 		return g_tls_interaction_get_type();
96 	}
97 
98 	/**
99 	 * Run synchronous interaction to ask the user for a password. In general,
100 	 * g_tls_interaction_invoke_ask_password() should be used instead of this
101 	 * function.
102 	 *
103 	 * Derived subclasses usually implement a password prompt, although they may
104 	 * also choose to provide a password from elsewhere. The @password value will
105 	 * be filled in and then @callback will be called. Alternatively the user may
106 	 * abort this password request, which will usually abort the TLS connection.
107 	 *
108 	 * If the interaction is cancelled by the cancellation object, or by the
109 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
110 	 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may
111 	 * not support immediate cancellation.
112 	 *
113 	 * Params:
114 	 *     password = a #GTlsPassword object
115 	 *     cancellable = an optional #GCancellable cancellation object
116 	 *
117 	 * Returns: The status of the ask password interaction.
118 	 *
119 	 * Since: 2.30
120 	 *
121 	 * Throws: GException on failure.
122 	 */
123 	public GTlsInteractionResult askPassword(TlsPassword password, Cancellable cancellable)
124 	{
125 		GError* err = null;
126 
127 		auto p = g_tls_interaction_ask_password(gTlsInteraction, (password is null) ? null : password.getTlsPasswordStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
128 
129 		if (err !is null)
130 		{
131 			throw new GException( new ErrorG(err) );
132 		}
133 
134 		return p;
135 	}
136 
137 	/**
138 	 * Run asynchronous interaction to ask the user for a password. In general,
139 	 * g_tls_interaction_invoke_ask_password() should be used instead of this
140 	 * function.
141 	 *
142 	 * Derived subclasses usually implement a password prompt, although they may
143 	 * also choose to provide a password from elsewhere. The @password value will
144 	 * be filled in and then @callback will be called. Alternatively the user may
145 	 * abort this password request, which will usually abort the TLS connection.
146 	 *
147 	 * If the interaction is cancelled by the cancellation object, or by the
148 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
149 	 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may
150 	 * not support immediate cancellation.
151 	 *
152 	 * Certain implementations may not support immediate cancellation.
153 	 *
154 	 * Params:
155 	 *     password = a #GTlsPassword object
156 	 *     cancellable = an optional #GCancellable cancellation object
157 	 *     callback = will be called when the interaction completes
158 	 *     userData = data to pass to the @callback
159 	 *
160 	 * Since: 2.30
161 	 */
162 	public void askPasswordAsync(TlsPassword password, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
163 	{
164 		g_tls_interaction_ask_password_async(gTlsInteraction, (password is null) ? null : password.getTlsPasswordStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
165 	}
166 
167 	/**
168 	 * Complete an ask password user interaction request. This should be once
169 	 * the g_tls_interaction_ask_password_async() completion callback is called.
170 	 *
171 	 * If %G_TLS_INTERACTION_HANDLED is returned, then the #GTlsPassword passed
172 	 * to g_tls_interaction_ask_password() will have its password filled in.
173 	 *
174 	 * If the interaction is cancelled by the cancellation object, or by the
175 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
176 	 * contains a %G_IO_ERROR_CANCELLED error code.
177 	 *
178 	 * Params:
179 	 *     result = the result passed to the callback
180 	 *
181 	 * Returns: The status of the ask password interaction.
182 	 *
183 	 * Since: 2.30
184 	 *
185 	 * Throws: GException on failure.
186 	 */
187 	public GTlsInteractionResult askPasswordFinish(AsyncResultIF result)
188 	{
189 		GError* err = null;
190 
191 		auto p = g_tls_interaction_ask_password_finish(gTlsInteraction, (result is null) ? null : result.getAsyncResultStruct(), &err);
192 
193 		if (err !is null)
194 		{
195 			throw new GException( new ErrorG(err) );
196 		}
197 
198 		return p;
199 	}
200 
201 	/**
202 	 * Invoke the interaction to ask the user for a password. It invokes this
203 	 * interaction in the main loop, specifically the #GMainContext returned by
204 	 * g_main_context_get_thread_default() when the interaction is created. This
205 	 * is called by called by #GTlsConnection or #GTlsDatabase to ask the user
206 	 * for a password.
207 	 *
208 	 * Derived subclasses usually implement a password prompt, although they may
209 	 * also choose to provide a password from elsewhere. The @password value will
210 	 * be filled in and then @callback will be called. Alternatively the user may
211 	 * abort this password request, which will usually abort the TLS connection.
212 	 *
213 	 * The implementation can either be a synchronous (eg: modal dialog) or an
214 	 * asynchronous one (eg: modeless dialog). This function will take care of
215 	 * calling which ever one correctly.
216 	 *
217 	 * If the interaction is cancelled by the cancellation object, or by the
218 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
219 	 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may
220 	 * not support immediate cancellation.
221 	 *
222 	 * Params:
223 	 *     password = a #GTlsPassword object
224 	 *     cancellable = an optional #GCancellable cancellation object
225 	 *
226 	 * Returns: The status of the ask password interaction.
227 	 *
228 	 * Since: 2.30
229 	 *
230 	 * Throws: GException on failure.
231 	 */
232 	public GTlsInteractionResult invokeAskPassword(TlsPassword password, Cancellable cancellable)
233 	{
234 		GError* err = null;
235 
236 		auto p = g_tls_interaction_invoke_ask_password(gTlsInteraction, (password is null) ? null : password.getTlsPasswordStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
237 
238 		if (err !is null)
239 		{
240 			throw new GException( new ErrorG(err) );
241 		}
242 
243 		return p;
244 	}
245 
246 	/**
247 	 * Invoke the interaction to ask the user to choose a certificate to
248 	 * use with the connection. It invokes this interaction in the main
249 	 * loop, specifically the #GMainContext returned by
250 	 * g_main_context_get_thread_default() when the interaction is
251 	 * created. This is called by called by #GTlsConnection when the peer
252 	 * requests a certificate during the handshake.
253 	 *
254 	 * Derived subclasses usually implement a certificate selector,
255 	 * although they may also choose to provide a certificate from
256 	 * elsewhere. Alternatively the user may abort this certificate
257 	 * request, which may or may not abort the TLS connection.
258 	 *
259 	 * The implementation can either be a synchronous (eg: modal dialog) or an
260 	 * asynchronous one (eg: modeless dialog). This function will take care of
261 	 * calling which ever one correctly.
262 	 *
263 	 * If the interaction is cancelled by the cancellation object, or by the
264 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
265 	 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may
266 	 * not support immediate cancellation.
267 	 *
268 	 * Params:
269 	 *     connection = a #GTlsConnection object
270 	 *     flags = flags providing more information about the request
271 	 *     cancellable = an optional #GCancellable cancellation object
272 	 *
273 	 * Returns: The status of the certificate request interaction.
274 	 *
275 	 * Since: 2.40
276 	 *
277 	 * Throws: GException on failure.
278 	 */
279 	public GTlsInteractionResult invokeRequestCertificate(TlsConnection connection, GTlsCertificateRequestFlags flags, Cancellable cancellable)
280 	{
281 		GError* err = null;
282 
283 		auto p = g_tls_interaction_invoke_request_certificate(gTlsInteraction, (connection is null) ? null : connection.getTlsConnectionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
284 
285 		if (err !is null)
286 		{
287 			throw new GException( new ErrorG(err) );
288 		}
289 
290 		return p;
291 	}
292 
293 	/**
294 	 * Run synchronous interaction to ask the user to choose a certificate to use
295 	 * with the connection. In general, g_tls_interaction_invoke_request_certificate()
296 	 * should be used instead of this function.
297 	 *
298 	 * Derived subclasses usually implement a certificate selector, although they may
299 	 * also choose to provide a certificate from elsewhere. Alternatively the user may
300 	 * abort this certificate request, which will usually abort the TLS connection.
301 	 *
302 	 * If %G_TLS_INTERACTION_HANDLED is returned, then the #GTlsConnection
303 	 * passed to g_tls_interaction_request_certificate() will have had its
304 	 * #GTlsConnection:certificate filled in.
305 	 *
306 	 * If the interaction is cancelled by the cancellation object, or by the
307 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
308 	 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may
309 	 * not support immediate cancellation.
310 	 *
311 	 * Params:
312 	 *     connection = a #GTlsConnection object
313 	 *     flags = flags providing more information about the request
314 	 *     cancellable = an optional #GCancellable cancellation object
315 	 *
316 	 * Returns: The status of the request certificate interaction.
317 	 *
318 	 * Since: 2.40
319 	 *
320 	 * Throws: GException on failure.
321 	 */
322 	public GTlsInteractionResult requestCertificate(TlsConnection connection, GTlsCertificateRequestFlags flags, Cancellable cancellable)
323 	{
324 		GError* err = null;
325 
326 		auto p = g_tls_interaction_request_certificate(gTlsInteraction, (connection is null) ? null : connection.getTlsConnectionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
327 
328 		if (err !is null)
329 		{
330 			throw new GException( new ErrorG(err) );
331 		}
332 
333 		return p;
334 	}
335 
336 	/**
337 	 * Run asynchronous interaction to ask the user for a certificate to use with
338 	 * the connection. In general, g_tls_interaction_invoke_request_certificate() should
339 	 * be used instead of this function.
340 	 *
341 	 * Derived subclasses usually implement a certificate selector, although they may
342 	 * also choose to provide a certificate from elsewhere. @callback will be called
343 	 * when the operation completes. Alternatively the user may abort this certificate
344 	 * request, which will usually abort the TLS connection.
345 	 *
346 	 * Params:
347 	 *     connection = a #GTlsConnection object
348 	 *     flags = flags providing more information about the request
349 	 *     cancellable = an optional #GCancellable cancellation object
350 	 *     callback = will be called when the interaction completes
351 	 *     userData = data to pass to the @callback
352 	 *
353 	 * Since: 2.40
354 	 */
355 	public void requestCertificateAsync(TlsConnection connection, GTlsCertificateRequestFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
356 	{
357 		g_tls_interaction_request_certificate_async(gTlsInteraction, (connection is null) ? null : connection.getTlsConnectionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
358 	}
359 
360 	/**
361 	 * Complete an request certificate user interaction request. This should be once
362 	 * the g_tls_interaction_request_certificate_async() completion callback is called.
363 	 *
364 	 * If %G_TLS_INTERACTION_HANDLED is returned, then the #GTlsConnection
365 	 * passed to g_tls_interaction_request_certificate_async() will have had its
366 	 * #GTlsConnection:certificate filled in.
367 	 *
368 	 * If the interaction is cancelled by the cancellation object, or by the
369 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
370 	 * contains a %G_IO_ERROR_CANCELLED error code.
371 	 *
372 	 * Params:
373 	 *     result = the result passed to the callback
374 	 *
375 	 * Returns: The status of the request certificate interaction.
376 	 *
377 	 * Since: 2.40
378 	 *
379 	 * Throws: GException on failure.
380 	 */
381 	public GTlsInteractionResult requestCertificateFinish(AsyncResultIF result)
382 	{
383 		GError* err = null;
384 
385 		auto p = g_tls_interaction_request_certificate_finish(gTlsInteraction, (result is null) ? null : result.getAsyncResultStruct(), &err);
386 
387 		if (err !is null)
388 		{
389 			throw new GException( new ErrorG(err) );
390 		}
391 
392 		return p;
393 	}
394 }