1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright © 2008, 2009 codethink
4 * Copyright © 2009 Red Hat, Inc
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Authors: Ryan Lortie <desrt@desrt.ca>
22 * Alexander Larsson <alexl@redhat.com>
26 #include "gsocketclient.h"
31 #include <gio/gioenumtypes.h>
32 #include <gio/gsocketaddressenumerator.h>
33 #include <gio/gsocketconnectable.h>
34 #include <gio/gsocketconnection.h>
35 #include <gio/gproxyaddressenumerator.h>
36 #include <gio/gproxyaddress.h>
37 #include <gio/gtask.h>
38 #include <gio/gcancellable.h>
39 #include <gio/gioerror.h>
40 #include <gio/gsocket.h>
41 #include <gio/gnetworkaddress.h>
42 #include <gio/gnetworkservice.h>
43 #include <gio/gproxy.h>
44 #include <gio/gproxyresolver.h>
45 #include <gio/gsocketaddress.h>
46 #include <gio/gtcpconnection.h>
47 #include <gio/gtcpwrapperconnection.h>
48 #include <gio/gtlscertificate.h>
49 #include <gio/gtlsclientconnection.h>
50 #include <gio/ginetaddress.h>
55 * SECTION:gsocketclient
56 * @short_description: Helper for connecting to a network service
58 * @see_also: #GSocketConnection, #GSocketListener
60 * #GSocketClient is a lightweight high-level utility class for connecting to
61 * a network host using a connection oriented socket type.
63 * You create a #GSocketClient object, set any options you want, and then
64 * call a sync or async connect operation, which returns a #GSocketConnection
65 * subclass on success.
67 * The type of the #GSocketConnection object returned depends on the type of
68 * the underlying socket that is in use. For instance, for a TCP/IP connection
69 * it will be a #GTcpConnection.
71 * As #GSocketClient is a lightweight object, you don't need to cache it. You
72 * can just create a new one any time you need one.
84 static guint signals[LAST_SIGNAL] = { 0 };
96 PROP_TLS_VALIDATION_FLAGS,
100 struct _GSocketClientPrivate
102 GSocketFamily family;
104 GSocketProtocol protocol;
105 GSocketAddress *local_address;
107 gboolean enable_proxy;
108 GHashTable *app_proxies;
110 GTlsCertificateFlags tls_validation_flags;
111 GProxyResolver *proxy_resolver;
114 G_DEFINE_TYPE_WITH_PRIVATE (GSocketClient, g_socket_client, G_TYPE_OBJECT)
117 create_socket (GSocketClient *client,
118 GSocketAddress *dest_address,
121 GSocketFamily family;
124 family = client->priv->family;
125 if (family == G_SOCKET_FAMILY_INVALID &&
126 client->priv->local_address != NULL)
127 family = g_socket_address_get_family (client->priv->local_address);
128 if (family == G_SOCKET_FAMILY_INVALID)
129 family = g_socket_address_get_family (dest_address);
131 socket = g_socket_new (family,
133 client->priv->protocol,
138 if (client->priv->local_address)
140 if (!g_socket_bind (socket,
141 client->priv->local_address,
145 g_object_unref (socket);
150 if (client->priv->timeout)
151 g_socket_set_timeout (socket, client->priv->timeout);
157 can_use_proxy (GSocketClient *client)
159 GSocketClientPrivate *priv = client->priv;
161 return priv->enable_proxy
162 && priv->type == G_SOCKET_TYPE_STREAM;
166 clarify_connect_error (GError *error,
167 GSocketConnectable *connectable,
168 GSocketAddress *address)
171 char *tmp_name = NULL;
173 if (G_IS_PROXY_ADDRESS (address))
175 name = tmp_name = g_inet_address_to_string (g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (address)));
177 g_prefix_error (&error, _("Could not connect to proxy server %s: "), name);
181 if (G_IS_NETWORK_ADDRESS (connectable))
182 name = g_network_address_get_hostname (G_NETWORK_ADDRESS (connectable));
183 else if (G_IS_NETWORK_SERVICE (connectable))
184 name = g_network_service_get_domain (G_NETWORK_SERVICE (connectable));
185 else if (G_IS_INET_SOCKET_ADDRESS (connectable))
186 name = tmp_name = g_inet_address_to_string (g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (connectable)));
191 g_prefix_error (&error, _("Could not connect to %s: "), name);
193 g_prefix_error (&error, _("Could not connect: "));
200 g_socket_client_init (GSocketClient *client)
202 client->priv = g_socket_client_get_instance_private (client);
203 client->priv->type = G_SOCKET_TYPE_STREAM;
204 client->priv->app_proxies = g_hash_table_new_full (g_str_hash,
211 * g_socket_client_new:
213 * Creates a new #GSocketClient with the default options.
215 * Returns: a #GSocketClient.
216 * Free the returned object with g_object_unref().
221 g_socket_client_new (void)
223 return g_object_new (G_TYPE_SOCKET_CLIENT, NULL);
227 g_socket_client_finalize (GObject *object)
229 GSocketClient *client = G_SOCKET_CLIENT (object);
231 g_clear_object (&client->priv->local_address);
232 g_clear_object (&client->priv->proxy_resolver);
234 G_OBJECT_CLASS (g_socket_client_parent_class)->finalize (object);
236 g_hash_table_unref (client->priv->app_proxies);
240 g_socket_client_get_property (GObject *object,
245 GSocketClient *client = G_SOCKET_CLIENT (object);
250 g_value_set_enum (value, client->priv->family);
254 g_value_set_enum (value, client->priv->type);
258 g_value_set_enum (value, client->priv->protocol);
261 case PROP_LOCAL_ADDRESS:
262 g_value_set_object (value, client->priv->local_address);
266 g_value_set_uint (value, client->priv->timeout);
269 case PROP_ENABLE_PROXY:
270 g_value_set_boolean (value, client->priv->enable_proxy);
274 g_value_set_boolean (value, g_socket_client_get_tls (client));
277 case PROP_TLS_VALIDATION_FLAGS:
278 g_value_set_flags (value, g_socket_client_get_tls_validation_flags (client));
281 case PROP_PROXY_RESOLVER:
282 g_value_set_object (value, g_socket_client_get_proxy_resolver (client));
286 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
291 g_socket_client_set_property (GObject *object,
296 GSocketClient *client = G_SOCKET_CLIENT (object);
301 g_socket_client_set_family (client, g_value_get_enum (value));
305 g_socket_client_set_socket_type (client, g_value_get_enum (value));
309 g_socket_client_set_protocol (client, g_value_get_enum (value));
312 case PROP_LOCAL_ADDRESS:
313 g_socket_client_set_local_address (client, g_value_get_object (value));
317 g_socket_client_set_timeout (client, g_value_get_uint (value));
320 case PROP_ENABLE_PROXY:
321 g_socket_client_set_enable_proxy (client, g_value_get_boolean (value));
325 g_socket_client_set_tls (client, g_value_get_boolean (value));
328 case PROP_TLS_VALIDATION_FLAGS:
329 g_socket_client_set_tls_validation_flags (client, g_value_get_flags (value));
332 case PROP_PROXY_RESOLVER:
333 g_socket_client_set_proxy_resolver (client, g_value_get_object (value));
337 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
342 * g_socket_client_get_family:
343 * @client: a #GSocketClient.
345 * Gets the socket family of the socket client.
347 * See g_socket_client_set_family() for details.
349 * Returns: a #GSocketFamily
354 g_socket_client_get_family (GSocketClient *client)
356 return client->priv->family;
360 * g_socket_client_set_family:
361 * @client: a #GSocketClient.
362 * @family: a #GSocketFamily
364 * Sets the socket family of the socket client.
365 * If this is set to something other than %G_SOCKET_FAMILY_INVALID
366 * then the sockets created by this object will be of the specified
369 * This might be useful for instance if you want to force the local
370 * connection to be an ipv4 socket, even though the address might
371 * be an ipv6 mapped to ipv4 address.
376 g_socket_client_set_family (GSocketClient *client,
377 GSocketFamily family)
379 if (client->priv->family == family)
382 client->priv->family = family;
383 g_object_notify (G_OBJECT (client), "family");
387 * g_socket_client_get_socket_type:
388 * @client: a #GSocketClient.
390 * Gets the socket type of the socket client.
392 * See g_socket_client_set_socket_type() for details.
394 * Returns: a #GSocketFamily
399 g_socket_client_get_socket_type (GSocketClient *client)
401 return client->priv->type;
405 * g_socket_client_set_socket_type:
406 * @client: a #GSocketClient.
407 * @type: a #GSocketType
409 * Sets the socket type of the socket client.
410 * The sockets created by this object will be of the specified
413 * It doesn't make sense to specify a type of %G_SOCKET_TYPE_DATAGRAM,
414 * as GSocketClient is used for connection oriented services.
419 g_socket_client_set_socket_type (GSocketClient *client,
422 if (client->priv->type == type)
425 client->priv->type = type;
426 g_object_notify (G_OBJECT (client), "type");
430 * g_socket_client_get_protocol:
431 * @client: a #GSocketClient
433 * Gets the protocol name type of the socket client.
435 * See g_socket_client_set_protocol() for details.
437 * Returns: a #GSocketProtocol
442 g_socket_client_get_protocol (GSocketClient *client)
444 return client->priv->protocol;
448 * g_socket_client_set_protocol:
449 * @client: a #GSocketClient.
450 * @protocol: a #GSocketProtocol
452 * Sets the protocol of the socket client.
453 * The sockets created by this object will use of the specified
456 * If @protocol is %0 that means to use the default
457 * protocol for the socket family and type.
462 g_socket_client_set_protocol (GSocketClient *client,
463 GSocketProtocol protocol)
465 if (client->priv->protocol == protocol)
468 client->priv->protocol = protocol;
469 g_object_notify (G_OBJECT (client), "protocol");
473 * g_socket_client_get_local_address:
474 * @client: a #GSocketClient.
476 * Gets the local address of the socket client.
478 * See g_socket_client_set_local_address() for details.
480 * Returns: (transfer none): a #GSocketAddress or %NULL. Do not free.
485 g_socket_client_get_local_address (GSocketClient *client)
487 return client->priv->local_address;
491 * g_socket_client_set_local_address:
492 * @client: a #GSocketClient.
493 * @address: (allow-none): a #GSocketAddress, or %NULL
495 * Sets the local address of the socket client.
496 * The sockets created by this object will bound to the
497 * specified address (if not %NULL) before connecting.
499 * This is useful if you want to ensure that the local
500 * side of the connection is on a specific port, or on
501 * a specific interface.
506 g_socket_client_set_local_address (GSocketClient *client,
507 GSocketAddress *address)
510 g_object_ref (address);
512 if (client->priv->local_address)
514 g_object_unref (client->priv->local_address);
516 client->priv->local_address = address;
517 g_object_notify (G_OBJECT (client), "local-address");
521 * g_socket_client_get_timeout:
522 * @client: a #GSocketClient
524 * Gets the I/O timeout time for sockets created by @client.
526 * See g_socket_client_set_timeout() for details.
528 * Returns: the timeout in seconds
533 g_socket_client_get_timeout (GSocketClient *client)
535 return client->priv->timeout;
540 * g_socket_client_set_timeout:
541 * @client: a #GSocketClient.
542 * @timeout: the timeout
544 * Sets the I/O timeout for sockets created by @client. @timeout is a
545 * time in seconds, or 0 for no timeout (the default).
547 * The timeout value affects the initial connection attempt as well,
548 * so setting this may cause calls to g_socket_client_connect(), etc,
549 * to fail with %G_IO_ERROR_TIMED_OUT.
554 g_socket_client_set_timeout (GSocketClient *client,
557 if (client->priv->timeout == timeout)
560 client->priv->timeout = timeout;
561 g_object_notify (G_OBJECT (client), "timeout");
565 * g_socket_client_get_enable_proxy:
566 * @client: a #GSocketClient.
568 * Gets the proxy enable state; see g_socket_client_set_enable_proxy()
570 * Returns: whether proxying is enabled
575 g_socket_client_get_enable_proxy (GSocketClient *client)
577 return client->priv->enable_proxy;
581 * g_socket_client_set_enable_proxy:
582 * @client: a #GSocketClient.
583 * @enable: whether to enable proxies
585 * Sets whether or not @client attempts to make connections via a
586 * proxy server. When enabled (the default), #GSocketClient will use a
587 * #GProxyResolver to determine if a proxy protocol such as SOCKS is
588 * needed, and automatically do the necessary proxy negotiation.
590 * See also g_socket_client_set_proxy_resolver().
595 g_socket_client_set_enable_proxy (GSocketClient *client,
599 if (client->priv->enable_proxy == enable)
602 client->priv->enable_proxy = enable;
603 g_object_notify (G_OBJECT (client), "enable-proxy");
607 * g_socket_client_get_tls:
608 * @client: a #GSocketClient.
610 * Gets whether @client creates TLS connections. See
611 * g_socket_client_set_tls() for details.
613 * Returns: whether @client uses TLS
618 g_socket_client_get_tls (GSocketClient *client)
620 return client->priv->tls;
624 * g_socket_client_set_tls:
625 * @client: a #GSocketClient.
626 * @tls: whether to use TLS
628 * Sets whether @client creates TLS (aka SSL) connections. If @tls is
629 * %TRUE, @client will wrap its connections in a #GTlsClientConnection
630 * and perform a TLS handshake when connecting.
632 * Note that since #GSocketClient must return a #GSocketConnection,
633 * but #GTlsClientConnection is not a #GSocketConnection, this
634 * actually wraps the resulting #GTlsClientConnection in a
635 * #GTcpWrapperConnection when returning it. You can use
636 * g_tcp_wrapper_connection_get_base_io_stream() on the return value
637 * to extract the #GTlsClientConnection.
639 * If you need to modify the behavior of the TLS handshake (eg, by
640 * setting a client-side certificate to use, or connecting to the
641 * #GTlsConnection::accept-certificate signal), you can connect to
642 * @client's #GSocketClient::event signal and wait for it to be
643 * emitted with %G_SOCKET_CLIENT_TLS_HANDSHAKING, which will give you
644 * a chance to see the #GTlsClientConnection before the handshake
650 g_socket_client_set_tls (GSocketClient *client,
654 if (tls == client->priv->tls)
657 client->priv->tls = tls;
658 g_object_notify (G_OBJECT (client), "tls");
662 * g_socket_client_get_tls_validation_flags:
663 * @client: a #GSocketClient.
665 * Gets the TLS validation flags used creating TLS connections via
668 * Returns: the TLS validation flags
673 g_socket_client_get_tls_validation_flags (GSocketClient *client)
675 return client->priv->tls_validation_flags;
679 * g_socket_client_set_tls_validation_flags:
680 * @client: a #GSocketClient.
681 * @flags: the validation flags
683 * Sets the TLS validation flags used when creating TLS connections
684 * via @client. The default value is %G_TLS_CERTIFICATE_VALIDATE_ALL.
689 g_socket_client_set_tls_validation_flags (GSocketClient *client,
690 GTlsCertificateFlags flags)
692 if (client->priv->tls_validation_flags != flags)
694 client->priv->tls_validation_flags = flags;
695 g_object_notify (G_OBJECT (client), "tls-validation-flags");
700 * g_socket_client_get_proxy_resolver:
701 * @client: a #GSocketClient.
703 * Gets the #GProxyResolver being used by @client. Normally, this will
704 * be the resolver returned by g_proxy_resolver_get_default(), but you
705 * can override it with g_socket_client_set_proxy_resolver().
707 * Returns: (transfer none): The #GProxyResolver being used by
713 g_socket_client_get_proxy_resolver (GSocketClient *client)
715 if (client->priv->proxy_resolver)
716 return client->priv->proxy_resolver;
718 return g_proxy_resolver_get_default ();
722 * g_socket_client_set_proxy_resolver:
723 * @client: a #GSocketClient.
724 * @proxy_resolver: (allow-none): a #GProxyResolver, or %NULL for the
727 * Overrides the #GProxyResolver used by @client. You can call this if
728 * you want to use specific proxies, rather than using the system
729 * default proxy settings.
731 * Note that whether or not the proxy resolver is actually used
732 * depends on the setting of #GSocketClient:enable-proxy, which is not
733 * changed by this function (but which is %TRUE by default)
738 g_socket_client_set_proxy_resolver (GSocketClient *client,
739 GProxyResolver *proxy_resolver)
741 /* We have to be careful to avoid calling
742 * g_proxy_resolver_get_default() until we're sure we need it,
743 * because trying to load the default proxy resolver module will
744 * break some test programs that aren't expecting it (eg,
748 if (client->priv->proxy_resolver)
749 g_object_unref (client->priv->proxy_resolver);
751 client->priv->proxy_resolver = proxy_resolver;
753 if (client->priv->proxy_resolver)
754 g_object_ref (client->priv->proxy_resolver);
758 g_socket_client_class_init (GSocketClientClass *class)
760 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
762 gobject_class->finalize = g_socket_client_finalize;
763 gobject_class->set_property = g_socket_client_set_property;
764 gobject_class->get_property = g_socket_client_get_property;
767 * GSocketClient::event:
768 * @client: the #GSocketClient
769 * @event: the event that is occurring
770 * @connectable: the #GSocketConnectable that @event is occurring on
771 * @connection: the current representation of the connection
773 * Emitted when @client's activity on @connectable changes state.
774 * Among other things, this can be used to provide progress
775 * information about a network connection in the UI. The meanings of
776 * the different @event values are as follows:
780 * <term>%G_SOCKET_CLIENT_RESOLVING:</term>
782 * @client is about to look up @connectable in DNS.
783 * @connection will be %NULL.
787 * <term>%G_SOCKET_CLIENT_RESOLVED:</term>
789 * @client has successfully resolved @connectable in DNS.
790 * @connection will be %NULL.
794 * <term>%G_SOCKET_CLIENT_CONNECTING:</term>
796 * @client is about to make a connection to a remote host;
797 * either a proxy server or the destination server itself.
798 * @connection is the #GSocketConnection, which is not yet
803 * <term>%G_SOCKET_CLIENT_CONNECTED:</term>
805 * @client has successfully connected to a remote host.
806 * @connection is the connected #GSocketConnection.
810 * <term>%G_SOCKET_CLIENT_PROXY_NEGOTIATING:</term>
812 * @client is about to negotiate with a proxy to get it to
813 * connect to @connectable. @connection is the
814 * #GSocketConnection to the proxy server.
818 * <term>%G_SOCKET_CLIENT_PROXY_NEGOTIATED:</term>
820 * @client has negotiated a connection to @connectable through
821 * a proxy server. @connection is the stream returned from
822 * g_proxy_connect(), which may or may not be a
823 * #GSocketConnection.
827 * <term>%G_SOCKET_CLIENT_TLS_HANDSHAKING:</term>
829 * @client is about to begin a TLS handshake. @connection is a
830 * #GTlsClientConnection.
834 * <term>%G_SOCKET_CLIENT_TLS_HANDSHAKED:</term>
836 * @client has successfully completed the TLS handshake.
837 * @connection is a #GTlsClientConnection.
841 * <term>%G_SOCKET_CLIENT_COMPLETE:</term>
843 * @client has either successfully connected to @connectable
844 * (in which case @connection is the #GSocketConnection that
845 * it will be returning to the caller) or has failed (in which
846 * case @connection is %NULL and the client is about to return
852 * Each event except %G_SOCKET_CLIENT_COMPLETE may be emitted
853 * multiple times (or not at all) for a given connectable (in
854 * particular, if @client ends up attempting to connect to more than
855 * one address). However, if @client emits the #GSocketClient::event
856 * signal at all for a given connectable, that it will always emit
857 * it with %G_SOCKET_CLIENT_COMPLETE when it is done.
859 * Note that there may be additional #GSocketClientEvent values in
860 * the future; unrecognized @event values should be ignored.
865 g_signal_new (I_("event"),
866 G_TYPE_FROM_CLASS (gobject_class),
868 G_STRUCT_OFFSET (GSocketClientClass, event),
872 G_TYPE_SOCKET_CLIENT_EVENT,
873 G_TYPE_SOCKET_CONNECTABLE,
876 g_object_class_install_property (gobject_class, PROP_FAMILY,
877 g_param_spec_enum ("family",
879 P_("The sockets address family to use for socket construction"),
880 G_TYPE_SOCKET_FAMILY,
881 G_SOCKET_FAMILY_INVALID,
884 G_PARAM_STATIC_STRINGS));
886 g_object_class_install_property (gobject_class, PROP_TYPE,
887 g_param_spec_enum ("type",
889 P_("The sockets type to use for socket construction"),
891 G_SOCKET_TYPE_STREAM,
894 G_PARAM_STATIC_STRINGS));
896 g_object_class_install_property (gobject_class, PROP_PROTOCOL,
897 g_param_spec_enum ("protocol",
898 P_("Socket protocol"),
899 P_("The protocol to use for socket construction, or 0 for default"),
900 G_TYPE_SOCKET_PROTOCOL,
901 G_SOCKET_PROTOCOL_DEFAULT,
904 G_PARAM_STATIC_STRINGS));
906 g_object_class_install_property (gobject_class, PROP_LOCAL_ADDRESS,
907 g_param_spec_object ("local-address",
909 P_("The local address constructed sockets will be bound to"),
910 G_TYPE_SOCKET_ADDRESS,
913 G_PARAM_STATIC_STRINGS));
915 g_object_class_install_property (gobject_class, PROP_TIMEOUT,
916 g_param_spec_uint ("timeout",
917 P_("Socket timeout"),
918 P_("The I/O timeout for sockets, or 0 for none"),
922 G_PARAM_STATIC_STRINGS));
924 g_object_class_install_property (gobject_class, PROP_ENABLE_PROXY,
925 g_param_spec_boolean ("enable-proxy",
927 P_("Enable proxy support"),
931 G_PARAM_STATIC_STRINGS));
933 g_object_class_install_property (gobject_class, PROP_TLS,
934 g_param_spec_boolean ("tls",
936 P_("Whether to create TLS connections"),
940 G_PARAM_STATIC_STRINGS));
941 g_object_class_install_property (gobject_class, PROP_TLS_VALIDATION_FLAGS,
942 g_param_spec_flags ("tls-validation-flags",
943 P_("TLS validation flags"),
944 P_("TLS validation flags to use"),
945 G_TYPE_TLS_CERTIFICATE_FLAGS,
946 G_TLS_CERTIFICATE_VALIDATE_ALL,
949 G_PARAM_STATIC_STRINGS));
952 * GSocketClient:proxy-resolver:
954 * The proxy resolver to use
958 g_object_class_install_property (gobject_class, PROP_PROXY_RESOLVER,
959 g_param_spec_object ("proxy-resolver",
960 P_("Proxy resolver"),
961 P_("The proxy resolver to use"),
962 G_TYPE_PROXY_RESOLVER,
965 G_PARAM_STATIC_STRINGS));
969 g_socket_client_emit_event (GSocketClient *client,
970 GSocketClientEvent event,
971 GSocketConnectable *connectable,
972 GIOStream *connection)
974 g_signal_emit (client, signals[EVENT], 0,
975 event, connectable, connection);
979 * g_socket_client_connect:
980 * @client: a #GSocketClient.
981 * @connectable: a #GSocketConnectable specifying the remote address.
982 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
983 * @error: #GError for error reporting, or %NULL to ignore.
985 * Tries to resolve the @connectable and make a network connection to it.
987 * Upon a successful connection, a new #GSocketConnection is constructed
988 * and returned. The caller owns this new object and must drop their
989 * reference to it when finished with it.
991 * The type of the #GSocketConnection object returned depends on the type of
992 * the underlying socket that is used. For instance, for a TCP/IP connection
993 * it will be a #GTcpConnection.
995 * The socket created will be the same family as the address that the
996 * @connectable resolves to, unless family is set with g_socket_client_set_family()
997 * or indirectly via g_socket_client_set_local_address(). The socket type
998 * defaults to %G_SOCKET_TYPE_STREAM but can be set with
999 * g_socket_client_set_socket_type().
1001 * If a local address is specified with g_socket_client_set_local_address() the
1002 * socket will be bound to this address before connecting.
1004 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1009 g_socket_client_connect (GSocketClient *client,
1010 GSocketConnectable *connectable,
1011 GCancellable *cancellable,
1014 GIOStream *connection = NULL;
1015 GSocketAddressEnumerator *enumerator = NULL;
1016 GError *last_error, *tmp_error;
1020 if (can_use_proxy (client))
1022 enumerator = g_socket_connectable_proxy_enumerate (connectable);
1023 if (client->priv->proxy_resolver &&
1024 G_IS_PROXY_ADDRESS_ENUMERATOR (enumerator))
1026 g_object_set (G_OBJECT (enumerator),
1027 "proxy-resolver", client->priv->proxy_resolver,
1032 enumerator = g_socket_connectable_enumerate (connectable);
1034 while (connection == NULL)
1036 GSocketAddress *address = NULL;
1037 gboolean application_proxy = FALSE;
1039 gboolean using_proxy;
1041 if (g_cancellable_is_cancelled (cancellable))
1043 g_clear_error (error);
1044 g_cancellable_set_error_if_cancelled (cancellable, error);
1049 g_socket_client_emit_event (client, G_SOCKET_CLIENT_RESOLVING,
1051 address = g_socket_address_enumerator_next (enumerator, cancellable,
1054 if (address == NULL)
1058 g_clear_error (&last_error);
1059 g_propagate_error (error, tmp_error);
1061 else if (last_error)
1063 g_propagate_error (error, last_error);
1066 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
1067 _("Unknown error on connect"));
1070 g_socket_client_emit_event (client, G_SOCKET_CLIENT_RESOLVED,
1073 using_proxy = (G_IS_PROXY_ADDRESS (address) &&
1074 client->priv->enable_proxy);
1076 /* clear error from previous attempt */
1077 g_clear_error (&last_error);
1079 socket = create_socket (client, address, &last_error);
1082 g_object_unref (address);
1086 connection = (GIOStream *)g_socket_connection_factory_create_connection (socket);
1087 g_socket_client_emit_event (client, G_SOCKET_CLIENT_CONNECTING, connectable, connection);
1089 if (g_socket_connection_connect (G_SOCKET_CONNECTION (connection),
1090 address, cancellable, &last_error))
1092 g_socket_client_emit_event (client, G_SOCKET_CLIENT_CONNECTED, connectable, connection);
1096 clarify_connect_error (last_error, connectable, address);
1097 g_object_unref (connection);
1101 if (connection && using_proxy)
1103 GProxyAddress *proxy_addr = G_PROXY_ADDRESS (address);
1104 const gchar *protocol;
1107 protocol = g_proxy_address_get_protocol (proxy_addr);
1108 proxy = g_proxy_get_default_for_protocol (protocol);
1110 /* The connection should not be anything else then TCP Connection,
1111 * but let's put a safety guard in case
1113 if (!G_IS_TCP_CONNECTION (connection))
1115 g_critical ("Trying to proxy over non-TCP connection, this is "
1116 "most likely a bug in GLib IO library.");
1118 g_set_error_literal (&last_error,
1119 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
1120 _("Proxying over a non-TCP connection is not supported."));
1122 g_object_unref (connection);
1127 GIOStream *proxy_connection;
1129 g_socket_client_emit_event (client, G_SOCKET_CLIENT_PROXY_NEGOTIATING, connectable, connection);
1130 proxy_connection = g_proxy_connect (proxy,
1135 g_object_unref (connection);
1136 connection = proxy_connection;
1137 g_object_unref (proxy);
1140 g_socket_client_emit_event (client, G_SOCKET_CLIENT_PROXY_NEGOTIATED, connectable, connection);
1142 else if (!g_hash_table_lookup_extended (client->priv->app_proxies,
1143 protocol, NULL, NULL))
1145 g_set_error (&last_error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
1146 _("Proxy protocol '%s' is not supported."),
1148 g_object_unref (connection);
1153 application_proxy = TRUE;
1157 if (!application_proxy && connection && client->priv->tls)
1161 tlsconn = g_tls_client_connection_new (connection, connectable, &last_error);
1162 g_object_unref (connection);
1163 connection = tlsconn;
1167 g_tls_client_connection_set_validation_flags (G_TLS_CLIENT_CONNECTION (tlsconn),
1168 client->priv->tls_validation_flags);
1169 g_socket_client_emit_event (client, G_SOCKET_CLIENT_TLS_HANDSHAKING, connectable, connection);
1170 if (g_tls_connection_handshake (G_TLS_CONNECTION (tlsconn),
1171 cancellable, &last_error))
1173 g_socket_client_emit_event (client, G_SOCKET_CLIENT_TLS_HANDSHAKED, connectable, connection);
1177 g_object_unref (tlsconn);
1183 if (connection && !G_IS_SOCKET_CONNECTION (connection))
1185 GSocketConnection *wrapper_connection;
1187 wrapper_connection = g_tcp_wrapper_connection_new (connection, socket);
1188 g_object_unref (connection);
1189 connection = (GIOStream *)wrapper_connection;
1192 g_object_unref (socket);
1193 g_object_unref (address);
1195 g_object_unref (enumerator);
1197 g_socket_client_emit_event (client, G_SOCKET_CLIENT_COMPLETE, connectable, connection);
1198 return G_SOCKET_CONNECTION (connection);
1202 * g_socket_client_connect_to_host:
1203 * @client: a #GSocketClient
1204 * @host_and_port: the name and optionally port of the host to connect to
1205 * @default_port: the default port to connect to
1206 * @cancellable: (allow-none): a #GCancellable, or %NULL
1207 * @error: a pointer to a #GError, or %NULL
1209 * This is a helper function for g_socket_client_connect().
1211 * Attempts to create a TCP connection to the named host.
1213 * @host_and_port may be in any of a number of recognized formats; an IPv6
1214 * address, an IPv4 address, or a domain name (in which case a DNS
1215 * lookup is performed). Quoting with [] is supported for all address
1216 * types. A port override may be specified in the usual way with a
1217 * colon. Ports may be given as decimal numbers or symbolic names (in
1218 * which case an /etc/services lookup is performed).
1220 * If no port override is given in @host_and_port then @default_port will be
1221 * used as the port number to connect to.
1223 * In general, @host_and_port is expected to be provided by the user (allowing
1224 * them to give the hostname, and a port override if necessary) and
1225 * @default_port is expected to be provided by the application.
1227 * In the case that an IP address is given, a single connection
1228 * attempt is made. In the case that a name is given, multiple
1229 * connection attempts may be made, in turn and according to the
1230 * number of address records in DNS, until a connection succeeds.
1232 * Upon a successful connection, a new #GSocketConnection is constructed
1233 * and returned. The caller owns this new object and must drop their
1234 * reference to it when finished with it.
1236 * In the event of any failure (DNS error, service not found, no hosts
1237 * connectable) %NULL is returned and @error (if non-%NULL) is set
1240 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1245 g_socket_client_connect_to_host (GSocketClient *client,
1246 const gchar *host_and_port,
1247 guint16 default_port,
1248 GCancellable *cancellable,
1251 GSocketConnectable *connectable;
1252 GSocketConnection *connection;
1254 connectable = g_network_address_parse (host_and_port, default_port, error);
1255 if (connectable == NULL)
1258 connection = g_socket_client_connect (client, connectable,
1259 cancellable, error);
1260 g_object_unref (connectable);
1266 * g_socket_client_connect_to_service:
1267 * @client: a #GSocketConnection
1268 * @domain: a domain name
1269 * @service: the name of the service to connect to
1270 * @cancellable: (allow-none): a #GCancellable, or %NULL
1271 * @error: a pointer to a #GError, or %NULL
1273 * Attempts to create a TCP connection to a service.
1275 * This call looks up the SRV record for @service at @domain for the
1276 * "tcp" protocol. It then attempts to connect, in turn, to each of
1277 * the hosts providing the service until either a connection succeeds
1278 * or there are no hosts remaining.
1280 * Upon a successful connection, a new #GSocketConnection is constructed
1281 * and returned. The caller owns this new object and must drop their
1282 * reference to it when finished with it.
1284 * In the event of any failure (DNS error, service not found, no hosts
1285 * connectable) %NULL is returned and @error (if non-%NULL) is set
1288 * Returns: (transfer full): a #GSocketConnection if successful, or %NULL on error
1291 g_socket_client_connect_to_service (GSocketClient *client,
1292 const gchar *domain,
1293 const gchar *service,
1294 GCancellable *cancellable,
1297 GSocketConnectable *connectable;
1298 GSocketConnection *connection;
1300 connectable = g_network_service_new (service, "tcp", domain);
1301 connection = g_socket_client_connect (client, connectable,
1302 cancellable, error);
1303 g_object_unref (connectable);
1309 * g_socket_client_connect_to_uri:
1310 * @client: a #GSocketClient
1311 * @uri: A network URI
1312 * @default_port: the default port to connect to
1313 * @cancellable: (allow-none): a #GCancellable, or %NULL
1314 * @error: a pointer to a #GError, or %NULL
1316 * This is a helper function for g_socket_client_connect().
1318 * Attempts to create a TCP connection with a network URI.
1320 * @uri may be any valid URI containing an "authority" (hostname/port)
1321 * component. If a port is not specified in the URI, @default_port
1322 * will be used. TLS will be negotiated if #GSocketClient:tls is %TRUE.
1323 * (#GSocketClient does not know to automatically assume TLS for
1324 * certain URI schemes.)
1326 * Using this rather than g_socket_client_connect() or
1327 * g_socket_client_connect_to_host() allows #GSocketClient to
1328 * determine when to use application-specific proxy protocols.
1330 * Upon a successful connection, a new #GSocketConnection is constructed
1331 * and returned. The caller owns this new object and must drop their
1332 * reference to it when finished with it.
1334 * In the event of any failure (DNS error, service not found, no hosts
1335 * connectable) %NULL is returned and @error (if non-%NULL) is set
1338 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1343 g_socket_client_connect_to_uri (GSocketClient *client,
1345 guint16 default_port,
1346 GCancellable *cancellable,
1349 GSocketConnectable *connectable;
1350 GSocketConnection *connection;
1352 connectable = g_network_address_parse_uri (uri, default_port, error);
1353 if (connectable == NULL)
1356 connection = g_socket_client_connect (client, connectable,
1357 cancellable, error);
1358 g_object_unref (connectable);
1366 GSocketClient *client;
1368 GSocketConnectable *connectable;
1369 GSocketAddressEnumerator *enumerator;
1370 GProxyAddress *proxy_addr;
1371 GSocketAddress *current_addr;
1372 GSocket *current_socket;
1373 GIOStream *connection;
1376 } GSocketClientAsyncConnectData;
1379 g_socket_client_async_connect_data_free (GSocketClientAsyncConnectData *data)
1381 g_clear_object (&data->connectable);
1382 g_clear_object (&data->enumerator);
1383 g_clear_object (&data->proxy_addr);
1384 g_clear_object (&data->current_addr);
1385 g_clear_object (&data->current_socket);
1386 g_clear_object (&data->connection);
1388 g_clear_error (&data->last_error);
1390 g_slice_free (GSocketClientAsyncConnectData, data);
1394 g_socket_client_async_connect_complete (GSocketClientAsyncConnectData *data)
1396 g_assert (data->connection);
1398 if (!G_IS_SOCKET_CONNECTION (data->connection))
1400 GSocketConnection *wrapper_connection;
1402 wrapper_connection = g_tcp_wrapper_connection_new (data->connection,
1403 data->current_socket);
1404 g_object_unref (data->connection);
1405 data->connection = (GIOStream *)wrapper_connection;
1408 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, data->connection);
1409 g_task_return_pointer (data->task, data->connection, g_object_unref);
1410 data->connection = NULL;
1411 g_object_unref (data->task);
1416 g_socket_client_enumerator_callback (GObject *object,
1417 GAsyncResult *result,
1418 gpointer user_data);
1421 set_last_error (GSocketClientAsyncConnectData *data,
1424 g_clear_error (&data->last_error);
1425 data->last_error = error;
1429 enumerator_next_async (GSocketClientAsyncConnectData *data)
1431 /* We need to cleanup the state */
1432 g_clear_object (&data->current_socket);
1433 g_clear_object (&data->current_addr);
1434 g_clear_object (&data->proxy_addr);
1435 g_clear_object (&data->connection);
1437 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_RESOLVING, data->connectable, NULL);
1438 g_socket_address_enumerator_next_async (data->enumerator,
1439 g_task_get_cancellable (data->task),
1440 g_socket_client_enumerator_callback,
1445 g_socket_client_tls_handshake_callback (GObject *object,
1446 GAsyncResult *result,
1449 GSocketClientAsyncConnectData *data = user_data;
1451 if (g_tls_connection_handshake_finish (G_TLS_CONNECTION (object),
1455 g_object_unref (data->connection);
1456 data->connection = G_IO_STREAM (object);
1458 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_TLS_HANDSHAKED, data->connectable, data->connection);
1459 g_socket_client_async_connect_complete (data);
1463 g_object_unref (object);
1464 enumerator_next_async (data);
1469 g_socket_client_tls_handshake (GSocketClientAsyncConnectData *data)
1473 if (!data->client->priv->tls)
1475 g_socket_client_async_connect_complete (data);
1479 tlsconn = g_tls_client_connection_new (data->connection,
1484 g_tls_client_connection_set_validation_flags (G_TLS_CLIENT_CONNECTION (tlsconn),
1485 data->client->priv->tls_validation_flags);
1486 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_TLS_HANDSHAKING, data->connectable, G_IO_STREAM (tlsconn));
1487 g_tls_connection_handshake_async (G_TLS_CONNECTION (tlsconn),
1489 g_task_get_cancellable (data->task),
1490 g_socket_client_tls_handshake_callback,
1495 enumerator_next_async (data);
1500 g_socket_client_proxy_connect_callback (GObject *object,
1501 GAsyncResult *result,
1504 GSocketClientAsyncConnectData *data = user_data;
1506 g_object_unref (data->connection);
1507 data->connection = g_proxy_connect_finish (G_PROXY (object),
1510 if (data->connection)
1512 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_PROXY_NEGOTIATED, data->connectable, data->connection);
1516 enumerator_next_async (data);
1520 g_socket_client_tls_handshake (data);
1524 g_socket_client_connected_callback (GObject *source,
1525 GAsyncResult *result,
1528 GSocketClientAsyncConnectData *data = user_data;
1529 GError *error = NULL;
1531 const gchar *protocol;
1533 if (!g_socket_connection_connect_finish (G_SOCKET_CONNECTION (source),
1536 clarify_connect_error (error, data->connectable,
1537 data->current_addr);
1538 set_last_error (data, error);
1541 enumerator_next_async (data);
1545 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_CONNECTED, data->connectable, data->connection);
1547 /* wrong, but backward compatible */
1548 g_socket_set_blocking (data->current_socket, TRUE);
1550 if (!data->proxy_addr)
1552 g_socket_client_tls_handshake (data);
1556 protocol = g_proxy_address_get_protocol (data->proxy_addr);
1557 proxy = g_proxy_get_default_for_protocol (protocol);
1559 /* The connection should not be anything other than TCP,
1560 * but let's put a safety guard in case
1562 if (!G_IS_TCP_CONNECTION (data->connection))
1564 g_critical ("Trying to proxy over non-TCP connection, this is "
1565 "most likely a bug in GLib IO library.");
1567 g_set_error_literal (&data->last_error,
1568 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
1569 _("Proxying over a non-TCP connection is not supported."));
1571 enumerator_next_async (data);
1575 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_PROXY_NEGOTIATING, data->connectable, data->connection);
1576 g_proxy_connect_async (proxy,
1579 g_task_get_cancellable (data->task),
1580 g_socket_client_proxy_connect_callback,
1582 g_object_unref (proxy);
1584 else if (!g_hash_table_lookup_extended (data->client->priv->app_proxies,
1585 protocol, NULL, NULL))
1587 g_clear_error (&data->last_error);
1589 g_set_error (&data->last_error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
1590 _("Proxy protocol '%s' is not supported."),
1593 enumerator_next_async (data);
1597 /* Simply complete the connection, we don't want to do TLS handshake
1598 * as the application proxy handling may need proxy handshake first */
1599 g_socket_client_async_connect_complete (data);
1604 g_socket_client_enumerator_callback (GObject *object,
1605 GAsyncResult *result,
1608 GSocketClientAsyncConnectData *data = user_data;
1609 GSocketAddress *address = NULL;
1611 GError *error = NULL;
1613 if (g_task_return_error_if_cancelled (data->task))
1616 address = g_socket_address_enumerator_next_finish (data->enumerator,
1618 if (address == NULL)
1620 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, NULL);
1623 if (data->last_error)
1625 error = data->last_error;
1626 data->last_error = NULL;
1630 g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
1631 _("Unknown error on connect"));
1634 g_task_return_error (data->task, error);
1635 g_object_unref (data->task);
1639 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_RESOLVED,
1640 data->connectable, NULL);
1642 if (G_IS_PROXY_ADDRESS (address) &&
1643 data->client->priv->enable_proxy)
1644 data->proxy_addr = g_object_ref (G_PROXY_ADDRESS (address));
1646 g_clear_error (&data->last_error);
1648 socket = create_socket (data->client, address, &data->last_error);
1651 g_object_unref (address);
1652 enumerator_next_async (data);
1656 data->current_socket = socket;
1657 data->current_addr = address;
1658 data->connection = (GIOStream *) g_socket_connection_factory_create_connection (socket);
1660 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_CONNECTING, data->connectable, data->connection);
1661 g_socket_connection_connect_async (G_SOCKET_CONNECTION (data->connection),
1663 g_task_get_cancellable (data->task),
1664 g_socket_client_connected_callback, data);
1668 * g_socket_client_connect_async:
1669 * @client: a #GSocketClient
1670 * @connectable: a #GSocketConnectable specifying the remote address.
1671 * @cancellable: (allow-none): a #GCancellable, or %NULL
1672 * @callback: (scope async): a #GAsyncReadyCallback
1673 * @user_data: (closure): user data for the callback
1675 * This is the asynchronous version of g_socket_client_connect().
1677 * When the operation is finished @callback will be
1678 * called. You can then call g_socket_client_connect_finish() to get
1679 * the result of the operation.
1684 g_socket_client_connect_async (GSocketClient *client,
1685 GSocketConnectable *connectable,
1686 GCancellable *cancellable,
1687 GAsyncReadyCallback callback,
1690 GSocketClientAsyncConnectData *data;
1692 g_return_if_fail (G_IS_SOCKET_CLIENT (client));
1694 data = g_slice_new0 (GSocketClientAsyncConnectData);
1695 data->client = client;
1696 data->connectable = g_object_ref (connectable);
1698 if (can_use_proxy (client))
1700 data->enumerator = g_socket_connectable_proxy_enumerate (connectable);
1701 if (client->priv->proxy_resolver &&
1702 G_IS_PROXY_ADDRESS_ENUMERATOR (data->enumerator))
1704 g_object_set (G_OBJECT (data->enumerator),
1705 "proxy-resolver", client->priv->proxy_resolver,
1710 data->enumerator = g_socket_connectable_enumerate (connectable);
1712 data->task = g_task_new (client, cancellable, callback, user_data);
1713 g_task_set_task_data (data->task, data, (GDestroyNotify)g_socket_client_async_connect_data_free);
1715 enumerator_next_async (data);
1719 * g_socket_client_connect_to_host_async:
1720 * @client: a #GSocketClient
1721 * @host_and_port: the name and optionally the port of the host to connect to
1722 * @default_port: the default port to connect to
1723 * @cancellable: (allow-none): a #GCancellable, or %NULL
1724 * @callback: (scope async): a #GAsyncReadyCallback
1725 * @user_data: (closure): user data for the callback
1727 * This is the asynchronous version of g_socket_client_connect_to_host().
1729 * When the operation is finished @callback will be
1730 * called. You can then call g_socket_client_connect_to_host_finish() to get
1731 * the result of the operation.
1736 g_socket_client_connect_to_host_async (GSocketClient *client,
1737 const gchar *host_and_port,
1738 guint16 default_port,
1739 GCancellable *cancellable,
1740 GAsyncReadyCallback callback,
1743 GSocketConnectable *connectable;
1747 connectable = g_network_address_parse (host_and_port, default_port,
1749 if (connectable == NULL)
1751 g_task_report_error (client, callback, user_data,
1752 g_socket_client_connect_to_host_async,
1757 g_socket_client_connect_async (client,
1758 connectable, cancellable,
1759 callback, user_data);
1760 g_object_unref (connectable);
1765 * g_socket_client_connect_to_service_async:
1766 * @client: a #GSocketClient
1767 * @domain: a domain name
1768 * @service: the name of the service to connect to
1769 * @cancellable: (allow-none): a #GCancellable, or %NULL
1770 * @callback: (scope async): a #GAsyncReadyCallback
1771 * @user_data: (closure): user data for the callback
1773 * This is the asynchronous version of
1774 * g_socket_client_connect_to_service().
1779 g_socket_client_connect_to_service_async (GSocketClient *client,
1780 const gchar *domain,
1781 const gchar *service,
1782 GCancellable *cancellable,
1783 GAsyncReadyCallback callback,
1786 GSocketConnectable *connectable;
1788 connectable = g_network_service_new (service, "tcp", domain);
1789 g_socket_client_connect_async (client,
1790 connectable, cancellable,
1791 callback, user_data);
1792 g_object_unref (connectable);
1796 * g_socket_client_connect_to_uri_async:
1797 * @client: a #GSocketClient
1798 * @uri: a network uri
1799 * @default_port: the default port to connect to
1800 * @cancellable: (allow-none): a #GCancellable, or %NULL
1801 * @callback: (scope async): a #GAsyncReadyCallback
1802 * @user_data: (closure): user data for the callback
1804 * This is the asynchronous version of g_socket_client_connect_to_uri().
1806 * When the operation is finished @callback will be
1807 * called. You can then call g_socket_client_connect_to_uri_finish() to get
1808 * the result of the operation.
1813 g_socket_client_connect_to_uri_async (GSocketClient *client,
1815 guint16 default_port,
1816 GCancellable *cancellable,
1817 GAsyncReadyCallback callback,
1820 GSocketConnectable *connectable;
1824 connectable = g_network_address_parse_uri (uri, default_port, &error);
1825 if (connectable == NULL)
1827 g_task_report_error (client, callback, user_data,
1828 g_socket_client_connect_to_uri_async,
1833 g_socket_client_connect_async (client,
1834 connectable, cancellable,
1835 callback, user_data);
1836 g_object_unref (connectable);
1842 * g_socket_client_connect_finish:
1843 * @client: a #GSocketClient.
1844 * @result: a #GAsyncResult.
1845 * @error: a #GError location to store the error occurring, or %NULL to
1848 * Finishes an async connect operation. See g_socket_client_connect_async()
1850 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1855 g_socket_client_connect_finish (GSocketClient *client,
1856 GAsyncResult *result,
1859 g_return_val_if_fail (g_task_is_valid (result, client), NULL);
1861 return g_task_propagate_pointer (G_TASK (result), error);
1865 * g_socket_client_connect_to_host_finish:
1866 * @client: a #GSocketClient.
1867 * @result: a #GAsyncResult.
1868 * @error: a #GError location to store the error occurring, or %NULL to
1871 * Finishes an async connect operation. See g_socket_client_connect_to_host_async()
1873 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1878 g_socket_client_connect_to_host_finish (GSocketClient *client,
1879 GAsyncResult *result,
1882 return g_socket_client_connect_finish (client, result, error);
1886 * g_socket_client_connect_to_service_finish:
1887 * @client: a #GSocketClient.
1888 * @result: a #GAsyncResult.
1889 * @error: a #GError location to store the error occurring, or %NULL to
1892 * Finishes an async connect operation. See g_socket_client_connect_to_service_async()
1894 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1899 g_socket_client_connect_to_service_finish (GSocketClient *client,
1900 GAsyncResult *result,
1903 return g_socket_client_connect_finish (client, result, error);
1907 * g_socket_client_connect_to_uri_finish:
1908 * @client: a #GSocketClient.
1909 * @result: a #GAsyncResult.
1910 * @error: a #GError location to store the error occurring, or %NULL to
1913 * Finishes an async connect operation. See g_socket_client_connect_to_uri_async()
1915 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1920 g_socket_client_connect_to_uri_finish (GSocketClient *client,
1921 GAsyncResult *result,
1924 return g_socket_client_connect_finish (client, result, error);
1928 * g_socket_client_add_application_proxy:
1929 * @client: a #GSocketClient
1930 * @protocol: The proxy protocol
1932 * Enable proxy protocols to be handled by the application. When the
1933 * indicated proxy protocol is returned by the #GProxyResolver,
1934 * #GSocketClient will consider this protocol as supported but will
1935 * not try to find a #GProxy instance to handle handshaking. The
1936 * application must check for this case by calling
1937 * g_socket_connection_get_remote_address() on the returned
1938 * #GSocketConnection, and seeing if it's a #GProxyAddress of the
1939 * appropriate type, to determine whether or not it needs to handle
1940 * the proxy handshaking itself.
1942 * This should be used for proxy protocols that are dialects of
1943 * another protocol such as HTTP proxy. It also allows cohabitation of
1944 * proxy protocols that are reused between protocols. A good example
1945 * is HTTP. It can be used to proxy HTTP, FTP and Gopher and can also
1946 * be use as generic socket proxy through the HTTP CONNECT method.
1948 * When the proxy is detected as being an application proxy, TLS handshake
1949 * will be skipped. This is required to let the application do the proxy
1950 * specific handshake.
1953 g_socket_client_add_application_proxy (GSocketClient *client,
1954 const gchar *protocol)
1956 g_hash_table_insert (client->priv->app_proxies, g_strdup (protocol), NULL);