gio/
simple_proxy_resolver.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{prelude::*, translate::*};
4
5use crate::{ffi, ProxyResolver, SimpleProxyResolver};
6
7impl SimpleProxyResolver {
8    /// Creates a new #GSimpleProxyResolver. See
9    /// #GSimpleProxyResolver:default-proxy and
10    /// #GSimpleProxyResolver:ignore-hosts for more details on how the
11    /// arguments are interpreted.
12    /// ## `default_proxy`
13    /// the default proxy to use, eg
14    ///     "socks://192.168.1.1"
15    /// ## `ignore_hosts`
16    /// an optional list of hosts/IP addresses
17    ///     to not use a proxy for.
18    ///
19    /// # Returns
20    ///
21    /// a new #GSimpleProxyResolver
22    #[doc(alias = "g_simple_proxy_resolver_new")]
23    #[allow(clippy::new_ret_no_self)]
24    pub fn new(default_proxy: Option<&str>, ignore_hosts: impl IntoStrV) -> ProxyResolver {
25        unsafe {
26            ignore_hosts.run_with_strv(|ignore_hosts| {
27                from_glib_full(ffi::g_simple_proxy_resolver_new(
28                    default_proxy.to_glib_none().0,
29                    ignore_hosts.as_ptr() as *mut _,
30                ))
31            })
32        }
33    }
34}
35
36pub trait SimpleProxyResolverExtManual: IsA<SimpleProxyResolver> + 'static {
37    /// Sets the list of ignored hosts.
38    ///
39    /// See #GSimpleProxyResolver:ignore-hosts for more details on how the
40    /// @ignore_hosts argument is interpreted.
41    /// ## `ignore_hosts`
42    /// [`None`]-terminated list of hosts/IP addresses
43    ///     to not use a proxy for
44    #[doc(alias = "g_simple_proxy_resolver_set_ignore_hosts")]
45    fn set_ignore_hosts(&self, ignore_hosts: impl IntoStrV) {
46        unsafe {
47            ignore_hosts.run_with_strv(|ignore_hosts| {
48                ffi::g_simple_proxy_resolver_set_ignore_hosts(
49                    self.as_ref().to_glib_none().0,
50                    ignore_hosts.as_ptr() as *mut _,
51                );
52            })
53        }
54    }
55}
56
57impl<O: IsA<SimpleProxyResolver>> SimpleProxyResolverExtManual for O {}