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