1#![allow(deprecated)]
5
6#[cfg(feature = "v2_70")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
8use crate::TlsProtocolVersion;
9use crate::{
10 AsyncResult, Cancellable, DatagramBased, TlsCertificate, TlsCertificateFlags, TlsDatabase,
11 TlsInteraction, TlsRehandshakeMode, ffi,
12};
13use glib::{
14 object::ObjectType as _,
15 prelude::*,
16 signal::{SignalHandlerId, connect_raw},
17 translate::*,
18};
19use std::{boxed::Box as Box_, pin::Pin};
20
21glib::wrapper! {
22 #[doc(alias = "GDtlsConnection")]
23 pub struct DtlsConnection(Interface<ffi::GDtlsConnection, ffi::GDtlsConnectionInterface>) @requires DatagramBased;
24
25 match fn {
26 type_ => || ffi::g_dtls_connection_get_type(),
27 }
28}
29
30impl DtlsConnection {
31 pub const NONE: Option<&'static DtlsConnection> = None;
32}
33
34pub trait DtlsConnectionExt: IsA<DtlsConnection> + 'static {
35 #[doc(alias = "g_dtls_connection_close")]
36 fn close(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<(), glib::Error> {
37 unsafe {
38 let mut error = std::ptr::null_mut();
39 let is_ok = ffi::g_dtls_connection_close(
40 self.as_ref().to_glib_none().0,
41 cancellable.map(|p| p.as_ref()).to_glib_none().0,
42 &mut error,
43 );
44 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
45 if error.is_null() {
46 Ok(())
47 } else {
48 Err(from_glib_full(error))
49 }
50 }
51 }
52
53 #[doc(alias = "g_dtls_connection_close_async")]
54 fn close_async<P: FnOnce(Result<(), glib::Error>) + 'static>(
55 &self,
56 io_priority: glib::Priority,
57 cancellable: Option<&impl IsA<Cancellable>>,
58 callback: P,
59 ) {
60 let main_context = glib::MainContext::ref_thread_default();
61 let is_main_context_owner = main_context.is_owner();
62 let has_acquired_main_context = (!is_main_context_owner)
63 .then(|| main_context.acquire().ok())
64 .flatten();
65 assert!(
66 is_main_context_owner || has_acquired_main_context.is_some(),
67 "Async operations only allowed if the thread is owning the MainContext"
68 );
69
70 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
71 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
72 unsafe extern "C" fn close_async_trampoline<
73 P: FnOnce(Result<(), glib::Error>) + 'static,
74 >(
75 _source_object: *mut glib::gobject_ffi::GObject,
76 res: *mut crate::ffi::GAsyncResult,
77 user_data: glib::ffi::gpointer,
78 ) {
79 unsafe {
80 let mut error = std::ptr::null_mut();
81 ffi::g_dtls_connection_close_finish(_source_object as *mut _, res, &mut error);
82 let result = if error.is_null() {
83 Ok(())
84 } else {
85 Err(from_glib_full(error))
86 };
87 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
88 Box_::from_raw(user_data as *mut _);
89 let callback: P = callback.into_inner();
90 callback(result);
91 }
92 }
93 let callback = close_async_trampoline::<P>;
94 unsafe {
95 ffi::g_dtls_connection_close_async(
96 self.as_ref().to_glib_none().0,
97 io_priority.into_glib(),
98 cancellable.map(|p| p.as_ref()).to_glib_none().0,
99 Some(callback),
100 Box_::into_raw(user_data) as *mut _,
101 );
102 }
103 }
104
105 fn close_future(
106 &self,
107 io_priority: glib::Priority,
108 ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
109 Box_::pin(crate::GioFuture::new(
110 self,
111 move |obj, cancellable, send| {
112 obj.close_async(io_priority, Some(cancellable), move |res| {
113 send.resolve(res);
114 });
115 },
116 ))
117 }
118
119 #[doc(alias = "g_dtls_connection_emit_accept_certificate")]
120 fn emit_accept_certificate(
121 &self,
122 peer_cert: &impl IsA<TlsCertificate>,
123 errors: TlsCertificateFlags,
124 ) -> bool {
125 unsafe {
126 from_glib(ffi::g_dtls_connection_emit_accept_certificate(
127 self.as_ref().to_glib_none().0,
128 peer_cert.as_ref().to_glib_none().0,
129 errors.into_glib(),
130 ))
131 }
132 }
133
134 #[doc(alias = "g_dtls_connection_get_certificate")]
135 #[doc(alias = "get_certificate")]
136 fn certificate(&self) -> Option<TlsCertificate> {
137 unsafe {
138 from_glib_none(ffi::g_dtls_connection_get_certificate(
139 self.as_ref().to_glib_none().0,
140 ))
141 }
142 }
143
144 #[cfg(feature = "v2_70")]
145 #[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
146 #[doc(alias = "g_dtls_connection_get_ciphersuite_name")]
147 #[doc(alias = "get_ciphersuite_name")]
148 #[doc(alias = "ciphersuite-name")]
149 fn ciphersuite_name(&self) -> Option<glib::GString> {
150 unsafe {
151 from_glib_full(ffi::g_dtls_connection_get_ciphersuite_name(
152 self.as_ref().to_glib_none().0,
153 ))
154 }
155 }
156
157 #[doc(alias = "g_dtls_connection_get_database")]
158 #[doc(alias = "get_database")]
159 fn database(&self) -> Option<TlsDatabase> {
160 unsafe {
161 from_glib_none(ffi::g_dtls_connection_get_database(
162 self.as_ref().to_glib_none().0,
163 ))
164 }
165 }
166
167 #[doc(alias = "g_dtls_connection_get_interaction")]
168 #[doc(alias = "get_interaction")]
169 fn interaction(&self) -> Option<TlsInteraction> {
170 unsafe {
171 from_glib_none(ffi::g_dtls_connection_get_interaction(
172 self.as_ref().to_glib_none().0,
173 ))
174 }
175 }
176
177 #[cfg(feature = "v2_60")]
178 #[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
179 #[doc(alias = "g_dtls_connection_get_negotiated_protocol")]
180 #[doc(alias = "get_negotiated_protocol")]
181 #[doc(alias = "negotiated-protocol")]
182 fn negotiated_protocol(&self) -> Option<glib::GString> {
183 unsafe {
184 from_glib_none(ffi::g_dtls_connection_get_negotiated_protocol(
185 self.as_ref().to_glib_none().0,
186 ))
187 }
188 }
189
190 #[doc(alias = "g_dtls_connection_get_peer_certificate")]
191 #[doc(alias = "get_peer_certificate")]
192 #[doc(alias = "peer-certificate")]
193 fn peer_certificate(&self) -> Option<TlsCertificate> {
194 unsafe {
195 from_glib_none(ffi::g_dtls_connection_get_peer_certificate(
196 self.as_ref().to_glib_none().0,
197 ))
198 }
199 }
200
201 #[doc(alias = "g_dtls_connection_get_peer_certificate_errors")]
202 #[doc(alias = "get_peer_certificate_errors")]
203 #[doc(alias = "peer-certificate-errors")]
204 fn peer_certificate_errors(&self) -> TlsCertificateFlags {
205 unsafe {
206 from_glib(ffi::g_dtls_connection_get_peer_certificate_errors(
207 self.as_ref().to_glib_none().0,
208 ))
209 }
210 }
211
212 #[cfg(feature = "v2_70")]
213 #[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
214 #[doc(alias = "g_dtls_connection_get_protocol_version")]
215 #[doc(alias = "get_protocol_version")]
216 #[doc(alias = "protocol-version")]
217 fn protocol_version(&self) -> TlsProtocolVersion {
218 unsafe {
219 from_glib(ffi::g_dtls_connection_get_protocol_version(
220 self.as_ref().to_glib_none().0,
221 ))
222 }
223 }
224
225 #[cfg_attr(feature = "v2_64", deprecated = "Since 2.64")]
226 #[allow(deprecated)]
227 #[doc(alias = "g_dtls_connection_get_rehandshake_mode")]
228 #[doc(alias = "get_rehandshake_mode")]
229 #[doc(alias = "rehandshake-mode")]
230 fn rehandshake_mode(&self) -> TlsRehandshakeMode {
231 unsafe {
232 from_glib(ffi::g_dtls_connection_get_rehandshake_mode(
233 self.as_ref().to_glib_none().0,
234 ))
235 }
236 }
237
238 #[doc(alias = "g_dtls_connection_get_require_close_notify")]
239 #[doc(alias = "get_require_close_notify")]
240 #[doc(alias = "require-close-notify")]
241 fn requires_close_notify(&self) -> bool {
242 unsafe {
243 from_glib(ffi::g_dtls_connection_get_require_close_notify(
244 self.as_ref().to_glib_none().0,
245 ))
246 }
247 }
248
249 #[doc(alias = "g_dtls_connection_handshake")]
250 fn handshake(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<(), glib::Error> {
251 unsafe {
252 let mut error = std::ptr::null_mut();
253 let is_ok = ffi::g_dtls_connection_handshake(
254 self.as_ref().to_glib_none().0,
255 cancellable.map(|p| p.as_ref()).to_glib_none().0,
256 &mut error,
257 );
258 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
259 if error.is_null() {
260 Ok(())
261 } else {
262 Err(from_glib_full(error))
263 }
264 }
265 }
266
267 #[doc(alias = "g_dtls_connection_handshake_async")]
268 fn handshake_async<P: FnOnce(Result<(), glib::Error>) + 'static>(
269 &self,
270 io_priority: glib::Priority,
271 cancellable: Option<&impl IsA<Cancellable>>,
272 callback: P,
273 ) {
274 let main_context = glib::MainContext::ref_thread_default();
275 let is_main_context_owner = main_context.is_owner();
276 let has_acquired_main_context = (!is_main_context_owner)
277 .then(|| main_context.acquire().ok())
278 .flatten();
279 assert!(
280 is_main_context_owner || has_acquired_main_context.is_some(),
281 "Async operations only allowed if the thread is owning the MainContext"
282 );
283
284 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
285 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
286 unsafe extern "C" fn handshake_async_trampoline<
287 P: FnOnce(Result<(), glib::Error>) + 'static,
288 >(
289 _source_object: *mut glib::gobject_ffi::GObject,
290 res: *mut crate::ffi::GAsyncResult,
291 user_data: glib::ffi::gpointer,
292 ) {
293 unsafe {
294 let mut error = std::ptr::null_mut();
295 ffi::g_dtls_connection_handshake_finish(_source_object as *mut _, res, &mut error);
296 let result = if error.is_null() {
297 Ok(())
298 } else {
299 Err(from_glib_full(error))
300 };
301 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
302 Box_::from_raw(user_data as *mut _);
303 let callback: P = callback.into_inner();
304 callback(result);
305 }
306 }
307 let callback = handshake_async_trampoline::<P>;
308 unsafe {
309 ffi::g_dtls_connection_handshake_async(
310 self.as_ref().to_glib_none().0,
311 io_priority.into_glib(),
312 cancellable.map(|p| p.as_ref()).to_glib_none().0,
313 Some(callback),
314 Box_::into_raw(user_data) as *mut _,
315 );
316 }
317 }
318
319 fn handshake_future(
320 &self,
321 io_priority: glib::Priority,
322 ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
323 Box_::pin(crate::GioFuture::new(
324 self,
325 move |obj, cancellable, send| {
326 obj.handshake_async(io_priority, Some(cancellable), move |res| {
327 send.resolve(res);
328 });
329 },
330 ))
331 }
332
333 #[cfg(feature = "v2_60")]
334 #[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
335 #[doc(alias = "g_dtls_connection_set_advertised_protocols")]
336 #[doc(alias = "advertised-protocols")]
337 fn set_advertised_protocols(&self, protocols: &[&str]) {
338 unsafe {
339 ffi::g_dtls_connection_set_advertised_protocols(
340 self.as_ref().to_glib_none().0,
341 protocols.to_glib_none().0,
342 );
343 }
344 }
345
346 #[doc(alias = "g_dtls_connection_set_certificate")]
347 #[doc(alias = "certificate")]
348 fn set_certificate(&self, certificate: &impl IsA<TlsCertificate>) {
349 unsafe {
350 ffi::g_dtls_connection_set_certificate(
351 self.as_ref().to_glib_none().0,
352 certificate.as_ref().to_glib_none().0,
353 );
354 }
355 }
356
357 #[doc(alias = "g_dtls_connection_set_database")]
358 #[doc(alias = "database")]
359 fn set_database(&self, database: Option<&impl IsA<TlsDatabase>>) {
360 unsafe {
361 ffi::g_dtls_connection_set_database(
362 self.as_ref().to_glib_none().0,
363 database.map(|p| p.as_ref()).to_glib_none().0,
364 );
365 }
366 }
367
368 #[doc(alias = "g_dtls_connection_set_interaction")]
369 #[doc(alias = "interaction")]
370 fn set_interaction(&self, interaction: Option<&impl IsA<TlsInteraction>>) {
371 unsafe {
372 ffi::g_dtls_connection_set_interaction(
373 self.as_ref().to_glib_none().0,
374 interaction.map(|p| p.as_ref()).to_glib_none().0,
375 );
376 }
377 }
378
379 #[cfg_attr(feature = "v2_60", deprecated = "Since 2.60")]
380 #[allow(deprecated)]
381 #[doc(alias = "g_dtls_connection_set_rehandshake_mode")]
382 #[doc(alias = "rehandshake-mode")]
383 fn set_rehandshake_mode(&self, mode: TlsRehandshakeMode) {
384 unsafe {
385 ffi::g_dtls_connection_set_rehandshake_mode(
386 self.as_ref().to_glib_none().0,
387 mode.into_glib(),
388 );
389 }
390 }
391
392 #[doc(alias = "g_dtls_connection_set_require_close_notify")]
393 #[doc(alias = "require-close-notify")]
394 fn set_require_close_notify(&self, require_close_notify: bool) {
395 unsafe {
396 ffi::g_dtls_connection_set_require_close_notify(
397 self.as_ref().to_glib_none().0,
398 require_close_notify.into_glib(),
399 );
400 }
401 }
402
403 #[doc(alias = "g_dtls_connection_shutdown")]
404 fn shutdown(
405 &self,
406 shutdown_read: bool,
407 shutdown_write: bool,
408 cancellable: Option<&impl IsA<Cancellable>>,
409 ) -> Result<(), glib::Error> {
410 unsafe {
411 let mut error = std::ptr::null_mut();
412 let is_ok = ffi::g_dtls_connection_shutdown(
413 self.as_ref().to_glib_none().0,
414 shutdown_read.into_glib(),
415 shutdown_write.into_glib(),
416 cancellable.map(|p| p.as_ref()).to_glib_none().0,
417 &mut error,
418 );
419 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
420 if error.is_null() {
421 Ok(())
422 } else {
423 Err(from_glib_full(error))
424 }
425 }
426 }
427
428 #[doc(alias = "g_dtls_connection_shutdown_async")]
429 fn shutdown_async<P: FnOnce(Result<(), glib::Error>) + 'static>(
430 &self,
431 shutdown_read: bool,
432 shutdown_write: bool,
433 io_priority: glib::Priority,
434 cancellable: Option<&impl IsA<Cancellable>>,
435 callback: P,
436 ) {
437 let main_context = glib::MainContext::ref_thread_default();
438 let is_main_context_owner = main_context.is_owner();
439 let has_acquired_main_context = (!is_main_context_owner)
440 .then(|| main_context.acquire().ok())
441 .flatten();
442 assert!(
443 is_main_context_owner || has_acquired_main_context.is_some(),
444 "Async operations only allowed if the thread is owning the MainContext"
445 );
446
447 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
448 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
449 unsafe extern "C" fn shutdown_async_trampoline<
450 P: FnOnce(Result<(), glib::Error>) + 'static,
451 >(
452 _source_object: *mut glib::gobject_ffi::GObject,
453 res: *mut crate::ffi::GAsyncResult,
454 user_data: glib::ffi::gpointer,
455 ) {
456 unsafe {
457 let mut error = std::ptr::null_mut();
458 ffi::g_dtls_connection_shutdown_finish(_source_object as *mut _, res, &mut error);
459 let result = if error.is_null() {
460 Ok(())
461 } else {
462 Err(from_glib_full(error))
463 };
464 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
465 Box_::from_raw(user_data as *mut _);
466 let callback: P = callback.into_inner();
467 callback(result);
468 }
469 }
470 let callback = shutdown_async_trampoline::<P>;
471 unsafe {
472 ffi::g_dtls_connection_shutdown_async(
473 self.as_ref().to_glib_none().0,
474 shutdown_read.into_glib(),
475 shutdown_write.into_glib(),
476 io_priority.into_glib(),
477 cancellable.map(|p| p.as_ref()).to_glib_none().0,
478 Some(callback),
479 Box_::into_raw(user_data) as *mut _,
480 );
481 }
482 }
483
484 fn shutdown_future(
485 &self,
486 shutdown_read: bool,
487 shutdown_write: bool,
488 io_priority: glib::Priority,
489 ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
490 Box_::pin(crate::GioFuture::new(
491 self,
492 move |obj, cancellable, send| {
493 obj.shutdown_async(
494 shutdown_read,
495 shutdown_write,
496 io_priority,
497 Some(cancellable),
498 move |res| {
499 send.resolve(res);
500 },
501 );
502 },
503 ))
504 }
505
506 #[cfg(feature = "v2_60")]
507 #[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
508 #[doc(alias = "advertised-protocols")]
509 fn advertised_protocols(&self) -> Vec<glib::GString> {
510 ObjectExt::property(self.as_ref(), "advertised-protocols")
511 }
512
513 #[doc(alias = "base-socket")]
514 fn base_socket(&self) -> Option<DatagramBased> {
515 ObjectExt::property(self.as_ref(), "base-socket")
516 }
517
518 #[doc(alias = "accept-certificate")]
519 fn connect_accept_certificate<
520 F: Fn(&Self, &TlsCertificate, TlsCertificateFlags) -> bool + 'static,
521 >(
522 &self,
523 f: F,
524 ) -> SignalHandlerId {
525 unsafe extern "C" fn accept_certificate_trampoline<
526 P: IsA<DtlsConnection>,
527 F: Fn(&P, &TlsCertificate, TlsCertificateFlags) -> bool + 'static,
528 >(
529 this: *mut ffi::GDtlsConnection,
530 peer_cert: *mut ffi::GTlsCertificate,
531 errors: ffi::GTlsCertificateFlags,
532 f: glib::ffi::gpointer,
533 ) -> glib::ffi::gboolean {
534 unsafe {
535 let f: &F = &*(f as *const F);
536 f(
537 DtlsConnection::from_glib_borrow(this).unsafe_cast_ref(),
538 &from_glib_borrow(peer_cert),
539 from_glib(errors),
540 )
541 .into_glib()
542 }
543 }
544 unsafe {
545 let f: Box_<F> = Box_::new(f);
546 connect_raw(
547 self.as_ptr() as *mut _,
548 c"accept-certificate".as_ptr(),
549 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
550 accept_certificate_trampoline::<Self, F> as *const (),
551 )),
552 Box_::into_raw(f),
553 )
554 }
555 }
556
557 #[cfg(feature = "v2_60")]
558 #[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
559 #[doc(alias = "advertised-protocols")]
560 fn connect_advertised_protocols_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
561 unsafe extern "C" fn notify_advertised_protocols_trampoline<
562 P: IsA<DtlsConnection>,
563 F: Fn(&P) + 'static,
564 >(
565 this: *mut ffi::GDtlsConnection,
566 _param_spec: glib::ffi::gpointer,
567 f: glib::ffi::gpointer,
568 ) {
569 unsafe {
570 let f: &F = &*(f as *const F);
571 f(DtlsConnection::from_glib_borrow(this).unsafe_cast_ref())
572 }
573 }
574 unsafe {
575 let f: Box_<F> = Box_::new(f);
576 connect_raw(
577 self.as_ptr() as *mut _,
578 c"notify::advertised-protocols".as_ptr(),
579 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
580 notify_advertised_protocols_trampoline::<Self, F> as *const (),
581 )),
582 Box_::into_raw(f),
583 )
584 }
585 }
586
587 #[doc(alias = "certificate")]
588 fn connect_certificate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
589 unsafe extern "C" fn notify_certificate_trampoline<
590 P: IsA<DtlsConnection>,
591 F: Fn(&P) + 'static,
592 >(
593 this: *mut ffi::GDtlsConnection,
594 _param_spec: glib::ffi::gpointer,
595 f: glib::ffi::gpointer,
596 ) {
597 unsafe {
598 let f: &F = &*(f as *const F);
599 f(DtlsConnection::from_glib_borrow(this).unsafe_cast_ref())
600 }
601 }
602 unsafe {
603 let f: Box_<F> = Box_::new(f);
604 connect_raw(
605 self.as_ptr() as *mut _,
606 c"notify::certificate".as_ptr(),
607 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
608 notify_certificate_trampoline::<Self, F> as *const (),
609 )),
610 Box_::into_raw(f),
611 )
612 }
613 }
614
615 #[cfg(feature = "v2_70")]
616 #[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
617 #[doc(alias = "ciphersuite-name")]
618 fn connect_ciphersuite_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
619 unsafe extern "C" fn notify_ciphersuite_name_trampoline<
620 P: IsA<DtlsConnection>,
621 F: Fn(&P) + 'static,
622 >(
623 this: *mut ffi::GDtlsConnection,
624 _param_spec: glib::ffi::gpointer,
625 f: glib::ffi::gpointer,
626 ) {
627 unsafe {
628 let f: &F = &*(f as *const F);
629 f(DtlsConnection::from_glib_borrow(this).unsafe_cast_ref())
630 }
631 }
632 unsafe {
633 let f: Box_<F> = Box_::new(f);
634 connect_raw(
635 self.as_ptr() as *mut _,
636 c"notify::ciphersuite-name".as_ptr(),
637 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
638 notify_ciphersuite_name_trampoline::<Self, F> as *const (),
639 )),
640 Box_::into_raw(f),
641 )
642 }
643 }
644
645 #[doc(alias = "database")]
646 fn connect_database_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
647 unsafe extern "C" fn notify_database_trampoline<
648 P: IsA<DtlsConnection>,
649 F: Fn(&P) + 'static,
650 >(
651 this: *mut ffi::GDtlsConnection,
652 _param_spec: glib::ffi::gpointer,
653 f: glib::ffi::gpointer,
654 ) {
655 unsafe {
656 let f: &F = &*(f as *const F);
657 f(DtlsConnection::from_glib_borrow(this).unsafe_cast_ref())
658 }
659 }
660 unsafe {
661 let f: Box_<F> = Box_::new(f);
662 connect_raw(
663 self.as_ptr() as *mut _,
664 c"notify::database".as_ptr(),
665 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
666 notify_database_trampoline::<Self, F> as *const (),
667 )),
668 Box_::into_raw(f),
669 )
670 }
671 }
672
673 #[doc(alias = "interaction")]
674 fn connect_interaction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
675 unsafe extern "C" fn notify_interaction_trampoline<
676 P: IsA<DtlsConnection>,
677 F: Fn(&P) + 'static,
678 >(
679 this: *mut ffi::GDtlsConnection,
680 _param_spec: glib::ffi::gpointer,
681 f: glib::ffi::gpointer,
682 ) {
683 unsafe {
684 let f: &F = &*(f as *const F);
685 f(DtlsConnection::from_glib_borrow(this).unsafe_cast_ref())
686 }
687 }
688 unsafe {
689 let f: Box_<F> = Box_::new(f);
690 connect_raw(
691 self.as_ptr() as *mut _,
692 c"notify::interaction".as_ptr(),
693 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
694 notify_interaction_trampoline::<Self, F> as *const (),
695 )),
696 Box_::into_raw(f),
697 )
698 }
699 }
700
701 #[cfg(feature = "v2_60")]
702 #[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
703 #[doc(alias = "negotiated-protocol")]
704 fn connect_negotiated_protocol_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
705 unsafe extern "C" fn notify_negotiated_protocol_trampoline<
706 P: IsA<DtlsConnection>,
707 F: Fn(&P) + 'static,
708 >(
709 this: *mut ffi::GDtlsConnection,
710 _param_spec: glib::ffi::gpointer,
711 f: glib::ffi::gpointer,
712 ) {
713 unsafe {
714 let f: &F = &*(f as *const F);
715 f(DtlsConnection::from_glib_borrow(this).unsafe_cast_ref())
716 }
717 }
718 unsafe {
719 let f: Box_<F> = Box_::new(f);
720 connect_raw(
721 self.as_ptr() as *mut _,
722 c"notify::negotiated-protocol".as_ptr(),
723 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
724 notify_negotiated_protocol_trampoline::<Self, F> as *const (),
725 )),
726 Box_::into_raw(f),
727 )
728 }
729 }
730
731 #[doc(alias = "peer-certificate")]
732 fn connect_peer_certificate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
733 unsafe extern "C" fn notify_peer_certificate_trampoline<
734 P: IsA<DtlsConnection>,
735 F: Fn(&P) + 'static,
736 >(
737 this: *mut ffi::GDtlsConnection,
738 _param_spec: glib::ffi::gpointer,
739 f: glib::ffi::gpointer,
740 ) {
741 unsafe {
742 let f: &F = &*(f as *const F);
743 f(DtlsConnection::from_glib_borrow(this).unsafe_cast_ref())
744 }
745 }
746 unsafe {
747 let f: Box_<F> = Box_::new(f);
748 connect_raw(
749 self.as_ptr() as *mut _,
750 c"notify::peer-certificate".as_ptr(),
751 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
752 notify_peer_certificate_trampoline::<Self, F> as *const (),
753 )),
754 Box_::into_raw(f),
755 )
756 }
757 }
758
759 #[doc(alias = "peer-certificate-errors")]
760 fn connect_peer_certificate_errors_notify<F: Fn(&Self) + 'static>(
761 &self,
762 f: F,
763 ) -> SignalHandlerId {
764 unsafe extern "C" fn notify_peer_certificate_errors_trampoline<
765 P: IsA<DtlsConnection>,
766 F: Fn(&P) + 'static,
767 >(
768 this: *mut ffi::GDtlsConnection,
769 _param_spec: glib::ffi::gpointer,
770 f: glib::ffi::gpointer,
771 ) {
772 unsafe {
773 let f: &F = &*(f as *const F);
774 f(DtlsConnection::from_glib_borrow(this).unsafe_cast_ref())
775 }
776 }
777 unsafe {
778 let f: Box_<F> = Box_::new(f);
779 connect_raw(
780 self.as_ptr() as *mut _,
781 c"notify::peer-certificate-errors".as_ptr(),
782 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
783 notify_peer_certificate_errors_trampoline::<Self, F> as *const (),
784 )),
785 Box_::into_raw(f),
786 )
787 }
788 }
789
790 #[cfg(feature = "v2_70")]
791 #[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
792 #[doc(alias = "protocol-version")]
793 fn connect_protocol_version_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
794 unsafe extern "C" fn notify_protocol_version_trampoline<
795 P: IsA<DtlsConnection>,
796 F: Fn(&P) + 'static,
797 >(
798 this: *mut ffi::GDtlsConnection,
799 _param_spec: glib::ffi::gpointer,
800 f: glib::ffi::gpointer,
801 ) {
802 unsafe {
803 let f: &F = &*(f as *const F);
804 f(DtlsConnection::from_glib_borrow(this).unsafe_cast_ref())
805 }
806 }
807 unsafe {
808 let f: Box_<F> = Box_::new(f);
809 connect_raw(
810 self.as_ptr() as *mut _,
811 c"notify::protocol-version".as_ptr(),
812 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
813 notify_protocol_version_trampoline::<Self, F> as *const (),
814 )),
815 Box_::into_raw(f),
816 )
817 }
818 }
819
820 #[cfg_attr(feature = "v2_60", deprecated = "Since 2.60")]
821 #[doc(alias = "rehandshake-mode")]
822 fn connect_rehandshake_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
823 unsafe extern "C" fn notify_rehandshake_mode_trampoline<
824 P: IsA<DtlsConnection>,
825 F: Fn(&P) + 'static,
826 >(
827 this: *mut ffi::GDtlsConnection,
828 _param_spec: glib::ffi::gpointer,
829 f: glib::ffi::gpointer,
830 ) {
831 unsafe {
832 let f: &F = &*(f as *const F);
833 f(DtlsConnection::from_glib_borrow(this).unsafe_cast_ref())
834 }
835 }
836 unsafe {
837 let f: Box_<F> = Box_::new(f);
838 connect_raw(
839 self.as_ptr() as *mut _,
840 c"notify::rehandshake-mode".as_ptr(),
841 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
842 notify_rehandshake_mode_trampoline::<Self, F> as *const (),
843 )),
844 Box_::into_raw(f),
845 )
846 }
847 }
848
849 #[doc(alias = "require-close-notify")]
850 fn connect_require_close_notify_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
851 unsafe extern "C" fn notify_require_close_notify_trampoline<
852 P: IsA<DtlsConnection>,
853 F: Fn(&P) + 'static,
854 >(
855 this: *mut ffi::GDtlsConnection,
856 _param_spec: glib::ffi::gpointer,
857 f: glib::ffi::gpointer,
858 ) {
859 unsafe {
860 let f: &F = &*(f as *const F);
861 f(DtlsConnection::from_glib_borrow(this).unsafe_cast_ref())
862 }
863 }
864 unsafe {
865 let f: Box_<F> = Box_::new(f);
866 connect_raw(
867 self.as_ptr() as *mut _,
868 c"notify::require-close-notify".as_ptr(),
869 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
870 notify_require_close_notify_trampoline::<Self, F> as *const (),
871 )),
872 Box_::into_raw(f),
873 )
874 }
875 }
876}
877
878impl<O: IsA<DtlsConnection>> DtlsConnectionExt for O {}