gio/auto/
dtls_client_connection.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4#![allow(deprecated)]
5
6use crate::{ffi, DatagramBased, DtlsConnection, SocketConnectable, TlsCertificateFlags};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GDtlsClientConnection")]
16    pub struct DtlsClientConnection(Interface<ffi::GDtlsClientConnection, ffi::GDtlsClientConnectionInterface>) @requires DatagramBased, DtlsConnection;
17
18    match fn {
19        type_ => || ffi::g_dtls_client_connection_get_type(),
20    }
21}
22
23impl DtlsClientConnection {
24    pub const NONE: Option<&'static DtlsClientConnection> = None;
25
26    #[doc(alias = "g_dtls_client_connection_new")]
27    pub fn new(
28        base_socket: &impl IsA<DatagramBased>,
29        server_identity: Option<&impl IsA<SocketConnectable>>,
30    ) -> Result<DtlsClientConnection, glib::Error> {
31        unsafe {
32            let mut error = std::ptr::null_mut();
33            let ret = ffi::g_dtls_client_connection_new(
34                base_socket.as_ref().to_glib_none().0,
35                server_identity.map(|p| p.as_ref()).to_glib_none().0,
36                &mut error,
37            );
38            if error.is_null() {
39                Ok(from_glib_full(ret))
40            } else {
41                Err(from_glib_full(error))
42            }
43        }
44    }
45}
46
47pub trait DtlsClientConnectionExt: IsA<DtlsClientConnection> + 'static {
48    #[doc(alias = "g_dtls_client_connection_get_accepted_cas")]
49    #[doc(alias = "get_accepted_cas")]
50    #[doc(alias = "accepted-cas")]
51    fn accepted_cas(&self) -> Vec<glib::ByteArray> {
52        unsafe {
53            FromGlibPtrContainer::from_glib_full(ffi::g_dtls_client_connection_get_accepted_cas(
54                self.as_ref().to_glib_none().0,
55            ))
56        }
57    }
58
59    #[doc(alias = "g_dtls_client_connection_get_server_identity")]
60    #[doc(alias = "get_server_identity")]
61    #[doc(alias = "server-identity")]
62    fn server_identity(&self) -> SocketConnectable {
63        unsafe {
64            from_glib_none(ffi::g_dtls_client_connection_get_server_identity(
65                self.as_ref().to_glib_none().0,
66            ))
67        }
68    }
69
70    #[cfg_attr(feature = "v2_74", deprecated = "Since 2.74")]
71    #[allow(deprecated)]
72    #[doc(alias = "g_dtls_client_connection_get_validation_flags")]
73    #[doc(alias = "get_validation_flags")]
74    #[doc(alias = "validation-flags")]
75    fn validation_flags(&self) -> TlsCertificateFlags {
76        unsafe {
77            from_glib(ffi::g_dtls_client_connection_get_validation_flags(
78                self.as_ref().to_glib_none().0,
79            ))
80        }
81    }
82
83    #[doc(alias = "g_dtls_client_connection_set_server_identity")]
84    #[doc(alias = "server-identity")]
85    fn set_server_identity(&self, identity: &impl IsA<SocketConnectable>) {
86        unsafe {
87            ffi::g_dtls_client_connection_set_server_identity(
88                self.as_ref().to_glib_none().0,
89                identity.as_ref().to_glib_none().0,
90            );
91        }
92    }
93
94    #[cfg_attr(feature = "v2_74", deprecated = "Since 2.74")]
95    #[allow(deprecated)]
96    #[doc(alias = "g_dtls_client_connection_set_validation_flags")]
97    #[doc(alias = "validation-flags")]
98    fn set_validation_flags(&self, flags: TlsCertificateFlags) {
99        unsafe {
100            ffi::g_dtls_client_connection_set_validation_flags(
101                self.as_ref().to_glib_none().0,
102                flags.into_glib(),
103            );
104        }
105    }
106
107    #[doc(alias = "accepted-cas")]
108    fn connect_accepted_cas_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
109        unsafe extern "C" fn notify_accepted_cas_trampoline<
110            P: IsA<DtlsClientConnection>,
111            F: Fn(&P) + 'static,
112        >(
113            this: *mut ffi::GDtlsClientConnection,
114            _param_spec: glib::ffi::gpointer,
115            f: glib::ffi::gpointer,
116        ) {
117            let f: &F = &*(f as *const F);
118            f(DtlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
119        }
120        unsafe {
121            let f: Box_<F> = Box_::new(f);
122            connect_raw(
123                self.as_ptr() as *mut _,
124                c"notify::accepted-cas".as_ptr() as *const _,
125                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
126                    notify_accepted_cas_trampoline::<Self, F> as *const (),
127                )),
128                Box_::into_raw(f),
129            )
130        }
131    }
132
133    #[doc(alias = "server-identity")]
134    fn connect_server_identity_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
135        unsafe extern "C" fn notify_server_identity_trampoline<
136            P: IsA<DtlsClientConnection>,
137            F: Fn(&P) + 'static,
138        >(
139            this: *mut ffi::GDtlsClientConnection,
140            _param_spec: glib::ffi::gpointer,
141            f: glib::ffi::gpointer,
142        ) {
143            let f: &F = &*(f as *const F);
144            f(DtlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
145        }
146        unsafe {
147            let f: Box_<F> = Box_::new(f);
148            connect_raw(
149                self.as_ptr() as *mut _,
150                c"notify::server-identity".as_ptr() as *const _,
151                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
152                    notify_server_identity_trampoline::<Self, F> as *const (),
153                )),
154                Box_::into_raw(f),
155            )
156        }
157    }
158
159    #[cfg_attr(feature = "v2_74", deprecated = "Since 2.74")]
160    #[doc(alias = "validation-flags")]
161    fn connect_validation_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
162        unsafe extern "C" fn notify_validation_flags_trampoline<
163            P: IsA<DtlsClientConnection>,
164            F: Fn(&P) + 'static,
165        >(
166            this: *mut ffi::GDtlsClientConnection,
167            _param_spec: glib::ffi::gpointer,
168            f: glib::ffi::gpointer,
169        ) {
170            let f: &F = &*(f as *const F);
171            f(DtlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
172        }
173        unsafe {
174            let f: Box_<F> = Box_::new(f);
175            connect_raw(
176                self.as_ptr() as *mut _,
177                c"notify::validation-flags".as_ptr() as *const _,
178                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
179                    notify_validation_flags_trampoline::<Self, F> as *const (),
180                )),
181                Box_::into_raw(f),
182            )
183        }
184    }
185}
186
187impl<O: IsA<DtlsClientConnection>> DtlsClientConnectionExt for O {}