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
91/// Trait containing all [`struct@SimpleProxyResolver`] methods.
92///
93/// # Implementors
94///
95/// [`SimpleProxyResolver`][struct@crate::SimpleProxyResolver]
96pub trait SimpleProxyResolverExt: IsA<SimpleProxyResolver> + 'static {
97 /// Sets the default proxy on @self, to be used for any URIs that
98 /// don't match #GSimpleProxyResolver:ignore-hosts or a proxy set
99 /// via g_simple_proxy_resolver_set_uri_proxy().
100 ///
101 /// If @default_proxy starts with "socks://",
102 /// #GSimpleProxyResolver will treat it as referring to all three of
103 /// the socks5, socks4a, and socks4 proxy types.
104 /// ## `default_proxy`
105 /// the default proxy to use
106 #[doc(alias = "g_simple_proxy_resolver_set_default_proxy")]
107 #[doc(alias = "default-proxy")]
108 fn set_default_proxy(&self, default_proxy: Option<&str>) {
109 unsafe {
110 ffi::g_simple_proxy_resolver_set_default_proxy(
111 self.as_ref().to_glib_none().0,
112 default_proxy.to_glib_none().0,
113 );
114 }
115 }
116
117 /// Adds a URI-scheme-specific proxy to @self; URIs whose scheme
118 /// matches @uri_scheme (and which don't match
119 /// #GSimpleProxyResolver:ignore-hosts) will be proxied via @proxy.
120 ///
121 /// As with #GSimpleProxyResolver:default-proxy, if @proxy starts with
122 /// "socks://", #GSimpleProxyResolver will treat it
123 /// as referring to all three of the socks5, socks4a, and socks4 proxy
124 /// types.
125 /// ## `uri_scheme`
126 /// the URI scheme to add a proxy for
127 /// ## `proxy`
128 /// the proxy to use for @uri_scheme
129 #[doc(alias = "g_simple_proxy_resolver_set_uri_proxy")]
130 fn set_uri_proxy(&self, uri_scheme: &str, proxy: &str) {
131 unsafe {
132 ffi::g_simple_proxy_resolver_set_uri_proxy(
133 self.as_ref().to_glib_none().0,
134 uri_scheme.to_glib_none().0,
135 proxy.to_glib_none().0,
136 );
137 }
138 }
139
140 /// The default proxy URI that will be used for any URI that doesn't
141 /// match #GSimpleProxyResolver:ignore-hosts, and doesn't match any
142 /// of the schemes set with g_simple_proxy_resolver_set_uri_proxy().
143 ///
144 /// Note that as a special case, if this URI starts with
145 /// "socks://", #GSimpleProxyResolver will treat it as referring
146 /// to all three of the socks5, socks4a, and socks4 proxy types.
147 #[doc(alias = "default-proxy")]
148 fn default_proxy(&self) -> Option<glib::GString> {
149 ObjectExt::property(self.as_ref(), "default-proxy")
150 }
151
152 /// A list of hostnames and IP addresses that the resolver should
153 /// allow direct connections to.
154 ///
155 /// Entries can be in one of 4 formats:
156 ///
157 /// - A hostname, such as "example.com", ".example.com", or
158 /// "*.example.com", any of which match "example.com" or
159 /// any subdomain of it.
160 ///
161 /// - An IPv4 or IPv6 address, such as "192.168.1.1",
162 /// which matches only that address.
163 ///
164 /// - A hostname or IP address followed by a port, such as
165 /// "example.com:80", which matches whatever the hostname or IP
166 /// address would match, but only for URLs with the (explicitly)
167 /// indicated port. In the case of an IPv6 address, the address
168 /// part must appear in brackets: "[::1]:443"
169 ///
170 /// - An IP address range, given by a base address and prefix length,
171 /// such as "fe80::/10", which matches any address in that range.
172 ///
173 /// Note that when dealing with Unicode hostnames, the matching is
174 /// done against the ASCII form of the name.
175 ///
176 /// Also note that hostname exclusions apply only to connections made
177 /// to hosts identified by name, and IP address exclusions apply only
178 /// to connections made to hosts identified by address. That is, if
179 /// example.com has an address of 192.168.1.1, and the :ignore-hosts list
180 /// contains only "192.168.1.1", then a connection to "example.com"
181 /// (eg, via a #GNetworkAddress) will use the proxy, and a connection to
182 /// "192.168.1.1" (eg, via a #GInetSocketAddress) will not.
183 ///
184 /// These rules match the "ignore-hosts"/"noproxy" rules most
185 /// commonly used by other applications.
186 #[doc(alias = "ignore-hosts")]
187 fn ignore_hosts(&self) -> Vec<glib::GString> {
188 ObjectExt::property(self.as_ref(), "ignore-hosts")
189 }
190
191 #[doc(alias = "default-proxy")]
192 fn connect_default_proxy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
193 unsafe extern "C" fn notify_default_proxy_trampoline<
194 P: IsA<SimpleProxyResolver>,
195 F: Fn(&P) + 'static,
196 >(
197 this: *mut ffi::GSimpleProxyResolver,
198 _param_spec: glib::ffi::gpointer,
199 f: glib::ffi::gpointer,
200 ) {
201 let f: &F = &*(f as *const F);
202 f(SimpleProxyResolver::from_glib_borrow(this).unsafe_cast_ref())
203 }
204 unsafe {
205 let f: Box_<F> = Box_::new(f);
206 connect_raw(
207 self.as_ptr() as *mut _,
208 c"notify::default-proxy".as_ptr() as *const _,
209 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
210 notify_default_proxy_trampoline::<Self, F> as *const (),
211 )),
212 Box_::into_raw(f),
213 )
214 }
215 }
216
217 #[doc(alias = "ignore-hosts")]
218 fn connect_ignore_hosts_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
219 unsafe extern "C" fn notify_ignore_hosts_trampoline<
220 P: IsA<SimpleProxyResolver>,
221 F: Fn(&P) + 'static,
222 >(
223 this: *mut ffi::GSimpleProxyResolver,
224 _param_spec: glib::ffi::gpointer,
225 f: glib::ffi::gpointer,
226 ) {
227 let f: &F = &*(f as *const F);
228 f(SimpleProxyResolver::from_glib_borrow(this).unsafe_cast_ref())
229 }
230 unsafe {
231 let f: Box_<F> = Box_::new(f);
232 connect_raw(
233 self.as_ptr() as *mut _,
234 c"notify::ignore-hosts".as_ptr() as *const _,
235 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
236 notify_ignore_hosts_trampoline::<Self, F> as *const (),
237 )),
238 Box_::into_raw(f),
239 )
240 }
241 }
242}
243
244impl<O: IsA<SimpleProxyResolver>> SimpleProxyResolverExt for O {}