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 
62 	/**
63 	 * Lookup "gio-proxy" extension point for a proxy implementation that supports
64 	 * specified protocol.
65 	 *
66 	 * Params:
67 	 *     protocol = the proxy protocol name (e.g. http, socks, etc)
68 	 *
69 	 * Return: return a #GProxy or NULL if protocol
70 	 *     is not supported.
71 	 *
72 	 * Since: 2.26
73 	 */
74 	public static ProxyIF getDefaultForProtocol(string protocol)
75 	{
76 		auto p = g_proxy_get_default_for_protocol(Str.toStringz(protocol));
77 		
78 		if(p is null)
79 		{
80 			return null;
81 		}
82 		
83 		return ObjectG.getDObject!(Proxy, ProxyIF)(cast(GProxy*) p);
84 	}
85 
86 	/**
87 	 * Given @connection to communicate with a proxy (eg, a
88 	 * #GSocketConnection that is connected to the proxy server), this
89 	 * does the necessary handshake to connect to @proxy_address, and if
90 	 * required, wraps the #GIOStream to handle proxy payload.
91 	 *
92 	 * Params:
93 	 *     connection = a #GIOStream
94 	 *     proxyAddress = a #GProxyAddress
95 	 *     cancellable = a #GCancellable
96 	 *
97 	 * Return: a #GIOStream that will replace @connection. This might
98 	 *     be the same as @connection, in which case a reference
99 	 *     will be added.
100 	 *
101 	 * Since: 2.26
102 	 *
103 	 * Throws: GException on failure.
104 	 */
105 	public IOStream connect(IOStream connection, ProxyAddress proxyAddress, Cancellable cancellable)
106 	{
107 		GError* err = null;
108 		
109 		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);
110 		
111 		if (err !is null)
112 		{
113 			throw new GException( new ErrorG(err) );
114 		}
115 		
116 		if(p is null)
117 		{
118 			return null;
119 		}
120 		
121 		return ObjectG.getDObject!(IOStream)(cast(GIOStream*) p, true);
122 	}
123 
124 	/**
125 	 * Asynchronous version of g_proxy_connect().
126 	 *
127 	 * Params:
128 	 *     connection = a #GIOStream
129 	 *     proxyAddress = a #GProxyAddress
130 	 *     cancellable = a #GCancellable
131 	 *     callback = a #GAsyncReadyCallback
132 	 *     userData = callback data
133 	 *
134 	 * Since: 2.26
135 	 */
136 	public void connectAsync(IOStream connection, ProxyAddress proxyAddress, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
137 	{
138 		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);
139 	}
140 
141 	/**
142 	 * See g_proxy_connect().
143 	 *
144 	 * Params:
145 	 *     result = a #GAsyncResult
146 	 *
147 	 * Return: a #GIOStream.
148 	 *
149 	 * Since: 2.26
150 	 *
151 	 * Throws: GException on failure.
152 	 */
153 	public IOStream connectFinish(AsyncResultIF result)
154 	{
155 		GError* err = null;
156 		
157 		auto p = g_proxy_connect_finish(getProxyStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err);
158 		
159 		if (err !is null)
160 		{
161 			throw new GException( new ErrorG(err) );
162 		}
163 		
164 		if(p is null)
165 		{
166 			return null;
167 		}
168 		
169 		return ObjectG.getDObject!(IOStream)(cast(GIOStream*) p, true);
170 	}
171 
172 	/**
173 	 * Some proxy protocols expect to be passed a hostname, which they
174 	 * will resolve to an IP address themselves. Others, like SOCKS4, do
175 	 * not allow this. This function will return %FALSE if @proxy is
176 	 * implementing such a protocol. When %FALSE is returned, the caller
177 	 * should resolve the destination hostname first, and then pass a
178 	 * #GProxyAddress containing the stringified IP address to
179 	 * g_proxy_connect() or g_proxy_connect_async().
180 	 *
181 	 * Return: %TRUE if hostname resolution is supported.
182 	 *
183 	 * Since: 2.26
184 	 */
185 	public bool supportsHostname()
186 	{
187 		return g_proxy_supports_hostname(getProxyStruct()) != 0;
188 	}
189 }