gio: Annotate GDBusObjectManagerClient signal appropriately
[glib.git] / gio / gproxyresolver.c
blob082274e4f615ad8966edd099f7873325b9408822
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.1 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>
21 #include "config.h"
23 #include "gproxyresolver.h"
25 #include <glib.h>
26 #include "glibintl.h"
28 #include "gasyncresult.h"
29 #include "gcancellable.h"
30 #include "giomodule.h"
31 #include "giomodule-priv.h"
33 /**
34 * SECTION:gproxyresolver
35 * @short_description: Asynchronous and cancellable network proxy resolver
36 * @include: gio/gio.h
38 * #GProxyResolver provides synchronous and asynchronous network proxy
39 * resolution. #GProxyResolver is used within #GSocketClient through
40 * the method g_socket_connectable_proxy_enumerate().
42 * Implementations of #GProxyResolver based on libproxy and GNOME settings can
43 * be found in glib-networking. GIO comes with an implementation for use inside
44 * Flatpak portals.
47 /**
48 * GProxyResolverInterface:
49 * @g_iface: The parent interface.
50 * @is_supported: the virtual function pointer for g_proxy_resolver_is_supported()
51 * @lookup: the virtual function pointer for g_proxy_resolver_lookup()
52 * @lookup_async: the virtual function pointer for
53 * g_proxy_resolver_lookup_async()
54 * @lookup_finish: the virtual function pointer for
55 * g_proxy_resolver_lookup_finish()
57 * The virtual function table for #GProxyResolver.
60 G_DEFINE_INTERFACE (GProxyResolver, g_proxy_resolver, G_TYPE_OBJECT)
62 static void
63 g_proxy_resolver_default_init (GProxyResolverInterface *iface)
67 /**
68 * g_proxy_resolver_get_default:
70 * Gets the default #GProxyResolver for the system.
72 * Returns: (transfer none): the default #GProxyResolver.
74 * Since: 2.26
76 GProxyResolver *
77 g_proxy_resolver_get_default (void)
79 return _g_io_module_get_default (G_PROXY_RESOLVER_EXTENSION_POINT_NAME,
80 "GIO_USE_PROXY_RESOLVER",
81 (GIOModuleVerifyFunc)g_proxy_resolver_is_supported);
84 /**
85 * g_proxy_resolver_is_supported:
86 * @resolver: a #GProxyResolver
88 * Checks if @resolver can be used on this system. (This is used
89 * internally; g_proxy_resolver_get_default() will only return a proxy
90 * resolver that returns %TRUE for this method.)
92 * Returns: %TRUE if @resolver is supported.
94 * Since: 2.26
96 gboolean
97 g_proxy_resolver_is_supported (GProxyResolver *resolver)
99 GProxyResolverInterface *iface;
101 g_return_val_if_fail (G_IS_PROXY_RESOLVER (resolver), FALSE);
103 iface = G_PROXY_RESOLVER_GET_IFACE (resolver);
105 return (* iface->is_supported) (resolver);
109 * g_proxy_resolver_lookup:
110 * @resolver: a #GProxyResolver
111 * @uri: a URI representing the destination to connect to
112 * @cancellable: (nullable): a #GCancellable, or %NULL
113 * @error: return location for a #GError, or %NULL
115 * Looks into the system proxy configuration to determine what proxy,
116 * if any, to use to connect to @uri. The returned proxy URIs are of
117 * the form `<protocol>://[user[:password]@]host:port` or
118 * `direct://`, where <protocol> could be http, rtsp, socks
119 * or other proxying protocol.
121 * If you don't know what network protocol is being used on the
122 * socket, you should use `none` as the URI protocol.
123 * In this case, the resolver might still return a generic proxy type
124 * (such as SOCKS), but would not return protocol-specific proxy types
125 * (such as http).
127 * `direct://` is used when no proxy is needed.
128 * Direct connection should not be attempted unless it is part of the
129 * returned array of proxies.
131 * Returns: (transfer full) (array zero-terminated=1): A
132 * NULL-terminated array of proxy URIs. Must be freed
133 * with g_strfreev().
135 * Since: 2.26
137 gchar **
138 g_proxy_resolver_lookup (GProxyResolver *resolver,
139 const gchar *uri,
140 GCancellable *cancellable,
141 GError **error)
143 GProxyResolverInterface *iface;
145 g_return_val_if_fail (G_IS_PROXY_RESOLVER (resolver), NULL);
146 g_return_val_if_fail (uri != NULL, NULL);
148 iface = G_PROXY_RESOLVER_GET_IFACE (resolver);
150 return (* iface->lookup) (resolver, uri, cancellable, error);
154 * g_proxy_resolver_lookup_async:
155 * @resolver: a #GProxyResolver
156 * @uri: a URI representing the destination to connect to
157 * @cancellable: (nullable): a #GCancellable, or %NULL
158 * @callback: (scope async): callback to call after resolution completes
159 * @user_data: (closure): data for @callback
161 * Asynchronous lookup of proxy. See g_proxy_resolver_lookup() for more
162 * details.
164 * Since: 2.26
166 void
167 g_proxy_resolver_lookup_async (GProxyResolver *resolver,
168 const gchar *uri,
169 GCancellable *cancellable,
170 GAsyncReadyCallback callback,
171 gpointer user_data)
173 GProxyResolverInterface *iface;
175 g_return_if_fail (G_IS_PROXY_RESOLVER (resolver));
176 g_return_if_fail (uri != NULL);
178 iface = G_PROXY_RESOLVER_GET_IFACE (resolver);
180 (* iface->lookup_async) (resolver, uri, cancellable, callback, user_data);
184 * g_proxy_resolver_lookup_finish:
185 * @resolver: a #GProxyResolver
186 * @result: the result passed to your #GAsyncReadyCallback
187 * @error: return location for a #GError, or %NULL
189 * Call this function to obtain the array of proxy URIs when
190 * g_proxy_resolver_lookup_async() is complete. See
191 * g_proxy_resolver_lookup() for more details.
193 * Returns: (transfer full) (array zero-terminated=1): A
194 * NULL-terminated array of proxy URIs. Must be freed
195 * with g_strfreev().
197 * Since: 2.26
199 gchar **
200 g_proxy_resolver_lookup_finish (GProxyResolver *resolver,
201 GAsyncResult *result,
202 GError **error)
204 GProxyResolverInterface *iface;
206 g_return_val_if_fail (G_IS_PROXY_RESOLVER (resolver), NULL);
208 iface = G_PROXY_RESOLVER_GET_IFACE (resolver);
210 return (* iface->lookup_finish) (resolver, result, error);