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