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 	protected override void setStruct(GObject* obj)
83 	{
84 		gTlsInteraction = cast(GTlsInteraction*)obj;
85 		super.setStruct(obj);
86 	}
87 
88 	/**
89 	 * Sets our main struct and passes it to the parent class.
90 	 */
91 	public this (GTlsInteraction* gTlsInteraction, bool ownedRef = false)
92 	{
93 		this.gTlsInteraction = gTlsInteraction;
94 		super(cast(GObject*)gTlsInteraction, ownedRef);
95 	}
96 
97 
98 	/** */
99 	public static GType getType()
100 	{
101 		return g_tls_interaction_get_type();
102 	}
103 
104 	/**
105 	 * Run synchronous interaction to ask the user for a password. In general,
106 	 * g_tls_interaction_invoke_ask_password() should be used instead of this
107 	 * function.
108 	 *
109 	 * Derived subclasses usually implement a password prompt, although they may
110 	 * also choose to provide a password from elsewhere. The @password value will
111 	 * be filled in and then @callback will be called. Alternatively the user may
112 	 * abort this password request, which will usually abort the TLS connection.
113 	 *
114 	 * If the interaction is cancelled by the cancellation object, or by the
115 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
116 	 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may
117 	 * not support immediate cancellation.
118 	 *
119 	 * Params:
120 	 *     password = a #GTlsPassword object
121 	 *     cancellable = an optional #GCancellable cancellation object
122 	 *
123 	 * Returns: The status of the ask password interaction.
124 	 *
125 	 * Since: 2.30
126 	 *
127 	 * Throws: GException on failure.
128 	 */
129 	public GTlsInteractionResult askPassword(TlsPassword password, Cancellable cancellable)
130 	{
131 		GError* err = null;
132 
133 		auto p = g_tls_interaction_ask_password(gTlsInteraction, (password is null) ? null : password.getTlsPasswordStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
134 
135 		if (err !is null)
136 		{
137 			throw new GException( new ErrorG(err) );
138 		}
139 
140 		return p;
141 	}
142 
143 	/**
144 	 * Run asynchronous interaction to ask the user for a password. In general,
145 	 * g_tls_interaction_invoke_ask_password() should be used instead of this
146 	 * function.
147 	 *
148 	 * Derived subclasses usually implement a password prompt, although they may
149 	 * also choose to provide a password from elsewhere. The @password value will
150 	 * be filled in and then @callback will be called. Alternatively the user may
151 	 * abort this password request, which will usually abort the TLS connection.
152 	 *
153 	 * If the interaction is cancelled by the cancellation object, or by the
154 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
155 	 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may
156 	 * not support immediate cancellation.
157 	 *
158 	 * Certain implementations may not support immediate cancellation.
159 	 *
160 	 * Params:
161 	 *     password = a #GTlsPassword object
162 	 *     cancellable = an optional #GCancellable cancellation object
163 	 *     callback = will be called when the interaction completes
164 	 *     userData = data to pass to the @callback
165 	 *
166 	 * Since: 2.30
167 	 */
168 	public void askPasswordAsync(TlsPassword password, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
169 	{
170 		g_tls_interaction_ask_password_async(gTlsInteraction, (password is null) ? null : password.getTlsPasswordStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
171 	}
172 
173 	/**
174 	 * Complete an ask password user interaction request. This should be once
175 	 * the g_tls_interaction_ask_password_async() completion callback is called.
176 	 *
177 	 * If %G_TLS_INTERACTION_HANDLED is returned, then the #GTlsPassword passed
178 	 * to g_tls_interaction_ask_password() will have its password filled in.
179 	 *
180 	 * If the interaction is cancelled by the cancellation object, or by the
181 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
182 	 * contains a %G_IO_ERROR_CANCELLED error code.
183 	 *
184 	 * Params:
185 	 *     result = the result passed to the callback
186 	 *
187 	 * Returns: The status of the ask password interaction.
188 	 *
189 	 * Since: 2.30
190 	 *
191 	 * Throws: GException on failure.
192 	 */
193 	public GTlsInteractionResult askPasswordFinish(AsyncResultIF result)
194 	{
195 		GError* err = null;
196 
197 		auto p = g_tls_interaction_ask_password_finish(gTlsInteraction, (result is null) ? null : result.getAsyncResultStruct(), &err);
198 
199 		if (err !is null)
200 		{
201 			throw new GException( new ErrorG(err) );
202 		}
203 
204 		return p;
205 	}
206 
207 	/**
208 	 * Invoke the interaction to ask the user for a password. It invokes this
209 	 * interaction in the main loop, specifically the #GMainContext returned by
210 	 * g_main_context_get_thread_default() when the interaction is created. This
211 	 * is called by called by #GTlsConnection or #GTlsDatabase to ask the user
212 	 * for a password.
213 	 *
214 	 * Derived subclasses usually implement a password prompt, although they may
215 	 * also choose to provide a password from elsewhere. The @password value will
216 	 * be filled in and then @callback will be called. Alternatively the user may
217 	 * abort this password request, which will usually abort the TLS connection.
218 	 *
219 	 * The implementation can either be a synchronous (eg: modal dialog) or an
220 	 * asynchronous one (eg: modeless dialog). This function will take care of
221 	 * calling which ever one correctly.
222 	 *
223 	 * If the interaction is cancelled by the cancellation object, or by the
224 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
225 	 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may
226 	 * not support immediate cancellation.
227 	 *
228 	 * Params:
229 	 *     password = a #GTlsPassword object
230 	 *     cancellable = an optional #GCancellable cancellation object
231 	 *
232 	 * Returns: The status of the ask password interaction.
233 	 *
234 	 * Since: 2.30
235 	 *
236 	 * Throws: GException on failure.
237 	 */
238 	public GTlsInteractionResult invokeAskPassword(TlsPassword password, Cancellable cancellable)
239 	{
240 		GError* err = null;
241 
242 		auto p = g_tls_interaction_invoke_ask_password(gTlsInteraction, (password is null) ? null : password.getTlsPasswordStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
243 
244 		if (err !is null)
245 		{
246 			throw new GException( new ErrorG(err) );
247 		}
248 
249 		return p;
250 	}
251 
252 	/**
253 	 * Invoke the interaction to ask the user to choose a certificate to
254 	 * use with the connection. It invokes this interaction in the main
255 	 * loop, specifically the #GMainContext returned by
256 	 * g_main_context_get_thread_default() when the interaction is
257 	 * created. This is called by called by #GTlsConnection when the peer
258 	 * requests a certificate during the handshake.
259 	 *
260 	 * Derived subclasses usually implement a certificate selector,
261 	 * although they may also choose to provide a certificate from
262 	 * elsewhere. Alternatively the user may abort this certificate
263 	 * request, which may or may not abort the TLS connection.
264 	 *
265 	 * The implementation can either be a synchronous (eg: modal dialog) or an
266 	 * asynchronous one (eg: modeless dialog). This function will take care of
267 	 * calling which ever one correctly.
268 	 *
269 	 * If the interaction is cancelled by the cancellation object, or by the
270 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
271 	 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may
272 	 * not support immediate cancellation.
273 	 *
274 	 * Params:
275 	 *     connection = a #GTlsConnection object
276 	 *     flags = flags providing more information about the request
277 	 *     cancellable = an optional #GCancellable cancellation object
278 	 *
279 	 * Returns: The status of the certificate request interaction.
280 	 *
281 	 * Since: 2.40
282 	 *
283 	 * Throws: GException on failure.
284 	 */
285 	public GTlsInteractionResult invokeRequestCertificate(TlsConnection connection, GTlsCertificateRequestFlags flags, Cancellable cancellable)
286 	{
287 		GError* err = null;
288 
289 		auto p = g_tls_interaction_invoke_request_certificate(gTlsInteraction, (connection is null) ? null : connection.getTlsConnectionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
290 
291 		if (err !is null)
292 		{
293 			throw new GException( new ErrorG(err) );
294 		}
295 
296 		return p;
297 	}
298 
299 	/**
300 	 * Run synchronous interaction to ask the user to choose a certificate to use
301 	 * with the connection. In general, g_tls_interaction_invoke_request_certificate()
302 	 * should be used instead of this function.
303 	 *
304 	 * Derived subclasses usually implement a certificate selector, although they may
305 	 * also choose to provide a certificate from elsewhere. Alternatively the user may
306 	 * abort this certificate request, which will usually abort the TLS connection.
307 	 *
308 	 * If %G_TLS_INTERACTION_HANDLED is returned, then the #GTlsConnection
309 	 * passed to g_tls_interaction_request_certificate() will have had its
310 	 * #GTlsConnection:certificate filled in.
311 	 *
312 	 * If the interaction is cancelled by the cancellation object, or by the
313 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
314 	 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may
315 	 * not support immediate cancellation.
316 	 *
317 	 * Params:
318 	 *     connection = a #GTlsConnection object
319 	 *     flags = flags providing more information about the request
320 	 *     cancellable = an optional #GCancellable cancellation object
321 	 *
322 	 * Returns: The status of the request certificate interaction.
323 	 *
324 	 * Since: 2.40
325 	 *
326 	 * Throws: GException on failure.
327 	 */
328 	public GTlsInteractionResult requestCertificate(TlsConnection connection, GTlsCertificateRequestFlags flags, Cancellable cancellable)
329 	{
330 		GError* err = null;
331 
332 		auto p = g_tls_interaction_request_certificate(gTlsInteraction, (connection is null) ? null : connection.getTlsConnectionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
333 
334 		if (err !is null)
335 		{
336 			throw new GException( new ErrorG(err) );
337 		}
338 
339 		return p;
340 	}
341 
342 	/**
343 	 * Run asynchronous interaction to ask the user for a certificate to use with
344 	 * the connection. In general, g_tls_interaction_invoke_request_certificate() should
345 	 * be used instead of this function.
346 	 *
347 	 * Derived subclasses usually implement a certificate selector, although they may
348 	 * also choose to provide a certificate from elsewhere. @callback will be called
349 	 * when the operation completes. Alternatively the user may abort this certificate
350 	 * request, which will usually abort the TLS connection.
351 	 *
352 	 * Params:
353 	 *     connection = a #GTlsConnection object
354 	 *     flags = flags providing more information about the request
355 	 *     cancellable = an optional #GCancellable cancellation object
356 	 *     callback = will be called when the interaction completes
357 	 *     userData = data to pass to the @callback
358 	 *
359 	 * Since: 2.40
360 	 */
361 	public void requestCertificateAsync(TlsConnection connection, GTlsCertificateRequestFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
362 	{
363 		g_tls_interaction_request_certificate_async(gTlsInteraction, (connection is null) ? null : connection.getTlsConnectionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
364 	}
365 
366 	/**
367 	 * Complete an request certificate user interaction request. This should be once
368 	 * the g_tls_interaction_request_certificate_async() completion callback is called.
369 	 *
370 	 * If %G_TLS_INTERACTION_HANDLED is returned, then the #GTlsConnection
371 	 * passed to g_tls_interaction_request_certificate_async() will have had its
372 	 * #GTlsConnection:certificate filled in.
373 	 *
374 	 * If the interaction is cancelled by the cancellation object, or by the
375 	 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that
376 	 * contains a %G_IO_ERROR_CANCELLED error code.
377 	 *
378 	 * Params:
379 	 *     result = the result passed to the callback
380 	 *
381 	 * Returns: The status of the request certificate interaction.
382 	 *
383 	 * Since: 2.40
384 	 *
385 	 * Throws: GException on failure.
386 	 */
387 	public GTlsInteractionResult requestCertificateFinish(AsyncResultIF result)
388 	{
389 		GError* err = null;
390 
391 		auto p = g_tls_interaction_request_certificate_finish(gTlsInteraction, (result is null) ? null : result.getAsyncResultStruct(), &err);
392 
393 		if (err !is null)
394 		{
395 			throw new GException( new ErrorG(err) );
396 		}
397 
398 		return p;
399 	}
400 }