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