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.DtlsConnectionT;
26 
27 public  import gio.AsyncResultIF;
28 public  import gio.Cancellable;
29 public  import gio.TlsCertificate;
30 public  import gio.TlsDatabase;
31 public  import gio.TlsInteraction;
32 public  import glib.ErrorG;
33 public  import glib.GException;
34 public  import gobject.ObjectG;
35 public  import gobject.Signals;
36 public  import gtkc.gio;
37 public  import gtkc.giotypes;
38 public  import std.algorithm;
39 
40 
41 /**
42  * #GDtlsConnection is the base DTLS connection class type, which wraps
43  * a #GDatagramBased and provides DTLS encryption on top of it. Its
44  * subclasses, #GDtlsClientConnection and #GDtlsServerConnection,
45  * implement client-side and server-side DTLS, respectively.
46  * 
47  * For TLS support, see #GTlsConnection.
48  * 
49  * As DTLS is datagram based, #GDtlsConnection implements #GDatagramBased,
50  * presenting a datagram-socket-like API for the encrypted connection. This
51  * operates over a base datagram connection, which is also a #GDatagramBased
52  * (#GDtlsConnection:base-socket).
53  * 
54  * To close a DTLS connection, use g_dtls_connection_close().
55  * 
56  * Neither #GDtlsServerConnection or #GDtlsClientConnection set the peer address
57  * on their base #GDatagramBased if it is a #GSocket — it is up to the caller to
58  * do that if they wish. If they do not, and g_socket_close() is called on the
59  * base socket, the #GDtlsConnection will not raise a %G_IO_ERROR_NOT_CONNECTED
60  * error on further I/O.
61  *
62  * Since: 2.48
63  */
64 public template DtlsConnectionT(TStruct)
65 {
66 	/** Get the main Gtk struct */
67 	public GDtlsConnection* getDtlsConnectionStruct(bool transferOwnership = false)
68 	{
69 		if (transferOwnership)
70 			ownedRef = false;
71 		return cast(GDtlsConnection*)getStruct();
72 	}
73 
74 
75 	/**
76 	 * Close the DTLS connection. This is equivalent to calling
77 	 * g_dtls_connection_shutdown() to shut down both sides of the connection.
78 	 *
79 	 * Closing a #GDtlsConnection waits for all buffered but untransmitted data to
80 	 * be sent before it completes. It then sends a `close_notify` DTLS alert to the
81 	 * peer and may wait for a `close_notify` to be received from the peer. It does
82 	 * not close the underlying #GDtlsConnection:base-socket; that must be closed
83 	 * separately.
84 	 *
85 	 * Once @conn is closed, all other operations will return %G_IO_ERROR_CLOSED.
86 	 * Closing a #GDtlsConnection multiple times will not return an error.
87 	 *
88 	 * #GDtlsConnections will be automatically closed when the last reference is
89 	 * dropped, but you might want to call this function to make sure resources are
90 	 * released as early as possible.
91 	 *
92 	 * If @cancellable is cancelled, the #GDtlsConnection may be left
93 	 * partially-closed and any pending untransmitted data may be lost. Call
94 	 * g_dtls_connection_close() again to complete closing the #GDtlsConnection.
95 	 *
96 	 * Params:
97 	 *     cancellable = a #GCancellable, or %NULL
98 	 *
99 	 * Returns: %TRUE on success, %FALSE otherwise
100 	 *
101 	 * Since: 2.48
102 	 *
103 	 * Throws: GException on failure.
104 	 */
105 	public bool close(Cancellable cancellable)
106 	{
107 		GError* err = null;
108 		
109 		auto p = g_dtls_connection_close(getDtlsConnectionStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
110 		
111 		if (err !is null)
112 		{
113 			throw new GException( new ErrorG(err) );
114 		}
115 		
116 		return p;
117 	}
118 
119 	/**
120 	 * Asynchronously close the DTLS connection. See g_dtls_connection_close() for
121 	 * more information.
122 	 *
123 	 * Params:
124 	 *     ioPriority = the [I/O priority][io-priority] of the request
125 	 *     cancellable = a #GCancellable, or %NULL
126 	 *     callback = callback to call when the close operation is complete
127 	 *     userData = the data to pass to the callback function
128 	 *
129 	 * Since: 2.48
130 	 */
131 	public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
132 	{
133 		g_dtls_connection_close_async(getDtlsConnectionStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
134 	}
135 
136 	/**
137 	 * Finish an asynchronous TLS close operation. See g_dtls_connection_close()
138 	 * for more information.
139 	 *
140 	 * Params:
141 	 *     result = a #GAsyncResult
142 	 *
143 	 * Returns: %TRUE on success, %FALSE on failure, in which
144 	 *     case @error will be set
145 	 *
146 	 * Since: 2.48
147 	 *
148 	 * Throws: GException on failure.
149 	 */
150 	public bool closeFinish(AsyncResultIF result)
151 	{
152 		GError* err = null;
153 		
154 		auto p = g_dtls_connection_close_finish(getDtlsConnectionStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
155 		
156 		if (err !is null)
157 		{
158 			throw new GException( new ErrorG(err) );
159 		}
160 		
161 		return p;
162 	}
163 
164 	/**
165 	 * Used by #GDtlsConnection implementations to emit the
166 	 * #GDtlsConnection::accept-certificate signal.
167 	 *
168 	 * Params:
169 	 *     peerCert = the peer's #GTlsCertificate
170 	 *     errors = the problems with @peer_cert
171 	 *
172 	 * Returns: %TRUE if one of the signal handlers has returned
173 	 *     %TRUE to accept @peer_cert
174 	 *
175 	 * Since: 2.48
176 	 */
177 	public bool emitAcceptCertificate(TlsCertificate peerCert, GTlsCertificateFlags errors)
178 	{
179 		return g_dtls_connection_emit_accept_certificate(getDtlsConnectionStruct(), (peerCert is null) ? null : peerCert.getTlsCertificateStruct(), errors) != 0;
180 	}
181 
182 	/**
183 	 * Gets @conn's certificate, as set by
184 	 * g_dtls_connection_set_certificate().
185 	 *
186 	 * Returns: @conn's certificate, or %NULL
187 	 *
188 	 * Since: 2.48
189 	 */
190 	public TlsCertificate getCertificate()
191 	{
192 		auto p = g_dtls_connection_get_certificate(getDtlsConnectionStruct());
193 		
194 		if(p is null)
195 		{
196 			return null;
197 		}
198 		
199 		return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p);
200 	}
201 
202 	/**
203 	 * Gets the certificate database that @conn uses to verify
204 	 * peer certificates. See g_dtls_connection_set_database().
205 	 *
206 	 * Returns: the certificate database that @conn uses or %NULL
207 	 *
208 	 * Since: 2.48
209 	 */
210 	public TlsDatabase getDatabase()
211 	{
212 		auto p = g_dtls_connection_get_database(getDtlsConnectionStruct());
213 		
214 		if(p is null)
215 		{
216 			return null;
217 		}
218 		
219 		return ObjectG.getDObject!(TlsDatabase)(cast(GTlsDatabase*) p);
220 	}
221 
222 	/**
223 	 * Get the object that will be used to interact with the user. It will be used
224 	 * for things like prompting the user for passwords. If %NULL is returned, then
225 	 * no user interaction will occur for this connection.
226 	 *
227 	 * Returns: The interaction object.
228 	 *
229 	 * Since: 2.48
230 	 */
231 	public TlsInteraction getInteraction()
232 	{
233 		auto p = g_dtls_connection_get_interaction(getDtlsConnectionStruct());
234 		
235 		if(p is null)
236 		{
237 			return null;
238 		}
239 		
240 		return ObjectG.getDObject!(TlsInteraction)(cast(GTlsInteraction*) p);
241 	}
242 
243 	/**
244 	 * Gets @conn's peer's certificate after the handshake has completed.
245 	 * (It is not set during the emission of
246 	 * #GDtlsConnection::accept-certificate.)
247 	 *
248 	 * Returns: @conn's peer's certificate, or %NULL
249 	 *
250 	 * Since: 2.48
251 	 */
252 	public TlsCertificate getPeerCertificate()
253 	{
254 		auto p = g_dtls_connection_get_peer_certificate(getDtlsConnectionStruct());
255 		
256 		if(p is null)
257 		{
258 			return null;
259 		}
260 		
261 		return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p);
262 	}
263 
264 	/**
265 	 * Gets the errors associated with validating @conn's peer's
266 	 * certificate, after the handshake has completed. (It is not set
267 	 * during the emission of #GDtlsConnection::accept-certificate.)
268 	 *
269 	 * Returns: @conn's peer's certificate errors
270 	 *
271 	 * Since: 2.48
272 	 */
273 	public GTlsCertificateFlags getPeerCertificateErrors()
274 	{
275 		return g_dtls_connection_get_peer_certificate_errors(getDtlsConnectionStruct());
276 	}
277 
278 	/**
279 	 * Gets @conn rehandshaking mode. See
280 	 * g_dtls_connection_set_rehandshake_mode() for details.
281 	 *
282 	 * Returns: @conn's rehandshaking mode
283 	 *
284 	 * Since: 2.48
285 	 */
286 	public GTlsRehandshakeMode getRehandshakeMode()
287 	{
288 		return g_dtls_connection_get_rehandshake_mode(getDtlsConnectionStruct());
289 	}
290 
291 	/**
292 	 * Tests whether or not @conn expects a proper TLS close notification
293 	 * when the connection is closed. See
294 	 * g_dtls_connection_set_require_close_notify() for details.
295 	 *
296 	 * Returns: %TRUE if @conn requires a proper TLS close notification.
297 	 *
298 	 * Since: 2.48
299 	 */
300 	public bool getRequireCloseNotify()
301 	{
302 		return g_dtls_connection_get_require_close_notify(getDtlsConnectionStruct()) != 0;
303 	}
304 
305 	/**
306 	 * Attempts a TLS handshake on @conn.
307 	 *
308 	 * On the client side, it is never necessary to call this method;
309 	 * although the connection needs to perform a handshake after
310 	 * connecting (or after sending a "STARTTLS"-type command) and may
311 	 * need to rehandshake later if the server requests it,
312 	 * #GDtlsConnection will handle this for you automatically when you try
313 	 * to send or receive data on the connection. However, you can call
314 	 * g_dtls_connection_handshake() manually if you want to know for sure
315 	 * whether the initial handshake succeeded or failed (as opposed to
316 	 * just immediately trying to write to @conn, in which
317 	 * case if it fails, it may not be possible to tell if it failed
318 	 * before or after completing the handshake).
319 	 *
320 	 * Likewise, on the server side, although a handshake is necessary at
321 	 * the beginning of the communication, you do not need to call this
322 	 * function explicitly unless you want clearer error reporting.
323 	 * However, you may call g_dtls_connection_handshake() later on to
324 	 * renegotiate parameters (encryption methods, etc) with the client.
325 	 *
326 	 * #GDtlsConnection::accept_certificate may be emitted during the
327 	 * handshake.
328 	 *
329 	 * Params:
330 	 *     cancellable = a #GCancellable, or %NULL
331 	 *
332 	 * Returns: success or failure
333 	 *
334 	 * Since: 2.48
335 	 *
336 	 * Throws: GException on failure.
337 	 */
338 	public bool handshake(Cancellable cancellable)
339 	{
340 		GError* err = null;
341 		
342 		auto p = g_dtls_connection_handshake(getDtlsConnectionStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
343 		
344 		if (err !is null)
345 		{
346 			throw new GException( new ErrorG(err) );
347 		}
348 		
349 		return p;
350 	}
351 
352 	/**
353 	 * Asynchronously performs a TLS handshake on @conn. See
354 	 * g_dtls_connection_handshake() for more information.
355 	 *
356 	 * Params:
357 	 *     ioPriority = the [I/O priority][io-priority] of the request
358 	 *     cancellable = a #GCancellable, or %NULL
359 	 *     callback = callback to call when the handshake is complete
360 	 *     userData = the data to pass to the callback function
361 	 *
362 	 * Since: 2.48
363 	 */
364 	public void handshakeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
365 	{
366 		g_dtls_connection_handshake_async(getDtlsConnectionStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
367 	}
368 
369 	/**
370 	 * Finish an asynchronous TLS handshake operation. See
371 	 * g_dtls_connection_handshake() for more information.
372 	 *
373 	 * Params:
374 	 *     result = a #GAsyncResult.
375 	 *
376 	 * Returns: %TRUE on success, %FALSE on failure, in which
377 	 *     case @error will be set.
378 	 *
379 	 * Since: 2.48
380 	 *
381 	 * Throws: GException on failure.
382 	 */
383 	public bool handshakeFinish(AsyncResultIF result)
384 	{
385 		GError* err = null;
386 		
387 		auto p = g_dtls_connection_handshake_finish(getDtlsConnectionStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
388 		
389 		if (err !is null)
390 		{
391 			throw new GException( new ErrorG(err) );
392 		}
393 		
394 		return p;
395 	}
396 
397 	/**
398 	 * This sets the certificate that @conn will present to its peer
399 	 * during the TLS handshake. For a #GDtlsServerConnection, it is
400 	 * mandatory to set this, and that will normally be done at construct
401 	 * time.
402 	 *
403 	 * For a #GDtlsClientConnection, this is optional. If a handshake fails
404 	 * with %G_TLS_ERROR_CERTIFICATE_REQUIRED, that means that the server
405 	 * requires a certificate, and if you try connecting again, you should
406 	 * call this method first. You can call
407 	 * g_dtls_client_connection_get_accepted_cas() on the failed connection
408 	 * to get a list of Certificate Authorities that the server will
409 	 * accept certificates from.
410 	 *
411 	 * (It is also possible that a server will allow the connection with
412 	 * or without a certificate; in that case, if you don't provide a
413 	 * certificate, you can tell that the server requested one by the fact
414 	 * that g_dtls_client_connection_get_accepted_cas() will return
415 	 * non-%NULL.)
416 	 *
417 	 * Params:
418 	 *     certificate = the certificate to use for @conn
419 	 *
420 	 * Since: 2.48
421 	 */
422 	public void setCertificate(TlsCertificate certificate)
423 	{
424 		g_dtls_connection_set_certificate(getDtlsConnectionStruct(), (certificate is null) ? null : certificate.getTlsCertificateStruct());
425 	}
426 
427 	/**
428 	 * Sets the certificate database that is used to verify peer certificates.
429 	 * This is set to the default database by default. See
430 	 * g_dtls_backend_get_default_database(). If set to %NULL, then
431 	 * peer certificate validation will always set the
432 	 * %G_TLS_CERTIFICATE_UNKNOWN_CA error (meaning
433 	 * #GDtlsConnection::accept-certificate will always be emitted on
434 	 * client-side connections, unless that bit is not set in
435 	 * #GDtlsClientConnection:validation-flags).
436 	 *
437 	 * Params:
438 	 *     database = a #GTlsDatabase
439 	 *
440 	 * Since: 2.48
441 	 */
442 	public void setDatabase(TlsDatabase database)
443 	{
444 		g_dtls_connection_set_database(getDtlsConnectionStruct(), (database is null) ? null : database.getTlsDatabaseStruct());
445 	}
446 
447 	/**
448 	 * Set the object that will be used to interact with the user. It will be used
449 	 * for things like prompting the user for passwords.
450 	 *
451 	 * The @interaction argument will normally be a derived subclass of
452 	 * #GTlsInteraction. %NULL can also be provided if no user interaction
453 	 * should occur for this connection.
454 	 *
455 	 * Params:
456 	 *     interaction = an interaction object, or %NULL
457 	 *
458 	 * Since: 2.48
459 	 */
460 	public void setInteraction(TlsInteraction interaction)
461 	{
462 		g_dtls_connection_set_interaction(getDtlsConnectionStruct(), (interaction is null) ? null : interaction.getTlsInteractionStruct());
463 	}
464 
465 	/**
466 	 * Sets how @conn behaves with respect to rehandshaking requests.
467 	 *
468 	 * %G_TLS_REHANDSHAKE_NEVER means that it will never agree to
469 	 * rehandshake after the initial handshake is complete. (For a client,
470 	 * this means it will refuse rehandshake requests from the server, and
471 	 * for a server, this means it will close the connection with an error
472 	 * if the client attempts to rehandshake.)
473 	 *
474 	 * %G_TLS_REHANDSHAKE_SAFELY means that the connection will allow a
475 	 * rehandshake only if the other end of the connection supports the
476 	 * TLS `renegotiation_info` extension. This is the default behavior,
477 	 * but means that rehandshaking will not work against older
478 	 * implementations that do not support that extension.
479 	 *
480 	 * %G_TLS_REHANDSHAKE_UNSAFELY means that the connection will allow
481 	 * rehandshaking even without the `renegotiation_info` extension. On
482 	 * the server side in particular, this is not recommended, since it
483 	 * leaves the server open to certain attacks. However, this mode is
484 	 * necessary if you need to allow renegotiation with older client
485 	 * software.
486 	 *
487 	 * Params:
488 	 *     mode = the rehandshaking mode
489 	 *
490 	 * Since: 2.48
491 	 */
492 	public void setRehandshakeMode(GTlsRehandshakeMode mode)
493 	{
494 		g_dtls_connection_set_rehandshake_mode(getDtlsConnectionStruct(), mode);
495 	}
496 
497 	/**
498 	 * Sets whether or not @conn expects a proper TLS close notification
499 	 * before the connection is closed. If this is %TRUE (the default),
500 	 * then @conn will expect to receive a TLS close notification from its
501 	 * peer before the connection is closed, and will return a
502 	 * %G_TLS_ERROR_EOF error if the connection is closed without proper
503 	 * notification (since this may indicate a network error, or
504 	 * man-in-the-middle attack).
505 	 *
506 	 * In some protocols, the application will know whether or not the
507 	 * connection was closed cleanly based on application-level data
508 	 * (because the application-level data includes a length field, or is
509 	 * somehow self-delimiting); in this case, the close notify is
510 	 * redundant and may be omitted. You
511 	 * can use g_dtls_connection_set_require_close_notify() to tell @conn
512 	 * to allow an "unannounced" connection close, in which case the close
513 	 * will show up as a 0-length read, as in a non-TLS
514 	 * #GDatagramBased, and it is up to the application to check that
515 	 * the data has been fully received.
516 	 *
517 	 * Note that this only affects the behavior when the peer closes the
518 	 * connection; when the application calls g_dtls_connection_close_async() on
519 	 * @conn itself, this will send a close notification regardless of the
520 	 * setting of this property. If you explicitly want to do an unclean
521 	 * close, you can close @conn's #GDtlsConnection:base-socket rather
522 	 * than closing @conn itself.
523 	 *
524 	 * Params:
525 	 *     requireCloseNotify = whether or not to require close notification
526 	 *
527 	 * Since: 2.48
528 	 */
529 	public void setRequireCloseNotify(bool requireCloseNotify)
530 	{
531 		g_dtls_connection_set_require_close_notify(getDtlsConnectionStruct(), requireCloseNotify);
532 	}
533 
534 	/**
535 	 * Shut down part or all of a DTLS connection.
536 	 *
537 	 * If @shutdown_read is %TRUE then the receiving side of the connection is shut
538 	 * down, and further reading is disallowed. Subsequent calls to
539 	 * g_datagram_based_receive_messages() will return %G_IO_ERROR_CLOSED.
540 	 *
541 	 * If @shutdown_write is %TRUE then the sending side of the connection is shut
542 	 * down, and further writing is disallowed. Subsequent calls to
543 	 * g_datagram_based_send_messages() will return %G_IO_ERROR_CLOSED.
544 	 *
545 	 * It is allowed for both @shutdown_read and @shutdown_write to be TRUE — this
546 	 * is equivalent to calling g_dtls_connection_close().
547 	 *
548 	 * If @cancellable is cancelled, the #GDtlsConnection may be left
549 	 * partially-closed and any pending untransmitted data may be lost. Call
550 	 * g_dtls_connection_shutdown() again to complete closing the #GDtlsConnection.
551 	 *
552 	 * Params:
553 	 *     shutdownRead = %TRUE to stop reception of incoming datagrams
554 	 *     shutdownWrite = %TRUE to stop sending outgoing datagrams
555 	 *     cancellable = a #GCancellable, or %NULL
556 	 *
557 	 * Returns: %TRUE on success, %FALSE otherwise
558 	 *
559 	 * Since: 2.48
560 	 *
561 	 * Throws: GException on failure.
562 	 */
563 	public bool shutdown(bool shutdownRead, bool shutdownWrite, Cancellable cancellable)
564 	{
565 		GError* err = null;
566 		
567 		auto p = g_dtls_connection_shutdown(getDtlsConnectionStruct(), shutdownRead, shutdownWrite, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
568 		
569 		if (err !is null)
570 		{
571 			throw new GException( new ErrorG(err) );
572 		}
573 		
574 		return p;
575 	}
576 
577 	/**
578 	 * Asynchronously shut down part or all of the DTLS connection. See
579 	 * g_dtls_connection_shutdown() for more information.
580 	 *
581 	 * Params:
582 	 *     shutdownRead = %TRUE to stop reception of incoming datagrams
583 	 *     shutdownWrite = %TRUE to stop sending outgoing datagrams
584 	 *     ioPriority = the [I/O priority][io-priority] of the request
585 	 *     cancellable = a #GCancellable, or %NULL
586 	 *     callback = callback to call when the shutdown operation is complete
587 	 *     userData = the data to pass to the callback function
588 	 *
589 	 * Since: 2.48
590 	 */
591 	public void shutdownAsync(bool shutdownRead, bool shutdownWrite, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
592 	{
593 		g_dtls_connection_shutdown_async(getDtlsConnectionStruct(), shutdownRead, shutdownWrite, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
594 	}
595 
596 	/**
597 	 * Finish an asynchronous TLS shutdown operation. See
598 	 * g_dtls_connection_shutdown() for more information.
599 	 *
600 	 * Params:
601 	 *     result = a #GAsyncResult
602 	 *
603 	 * Returns: %TRUE on success, %FALSE on failure, in which
604 	 *     case @error will be set
605 	 *
606 	 * Since: 2.48
607 	 *
608 	 * Throws: GException on failure.
609 	 */
610 	public bool shutdownFinish(AsyncResultIF result)
611 	{
612 		GError* err = null;
613 		
614 		auto p = g_dtls_connection_shutdown_finish(getDtlsConnectionStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
615 		
616 		if (err !is null)
617 		{
618 			throw new GException( new ErrorG(err) );
619 		}
620 		
621 		return p;
622 	}
623 
624 	protected class OnAcceptCertificateDelegateWrapper
625 	{
626 		static OnAcceptCertificateDelegateWrapper[] listeners;
627 		bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF) dlg;
628 		gulong handlerId;
629 		
630 		this(bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF) dlg)
631 		{
632 			this.dlg = dlg;
633 			this.listeners ~= this;
634 		}
635 		
636 		void remove(OnAcceptCertificateDelegateWrapper source)
637 		{
638 			foreach(index, wrapper; listeners)
639 			{
640 				if (wrapper.handlerId == source.handlerId)
641 				{
642 					listeners[index] = null;
643 					listeners = std.algorithm.remove(listeners, index);
644 					break;
645 				}
646 			}
647 		}
648 	}
649 
650 	/**
651 	 * Emitted during the TLS handshake after the peer certificate has
652 	 * been received. You can examine @peer_cert's certification path by
653 	 * calling g_tls_certificate_get_issuer() on it.
654 	 *
655 	 * For a client-side connection, @peer_cert is the server's
656 	 * certificate, and the signal will only be emitted if the
657 	 * certificate was not acceptable according to @conn's
658 	 * #GDtlsClientConnection:validation_flags. If you would like the
659 	 * certificate to be accepted despite @errors, return %TRUE from the
660 	 * signal handler. Otherwise, if no handler accepts the certificate,
661 	 * the handshake will fail with %G_TLS_ERROR_BAD_CERTIFICATE.
662 	 *
663 	 * For a server-side connection, @peer_cert is the certificate
664 	 * presented by the client, if this was requested via the server's
665 	 * #GDtlsServerConnection:authentication_mode. On the server side,
666 	 * the signal is always emitted when the client presents a
667 	 * certificate, and the certificate will only be accepted if a
668 	 * handler returns %TRUE.
669 	 *
670 	 * Note that if this signal is emitted as part of asynchronous I/O
671 	 * in the main thread, then you should not attempt to interact with
672 	 * the user before returning from the signal handler. If you want to
673 	 * let the user decide whether or not to accept the certificate, you
674 	 * would have to return %FALSE from the signal handler on the first
675 	 * attempt, and then after the connection attempt returns a
676 	 * %G_TLS_ERROR_HANDSHAKE, you can interact with the user, and if
677 	 * the user decides to accept the certificate, remember that fact,
678 	 * create a new connection, and return %TRUE from the signal handler
679 	 * the next time.
680 	 *
681 	 * If you are doing I/O in another thread, you do not
682 	 * need to worry about this, and can simply block in the signal
683 	 * handler until the UI thread returns an answer.
684 	 *
685 	 * Params:
686 	 *     peerCert = the peer's #GTlsCertificate
687 	 *     errors = the problems with @peer_cert.
688 	 *
689 	 * Returns: %TRUE to accept @peer_cert (which will also
690 	 *     immediately end the signal emission). %FALSE to allow the signal
691 	 *     emission to continue, which will cause the handshake to fail if
692 	 *     no one else overrides it.
693 	 *
694 	 * Since: 2.48
695 	 */
696 	gulong addOnAcceptCertificate(bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
697 	{
698 		auto wrapper = new OnAcceptCertificateDelegateWrapper(dlg);
699 		wrapper.handlerId = Signals.connectData(
700 			this,
701 			"accept-certificate",
702 			cast(GCallback)&callBackAcceptCertificate,
703 			cast(void*)wrapper,
704 			cast(GClosureNotify)&callBackAcceptCertificateDestroy,
705 			connectFlags);
706 		return wrapper.handlerId;
707 	}
708 	
709 	extern(C) static int callBackAcceptCertificate(GDtlsConnection* dtlsconnectionStruct, GTlsCertificate* peerCert, GTlsCertificateFlags errors, OnAcceptCertificateDelegateWrapper wrapper)
710 	{
711 		return wrapper.dlg(ObjectG.getDObject!(TlsCertificate)(peerCert), errors, wrapper.outer);
712 	}
713 	
714 	extern(C) static void callBackAcceptCertificateDestroy(OnAcceptCertificateDelegateWrapper wrapper, GClosure* closure)
715 	{
716 		wrapper.remove(wrapper);
717 	}
718 }