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