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, see <http://www.gnu.org/licenses/>.
18 * Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
23 #include "gproxyresolver.h"
28 #include "gasyncresult.h"
29 #include "gcancellable.h"
30 #include "giomodule.h"
31 #include "giomodule-priv.h"
32 #include "gsimpleasyncresult.h"
35 * SECTION:gproxyresolver
36 * @short_description: Asynchronous and cancellable network proxy resolver
39 * #GProxyResolver provides synchronous and asynchronous network proxy
40 * resolution. #GProxyResolver is used within #GSocketClient through
41 * the method g_socket_connectable_proxy_enumerate().
44 G_DEFINE_INTERFACE (GProxyResolver, g_proxy_resolver, G_TYPE_OBJECT)
47 g_proxy_resolver_default_init (GProxyResolverInterface *iface)
52 * g_proxy_resolver_get_default:
54 * Gets the default #GProxyResolver for the system.
56 * Returns: (transfer none): the default #GProxyResolver.
61 g_proxy_resolver_get_default (void)
63 return _g_io_module_get_default (G_PROXY_RESOLVER_EXTENSION_POINT_NAME,
64 "GIO_USE_PROXY_RESOLVER",
65 (GIOModuleVerifyFunc)g_proxy_resolver_is_supported);
69 * g_proxy_resolver_is_supported:
70 * @resolver: a #GProxyResolver
72 * Checks if @resolver can be used on this system. (This is used
73 * internally; g_proxy_resolver_get_default() will only return a proxy
74 * resolver that returns %TRUE for this method.)
76 * Returns: %TRUE if @resolver is supported.
81 g_proxy_resolver_is_supported (GProxyResolver *resolver)
83 GProxyResolverInterface *iface;
85 g_return_val_if_fail (G_IS_PROXY_RESOLVER (resolver), FALSE);
87 iface = G_PROXY_RESOLVER_GET_IFACE (resolver);
89 return (* iface->is_supported) (resolver);
93 * g_proxy_resolver_lookup:
94 * @resolver: a #GProxyResolver
95 * @uri: a URI representing the destination to connect to
96 * @cancellable: (allow-none): a #GCancellable, or %NULL
97 * @error: return location for a #GError, or %NULL
99 * Looks into the system proxy configuration to determine what proxy,
100 * if any, to use to connect to @uri. The returned proxy URIs are of
101 * the form `<protocol>://[user[:password]@]host:port` or
102 * `direct://`, where <protocol> could be http, rtsp, socks
103 * or other proxying protocol.
105 * If you don't know what network protocol is being used on the
106 * socket, you should use `none` as the URI protocol.
107 * In this case, the resolver might still return a generic proxy type
108 * (such as SOCKS), but would not return protocol-specific proxy types
111 * `direct://` is used when no proxy is needed.
112 * Direct connection should not be attempted unless it is part of the
113 * returned array of proxies.
115 * Returns: (transfer full) (array zero-terminated=1): A
116 * NULL-terminated array of proxy URIs. Must be freed
122 g_proxy_resolver_lookup (GProxyResolver *resolver,
124 GCancellable *cancellable,
127 GProxyResolverInterface *iface;
129 g_return_val_if_fail (G_IS_PROXY_RESOLVER (resolver), NULL);
130 g_return_val_if_fail (uri != NULL, NULL);
132 iface = G_PROXY_RESOLVER_GET_IFACE (resolver);
134 return (* iface->lookup) (resolver, uri, cancellable, error);
138 * g_proxy_resolver_lookup_async:
139 * @resolver: a #GProxyResolver
140 * @uri: a URI representing the destination to connect to
141 * @cancellable: (allow-none): a #GCancellable, or %NULL
142 * @callback: (scope async): callback to call after resolution completes
143 * @user_data: (closure): data for @callback
145 * Asynchronous lookup of proxy. See g_proxy_resolver_lookup() for more
151 g_proxy_resolver_lookup_async (GProxyResolver *resolver,
153 GCancellable *cancellable,
154 GAsyncReadyCallback callback,
157 GProxyResolverInterface *iface;
159 g_return_if_fail (G_IS_PROXY_RESOLVER (resolver));
160 g_return_if_fail (uri != NULL);
162 iface = G_PROXY_RESOLVER_GET_IFACE (resolver);
164 (* iface->lookup_async) (resolver, uri, cancellable, callback, user_data);
168 * g_proxy_resolver_lookup_finish:
169 * @resolver: a #GProxyResolver
170 * @result: the result passed to your #GAsyncReadyCallback
171 * @error: return location for a #GError, or %NULL
173 * Call this function to obtain the array of proxy URIs when
174 * g_proxy_resolver_lookup_async() is complete. See
175 * g_proxy_resolver_lookup() for more details.
177 * Returns: (transfer full) (array zero-terminated=1): A
178 * NULL-terminated array of proxy URIs. Must be freed
184 g_proxy_resolver_lookup_finish (GProxyResolver *resolver,
185 GAsyncResult *result,
188 GProxyResolverInterface *iface;
190 g_return_val_if_fail (G_IS_PROXY_RESOLVER (resolver), NULL);
192 iface = G_PROXY_RESOLVER_GET_IFACE (resolver);
194 return (* iface->lookup_finish) (resolver, result, error);