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 
5 use crate::IOStream;
6 use crate::SocketConnectable;
7 use crate::TlsCertificateFlags;
8 use crate::TlsConnection;
9 use glib::object::Cast;
10 use glib::object::IsA;
11 use glib::signal::connect_raw;
12 use glib::signal::SignalHandlerId;
13 use glib::translate::*;
14 use std::boxed::Box as Box_;
15 use std::fmt;
16 use std::mem::transmute;
17 use std::ptr;
18 
19 glib::wrapper! {
20     #[doc(alias = "GTlsClientConnection")]
21     pub struct TlsClientConnection(Interface<ffi::GTlsClientConnection, ffi::GTlsClientConnectionInterface>) @requires TlsConnection, IOStream;
22 
23     match fn {
24         type_ => || ffi::g_tls_client_connection_get_type(),
25     }
26 }
27 
28 impl TlsClientConnection {
29     #[doc(alias = "g_tls_client_connection_new")]
new<P: IsA<IOStream>, Q: IsA<SocketConnectable>>( base_io_stream: &P, server_identity: Option<&Q>, ) -> Result<TlsClientConnection, glib::Error>30     pub fn new<P: IsA<IOStream>, Q: IsA<SocketConnectable>>(
31         base_io_stream: &P,
32         server_identity: Option<&Q>,
33     ) -> Result<TlsClientConnection, glib::Error> {
34         unsafe {
35             let mut error = ptr::null_mut();
36             let ret = ffi::g_tls_client_connection_new(
37                 base_io_stream.as_ref().to_glib_none().0,
38                 server_identity.map(|p| p.as_ref()).to_glib_none().0,
39                 &mut error,
40             );
41             if error.is_null() {
42                 Ok(from_glib_full(ret))
43             } else {
44                 Err(from_glib_full(error))
45             }
46         }
47     }
48 }
49 
50 pub const NONE_TLS_CLIENT_CONNECTION: Option<&TlsClientConnection> = None;
51 
52 pub trait TlsClientConnectionExt: 'static {
53     #[doc(alias = "g_tls_client_connection_copy_session_state")]
copy_session_state<P: IsA<TlsClientConnection>>(&self, source: &P)54     fn copy_session_state<P: IsA<TlsClientConnection>>(&self, source: &P);
55 
56     #[doc(alias = "g_tls_client_connection_get_accepted_cas")]
57     #[doc(alias = "get_accepted_cas")]
accepted_cas(&self) -> Vec<glib::ByteArray>58     fn accepted_cas(&self) -> Vec<glib::ByteArray>;
59 
60     #[doc(alias = "g_tls_client_connection_get_server_identity")]
61     #[doc(alias = "get_server_identity")]
server_identity(&self) -> Option<SocketConnectable>62     fn server_identity(&self) -> Option<SocketConnectable>;
63 
64     #[cfg_attr(feature = "v2_56", deprecated = "Since 2.56")]
65     #[doc(alias = "g_tls_client_connection_get_use_ssl3")]
66     #[doc(alias = "get_use_ssl3")]
uses_ssl3(&self) -> bool67     fn uses_ssl3(&self) -> bool;
68 
69     #[doc(alias = "g_tls_client_connection_get_validation_flags")]
70     #[doc(alias = "get_validation_flags")]
validation_flags(&self) -> TlsCertificateFlags71     fn validation_flags(&self) -> TlsCertificateFlags;
72 
73     #[doc(alias = "g_tls_client_connection_set_server_identity")]
set_server_identity<P: IsA<SocketConnectable>>(&self, identity: &P)74     fn set_server_identity<P: IsA<SocketConnectable>>(&self, identity: &P);
75 
76     #[cfg_attr(feature = "v2_56", deprecated = "Since 2.56")]
77     #[doc(alias = "g_tls_client_connection_set_use_ssl3")]
set_use_ssl3(&self, use_ssl3: bool)78     fn set_use_ssl3(&self, use_ssl3: bool);
79 
80     #[doc(alias = "g_tls_client_connection_set_validation_flags")]
set_validation_flags(&self, flags: TlsCertificateFlags)81     fn set_validation_flags(&self, flags: TlsCertificateFlags);
82 
83     #[doc(alias = "accepted-cas")]
connect_accepted_cas_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId84     fn connect_accepted_cas_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
85 
86     #[doc(alias = "server-identity")]
connect_server_identity_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId87     fn connect_server_identity_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
88 
89     #[cfg_attr(feature = "v2_56", deprecated = "Since 2.56")]
90     #[doc(alias = "use-ssl3")]
connect_use_ssl3_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId91     fn connect_use_ssl3_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
92 
93     #[doc(alias = "validation-flags")]
connect_validation_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId94     fn connect_validation_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
95 }
96 
97 impl<O: IsA<TlsClientConnection>> TlsClientConnectionExt for O {
copy_session_state<P: IsA<TlsClientConnection>>(&self, source: &P)98     fn copy_session_state<P: IsA<TlsClientConnection>>(&self, source: &P) {
99         unsafe {
100             ffi::g_tls_client_connection_copy_session_state(
101                 self.as_ref().to_glib_none().0,
102                 source.as_ref().to_glib_none().0,
103             );
104         }
105     }
106 
accepted_cas(&self) -> Vec<glib::ByteArray>107     fn accepted_cas(&self) -> Vec<glib::ByteArray> {
108         unsafe {
109             FromGlibPtrContainer::from_glib_full(ffi::g_tls_client_connection_get_accepted_cas(
110                 self.as_ref().to_glib_none().0,
111             ))
112         }
113     }
114 
server_identity(&self) -> Option<SocketConnectable>115     fn server_identity(&self) -> Option<SocketConnectable> {
116         unsafe {
117             from_glib_none(ffi::g_tls_client_connection_get_server_identity(
118                 self.as_ref().to_glib_none().0,
119             ))
120         }
121     }
122 
uses_ssl3(&self) -> bool123     fn uses_ssl3(&self) -> bool {
124         unsafe {
125             from_glib(ffi::g_tls_client_connection_get_use_ssl3(
126                 self.as_ref().to_glib_none().0,
127             ))
128         }
129     }
130 
validation_flags(&self) -> TlsCertificateFlags131     fn validation_flags(&self) -> TlsCertificateFlags {
132         unsafe {
133             from_glib(ffi::g_tls_client_connection_get_validation_flags(
134                 self.as_ref().to_glib_none().0,
135             ))
136         }
137     }
138 
set_server_identity<P: IsA<SocketConnectable>>(&self, identity: &P)139     fn set_server_identity<P: IsA<SocketConnectable>>(&self, identity: &P) {
140         unsafe {
141             ffi::g_tls_client_connection_set_server_identity(
142                 self.as_ref().to_glib_none().0,
143                 identity.as_ref().to_glib_none().0,
144             );
145         }
146     }
147 
set_use_ssl3(&self, use_ssl3: bool)148     fn set_use_ssl3(&self, use_ssl3: bool) {
149         unsafe {
150             ffi::g_tls_client_connection_set_use_ssl3(
151                 self.as_ref().to_glib_none().0,
152                 use_ssl3.into_glib(),
153             );
154         }
155     }
156 
set_validation_flags(&self, flags: TlsCertificateFlags)157     fn set_validation_flags(&self, flags: TlsCertificateFlags) {
158         unsafe {
159             ffi::g_tls_client_connection_set_validation_flags(
160                 self.as_ref().to_glib_none().0,
161                 flags.into_glib(),
162             );
163         }
164     }
165 
connect_accepted_cas_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId166     fn connect_accepted_cas_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
167         unsafe extern "C" fn notify_accepted_cas_trampoline<
168             P: IsA<TlsClientConnection>,
169             F: Fn(&P) + 'static,
170         >(
171             this: *mut ffi::GTlsClientConnection,
172             _param_spec: glib::ffi::gpointer,
173             f: glib::ffi::gpointer,
174         ) {
175             let f: &F = &*(f as *const F);
176             f(TlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
177         }
178         unsafe {
179             let f: Box_<F> = Box_::new(f);
180             connect_raw(
181                 self.as_ptr() as *mut _,
182                 b"notify::accepted-cas\0".as_ptr() as *const _,
183                 Some(transmute::<_, unsafe extern "C" fn()>(
184                     notify_accepted_cas_trampoline::<Self, F> as *const (),
185                 )),
186                 Box_::into_raw(f),
187             )
188         }
189     }
190 
connect_server_identity_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId191     fn connect_server_identity_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
192         unsafe extern "C" fn notify_server_identity_trampoline<
193             P: IsA<TlsClientConnection>,
194             F: Fn(&P) + 'static,
195         >(
196             this: *mut ffi::GTlsClientConnection,
197             _param_spec: glib::ffi::gpointer,
198             f: glib::ffi::gpointer,
199         ) {
200             let f: &F = &*(f as *const F);
201             f(TlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
202         }
203         unsafe {
204             let f: Box_<F> = Box_::new(f);
205             connect_raw(
206                 self.as_ptr() as *mut _,
207                 b"notify::server-identity\0".as_ptr() as *const _,
208                 Some(transmute::<_, unsafe extern "C" fn()>(
209                     notify_server_identity_trampoline::<Self, F> as *const (),
210                 )),
211                 Box_::into_raw(f),
212             )
213         }
214     }
215 
connect_use_ssl3_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId216     fn connect_use_ssl3_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
217         unsafe extern "C" fn notify_use_ssl3_trampoline<
218             P: IsA<TlsClientConnection>,
219             F: Fn(&P) + 'static,
220         >(
221             this: *mut ffi::GTlsClientConnection,
222             _param_spec: glib::ffi::gpointer,
223             f: glib::ffi::gpointer,
224         ) {
225             let f: &F = &*(f as *const F);
226             f(TlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
227         }
228         unsafe {
229             let f: Box_<F> = Box_::new(f);
230             connect_raw(
231                 self.as_ptr() as *mut _,
232                 b"notify::use-ssl3\0".as_ptr() as *const _,
233                 Some(transmute::<_, unsafe extern "C" fn()>(
234                     notify_use_ssl3_trampoline::<Self, F> as *const (),
235                 )),
236                 Box_::into_raw(f),
237             )
238         }
239     }
240 
connect_validation_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId241     fn connect_validation_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
242         unsafe extern "C" fn notify_validation_flags_trampoline<
243             P: IsA<TlsClientConnection>,
244             F: Fn(&P) + 'static,
245         >(
246             this: *mut ffi::GTlsClientConnection,
247             _param_spec: glib::ffi::gpointer,
248             f: glib::ffi::gpointer,
249         ) {
250             let f: &F = &*(f as *const F);
251             f(TlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
252         }
253         unsafe {
254             let f: Box_<F> = Box_::new(f);
255             connect_raw(
256                 self.as_ptr() as *mut _,
257                 b"notify::validation-flags\0".as_ptr() as *const _,
258                 Some(transmute::<_, unsafe extern "C" fn()>(
259                     notify_validation_flags_trampoline::<Self, F> as *const (),
260                 )),
261                 Box_::into_raw(f),
262             )
263         }
264     }
265 }
266 
267 impl fmt::Display for TlsClientConnection {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result268     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
269         f.write_str("TlsClientConnection")
270     }
271 }
272