1 module webkit2.NetworkProxySettings;
2 
3 private import glib.ConstructionException;
4 private import glib.Str;
5 private import gobject.ObjectG;
6 private import webkit2.c.functions;
7 public  import webkit2.c.types;
8 
9 
10 /**
11  * WebKitNetworkProxySettings can be used to provide a custom proxy configuration
12  * to a #WebKitWebContext. You need to call webkit_web_context_set_network_proxy_settings()
13  * with %WEBKIT_NETWORK_PROXY_MODE_CUSTOM and a WebKitNetworkProxySettings.
14  *
15  * Since: 2.16
16  */
17 public class NetworkProxySettings
18 {
19 	/** the main Gtk struct */
20 	protected WebKitNetworkProxySettings* webKitNetworkProxySettings;
21 	protected bool ownedRef;
22 
23 	/** Get the main Gtk struct */
24 	public WebKitNetworkProxySettings* getNetworkProxySettingsStruct(bool transferOwnership = false)
25 	{
26 		if (transferOwnership)
27 			ownedRef = false;
28 		return webKitNetworkProxySettings;
29 	}
30 
31 	/** the main Gtk struct as a void* */
32 	protected void* getStruct()
33 	{
34 		return cast(void*)webKitNetworkProxySettings;
35 	}
36 
37 	/**
38 	 * Sets our main struct and passes it to the parent class.
39 	 */
40 	public this (WebKitNetworkProxySettings* webKitNetworkProxySettings, bool ownedRef = false)
41 	{
42 		this.webKitNetworkProxySettings = webKitNetworkProxySettings;
43 		this.ownedRef = ownedRef;
44 	}
45 
46 	~this ()
47 	{
48 		if ( ownedRef )
49 			webkit_network_proxy_settings_free(webKitNetworkProxySettings);
50 	}
51 
52 
53 	/** */
54 	public static GType getType()
55 	{
56 		return webkit_network_proxy_settings_get_type();
57 	}
58 
59 	/**
60 	 * Create a new #WebKitNetworkProxySettings with the given @default_proxy_uri and @ignore_hosts.
61 	 *
62 	 * The default proxy URI will be used for any URI that doesn't match @ignore_hosts, and doesn't match any
63 	 * of the schemes added with webkit_network_proxy_settings_add_proxy_for_scheme().
64 	 * If @default_proxy_uri starts with "socks://", it will be treated as referring to all three of the
65 	 * socks5, socks4a, and socks4 proxy types.
66 	 *
67 	 * @ignore_hosts is a list of hostnames and IP addresses that the resolver should allow direct connections to.
68 	 * Entries can be in one of 4 formats:
69 	 * <itemizedlist>
70 	 * <listitem><para>
71 	 * A hostname, such as "example.com", ".example.com", or "*.example.com", any of which match "example.com" or
72 	 * any subdomain of it.
73 	 * </para></listitem>
74 	 * <listitem><para>
75 	 * An IPv4 or IPv6 address, such as "192.168.1.1", which matches only that address.
76 	 * </para></listitem>
77 	 * <listitem><para>
78 	 * A hostname or IP address followed by a port, such as "example.com:80", which matches whatever the hostname or IP
79 	 * address would match, but only for URLs with the (explicitly) indicated port. In the case of an IPv6 address, the address
80 	 * part must appear in brackets: "[::1]:443"
81 	 * </para></listitem>
82 	 * <listitem><para>
83 	 * An IP address range, given by a base address and prefix length, such as "fe80::/10", which matches any address in that range.
84 	 * </para></listitem>
85 	 * </itemizedlist>
86 	 *
87 	 * Note that when dealing with Unicode hostnames, the matching is done against the ASCII form of the name.
88 	 * Also note that hostname exclusions apply only to connections made to hosts identified by name, and IP address exclusions apply only
89 	 * to connections made to hosts identified by address. That is, if example.com has an address of 192.168.1.1, and @ignore_hosts
90 	 * contains only "192.168.1.1", then a connection to "example.com" will use the proxy, and a connection to 192.168.1.1" will not.
91 	 *
92 	 * Params:
93 	 *     defaultProxyUri = the default proxy URI to use, or %NULL.
94 	 *     ignoreHosts = an optional list of hosts/IP addresses to not use a proxy for.
95 	 *
96 	 * Returns: A new #WebKitNetworkProxySettings.
97 	 *
98 	 * Since: 2.16
99 	 *
100 	 * Throws: ConstructionException GTK+ fails to create the object.
101 	 */
102 	public this(string defaultProxyUri, string[] ignoreHosts)
103 	{
104 		auto __p = webkit_network_proxy_settings_new(Str.toStringz(defaultProxyUri), Str.toStringzArray(ignoreHosts));
105 
106 		if(__p is null)
107 		{
108 			throw new ConstructionException("null returned by new");
109 		}
110 
111 		this(cast(WebKitNetworkProxySettings*) __p);
112 	}
113 
114 	/**
115 	 * Adds a URI-scheme-specific proxy. URIs whose scheme matches @uri_scheme will be proxied via @proxy_uri.
116 	 * As with the default proxy URI, if @proxy_uri starts with "socks://", it will be treated as referring to
117 	 * all three of the socks5, socks4a, and socks4 proxy types.
118 	 *
119 	 * Params:
120 	 *     scheme = the URI scheme to add a proxy for
121 	 *     proxyUri = the proxy URI to use for @uri_scheme
122 	 *
123 	 * Since: 2.16
124 	 */
125 	public void addProxyForScheme(string scheme, string proxyUri)
126 	{
127 		webkit_network_proxy_settings_add_proxy_for_scheme(webKitNetworkProxySettings, Str.toStringz(scheme), Str.toStringz(proxyUri));
128 	}
129 
130 	/**
131 	 * Make a copy of the #WebKitNetworkProxySettings.
132 	 *
133 	 * Returns: A copy of passed in #WebKitNetworkProxySettings
134 	 *
135 	 * Since: 2.16
136 	 */
137 	public NetworkProxySettings copy()
138 	{
139 		auto __p = webkit_network_proxy_settings_copy(webKitNetworkProxySettings);
140 
141 		if(__p is null)
142 		{
143 			return null;
144 		}
145 
146 		return ObjectG.getDObject!(NetworkProxySettings)(cast(WebKitNetworkProxySettings*) __p, true);
147 	}
148 
149 	/**
150 	 * Free the #WebKitNetworkProxySettings.
151 	 *
152 	 * Since: 2.16
153 	 */
154 	public void free()
155 	{
156 		webkit_network_proxy_settings_free(webKitNetworkProxySettings);
157 		ownedRef = false;
158 	}
159 }