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/gsimpleasyncresult.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/gsocketaddress.h>
45 #include <gio/gtcpconnection.h>
46 #include <gio/gtcpwrapperconnection.h>
47 #include <gio/gtlscertificate.h>
48 #include <gio/gtlsclientconnection.h>
49 #include <gio/ginetaddress.h>
54 * SECTION:gsocketclient
55 * @short_description: Helper for connecting to a network service
57 * @see_also: #GSocketConnection, #GSocketListener
59 * #GSocketClient is a high-level utility class for connecting to a
60 * network host using a connection oriented socket type.
62 * You create a #GSocketClient object, set any options you want, and then
63 * call a sync or async connect operation, which returns a #GSocketConnection
64 * subclass on success.
66 * The type of the #GSocketConnection object returned depends on the type of
67 * the underlying socket that is in use. For instance, for a TCP/IP connection
68 * it will be a #GTcpConnection.
74 G_DEFINE_TYPE (GSocketClient, g_socket_client, G_TYPE_OBJECT);
82 static guint signals[LAST_SIGNAL] = { 0 };
94 PROP_TLS_VALIDATION_FLAGS
97 struct _GSocketClientPrivate
101 GSocketProtocol protocol;
102 GSocketAddress *local_address;
104 gboolean enable_proxy;
105 GHashTable *app_proxies;
107 GTlsCertificateFlags tls_validation_flags;
111 create_socket (GSocketClient *client,
112 GSocketAddress *dest_address,
115 GSocketFamily family;
118 family = client->priv->family;
119 if (family == G_SOCKET_FAMILY_INVALID &&
120 client->priv->local_address != NULL)
121 family = g_socket_address_get_family (client->priv->local_address);
122 if (family == G_SOCKET_FAMILY_INVALID)
123 family = g_socket_address_get_family (dest_address);
125 socket = g_socket_new (family,
127 client->priv->protocol,
132 if (client->priv->local_address)
134 if (!g_socket_bind (socket,
135 client->priv->local_address,
139 g_object_unref (socket);
144 if (client->priv->timeout)
145 g_socket_set_timeout (socket, client->priv->timeout);
151 can_use_proxy (GSocketClient *client)
153 GSocketClientPrivate *priv = client->priv;
155 return priv->enable_proxy
156 && priv->type == G_SOCKET_TYPE_STREAM;
160 clarify_connect_error (GError *error,
161 GSocketConnectable *connectable,
162 GSocketAddress *address)
165 char *tmp_name = NULL;
167 if (G_IS_PROXY_ADDRESS (address))
169 name = tmp_name = g_inet_address_to_string (g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (address)));
171 g_prefix_error (&error, _("Could not connect to proxy server %s: "), name);
175 if (G_IS_NETWORK_ADDRESS (connectable))
176 name = g_network_address_get_hostname (G_NETWORK_ADDRESS (connectable));
177 else if (G_IS_NETWORK_SERVICE (connectable))
178 name = g_network_service_get_domain (G_NETWORK_SERVICE (connectable));
179 else if (G_IS_INET_SOCKET_ADDRESS (connectable))
180 name = tmp_name = g_inet_address_to_string (g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (connectable)));
185 g_prefix_error (&error, _("Could not connect to %s: "), name);
187 g_prefix_error (&error, _("Could not connect: "));
194 g_socket_client_init (GSocketClient *client)
196 client->priv = G_TYPE_INSTANCE_GET_PRIVATE (client,
197 G_TYPE_SOCKET_CLIENT,
198 GSocketClientPrivate);
199 client->priv->type = G_SOCKET_TYPE_STREAM;
200 client->priv->app_proxies = g_hash_table_new_full (g_str_hash,
207 * g_socket_client_new:
209 * Creates a new #GSocketClient with the default options.
211 * Returns: a #GSocketClient.
212 * Free the returned object with g_object_unref().
217 g_socket_client_new (void)
219 return g_object_new (G_TYPE_SOCKET_CLIENT, NULL);
223 g_socket_client_finalize (GObject *object)
225 GSocketClient *client = G_SOCKET_CLIENT (object);
227 if (client->priv->local_address)
228 g_object_unref (client->priv->local_address);
230 if (G_OBJECT_CLASS (g_socket_client_parent_class)->finalize)
231 (*G_OBJECT_CLASS (g_socket_client_parent_class)->finalize) (object);
233 g_hash_table_unref (client->priv->app_proxies);
237 g_socket_client_get_property (GObject *object,
242 GSocketClient *client = G_SOCKET_CLIENT (object);
247 g_value_set_enum (value, client->priv->family);
251 g_value_set_enum (value, client->priv->type);
255 g_value_set_enum (value, client->priv->protocol);
258 case PROP_LOCAL_ADDRESS:
259 g_value_set_object (value, client->priv->local_address);
263 g_value_set_uint (value, client->priv->timeout);
266 case PROP_ENABLE_PROXY:
267 g_value_set_boolean (value, client->priv->enable_proxy);
271 g_value_set_boolean (value, g_socket_client_get_tls (client));
274 case PROP_TLS_VALIDATION_FLAGS:
275 g_value_set_flags (value, g_socket_client_get_tls_validation_flags (client));
279 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
284 g_socket_client_set_property (GObject *object,
289 GSocketClient *client = G_SOCKET_CLIENT (object);
294 g_socket_client_set_family (client, g_value_get_enum (value));
298 g_socket_client_set_socket_type (client, g_value_get_enum (value));
302 g_socket_client_set_protocol (client, g_value_get_enum (value));
305 case PROP_LOCAL_ADDRESS:
306 g_socket_client_set_local_address (client, g_value_get_object (value));
310 g_socket_client_set_timeout (client, g_value_get_uint (value));
313 case PROP_ENABLE_PROXY:
314 g_socket_client_set_enable_proxy (client, g_value_get_boolean (value));
318 g_socket_client_set_tls (client, g_value_get_boolean (value));
321 case PROP_TLS_VALIDATION_FLAGS:
322 g_socket_client_set_tls_validation_flags (client, g_value_get_flags (value));
326 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
331 * g_socket_client_get_family:
332 * @client: a #GSocketClient.
334 * Gets the socket family of the socket client.
336 * See g_socket_client_set_family() for details.
338 * Returns: a #GSocketFamily
343 g_socket_client_get_family (GSocketClient *client)
345 return client->priv->family;
349 * g_socket_client_set_family:
350 * @client: a #GSocketClient.
351 * @family: a #GSocketFamily
353 * Sets the socket family of the socket client.
354 * If this is set to something other than %G_SOCKET_FAMILY_INVALID
355 * then the sockets created by this object will be of the specified
358 * This might be useful for instance if you want to force the local
359 * connection to be an ipv4 socket, even though the address might
360 * be an ipv6 mapped to ipv4 address.
365 g_socket_client_set_family (GSocketClient *client,
366 GSocketFamily family)
368 if (client->priv->family == family)
371 client->priv->family = family;
372 g_object_notify (G_OBJECT (client), "family");
376 * g_socket_client_get_socket_type:
377 * @client: a #GSocketClient.
379 * Gets the socket type of the socket client.
381 * See g_socket_client_set_socket_type() for details.
383 * Returns: a #GSocketFamily
388 g_socket_client_get_socket_type (GSocketClient *client)
390 return client->priv->type;
394 * g_socket_client_set_socket_type:
395 * @client: a #GSocketClient.
396 * @type: a #GSocketType
398 * Sets the socket type of the socket client.
399 * The sockets created by this object will be of the specified
402 * It doesn't make sense to specify a type of %G_SOCKET_TYPE_DATAGRAM,
403 * as GSocketClient is used for connection oriented services.
408 g_socket_client_set_socket_type (GSocketClient *client,
411 if (client->priv->type == type)
414 client->priv->type = type;
415 g_object_notify (G_OBJECT (client), "type");
419 * g_socket_client_get_protocol:
420 * @client: a #GSocketClient
422 * Gets the protocol name type of the socket client.
424 * See g_socket_client_set_protocol() for details.
426 * Returns: a #GSocketProtocol
431 g_socket_client_get_protocol (GSocketClient *client)
433 return client->priv->protocol;
437 * g_socket_client_set_protocol:
438 * @client: a #GSocketClient.
439 * @protocol: a #GSocketProtocol
441 * Sets the protocol of the socket client.
442 * The sockets created by this object will use of the specified
445 * If @protocol is %0 that means to use the default
446 * protocol for the socket family and type.
451 g_socket_client_set_protocol (GSocketClient *client,
452 GSocketProtocol protocol)
454 if (client->priv->protocol == protocol)
457 client->priv->protocol = protocol;
458 g_object_notify (G_OBJECT (client), "protocol");
462 * g_socket_client_get_local_address:
463 * @client: a #GSocketClient.
465 * Gets the local address of the socket client.
467 * See g_socket_client_set_local_address() for details.
469 * Returns: (transfer none): a #GSocketAddress or %NULL. Do not free.
474 g_socket_client_get_local_address (GSocketClient *client)
476 return client->priv->local_address;
480 * g_socket_client_set_local_address:
481 * @client: a #GSocketClient.
482 * @address: a #GSocketAddress, or %NULL
484 * Sets the local address of the socket client.
485 * The sockets created by this object will bound to the
486 * specified address (if not %NULL) before connecting.
488 * This is useful if you want to ensure that the local
489 * side of the connection is on a specific port, or on
490 * a specific interface.
495 g_socket_client_set_local_address (GSocketClient *client,
496 GSocketAddress *address)
499 g_object_ref (address);
501 if (client->priv->local_address)
503 g_object_unref (client->priv->local_address);
505 client->priv->local_address = address;
506 g_object_notify (G_OBJECT (client), "local-address");
510 * g_socket_client_get_timeout:
511 * @client: a #GSocketClient
513 * Gets the I/O timeout time for sockets created by @client.
515 * See g_socket_client_set_timeout() for details.
517 * Returns: the timeout in seconds
522 g_socket_client_get_timeout (GSocketClient *client)
524 return client->priv->timeout;
529 * g_socket_client_set_timeout:
530 * @client: a #GSocketClient.
531 * @timeout: the timeout
533 * Sets the I/O timeout for sockets created by @client. @timeout is a
534 * time in seconds, or 0 for no timeout (the default).
536 * The timeout value affects the initial connection attempt as well,
537 * so setting this may cause calls to g_socket_client_connect(), etc,
538 * to fail with %G_IO_ERROR_TIMED_OUT.
543 g_socket_client_set_timeout (GSocketClient *client,
546 if (client->priv->timeout == timeout)
549 client->priv->timeout = timeout;
550 g_object_notify (G_OBJECT (client), "timeout");
554 * g_socket_client_get_enable_proxy:
555 * @client: a #GSocketClient.
557 * Gets the proxy enable state; see g_socket_client_set_enable_proxy()
559 * Returns: whether proxying is enabled
564 g_socket_client_get_enable_proxy (GSocketClient *client)
566 return client->priv->enable_proxy;
570 * g_socket_client_set_enable_proxy:
571 * @client: a #GSocketClient.
572 * @enable: whether to enable proxies
574 * Sets whether or not @client attempts to make connections via a
575 * proxy server. When enabled (the default), #GSocketClient will use a
576 * #GProxyResolver to determine if a proxy protocol such as SOCKS is
577 * needed, and automatically do the necessary proxy negotiation.
582 g_socket_client_set_enable_proxy (GSocketClient *client,
586 if (client->priv->enable_proxy == enable)
589 client->priv->enable_proxy = enable;
590 g_object_notify (G_OBJECT (client), "enable-proxy");
594 * g_socket_client_get_tls:
595 * @client: a #GSocketClient.
597 * Gets whether @client creates TLS connections. See
598 * g_socket_client_set_tls() for details.
600 * Returns: whether @client uses TLS
605 g_socket_client_get_tls (GSocketClient *client)
607 return client->priv->tls;
611 * g_socket_client_set_tls:
612 * @client: a #GSocketClient.
613 * @tls: whether to use TLS
615 * Sets whether @client creates TLS (aka SSL) connections. If @tls is
616 * %TRUE, @client will wrap its connections in a #GTlsClientConnection
617 * and perform a TLS handshake when connecting.
619 * Note that since #GSocketClient must return a #GSocketConnection,
620 * but #GTlsClientConnection is not a #GSocketConnection, this
621 * actually wraps the resulting #GTlsClientConnection in a
622 * #GTcpWrapperConnection when returning it. You can use
623 * g_tcp_wrapper_connection_get_base_io_stream() on the return value
624 * to extract the #GTlsClientConnection.
626 * If you need to modify the behavior of the TLS handshake (eg, by
627 * setting a client-side certificate to use, or connecting to the
628 * #GTlsConnection::accept-certificate signal), you can connect to
629 * @client's #GSocketClient::event signal and wait for it to be
630 * emitted with %G_SOCKET_CLIENT_TLS_HANDSHAKING, which will give you
631 * a chance to see the #GTlsClientConnection before the handshake
637 g_socket_client_set_tls (GSocketClient *client,
641 if (tls == client->priv->tls)
644 client->priv->tls = tls;
645 g_object_notify (G_OBJECT (client), "tls");
649 * g_socket_client_get_tls_validation_flags:
650 * @client: a #GSocketClient.
652 * Gets the TLS validation flags used creating TLS connections via
655 * Returns: the TLS validation flags
660 g_socket_client_get_tls_validation_flags (GSocketClient *client)
662 return client->priv->tls_validation_flags;
666 * g_socket_client_set_tls_validation_flags:
667 * @client: a #GSocketClient.
668 * @flags: the validation flags
670 * Sets the TLS validation flags used when creating TLS connections
671 * via @client. The default value is %G_TLS_CERTIFICATE_VALIDATE_ALL.
676 g_socket_client_set_tls_validation_flags (GSocketClient *client,
677 GTlsCertificateFlags flags)
679 if (client->priv->tls_validation_flags != flags)
681 client->priv->tls_validation_flags = flags;
682 g_object_notify (G_OBJECT (client), "tls-validation-flags");
687 g_socket_client_class_init (GSocketClientClass *class)
689 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
691 g_type_class_add_private (class, sizeof (GSocketClientPrivate));
693 gobject_class->finalize = g_socket_client_finalize;
694 gobject_class->set_property = g_socket_client_set_property;
695 gobject_class->get_property = g_socket_client_get_property;
698 * GSocketClient::event:
699 * @client: the #GSocketClient
700 * @event: the event that is occurring
701 * @connectable: the #GSocketConnectable that @event is occurring on
702 * @connection: the current representation of the connection
704 * Emitted when @client's activity on @connectable changes state.
705 * Among other things, this can be used to provide progress
706 * information about a network connection in the UI. The meanings of
707 * the different @event values are as follows:
711 * <term>%G_SOCKET_CLIENT_RESOLVING:</term>
713 * @client is about to look up @connectable in DNS.
714 * @connection will be %NULL.
718 * <term>%G_SOCKET_CLIENT_RESOLVED:</term>
720 * @client has successfully resolved @connectable in DNS.
721 * @connection will be %NULL.
725 * <term>%G_SOCKET_CLIENT_CONNECTING:</term>
727 * @client is about to make a connection to a remote host;
728 * either a proxy server or the destination server itself.
729 * @connection is the #GSocketConnection, which is not yet
734 * <term>%G_SOCKET_CLIENT_CONNECTED:</term>
736 * @client has successfully connected to a remote host.
737 * @connection is the connected #GSocketConnection.
741 * <term>%G_SOCKET_CLIENT_PROXY_NEGOTIATING:</term>
743 * @client is about to negotiate with a proxy to get it to
744 * connect to @connectable. @connection is the
745 * #GSocketConnection to the proxy server.
749 * <term>%G_SOCKET_CLIENT_PROXY_NEGOTIATED:</term>
751 * @client has negotiated a connection to @connectable through
752 * a proxy server. @connection is the stream returned from
753 * g_proxy_connect(), which may or may not be a
754 * #GSocketConnection.
758 * <term>%G_SOCKET_CLIENT_TLS_HANDSHAKING:</term>
760 * @client is about to begin a TLS handshake. @connection is a
761 * #GTlsClientConnection.
765 * <term>%G_SOCKET_CLIENT_TLS_HANDSHAKED:</term>
767 * @client has successfully completed the TLS handshake.
768 * @connection is a #GTlsClientConnection.
772 * <term>%G_SOCKET_CLIENT_COMPLETE:</term>
774 * @client has either successfully connected to @connectable
775 * (in which case @connection is the #GSocketConnection that
776 * it will be returning to the caller) or has failed (in which
777 * case @connection is %NULL and the client is about to return
783 * Each event except %G_SOCKET_CLIENT_COMPLETE may be emitted
784 * multiple times (or not at all) for a given connectable (in
785 * particular, if @client ends up attempting to connect to more than
786 * one address). However, if @client emits the #GSocketClient:event
787 * signal at all for a given connectable, that it will always emit
788 * it with %G_SOCKET_CLIENT_COMPLETE when it is done.
790 * Note that there may be additional #GSocketClientEvent values in
791 * the future; unrecognized @event values should be ignored.
796 g_signal_new (I_("event"),
797 G_TYPE_FROM_CLASS (gobject_class),
799 G_STRUCT_OFFSET (GSocketClientClass, event),
803 G_TYPE_SOCKET_CLIENT_EVENT,
804 G_TYPE_SOCKET_CONNECTABLE,
807 g_object_class_install_property (gobject_class, PROP_FAMILY,
808 g_param_spec_enum ("family",
810 P_("The sockets address family to use for socket construction"),
811 G_TYPE_SOCKET_FAMILY,
812 G_SOCKET_FAMILY_INVALID,
815 G_PARAM_STATIC_STRINGS));
817 g_object_class_install_property (gobject_class, PROP_TYPE,
818 g_param_spec_enum ("type",
820 P_("The sockets type to use for socket construction"),
822 G_SOCKET_TYPE_STREAM,
825 G_PARAM_STATIC_STRINGS));
827 g_object_class_install_property (gobject_class, PROP_PROTOCOL,
828 g_param_spec_enum ("protocol",
829 P_("Socket protocol"),
830 P_("The protocol to use for socket construction, or 0 for default"),
831 G_TYPE_SOCKET_PROTOCOL,
832 G_SOCKET_PROTOCOL_DEFAULT,
835 G_PARAM_STATIC_STRINGS));
837 g_object_class_install_property (gobject_class, PROP_LOCAL_ADDRESS,
838 g_param_spec_object ("local-address",
840 P_("The local address constructed sockets will be bound to"),
841 G_TYPE_SOCKET_ADDRESS,
844 G_PARAM_STATIC_STRINGS));
846 g_object_class_install_property (gobject_class, PROP_TIMEOUT,
847 g_param_spec_uint ("timeout",
848 P_("Socket timeout"),
849 P_("The I/O timeout for sockets, or 0 for none"),
853 G_PARAM_STATIC_STRINGS));
855 g_object_class_install_property (gobject_class, PROP_ENABLE_PROXY,
856 g_param_spec_boolean ("enable-proxy",
858 P_("Enable proxy support"),
862 G_PARAM_STATIC_STRINGS));
864 g_object_class_install_property (gobject_class, PROP_TLS,
865 g_param_spec_boolean ("tls",
867 P_("Whether to create TLS connections"),
871 G_PARAM_STATIC_STRINGS));
872 g_object_class_install_property (gobject_class, PROP_TLS_VALIDATION_FLAGS,
873 g_param_spec_flags ("tls-validation-flags",
874 P_("TLS validation flags"),
875 P_("TLS validation flags to use"),
876 G_TYPE_TLS_CERTIFICATE_FLAGS,
877 G_TLS_CERTIFICATE_VALIDATE_ALL,
880 G_PARAM_STATIC_STRINGS));
884 g_socket_client_emit_event (GSocketClient *client,
885 GSocketClientEvent event,
886 GSocketConnectable *connectable,
887 GIOStream *connection)
889 g_signal_emit (client, signals[EVENT], 0,
890 event, connectable, connection);
894 * g_socket_client_connect:
895 * @client: a #GSocketClient.
896 * @connectable: a #GSocketConnectable specifying the remote address.
897 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
898 * @error: #GError for error reporting, or %NULL to ignore.
900 * Tries to resolve the @connectable and make a network connection to it.
902 * Upon a successful connection, a new #GSocketConnection is constructed
903 * and returned. The caller owns this new object and must drop their
904 * reference to it when finished with it.
906 * The type of the #GSocketConnection object returned depends on the type of
907 * the underlying socket that is used. For instance, for a TCP/IP connection
908 * it will be a #GTcpConnection.
910 * The socket created will be the same family as the address that the
911 * @connectable resolves to, unless family is set with g_socket_client_set_family()
912 * or indirectly via g_socket_client_set_local_address(). The socket type
913 * defaults to %G_SOCKET_TYPE_STREAM but can be set with
914 * g_socket_client_set_socket_type().
916 * If a local address is specified with g_socket_client_set_local_address() the
917 * socket will be bound to this address before connecting.
919 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
924 g_socket_client_connect (GSocketClient *client,
925 GSocketConnectable *connectable,
926 GCancellable *cancellable,
929 GIOStream *connection = NULL;
930 GSocketAddressEnumerator *enumerator = NULL;
931 GError *last_error, *tmp_error;
935 if (can_use_proxy (client))
936 enumerator = g_socket_connectable_proxy_enumerate (connectable);
938 enumerator = g_socket_connectable_enumerate (connectable);
940 while (connection == NULL)
942 GSocketAddress *address = NULL;
943 gboolean application_proxy = FALSE;
945 gboolean using_proxy;
947 if (g_cancellable_is_cancelled (cancellable))
949 g_clear_error (error);
950 g_cancellable_set_error_if_cancelled (cancellable, error);
955 g_socket_client_emit_event (client, G_SOCKET_CLIENT_RESOLVING,
957 address = g_socket_address_enumerator_next (enumerator, cancellable,
964 g_clear_error (&last_error);
965 g_propagate_error (error, tmp_error);
969 g_propagate_error (error, last_error);
972 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
973 _("Unknown error on connect"));
976 g_socket_client_emit_event (client, G_SOCKET_CLIENT_RESOLVED,
979 using_proxy = (G_IS_PROXY_ADDRESS (address) &&
980 client->priv->enable_proxy);
982 /* clear error from previous attempt */
983 g_clear_error (&last_error);
985 socket = create_socket (client, address, &last_error);
988 g_object_unref (address);
992 connection = (GIOStream *)g_socket_connection_factory_create_connection (socket);
993 g_socket_client_emit_event (client, G_SOCKET_CLIENT_CONNECTING, connectable, connection);
995 if (g_socket_connection_connect (G_SOCKET_CONNECTION (connection),
996 address, cancellable, &last_error))
998 g_socket_client_emit_event (client, G_SOCKET_CLIENT_CONNECTED, connectable, connection);
1002 clarify_connect_error (last_error, connectable, address);
1003 g_object_unref (connection);
1007 if (connection && using_proxy)
1009 GProxyAddress *proxy_addr = G_PROXY_ADDRESS (address);
1010 const gchar *protocol;
1013 protocol = g_proxy_address_get_protocol (proxy_addr);
1014 proxy = g_proxy_get_default_for_protocol (protocol);
1016 /* The connection should not be anything else then TCP Connection,
1017 * but let's put a safety guard in case
1019 if (!G_IS_TCP_CONNECTION (connection))
1021 g_critical ("Trying to proxy over non-TCP connection, this is "
1022 "most likely a bug in GLib IO library.");
1024 g_set_error_literal (&last_error,
1025 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
1026 _("Trying to proxy over non-TCP connection is not supported."));
1028 g_object_unref (connection);
1033 GIOStream *proxy_connection;
1035 g_socket_client_emit_event (client, G_SOCKET_CLIENT_PROXY_NEGOTIATING, connectable, connection);
1036 proxy_connection = g_proxy_connect (proxy,
1041 g_object_unref (connection);
1042 connection = proxy_connection;
1043 g_object_unref (proxy);
1046 g_socket_client_emit_event (client, G_SOCKET_CLIENT_PROXY_NEGOTIATED, connectable, connection);
1048 else if (!g_hash_table_lookup_extended (client->priv->app_proxies,
1049 protocol, NULL, NULL))
1051 g_set_error (&last_error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
1052 _("Proxy protocol '%s' is not supported."),
1054 g_object_unref (connection);
1059 application_proxy = TRUE;
1063 if (!application_proxy && connection && client->priv->tls)
1067 tlsconn = g_tls_client_connection_new (connection, connectable, &last_error);
1068 g_object_unref (connection);
1069 connection = tlsconn;
1073 g_tls_client_connection_set_validation_flags (G_TLS_CLIENT_CONNECTION (tlsconn),
1074 client->priv->tls_validation_flags);
1075 g_socket_client_emit_event (client, G_SOCKET_CLIENT_TLS_HANDSHAKING, connectable, connection);
1076 if (g_tls_connection_handshake (G_TLS_CONNECTION (tlsconn),
1077 cancellable, &last_error))
1079 g_socket_client_emit_event (client, G_SOCKET_CLIENT_TLS_HANDSHAKED, connectable, connection);
1083 g_object_unref (tlsconn);
1089 if (connection && !G_IS_SOCKET_CONNECTION (connection))
1091 GSocketConnection *wrapper_connection;
1093 wrapper_connection = g_tcp_wrapper_connection_new (connection, socket);
1094 g_object_unref (connection);
1095 connection = (GIOStream *)wrapper_connection;
1098 g_object_unref (socket);
1099 g_object_unref (address);
1101 g_object_unref (enumerator);
1103 g_socket_client_emit_event (client, G_SOCKET_CLIENT_COMPLETE, connectable, connection);
1104 return G_SOCKET_CONNECTION (connection);
1108 * g_socket_client_connect_to_host:
1109 * @client: a #GSocketClient
1110 * @host_and_port: the name and optionally port of the host to connect to
1111 * @default_port: the default port to connect to
1112 * @cancellable: (allow-none): a #GCancellable, or %NULL
1113 * @error: a pointer to a #GError, or %NULL
1115 * This is a helper function for g_socket_client_connect().
1117 * Attempts to create a TCP connection to the named host.
1119 * @host_and_port may be in any of a number of recognized formats; an IPv6
1120 * address, an IPv4 address, or a domain name (in which case a DNS
1121 * lookup is performed). Quoting with [] is supported for all address
1122 * types. A port override may be specified in the usual way with a
1123 * colon. Ports may be given as decimal numbers or symbolic names (in
1124 * which case an /etc/services lookup is performed).
1126 * If no port override is given in @host_and_port then @default_port will be
1127 * used as the port number to connect to.
1129 * In general, @host_and_port is expected to be provided by the user (allowing
1130 * them to give the hostname, and a port override if necessary) and
1131 * @default_port is expected to be provided by the application.
1133 * In the case that an IP address is given, a single connection
1134 * attempt is made. In the case that a name is given, multiple
1135 * connection attempts may be made, in turn and according to the
1136 * number of address records in DNS, until a connection succeeds.
1138 * Upon a successful connection, a new #GSocketConnection is constructed
1139 * and returned. The caller owns this new object and must drop their
1140 * reference to it when finished with it.
1142 * In the event of any failure (DNS error, service not found, no hosts
1143 * connectable) %NULL is returned and @error (if non-%NULL) is set
1146 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1151 g_socket_client_connect_to_host (GSocketClient *client,
1152 const gchar *host_and_port,
1153 guint16 default_port,
1154 GCancellable *cancellable,
1157 GSocketConnectable *connectable;
1158 GSocketConnection *connection;
1160 connectable = g_network_address_parse (host_and_port, default_port, error);
1161 if (connectable == NULL)
1164 connection = g_socket_client_connect (client, connectable,
1165 cancellable, error);
1166 g_object_unref (connectable);
1172 * g_socket_client_connect_to_service:
1173 * @client: a #GSocketConnection
1174 * @domain: a domain name
1175 * @service: the name of the service to connect to
1176 * @cancellable: (allow-none): a #GCancellable, or %NULL
1177 * @error: a pointer to a #GError, or %NULL
1179 * Attempts to create a TCP connection to a service.
1181 * This call looks up the SRV record for @service at @domain for the
1182 * "tcp" protocol. It then attempts to connect, in turn, to each of
1183 * the hosts providing the service until either a connection succeeds
1184 * or there are no hosts remaining.
1186 * Upon a successful connection, a new #GSocketConnection is constructed
1187 * and returned. The caller owns this new object and must drop their
1188 * reference to it when finished with it.
1190 * In the event of any failure (DNS error, service not found, no hosts
1191 * connectable) %NULL is returned and @error (if non-%NULL) is set
1194 * Returns: (transfer full): a #GSocketConnection if successful, or %NULL on error
1197 g_socket_client_connect_to_service (GSocketClient *client,
1198 const gchar *domain,
1199 const gchar *service,
1200 GCancellable *cancellable,
1203 GSocketConnectable *connectable;
1204 GSocketConnection *connection;
1206 connectable = g_network_service_new (service, "tcp", domain);
1207 connection = g_socket_client_connect (client, connectable,
1208 cancellable, error);
1209 g_object_unref (connectable);
1215 * g_socket_client_connect_to_uri:
1216 * @client: a #GSocketClient
1217 * @uri: A network URI
1218 * @default_port: the default port to connect to
1219 * @cancellable: (allow-none): a #GCancellable, or %NULL
1220 * @error: a pointer to a #GError, or %NULL
1222 * This is a helper function for g_socket_client_connect().
1224 * Attempts to create a TCP connection with a network URI.
1226 * @uri may be any valid URI containing an "authority" (hostname/port)
1227 * component. If a port is not specified in the URI, @default_port
1228 * will be used. TLS will be negotiated if #GSocketClient:tls is %TRUE.
1229 * (#GSocketClient does not know to automatically assume TLS for
1230 * certain URI schemes.)
1232 * Using this rather than g_socket_client_connect() or
1233 * g_socket_client_connect_to_host() allows #GSocketClient to
1234 * determine when to use application-specific proxy protocols.
1236 * Upon a successful connection, a new #GSocketConnection is constructed
1237 * and returned. The caller owns this new object and must drop their
1238 * reference to it when finished with it.
1240 * In the event of any failure (DNS error, service not found, no hosts
1241 * connectable) %NULL is returned and @error (if non-%NULL) is set
1244 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1249 g_socket_client_connect_to_uri (GSocketClient *client,
1251 guint16 default_port,
1252 GCancellable *cancellable,
1255 GSocketConnectable *connectable;
1256 GSocketConnection *connection;
1258 connectable = g_network_address_parse_uri (uri, default_port, error);
1259 if (connectable == NULL)
1262 connection = g_socket_client_connect (client, connectable,
1263 cancellable, error);
1264 g_object_unref (connectable);
1271 GSimpleAsyncResult *result;
1272 GCancellable *cancellable;
1273 GSocketClient *client;
1275 GSocketConnectable *connectable;
1276 GSocketAddressEnumerator *enumerator;
1277 GProxyAddress *proxy_addr;
1278 GSocketAddress *current_addr;
1279 GSocket *current_socket;
1280 GIOStream *connection;
1283 } GSocketClientAsyncConnectData;
1286 g_socket_client_async_connect_complete (GSocketClientAsyncConnectData *data)
1288 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, data->connection);
1290 if (data->last_error)
1292 g_simple_async_result_take_error (data->result, data->last_error);
1296 g_assert (data->connection);
1298 if (!G_IS_SOCKET_CONNECTION (data->connection))
1300 GSocketConnection *wrapper_connection;
1302 wrapper_connection = g_tcp_wrapper_connection_new (data->connection,
1303 data->current_socket);
1304 g_object_unref (data->connection);
1305 data->connection = (GIOStream *)wrapper_connection;
1308 g_simple_async_result_set_op_res_gpointer (data->result,
1313 g_simple_async_result_complete (data->result);
1314 g_object_unref (data->result);
1315 g_object_unref (data->connectable);
1316 g_object_unref (data->enumerator);
1317 if (data->cancellable)
1318 g_object_unref (data->cancellable);
1319 if (data->current_addr)
1320 g_object_unref (data->current_addr);
1321 if (data->current_socket)
1322 g_object_unref (data->current_socket);
1323 if (data->proxy_addr)
1324 g_object_unref (data->proxy_addr);
1325 g_slice_free (GSocketClientAsyncConnectData, data);
1330 g_socket_client_enumerator_callback (GObject *object,
1331 GAsyncResult *result,
1332 gpointer user_data);
1335 set_last_error (GSocketClientAsyncConnectData *data,
1338 g_clear_error (&data->last_error);
1339 data->last_error = error;
1343 enumerator_next_async (GSocketClientAsyncConnectData *data)
1345 /* We need to cleanup the state */
1346 g_clear_object (&data->current_socket);
1347 g_clear_object (&data->current_addr);
1348 g_clear_object (&data->proxy_addr);
1349 g_clear_object (&data->connection);
1351 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_RESOLVING, data->connectable, NULL);
1352 g_socket_address_enumerator_next_async (data->enumerator,
1354 g_socket_client_enumerator_callback,
1359 g_socket_client_tls_handshake_callback (GObject *object,
1360 GAsyncResult *result,
1363 GSocketClientAsyncConnectData *data = user_data;
1365 if (g_tls_connection_handshake_finish (G_TLS_CONNECTION (object),
1369 g_object_unref (data->connection);
1370 data->connection = G_IO_STREAM (object);
1372 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_TLS_HANDSHAKED, data->connectable, data->connection);
1373 g_socket_client_async_connect_complete (data);
1377 g_object_unref (object);
1378 enumerator_next_async (data);
1383 g_socket_client_tls_handshake (GSocketClientAsyncConnectData *data)
1387 if (!data->client->priv->tls)
1389 g_socket_client_async_connect_complete (data);
1393 tlsconn = g_tls_client_connection_new (data->connection,
1398 g_tls_client_connection_set_validation_flags (G_TLS_CLIENT_CONNECTION (tlsconn),
1399 data->client->priv->tls_validation_flags);
1400 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_TLS_HANDSHAKING, data->connectable, G_IO_STREAM (tlsconn));
1401 g_tls_connection_handshake_async (G_TLS_CONNECTION (tlsconn),
1404 g_socket_client_tls_handshake_callback,
1409 enumerator_next_async (data);
1414 g_socket_client_proxy_connect_callback (GObject *object,
1415 GAsyncResult *result,
1418 GSocketClientAsyncConnectData *data = user_data;
1420 g_object_unref (data->connection);
1421 data->connection = g_proxy_connect_finish (G_PROXY (object),
1424 if (data->connection)
1426 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_PROXY_NEGOTIATED, data->connectable, data->connection);
1430 enumerator_next_async (data);
1434 g_socket_client_tls_handshake (data);
1438 g_socket_client_connected_callback (GObject *source,
1439 GAsyncResult *result,
1442 GSocketClientAsyncConnectData *data = user_data;
1443 GError *error = NULL;
1445 const gchar *protocol;
1447 if (!g_socket_connection_connect_finish (G_SOCKET_CONNECTION (source),
1450 clarify_connect_error (error, data->connectable,
1451 data->current_addr);
1452 set_last_error (data, error);
1455 enumerator_next_async (data);
1459 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_CONNECTED, data->connectable, data->connection);
1461 /* wrong, but backward compatible */
1462 g_socket_set_blocking (data->current_socket, TRUE);
1464 if (!data->proxy_addr)
1466 g_socket_client_tls_handshake (data);
1470 protocol = g_proxy_address_get_protocol (data->proxy_addr);
1471 proxy = g_proxy_get_default_for_protocol (protocol);
1473 /* The connection should not be anything other than TCP,
1474 * but let's put a safety guard in case
1476 if (!G_IS_TCP_CONNECTION (data->connection))
1478 g_critical ("Trying to proxy over non-TCP connection, this is "
1479 "most likely a bug in GLib IO library.");
1481 g_set_error_literal (&data->last_error,
1482 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
1483 _("Trying to proxy over non-TCP connection is not supported."));
1485 enumerator_next_async (data);
1489 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_PROXY_NEGOTIATING, data->connectable, data->connection);
1490 g_proxy_connect_async (proxy,
1494 g_socket_client_proxy_connect_callback,
1496 g_object_unref (proxy);
1498 else if (!g_hash_table_lookup_extended (data->client->priv->app_proxies,
1499 protocol, NULL, NULL))
1501 g_clear_error (&data->last_error);
1503 g_set_error (&data->last_error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
1504 _("Proxy protocol '%s' is not supported."),
1507 enumerator_next_async (data);
1511 /* Simply complete the connection, we don't want to do TLS handshake
1512 * as the application proxy handling may need proxy handshake first */
1513 g_socket_client_async_connect_complete (data);
1518 g_socket_client_enumerator_callback (GObject *object,
1519 GAsyncResult *result,
1522 GSocketClientAsyncConnectData *data = user_data;
1523 GSocketAddress *address = NULL;
1525 GError *tmp_error = NULL;
1527 if (g_cancellable_is_cancelled (data->cancellable))
1529 g_clear_error (&data->last_error);
1530 g_cancellable_set_error_if_cancelled (data->cancellable, &data->last_error);
1531 g_socket_client_async_connect_complete (data);
1535 address = g_socket_address_enumerator_next_finish (data->enumerator,
1536 result, &tmp_error);
1538 if (address == NULL)
1541 set_last_error (data, tmp_error);
1542 else if (data->last_error == NULL)
1543 g_set_error_literal (&data->last_error, G_IO_ERROR, G_IO_ERROR_FAILED,
1544 _("Unknown error on connect"));
1546 g_socket_client_async_connect_complete (data);
1550 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_RESOLVED,
1551 data->connectable, NULL);
1553 if (G_IS_PROXY_ADDRESS (address) &&
1554 data->client->priv->enable_proxy)
1555 data->proxy_addr = g_object_ref (G_PROXY_ADDRESS (address));
1557 g_clear_error (&data->last_error);
1559 socket = create_socket (data->client, address, &data->last_error);
1562 g_object_unref (address);
1563 enumerator_next_async (data);
1567 data->current_socket = socket;
1568 data->current_addr = address;
1569 data->connection = (GIOStream *) g_socket_connection_factory_create_connection (socket);
1571 g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_CONNECTING, data->connectable, data->connection);
1572 g_socket_connection_connect_async (G_SOCKET_CONNECTION (data->connection),
1573 address, data->cancellable,
1574 g_socket_client_connected_callback, data);
1578 * g_socket_client_connect_async:
1579 * @client: a #GSocketClient
1580 * @connectable: a #GSocketConnectable specifying the remote address.
1581 * @cancellable: (allow-none): a #GCancellable, or %NULL
1582 * @callback: (scope async): a #GAsyncReadyCallback
1583 * @user_data: (closure): user data for the callback
1585 * This is the asynchronous version of g_socket_client_connect().
1587 * When the operation is finished @callback will be
1588 * called. You can then call g_socket_client_connect_finish() to get
1589 * the result of the operation.
1594 g_socket_client_connect_async (GSocketClient *client,
1595 GSocketConnectable *connectable,
1596 GCancellable *cancellable,
1597 GAsyncReadyCallback callback,
1600 GSocketClientAsyncConnectData *data;
1602 g_return_if_fail (G_IS_SOCKET_CLIENT (client));
1604 data = g_slice_new0 (GSocketClientAsyncConnectData);
1606 data->result = g_simple_async_result_new (G_OBJECT (client),
1607 callback, user_data,
1608 g_socket_client_connect_async);
1609 data->client = client;
1611 data->cancellable = g_object_ref (cancellable);
1613 data->cancellable = NULL;
1614 data->last_error = NULL;
1615 data->connectable = g_object_ref (connectable);
1617 if (can_use_proxy (client))
1618 data->enumerator = g_socket_connectable_proxy_enumerate (connectable);
1620 data->enumerator = g_socket_connectable_enumerate (connectable);
1622 enumerator_next_async (data);
1626 * g_socket_client_connect_to_host_async:
1627 * @client: a #GSocketClient
1628 * @host_and_port: the name and optionally the port of the host to connect to
1629 * @default_port: the default port to connect to
1630 * @cancellable: (allow-none): a #GCancellable, or %NULL
1631 * @callback: (scope async): a #GAsyncReadyCallback
1632 * @user_data: (closure): user data for the callback
1634 * This is the asynchronous version of g_socket_client_connect_to_host().
1636 * When the operation is finished @callback will be
1637 * called. You can then call g_socket_client_connect_to_host_finish() to get
1638 * the result of the operation.
1643 g_socket_client_connect_to_host_async (GSocketClient *client,
1644 const gchar *host_and_port,
1645 guint16 default_port,
1646 GCancellable *cancellable,
1647 GAsyncReadyCallback callback,
1650 GSocketConnectable *connectable;
1654 connectable = g_network_address_parse (host_and_port, default_port,
1656 if (connectable == NULL)
1658 g_simple_async_report_take_gerror_in_idle (G_OBJECT (client),
1659 callback, user_data, error);
1663 g_socket_client_connect_async (client,
1664 connectable, cancellable,
1665 callback, user_data);
1666 g_object_unref (connectable);
1671 * g_socket_client_connect_to_service_async:
1672 * @client: a #GSocketClient
1673 * @domain: a domain name
1674 * @service: the name of the service to connect to
1675 * @cancellable: (allow-none): a #GCancellable, or %NULL
1676 * @callback: (scope async): a #GAsyncReadyCallback
1677 * @user_data: (closure): user data for the callback
1679 * This is the asynchronous version of
1680 * g_socket_client_connect_to_service().
1685 g_socket_client_connect_to_service_async (GSocketClient *client,
1686 const gchar *domain,
1687 const gchar *service,
1688 GCancellable *cancellable,
1689 GAsyncReadyCallback callback,
1692 GSocketConnectable *connectable;
1694 connectable = g_network_service_new (service, "tcp", domain);
1695 g_socket_client_connect_async (client,
1696 connectable, cancellable,
1697 callback, user_data);
1698 g_object_unref (connectable);
1702 * g_socket_client_connect_to_uri_async:
1703 * @client: a #GSocketClient
1704 * @uri: a network uri
1705 * @default_port: the default port to connect to
1706 * @cancellable: (allow-none): a #GCancellable, or %NULL
1707 * @callback: (scope async): a #GAsyncReadyCallback
1708 * @user_data: (closure): user data for the callback
1710 * This is the asynchronous version of g_socket_client_connect_to_uri().
1712 * When the operation is finished @callback will be
1713 * called. You can then call g_socket_client_connect_to_uri_finish() to get
1714 * the result of the operation.
1719 g_socket_client_connect_to_uri_async (GSocketClient *client,
1721 guint16 default_port,
1722 GCancellable *cancellable,
1723 GAsyncReadyCallback callback,
1726 GSocketConnectable *connectable;
1730 connectable = g_network_address_parse_uri (uri, default_port, &error);
1731 if (connectable == NULL)
1733 g_simple_async_report_take_gerror_in_idle (G_OBJECT (client),
1734 callback, user_data, error);
1738 g_socket_client_connect_async (client,
1739 connectable, cancellable,
1740 callback, user_data);
1741 g_object_unref (connectable);
1747 * g_socket_client_connect_finish:
1748 * @client: a #GSocketClient.
1749 * @result: a #GAsyncResult.
1750 * @error: a #GError location to store the error occurring, or %NULL to
1753 * Finishes an async connect operation. See g_socket_client_connect_async()
1755 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1760 g_socket_client_connect_finish (GSocketClient *client,
1761 GAsyncResult *result,
1764 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
1766 if (g_simple_async_result_propagate_error (simple, error))
1769 return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
1773 * g_socket_client_connect_to_host_finish:
1774 * @client: a #GSocketClient.
1775 * @result: a #GAsyncResult.
1776 * @error: a #GError location to store the error occurring, or %NULL to
1779 * Finishes an async connect operation. See g_socket_client_connect_to_host_async()
1781 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1786 g_socket_client_connect_to_host_finish (GSocketClient *client,
1787 GAsyncResult *result,
1790 return g_socket_client_connect_finish (client, result, error);
1794 * g_socket_client_connect_to_service_finish:
1795 * @client: a #GSocketClient.
1796 * @result: a #GAsyncResult.
1797 * @error: a #GError location to store the error occurring, or %NULL to
1800 * Finishes an async connect operation. See g_socket_client_connect_to_service_async()
1802 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1807 g_socket_client_connect_to_service_finish (GSocketClient *client,
1808 GAsyncResult *result,
1811 return g_socket_client_connect_finish (client, result, error);
1815 * g_socket_client_connect_to_uri_finish:
1816 * @client: a #GSocketClient.
1817 * @result: a #GAsyncResult.
1818 * @error: a #GError location to store the error occurring, or %NULL to
1821 * Finishes an async connect operation. See g_socket_client_connect_to_uri_async()
1823 * Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
1828 g_socket_client_connect_to_uri_finish (GSocketClient *client,
1829 GAsyncResult *result,
1832 return g_socket_client_connect_finish (client, result, error);
1836 * g_socket_client_add_application_proxy:
1837 * @client: a #GSocketClient
1838 * @protocol: The proxy protocol
1840 * Enable proxy protocols to be handled by the application. When the
1841 * indicated proxy protocol is returned by the #GProxyResolver,
1842 * #GSocketClient will consider this protocol as supported but will
1843 * not try to find a #GProxy instance to handle handshaking. The
1844 * application must check for this case by calling
1845 * g_socket_connection_get_remote_address() on the returned
1846 * #GSocketConnection, and seeing if it's a #GProxyAddress of the
1847 * appropriate type, to determine whether or not it needs to handle
1848 * the proxy handshaking itself.
1850 * This should be used for proxy protocols that are dialects of
1851 * another protocol such as HTTP proxy. It also allows cohabitation of
1852 * proxy protocols that are reused between protocols. A good example
1853 * is HTTP. It can be used to proxy HTTP, FTP and Gopher and can also
1854 * be use as generic socket proxy through the HTTP CONNECT method.
1856 * When the proxy is detected as being an application proxy, TLS handshake
1857 * will be skipped. This is required to let the application do the proxy
1858 * specific handshake.
1861 g_socket_client_add_application_proxy (GSocketClient *client,
1862 const gchar *protocol)
1864 g_hash_table_insert (client->priv->app_proxies, g_strdup (protocol), NULL);