1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2010 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
27 #include "giomodule.h"
28 #include "giomodule-priv.h"
33 * @short_description: Interface for proxy handling
36 * A #GProxy handles connecting to a remote host via a given type of
37 * proxy server. It is implemented by the 'gio-proxy' extension point.
38 * The extensions are named after their proxy protocol name. As an
39 * example, a SOCKS5 proxy implementation can be retrieved with the
40 * name 'socks5' using the function
41 * g_io_extension_point_get_extension_by_name().
46 G_DEFINE_INTERFACE (GProxy, g_proxy, G_TYPE_OBJECT)
49 g_proxy_default_init (GProxyInterface *iface)
54 * g_proxy_get_default_for_protocol:
55 * @protocol: the proxy protocol name (e.g. http, socks, etc)
57 * Lookup "gio-proxy" extension point for a proxy implementation that supports
60 * Return value: (transfer full): return a #GProxy or NULL if protocol
66 g_proxy_get_default_for_protocol (const gchar *protocol)
68 GIOExtensionPoint *ep;
69 GIOExtension *extension;
71 /* Ensure proxy modules loaded */
72 _g_io_modules_ensure_loaded ();
74 ep = g_io_extension_point_lookup (G_PROXY_EXTENSION_POINT_NAME);
76 extension = g_io_extension_point_get_extension_by_name (ep, protocol);
79 return g_object_new (g_io_extension_get_type (extension), NULL);
87 * @connection: a #GIOStream
88 * @proxy_address: a #GProxyAddress
89 * @cancellable: (allow-none): a #GCancellable
90 * @error: return #GError
92 * Given @connection to communicate with a proxy (eg, a
93 * #GSocketConnection that is connected to the proxy server), this
94 * does the necessary handshake to connect to @proxy_address, and if
95 * required, wraps the #GIOStream to handle proxy payload.
97 * Return value: (transfer full): a #GIOStream that will replace @connection. This might
98 * be the same as @connection, in which case a reference
104 g_proxy_connect (GProxy *proxy,
105 GIOStream *connection,
106 GProxyAddress *proxy_address,
107 GCancellable *cancellable,
110 GProxyInterface *iface;
112 g_return_val_if_fail (G_IS_PROXY (proxy), NULL);
114 iface = G_PROXY_GET_IFACE (proxy);
116 return (* iface->connect) (proxy,
124 * g_proxy_connect_async:
126 * @connection: a #GIOStream
127 * @proxy_address: a #GProxyAddress
128 * @cancellable: (allow-none): a #GCancellable
129 * @callback: (scope async): a #GAsyncReadyCallback
130 * @user_data: (closure): callback data
132 * Asynchronous version of g_proxy_connect().
137 g_proxy_connect_async (GProxy *proxy,
138 GIOStream *connection,
139 GProxyAddress *proxy_address,
140 GCancellable *cancellable,
141 GAsyncReadyCallback callback,
144 GProxyInterface *iface;
146 g_return_if_fail (G_IS_PROXY (proxy));
148 iface = G_PROXY_GET_IFACE (proxy);
150 (* iface->connect_async) (proxy,
159 * g_proxy_connect_finish:
161 * @result: a #GAsyncResult
162 * @error: return #GError
164 * See g_proxy_connect().
166 * Return value: (transfer full): a #GIOStream.
171 g_proxy_connect_finish (GProxy *proxy,
172 GAsyncResult *result,
175 GProxyInterface *iface;
177 g_return_val_if_fail (G_IS_PROXY (proxy), NULL);
179 iface = G_PROXY_GET_IFACE (proxy);
181 return (* iface->connect_finish) (proxy, result, error);
185 * g_proxy_supports_hostname:
188 * Some proxy protocols expect to be passed a hostname, which they
189 * will resolve to an IP address themselves. Others, like SOCKS4, do
190 * not allow this. This function will return %FALSE if @proxy is
191 * implementing such a protocol. When %FALSE is returned, the caller
192 * should resolve the destination hostname first, and then pass a
193 * #GProxyAddress containing the stringified IP address to
194 * g_proxy_connect() or g_proxy_connect_async().
196 * Return value: %TRUE if hostname resolution is supported.
201 g_proxy_supports_hostname (GProxy *proxy)
203 GProxyInterface *iface;
205 g_return_val_if_fail (G_IS_PROXY (proxy), FALSE);
207 iface = G_PROXY_GET_IFACE (proxy);
209 return (* iface->supports_hostname) (proxy);