gio/auto/
tls_client_connection.rs1#![allow(deprecated)]
5
6use crate::{ffi, IOStream, SocketConnectable, TlsCertificateFlags, TlsConnection};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GTlsClientConnection")]
16 pub struct TlsClientConnection(Interface<ffi::GTlsClientConnection, ffi::GTlsClientConnectionInterface>) @requires TlsConnection, IOStream;
17
18 match fn {
19 type_ => || ffi::g_tls_client_connection_get_type(),
20 }
21}
22
23impl TlsClientConnection {
24 pub const NONE: Option<&'static TlsClientConnection> = None;
25
26 #[doc(alias = "g_tls_client_connection_new")]
27 pub fn new(
28 base_io_stream: &impl IsA<IOStream>,
29 server_identity: Option<&impl IsA<SocketConnectable>>,
30 ) -> Result<TlsClientConnection, glib::Error> {
31 unsafe {
32 let mut error = std::ptr::null_mut();
33 let ret = ffi::g_tls_client_connection_new(
34 base_io_stream.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
47mod sealed {
48 pub trait Sealed {}
49 impl<T: super::IsA<super::TlsClientConnection>> Sealed for T {}
50}
51
52pub trait TlsClientConnectionExt: IsA<TlsClientConnection> + sealed::Sealed + 'static {
53 #[doc(alias = "g_tls_client_connection_copy_session_state")]
54 fn copy_session_state(&self, source: &impl IsA<TlsClientConnection>) {
55 unsafe {
56 ffi::g_tls_client_connection_copy_session_state(
57 self.as_ref().to_glib_none().0,
58 source.as_ref().to_glib_none().0,
59 );
60 }
61 }
62
63 #[doc(alias = "g_tls_client_connection_get_accepted_cas")]
64 #[doc(alias = "get_accepted_cas")]
65 #[doc(alias = "accepted-cas")]
66 fn accepted_cas(&self) -> Vec<glib::ByteArray> {
67 unsafe {
68 FromGlibPtrContainer::from_glib_full(ffi::g_tls_client_connection_get_accepted_cas(
69 self.as_ref().to_glib_none().0,
70 ))
71 }
72 }
73
74 #[doc(alias = "g_tls_client_connection_get_server_identity")]
75 #[doc(alias = "get_server_identity")]
76 #[doc(alias = "server-identity")]
77 fn server_identity(&self) -> Option<SocketConnectable> {
78 unsafe {
79 from_glib_none(ffi::g_tls_client_connection_get_server_identity(
80 self.as_ref().to_glib_none().0,
81 ))
82 }
83 }
84
85 #[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
86 #[allow(deprecated)]
87 #[doc(alias = "g_tls_client_connection_get_validation_flags")]
88 #[doc(alias = "get_validation_flags")]
89 #[doc(alias = "validation-flags")]
90 fn validation_flags(&self) -> TlsCertificateFlags {
91 unsafe {
92 from_glib(ffi::g_tls_client_connection_get_validation_flags(
93 self.as_ref().to_glib_none().0,
94 ))
95 }
96 }
97
98 #[doc(alias = "g_tls_client_connection_set_server_identity")]
99 #[doc(alias = "server-identity")]
100 fn set_server_identity(&self, identity: &impl IsA<SocketConnectable>) {
101 unsafe {
102 ffi::g_tls_client_connection_set_server_identity(
103 self.as_ref().to_glib_none().0,
104 identity.as_ref().to_glib_none().0,
105 );
106 }
107 }
108
109 #[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
110 #[allow(deprecated)]
111 #[doc(alias = "g_tls_client_connection_set_validation_flags")]
112 #[doc(alias = "validation-flags")]
113 fn set_validation_flags(&self, flags: TlsCertificateFlags) {
114 unsafe {
115 ffi::g_tls_client_connection_set_validation_flags(
116 self.as_ref().to_glib_none().0,
117 flags.into_glib(),
118 );
119 }
120 }
121
122 #[doc(alias = "accepted-cas")]
123 fn connect_accepted_cas_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
124 unsafe extern "C" fn notify_accepted_cas_trampoline<
125 P: IsA<TlsClientConnection>,
126 F: Fn(&P) + 'static,
127 >(
128 this: *mut ffi::GTlsClientConnection,
129 _param_spec: glib::ffi::gpointer,
130 f: glib::ffi::gpointer,
131 ) {
132 let f: &F = &*(f as *const F);
133 f(TlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
134 }
135 unsafe {
136 let f: Box_<F> = Box_::new(f);
137 connect_raw(
138 self.as_ptr() as *mut _,
139 b"notify::accepted-cas\0".as_ptr() as *const _,
140 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
141 notify_accepted_cas_trampoline::<Self, F> as *const (),
142 )),
143 Box_::into_raw(f),
144 )
145 }
146 }
147
148 #[doc(alias = "server-identity")]
149 fn connect_server_identity_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
150 unsafe extern "C" fn notify_server_identity_trampoline<
151 P: IsA<TlsClientConnection>,
152 F: Fn(&P) + 'static,
153 >(
154 this: *mut ffi::GTlsClientConnection,
155 _param_spec: glib::ffi::gpointer,
156 f: glib::ffi::gpointer,
157 ) {
158 let f: &F = &*(f as *const F);
159 f(TlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
160 }
161 unsafe {
162 let f: Box_<F> = Box_::new(f);
163 connect_raw(
164 self.as_ptr() as *mut _,
165 b"notify::server-identity\0".as_ptr() as *const _,
166 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
167 notify_server_identity_trampoline::<Self, F> as *const (),
168 )),
169 Box_::into_raw(f),
170 )
171 }
172 }
173
174 #[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
175 #[doc(alias = "validation-flags")]
176 fn connect_validation_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
177 unsafe extern "C" fn notify_validation_flags_trampoline<
178 P: IsA<TlsClientConnection>,
179 F: Fn(&P) + 'static,
180 >(
181 this: *mut ffi::GTlsClientConnection,
182 _param_spec: glib::ffi::gpointer,
183 f: glib::ffi::gpointer,
184 ) {
185 let f: &F = &*(f as *const F);
186 f(TlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
187 }
188 unsafe {
189 let f: Box_<F> = Box_::new(f);
190 connect_raw(
191 self.as_ptr() as *mut _,
192 b"notify::validation-flags\0".as_ptr() as *const _,
193 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
194 notify_validation_flags_trampoline::<Self, F> as *const (),
195 )),
196 Box_::into_raw(f),
197 )
198 }
199 }
200}
201
202impl<O: IsA<TlsClientConnection>> TlsClientConnectionExt for O {}