1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gio.ProxyT;
26 
27 public  import gio.AsyncResultIF;
28 public  import gio.Cancellable;
29 public  import gio.IOStream;
30 public  import gio.Proxy;
31 public  import gio.ProxyAddress;
32 public  import gio.ProxyIF;
33 public  import glib.ErrorG;
34 public  import glib.GException;
35 public  import glib.Str;
36 public  import gobject.ObjectG;
37 public  import gtkc.gio;
38 public  import gtkc.giotypes;
39 
40 
41 /**
42  * A #GProxy handles connecting to a remote host via a given type of
43  * proxy server. It is implemented by the 'gio-proxy' extension point.
44  * The extensions are named after their proxy protocol name. As an
45  * example, a SOCKS5 proxy implementation can be retrieved with the
46  * name 'socks5' using the function
47  * g_io_extension_point_get_extension_by_name().
48  *
49  * Since: 2.26
50  */
51 public template ProxyT(TStruct)
52 {
53 	/** Get the main Gtk struct */
54 	public GProxy* getProxyStruct()
55 	{
56 		return cast(GProxy*)getStruct();
57 	}
58 
59 
60 	/**
61 	 * Lookup "gio-proxy" extension point for a proxy implementation that supports
62 	 * specified protocol.
63 	 *
64 	 * Params:
65 	 *     protocol = the proxy protocol name (e.g. http, socks, etc)
66 	 *
67 	 * Return: return a #GProxy or NULL if protocol
68 	 *     is not supported.
69 	 *
70 	 * Since: 2.26
71 	 */
72 	public static ProxyIF getDefaultForProtocol(string protocol)
73 	{
74 		auto p = g_proxy_get_default_for_protocol(Str.toStringz(protocol));
75 		
76 		if(p is null)
77 		{
78 			return null;
79 		}
80 		
81 		return ObjectG.getDObject!(Proxy, ProxyIF)(cast(GProxy*) p, true);
82 	}
83 
84 	/**
85 	 * Given @connection to communicate with a proxy (eg, a
86 	 * #GSocketConnection that is connected to the proxy server), this
87 	 * does the necessary handshake to connect to @proxy_address, and if
88 	 * required, wraps the #GIOStream to handle proxy payload.
89 	 *
90 	 * Params:
91 	 *     connection = a #GIOStream
92 	 *     proxyAddress = a #GProxyAddress
93 	 *     cancellable = a #GCancellable
94 	 *
95 	 * Return: a #GIOStream that will replace @connection. This might
96 	 *     be the same as @connection, in which case a reference
97 	 *     will be added.
98 	 *
99 	 * Since: 2.26
100 	 *
101 	 * Throws: GException on failure.
102 	 */
103 	public IOStream connect(IOStream connection, ProxyAddress proxyAddress, Cancellable cancellable)
104 	{
105 		GError* err = null;
106 		
107 		auto p = g_proxy_connect(getProxyStruct(), (connection is null) ? null : connection.getIOStreamStruct(), (proxyAddress is null) ? null : proxyAddress.getProxyAddressStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
108 		
109 		if (err !is null)
110 		{
111 			throw new GException( new ErrorG(err) );
112 		}
113 		
114 		if(p is null)
115 		{
116 			return null;
117 		}
118 		
119 		return ObjectG.getDObject!(IOStream)(cast(GIOStream*) p, true);
120 	}
121 
122 	/**
123 	 * Asynchronous version of g_proxy_connect().
124 	 *
125 	 * Params:
126 	 *     connection = a #GIOStream
127 	 *     proxyAddress = a #GProxyAddress
128 	 *     cancellable = a #GCancellable
129 	 *     callback = a #GAsyncReadyCallback
130 	 *     userData = callback data
131 	 *
132 	 * Since: 2.26
133 	 */
134 	public void connectAsync(IOStream connection, ProxyAddress proxyAddress, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
135 	{
136 		g_proxy_connect_async(getProxyStruct(), (connection is null) ? null : connection.getIOStreamStruct(), (proxyAddress is null) ? null : proxyAddress.getProxyAddressStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
137 	}
138 
139 	/**
140 	 * See g_proxy_connect().
141 	 *
142 	 * Params:
143 	 *     result = a #GAsyncResult
144 	 *
145 	 * Return: a #GIOStream.
146 	 *
147 	 * Since: 2.26
148 	 *
149 	 * Throws: GException on failure.
150 	 */
151 	public IOStream connectFinish(AsyncResultIF result)
152 	{
153 		GError* err = null;
154 		
155 		auto p = g_proxy_connect_finish(getProxyStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err);
156 		
157 		if (err !is null)
158 		{
159 			throw new GException( new ErrorG(err) );
160 		}
161 		
162 		if(p is null)
163 		{
164 			return null;
165 		}
166 		
167 		return ObjectG.getDObject!(IOStream)(cast(GIOStream*) p, true);
168 	}
169 
170 	/**
171 	 * Some proxy protocols expect to be passed a hostname, which they
172 	 * will resolve to an IP address themselves. Others, like SOCKS4, do
173 	 * not allow this. This function will return %FALSE if @proxy is
174 	 * implementing such a protocol. When %FALSE is returned, the caller
175 	 * should resolve the destination hostname first, and then pass a
176 	 * #GProxyAddress containing the stringified IP address to
177 	 * g_proxy_connect() or g_proxy_connect_async().
178 	 *
179 	 * Return: %TRUE if hostname resolution is supported.
180 	 *
181 	 * Since: 2.26
182 	 */
183 	public bool supportsHostname()
184 	{
185 		return g_proxy_supports_hostname(getProxyStruct()) != 0;
186 	}
187 }