gio/auto/simple_proxy_resolver.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
5use crate::{ffi, ProxyResolver};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 /// `GSimpleProxyResolver` is a simple [`ProxyResolver`][crate::ProxyResolver] implementation
15 /// that handles a single default proxy, multiple URI-scheme-specific
16 /// proxies, and a list of hosts that proxies should not be used for.
17 ///
18 /// `GSimpleProxyResolver` is never the default proxy resolver, but it
19 /// can be used as the base class for another proxy resolver
20 /// implementation, or it can be created and used manually, such as
21 /// with [`SocketClientExt::set_proxy_resolver()`][crate::prelude::SocketClientExt::set_proxy_resolver()].
22 ///
23 /// ## Properties
24 ///
25 ///
26 /// #### `default-proxy`
27 /// The default proxy URI that will be used for any URI that doesn't
28 /// match #GSimpleProxyResolver:ignore-hosts, and doesn't match any
29 /// of the schemes set with g_simple_proxy_resolver_set_uri_proxy().
30 ///
31 /// Note that as a special case, if this URI starts with
32 /// "socks://", #GSimpleProxyResolver will treat it as referring
33 /// to all three of the socks5, socks4a, and socks4 proxy types.
34 ///
35 /// Readable | Writeable
36 ///
37 ///
38 /// #### `ignore-hosts`
39 /// A list of hostnames and IP addresses that the resolver should
40 /// allow direct connections to.
41 ///
42 /// Entries can be in one of 4 formats:
43 ///
44 /// - A hostname, such as "example.com", ".example.com", or
45 /// "*.example.com", any of which match "example.com" or
46 /// any subdomain of it.
47 ///
48 /// - An IPv4 or IPv6 address, such as "192.168.1.1",
49 /// which matches only that address.
50 ///
51 /// - A hostname or IP address followed by a port, such as
52 /// "example.com:80", which matches whatever the hostname or IP
53 /// address would match, but only for URLs with the (explicitly)
54 /// indicated port. In the case of an IPv6 address, the address
55 /// part must appear in brackets: "[::1]:443"
56 ///
57 /// - An IP address range, given by a base address and prefix length,
58 /// such as "fe80::/10", which matches any address in that range.
59 ///
60 /// Note that when dealing with Unicode hostnames, the matching is
61 /// done against the ASCII form of the name.
62 ///
63 /// Also note that hostname exclusions apply only to connections made
64 /// to hosts identified by name, and IP address exclusions apply only
65 /// to connections made to hosts identified by address. That is, if
66 /// example.com has an address of 192.168.1.1, and the :ignore-hosts list
67 /// contains only "192.168.1.1", then a connection to "example.com"
68 /// (eg, via a #GNetworkAddress) will use the proxy, and a connection to
69 /// "192.168.1.1" (eg, via a #GInetSocketAddress) will not.
70 ///
71 /// These rules match the "ignore-hosts"/"noproxy" rules most
72 /// commonly used by other applications.
73 ///
74 /// Readable | Writeable
75 ///
76 /// # Implements
77 ///
78 /// [`SimpleProxyResolverExt`][trait@crate::prelude::SimpleProxyResolverExt], [`trait@glib::ObjectExt`], [`ProxyResolverExt`][trait@crate::prelude::ProxyResolverExt], [`SimpleProxyResolverExtManual`][trait@crate::prelude::SimpleProxyResolverExtManual]
79 #[doc(alias = "GSimpleProxyResolver")]
80 pub struct SimpleProxyResolver(Object<ffi::GSimpleProxyResolver, ffi::GSimpleProxyResolverClass>) @implements ProxyResolver;
81
82 match fn {
83 type_ => || ffi::g_simple_proxy_resolver_get_type(),
84 }
85}
86
87impl SimpleProxyResolver {
88 pub const NONE: Option<&'static SimpleProxyResolver> = None;
89}
90
91mod sealed {
92 pub trait Sealed {}
93 impl<T: super::IsA<super::SimpleProxyResolver>> Sealed for T {}
94}
95
96/// Trait containing all [`struct@SimpleProxyResolver`] methods.
97///
98/// # Implementors
99///
100/// [`SimpleProxyResolver`][struct@crate::SimpleProxyResolver]
101pub trait SimpleProxyResolverExt: IsA<SimpleProxyResolver> + sealed::Sealed + 'static {
102 /// Sets the default proxy on @self, to be used for any URIs that
103 /// don't match #GSimpleProxyResolver:ignore-hosts or a proxy set
104 /// via g_simple_proxy_resolver_set_uri_proxy().
105 ///
106 /// If @default_proxy starts with "socks://",
107 /// #GSimpleProxyResolver will treat it as referring to all three of
108 /// the socks5, socks4a, and socks4 proxy types.
109 /// ## `default_proxy`
110 /// the default proxy to use
111 #[doc(alias = "g_simple_proxy_resolver_set_default_proxy")]
112 #[doc(alias = "default-proxy")]
113 fn set_default_proxy(&self, default_proxy: Option<&str>) {
114 unsafe {
115 ffi::g_simple_proxy_resolver_set_default_proxy(
116 self.as_ref().to_glib_none().0,
117 default_proxy.to_glib_none().0,
118 );
119 }
120 }
121
122 /// Adds a URI-scheme-specific proxy to @self; URIs whose scheme
123 /// matches @uri_scheme (and which don't match
124 /// #GSimpleProxyResolver:ignore-hosts) will be proxied via @proxy.
125 ///
126 /// As with #GSimpleProxyResolver:default-proxy, if @proxy starts with
127 /// "socks://", #GSimpleProxyResolver will treat it
128 /// as referring to all three of the socks5, socks4a, and socks4 proxy
129 /// types.
130 /// ## `uri_scheme`
131 /// the URI scheme to add a proxy for
132 /// ## `proxy`
133 /// the proxy to use for @uri_scheme
134 #[doc(alias = "g_simple_proxy_resolver_set_uri_proxy")]
135 fn set_uri_proxy(&self, uri_scheme: &str, proxy: &str) {
136 unsafe {
137 ffi::g_simple_proxy_resolver_set_uri_proxy(
138 self.as_ref().to_glib_none().0,
139 uri_scheme.to_glib_none().0,
140 proxy.to_glib_none().0,
141 );
142 }
143 }
144
145 /// The default proxy URI that will be used for any URI that doesn't
146 /// match #GSimpleProxyResolver:ignore-hosts, and doesn't match any
147 /// of the schemes set with g_simple_proxy_resolver_set_uri_proxy().
148 ///
149 /// Note that as a special case, if this URI starts with
150 /// "socks://", #GSimpleProxyResolver will treat it as referring
151 /// to all three of the socks5, socks4a, and socks4 proxy types.
152 #[doc(alias = "default-proxy")]
153 fn default_proxy(&self) -> Option<glib::GString> {
154 ObjectExt::property(self.as_ref(), "default-proxy")
155 }
156
157 /// A list of hostnames and IP addresses that the resolver should
158 /// allow direct connections to.
159 ///
160 /// Entries can be in one of 4 formats:
161 ///
162 /// - A hostname, such as "example.com", ".example.com", or
163 /// "*.example.com", any of which match "example.com" or
164 /// any subdomain of it.
165 ///
166 /// - An IPv4 or IPv6 address, such as "192.168.1.1",
167 /// which matches only that address.
168 ///
169 /// - A hostname or IP address followed by a port, such as
170 /// "example.com:80", which matches whatever the hostname or IP
171 /// address would match, but only for URLs with the (explicitly)
172 /// indicated port. In the case of an IPv6 address, the address
173 /// part must appear in brackets: "[::1]:443"
174 ///
175 /// - An IP address range, given by a base address and prefix length,
176 /// such as "fe80::/10", which matches any address in that range.
177 ///
178 /// Note that when dealing with Unicode hostnames, the matching is
179 /// done against the ASCII form of the name.
180 ///
181 /// Also note that hostname exclusions apply only to connections made
182 /// to hosts identified by name, and IP address exclusions apply only
183 /// to connections made to hosts identified by address. That is, if
184 /// example.com has an address of 192.168.1.1, and the :ignore-hosts list
185 /// contains only "192.168.1.1", then a connection to "example.com"
186 /// (eg, via a #GNetworkAddress) will use the proxy, and a connection to
187 /// "192.168.1.1" (eg, via a #GInetSocketAddress) will not.
188 ///
189 /// These rules match the "ignore-hosts"/"noproxy" rules most
190 /// commonly used by other applications.
191 #[doc(alias = "ignore-hosts")]
192 fn ignore_hosts(&self) -> Vec<glib::GString> {
193 ObjectExt::property(self.as_ref(), "ignore-hosts")
194 }
195
196 #[doc(alias = "default-proxy")]
197 fn connect_default_proxy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
198 unsafe extern "C" fn notify_default_proxy_trampoline<
199 P: IsA<SimpleProxyResolver>,
200 F: Fn(&P) + 'static,
201 >(
202 this: *mut ffi::GSimpleProxyResolver,
203 _param_spec: glib::ffi::gpointer,
204 f: glib::ffi::gpointer,
205 ) {
206 let f: &F = &*(f as *const F);
207 f(SimpleProxyResolver::from_glib_borrow(this).unsafe_cast_ref())
208 }
209 unsafe {
210 let f: Box_<F> = Box_::new(f);
211 connect_raw(
212 self.as_ptr() as *mut _,
213 b"notify::default-proxy\0".as_ptr() as *const _,
214 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
215 notify_default_proxy_trampoline::<Self, F> as *const (),
216 )),
217 Box_::into_raw(f),
218 )
219 }
220 }
221
222 #[doc(alias = "ignore-hosts")]
223 fn connect_ignore_hosts_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
224 unsafe extern "C" fn notify_ignore_hosts_trampoline<
225 P: IsA<SimpleProxyResolver>,
226 F: Fn(&P) + 'static,
227 >(
228 this: *mut ffi::GSimpleProxyResolver,
229 _param_spec: glib::ffi::gpointer,
230 f: glib::ffi::gpointer,
231 ) {
232 let f: &F = &*(f as *const F);
233 f(SimpleProxyResolver::from_glib_borrow(this).unsafe_cast_ref())
234 }
235 unsafe {
236 let f: Box_<F> = Box_::new(f);
237 connect_raw(
238 self.as_ptr() as *mut _,
239 b"notify::ignore-hosts\0".as_ptr() as *const _,
240 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
241 notify_ignore_hosts_trampoline::<Self, F> as *const (),
242 )),
243 Box_::into_raw(f),
244 )
245 }
246 }
247}
248
249impl<O: IsA<SimpleProxyResolver>> SimpleProxyResolverExt for O {}