gio/auto/
tls_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, 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
47pub trait TlsClientConnectionExt: IsA<TlsClientConnection> + 'static {
48    #[doc(alias = "g_tls_client_connection_copy_session_state")]
49    fn copy_session_state(&self, source: &impl IsA<TlsClientConnection>) {
50        unsafe {
51            ffi::g_tls_client_connection_copy_session_state(
52                self.as_ref().to_glib_none().0,
53                source.as_ref().to_glib_none().0,
54            );
55        }
56    }
57
58    #[doc(alias = "g_tls_client_connection_get_accepted_cas")]
59    #[doc(alias = "get_accepted_cas")]
60    #[doc(alias = "accepted-cas")]
61    fn accepted_cas(&self) -> Vec<glib::ByteArray> {
62        unsafe {
63            FromGlibPtrContainer::from_glib_full(ffi::g_tls_client_connection_get_accepted_cas(
64                self.as_ref().to_glib_none().0,
65            ))
66        }
67    }
68
69    #[doc(alias = "g_tls_client_connection_get_server_identity")]
70    #[doc(alias = "get_server_identity")]
71    #[doc(alias = "server-identity")]
72    fn server_identity(&self) -> Option<SocketConnectable> {
73        unsafe {
74            from_glib_none(ffi::g_tls_client_connection_get_server_identity(
75                self.as_ref().to_glib_none().0,
76            ))
77        }
78    }
79
80    #[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
81    #[allow(deprecated)]
82    #[doc(alias = "g_tls_client_connection_get_validation_flags")]
83    #[doc(alias = "get_validation_flags")]
84    #[doc(alias = "validation-flags")]
85    fn validation_flags(&self) -> TlsCertificateFlags {
86        unsafe {
87            from_glib(ffi::g_tls_client_connection_get_validation_flags(
88                self.as_ref().to_glib_none().0,
89            ))
90        }
91    }
92
93    #[doc(alias = "g_tls_client_connection_set_server_identity")]
94    #[doc(alias = "server-identity")]
95    fn set_server_identity(&self, identity: &impl IsA<SocketConnectable>) {
96        unsafe {
97            ffi::g_tls_client_connection_set_server_identity(
98                self.as_ref().to_glib_none().0,
99                identity.as_ref().to_glib_none().0,
100            );
101        }
102    }
103
104    #[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
105    #[allow(deprecated)]
106    #[doc(alias = "g_tls_client_connection_set_validation_flags")]
107    #[doc(alias = "validation-flags")]
108    fn set_validation_flags(&self, flags: TlsCertificateFlags) {
109        unsafe {
110            ffi::g_tls_client_connection_set_validation_flags(
111                self.as_ref().to_glib_none().0,
112                flags.into_glib(),
113            );
114        }
115    }
116
117    #[doc(alias = "accepted-cas")]
118    fn connect_accepted_cas_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
119        unsafe extern "C" fn notify_accepted_cas_trampoline<
120            P: IsA<TlsClientConnection>,
121            F: Fn(&P) + 'static,
122        >(
123            this: *mut ffi::GTlsClientConnection,
124            _param_spec: glib::ffi::gpointer,
125            f: glib::ffi::gpointer,
126        ) {
127            let f: &F = &*(f as *const F);
128            f(TlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
129        }
130        unsafe {
131            let f: Box_<F> = Box_::new(f);
132            connect_raw(
133                self.as_ptr() as *mut _,
134                c"notify::accepted-cas".as_ptr() as *const _,
135                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
136                    notify_accepted_cas_trampoline::<Self, F> as *const (),
137                )),
138                Box_::into_raw(f),
139            )
140        }
141    }
142
143    #[doc(alias = "server-identity")]
144    fn connect_server_identity_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
145        unsafe extern "C" fn notify_server_identity_trampoline<
146            P: IsA<TlsClientConnection>,
147            F: Fn(&P) + 'static,
148        >(
149            this: *mut ffi::GTlsClientConnection,
150            _param_spec: glib::ffi::gpointer,
151            f: glib::ffi::gpointer,
152        ) {
153            let f: &F = &*(f as *const F);
154            f(TlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
155        }
156        unsafe {
157            let f: Box_<F> = Box_::new(f);
158            connect_raw(
159                self.as_ptr() as *mut _,
160                c"notify::server-identity".as_ptr() as *const _,
161                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
162                    notify_server_identity_trampoline::<Self, F> as *const (),
163                )),
164                Box_::into_raw(f),
165            )
166        }
167    }
168
169    #[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
170    #[doc(alias = "validation-flags")]
171    fn connect_validation_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
172        unsafe extern "C" fn notify_validation_flags_trampoline<
173            P: IsA<TlsClientConnection>,
174            F: Fn(&P) + 'static,
175        >(
176            this: *mut ffi::GTlsClientConnection,
177            _param_spec: glib::ffi::gpointer,
178            f: glib::ffi::gpointer,
179        ) {
180            let f: &F = &*(f as *const F);
181            f(TlsClientConnection::from_glib_borrow(this).unsafe_cast_ref())
182        }
183        unsafe {
184            let f: Box_<F> = Box_::new(f);
185            connect_raw(
186                self.as_ptr() as *mut _,
187                c"notify::validation-flags".as_ptr() as *const _,
188                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
189                    notify_validation_flags_trampoline::<Self, F> as *const (),
190                )),
191                Box_::into_raw(f),
192            )
193        }
194    }
195}
196
197impl<O: IsA<TlsClientConnection>> TlsClientConnectionExt for O {}